xref: /openbmc/linux/arch/powerpc/include/asm/machdep.h (revision b8d312aa)
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 /*
7  */
8 
9 #include <linux/seq_file.h>
10 #include <linux/init.h>
11 #include <linux/dma-mapping.h>
12 #include <linux/export.h>
13 
14 #include <asm/setup.h>
15 
16 /* We export this macro for external modules like Alsa to know if
17  * ppc_md.feature_call is implemented or not
18  */
19 #define CONFIG_PPC_HAS_FEATURE_CALLS
20 
21 struct pt_regs;
22 struct pci_bus;
23 struct device_node;
24 struct iommu_table;
25 struct rtc_time;
26 struct file;
27 struct pci_controller;
28 struct kimage;
29 struct pci_host_bridge;
30 
31 struct machdep_calls {
32 	char		*name;
33 #ifdef CONFIG_PPC64
34 	void __iomem *	(*ioremap)(phys_addr_t addr, unsigned long size,
35 				   pgprot_t prot, void *caller);
36 	void		(*iounmap)(volatile void __iomem *token);
37 
38 #ifdef CONFIG_PM
39 	void		(*iommu_save)(void);
40 	void		(*iommu_restore)(void);
41 #endif
42 #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE
43 	unsigned long	(*memory_block_size)(void);
44 #endif
45 #endif /* CONFIG_PPC64 */
46 
47 	void		(*dma_set_mask)(struct device *dev, u64 dma_mask);
48 
49 	int		(*probe)(void);
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);
56 
57 	void		(*init_IRQ)(void);
58 
59 	/* Return an irq, or 0 to indicate there are none pending. */
60 	unsigned int	(*get_irq)(void);
61 
62 	/* PCI stuff */
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
67 				*bridge);
68 
69 	/* To setup PHBs when using automatic OF platform driver for PCI */
70 	int		(*pci_setup_phb)(struct pci_controller *host);
71 
72 	void __noreturn	(*restart)(char *cmd);
73 	void __noreturn (*halt)(void);
74 	void		(*panic)(char *str);
75 	void		(*cpu_die)(void);
76 
77 	long		(*time_init)(void); /* Optional, may be NULL */
78 
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);
84 
85 	void		(*calibrate_decr)(void);
86 
87 	void		(*progress)(char *, unsigned short);
88 
89 	/* Interface for platform error logging */
90 	void 		(*log_error)(char *buf, unsigned int err_type, int fatal);
91 
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);
98 
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);
103 
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);
107 
108 	/* Called during machine check exception to retrive fixup address. */
109 	bool		(*mce_check_early_recovery)(struct pt_regs *regs);
110 
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...).
114 	 */
115 	long	 	(*feature_call)(unsigned int feature, ...);
116 
117 	/* Get legacy PCI/IDE interrupt mapping */
118 	int		(*pci_get_legacy_ide_irq)(struct pci_dev *dev, int channel);
119 
120 	/* Get access protection for /dev/mem */
121 	pgprot_t	(*phys_mem_access_prot)(struct file *file,
122 						unsigned long pfn,
123 						unsigned long size,
124 						pgprot_t vma_prot);
125 
126 	/*
127 	 * Function for waiting for work with reduced power in idle loop;
128 	 * called with interrupts disabled.
129 	 */
130 	void		(*power_save)(void);
131 
132 	/* Function to enable performance monitor counters for this
133 	   platform, called once per cpu. */
134 	void		(*enable_pmcs)(void);
135 
136 	/* Set DABR for this platform, leave empty for default implementation */
137 	int		(*set_dabr)(unsigned long dabr,
138 				    unsigned long dabrx);
139 
140 	/* Set DAWR for this platform, leave empty for default implementation */
141 	int		(*set_dawr)(unsigned long dawr,
142 				    unsigned long dawrx);
143 
144 #ifdef CONFIG_PPC32	/* XXX for now */
145 	/* A general init function, called by ppc_init in init/main.c.
146 	   May be NULL. */
147 	void		(*init)(void);
148 
149 	void		(*kgdb_map_scc)(void);
150 
151 	/*
152 	 * optional PCI "hooks"
153 	 */
154 	/* Called at then very end of pcibios_init() */
155 	void (*pcibios_after_init)(void);
156 
157 #endif /* CONFIG_PPC32 */
158 
159 	/* Called in indirect_* to avoid touching devices */
160 	int (*pci_exclude_device)(struct pci_controller *, unsigned char, unsigned char);
161 
162 	/* Called after PPC generic resource fixup to perform
163 	   machine specific fixups */
164 	void (*pcibios_fixup_resources)(struct pci_dev *);
165 
166 	/* Called for each PCI bus in the system when it's probed */
167 	void (*pcibios_fixup_bus)(struct pci_bus *);
168 
169 	/* Called after scan and before resource survey */
170 	void (*pcibios_fixup_phb)(struct pci_controller *hose);
171 
172 	/*
173 	 * Called after device has been added to bus and
174 	 * before sysfs has been created.
175 	 */
176 	void (*pcibios_bus_add_device)(struct pci_dev *pdev);
177 
178 	resource_size_t (*pcibios_default_alignment)(void);
179 
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 */
186 
187 	/* Called to shutdown machine specific hardware not already controlled
188 	 * by other drivers.
189 	 */
190 	void (*machine_shutdown)(void);
191 
192 #ifdef CONFIG_KEXEC_CORE
193 	void (*kexec_cpu_down)(int crash_shutdown, int secondary);
194 
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.
199 	 */
200 	int (*machine_kexec_prepare)(struct kimage *image);
201 
202 	/* Called to perform the _real_ kexec.
203 	 * Do NOT allocate memory or fail here. We are past the point of
204 	 * no return.
205 	 */
206 	void (*machine_kexec)(struct kimage *image);
207 #endif /* CONFIG_KEXEC_CORE */
208 
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.
214 	 */
215 	void (*suspend_disable_irqs)(void);
216 	void (*suspend_enable_irqs)(void);
217 #endif
218 	int (*suspend_disable_cpu)(void);
219 
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);
223 #endif
224 
225 #ifdef CONFIG_ARCH_RANDOM
226 	int (*get_random_seed)(unsigned long *v);
227 #endif
228 };
229 
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);
236 
237 /*
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.
241  */
242 extern struct machdep_calls ppc_md;
243 extern struct machdep_calls *machine_id;
244 
245 #define __machine_desc __attribute__ ((__section__ (".machine.desc")))
246 
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 =
251 
252 #define machine_is(name) \
253 	({ \
254 		extern struct machdep_calls mach_##name \
255 			__attribute__((weak));		 \
256 		machine_id == &mach_##name; \
257 	})
258 
259 extern void probe_machine(void);
260 
261 #ifdef CONFIG_PPC_PMAC
262 /*
263  * Power macintoshes have either a CUDA, PMU or SMU controlling
264  * system reset, power, NVRAM, RTC.
265  */
266 typedef enum sys_ctrler_kind {
267 	SYS_CTRLER_UNKNOWN = 0,
268 	SYS_CTRLER_CUDA = 1,
269 	SYS_CTRLER_PMU = 2,
270 	SYS_CTRLER_SMU = 3,
271 } sys_ctrler_t;
272 extern sys_ctrler_t sys_ctrler;
273 
274 #endif /* CONFIG_PPC_PMAC */
275 
276 static inline void log_error(char *buf, unsigned int err_type, int fatal)
277 {
278 	if (ppc_md.log_error)
279 		ppc_md.log_error(buf, err_type, fatal);
280 }
281 
282 #define __define_machine_initcall(mach, fn, id) \
283 	static int __init __machine_initcall_##mach##_##fn(void) { \
284 		if (machine_is(mach)) return fn(); \
285 		return 0; \
286 	} \
287 	__define_initcall(__machine_initcall_##mach##_##fn, id);
288 
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)
305 
306 #endif /* __KERNEL__ */
307 #endif /* _ASM_POWERPC_MACHDEP_H */
308