blob: a3afec5cad0be9576ff2bd1a4a9fcb8ede58cbb7 [file] [log] [blame]
H. Peter Anvin1965aae2008-10-22 22:26:29 -07001#ifndef _ASM_X86_SMP_H
2#define _ASM_X86_SMP_H
Glauber Costac27cfef2008-03-03 14:12:29 -03003#ifndef __ASSEMBLY__
Glauber Costa53ebef42008-03-03 14:12:31 -03004#include <linux/cpumask.h>
Glauber Costa93b016f2008-03-03 14:12:40 -03005#include <linux/init.h>
Glauber de Oliveira Costa7e1efc02008-03-19 14:25:18 -03006#include <asm/percpu.h>
Glauber Costa53ebef42008-03-03 14:12:31 -03007
Glauber Costab23dab02008-03-27 14:06:00 -03008/*
9 * We need the APIC definitions automatically as part of 'smp.h'
10 */
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>
16# endif
17#endif
18#include <asm/pda.h>
19#include <asm/thread_info.h>
Jaswinder Singh Rajputfb8fd072009-01-10 12:20:24 +053020#include <asm/cpumask.h>
Glauber Costab23dab02008-03-27 14:06:00 -030021
Mike Travisc2d1cec2009-01-04 05:18:03 -080022#ifdef CONFIG_X86_64
23
Mike Travisc2d1cec2009-01-04 05:18:03 -080024extern cpumask_var_t cpu_initialized_mask;
25extern cpumask_var_t cpu_sibling_setup_mask;
26
27#else /* CONFIG_X86_32 */
28
Glauber Costa8be9ac82008-03-27 14:06:04 -030029extern cpumask_t cpu_initialized;
Mike Travisc2d1cec2009-01-04 05:18:03 -080030extern cpumask_t cpu_sibling_setup_map;
31
Mike Travisc2d1cec2009-01-04 05:18:03 -080032#define cpu_initialized_mask ((struct cpumask *)&cpu_initialized)
33#define cpu_sibling_setup_mask ((struct cpumask *)&cpu_sibling_setup_map)
34
35#endif /* CONFIG_X86_32 */
Glauber Costa8be9ac82008-03-27 14:06:04 -030036
Jeremy Fitzhardinge7c33b1e2008-07-08 15:06:29 -070037extern int __cpuinit get_local_pda(int cpu);
38
Glauber Costa53ebef42008-03-03 14:12:31 -030039extern int smp_num_siblings;
40extern unsigned int num_processors;
Glauber Costac27cfef2008-03-03 14:12:29 -030041
Glauber de Oliveira Costa7e1efc02008-03-19 14:25:18 -030042DECLARE_PER_CPU(cpumask_t, cpu_sibling_map);
43DECLARE_PER_CPU(cpumask_t, cpu_core_map);
44DECLARE_PER_CPU(u16, cpu_llc_id);
Jaswinder Singhfb261322008-07-21 21:36:40 +053045#ifdef CONFIG_X86_32
46DECLARE_PER_CPU(int, cpu_number);
47#endif
Mike Travis23ca4bb2008-05-12 21:21:12 +020048
Mike Travisc2d1cec2009-01-04 05:18:03 -080049static inline struct cpumask *cpu_sibling_mask(int cpu)
50{
51 return &per_cpu(cpu_sibling_map, cpu);
52}
53
54static inline struct cpumask *cpu_core_mask(int cpu)
55{
56 return &per_cpu(cpu_core_map, cpu);
57}
58
Mike Travis23ca4bb2008-05-12 21:21:12 +020059DECLARE_EARLY_PER_CPU(u16, x86_cpu_to_apicid);
60DECLARE_EARLY_PER_CPU(u16, x86_bios_cpu_apicid);
Glauber de Oliveira Costa7e1efc02008-03-19 14:25:18 -030061
Glauber de Oliveira Costa9d97d0d2008-03-19 14:25:57 -030062/* Static state in head.S used to set up a CPU */
63extern struct {
64 void *sp;
65 unsigned short ss;
66} stack_start;
67
Glauber Costa16694022008-03-03 14:12:32 -030068struct smp_ops {
69 void (*smp_prepare_boot_cpu)(void);
70 void (*smp_prepare_cpus)(unsigned max_cpus);
Glauber Costa16694022008-03-03 14:12:32 -030071 void (*smp_cpus_done)(unsigned max_cpus);
72
73 void (*smp_send_stop)(void);
74 void (*smp_send_reschedule)(int cpu);
Jens Axboe3b16cf82008-06-26 11:21:54 +020075
Alex Nixon93be71b2008-08-22 11:52:11 +010076 int (*cpu_up)(unsigned cpu);
77 int (*cpu_disable)(void);
78 void (*cpu_die)(unsigned int cpu);
79 void (*play_dead)(void);
80
Mike Travisbcda0162008-12-16 17:33:59 -080081 void (*send_call_func_ipi)(const struct cpumask *mask);
Jens Axboe3b16cf82008-06-26 11:21:54 +020082 void (*send_call_func_single_ipi)(int cpu);
Glauber Costa16694022008-03-03 14:12:32 -030083};
84
Glauber Costa14522072008-03-03 14:12:59 -030085/* Globals due to paravirt */
86extern void set_cpu_sibling_map(int cpu);
87
Glauber Costac76cb362008-03-03 14:12:33 -030088#ifdef CONFIG_SMP
Glauber de Oliveira Costad0173ae2008-03-19 14:24:59 -030089#ifndef CONFIG_PARAVIRT
90#define startup_ipi_hook(phys_apicid, start_eip, start_esp) do { } while (0)
91#endif
Glauber Costac76cb362008-03-03 14:12:33 -030092extern struct smp_ops smp_ops;
Glauber Costa86789692008-03-03 14:12:34 -030093
Glauber Costa377d6982008-03-03 14:12:51 -030094static inline void smp_send_stop(void)
95{
96 smp_ops.smp_send_stop();
97}
98
Glauber Costa1e3fac82008-03-03 14:12:37 -030099static inline void smp_prepare_boot_cpu(void)
100{
101 smp_ops.smp_prepare_boot_cpu();
102}
103
Glauber Costa7557da62008-03-03 14:12:38 -0300104static inline void smp_prepare_cpus(unsigned int max_cpus)
105{
106 smp_ops.smp_prepare_cpus(max_cpus);
107}
108
Glauber Costac5597642008-03-03 14:12:39 -0300109static inline void smp_cpus_done(unsigned int max_cpus)
110{
111 smp_ops.smp_cpus_done(max_cpus);
112}
113
Glauber Costa71d19542008-03-03 14:12:36 -0300114static inline int __cpu_up(unsigned int cpu)
115{
116 return smp_ops.cpu_up(cpu);
117}
118
Alex Nixon93be71b2008-08-22 11:52:11 +0100119static inline int __cpu_disable(void)
120{
121 return smp_ops.cpu_disable();
122}
123
124static inline void __cpu_die(unsigned int cpu)
125{
126 smp_ops.cpu_die(cpu);
127}
128
129static inline void play_dead(void)
130{
131 smp_ops.play_dead();
132}
133
Glauber Costa86789692008-03-03 14:12:34 -0300134static inline void smp_send_reschedule(int cpu)
135{
136 smp_ops.smp_send_reschedule(cpu);
137}
Glauber Costa64b1a21e02008-03-03 14:12:35 -0300138
Jens Axboe3b16cf82008-06-26 11:21:54 +0200139static inline void arch_send_call_function_single_ipi(int cpu)
Glauber Costa64b1a21e02008-03-03 14:12:35 -0300140{
Jens Axboe3b16cf82008-06-26 11:21:54 +0200141 smp_ops.send_call_func_single_ipi(cpu);
142}
143
144static inline void arch_send_call_function_ipi(cpumask_t mask)
145{
Mike Travise7986732008-12-16 17:33:52 -0800146 smp_ops.send_call_func_ipi(&mask);
Glauber Costa64b1a21e02008-03-03 14:12:35 -0300147}
Glauber Costa71d19542008-03-03 14:12:36 -0300148
Alex Nixon8227dce2008-08-22 11:52:14 +0100149void cpu_disable_common(void);
Glauber Costa1e3fac82008-03-03 14:12:37 -0300150void native_smp_prepare_boot_cpu(void);
Glauber Costa7557da62008-03-03 14:12:38 -0300151void native_smp_prepare_cpus(unsigned int max_cpus);
Glauber Costac5597642008-03-03 14:12:39 -0300152void native_smp_cpus_done(unsigned int max_cpus);
Glauber Costa71d19542008-03-03 14:12:36 -0300153int native_cpu_up(unsigned int cpunum);
Alex Nixon93be71b2008-08-22 11:52:11 +0100154int native_cpu_disable(void);
155void native_cpu_die(unsigned int cpu);
156void native_play_dead(void);
Alex Nixona21f5d882008-08-22 11:52:13 +0100157void play_dead_common(void);
Alex Nixon93be71b2008-08-22 11:52:11 +0100158
Mike Travisbcda0162008-12-16 17:33:59 -0800159void native_send_call_func_ipi(const struct cpumask *mask);
Jens Axboe3b16cf82008-06-26 11:21:54 +0200160void native_send_call_func_single_ipi(int cpu);
Glauber Costa93b016f2008-03-03 14:12:40 -0300161
Glauber de Oliveira Costa1d89a7f2008-03-19 14:25:05 -0300162void smp_store_cpu_info(int id);
Glauber de Oliveira Costac70dcb72008-03-19 14:25:58 -0300163#define cpu_physical_id(cpu) per_cpu(x86_cpu_to_apicid, cpu)
Glauber Costaa9c057c2008-03-27 14:06:02 -0300164
165/* We don't mark CPUs online until __cpu_up(), so we need another measure */
166static inline int num_booting_cpus(void)
167{
Mike Travisc2d1cec2009-01-04 05:18:03 -0800168 return cpumask_weight(cpu_callout_mask);
Glauber Costaa9c057c2008-03-27 14:06:02 -0300169}
Chuck Ebbert14adf852008-09-29 18:29:42 -0400170#endif /* CONFIG_SMP */
Glauber Costaa9c057c2008-03-27 14:06:02 -0300171
Alexey Starikovskiy2fe60142008-04-04 23:41:44 +0400172extern unsigned disabled_cpus __cpuinitdata;
173
Glauber Costaa9c057c2008-03-27 14:06:02 -0300174#ifdef CONFIG_X86_32_SMP
175/*
176 * This function is needed by all SMP systems. It must _always_ be valid
177 * from the initial startup. We map APIC_BASE very early in page_setup(),
178 * so this is correct in the x86 case.
179 */
Glauber Costaa9c057c2008-03-27 14:06:02 -0300180#define raw_smp_processor_id() (x86_read_percpu(cpu_number))
181extern int safe_smp_processor_id(void);
182
183#elif defined(CONFIG_X86_64_SMP)
184#define raw_smp_processor_id() read_pda(cpunumber)
185
186#define stack_smp_processor_id() \
187({ \
188 struct thread_info *ti; \
189 __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
190 ti->cpu; \
191})
192#define safe_smp_processor_id() smp_processor_id()
193
Glauber Costac76cb362008-03-03 14:12:33 -0300194#endif
Glauber Costa16694022008-03-03 14:12:32 -0300195
Glauber Costa1b000842008-03-27 14:05:58 -0300196#ifdef CONFIG_X86_LOCAL_APIC
197
Suresh Siddha1b374e42008-07-10 11:16:49 -0700198#ifndef CONFIG_X86_64
Glauber Costa1b000842008-03-27 14:05:58 -0300199static inline int logical_smp_processor_id(void)
200{
201 /* we don't want to mark this access volatile - bad code generation */
202 return GET_APIC_LOGICAL_ID(*(u32 *)(APIC_BASE + APIC_LDR));
203}
204
Yinghai Lu4c9961d2008-07-11 18:44:16 -0700205#include <mach_apicdef.h>
Jack Steiner05f2d122008-03-28 14:12:02 -0500206static inline unsigned int read_apic_id(void)
207{
Yinghai Lu4c9961d2008-07-11 18:44:16 -0700208 unsigned int reg;
209
210 reg = *(u32 *)(APIC_BASE + APIC_ID);
211
212 return GET_APIC_ID(reg);
Jack Steiner05f2d122008-03-28 14:12:02 -0500213}
Jack Steinerac23d4e2008-03-28 14:12:16 -0500214#endif
215
Jack Steiner05f2d122008-03-28 14:12:02 -0500216
Suresh Siddha0c81c742008-07-10 11:16:48 -0700217# if defined(APIC_DEFINITION) || defined(CONFIG_X86_64)
Glauber Costa1b000842008-03-27 14:05:58 -0300218extern int hard_smp_processor_id(void);
219# else
Yinghai Lu4c9961d2008-07-11 18:44:16 -0700220#include <mach_apicdef.h>
Glauber Costa1b000842008-03-27 14:05:58 -0300221static inline int hard_smp_processor_id(void)
222{
223 /* we don't want to mark this access volatile - bad code generation */
Yinghai Lu4c9961d2008-07-11 18:44:16 -0700224 return read_apic_id();
Glauber Costa1b000842008-03-27 14:05:58 -0300225}
226# endif /* APIC_DEFINITION */
227
228#else /* CONFIG_X86_LOCAL_APIC */
229
230# ifndef CONFIG_SMP
231# define hard_smp_processor_id() 0
232# endif
233
234#endif /* CONFIG_X86_LOCAL_APIC */
235
Glauber Costac27cfef2008-03-03 14:12:29 -0300236#endif /* __ASSEMBLY__ */
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700237#endif /* _ASM_X86_SMP_H */