2 * IBM Automatic Server Restart driver.
4 * Copyright (c) 2005 Andrey Panin <pazke@donpac.ru>
6 * Based on driver written by Pete Reynolds.
7 * Copyright (c) IBM Corporation, 1998-2004.
9 * This software may be used and distributed according to the terms
10 * of the GNU Public License, incorporated herein by reference.
14 #include <linux/kernel.h>
15 #include <linux/slab.h>
16 #include <linux/module.h>
17 #include <linux/pci.h>
18 #include <linux/timer.h>
19 #include <linux/miscdevice.h>
20 #include <linux/watchdog.h>
21 #include <linux/dmi.h>
24 #include <asm/uaccess.h>
36 #define PFX "ibmasr: "
38 #define TOPAZ_ASR_REG_OFFSET 4
39 #define TOPAZ_ASR_TOGGLE 0x40
40 #define TOPAZ_ASR_DISABLE 0x80
42 /* PEARL ASR S/W REGISTER SUPERIO PORT ADDRESSES */
43 #define PEARL_BASE 0xe04
44 #define PEARL_WRITE 0xe06
45 #define PEARL_READ 0xe07
47 #define PEARL_ASR_DISABLE_MASK 0x80 /* bit 7: disable = 1, enable = 0 */
48 #define PEARL_ASR_TOGGLE_MASK 0x40 /* bit 6: 0, then 1, then 0 */
50 /* JASPER OFFSET FROM SIO BASE ADDR TO ASR S/W REGISTERS. */
51 #define JASPER_ASR_REG_OFFSET 0x38
53 #define JASPER_ASR_DISABLE_MASK 0x01 /* bit 0: disable = 1, enable = 0 */
54 #define JASPER_ASR_TOGGLE_MASK 0x02 /* bit 1: 0, then 1, then 0 */
56 #define JUNIPER_BASE_ADDRESS 0x54b /* Base address of Juniper ASR */
57 #define JUNIPER_ASR_DISABLE_MASK 0x01 /* bit 0: disable = 1 enable = 0 */
58 #define JUNIPER_ASR_TOGGLE_MASK 0x02 /* bit 1: 0, then 1, then 0 */
60 #define SPRUCE_BASE_ADDRESS 0x118e /* Base address of Spruce ASR */
61 #define SPRUCE_ASR_DISABLE_MASK 0x01 /* bit 1: disable = 1 enable = 0 */
62 #define SPRUCE_ASR_TOGGLE_MASK 0x02 /* bit 0: 0, then 1, then 0 */
65 static int nowayout = WATCHDOG_NOWAYOUT;
67 static unsigned long asr_is_open;
68 static char asr_expect_close;
70 static unsigned int asr_type, asr_base, asr_length;
71 static unsigned int asr_read_addr, asr_write_addr;
72 static unsigned char asr_toggle_mask, asr_disable_mask;
74 static void asr_toggle(void)
76 unsigned char reg = inb(asr_read_addr);
78 outb(reg & ~asr_toggle_mask, asr_write_addr);
79 reg = inb(asr_read_addr);
81 outb(reg | asr_toggle_mask, asr_write_addr);
82 reg = inb(asr_read_addr);
84 outb(reg & ~asr_toggle_mask, asr_write_addr);
85 reg = inb(asr_read_addr);
88 static void asr_enable(void)
92 if (asr_type == ASMTYPE_TOPAZ) {
93 /* asr_write_addr == asr_read_addr */
94 reg = inb(asr_read_addr);
95 outb(reg & ~(TOPAZ_ASR_TOGGLE | TOPAZ_ASR_DISABLE),
99 * First make sure the hardware timer is reset by toggling
100 * ASR hardware timer line.
104 reg = inb(asr_read_addr);
105 outb(reg & ~asr_disable_mask, asr_write_addr);
107 reg = inb(asr_read_addr);
110 static void asr_disable(void)
112 unsigned char reg = inb(asr_read_addr);
114 if (asr_type == ASMTYPE_TOPAZ)
115 /* asr_write_addr == asr_read_addr */
116 outb(reg | TOPAZ_ASR_TOGGLE | TOPAZ_ASR_DISABLE,
119 outb(reg | asr_toggle_mask, asr_write_addr);
120 reg = inb(asr_read_addr);
122 outb(reg | asr_disable_mask, asr_write_addr);
124 reg = inb(asr_read_addr);
127 static int __init asr_get_base_address(void)
129 unsigned char low, high;
130 const char *type = "";
136 /* SELECT SuperIO CHIP FOR QUERYING (WRITE 0x07 TO BOTH 0x2E and 0x2F) */
140 /* SELECT AND READ THE HIGH-NIBBLE OF THE GPIO BASE ADDRESS */
144 /* SELECT AND READ THE LOW-NIBBLE OF THE GPIO BASE ADDRESS */
148 asr_base = (high << 16) | low;
149 asr_read_addr = asr_write_addr =
150 asr_base + TOPAZ_ASR_REG_OFFSET;
158 /* FIXME: need to use pci_config_lock here, but it's not exported */
160 /* spin_lock_irqsave(&pci_config_lock, flags);*/
162 /* Select the SuperIO chip in the PCI I/O port register */
163 outl(0x8000f858, 0xcf8);
166 * Read the base address for the SuperIO chip.
167 * Only the lower 16 bits are valid, but the address is word
168 * aligned so the last bit must be masked off.
170 asr_base = inl(0xcfc) & 0xfffe;
172 /* spin_unlock_irqrestore(&pci_config_lock, flags);*/
174 asr_read_addr = asr_write_addr =
175 asr_base + JASPER_ASR_REG_OFFSET;
176 asr_toggle_mask = JASPER_ASR_TOGGLE_MASK;
177 asr_disable_mask = JASPER_ASR_DISABLE_MASK;
178 asr_length = JASPER_ASR_REG_OFFSET + 1;
184 asr_base = PEARL_BASE;
185 asr_read_addr = PEARL_READ;
186 asr_write_addr = PEARL_WRITE;
187 asr_toggle_mask = PEARL_ASR_TOGGLE_MASK;
188 asr_disable_mask = PEARL_ASR_DISABLE_MASK;
192 case ASMTYPE_JUNIPER:
194 asr_base = JUNIPER_BASE_ADDRESS;
195 asr_read_addr = asr_write_addr = asr_base;
196 asr_toggle_mask = JUNIPER_ASR_TOGGLE_MASK;
197 asr_disable_mask = JUNIPER_ASR_DISABLE_MASK;
202 asr_base = SPRUCE_BASE_ADDRESS;
203 asr_read_addr = asr_write_addr = asr_base;
204 asr_toggle_mask = SPRUCE_ASR_TOGGLE_MASK;
205 asr_disable_mask = SPRUCE_ASR_DISABLE_MASK;
209 if (!request_region(asr_base, asr_length, "ibmasr")) {
210 printk(KERN_ERR PFX "address %#x already in use\n",
215 printk(KERN_INFO PFX "found %sASR @ addr %#x\n", type, asr_base);
221 static ssize_t asr_write(struct file *file, const char __user *buf,
222 size_t count, loff_t *ppos)
228 /* In case it was set long ago */
229 asr_expect_close = 0;
231 for (i = 0; i != count; i++) {
233 if (get_user(c, buf + i))
236 asr_expect_close = 42;
244 static int asr_ioctl(struct inode *inode, struct file *file,
245 unsigned int cmd, unsigned long arg)
247 static const struct watchdog_info ident = {
248 .options = WDIOF_KEEPALIVEPING |
250 .identity = "IBM ASR"
252 void __user *argp = (void __user *)arg;
253 int __user *p = argp;
257 case WDIOC_GETSUPPORT:
258 return copy_to_user(argp, &ident, sizeof(ident)) ?
261 case WDIOC_GETSTATUS:
262 case WDIOC_GETBOOTSTATUS:
263 return put_user(0, p);
265 case WDIOC_KEEPALIVE:
270 * The hardware has a fixed timeout value, so no WDIOC_SETTIMEOUT
271 * and WDIOC_GETTIMEOUT always returns 256.
273 case WDIOC_GETTIMEOUT:
275 return put_user(heartbeat, p);
277 case WDIOC_SETOPTIONS: {
278 int new_options, retval = -EINVAL;
280 if (get_user(new_options, p))
283 if (new_options & WDIOS_DISABLECARD) {
288 if (new_options & WDIOS_ENABLECARD) {
301 static int asr_open(struct inode *inode, struct file *file)
303 if(test_and_set_bit(0, &asr_is_open))
309 return nonseekable_open(inode, file);
312 static int asr_release(struct inode *inode, struct file *file)
314 if (asr_expect_close == 42)
317 printk(KERN_CRIT PFX "unexpected close, not stopping watchdog!\n");
320 clear_bit(0, &asr_is_open);
321 asr_expect_close = 0;
325 static const struct file_operations asr_fops = {
326 .owner = THIS_MODULE,
331 .release = asr_release,
334 static struct miscdevice asr_miscdev = {
335 .minor = WATCHDOG_MINOR,
346 static struct ibmasr_id __initdata ibmasr_id_table[] = {
347 { "IBM Automatic Server Restart - eserver xSeries 220", ASMTYPE_TOPAZ },
348 { "IBM Automatic Server Restart - Machine Type 8673", ASMTYPE_PEARL },
349 { "IBM Automatic Server Restart - Machine Type 8480", ASMTYPE_JASPER },
350 { "IBM Automatic Server Restart - Machine Type 8482", ASMTYPE_JUNIPER },
351 { "IBM Automatic Server Restart - Machine Type 8648", ASMTYPE_SPRUCE },
355 static int __init ibmasr_init(void)
357 struct ibmasr_id *id;
360 for (id = ibmasr_id_table; id->desc; id++) {
361 if (dmi_find_device(DMI_DEV_TYPE_OTHER, id->desc, NULL)) {
370 rc = misc_register(&asr_miscdev);
372 printk(KERN_ERR PFX "failed to register misc device\n");
376 rc = asr_get_base_address();
378 misc_deregister(&asr_miscdev);
385 static void __exit ibmasr_exit(void)
390 misc_deregister(&asr_miscdev);
392 release_region(asr_base, asr_length);
395 module_init(ibmasr_init);
396 module_exit(ibmasr_exit);
398 module_param(nowayout, int, 0);
399 MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
401 MODULE_DESCRIPTION("IBM Automatic Server Restart driver");
402 MODULE_AUTHOR("Andrey Panin");
403 MODULE_LICENSE("GPL");
404 MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);