smp.h 4.8 KB

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