smp.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_X86_SMP_H
  3. #define _ASM_X86_SMP_H
  4. #ifndef __ASSEMBLY__
  5. #include <linux/cpumask.h>
  6. #include <asm/percpu.h>
  7. #include <asm/thread_info.h>
  8. #include <asm/cpumask.h>
  9. extern int smp_num_siblings;
  10. extern unsigned int num_processors;
  11. DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_sibling_map);
  12. DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
  13. DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_die_map);
  14. /* cpus sharing the last level cache: */
  15. DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
  16. DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_l2c_shared_map);
  17. DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
  18. DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_l2c_id);
  19. DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
  20. DECLARE_EARLY_PER_CPU_READ_MOSTLY(u16, x86_cpu_to_apicid);
  21. DECLARE_EARLY_PER_CPU_READ_MOSTLY(u32, x86_cpu_to_acpiid);
  22. DECLARE_EARLY_PER_CPU_READ_MOSTLY(u16, x86_bios_cpu_apicid);
  23. #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
  24. DECLARE_EARLY_PER_CPU_READ_MOSTLY(int, x86_cpu_to_logical_apicid);
  25. #endif
  26. struct task_struct;
  27. struct smp_ops {
  28. void (*smp_prepare_boot_cpu)(void);
  29. void (*smp_prepare_cpus)(unsigned max_cpus);
  30. void (*smp_cpus_done)(unsigned max_cpus);
  31. void (*stop_other_cpus)(int wait);
  32. void (*crash_stop_other_cpus)(void);
  33. void (*smp_send_reschedule)(int cpu);
  34. int (*cpu_up)(unsigned cpu, struct task_struct *tidle);
  35. int (*cpu_disable)(void);
  36. void (*cpu_die)(unsigned int cpu);
  37. void (*play_dead)(void);
  38. void (*send_call_func_ipi)(const struct cpumask *mask);
  39. void (*send_call_func_single_ipi)(int cpu);
  40. };
  41. /* Globals due to paravirt */
  42. extern void set_cpu_sibling_map(int cpu);
  43. #ifdef CONFIG_SMP
  44. extern struct smp_ops smp_ops;
  45. static inline void smp_send_stop(void)
  46. {
  47. smp_ops.stop_other_cpus(0);
  48. }
  49. static inline void stop_other_cpus(void)
  50. {
  51. smp_ops.stop_other_cpus(1);
  52. }
  53. static inline void smp_prepare_boot_cpu(void)
  54. {
  55. smp_ops.smp_prepare_boot_cpu();
  56. }
  57. static inline void smp_prepare_cpus(unsigned int max_cpus)
  58. {
  59. smp_ops.smp_prepare_cpus(max_cpus);
  60. }
  61. static inline void smp_cpus_done(unsigned int max_cpus)
  62. {
  63. smp_ops.smp_cpus_done(max_cpus);
  64. }
  65. static inline int __cpu_up(unsigned int cpu, struct task_struct *tidle)
  66. {
  67. return smp_ops.cpu_up(cpu, tidle);
  68. }
  69. static inline int __cpu_disable(void)
  70. {
  71. return smp_ops.cpu_disable();
  72. }
  73. static inline void __cpu_die(unsigned int cpu)
  74. {
  75. smp_ops.cpu_die(cpu);
  76. }
  77. static inline void play_dead(void)
  78. {
  79. smp_ops.play_dead();
  80. }
  81. static inline void smp_send_reschedule(int cpu)
  82. {
  83. smp_ops.smp_send_reschedule(cpu);
  84. }
  85. static inline void arch_send_call_function_single_ipi(int cpu)
  86. {
  87. smp_ops.send_call_func_single_ipi(cpu);
  88. }
  89. static inline void arch_send_call_function_ipi_mask(const struct cpumask *mask)
  90. {
  91. smp_ops.send_call_func_ipi(mask);
  92. }
  93. void cpu_disable_common(void);
  94. void native_smp_prepare_boot_cpu(void);
  95. void smp_prepare_cpus_common(void);
  96. void native_smp_prepare_cpus(unsigned int max_cpus);
  97. void calculate_max_logical_packages(void);
  98. void native_smp_cpus_done(unsigned int max_cpus);
  99. int common_cpu_up(unsigned int cpunum, struct task_struct *tidle);
  100. int native_cpu_up(unsigned int cpunum, struct task_struct *tidle);
  101. int native_cpu_disable(void);
  102. int common_cpu_die(unsigned int cpu);
  103. void native_cpu_die(unsigned int cpu);
  104. void hlt_play_dead(void);
  105. void native_play_dead(void);
  106. void play_dead_common(void);
  107. void wbinvd_on_cpu(int cpu);
  108. int wbinvd_on_all_cpus(void);
  109. void cond_wakeup_cpu0(void);
  110. void smp_kick_mwait_play_dead(void);
  111. void native_smp_send_reschedule(int cpu);
  112. void native_send_call_func_ipi(const struct cpumask *mask);
  113. void native_send_call_func_single_ipi(int cpu);
  114. void x86_idle_thread_init(unsigned int cpu, struct task_struct *idle);
  115. void smp_store_boot_cpu_info(void);
  116. void smp_store_cpu_info(int id);
  117. asmlinkage __visible void smp_reboot_interrupt(void);
  118. __visible void smp_reschedule_interrupt(struct pt_regs *regs);
  119. __visible void smp_call_function_interrupt(struct pt_regs *regs);
  120. __visible void smp_call_function_single_interrupt(struct pt_regs *r);
  121. #define cpu_physical_id(cpu) per_cpu(x86_cpu_to_apicid, cpu)
  122. #define cpu_acpi_id(cpu) per_cpu(x86_cpu_to_acpiid, cpu)
  123. /*
  124. * This function is needed by all SMP systems. It must _always_ be valid
  125. * from the initial startup. We map APIC_BASE very early in page_setup(),
  126. * so this is correct in the x86 case.
  127. */
  128. #define raw_smp_processor_id() this_cpu_read(cpu_number)
  129. #define __smp_processor_id() __this_cpu_read(cpu_number)
  130. #ifdef CONFIG_X86_32
  131. extern int safe_smp_processor_id(void);
  132. #else
  133. # define safe_smp_processor_id() smp_processor_id()
  134. #endif
  135. static inline struct cpumask *cpu_llc_shared_mask(int cpu)
  136. {
  137. return per_cpu(cpu_llc_shared_map, cpu);
  138. }
  139. static inline struct cpumask *cpu_l2c_shared_mask(int cpu)
  140. {
  141. return per_cpu(cpu_l2c_shared_map, cpu);
  142. }
  143. #else /* !CONFIG_SMP */
  144. #define wbinvd_on_cpu(cpu) wbinvd()
  145. static inline int wbinvd_on_all_cpus(void)
  146. {
  147. wbinvd();
  148. return 0;
  149. }
  150. static inline struct cpumask *cpu_llc_shared_mask(int cpu)
  151. {
  152. return (struct cpumask *)cpumask_of(0);
  153. }
  154. #endif /* CONFIG_SMP */
  155. extern unsigned disabled_cpus;
  156. #ifdef CONFIG_X86_LOCAL_APIC
  157. extern int hard_smp_processor_id(void);
  158. #else /* CONFIG_X86_LOCAL_APIC */
  159. #define hard_smp_processor_id() 0
  160. #endif /* CONFIG_X86_LOCAL_APIC */
  161. #ifdef CONFIG_DEBUG_NMI_SELFTEST
  162. extern void nmi_selftest(void);
  163. #else
  164. #define nmi_selftest() do { } while (0)
  165. #endif
  166. #endif /* __ASSEMBLY__ */
  167. #endif /* _ASM_X86_SMP_H */