smp.h 4.8 KB

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