--- Net2/arch/i386/isa/com.c 2018/04/24 18:12:06 1.1.1.4 +++ Net2/arch/i386/isa/com.c 2018/04/24 18:20:08 1.1.1.5 @@ -30,19 +30,9 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)com.c 7.5 (Berkeley) 5/16/91 - * - * PATCHES MAGIC LEVEL PATCH THAT GOT US HERE - * -------------------- ----- ---------------------- - * CURRENT PATCH LEVEL: 4 00079 - * -------------------- ----- ---------------------- - * - * 23 Sep 92 Rodney W. Grimes Fix SILO overflow on 16550 UARTS - * 30 Aug 92 Poul-Henning Kamp Stabilize SLIP on lossy lines/UARTS - * 09 Aug 92 Christoph Robitschko Correct minor number on com ports - * 10 Feb 93 Jordan K. Hubbard Added select code + * from: @(#)com.c 7.5 (Berkeley) 5/16/91 + * com.c,v 1.11 1993/07/12 11:37:16 mycroft Exp */ -static char rcsid[] = "$Header: /var/lib/cvsd/net2/Net2/arch/i386/isa/com.c,v 1.1.1.4 2018/04/24 18:12:06 root Exp $"; #include "com.h" #if NCOM > 0 @@ -53,6 +43,7 @@ static char rcsid[] = "$Header: /var/lib #include "param.h" #include "systm.h" #include "ioctl.h" +#include "select.h" #include "tty.h" #include "proc.h" #include "user.h" @@ -87,7 +78,7 @@ int comconsinit; int comdefaultrate = TTYDEF_SPEED; int commajor; short com_addr[NCOM]; -struct tty com_tty[NCOM]; +struct tty *com_tty[NCOM]; struct speedtab comspeedtab[] = { 0, 0, @@ -198,7 +189,10 @@ comopen(dev_t dev, int flag, int mode, s unit = UNIT(dev); if (unit >= NCOM || (com_active & (1 << unit)) == 0) return (ENXIO); - tp = &com_tty[unit]; + if(!com_tty[unit]) { + tp = com_tty[unit] = ttymalloc(); + } else + tp = com_tty[unit]; tp->t_oproc = comstart; tp->t_param = comparam; tp->t_dev = dev; @@ -223,7 +217,7 @@ comopen(dev_t dev, int flag, int mode, s while ((flag&O_NONBLOCK) == 0 && (tp->t_cflag&CLOCAL) == 0 && (tp->t_state & TS_CARR_ON) == 0) { tp->t_state |= TS_WOPEN; - if (error = ttysleep(tp, (caddr_t)&tp->t_raw, TTIPRI | PCATCH, + if (error = ttysleep(tp, (caddr_t)&tp->t_rawq, TTIPRI | PCATCH, ttopen, 0)) break; } @@ -245,7 +239,7 @@ comclose(dev, flag, mode, p) unit = UNIT(dev); com = com_addr[unit]; - tp = &com_tty[unit]; + tp = com_tty[unit]; (*linesw[tp->t_line].l_close)(tp, flag); outb(com+com_cfcr, inb(com+com_cfcr) & ~CFCR_SBREAK); #ifdef KGDB @@ -257,6 +251,8 @@ comclose(dev, flag, mode, p) (tp->t_state&TS_ISOPEN) == 0) (void) commctl(dev, 0, DMSET); ttyclose(tp); + ttyfree(tp); + com_tty[unit] = (struct tty *)NULL; return(0); } @@ -264,7 +260,7 @@ comread(dev, uio, flag) dev_t dev; struct uio *uio; { - register struct tty *tp = &com_tty[UNIT(dev)]; + register struct tty *tp = com_tty[UNIT(dev)]; return ((*linesw[tp->t_line].l_read)(tp, uio, flag)); } @@ -274,7 +270,7 @@ comwrite(dev, uio, flag) struct uio *uio; { int unit = UNIT(dev); - register struct tty *tp = &com_tty[unit]; + register struct tty *tp = com_tty[unit]; /* * (XXX) We disallow virtual consoles if the physical console is @@ -303,7 +299,7 @@ comintr(unit) return (1); case IIR_RXTOUT: case IIR_RXRDY: - tp = &com_tty[unit]; + tp = com_tty[unit]; /* * Process received bytes. Inline for speed... */ @@ -334,7 +330,7 @@ comintr(unit) } break; case IIR_TXRDY: - tp = &com_tty[unit]; + tp = com_tty[unit]; tp->t_state &=~ (TS_BUSY|TS_FLUSH); if (tp->t_line) (*linesw[tp->t_line].l_start)(tp); @@ -364,7 +360,7 @@ comeint(unit, stat, com) register struct tty *tp; register int c; - tp = &com_tty[unit]; + tp = com_tty[unit]; c = inb(com+com_data); if ((tp->t_state & TS_ISOPEN) == 0) { #ifdef KGDB @@ -393,7 +389,7 @@ commint(unit, com) register struct tty *tp; register int stat; - tp = &com_tty[unit]; + tp = com_tty[unit]; stat = inb(com+com_msr); if ((stat & MSR_DDCD) && (comsoftCAR & (1 << unit)) == 0) { if (stat & MSR_DCD) @@ -421,7 +417,7 @@ comioctl(dev, cmd, data, flag) register com; register int error; - tp = &com_tty[unit]; + tp = com_tty[unit]; error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag); if (error >= 0) return (error); @@ -532,26 +528,22 @@ comstart(tp) s = spltty(); if (tp->t_state & (TS_TIMEOUT|TS_TTSTOP)) goto out; - if (RB_LEN(&tp->t_out) <= tp->t_lowat) { + if (tp->t_outq.c_cc <= tp->t_lowat) { if (tp->t_state&TS_ASLEEP) { tp->t_state &= ~TS_ASLEEP; - wakeup((caddr_t)&tp->t_out); - } - if (tp->t_wsel) { - selwakeup(tp->t_wsel, tp->t_state & TS_WCOLL); - tp->t_wsel = 0; - tp->t_state &= ~TS_WCOLL; + wakeup((caddr_t)&tp->t_outq); } + selwakeup(&tp->t_wsel); } - if (RB_LEN(&tp->t_out) == 0) + if (tp->t_outq.c_cc == 0) goto out; if (inb(com+com_lsr) & LSR_TXRDY) { - c = getc(&tp->t_out); + c = getc(&tp->t_outq); tp->t_state |= TS_BUSY; outb(com+com_data, c); if (com_hasfifo & (1 << unit)) - for (c = 1; c < 16 && RB_LEN(&tp->t_out); ++c) - outb(com+com_data, getc(&tp->t_out)); + for (c = 1; c < 16 && tp->t_outq.c_cc; ++c) + outb(com+com_data, getc(&tp->t_outq)); } out: splx(s); @@ -630,7 +622,6 @@ comcnprobe(cp) /* initialize required fields */ cp->cn_dev = makedev(commajor, unit); - cp->cn_tp = &com_tty[unit]; #ifdef COMCONSOLE cp->cn_pri = CN_REMOTE; /* Force a serial port console */ #else @@ -731,7 +722,7 @@ comselect(dev, rw, p) int rw; struct proc *p; { - register struct tty *tp = &com_tty[UNIT(dev)]; + register struct tty *tp = com_tty[UNIT(dev)]; int nread; int s = spltty(); struct proc *selp; @@ -743,19 +734,13 @@ comselect(dev, rw, p) if (nread > 0 || ((tp->t_cflag&CLOCAL) == 0 && (tp->t_state&TS_CARR_ON) == 0)) goto win; - if (tp->t_rsel && (selp = pfind(tp->t_rsel)) && selp->p_wchan == (caddr_t)&selwait) - tp->t_state |= TS_RCOLL; - else - tp->t_rsel = p->p_pid; + selrecord(p, &tp->t_rsel); break; case FWRITE: - if (RB_LEN(&tp->t_out) <= tp->t_lowat) + if (tp->t_outq.c_cc <= tp->t_lowat) goto win; - if (tp->t_wsel && (selp = pfind(tp->t_wsel)) && selp->p_wchan == (caddr_t)&selwait) - tp->t_state |= TS_WCOLL; - else - tp->t_wsel = p->p_pid; + selrecord(p, &tp->t_wsel); break; } splx(s);