diff options
Diffstat (limited to 'arch/i386/lib/msr-on-cpu.c')
-rw-r--r-- | arch/i386/lib/msr-on-cpu.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/arch/i386/lib/msr-on-cpu.c b/arch/i386/lib/msr-on-cpu.c new file mode 100644 index 000000000000..2092ea15ba85 --- /dev/null +++ b/arch/i386/lib/msr-on-cpu.c | |||
@@ -0,0 +1,70 @@ | |||
1 | #include <linux/module.h> | ||
2 | #include <linux/preempt.h> | ||
3 | #include <linux/smp.h> | ||
4 | #include <asm/msr.h> | ||
5 | |||
6 | #ifdef CONFIG_SMP | ||
7 | struct msr_info { | ||
8 | u32 msr_no; | ||
9 | u32 l, h; | ||
10 | }; | ||
11 | |||
12 | static void __rdmsr_on_cpu(void *info) | ||
13 | { | ||
14 | struct msr_info *rv = info; | ||
15 | |||
16 | rdmsr(rv->msr_no, rv->l, rv->h); | ||
17 | } | ||
18 | |||
19 | void rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h) | ||
20 | { | ||
21 | preempt_disable(); | ||
22 | if (smp_processor_id() == cpu) | ||
23 | rdmsr(msr_no, *l, *h); | ||
24 | else { | ||
25 | struct msr_info rv; | ||
26 | |||
27 | rv.msr_no = msr_no; | ||
28 | smp_call_function_single(cpu, __rdmsr_on_cpu, &rv, 0, 1); | ||
29 | *l = rv.l; | ||
30 | *h = rv.h; | ||
31 | } | ||
32 | preempt_enable(); | ||
33 | } | ||
34 | |||
35 | static void __wrmsr_on_cpu(void *info) | ||
36 | { | ||
37 | struct msr_info *rv = info; | ||
38 | |||
39 | wrmsr(rv->msr_no, rv->l, rv->h); | ||
40 | } | ||
41 | |||
42 | void wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h) | ||
43 | { | ||
44 | preempt_disable(); | ||
45 | if (smp_processor_id() == cpu) | ||
46 | wrmsr(msr_no, l, h); | ||
47 | else { | ||
48 | struct msr_info rv; | ||
49 | |||
50 | rv.msr_no = msr_no; | ||
51 | rv.l = l; | ||
52 | rv.h = h; | ||
53 | smp_call_function_single(cpu, __wrmsr_on_cpu, &rv, 0, 1); | ||
54 | } | ||
55 | preempt_enable(); | ||
56 | } | ||
57 | #else | ||
58 | void rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h) | ||
59 | { | ||
60 | rdmsr(msr_no, *l, *h); | ||
61 | } | ||
62 | |||
63 | void wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h) | ||
64 | { | ||
65 | wrmsr(msr_no, l, h); | ||
66 | } | ||
67 | #endif | ||
68 | |||
69 | EXPORT_SYMBOL(rdmsr_on_cpu); | ||
70 | EXPORT_SYMBOL(wrmsr_on_cpu); | ||