2 * SoftDog 0.05: A Software Watchdog Device
4 * (c) Copyright 1996 Alan Cox <alan@redhat.com>, All Rights Reserved.
5 * http://www.redhat.com
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
12 * Neither Alan Cox nor CymruNet Ltd. admit liability nor provide
13 * warranty for any of this software. This material is provided
14 * "AS-IS" and at no charge.
16 * (c) Copyright 1995 Alan Cox <alan@lxorguk.ukuu.org.uk>
18 * Software only watchdog driver. Unlike its big brother the WDT501P
19 * driver this won't always recover a failed machine.
21 * 03/96: Angelo Haritsis <ah@doc.ic.ac.uk> :
23 * Added soft_margin; use upon insmod to change the timer delay.
24 * NB: uses same minor as wdt (WATCHDOG_MINOR); we could use separate
28 * Made SMP safe for 2.3.x
31 #include <linux/module.h>
32 #include <linux/config.h>
33 #include <linux/types.h>
34 #include <linux/kernel.h>
37 #include <linux/miscdevice.h>
38 #include <linux/watchdog.h>
39 #include <linux/reboot.h>
40 #include <linux/smp_lock.h>
41 #include <linux/init.h>
42 #include <asm/uaccess.h>
44 #define TIMER_MARGIN 60 /* (secs) Default is 1 minute */
46 static int soft_margin
= TIMER_MARGIN
; /* in seconds */
49 MODULE_PARM(soft_margin
,"i");
56 static void watchdog_fire(unsigned long);
58 static struct timer_list watchdog_ticktock
= {
59 function
: watchdog_fire
,
61 static int timer_alive
;
65 * If the timer expires..
68 static void watchdog_fire(unsigned long data
)
71 printk(KERN_CRIT
"SOFTDOG: Would Reboot.\n");
73 printk(KERN_CRIT
"SOFTDOG: Initiating system reboot.\n");
74 machine_restart(NULL
);
75 printk("WATCHDOG: Reboot didn't ?????\n");
80 * Allow only one person to hold it open
83 static int softdog_open(struct inode
*inode
, struct file
*file
)
87 #ifdef CONFIG_WATCHDOG_NOWAYOUT
93 mod_timer(&watchdog_ticktock
, jiffies
+(soft_margin
*HZ
));
98 static int softdog_release(struct inode
*inode
, struct file
*file
)
101 * Shut off the timer.
102 * Lock it in if it's a module and we defined ...NOWAYOUT
105 #ifndef CONFIG_WATCHDOG_NOWAYOUT
106 del_timer(&watchdog_ticktock
);
113 static ssize_t
softdog_write(struct file
*file
, const char *data
, size_t len
, loff_t
*ppos
)
115 /* Can't seek (pwrite) on this device */
116 if (ppos
!= &file
->f_pos
)
123 mod_timer(&watchdog_ticktock
, jiffies
+(soft_margin
*HZ
));
129 static int softdog_ioctl(struct inode
*inode
, struct file
*file
,
130 unsigned int cmd
, unsigned long arg
)
132 static struct watchdog_info ident
=
142 case WDIOC_GETSUPPORT
:
143 if(copy_to_user((struct watchdog_info
*)arg
, &ident
, sizeof(ident
)))
146 case WDIOC_GETSTATUS
:
147 case WDIOC_GETBOOTSTATUS
:
148 return put_user(0,(int *)arg
);
149 case WDIOC_KEEPALIVE
:
150 mod_timer(&watchdog_ticktock
, jiffies
+(soft_margin
*HZ
));
155 static struct file_operations softdog_fops
=
158 write
: softdog_write
,
159 ioctl
: softdog_ioctl
,
161 release
: softdog_release
,
164 static struct miscdevice softdog_miscdev
=
171 static int __init
watchdog_init(void)
175 ret
= misc_register(&softdog_miscdev
);
180 printk("Software Watchdog Timer: 0.05, timer margin: %d sec\n", soft_margin
);
185 static void __exit
watchdog_exit(void)
187 misc_deregister(&softdog_miscdev
);
190 module_init(watchdog_init
);
191 module_exit(watchdog_exit
);