smp.h 5.3 KB
Newer Older
G
Glauber Costa 已提交
1 2 3
#ifndef _ASM_X86_SMP_H_
#define _ASM_X86_SMP_H_
#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

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

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

47 48 49 50 51 52 53
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);
54

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

60 61
	void (*send_call_func_ipi)(cpumask_t mask);
	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
#ifdef CONFIG_SMP
68 69 70
#ifndef CONFIG_PARAVIRT
#define startup_ipi_hook(phys_apicid, start_eip, start_esp) do { } while (0)
#endif
71
extern struct smp_ops smp_ops;
G
Glauber Costa 已提交
72

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

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

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

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

G
Glauber Costa 已提交
93 94 95 96 97
static inline int __cpu_up(unsigned int cpu)
{
	return smp_ops.cpu_up(cpu);
}

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

118 119 120 121 122 123
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)
124
{
125
	smp_ops.send_call_func_ipi(mask);
126
}
G
Glauber Costa 已提交
127

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

138 139
void native_send_call_func_ipi(cpumask_t mask);
void native_send_call_func_single_ipi(int cpu);
140

141
void smp_store_cpu_info(int id);
142
#define cpu_physical_id(cpu)	per_cpu(x86_cpu_to_apicid, cpu)
143 144 145 146 147 148

/* 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);
}
149 150 151 152
#endif /* CONFIG_SMP */

#if defined(CONFIG_SMP) && defined(CONFIG_HOTPLUG_CPU)
extern void prefill_possible_map(void);
153 154 155 156
#else
static inline void prefill_possible_map(void)
{
}
157
#endif
158

159 160
extern unsigned disabled_cpus __cpuinitdata;

161 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.
 */
DECLARE_PER_CPU(int, cpu_number);
#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 190 191 192 193 194 195
#ifdef CONFIG_X86_LOCAL_APIC

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));
}

I
Ingo Molnar 已提交
196
#ifndef CONFIG_X86_64
197 198 199 200
static inline unsigned int read_apic_id(void)
{
	return *(u32 *)(APIC_BASE + APIC_ID);
}
J
Jack Steiner 已提交
201 202 203 204
#else
extern unsigned int read_apic_id(void);
#endif

205

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

#else /* CONFIG_X86_LOCAL_APIC */

# ifndef CONFIG_SMP
#  define hard_smp_processor_id()	0
# endif

#endif /* CONFIG_X86_LOCAL_APIC */

225
#ifdef CONFIG_HOTPLUG_CPU
A
Alex Nixon 已提交
226 227 228 229 230 231
#ifdef CONFIG_X86_32
extern void reset_lazy_tlbstate(void);
#else
static inline void reset_lazy_tlbstate(void)
{ }
#endif /* CONFIG_X86_32 */
232 233
#endif

G
Glauber Costa 已提交
234 235
#endif /* __ASSEMBLY__ */
#endif