smp.h 5.3 KB

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