1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 #ifndef _ASM_POWERPC_MACHDEP_H 3 #define _ASM_POWERPC_MACHDEP_H 4 #ifdef __KERNEL__ 5 6 #include <linux/compiler.h> 7 #include <linux/seq_file.h> 8 #include <linux/init.h> 9 #include <linux/dma-mapping.h> 10 #include <linux/export.h> 11 12 struct pt_regs; 13 struct pci_bus; 14 struct device_node; 15 struct iommu_table; 16 struct rtc_time; 17 struct file; 18 struct pci_controller; 19 struct kimage; 20 struct pci_host_bridge; 21 22 struct machdep_calls { 23 char *name; 24 #ifdef CONFIG_PPC64 25 #ifdef CONFIG_PM 26 void (*iommu_restore)(void); 27 #endif 28 #ifdef CONFIG_MEMORY_HOTPLUG 29 unsigned long (*memory_block_size)(void); 30 #endif 31 #endif /* CONFIG_PPC64 */ 32 33 void (*dma_set_mask)(struct device *dev, u64 dma_mask); 34 35 int (*probe)(void); 36 void (*setup_arch)(void); /* Optional, may be NULL */ 37 /* Optional, may be NULL. */ 38 void (*show_cpuinfo)(struct seq_file *m); 39 /* Returns the current operating frequency of "cpu" in Hz */ 40 unsigned long (*get_proc_freq)(unsigned int cpu); 41 42 void (*init_IRQ)(void); 43 44 /* Return an irq, or 0 to indicate there are none pending. */ 45 unsigned int (*get_irq)(void); 46 47 /* PCI stuff */ 48 /* Called after allocating resources */ 49 void (*pcibios_fixup)(void); 50 void (*pci_irq_fixup)(struct pci_dev *dev); 51 int (*pcibios_root_bridge_prepare)(struct pci_host_bridge 52 *bridge); 53 54 /* finds all the pci_controllers present at boot */ 55 void (*discover_phbs)(void); 56 57 /* To setup PHBs when using automatic OF platform driver for PCI */ 58 int (*pci_setup_phb)(struct pci_controller *host); 59 60 void __noreturn (*restart)(char *cmd); 61 void __noreturn (*halt)(void); 62 void (*panic)(char *str); 63 64 long (*time_init)(void); /* Optional, may be NULL */ 65 66 int (*set_rtc_time)(struct rtc_time *); 67 void (*get_rtc_time)(struct rtc_time *); 68 time64_t (*get_boot_time)(void); 69 70 void (*calibrate_decr)(void); 71 72 void (*progress)(char *, unsigned short); 73 74 /* Interface for platform error logging */ 75 void (*log_error)(char *buf, unsigned int err_type, int fatal); 76 77 unsigned char (*nvram_read_val)(int addr); 78 void (*nvram_write_val)(int addr, unsigned char val); 79 ssize_t (*nvram_write)(char *buf, size_t count, loff_t *index); 80 ssize_t (*nvram_read)(char *buf, size_t count, loff_t *index); 81 ssize_t (*nvram_size)(void); 82 void (*nvram_sync)(void); 83 84 /* Exception handlers */ 85 int (*system_reset_exception)(struct pt_regs *regs); 86 int (*machine_check_exception)(struct pt_regs *regs); 87 int (*handle_hmi_exception)(struct pt_regs *regs); 88 89 /* Early exception handlers called in realmode */ 90 int (*hmi_exception_early)(struct pt_regs *regs); 91 long (*machine_check_early)(struct pt_regs *regs); 92 93 /* Called during machine check exception to retrive fixup address. */ 94 bool (*mce_check_early_recovery)(struct pt_regs *regs); 95 96 void (*machine_check_log_err)(void); 97 98 /* Motherboard/chipset features. This is a kind of general purpose 99 * hook used to control some machine specific features (like reset 100 * lines, chip power control, etc...). 101 */ 102 long (*feature_call)(unsigned int feature, ...); 103 104 /* Get legacy PCI/IDE interrupt mapping */ 105 int (*pci_get_legacy_ide_irq)(struct pci_dev *dev, int channel); 106 107 /* Get access protection for /dev/mem */ 108 pgprot_t (*phys_mem_access_prot)(struct file *file, 109 unsigned long pfn, 110 unsigned long size, 111 pgprot_t vma_prot); 112 113 /* 114 * Function for waiting for work with reduced power in idle loop; 115 * called with interrupts disabled. 116 */ 117 void (*power_save)(void); 118 119 /* Function to enable performance monitor counters for this 120 platform, called once per cpu. */ 121 void (*enable_pmcs)(void); 122 123 /* Set DABR for this platform, leave empty for default implementation */ 124 int (*set_dabr)(unsigned long dabr, 125 unsigned long dabrx); 126 127 /* Set DAWR for this platform, leave empty for default implementation */ 128 int (*set_dawr)(int nr, unsigned long dawr, 129 unsigned long dawrx); 130 131 #ifdef CONFIG_PPC32 /* XXX for now */ 132 /* A general init function, called by ppc_init in init/main.c. 133 May be NULL. */ 134 void (*init)(void); 135 136 /* 137 * optional PCI "hooks" 138 */ 139 /* Called at then very end of pcibios_init() */ 140 void (*pcibios_after_init)(void); 141 142 #endif /* CONFIG_PPC32 */ 143 144 /* Called in indirect_* to avoid touching devices */ 145 int (*pci_exclude_device)(struct pci_controller *, unsigned char, unsigned char); 146 147 /* Called after PPC generic resource fixup to perform 148 machine specific fixups */ 149 void (*pcibios_fixup_resources)(struct pci_dev *); 150 151 /* Called for each PCI bus in the system when it's probed */ 152 void (*pcibios_fixup_bus)(struct pci_bus *); 153 154 /* Called after scan and before resource survey */ 155 void (*pcibios_fixup_phb)(struct pci_controller *hose); 156 157 /* 158 * Called after device has been added to bus and 159 * before sysfs has been created. 160 */ 161 void (*pcibios_bus_add_device)(struct pci_dev *pdev); 162 163 resource_size_t (*pcibios_default_alignment)(void); 164 165 #ifdef CONFIG_PCI_IOV 166 void (*pcibios_fixup_sriov)(struct pci_dev *pdev); 167 resource_size_t (*pcibios_iov_resource_alignment)(struct pci_dev *, int resno); 168 int (*pcibios_sriov_enable)(struct pci_dev *pdev, u16 num_vfs); 169 int (*pcibios_sriov_disable)(struct pci_dev *pdev); 170 #endif /* CONFIG_PCI_IOV */ 171 172 /* Called to shutdown machine specific hardware not already controlled 173 * by other drivers. 174 */ 175 void (*machine_shutdown)(void); 176 177 #ifdef CONFIG_KEXEC_CORE 178 void (*kexec_cpu_down)(int crash_shutdown, int secondary); 179 180 /* Called to perform the _real_ kexec. 181 * Do NOT allocate memory or fail here. We are past the point of 182 * no return. 183 */ 184 void (*machine_kexec)(struct kimage *image); 185 #endif /* CONFIG_KEXEC_CORE */ 186 187 #ifdef CONFIG_SUSPEND 188 /* These are called to disable and enable, respectively, IRQs when 189 * entering a suspend state. If NULL, then the generic versions 190 * will be called. The generic versions disable/enable the 191 * decrementer along with interrupts. 192 */ 193 void (*suspend_disable_irqs)(void); 194 void (*suspend_enable_irqs)(void); 195 #endif 196 197 #ifdef CONFIG_ARCH_CPU_PROBE_RELEASE 198 ssize_t (*cpu_probe)(const char *, size_t); 199 ssize_t (*cpu_release)(const char *, size_t); 200 #endif 201 202 int (*get_random_seed)(unsigned long *v); 203 }; 204 205 extern void e500_idle(void); 206 extern void power4_idle(void); 207 extern void ppc6xx_idle(void); 208 209 /* 210 * ppc_md contains a copy of the machine description structure for the 211 * current platform. machine_id contains the initial address where the 212 * description was found during boot. 213 */ 214 extern struct machdep_calls ppc_md; 215 extern struct machdep_calls *machine_id; 216 217 #define __machine_desc __section(".machine.desc") 218 219 #define define_machine(name) \ 220 extern struct machdep_calls mach_##name; \ 221 EXPORT_SYMBOL(mach_##name); \ 222 struct machdep_calls mach_##name __machine_desc = 223 224 static inline bool __machine_is(const struct machdep_calls *md) 225 { 226 WARN_ON(!machine_id); // complain if used before probe_machine() 227 return machine_id == md; 228 } 229 230 #define machine_is(name) \ 231 ({ \ 232 extern struct machdep_calls mach_##name __weak; \ 233 __machine_is(&mach_##name); \ 234 }) 235 236 static inline void log_error(char *buf, unsigned int err_type, int fatal) 237 { 238 if (ppc_md.log_error) 239 ppc_md.log_error(buf, err_type, fatal); 240 } 241 242 #define __define_machine_initcall(mach, fn, id) \ 243 static int __init __machine_initcall_##mach##_##fn(void) { \ 244 if (machine_is(mach)) return fn(); \ 245 return 0; \ 246 } \ 247 __define_initcall(__machine_initcall_##mach##_##fn, id); 248 249 #define machine_early_initcall(mach, fn) __define_machine_initcall(mach, fn, early) 250 #define machine_core_initcall(mach, fn) __define_machine_initcall(mach, fn, 1) 251 #define machine_core_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 1s) 252 #define machine_postcore_initcall(mach, fn) __define_machine_initcall(mach, fn, 2) 253 #define machine_postcore_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 2s) 254 #define machine_arch_initcall(mach, fn) __define_machine_initcall(mach, fn, 3) 255 #define machine_arch_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 3s) 256 #define machine_subsys_initcall(mach, fn) __define_machine_initcall(mach, fn, 4) 257 #define machine_subsys_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 4s) 258 #define machine_fs_initcall(mach, fn) __define_machine_initcall(mach, fn, 5) 259 #define machine_fs_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 5s) 260 #define machine_rootfs_initcall(mach, fn) __define_machine_initcall(mach, fn, rootfs) 261 #define machine_device_initcall(mach, fn) __define_machine_initcall(mach, fn, 6) 262 #define machine_device_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 6s) 263 #define machine_late_initcall(mach, fn) __define_machine_initcall(mach, fn, 7) 264 #define machine_late_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 7s) 265 266 #endif /* __KERNEL__ */ 267 #endif /* _ASM_POWERPC_MACHDEP_H */ 268