smp.h 5.3 KB

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