smp.h 5.5 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
/*
 * 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>
19
#include <asm/cpumask.h>
20
#include <asm/cpufeature.h>
G
Glauber Costa 已提交
21

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

25 26 27 28 29 30 31 32 33
static inline bool cpu_has_ht_siblings(void)
{
	bool has_siblings = false;
#ifdef CONFIG_SMP
	has_siblings = cpu_has_ht && smp_num_siblings > 1;
#endif
	return has_siblings;
}

34 35
DECLARE_PER_CPU(cpumask_var_t, cpu_sibling_map);
DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
36 37
/* cpus sharing the last level cache: */
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

41 42
static inline struct cpumask *cpu_sibling_mask(int cpu)
{
43
	return per_cpu(cpu_sibling_map, cpu);
44 45 46 47
}

static inline struct cpumask *cpu_core_mask(int cpu)
{
48
	return per_cpu(cpu_core_map, cpu);
49 50
}

51 52 53 54 55
static inline struct cpumask *cpu_llc_shared_mask(int cpu)
{
	return per_cpu(cpu_llc_shared_map, cpu);
}

56 57
DECLARE_EARLY_PER_CPU(u16, x86_cpu_to_apicid);
DECLARE_EARLY_PER_CPU(u16, x86_bios_cpu_apicid);
58
#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
59 60
DECLARE_EARLY_PER_CPU(int, x86_cpu_to_logical_apicid);
#endif
61

62
/* Static state in head.S used to set up a CPU */
63
extern unsigned long stack_start; /* Initial stack pointer address */
64

65 66
struct task_struct;

67 68 69 70 71
struct smp_ops {
	void (*smp_prepare_boot_cpu)(void);
	void (*smp_prepare_cpus)(unsigned max_cpus);
	void (*smp_cpus_done)(unsigned max_cpus);

72
	void (*stop_other_cpus)(int wait);
73
	void (*smp_send_reschedule)(int cpu);
74

75
	int (*cpu_up)(unsigned cpu, struct task_struct *tidle);
76 77 78 79
	int (*cpu_disable)(void);
	void (*cpu_die)(unsigned int cpu);
	void (*play_dead)(void);

80
	void (*send_call_func_ipi)(const struct cpumask *mask);
81
	void (*send_call_func_single_ipi)(int cpu);
82 83
};

84 85 86
/* Globals due to paravirt */
extern void set_cpu_sibling_map(int cpu);

87
#ifdef CONFIG_SMP
88 89 90
#ifndef CONFIG_PARAVIRT
#define startup_ipi_hook(phys_apicid, start_eip, start_esp) do { } while (0)
#endif
91
extern struct smp_ops smp_ops;
G
Glauber Costa 已提交
92

G
Glauber Costa 已提交
93 94
static inline void smp_send_stop(void)
{
95 96 97 98 99 100
	smp_ops.stop_other_cpus(0);
}

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

G
Glauber Costa 已提交
103 104 105 106 107
static inline void smp_prepare_boot_cpu(void)
{
	smp_ops.smp_prepare_boot_cpu();
}

G
Glauber Costa 已提交
108 109 110 111 112
static inline void smp_prepare_cpus(unsigned int max_cpus)
{
	smp_ops.smp_prepare_cpus(max_cpus);
}

G
Glauber Costa 已提交
113 114 115 116 117
static inline void smp_cpus_done(unsigned int max_cpus)
{
	smp_ops.smp_cpus_done(max_cpus);
}

118
static inline int __cpu_up(unsigned int cpu, struct task_struct *tidle)
G
Glauber Costa 已提交
119
{
120
	return smp_ops.cpu_up(cpu, tidle);
G
Glauber Costa 已提交
121 122
}

123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
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 已提交
138 139 140 141
static inline void smp_send_reschedule(int cpu)
{
	smp_ops.smp_send_reschedule(cpu);
}
142

143 144 145 146 147
static inline void arch_send_call_function_single_ipi(int cpu)
{
	smp_ops.send_call_func_single_ipi(cpu);
}

148
static inline void arch_send_call_function_ipi_mask(const struct cpumask *mask)
149
{
150
	smp_ops.send_call_func_ipi(mask);
151
}
G
Glauber Costa 已提交
152

153
void cpu_disable_common(void);
G
Glauber Costa 已提交
154
void native_smp_prepare_boot_cpu(void);
G
Glauber Costa 已提交
155
void native_smp_prepare_cpus(unsigned int max_cpus);
G
Glauber Costa 已提交
156
void native_smp_cpus_done(unsigned int max_cpus);
157
int native_cpu_up(unsigned int cpunum, struct task_struct *tidle);
158 159 160
int native_cpu_disable(void);
void native_cpu_die(unsigned int cpu);
void native_play_dead(void);
161
void play_dead_common(void);
162 163
void wbinvd_on_cpu(int cpu);
int wbinvd_on_all_cpus(void);
164

165
void native_send_call_func_ipi(const struct cpumask *mask);
166
void native_send_call_func_single_ipi(int cpu);
167
void x86_idle_thread_init(unsigned int cpu, struct task_struct *idle);
168

169
void smp_store_cpu_info(int id);
170
#define cpu_physical_id(cpu)	per_cpu(x86_cpu_to_apicid, cpu)
171 172 173 174

/* We don't mark CPUs online until __cpu_up(), so we need another measure */
static inline int num_booting_cpus(void)
{
175
	return cpumask_weight(cpu_callout_mask);
176
}
177 178 179 180 181 182 183
#else /* !CONFIG_SMP */
#define wbinvd_on_cpu(cpu)     wbinvd()
static inline int wbinvd_on_all_cpus(void)
{
	wbinvd();
	return 0;
}
184
#endif /* CONFIG_SMP */
185

186 187
extern unsigned disabled_cpus __cpuinitdata;

188 189 190 191 192 193
#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.
 */
194
#define raw_smp_processor_id() (this_cpu_read(cpu_number))
195 196 197
extern int safe_smp_processor_id(void);

#elif defined(CONFIG_X86_64_SMP)
198
#define raw_smp_processor_id() (this_cpu_read(cpu_number))
199 200 201 202 203 204 205 206 207

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

208
#endif
209

210 211
#ifdef CONFIG_X86_LOCAL_APIC

212
#ifndef CONFIG_X86_64
213 214 215
static inline int logical_smp_processor_id(void)
{
	/* we don't want to mark this access volatile - bad code generation */
216
	return GET_APIC_LOGICAL_ID(apic_read(APIC_LDR));
217 218
}

J
Jack Steiner 已提交
219 220
#endif

221 222 223 224 225 226 227 228 229 230
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 已提交
231 232 233 234 235 236
#ifdef CONFIG_DEBUG_NMI_SELFTEST
extern void nmi_selftest(void);
#else
#define nmi_selftest() do { } while (0)
#endif

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