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