smp.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. #ifndef _ASM_X86_SMP_H
  2. #define _ASM_X86_SMP_H
  3. #ifndef __ASSEMBLY__
  4. #include <linux/cpumask.h>
  5. #include <asm/percpu.h>
  6. /*
  7. * We need the APIC definitions automatically as part of 'smp.h'
  8. */
  9. #ifdef CONFIG_X86_LOCAL_APIC
  10. # include <asm/mpspec.h>
  11. # include <asm/apic.h>
  12. # ifdef CONFIG_X86_IO_APIC
  13. # include <asm/io_apic.h>
  14. # endif
  15. #endif
  16. #include <asm/thread_info.h>
  17. #include <asm/cpumask.h>
  18. extern int smp_num_siblings;
  19. extern unsigned int num_processors;
  20. DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_sibling_map);
  21. DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
  22. /* cpus sharing the last level cache: */
  23. DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
  24. DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
  25. DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
  26. static inline struct cpumask *cpu_llc_shared_mask(int cpu)
  27. {
  28. return per_cpu(cpu_llc_shared_map, cpu);
  29. }
  30. DECLARE_EARLY_PER_CPU_READ_MOSTLY(u16, x86_cpu_to_apicid);
  31. DECLARE_EARLY_PER_CPU_READ_MOSTLY(u32, x86_cpu_to_acpiid);
  32. DECLARE_EARLY_PER_CPU_READ_MOSTLY(u16, x86_bios_cpu_apicid);
  33. #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
  34. DECLARE_EARLY_PER_CPU_READ_MOSTLY(int, x86_cpu_to_logical_apicid);
  35. #endif
  36. struct task_struct;
  37. struct smp_ops {
  38. void (*smp_prepare_boot_cpu)(void);
  39. void (*smp_prepare_cpus)(unsigned max_cpus);
  40. void (*smp_cpus_done)(unsigned max_cpus);
  41. void (*stop_other_cpus)(int wait);
  42. void (*smp_send_reschedule)(int cpu);
  43. int (*cpu_up)(unsigned cpu, struct task_struct *tidle);
  44. int (*cpu_disable)(void);
  45. void (*cpu_die)(unsigned int cpu);
  46. void (*play_dead)(void);
  47. void (*send_call_func_ipi)(const struct cpumask *mask);
  48. void (*send_call_func_single_ipi)(int cpu);
  49. };
  50. /* Globals due to paravirt */
  51. extern void set_cpu_sibling_map(int cpu);
  52. #ifdef CONFIG_SMP
  53. extern struct smp_ops smp_ops;
  54. static inline void smp_send_stop(void)
  55. {
  56. smp_ops.stop_other_cpus(0);
  57. }
  58. static inline void stop_other_cpus(void)
  59. {
  60. smp_ops.stop_other_cpus(1);
  61. }
  62. static inline void smp_prepare_boot_cpu(void)
  63. {
  64. smp_ops.smp_prepare_boot_cpu();
  65. }
  66. static inline void smp_prepare_cpus(unsigned int max_cpus)
  67. {
  68. smp_ops.smp_prepare_cpus(max_cpus);
  69. }
  70. static inline void smp_cpus_done(unsigned int max_cpus)
  71. {
  72. smp_ops.smp_cpus_done(max_cpus);
  73. }
  74. static inline int __cpu_up(unsigned int cpu, struct task_struct *tidle)
  75. {
  76. return smp_ops.cpu_up(cpu, tidle);
  77. }
  78. static inline int __cpu_disable(void)
  79. {
  80. return smp_ops.cpu_disable();
  81. }
  82. static inline void __cpu_die(unsigned int cpu)
  83. {
  84. smp_ops.cpu_die(cpu);
  85. }
  86. static inline void play_dead(void)
  87. {
  88. smp_ops.play_dead();
  89. }
  90. static inline void smp_send_reschedule(int cpu)
  91. {
  92. smp_ops.smp_send_reschedule(cpu);
  93. }
  94. static inline void arch_send_call_function_single_ipi(int cpu)
  95. {
  96. smp_ops.send_call_func_single_ipi(cpu);
  97. }
  98. static inline void arch_send_call_function_ipi_mask(const struct cpumask *mask)
  99. {
  100. smp_ops.send_call_func_ipi(mask);
  101. }
  102. void cpu_disable_common(void);
  103. void native_smp_prepare_boot_cpu(void);
  104. void native_smp_prepare_cpus(unsigned int max_cpus);
  105. void native_smp_cpus_done(unsigned int max_cpus);
  106. void common_cpu_up(unsigned int cpunum, struct task_struct *tidle);
  107. int native_cpu_up(unsigned int cpunum, struct task_struct *tidle);
  108. int native_cpu_disable(void);
  109. int common_cpu_die(unsigned int cpu);
  110. void native_cpu_die(unsigned int cpu);
  111. void hlt_play_dead(void);
  112. void native_play_dead(void);
  113. void play_dead_common(void);
  114. void wbinvd_on_cpu(int cpu);
  115. int wbinvd_on_all_cpus(void);
  116. void native_send_call_func_ipi(const struct cpumask *mask);
  117. void native_send_call_func_single_ipi(int cpu);
  118. void x86_idle_thread_init(unsigned int cpu, struct task_struct *idle);
  119. void smp_store_boot_cpu_info(void);
  120. void smp_store_cpu_info(int id);
  121. #define cpu_physical_id(cpu) per_cpu(x86_cpu_to_apicid, cpu)
  122. #define cpu_acpi_id(cpu) per_cpu(x86_cpu_to_acpiid, cpu)
  123. #else /* !CONFIG_SMP */
  124. #define wbinvd_on_cpu(cpu) wbinvd()
  125. static inline int wbinvd_on_all_cpus(void)
  126. {
  127. wbinvd();
  128. return 0;
  129. }
  130. #define smp_num_siblings 1
  131. #endif /* CONFIG_SMP */
  132. extern unsigned disabled_cpus;
  133. #ifdef CONFIG_X86_32_SMP
  134. /*
  135. * This function is needed by all SMP systems. It must _always_ be valid
  136. * from the initial startup. We map APIC_BASE very early in page_setup(),
  137. * so this is correct in the x86 case.
  138. */
  139. #define raw_smp_processor_id() (this_cpu_read(cpu_number))
  140. extern int safe_smp_processor_id(void);
  141. #elif defined(CONFIG_X86_64_SMP)
  142. #define raw_smp_processor_id() (this_cpu_read(cpu_number))
  143. #define safe_smp_processor_id() smp_processor_id()
  144. #endif
  145. #ifdef CONFIG_X86_LOCAL_APIC
  146. #ifndef CONFIG_X86_64
  147. static inline int logical_smp_processor_id(void)
  148. {
  149. /* we don't want to mark this access volatile - bad code generation */
  150. return GET_APIC_LOGICAL_ID(apic_read(APIC_LDR));
  151. }
  152. #endif
  153. extern int hard_smp_processor_id(void);
  154. #else /* CONFIG_X86_LOCAL_APIC */
  155. # ifndef CONFIG_SMP
  156. # define hard_smp_processor_id() 0
  157. # endif
  158. #endif /* CONFIG_X86_LOCAL_APIC */
  159. #ifdef CONFIG_DEBUG_NMI_SELFTEST
  160. extern void nmi_selftest(void);
  161. #else
  162. #define nmi_selftest() do { } while (0)
  163. #endif
  164. #endif /* __ASSEMBLY__ */
  165. #endif /* _ASM_X86_SMP_H */