blob: 912a3a17b9db85958abee1464d58e64d798f5f31 [file] [log] [blame]
travis@sgi.com33340522008-01-30 13:32:53 +01001#ifndef _ASM_X86_PERCPU_H_
2#define _ASM_X86_PERCPU_H_
3
4#ifdef CONFIG_X86_64
5#include <linux/compiler.h>
6
7/* Same as asm-generic/percpu.h, except that we store the per cpu offset
8 in the PDA. Longer term the PDA and every per cpu variable
9 should be just put into a single section and referenced directly
10 from %gs */
11
12#ifdef CONFIG_SMP
13#include <asm/pda.h>
14
15#define __per_cpu_offset(cpu) (cpu_pda(cpu)->data_offset)
16#define __my_cpu_offset read_pda(data_offset)
17
18#define per_cpu_offset(x) (__per_cpu_offset(x))
19
Thomas Gleixner96a388d2007-10-11 11:20:03 +020020#endif
travis@sgi.com33340522008-01-30 13:32:53 +010021#include <asm-generic/percpu.h>
22
23DECLARE_PER_CPU(struct x8664_pda, pda);
24
25#else /* CONFIG_X86_64 */
26
27#ifdef __ASSEMBLY__
28
29/*
30 * PER_CPU finds an address of a per-cpu variable.
31 *
32 * Args:
33 * var - variable name
34 * reg - 32bit register
35 *
36 * The resulting address is stored in the "reg" argument.
37 *
38 * Example:
39 * PER_CPU(cpu_gdt_descr, %ebx)
40 */
41#ifdef CONFIG_SMP
42#define PER_CPU(var, reg) \
43 movl %fs:per_cpu__##this_cpu_off, reg; \
44 lea per_cpu__##var(reg), reg
45#define PER_CPU_VAR(var) %fs:per_cpu__##var
46#else /* ! SMP */
47#define PER_CPU(var, reg) \
48 movl $per_cpu__##var, reg
49#define PER_CPU_VAR(var) per_cpu__##var
50#endif /* SMP */
51
52#else /* ...!ASSEMBLY */
53
54/*
55 * PER_CPU finds an address of a per-cpu variable.
56 *
57 * Args:
58 * var - variable name
59 * cpu - 32bit register containing the current CPU number
60 *
61 * The resulting address is stored in the "cpu" argument.
62 *
63 * Example:
64 * PER_CPU(cpu_gdt_descr, %ebx)
65 */
66#ifdef CONFIG_SMP
67
68#define __my_cpu_offset x86_read_percpu(this_cpu_off)
69
70/* fs segment starts at (positive) offset == __per_cpu_offset[cpu] */
71#define __percpu_seg "%%fs:"
72
73#else /* !SMP */
74
75#define __percpu_seg ""
76
77#endif /* SMP */
78
79#include <asm-generic/percpu.h>
80
81/* We can use this directly for local CPU (faster). */
82DECLARE_PER_CPU(unsigned long, this_cpu_off);
83
84/* For arch-specific code, we can use direct single-insn ops (they
85 * don't give an lvalue though). */
86extern void __bad_percpu_size(void);
87
Joe Perchesbc9e3be2008-03-23 01:03:06 -070088#define percpu_to_op(op, var, val) \
89do { \
90 typedef typeof(var) T__; \
91 if (0) { \
92 T__ tmp__; \
93 tmp__ = (val); \
94 } \
95 switch (sizeof(var)) { \
96 case 1: \
97 asm(op "b %1,"__percpu_seg"%0" \
98 : "+m" (var) \
99 : "ri" ((T__)val)); \
100 break; \
101 case 2: \
102 asm(op "w %1,"__percpu_seg"%0" \
103 : "+m" (var) \
104 : "ri" ((T__)val)); \
105 break; \
106 case 4: \
107 asm(op "l %1,"__percpu_seg"%0" \
108 : "+m" (var) \
109 : "ri" ((T__)val)); \
110 break; \
111 default: __bad_percpu_size(); \
112 } \
113} while (0)
travis@sgi.com33340522008-01-30 13:32:53 +0100114
Joe Perchesbc9e3be2008-03-23 01:03:06 -0700115#define percpu_from_op(op, var) \
116({ \
117 typeof(var) ret__; \
118 switch (sizeof(var)) { \
119 case 1: \
120 asm(op "b "__percpu_seg"%1,%0" \
121 : "=r" (ret__) \
122 : "m" (var)); \
123 break; \
124 case 2: \
125 asm(op "w "__percpu_seg"%1,%0" \
126 : "=r" (ret__) \
127 : "m" (var)); \
128 break; \
129 case 4: \
130 asm(op "l "__percpu_seg"%1,%0" \
131 : "=r" (ret__) \
132 : "m" (var)); \
133 break; \
134 default: __bad_percpu_size(); \
135 } \
136 ret__; \
137})
travis@sgi.com33340522008-01-30 13:32:53 +0100138
139#define x86_read_percpu(var) percpu_from_op("mov", per_cpu__##var)
Joe Perchesbc9e3be2008-03-23 01:03:06 -0700140#define x86_write_percpu(var, val) percpu_to_op("mov", per_cpu__##var, val)
141#define x86_add_percpu(var, val) percpu_to_op("add", per_cpu__##var, val)
142#define x86_sub_percpu(var, val) percpu_to_op("sub", per_cpu__##var, val)
143#define x86_or_percpu(var, val) percpu_to_op("or", per_cpu__##var, val)
travis@sgi.com33340522008-01-30 13:32:53 +0100144#endif /* !__ASSEMBLY__ */
145#endif /* !CONFIG_X86_64 */
Mike Travis23ca4bb2008-05-12 21:21:12 +0200146
147#ifdef CONFIG_SMP
148
149/*
150 * Define the "EARLY_PER_CPU" macros. These are used for some per_cpu
151 * variables that are initialized and accessed before there are per_cpu
152 * areas allocated.
153 */
154
155#define DEFINE_EARLY_PER_CPU(_type, _name, _initvalue) \
156 DEFINE_PER_CPU(_type, _name) = _initvalue; \
157 __typeof__(_type) _name##_early_map[NR_CPUS] __initdata = \
158 { [0 ... NR_CPUS-1] = _initvalue }; \
159 __typeof__(_type) *_name##_early_ptr = _name##_early_map
160
161#define EXPORT_EARLY_PER_CPU_SYMBOL(_name) \
162 EXPORT_PER_CPU_SYMBOL(_name)
163
164#define DECLARE_EARLY_PER_CPU(_type, _name) \
165 DECLARE_PER_CPU(_type, _name); \
166 extern __typeof__(_type) *_name##_early_ptr; \
167 extern __typeof__(_type) _name##_early_map[]
168
169#define early_per_cpu_ptr(_name) (_name##_early_ptr)
170#define early_per_cpu_map(_name, _idx) (_name##_early_map[_idx])
171#define early_per_cpu(_name, _cpu) \
172 (early_per_cpu_ptr(_name) ? \
173 early_per_cpu_ptr(_name)[_cpu] : \
174 per_cpu(_name, _cpu))
175
176#else /* !CONFIG_SMP */
177#define DEFINE_EARLY_PER_CPU(_type, _name, _initvalue) \
178 DEFINE_PER_CPU(_type, _name) = _initvalue
179
180#define EXPORT_EARLY_PER_CPU_SYMBOL(_name) \
181 EXPORT_PER_CPU_SYMBOL(_name)
182
183#define DECLARE_EARLY_PER_CPU(_type, _name) \
184 DECLARE_PER_CPU(_type, _name)
185
186#define early_per_cpu(_name, _cpu) per_cpu(_name, _cpu)
187#define early_per_cpu_ptr(_name) NULL
188/* no early_per_cpu_map() */
189
190#endif /* !CONFIG_SMP */
191
travis@sgi.com33340522008-01-30 13:32:53 +0100192#endif /* _ASM_X86_PERCPU_H_ */