diff options
-rw-r--r-- | include/asm-x86/percpu.h | 145 | ||||
-rw-r--r-- | include/asm-x86/percpu_32.h | 128 | ||||
-rw-r--r-- | include/asm-x86/percpu_64.h | 32 |
3 files changed, 141 insertions, 164 deletions
diff --git a/include/asm-x86/percpu.h b/include/asm-x86/percpu.h index a1aaad274cca..0dec00f27eb4 100644 --- a/include/asm-x86/percpu.h +++ b/include/asm-x86/percpu.h | |||
@@ -1,5 +1,142 @@ | |||
1 | #ifdef CONFIG_X86_32 | 1 | #ifndef _ASM_X86_PERCPU_H_ |
2 | # include "percpu_32.h" | 2 | #define _ASM_X86_PERCPU_H_ |
3 | #else | 3 | |
4 | # include "percpu_64.h" | 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 | |||
5 | #endif | 20 | #endif |
21 | #include <asm-generic/percpu.h> | ||
22 | |||
23 | DECLARE_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). */ | ||
82 | DECLARE_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). */ | ||
86 | extern void __bad_percpu_size(void); | ||
87 | |||
88 | #define percpu_to_op(op,var,val) \ | ||
89 | do { \ | ||
90 | typedef typeof(var) T__; \ | ||
91 | if (0) { T__ tmp__; tmp__ = (val); } \ | ||
92 | switch (sizeof(var)) { \ | ||
93 | case 1: \ | ||
94 | asm(op "b %1,"__percpu_seg"%0" \ | ||
95 | : "+m" (var) \ | ||
96 | :"ri" ((T__)val)); \ | ||
97 | break; \ | ||
98 | case 2: \ | ||
99 | asm(op "w %1,"__percpu_seg"%0" \ | ||
100 | : "+m" (var) \ | ||
101 | :"ri" ((T__)val)); \ | ||
102 | break; \ | ||
103 | case 4: \ | ||
104 | asm(op "l %1,"__percpu_seg"%0" \ | ||
105 | : "+m" (var) \ | ||
106 | :"ri" ((T__)val)); \ | ||
107 | break; \ | ||
108 | default: __bad_percpu_size(); \ | ||
109 | } \ | ||
110 | } while (0) | ||
111 | |||
112 | #define percpu_from_op(op,var) \ | ||
113 | ({ \ | ||
114 | typeof(var) ret__; \ | ||
115 | switch (sizeof(var)) { \ | ||
116 | case 1: \ | ||
117 | asm(op "b "__percpu_seg"%1,%0" \ | ||
118 | : "=r" (ret__) \ | ||
119 | : "m" (var)); \ | ||
120 | break; \ | ||
121 | case 2: \ | ||
122 | asm(op "w "__percpu_seg"%1,%0" \ | ||
123 | : "=r" (ret__) \ | ||
124 | : "m" (var)); \ | ||
125 | break; \ | ||
126 | case 4: \ | ||
127 | asm(op "l "__percpu_seg"%1,%0" \ | ||
128 | : "=r" (ret__) \ | ||
129 | : "m" (var)); \ | ||
130 | break; \ | ||
131 | default: __bad_percpu_size(); \ | ||
132 | } \ | ||
133 | ret__; }) | ||
134 | |||
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_ */ | ||
diff --git a/include/asm-x86/percpu_32.h b/include/asm-x86/percpu_32.h deleted file mode 100644 index e62ce2fe2c9c..000000000000 --- a/include/asm-x86/percpu_32.h +++ /dev/null | |||
@@ -1,128 +0,0 @@ | |||
1 | #ifndef __ARCH_I386_PERCPU__ | ||
2 | #define __ARCH_I386_PERCPU__ | ||
3 | |||
4 | #ifdef __ASSEMBLY__ | ||
5 | |||
6 | /* | ||
7 | * PER_CPU finds an address of a per-cpu variable. | ||
8 | * | ||
9 | * Args: | ||
10 | * var - variable name | ||
11 | * reg - 32bit register | ||
12 | * | ||
13 | * The resulting address is stored in the "reg" argument. | ||
14 | * | ||
15 | * Example: | ||
16 | * PER_CPU(cpu_gdt_descr, %ebx) | ||
17 | */ | ||
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 */ | ||
28 | |||
29 | #else /* ...!ASSEMBLY */ | ||
30 | |||
31 | /* | ||
32 | * PER_CPU finds an address of a per-cpu variable. | ||
33 | * | ||
34 | * Args: | ||
35 | * var - variable name | ||
36 | * cpu - 32bit register containing the current CPU number | ||
37 | * | ||
38 | * The resulting address is stored in the "cpu" argument. | ||
39 | * | ||
40 | * Example: | ||
41 | * PER_CPU(cpu_gdt_descr, %ebx) | ||
42 | */ | ||
43 | #ifdef CONFIG_SMP | ||
44 | |||
45 | #define __my_cpu_offset x86_read_percpu(this_cpu_off) | ||
46 | |||
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) | ||
55 | |||
56 | /* fs segment starts at (positive) offset == __per_cpu_offset[cpu] */ | ||
57 | #define __percpu_seg "%%fs:" | ||
58 | |||
59 | #else /* !SMP */ | ||
60 | |||
61 | #define __percpu_seg "" | ||
62 | |||
63 | #endif /* SMP */ | ||
64 | |||
65 | #include <asm-generic/percpu.h> | ||
66 | |||
67 | /* We can use this directly for local CPU (faster). */ | ||
68 | DECLARE_PER_CPU(unsigned long, this_cpu_off); | ||
69 | |||
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); | ||
73 | |||
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) | ||
97 | |||
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(); \ | ||
118 | } \ | ||
119 | ret__; }) | ||
120 | |||
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__ */ | ||
127 | |||
128 | #endif /* __ARCH_I386_PERCPU__ */ | ||
diff --git a/include/asm-x86/percpu_64.h b/include/asm-x86/percpu_64.h deleted file mode 100644 index e7f3f6d21759..000000000000 --- a/include/asm-x86/percpu_64.h +++ /dev/null | |||
@@ -1,32 +0,0 @@ | |||
1 | #ifndef _ASM_X8664_PERCPU_H_ | ||
2 | #define _ASM_X8664_PERCPU_H_ | ||
3 | #include <linux/compiler.h> | ||
4 | |||
5 | /* Same as asm-generic/percpu.h, except that we store the per cpu offset | ||
6 | in the PDA. Longer term the PDA and every per cpu variable | ||
7 | should be just put into a single section and referenced directly | ||
8 | from %gs */ | ||
9 | |||
10 | #ifdef CONFIG_SMP | ||
11 | |||
12 | #include <asm/pda.h> | ||
13 | |||
14 | #define __per_cpu_offset(cpu) (cpu_pda(cpu)->data_offset) | ||
15 | #define __my_cpu_offset read_pda(data_offset) | ||
16 | |||
17 | #define per_cpu_offset(x) (__per_cpu_offset(x)) | ||
18 | |||
19 | /* A macro to avoid #include hell... */ | ||
20 | #define percpu_modcopy(pcpudst, src, size) \ | ||
21 | do { \ | ||
22 | unsigned int __i; \ | ||
23 | for_each_possible_cpu(__i) \ | ||
24 | memcpy((pcpudst)+__per_cpu_offset(__i), \ | ||
25 | (src), (size)); \ | ||
26 | } while (0) | ||
27 | |||
28 | #endif /* SMP */ | ||
29 | |||
30 | #include <asm-generic/percpu.h> | ||
31 | |||
32 | #endif /* _ASM_X8664_PERCPU_H_ */ | ||