smp.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * smp.h: PowerPC-specific SMP code.
  4. *
  5. * Original was a copy of sparc smp.h. Now heavily modified
  6. * for PPC.
  7. *
  8. * Copyright (C) 1996 David S. Miller ([email protected])
  9. * Copyright (C) 1996-2001 Cort Dougan <[email protected]>
  10. */
  11. #ifndef _ASM_POWERPC_SMP_H
  12. #define _ASM_POWERPC_SMP_H
  13. #ifdef __KERNEL__
  14. #include <linux/threads.h>
  15. #include <linux/cpumask.h>
  16. #include <linux/kernel.h>
  17. #include <linux/irqreturn.h>
  18. #ifndef __ASSEMBLY__
  19. #ifdef CONFIG_PPC64
  20. #include <asm/paca.h>
  21. #endif
  22. #include <asm/percpu.h>
  23. extern int boot_cpuid;
  24. extern int boot_cpu_hwid; /* PPC64 only */
  25. extern int spinning_secondaries;
  26. extern u32 *cpu_to_phys_id;
  27. extern bool coregroup_enabled;
  28. extern int cpu_to_chip_id(int cpu);
  29. extern int *chip_id_lookup_table;
  30. DECLARE_PER_CPU(cpumask_var_t, thread_group_l1_cache_map);
  31. DECLARE_PER_CPU(cpumask_var_t, thread_group_l2_cache_map);
  32. DECLARE_PER_CPU(cpumask_var_t, thread_group_l3_cache_map);
  33. #ifdef CONFIG_SMP
  34. struct smp_ops_t {
  35. void (*message_pass)(int cpu, int msg);
  36. #ifdef CONFIG_PPC_SMP_MUXED_IPI
  37. void (*cause_ipi)(int cpu);
  38. #endif
  39. int (*cause_nmi_ipi)(int cpu);
  40. void (*probe)(void);
  41. int (*kick_cpu)(int nr);
  42. int (*prepare_cpu)(int nr);
  43. void (*setup_cpu)(int nr);
  44. void (*bringup_done)(void);
  45. void (*take_timebase)(void);
  46. void (*give_timebase)(void);
  47. int (*cpu_disable)(void);
  48. void (*cpu_die)(unsigned int nr);
  49. int (*cpu_bootable)(unsigned int nr);
  50. #ifdef CONFIG_HOTPLUG_CPU
  51. void (*cpu_offline_self)(void);
  52. #endif
  53. };
  54. extern struct task_struct *secondary_current;
  55. void start_secondary(void *unused);
  56. extern int smp_send_nmi_ipi(int cpu, void (*fn)(struct pt_regs *), u64 delay_us);
  57. extern int smp_send_safe_nmi_ipi(int cpu, void (*fn)(struct pt_regs *), u64 delay_us);
  58. extern void smp_send_debugger_break(void);
  59. extern void start_secondary_resume(void);
  60. extern void smp_generic_give_timebase(void);
  61. extern void smp_generic_take_timebase(void);
  62. DECLARE_PER_CPU(unsigned int, cpu_pvr);
  63. #ifdef CONFIG_HOTPLUG_CPU
  64. int generic_cpu_disable(void);
  65. void generic_cpu_die(unsigned int cpu);
  66. void generic_set_cpu_dead(unsigned int cpu);
  67. void generic_set_cpu_up(unsigned int cpu);
  68. int generic_check_cpu_restart(unsigned int cpu);
  69. int is_cpu_dead(unsigned int cpu);
  70. #else
  71. #define generic_set_cpu_up(i) do { } while (0)
  72. #endif
  73. #ifdef CONFIG_PPC64
  74. #define raw_smp_processor_id() (local_paca->paca_index)
  75. #define hard_smp_processor_id() (get_paca()->hw_cpu_id)
  76. #else
  77. /* 32-bit */
  78. extern int smp_hw_index[];
  79. #define raw_smp_processor_id() (current_thread_info()->cpu)
  80. #define hard_smp_processor_id() (smp_hw_index[smp_processor_id()])
  81. static inline int get_hard_smp_processor_id(int cpu)
  82. {
  83. return smp_hw_index[cpu];
  84. }
  85. static inline void set_hard_smp_processor_id(int cpu, int phys)
  86. {
  87. smp_hw_index[cpu] = phys;
  88. }
  89. #endif
  90. DECLARE_PER_CPU(cpumask_var_t, cpu_sibling_map);
  91. DECLARE_PER_CPU(cpumask_var_t, cpu_l2_cache_map);
  92. DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
  93. DECLARE_PER_CPU(cpumask_var_t, cpu_smallcore_map);
  94. static inline struct cpumask *cpu_sibling_mask(int cpu)
  95. {
  96. return per_cpu(cpu_sibling_map, cpu);
  97. }
  98. static inline struct cpumask *cpu_core_mask(int cpu)
  99. {
  100. return per_cpu(cpu_core_map, cpu);
  101. }
  102. static inline struct cpumask *cpu_l2_cache_mask(int cpu)
  103. {
  104. return per_cpu(cpu_l2_cache_map, cpu);
  105. }
  106. static inline struct cpumask *cpu_smallcore_mask(int cpu)
  107. {
  108. return per_cpu(cpu_smallcore_map, cpu);
  109. }
  110. extern int cpu_to_core_id(int cpu);
  111. extern bool has_big_cores;
  112. extern bool thread_group_shares_l2;
  113. extern bool thread_group_shares_l3;
  114. #define cpu_smt_mask cpu_smt_mask
  115. #ifdef CONFIG_SCHED_SMT
  116. static inline const struct cpumask *cpu_smt_mask(int cpu)
  117. {
  118. if (has_big_cores)
  119. return per_cpu(cpu_smallcore_map, cpu);
  120. return per_cpu(cpu_sibling_map, cpu);
  121. }
  122. #endif /* CONFIG_SCHED_SMT */
  123. /* Since OpenPIC has only 4 IPIs, we use slightly different message numbers.
  124. *
  125. * Make sure this matches openpic_request_IPIs in open_pic.c, or what shows up
  126. * in /proc/interrupts will be wrong!!! --Troy */
  127. #define PPC_MSG_CALL_FUNCTION 0
  128. #define PPC_MSG_RESCHEDULE 1
  129. #define PPC_MSG_TICK_BROADCAST 2
  130. #define PPC_MSG_NMI_IPI 3
  131. /* This is only used by the powernv kernel */
  132. #define PPC_MSG_RM_HOST_ACTION 4
  133. #define NMI_IPI_ALL_OTHERS -2
  134. #ifdef CONFIG_NMI_IPI
  135. extern int smp_handle_nmi_ipi(struct pt_regs *regs);
  136. #else
  137. static inline int smp_handle_nmi_ipi(struct pt_regs *regs) { return 0; }
  138. #endif
  139. /* for irq controllers that have dedicated ipis per message (4) */
  140. extern int smp_request_message_ipi(int virq, int message);
  141. extern const char *smp_ipi_name[];
  142. /* for irq controllers with only a single ipi */
  143. extern void smp_muxed_ipi_message_pass(int cpu, int msg);
  144. extern void smp_muxed_ipi_set_message(int cpu, int msg);
  145. extern irqreturn_t smp_ipi_demux(void);
  146. extern irqreturn_t smp_ipi_demux_relaxed(void);
  147. void smp_init_pSeries(void);
  148. void smp_init_cell(void);
  149. void smp_setup_cpu_maps(void);
  150. extern int __cpu_disable(void);
  151. extern void __cpu_die(unsigned int cpu);
  152. #else
  153. /* for UP */
  154. #define hard_smp_processor_id() get_hard_smp_processor_id(0)
  155. #define smp_setup_cpu_maps()
  156. #define thread_group_shares_l2 0
  157. #define thread_group_shares_l3 0
  158. static inline const struct cpumask *cpu_sibling_mask(int cpu)
  159. {
  160. return cpumask_of(cpu);
  161. }
  162. static inline const struct cpumask *cpu_smallcore_mask(int cpu)
  163. {
  164. return cpumask_of(cpu);
  165. }
  166. static inline const struct cpumask *cpu_l2_cache_mask(int cpu)
  167. {
  168. return cpumask_of(cpu);
  169. }
  170. #endif /* CONFIG_SMP */
  171. #ifdef CONFIG_PPC64
  172. static inline int get_hard_smp_processor_id(int cpu)
  173. {
  174. return paca_ptrs[cpu]->hw_cpu_id;
  175. }
  176. static inline void set_hard_smp_processor_id(int cpu, int phys)
  177. {
  178. paca_ptrs[cpu]->hw_cpu_id = phys;
  179. }
  180. #else
  181. /* 32-bit */
  182. #ifndef CONFIG_SMP
  183. extern int boot_cpuid_phys;
  184. static inline int get_hard_smp_processor_id(int cpu)
  185. {
  186. return boot_cpuid_phys;
  187. }
  188. static inline void set_hard_smp_processor_id(int cpu, int phys)
  189. {
  190. boot_cpuid_phys = phys;
  191. }
  192. #endif /* !CONFIG_SMP */
  193. #endif /* !CONFIG_PPC64 */
  194. #if defined(CONFIG_PPC64) && (defined(CONFIG_SMP) || defined(CONFIG_KEXEC_CORE))
  195. extern void smp_release_cpus(void);
  196. #else
  197. static inline void smp_release_cpus(void) { }
  198. #endif
  199. extern int smt_enabled_at_boot;
  200. extern void smp_mpic_probe(void);
  201. extern void smp_mpic_setup_cpu(int cpu);
  202. extern int smp_generic_kick_cpu(int nr);
  203. extern int smp_generic_cpu_bootable(unsigned int nr);
  204. extern void smp_generic_give_timebase(void);
  205. extern void smp_generic_take_timebase(void);
  206. extern struct smp_ops_t *smp_ops;
  207. extern void arch_send_call_function_single_ipi(int cpu);
  208. extern void arch_send_call_function_ipi_mask(const struct cpumask *mask);
  209. /* Definitions relative to the secondary CPU spin loop
  210. * and entry point. Not all of them exist on both 32 and
  211. * 64-bit but defining them all here doesn't harm
  212. */
  213. extern void generic_secondary_smp_init(void);
  214. extern unsigned long __secondary_hold_spinloop;
  215. extern unsigned long __secondary_hold_acknowledge;
  216. extern char __secondary_hold;
  217. extern unsigned int booting_thread_hwid;
  218. extern void __early_start(void);
  219. #endif /* __ASSEMBLY__ */
  220. #endif /* __KERNEL__ */
  221. #endif /* _ASM_POWERPC_SMP_H) */