[SECMARK]: Add secmark support to conntrack
[linux-2.6.git] / drivers / char / watchdog / indydog.c
blobb4b94daba67ea55e916173bf1738e422b2eec5d4
1 /*
2 * IndyDog 0.3 A Hardware Watchdog Device for SGI IP22
4 * (c) Copyright 2002 Guido Guenther <agx@sigxcpu.org>, All Rights Reserved.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
11 * based on softdog.c by Alan Cox <alan@redhat.com>
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
16 #include <linux/config.h>
17 #include <linux/types.h>
18 #include <linux/kernel.h>
19 #include <linux/fs.h>
20 #include <linux/mm.h>
21 #include <linux/miscdevice.h>
22 #include <linux/watchdog.h>
23 #include <linux/notifier.h>
24 #include <linux/reboot.h>
25 #include <linux/init.h>
26 #include <asm/uaccess.h>
27 #include <asm/sgi/mc.h>
29 #define PFX "indydog: "
30 static int indydog_alive;
32 #define WATCHDOG_TIMEOUT 30 /* 30 sec default timeout */
34 static int nowayout = WATCHDOG_NOWAYOUT;
35 module_param(nowayout, int, 0);
36 MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
38 static void indydog_start(void)
40 u32 mc_ctrl0 = sgimc->cpuctrl0;
42 mc_ctrl0 = sgimc->cpuctrl0 | SGIMC_CCTRL0_WDOG;
43 sgimc->cpuctrl0 = mc_ctrl0;
46 static void indydog_stop(void)
48 u32 mc_ctrl0 = sgimc->cpuctrl0;
50 mc_ctrl0 &= ~SGIMC_CCTRL0_WDOG;
51 sgimc->cpuctrl0 = mc_ctrl0;
53 printk(KERN_INFO PFX "Stopped watchdog timer.\n");
56 static void indydog_ping(void)
58 sgimc->watchdogt = 0;
62 * Allow only one person to hold it open
64 static int indydog_open(struct inode *inode, struct file *file)
66 if (indydog_alive)
67 return -EBUSY;
69 if (nowayout)
70 __module_get(THIS_MODULE);
72 /* Activate timer */
73 indydog_start();
74 indydog_ping();
76 indydog_alive = 1;
77 printk(KERN_INFO "Started watchdog timer.\n");
79 return nonseekable_open(inode, file);
82 static int indydog_release(struct inode *inode, struct file *file)
84 /* Shut off the timer.
85 * Lock it in if it's a module and we defined ...NOWAYOUT */
86 if (!nowayout)
87 indydog_stop(); /* Turn the WDT off */
89 indydog_alive = 0;
91 return 0;
94 static ssize_t indydog_write(struct file *file, const char *data, size_t len, loff_t *ppos)
96 /* Refresh the timer. */
97 if (len) {
98 indydog_ping();
100 return len;
103 static int indydog_ioctl(struct inode *inode, struct file *file,
104 unsigned int cmd, unsigned long arg)
106 int options, retval = -EINVAL;
107 static struct watchdog_info ident = {
108 .options = WDIOF_KEEPALIVEPING |
109 WDIOF_MAGICCLOSE,
110 .firmware_version = 0,
111 .identity = "Hardware Watchdog for SGI IP22",
114 switch (cmd) {
115 default:
116 return -ENOIOCTLCMD;
117 case WDIOC_GETSUPPORT:
118 if (copy_to_user((struct watchdog_info *)arg,
119 &ident, sizeof(ident)))
120 return -EFAULT;
121 return 0;
122 case WDIOC_GETSTATUS:
123 case WDIOC_GETBOOTSTATUS:
124 return put_user(0,(int *)arg);
125 case WDIOC_KEEPALIVE:
126 indydog_ping();
127 return 0;
128 case WDIOC_GETTIMEOUT:
129 return put_user(WATCHDOG_TIMEOUT,(int *)arg);
130 case WDIOC_SETOPTIONS:
132 if (get_user(options, (int *)arg))
133 return -EFAULT;
135 if (options & WDIOS_DISABLECARD) {
136 indydog_stop();
137 retval = 0;
140 if (options & WDIOS_ENABLECARD) {
141 indydog_start();
142 retval = 0;
145 return retval;
150 static int indydog_notify_sys(struct notifier_block *this, unsigned long code, void *unused)
152 if (code == SYS_DOWN || code == SYS_HALT)
153 indydog_stop(); /* Turn the WDT off */
155 return NOTIFY_DONE;
158 static struct file_operations indydog_fops = {
159 .owner = THIS_MODULE,
160 .llseek = no_llseek,
161 .write = indydog_write,
162 .ioctl = indydog_ioctl,
163 .open = indydog_open,
164 .release = indydog_release,
167 static struct miscdevice indydog_miscdev = {
168 .minor = WATCHDOG_MINOR,
169 .name = "watchdog",
170 .fops = &indydog_fops,
173 static struct notifier_block indydog_notifier = {
174 .notifier_call = indydog_notify_sys,
177 static char banner[] __initdata =
178 KERN_INFO PFX "Hardware Watchdog Timer for SGI IP22: 0.3\n";
180 static int __init watchdog_init(void)
182 int ret;
184 ret = register_reboot_notifier(&indydog_notifier);
185 if (ret) {
186 printk(KERN_ERR PFX "cannot register reboot notifier (err=%d)\n",
187 ret);
188 return ret;
191 ret = misc_register(&indydog_miscdev);
192 if (ret) {
193 printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
194 WATCHDOG_MINOR, ret);
195 unregister_reboot_notifier(&indydog_notifier);
196 return ret;
199 printk(banner);
201 return 0;
204 static void __exit watchdog_exit(void)
206 misc_deregister(&indydog_miscdev);
207 unregister_reboot_notifier(&indydog_notifier);
210 module_init(watchdog_init);
211 module_exit(watchdog_exit);
213 MODULE_AUTHOR("Guido Guenther <agx@sigxcpu.org>");
214 MODULE_DESCRIPTION("Hardware Watchdog Device for SGI IP22");
215 MODULE_LICENSE("GPL");
216 MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);