x86_32: use generic percpu.h
[wrt350n-kernel.git] / include / asm-x86 / percpu_32.h
blobe62ce2fe2c9cc519a8717d5affe79f6f462a6908
1 #ifndef __ARCH_I386_PERCPU__
2 #define __ARCH_I386_PERCPU__
4 #ifdef __ASSEMBLY__
6 /*
7 * PER_CPU finds an address of a per-cpu variable.
9 * Args:
10 * var - variable name
11 * reg - 32bit register
13 * The resulting address is stored in the "reg" argument.
15 * Example:
16 * PER_CPU(cpu_gdt_descr, %ebx)
18 #ifdef CONFIG_SMP
19 #define PER_CPU(var, reg) \
20 movl %fs:per_cpu__##this_cpu_off, reg; \
21 lea per_cpu__##var(reg), reg
22 #define PER_CPU_VAR(var) %fs:per_cpu__##var
23 #else /* ! SMP */
24 #define PER_CPU(var, reg) \
25 movl $per_cpu__##var, reg
26 #define PER_CPU_VAR(var) per_cpu__##var
27 #endif /* SMP */
29 #else /* ...!ASSEMBLY */
32 * PER_CPU finds an address of a per-cpu variable.
34 * Args:
35 * var - variable name
36 * cpu - 32bit register containing the current CPU number
38 * The resulting address is stored in the "cpu" argument.
40 * Example:
41 * PER_CPU(cpu_gdt_descr, %ebx)
43 #ifdef CONFIG_SMP
45 #define __my_cpu_offset x86_read_percpu(this_cpu_off)
47 /* A macro to avoid #include hell... */
48 #define percpu_modcopy(pcpudst, src, size) \
49 do { \
50 unsigned int __i; \
51 for_each_possible_cpu(__i) \
52 memcpy((pcpudst)+__per_cpu_offset[__i], \
53 (src), (size)); \
54 } while (0)
56 /* fs segment starts at (positive) offset == __per_cpu_offset[cpu] */
57 #define __percpu_seg "%%fs:"
59 #else /* !SMP */
61 #define __percpu_seg ""
63 #endif /* SMP */
65 #include <asm-generic/percpu.h>
67 /* We can use this directly for local CPU (faster). */
68 DECLARE_PER_CPU(unsigned long, this_cpu_off);
70 /* For arch-specific code, we can use direct single-insn ops (they
71 * don't give an lvalue though). */
72 extern void __bad_percpu_size(void);
74 #define percpu_to_op(op,var,val) \
75 do { \
76 typedef typeof(var) T__; \
77 if (0) { T__ tmp__; tmp__ = (val); } \
78 switch (sizeof(var)) { \
79 case 1: \
80 asm(op "b %1,"__percpu_seg"%0" \
81 : "+m" (var) \
82 :"ri" ((T__)val)); \
83 break; \
84 case 2: \
85 asm(op "w %1,"__percpu_seg"%0" \
86 : "+m" (var) \
87 :"ri" ((T__)val)); \
88 break; \
89 case 4: \
90 asm(op "l %1,"__percpu_seg"%0" \
91 : "+m" (var) \
92 :"ri" ((T__)val)); \
93 break; \
94 default: __bad_percpu_size(); \
95 } \
96 } while (0)
98 #define percpu_from_op(op,var) \
99 ({ \
100 typeof(var) ret__; \
101 switch (sizeof(var)) { \
102 case 1: \
103 asm(op "b "__percpu_seg"%1,%0" \
104 : "=r" (ret__) \
105 : "m" (var)); \
106 break; \
107 case 2: \
108 asm(op "w "__percpu_seg"%1,%0" \
109 : "=r" (ret__) \
110 : "m" (var)); \
111 break; \
112 case 4: \
113 asm(op "l "__percpu_seg"%1,%0" \
114 : "=r" (ret__) \
115 : "m" (var)); \
116 break; \
117 default: __bad_percpu_size(); \
119 ret__; })
121 #define x86_read_percpu(var) percpu_from_op("mov", per_cpu__##var)
122 #define x86_write_percpu(var,val) percpu_to_op("mov", per_cpu__##var, val)
123 #define x86_add_percpu(var,val) percpu_to_op("add", per_cpu__##var, val)
124 #define x86_sub_percpu(var,val) percpu_to_op("sub", per_cpu__##var, val)
125 #define x86_or_percpu(var,val) percpu_to_op("or", per_cpu__##var, val)
126 #endif /* !__ASSEMBLY__ */
128 #endif /* __ARCH_I386_PERCPU__ */