/* * Watchdog driver for SiByte SB1 SoCs * * Copyright (C) 2007 OnStor, Inc. * Andrew Sharp <andy.sharp@lsi.com> * * This driver is intended to make the second of two hardware watchdogs * on the Sibyte 12XX and 11XX SoCs available to the user. There are two * such devices available on the SoC, but it seems that there isn't an * enumeration class for watchdogs in Linux like there is for RTCs. * The second is used rather than the first because it uses IRQ 1, * thereby avoiding all that IRQ 0 problematic nonsense. * * I have not tried this driver on a 1480 processor; it might work * just well enough to really screw things up. * * It is a simple timer, and there is an interrupt that is raised the * first time the timer expires. The second time it expires, the chip * is reset and there is no way to redirect that NMI. Which could * be problematic in some cases where this chip is sitting on the HT * bus and has just taken responsibility for providing a cache block. * Since the reset can't be redirected to the external reset pin, it is * possible that other HT connected processors might hang and not reset. * For Linux, a soft reset would probably be even worse than a hard reset. * There you have it. * * The timer takes 23 bits of a 64 bit register (?) as a count value, * and decrements the count every microsecond, for a max value of * 0x7fffff usec or about 8.3ish seconds. * * This watchdog borrows some user semantics from the softdog driver, * in that if you close the fd, it leaves the watchdog running, unless * you previously wrote a 'V' to the fd, in which case it disables * the watchdog when you close the fd like some other drivers. * * Based on various other watchdog drivers, which are probably all * loosely based on something Alan Cox wrote years ago. * * (c) Copyright 1996 Alan Cox <alan@lxorguk.ukuu.org.uk>, * All Rights Reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 1 or 2 as published by the Free Software Foundation. *
*/
/* * set the initial count value of a timer * * wdog is the iomem address of the cfg register
*/ staticvoid sbwdog_set(char __iomem *wdog, unsignedlong t)
{
spin_lock(&sbwd_lock);
__raw_writeb(0, wdog);
__raw_writeq(t & 0x7fffffUL, wdog - 0x10);
spin_unlock(&sbwd_lock);
}
/* * cause the timer to [re]load it's initial count and start counting * all over again * * wdog is the iomem address of the cfg register
*/ staticvoid sbwdog_pet(char __iomem *wdog)
{
spin_lock(&sbwd_lock);
__raw_writeb(__raw_readb(wdog) | 1, wdog);
spin_unlock(&sbwd_lock);
}
staticunsignedlong sbwdog_gate; /* keeps it to one thread only */ staticchar __iomem *kern_dog = (char __iomem *)(IO_BASE + (A_SCD_WDOG_CFG_0)); staticchar __iomem *user_dog = (char __iomem *)(IO_BASE + (A_SCD_WDOG_CFG_1)); staticunsignedlong timeout = 0x7fffffUL; /* useconds: 8.3ish secs. */ staticint expect_close;
/* * Allow only a single thread to walk the dog
*/ staticint sbwdog_open(struct inode *inode, struct file *file)
{
stream_open(inode, file); if (test_and_set_bit(0, &sbwdog_gate)) return -EBUSY;
__module_get(THIS_MODULE);
/* * Activate the timer
*/
sbwdog_set(user_dog, timeout);
__raw_writeb(1, user_dog);
return 0;
}
/* * Put the dog back in the kennel.
*/ staticint sbwdog_release(struct inode *inode, struct file *file)
{ if (expect_close == 42) {
__raw_writeb(0, user_dog);
module_put(THIS_MODULE);
} else {
pr_crit("%s: Unexpected close, not stopping watchdog!\n",
ident.identity);
sbwdog_pet(user_dog);
}
clear_bit(0, &sbwdog_gate);
expect_close = 0;
if (len) { /* * restart the timer
*/
expect_close = 0;
for (i = 0; i != len; i++) { char c;
if (get_user(c, data + i)) return -EFAULT; if (c == 'V')
expect_close = 42;
}
sbwdog_pet(user_dog);
}
return len;
}
staticlong sbwdog_ioctl(struct file *file, unsignedint cmd, unsignedlong arg)
{ int ret = -ENOTTY; unsignedlong time; void __user *argp = (void __user *)arg; int __user *p = argp;
switch (cmd) { case WDIOC_GETSUPPORT:
ret = copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0; break;
case WDIOC_GETSTATUS: case WDIOC_GETBOOTSTATUS:
ret = put_user(0, p); break;
case WDIOC_KEEPALIVE:
sbwdog_pet(user_dog);
ret = 0; break;
case WDIOC_SETTIMEOUT:
ret = get_user(time, p); if (ret) break;
time *= 1000000; if (time > 0x7fffffUL) {
ret = -EINVAL; break;
}
timeout = time;
sbwdog_set(user_dog, timeout);
sbwdog_pet(user_dog);
fallthrough;
case WDIOC_GETTIMEOUT: /* * get the remaining count from the ... count register * which is 1*8 before the config register
*/
ret = put_user((u32)__raw_readq(user_dog - 8) / 1000000, p); break;
} return ret;
}
/* * Notifier for system down
*/ staticint sbwdog_notify_sys(struct notifier_block *this, unsignedlong code, void *erf)
{ if (code == SYS_DOWN || code == SYS_HALT) { /* * sit and sit
*/
__raw_writeb(0, user_dog);
__raw_writeb(0, kern_dog);
}
/* * interrupt handler * * doesn't do a whole lot for user, but oh so cleverly written so kernel * code can use it to re-up the watchdog, thereby saving the kernel from * having to create and maintain a timer, just to tickle another timer, * which is just so wrong.
*/
irqreturn_t sbwdog_interrupt(int irq, void *addr)
{ unsignedlong wd_init; char *wd_cfg_reg = (char *)addr;
u8 cfg;
/* * if it's the second watchdog timer, it's for those users
*/ if (wd_cfg_reg == user_dog)
pr_crit("%s in danger of initiating system reset " "in %ld.%01ld seconds\n",
ident.identity,
wd_init / 1000000, (wd_init / 100000) % 10); else
cfg |= 1;
__raw_writeb(cfg, wd_cfg_reg);
return IRQ_HANDLED;
}
staticint __init sbwdog_init(void)
{ int ret;
/* * register a reboot notifier
*/
ret = register_reboot_notifier(&sbwdog_notifier); if (ret) {
pr_err("%s: cannot register reboot notifier (err=%d)\n",
ident.identity, ret); return ret;
}
/* * get the resources
*/
ret = request_irq(1, sbwdog_interrupt, IRQF_SHARED,
ident.identity, (void *)user_dog); if (ret) {
pr_err("%s: failed to request irq 1 - %d\n",
ident.identity, ret); goto out;
}
ret = misc_register(&sbwdog_miscdev); if (ret == 0) {
pr_info("%s: timeout is %ld.%ld secs\n",
ident.identity,
timeout / 1000000, (timeout / 100000) % 10); return 0;
}
free_irq(1, (void *)user_dog);
out:
unregister_reboot_notifier(&sbwdog_notifier);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.