]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/x86/include/asm/smp.h
Merge branch 'linus' into x86/cleanups
[linux-2.6-omap-h63xx.git] / arch / x86 / include / asm / smp.h
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 /*
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>
20
21 #ifdef CONFIG_X86_64
22
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;
27
28 #else /* CONFIG_X86_32 */
29
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;
34
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)
39
40 #endif /* CONFIG_X86_32 */
41
42 extern int __cpuinit get_local_pda(int cpu);
43
44 extern int smp_num_siblings;
45 extern unsigned int num_processors;
46
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);
50 #ifdef CONFIG_X86_32
51 DECLARE_PER_CPU(int, cpu_number);
52 #endif
53
54 static inline struct cpumask *cpu_sibling_mask(int cpu)
55 {
56         return &per_cpu(cpu_sibling_map, cpu);
57 }
58
59 static inline struct cpumask *cpu_core_mask(int cpu)
60 {
61         return &per_cpu(cpu_core_map, cpu);
62 }
63
64 DECLARE_EARLY_PER_CPU(u16, x86_cpu_to_apicid);
65 DECLARE_EARLY_PER_CPU(u16, x86_bios_cpu_apicid);
66
67 /* Static state in head.S used to set up a CPU */
68 extern struct {
69         void *sp;
70         unsigned short ss;
71 } stack_start;
72
73 struct smp_ops {
74         void (*smp_prepare_boot_cpu)(void);
75         void (*smp_prepare_cpus)(unsigned max_cpus);
76         void (*smp_cpus_done)(unsigned max_cpus);
77
78         void (*smp_send_stop)(void);
79         void (*smp_send_reschedule)(int cpu);
80
81         int (*cpu_up)(unsigned cpu);
82         int (*cpu_disable)(void);
83         void (*cpu_die)(unsigned int cpu);
84         void (*play_dead)(void);
85
86         void (*send_call_func_ipi)(const struct cpumask *mask);
87         void (*send_call_func_single_ipi)(int cpu);
88 };
89
90 /* Globals due to paravirt */
91 extern void set_cpu_sibling_map(int cpu);
92
93 #ifdef CONFIG_SMP
94 #ifndef CONFIG_PARAVIRT
95 #define startup_ipi_hook(phys_apicid, start_eip, start_esp) do { } while (0)
96 #endif
97 extern struct smp_ops smp_ops;
98
99 static inline void smp_send_stop(void)
100 {
101         smp_ops.smp_send_stop();
102 }
103
104 static inline void smp_prepare_boot_cpu(void)
105 {
106         smp_ops.smp_prepare_boot_cpu();
107 }
108
109 static inline void smp_prepare_cpus(unsigned int max_cpus)
110 {
111         smp_ops.smp_prepare_cpus(max_cpus);
112 }
113
114 static inline void smp_cpus_done(unsigned int max_cpus)
115 {
116         smp_ops.smp_cpus_done(max_cpus);
117 }
118
119 static inline int __cpu_up(unsigned int cpu)
120 {
121         return smp_ops.cpu_up(cpu);
122 }
123
124 static inline int __cpu_disable(void)
125 {
126         return smp_ops.cpu_disable();
127 }
128
129 static inline void __cpu_die(unsigned int cpu)
130 {
131         smp_ops.cpu_die(cpu);
132 }
133
134 static inline void play_dead(void)
135 {
136         smp_ops.play_dead();
137 }
138
139 static inline void smp_send_reschedule(int cpu)
140 {
141         smp_ops.smp_send_reschedule(cpu);
142 }
143
144 static inline void arch_send_call_function_single_ipi(int cpu)
145 {
146         smp_ops.send_call_func_single_ipi(cpu);
147 }
148
149 static inline void arch_send_call_function_ipi(cpumask_t mask)
150 {
151         smp_ops.send_call_func_ipi(&mask);
152 }
153
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);
163
164 void native_send_call_func_ipi(const struct cpumask *mask);
165 void native_send_call_func_single_ipi(int cpu);
166
167 void smp_store_cpu_info(int id);
168 #define cpu_physical_id(cpu)    per_cpu(x86_cpu_to_apicid, cpu)
169
170 /* We don't mark CPUs online until __cpu_up(), so we need another measure */
171 static inline int num_booting_cpus(void)
172 {
173         return cpumask_weight(cpu_callout_mask);
174 }
175 #endif /* CONFIG_SMP */
176
177 extern unsigned disabled_cpus __cpuinitdata;
178
179 #ifdef CONFIG_X86_32_SMP
180 /*
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.
184  */
185 #define raw_smp_processor_id() (x86_read_percpu(cpu_number))
186 extern int safe_smp_processor_id(void);
187
188 #elif defined(CONFIG_X86_64_SMP)
189 #define raw_smp_processor_id()  read_pda(cpunumber)
190
191 #define stack_smp_processor_id()                                        \
192 ({                                                              \
193         struct thread_info *ti;                                         \
194         __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK));      \
195         ti->cpu;                                                        \
196 })
197 #define safe_smp_processor_id()         smp_processor_id()
198
199 #endif
200
201 #ifdef CONFIG_X86_LOCAL_APIC
202
203 #ifndef CONFIG_X86_64
204 static inline int logical_smp_processor_id(void)
205 {
206         /* we don't want to mark this access volatile - bad code generation */
207         return GET_APIC_LOGICAL_ID(*(u32 *)(APIC_BASE + APIC_LDR));
208 }
209
210 #include <mach_apicdef.h>
211 static inline unsigned int read_apic_id(void)
212 {
213         unsigned int reg;
214
215         reg = *(u32 *)(APIC_BASE + APIC_ID);
216
217         return GET_APIC_ID(reg);
218 }
219 #endif
220
221
222 # if defined(APIC_DEFINITION) || defined(CONFIG_X86_64)
223 extern int hard_smp_processor_id(void);
224 # else
225 #include <mach_apicdef.h>
226 static inline int hard_smp_processor_id(void)
227 {
228         /* we don't want to mark this access volatile - bad code generation */
229         return read_apic_id();
230 }
231 # endif /* APIC_DEFINITION */
232
233 #else /* CONFIG_X86_LOCAL_APIC */
234
235 # ifndef CONFIG_SMP
236 #  define hard_smp_processor_id()       0
237 # endif
238
239 #endif /* CONFIG_X86_LOCAL_APIC */
240
241 #endif /* __ASSEMBLY__ */
242 #endif /* _ASM_X86_SMP_H */