blob: a6afc29f2dd9981e713a36d3ec14b507796415bf [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 Costa64b1a212008-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 Costa64b1a212008-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 Costa64b1a212008-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 Nixona21f5d82008-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
Chuck Ebbert14adf852008-09-29 18:29:42 -0400144extern void prefill_possible_map(void);
145
Glauber de Oliveira Costa1d89a7f2008-03-19 14:25:05 -0300146void smp_store_cpu_info(int id);
Glauber de Oliveira Costac70dcb72008-03-19 14:25:58 -0300147#define cpu_physical_id(cpu) per_cpu(x86_cpu_to_apicid, cpu)
Glauber Costaa9c057c2008-03-27 14:06:02 -0300148
149/* We don't mark CPUs online until __cpu_up(), so we need another measure */
150static inline int num_booting_cpus(void)
151{
152 return cpus_weight(cpu_callout_map);
153}
Yinghai Lu329513a2008-07-02 18:54:40 -0700154#else
155static inline void prefill_possible_map(void)
156{
157}
Chuck Ebbert14adf852008-09-29 18:29:42 -0400158#endif /* CONFIG_SMP */
Glauber Costaa9c057c2008-03-27 14:06:02 -0300159
Alexey Starikovskiy2fe60142008-04-04 23:41:44 +0400160extern unsigned disabled_cpus __cpuinitdata;
161
Glauber Costaa9c057c2008-03-27 14:06:02 -0300162#ifdef CONFIG_X86_32_SMP
163/*
164 * This function is needed by all SMP systems. It must _always_ be valid
165 * from the initial startup. We map APIC_BASE very early in page_setup(),
166 * so this is correct in the x86 case.
167 */
Glauber Costaa9c057c2008-03-27 14:06:02 -0300168#define raw_smp_processor_id() (x86_read_percpu(cpu_number))
169extern int safe_smp_processor_id(void);
170
171#elif defined(CONFIG_X86_64_SMP)
172#define raw_smp_processor_id() read_pda(cpunumber)
173
174#define stack_smp_processor_id() \
175({ \
176 struct thread_info *ti; \
177 __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
178 ti->cpu; \
179})
180#define safe_smp_processor_id() smp_processor_id()
181
182#else /* !CONFIG_X86_32_SMP && !CONFIG_X86_64_SMP */
Glauber de Oliveira Costac70dcb72008-03-19 14:25:58 -0300183#define cpu_physical_id(cpu) boot_cpu_physical_apicid
Glauber Costaa9c057c2008-03-27 14:06:02 -0300184#define safe_smp_processor_id() 0
185#define stack_smp_processor_id() 0
Glauber Costac76cb362008-03-03 14:12:33 -0300186#endif
Glauber Costa16694022008-03-03 14:12:32 -0300187
Glauber Costa1b000842008-03-27 14:05:58 -0300188#ifdef CONFIG_X86_LOCAL_APIC
189
Suresh Siddha1b374e42008-07-10 11:16:49 -0700190#ifndef CONFIG_X86_64
Glauber Costa1b000842008-03-27 14:05:58 -0300191static inline int logical_smp_processor_id(void)
192{
193 /* we don't want to mark this access volatile - bad code generation */
194 return GET_APIC_LOGICAL_ID(*(u32 *)(APIC_BASE + APIC_LDR));
195}
196
Yinghai Lu4c9961d2008-07-11 18:44:16 -0700197#include <mach_apicdef.h>
Jack Steiner05f2d122008-03-28 14:12:02 -0500198static inline unsigned int read_apic_id(void)
199{
Yinghai Lu4c9961d2008-07-11 18:44:16 -0700200 unsigned int reg;
201
202 reg = *(u32 *)(APIC_BASE + APIC_ID);
203
204 return GET_APIC_ID(reg);
Jack Steiner05f2d122008-03-28 14:12:02 -0500205}
Jack Steinerac23d4e2008-03-28 14:12:16 -0500206#endif
207
Jack Steiner05f2d122008-03-28 14:12:02 -0500208
Suresh Siddha0c81c742008-07-10 11:16:48 -0700209# if defined(APIC_DEFINITION) || defined(CONFIG_X86_64)
Glauber Costa1b000842008-03-27 14:05:58 -0300210extern int hard_smp_processor_id(void);
211# else
Yinghai Lu4c9961d2008-07-11 18:44:16 -0700212#include <mach_apicdef.h>
Glauber Costa1b000842008-03-27 14:05:58 -0300213static inline int hard_smp_processor_id(void)
214{
215 /* we don't want to mark this access volatile - bad code generation */
Yinghai Lu4c9961d2008-07-11 18:44:16 -0700216 return read_apic_id();
Glauber Costa1b000842008-03-27 14:05:58 -0300217}
218# endif /* APIC_DEFINITION */
219
220#else /* CONFIG_X86_LOCAL_APIC */
221
222# ifndef CONFIG_SMP
223# define hard_smp_processor_id() 0
224# endif
225
226#endif /* CONFIG_X86_LOCAL_APIC */
227
Glauber Costac27cfef2008-03-03 14:12:29 -0300228#endif /* __ASSEMBLY__ */
Vegard Nossum77ef50a2008-06-18 17:08:48 +0200229#endif /* ASM_X86__SMP_H */