1 /* UML hardware watchdog, shamelessly stolen from:
3 * SoftDog 0.05: A Software Watchdog Device
5 * (c) Copyright 1996 Alan Cox <alan@redhat.com>, All Rights Reserved.
6 * http://www.redhat.com
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
13 * Neither Alan Cox nor CymruNet Ltd. admit liability nor provide
14 * warranty for any of this software. This material is provided
15 * "AS-IS" and at no charge.
17 * (c) Copyright 1995 Alan Cox <alan@lxorguk.ukuu.org.uk>
19 * Software only watchdog driver. Unlike its big brother the WDT501P
20 * driver this won't always recover a failed machine.
22 * 03/96: Angelo Haritsis <ah@doc.ic.ac.uk> :
24 * Added soft_margin; use upon insmod to change the timer delay.
25 * NB: uses same minor as wdt (WATCHDOG_MINOR); we could use separate
29 * Made SMP safe for 2.3.x
31 * 20011127 Joel Becker (jlbec@evilplan.org>
32 * Added soft_noboot; Allows testing the softdog trigger without
33 * requiring a recompile.
34 * Added WDIOC_GETTIMEOUT and WDIOC_SETTIMOUT.
37 #include <linux/module.h>
38 #include <linux/config.h>
39 #include <linux/types.h>
40 #include <linux/kernel.h>
43 #include <linux/miscdevice.h>
44 #include <linux/watchdog.h>
45 #include <linux/reboot.h>
46 #include <linux/smp_lock.h>
47 #include <linux/init.h>
48 #include <asm/uaccess.h>
52 MODULE_LICENSE("GPL");
54 /* Locked by the BKL in harddog_open and harddog_release */
55 static int timer_alive;
56 static int harddog_in_fd = -1;
57 static int harddog_out_fd = -1;
60 * Allow only one person to hold it open
63 extern int start_watchdog(int *in_fd_ret, int *out_fd_ret, char *sock);
65 static int harddog_open(struct inode *inode, struct file *file)
73 #ifdef CONFIG_HARDDOG_NOWAYOUT
77 #ifdef CONFIG_MCONSOLE
78 sock = mconsole_notify_socket();
80 err = start_watchdog(&harddog_in_fd, &harddog_out_fd, sock);
88 extern void stop_watchdog(int in_fd, int out_fd);
90 static int harddog_release(struct inode *inode, struct file *file)
97 stop_watchdog(harddog_in_fd, harddog_out_fd);
106 extern int ping_watchdog(int fd);
108 static ssize_t harddog_write(struct file *file, const char *data, size_t len,
111 /* Can't seek (pwrite) on this device */
112 if (ppos != &file->f_pos)
119 return(ping_watchdog(harddog_out_fd));
123 static int harddog_ioctl(struct inode *inode, struct file *file,
124 unsigned int cmd, unsigned long arg)
126 static struct watchdog_info ident = {
129 "UML Hardware Watchdog"
134 case WDIOC_GETSUPPORT:
135 if(copy_to_user((struct harddog_info *)arg, &ident,
139 case WDIOC_GETSTATUS:
140 case WDIOC_GETBOOTSTATUS:
141 return put_user(0,(int *)arg);
142 case WDIOC_KEEPALIVE:
143 return(ping_watchdog(harddog_out_fd));
147 static struct file_operations harddog_fops = {
148 .owner = THIS_MODULE,
149 .write = harddog_write,
150 .ioctl = harddog_ioctl,
151 .open = harddog_open,
152 .release = harddog_release,
155 static struct miscdevice harddog_miscdev = {
156 .minor = WATCHDOG_MINOR,
158 .fops = &harddog_fops,
161 static char banner[] __initdata = KERN_INFO "UML Watchdog Timer\n";
163 static int __init harddog_init(void)
167 ret = misc_register(&harddog_miscdev);
177 static void __exit harddog_exit(void)
179 misc_deregister(&harddog_miscdev);
182 module_init(harddog_init);
183 module_exit(harddog_exit);
186 * Overrides for Emacs so that we follow Linus's tabbing style.
187 * Emacs will notice this stuff at the end of the file and automatically
188 * adjust the settings for this buffer only. This must remain at the end
190 * ---------------------------------------------------------------------------
192 * c-file-style: "linux"