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 int __cpuinit
get_local_pda(int cpu
);
44 extern int smp_num_siblings
;
45 extern unsigned int num_processors
;
47 DECLARE_PER_CPU(cpumask_t
, cpu_sibling_map
);
48 DECLARE_PER_CPU(cpumask_t
, cpu_core_map
);
49 DECLARE_PER_CPU(u16
, cpu_llc_id
);
51 DECLARE_PER_CPU(int, cpu_number
);
54 static inline struct cpumask
*cpu_sibling_mask(int cpu
)
56 return &per_cpu(cpu_sibling_map
, cpu
);
59 static inline struct cpumask
*cpu_core_mask(int cpu
)
61 return &per_cpu(cpu_core_map
, cpu
);
64 DECLARE_EARLY_PER_CPU(u16
, x86_cpu_to_apicid
);
65 DECLARE_EARLY_PER_CPU(u16
, x86_bios_cpu_apicid
);
67 /* Static state in head.S used to set up a CPU */
74 void (*smp_prepare_boot_cpu
)(void);
75 void (*smp_prepare_cpus
)(unsigned max_cpus
);
76 void (*smp_cpus_done
)(unsigned max_cpus
);
78 void (*smp_send_stop
)(void);
79 void (*smp_send_reschedule
)(int cpu
);
81 int (*cpu_up
)(unsigned cpu
);
82 int (*cpu_disable
)(void);
83 void (*cpu_die
)(unsigned int cpu
);
84 void (*play_dead
)(void);
86 void (*send_call_func_ipi
)(const struct cpumask
*mask
);
87 void (*send_call_func_single_ipi
)(int cpu
);
90 /* Globals due to paravirt */
91 extern void set_cpu_sibling_map(int cpu
);
94 #ifndef CONFIG_PARAVIRT
95 #define startup_ipi_hook(phys_apicid, start_eip, start_esp) do { } while (0)
97 extern struct smp_ops smp_ops
;
99 static inline void smp_send_stop(void)
101 smp_ops
.smp_send_stop();
104 static inline void smp_prepare_boot_cpu(void)
106 smp_ops
.smp_prepare_boot_cpu();
109 static inline void smp_prepare_cpus(unsigned int max_cpus
)
111 smp_ops
.smp_prepare_cpus(max_cpus
);
114 static inline void smp_cpus_done(unsigned int max_cpus
)
116 smp_ops
.smp_cpus_done(max_cpus
);
119 static inline int __cpu_up(unsigned int cpu
)
121 return smp_ops
.cpu_up(cpu
);
124 static inline int __cpu_disable(void)
126 return smp_ops
.cpu_disable();
129 static inline void __cpu_die(unsigned int cpu
)
131 smp_ops
.cpu_die(cpu
);
134 static inline void play_dead(void)
139 static inline void smp_send_reschedule(int cpu
)
141 smp_ops
.smp_send_reschedule(cpu
);
144 static inline void arch_send_call_function_single_ipi(int cpu
)
146 smp_ops
.send_call_func_single_ipi(cpu
);
149 static inline void arch_send_call_function_ipi(cpumask_t mask
)
151 smp_ops
.send_call_func_ipi(&mask
);
154 void cpu_disable_common(void);
155 void native_smp_prepare_boot_cpu(void);
156 void native_smp_prepare_cpus(unsigned int max_cpus
);
157 void native_smp_cpus_done(unsigned int max_cpus
);
158 int native_cpu_up(unsigned int cpunum
);
159 int native_cpu_disable(void);
160 void native_cpu_die(unsigned int cpu
);
161 void native_play_dead(void);
162 void play_dead_common(void);
164 void native_send_call_func_ipi(const struct cpumask
*mask
);
165 void native_send_call_func_single_ipi(int cpu
);
167 void smp_store_cpu_info(int id
);
168 #define cpu_physical_id(cpu) per_cpu(x86_cpu_to_apicid, cpu)
170 /* We don't mark CPUs online until __cpu_up(), so we need another measure */
171 static inline int num_booting_cpus(void)
173 return cpumask_weight(cpu_callout_mask
);
175 #endif /* CONFIG_SMP */
177 extern unsigned disabled_cpus __cpuinitdata
;
179 #ifdef CONFIG_X86_32_SMP
181 * This function is needed by all SMP systems. It must _always_ be valid
182 * from the initial startup. We map APIC_BASE very early in page_setup(),
183 * so this is correct in the x86 case.
185 #define raw_smp_processor_id() (x86_read_percpu(cpu_number))
186 extern int safe_smp_processor_id(void);
188 #elif defined(CONFIG_X86_64_SMP)
189 #define raw_smp_processor_id() read_pda(cpunumber)
191 #define stack_smp_processor_id() \
193 struct thread_info *ti; \
194 __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
197 #define safe_smp_processor_id() smp_processor_id()
201 #ifdef CONFIG_X86_LOCAL_APIC
203 #ifndef CONFIG_X86_64
204 static inline int logical_smp_processor_id(void)
206 /* we don't want to mark this access volatile - bad code generation */
207 return GET_APIC_LOGICAL_ID(*(u32
*)(APIC_BASE
+ APIC_LDR
));
210 #include <mach_apicdef.h>
211 static inline unsigned int read_apic_id(void)
215 reg
= *(u32
*)(APIC_BASE
+ APIC_ID
);
217 return GET_APIC_ID(reg
);
222 # if defined(APIC_DEFINITION) || defined(CONFIG_X86_64)
223 extern int hard_smp_processor_id(void);
225 #include <mach_apicdef.h>
226 static inline int hard_smp_processor_id(void)
228 /* we don't want to mark this access volatile - bad code generation */
229 return read_apic_id();
231 # endif /* APIC_DEFINITION */
233 #else /* CONFIG_X86_LOCAL_APIC */
236 # define hard_smp_processor_id() 0
239 #endif /* CONFIG_X86_LOCAL_APIC */
241 #endif /* __ASSEMBLY__ */
242 #endif /* _ASM_X86_SMP_H */