smp.h 6.0 KB

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