diff options
Diffstat (limited to 'arch/x86/lib/msr.c')
-rw-r--r-- | arch/x86/lib/msr.c | 227 |
1 files changed, 12 insertions, 215 deletions
diff --git a/arch/x86/lib/msr.c b/arch/x86/lib/msr.c index 33a1e3ca22d8..8f8eebdca7d4 100644 --- a/arch/x86/lib/msr.c +++ b/arch/x86/lib/msr.c | |||
@@ -1,226 +1,23 @@ | |||
1 | #include <linux/module.h> | 1 | #include <linux/module.h> |
2 | #include <linux/preempt.h> | 2 | #include <linux/preempt.h> |
3 | #include <linux/smp.h> | ||
4 | #include <asm/msr.h> | 3 | #include <asm/msr.h> |
5 | 4 | ||
6 | struct msr_info { | 5 | struct msr *msrs_alloc(void) |
7 | u32 msr_no; | ||
8 | struct msr reg; | ||
9 | struct msr *msrs; | ||
10 | int off; | ||
11 | int err; | ||
12 | }; | ||
13 | |||
14 | static void __rdmsr_on_cpu(void *info) | ||
15 | { | ||
16 | struct msr_info *rv = info; | ||
17 | struct msr *reg; | ||
18 | int this_cpu = raw_smp_processor_id(); | ||
19 | |||
20 | if (rv->msrs) | ||
21 | reg = &rv->msrs[this_cpu - rv->off]; | ||
22 | else | ||
23 | reg = &rv->reg; | ||
24 | |||
25 | rdmsr(rv->msr_no, reg->l, reg->h); | ||
26 | } | ||
27 | |||
28 | static void __wrmsr_on_cpu(void *info) | ||
29 | { | ||
30 | struct msr_info *rv = info; | ||
31 | struct msr *reg; | ||
32 | int this_cpu = raw_smp_processor_id(); | ||
33 | |||
34 | if (rv->msrs) | ||
35 | reg = &rv->msrs[this_cpu - rv->off]; | ||
36 | else | ||
37 | reg = &rv->reg; | ||
38 | |||
39 | wrmsr(rv->msr_no, reg->l, reg->h); | ||
40 | } | ||
41 | |||
42 | int rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h) | ||
43 | { | ||
44 | int err; | ||
45 | struct msr_info rv; | ||
46 | |||
47 | memset(&rv, 0, sizeof(rv)); | ||
48 | |||
49 | rv.msr_no = msr_no; | ||
50 | err = smp_call_function_single(cpu, __rdmsr_on_cpu, &rv, 1); | ||
51 | *l = rv.reg.l; | ||
52 | *h = rv.reg.h; | ||
53 | |||
54 | return err; | ||
55 | } | ||
56 | EXPORT_SYMBOL(rdmsr_on_cpu); | ||
57 | |||
58 | int wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h) | ||
59 | { | ||
60 | int err; | ||
61 | struct msr_info rv; | ||
62 | |||
63 | memset(&rv, 0, sizeof(rv)); | ||
64 | |||
65 | rv.msr_no = msr_no; | ||
66 | rv.reg.l = l; | ||
67 | rv.reg.h = h; | ||
68 | err = smp_call_function_single(cpu, __wrmsr_on_cpu, &rv, 1); | ||
69 | |||
70 | return err; | ||
71 | } | ||
72 | EXPORT_SYMBOL(wrmsr_on_cpu); | ||
73 | |||
74 | /* rdmsr on a bunch of CPUs | ||
75 | * | ||
76 | * @mask: which CPUs | ||
77 | * @msr_no: which MSR | ||
78 | * @msrs: array of MSR values | ||
79 | * | ||
80 | */ | ||
81 | void rdmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs) | ||
82 | { | ||
83 | struct msr_info rv; | ||
84 | int this_cpu; | ||
85 | |||
86 | memset(&rv, 0, sizeof(rv)); | ||
87 | |||
88 | rv.off = cpumask_first(mask); | ||
89 | rv.msrs = msrs; | ||
90 | rv.msr_no = msr_no; | ||
91 | |||
92 | this_cpu = get_cpu(); | ||
93 | |||
94 | if (cpumask_test_cpu(this_cpu, mask)) | ||
95 | __rdmsr_on_cpu(&rv); | ||
96 | |||
97 | smp_call_function_many(mask, __rdmsr_on_cpu, &rv, 1); | ||
98 | put_cpu(); | ||
99 | } | ||
100 | EXPORT_SYMBOL(rdmsr_on_cpus); | ||
101 | |||
102 | /* | ||
103 | * wrmsr on a bunch of CPUs | ||
104 | * | ||
105 | * @mask: which CPUs | ||
106 | * @msr_no: which MSR | ||
107 | * @msrs: array of MSR values | ||
108 | * | ||
109 | */ | ||
110 | void wrmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs) | ||
111 | { | ||
112 | struct msr_info rv; | ||
113 | int this_cpu; | ||
114 | |||
115 | memset(&rv, 0, sizeof(rv)); | ||
116 | |||
117 | rv.off = cpumask_first(mask); | ||
118 | rv.msrs = msrs; | ||
119 | rv.msr_no = msr_no; | ||
120 | |||
121 | this_cpu = get_cpu(); | ||
122 | |||
123 | if (cpumask_test_cpu(this_cpu, mask)) | ||
124 | __wrmsr_on_cpu(&rv); | ||
125 | |||
126 | smp_call_function_many(mask, __wrmsr_on_cpu, &rv, 1); | ||
127 | put_cpu(); | ||
128 | } | ||
129 | EXPORT_SYMBOL(wrmsr_on_cpus); | ||
130 | |||
131 | /* These "safe" variants are slower and should be used when the target MSR | ||
132 | may not actually exist. */ | ||
133 | static void __rdmsr_safe_on_cpu(void *info) | ||
134 | { | ||
135 | struct msr_info *rv = info; | ||
136 | |||
137 | rv->err = rdmsr_safe(rv->msr_no, &rv->reg.l, &rv->reg.h); | ||
138 | } | ||
139 | |||
140 | static void __wrmsr_safe_on_cpu(void *info) | ||
141 | { | ||
142 | struct msr_info *rv = info; | ||
143 | |||
144 | rv->err = wrmsr_safe(rv->msr_no, rv->reg.l, rv->reg.h); | ||
145 | } | ||
146 | |||
147 | int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h) | ||
148 | { | 6 | { |
149 | int err; | 7 | struct msr *msrs = NULL; |
150 | struct msr_info rv; | ||
151 | 8 | ||
152 | memset(&rv, 0, sizeof(rv)); | 9 | msrs = alloc_percpu(struct msr); |
10 | if (!msrs) { | ||
11 | pr_warning("%s: error allocating msrs\n", __func__); | ||
12 | return NULL; | ||
13 | } | ||
153 | 14 | ||
154 | rv.msr_no = msr_no; | 15 | return msrs; |
155 | err = smp_call_function_single(cpu, __rdmsr_safe_on_cpu, &rv, 1); | ||
156 | *l = rv.reg.l; | ||
157 | *h = rv.reg.h; | ||
158 | |||
159 | return err ? err : rv.err; | ||
160 | } | 16 | } |
161 | EXPORT_SYMBOL(rdmsr_safe_on_cpu); | 17 | EXPORT_SYMBOL(msrs_alloc); |
162 | 18 | ||
163 | int wrmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h) | 19 | void msrs_free(struct msr *msrs) |
164 | { | 20 | { |
165 | int err; | 21 | free_percpu(msrs); |
166 | struct msr_info rv; | ||
167 | |||
168 | memset(&rv, 0, sizeof(rv)); | ||
169 | |||
170 | rv.msr_no = msr_no; | ||
171 | rv.reg.l = l; | ||
172 | rv.reg.h = h; | ||
173 | err = smp_call_function_single(cpu, __wrmsr_safe_on_cpu, &rv, 1); | ||
174 | |||
175 | return err ? err : rv.err; | ||
176 | } | ||
177 | EXPORT_SYMBOL(wrmsr_safe_on_cpu); | ||
178 | |||
179 | /* | ||
180 | * These variants are significantly slower, but allows control over | ||
181 | * the entire 32-bit GPR set. | ||
182 | */ | ||
183 | struct msr_regs_info { | ||
184 | u32 *regs; | ||
185 | int err; | ||
186 | }; | ||
187 | |||
188 | static void __rdmsr_safe_regs_on_cpu(void *info) | ||
189 | { | ||
190 | struct msr_regs_info *rv = info; | ||
191 | |||
192 | rv->err = rdmsr_safe_regs(rv->regs); | ||
193 | } | ||
194 | |||
195 | static void __wrmsr_safe_regs_on_cpu(void *info) | ||
196 | { | ||
197 | struct msr_regs_info *rv = info; | ||
198 | |||
199 | rv->err = wrmsr_safe_regs(rv->regs); | ||
200 | } | ||
201 | |||
202 | int rdmsr_safe_regs_on_cpu(unsigned int cpu, u32 *regs) | ||
203 | { | ||
204 | int err; | ||
205 | struct msr_regs_info rv; | ||
206 | |||
207 | rv.regs = regs; | ||
208 | rv.err = -EIO; | ||
209 | err = smp_call_function_single(cpu, __rdmsr_safe_regs_on_cpu, &rv, 1); | ||
210 | |||
211 | return err ? err : rv.err; | ||
212 | } | ||
213 | EXPORT_SYMBOL(rdmsr_safe_regs_on_cpu); | ||
214 | |||
215 | int wrmsr_safe_regs_on_cpu(unsigned int cpu, u32 *regs) | ||
216 | { | ||
217 | int err; | ||
218 | struct msr_regs_info rv; | ||
219 | |||
220 | rv.regs = regs; | ||
221 | rv.err = -EIO; | ||
222 | err = smp_call_function_single(cpu, __wrmsr_safe_regs_on_cpu, &rv, 1); | ||
223 | |||
224 | return err ? err : rv.err; | ||
225 | } | 22 | } |
226 | EXPORT_SYMBOL(wrmsr_safe_regs_on_cpu); | 23 | EXPORT_SYMBOL(msrs_free); |