blob: a47de82fb8e2701041a74c575bde8aa54315f1f4 [file] [log] [blame]
Paul Mackerrasb41fc4f2005-10-26 21:53:19 +10001#ifndef _ASM_POWERPC_MACHDEP_H
2#define _ASM_POWERPC_MACHDEP_H
Paul Mackerras143a1de2005-10-19 23:11:21 +10003#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
Paul Mackerras143a1de2005-10-19 23:11:21 +100012#include <linux/seq_file.h>
13#include <linux/init.h>
14#include <linux/dma-mapping.h>
Paul Gortmaker93087942011-07-29 16:19:31 +100015#include <linux/export.h>
Paul Mackerras143a1de2005-10-19 23:11:21 +100016
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
24struct pt_regs;
25struct pci_bus;
26struct device_node;
27struct iommu_table;
28struct rtc_time;
29struct file;
Benjamin Herrenschmidt4c9d2802006-11-11 17:25:08 +110030struct pci_controller;
Michael Ellerman3d1229d2005-11-14 23:35:00 +110031struct kimage;
Kleber Sacilotto de Souzad82fb312013-05-03 12:43:12 +000032struct pci_host_bridge;
Paul Mackerras143a1de2005-10-19 23:11:21 +100033
Paul Mackerras143a1de2005-10-19 23:11:21 +100034struct machdep_calls {
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +110035 char *name;
Paul Mackerras143a1de2005-10-19 23:11:21 +100036#ifdef CONFIG_PPC64
Benjamin Herrenschmidt68a64352006-11-13 09:27:39 +110037 void __iomem * (*ioremap)(phys_addr_t addr, unsigned long size,
Benjamin Herrenschmidt1cdab552009-02-22 16:19:14 +000038 unsigned long flags, void *caller);
Benjamin Herrenschmidt68a64352006-11-13 09:27:39 +110039 void (*iounmap)(volatile void __iomem *token);
Johannes Berg7e115802007-05-03 22:28:32 +100040
41#ifdef CONFIG_PM
42 void (*iommu_save)(void);
43 void (*iommu_restore)(void);
44#endif
Anton Blancharda5d86252014-06-04 17:50:47 +100045#ifdef CONFIG_MEMORY_HOTPLUG_SPARSE
46 unsigned long (*memory_block_size)(void);
47#endif
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +110048#endif /* CONFIG_PPC64 */
Paul Mackerras143a1de2005-10-19 23:11:21 +100049
Milton Miller6a5c7be2011-06-24 09:05:22 +000050 /* Platform set_dma_mask and dma_get_required_mask overrides */
Benjamin Herrenschmidt5b6e9ff2010-08-30 19:23:52 +000051 int (*dma_set_mask)(struct device *dev, u64 dma_mask);
Milton Miller6a5c7be2011-06-24 09:05:22 +000052 u64 (*dma_get_required_mask)(struct device *dev);
Benjamin Herrenschmidt5b6e9ff2010-08-30 19:23:52 +000053
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +110054 int (*probe)(void);
Grant Likely38db7e72007-10-11 04:48:18 +100055 void (*setup_arch)(void); /* Optional, may be NULL */
Paul Mackerras143a1de2005-10-19 23:11:21 +100056 /* Optional, may be NULL. */
Paul Mackerrasd8699e62005-10-20 17:02:01 +100057 void (*show_cpuinfo)(struct seq_file *m);
58 void (*show_percpuinfo)(struct seq_file *m, int i);
Gautham R. Shenoy2299d032014-03-11 17:01:18 +053059 /* Returns the current operating frequency of "cpu" in Hz */
60 unsigned long (*get_proc_freq)(unsigned int cpu);
Paul Mackerras143a1de2005-10-19 23:11:21 +100061
62 void (*init_IRQ)(void);
Michael Ellerman9b647a32009-04-22 15:31:38 +000063
Michael Ellermanef24ba72016-09-06 21:53:24 +100064 /* Return an irq, or 0 to indicate there are none pending. */
Olaf Hering35a84c22006-10-07 22:08:26 +100065 unsigned int (*get_irq)(void);
Paul Mackerras143a1de2005-10-19 23:11:21 +100066
67 /* PCI stuff */
Gavin Shan6ec73342015-02-13 15:16:32 +110068 /* Called after allocating resources */
Paul Mackerras143a1de2005-10-19 23:11:21 +100069 void (*pcibios_fixup)(void);
Benjamin Herrenschmidtf90bb152006-11-11 17:24:51 +110070 void (*pci_irq_fixup)(struct pci_dev *dev);
Kleber Sacilotto de Souzad82fb312013-05-03 12:43:12 +000071 int (*pcibios_root_bridge_prepare)(struct pci_host_bridge
72 *bridge);
Paul Mackerras143a1de2005-10-19 23:11:21 +100073
Benjamin Herrenschmidt4c9d2802006-11-11 17:25:08 +110074 /* To setup PHBs when using automatic OF platform driver for PCI */
75 int (*pci_setup_phb)(struct pci_controller *host);
76
Daniel Axtens95ec77c2016-07-12 10:54:52 +100077 void __noreturn (*restart)(char *cmd);
78 void __noreturn (*halt)(void);
David Gibsonab9dbf72017-12-04 16:27:25 +110079 void (*panic)(char *str);
Paul Mackerras143a1de2005-10-19 23:11:21 +100080 void (*cpu_die)(void);
81
82 long (*time_init)(void); /* Optional, may be NULL */
83
84 int (*set_rtc_time)(struct rtc_time *);
85 void (*get_rtc_time)(struct rtc_time *);
Arnd Bergmann5bfd6432018-04-23 10:36:40 +020086 time64_t (*get_boot_time)(void);
Paul Mackerras143a1de2005-10-19 23:11:21 +100087 unsigned char (*rtc_read_val)(int addr);
88 void (*rtc_write_val)(int addr, unsigned char val);
89
90 void (*calibrate_decr)(void);
91
92 void (*progress)(char *, unsigned short);
93
94 /* Interface for platform error logging */
95 void (*log_error)(char *buf, unsigned int err_type, int fatal);
96
Paul Mackerras35499c02005-10-22 16:02:39 +100097 unsigned char (*nvram_read_val)(int addr);
98 void (*nvram_write_val)(int addr, unsigned char val);
Paul Mackerras143a1de2005-10-19 23:11:21 +100099 ssize_t (*nvram_write)(char *buf, size_t count, loff_t *index);
100 ssize_t (*nvram_read)(char *buf, size_t count, loff_t *index);
101 ssize_t (*nvram_size)(void);
102 void (*nvram_sync)(void);
103
104 /* Exception handlers */
Arnd Bergmannc902be72006-01-04 19:55:53 +0000105 int (*system_reset_exception)(struct pt_regs *regs);
Paul Mackerras143a1de2005-10-19 23:11:21 +1000106 int (*machine_check_exception)(struct pt_regs *regs);
Mahesh Salgaonkar0869b6f2014-07-29 18:40:01 +0530107 int (*handle_hmi_exception)(struct pt_regs *regs);
108
109 /* Early exception handlers called in realmode */
110 int (*hmi_exception_early)(struct pt_regs *regs);
Paul Mackerras143a1de2005-10-19 23:11:21 +1000111
Mahesh Salgaonkar55672ec2013-12-16 10:46:24 +0530112 /* Called during machine check exception to retrive fixup address. */
113 bool (*mce_check_early_recovery)(struct pt_regs *regs);
114
Paul Mackerras143a1de2005-10-19 23:11:21 +1000115 /* Motherboard/chipset features. This is a kind of general purpose
116 * hook used to control some machine specific features (like reset
117 * lines, chip power control, etc...).
118 */
119 long (*feature_call)(unsigned int feature, ...);
120
Paul Mackerras143a1de2005-10-19 23:11:21 +1000121 /* Get legacy PCI/IDE interrupt mapping */
122 int (*pci_get_legacy_ide_irq)(struct pci_dev *dev, int channel);
123
124 /* Get access protection for /dev/mem */
125 pgprot_t (*phys_mem_access_prot)(struct file *file,
Roland Dreier8b150472005-10-28 17:46:18 -0700126 unsigned long pfn,
Paul Mackerras143a1de2005-10-19 23:11:21 +1000127 unsigned long size,
128 pgprot_t vma_prot);
129
Paul Mackerrasa0652fc2006-03-27 15:03:03 +1100130 /*
131 * Function for waiting for work with reduced power in idle loop;
132 * called with interrupts disabled.
133 */
134 void (*power_save)(void);
135
Paul Mackerras143a1de2005-10-19 23:11:21 +1000136 /* Function to enable performance monitor counters for this
137 platform, called once per cpu. */
138 void (*enable_pmcs)(void);
139
Adam Buchbinder446957b2016-02-24 10:51:11 -0800140 /* Set DABR for this platform, leave empty for default implementation */
Michael Neuling4474ef02012-09-06 21:24:56 +0000141 int (*set_dabr)(unsigned long dabr,
142 unsigned long dabrx);
Michael Ellerman76032de2005-11-07 13:12:03 +1100143
Adam Buchbinder446957b2016-02-24 10:51:11 -0800144 /* Set DAWR for this platform, leave empty for default implementation */
Michael Neulingbf99de32012-12-20 14:06:45 +0000145 int (*set_dawr)(unsigned long dawr,
146 unsigned long dawrx);
147
Paul Mackerras143a1de2005-10-19 23:11:21 +1000148#ifdef CONFIG_PPC32 /* XXX for now */
Paul Mackerras143a1de2005-10-19 23:11:21 +1000149 /* A general init function, called by ppc_init in init/main.c.
150 May be NULL. */
151 void (*init)(void);
152
Paul Mackerras143a1de2005-10-19 23:11:21 +1000153 void (*kgdb_map_scc)(void);
154
Paul Mackerras143a1de2005-10-19 23:11:21 +1000155 /*
156 * optional PCI "hooks"
157 */
Paul Mackerras143a1de2005-10-19 23:11:21 +1000158 /* Called at then very end of pcibios_init() */
159 void (*pcibios_after_init)(void);
160
Michael Ellerman3d1229d2005-11-14 23:35:00 +1100161#endif /* CONFIG_PPC32 */
Paul Mackerras143a1de2005-10-19 23:11:21 +1000162
Kumar Gala89c2dd62009-08-25 16:20:45 +0000163 /* Called in indirect_* to avoid touching devices */
164 int (*pci_exclude_device)(struct pci_controller *, unsigned char, unsigned char);
165
Benjamin Herrenschmidtbf5e2ba2007-12-20 14:54:51 +1100166 /* Called after PPC generic resource fixup to perform
167 machine specific fixups */
168 void (*pcibios_fixup_resources)(struct pci_dev *);
169
170 /* Called for each PCI bus in the system when it's probed */
171 void (*pcibios_fixup_bus)(struct pci_bus *);
172
Benjamin Herrenschmidt491b98c2011-11-06 18:55:57 +0000173 /* Called after scan and before resource survey */
174 void (*pcibios_fixup_phb)(struct pci_controller *hose);
175
Bryant G. Ly988fc3b2017-11-09 08:00:33 -0600176 /*
177 * Called after device has been added to bus and
178 * before sysfs has been created.
179 */
180 void (*pcibios_bus_add_device)(struct pci_dev *pdev);
181
Yongji Xie38274632017-04-10 19:58:13 +0800182 resource_size_t (*pcibios_default_alignment)(void);
183
Wei Yang6e628c72015-03-25 16:23:55 +0800184#ifdef CONFIG_PCI_IOV
185 void (*pcibios_fixup_sriov)(struct pci_dev *pdev);
Wei Yang5350ab32015-03-25 16:23:56 +0800186 resource_size_t (*pcibios_iov_resource_alignment)(struct pci_dev *, int resno);
Bryant G. Ly988fc3b2017-11-09 08:00:33 -0600187 int (*pcibios_sriov_enable)(struct pci_dev *pdev, u16 num_vfs);
188 int (*pcibios_sriov_disable)(struct pci_dev *pdev);
Wei Yang6e628c72015-03-25 16:23:55 +0800189#endif /* CONFIG_PCI_IOV */
190
Paul Mackerras143a1de2005-10-19 23:11:21 +1000191 /* Called to shutdown machine specific hardware not already controlled
192 * by other drivers.
Paul Mackerras143a1de2005-10-19 23:11:21 +1000193 */
194 void (*machine_shutdown)(void);
195
Thiago Jung Bauermannda665882016-11-29 23:45:50 +1100196#ifdef CONFIG_KEXEC_CORE
Anton Blanchard50266a12011-01-06 17:54:15 +0000197 void (*kexec_cpu_down)(int crash_shutdown, int secondary);
198
Paul Mackerras143a1de2005-10-19 23:11:21 +1000199 /* Called to do what every setup is needed on image and the
200 * reboot code buffer. Returns 0 on success.
201 * Provide your own (maybe dummy) implementation if your platform
202 * claims to support kexec.
203 */
204 int (*machine_kexec_prepare)(struct kimage *image);
Anton Blanchard357574c2011-02-23 12:46:16 +0000205
206 /* Called to perform the _real_ kexec.
207 * Do NOT allocate memory or fail here. We are past the point of
208 * no return.
209 */
210 void (*machine_kexec)(struct kimage *image);
Thiago Jung Bauermannda665882016-11-29 23:45:50 +1100211#endif /* CONFIG_KEXEC_CORE */
Scott Wood7ac5dde2007-12-13 04:35:19 +1100212
213#ifdef CONFIG_SUSPEND
214 /* These are called to disable and enable, respectively, IRQs when
215 * entering a suspend state. If NULL, then the generic versions
216 * will be called. The generic versions disable/enable the
217 * decrementer along with interrupts.
218 */
219 void (*suspend_disable_irqs)(void);
220 void (*suspend_enable_irqs)(void);
221#endif
Brian King32d8ad42010-07-07 12:31:02 +0000222 int (*suspend_disable_cpu)(void);
Nathan Fontenot12633e82009-11-25 17:23:25 +0000223
224#ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
225 ssize_t (*cpu_probe)(const char *, size_t);
226 ssize_t (*cpu_release)(const char *, size_t);
227#endif
Michael Ellermana4da0d52013-10-11 14:07:57 +1100228
229#ifdef CONFIG_ARCH_RANDOM
Paul Mackerras01c93482015-07-17 20:11:43 +1000230 int (*get_random_seed)(unsigned long *v);
Michael Ellermana4da0d52013-10-11 14:07:57 +1100231#endif
Paul Mackerras143a1de2005-10-19 23:11:21 +1000232};
233
Kumar Galafc4033b2008-06-18 16:26:52 -0500234extern void e500_idle(void);
Paul Mackerrasa0652fc2006-03-27 15:03:03 +1100235extern void power4_idle(void);
Benjamin Herrenschmidt948cf672011-01-24 18:42:41 +1100236extern void power7_idle(void);
Nicholas Piggin2201f992017-06-13 23:05:45 +1000237extern void power9_idle(void);
Paul Mackerrasa0652fc2006-03-27 15:03:03 +1100238extern void ppc6xx_idle(void);
Benjamin Herrenschmidt34d97e02010-07-14 14:12:16 +1000239extern void book3e_idle(void);
Paul Mackerras143a1de2005-10-19 23:11:21 +1000240
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100241/*
242 * ppc_md contains a copy of the machine description structure for the
243 * current platform. machine_id contains the initial address where the
244 * description was found during boot.
245 */
Paul Mackerras143a1de2005-10-19 23:11:21 +1000246extern struct machdep_calls ppc_md;
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100247extern struct machdep_calls *machine_id;
248
249#define __machine_desc __attribute__ ((__section__ (".machine.desc")))
250
Paul Mackerrasd0e15be2006-04-23 10:42:04 +1000251#define define_machine(name) \
252 extern struct machdep_calls mach_##name; \
253 EXPORT_SYMBOL(mach_##name); \
254 struct machdep_calls mach_##name __machine_desc =
255
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100256#define machine_is(name) \
257 ({ \
258 extern struct machdep_calls mach_##name \
259 __attribute__((weak)); \
260 machine_id == &mach_##name; \
261 })
262
263extern void probe_machine(void);
264
Paul Mackerras143a1de2005-10-19 23:11:21 +1000265#ifdef CONFIG_PPC_PMAC
266/*
267 * Power macintoshes have either a CUDA, PMU or SMU controlling
268 * system reset, power, NVRAM, RTC.
269 */
270typedef enum sys_ctrler_kind {
271 SYS_CTRLER_UNKNOWN = 0,
272 SYS_CTRLER_CUDA = 1,
273 SYS_CTRLER_PMU = 2,
274 SYS_CTRLER_SMU = 3,
275} sys_ctrler_t;
276extern sys_ctrler_t sys_ctrler;
277
278#endif /* CONFIG_PPC_PMAC */
279
Paul Mackerras143a1de2005-10-19 23:11:21 +1000280static inline void log_error(char *buf, unsigned int err_type, int fatal)
281{
282 if (ppc_md.log_error)
283 ppc_md.log_error(buf, err_type, fatal);
284}
285
Matthew Leach7929d402012-12-17 15:59:32 -0800286#define __define_machine_initcall(mach, fn, id) \
Grant Likely800d68c2007-12-02 17:10:28 +1100287 static int __init __machine_initcall_##mach##_##fn(void) { \
288 if (machine_is(mach)) return fn(); \
289 return 0; \
290 } \
Matthew Leach7929d402012-12-17 15:59:32 -0800291 __define_initcall(__machine_initcall_##mach##_##fn, id);
Grant Likely800d68c2007-12-02 17:10:28 +1100292
Michael Ellerman8d3c9412014-07-15 22:22:23 +1000293#define machine_early_initcall(mach, fn) __define_machine_initcall(mach, fn, early)
Matthew Leach7929d402012-12-17 15:59:32 -0800294#define machine_core_initcall(mach, fn) __define_machine_initcall(mach, fn, 1)
295#define machine_core_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 1s)
296#define machine_postcore_initcall(mach, fn) __define_machine_initcall(mach, fn, 2)
297#define machine_postcore_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 2s)
298#define machine_arch_initcall(mach, fn) __define_machine_initcall(mach, fn, 3)
299#define machine_arch_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 3s)
300#define machine_subsys_initcall(mach, fn) __define_machine_initcall(mach, fn, 4)
301#define machine_subsys_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 4s)
302#define machine_fs_initcall(mach, fn) __define_machine_initcall(mach, fn, 5)
303#define machine_fs_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 5s)
304#define machine_rootfs_initcall(mach, fn) __define_machine_initcall(mach, fn, rootfs)
305#define machine_device_initcall(mach, fn) __define_machine_initcall(mach, fn, 6)
306#define machine_device_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 6s)
307#define machine_late_initcall(mach, fn) __define_machine_initcall(mach, fn, 7)
308#define machine_late_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 7s)
Grant Likely800d68c2007-12-02 17:10:28 +1100309
Paul Mackerras143a1de2005-10-19 23:11:21 +1000310#endif /* __KERNEL__ */
Paul Mackerrasb41fc4f2005-10-26 21:53:19 +1000311#endif /* _ASM_POWERPC_MACHDEP_H */