Add a generic watchdog facility which through a single device entry
in /dev controls all available watchdog implementations.
This commit is contained in:
parent
16b9d7e064
commit
1208feeaed
@ -868,6 +868,7 @@ dev/vx/if_vx.c optional vx
|
||||
dev/vx/if_vx_eisa.c optional vx eisa
|
||||
dev/vx/if_vx_pci.c optional vx pci
|
||||
#dev/wlp/if_wlp.c optional wlp card
|
||||
dev/watchdog/watchdog.c standard
|
||||
dev/wds/wd7000.c optional wds isa
|
||||
dev/wi/if_wi.c optional wi
|
||||
dev/wi/if_wi_pccard.c optional wi pccard
|
||||
|
89
sys/dev/watchdog/watchdog.c
Normal file
89
sys/dev/watchdog/watchdog.c
Normal file
@ -0,0 +1,89 @@
|
||||
/*-
|
||||
* Copyright (c) 2004 Poul-Henning Kamp
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer
|
||||
* in this position and unchanged.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/module.h>
|
||||
#include <sys/watchdog.h>
|
||||
#include <sys/bus.h>
|
||||
#include <machine/bus.h>
|
||||
|
||||
static dev_t wd_dev;
|
||||
|
||||
static int
|
||||
wd_ioctl(dev_t dev __unused, u_long cmd, caddr_t data,
|
||||
int flags __unused, struct thread *td)
|
||||
{
|
||||
int error;
|
||||
u_int u;
|
||||
|
||||
if (cmd != WDIOCPATPAT)
|
||||
return (ENOIOCTL);
|
||||
u = *(u_int *)data;
|
||||
if (u & ~(WD_ACTIVE | WD_PASSIVE | WD_INTERVAL))
|
||||
return (EINVAL);
|
||||
if ((u & (WD_ACTIVE | WD_PASSIVE)) == (WD_ACTIVE | WD_PASSIVE))
|
||||
return (EINVAL);
|
||||
if ((u & WD_INTERVAL) == WD_TO_NEVER)
|
||||
u = 0;
|
||||
error = EOPNOTSUPP;
|
||||
EVENTHANDLER_INVOKE(watchdog_list, u, &error);
|
||||
return (error);
|
||||
}
|
||||
|
||||
static struct cdevsw wd_cdevsw = {
|
||||
.d_version = D_VERSION,
|
||||
.d_ioctl = wd_ioctl,
|
||||
.d_name = "watchdog",
|
||||
};
|
||||
|
||||
static int
|
||||
watchdog_modevent(module_t mod __unused, int type, void *data __unused)
|
||||
{
|
||||
switch(type) {
|
||||
case MOD_LOAD:
|
||||
wd_dev = make_dev(&wd_cdevsw, 0,
|
||||
UID_ROOT, GID_WHEEL, 0600, _PATH_WATCHDOG);
|
||||
return 0;
|
||||
case MOD_UNLOAD:
|
||||
destroy_dev(wd_dev);
|
||||
return 0;
|
||||
case MOD_SHUTDOWN:
|
||||
return 0;
|
||||
default:
|
||||
return EOPNOTSUPP;
|
||||
}
|
||||
}
|
||||
|
||||
DEV_MODULE(watchdog, watchdog_modevent, NULL);
|
@ -323,8 +323,93 @@ init_AMD_Elan_sc520(void)
|
||||
tc_init(&elan_timecounter);
|
||||
}
|
||||
|
||||
static d_ioctl_t elan_ioctl;
|
||||
static d_mmap_t elan_mmap;
|
||||
static void
|
||||
elan_watchdog(void *foo __unused, u_int spec, int *error)
|
||||
{
|
||||
u_int u, v;
|
||||
static u_int cur;
|
||||
|
||||
u = spec & WD_INTERVAL;
|
||||
if (spec && u <= 35) {
|
||||
u = imax(u - 5, 24);
|
||||
v = 2 << (u - 24);
|
||||
v |= 0xc000;
|
||||
|
||||
/*
|
||||
* There is a bug in some silicon which prevents us from
|
||||
* writing to the WDTMRCTL register if the GP echo mode is
|
||||
* enabled. GP echo mode on the other hand is desirable
|
||||
* for other reasons. Save and restore the GP echo mode
|
||||
* around our hardware tom-foolery.
|
||||
*/
|
||||
u = elan_mmcr->GPECHO;
|
||||
elan_mmcr->GPECHO = 0;
|
||||
if (v != cur) {
|
||||
/* Clear the ENB bit */
|
||||
elan_mmcr->WDTMRCTL = 0x3333;
|
||||
elan_mmcr->WDTMRCTL = 0xcccc;
|
||||
elan_mmcr->WDTMRCTL = 0;
|
||||
|
||||
/* Set new value */
|
||||
elan_mmcr->WDTMRCTL = 0x3333;
|
||||
elan_mmcr->WDTMRCTL = 0xcccc;
|
||||
elan_mmcr->WDTMRCTL = v;
|
||||
cur = v;
|
||||
} else {
|
||||
/* Just reset timer */
|
||||
elan_mmcr->WDTMRCTL = 0xaaaa;
|
||||
elan_mmcr->WDTMRCTL = 0x5555;
|
||||
}
|
||||
elan_mmcr->GPECHO = u;
|
||||
*error = 0;
|
||||
return;
|
||||
} else {
|
||||
u = elan_mmcr->GPECHO;
|
||||
elan_mmcr->GPECHO = 0;
|
||||
elan_mmcr->WDTMRCTL = 0x3333;
|
||||
elan_mmcr->WDTMRCTL = 0xcccc;
|
||||
elan_mmcr->WDTMRCTL = 0x4080;
|
||||
elan_mmcr->WDTMRCTL = u;
|
||||
elan_mmcr->GPECHO = u;
|
||||
cur = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
elan_mmap(dev_t dev, vm_offset_t offset, vm_paddr_t *paddr, int nprot)
|
||||
{
|
||||
|
||||
if (offset >= 0x1000)
|
||||
return (-1);
|
||||
*paddr = 0xfffef000;
|
||||
return (0);
|
||||
}
|
||||
static int
|
||||
elan_ioctl(dev_t dev, u_long cmd, caddr_t arg, int flag, struct thread *tdr)
|
||||
{
|
||||
int error;
|
||||
|
||||
error = ENOIOCTL;
|
||||
|
||||
#ifdef CPU_ELAN_PPS
|
||||
if (pps_a != 0)
|
||||
error = pps_ioctl(cmd, arg, &elan_pps);
|
||||
/*
|
||||
* We only want to incur the overhead of the PPS polling if we
|
||||
* are actually asked to timestamp.
|
||||
*/
|
||||
if (elan_pps.ppsparam.mode & PPS_CAPTUREASSERT) {
|
||||
elan_timecounter.tc_poll_pps = elan_poll_pps;
|
||||
} else {
|
||||
elan_timecounter.tc_poll_pps = NULL;
|
||||
}
|
||||
if (error != ENOIOCTL)
|
||||
return (error);
|
||||
#endif
|
||||
|
||||
return(error);
|
||||
}
|
||||
|
||||
static struct cdevsw elan_cdevsw = {
|
||||
.d_version = D_VERSION,
|
||||
@ -365,109 +450,9 @@ elan_drvinit(void)
|
||||
/* We don't know which pins are available so enable them all */
|
||||
strcpy(gpio_config, "................................");
|
||||
#endif /* CPU_SOEKRIS */
|
||||
|
||||
EVENTHANDLER_REGISTER(watchdog_list, elan_watchdog, NULL, 0);
|
||||
}
|
||||
|
||||
SYSINIT(elan, SI_SUB_PSEUDO, SI_ORDER_MIDDLE, elan_drvinit, NULL);
|
||||
|
||||
static int
|
||||
elan_mmap(dev_t dev, vm_offset_t offset, vm_paddr_t *paddr, int nprot)
|
||||
{
|
||||
|
||||
if (offset >= 0x1000)
|
||||
return (-1);
|
||||
*paddr = 0xfffef000;
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
elan_watchdog(u_int spec)
|
||||
{
|
||||
u_int u, v;
|
||||
static u_int cur;
|
||||
|
||||
if (spec & ~__WD_LEGAL)
|
||||
return (EINVAL);
|
||||
switch (spec & (WD_ACTIVE|WD_PASSIVE)) {
|
||||
case WD_ACTIVE:
|
||||
u = spec & WD_INTERVAL;
|
||||
if (u > 35)
|
||||
return (EINVAL);
|
||||
u = imax(u - 5, 24);
|
||||
v = 2 << (u - 24);
|
||||
v |= 0xc000;
|
||||
|
||||
/*
|
||||
* There is a bug in some silicon which prevents us from
|
||||
* writing to the WDTMRCTL register if the GP echo mode is
|
||||
* enabled. GP echo mode on the other hand is desirable
|
||||
* for other reasons. Save and restore the GP echo mode
|
||||
* around our hardware tom-foolery.
|
||||
*/
|
||||
u = elan_mmcr->GPECHO;
|
||||
elan_mmcr->GPECHO = 0;
|
||||
if (v != cur) {
|
||||
/* Clear the ENB bit */
|
||||
elan_mmcr->WDTMRCTL = 0x3333;
|
||||
elan_mmcr->WDTMRCTL = 0xcccc;
|
||||
elan_mmcr->WDTMRCTL = 0;
|
||||
|
||||
/* Set new value */
|
||||
elan_mmcr->WDTMRCTL = 0x3333;
|
||||
elan_mmcr->WDTMRCTL = 0xcccc;
|
||||
elan_mmcr->WDTMRCTL = v;
|
||||
cur = v;
|
||||
} else {
|
||||
/* Just reset timer */
|
||||
elan_mmcr->WDTMRCTL = 0xaaaa;
|
||||
elan_mmcr->WDTMRCTL = 0x5555;
|
||||
}
|
||||
elan_mmcr->GPECHO = u;
|
||||
return (0);
|
||||
case WD_PASSIVE:
|
||||
return (EOPNOTSUPP);
|
||||
case 0:
|
||||
u = elan_mmcr->GPECHO;
|
||||
elan_mmcr->GPECHO = 0;
|
||||
elan_mmcr->WDTMRCTL = 0x3333;
|
||||
elan_mmcr->WDTMRCTL = 0xcccc;
|
||||
elan_mmcr->WDTMRCTL = 0x4080;
|
||||
elan_mmcr->WDTMRCTL = u;
|
||||
elan_mmcr->GPECHO = u;
|
||||
cur = 0;
|
||||
return (0);
|
||||
default:
|
||||
return (EINVAL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static int
|
||||
elan_ioctl(dev_t dev, u_long cmd, caddr_t arg, int flag, struct thread *tdr)
|
||||
{
|
||||
int error;
|
||||
|
||||
error = ENOTTY;
|
||||
|
||||
#ifdef CPU_ELAN_PPS
|
||||
if (pps_a != 0)
|
||||
error = pps_ioctl(cmd, arg, &elan_pps);
|
||||
/*
|
||||
* We only want to incur the overhead of the PPS polling if we
|
||||
* are actually asked to timestamp.
|
||||
*/
|
||||
if (elan_pps.ppsparam.mode & PPS_CAPTUREASSERT) {
|
||||
elan_timecounter.tc_poll_pps = elan_poll_pps;
|
||||
} else {
|
||||
elan_timecounter.tc_poll_pps = NULL;
|
||||
}
|
||||
if (error != ENOTTY)
|
||||
return (error);
|
||||
#endif
|
||||
|
||||
if (cmd == WDIOCPATPAT)
|
||||
return elan_watchdog(*((u_int*)arg));
|
||||
|
||||
/* Other future ioctl handling here */
|
||||
return(error);
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,12 @@
|
||||
|
||||
#include <sys/ioccom.h>
|
||||
|
||||
#ifdef I_HAVE_TOTALLY_LOST_MY_SENSE_OF_HUMOUR
|
||||
#define _PATH_WATCHDOG "watchdog"
|
||||
#else
|
||||
#define _PATH_WATCHDOG "fido"
|
||||
#endif
|
||||
|
||||
#define WDIOCPATPAT _IOW('W', 42, u_int)
|
||||
|
||||
#define WD_ACTIVE 0x8000000
|
||||
@ -56,10 +62,6 @@
|
||||
* NB: Expect variance in the +/- 10-20% range.
|
||||
*/
|
||||
|
||||
#ifdef _KERNEL
|
||||
#define __WD_LEGAL (WD_ACTIVE | WD_PASSIVE | WD_INTERVAL)
|
||||
#endif
|
||||
|
||||
/* Handy macros for humans not used to power of two nanoseconds */
|
||||
#define WD_TO_NEVER 0
|
||||
#define WD_TO_1MS 20
|
||||
@ -73,4 +75,13 @@
|
||||
#define WD_TO_16SEC 34
|
||||
#define WD_TO_32SEC 35
|
||||
|
||||
#ifdef _KERNEL
|
||||
|
||||
#include <sys/eventhandler.h>
|
||||
|
||||
typedef void (*watchdog_fn)(void *, u_int, int *);
|
||||
|
||||
EVENTHANDLER_DECLARE(watchdog_list, watchdog_fn);
|
||||
#endif
|
||||
|
||||
#endif /* _SYS_WATCHDOG_H */
|
||||
|
Loading…
Reference in New Issue
Block a user