aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorNicolas Boichat <nicolas@boichat.ch>2007-05-08 11:22:01 -0400
committerJean Delvare <khali@hyperion.delvare>2007-05-08 11:22:01 -0400
commit78a62d2c9817dc1adfc563f5a7654df2c89be416 (patch)
tree95a9849259b379795c2842627af98a2c437883cc /arch
parent4e9baad8f5cb2040e802eff484fad7e721b21c0b (diff)
i386: Use functions from library in msr driver
Use safe MSR functions provided by arch/*/lib/msr-on-cpu.c in arch/i386/kernel/msr.c. Signed-off-by: Nicolas Boichat <nicolas@boichat.ch> Cc: H. Peter Anvin <hpa@zytor.com> Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'arch')
-rw-r--r--arch/i386/kernel/msr.c106
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
46static struct class *msr_class; 46static struct class *msr_class;
47 47
48static 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
58static 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
70struct msr_command {
71 int err;
72 u32 reg;
73 u32 data[2];
74};
75
76static 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
83static 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
90static 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
110static 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
134static inline int do_wrmsr(int cpu, u32 reg, u32 eax, u32 edx)
135{
136 return wrmsr_eio(reg, eax, edx);
137}
138
139static 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
146static loff_t msr_seek(struct file *file, loff_t offset, int orig) 48static 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