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