Alexey Dobriyan | b077ffb | 2007-02-16 01:48:11 -0800 | [diff] [blame] | 1 | #include <linux/module.h> |
| 2 | #include <linux/preempt.h> |
| 3 | #include <linux/smp.h> |
| 4 | #include <asm/msr.h> |
| 5 | |
Alexey Dobriyan | b077ffb | 2007-02-16 01:48:11 -0800 | [diff] [blame] | 6 | struct msr_info { |
| 7 | u32 msr_no; |
| 8 | u32 l, h; |
Rudolf Marek | 4e9baad | 2007-05-08 17:22:01 +0200 | [diff] [blame] | 9 | int err; |
Alexey Dobriyan | b077ffb | 2007-02-16 01:48:11 -0800 | [diff] [blame] | 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 | |
Rudolf Marek | 4e9baad | 2007-05-08 17:22:01 +0200 | [diff] [blame] | 19 | static void __rdmsr_safe_on_cpu(void *info) |
Alexey Dobriyan | b077ffb | 2007-02-16 01:48:11 -0800 | [diff] [blame] | 20 | { |
Rudolf Marek | 4e9baad | 2007-05-08 17:22:01 +0200 | [diff] [blame] | 21 | struct msr_info *rv = info; |
| 22 | |
| 23 | rv->err = rdmsr_safe(rv->msr_no, &rv->l, &rv->h); |
| 24 | } |
| 25 | |
| 26 | static int _rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h, int safe) |
| 27 | { |
| 28 | int err = 0; |
Avi Kivity | 5f1f935 | 2007-10-17 18:04:38 +0200 | [diff] [blame] | 29 | struct msr_info rv; |
Alexey Dobriyan | b077ffb | 2007-02-16 01:48:11 -0800 | [diff] [blame] | 30 | |
Avi Kivity | 5f1f935 | 2007-10-17 18:04:38 +0200 | [diff] [blame] | 31 | rv.msr_no = msr_no; |
| 32 | if (safe) { |
| 33 | smp_call_function_single(cpu, __rdmsr_safe_on_cpu, &rv, 0, 1); |
| 34 | err = rv.err; |
| 35 | } else { |
| 36 | smp_call_function_single(cpu, __rdmsr_on_cpu, &rv, 0, 1); |
Alexey Dobriyan | b077ffb | 2007-02-16 01:48:11 -0800 | [diff] [blame] | 37 | } |
Avi Kivity | 5f1f935 | 2007-10-17 18:04:38 +0200 | [diff] [blame] | 38 | *l = rv.l; |
| 39 | *h = rv.h; |
| 40 | |
Rudolf Marek | 4e9baad | 2007-05-08 17:22:01 +0200 | [diff] [blame] | 41 | return err; |
Alexey Dobriyan | b077ffb | 2007-02-16 01:48:11 -0800 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | static void __wrmsr_on_cpu(void *info) |
| 45 | { |
| 46 | struct msr_info *rv = info; |
| 47 | |
| 48 | wrmsr(rv->msr_no, rv->l, rv->h); |
| 49 | } |
| 50 | |
Rudolf Marek | 4e9baad | 2007-05-08 17:22:01 +0200 | [diff] [blame] | 51 | static void __wrmsr_safe_on_cpu(void *info) |
Alexey Dobriyan | b077ffb | 2007-02-16 01:48:11 -0800 | [diff] [blame] | 52 | { |
Rudolf Marek | 4e9baad | 2007-05-08 17:22:01 +0200 | [diff] [blame] | 53 | struct msr_info *rv = info; |
| 54 | |
| 55 | rv->err = wrmsr_safe(rv->msr_no, rv->l, rv->h); |
| 56 | } |
| 57 | |
| 58 | static int _wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h, int safe) |
| 59 | { |
| 60 | int err = 0; |
Avi Kivity | 5f1f935 | 2007-10-17 18:04:38 +0200 | [diff] [blame] | 61 | struct msr_info rv; |
Alexey Dobriyan | b077ffb | 2007-02-16 01:48:11 -0800 | [diff] [blame] | 62 | |
Avi Kivity | 5f1f935 | 2007-10-17 18:04:38 +0200 | [diff] [blame] | 63 | rv.msr_no = msr_no; |
| 64 | rv.l = l; |
| 65 | rv.h = h; |
| 66 | if (safe) { |
| 67 | smp_call_function_single(cpu, __wrmsr_safe_on_cpu, &rv, 0, 1); |
| 68 | err = rv.err; |
| 69 | } else { |
| 70 | smp_call_function_single(cpu, __wrmsr_on_cpu, &rv, 0, 1); |
Alexey Dobriyan | b077ffb | 2007-02-16 01:48:11 -0800 | [diff] [blame] | 71 | } |
Avi Kivity | 5f1f935 | 2007-10-17 18:04:38 +0200 | [diff] [blame] | 72 | |
Rudolf Marek | 4e9baad | 2007-05-08 17:22:01 +0200 | [diff] [blame] | 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 | |
| 81 | void rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h) |
| 82 | { |
| 83 | _rdmsr_on_cpu(cpu, msr_no, l, h, 0); |
| 84 | } |
| 85 | |
| 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) |
| 89 | { |
| 90 | return _wrmsr_on_cpu(cpu, msr_no, l, h, 1); |
| 91 | } |
| 92 | |
| 93 | int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h) |
| 94 | { |
| 95 | return _rdmsr_on_cpu(cpu, msr_no, l, h, 1); |
Alexey Dobriyan | b077ffb | 2007-02-16 01:48:11 -0800 | [diff] [blame] | 96 | } |
Alexey Dobriyan | b077ffb | 2007-02-16 01:48:11 -0800 | [diff] [blame] | 97 | |
| 98 | EXPORT_SYMBOL(rdmsr_on_cpu); |
| 99 | EXPORT_SYMBOL(wrmsr_on_cpu); |
Rudolf Marek | 4e9baad | 2007-05-08 17:22:01 +0200 | [diff] [blame] | 100 | EXPORT_SYMBOL(rdmsr_safe_on_cpu); |
| 101 | EXPORT_SYMBOL(wrmsr_safe_on_cpu); |