watchdog timer

This commit is contained in:
msaitoh 2000-02-24 17:07:34 +00:00
parent 0e12305a13
commit e2cc2d00d7
14 changed files with 245 additions and 14 deletions

View File

@ -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%)

View File

@ -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

View File

@ -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
#

View File

@ -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]);

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -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
#

View File

@ -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);

View File

@ -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]);

157
sys/arch/sh3/dev/wdog.c Normal file
View File

@ -0,0 +1,157 @@
#include <sys/param.h>
#include <sys/buf.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/uio.h>
#include <sys/device.h>
#include <sys/fcntl.h>
#include <sys/ioctl.h>
#include <sys/malloc.h>
#include <sys/proc.h>
#include <sys/syslog.h>
#include <machine/cpu.h>
#include <machine/conf.h>
#include <sh3/shbvar.h>
#include <sh3/wdtreg.h>
#include <sh3/wdogvar.h>
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);
}

View File

@ -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 <bsd.kinc.mk>

View File

@ -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_ */

View File

@ -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 <sys/param.h>
#include <sys/systm.h>
@ -101,6 +102,7 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <sh3/rtcreg.h>
#include <sh3/tmureg.h>
#include <sh3/wdogvar.h>
#include <machine/cpu.h>
#include <machine/intr.h>
#include <machine/cpufunc.h>
@ -176,6 +178,8 @@ microtime(tvp)
splx(s);
}
#include <sh3/wdtreg.h>
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