1 #include <linux/module.h>
2 #include <linux/preempt.h>
14 static void __rdmsr_on_cpu(void *info
)
16 struct msr_info
*rv
= info
;
18 int this_cpu
= raw_smp_processor_id();
21 reg
= &rv
->msrs
[this_cpu
- rv
->off
];
25 rdmsr(rv
->msr_no
, reg
->l
, reg
->h
);
28 static void __wrmsr_on_cpu(void *info
)
30 struct msr_info
*rv
= info
;
32 int this_cpu
= raw_smp_processor_id();
35 reg
= &rv
->msrs
[this_cpu
- rv
->off
];
39 wrmsr(rv
->msr_no
, reg
->l
, reg
->h
);
42 int rdmsr_on_cpu(unsigned int cpu
, u32 msr_no
, u32
*l
, u32
*h
)
47 memset(&rv
, 0, sizeof(rv
));
50 err
= smp_call_function_single(cpu
, __rdmsr_on_cpu
, &rv
, 1);
56 EXPORT_SYMBOL(rdmsr_on_cpu
);
58 int wrmsr_on_cpu(unsigned int cpu
, u32 msr_no
, u32 l
, u32 h
)
63 memset(&rv
, 0, sizeof(rv
));
68 err
= smp_call_function_single(cpu
, __wrmsr_on_cpu
, &rv
, 1);
72 EXPORT_SYMBOL(wrmsr_on_cpu
);
74 static void __rwmsr_on_cpus(const struct cpumask
*mask
, u32 msr_no
,
76 void (*msr_func
) (void *info
))
81 memset(&rv
, 0, sizeof(rv
));
83 rv
.off
= cpumask_first(mask
);
89 if (cpumask_test_cpu(this_cpu
, mask
))
92 smp_call_function_many(mask
, msr_func
, &rv
, 1);
96 /* rdmsr on a bunch of CPUs
100 * @msrs: array of MSR values
103 void rdmsr_on_cpus(const struct cpumask
*mask
, u32 msr_no
, struct msr
*msrs
)
105 __rwmsr_on_cpus(mask
, msr_no
, msrs
, __rdmsr_on_cpu
);
107 EXPORT_SYMBOL(rdmsr_on_cpus
);
110 * wrmsr on a bunch of CPUs
114 * @msrs: array of MSR values
117 void wrmsr_on_cpus(const struct cpumask
*mask
, u32 msr_no
, struct msr
*msrs
)
119 __rwmsr_on_cpus(mask
, msr_no
, msrs
, __wrmsr_on_cpu
);
121 EXPORT_SYMBOL(wrmsr_on_cpus
);
123 /* These "safe" variants are slower and should be used when the target MSR
124 may not actually exist. */
125 static void __rdmsr_safe_on_cpu(void *info
)
127 struct msr_info
*rv
= info
;
129 rv
->err
= rdmsr_safe(rv
->msr_no
, &rv
->reg
.l
, &rv
->reg
.h
);
132 static void __wrmsr_safe_on_cpu(void *info
)
134 struct msr_info
*rv
= info
;
136 rv
->err
= wrmsr_safe(rv
->msr_no
, rv
->reg
.l
, rv
->reg
.h
);
139 int rdmsr_safe_on_cpu(unsigned int cpu
, u32 msr_no
, u32
*l
, u32
*h
)
144 memset(&rv
, 0, sizeof(rv
));
147 err
= smp_call_function_single(cpu
, __rdmsr_safe_on_cpu
, &rv
, 1);
151 return err
? err
: rv
.err
;
153 EXPORT_SYMBOL(rdmsr_safe_on_cpu
);
155 int wrmsr_safe_on_cpu(unsigned int cpu
, u32 msr_no
, u32 l
, u32 h
)
160 memset(&rv
, 0, sizeof(rv
));
165 err
= smp_call_function_single(cpu
, __wrmsr_safe_on_cpu
, &rv
, 1);
167 return err
? err
: rv
.err
;
169 EXPORT_SYMBOL(wrmsr_safe_on_cpu
);
172 * These variants are significantly slower, but allows control over
173 * the entire 32-bit GPR set.
175 struct msr_regs_info
{
180 static void __rdmsr_safe_regs_on_cpu(void *info
)
182 struct msr_regs_info
*rv
= info
;
184 rv
->err
= rdmsr_safe_regs(rv
->regs
);
187 static void __wrmsr_safe_regs_on_cpu(void *info
)
189 struct msr_regs_info
*rv
= info
;
191 rv
->err
= wrmsr_safe_regs(rv
->regs
);
194 int rdmsr_safe_regs_on_cpu(unsigned int cpu
, u32
*regs
)
197 struct msr_regs_info rv
;
201 err
= smp_call_function_single(cpu
, __rdmsr_safe_regs_on_cpu
, &rv
, 1);
203 return err
? err
: rv
.err
;
205 EXPORT_SYMBOL(rdmsr_safe_regs_on_cpu
);
207 int wrmsr_safe_regs_on_cpu(unsigned int cpu
, u32
*regs
)
210 struct msr_regs_info rv
;
214 err
= smp_call_function_single(cpu
, __wrmsr_safe_regs_on_cpu
, &rv
, 1);
216 return err
? err
: rv
.err
;
218 EXPORT_SYMBOL(wrmsr_safe_regs_on_cpu
);