xref: /linux/arch/powerpc/include/asm/machdep.h (revision 9208c05f9fdfd927ea160b97dfef3c379049fff2)
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/init.h>
8 #include <linux/export.h>
9 #include <linux/time64.h>
10 
11 #include <asm/page.h>
12 
13 struct pt_regs;
14 struct pci_bus;
15 struct device;
16 struct device_node;
17 struct iommu_table;
18 struct rtc_time;
19 struct file;
20 struct pci_dev;
21 struct pci_controller;
22 struct kimage;
23 struct pci_host_bridge;
24 struct seq_file;
25 
26 struct machdep_calls {
27 	const char	*name;
28 	const char	*compatible;
29 	const char * const *compatibles;
30 #ifdef CONFIG_PPC64
31 #ifdef CONFIG_PM
32 	void		(*iommu_restore)(void);
33 #endif
34 #ifdef CONFIG_MEMORY_HOTPLUG
35 	unsigned long	(*memory_block_size)(void);
36 #endif
37 #endif /* CONFIG_PPC64 */
38 
39 	void		(*dma_set_mask)(struct device *dev, u64 dma_mask);
40 
41 	int		(*probe)(void);
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);
47 
48 	void		(*init_IRQ)(void);
49 
50 	/* Return an irq, or 0 to indicate there are none pending. */
51 	unsigned int	(*get_irq)(void);
52 
53 	/* PCI stuff */
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
58 				*bridge);
59 
60 	/* finds all the pci_controllers present at boot */
61 	void 		(*discover_phbs)(void);
62 
63 	/* To setup PHBs when using automatic OF platform driver for PCI */
64 	int		(*pci_setup_phb)(struct pci_controller *host);
65 
66 	void __noreturn	(*restart)(char *cmd);
67 	void __noreturn (*halt)(void);
68 	void		(*panic)(char *str);
69 
70 	long		(*time_init)(void); /* Optional, may be NULL */
71 
72 	int		(*set_rtc_time)(struct rtc_time *);
73 	void		(*get_rtc_time)(struct rtc_time *);
74 	time64_t	(*get_boot_time)(void);
75 
76 	void		(*calibrate_decr)(void);
77 
78 	void		(*progress)(char *, unsigned short);
79 
80 	/* Interface for platform error logging */
81 	void 		(*log_error)(char *buf, unsigned int err_type, int fatal);
82 
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);
89 
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);
94 
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);
98 
99 	/* Called during machine check exception to retrive fixup address. */
100 	bool		(*mce_check_early_recovery)(struct pt_regs *regs);
101 
102 	void            (*machine_check_log_err)(void);
103 
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...).
107 	 */
108 	long	 	(*feature_call)(unsigned int feature, ...);
109 
110 	/* Get legacy PCI/IDE interrupt mapping */
111 	int		(*pci_get_legacy_ide_irq)(struct pci_dev *dev, int channel);
112 
113 	/* Get access protection for /dev/mem */
114 	pgprot_t	(*phys_mem_access_prot)(unsigned long pfn,
115 						unsigned long size,
116 						pgprot_t vma_prot);
117 
118 	/*
119 	 * Function for waiting for work with reduced power in idle loop;
120 	 * called with interrupts disabled.
121 	 */
122 	void		(*power_save)(void);
123 
124 	/* Function to enable performance monitor counters for this
125 	   platform, called once per cpu. */
126 	void		(*enable_pmcs)(void);
127 
128 	/* Set DABR for this platform, leave empty for default implementation */
129 	int		(*set_dabr)(unsigned long dabr,
130 				    unsigned long dabrx);
131 
132 	/* Set DAWR for this platform, leave empty for default implementation */
133 	int		(*set_dawr)(int nr, unsigned long dawr,
134 				    unsigned long dawrx);
135 
136 #ifdef CONFIG_PPC32	/* XXX for now */
137 	/* A general init function, called by ppc_init in init/main.c.
138 	   May be NULL. */
139 	void		(*init)(void);
140 
141 	/*
142 	 * optional PCI "hooks"
143 	 */
144 	/* Called at then very end of pcibios_init() */
145 	void (*pcibios_after_init)(void);
146 
147 #endif /* CONFIG_PPC32 */
148 
149 	/* Called in indirect_* to avoid touching devices */
150 	int (*pci_exclude_device)(struct pci_controller *, unsigned char, unsigned char);
151 
152 	/* Called after PPC generic resource fixup to perform
153 	   machine specific fixups */
154 	void (*pcibios_fixup_resources)(struct pci_dev *);
155 
156 	/* Called for each PCI bus in the system when it's probed */
157 	void (*pcibios_fixup_bus)(struct pci_bus *);
158 
159 	/* Called after scan and before resource survey */
160 	void (*pcibios_fixup_phb)(struct pci_controller *hose);
161 
162 	/*
163 	 * Called after device has been added to bus and
164 	 * before sysfs has been created.
165 	 */
166 	void (*pcibios_bus_add_device)(struct pci_dev *pdev);
167 
168 	resource_size_t (*pcibios_default_alignment)(void);
169 
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 */
176 
177 	/* Called to shutdown machine specific hardware not already controlled
178 	 * by other drivers.
179 	 */
180 	void (*machine_shutdown)(void);
181 
182 #ifdef CONFIG_KEXEC_CORE
183 	void (*kexec_cpu_down)(int crash_shutdown, int secondary);
184 
185 	/* Called to perform the _real_ kexec.
186 	 * Do NOT allocate memory or fail here. We are past the point of
187 	 * no return.
188 	 */
189 	void (*machine_kexec)(struct kimage *image);
190 #endif /* CONFIG_KEXEC_CORE */
191 
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.
197 	 */
198 	void (*suspend_disable_irqs)(void);
199 	void (*suspend_enable_irqs)(void);
200 #endif
201 
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);
205 #endif
206 
207 	int (*get_random_seed)(unsigned long *v);
208 };
209 
210 extern void e500_idle(void);
211 extern void power4_idle(void);
212 extern void ppc6xx_idle(void);
213 
214 /*
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.
218  */
219 extern struct machdep_calls ppc_md;
220 extern struct machdep_calls *machine_id;
221 
222 #define __machine_desc __section(".machine.desc")
223 
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 =
228 
229 static inline bool __machine_is(const struct machdep_calls *md)
230 {
231 	WARN_ON(!machine_id); // complain if used before probe_machine()
232 	return machine_id == md;
233 }
234 
235 #define machine_is(name)                                        \
236 	({                                                      \
237 		extern struct machdep_calls mach_##name __weak; \
238 		__machine_is(&mach_##name);                     \
239 	})
240 
241 static inline void log_error(char *buf, unsigned int err_type, int fatal)
242 {
243 	if (ppc_md.log_error)
244 		ppc_md.log_error(buf, err_type, fatal);
245 }
246 
247 #define __define_machine_initcall(mach, fn, id) \
248 	static int __init __machine_initcall_##mach##_##fn(void) { \
249 		if (machine_is(mach)) return fn(); \
250 		return 0; \
251 	} \
252 	__define_initcall(__machine_initcall_##mach##_##fn, id);
253 
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)
270 
271 #endif /* __KERNEL__ */
272 #endif /* _ASM_POWERPC_MACHDEP_H */
273