diff options
author | Alan Cox <alan@redhat.com> | 2008-05-19 09:05:24 -0400 |
---|---|---|
committer | Wim Van Sebroeck <wim@iguana.be> | 2008-05-27 11:26:47 -0400 |
commit | 6f932f18de7f0e22a1bdae5d0040eb5d8e4a6777 (patch) | |
tree | bde5406cb425fd3971345e80846a101f5c7ec5be /drivers | |
parent | 2760600da2a13d5a2a335ba012d0f3ad5df4c098 (diff) |
[WATCHDOG 07/57] cpu5_wdt: switch to unlocked_ioctl
Review and switch to unlocked_ioctl
Signed-off-by: Alan Cox <alan@redhat.com>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/watchdog/cpu5wdt.c | 144 |
1 files changed, 70 insertions, 74 deletions
diff --git a/drivers/watchdog/cpu5wdt.c b/drivers/watchdog/cpu5wdt.c index df72f90123df..ec324e5e1c99 100644 --- a/drivers/watchdog/cpu5wdt.c +++ b/drivers/watchdog/cpu5wdt.c | |||
@@ -30,16 +30,16 @@ | |||
30 | #include <linux/timer.h> | 30 | #include <linux/timer.h> |
31 | #include <linux/completion.h> | 31 | #include <linux/completion.h> |
32 | #include <linux/jiffies.h> | 32 | #include <linux/jiffies.h> |
33 | #include <asm/io.h> | 33 | #include <linux/io.h> |
34 | #include <asm/uaccess.h> | 34 | #include <linux/uaccess.h> |
35 | |||
36 | #include <linux/watchdog.h> | 35 | #include <linux/watchdog.h> |
37 | 36 | ||
38 | /* adjustable parameters */ | 37 | /* adjustable parameters */ |
39 | 38 | ||
40 | static int verbose = 0; | 39 | static int verbose; |
41 | static int port = 0x91; | 40 | static int port = 0x91; |
42 | static int ticks = 10000; | 41 | static int ticks = 10000; |
42 | static spinlock_t cpu5wdt_lock; | ||
43 | 43 | ||
44 | #define PFX "cpu5wdt: " | 44 | #define PFX "cpu5wdt: " |
45 | 45 | ||
@@ -70,12 +70,13 @@ static struct { | |||
70 | 70 | ||
71 | static void cpu5wdt_trigger(unsigned long unused) | 71 | static void cpu5wdt_trigger(unsigned long unused) |
72 | { | 72 | { |
73 | if ( verbose > 2 ) | 73 | if (verbose > 2) |
74 | printk(KERN_DEBUG PFX "trigger at %i ticks\n", ticks); | 74 | printk(KERN_DEBUG PFX "trigger at %i ticks\n", ticks); |
75 | 75 | ||
76 | if( cpu5wdt_device.running ) | 76 | if (cpu5wdt_device.running) |
77 | ticks--; | 77 | ticks--; |
78 | 78 | ||
79 | spin_lock(&cpu5wdt_lock); | ||
79 | /* keep watchdog alive */ | 80 | /* keep watchdog alive */ |
80 | outb(1, port + CPU5WDT_TRIGGER_REG); | 81 | outb(1, port + CPU5WDT_TRIGGER_REG); |
81 | 82 | ||
@@ -86,6 +87,7 @@ static void cpu5wdt_trigger(unsigned long unused) | |||
86 | /* ticks doesn't matter anyway */ | 87 | /* ticks doesn't matter anyway */ |
87 | complete(&cpu5wdt_device.stop); | 88 | complete(&cpu5wdt_device.stop); |
88 | } | 89 | } |
90 | spin_unlock(&cpu5wdt_lock); | ||
89 | 91 | ||
90 | } | 92 | } |
91 | 93 | ||
@@ -93,14 +95,17 @@ static void cpu5wdt_reset(void) | |||
93 | { | 95 | { |
94 | ticks = cpu5wdt_device.default_ticks; | 96 | ticks = cpu5wdt_device.default_ticks; |
95 | 97 | ||
96 | if ( verbose ) | 98 | if (verbose) |
97 | printk(KERN_DEBUG PFX "reset (%i ticks)\n", (int) ticks); | 99 | printk(KERN_DEBUG PFX "reset (%i ticks)\n", (int) ticks); |
98 | 100 | ||
99 | } | 101 | } |
100 | 102 | ||
101 | static void cpu5wdt_start(void) | 103 | static void cpu5wdt_start(void) |
102 | { | 104 | { |
103 | if ( !cpu5wdt_device.queue ) { | 105 | unsigned long flags; |
106 | |||
107 | spin_lock_irqsave(&cpu5wdt_lock, flags); | ||
108 | if (!cpu5wdt_device.queue) { | ||
104 | cpu5wdt_device.queue = 1; | 109 | cpu5wdt_device.queue = 1; |
105 | outb(0, port + CPU5WDT_TIME_A_REG); | 110 | outb(0, port + CPU5WDT_TIME_A_REG); |
106 | outb(0, port + CPU5WDT_TIME_B_REG); | 111 | outb(0, port + CPU5WDT_TIME_B_REG); |
@@ -111,18 +116,20 @@ static void cpu5wdt_start(void) | |||
111 | } | 116 | } |
112 | /* if process dies, counter is not decremented */ | 117 | /* if process dies, counter is not decremented */ |
113 | cpu5wdt_device.running++; | 118 | cpu5wdt_device.running++; |
119 | spin_unlock_irqrestore(&cpu5wdt_lock, flags); | ||
114 | } | 120 | } |
115 | 121 | ||
116 | static int cpu5wdt_stop(void) | 122 | static int cpu5wdt_stop(void) |
117 | { | 123 | { |
118 | if ( cpu5wdt_device.running ) | 124 | unsigned long flags; |
119 | cpu5wdt_device.running = 0; | ||
120 | 125 | ||
126 | spin_lock_irqsave(&cpu5wdt_lock, flags); | ||
127 | if (cpu5wdt_device.running) | ||
128 | cpu5wdt_device.running = 0; | ||
121 | ticks = cpu5wdt_device.default_ticks; | 129 | ticks = cpu5wdt_device.default_ticks; |
122 | 130 | spin_unlock_irqrestore(&cpu5wdt_lock, flags); | |
123 | if ( verbose ) | 131 | if (verbose) |
124 | printk(KERN_CRIT PFX "stop not possible\n"); | 132 | printk(KERN_CRIT PFX "stop not possible\n"); |
125 | |||
126 | return -EIO; | 133 | return -EIO; |
127 | } | 134 | } |
128 | 135 | ||
@@ -130,9 +137,8 @@ static int cpu5wdt_stop(void) | |||
130 | 137 | ||
131 | static int cpu5wdt_open(struct inode *inode, struct file *file) | 138 | static int cpu5wdt_open(struct inode *inode, struct file *file) |
132 | { | 139 | { |
133 | if ( test_and_set_bit(0, &cpu5wdt_device.inuse) ) | 140 | if (test_and_set_bit(0, &cpu5wdt_device.inuse)) |
134 | return -EBUSY; | 141 | return -EBUSY; |
135 | |||
136 | return nonseekable_open(inode, file); | 142 | return nonseekable_open(inode, file); |
137 | } | 143 | } |
138 | 144 | ||
@@ -142,67 +148,58 @@ static int cpu5wdt_release(struct inode *inode, struct file *file) | |||
142 | return 0; | 148 | return 0; |
143 | } | 149 | } |
144 | 150 | ||
145 | static int cpu5wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) | 151 | static long cpu5wdt_ioctl(struct file *file, unsigned int cmd, |
152 | unsigned long arg) | ||
146 | { | 153 | { |
147 | void __user *argp = (void __user *)arg; | 154 | void __user *argp = (void __user *)arg; |
155 | int __user *p = argp; | ||
148 | unsigned int value; | 156 | unsigned int value; |
149 | static struct watchdog_info ident = | 157 | static struct watchdog_info ident = { |
150 | { | ||
151 | .options = WDIOF_CARDRESET, | 158 | .options = WDIOF_CARDRESET, |
152 | .identity = "CPU5 WDT", | 159 | .identity = "CPU5 WDT", |
153 | }; | 160 | }; |
154 | 161 | ||
155 | switch(cmd) { | 162 | switch (cmd) { |
156 | case WDIOC_KEEPALIVE: | 163 | case WDIOC_KEEPALIVE: |
157 | cpu5wdt_reset(); | 164 | cpu5wdt_reset(); |
158 | break; | 165 | break; |
159 | case WDIOC_GETSTATUS: | 166 | case WDIOC_GETSTATUS: |
160 | value = inb(port + CPU5WDT_STATUS_REG); | 167 | value = inb(port + CPU5WDT_STATUS_REG); |
161 | value = (value >> 2) & 1; | 168 | value = (value >> 2) & 1; |
162 | if ( copy_to_user(argp, &value, sizeof(int)) ) | 169 | return put_user(value, p); |
163 | return -EFAULT; | 170 | case WDIOC_GETBOOTSTATUS: |
164 | break; | 171 | return put_user(0, p); |
165 | case WDIOC_GETBOOTSTATUS: | 172 | case WDIOC_GETSUPPORT: |
166 | if ( copy_to_user(argp, &value, sizeof(int)) ) | 173 | if (copy_to_user(argp, &ident, sizeof(ident))) |
167 | return -EFAULT; | 174 | return -EFAULT; |
168 | break; | 175 | break; |
169 | case WDIOC_GETSUPPORT: | 176 | case WDIOC_SETOPTIONS: |
170 | if ( copy_to_user(argp, &ident, sizeof(ident)) ) | 177 | if (get_user(value, p)) |
171 | return -EFAULT; | 178 | return -EFAULT; |
172 | break; | 179 | if (value & WDIOS_ENABLECARD) |
173 | case WDIOC_SETOPTIONS: | 180 | cpu5wdt_start(); |
174 | if ( copy_from_user(&value, argp, sizeof(int)) ) | 181 | if (value & WDIOS_DISABLECARD) |
175 | return -EFAULT; | 182 | cpu5wdt_stop(); |
176 | switch(value) { | 183 | break; |
177 | case WDIOS_ENABLECARD: | 184 | default: |
178 | cpu5wdt_start(); | 185 | return -ENOTTY; |
179 | break; | ||
180 | case WDIOS_DISABLECARD: | ||
181 | return cpu5wdt_stop(); | ||
182 | default: | ||
183 | return -EINVAL; | ||
184 | } | ||
185 | break; | ||
186 | default: | ||
187 | return -ENOTTY; | ||
188 | } | 186 | } |
189 | return 0; | 187 | return 0; |
190 | } | 188 | } |
191 | 189 | ||
192 | static ssize_t cpu5wdt_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) | 190 | static ssize_t cpu5wdt_write(struct file *file, const char __user *buf, |
191 | size_t count, loff_t *ppos) | ||
193 | { | 192 | { |
194 | if ( !count ) | 193 | if (!count) |
195 | return -EIO; | 194 | return -EIO; |
196 | |||
197 | cpu5wdt_reset(); | 195 | cpu5wdt_reset(); |
198 | |||
199 | return count; | 196 | return count; |
200 | } | 197 | } |
201 | 198 | ||
202 | static const struct file_operations cpu5wdt_fops = { | 199 | static const struct file_operations cpu5wdt_fops = { |
203 | .owner = THIS_MODULE, | 200 | .owner = THIS_MODULE, |
204 | .llseek = no_llseek, | 201 | .llseek = no_llseek, |
205 | .ioctl = cpu5wdt_ioctl, | 202 | .unlocked_ioctl = cpu5wdt_ioctl, |
206 | .open = cpu5wdt_open, | 203 | .open = cpu5wdt_open, |
207 | .write = cpu5wdt_write, | 204 | .write = cpu5wdt_write, |
208 | .release = cpu5wdt_release, | 205 | .release = cpu5wdt_release, |
@@ -221,37 +218,36 @@ static int __devinit cpu5wdt_init(void) | |||
221 | unsigned int val; | 218 | unsigned int val; |
222 | int err; | 219 | int err; |
223 | 220 | ||
224 | if ( verbose ) | 221 | if (verbose) |
225 | printk(KERN_DEBUG PFX "port=0x%x, verbose=%i\n", port, verbose); | 222 | printk(KERN_DEBUG PFX |
223 | "port=0x%x, verbose=%i\n", port, verbose); | ||
226 | 224 | ||
227 | if ( !request_region(port, CPU5WDT_EXTENT, PFX) ) { | 225 | init_completion(&cpu5wdt_device.stop); |
226 | spin_lock_init(&cpu5wdt_lock); | ||
227 | cpu5wdt_device.queue = 0; | ||
228 | setup_timer(&cpu5wdt_device.timer, cpu5wdt_trigger, 0); | ||
229 | cpu5wdt_device.default_ticks = ticks; | ||
230 | |||
231 | if (!request_region(port, CPU5WDT_EXTENT, PFX)) { | ||
228 | printk(KERN_ERR PFX "request_region failed\n"); | 232 | printk(KERN_ERR PFX "request_region failed\n"); |
229 | err = -EBUSY; | 233 | err = -EBUSY; |
230 | goto no_port; | 234 | goto no_port; |
231 | } | 235 | } |
232 | 236 | ||
233 | if ( (err = misc_register(&cpu5wdt_misc)) < 0 ) { | ||
234 | printk(KERN_ERR PFX "misc_register failed\n"); | ||
235 | goto no_misc; | ||
236 | } | ||
237 | |||
238 | /* watchdog reboot? */ | 237 | /* watchdog reboot? */ |
239 | val = inb(port + CPU5WDT_STATUS_REG); | 238 | val = inb(port + CPU5WDT_STATUS_REG); |
240 | val = (val >> 2) & 1; | 239 | val = (val >> 2) & 1; |
241 | if ( !val ) | 240 | if (!val) |
242 | printk(KERN_INFO PFX "sorry, was my fault\n"); | 241 | printk(KERN_INFO PFX "sorry, was my fault\n"); |
243 | 242 | ||
244 | init_completion(&cpu5wdt_device.stop); | 243 | err = misc_register(&cpu5wdt_misc); |
245 | cpu5wdt_device.queue = 0; | 244 | if (err < 0) { |
246 | 245 | printk(KERN_ERR PFX "misc_register failed\n"); | |
247 | clear_bit(0, &cpu5wdt_device.inuse); | 246 | goto no_misc; |
248 | 247 | } | |
249 | setup_timer(&cpu5wdt_device.timer, cpu5wdt_trigger, 0); | ||
250 | 248 | ||
251 | cpu5wdt_device.default_ticks = ticks; | ||
252 | 249 | ||
253 | printk(KERN_INFO PFX "init success\n"); | 250 | printk(KERN_INFO PFX "init success\n"); |
254 | |||
255 | return 0; | 251 | return 0; |
256 | 252 | ||
257 | no_misc: | 253 | no_misc: |
@@ -267,7 +263,7 @@ static int __devinit cpu5wdt_init_module(void) | |||
267 | 263 | ||
268 | static void __devexit cpu5wdt_exit(void) | 264 | static void __devexit cpu5wdt_exit(void) |
269 | { | 265 | { |
270 | if ( cpu5wdt_device.queue ) { | 266 | if (cpu5wdt_device.queue) { |
271 | cpu5wdt_device.queue = 0; | 267 | cpu5wdt_device.queue = 0; |
272 | wait_for_completion(&cpu5wdt_device.stop); | 268 | wait_for_completion(&cpu5wdt_device.stop); |
273 | } | 269 | } |