change zsinfo to a zs_softc, and impliment intr counts. mostly from OpenBSD.

This commit is contained in:
mrg 1996-05-28 14:06:28 +00:00
parent 08bd090b26
commit 6ce8e31376
1 changed files with 108 additions and 84 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: zs.c,v 1.37 1996/04/01 17:29:44 christos Exp $ */
/* $NetBSD: zs.c,v 1.38 1996/05/28 14:06:28 mrg Exp $ */
/*
* Copyright (c) 1992, 1993
@ -48,10 +48,13 @@
* Zilog Z8530 (ZSCC) driver.
*
* Runs two tty ports (ttya and ttyb) on zs0,
* and runs a keyboard and mouse on zs1.
* and runs a keyboard and mouse on zs1, and
* possibly two more tty ports (ttyc and ttyd) on zs2.
*
* This driver knows far too much about chip to usage mappings.
*/
#include "zs.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/proc.h>
@ -68,14 +71,12 @@
#include <machine/autoconf.h>
#include <machine/conf.h>
#include <machine/cpu.h>
#include <machine/kbd.h>
#include <sparc/sparc/vaddrs.h>
#include <sparc/sparc/auxreg.h>
#include <machine/kbd.h>
#include <sparc/dev/zsreg.h>
#include <dev/ic/z8530reg.h>
#include <sparc/dev/zsvar.h>
#ifdef KGDB
@ -104,13 +105,13 @@
#endif
/*
* Software state per found chip. This would be called `zs_softc',
* but the previous driver had a rather different zs_softc....
* Software state per found chip.
*/
struct zsinfo {
struct device zi_dev; /* base device */
volatile struct zsdevice *zi_zs;/* chip registers */
struct zs_chanstate zi_cs[2]; /* channel A and B software state */
struct zs_softc {
struct device sc_dev; /* base device */
volatile struct zsdevice *sc_zs; /* chip registers */
struct evcnt sc_intrcnt;
struct zs_chanstate sc_cs[2]; /* chan A/B software state */
};
/* Definition of the driver for autoconfig. */
@ -118,7 +119,7 @@ static int zsmatch __P((struct device *, void *, void *));
static void zsattach __P((struct device *, struct device *, void *));
struct cfattach zs_ca = {
sizeof(struct zsinfo), zsmatch, zsattach
sizeof(struct zs_softc), zsmatch, zsattach
};
struct cfdriver zs_cd = {
@ -152,7 +153,8 @@ static struct tty *zs_ctty; /* console `struct tty *' */
static int zs_consin = -1, zs_consout = -1;
static void zscnputc __P((int)); /* console putc function */
static volatile struct zschan *zs_conschan;
static struct tty *zs_checkcons __P((struct zsinfo *, int, struct zs_chanstate *));
static struct tty *zs_checkcons __P((struct zs_softc *, int,
struct zs_chanstate *));
#ifdef KGDB
/* KGDB stuff. Must reboot to change zs_kgdbunit. */
@ -171,7 +173,6 @@ static int zssint __P((struct zs_chanstate *, volatile struct zschan *));
void zsabort __P((void));
static void zsoverrun __P((int, long *, char *));
#include "zs.h" /* XXX: */
static volatile struct zsdevice *zsaddr[NZS]; /* XXX, but saves work */
/*
@ -255,7 +256,7 @@ zsattach(parent, dev, aux)
void *aux;
{
register int zs = dev->dv_unit, unit;
register struct zsinfo *zi;
register struct zs_softc *sc;
register struct zs_chanstate *cs;
register volatile struct zsdevice *addr;
register struct tty *tp, *ctp;
@ -266,7 +267,7 @@ zsattach(parent, dev, aux)
int ringsize;
if ((addr = zsaddr[zs]) == NULL)
addr = zsaddr[zs] = findzs(zs);
addr = zsaddr[zs] = (volatile struct zsdevice *)findzs(zs);
if (ca->ca_bustype==BUS_MAIN)
if ((void *)addr != ra->ra_vaddr)
panic("zsattach");
@ -283,25 +284,33 @@ zsattach(parent, dev, aux)
intr_establish(PIL_TTY, &levelsoft);
} else if (pri != prevpri)
panic("broken zs interrupt scheme");
zi = (struct zsinfo *)dev;
zi->zi_zs = addr;
sc = (struct zs_softc *)dev;
evcnt_attach(&sc->sc_dev, "intr", &sc->sc_intrcnt);
sc->sc_zs = addr;
unit = zs * 2;
cs = zi->zi_cs;
cs = sc->sc_cs;
cs->cs_ttyp = tp = ttymalloc();
/* link into interrupt list with order (A,B) (B=A+1) */
cs[0].cs_next = &cs[1];
cs[0].cs_sc = sc;
cs[1].cs_next = zslist;
cs[1].cs_sc = sc;
zslist = cs;
cs->cs_unit = unit;
cs->cs_speed = zs_getspeed(&addr->zs_chan[ZS_CHAN_A]);
cs->cs_zc = &addr->zs_chan[ZS_CHAN_A];
tp->t_dev = makedev(ZSMAJOR, unit);
if ((ctp = zs_checkcons(cs, unit, cs)) != NULL)
cs->cs_ttyp = tp = ctp;
else {
tp = ttymalloc();
tp->t_dev = makedev(ZSMAJOR, unit);
tp->t_oproc = zsstart;
tp->t_param = zsparam;
if ((ctp = zs_checkcons(zi, unit, cs)) != NULL)
cs->cs_ttyp = tp = ctp;
}
cs->cs_ttyp = tp;
#ifdef KGDB
if (ctp == NULL)
zs_checkkgdb(unit, cs, tp);
@ -315,23 +324,27 @@ zsattach(parent, dev, aux)
kbd_serial(tp, zsiopen, zsiclose);
cs->cs_conk = 1; /* do L1-A processing */
ringsize = 128;
} else
} else {
if (tp != ctp)
tty_attach(tp);
ringsize = 4096;
}
cs->cs_ringmask = ringsize - 1;
cs->cs_rbuf = malloc((u_long)ringsize * sizeof(*cs->cs_rbuf),
M_DEVBUF, M_NOWAIT);
unit++;
cs++;
cs->cs_ttyp = tp = ttymalloc();
cs->cs_unit = unit;
cs->cs_speed = zs_getspeed(&addr->zs_chan[ZS_CHAN_B]);
cs->cs_zc = &addr->zs_chan[ZS_CHAN_B];
if ((ctp = zs_checkcons(sc, unit, cs)) != NULL)
tp = ctp;
else {
tp = ttymalloc();
tp->t_dev = makedev(ZSMAJOR, unit);
tp->t_oproc = zsstart;
tp->t_param = zsparam;
if ((ctp = zs_checkcons(zi, unit, cs)) != NULL)
cs->cs_ttyp = tp = ctp;
}
cs->cs_ttyp = tp;
#ifdef KGDB
if (ctp == NULL)
zs_checkkgdb(unit, cs, tp);
@ -340,12 +353,15 @@ zsattach(parent, dev, aux)
/*
* Mouse: tell /dev/mouse driver how to talk to us.
*/
tp->t_ispeed = tp->t_ospeed = cs->cs_speed;
tp->t_ispeed = tp->t_ospeed = B1200;
tp->t_cflag = CS8;
ms_serial(tp, zsiopen, zsiclose);
ringsize = 128;
} else
} else {
if (tp != ctp)
tty_attach(tp);
ringsize = 4096;
}
cs->cs_ringmask = ringsize - 1;
cs->cs_rbuf = malloc((u_long)ringsize * sizeof(*cs->cs_rbuf),
M_DEVBUF, M_NOWAIT);
@ -414,7 +430,7 @@ zsconsole(tp, unit, out, fnstop)
zs_consout = unit;
zs = unit >> 1;
if ((addr = zsaddr[zs]) == NULL)
addr = zsaddr[zs] = findzs(zs);
addr = zsaddr[zs] = (volatile struct zsdevice *)findzs(zs);
zs_conschan = (unit & 1) == 0 ? &addr->zs_chan[ZS_CHAN_A] :
&addr->zs_chan[ZS_CHAN_B];
v_putc = zscnputc;
@ -456,8 +472,8 @@ zscnputc(c)
* needed. Return console tty if it is to receive console input.
*/
static struct tty *
zs_checkcons(zi, unit, cs)
struct zsinfo *zi;
zs_checkcons(sc, unit, cs)
struct zs_softc *sc;
int unit;
struct zs_chanstate *cs;
{
@ -492,7 +508,7 @@ zs_checkcons(zi, unit, cs)
tp->t_oproc = zsstart;
}
printf("%s%c: console %s\n",
zi->zi_dev.dv_xname, (unit & 1) + 'a', i ? (o ? "i/o" : i) : o);
sc->sc_dev.dv_xname, (unit & 1) + 'a', i ? (o ? "i/o" : i) : o);
cs->cs_consio = 1;
cs->cs_brkabort = 1;
return (tp);
@ -577,13 +593,13 @@ zsopen(dev, flags, mode, p)
{
register struct tty *tp;
register struct zs_chanstate *cs;
struct zsinfo *zi;
struct zs_softc *sc;
int unit = minor(dev), zs = unit >> 1, error, s;
if (zs >= zs_cd.cd_ndevs || (zi = zs_cd.cd_devs[zs]) == NULL ||
if (zs >= zs_cd.cd_ndevs || (sc = zs_cd.cd_devs[zs]) == NULL ||
unit == ZS_KBD || unit == ZS_MOUSE)
return (ENXIO);
cs = &zi->zi_cs[unit & 1];
cs = &sc->sc_cs[unit & 1];
if (cs->cs_consio)
return (ENXIO); /* ??? */
tp = cs->cs_ttyp;
@ -650,11 +666,11 @@ zsclose(dev, flags, mode, p)
{
register struct zs_chanstate *cs;
register struct tty *tp;
struct zsinfo *zi;
struct zs_softc *sc;
int unit = minor(dev), s;
zi = zs_cd.cd_devs[unit >> 1];
cs = &zi->zi_cs[unit & 1];
sc = zs_cd.cd_devs[unit >> 1];
cs = &sc->sc_cs[unit & 1];
tp = cs->cs_ttyp;
linesw[tp->t_line].l_close(tp, flags);
if (tp->t_cflag & HUPCL || tp->t_state & TS_WOPEN ||
@ -692,12 +708,12 @@ zsread(dev, uio, flags)
int flags;
{
register struct zs_chanstate *cs;
register struct zsinfo *zi;
register struct zs_softc *sc;
register struct tty *tp;
int unit = minor(dev);
zi = zs_cd.cd_devs[unit >> 1];
cs = &zi->zi_cs[unit & 1];
sc = zs_cd.cd_devs[unit >> 1];
cs = &sc->sc_cs[unit & 1];
tp = cs->cs_ttyp;
return (linesw[tp->t_line].l_read(tp, uio, flags));
@ -711,12 +727,12 @@ zswrite(dev, uio, flags)
int flags;
{
register struct zs_chanstate *cs;
register struct zsinfo *zi;
register struct zs_softc *sc;
register struct tty *tp;
int unit = minor(dev);
zi = zs_cd.cd_devs[unit >> 1];
cs = &zi->zi_cs[unit & 1];
sc = zs_cd.cd_devs[unit >> 1];
cs = &sc->sc_cs[unit & 1];
tp = cs->cs_ttyp;
return (linesw[tp->t_line].l_write(tp, uio, flags));
@ -727,16 +743,19 @@ zstty(dev)
dev_t dev;
{
register struct zs_chanstate *cs;
register struct zsinfo *zi;
register struct zs_softc *sc;
int unit = minor(dev);
zi = zs_cd.cd_devs[unit >> 1];
cs = &zi->zi_cs[unit & 1];
sc = zs_cd.cd_devs[unit >> 1];
cs = &sc->sc_cs[unit & 1];
return (cs->cs_ttyp);
}
static int zsrint __P((struct zs_chanstate *, volatile struct zschan *));
static int zsxint __P((struct zs_chanstate *, volatile struct zschan *));
static int zssint __P((struct zs_chanstate *, volatile struct zschan *));
/*
* ZS hardware interrupt. Scan all ZS channels. NB: we know here that
* channels are kept in (A,B) pairs.
@ -757,53 +776,58 @@ zshard(intrarg)
#define b (a + 1)
register volatile struct zschan *zc;
register int rr3, intflags = 0, v, i, ringmask;
static int zsrint(struct zs_chanstate *, volatile struct zschan *);
static int zsxint(struct zs_chanstate *, volatile struct zschan *);
static int zssint(struct zs_chanstate *, volatile struct zschan *);
#define ZSHARD_NEED_SOFTINTR 1
#define ZSHARD_WAS_SERVICED 2
#define ZSHARD_CHIP_GOTINTR 4
for (a = zslist; a != NULL; a = b->cs_next) {
ringmask = a->cs_ringmask;
rr3 = ZS_READ(a->cs_zc, 3);
if (rr3 & (ZSRR3_IP_A_RX|ZSRR3_IP_A_TX|ZSRR3_IP_A_STAT)) {
intflags |= 2;
intflags |= (ZSHARD_CHIP_GOTINTR|ZSHARD_WAS_SERVICED);
zc = a->cs_zc;
i = a->cs_rbput;
if (rr3 & ZSRR3_IP_A_RX && (v = zsrint(a, zc)) != 0) {
a->cs_rbuf[i++ & ringmask] = v;
intflags |= 1;
intflags |= ZSHARD_NEED_SOFTINTR;
}
if (rr3 & ZSRR3_IP_A_TX && (v = zsxint(a, zc)) != 0) {
a->cs_rbuf[i++ & ringmask] = v;
intflags |= 1;
intflags |= ZSHARD_NEED_SOFTINTR;
}
if (rr3 & ZSRR3_IP_A_STAT && (v = zssint(a, zc)) != 0) {
a->cs_rbuf[i++ & ringmask] = v;
intflags |= 1;
intflags |= ZSHARD_NEED_SOFTINTR;
}
a->cs_rbput = i;
}
if (rr3 & (ZSRR3_IP_B_RX|ZSRR3_IP_B_TX|ZSRR3_IP_B_STAT)) {
intflags |= 2;
intflags |= (ZSHARD_CHIP_GOTINTR|ZSHARD_WAS_SERVICED);
zc = b->cs_zc;
i = b->cs_rbput;
if (rr3 & ZSRR3_IP_B_RX && (v = zsrint(b, zc)) != 0) {
b->cs_rbuf[i++ & ringmask] = v;
intflags |= 1;
intflags |= ZSHARD_NEED_SOFTINTR;
}
if (rr3 & ZSRR3_IP_B_TX && (v = zsxint(b, zc)) != 0) {
b->cs_rbuf[i++ & ringmask] = v;
intflags |= 1;
intflags |= ZSHARD_NEED_SOFTINTR;
}
if (rr3 & ZSRR3_IP_B_STAT && (v = zssint(b, zc)) != 0) {
b->cs_rbuf[i++ & ringmask] = v;
intflags |= 1;
intflags |= ZSHARD_NEED_SOFTINTR;
}
b->cs_rbput = i;
}
if (intflags & ZSHARD_CHIP_GOTINTR) {
a->cs_sc->sc_intrcnt.ev_count++;
intflags &= ~ZSHARD_CHIP_GOTINTR;
}
}
#undef b
if (intflags & 1) {
if (intflags & ZSHARD_NEED_SOFTINTR) {
if (CPU_ISSUN4COR4M) {
/* XXX -- but this will go away when zshard moves to locore.s */
struct clockframe *p = intrarg;
@ -819,14 +843,12 @@ zshard(intrarg)
}
}
#if defined(SUN4M)
if (CPU_ISSUN4M)
raise(0, PIL_TTY);
else
#endif
ienab_bis(IE_ZSSOFT);
}
return (intflags & 2);
return (intflags & ZSHARD_WAS_SERVICED);
}
static int
@ -834,7 +856,7 @@ zsrint(cs, zc)
register struct zs_chanstate *cs;
register volatile struct zschan *zc;
{
register int c = zc->zc_data;
register u_int c = zc->zc_data;
ZS_DELAY();
if (cs->cs_conk) {
@ -914,7 +936,7 @@ zssint(cs, zc)
register struct zs_chanstate *cs;
register volatile struct zschan *zc;
{
register int rr0;
register u_int rr0;
rr0 = zc->zc_csr;
ZS_DELAY();
@ -1137,8 +1159,8 @@ zsioctl(dev, cmd, data, flag, p)
struct proc *p;
{
int unit = minor(dev);
struct zsinfo *zi = zs_cd.cd_devs[unit >> 1];
register struct zs_chanstate *cs = &zi->zi_cs[unit & 1];
struct zs_softc *sc = zs_cd.cd_devs[unit >> 1];
register struct zs_chanstate *cs = &sc->sc_cs[unit & 1];
register struct tty *tp = cs->cs_ttyp;
register int error, s;
@ -1235,9 +1257,9 @@ zsioctl(dev, cmd, data, flag, p)
zs_modem(cs, 0);
break;
case TIOCMSET:
case TIOCMGET:
case TIOCMBIS:
case TIOCMBIC:
case TIOCMGET:
default:
return (ENOTTY);
}
@ -1254,9 +1276,9 @@ zsstart(tp)
register struct zs_chanstate *cs;
register int s, nch;
int unit = minor(tp->t_dev);
struct zsinfo *zi = zs_cd.cd_devs[unit >> 1];
struct zs_softc *sc = zs_cd.cd_devs[unit >> 1];
cs = &zi->zi_cs[unit & 1];
cs = &sc->sc_cs[unit & 1];
s = spltty();
/*
@ -1315,9 +1337,9 @@ zsstop(tp, flag)
{
register struct zs_chanstate *cs;
register int s, unit = minor(tp->t_dev);
struct zsinfo *zi = zs_cd.cd_devs[unit >> 1];
struct zs_softc *sc = zs_cd.cd_devs[unit >> 1];
cs = &zi->zi_cs[unit & 1];
cs = &sc->sc_cs[unit & 1];
s = splzs();
if (tp->t_state & TS_BUSY) {
/*
@ -1328,7 +1350,6 @@ zsstop(tp, flag)
tp->t_state |= TS_FLUSH;
}
splx(s);
return 0;
}
/*
@ -1343,8 +1364,8 @@ zsparam(tp, t)
register struct termios *t;
{
int unit = minor(tp->t_dev);
struct zsinfo *zi = zs_cd.cd_devs[unit >> 1];
register struct zs_chanstate *cs = &zi->zi_cs[unit & 1];
struct zs_softc *sc = zs_cd.cd_devs[unit >> 1];
register struct zs_chanstate *cs = &sc->sc_cs[unit & 1];
register int tmp, tmp5, cflag, s;
/*
@ -1518,10 +1539,13 @@ zs_kgdb_getc(arg)
void *arg;
{
register volatile struct zschan *zc = (volatile struct zschan *)arg;
u_char c;
while ((zc->zc_csr & ZSRR0_RX_READY) == 0)
ZS_DELAY();
return (zc->zc_data);
c = zc->zc_data;
ZS_DELAY();
return c;
}
/*
@ -1563,7 +1587,7 @@ zs_kgdb_init()
}
zs = unit >> 1;
if ((addr = zsaddr[zs]) == NULL)
addr = zsaddr[zs] = findzs(zs);
addr = zsaddr[zs] = (volatile struct zsdevice *)findzs(zs);
unit &= 1;
zc = unit == 0 ? &addr->zs_chan[ZS_CHAN_A] : &addr->zs_chan[ZS_CHAN_B];
zs_kgdb_savedspeed = zs_getspeed(zc);