x86/topology: Update the 'cpu cores' field in /proc/cpuinfo correctly across CPU...
[cris-mirror.git] / arch / x86 / lib / msr-smp.c
blob693cce0be82dffb822cecd0c7e38d2821aff896c
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/export.h>
3 #include <linux/preempt.h>
4 #include <linux/smp.h>
5 #include <asm/msr.h>
7 static void __rdmsr_on_cpu(void *info)
9 struct msr_info *rv = info;
10 struct msr *reg;
11 int this_cpu = raw_smp_processor_id();
13 if (rv->msrs)
14 reg = per_cpu_ptr(rv->msrs, this_cpu);
15 else
16 reg = &rv->reg;
18 rdmsr(rv->msr_no, reg->l, reg->h);
21 static void __wrmsr_on_cpu(void *info)
23 struct msr_info *rv = info;
24 struct msr *reg;
25 int this_cpu = raw_smp_processor_id();
27 if (rv->msrs)
28 reg = per_cpu_ptr(rv->msrs, this_cpu);
29 else
30 reg = &rv->reg;
32 wrmsr(rv->msr_no, reg->l, reg->h);
35 int rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h)
37 int err;
38 struct msr_info rv;
40 memset(&rv, 0, sizeof(rv));
42 rv.msr_no = msr_no;
43 err = smp_call_function_single(cpu, __rdmsr_on_cpu, &rv, 1);
44 *l = rv.reg.l;
45 *h = rv.reg.h;
47 return err;
49 EXPORT_SYMBOL(rdmsr_on_cpu);
51 int rdmsrl_on_cpu(unsigned int cpu, u32 msr_no, u64 *q)
53 int err;
54 struct msr_info rv;
56 memset(&rv, 0, sizeof(rv));
58 rv.msr_no = msr_no;
59 err = smp_call_function_single(cpu, __rdmsr_on_cpu, &rv, 1);
60 *q = rv.reg.q;
62 return err;
64 EXPORT_SYMBOL(rdmsrl_on_cpu);
66 int wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h)
68 int err;
69 struct msr_info rv;
71 memset(&rv, 0, sizeof(rv));
73 rv.msr_no = msr_no;
74 rv.reg.l = l;
75 rv.reg.h = h;
76 err = smp_call_function_single(cpu, __wrmsr_on_cpu, &rv, 1);
78 return err;
80 EXPORT_SYMBOL(wrmsr_on_cpu);
82 int wrmsrl_on_cpu(unsigned int cpu, u32 msr_no, u64 q)
84 int err;
85 struct msr_info rv;
87 memset(&rv, 0, sizeof(rv));
89 rv.msr_no = msr_no;
90 rv.reg.q = q;
92 err = smp_call_function_single(cpu, __wrmsr_on_cpu, &rv, 1);
94 return err;
96 EXPORT_SYMBOL(wrmsrl_on_cpu);
98 static void __rwmsr_on_cpus(const struct cpumask *mask, u32 msr_no,
99 struct msr *msrs,
100 void (*msr_func) (void *info))
102 struct msr_info rv;
103 int this_cpu;
105 memset(&rv, 0, sizeof(rv));
107 rv.msrs = msrs;
108 rv.msr_no = msr_no;
110 this_cpu = get_cpu();
112 if (cpumask_test_cpu(this_cpu, mask))
113 msr_func(&rv);
115 smp_call_function_many(mask, msr_func, &rv, 1);
116 put_cpu();
119 /* rdmsr on a bunch of CPUs
121 * @mask: which CPUs
122 * @msr_no: which MSR
123 * @msrs: array of MSR values
126 void rdmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr *msrs)
128 __rwmsr_on_cpus(mask, msr_no, msrs, __rdmsr_on_cpu);
130 EXPORT_SYMBOL(rdmsr_on_cpus);
133 * wrmsr on a bunch of CPUs
135 * @mask: which CPUs
136 * @msr_no: which MSR
137 * @msrs: array of MSR values
140 void wrmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr *msrs)
142 __rwmsr_on_cpus(mask, msr_no, msrs, __wrmsr_on_cpu);
144 EXPORT_SYMBOL(wrmsr_on_cpus);
146 /* These "safe" variants are slower and should be used when the target MSR
147 may not actually exist. */
148 static void __rdmsr_safe_on_cpu(void *info)
150 struct msr_info *rv = info;
152 rv->err = rdmsr_safe(rv->msr_no, &rv->reg.l, &rv->reg.h);
155 static void __wrmsr_safe_on_cpu(void *info)
157 struct msr_info *rv = info;
159 rv->err = wrmsr_safe(rv->msr_no, rv->reg.l, rv->reg.h);
162 int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h)
164 int err;
165 struct msr_info rv;
167 memset(&rv, 0, sizeof(rv));
169 rv.msr_no = msr_no;
170 err = smp_call_function_single(cpu, __rdmsr_safe_on_cpu, &rv, 1);
171 *l = rv.reg.l;
172 *h = rv.reg.h;
174 return err ? err : rv.err;
176 EXPORT_SYMBOL(rdmsr_safe_on_cpu);
178 int wrmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h)
180 int err;
181 struct msr_info rv;
183 memset(&rv, 0, sizeof(rv));
185 rv.msr_no = msr_no;
186 rv.reg.l = l;
187 rv.reg.h = h;
188 err = smp_call_function_single(cpu, __wrmsr_safe_on_cpu, &rv, 1);
190 return err ? err : rv.err;
192 EXPORT_SYMBOL(wrmsr_safe_on_cpu);
194 int wrmsrl_safe_on_cpu(unsigned int cpu, u32 msr_no, u64 q)
196 int err;
197 struct msr_info rv;
199 memset(&rv, 0, sizeof(rv));
201 rv.msr_no = msr_no;
202 rv.reg.q = q;
204 err = smp_call_function_single(cpu, __wrmsr_safe_on_cpu, &rv, 1);
206 return err ? err : rv.err;
208 EXPORT_SYMBOL(wrmsrl_safe_on_cpu);
210 int rdmsrl_safe_on_cpu(unsigned int cpu, u32 msr_no, u64 *q)
212 int err;
213 struct msr_info rv;
215 memset(&rv, 0, sizeof(rv));
217 rv.msr_no = msr_no;
218 err = smp_call_function_single(cpu, __rdmsr_safe_on_cpu, &rv, 1);
219 *q = rv.reg.q;
221 return err ? err : rv.err;
223 EXPORT_SYMBOL(rdmsrl_safe_on_cpu);
226 * These variants are significantly slower, but allows control over
227 * the entire 32-bit GPR set.
229 static void __rdmsr_safe_regs_on_cpu(void *info)
231 struct msr_regs_info *rv = info;
233 rv->err = rdmsr_safe_regs(rv->regs);
236 static void __wrmsr_safe_regs_on_cpu(void *info)
238 struct msr_regs_info *rv = info;
240 rv->err = wrmsr_safe_regs(rv->regs);
243 int rdmsr_safe_regs_on_cpu(unsigned int cpu, u32 *regs)
245 int err;
246 struct msr_regs_info rv;
248 rv.regs = regs;
249 rv.err = -EIO;
250 err = smp_call_function_single(cpu, __rdmsr_safe_regs_on_cpu, &rv, 1);
252 return err ? err : rv.err;
254 EXPORT_SYMBOL(rdmsr_safe_regs_on_cpu);
256 int wrmsr_safe_regs_on_cpu(unsigned int cpu, u32 *regs)
258 int err;
259 struct msr_regs_info rv;
261 rv.regs = regs;
262 rv.err = -EIO;
263 err = smp_call_function_single(cpu, __wrmsr_safe_regs_on_cpu, &rv, 1);
265 return err ? err : rv.err;
267 EXPORT_SYMBOL(wrmsr_safe_regs_on_cpu);