smp.h 5.1 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 <asm/percpu.h>
6

G
Glauber Costa 已提交
7 8 9 10 11 12 13 14 15 16 17
/*
 * 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/thread_info.h>
18
#include <asm/cpumask.h>
19
#include <asm/cpufeature.h>
G
Glauber Costa 已提交
20

21 22
extern int smp_num_siblings;
extern unsigned int num_processors;
G
Glauber Costa 已提交
23

24 25
DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_sibling_map);
DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
26
/* cpus sharing the last level cache: */
27 28 29
DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
30

31 32 33 34 35
static inline struct cpumask *cpu_llc_shared_mask(int cpu)
{
	return per_cpu(cpu_llc_shared_map, cpu);
}

36 37
DECLARE_EARLY_PER_CPU_READ_MOSTLY(u16, x86_cpu_to_apicid);
DECLARE_EARLY_PER_CPU_READ_MOSTLY(u16, x86_bios_cpu_apicid);
38
#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
39
DECLARE_EARLY_PER_CPU_READ_MOSTLY(int, x86_cpu_to_logical_apicid);
40
#endif
41

42
/* Static state in head.S used to set up a CPU */
43
extern unsigned long stack_start; /* Initial stack pointer address */
44

45 46
struct task_struct;

47 48 49 50 51
struct smp_ops {
	void (*smp_prepare_boot_cpu)(void);
	void (*smp_prepare_cpus)(unsigned max_cpus);
	void (*smp_cpus_done)(unsigned max_cpus);

52
	void (*stop_other_cpus)(int wait);
53
	void (*smp_send_reschedule)(int cpu);
54

55
	int (*cpu_up)(unsigned cpu, struct task_struct *tidle);
56 57 58 59
	int (*cpu_disable)(void);
	void (*cpu_die)(unsigned int cpu);
	void (*play_dead)(void);

60
	void (*send_call_func_ipi)(const struct cpumask *mask);
61
	void (*send_call_func_single_ipi)(int cpu);
62 63
};

64 65 66
/* Globals due to paravirt */
extern void set_cpu_sibling_map(int cpu);

67 68
#ifdef CONFIG_SMP
extern struct smp_ops smp_ops;
G
Glauber Costa 已提交
69

G
Glauber Costa 已提交
70 71
static inline void smp_send_stop(void)
{
72 73 74 75 76 77
	smp_ops.stop_other_cpus(0);
}

static inline void stop_other_cpus(void)
{
	smp_ops.stop_other_cpus(1);
G
Glauber Costa 已提交
78 79
}

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

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

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

95
static inline int __cpu_up(unsigned int cpu, struct task_struct *tidle)
G
Glauber Costa 已提交
96
{
97
	return smp_ops.cpu_up(cpu, tidle);
G
Glauber Costa 已提交
98 99
}

100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
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 已提交
115 116 117 118
static inline void smp_send_reschedule(int cpu)
{
	smp_ops.smp_send_reschedule(cpu);
}
119

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

125
static inline void arch_send_call_function_ipi_mask(const struct cpumask *mask)
126
{
127
	smp_ops.send_call_func_ipi(mask);
128
}
G
Glauber Costa 已提交
129

130
void cpu_disable_common(void);
G
Glauber Costa 已提交
131
void native_smp_prepare_boot_cpu(void);
G
Glauber Costa 已提交
132
void native_smp_prepare_cpus(unsigned int max_cpus);
G
Glauber Costa 已提交
133
void native_smp_cpus_done(unsigned int max_cpus);
134
void common_cpu_up(unsigned int cpunum, struct task_struct *tidle);
135
int native_cpu_up(unsigned int cpunum, struct task_struct *tidle);
136
int native_cpu_disable(void);
137
int common_cpu_die(unsigned int cpu);
138 139
void native_cpu_die(unsigned int cpu);
void native_play_dead(void);
140
void play_dead_common(void);
141 142
void wbinvd_on_cpu(int cpu);
int wbinvd_on_all_cpus(void);
143

144
void native_send_call_func_ipi(const struct cpumask *mask);
145
void native_send_call_func_single_ipi(int cpu);
146
void x86_idle_thread_init(unsigned int cpu, struct task_struct *idle);
147

148
void smp_store_boot_cpu_info(void);
149
void smp_store_cpu_info(int id);
150
#define cpu_physical_id(cpu)	per_cpu(x86_cpu_to_apicid, cpu)
151

152 153 154 155 156 157 158
#else /* !CONFIG_SMP */
#define wbinvd_on_cpu(cpu)     wbinvd()
static inline int wbinvd_on_all_cpus(void)
{
	wbinvd();
	return 0;
}
159
#endif /* CONFIG_SMP */
160

161
extern unsigned disabled_cpus;
162

163 164 165 166 167 168
#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.
 */
169
#define raw_smp_processor_id() (this_cpu_read(cpu_number))
170 171 172
extern int safe_smp_processor_id(void);

#elif defined(CONFIG_X86_64_SMP)
173
#define raw_smp_processor_id() (this_cpu_read(cpu_number))
174 175 176 177 178 179 180 181 182

#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()

183
#endif
184

185 186
#ifdef CONFIG_X86_LOCAL_APIC

187
#ifndef CONFIG_X86_64
188 189 190
static inline int logical_smp_processor_id(void)
{
	/* we don't want to mark this access volatile - bad code generation */
191
	return GET_APIC_LOGICAL_ID(apic_read(APIC_LDR));
192 193
}

J
Jack Steiner 已提交
194 195
#endif

196 197 198 199 200 201 202 203 204 205
extern int hard_smp_processor_id(void);

#else /* CONFIG_X86_LOCAL_APIC */

# ifndef CONFIG_SMP
#  define hard_smp_processor_id()	0
# endif

#endif /* CONFIG_X86_LOCAL_APIC */

D
Don Zickus 已提交
206 207 208 209 210 211
#ifdef CONFIG_DEBUG_NMI_SELFTEST
extern void nmi_selftest(void);
#else
#define nmi_selftest() do { } while (0)
#endif

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