// SPDX-License-Identifier: GPL-2.0-only /* * ALi M7101 PMU Computer Watchdog Timer driver * * Based on w83877f_wdt.c by Scott Jennings <linuxdrivers@oro.net> * and the Cobalt kernel WDT timer driver by Tim Hockin * <thockin@cobaltnet.com> * * (c)2002 Steve Hill <steve@navaho.co.uk> * * This WDT driver is different from most other Linux WDT * drivers in that the driver will ping the watchdog by itself, * because this particular WDT has a very short timeout (1.6 * seconds) and it would be insane to count on any userspace * daemon always getting scheduled within that time frame. * * Additions: * Aug 23, 2004 - Added use_gpio module parameter for use on revision a1d PMUs * found on very old cobalt hardware. * -- Mike Waychison <michael.waychison@sun.com>
*/
/* * We're going to use a 1 second timeout.
* 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.
*/
#define WATCHDOG_TIMEOUT 30 /* 30 sec default timeout */ /* in seconds, will be multiplied by HZ to get seconds to wait for a ping */ staticint timeout = WATCHDOG_TIMEOUT;
module_param(timeout, int, 0);
MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. (1<=timeout<=3600, default="
__MODULE_STRING(WATCHDOG_TIMEOUT) ")");
staticint use_gpio; /* Use the pic (for a1d revision alim7101) */
module_param(use_gpio, int, 0);
MODULE_PARM_DESC(use_gpio, "Use the gpio watchdog (required by old cobalt boards).");
staticbool nowayout = WATCHDOG_NOWAYOUT;
module_param(nowayout, bool, 0);
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
/* * Whack the dog
*/
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
*/ char tmp;
if (time_before(jiffies, next_heartbeat)) { /* Ping the WDT (this is actually a disarm/arm sequence) */
pci_read_config_byte(alim7101_pmu, 0x92, &tmp);
pci_write_config_byte(alim7101_pmu,
ALI_7101_WDT, (tmp & ~ALI_WDT_ARM));
pci_write_config_byte(alim7101_pmu,
ALI_7101_WDT, (tmp | ALI_WDT_ARM)); if (use_gpio) {
pci_read_config_byte(alim7101_pmu,
ALI_7101_GPIO_O, &tmp);
pci_write_config_byte(alim7101_pmu,
ALI_7101_GPIO_O, tmp | 0x20);
pci_write_config_byte(alim7101_pmu,
ALI_7101_GPIO_O, tmp & ~0x20);
}
} else {
pr_warn("Heartbeat lost! Will not ping the watchdog\n");
} /* Re-set the timer interval */
mod_timer(&timer, jiffies + WDT_INTERVAL);
}
/* We must enable before we kick off the timer in case the timer
occurs as we ping it */
wdt_change(WDT_ENABLE);
/* 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);
wdt_change(WDT_DISABLE);
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;
/* now scan */ for (ofs = 0; ofs != count; ofs++) { char c; if (get_user(c, buf + ofs)) return -EFAULT; if (c == 'V')
wdt_expect_close = 42;
}
} /* someone wrote to us, we should restart timer */
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; /* 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 { /* wim: shouldn't there be a: 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 wdt_restart_handle(struct notifier_block *this, unsignedlong mode, void *cmd)
{ /* * Cobalt devices have no way of rebooting themselves other * than getting the watchdog to pull reset, so we restart the * watchdog on reboot with no heartbeat.
*/
wdt_change(WDT_ENABLE);
/* loop until the watchdog fires */ while (true)
;
pr_info("Steve Hill \n");
alim7101_pmu = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101,
NULL); if (!alim7101_pmu) {
pr_info("ALi M7101 PMU not present - WDT not set\n"); return -EBUSY;
}
/* Set the WDT in the PMU to 1 second */
pci_write_config_byte(alim7101_pmu, ALI_7101_WDT, 0x02);
ali1543_south = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533,
NULL); if (!ali1543_south) {
pr_info("ALi 1543 South-Bridge not present - WDT not set\n"); goto err_out;
}
pci_read_config_byte(ali1543_south, 0x5e, &tmp);
pci_dev_put(ali1543_south); if ((tmp & 0x1e) == 0x00) { if (!use_gpio) {
pr_info("Detected old alim7101 revision 'a1d'. If this is a cobalt board, set the 'use_gpio' module parameter.\n"); goto err_out;
}
nowayout = 1;
} elseif ((tmp & 0x1e) != 0x12 && (tmp & 0x1e) != 0x00) {
pr_info("ALi 1543 South-Bridge does not have the correct revision number (???1001?) - WDT not set\n"); goto err_out;
}
if (timeout < 1 || timeout > 3600) { /* arbitrary upper limit */
timeout = WATCHDOG_TIMEOUT;
pr_info("timeout value must be 1 <= x <= 3600, using %d\n",
timeout);
}
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.