smp.h 5.0 KB

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