diff options
Diffstat (limited to 'arch/x86/lib/msr-on-cpu.c')
-rw-r--r-- | arch/x86/lib/msr-on-cpu.c | 76 |
1 files changed, 36 insertions, 40 deletions
diff --git a/arch/x86/lib/msr-on-cpu.c b/arch/x86/lib/msr-on-cpu.c index d5a2b39f882b..321cf720dbb6 100644 --- a/arch/x86/lib/msr-on-cpu.c +++ b/arch/x86/lib/msr-on-cpu.c | |||
@@ -16,36 +16,46 @@ static void __rdmsr_on_cpu(void *info) | |||
16 | rdmsr(rv->msr_no, rv->l, rv->h); | 16 | rdmsr(rv->msr_no, rv->l, rv->h); |
17 | } | 17 | } |
18 | 18 | ||
19 | static void __rdmsr_safe_on_cpu(void *info) | 19 | static void __wrmsr_on_cpu(void *info) |
20 | { | 20 | { |
21 | struct msr_info *rv = info; | 21 | struct msr_info *rv = info; |
22 | 22 | ||
23 | rv->err = rdmsr_safe(rv->msr_no, &rv->l, &rv->h); | 23 | wrmsr(rv->msr_no, rv->l, rv->h); |
24 | } | 24 | } |
25 | 25 | ||
26 | static int _rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h, int safe) | 26 | int rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h) |
27 | { | 27 | { |
28 | int err = 0; | 28 | int err; |
29 | struct msr_info rv; | 29 | struct msr_info rv; |
30 | 30 | ||
31 | rv.msr_no = msr_no; | 31 | rv.msr_no = msr_no; |
32 | if (safe) { | 32 | err = smp_call_function_single(cpu, __rdmsr_on_cpu, &rv, 1); |
33 | smp_call_function_single(cpu, __rdmsr_safe_on_cpu, &rv, 1); | ||
34 | err = rv.err; | ||
35 | } else { | ||
36 | smp_call_function_single(cpu, __rdmsr_on_cpu, &rv, 1); | ||
37 | } | ||
38 | *l = rv.l; | 33 | *l = rv.l; |
39 | *h = rv.h; | 34 | *h = rv.h; |
40 | 35 | ||
41 | return err; | 36 | return err; |
42 | } | 37 | } |
43 | 38 | ||
44 | static void __wrmsr_on_cpu(void *info) | 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.l = l; | ||
46 | rv.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) | ||
45 | { | 55 | { |
46 | struct msr_info *rv = info; | 56 | struct msr_info *rv = info; |
47 | 57 | ||
48 | wrmsr(rv->msr_no, rv->l, rv->h); | 58 | rv->err = rdmsr_safe(rv->msr_no, &rv->l, &rv->h); |
49 | } | 59 | } |
50 | 60 | ||
51 | static void __wrmsr_safe_on_cpu(void *info) | 61 | static void __wrmsr_safe_on_cpu(void *info) |
@@ -55,44 +65,30 @@ static void __wrmsr_safe_on_cpu(void *info) | |||
55 | rv->err = wrmsr_safe(rv->msr_no, rv->l, rv->h); | 65 | rv->err = wrmsr_safe(rv->msr_no, rv->l, rv->h); |
56 | } | 66 | } |
57 | 67 | ||
58 | static int _wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h, int safe) | 68 | int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h) |
59 | { | 69 | { |
60 | int err = 0; | 70 | int err; |
61 | struct msr_info rv; | 71 | struct msr_info rv; |
62 | 72 | ||
63 | rv.msr_no = msr_no; | 73 | rv.msr_no = msr_no; |
64 | rv.l = l; | 74 | err = smp_call_function_single(cpu, __rdmsr_safe_on_cpu, &rv, 1); |
65 | rv.h = h; | 75 | *l = rv.l; |
66 | if (safe) { | 76 | *h = rv.h; |
67 | smp_call_function_single(cpu, __wrmsr_safe_on_cpu, &rv, 1); | ||
68 | err = rv.err; | ||
69 | } else { | ||
70 | smp_call_function_single(cpu, __wrmsr_on_cpu, &rv, 1); | ||
71 | } | ||
72 | |||
73 | return err; | ||
74 | } | ||
75 | |||
76 | void wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h) | ||
77 | { | ||
78 | _wrmsr_on_cpu(cpu, msr_no, l, h, 0); | ||
79 | } | ||
80 | 77 | ||
81 | void rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h) | 78 | return err ? err : rv.err; |
82 | { | ||
83 | _rdmsr_on_cpu(cpu, msr_no, l, h, 0); | ||
84 | } | 79 | } |
85 | 80 | ||
86 | /* These "safe" variants are slower and should be used when the target MSR | ||
87 | may not actually exist. */ | ||
88 | int wrmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h) | 81 | int wrmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h) |
89 | { | 82 | { |
90 | return _wrmsr_on_cpu(cpu, msr_no, l, h, 1); | 83 | int err; |
91 | } | 84 | struct msr_info rv; |
92 | 85 | ||
93 | int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h) | 86 | rv.msr_no = msr_no; |
94 | { | 87 | rv.l = l; |
95 | return _rdmsr_on_cpu(cpu, msr_no, l, h, 1); | 88 | rv.h = h; |
89 | err = smp_call_function_single(cpu, __wrmsr_safe_on_cpu, &rv, 1); | ||
90 | |||
91 | return err ? err : rv.err; | ||
96 | } | 92 | } |
97 | 93 | ||
98 | EXPORT_SYMBOL(rdmsr_on_cpu); | 94 | EXPORT_SYMBOL(rdmsr_on_cpu); |