diff options
Diffstat (limited to 'arch/i386')
-rw-r--r-- | arch/i386/kernel/msr.c | 106 |
1 files changed, 4 insertions, 102 deletions
diff --git a/arch/i386/kernel/msr.c b/arch/i386/kernel/msr.c index bcaa6e9b6197..8cd0a91ce107 100644 --- a/arch/i386/kernel/msr.c +++ b/arch/i386/kernel/msr.c | |||
@@ -45,104 +45,6 @@ | |||
45 | 45 | ||
46 | static struct class *msr_class; | 46 | static struct class *msr_class; |
47 | 47 | ||
48 | static inline int wrmsr_eio(u32 reg, u32 eax, u32 edx) | ||
49 | { | ||
50 | int err; | ||
51 | |||
52 | err = wrmsr_safe(reg, eax, edx); | ||
53 | if (err) | ||
54 | err = -EIO; | ||
55 | return err; | ||
56 | } | ||
57 | |||
58 | static inline int rdmsr_eio(u32 reg, u32 *eax, u32 *edx) | ||
59 | { | ||
60 | int err; | ||
61 | |||
62 | err = rdmsr_safe(reg, eax, edx); | ||
63 | if (err) | ||
64 | err = -EIO; | ||
65 | return err; | ||
66 | } | ||
67 | |||
68 | #ifdef CONFIG_SMP | ||
69 | |||
70 | struct msr_command { | ||
71 | int err; | ||
72 | u32 reg; | ||
73 | u32 data[2]; | ||
74 | }; | ||
75 | |||
76 | static void msr_smp_wrmsr(void *cmd_block) | ||
77 | { | ||
78 | struct msr_command *cmd = (struct msr_command *)cmd_block; | ||
79 | |||
80 | cmd->err = wrmsr_eio(cmd->reg, cmd->data[0], cmd->data[1]); | ||
81 | } | ||
82 | |||
83 | static void msr_smp_rdmsr(void *cmd_block) | ||
84 | { | ||
85 | struct msr_command *cmd = (struct msr_command *)cmd_block; | ||
86 | |||
87 | cmd->err = rdmsr_eio(cmd->reg, &cmd->data[0], &cmd->data[1]); | ||
88 | } | ||
89 | |||
90 | static inline int do_wrmsr(int cpu, u32 reg, u32 eax, u32 edx) | ||
91 | { | ||
92 | struct msr_command cmd; | ||
93 | int ret; | ||
94 | |||
95 | preempt_disable(); | ||
96 | if (cpu == smp_processor_id()) { | ||
97 | ret = wrmsr_eio(reg, eax, edx); | ||
98 | } else { | ||
99 | cmd.reg = reg; | ||
100 | cmd.data[0] = eax; | ||
101 | cmd.data[1] = edx; | ||
102 | |||
103 | smp_call_function_single(cpu, msr_smp_wrmsr, &cmd, 1, 1); | ||
104 | ret = cmd.err; | ||
105 | } | ||
106 | preempt_enable(); | ||
107 | return ret; | ||
108 | } | ||
109 | |||
110 | static inline int do_rdmsr(int cpu, u32 reg, u32 * eax, u32 * edx) | ||
111 | { | ||
112 | struct msr_command cmd; | ||
113 | int ret; | ||
114 | |||
115 | preempt_disable(); | ||
116 | if (cpu == smp_processor_id()) { | ||
117 | ret = rdmsr_eio(reg, eax, edx); | ||
118 | } else { | ||
119 | cmd.reg = reg; | ||
120 | |||
121 | smp_call_function_single(cpu, msr_smp_rdmsr, &cmd, 1, 1); | ||
122 | |||
123 | *eax = cmd.data[0]; | ||
124 | *edx = cmd.data[1]; | ||
125 | |||
126 | ret = cmd.err; | ||
127 | } | ||
128 | preempt_enable(); | ||
129 | return ret; | ||
130 | } | ||
131 | |||
132 | #else /* ! CONFIG_SMP */ | ||
133 | |||
134 | static inline int do_wrmsr(int cpu, u32 reg, u32 eax, u32 edx) | ||
135 | { | ||
136 | return wrmsr_eio(reg, eax, edx); | ||
137 | } | ||
138 | |||
139 | static inline int do_rdmsr(int cpu, u32 reg, u32 *eax, u32 *edx) | ||
140 | { | ||
141 | return rdmsr_eio(reg, eax, edx); | ||
142 | } | ||
143 | |||
144 | #endif /* ! CONFIG_SMP */ | ||
145 | |||
146 | static loff_t msr_seek(struct file *file, loff_t offset, int orig) | 48 | static loff_t msr_seek(struct file *file, loff_t offset, int orig) |
147 | { | 49 | { |
148 | loff_t ret = -EINVAL; | 50 | loff_t ret = -EINVAL; |
@@ -174,9 +76,9 @@ static ssize_t msr_read(struct file *file, char __user * buf, | |||
174 | return -EINVAL; /* Invalid chunk size */ | 76 | return -EINVAL; /* Invalid chunk size */ |
175 | 77 | ||
176 | for (; count; count -= 8) { | 78 | for (; count; count -= 8) { |
177 | err = do_rdmsr(cpu, reg, &data[0], &data[1]); | 79 | err = rdmsr_safe_on_cpu(cpu, reg, &data[0], &data[1]); |
178 | if (err) | 80 | if (err) |
179 | return err; | 81 | return -EIO; |
180 | if (copy_to_user(tmp, &data, 8)) | 82 | if (copy_to_user(tmp, &data, 8)) |
181 | return -EFAULT; | 83 | return -EFAULT; |
182 | tmp += 2; | 84 | tmp += 2; |
@@ -200,9 +102,9 @@ static ssize_t msr_write(struct file *file, const char __user *buf, | |||
200 | for (; count; count -= 8) { | 102 | for (; count; count -= 8) { |
201 | if (copy_from_user(&data, tmp, 8)) | 103 | if (copy_from_user(&data, tmp, 8)) |
202 | return -EFAULT; | 104 | return -EFAULT; |
203 | err = do_wrmsr(cpu, reg, data[0], data[1]); | 105 | err = wrmsr_safe_on_cpu(cpu, reg, data[0], data[1]); |
204 | if (err) | 106 | if (err) |
205 | return err; | 107 | return -EIO; |
206 | tmp += 2; | 108 | tmp += 2; |
207 | } | 109 | } |
208 | 110 | ||