1 #include <linux/module.h>
2 #include <linux/preempt.h>
6 static void __rdmsr_on_cpu(void *info
)
8 struct msr_info
*rv
= info
;
10 int this_cpu
= raw_smp_processor_id();
13 reg
= per_cpu_ptr(rv
->msrs
, this_cpu
);
17 rdmsr(rv
->msr_no
, reg
->l
, reg
->h
);
20 static void __wrmsr_on_cpu(void *info
)
22 struct msr_info
*rv
= info
;
24 int this_cpu
= raw_smp_processor_id();
27 reg
= per_cpu_ptr(rv
->msrs
, this_cpu
);
31 wrmsr(rv
->msr_no
, reg
->l
, reg
->h
);
34 int rdmsr_on_cpu(unsigned int cpu
, u32 msr_no
, u32
*l
, u32
*h
)
39 memset(&rv
, 0, sizeof(rv
));
42 err
= smp_call_function_single(cpu
, __rdmsr_on_cpu
, &rv
, 1);
48 EXPORT_SYMBOL(rdmsr_on_cpu
);
50 int rdmsrl_on_cpu(unsigned int cpu
, u32 msr_no
, u64
*q
)
55 memset(&rv
, 0, sizeof(rv
));
58 err
= smp_call_function_single(cpu
, __rdmsr_on_cpu
, &rv
, 1);
63 EXPORT_SYMBOL(rdmsrl_on_cpu
);
65 int wrmsr_on_cpu(unsigned int cpu
, u32 msr_no
, u32 l
, u32 h
)
70 memset(&rv
, 0, sizeof(rv
));
75 err
= smp_call_function_single(cpu
, __wrmsr_on_cpu
, &rv
, 1);
79 EXPORT_SYMBOL(wrmsr_on_cpu
);
81 int wrmsrl_on_cpu(unsigned int cpu
, u32 msr_no
, u64 q
)
86 memset(&rv
, 0, sizeof(rv
));
91 err
= smp_call_function_single(cpu
, __wrmsr_on_cpu
, &rv
, 1);
95 EXPORT_SYMBOL(wrmsrl_on_cpu
);
97 static void __rwmsr_on_cpus(const struct cpumask
*mask
, u32 msr_no
,
99 void (*msr_func
) (void *info
))
104 memset(&rv
, 0, sizeof(rv
));
109 this_cpu
= get_cpu();
111 if (cpumask_test_cpu(this_cpu
, mask
))
114 smp_call_function_many(mask
, msr_func
, &rv
, 1);
118 /* rdmsr on a bunch of CPUs
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
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
)
166 memset(&rv
, 0, sizeof(rv
));
169 err
= smp_call_function_single(cpu
, __rdmsr_safe_on_cpu
, &rv
, 1);
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
)
182 memset(&rv
, 0, sizeof(rv
));
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
)
198 memset(&rv
, 0, sizeof(rv
));
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
)
214 memset(&rv
, 0, sizeof(rv
));
217 err
= smp_call_function_single(cpu
, __rdmsr_safe_on_cpu
, &rv
, 1);
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
)
245 struct msr_regs_info rv
;
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
)
258 struct msr_regs_info rv
;
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
);