// SPDX-License-Identifier: GPL-2.0-or-later /* * 60xx Single Board Computer Watchdog Timer driver for Linux 2.2.x * * Based on acquirewdt.c by Alan Cox. * * The author does NOT admit liability nor provide warranty for * any of this software. This material is provided "AS-IS" in * the hope that it may be useful for others. * * (c) Copyright 2000 Jakob Oestergaard <jakob@unthought.net> * * 12/4 - 2000 [Initial revision] * 25/4 - 2000 Added /dev/watchdog support * 09/5 - 2001 [smj@oro.net] fixed fop_write to "return 1" * on success * 12/4 - 2002 [rob@osinvestor.com] eliminate fop_read * fix possible wdt_is_open race * add CONFIG_WATCHDOG_NOWAYOUT support * remove lock_kernel/unlock_kernel pairs * added KERN_* to printk's * got rid of extraneous comments * changed watchdog_info to correctly reflect what * the driver offers * added WDIOC_GETSTATUS, WDIOC_GETBOOTSTATUS, * WDIOC_SETTIMEOUT, WDIOC_GETTIMEOUT, and * WDIOC_SETOPTIONS ioctls * 09/8 - 2003 [wim@iguana.be] cleanup of trailing spaces * use module_param * made timeout (the emulated heartbeat) a * module_param * made the keepalive ping an internal subroutine * made wdt_stop and wdt_start module params * added extra printk's for startup problems * added MODULE_AUTHOR and MODULE_DESCRIPTION info * * This WDT driver is different from the other Linux WDT * drivers in the following ways: * *) The driver will ping the watchdog by itself, because this * particular WDT has a very short timeout (one second) and it * would be insane to count on any userspace daemon always * getting scheduled within that time frame.
*/
/* * The 60xx board can use watchdog timeout values from one second * to several minutes. The default is one second, so if we reset * the watchdog every ~250ms we should be safe.
*/
#define WDT_INTERVAL (HZ/4+1)
/* * We must not require too good response from the userspace daemon. * Here we require the userspace daemon to send us a heartbeat * char to /dev/watchdog every 30 seconds. * If the daemon pulses us every 25 seconds, we can still afford * a 5 second scheduling delay on the (high priority) daemon. That * should be sufficient for a box under any load.
*/
#define WATCHDOG_TIMEOUT 30 /* 30 sec default timeout */ staticint timeout = WATCHDOG_TIMEOUT; /* in seconds, multiplied by HZ to
get seconds to wait for a ping */
module_param(timeout, int, 0);
MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. (1<=timeout<=3600, default="
__MODULE_STRING(WATCHDOG_TIMEOUT) ")");
staticbool nowayout = WATCHDOG_NOWAYOUT;
module_param(nowayout, bool, 0);
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
staticvoid wdt_timer_ping(struct timer_list *unused)
{ /* If we got a heartbeat pulse within the WDT_US_INTERVAL * we agree to ping the WDT
*/ if (time_before(jiffies, next_heartbeat)) { /* Ping the WDT by reading from wdt_start */
inb_p(wdt_start); /* Re-set the timer interval */
mod_timer(&timer, jiffies + WDT_INTERVAL);
} else
pr_warn("Heartbeat lost! Will not ping the watchdog\n");
}
/* Start the timer */
mod_timer(&timer, jiffies + WDT_INTERVAL);
pr_info("Watchdog timer is now enabled\n");
}
staticvoid wdt_turnoff(void)
{ /* Stop the timer */
timer_delete_sync(&timer);
inb_p(wdt_stop);
pr_info("Watchdog timer is now disabled...\n");
}
staticvoid wdt_keepalive(void)
{ /* user land ping */
next_heartbeat = jiffies + (timeout * HZ);
}
/* * /dev/watchdog handling
*/
static ssize_t fop_write(struct file *file, constchar __user *buf,
size_t count, loff_t *ppos)
{ /* See if we got the magic character 'V' and reload the timer */ if (count) { if (!nowayout) {
size_t ofs;
/* note: just in case someone wrote the
magic character five months ago... */
wdt_expect_close = 0;
/* scan to see whether or not we got the
magic character */ for (ofs = 0; ofs != count; ofs++) { char c; if (get_user(c, buf + ofs)) return -EFAULT; if (c == 'V')
wdt_expect_close = 42;
}
}
/* Well, anyhow someone wrote to us, we should
return that favour */
wdt_keepalive();
} return count;
}
staticint fop_open(struct inode *inode, struct file *file)
{ /* Just in case we're already talking to someone... */ if (test_and_set_bit(0, &wdt_is_open)) return -EBUSY;
if (nowayout)
__module_get(THIS_MODULE);
/* Good, fire up the show */
wdt_startup(); return stream_open(inode, file);
}
staticint fop_close(struct inode *inode, struct file *file)
{ if (wdt_expect_close == 42)
wdt_turnoff(); else {
timer_delete(&timer);
pr_crit("device file closed unexpectedly. Will not stop the WDT!\n");
}
clear_bit(0, &wdt_is_open);
wdt_expect_close = 0; return 0;
}
staticint __init sbc60xxwdt_init(void)
{ int rc = -EBUSY;
if (timeout < 1 || timeout > 3600) { /* arbitrary upper limit */
timeout = WATCHDOG_TIMEOUT;
pr_info("timeout value must be 1 <= x <= 3600, using %d\n",
timeout);
}
if (!request_region(wdt_start, 1, "SBC 60XX WDT")) {
pr_err("I/O address 0x%04x already in use\n", wdt_start);
rc = -EIO; goto err_out;
}
/* We cannot reserve 0x45 - the kernel already has! */ if (wdt_stop != 0x45 && wdt_stop != wdt_start) { if (!request_region(wdt_stop, 1, "SBC 60XX WDT")) {
pr_err("I/O address 0x%04x already in use\n", wdt_stop);
rc = -EIO; goto err_out_region1;
}
}
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.