aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/drivers/harddog_kern.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/um/drivers/harddog_kern.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'arch/um/drivers/harddog_kern.c')
-rw-r--r--arch/um/drivers/harddog_kern.c190
1 files changed, 190 insertions, 0 deletions
diff --git a/arch/um/drivers/harddog_kern.c b/arch/um/drivers/harddog_kern.c
new file mode 100644
index 000000000000..147ec19f6bb9
--- /dev/null
+++ b/arch/um/drivers/harddog_kern.c
@@ -0,0 +1,190 @@
1/* UML hardware watchdog, shamelessly stolen from:
2 *
3 * SoftDog 0.05: A Software Watchdog Device
4 *
5 * (c) Copyright 1996 Alan Cox <alan@redhat.com>, All Rights Reserved.
6 * http://www.redhat.com
7 *
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.
12 *
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.
16 *
17 * (c) Copyright 1995 Alan Cox <alan@lxorguk.ukuu.org.uk>
18 *
19 * Software only watchdog driver. Unlike its big brother the WDT501P
20 * driver this won't always recover a failed machine.
21 *
22 * 03/96: Angelo Haritsis <ah@doc.ic.ac.uk> :
23 * Modularised.
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
26 * minors.
27 *
28 * 19980911 Alan Cox
29 * Made SMP safe for 2.3.x
30 *
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.
35 */
36
37#include <linux/module.h>
38#include <linux/config.h>
39#include <linux/types.h>
40#include <linux/kernel.h>
41#include <linux/fs.h>
42#include <linux/mm.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>
49#include "helper.h"
50#include "mconsole.h"
51
52MODULE_LICENSE("GPL");
53
54/* Locked by the BKL in harddog_open and harddog_release */
55static int timer_alive;
56static int harddog_in_fd = -1;
57static int harddog_out_fd = -1;
58
59/*
60 * Allow only one person to hold it open
61 */
62
63extern int start_watchdog(int *in_fd_ret, int *out_fd_ret, char *sock);
64
65static int harddog_open(struct inode *inode, struct file *file)
66{
67 int err;
68 char *sock = NULL;
69
70 lock_kernel();
71 if(timer_alive)
72 return -EBUSY;
73#ifdef CONFIG_HARDDOG_NOWAYOUT
74 __module_get(THIS_MODULE);
75#endif
76
77#ifdef CONFIG_MCONSOLE
78 sock = mconsole_notify_socket();
79#endif
80 err = start_watchdog(&harddog_in_fd, &harddog_out_fd, sock);
81 if(err) return(err);
82
83 timer_alive = 1;
84 unlock_kernel();
85 return nonseekable_open(inode, file);
86}
87
88extern void stop_watchdog(int in_fd, int out_fd);
89
90static int harddog_release(struct inode *inode, struct file *file)
91{
92 /*
93 * Shut off the timer.
94 */
95 lock_kernel();
96
97 stop_watchdog(harddog_in_fd, harddog_out_fd);
98 harddog_in_fd = -1;
99 harddog_out_fd = -1;
100
101 timer_alive=0;
102 unlock_kernel();
103 return 0;
104}
105
106extern int ping_watchdog(int fd);
107
108static ssize_t harddog_write(struct file *file, const char *data, size_t len,
109 loff_t *ppos)
110{
111 /*
112 * Refresh the timer.
113 */
114 if(len)
115 return(ping_watchdog(harddog_out_fd));
116 return 0;
117}
118
119static int harddog_ioctl(struct inode *inode, struct file *file,
120 unsigned int cmd, unsigned long arg)
121{
122 static struct watchdog_info ident = {
123 WDIOC_SETTIMEOUT,
124 0,
125 "UML Hardware Watchdog"
126 };
127 switch (cmd) {
128 default:
129 return -ENOTTY;
130 case WDIOC_GETSUPPORT:
131 if(copy_to_user((struct harddog_info *)arg, &ident,
132 sizeof(ident)))
133 return -EFAULT;
134 return 0;
135 case WDIOC_GETSTATUS:
136 case WDIOC_GETBOOTSTATUS:
137 return put_user(0,(int *)arg);
138 case WDIOC_KEEPALIVE:
139 return(ping_watchdog(harddog_out_fd));
140 }
141}
142
143static struct file_operations harddog_fops = {
144 .owner = THIS_MODULE,
145 .write = harddog_write,
146 .ioctl = harddog_ioctl,
147 .open = harddog_open,
148 .release = harddog_release,
149};
150
151static struct miscdevice harddog_miscdev = {
152 .minor = WATCHDOG_MINOR,
153 .name = "watchdog",
154 .fops = &harddog_fops,
155};
156
157static char banner[] __initdata = KERN_INFO "UML Watchdog Timer\n";
158
159static int __init harddog_init(void)
160{
161 int ret;
162
163 ret = misc_register(&harddog_miscdev);
164
165 if (ret)
166 return ret;
167
168 printk(banner);
169
170 return(0);
171}
172
173static void __exit harddog_exit(void)
174{
175 misc_deregister(&harddog_miscdev);
176}
177
178module_init(harddog_init);
179module_exit(harddog_exit);
180
181/*
182 * Overrides for Emacs so that we follow Linus's tabbing style.
183 * Emacs will notice this stuff at the end of the file and automatically
184 * adjust the settings for this buffer only. This must remain at the end
185 * of the file.
186 * ---------------------------------------------------------------------------
187 * Local variables:
188 * c-file-style: "linux"
189 * End:
190 */