aboutsummaryrefslogtreecommitdiff
path: root/sys/i386/isa/com.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/i386/isa/com.c')
-rw-r--r--sys/i386/isa/com.c101
1 files changed, 28 insertions, 73 deletions
diff --git a/sys/i386/isa/com.c b/sys/i386/isa/com.c
index dcaf878685be..25b4dee3238c 100644
--- a/sys/i386/isa/com.c
+++ b/sys/i386/isa/com.c
@@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* from: @(#)com.c 7.5 (Berkeley) 5/16/91
- * $Id: com.c,v 1.7 1993/12/19 00:50:32 wollman Exp $
+ * $Id: com.c,v 1.10 1994/05/30 03:14:13 ache Exp $
*/
#include "com.h"
@@ -86,7 +86,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,
@@ -199,12 +199,11 @@ comopen(int /*dev_t*/ dev, int flag, int mode, struct proc *p)
unit = UNIT(dev);
if (unit >= NCOM || (com_active & (1 << unit)) == 0)
return (ENXIO);
- tp = &com_tty[unit];
+ tp = com_tty[unit] = ttymalloc(com_tty[unit]);
tp->t_oproc = comstart;
tp->t_param = comparam;
tp->t_dev = dev;
if ((tp->t_state & TS_ISOPEN) == 0) {
- tp->t_state |= TS_WOPEN;
ttychars(tp);
if (tp->t_ispeed == 0) {
tp->t_iflag = TTYDEF_IFLAG;
@@ -223,9 +222,8 @@ comopen(int /*dev_t*/ dev, int flag, int mode, struct proc *p)
tp->t_state |= TS_CARR_ON;
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,
- ttopen, 0))
+ if (error = tsleep(tp, TSA_CARR_ON(tp), TTIPRI | PCATCH,
+ "comdcd", 0))
break;
}
(void) spl0();
@@ -247,7 +245,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
@@ -255,10 +253,16 @@ comclose(dev, flag, mode, p)
if (kgdb_dev != makedev(commajor, unit))
#endif
outb(com+com_ier, 0);
- if (tp->t_cflag&HUPCL || tp->t_state&TS_WOPEN ||
- (tp->t_state&TS_ISOPEN) == 0)
+ if (tp->t_cflag&HUPCL || (tp->t_state&TS_ISOPEN) == 0)
(void) commctl(dev, 0, DMSET);
ttyclose(tp);
+#ifdef broken /* session holds a ref to the tty; can't deallocate */
+ ttyfree(tp);
+ com_tty[unit] = (struct tty *)NULL;
+#endif
+ return (0);
+
+
return(0);
}
@@ -268,7 +272,7 @@ comread(dev, uio, flag)
struct uio *uio;
int flag;
{
- 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));
}
@@ -280,7 +284,7 @@ comwrite(dev, uio, flag)
int flag;
{
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
@@ -309,7 +313,7 @@ comintr(unit)
return;
case IIR_RXTOUT:
case IIR_RXRDY:
- tp = &com_tty[unit];
+ tp = com_tty[unit];
/*
* Process received bytes. Inline for speed...
*/
@@ -340,7 +344,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);
@@ -371,7 +375,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
@@ -401,7 +405,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)
@@ -432,7 +436,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);
@@ -545,26 +549,17 @@ 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_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;
- }
- }
- if (RB_LEN(&tp->t_out) == 0)
+ if (tp->t_state & (TS_SO_OCOMPLETE | TS_SO_OLOWAT) || tp->t_wsel)
+ ttwwakeup(tp);
+ if (RB_LEN(tp->t_out) == 0)
goto out;
if (inb(com+com_lsr) & LSR_TXRDY) {
- c = getc(&tp->t_out);
+ c = getc(tp->t_out);
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 && RB_LEN(tp->t_out); ++c)
+ outb(com+com_data, getc(tp->t_out));
}
out:
splx(s);
@@ -647,7 +642,7 @@ comcnprobe(cp)
/* initialize required fields */
cp->cn_dev = makedev(commajor, unit);
- cp->cn_tp = &com_tty[unit];
+ cp->cn_tp = com_tty[unit];
#ifdef COMCONSOLE
cp->cn_pri = CN_REMOTE; /* Force a serial port console */
#else
@@ -747,43 +742,3 @@ comcnputc(dev, c)
splx(s);
}
#endif
-
-int
-comselect(dev, rw, p)
- dev_t dev;
- int rw;
- struct proc *p;
-{
- register struct tty *tp = &com_tty[UNIT(dev)];
- int nread;
- int s = spltty();
- struct proc *selp;
-
- switch (rw) {
-
- case FREAD:
- nread = ttnread(tp);
- 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;
- break;
-
- case FWRITE:
- if (RB_LEN(&tp->t_out) <= 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;
- break;
- }
- splx(s);
- return (0);
- win:
- splx(s);
- return (1);
-}