smp.h 5.3 KB
Newer Older
H
H. Peter Anvin 已提交
1 2
#ifndef _ASM_X86_SMP_H
#define _ASM_X86_SMP_H
G
Glauber Costa 已提交
3
#ifndef __ASSEMBLY__
4
#include <linux/cpumask.h>
5
#include <linux/init.h>
6
#include <asm/percpu.h>
7

G
Glauber Costa 已提交
8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * We need the APIC definitions automatically as part of 'smp.h'
 */
#ifdef CONFIG_X86_LOCAL_APIC
# include <asm/mpspec.h>
# include <asm/apic.h>
# ifdef CONFIG_X86_IO_APIC
#  include <asm/io_apic.h>
# endif
#endif
#include <asm/pda.h>
#include <asm/thread_info.h>

21
extern cpumask_t cpu_callout_map;
22 23 24 25 26
extern cpumask_t cpu_initialized;
extern cpumask_t cpu_callin_map;

extern void (*mtrr_hook)(void);
extern void zap_low_mappings(void);
27

28 29
extern int __cpuinit get_local_pda(int cpu);

30 31
extern int smp_num_siblings;
extern unsigned int num_processors;
32
extern cpumask_t cpu_initialized;
G
Glauber Costa 已提交
33

34 35 36
DECLARE_PER_CPU(cpumask_t, cpu_sibling_map);
DECLARE_PER_CPU(cpumask_t, cpu_core_map);
DECLARE_PER_CPU(u16, cpu_llc_id);
37 38 39
#ifdef CONFIG_X86_32
DECLARE_PER_CPU(int, cpu_number);
#endif
40 41 42

DECLARE_EARLY_PER_CPU(u16, x86_cpu_to_apicid);
DECLARE_EARLY_PER_CPU(u16, x86_bios_cpu_apicid);
43

44 45 46 47 48 49
/* Static state in head.S used to set up a CPU */
extern struct {
	void *sp;
	unsigned short ss;
} stack_start;

50 51 52 53 54 55 56
struct smp_ops {
	void (*smp_prepare_boot_cpu)(void);
	void (*smp_prepare_cpus)(unsigned max_cpus);
	void (*smp_cpus_done)(unsigned max_cpus);

	void (*smp_send_stop)(void);
	void (*smp_send_reschedule)(int cpu);
57

58 59 60 61 62
	int (*cpu_up)(unsigned cpu);
	int (*cpu_disable)(void);
	void (*cpu_die)(unsigned int cpu);
	void (*play_dead)(void);

63
	void (*send_call_func_ipi)(const cpumask_t *mask);
64
	void (*send_call_func_single_ipi)(int cpu);
65 66
};

67 68 69
/* Globals due to paravirt */
extern void set_cpu_sibling_map(int cpu);

70
#ifdef CONFIG_SMP
71 72 73
#ifndef CONFIG_PARAVIRT
#define startup_ipi_hook(phys_apicid, start_eip, start_esp) do { } while (0)
#endif
74
extern struct smp_ops smp_ops;
G
Glauber Costa 已提交
75

G
Glauber Costa 已提交
76 77 78 79 80
static inline void smp_send_stop(void)
{
	smp_ops.smp_send_stop();
}

G
Glauber Costa 已提交
81 82 83 84 85
static inline void smp_prepare_boot_cpu(void)
{
	smp_ops.smp_prepare_boot_cpu();
}

G
Glauber Costa 已提交
86 87 88 89 90
static inline void smp_prepare_cpus(unsigned int max_cpus)
{
	smp_ops.smp_prepare_cpus(max_cpus);
}

G
Glauber Costa 已提交
91 92 93 94 95
static inline void smp_cpus_done(unsigned int max_cpus)
{
	smp_ops.smp_cpus_done(max_cpus);
}

G
Glauber Costa 已提交
96 97 98 99 100
static inline int __cpu_up(unsigned int cpu)
{
	return smp_ops.cpu_up(cpu);
}

101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
static inline int __cpu_disable(void)
{
	return smp_ops.cpu_disable();
}

static inline void __cpu_die(unsigned int cpu)
{
	smp_ops.cpu_die(cpu);
}

static inline void play_dead(void)
{
	smp_ops.play_dead();
}

G
Glauber Costa 已提交
116 117 118 119
static inline void smp_send_reschedule(int cpu)
{
	smp_ops.smp_send_reschedule(cpu);
}
120

