GNU Linux-libre 4.19.211-gnu1
[releases.git] / arch / powerpc / include / asm / machdep.h
1 #ifndef _ASM_POWERPC_MACHDEP_H
2 #define _ASM_POWERPC_MACHDEP_H
3 #ifdef __KERNEL__
4
5 /*
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version
9  * 2 of the License, or (at your option) any later version.
10  */
11
12 #include <linux/seq_file.h>
13 #include <linux/init.h>
14 #include <linux/dma-mapping.h>
15 #include <linux/export.h>
16
17 #include <asm/setup.h>
18
19 /* We export this macro for external modules like Alsa to know if
20  * ppc_md.feature_call is implemented or not
21  */
22 #define CONFIG_PPC_HAS_FEATURE_CALLS
23
24 struct pt_regs;
25 struct pci_bus; 
26 struct device_node;
27 struct iommu_table;
28 struct rtc_time;
29 struct file;
30 struct pci_controller;
31 struct kimage;
32 struct pci_host_bridge;
33
34 struct machdep_calls {
35         char            *name;
36 #ifdef CONFIG_PPC64
37         void __iomem *  (*ioremap)(phys_addr_t addr, unsigned long size,
38                                    unsigned long flags, void *caller);
39         void            (*iounmap)(volatile void __iomem *token);
40
41 #ifdef CONFIG_PM
42         void            (*iommu_save)(void);
43         void            (*iommu_restore)(void);
44 #endif
45 #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE
46         unsigned long   (*memory_block_size)(void);
47 #endif
48 #endif /* CONFIG_PPC64 */
49
50         /* Platform set_dma_mask and dma_get_required_mask overrides */
51         int             (*dma_set_mask)(struct device *dev, u64 dma_mask);
52         u64             (*dma_get_required_mask)(struct device *dev);
53
54         int             (*probe)(void);
55         void            (*setup_arch)(void); /* Optional, may be NULL */
56         /* Optional, may be NULL. */
57         void            (*show_cpuinfo)(struct seq_file *m);
58         void            (*show_percpuinfo)(struct seq_file *m, int i);
59         /* Returns the current operating frequency of "cpu" in Hz */
60         unsigned long   (*get_proc_freq)(unsigned int cpu);
61
62         void            (*init_IRQ)(void);
63
64         /* Return an irq, or 0 to indicate there are none pending. */
65         unsigned int    (*get_irq)(void);
66
67         /* PCI stuff */
68         /* Called after allocating resources */
69         void            (*pcibios_fixup)(void);
70         void            (*pci_irq_fixup)(struct pci_dev *dev);
71         int             (*pcibios_root_bridge_prepare)(struct pci_host_bridge
72                                 *bridge);
73
74         /* finds all the pci_controllers present at boot */
75         void            (*discover_phbs)(void);
76
77         /* To setup PHBs when using automatic OF platform driver for PCI */
78         int             (*pci_setup_phb)(struct pci_controller *host);
79
80         void __noreturn (*restart)(char *cmd);
81         void __noreturn (*halt)(void);
82         void            (*panic)(char *str);
83         void            (*cpu_die)(void);
84
85         long            (*time_init)(void); /* Optional, may be NULL */
86
87         int             (*set_rtc_time)(struct rtc_time *);
88         void            (*get_rtc_time)(struct rtc_time *);
89         time64_t        (*get_boot_time)(void);
90         unsigned char   (*rtc_read_val)(int addr);
91         void            (*rtc_write_val)(int addr, unsigned char val);
92
93         void            (*calibrate_decr)(void);
94
95         void            (*progress)(char *, unsigned short);
96
97         /* Interface for platform error logging */
98         void            (*log_error)(char *buf, unsigned int err_type, int fatal);
99
100         unsigned char   (*nvram_read_val)(int addr);
101         void            (*nvram_write_val)(int addr, unsigned char val);
102         ssize_t         (*nvram_write)(char *buf, size_t count, loff_t *index);
103         ssize_t         (*nvram_read)(char *buf, size_t count, loff_t *index);  
104         ssize_t         (*nvram_size)(void);            
105         void            (*nvram_sync)(void);
106
107         /* Exception handlers */
108         int             (*system_reset_exception)(struct pt_regs *regs);
109         int             (*machine_check_exception)(struct pt_regs *regs);
110         int             (*handle_hmi_exception)(struct pt_regs *regs);
111
112         /* Early exception handlers called in realmode */
113         int             (*hmi_exception_early)(struct pt_regs *regs);
114
115         /* Called during machine check exception to retrive fixup address. */
116         bool            (*mce_check_early_recovery)(struct pt_regs *regs);
117
118         /* Motherboard/chipset features. This is a kind of general purpose
119          * hook used to control some machine specific features (like reset
120          * lines, chip power control, etc...).
121          */
122         long            (*feature_call)(unsigned int feature, ...);
123
124         /* Get legacy PCI/IDE interrupt mapping */ 
125         int             (*pci_get_legacy_ide_irq)(struct pci_dev *dev, int channel);
126         
127         /* Get access protection for /dev/mem */
128         pgprot_t        (*phys_mem_access_prot)(struct file *file,
129                                                 unsigned long pfn,
130                                                 unsigned long size,
131                                                 pgprot_t vma_prot);
132
133         /*
134          * Function for waiting for work with reduced power in idle loop;
135          * called with interrupts disabled.
136          */
137         void            (*power_save)(void);
138
139         /* Function to enable performance monitor counters for this
140            platform, called once per cpu. */
141         void            (*enable_pmcs)(void);
142
143         /* Set DABR for this platform, leave empty for default implementation */
144         int             (*set_dabr)(unsigned long dabr,
145                                     unsigned long dabrx);
146
147         /* Set DAWR for this platform, leave empty for default implementation */
148         int             (*set_dawr)(unsigned long dawr,
149                                     unsigned long dawrx);
150
151 #ifdef CONFIG_PPC32     /* XXX for now */
152         /* A general init function, called by ppc_init in init/main.c.
153            May be NULL. */
154         void            (*init)(void);
155
156         void            (*kgdb_map_scc)(void);
157
158         /*
159          * optional PCI "hooks"
160          */
161         /* Called at then very end of pcibios_init() */
162         void (*pcibios_after_init)(void);
163
164 #endif /* CONFIG_PPC32 */
165
166         /* Called in indirect_* to avoid touching devices */
167         int (*pci_exclude_device)(struct pci_controller *, unsigned char, unsigned char);
168
169         /* Called after PPC generic resource fixup to perform
170            machine specific fixups */
171         void (*pcibios_fixup_resources)(struct pci_dev *);
172
173         /* Called for each PCI bus in the system when it's probed */
174         void (*pcibios_fixup_bus)(struct pci_bus *);
175
176         /* Called after scan and before resource survey */
177         void (*pcibios_fixup_phb)(struct pci_controller *hose);
178
179         /*
180          * Called after device has been added to bus and
181          * before sysfs has been created.
182          */
183         void (*pcibios_bus_add_device)(struct pci_dev *pdev);
184
185         resource_size_t (*pcibios_default_alignment)(void);
186
187 #ifdef CONFIG_PCI_IOV
188         void (*pcibios_fixup_sriov)(struct pci_dev *pdev);
189         resource_size_t (*pcibios_iov_resource_alignment)(struct pci_dev *, int resno);
190         int (*pcibios_sriov_enable)(struct pci_dev *pdev, u16 num_vfs);
191         int (*pcibios_sriov_disable)(struct pci_dev *pdev);
192 #endif /* CONFIG_PCI_IOV */
193
194         /* Called to shutdown machine specific hardware not already controlled
195          * by other drivers.
196          */
197         void (*machine_shutdown)(void);
198
199 #ifdef CONFIG_KEXEC_CORE
200         void (*kexec_cpu_down)(int crash_shutdown, int secondary);
201
202         /* Called to do what every setup is needed on image and the
203          * reboot code buffer. Returns 0 on success.
204          * Provide your own (maybe dummy) implementation if your platform
205          * claims to support kexec.
206          */
207         int (*machine_kexec_prepare)(struct kimage *image);
208
209         /* Called to perform the _real_ kexec.
210          * Do NOT allocate memory or fail here. We are past the point of
211          * no return.
212          */
213         void (*machine_kexec)(struct kimage *image);
214 #endif /* CONFIG_KEXEC_CORE */
215
216 #ifdef CONFIG_SUSPEND
217         /* These are called to disable and enable, respectively, IRQs when
218          * entering a suspend state.  If NULL, then the generic versions
219          * will be called.  The generic versions disable/enable the
220          * decrementer along with interrupts.
221          */
222         void (*suspend_disable_irqs)(void);
223         void (*suspend_enable_irqs)(void);
224 #endif
225         int (*suspend_disable_cpu)(void);
226
227 #ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
228         ssize_t (*cpu_probe)(const char *, size_t);
229         ssize_t (*cpu_release)(const char *, size_t);
230 #endif
231
232 #ifdef CONFIG_ARCH_RANDOM
233         int (*get_random_seed)(unsigned long *v);
234 #endif
235 };
236
237 extern void e500_idle(void);
238 extern void power4_idle(void);
239 extern void power7_idle(void);
240 extern void power9_idle(void);
241 extern void ppc6xx_idle(void);
242 extern void book3e_idle(void);
243
244 /*
245  * ppc_md contains a copy of the machine description structure for the
246  * current platform. machine_id contains the initial address where the
247  * description was found during boot.
248  */
249 extern struct machdep_calls ppc_md;
250 extern struct machdep_calls *machine_id;
251
252 #define __machine_desc __attribute__ ((__section__ (".machine.desc")))
253
254 #define define_machine(name)                                    \
255         extern struct machdep_calls mach_##name;                \
256         EXPORT_SYMBOL(mach_##name);                             \
257         struct machdep_calls mach_##name __machine_desc =
258
259 #define machine_is(name) \
260         ({ \
261                 extern struct machdep_calls mach_##name \
262                         __attribute__((weak));           \
263                 machine_id == &mach_##name; \
264         })
265
266 extern void probe_machine(void);
267
268 #ifdef CONFIG_PPC_PMAC
269 /*
270  * Power macintoshes have either a CUDA, PMU or SMU controlling
271  * system reset, power, NVRAM, RTC.
272  */
273 typedef enum sys_ctrler_kind {
274         SYS_CTRLER_UNKNOWN = 0,
275         SYS_CTRLER_CUDA = 1,
276         SYS_CTRLER_PMU = 2,
277         SYS_CTRLER_SMU = 3,
278 } sys_ctrler_t;
279 extern sys_ctrler_t sys_ctrler;
280
281 #endif /* CONFIG_PPC_PMAC */
282
283 static inline void log_error(char *buf, unsigned int err_type, int fatal)
284 {
285         if (ppc_md.log_error)
286                 ppc_md.log_error(buf, err_type, fatal);
287 }
288
289 #define __define_machine_initcall(mach, fn, id) \
290         static int __init __machine_initcall_##mach##_##fn(void) { \
291                 if (machine_is(mach)) return fn(); \
292                 return 0; \
293         } \
294         __define_initcall(__machine_initcall_##mach##_##fn, id);
295
296 #define machine_early_initcall(mach, fn)        __define_machine_initcall(mach, fn, early)
297 #define machine_core_initcall(mach, fn)         __define_machine_initcall(mach, fn, 1)
298 #define machine_core_initcall_sync(mach, fn)    __define_machine_initcall(mach, fn, 1s)
299 #define machine_postcore_initcall(mach, fn)     __define_machine_initcall(mach, fn, 2)
300 #define machine_postcore_initcall_sync(mach, fn)        __define_machine_initcall(mach, fn, 2s)
301 #define machine_arch_initcall(mach, fn)         __define_machine_initcall(mach, fn, 3)
302 #define machine_arch_initcall_sync(mach, fn)    __define_machine_initcall(mach, fn, 3s)
303 #define machine_subsys_initcall(mach, fn)       __define_machine_initcall(mach, fn, 4)
304 #define machine_subsys_initcall_sync(mach, fn)  __define_machine_initcall(mach, fn, 4s)
305 #define machine_fs_initcall(mach, fn)           __define_machine_initcall(mach, fn, 5)
306 #define machine_fs_initcall_sync(mach, fn)      __define_machine_initcall(mach, fn, 5s)
307 #define machine_rootfs_initcall(mach, fn)       __define_machine_initcall(mach, fn, rootfs)
308 #define machine_device_initcall(mach, fn)       __define_machine_initcall(mach, fn, 6)
309 #define machine_device_initcall_sync(mach, fn)  __define_machine_initcall(mach, fn, 6s)
310 #define machine_late_initcall(mach, fn)         __define_machine_initcall(mach, fn, 7)
311 #define machine_late_initcall_sync(mach, fn)    __define_machine_initcall(mach, fn, 7s)
312
313 #endif /* __KERNEL__ */
314 #endif /* _ASM_POWERPC_MACHDEP_H */