machdep.h 11 KB

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