]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
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> | |
1da177e4 LT |
38 | #include <linux/types.h> |
39 | #include <linux/kernel.h> | |
40 | #include <linux/fs.h> | |
41 | #include <linux/mm.h> | |
42 | #include <linux/miscdevice.h> | |
43 | #include <linux/watchdog.h> | |
44 | #include <linux/reboot.h> | |
45 | #include <linux/smp_lock.h> | |
46 | #include <linux/init.h> | |
47 | #include <asm/uaccess.h> | |
1da177e4 LT |
48 | #include "mconsole.h" |
49 | ||
50 | MODULE_LICENSE("GPL"); | |
51 | ||
52 | /* Locked by the BKL in harddog_open and harddog_release */ | |
53 | static int timer_alive; | |
54 | static int harddog_in_fd = -1; | |
55 | static int harddog_out_fd = -1; | |
56 | ||
57 | /* | |
58 | * Allow only one person to hold it open | |
59 | */ | |
60 | ||
61 | extern int start_watchdog(int *in_fd_ret, int *out_fd_ret, char *sock); | |
62 | ||
63 | static int harddog_open(struct inode *inode, struct file *file) | |
64 | { | |
65 | int err; | |
66 | char *sock = NULL; | |
67 | ||
68 | lock_kernel(); | |
69 | if(timer_alive) | |
70 | return -EBUSY; | |
71 | #ifdef CONFIG_HARDDOG_NOWAYOUT | |
72 | __module_get(THIS_MODULE); | |
73 | #endif | |
74 | ||
75 | #ifdef CONFIG_MCONSOLE | |
76 | sock = mconsole_notify_socket(); | |
77 | #endif | |
78 | err = start_watchdog(&harddog_in_fd, &harddog_out_fd, sock); | |
79 | if(err) return(err); | |
80 | ||
81 | timer_alive = 1; | |
82 | unlock_kernel(); | |
83 | return nonseekable_open(inode, file); | |
84 | } | |
85 | ||
86 | extern void stop_watchdog(int in_fd, int out_fd); | |
87 | ||
88 | static int harddog_release(struct inode *inode, struct file *file) | |
89 | { | |
90 | /* | |
91 | * Shut off the timer. | |
92 | */ | |
93 | lock_kernel(); | |
94 | ||
95 | stop_watchdog(harddog_in_fd, harddog_out_fd); | |
96 | harddog_in_fd = -1; | |
97 | harddog_out_fd = -1; | |
98 | ||
99 | timer_alive=0; | |
100 | unlock_kernel(); | |
101 | return 0; | |
102 | } | |
103 | ||
104 | extern int ping_watchdog(int fd); | |
105 | ||
4d338e1a | 106 | static ssize_t harddog_write(struct file *file, const char __user *data, size_t len, |
1da177e4 LT |
107 | loff_t *ppos) |
108 | { | |
109 | /* | |
110 | * Refresh the timer. | |
111 | */ | |
112 | if(len) | |
113 | return(ping_watchdog(harddog_out_fd)); | |
114 | return 0; | |
115 | } | |
116 | ||
117 | static int harddog_ioctl(struct inode *inode, struct file *file, | |
118 | unsigned int cmd, unsigned long arg) | |
119 | { | |
4d338e1a | 120 | void __user *argp= (void __user *)arg; |
1da177e4 LT |
121 | static struct watchdog_info ident = { |
122 | WDIOC_SETTIMEOUT, | |
123 | 0, | |
124 | "UML Hardware Watchdog" | |
125 | }; | |
126 | switch (cmd) { | |
127 | default: | |
128 | return -ENOTTY; | |
129 | case WDIOC_GETSUPPORT: | |
4d338e1a | 130 | if(copy_to_user(argp, &ident, sizeof(ident))) |
1da177e4 LT |
131 | return -EFAULT; |
132 | return 0; | |
133 | case WDIOC_GETSTATUS: | |
134 | case WDIOC_GETBOOTSTATUS: | |
4d338e1a | 135 | return put_user(0,(int __user *)argp); |
1da177e4 LT |
136 | case WDIOC_KEEPALIVE: |
137 | return(ping_watchdog(harddog_out_fd)); | |
138 | } | |
139 | } | |
140 | ||
141 | static struct file_operations harddog_fops = { | |
142 | .owner = THIS_MODULE, | |
143 | .write = harddog_write, | |
144 | .ioctl = harddog_ioctl, | |
145 | .open = harddog_open, | |
146 | .release = harddog_release, | |
147 | }; | |
148 | ||
149 | static struct miscdevice harddog_miscdev = { | |
150 | .minor = WATCHDOG_MINOR, | |
151 | .name = "watchdog", | |
152 | .fops = &harddog_fops, | |
153 | }; | |
154 | ||
155 | static char banner[] __initdata = KERN_INFO "UML Watchdog Timer\n"; | |
156 | ||
157 | static int __init harddog_init(void) | |
158 | { | |
159 | int ret; | |
160 | ||
161 | ret = misc_register(&harddog_miscdev); | |
162 | ||
163 | if (ret) | |
164 | return ret; | |
165 | ||
166 | printk(banner); | |
167 | ||
168 | return(0); | |
169 | } | |
170 | ||
171 | static void __exit harddog_exit(void) | |
172 | { | |
173 | misc_deregister(&harddog_miscdev); | |
174 | } | |
175 | ||
176 | module_init(harddog_init); | |
177 | module_exit(harddog_exit); | |
178 | ||
179 | /* | |
180 | * Overrides for Emacs so that we follow Linus's tabbing style. | |
181 | * Emacs will notice this stuff at the end of the file and automatically | |
182 | * adjust the settings for this buffer only. This must remain at the end | |
183 | * of the file. | |
184 | * --------------------------------------------------------------------------- | |
185 | * Local variables: | |
186 | * c-file-style: "linux" | |
187 | * End: | |
188 | */ |