From e2cc2d00d72a75d34f7447e02d10807049cad0ca Mon Sep 17 00:00:00 2001 From: msaitoh Date: Thu, 24 Feb 2000 17:07:34 +0000 Subject: [PATCH] watchdog timer --- sys/arch/evbsh3/conf/COMPUTEXEVB | 5 +- sys/arch/evbsh3/conf/CQREEKSH3 | 5 +- sys/arch/evbsh3/conf/files.shbus | 8 +- sys/arch/evbsh3/evbsh3/conf.c | 5 +- sys/arch/evbsh3/include/conf.h | 10 +- sys/arch/mmeye/conf/GENERIC | 7 +- sys/arch/mmeye/conf/MMEYE | 5 +- sys/arch/mmeye/conf/files.shbus | 8 +- sys/arch/mmeye/include/conf.h | 10 +- sys/arch/mmeye/mmeye/conf.c | 5 +- sys/arch/sh3/dev/wdog.c | 157 +++++++++++++++++++++++++++++++ sys/arch/sh3/include/Makefile | 4 +- sys/arch/sh3/include/wdogvar.h | 16 ++++ sys/arch/sh3/sh3/clock.c | 14 ++- 14 files changed, 245 insertions(+), 14 deletions(-) create mode 100644 sys/arch/sh3/dev/wdog.c create mode 100644 sys/arch/sh3/include/wdogvar.h diff --git a/sys/arch/evbsh3/conf/COMPUTEXEVB b/sys/arch/evbsh3/conf/COMPUTEXEVB index 446aab2a10a9..de3a0a2c19df 100644 --- a/sys/arch/evbsh3/conf/COMPUTEXEVB +++ b/sys/arch/evbsh3/conf/COMPUTEXEVB @@ -1,4 +1,4 @@ -# $NetBSD: COMPUTEXEVB,v 1.2 2000/01/07 11:20:43 msaitoh Exp $ +# $NetBSD: COMPUTEXEVB,v 1.3 2000/02/24 17:07:36 msaitoh Exp $ # # GENERIC -- everything that's currently supported # @@ -134,6 +134,9 @@ mainbus0 at root shb* at mainbus? +# WatchDog Timer +wdog0 at shb? port 0xffffff84 + # Serial Devices # 115200bps (3.2%) diff --git a/sys/arch/evbsh3/conf/CQREEKSH3 b/sys/arch/evbsh3/conf/CQREEKSH3 index d56088dc0ce4..aef157d450d3 100644 --- a/sys/arch/evbsh3/conf/CQREEKSH3 +++ b/sys/arch/evbsh3/conf/CQREEKSH3 @@ -1,4 +1,4 @@ -# $NetBSD: CQREEKSH3,v 1.5 2000/01/07 11:20:43 msaitoh Exp $ +# $NetBSD: CQREEKSH3,v 1.6 2000/02/24 17:07:36 msaitoh Exp $ # # GENERIC -- everything that's currently supported # @@ -134,6 +134,9 @@ mainbus0 at root shb* at mainbus? +# WatchDog Timer +wdog0 at shb? port 0xffffff84 + # Serial Devices options SCICONSOLE,SCICN_SPEED=38400 diff --git a/sys/arch/evbsh3/conf/files.shbus b/sys/arch/evbsh3/conf/files.shbus index eadc522e72cc..024972305a13 100644 --- a/sys/arch/evbsh3/conf/files.shbus +++ b/sys/arch/evbsh3/conf/files.shbus @@ -1,4 +1,4 @@ -# $NetBSD: files.shbus,v 1.4 1999/09/17 01:21:41 msaitoh Exp $ +# $NetBSD: files.shbus,v 1.5 2000/02/24 17:07:36 msaitoh Exp $ # # Config file and device description for machine-independent SHBus code. # Included by ports that need it. Requires that the SCSI files be @@ -15,6 +15,12 @@ attach shb at mainbus file arch/evbsh3/evbsh3/shb.c shb needs-flag +# Misc devices + +device wdog +attach wdog at shb +file arch/sh3/dev/wdog.c wdog needs-flag + # # Serial drivers # diff --git a/sys/arch/evbsh3/evbsh3/conf.c b/sys/arch/evbsh3/evbsh3/conf.c index 85f86ba67210..1509042d4ce1 100644 --- a/sys/arch/evbsh3/evbsh3/conf.c +++ b/sys/arch/evbsh3/evbsh3/conf.c @@ -1,4 +1,4 @@ -/* $NetBSD: conf.c,v 1.2 1999/09/13 16:26:18 msaitoh Exp $ */ +/* $NetBSD: conf.c,v 1.3 2000/02/24 17:07:36 msaitoh Exp $ */ /* * Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved. @@ -84,6 +84,8 @@ cdev_decl(ctty); #define mmread mmrw #define mmwrite mmrw cdev_decl(mm); +#include "wdog.h" +cdev_decl(wdog); cdev_decl(wd); cdev_decl(sw); #include "pty.h" @@ -188,6 +190,7 @@ struct cdevsw cdevsw[] = cdev_scsibus_init(NSCSIBUS,scsibus), /* 48: SCSI bus */ cdev_disk_init(NRAID,raid), /* 49: RAIDframe disk driver */ cdev_esh_init(NESH, esh_fp), /* 50: HIPPI (esh) raw device */ + cdev_wdog_init(NWDOG,wdog), /* 51: watchdog timer */ }; int nchrdev = sizeof(cdevsw) / sizeof(cdevsw[0]); diff --git a/sys/arch/evbsh3/include/conf.h b/sys/arch/evbsh3/include/conf.h index 05a599c187c2..6fdf5947639b 100644 --- a/sys/arch/evbsh3/include/conf.h +++ b/sys/arch/evbsh3/include/conf.h @@ -1,4 +1,4 @@ -/* $NetBSD: conf.h,v 1.1 1999/09/13 10:30:30 itojun Exp $ */ +/* $NetBSD: conf.h,v 1.2 2000/02/24 17:07:36 msaitoh Exp $ */ /* * Copyright (c) 1996 Christos Zoulas. All rights reserved. @@ -37,3 +37,11 @@ cdev_decl(mm); bdev_decl(fd); cdev_decl(fd); + +/* open, close, ioctl */ +#define cdev_wdog_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, seltrue, (dev_type_mmap((*))) enodev } + +cdev_decl(wdog); diff --git a/sys/arch/mmeye/conf/GENERIC b/sys/arch/mmeye/conf/GENERIC index ea6665712191..411d51d76fdb 100644 --- a/sys/arch/mmeye/conf/GENERIC +++ b/sys/arch/mmeye/conf/GENERIC @@ -1,11 +1,11 @@ -# $NetBSD: GENERIC,v 1.8 2000/02/23 21:14:12 msaitoh Exp $ +# $NetBSD: GENERIC,v 1.9 2000/02/24 17:07:35 msaitoh Exp $ # # GENERIC -- everything that's currently supported # include "arch/mmeye/conf/std.mmeye" -#ident "GENERIC-$Revision: 1.8 $" +#ident "GENERIC-$Revision: 1.9 $" maxusers 16 # estimated number of users @@ -130,6 +130,9 @@ mainbus0 at root shb* at mainbus? +# WatchDog Timer +wdog0 at shb? port 0xffffff84 + com0 at shb? port 0xa4000000 irq 11 com1 at shb? port 0xa4000008 irq 12 diff --git a/sys/arch/mmeye/conf/MMEYE b/sys/arch/mmeye/conf/MMEYE index 34c9ad4eb4b5..9e431b9abe23 100644 --- a/sys/arch/mmeye/conf/MMEYE +++ b/sys/arch/mmeye/conf/MMEYE @@ -1,4 +1,4 @@ -# $NetBSD: MMEYE,v 1.4 2000/02/23 21:14:12 msaitoh Exp $ +# $NetBSD: MMEYE,v 1.5 2000/02/24 17:07:35 msaitoh Exp $ # # GENERIC -- everything that's currently supported # @@ -65,6 +65,9 @@ mainbus0 at root shb* at mainbus? +# WatchDog Timer +wdog0 at shb? port 0xffffff84 + com0 at shb? port 0xa4000000 irq 11 com1 at shb? port 0xa4000008 irq 12 diff --git a/sys/arch/mmeye/conf/files.shbus b/sys/arch/mmeye/conf/files.shbus index 39d8252d06b0..5ee87bdb7fee 100644 --- a/sys/arch/mmeye/conf/files.shbus +++ b/sys/arch/mmeye/conf/files.shbus @@ -1,4 +1,4 @@ -# $NetBSD: files.shbus,v 1.3 1999/09/16 21:18:55 msaitoh Exp $ +# $NetBSD: files.shbus,v 1.4 2000/02/24 17:07:35 msaitoh Exp $ # # Config file and device description for machine-independent ISA code. # Included by ports that need it. Requires that the SCSI files be @@ -15,6 +15,12 @@ attach shb at mainbus file arch/mmeye/mmeye/shb.c shb needs-flag +# Misc devices + +device wdog +attach wdog at shb +file arch/sh3/dev/wdog.c wdog needs-flag + # # Serial and parallel drivers # diff --git a/sys/arch/mmeye/include/conf.h b/sys/arch/mmeye/include/conf.h index 652692eac1f2..a33febe6eeae 100644 --- a/sys/arch/mmeye/include/conf.h +++ b/sys/arch/mmeye/include/conf.h @@ -1,4 +1,4 @@ -/* $NetBSD: conf.h,v 1.1 1999/09/13 10:30:54 itojun Exp $ */ +/* $NetBSD: conf.h,v 1.2 2000/02/24 17:07:35 msaitoh Exp $ */ /* * Copyright (c) 1996 Christos Zoulas. All rights reserved. @@ -37,3 +37,11 @@ cdev_decl(mm); bdev_decl(fd); cdev_decl(fd); + +/* open, close, ioctl */ +#define cdev_wdog_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, seltrue, (dev_type_mmap((*))) enodev } + +cdev_decl(wdog); diff --git a/sys/arch/mmeye/mmeye/conf.c b/sys/arch/mmeye/mmeye/conf.c index 6c6e0118ce01..8e01ade0ece3 100644 --- a/sys/arch/mmeye/mmeye/conf.c +++ b/sys/arch/mmeye/mmeye/conf.c @@ -1,4 +1,4 @@ -/* $NetBSD: conf.c,v 1.3 1999/09/14 11:20:53 tsubai Exp $ */ +/* $NetBSD: conf.c,v 1.4 2000/02/24 17:07:35 msaitoh Exp $ */ /* * Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved. @@ -84,6 +84,8 @@ cdev_decl(ctty); #define mmread mmrw #define mmwrite mmrw cdev_decl(mm); +#include "wdog.h" +cdev_decl(wdog); cdev_decl(wd); cdev_decl(sw); #include "pty.h" @@ -184,6 +186,7 @@ struct cdevsw cdevsw[] = cdev_scsibus_init(NSCSIBUS,scsibus), /* 48: SCSI bus */ cdev_disk_init(NRAID,raid), /* 49: RAIDframe disk driver */ cdev_esh_init(NESH, esh_fp), /* 50: HIPPI (esh) raw device */ + cdev_wdog_init(NWDOG,wdog), /* 51: watchdog timer */ }; int nchrdev = sizeof(cdevsw) / sizeof(cdevsw[0]); diff --git a/sys/arch/sh3/dev/wdog.c b/sys/arch/sh3/dev/wdog.c new file mode 100644 index 000000000000..8a71e426f225 --- /dev/null +++ b/sys/arch/sh3/dev/wdog.c @@ -0,0 +1,157 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +struct wdog_softc { + struct device sc_dev; /* generic device structures */ + unsigned int iobase; + int flags; +}; + +static int wdogmatch __P((struct device *, struct cfdata *, void *)); +static void wdogattach __P((struct device *, struct device *, void *)); + +struct cfattach wdog_ca = { + sizeof(struct wdog_softc), wdogmatch, wdogattach +}; + +extern struct cfdriver wdog_cd; + +void +wdog_wr_cnt(x) + unsigned char x; +{ + + SHREG_WTCNT_W = WTCNT_W_M | (unsigned short) x; +} + +void +wdog_wr_csr(x) + unsigned char x; +{ + + SHREG_WTCSR_W = WTCSR_W_M | (unsigned short) x; +} + +static int +wdogmatch(parent, cfp, aux) + struct device *parent; + struct cfdata *cfp; + void *aux; +{ + struct shb_attach_args *sa = aux; + + if (strcmp(cfp->cf_driver->cd_name, "wdog")) + return 0; + + sa->ia_iosize = 4; /* XXX */ + + return (1); +} + +/* + * functions for probeing. + */ +/* ARGSUSED */ +static void +wdogattach(parent, self, aux) + struct device *parent, *self; + void *aux; +{ + struct wdog_softc *sc = (struct wdog_softc *)self; + struct shb_attach_args *sa = aux; + + sc->iobase = sa->ia_iobase; + sc->flags = 0; + + printf("\nwdog0: internal watchdog timer\n"); +} + +/*ARGSUSED*/ +int +wdogopen(dev, flag, mode, p) + dev_t dev; + int flag, mode; + struct proc *p; +{ + struct wdog_softc *sc = wdog_cd.cd_devs[0]; /* XXX */ + + if (minor(dev) != 0) + return (ENXIO); + if (sc->flags & WDOGF_OPEN) + return (EBUSY); + sc->flags |= WDOGF_OPEN; + return (0); +} + +/*ARGSUSED*/ +int +wdogclose(dev, flag, mode, p) + dev_t dev; + int flag, mode; + struct proc *p; +{ + struct wdog_softc *sc = wdog_cd.cd_devs[0]; /* XXX */ + + if (sc->flags & WDOGF_OPEN) + sc->flags = 0; + + return (0); +} + +extern unsigned int maxwdog; + +/*ARGSUSED*/ +int +wdogioctl (dev, cmd, data, flag, p) + dev_t dev; + u_long cmd; + caddr_t data; + int flag; + struct proc *p; +{ + int error = 0; + int request; + + switch (cmd) { + case SIORESETWDOG: + wdog_wr_cnt(0); /* reset to zero */ + break; + case SIOSTARTWDOG: + wdog_wr_csr(WTCSR_WT | WTCSR_CKS_4096); + wdog_wr_cnt(0); /* reset to zero */ + wdog_wr_csr(SHREG_WTCSR_R | WTCSR_TME); /* start!!! */ + break; + case SIOSTOPWDOG: + wdog_wr_csr(SHREG_WTCSR_R & ~WTCSR_TME); /* stop */ + log(LOG_SYSTEM | LOG_DEBUG, "wdog: maxwdog = %u\n", maxwdog); + break; + case SIOSETWDOG: + request = *(int *)data; + + if (request > 2) { + error = EINVAL; + break; + } + break; + default: + error = EINVAL; + break; + } + + return (error); +} diff --git a/sys/arch/sh3/include/Makefile b/sys/arch/sh3/include/Makefile index 53481c9e1a76..6ef5a2e4966c 100644 --- a/sys/arch/sh3/include/Makefile +++ b/sys/arch/sh3/include/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.4 2000/01/17 16:27:53 kleink Exp $ +# $NetBSD: Makefile,v 1.5 2000/02/24 17:07:34 msaitoh Exp $ KDIR= /sys/arch/sh3/include INCSDIR= /usr/include/sh3 @@ -11,6 +11,6 @@ INCS= ansi.h aout_machdep.h asm.h bootinfo.h bscreg.h bswap.h bus.h \ pte.h ptrace.h reg.h rtcreg.h scifreg.h scireg.h segments.h setjmp.h \ sh_opcode.h shbvar.h signal.h stdarg.h tmureg.h \ trap.h trapreg.h types.h ubcreg.h va-sh.h varargs.h vmparam.h \ - wdtreg.h + wdogvar.h wdtreg.h .include diff --git a/sys/arch/sh3/include/wdogvar.h b/sys/arch/sh3/include/wdogvar.h new file mode 100644 index 000000000000..2bd4390033c0 --- /dev/null +++ b/sys/arch/sh3/include/wdogvar.h @@ -0,0 +1,16 @@ +#ifndef _SH3_WDOGVAR_H_ +#define _SH3_WDOGVAR_H_ + +#define WDOGF_OPEN 1 + +#define SIORESETWDOG _IO('S', 0x0) +#define SIOSTARTWDOG _IO('S', 0x1) +#define SIOSTOPWDOG _IO('S', 0x2) +#define SIOSETWDOG _IOW('S', 0x3, int) + +#ifdef _KERNEL +extern void wdog_wr_cnt __P((unsigned char)); +extern void wdog_wr_csr __P((unsigned char)); +#endif + +#endif /* !_SH3_WDOGVAR_H_ */ diff --git a/sys/arch/sh3/sh3/clock.c b/sys/arch/sh3/sh3/clock.c index 14a5d024c1f1..1e8f76dc7cc2 100644 --- a/sys/arch/sh3/sh3/clock.c +++ b/sys/arch/sh3/sh3/clock.c @@ -1,4 +1,4 @@ -/* $NetBSD: clock.c,v 1.7 2000/01/17 21:54:32 msaitoh Exp $ */ +/* $NetBSD: clock.c,v 1.8 2000/02/24 17:07:35 msaitoh Exp $ */ /*- * Copyright (c) 1993, 1994 Charles Hannum. @@ -90,6 +90,7 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include "opt_pclock.h" +#include "wdog.h" #include #include @@ -101,6 +102,7 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include +#include #include #include #include @@ -176,6 +178,8 @@ microtime(tvp) splx(s); } +#include +unsigned int maxwdog; int clockintr(arg) @@ -184,6 +188,14 @@ clockintr(arg) #if 1 struct clockframe *frame = arg; /* not strictly necessary */ #endif +#if (NWDOG > 0) + unsigned int i; + + i = (unsigned int)SHREG_WTCNT_R; + if (i > maxwdog) + maxwdog = i; + wdog_wr_cnt(0); /* reset to zero */ +#endif /* clear timer counter under flow interrupt flag */ #ifdef USE_RTCCLK