Update to 3.4-final.
[linux-flexiantxendom0-3.2.10.git] / arch / x86 / include / mach-xen / 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 <linux/thread_info.h>
19 #include <asm/cpumask.h>
20 #include <asm/cpufeature.h>
21
22 extern unsigned int num_processors;
23
24 #ifndef CONFIG_XEN
25 static inline bool cpu_has_ht_siblings(void)
26 {
27         bool has_siblings = false;
28 #ifdef CONFIG_SMP
29         has_siblings = cpu_has_ht && smp_num_siblings > 1;
30 #endif
31         return has_siblings;
32 }
33
34 DECLARE_PER_CPU(cpumask_var_t, cpu_sibling_map);
35 DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
36 /* cpus sharing the last level cache: */
37 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
38 DECLARE_PER_CPU(u16, cpu_llc_id);
39 DECLARE_PER_CPU(int, cpu_number);
40 #endif
41
42 static inline const struct cpumask *cpu_sibling_mask(int cpu)
43 {
44         return cpumask_of(cpu);
45 }
46
47 static inline const struct cpumask *cpu_core_mask(int cpu)
48 {
49         return cpumask_of(cpu);
50 }
51
52 #ifndef CONFIG_XEN
53 static inline struct cpumask *cpu_llc_shared_mask(int cpu)
54 {
55         return per_cpu(cpu_llc_shared_map, cpu);
56 }
57
58 DECLARE_EARLY_PER_CPU(u16, x86_cpu_to_apicid);
59 DECLARE_EARLY_PER_CPU(u16, x86_bios_cpu_apicid);
60 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
61 DECLARE_EARLY_PER_CPU(int, x86_cpu_to_logical_apicid);
62 #endif
63 #endif
64
65 #ifdef CONFIG_SMP
66
67 #ifndef CONFIG_XEN
68
69 /* Static state in head.S used to set up a CPU */
70 extern unsigned long stack_start; /* Initial stack pointer address */
71
72 struct smp_ops {
73         void (*smp_prepare_boot_cpu)(void);
74         void (*smp_prepare_cpus)(unsigned max_cpus);
75         void (*smp_cpus_done)(unsigned max_cpus);
76
77         void (*stop_other_cpus)(int wait);
78         void (*smp_send_reschedule)(int cpu);
79
80         int (*cpu_up)(unsigned cpu);
81         int (*cpu_disable)(void);
82         void (*cpu_die)(unsigned int cpu);
83         void (*play_dead)(void);
84
85         void (*send_call_func_ipi)(const struct cpumask *mask);
86         void (*send_call_func_single_ipi)(int cpu);
87 };
88
89 /* Globals due to paravirt */
90 extern void set_cpu_sibling_map(int cpu);
91
92 extern struct smp_ops smp_ops;
93
94 static inline void smp_send_stop(void)
95 {
96         smp_ops.stop_other_cpus(0);
97 }
98
99 static inline void stop_other_cpus(void)
100 {
101         smp_ops.stop_other_cpus(1);
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_mask(const struct cpumask *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 void wbinvd_on_cpu(int cpu);
164 int wbinvd_on_all_cpus(void);
165
166 void smp_store_cpu_info(int id);
167 #define cpu_physical_id(cpu)    per_cpu(x86_cpu_to_apicid, cpu)
168
169 #else /* CONFIG_XEN */
170
171 extern int __cpu_disable(void);
172 extern void __cpu_die(unsigned int cpu);
173 void xen_stop_other_cpus(int wait);
174 void xen_smp_send_reschedule(int cpu);
175 void xen_send_call_func_ipi(const struct cpumask *mask);
176 void xen_send_call_func_single_ipi(int cpu);
177
178 static inline void smp_send_stop(void)
179 {
180         xen_stop_other_cpus(0);
181 }
182
183 #define smp_send_reschedule     xen_smp_send_reschedule
184 #define arch_send_call_function_single_ipi      xen_send_call_func_single_ipi
185 #define arch_send_call_function_ipi_mask        xen_send_call_func_ipi
186
187 void play_dead(void);
188
189 #endif /* CONFIG_XEN */
190
191 /* We don't mark CPUs online until __cpu_up(), so we need another measure */
192 static inline int num_booting_cpus(void)
193 {
194         return cpumask_weight(cpu_callout_mask);
195 }
196 #elif /* !CONFIG_SMP && */ !defined(CONFIG_XEN)
197 #define wbinvd_on_cpu(cpu)     wbinvd()
198 static inline int wbinvd_on_all_cpus(void)
199 {
200         wbinvd();
201         return 0;
202 }
203 #endif /* CONFIG_SMP */
204
205 #ifdef CONFIG_XEN
206 int wbinvd_on_all_cpus(void);
207 #endif
208
209 extern unsigned disabled_cpus __cpuinitdata;
210
211 #include <asm/smp-processor-id.h>
212
213 #if defined(CONFIG_X86_LOCAL_APIC) && !defined(CONFIG_XEN)
214
215 #ifndef CONFIG_X86_64
216 static inline int logical_smp_processor_id(void)
217 {
218         /* we don't want to mark this access volatile - bad code generation */
219         return GET_APIC_LOGICAL_ID(apic_read(APIC_LDR));
220 }
221
222 #endif
223
224 extern int hard_smp_processor_id(void);
225
226 #else /* CONFIG_X86_LOCAL_APIC */
227
228 # ifndef CONFIG_SMP
229 #  define hard_smp_processor_id()       0
230 # endif
231
232 #endif /* CONFIG_X86_LOCAL_APIC */
233
234 #ifdef CONFIG_DEBUG_NMI_SELFTEST
235 extern void nmi_selftest(void);
236 #else
237 #define nmi_selftest() do { } while (0)
238 #endif
239
240 #endif /* __ASSEMBLY__ */
241 #endif /* _ASM_X86_SMP_H */