machdep.h 9.5 KB

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