From 2032b7529e2d0fdf27185283cf011ecf7cd21536 Mon Sep 17 00:00:00 2001 From: deraadt Date: Thu, 27 May 1993 09:35:10 +0000 Subject: [PATCH] Changes to hp300 code to support two things: 1. dynamic tty allocation 2. use ring buffers instead of clists Of course, I can't test it :-) --- sys/arch/hp300/dev/dca.c | 45 +++++++++++++++++++--------------- sys/arch/hp300/dev/dcm.c | 52 ++++++++++++++++++++++++---------------- sys/arch/hp300/dev/ite.c | 38 +++++++++++++++++------------ 3 files changed, 81 insertions(+), 54 deletions(-) diff --git a/sys/arch/hp300/dev/dca.c b/sys/arch/hp300/dev/dca.c index 7b586099c443..de99147d9f81 100644 --- a/sys/arch/hp300/dev/dca.c +++ b/sys/arch/hp300/dev/dca.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * from: @(#)dca.c 7.12 (Berkeley) 6/27/91 - * $Id: dca.c,v 1.3 1993/05/22 11:40:42 cgd Exp $ + * $Id: dca.c,v 1.4 1993/05/27 09:35:10 deraadt Exp $ */ #include "dca.h" @@ -43,11 +43,11 @@ #include "sys/param.h" #include "sys/systm.h" #include "sys/ioctl.h" -#include "sys/select.h" #include "sys/tty.h" #include "sys/proc.h" #include "sys/conf.h" #include "sys/file.h" +#include "sys/malloc.h" #include "sys/uio.h" #include "sys/kernel.h" #include "sys/syslog.h" @@ -76,7 +76,7 @@ int dcaconsinit; int dcadefaultrate = TTYDEF_SPEED; int dcamajor; struct dcadevice *dca_addr[NDCA]; -struct tty dca_tty[NDCA]; +struct tty *dca_tty[NDCA]; struct isr dcaisr[NDCA]; struct speedtab dcaspeedtab[] = { @@ -197,7 +197,12 @@ dcaopen(dev, flag, mode, p) unit = UNIT(dev); if (unit >= NDCA || (dca_active & (1 << unit)) == 0) return (ENXIO); - tp = &dca_tty[unit]; + if(!dca_tty[unit]) { + MALLOC(tp, struct tty *, sizeof(struct tty), M_TTYS, M_WAITOK); + bzero(tp, sizeof(struct tty)); + dca_tty[unit] = tp; + } else + tp = dca_tty[unit]; tp->t_oproc = dcastart; tp->t_param = dcaparam; tp->t_dev = dev; @@ -244,7 +249,7 @@ dcaclose(dev, flag, mode, p) unit = UNIT(dev); dca = dca_addr[unit]; - tp = &dca_tty[unit]; + tp = dca_tty[unit]; (*linesw[tp->t_line].l_close)(tp, flag); dca->dca_cfcr &= ~CFCR_SBREAK; #ifdef KGDB @@ -256,6 +261,8 @@ dcaclose(dev, flag, mode, p) (tp->t_state&TS_ISOPEN) == 0) (void) dcamctl(dev, 0, DMSET); ttyclose(tp); + FREE(tp, M_TTYS); + dca_tty[unit] = (struct tty *)NULL; return (0); } @@ -263,7 +270,7 @@ dcaread(dev, uio, flag) dev_t dev; struct uio *uio; { - register struct tty *tp = &dca_tty[UNIT(dev)]; + register struct tty *tp = dca_tty[UNIT(dev)]; return ((*linesw[tp->t_line].l_read)(tp, uio, flag)); } @@ -273,7 +280,7 @@ dcawrite(dev, uio, flag) struct uio *uio; { int unit = UNIT(dev); - register struct tty *tp = &dca_tty[unit]; + register struct tty *tp = dca_tty[unit]; /* * (XXX) We disallow virtual consoles if the physical console is @@ -307,7 +314,7 @@ dcaintr(unit) case IIR_RXTOUT: case IIR_RXRDY: /* do time-critical read in-line */ - tp = &dca_tty[unit]; + tp = dca_tty[unit]; /* * Process a received byte. Inline for speed... */ @@ -349,7 +356,7 @@ dcaintr(unit) } break; case IIR_TXRDY: - tp = &dca_tty[unit]; + tp = dca_tty[unit]; tp->t_state &=~ (TS_BUSY|TS_FLUSH); if (tp->t_line) (*linesw[tp->t_line].l_start)(tp); @@ -379,7 +386,7 @@ dcaeint(unit, stat, dca) register struct tty *tp; register int c; - tp = &dca_tty[unit]; + tp = dca_tty[unit]; c = dca->dca_data; if ((tp->t_state & TS_ISOPEN) == 0) { #ifdef KGDB @@ -406,7 +413,7 @@ dcamint(unit, dca) register struct tty *tp; register int stat; - tp = &dca_tty[unit]; + tp = dca_tty[unit]; stat = dca->dca_msr; #ifdef DEBUG dcamintcount[stat & 0xf]++; @@ -436,7 +443,7 @@ dcaioctl(dev, cmd, data, flag) register struct dcadevice *dca; register int error; - tp = &dca_tty[unit]; + tp = dca_tty[unit]; error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag); if (error >= 0) return (error); @@ -545,22 +552,22 @@ dcastart(tp) s = spltty(); if (tp->t_state & (TS_TIMEOUT|TS_TTSTOP)) goto out; - if (tp->t_outq.c_cc <= tp->t_lowat) { + if (RB_LEN(&tp->t_out) <= tp->t_lowat) { if (tp->t_state&TS_ASLEEP) { tp->t_state &= ~TS_ASLEEP; - wakeup((caddr_t)&tp->t_outq); + wakeup((caddr_t)&tp->t_out); } selwakeup(&tp->t_wsel); } - if (tp->t_outq.c_cc == 0) + if (RB_LEN(&tp->t_out) == 0) goto out; if (dca->dca_lsr & LSR_TXRDY) { - c = getc(&tp->t_outq); + c = getc(&tp->t_out); tp->t_state |= TS_BUSY; dca->dca_data = c; if (dca_hasfifo & (1 << unit)) { - for (c = 1; c < 16 && tp->t_outq.c_cc; ++c) - dca->dca_data = getc(&tp->t_outq); + for (c = 1; c < 16 && RB_LEN(&tp->t_out); ++c) + dca->dca_data = getc(&tp->t_out); #ifdef DEBUG if (c > 16) fifoout[0]++; @@ -650,7 +657,7 @@ dcacnprobe(cp) /* initialize required fields */ cp->cn_dev = makedev(dcamajor, unit); - cp->cn_tp = &dca_tty[unit]; + cp->cn_tp = dca_tty[unit]; switch (dca_addr[unit]->dca_irid) { case DCAID0: case DCAID1: diff --git a/sys/arch/hp300/dev/dcm.c b/sys/arch/hp300/dev/dcm.c index 9b1e64de375c..c38e33d96c53 100644 --- a/sys/arch/hp300/dev/dcm.c +++ b/sys/arch/hp300/dev/dcm.c @@ -38,7 +38,7 @@ * from: $Hdr: dcm.c 1.26 91/01/21$ * * from: @(#)dcm.c 7.14 (Berkeley) 6/27/91 - * $Id: dcm.c,v 1.3 1993/05/22 11:40:46 cgd Exp $ + * $Id: dcm.c,v 1.4 1993/05/27 09:35:15 deraadt Exp $ */ /* @@ -55,12 +55,12 @@ #include "sys/param.h" #include "sys/systm.h" #include "sys/ioctl.h" -#include "sys/select.h" #include "sys/tty.h" #include "sys/proc.h" #include "sys/conf.h" #include "sys/file.h" #include "sys/uio.h" +#include "sys/malloc.h" #include "sys/kernel.h" #include "sys/syslog.h" #include "sys/time.h" @@ -83,7 +83,7 @@ struct driver dcmdriver = { #define NDCMLINE (NDCM*4) -struct tty dcm_tty[NDCMLINE]; +struct tty *dcm_tty[NDCMLINE]; struct modemreg *dcm_modem[NDCMLINE]; char mcndlast[NDCMLINE]; /* XXX last modem status for line */ int ndcm = NDCMLINE; @@ -353,7 +353,12 @@ dcmopen(dev, flag, mode, p) brd = BOARD(unit); if (unit >= NDCMLINE || (dcm_active & (1 << brd)) == 0) return (ENXIO); - tp = &dcm_tty[unit]; + if(!dcm_tty[unit]) { + MALLOC(tp, struct tty *, sizeof(struct tty), M_TTYS, M_WAITOK); + bzero(tp, sizeof(struct tty)); + dcm_tty[unit] = tp; + } else + tp = dcm_tty[unit]; tp->t_oproc = dcmstart; tp->t_param = dcmparam; tp->t_dev = dev; @@ -413,7 +418,7 @@ dcmclose(dev, flag, mode, p) int unit; unit = UNIT(dev); - tp = &dcm_tty[unit]; + tp = dcm_tty[unit]; (*linesw[tp->t_line].l_close)(tp, flag); if (tp->t_cflag&HUPCL || tp->t_state&TS_WOPEN || (tp->t_state&TS_ISOPEN) == 0) @@ -424,6 +429,8 @@ dcmclose(dev, flag, mode, p) unit, tp->t_state, tp->t_flags); #endif ttyclose(tp); + FREE(tp, M_TTYS); + dcm_tty[unit] = (struct tty *)NULL; return (0); } @@ -433,7 +440,7 @@ dcmread(dev, uio, flag) { register struct tty *tp; - tp = &dcm_tty[UNIT(dev)]; + tp = dcm_tty[UNIT(dev)]; return ((*linesw[tp->t_line].l_read)(tp, uio, flag)); } @@ -444,7 +451,7 @@ dcmwrite(dev, uio, flag) int unit = UNIT(dev); register struct tty *tp; - tp = &dcm_tty[unit]; + tp = dcm_tty[unit]; /* * XXX we disallow virtual consoles if the physical console is * a serial port. This is in case there is a display attached that @@ -567,7 +574,7 @@ dcmpint(unit, code, dcm) int unit, code; struct dcmdevice *dcm; { - struct tty *tp = &dcm_tty[unit]; + struct tty *tp = dcm_tty[unit]; if (code & IT_SPEC) dcmreadbuf(unit, dcm, tp); @@ -583,7 +590,7 @@ dcmrint(brd, dcm) register struct tty *tp; unit = MKUNIT(brd, 0); - tp = &dcm_tty[unit]; + tp = dcm_tty[unit]; for (i = 0; i < 4; i++, tp++, unit++) dcmreadbuf(unit, dcm, tp); } @@ -697,7 +704,7 @@ dcmmint(unit, mcnd, dcm) printf("dcmmint: port %d mcnd %x mcndlast %x\n", unit, mcnd, mcndlast[unit]); #endif - tp = &dcm_tty[unit]; + tp = dcm_tty[unit]; delta = mcnd ^ mcndlast[unit]; mcndlast[unit] = mcnd; if ((delta & MI_CTS) && (tp->t_state & TS_ISOPEN) && @@ -738,7 +745,7 @@ dcmioctl(dev, cmd, data, flag) printf("dcmioctl: unit %d cmd %x data %x flag %x\n", unit, cmd, *data, flag); #endif - tp = &dcm_tty[unit]; + tp = dcm_tty[unit]; error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag); if (error >= 0) return (error); @@ -897,18 +904,18 @@ dcmstart(tp) if (dcmdebug & DDB_OUTPUT) printf("dcmstart(%d): state %x flags %x outcc %d\n", UNIT(tp->t_dev), tp->t_state, tp->t_flags, - tp->t_outq.c_cc); + RB_LEN(&tp->t_out)); #endif if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP)) goto out; - if (tp->t_outq.c_cc <= tp->t_lowat) { + if (RB_LEN(&tp->t_out) <= tp->t_lowat) { if (tp->t_state&TS_ASLEEP) { tp->t_state &= ~TS_ASLEEP; - wakeup((caddr_t)&tp->t_outq); + wakeup((caddr_t)&tp->t_out); } selwakeup(&tp->t_wsel); } - if (tp->t_outq.c_cc == 0) { + if (RB_LEN(&tp->t_out) == 0) { #ifdef IOSTATS dsp->xempty++; #endif @@ -925,7 +932,12 @@ dcmstart(tp) goto out; fifo = &dcm->dcm_tfifos[3-port][tail]; again: +#if 0 nch = q_to_b(&tp->t_outq, buf, (head - next) & TX_MASK); +#else + nch = rbunpack(&tp->t_out, buf, nch); +#endif + #ifdef IOSTATS tch += nch; #endif @@ -958,7 +970,7 @@ again: * Head changed while we were loading the buffer, * go back and load some more if we can. */ - if (tp->t_outq.c_cc && head != (pp->t_head & TX_MASK)) { + if (RB_LEN(&tp->t_out) && head != (pp->t_head & TX_MASK)) { #ifdef IOSTATS dsp->xrestarts++; #endif @@ -979,8 +991,8 @@ again: } #ifdef DEBUG if (dcmdebug & DDB_INTR) - printf("dcmstart(%d): head %x tail %x outqcc %d\n", - UNIT(tp->t_dev), head, tail, tp->t_outq.c_cc); + printf("dcmstart(%d): head %x tail %x outlen %d\n", + UNIT(tp->t_dev), head, tail, RB_LEN(&tp->t_out)); #endif out: #ifdef IOSTATS @@ -1101,7 +1113,7 @@ dcmsetischeme(brd, flags) * chars for any port on the board. */ if (!perchar) { - register struct tty *tp = &dcm_tty[MKUNIT(brd, 0)]; + register struct tty *tp = dcm_tty[MKUNIT(brd, 0)]; int c; for (i = 0; i < 4; i++, tp++) { @@ -1161,7 +1173,7 @@ dcmcnprobe(cp) /* initialize required fields */ cp->cn_dev = makedev(dcmmajor, unit); - cp->cn_tp = &dcm_tty[unit]; + cp->cn_tp = dcm_tty[unit]; switch (dcm_addr[BOARD(unit)]->dcm_rsid) { case DCMID: cp->cn_pri = CN_NORMAL; diff --git a/sys/arch/hp300/dev/ite.c b/sys/arch/hp300/dev/ite.c index 37ae2e67a7bd..18d6719ad0b7 100644 --- a/sys/arch/hp300/dev/ite.c +++ b/sys/arch/hp300/dev/ite.c @@ -38,7 +38,7 @@ * from: Utah $Hdr: ite.c 1.1 90/07/09$ * * from: @(#)ite.c 7.6 (Berkeley) 5/16/91 - * $Id: ite.c,v 1.3 1993/05/22 11:40:52 cgd Exp $ + * $Id: ite.c,v 1.4 1993/05/27 09:35:18 deraadt Exp $ */ /* @@ -58,7 +58,6 @@ #include "conf.h" #include "proc.h" #include "ioctl.h" -#include "select.h" #include "tty.h" #include "systm.h" #include "malloc.h" @@ -108,7 +107,7 @@ int iteburst = 64; int nite = NITE; struct tty *kbd_tty = NULL; -struct tty ite_tty[NITE]; +struct tty *ite_tty[NITE]; struct ite_softc ite_softc[NITE]; int itestart(); @@ -129,7 +128,7 @@ iteon(dev, flag) dev_t dev; { int unit = UNIT(dev); - struct tty *tp = &ite_tty[unit]; + struct tty *tp = ite_tty[unit]; struct ite_softc *ip = &ite_softc[unit]; if (unit < 0 || unit >= NITE || (ip->flags&ITE_ALIVE) == 0) @@ -216,11 +215,18 @@ iteopen(dev, mode, devtype, p) #endif { int unit = UNIT(dev); - register struct tty *tp = &ite_tty[unit]; + register struct tty *tp; register struct ite_softc *ip = &ite_softc[unit]; register int error; int first = 0; + if(!ite_tty[unit]) { + MALLOC(tp, struct tty *, sizeof(struct tty), M_TTYS, M_WAITOK); + bzero(tp, sizeof(struct tty)); + ite_tty[unit] = tp; + } else + tp = ite_tty[unit]; + if ((tp->t_state&(TS_ISOPEN|TS_XCLUDE)) == (TS_ISOPEN|TS_XCLUDE) && p->p_ucred->cr_uid != 0) return (EBUSY); @@ -258,11 +264,13 @@ iteclose(dev, flag, mode, p) int flag, mode; struct proc *p; { - register struct tty *tp = &ite_tty[UNIT(dev)]; + register struct tty *tp = ite_tty[UNIT(dev)]; (*linesw[tp->t_line].l_close)(tp, flag); ttyclose(tp); iteoff(dev, 0); + FREE(dev, M_TTYS); + ite_tty[UNIT(dev)] = (struct tty *)NULL; return(0); } @@ -270,7 +278,7 @@ iteread(dev, uio, flag) dev_t dev; struct uio *uio; { - register struct tty *tp = &ite_tty[UNIT(dev)]; + register struct tty *tp = ite_tty[UNIT(dev)]; return ((*linesw[tp->t_line].l_read)(tp, uio, flag)); } @@ -280,7 +288,7 @@ itewrite(dev, uio, flag) struct uio *uio; { int unit = UNIT(dev); - register struct tty *tp = &ite_tty[unit]; + register struct tty *tp = ite_tty[unit]; if ((ite_softc[unit].flags & ITE_ISCONS) && constty && (constty->t_state&(TS_CARR_ON|TS_ISOPEN))==(TS_CARR_ON|TS_ISOPEN)) @@ -292,7 +300,7 @@ iteioctl(dev, cmd, addr, flag) dev_t dev; caddr_t addr; { - register struct tty *tp = &ite_tty[UNIT(dev)]; + register struct tty *tp = ite_tty[UNIT(dev)]; int error; error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, addr, flag); @@ -316,11 +324,11 @@ itestart(tp) return; } tp->t_state |= TS_BUSY; - cc = tp->t_outq.c_cc; + cc = RB_LEN(&tp->t_out); if (cc <= tp->t_lowat) { if (tp->t_state & TS_ASLEEP) { tp->t_state &= ~TS_ASLEEP; - wakeup(&tp->t_outq); + wakeup(&tp->t_out); } selwakeup(&tp->t_wsel); } @@ -335,7 +343,7 @@ itestart(tp) while (--cc >= 0) { register int c; - c = getc(&tp->t_outq); + c = getc(&tp->t_out); /* * iteputchar() may take a long time and we don't want to * block all interrupts for long periods of time. Since @@ -661,7 +669,7 @@ ignore: break; case CTRL('G'): - if (&ite_tty[unit] == kbd_tty) + if (ite_tty[unit] == kbd_tty) kbdbell(); break; @@ -841,7 +849,7 @@ itecnprobe(cp) /* initialize required fields */ cp->cn_dev = makedev(maj, unit); - cp->cn_tp = &ite_tty[unit]; + cp->cn_tp = ite_tty[unit]; cp->cn_pri = pri; } @@ -854,7 +862,7 @@ itecninit(cp) ip->attrbuf = console_attributes; iteinit(cp->cn_dev); ip->flags |= (ITE_ACTIVE|ITE_ISCONS); - kbd_tty = &ite_tty[unit]; + kbd_tty = ite_tty[unit]; } /*ARGSUSED*/