1 #include <linux/module.h>
2 #include <linux/preempt.h>
12 static void __rdmsr_on_cpu(void *info
)
14 struct msr_info
*rv
= info
;
16 rdmsr(rv
->msr_no
, rv
->l
, rv
->h
);
19 static void __rdmsr_safe_on_cpu(void *info
)
21 struct msr_info
*rv
= info
;
23 rv
->err
= rdmsr_safe(rv
->msr_no
, &rv
->l
, &rv
->h
);
26 static int _rdmsr_on_cpu(unsigned int cpu
, u32 msr_no
, u32
*l
, u32
*h
, int safe
)
30 if (smp_processor_id() == cpu
)
32 err
= rdmsr_safe(msr_no
, l
, h
);
34 rdmsr(msr_no
, *l
, *h
);
40 smp_call_function_single(cpu
, __rdmsr_safe_on_cpu
,
44 smp_call_function_single(cpu
, __rdmsr_on_cpu
, &rv
, 0, 1);
53 static void __wrmsr_on_cpu(void *info
)
55 struct msr_info
*rv
= info
;
57 wrmsr(rv
->msr_no
, rv
->l
, rv
->h
);
60 static void __wrmsr_safe_on_cpu(void *info
)
62 struct msr_info
*rv
= info
;
64 rv
->err
= wrmsr_safe(rv
->msr_no
, rv
->l
, rv
->h
);
67 static int _wrmsr_on_cpu(unsigned int cpu
, u32 msr_no
, u32 l
, u32 h
, int safe
)
71 if (smp_processor_id() == cpu
)
73 err
= wrmsr_safe(msr_no
, l
, h
);
83 smp_call_function_single(cpu
, __wrmsr_safe_on_cpu
,
87 smp_call_function_single(cpu
, __wrmsr_on_cpu
, &rv
, 0, 1);
94 void wrmsr_on_cpu(unsigned int cpu
, u32 msr_no
, u32 l
, u32 h
)
96 _wrmsr_on_cpu(cpu
, msr_no
, l
, h
, 0);
99 void rdmsr_on_cpu(unsigned int cpu
, u32 msr_no
, u32
*l
, u32
*h
)
101 _rdmsr_on_cpu(cpu
, msr_no
, l
, h
, 0);
104 /* These "safe" variants are slower and should be used when the target MSR
105 may not actually exist. */
106 int wrmsr_safe_on_cpu(unsigned int cpu
, u32 msr_no
, u32 l
, u32 h
)
108 return _wrmsr_on_cpu(cpu
, msr_no
, l
, h
, 1);
111 int rdmsr_safe_on_cpu(unsigned int cpu
, u32 msr_no
, u32
*l
, u32
*h
)
113 return _rdmsr_on_cpu(cpu
, msr_no
, l
, h
, 1);
116 EXPORT_SYMBOL(rdmsr_on_cpu
);
117 EXPORT_SYMBOL(wrmsr_on_cpu
);
118 EXPORT_SYMBOL(rdmsr_safe_on_cpu
);
119 EXPORT_SYMBOL(wrmsr_safe_on_cpu
);