/arch/powerpc/include/asm/machdep.h

http://github.com/mirrors/linux · C Header · 300 lines · 173 code · 58 blank · 69 comment · 3 complexity · cc02746f111da8893b469e7d69427afa MD5 · raw file

  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. #ifndef _ASM_POWERPC_MACHDEP_H
  3. #define _ASM_POWERPC_MACHDEP_H
  4. #ifdef __KERNEL__
  5. #include <linux/seq_file.h>
  6. #include <linux/init.h>
  7. #include <linux/dma-mapping.h>
  8. #include <linux/export.h>
  9. #include <asm/setup.h>
  10. /* We export this macro for external modules like Alsa to know if
  11. * ppc_md.feature_call is implemented or not
  12. */
  13. #define CONFIG_PPC_HAS_FEATURE_CALLS
  14. struct pt_regs;
  15. struct pci_bus;
  16. struct device_node;
  17. struct iommu_table;
  18. struct rtc_time;
  19. struct file;
  20. struct pci_controller;
  21. struct kimage;
  22. struct pci_host_bridge;
  23. struct machdep_calls {
  24. char *name;
  25. #ifdef CONFIG_PPC64
  26. #ifdef CONFIG_PM
  27. void (*iommu_save)(void);
  28. void (*iommu_restore)(void);
  29. #endif
  30. #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE
  31. unsigned long (*memory_block_size)(void);
  32. #endif
  33. #endif /* CONFIG_PPC64 */
  34. void (*dma_set_mask)(struct device *dev, u64 dma_mask);
  35. int (*probe)(void);
  36. void (*setup_arch)(void); /* Optional, may be NULL */
  37. /* Optional, may be NULL. */
  38. void (*show_cpuinfo)(struct seq_file *m);
  39. void (*show_percpuinfo)(struct seq_file *m, int i);
  40. /* Returns the current operating frequency of "cpu" in Hz */
  41. unsigned long (*get_proc_freq)(unsigned int cpu);
  42. void (*init_IRQ)(void);
  43. /* Return an irq, or 0 to indicate there are none pending. */
  44. unsigned int (*get_irq)(void);
  45. /* PCI stuff */
  46. /* Called after allocating resources */
  47. void (*pcibios_fixup)(void);
  48. void (*pci_irq_fixup)(struct pci_dev *dev);
  49. int (*pcibios_root_bridge_prepare)(struct pci_host_bridge
  50. *bridge);
  51. /* To setup PHBs when using automatic OF platform driver for PCI */
  52. int (*pci_setup_phb)(struct pci_controller *host);
  53. void __noreturn (*restart)(char *cmd);
  54. void __noreturn (*halt)(void);
  55. void (*panic)(char *str);
  56. void (*cpu_die)(void);
  57. long (*time_init)(void); /* Optional, may be NULL */
  58. int (*set_rtc_time)(struct rtc_time *);
  59. void (*get_rtc_time)(struct rtc_time *);
  60. time64_t (*get_boot_time)(void);
  61. unsigned char (*rtc_read_val)(int addr);
  62. void (*rtc_write_val)(int addr, unsigned char val);
  63. void (*calibrate_decr)(void);
  64. void (*progress)(char *, unsigned short);
  65. /* Interface for platform error logging */
  66. void (*log_error)(char *buf, unsigned int err_type, int fatal);
  67. unsigned char (*nvram_read_val)(int addr);
  68. void (*nvram_write_val)(int addr, unsigned char val);
  69. ssize_t (*nvram_write)(char *buf, size_t count, loff_t *index);
  70. ssize_t (*nvram_read)(char *buf, size_t count, loff_t *index);
  71. ssize_t (*nvram_size)(void);
  72. void (*nvram_sync)(void);
  73. /* Exception handlers */
  74. int (*system_reset_exception)(struct pt_regs *regs);
  75. int (*machine_check_exception)(struct pt_regs *regs);
  76. int (*handle_hmi_exception)(struct pt_regs *regs);
  77. /* Early exception handlers called in realmode */
  78. int (*hmi_exception_early)(struct pt_regs *regs);
  79. long (*machine_check_early)(struct pt_regs *regs);
  80. /* Called during machine check exception to retrive fixup address. */
  81. bool (*mce_check_early_recovery)(struct pt_regs *regs);
  82. /* Motherboard/chipset features. This is a kind of general purpose
  83. * hook used to control some machine specific features (like reset
  84. * lines, chip power control, etc...).
  85. */
  86. long (*feature_call)(unsigned int feature, ...);
  87. /* Get legacy PCI/IDE interrupt mapping */
  88. int (*pci_get_legacy_ide_irq)(struct pci_dev *dev, int channel);
  89. /* Get access protection for /dev/mem */
  90. pgprot_t (*phys_mem_access_prot)(struct file *file,
  91. unsigned long pfn,
  92. unsigned long size,
  93. pgprot_t vma_prot);
  94. /*
  95. * Function for waiting for work with reduced power in idle loop;
  96. * called with interrupts disabled.
  97. */
  98. void (*power_save)(void);
  99. /* Function to enable performance monitor counters for this
  100. platform, called once per cpu. */
  101. void (*enable_pmcs)(void);
  102. /* Set DABR for this platform, leave empty for default implementation */
  103. int (*set_dabr)(unsigned long dabr,
  104. unsigned long dabrx);
  105. /* Set DAWR for this platform, leave empty for default implementation */
  106. int (*set_dawr)(unsigned long dawr,
  107. unsigned long dawrx);
  108. #ifdef CONFIG_PPC32 /* XXX for now */
  109. /* A general init function, called by ppc_init in init/main.c.
  110. May be NULL. */
  111. void (*init)(void);
  112. void (*kgdb_map_scc)(void);
  113. /*
  114. * optional PCI "hooks"
  115. */
  116. /* Called at then very end of pcibios_init() */
  117. void (*pcibios_after_init)(void);
  118. #endif /* CONFIG_PPC32 */
  119. /* Called in indirect_* to avoid touching devices */
  120. int (*pci_exclude_device)(struct pci_controller *, unsigned char, unsigned char);
  121. /* Called after PPC generic resource fixup to perform
  122. machine specific fixups */
  123. void (*pcibios_fixup_resources)(struct pci_dev *);
  124. /* Called for each PCI bus in the system when it's probed */
  125. void (*pcibios_fixup_bus)(struct pci_bus *);
  126. /* Called after scan and before resource survey */
  127. void (*pcibios_fixup_phb)(struct pci_controller *hose);
  128. /*
  129. * Called after device has been added to bus and
  130. * before sysfs has been created.
  131. */
  132. void (*pcibios_bus_add_device)(struct pci_dev *pdev);
  133. resource_size_t (*pcibios_default_alignment)(void);
  134. #ifdef CONFIG_PCI_IOV
  135. void (*pcibios_fixup_sriov)(struct pci_dev *pdev);
  136. resource_size_t (*pcibios_iov_resource_alignment)(struct pci_dev *, int resno);
  137. int (*pcibios_sriov_enable)(struct pci_dev *pdev, u16 num_vfs);
  138. int (*pcibios_sriov_disable)(struct pci_dev *pdev);
  139. #endif /* CONFIG_PCI_IOV */
  140. /* Called to shutdown machine specific hardware not already controlled
  141. * by other drivers.
  142. */
  143. void (*machine_shutdown)(void);
  144. #ifdef CONFIG_KEXEC_CORE
  145. void (*kexec_cpu_down)(int crash_shutdown, int secondary);
  146. /* Called to do what every setup is needed on image and the
  147. * reboot code buffer. Returns 0 on success.
  148. * Provide your own (maybe dummy) implementation if your platform
  149. * claims to support kexec.
  150. */
  151. int (*machine_kexec_prepare)(struct kimage *image);
  152. /* Called to perform the _real_ kexec.
  153. * Do NOT allocate memory or fail here. We are past the point of
  154. * no return.
  155. */
  156. void (*machine_kexec)(struct kimage *image);
  157. #endif /* CONFIG_KEXEC_CORE */
  158. #ifdef CONFIG_SUSPEND
  159. /* These are called to disable and enable, respectively, IRQs when
  160. * entering a suspend state. If NULL, then the generic versions
  161. * will be called. The generic versions disable/enable the
  162. * decrementer along with interrupts.
  163. */
  164. void (*suspend_disable_irqs)(void);
  165. void (*suspend_enable_irqs)(void);
  166. #endif
  167. int (*suspend_disable_cpu)(void);
  168. #ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
  169. ssize_t (*cpu_probe)(const char *, size_t);
  170. ssize_t (*cpu_release)(const char *, size_t);
  171. #endif
  172. #ifdef CONFIG_ARCH_RANDOM
  173. int (*get_random_seed)(unsigned long *v);
  174. #endif
  175. };
  176. extern void e500_idle(void);
  177. extern void power4_idle(void);
  178. extern void power7_idle(void);
  179. extern void power9_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 */