machdep.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. struct pt_regs;
  10. struct pci_bus;
  11. struct device_node;
  12. struct iommu_table;
  13. struct rtc_time;
  14. struct file;
  15. struct pci_controller;
  16. struct kimage;
  17. struct pci_host_bridge;
  18. struct machdep_calls {
  19. char *name;
  20. #ifdef CONFIG_PPC64
  21. #ifdef CONFIG_PM
  22. void (*iommu_restore)(void);
  23. #endif
  24. #ifdef CONFIG_MEMORY_HOTPLUG
  25. unsigned long (*memory_block_size)(void);
  26. #endif
  27. #endif /* CONFIG_PPC64 */
  28. void (*dma_set_mask)(struct device *dev, u64 dma_mask);
  29. int (*probe)(void);
  30. void (*setup_arch)(void); /* Optional, may be NULL */
  31. /* Optional, may be NULL. */
  32. void (*show_cpuinfo)(struct seq_file *m);
  33. /* Returns the current operating frequency of "cpu" in Hz */
  34. unsigned long (*get_proc_freq)(unsigned int cpu);
  35. void (*init_IRQ)(void);
  36. /* Return an irq, or 0 to indicate there are none pending. */
  37. unsigned int (*get_irq)(void);
  38. /* PCI stuff */
  39. /* Called after allocating resources */
  40. void (*pcibios_fixup)(void);
  41. void (*pci_irq_fixup)(struct pci_dev *dev);
  42. int (*pcibios_root_bridge_prepare)(struct pci_host_bridge
  43. *bridge);
  44. /* finds all the pci_controllers present at boot */
  45. void (*discover_phbs)(void);
  46. /* To setup PHBs when using automatic OF platform driver for PCI */
  47. int (*pci_setup_phb)(struct pci_controller *host);
  48. void __noreturn (*restart)(char *cmd);
  49. void __noreturn (*halt)(void);
  50. void (*panic)(char *str);
  51. long (*time_init)(void); /* Optional, may be NULL */
  52. int (*set_rtc_time)(struct rtc_time *);
  53. void (*get_rtc_time)(struct rtc_time *);
  54. time64_t (*get_boot_time)(void);
  55. void (*calibrate_decr)(void);
  56. void (*progress)(char *, unsigned short);
  57. /* Interface for platform error logging */
  58. void (*log_error)(char *buf, unsigned int err_type, int fatal);
  59. unsigned char (*nvram_read_val)(int addr);
  60. void (*nvram_write_val)(int addr, unsigned char val);
  61. ssize_t (*nvram_write)(char *buf, size_t count, loff_t *index);
  62. ssize_t (*nvram_read)(char *buf, size_t count, loff_t *index);
  63. ssize_t (*nvram_size)(void);
  64. void (*nvram_sync)(void);
  65. /* Exception handlers */
  66. int (*system_reset_exception)(struct pt_regs *regs);
  67. int (*machine_check_exception)(struct pt_regs *regs);
  68. int (*handle_hmi_exception)(struct pt_regs *regs);
  69. /* Early exception handlers called in realmode */
  70. int (*hmi_exception_early)(struct pt_regs *regs);
  71. long (*machine_check_early)(struct pt_regs *regs);
  72. /* Called during machine check exception to retrive fixup address. */
  73. bool (*mce_check_early_recovery)(struct pt_regs *regs);
  74. void (*machine_check_log_err)(void);
  75. /* Motherboard/chipset features. This is a kind of general purpose
  76. * hook used to control some machine specific features (like reset
  77. * lines, chip power control, etc...).
  78. */
  79. long (*feature_call)(unsigned int feature, ...);
  80. /* Get legacy PCI/IDE interrupt mapping */
  81. int (*pci_get_legacy_ide_irq)(struct pci_dev *dev, int channel);
  82. /* Get access protection for /dev/mem */
  83. pgprot_t (*phys_mem_access_prot)(struct file *file,
  84. unsigned long pfn,
  85. unsigned long size,
  86. pgprot_t vma_prot);
  87. /*
  88. * Function for waiting for work with reduced power in idle loop;
  89. * called with interrupts disabled.
  90. */
  91. void (*power_save)(void);
  92. /* Function to enable performance monitor counters for this
  93. platform, called once per cpu. */
  94. void (*enable_pmcs)(void);
  95. /* Set DABR for this platform, leave empty for default implementation */
  96. int (*set_dabr)(unsigned long dabr,
  97. unsigned long dabrx);
  98. /* Set DAWR for this platform, leave empty for default implementation */
  99. int (*set_dawr)(int nr, unsigned long dawr,
  100. unsigned long dawrx);
  101. #ifdef CONFIG_PPC32 /* XXX for now */
  102. /* A general init function, called by ppc_init in init/main.c.
  103. May be NULL. */
  104. void (*init)(void);
  105. /*
  106. * optional PCI "hooks"
  107. */
  108. /* Called at then very end of pcibios_init() */
  109. void (*pcibios_after_init)(void);
  110. #endif /* CONFIG_PPC32 */
  111. /* Called in indirect_* to avoid touching devices */
  112. int (*pci_exclude_device)(struct pci_controller *, unsigned char, unsigned char);
  113. /* Called after PPC generic resource fixup to perform
  114. machine specific fixups */
  115. void (*pcibios_fixup_resources)(struct pci_dev *);
  116. /* Called for each PCI bus in the system when it's probed */
  117. void (*pcibios_fixup_bus)(struct pci_bus *);
  118. /* Called after scan and before resource survey */
  119. void (*pcibios_fixup_phb)(struct pci_controller *hose);
  120. /*
  121. * Called after device has been added to bus and
  122. * before sysfs has been created.
  123. */
  124. void (*pcibios_bus_add_device)(struct pci_dev *pdev);
  125. resource_size_t (*pcibios_default_alignment)(void);
  126. #ifdef CONFIG_PCI_IOV
  127. void (*pcibios_fixup_sriov)(struct pci_dev *pdev);
  128. resource_size_t (*pcibios_iov_resource_alignment)(struct pci_dev *, int resno);
  129. int (*pcibios_sriov_enable)(struct pci_dev *pdev, u16 num_vfs);
  130. int (*pcibios_sriov_disable)(struct pci_dev *pdev);
  131. #endif /* CONFIG_PCI_IOV */
  132. /* Called to shutdown machine specific hardware not already controlled
  133. * by other drivers.
  134. */
  135. void (*machine_shutdown)(void);
  136. #ifdef CONFIG_KEXEC_CORE
  137. void (*kexec_cpu_down)(int crash_shutdown, int secondary);
  138. /* Called to perform the _real_ kexec.
  139. * Do NOT allocate memory or fail here. We are past the point of
  140. * no return.
  141. */
  142. void (*machine_kexec)(struct kimage *image);
  143. #endif /* CONFIG_KEXEC_CORE */
  144. #ifdef CONFIG_SUSPEND
  145. /* These are called to disable and enable, respectively, IRQs when
  146. * entering a suspend state. If NULL, then the generic versions
  147. * will be called. The generic versions disable/enable the
  148. * decrementer along with interrupts.
  149. */
  150. void (*suspend_disable_irqs)(void);
  151. void (*suspend_enable_irqs)(void);
  152. #endif
  153. #ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
  154. ssize_t (*cpu_probe)(const char *, size_t);
  155. ssize_t (*cpu_release)(const char *, size_t);
  156. #endif
  157. int (*get_random_seed)(unsigned long *v);
  158. };
  159. extern void e500_idle(void);
  160. extern void power4_idle(void);
  161. extern void ppc6xx_idle(void);
  162. /*
  163. * ppc_md contains a copy of the machine description structure for the
  164. * current platform. machine_id contains the initial address where the
  165. * description was found during boot.
  166. */
  167. extern struct machdep_calls ppc_md;
  168. extern struct machdep_calls *machine_id;
  169. #define __machine_desc __section(".machine.desc")
  170. #define define_machine(name) \
  171. extern struct machdep_calls mach_##name; \
  172. EXPORT_SYMBOL(mach_##name); \
  173. struct machdep_calls mach_##name __machine_desc =
  174. #define machine_is(name) \
  175. ({ \
  176. extern struct machdep_calls mach_##name \
  177. __attribute__((weak)); \
  178. machine_id == &mach_##name; \
  179. })
  180. static inline void log_error(char *buf, unsigned int err_type, int fatal)
  181. {
  182. if (ppc_md.log_error)
  183. ppc_md.log_error(buf, err_type, fatal);
  184. }
  185. #define __define_machine_initcall(mach, fn, id) \
  186. static int __init __machine_initcall_##mach##_##fn(void) { \
  187. if (machine_is(mach)) return fn(); \
  188. return 0; \
  189. } \
  190. __define_initcall(__machine_initcall_##mach##_##fn, id);
  191. #define machine_early_initcall(mach, fn) __define_machine_initcall(mach, fn, early)
  192. #define machine_core_initcall(mach, fn) __define_machine_initcall(mach, fn, 1)
  193. #define machine_core_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 1s)
  194. #define machine_postcore_initcall(mach, fn) __define_machine_initcall(mach, fn, 2)
  195. #define machine_postcore_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 2s)
  196. #define machine_arch_initcall(mach, fn) __define_machine_initcall(mach, fn, 3)
  197. #define machine_arch_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 3s)
  198. #define machine_subsys_initcall(mach, fn) __define_machine_initcall(mach, fn, 4)
  199. #define machine_subsys_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 4s)
  200. #define machine_fs_initcall(mach, fn) __define_machine_initcall(mach, fn, 5)
  201. #define machine_fs_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 5s)
  202. #define machine_rootfs_initcall(mach, fn) __define_machine_initcall(mach, fn, rootfs)
  203. #define machine_device_initcall(mach, fn) __define_machine_initcall(mach, fn, 6)
  204. #define machine_device_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 6s)
  205. #define machine_late_initcall(mach, fn) __define_machine_initcall(mach, fn, 7)
  206. #define machine_late_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 7s)
  207. #endif /* __KERNEL__ */
  208. #endif /* _ASM_POWERPC_MACHDEP_H */