diff options
Diffstat (limited to 'sys/arch/sparc/dev/zs.c')
-rw-r--r-- | sys/arch/sparc/dev/zs.c | 161 |
1 files changed, 94 insertions, 67 deletions
diff --git a/sys/arch/sparc/dev/zs.c b/sys/arch/sparc/dev/zs.c index 28adc15d977..bec292c6b95 100644 --- a/sys/arch/sparc/dev/zs.c +++ b/sys/arch/sparc/dev/zs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: zs.c,v 1.10 1996/08/11 23:39:56 downsj Exp $ */ +/* $OpenBSD: zs.c,v 1.11 1996/08/12 00:28:16 downsj Exp $ */ /* $NetBSD: zs.c,v 1.37.4.1 1996/06/02 09:07:55 mrg Exp $ */ /* @@ -49,10 +49,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> @@ -105,13 +108,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]; /* channel A/B software state */ }; /* Definition of the driver for autoconfig. */ @@ -119,7 +122,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 = { @@ -153,7 +156,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. */ @@ -172,7 +176,7 @@ 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: */ +extern void *findzs __P((int)); static volatile struct zsdevice *zsaddr[NZS]; /* XXX, but saves work */ /* @@ -256,7 +260,7 @@ zsattach(parent, dev, aux) void *aux; { register int zs = dev->dv_unit, unit; - register struct zsinfo *zi; + register struct zs_softc *zi; register struct zs_chanstate *cs; register volatile struct zsdevice *addr; register struct tty *tp, *ctp; @@ -267,8 +271,8 @@ zsattach(parent, dev, aux) int ringsize; if ((addr = zsaddr[zs]) == NULL) - addr = zsaddr[zs] = findzs(zs); - if (ca->ca_bustype==BUS_MAIN) + addr = zsaddr[zs] = (volatile struct zsdevice *)findzs(zs); + if (ca->ca_bustype == BUS_MAIN) if ((void *)addr != ra->ra_vaddr) panic("zsattach"); if (ra->ra_nintr != 1) { @@ -284,14 +288,17 @@ 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; /* 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; @@ -329,6 +336,7 @@ zsattach(parent, dev, aux) M_DEVBUF, M_NOWAIT); unit++; cs++; + cs->cs_unit = unit; cs->cs_speed = zs_getspeed(&addr->zs_chan[ZS_CHAN_B]); cs->cs_zc = &addr->zs_chan[ZS_CHAN_B]; @@ -425,7 +433,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; @@ -467,15 +475,15 @@ 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; { register struct tty *tp; char *i, *o; - if ((tp = zs_ctty) == NULL) /* XXX */ + if ((tp = zs_ctty) == NULL) return (0); i = zs_consin == unit ? "input" : NULL; o = zs_consout == unit ? "output" : NULL; @@ -503,7 +511,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); @@ -588,13 +596,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; @@ -615,7 +623,7 @@ zsopen(dev, flags, mode, p) return (EBUSY); } error = 0; - for (;;) { + while (1) { register int rr0; /* loop, turning on the device, until carrier present */ @@ -661,11 +669,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 || @@ -703,16 +711,15 @@ 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)); - } int @@ -722,12 +729,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)); @@ -738,16 +745,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. @@ -765,56 +775,62 @@ zshard(intrarg) void *intrarg; { register struct zs_chanstate *a; + struct zs_softc *sc; #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; @@ -837,7 +853,7 @@ zshard(intrarg) #endif ienab_bis(IE_ZSSOFT); } - return (intflags & 2); + return (intflags & ZSHARD_WAS_SERVICED); } static int @@ -845,9 +861,11 @@ zsrint(cs, zc) register struct zs_chanstate *cs; register volatile struct zschan *zc; { - register int c = zc->zc_data; + register u_int c; + c = zc->zc_data; ZS_DELAY(); + if (cs->cs_conk) { register struct conk_state *conk = &zsconk_state; @@ -925,7 +943,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(); @@ -1148,10 +1166,10 @@ 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]; - register struct tty *tp = cs->cs_ttyp; + struct zs_softc *sc = zs_cd.cd_devs[unit >> 1]; + register struct tty *tp = sc->sc_cs[unit & 1].cs_ttyp; register int error, s; + register struct zs_chanstate *cs = &sc->sc_cs[unit & 1]; error = linesw[tp->t_line].l_ioctl(tp, cmd, data, flag, p); if (error >= 0) @@ -1245,10 +1263,16 @@ zsioctl(dev, cmd, data, flag, p) case TIOCCDTR: zs_modem(cs, 0); break; + case TIOCMGET: + /* XXX: fixme */ + *(int *)data = TIOCM_CAR | TIOCM_CTS | TIOCM_DTR | TIOCM_RTS; + return (0); case TIOCMSET: + /* XXX: fixme */ + zs_modem(cs, *(int *)data & (TIOCM_DTR|TIOCM_RTS)); + return (0); case TIOCMBIS: case TIOCMBIC: - case TIOCMGET: default: return (ENOTTY); } @@ -1265,9 +1289,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(); /* @@ -1326,9 +1350,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) { /* @@ -1354,8 +1378,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; /* @@ -1529,10 +1553,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; } /* @@ -1574,7 +1601,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); |