1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 #ifndef _ASM_POWERPC_MACHDEP_H
3 #define _ASM_POWERPC_MACHDEP_H
9 #include <linux/seq_file.h>
10 #include <linux/init.h>
11 #include <linux/dma-mapping.h>
12 #include <linux/export.h>
14 #include <asm/setup.h>
16 /* We export this macro for external modules like Alsa to know if
17 * ppc_md.feature_call is implemented or not
19 #define CONFIG_PPC_HAS_FEATURE_CALLS
27 struct pci_controller;
29 struct pci_host_bridge;
31 struct machdep_calls {
34 void __iomem * (*ioremap)(phys_addr_t addr, unsigned long size,
35 pgprot_t prot, void *caller);
36 void (*iounmap)(volatile void __iomem *token);
39 void (*iommu_save)(void);
40 void (*iommu_restore)(void);
42 #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE
43 unsigned long (*memory_block_size)(void);
45 #endif /* CONFIG_PPC64 */
47 void (*dma_set_mask)(struct device *dev, u64 dma_mask);
50 void (*setup_arch)(void); /* Optional, may be NULL */
51 /* Optional, may be NULL. */
52 void (*show_cpuinfo)(struct seq_file *m);
53 void (*show_percpuinfo)(struct seq_file *m, int i);
54 /* Returns the current operating frequency of "cpu" in Hz */
55 unsigned long (*get_proc_freq)(unsigned int cpu);
57 void (*init_IRQ)(void);
59 /* Return an irq, or 0 to indicate there are none pending. */
60 unsigned int (*get_irq)(void);
63 /* Called after allocating resources */
64 void (*pcibios_fixup)(void);
65 void (*pci_irq_fixup)(struct pci_dev *dev);
66 int (*pcibios_root_bridge_prepare)(struct pci_host_bridge
69 /* To setup PHBs when using automatic OF platform driver for PCI */
70 int (*pci_setup_phb)(struct pci_controller *host);
72 void __noreturn (*restart)(char *cmd);
73 void __noreturn (*halt)(void);
74 void (*panic)(char *str);
75 void (*cpu_die)(void);
77 long (*time_init)(void); /* Optional, may be NULL */
79 int (*set_rtc_time)(struct rtc_time *);
80 void (*get_rtc_time)(struct rtc_time *);
81 time64_t (*get_boot_time)(void);
82 unsigned char (*rtc_read_val)(int addr);
83 void (*rtc_write_val)(int addr, unsigned char val);
85 void (*calibrate_decr)(void);
87 void (*progress)(char *, unsigned short);
89 /* Interface for platform error logging */
90 void (*log_error)(char *buf, unsigned int err_type, int fatal);
92 unsigned char (*nvram_read_val)(int addr);
93 void (*nvram_write_val)(int addr, unsigned char val);
94 ssize_t (*nvram_write)(char *buf, size_t count, loff_t *index);
95 ssize_t (*nvram_read)(char *buf, size_t count, loff_t *index);
96 ssize_t (*nvram_size)(void);
97 void (*nvram_sync)(void);
99 /* Exception handlers */
100 int (*system_reset_exception)(struct pt_regs *regs);
101 int (*machine_check_exception)(struct pt_regs *regs);
102 int (*handle_hmi_exception)(struct pt_regs *regs);
104 /* Early exception handlers called in realmode */
105 int (*hmi_exception_early)(struct pt_regs *regs);
106 long (*machine_check_early)(struct pt_regs *regs);
108 /* Called during machine check exception to retrive fixup address. */
109 bool (*mce_check_early_recovery)(struct pt_regs *regs);
111 /* Motherboard/chipset features. This is a kind of general purpose
112 * hook used to control some machine specific features (like reset
113 * lines, chip power control, etc...).
115 long (*feature_call)(unsigned int feature, ...);
117 /* Get legacy PCI/IDE interrupt mapping */
118 int (*pci_get_legacy_ide_irq)(struct pci_dev *dev, int channel);
120 /* Get access protection for /dev/mem */
121 pgprot_t (*phys_mem_access_prot)(struct file *file,
127 * Function for waiting for work with reduced power in idle loop;
128 * called with interrupts disabled.
130 void (*power_save)(void);
132 /* Function to enable performance monitor counters for this
133 platform, called once per cpu. */
134 void (*enable_pmcs)(void);
136 /* Set DABR for this platform, leave empty for default implementation */
137 int (*set_dabr)(unsigned long dabr,
138 unsigned long dabrx);
140 /* Set DAWR for this platform, leave empty for default implementation */
141 int (*set_dawr)(unsigned long dawr,
142 unsigned long dawrx);
144 #ifdef CONFIG_PPC32 /* XXX for now */
145 /* A general init function, called by ppc_init in init/main.c.
149 void (*kgdb_map_scc)(void);
152 * optional PCI "hooks"
154 /* Called at then very end of pcibios_init() */
155 void (*pcibios_after_init)(void);
157 #endif /* CONFIG_PPC32 */
159 /* Called in indirect_* to avoid touching devices */
160 int (*pci_exclude_device)(struct pci_controller *, unsigned char, unsigned char);
162 /* Called after PPC generic resource fixup to perform
163 machine specific fixups */
164 void (*pcibios_fixup_resources)(struct pci_dev *);
166 /* Called for each PCI bus in the system when it's probed */
167 void (*pcibios_fixup_bus)(struct pci_bus *);
169 /* Called after scan and before resource survey */
170 void (*pcibios_fixup_phb)(struct pci_controller *hose);
173 * Called after device has been added to bus and
174 * before sysfs has been created.
176 void (*pcibios_bus_add_device)(struct pci_dev *pdev);
178 resource_size_t (*pcibios_default_alignment)(void);
180 #ifdef CONFIG_PCI_IOV
181 void (*pcibios_fixup_sriov)(struct pci_dev *pdev);
182 resource_size_t (*pcibios_iov_resource_alignment)(struct pci_dev *, int resno);
183 int (*pcibios_sriov_enable)(struct pci_dev *pdev, u16 num_vfs);
184 int (*pcibios_sriov_disable)(struct pci_dev *pdev);
185 #endif /* CONFIG_PCI_IOV */
187 /* Called to shutdown machine specific hardware not already controlled
190 void (*machine_shutdown)(void);
192 #ifdef CONFIG_KEXEC_CORE
193 void (*kexec_cpu_down)(int crash_shutdown, int secondary);
195 /* Called to do what every setup is needed on image and the
196 * reboot code buffer. Returns 0 on success.
197 * Provide your own (maybe dummy) implementation if your platform
198 * claims to support kexec.
200 int (*machine_kexec_prepare)(struct kimage *image);
202 /* Called to perform the _real_ kexec.
203 * Do NOT allocate memory or fail here. We are past the point of
206 void (*machine_kexec)(struct kimage *image);
207 #endif /* CONFIG_KEXEC_CORE */
209 #ifdef CONFIG_SUSPEND
210 /* These are called to disable and enable, respectively, IRQs when
211 * entering a suspend state. If NULL, then the generic versions
212 * will be called. The generic versions disable/enable the
213 * decrementer along with interrupts.
215 void (*suspend_disable_irqs)(void);
216 void (*suspend_enable_irqs)(void);
218 int (*suspend_disable_cpu)(void);
220 #ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
221 ssize_t (*cpu_probe)(const char *, size_t);
222 ssize_t (*cpu_release)(const char *, size_t);
225 #ifdef CONFIG_ARCH_RANDOM
226 int (*get_random_seed)(unsigned long *v);
230 extern void e500_idle(void);
231 extern void power4_idle(void);
232 extern void power7_idle(void);
233 extern void power9_idle(void);
234 extern void ppc6xx_idle(void);
235 extern void book3e_idle(void);
238 * ppc_md contains a copy of the machine description structure for the
239 * current platform. machine_id contains the initial address where the
240 * description was found during boot.
242 extern struct machdep_calls ppc_md;
243 extern struct machdep_calls *machine_id;
245 #define __machine_desc __attribute__ ((__section__ (".machine.desc")))
247 #define define_machine(name) \
248 extern struct machdep_calls mach_##name; \
249 EXPORT_SYMBOL(mach_##name); \
250 struct machdep_calls mach_##name __machine_desc =
252 #define machine_is(name) \
254 extern struct machdep_calls mach_##name \
255 __attribute__((weak)); \
256 machine_id == &mach_##name; \
259 extern void probe_machine(void);
261 #ifdef CONFIG_PPC_PMAC
263 * Power macintoshes have either a CUDA, PMU or SMU controlling
264 * system reset, power, NVRAM, RTC.
266 typedef enum sys_ctrler_kind {
267 SYS_CTRLER_UNKNOWN = 0,
272 extern sys_ctrler_t sys_ctrler;
274 #endif /* CONFIG_PPC_PMAC */
276 static inline void log_error(char *buf, unsigned int err_type, int fatal)
278 if (ppc_md.log_error)
279 ppc_md.log_error(buf, err_type, fatal);
282 #define __define_machine_initcall(mach, fn, id) \
283 static int __init __machine_initcall_##mach##_##fn(void) { \
284 if (machine_is(mach)) return fn(); \
287 __define_initcall(__machine_initcall_##mach##_##fn, id);
289 #define machine_early_initcall(mach, fn) __define_machine_initcall(mach, fn, early)
290 #define machine_core_initcall(mach, fn) __define_machine_initcall(mach, fn, 1)
291 #define machine_core_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 1s)
292 #define machine_postcore_initcall(mach, fn) __define_machine_initcall(mach, fn, 2)
293 #define machine_postcore_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 2s)
294 #define machine_arch_initcall(mach, fn) __define_machine_initcall(mach, fn, 3)
295 #define machine_arch_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 3s)
296 #define machine_subsys_initcall(mach, fn) __define_machine_initcall(mach, fn, 4)
297 #define machine_subsys_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 4s)
298 #define machine_fs_initcall(mach, fn) __define_machine_initcall(mach, fn, 5)
299 #define machine_fs_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 5s)
300 #define machine_rootfs_initcall(mach, fn) __define_machine_initcall(mach, fn, rootfs)
301 #define machine_device_initcall(mach, fn) __define_machine_initcall(mach, fn, 6)
302 #define machine_device_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 6s)
303 #define machine_late_initcall(mach, fn) __define_machine_initcall(mach, fn, 7)
304 #define machine_late_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 7s)
306 #endif /* __KERNEL__ */
307 #endif /* _ASM_POWERPC_MACHDEP_H */