121 122 123 124 125 126
static inline void arch_send_call_function_single_ipi(int cpu)
{
	smp_ops.send_call_func_single_ipi(cpu);
}

static inline void arch_send_call_function_ipi(cpumask_t mask)
127
{
128
	smp_ops.send_call_func_ipi(&mask);
129
}
G
Glauber Costa 已提交
130

131
void cpu_disable_common(void);
G
Glauber Costa 已提交
132
void native_smp_prepare_boot_cpu(void);
G
Glauber Costa 已提交
133
void native_smp_prepare_cpus(unsigned int max_cpus);
G
Glauber Costa 已提交
134
void native_smp_cpus_done(unsigned int max_cpus);
G
Glauber Costa 已提交
135
int native_cpu_up(unsigned int cpunum);
136 137 138
int native_cpu_disable(void);
void native_cpu_die(unsigned int cpu);
void native_play_dead(void);
139
void play_dead_common(void);
140

141
void native_send_call_func_ipi(const cpumask_t *mask);
142
void native_send_call_func_single_ipi(int cpu);
143

144 145
extern void prefill_possible_map(void);

146
void smp_store_cpu_info(int id);
147
#define cpu_physical_id(cpu)	per_cpu(x86_cpu_to_apicid, cpu)
148 149 150 151 152 153

/* We don't mark CPUs online until __cpu_up(), so we need another measure */
static inline int num_booting_cpus(void)
{
	return cpus_weight(cpu_callout_map);
}
154 155 156 157
#else
static inline void prefill_possible_map(void)
{
}
158
#endif /* CONFIG_SMP */
159

160 161
extern unsigned disabled_cpus __cpuinitdata;

162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
#ifdef CONFIG_X86_32_SMP
/*
 * This function is needed by all SMP systems. It must _always_ be valid
 * from the initial startup. We map APIC_BASE very early in page_setup(),
 * so this is correct in the x86 case.
 */
#define raw_smp_processor_id() (x86_read_percpu(cpu_number))
extern int safe_smp_processor_id(void);

#elif defined(CONFIG_X86_64_SMP)
#define raw_smp_processor_id()	read_pda(cpunumber)

#define stack_smp_processor_id()					\
({								\
	struct thread_info *ti;						\
	__asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK));	\
	ti->cpu;							\
})
#define safe_smp_processor_id()		smp_processor_id()

#else /* !CONFIG_X86_32_SMP && !CONFIG_X86_64_SMP */
183
#define cpu_physical_id(cpu)		boot_cpu_physical_apicid
184 185
#define safe_smp_processor_id()		0
#define stack_smp_processor_id() 	0
186
#endif
187

188 189
#ifdef CONFIG_X86_LOCAL_APIC

190
#ifndef CONFIG_X86_64
191 192 193 194 195 196
static inline int logical_smp_processor_id(void)
{
	/* we don't want to mark this access volatile - bad code generation */
	return GET_APIC_LOGICAL_ID(*(u32 *)(APIC_BASE + APIC_LDR));
}

197
#include <mach_apicdef.h>
198 199
static inline unsigned int read_apic_id(void)
{
200 201 202 203 204
	unsigned int reg;

	reg = *(u32 *)(APIC_BASE + APIC_ID);

	return GET_APIC_ID(reg);
205
}
J
Jack Steiner 已提交
206 207
#endif

208

209
# if defined(APIC_DEFINITION) || defined(CONFIG_X86_64)
210 211
extern int hard_smp_processor_id(void);
# else
212
#include <mach_apicdef.h>
213 214 215
static inline int hard_smp_processor_id(void)
{
	/* we don't want to mark this access volatile - bad code generation */
216
	return read_apic_id();
217 218 219 220 221 222 223 224 225 226 227
}
# endif /* APIC_DEFINITION */

#else /* CONFIG_X86_LOCAL_APIC */

# ifndef CONFIG_SMP
#  define hard_smp_processor_id()	0
# endif

#endif /* CONFIG_X86_LOCAL_APIC */

228 229 230 231 232 233
#ifdef CONFIG_X86_HAS_BOOT_CPU_ID
extern unsigned char boot_cpu_id;
#else
#define boot_cpu_id	0
#endif

G
Glauber Costa 已提交
234
#endif /* __ASSEMBLY__ */
H
H. Peter Anvin 已提交
235
#endif /* _ASM_X86_SMP_H */