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