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 wrmsr_on_cpu(unsigned int cpu
, u32 msr_no
, u32 l
, u32 h
)
55 memset(&rv
, 0, sizeof(rv
));
60 err
= smp_call_function_single(cpu
, __wrmsr_on_cpu
, &rv
, 1);
64 EXPORT_SYMBOL(wrmsr_on_cpu
);
66 static void __rwmsr_on_cpus(const struct cpumask
*mask
, u32 msr_no
,
68 void (*msr_func
) (void *info
))
73 memset(&rv
, 0, sizeof(rv
));
80 if (cpumask_test_cpu(this_cpu
, mask
))
83 smp_call_function_many(mask
, msr_func
, &rv
, 1);
87 /* rdmsr on a bunch of CPUs
91 * @msrs: array of MSR values
94 void rdmsr_on_cpus(const struct cpumask
*mask
, u32 msr_no
, struct msr
*msrs
)
96 __rwmsr_on_cpus(mask
, msr_no
, msrs
, __rdmsr_on_cpu
);
98 EXPORT_SYMBOL(rdmsr_on_cpus
);
101 * wrmsr on a bunch of CPUs
105 * @msrs: array of MSR values
108 void wrmsr_on_cpus(const struct cpumask
*mask
, u32 msr_no
, struct msr
*msrs
)
110 __rwmsr_on_cpus(mask
, msr_no
, msrs
, __wrmsr_on_cpu
);
112 EXPORT_SYMBOL(wrmsr_on_cpus
);
114 /* These "safe" variants are slower and should be used when the target MSR
115 may not actually exist. */
116 static void __rdmsr_safe_on_cpu(void *info
)
118 struct msr_info
*rv
= info
;
120 rv
->err
= rdmsr_safe(rv
->msr_no
, &rv
->reg
.l
, &rv
->reg
.h
);
123 static void __wrmsr_safe_on_cpu(void *info
)
125 struct msr_info
*rv
= info
;
127 rv
->err
= wrmsr_safe(rv
->msr_no
, rv
->reg
.l
, rv
->reg
.h
);
130 int rdmsr_safe_on_cpu(unsigned int cpu
, u32 msr_no
, u32
*l
, u32
*h
)
135 memset(&rv
, 0, sizeof(rv
));
138 err
= smp_call_function_single(cpu
, __rdmsr_safe_on_cpu
, &rv
, 1);
142 return err
? err
: rv
.err
;
144 EXPORT_SYMBOL(rdmsr_safe_on_cpu
);
146 int wrmsr_safe_on_cpu(unsigned int cpu
, u32 msr_no
, u32 l
, u32 h
)
151 memset(&rv
, 0, sizeof(rv
));
156 err
= smp_call_function_single(cpu
, __wrmsr_safe_on_cpu
, &rv
, 1);
158 return err
? err
: rv
.err
;
160 EXPORT_SYMBOL(wrmsr_safe_on_cpu
);
163 * These variants are significantly slower, but allows control over
164 * the entire 32-bit GPR set.
166 static void __rdmsr_safe_regs_on_cpu(void *info
)
168 struct msr_regs_info
*rv
= info
;
170 rv
->err
= rdmsr_safe_regs(rv
->regs
);
173 static void __wrmsr_safe_regs_on_cpu(void *info
)
175 struct msr_regs_info
*rv
= info
;
177 rv
->err
= wrmsr_safe_regs(rv
->regs
);
180 int rdmsr_safe_regs_on_cpu(unsigned int cpu
, u32
*regs
)
183 struct msr_regs_info rv
;
187 err
= smp_call_function_single(cpu
, __rdmsr_safe_regs_on_cpu
, &rv
, 1);
189 return err
? err
: rv
.err
;
191 EXPORT_SYMBOL(rdmsr_safe_regs_on_cpu
);
193 int wrmsr_safe_regs_on_cpu(unsigned int cpu
, u32
*regs
)
196 struct msr_regs_info rv
;
200 err
= smp_call_function_single(cpu
, __wrmsr_safe_regs_on_cpu
, &rv
, 1);
202 return err
? err
: rv
.err
;
204 EXPORT_SYMBOL(wrmsr_safe_regs_on_cpu
);