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/types.h>
39 #include <linux/kernel.h>
42 #include <linux/miscdevice.h>
43 #include <linux/watchdog.h>
44 #include <linux/reboot.h>
45 #include <linux/mutex.h>
46 #include <linux/init.h>
47 #include <linux/spinlock.h>
48 #include <linux/uaccess.h>
51 MODULE_LICENSE("GPL");
53 static DEFINE_MUTEX(harddog_mutex
);
54 static DEFINE_SPINLOCK(lock
);
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
)
70 mutex_lock(&harddog_mutex
);
74 #ifdef CONFIG_WATCHDOG_NOWAYOUT
75 __module_get(THIS_MODULE
);
78 #ifdef CONFIG_MCONSOLE
79 sock
= mconsole_notify_socket();
81 err
= start_watchdog(&harddog_in_fd
, &harddog_out_fd
, sock
);
87 mutex_unlock(&harddog_mutex
);
88 return nonseekable_open(inode
, file
);
91 mutex_unlock(&harddog_mutex
);
95 extern void stop_watchdog(int in_fd
, int out_fd
);
97 static int harddog_release(struct inode
*inode
, struct file
*file
)
100 * Shut off the timer.
105 stop_watchdog(harddog_in_fd
, harddog_out_fd
);
115 extern int ping_watchdog(int fd
);
117 static ssize_t
harddog_write(struct file
*file
, const char __user
*data
, size_t len
,
124 return ping_watchdog(harddog_out_fd
);
128 static int harddog_ioctl_unlocked(struct file
*file
,
129 unsigned int cmd
, unsigned long arg
)
131 void __user
*argp
= (void __user
*)arg
;
132 static struct watchdog_info ident
= {
135 "UML Hardware Watchdog"
140 case WDIOC_GETSUPPORT
:
141 if(copy_to_user(argp
, &ident
, sizeof(ident
)))
144 case WDIOC_GETSTATUS
:
145 case WDIOC_GETBOOTSTATUS
:
146 return put_user(0,(int __user
*)argp
);
147 case WDIOC_KEEPALIVE
:
148 return ping_watchdog(harddog_out_fd
);
152 static long harddog_ioctl(struct file
*file
,
153 unsigned int cmd
, unsigned long arg
)
157 mutex_lock(&harddog_mutex
);
158 ret
= harddog_ioctl_unlocked(file
, cmd
, arg
);
159 mutex_unlock(&harddog_mutex
);
164 static const struct file_operations harddog_fops
= {
165 .owner
= THIS_MODULE
,
166 .write
= harddog_write
,
167 .unlocked_ioctl
= harddog_ioctl
,
168 .open
= harddog_open
,
169 .release
= harddog_release
,
173 static struct miscdevice harddog_miscdev
= {
174 .minor
= WATCHDOG_MINOR
,
176 .fops
= &harddog_fops
,
178 module_misc_device(harddog_miscdev
);