diff options
Diffstat (limited to 'drivers/watchdog/indydog.c')
-rw-r--r-- | drivers/watchdog/indydog.c | 114 |
1 files changed, 62 insertions, 52 deletions
diff --git a/drivers/watchdog/indydog.c b/drivers/watchdog/indydog.c index 788245bdaa7f..73c9e7992feb 100644 --- a/drivers/watchdog/indydog.c +++ b/drivers/watchdog/indydog.c | |||
@@ -1,7 +1,8 @@ | |||
1 | /* | 1 | /* |
2 | * IndyDog 0.3 A Hardware Watchdog Device for SGI IP22 | 2 | * IndyDog 0.3 A Hardware Watchdog Device for SGI IP22 |
3 | * | 3 | * |
4 | * (c) Copyright 2002 Guido Guenther <agx@sigxcpu.org>, All Rights Reserved. | 4 | * (c) Copyright 2002 Guido Guenther <agx@sigxcpu.org>, |
5 | * All Rights Reserved. | ||
5 | * | 6 | * |
6 | * This program is free software; you can redistribute it and/or | 7 | * This program is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU General Public License | 8 | * modify it under the terms of the GNU General Public License |
@@ -22,32 +23,42 @@ | |||
22 | #include <linux/notifier.h> | 23 | #include <linux/notifier.h> |
23 | #include <linux/reboot.h> | 24 | #include <linux/reboot.h> |
24 | #include <linux/init.h> | 25 | #include <linux/init.h> |
25 | #include <asm/uaccess.h> | 26 | #include <linux/uaccess.h> |
26 | #include <asm/sgi/mc.h> | 27 | #include <asm/sgi/mc.h> |
27 | 28 | ||
28 | #define PFX "indydog: " | 29 | #define PFX "indydog: " |
29 | static int indydog_alive; | 30 | static unsigned long indydog_alive; |
31 | static spinlock_t indydog_lock; | ||
30 | 32 | ||
31 | #define WATCHDOG_TIMEOUT 30 /* 30 sec default timeout */ | 33 | #define WATCHDOG_TIMEOUT 30 /* 30 sec default timeout */ |
32 | 34 | ||
33 | static int nowayout = WATCHDOG_NOWAYOUT; | 35 | static int nowayout = WATCHDOG_NOWAYOUT; |
34 | module_param(nowayout, int, 0); | 36 | module_param(nowayout, int, 0); |
35 | MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); | 37 | MODULE_PARM_DESC(nowayout, |
38 | "Watchdog cannot be stopped once started (default=" | ||
39 | __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); | ||
36 | 40 | ||
37 | static void indydog_start(void) | 41 | static void indydog_start(void) |
38 | { | 42 | { |
39 | u32 mc_ctrl0 = sgimc->cpuctrl0; | 43 | u32 mc_ctrl0; |
40 | 44 | ||
45 | spin_lock(&indydog_lock); | ||
46 | mc_ctrl0 = sgimc->cpuctrl0; | ||
41 | mc_ctrl0 = sgimc->cpuctrl0 | SGIMC_CCTRL0_WDOG; | 47 | mc_ctrl0 = sgimc->cpuctrl0 | SGIMC_CCTRL0_WDOG; |
42 | sgimc->cpuctrl0 = mc_ctrl0; | 48 | sgimc->cpuctrl0 = mc_ctrl0; |
49 | spin_unlock(&indydog_lock); | ||
43 | } | 50 | } |
44 | 51 | ||
45 | static void indydog_stop(void) | 52 | static void indydog_stop(void) |
46 | { | 53 | { |
47 | u32 mc_ctrl0 = sgimc->cpuctrl0; | 54 | u32 mc_ctrl0; |
48 | 55 | ||
56 | spin_lock(&indydog_lock); | ||
57 | |||
58 | mc_ctrl0 = sgimc->cpuctrl0; | ||
49 | mc_ctrl0 &= ~SGIMC_CCTRL0_WDOG; | 59 | mc_ctrl0 &= ~SGIMC_CCTRL0_WDOG; |
50 | sgimc->cpuctrl0 = mc_ctrl0; | 60 | sgimc->cpuctrl0 = mc_ctrl0; |
61 | spin_unlock(&indydog_lock); | ||
51 | 62 | ||
52 | printk(KERN_INFO PFX "Stopped watchdog timer.\n"); | 63 | printk(KERN_INFO PFX "Stopped watchdog timer.\n"); |
53 | } | 64 | } |
@@ -62,7 +73,7 @@ static void indydog_ping(void) | |||
62 | */ | 73 | */ |
63 | static int indydog_open(struct inode *inode, struct file *file) | 74 | static int indydog_open(struct inode *inode, struct file *file) |
64 | { | 75 | { |
65 | if (indydog_alive) | 76 | if (test_and_set_bit(0, &indydog_alive)) |
66 | return -EBUSY; | 77 | return -EBUSY; |
67 | 78 | ||
68 | if (nowayout) | 79 | if (nowayout) |
@@ -84,23 +95,21 @@ static int indydog_release(struct inode *inode, struct file *file) | |||
84 | * Lock it in if it's a module and we defined ...NOWAYOUT */ | 95 | * Lock it in if it's a module and we defined ...NOWAYOUT */ |
85 | if (!nowayout) | 96 | if (!nowayout) |
86 | indydog_stop(); /* Turn the WDT off */ | 97 | indydog_stop(); /* Turn the WDT off */ |
87 | 98 | clear_bit(0, &indydog_alive); | |
88 | indydog_alive = 0; | ||
89 | |||
90 | return 0; | 99 | return 0; |
91 | } | 100 | } |
92 | 101 | ||
93 | static ssize_t indydog_write(struct file *file, const char *data, size_t len, loff_t *ppos) | 102 | static ssize_t indydog_write(struct file *file, const char *data, |
103 | size_t len, loff_t *ppos) | ||
94 | { | 104 | { |
95 | /* Refresh the timer. */ | 105 | /* Refresh the timer. */ |
96 | if (len) { | 106 | if (len) |
97 | indydog_ping(); | 107 | indydog_ping(); |
98 | } | ||
99 | return len; | 108 | return len; |
100 | } | 109 | } |
101 | 110 | ||
102 | static int indydog_ioctl(struct inode *inode, struct file *file, | 111 | static long indydog_ioctl(struct file *file, unsigned int cmd, |
103 | unsigned int cmd, unsigned long arg) | 112 | unsigned long arg) |
104 | { | 113 | { |
105 | int options, retval = -EINVAL; | 114 | int options, retval = -EINVAL; |
106 | static struct watchdog_info ident = { | 115 | static struct watchdog_info ident = { |
@@ -111,42 +120,40 @@ static int indydog_ioctl(struct inode *inode, struct file *file, | |||
111 | }; | 120 | }; |
112 | 121 | ||
113 | switch (cmd) { | 122 | switch (cmd) { |
114 | default: | 123 | case WDIOC_GETSUPPORT: |
115 | return -ENOTTY; | 124 | if (copy_to_user((struct watchdog_info *)arg, |
116 | case WDIOC_GETSUPPORT: | 125 | &ident, sizeof(ident))) |
117 | if (copy_to_user((struct watchdog_info *)arg, | 126 | return -EFAULT; |
118 | &ident, sizeof(ident))) | 127 | return 0; |
119 | return -EFAULT; | 128 | case WDIOC_GETSTATUS: |
120 | return 0; | 129 | case WDIOC_GETBOOTSTATUS: |
121 | case WDIOC_GETSTATUS: | 130 | return put_user(0, (int *)arg); |
122 | case WDIOC_GETBOOTSTATUS: | 131 | case WDIOC_SETOPTIONS: |
123 | return put_user(0,(int *)arg); | 132 | { |
124 | case WDIOC_KEEPALIVE: | 133 | if (get_user(options, (int *)arg)) |
125 | indydog_ping(); | 134 | return -EFAULT; |
126 | return 0; | 135 | if (options & WDIOS_DISABLECARD) { |
127 | case WDIOC_GETTIMEOUT: | 136 | indydog_stop(); |
128 | return put_user(WATCHDOG_TIMEOUT,(int *)arg); | 137 | retval = 0; |
129 | case WDIOC_SETOPTIONS: | ||
130 | { | ||
131 | if (get_user(options, (int *)arg)) | ||
132 | return -EFAULT; | ||
133 | |||
134 | if (options & WDIOS_DISABLECARD) { | ||
135 | indydog_stop(); | ||
136 | retval = 0; | ||
137 | } | ||
138 | |||
139 | if (options & WDIOS_ENABLECARD) { | ||
140 | indydog_start(); | ||
141 | retval = 0; | ||
142 | } | ||
143 | |||
144 | return retval; | ||
145 | } | 138 | } |
139 | if (options & WDIOS_ENABLECARD) { | ||
140 | indydog_start(); | ||
141 | retval = 0; | ||
142 | } | ||
143 | return retval; | ||
144 | } | ||
145 | case WDIOC_KEEPALIVE: | ||
146 | indydog_ping(); | ||
147 | return 0; | ||
148 | case WDIOC_GETTIMEOUT: | ||
149 | return put_user(WATCHDOG_TIMEOUT, (int *)arg); | ||
150 | default: | ||
151 | return -ENOTTY; | ||
146 | } | 152 | } |
147 | } | 153 | } |
148 | 154 | ||
149 | static int indydog_notify_sys(struct notifier_block *this, unsigned long code, void *unused) | 155 | static int indydog_notify_sys(struct notifier_block *this, |
156 | unsigned long code, void *unused) | ||
150 | { | 157 | { |
151 | if (code == SYS_DOWN || code == SYS_HALT) | 158 | if (code == SYS_DOWN || code == SYS_HALT) |
152 | indydog_stop(); /* Turn the WDT off */ | 159 | indydog_stop(); /* Turn the WDT off */ |
@@ -158,7 +165,7 @@ static const struct file_operations indydog_fops = { | |||
158 | .owner = THIS_MODULE, | 165 | .owner = THIS_MODULE, |
159 | .llseek = no_llseek, | 166 | .llseek = no_llseek, |
160 | .write = indydog_write, | 167 | .write = indydog_write, |
161 | .ioctl = indydog_ioctl, | 168 | .unlocked_ioctl = indydog_ioctl, |
162 | .open = indydog_open, | 169 | .open = indydog_open, |
163 | .release = indydog_release, | 170 | .release = indydog_release, |
164 | }; | 171 | }; |
@@ -180,17 +187,20 @@ static int __init watchdog_init(void) | |||
180 | { | 187 | { |
181 | int ret; | 188 | int ret; |
182 | 189 | ||
190 | spin_lock_init(&indydog_lock); | ||
191 | |||
183 | ret = register_reboot_notifier(&indydog_notifier); | 192 | ret = register_reboot_notifier(&indydog_notifier); |
184 | if (ret) { | 193 | if (ret) { |
185 | printk(KERN_ERR PFX "cannot register reboot notifier (err=%d)\n", | 194 | printk(KERN_ERR PFX |
186 | ret); | 195 | "cannot register reboot notifier (err=%d)\n", ret); |
187 | return ret; | 196 | return ret; |
188 | } | 197 | } |
189 | 198 | ||
190 | ret = misc_register(&indydog_miscdev); | 199 | ret = misc_register(&indydog_miscdev); |
191 | if (ret) { | 200 | if (ret) { |
192 | printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", | 201 | printk(KERN_ERR PFX |
193 | WATCHDOG_MINOR, ret); | 202 | "cannot register miscdev on minor=%d (err=%d)\n", |
203 | WATCHDOG_MINOR, ret); | ||
194 | unregister_reboot_notifier(&indydog_notifier); | 204 | unregister_reboot_notifier(&indydog_notifier); |
195 | return ret; | 205 | return ret; |
196 | } | 206 | } |