diff options
author | Borislav Petkov <borislav.petkov@amd.com> | 2009-05-22 06:12:01 -0400 |
---|---|---|
committer | Borislav Petkov <borislav.petkov@amd.com> | 2009-06-10 06:18:42 -0400 |
commit | 6bc1096d7ab3621b3ffcf06616d1f4e0325d903d (patch) | |
tree | 286d1e4545fbd69c25fb4a5044d1d51122169a1d /arch/x86/lib/msr.c | |
parent | 07a2039b8eb0af4ff464efd3dfd95de5c02648c6 (diff) |
x86: MSR: add a struct representation of an MSR
Add a struct representing a 64bit MSR pair consisting of a low and high
register part and convert msr_info to use it. Also, rename msr-on-cpu.c
to msr.c.
Side note: Put the cpumask.h include in __KERNEL__ space thus fixing an
allmodconfig build failure in the headers_check target.
CC: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
Diffstat (limited to 'arch/x86/lib/msr.c')
-rw-r--r-- | arch/x86/lib/msr.c | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/arch/x86/lib/msr.c b/arch/x86/lib/msr.c new file mode 100644 index 000000000000..cade714e57f9 --- /dev/null +++ b/arch/x86/lib/msr.c | |||
@@ -0,0 +1,97 @@ | |||
1 | #include <linux/module.h> | ||
2 | #include <linux/preempt.h> | ||
3 | #include <linux/smp.h> | ||
4 | #include <asm/msr.h> | ||
5 | |||
6 | struct msr_info { | ||
7 | u32 msr_no; | ||
8 | struct msr reg; | ||
9 | int err; | ||
10 | }; | ||
11 | |||
12 | static void __rdmsr_on_cpu(void *info) | ||
13 | { | ||
14 | struct msr_info *rv = info; | ||
15 | |||
16 | rdmsr(rv->msr_no, rv->reg.l, rv->reg.h); | ||
17 | } | ||
18 | |||
19 | static void __wrmsr_on_cpu(void *info) | ||
20 | { | ||
21 | struct msr_info *rv = info; | ||
22 | |||
23 | wrmsr(rv->msr_no, rv->reg.l, rv->reg.h); | ||
24 | } | ||
25 | |||
26 | int rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h) | ||
27 | { | ||
28 | int err; | ||
29 | struct msr_info rv; | ||
30 | |||
31 | rv.msr_no = msr_no; | ||
32 | err = smp_call_function_single(cpu, __rdmsr_on_cpu, &rv, 1); | ||
33 | *l = rv.reg.l; | ||
34 | *h = rv.reg.h; | ||
35 | |||
36 | return err; | ||
37 | } | ||
38 | |||
39 | int wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h) | ||
40 | { | ||
41 | int err; | ||
42 | struct msr_info rv; | ||
43 | |||
44 | rv.msr_no = msr_no; | ||
45 | rv.reg.l = l; | ||
46 | rv.reg.h = h; | ||
47 | err = smp_call_function_single(cpu, __wrmsr_on_cpu, &rv, 1); | ||
48 | |||
49 | return err; | ||
50 | } | ||
51 | |||
52 | /* These "safe" variants are slower and should be used when the target MSR | ||
53 | may not actually exist. */ | ||
54 | static void __rdmsr_safe_on_cpu(void *info) | ||
55 | { | ||
56 | struct msr_info *rv = info; | ||
57 | |||
58 | rv->err = rdmsr_safe(rv->msr_no, &rv->reg.l, &rv->reg.h); | ||
59 | } | ||
60 | |||
61 | static void __wrmsr_safe_on_cpu(void *info) | ||
62 | { | ||
63 | struct msr_info *rv = info; | ||
64 | |||
65 | rv->err = wrmsr_safe(rv->msr_no, rv->reg.l, rv->reg.h); | ||
66 | } | ||
67 | |||
68 | int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h) | ||
69 | { | ||
70 | int err; | ||
71 | struct msr_info rv; | ||
72 | |||
73 | rv.msr_no = msr_no; | ||
74 | err = smp_call_function_single(cpu, __rdmsr_safe_on_cpu, &rv, 1); | ||
75 | *l = rv.reg.l; | ||
76 | *h = rv.reg.h; | ||
77 | |||
78 | return err ? err : rv.err; | ||
79 | } | ||
80 | |||
81 | int wrmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h) | ||
82 | { | ||
83 | int err; | ||
84 | struct msr_info rv; | ||
85 | |||
86 | rv.msr_no = msr_no; | ||
87 | rv.reg.l = l; | ||
88 | rv.reg.h = h; | ||
89 | err = smp_call_function_single(cpu, __wrmsr_safe_on_cpu, &rv, 1); | ||
90 | |||
91 | return err ? err : rv.err; | ||
92 | } | ||
93 | |||
94 | EXPORT_SYMBOL(rdmsr_on_cpu); | ||
95 | EXPORT_SYMBOL(wrmsr_on_cpu); | ||
96 | EXPORT_SYMBOL(rdmsr_safe_on_cpu); | ||
97 | EXPORT_SYMBOL(wrmsr_safe_on_cpu); | ||