1 #ifndef _ASM_X86_PERCPU_H_
2 #define _ASM_X86_PERCPU_H_
5 #include <linux/compiler.h>
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
15 #define __per_cpu_offset(cpu) (cpu_pda(cpu)->data_offset)
16 #define __my_cpu_offset read_pda(data_offset)
18 #define per_cpu_offset(x) (__per_cpu_offset(x))
21 #include <asm-generic/percpu.h>
23 DECLARE_PER_CPU(struct x8664_pda, pda);
25 #else /* CONFIG_X86_64 */
30 * PER_CPU finds an address of a per-cpu variable.
34 * reg - 32bit register
36 * The resulting address is stored in the "reg" argument.
39 * PER_CPU(cpu_gdt_descr, %ebx)
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
47 #define PER_CPU(var, reg) \
48 movl $per_cpu__##var, reg
49 #define PER_CPU_VAR(var) per_cpu__##var
52 #else /* ...!ASSEMBLY */
55 * PER_CPU finds an address of a per-cpu variable.
59 * cpu - 32bit register containing the current CPU number
61 * The resulting address is stored in the "cpu" argument.
64 * PER_CPU(cpu_gdt_descr, %ebx)
68 #define __my_cpu_offset x86_read_percpu(this_cpu_off)
70 /* fs segment starts at (positive) offset == __per_cpu_offset[cpu] */
71 #define __percpu_seg "%%fs:"
75 #define __percpu_seg ""
79 #include <asm-generic/percpu.h>
81 /* We can use this directly for local CPU (faster). */
82 DECLARE_PER_CPU(unsigned long, this_cpu_off);
84 /* For arch-specific code, we can use direct single-insn ops (they
85 * don't give an lvalue though). */
86 extern void __bad_percpu_size(void);
88 #define percpu_to_op(op,var,val) \
90 typedef typeof(var) T__; \
91 if (0) { T__ tmp__; tmp__ = (val); } \
92 switch (sizeof(var)) { \
94 asm(op "b %1,"__percpu_seg"%0" \
99 asm(op "w %1,"__percpu_seg"%0" \
104 asm(op "l %1,"__percpu_seg"%0" \
108 default: __bad_percpu_size(); \
112 #define percpu_from_op(op,var) \
115 switch (sizeof(var)) { \
117 asm(op "b "__percpu_seg"%1,%0" \
122 asm(op "w "__percpu_seg"%1,%0" \
127 asm(op "l "__percpu_seg"%1,%0" \
131 default: __bad_percpu_size(); \
135 #define x86_read_percpu(var) percpu_from_op("mov", per_cpu__##var)
136 #define x86_write_percpu(var,val) percpu_to_op("mov", per_cpu__##var, val)
137 #define x86_add_percpu(var,val) percpu_to_op("add", per_cpu__##var, val)
138 #define x86_sub_percpu(var,val) percpu_to_op("sub", per_cpu__##var, val)
139 #define x86_or_percpu(var,val) percpu_to_op("or", per_cpu__##var, val)
140 #endif /* !__ASSEMBLY__ */
141 #endif /* !CONFIG_X86_64 */
142 #endif /* _ASM_X86_PERCPU_H_ */