blob: 6df2615f9138728cfd29ea2ac46a0194c1fd1555 [file] [log] [blame]
Vegard Nossum77ef50a2008-06-18 17:08:48 +02001#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>
20
Glauber Costa53ebef42008-03-03 14:12:31 -030021extern cpumask_t cpu_callout_map;
Glauber Costa8be9ac82008-03-27 14:06:04 -030022extern cpumask_t cpu_initialized;
23extern cpumask_t cpu_callin_map;
24
25extern void (*mtrr_hook)(void);
26extern void zap_low_mappings(void);
Glauber Costa53ebef42008-03-03 14:12:31 -030027
Jeremy Fitzhardinge7c33b1e2008-07-08 15:06:29 -070028extern int __cpuinit get_local_pda(int cpu);
29
Glauber Costa53ebef42008-03-03 14:12:31 -030030extern int smp_num_siblings;
31extern unsigned int num_processors;
Glauber de Oliveira Costacb3c8b92008-03-19 14:25:59 -030032extern cpumask_t cpu_initialized;
Glauber Costac27cfef2008-03-03 14:12:29 -030033
Glauber de Oliveira Costa7e1efc02008-03-19 14:25:18 -030034DECLARE_PER_CPU(cpumask_t, cpu_sibling_map);
35DECLARE_PER_CPU(cpumask_t, cpu_core_map);
36DECLARE_PER_CPU(u16, cpu_llc_id);
Jaswinder Singhfb261322008-07-21 21:36:40 +053037#ifdef CONFIG_X86_32
38DECLARE_PER_CPU(int, cpu_number);
39#endif
Mike Travis23ca4bb2008-05-12 21:21:12 +020040
41DECLARE_EARLY_PER_CPU(u16, x86_cpu_to_apicid);
42DECLARE_EARLY_PER_CPU(u16, x86_bios_cpu_apicid);
Glauber de Oliveira Costa7e1efc02008-03-19 14:25:18 -030043
Glauber de Oliveira Costa9d97d0d2008-03-19 14:25:57 -030044/* Static state in head.S used to set up a CPU */
45extern struct {
46 void *sp;
47 unsigned short ss;
48} stack_start;
49
Glauber Costa16694022008-03-03 14:12:32 -030050struct smp_ops {
51 void (*smp_prepare_boot_cpu)(void);
52 void (*smp_prepare_cpus)(unsigned max_cpus);
Glauber Costa16694022008-03-03 14:12:32 -030053 void (*smp_cpus_done)(unsigned max_cpus);
54
55 void (*smp_send_stop)(void);
56 void (*smp_send_reschedule)(int cpu);
Jens Axboe3b16cf82008-06-26 11:21:54 +020057
Alex Nixon93be71b2008-08-22 11:52:11 +010058 int (*cpu_up)(unsigned cpu);
59 int (*cpu_disable)(void);
60 void (*cpu_die)(unsigned int cpu);
61 void (*play_dead)(void);
62
Jens Axboe3b16cf82008-06-26 11:21:54 +020063 void (*send_call_func_ipi)(cpumask_t mask);
64 void (*send_call_func_single_ipi)(int cpu);
Glauber Costa16694022008-03-03 14:12:32 -030065};
66
Glauber Costa14522072008-03-03 14:12:59 -030067/* Globals due to paravirt */
68extern void set_cpu_sibling_map(int cpu);
69
Glauber Costac76cb362008-03-03 14:12:33 -030070#ifdef CONFIG_SMP
Glauber de Oliveira Costad0173ae2008-03-19 14:24:59 -030071#ifndef CONFIG_PARAVIRT
72#define startup_ipi_hook(phys_apicid, start_eip, start_esp) do { } while (0)
73#endif
Glauber Costac76cb362008-03-03 14:12:33 -030074extern struct smp_ops smp_ops;
Glauber Costa86789692008-03-03 14:12:34 -030075
Glauber Costa377d6982008-03-03 14:12:51 -030076static inline void smp_send_stop(void)
77{
78 smp_ops.smp_send_stop();
79}
80
Glauber Costa1e3fac82008-03-03 14:12:37 -030081static inline void smp_prepare_boot_cpu(void)
82{
83 smp_ops.smp_prepare_boot_cpu();
84}
85
Glauber Costa7557da62008-03-03 14:12:38 -030086static inline void smp_prepare_cpus(unsigned int max_cpus)
87{
88 smp_ops.smp_prepare_cpus(max_cpus);
89}
90
Glauber Costac5597642008-03-03 14:12:39 -030091static inline void smp_cpus_done(unsigned int max_cpus)
92{
93 smp_ops.smp_cpus_done(max_cpus);
94}
95
Glauber Costa71d19542008-03-03 14:12:36 -030096static inline int __cpu_up(unsigned int cpu)
97{
98 return smp_ops.cpu_up(cpu);
99}
100
Alex Nixon93be71b2008-08-22 11:52:11 +0100101static inline int __cpu_disable(void)
102{
103 return smp_ops.cpu_disable();
104}
105
106static inline void __cpu_die(unsigned int cpu)
107{
108 smp_ops.cpu_die(cpu);
109}
110
111static inline void play_dead(void)
112{
113 smp_ops.play_dead();
114}
115
Glauber Costa86789692008-03-03 14:12:34 -0300116static inline void smp_send_reschedule(int cpu)
117{
118 smp_ops.smp_send_reschedule(cpu);
119}
Glauber Costa64b1a21e02008-03-03 14:12:35 -0300120
Jens Axboe3b16cf82008-06-26 11:21:54 +0200121static inline void arch_send_call_function_single_ipi(int cpu)
Glauber Costa64b1a21e02008-03-03 14:12:35 -0300122{
Jens Axboe3b16cf82008-06-26 11:21:54 +0200123 smp_ops.send_call_func_single_ipi(cpu);
124}
125
126static inline void arch_send_call_function_ipi(cpumask_t mask)
127{
128 smp_ops.send_call_func_ipi(mask);
Glauber Costa64b1a21e02008-03-03 14:12:35 -0300129}
Glauber Costa71d19542008-03-03 14:12:36 -0300130
Alex Nixon8227dce2008-08-22 11:52:14 +0100131void cpu_disable_common(void);
Glauber Costa1e3fac82008-03-03 14:12:37 -0300132void native_smp_prepare_boot_cpu(void);
Glauber Costa7557da62008-03-03 14:12:38 -0300133void native_smp_prepare_cpus(unsigned int max_cpus);
Glauber Costac5597642008-03-03 14:12:39 -0300134void native_smp_cpus_done(unsigned int max_cpus);
Glauber Costa71d19542008-03-03 14:12:36 -0300135int native_cpu_up(unsigned int cpunum);
Alex Nixon93be71b2008-08-22 11:52:11 +0100136int native_cpu_disable(void);
137void native_cpu_die(unsigned int cpu);
138void native_play_dead(void);
Alex Nixona21f5d882008-08-22 11:52:13 +0100139void play_dead_common(void);
Alex Nixon93be71b2008-08-22 11:52:11 +0100140
Jens Axboe3b16cf82008-06-26 11:21:54 +0200141void native_send_call_func_ipi(cpumask_t mask);
142void native_send_call_func_single_ipi(int cpu);
Glauber Costa93b016f2008-03-03 14:12:40 -0300143
Glauber de Oliveira Costa1d89a7f2008-03-19 14:25:05 -0300144void smp_store_cpu_info(int id);
Glauber de Oliveira Costac70dcb72008-03-19 14:25:58 -0300145#define cpu_physical_id(cpu) per_cpu(x86_cpu_to_apicid, cpu)
Glauber Costaa9c057c2008-03-27 14:06:02 -0300146
147/* We don't mark CPUs online until __cpu_up(), so we need another measure */
148static inline int num_booting_cpus(void)
149{
150 return cpus_weight(cpu_callout_map);
151}
Ingo Molnar4a701732008-07-03 15:57:47 +0200152#endif /* CONFIG_SMP */
153
154#if defined(CONFIG_SMP) && defined(CONFIG_HOTPLUG_CPU)
155extern void prefill_possible_map(void);
Yinghai Lu329513a2008-07-02 18:54:40 -0700156#else
157static inline void prefill_possible_map(void)
158{
159}
Ingo Molnar4a701732008-07-03 15:57:47 +0200160#endif
Glauber Costaa9c057c2008-03-27 14:06:02 -0300161
Alexey Starikovskiy2fe60142008-04-04 23:41:44 +0400162extern unsigned disabled_cpus __cpuinitdata;
163
Glauber Costaa9c057c2008-03-27 14:06:02 -0300164#ifdef CONFIG_X86_32_SMP
165/*
166 * This function is needed by all SMP systems. It must _always_ be valid
167 * from the initial startup. We map APIC_BASE very early in page_setup(),
168 * so this is correct in the x86 case.
169 */
Glauber Costaa9c057c2008-03-27 14:06:02 -0300170#define raw_smp_processor_id() (x86_read_percpu(cpu_number))
171extern int safe_smp_processor_id(void);
172
173#elif defined(CONFIG_X86_64_SMP)
174#define raw_smp_processor_id() read_pda(cpunumber)
175
176#define stack_smp_processor_id() \
177({ \
178 struct thread_info *ti; \
179 __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
180 ti->cpu; \
181})
182#define safe_smp_processor_id() smp_processor_id()
183
184#else /* !CONFIG_X86_32_SMP && !CONFIG_X86_64_SMP */
Glauber de Oliveira Costac70dcb72008-03-19 14:25:58 -0300185#define cpu_physical_id(cpu) boot_cpu_physical_apicid
Glauber Costaa9c057c2008-03-27 14:06:02 -0300186#define safe_smp_processor_id() 0
187#define stack_smp_processor_id() 0
Glauber Costac76cb362008-03-03 14:12:33 -0300188#endif
Glauber Costa16694022008-03-03 14:12:32 -0300189
Glauber Costa1b0008432008-03-27 14:05:58 -0300190#ifdef CONFIG_X86_LOCAL_APIC
191
Suresh Siddha1b374e42008-07-10 11:16:49 -0700192#ifndef CONFIG_X86_64
Glauber Costa1b0008432008-03-27 14:05:58 -0300193static inline int logical_smp_processor_id(void)
194{
195 /* we don't want to mark this access volatile - bad code generation */
196 return GET_APIC_LOGICAL_ID(*(u32 *)(APIC_BASE + APIC_LDR));
197}
198
Yinghai Lu4c9961d2008-07-11 18:44:16 -0700199#include <mach_apicdef.h>
Jack Steiner05f2d122008-03-28 14:12:02 -0500200static inline unsigned int read_apic_id(void)
201{
Yinghai Lu4c9961d2008-07-11 18:44:16 -0700202 unsigned int reg;
203
204 reg = *(u32 *)(APIC_BASE + APIC_ID);
205
206 return GET_APIC_ID(reg);
Jack Steiner05f2d122008-03-28 14:12:02 -0500207}
Jack Steinerac23d4e2008-03-28 14:12:16 -0500208#endif
209
Jack Steiner05f2d122008-03-28 14:12:02 -0500210
Suresh Siddha0c81c742008-07-10 11:16:48 -0700211# if defined(APIC_DEFINITION) || defined(CONFIG_X86_64)
Glauber Costa1b0008432008-03-27 14:05:58 -0300212extern int hard_smp_processor_id(void);
213# else
Yinghai Lu4c9961d2008-07-11 18:44:16 -0700214#include <mach_apicdef.h>
Glauber Costa1b0008432008-03-27 14:05:58 -0300215static inline int hard_smp_processor_id(void)
216{
217 /* we don't want to mark this access volatile - bad code generation */
Yinghai Lu4c9961d2008-07-11 18:44:16 -0700218 return read_apic_id();
Glauber Costa1b0008432008-03-27 14:05:58 -0300219}
220# endif /* APIC_DEFINITION */
221
222#else /* CONFIG_X86_LOCAL_APIC */
223
224# ifndef CONFIG_SMP
225# define hard_smp_processor_id() 0
226# endif
227
228#endif /* CONFIG_X86_LOCAL_APIC */
229
Glauber Costac27cfef2008-03-03 14:12:29 -0300230#endif /* __ASSEMBLY__ */
Vegard Nossum77ef50a2008-06-18 17:08:48 +0200231#endif /* ASM_X86__SMP_H */