ARM: OMAP2+: Prepare to move GPMC to drivers by platform data header
[linux/fpc-iii.git] / arch / x86 / lib / msr-smp.c
blob518532e6a3faa213eb0833c6781c9ceba34dea86
1 #include <linux/module.h>
2 #include <linux/preempt.h>
3 #include <linux/smp.h>
4 #include <asm/msr.h>
6 static void __rdmsr_on_cpu(void *info)
8 struct msr_info *rv = info;
9 struct msr *reg;
10 int this_cpu = raw_smp_processor_id();
12 if (rv->msrs)
13 reg = per_cpu_ptr(rv->msrs, this_cpu);
14 else
15 reg = &rv->reg;
17 rdmsr(rv->msr_no, reg->l, reg->h);
20 static void __wrmsr_on_cpu(void *info)
22 struct msr_info *rv = info;
23 struct msr *reg;
24 int this_cpu = raw_smp_processor_id();
26 if (rv->msrs)
27 reg = per_cpu_ptr(rv->msrs, this_cpu);
28 else
29 reg = &rv->reg;
31 wrmsr(rv->msr_no, reg->l, reg->h);
34 int rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h)
36 int err;
37 struct msr_info rv;
39 memset(&rv, 0, sizeof(rv));
41 rv.msr_no = msr_no;
42 err = smp_call_function_single(cpu, __rdmsr_on_cpu, &rv, 1);
43 *l = rv.reg.l;
44 *h = rv.reg.h;
46 return err;
48 EXPORT_SYMBOL(rdmsr_on_cpu);
50 int rdmsrl_on_cpu(unsigned int cpu, u32 msr_no, u64 *q)
52 int err;
53 struct msr_info rv;
55 memset(&rv, 0, sizeof(rv));
57 rv.msr_no = msr_no;
58 err = smp_call_function_single(cpu, __rdmsr_on_cpu, &rv, 1);
59 *q = rv.reg.q;
61 return err;
63 EXPORT_SYMBOL(rdmsrl_on_cpu);
65 int wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h)
67 int err;
68 struct msr_info rv;
70 memset(&rv, 0, sizeof(rv));
72 rv.msr_no = msr_no;
73 rv.reg.l = l;
74 rv.reg.h = h;
75 err = smp_call_function_single(cpu, __wrmsr_on_cpu, &rv, 1);
77 return err;
79 EXPORT_SYMBOL(wrmsr_on_cpu);
81 int wrmsrl_on_cpu(unsigned int cpu, u32 msr_no, u64 q)
83 int err;
84 struct msr_info rv;
86 memset(&rv, 0, sizeof(rv));
88 rv.msr_no = msr_no;
89 rv.reg.q = q;
91 err = smp_call_function_single(cpu, __wrmsr_on_cpu, &rv, 1);
93 return err;
95 EXPORT_SYMBOL(wrmsrl_on_cpu);
97 static void __rwmsr_on_cpus(const struct cpumask *mask, u32 msr_no,
98 struct msr *msrs,
99 void (*msr_func) (void *info))
101 struct msr_info rv;
102 int this_cpu;
104 memset(&rv, 0, sizeof(rv));
106 rv.msrs = msrs;
107 rv.msr_no = msr_no;
109 this_cpu = get_cpu();
111 if (cpumask_test_cpu(this_cpu, mask))
112 msr_func(&rv);
114 smp_call_function_many(mask, msr_func, &rv, 1);
115 put_cpu();
118 /* rdmsr on a bunch of CPUs
120 * @mask: which CPUs
121 * @msr_no: which MSR
122 * @msrs: array of MSR values
125 void rdmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr *msrs)
127 __rwmsr_on_cpus(mask, msr_no, msrs, __rdmsr_on_cpu);
129 EXPORT_SYMBOL(rdmsr_on_cpus);
132 * wrmsr on a bunch of CPUs
134 * @mask: which CPUs
135 * @msr_no: which MSR
136 * @msrs: array of MSR values
139 void wrmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr *msrs)
141 __rwmsr_on_cpus(mask, msr_no, msrs, __wrmsr_on_cpu);
143 EXPORT_SYMBOL(wrmsr_on_cpus);
145 /* These "safe" variants are slower and should be used when the target MSR
146 may not actually exist. */
147 static void __rdmsr_safe_on_cpu(void *info)
149 struct msr_info *rv = info;
151 rv->err = rdmsr_safe(rv->msr_no, &rv->reg.l, &rv->reg.h);
154 static void __wrmsr_safe_on_cpu(void *info)
156 struct msr_info *rv = info;
158 rv->err = wrmsr_safe(rv->msr_no, rv->reg.l, rv->reg.h);
161 int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h)
163 int err;
164 struct msr_info rv;
166 memset(&rv, 0, sizeof(rv));
168 rv.msr_no = msr_no;
169 err = smp_call_function_single(cpu, __rdmsr_safe_on_cpu, &rv, 1);
170 *l = rv.reg.l;
171 *h = rv.reg.h;
173 return err ? err : rv.err;
175 EXPORT_SYMBOL(rdmsr_safe_on_cpu);
177 int wrmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h)
179 int err;
180 struct msr_info rv;
182 memset(&rv, 0, sizeof(rv));
184 rv.msr_no = msr_no;
185 rv.reg.l = l;
186 rv.reg.h = h;
187 err = smp_call_function_single(cpu, __wrmsr_safe_on_cpu, &rv, 1);
189 return err ? err : rv.err;
191 EXPORT_SYMBOL(wrmsr_safe_on_cpu);
193 int wrmsrl_safe_on_cpu(unsigned int cpu, u32 msr_no, u64 q)
195 int err;
196 struct msr_info rv;
198 memset(&rv, 0, sizeof(rv));
200 rv.msr_no = msr_no;
201 rv.reg.q = q;
203 err = smp_call_function_single(cpu, __wrmsr_safe_on_cpu, &rv, 1);
205 return err ? err : rv.err;
207 EXPORT_SYMBOL(wrmsrl_safe_on_cpu);
209 int rdmsrl_safe_on_cpu(unsigned int cpu, u32 msr_no, u64 *q)
211 int err;
212 struct msr_info rv;
214 memset(&rv, 0, sizeof(rv));
216 rv.msr_no = msr_no;
217 err = smp_call_function_single(cpu, __rdmsr_safe_on_cpu, &rv, 1);
218 *q = rv.reg.q;
220 return err ? err : rv.err;
222 EXPORT_SYMBOL(rdmsrl_safe_on_cpu);
225 * These variants are significantly slower, but allows control over
226 * the entire 32-bit GPR set.
228 static void __rdmsr_safe_regs_on_cpu(void *info)
230 struct msr_regs_info *rv = info;
232 rv->err = rdmsr_safe_regs(rv->regs);
235 static void __wrmsr_safe_regs_on_cpu(void *info)
237 struct msr_regs_info *rv = info;
239 rv->err = wrmsr_safe_regs(rv->regs);
242 int rdmsr_safe_regs_on_cpu(unsigned int cpu, u32 *regs)
244 int err;
245 struct msr_regs_info rv;
247 rv.regs = regs;
248 rv.err = -EIO;
249 err = smp_call_function_single(cpu, __rdmsr_safe_regs_on_cpu, &rv, 1);
251 return err ? err : rv.err;
253 EXPORT_SYMBOL(rdmsr_safe_regs_on_cpu);
255 int wrmsr_safe_regs_on_cpu(unsigned int cpu, u32 *regs)
257 int err;
258 struct msr_regs_info rv;
260 rv.regs = regs;
261 rv.err = -EIO;
262 err = smp_call_function_single(cpu, __wrmsr_safe_regs_on_cpu, &rv, 1);
264 return err ? err : rv.err;
266 EXPORT_SYMBOL(wrmsr_safe_regs_on_cpu);