4 #include <linux/cpumask.h>
5 #include <linux/init.h>
6 #include <asm/percpu.h>
9 * We need the APIC definitions automatically as part of 'smp.h'
11 #ifdef CONFIG_X86_LOCAL_APIC
12 # include <asm/mpspec.h>
13 # include <asm/apic.h>
14 # ifdef CONFIG_X86_IO_APIC
15 # include <asm/io_apic.h>
19 #include <asm/thread_info.h>
23 extern cpumask_var_t cpu_callin_mask
;
24 extern cpumask_var_t cpu_callout_mask
;
25 extern cpumask_var_t cpu_initialized_mask
;
26 extern cpumask_var_t cpu_sibling_setup_mask
;
28 #else /* CONFIG_X86_32 */
30 extern cpumask_t cpu_callin_map
;
31 extern cpumask_t cpu_callout_map
;
32 extern cpumask_t cpu_initialized
;
33 extern cpumask_t cpu_sibling_setup_map
;
35 #define cpu_callin_mask ((struct cpumask *)&cpu_callin_map)
36 #define cpu_callout_mask ((struct cpumask *)&cpu_callout_map)
37 #define cpu_initialized_mask ((struct cpumask *)&cpu_initialized)
38 #define cpu_sibling_setup_mask ((struct cpumask *)&cpu_sibling_setup_map)
40 #endif /* CONFIG_X86_32 */
42 extern void (*mtrr_hook
)(void);
43 extern void zap_low_mappings(void);
45 extern int __cpuinit
get_local_pda(int cpu
);
47 extern int smp_num_siblings
;
48 extern unsigned int num_processors
;
50 DECLARE_PER_CPU(cpumask_t
, cpu_sibling_map
);
51 DECLARE_PER_CPU(cpumask_t
, cpu_core_map
);
52 DECLARE_PER_CPU(u16
, cpu_llc_id
);
54 DECLARE_PER_CPU(int, cpu_number
);
57 static inline struct cpumask
*cpu_sibling_mask(int cpu
)
59 return &per_cpu(cpu_sibling_map
, cpu
);
62 static inline struct cpumask
*cpu_core_mask(int cpu
)
64 return &per_cpu(cpu_core_map
, cpu
);
67 DECLARE_EARLY_PER_CPU(u16
, x86_cpu_to_apicid
);
68 DECLARE_EARLY_PER_CPU(u16
, x86_bios_cpu_apicid
);
70 /* Static state in head.S used to set up a CPU */
77 void (*smp_prepare_boot_cpu
)(void);
78 void (*smp_prepare_cpus
)(unsigned max_cpus
);
79 void (*smp_cpus_done
)(unsigned max_cpus
);
81 void (*smp_send_stop
)(void);
82 void (*smp_send_reschedule
)(int cpu
);
84 int (*cpu_up
)(unsigned cpu
);
85 int (*cpu_disable
)(void);
86 void (*cpu_die
)(unsigned int cpu
);
87 void (*play_dead
)(void);
89 void (*send_call_func_ipi
)(const struct cpumask
*mask
);
90 void (*send_call_func_single_ipi
)(int cpu
);
93 /* Globals due to paravirt */
94 extern void set_cpu_sibling_map(int cpu
);
97 #ifndef CONFIG_PARAVIRT
98 #define startup_ipi_hook(phys_apicid, start_eip, start_esp) do { } while (0)
100 extern struct smp_ops smp_ops
;
102 static inline void smp_send_stop(void)
104 smp_ops
.smp_send_stop();
107 static inline void smp_prepare_boot_cpu(void)
109 smp_ops
.smp_prepare_boot_cpu();
112 static inline void smp_prepare_cpus(unsigned int max_cpus
)
114 smp_ops
.smp_prepare_cpus(max_cpus
);
117 static inline void smp_cpus_done(unsigned int max_cpus
)
119 smp_ops
.smp_cpus_done(max_cpus
);
122 static inline int __cpu_up(unsigned int cpu
)
124 return smp_ops
.cpu_up(cpu
);
127 static inline int __cpu_disable(void)
129 return smp_ops
.cpu_disable();
132 static inline void __cpu_die(unsigned int cpu
)
134 smp_ops
.cpu_die(cpu
);
137 static inline void play_dead(void)
142 static inline void smp_send_reschedule(int cpu
)
144 smp_ops
.smp_send_reschedule(cpu
);
147 static inline void arch_send_call_function_single_ipi(int cpu
)
149 smp_ops
.send_call_func_single_ipi(cpu
);
152 static inline void arch_send_call_function_ipi(cpumask_t mask
)
154 smp_ops
.send_call_func_ipi(&mask
);
157 void cpu_disable_common(void);
158 void native_smp_prepare_boot_cpu(void);
159 void native_smp_prepare_cpus(unsigned int max_cpus
);
160 void native_smp_cpus_done(unsigned int max_cpus
);
161 int native_cpu_up(unsigned int cpunum
);
162 int native_cpu_disable(void);
163 void native_cpu_die(unsigned int cpu
);
164 void native_play_dead(void);
165 void play_dead_common(void);
167 void native_send_call_func_ipi(const struct cpumask
*mask
);
168 void native_send_call_func_single_ipi(int cpu
);
170 extern void prefill_possible_map(void);
172 void smp_store_cpu_info(int id
);
173 #define cpu_physical_id(cpu) per_cpu(x86_cpu_to_apicid, cpu)
175 /* We don't mark CPUs online until __cpu_up(), so we need another measure */
176 static inline int num_booting_cpus(void)
178 return cpumask_weight(cpu_callout_mask
);
181 static inline void prefill_possible_map(void)
184 #endif /* CONFIG_SMP */
186 extern unsigned disabled_cpus __cpuinitdata
;
188 #ifdef CONFIG_X86_32_SMP
190 * This function is needed by all SMP systems. It must _always_ be valid
191 * from the initial startup. We map APIC_BASE very early in page_setup(),
192 * so this is correct in the x86 case.
194 #define raw_smp_processor_id() (x86_read_percpu(cpu_number))
195 extern int safe_smp_processor_id(void);
197 #elif defined(CONFIG_X86_64_SMP)
198 #define raw_smp_processor_id() read_pda(cpunumber)
200 #define stack_smp_processor_id() \
202 struct thread_info *ti; \
203 __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
206 #define safe_smp_processor_id() smp_processor_id()
208 #else /* !CONFIG_X86_32_SMP && !CONFIG_X86_64_SMP */
209 #define cpu_physical_id(cpu) boot_cpu_physical_apicid
210 #define safe_smp_processor_id() 0
211 #define stack_smp_processor_id() 0
214 #ifdef CONFIG_X86_LOCAL_APIC
216 #ifndef CONFIG_X86_64
217 static inline int logical_smp_processor_id(void)
219 /* we don't want to mark this access volatile - bad code generation */
220 return GET_APIC_LOGICAL_ID(*(u32
*)(APIC_BASE
+ APIC_LDR
));
223 #include <mach_apicdef.h>
224 static inline unsigned int read_apic_id(void)
228 reg
= *(u32
*)(APIC_BASE
+ APIC_ID
);
230 return GET_APIC_ID(reg
);
235 # if defined(APIC_DEFINITION) || defined(CONFIG_X86_64)
236 extern int hard_smp_processor_id(void);
238 #include <mach_apicdef.h>
239 static inline int hard_smp_processor_id(void)
241 /* we don't want to mark this access volatile - bad code generation */
242 return read_apic_id();
244 # endif /* APIC_DEFINITION */
246 #else /* CONFIG_X86_LOCAL_APIC */
249 # define hard_smp_processor_id() 0
252 #endif /* CONFIG_X86_LOCAL_APIC */
254 #ifdef CONFIG_X86_HAS_BOOT_CPU_ID
255 extern unsigned char boot_cpu_id
;
257 #define boot_cpu_id 0
260 #endif /* __ASSEMBLY__ */
261 #endif /* _ASM_X86_SMP_H */