smp.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. #ifndef _ASM_X86_SMP_H
  2. #define _ASM_X86_SMP_H
  3. #ifndef __ASSEMBLY__
  4. #include <linux/cpumask.h>
  5. #include <linux/init.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. #include <asm/cpufeature.h>
  20. extern int smp_num_siblings;
  21. extern unsigned int num_processors;
  22. static inline bool cpu_has_ht_siblings(void)
  23. {
  24. bool has_siblings = false;
  25. #ifdef CONFIG_SMP
  26. has_siblings = cpu_has_ht && smp_num_siblings > 1;
  27. #endif
  28. return has_siblings;
  29. }
  30. DECLARE_PER_CPU(cpumask_var_t, cpu_sibling_map);
  31. DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
  32. DECLARE_PER_CPU(u16, cpu_llc_id);
  33. DECLARE_PER_CPU(int, cpu_number);
  34. static inline struct cpumask *cpu_sibling_mask(int cpu)
  35. {
  36. return per_cpu(cpu_sibling_map, cpu);
  37. }
  38. static inline struct cpumask *cpu_core_mask(int cpu)
  39. {
  40. return per_cpu(cpu_core_map, cpu);
  41. }
  42. DECLARE_EARLY_PER_CPU(u16, x86_cpu_to_apicid);
  43. DECLARE_EARLY_PER_CPU(u16, x86_bios_cpu_apicid);
  44. /* Static state in head.S used to set up a CPU */
  45. extern unsigned long stack_start; /* Initial stack pointer address */
  46. struct smp_ops {
  47. void (*smp_prepare_boot_cpu)(void);
  48. void (*smp_prepare_cpus)(unsigned max_cpus);
  49. void (*smp_cpus_done)(unsigned max_cpus);
  50. void (*stop_other_cpus)(int wait);
  51. void (*smp_send_reschedule)(int cpu);
  52. int (*cpu_up)(unsigned cpu);
  53. int (*cpu_disable)(void);
  54. void (*cpu_die)(unsigned int cpu);
  55. void (*play_dead)(void);
  56. void (*send_call_func_ipi)(const struct cpumask *mask);
  57. void (*send_call_func_single_ipi)(int cpu);
  58. };
  59. /* Globals due to paravirt */
  60. extern void set_cpu_sibling_map(int cpu);
  61. #ifdef CONFIG_SMP
  62. #ifndef CONFIG_PARAVIRT
  63. #define startup_ipi_hook(phys_apicid, start_eip, start_esp) do { } while (0)
  64. #endif
  65. extern struct smp_ops smp_ops;
  66. static inline void smp_send_stop(void)
  67. {
  68. smp_ops.stop_other_cpus(0);
  69. }
  70. static inline void stop_other_cpus(void)
  71. {
  72. smp_ops.stop_other_cpus(1);
  73. }
  74. static inline void smp_prepare_boot_cpu(void)
  75. {
  76. smp_ops.smp_prepare_boot_cpu();
  77. }
  78. static inline void smp_prepare_cpus(unsigned int max_cpus)
  79. {
  80. smp_ops.smp_prepare_cpus(max_cpus);
  81. }
  82. static inline void smp_cpus_done(unsigned int max_cpus)
  83. {
  84. smp_ops.smp_cpus_done(max_cpus);
  85. }
  86. static inline int __cpu_up(unsigned int cpu)
  87. {
  88. return smp_ops.cpu_up(cpu);
  89. }
  90. static inline int __cpu_disable(void)
  91. {
  92. return smp_ops.cpu_disable();
  93. }
  94. static inline void __cpu_die(unsigned int cpu)
  95. {
  96. smp_ops.cpu_die(cpu);
  97. }
  98. static inline void play_dead(void)
  99. {
  100. smp_ops.play_dead();
  101. }
  102. static inline void smp_send_reschedule(int cpu)
  103. {
  104. smp_ops.smp_send_reschedule(cpu);
  105. }
  106. static inline void arch_send_call_function_single_ipi(int cpu)
  107. {
  108. smp_ops.send_call_func_single_ipi(cpu);
  109. }
  110. static inline void arch_send_call_function_ipi_mask(const struct cpumask *mask)
  111. {
  112. smp_ops.send_call_func_ipi(mask);
  113. }
  114. void cpu_disable_common(void);
  115. void native_smp_prepare_boot_cpu(void);
  116. void native_smp_prepare_cpus(unsigned int max_cpus);
  117. void native_smp_cpus_done(unsigned int max_cpus);
  118. int native_cpu_up(unsigned int cpunum);
  119. int native_cpu_disable(void);
  120. void native_cpu_die(unsigned int cpu);
  121. void native_play_dead(void);
  122. void play_dead_common(void);
  123. void wbinvd_on_cpu(int cpu);
  124. int wbinvd_on_all_cpus(void);
  125. void native_send_call_func_ipi(const struct cpumask *mask);
  126. void native_send_call_func_single_ipi(int cpu);
  127. void smp_store_cpu_info(int id);
  128. #define cpu_physical_id(cpu) per_cpu(x86_cpu_to_apicid, cpu)
  129. /* We don't mark CPUs online until __cpu_up(), so we need another measure */
  130. static inline int num_booting_cpus(void)
  131. {
  132. return cpumask_weight(cpu_callout_mask);
  133. }
  134. #else /* !CONFIG_SMP */
  135. #define wbinvd_on_cpu(cpu) wbinvd()
  136. static inline int wbinvd_on_all_cpus(void)
  137. {
  138. wbinvd();
  139. return 0;
  140. }
  141. #endif /* CONFIG_SMP */
  142. extern unsigned disabled_cpus __cpuinitdata;
  143. #ifdef CONFIG_X86_32_SMP
  144. /*
  145. * This function is needed by all SMP systems. It must _always_ be valid
  146. * from the initial startup. We map APIC_BASE very early in page_setup(),
  147. * so this is correct in the x86 case.
  148. */
  149. #define raw_smp_processor_id() (percpu_read(cpu_number))
  150. extern int safe_smp_processor_id(void);
  151. #elif defined(CONFIG_X86_64_SMP)
  152. #define raw_smp_processor_id() (percpu_read(cpu_number))
  153. #define stack_smp_processor_id() \
  154. ({ \
  155. struct thread_info *ti; \
  156. __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
  157. ti->cpu; \
  158. })
  159. #define safe_smp_processor_id() smp_processor_id()
  160. #endif
  161. #ifdef CONFIG_X86_LOCAL_APIC
  162. #ifndef CONFIG_X86_64
  163. static inline int logical_smp_processor_id(void)
  164. {
  165. /* we don't want to mark this access volatile - bad code generation */
  166. return GET_APIC_LOGICAL_ID(apic_read(APIC_LDR));
  167. }
  168. #endif
  169. extern int hard_smp_processor_id(void);
  170. #else /* CONFIG_X86_LOCAL_APIC */
  171. # ifndef CONFIG_SMP
  172. # define hard_smp_processor_id() 0
  173. # endif
  174. #endif /* CONFIG_X86_LOCAL_APIC */
  175. #endif /* __ASSEMBLY__ */
  176. #endif /* _ASM_X86_SMP_H */