smp.h 5.0 KB

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