[XFRM]: skb_cow_data() does not set proper owner for new skbs.
[linux-2.6/verdex.git] / drivers / char / watchdog / acquirewdt.c
blob8f302121741bc9a08c53695898f1db3b2c39a8db
1 /*
2 * Acquire Single Board Computer Watchdog Timer driver
4 * Based on wdt.c. Original copyright messages:
6 * (c) Copyright 1996 Alan Cox <alan@redhat.com>, All Rights Reserved.
7 * http://www.redhat.com
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
14 * Neither Alan Cox nor CymruNet Ltd. admit liability nor provide
15 * warranty for any of this software. This material is provided
16 * "AS-IS" and at no charge.
18 * (c) Copyright 1995 Alan Cox <alan@redhat.com>
20 * 14-Dec-2001 Matt Domsch <Matt_Domsch@dell.com>
21 * Added nowayout module option to override CONFIG_WATCHDOG_NOWAYOUT
22 * Can't add timeout - driver doesn't allow changing value
26 * Theory of Operation:
27 * The Watch-Dog Timer is provided to ensure that standalone
28 * Systems can always recover from catastrophic conditions that
29 * caused the CPU to crash. This condition may have occured by
30 * external EMI or a software bug. When the CPU stops working
31 * correctly, hardware on the board will either perform a hardware
32 * reset (cold boot) or a non-maskable interrupt (NMI) to bring the
33 * system back to a known state.
35 * The Watch-Dog Timer is controlled by two I/O Ports.
36 * 443 hex - Read - Enable or refresh the Watch-Dog Timer
37 * 043 hex - Read - Disable the Watch-Dog Timer
39 * To enable the Watch-Dog Timer, a read from I/O port 443h must
40 * be performed. This will enable and activate the countdown timer
41 * which will eventually time out and either reset the CPU or cause
42 * an NMI depending on the setting of a jumper. To ensure that this
43 * reset condition does not occur, the Watch-Dog Timer must be
44 * periodically refreshed by reading the same I/O port 443h.
45 * The Watch-Dog Timer is disabled by reading I/O port 043h.
47 * The Watch-Dog Timer Time-Out Period is set via jumpers.
48 * It can be 1, 2, 10, 20, 110 or 220 seconds.
51 #include <linux/module.h>
52 #include <linux/moduleparam.h>
53 #include <linux/types.h>
54 #include <linux/miscdevice.h>
55 #include <linux/watchdog.h>
56 #include <linux/fs.h>
57 #include <linux/ioport.h>
58 #include <linux/notifier.h>
59 #include <linux/reboot.h>
60 #include <linux/init.h>
62 #include <asm/io.h>
63 #include <asm/uaccess.h>
64 #include <asm/system.h>
66 #define WATCHDOG_NAME "Acquire WDT"
67 #define PFX WATCHDOG_NAME ": "
68 #define WATCHDOG_HEARTBEAT 0 /* There is no way to see what the correct time-out period is */
70 static unsigned long acq_is_open;
71 static char expect_close;
74 * You must set these - there is no sane way to probe for this board.
77 static int wdt_stop = 0x43;
78 module_param(wdt_stop, int, 0);
79 MODULE_PARM_DESC(wdt_stop, "Acquire WDT 'stop' io port (default 0x43)");
81 static int wdt_start = 0x443;
82 module_param(wdt_start, int, 0);
83 MODULE_PARM_DESC(wdt_start, "Acquire WDT 'start' io port (default 0x443)");
85 #ifdef CONFIG_WATCHDOG_NOWAYOUT
86 static int nowayout = 1;
87 #else
88 static int nowayout = 0;
89 #endif
91 module_param(nowayout, int, 0);
92 MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
95 * Kernel methods.
98 static void acq_keepalive(void)
100 /* Write a watchdog value */
101 inb_p(wdt_start);
104 static void acq_stop(void)
106 /* Turn the card off */
107 inb_p(wdt_stop);
111 * /dev/watchdog handling.
114 static ssize_t acq_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
116 /* See if we got the magic character 'V' and reload the timer */
117 if(count) {
118 if (!nowayout) {
119 size_t i;
121 /* note: just in case someone wrote the magic character
122 * five months ago... */
123 expect_close = 0;
125 /* scan to see whether or not we got the magic character */
126 for (i = 0; i != count; i++) {
127 char c;
128 if (get_user(c, buf + i))
129 return -EFAULT;
130 if (c == 'V')
131 expect_close = 42;
135 /* Well, anyhow someone wrote to us, we should return that favour */
136 acq_keepalive();
138 return count;
141 static int acq_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
142 unsigned long arg)
144 int options, retval = -EINVAL;
145 void __user *argp = (void __user *)arg;
146 int __user *p = argp;
147 static struct watchdog_info ident =
149 .options = WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
150 .firmware_version = 1,
151 .identity = "Acquire WDT",
154 switch(cmd)
156 case WDIOC_GETSUPPORT:
157 return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
159 case WDIOC_GETSTATUS:
160 case WDIOC_GETBOOTSTATUS:
161 return put_user(0, p);
163 case WDIOC_KEEPALIVE:
164 acq_keepalive();
165 return 0;
167 case WDIOC_GETTIMEOUT:
168 return put_user(WATCHDOG_HEARTBEAT, p);
170 case WDIOC_SETOPTIONS:
172 if (get_user(options, p))
173 return -EFAULT;
175 if (options & WDIOS_DISABLECARD)
177 acq_stop();
178 retval = 0;
181 if (options & WDIOS_ENABLECARD)
183 acq_keepalive();
184 retval = 0;
187 return retval;
190 default:
191 return -ENOIOCTLCMD;
195 static int acq_open(struct inode *inode, struct file *file)
197 if (test_and_set_bit(0, &acq_is_open))
198 return -EBUSY;
200 if (nowayout)
201 __module_get(THIS_MODULE);
203 /* Activate */
204 acq_keepalive();
205 return nonseekable_open(inode, file);
208 static int acq_close(struct inode *inode, struct file *file)
210 if (expect_close == 42) {
211 acq_stop();
212 } else {
213 printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n");
214 acq_keepalive();
216 clear_bit(0, &acq_is_open);
217 expect_close = 0;
218 return 0;
222 * Notifier for system down
225 static int acq_notify_sys(struct notifier_block *this, unsigned long code,
226 void *unused)
228 if(code==SYS_DOWN || code==SYS_HALT) {
229 /* Turn the WDT off */
230 acq_stop();
232 return NOTIFY_DONE;
236 * Kernel Interfaces
239 static struct file_operations acq_fops = {
240 .owner = THIS_MODULE,
241 .llseek = no_llseek,
242 .write = acq_write,
243 .ioctl = acq_ioctl,
244 .open = acq_open,
245 .release = acq_close,
248 static struct miscdevice acq_miscdev=
250 .minor = WATCHDOG_MINOR,
251 .name = "watchdog",
252 .fops = &acq_fops,
256 * The WDT card needs to learn about soft shutdowns in order to
257 * turn the timebomb registers off.
260 static struct notifier_block acq_notifier =
262 .notifier_call = acq_notify_sys,
265 static int __init acq_init(void)
267 int ret;
269 printk(KERN_INFO "WDT driver for Acquire single board computer initialising.\n");
271 if (wdt_stop != wdt_start) {
272 if (!request_region(wdt_stop, 1, WATCHDOG_NAME)) {
273 printk (KERN_ERR PFX "I/O address 0x%04x already in use\n",
274 wdt_stop);
275 ret = -EIO;
276 goto out;
280 if (!request_region(wdt_start, 1, WATCHDOG_NAME)) {
281 printk (KERN_ERR PFX "I/O address 0x%04x already in use\n",
282 wdt_start);
283 ret = -EIO;
284 goto unreg_stop;
287 ret = register_reboot_notifier(&acq_notifier);
288 if (ret != 0) {
289 printk (KERN_ERR PFX "cannot register reboot notifier (err=%d)\n",
290 ret);
291 goto unreg_regions;
294 ret = misc_register(&acq_miscdev);
295 if (ret != 0) {
296 printk (KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
297 WATCHDOG_MINOR, ret);
298 goto unreg_reboot;
301 printk (KERN_INFO PFX "initialized. (nowayout=%d)\n",
302 nowayout);
304 return 0;
306 unreg_reboot:
307 unregister_reboot_notifier(&acq_notifier);
308 unreg_regions:
309 release_region(wdt_start, 1);
310 unreg_stop:
311 if (wdt_stop != wdt_start)
312 release_region(wdt_stop, 1);
313 out:
314 return ret;
317 static void __exit acq_exit(void)
319 misc_deregister(&acq_miscdev);
320 unregister_reboot_notifier(&acq_notifier);
321 if(wdt_stop != wdt_start)
322 release_region(wdt_stop,1);
323 release_region(wdt_start,1);
326 module_init(acq_init);
327 module_exit(acq_exit);
329 MODULE_AUTHOR("David Woodhouse");
330 MODULE_DESCRIPTION("Acquire Inc. Single Board Computer Watchdog Timer driver");
331 MODULE_LICENSE("GPL");
332 MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);