smp.h 5.2 KB

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