blob: 4298ceae6db58e2900f0c268bdbd6b36ea92d9de [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);
Paul Mackerras143a1de2005-10-19 23:11:21 +100079 void (*cpu_die)(void);
80
81 long (*time_init)(void); /* Optional, may be NULL */
82
83 int (*set_rtc_time)(struct rtc_time *);
84 void (*get_rtc_time)(struct rtc_time *);
85 unsigned long (*get_boot_time)(void);
86 unsigned char (*rtc_read_val)(int addr);
87 void (*rtc_write_val)(int addr, unsigned char val);
88
89 void (*calibrate_decr)(void);
90
91 void (*progress)(char *, unsigned short);
92
93 /* Interface for platform error logging */
94 void (*log_error)(char *buf, unsigned int err_type, int fatal);
95
Paul Mackerras35499c02005-10-22 16:02:39 +100096 unsigned char (*nvram_read_val)(int addr);
97 void (*nvram_write_val)(int addr, unsigned char val);
Paul Mackerras143a1de2005-10-19 23:11:21 +100098 ssize_t (*nvram_write)(char *buf, size_t count, loff_t *index);
99 ssize_t (*nvram_read)(char *buf, size_t count, loff_t *index);
100 ssize_t (*nvram_size)(void);
101 void (*nvram_sync)(void);
102
103 /* Exception handlers */
Arnd Bergmannc902be72006-01-04 19:55:53 +0000104 int (*system_reset_exception)(struct pt_regs *regs);
Paul Mackerras143a1de2005-10-19 23:11:21 +1000105 int (*machine_check_exception)(struct pt_regs *regs);
Mahesh Salgaonkar0869b6f2014-07-29 18:40:01 +0530106 int (*handle_hmi_exception)(struct pt_regs *regs);
107
108 /* Early exception handlers called in realmode */
109 int (*hmi_exception_early)(struct pt_regs *regs);
Paul Mackerras143a1de2005-10-19 23:11:21 +1000110
Mahesh Salgaonkar55672ec2013-12-16 10:46:24 +0530111 /* Called during machine check exception to retrive fixup address. */
112 bool (*mce_check_early_recovery)(struct pt_regs *regs);
113
Paul Mackerras143a1de2005-10-19 23:11:21 +1000114 /* Motherboard/chipset features. This is a kind of general purpose
115 * hook used to control some machine specific features (like reset
116 * lines, chip power control, etc...).
117 */
118 long (*feature_call)(unsigned int feature, ...);
119
Paul Mackerras143a1de2005-10-19 23:11:21 +1000120 /* Get legacy PCI/IDE interrupt mapping */
121 int (*pci_get_legacy_ide_irq)(struct pci_dev *dev, int channel);
122
123 /* Get access protection for /dev/mem */
124 pgprot_t (*phys_mem_access_prot)(struct file *file,
Roland Dreier8b150472005-10-28 17:46:18 -0700125 unsigned long pfn,
Paul Mackerras143a1de2005-10-19 23:11:21 +1000126 unsigned long size,
127 pgprot_t vma_prot);
128
Paul Mackerrasa0652fc2006-03-27 15:03:03 +1100129 /*
130 * Function for waiting for work with reduced power in idle loop;
131 * called with interrupts disabled.
132 */
133 void (*power_save)(void);
134
Paul Mackerras143a1de2005-10-19 23:11:21 +1000135 /* Function to enable performance monitor counters for this
136 platform, called once per cpu. */
137 void (*enable_pmcs)(void);
138
Adam Buchbinder446957b2016-02-24 10:51:11 -0800139 /* Set DABR for this platform, leave empty for default implementation */
Michael Neuling4474ef02012-09-06 21:24:56 +0000140 int (*set_dabr)(unsigned long dabr,
141 unsigned long dabrx);
Michael Ellerman76032de2005-11-07 13:12:03 +1100142
Adam Buchbinder446957b2016-02-24 10:51:11 -0800143 /* Set DAWR for this platform, leave empty for default implementation */
Michael Neulingbf99de32012-12-20 14:06:45 +0000144 int (*set_dawr)(unsigned long dawr,
145 unsigned long dawrx);
146
Paul Mackerras143a1de2005-10-19 23:11:21 +1000147#ifdef CONFIG_PPC32 /* XXX for now */
Paul Mackerras143a1de2005-10-19 23:11:21 +1000148 /* A general init function, called by ppc_init in init/main.c.
149 May be NULL. */
150 void (*init)(void);
151
Paul Mackerras143a1de2005-10-19 23:11:21 +1000152 void (*kgdb_map_scc)(void);
153
Paul Mackerras143a1de2005-10-19 23:11:21 +1000154 /*
155 * optional PCI "hooks"
156 */
Paul Mackerras143a1de2005-10-19 23:11:21 +1000157 /* Called at then very end of pcibios_init() */
158 void (*pcibios_after_init)(void);
159
Michael Ellerman3d1229d2005-11-14 23:35:00 +1100160#endif /* CONFIG_PPC32 */
Paul Mackerras143a1de2005-10-19 23:11:21 +1000161
Kumar Gala89c2dd62009-08-25 16:20:45 +0000162 /* Called in indirect_* to avoid touching devices */
163 int (*pci_exclude_device)(struct pci_controller *, unsigned char, unsigned char);
164
Benjamin Herrenschmidtbf5e2ba2007-12-20 14:54:51 +1100165 /* Called after PPC generic resource fixup to perform
166 machine specific fixups */
167 void (*pcibios_fixup_resources)(struct pci_dev *);
168
169 /* Called for each PCI bus in the system when it's probed */
170 void (*pcibios_fixup_bus)(struct pci_bus *);
171
Benjamin Herrenschmidt491b98c2011-11-06 18:55:57 +0000172 /* Called after scan and before resource survey */
173 void (*pcibios_fixup_phb)(struct pci_controller *hose);
174
Bryant G. Ly988fc3b2017-11-09 08:00:33 -0600175 /*
176 * Called after device has been added to bus and
177 * before sysfs has been created.
178 */
179 void (*pcibios_bus_add_device)(struct pci_dev *pdev);
180
Yongji Xie38274632017-04-10 19:58:13 +0800181 resource_size_t (*pcibios_default_alignment)(void);
182
Wei Yang6e628c72015-03-25 16:23:55 +0800183#ifdef CONFIG_PCI_IOV
184 void (*pcibios_fixup_sriov)(struct pci_dev *pdev);
Wei Yang5350ab32015-03-25 16:23:56 +0800185 resource_size_t (*pcibios_iov_resource_alignment)(struct pci_dev *, int resno);
Bryant G. Ly988fc3b2017-11-09 08:00:33 -0600186 int (*pcibios_sriov_enable)(struct pci_dev *pdev, u16 num_vfs);
187 int (*pcibios_sriov_disable)(struct pci_dev *pdev);
Wei Yang6e628c72015-03-25 16:23:55 +0800188#endif /* CONFIG_PCI_IOV */
189
Paul Mackerras143a1de2005-10-19 23:11:21 +1000190 /* Called to shutdown machine specific hardware not already controlled
191 * by other drivers.
Paul Mackerras143a1de2005-10-19 23:11:21 +1000192 */
193 void (*machine_shutdown)(void);
194
Thiago Jung Bauermannda665882016-11-29 23:45:50 +1100195#ifdef CONFIG_KEXEC_CORE
Anton Blanchard50266a12011-01-06 17:54:15 +0000196 void (*kexec_cpu_down)(int crash_shutdown, int secondary);
197
Paul Mackerras143a1de2005-10-19 23:11:21 +1000198 /* Called to do what every setup is needed on image and the
199 * reboot code buffer. Returns 0 on success.
200 * Provide your own (maybe dummy) implementation if your platform
201 * claims to support kexec.
202 */
203 int (*machine_kexec_prepare)(struct kimage *image);
Anton Blanchard357574c2011-02-23 12:46:16 +0000204
205 /* Called to perform the _real_ kexec.
206 * Do NOT allocate memory or fail here. We are past the point of
207 * no return.
208 */
209 void (*machine_kexec)(struct kimage *image);
Thiago Jung Bauermannda665882016-11-29 23:45:50 +1100210#endif /* CONFIG_KEXEC_CORE */
Scott Wood7ac5dde2007-12-13 04:35:19 +1100211
212#ifdef CONFIG_SUSPEND
213 /* These are called to disable and enable, respectively, IRQs when
214 * entering a suspend state. If NULL, then the generic versions
215 * will be called. The generic versions disable/enable the
216 * decrementer along with interrupts.
217 */
218 void (*suspend_disable_irqs)(void);
219 void (*suspend_enable_irqs)(void);
220#endif
Brian King32d8ad42010-07-07 12:31:02 +0000221 int (*suspend_disable_cpu)(void);
Nathan Fontenot12633e82009-11-25 17:23:25 +0000222
223#ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
224 ssize_t (*cpu_probe)(const char *, size_t);
225 ssize_t (*cpu_release)(const char *, size_t);
226#endif
Michael Ellermana4da0d52013-10-11 14:07:57 +1100227
228#ifdef CONFIG_ARCH_RANDOM
Paul Mackerras01c93482015-07-17 20:11:43 +1000229 int (*get_random_seed)(unsigned long *v);
Michael Ellermana4da0d52013-10-11 14:07:57 +1100230#endif
Paul Mackerras143a1de2005-10-19 23:11:21 +1000231};
232
Kumar Galafc4033b2008-06-18 16:26:52 -0500233extern void e500_idle(void);
Paul Mackerrasa0652fc2006-03-27 15:03:03 +1100234extern void power4_idle(void);
Benjamin Herrenschmidt948cf672011-01-24 18:42:41 +1100235extern void power7_idle(void);
Nicholas Piggin2201f992017-06-13 23:05:45 +1000236extern void power9_idle(void);
Paul Mackerrasa0652fc2006-03-27 15:03:03 +1100237extern void ppc6xx_idle(void);
Benjamin Herrenschmidt34d97e02010-07-14 14:12:16 +1000238extern void book3e_idle(void);
Paul Mackerras143a1de2005-10-19 23:11:21 +1000239
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100240/*
241 * ppc_md contains a copy of the machine description structure for the
242 * current platform. machine_id contains the initial address where the
243 * description was found during boot.
244 */
Paul Mackerras143a1de2005-10-19 23:11:21 +1000245extern struct machdep_calls ppc_md;
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100246extern struct machdep_calls *machine_id;
247
248#define __machine_desc __attribute__ ((__section__ (".machine.desc")))
249
Paul Mackerrasd0e15be2006-04-23 10:42:04 +1000250#define define_machine(name) \
251 extern struct machdep_calls mach_##name; \
252 EXPORT_SYMBOL(mach_##name); \
253 struct machdep_calls mach_##name __machine_desc =
254
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100255#define machine_is(name) \
256 ({ \
257 extern struct machdep_calls mach_##name \
258 __attribute__((weak)); \
259 machine_id == &mach_##name; \
260 })
261
262extern void probe_machine(void);
263
Paul Mackerras143a1de2005-10-19 23:11:21 +1000264#ifdef CONFIG_PPC_PMAC
265/*
266 * Power macintoshes have either a CUDA, PMU or SMU controlling
267 * system reset, power, NVRAM, RTC.
268 */
269typedef enum sys_ctrler_kind {
270 SYS_CTRLER_UNKNOWN = 0,
271 SYS_CTRLER_CUDA = 1,
272 SYS_CTRLER_PMU = 2,
273 SYS_CTRLER_SMU = 3,
274} sys_ctrler_t;
275extern sys_ctrler_t sys_ctrler;
276
277#endif /* CONFIG_PPC_PMAC */
278
Paul Mackerras143a1de2005-10-19 23:11:21 +1000279static inline void log_error(char *buf, unsigned int err_type, int fatal)
280{
281 if (ppc_md.log_error)
282 ppc_md.log_error(buf, err_type, fatal);
283}
284
Matthew Leach7929d402012-12-17 15:59:32 -0800285#define __define_machine_initcall(mach, fn, id) \
Grant Likely800d68c2007-12-02 17:10:28 +1100286 static int __init __machine_initcall_##mach##_##fn(void) { \
287 if (machine_is(mach)) return fn(); \
288 return 0; \
289 } \
Matthew Leach7929d402012-12-17 15:59:32 -0800290 __define_initcall(__machine_initcall_##mach##_##fn, id);
Grant Likely800d68c2007-12-02 17:10:28 +1100291
Michael Ellerman8d3c9412014-07-15 22:22:23 +1000292#define machine_early_initcall(mach, fn) __define_machine_initcall(mach, fn, early)
Matthew Leach7929d402012-12-17 15:59:32 -0800293#define machine_core_initcall(mach, fn) __define_machine_initcall(mach, fn, 1)
294#define machine_core_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 1s)
295#define machine_postcore_initcall(mach, fn) __define_machine_initcall(mach, fn, 2)
296#define machine_postcore_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 2s)
297#define machine_arch_initcall(mach, fn) __define_machine_initcall(mach, fn, 3)
298#define machine_arch_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 3s)
299#define machine_subsys_initcall(mach, fn) __define_machine_initcall(mach, fn, 4)
300#define machine_subsys_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 4s)
301#define machine_fs_initcall(mach, fn) __define_machine_initcall(mach, fn, 5)
302#define machine_fs_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 5s)
303#define machine_rootfs_initcall(mach, fn) __define_machine_initcall(mach, fn, rootfs)
304#define machine_device_initcall(mach, fn) __define_machine_initcall(mach, fn, 6)
305#define machine_device_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 6s)
306#define machine_late_initcall(mach, fn) __define_machine_initcall(mach, fn, 7)
307#define machine_late_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 7s)
Grant Likely800d68c2007-12-02 17:10:28 +1100308
Paul Mackerras143a1de2005-10-19 23:11:21 +1000309#endif /* __KERNEL__ */
Paul Mackerrasb41fc4f2005-10-26 21:53:19 +1000310#endif /* _ASM_POWERPC_MACHDEP_H */