Home | History | Annotate | Line # | Download | only in ic
com.c revision 1.56
      1  1.56      jtc /*	$NetBSD: com.c,v 1.56 1995/06/01 21:26:51 jtc Exp $	*/
      2  1.38      cgd 
      3   1.1      cgd /*-
      4  1.50  mycroft  * Copyright (c) 1993, 1994, 1995 Charles Hannum.  All rights reserved.
      5   1.1      cgd  * Copyright (c) 1991 The Regents of the University of California.
      6   1.1      cgd  * All rights reserved.
      7   1.1      cgd  *
      8   1.1      cgd  * Redistribution and use in source and binary forms, with or without
      9   1.1      cgd  * modification, are permitted provided that the following conditions
     10   1.1      cgd  * are met:
     11   1.1      cgd  * 1. Redistributions of source code must retain the above copyright
     12   1.1      cgd  *    notice, this list of conditions and the following disclaimer.
     13   1.1      cgd  * 2. Redistributions in binary form must reproduce the above copyright
     14   1.1      cgd  *    notice, this list of conditions and the following disclaimer in the
     15   1.1      cgd  *    documentation and/or other materials provided with the distribution.
     16   1.1      cgd  * 3. All advertising materials mentioning features or use of this software
     17   1.1      cgd  *    must display the following acknowledgement:
     18   1.1      cgd  *	This product includes software developed by the University of
     19   1.1      cgd  *	California, Berkeley and its contributors.
     20   1.1      cgd  * 4. Neither the name of the University nor the names of its contributors
     21   1.1      cgd  *    may be used to endorse or promote products derived from this software
     22   1.1      cgd  *    without specific prior written permission.
     23   1.1      cgd  *
     24   1.1      cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25   1.1      cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26   1.1      cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27   1.1      cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28   1.1      cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29   1.1      cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30   1.1      cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31   1.1      cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32   1.1      cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33   1.1      cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34   1.1      cgd  * SUCH DAMAGE.
     35   1.1      cgd  *
     36  1.38      cgd  *	@(#)com.c	7.5 (Berkeley) 5/16/91
     37   1.1      cgd  */
     38   1.1      cgd 
     39   1.1      cgd /*
     40   1.1      cgd  * COM driver, based on HP dca driver
     41   1.1      cgd  * uses National Semiconductor NS16450/NS16550AF UART
     42   1.1      cgd  */
     43  1.14  mycroft #include <sys/param.h>
     44  1.14  mycroft #include <sys/systm.h>
     45  1.14  mycroft #include <sys/ioctl.h>
     46  1.14  mycroft #include <sys/select.h>
     47  1.14  mycroft #include <sys/tty.h>
     48  1.14  mycroft #include <sys/proc.h>
     49  1.14  mycroft #include <sys/user.h>
     50  1.14  mycroft #include <sys/conf.h>
     51  1.14  mycroft #include <sys/file.h>
     52  1.14  mycroft #include <sys/uio.h>
     53  1.14  mycroft #include <sys/kernel.h>
     54  1.14  mycroft #include <sys/syslog.h>
     55  1.14  mycroft #include <sys/types.h>
     56  1.21  mycroft #include <sys/device.h>
     57  1.14  mycroft 
     58  1.21  mycroft #include <machine/cpu.h>
     59  1.14  mycroft #include <machine/pio.h>
     60  1.14  mycroft 
     61  1.49      cgd #include <dev/isa/isavar.h>
     62  1.47      cgd #include <dev/isa/comreg.h>
     63  1.46      cgd #include <dev/ic/ns16550.h>
     64  1.14  mycroft 
     65  1.21  mycroft struct com_softc {
     66  1.21  mycroft 	struct device sc_dev;
     67  1.49      cgd 	void *sc_ih;
     68  1.50  mycroft 	struct tty *sc_tty;
     69   1.1      cgd 
     70  1.33  mycroft 	int sc_overflows;
     71  1.41  mycroft 	int sc_iobase;
     72  1.22      cgd 	u_char sc_hwflags;
     73  1.29  mycroft #define	COM_HW_NOIEN	0x01
     74  1.22      cgd #define	COM_HW_FIFO	0x02
     75  1.22      cgd #define	COM_HW_CONSOLE	0x40
     76  1.22      cgd 	u_char sc_swflags;
     77  1.22      cgd #define	COM_SW_SOFTCAR	0x01
     78  1.22      cgd #define	COM_SW_CLOCAL	0x02
     79  1.22      cgd #define	COM_SW_CRTSCTS	0x04
     80  1.25      cgd #define	COM_SW_MDMBUF	0x08
     81  1.21  mycroft 	u_char sc_msr, sc_mcr;
     82  1.29  mycroft };
     83  1.21  mycroft 
     84  1.40  mycroft int comprobe __P((struct device *, void *, void *));
     85  1.40  mycroft void comattach __P((struct device *, struct device *, void *));
     86  1.21  mycroft int comopen __P((dev_t, int, int, struct proc *));
     87  1.21  mycroft int comclose __P((dev_t, int, int, struct proc *));
     88  1.33  mycroft void comdiag __P((void *));
     89  1.49      cgd int comintr __P((void *));
     90  1.21  mycroft int comparam __P((struct tty *, struct termios *));
     91  1.21  mycroft void comstart __P((struct tty *));
     92   1.1      cgd 
     93  1.29  mycroft struct cfdriver comcd = {
     94  1.29  mycroft 	NULL, "com", comprobe, comattach, DV_TTY, sizeof(struct com_softc)
     95   1.1      cgd };
     96   1.1      cgd 
     97  1.21  mycroft int	comdefaultrate = TTYDEF_SPEED;
     98   1.1      cgd #ifdef COMCONSOLE
     99   1.1      cgd int	comconsole = COMCONSOLE;
    100   1.1      cgd #else
    101   1.1      cgd int	comconsole = -1;
    102   1.1      cgd #endif
    103   1.1      cgd int	comconsinit;
    104   1.1      cgd int	commajor;
    105   1.1      cgd 
    106   1.1      cgd #ifdef KGDB
    107  1.14  mycroft #include <machine/remote-sl.h>
    108   1.1      cgd extern int kgdb_dev;
    109   1.1      cgd extern int kgdb_rate;
    110   1.1      cgd extern int kgdb_debug_init;
    111   1.1      cgd #endif
    112   1.1      cgd 
    113  1.21  mycroft #define	COMUNIT(x)	(minor(x))
    114   1.1      cgd 
    115  1.41  mycroft #define	bis(c, b)	do { const register int com_ad = (c); \
    116  1.21  mycroft 			     outb(com_ad, inb(com_ad) | (b)); } while(0)
    117  1.41  mycroft #define	bic(c, b)	do { const register int com_ad = (c); \
    118  1.21  mycroft 			     outb(com_ad, inb(com_ad) & ~(b)); } while(0)
    119  1.21  mycroft 
    120  1.21  mycroft int
    121  1.21  mycroft comspeed(speed)
    122  1.21  mycroft 	long speed;
    123   1.1      cgd {
    124  1.21  mycroft #define	divrnd(n, q)	(((n)*2/(q)+1)/2)	/* divide and round off */
    125  1.21  mycroft 
    126  1.21  mycroft 	int x, err;
    127  1.21  mycroft 
    128  1.21  mycroft 	if (speed == 0)
    129  1.21  mycroft 		return 0;
    130  1.21  mycroft 	if (speed < 0)
    131  1.21  mycroft 		return -1;
    132  1.21  mycroft 	x = divrnd((COM_FREQ / 16), speed);
    133  1.21  mycroft 	if (x <= 0)
    134  1.21  mycroft 		return -1;
    135  1.21  mycroft 	err = divrnd((COM_FREQ / 16) * 1000, speed * x) - 1000;
    136  1.21  mycroft 	if (err < 0)
    137  1.21  mycroft 		err = -err;
    138  1.21  mycroft 	if (err > COM_TOLERANCE)
    139  1.21  mycroft 		return -1;
    140  1.21  mycroft 	return x;
    141  1.21  mycroft 
    142  1.21  mycroft #undef	divrnd(n, q)
    143  1.21  mycroft }
    144  1.21  mycroft 
    145  1.21  mycroft int
    146  1.21  mycroft comprobe1(iobase)
    147  1.41  mycroft 	int iobase;
    148  1.21  mycroft {
    149  1.21  mycroft 
    150   1.1      cgd 	/* force access to id reg */
    151  1.21  mycroft 	outb(iobase + com_cfcr, 0);
    152  1.21  mycroft 	outb(iobase + com_iir, 0);
    153  1.21  mycroft 	if (inb(iobase + com_iir) & 0x38)
    154  1.21  mycroft 		return 0;
    155  1.21  mycroft 
    156  1.21  mycroft 	return 1;
    157   1.1      cgd }
    158   1.1      cgd 
    159  1.21  mycroft int
    160  1.40  mycroft comprobe(parent, match, aux)
    161  1.40  mycroft 	struct device *parent;
    162  1.40  mycroft 	void *match, *aux;
    163  1.29  mycroft {
    164  1.29  mycroft 	struct isa_attach_args *ia = aux;
    165  1.41  mycroft 	int iobase = ia->ia_iobase;
    166  1.21  mycroft 
    167  1.21  mycroft 	if (!comprobe1(iobase))
    168  1.21  mycroft 		return 0;
    169  1.21  mycroft 
    170  1.29  mycroft 	ia->ia_iosize = COM_NPORTS;
    171  1.29  mycroft 	ia->ia_msize = 0;
    172  1.29  mycroft 	return 1;
    173  1.21  mycroft }
    174   1.1      cgd 
    175  1.29  mycroft void
    176  1.29  mycroft comattach(parent, self, aux)
    177  1.29  mycroft 	struct device *parent, *self;
    178  1.29  mycroft 	void *aux;
    179  1.29  mycroft {
    180  1.29  mycroft 	struct com_softc *sc = (void *)self;
    181  1.29  mycroft 	struct isa_attach_args *ia = aux;
    182  1.29  mycroft 	struct cfdata *cf = sc->sc_dev.dv_cfdata;
    183  1.41  mycroft 	int iobase = ia->ia_iobase;
    184  1.21  mycroft 	struct tty *tp;
    185   1.1      cgd 
    186  1.21  mycroft 	sc->sc_iobase = iobase;
    187  1.29  mycroft 	sc->sc_hwflags = cf->cf_flags & COM_HW_NOIEN;
    188  1.22      cgd 	sc->sc_swflags = 0;
    189  1.21  mycroft 
    190  1.29  mycroft 	if (sc->sc_dev.dv_unit == comconsole)
    191  1.29  mycroft 		delay(1000);
    192  1.26      cgd 
    193   1.1      cgd 	/* look for a NS 16550AF UART with FIFOs */
    194  1.21  mycroft 	outb(iobase + com_fifo,
    195  1.21  mycroft 	    FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_14);
    196  1.20  mycroft 	delay(100);
    197  1.21  mycroft 	if ((inb(iobase + com_iir) & IIR_FIFO_MASK) == IIR_FIFO_MASK)
    198  1.21  mycroft 		if ((inb(iobase + com_fifo) & FIFO_TRIGGER_14) == FIFO_TRIGGER_14) {
    199  1.22      cgd 			sc->sc_hwflags |= COM_HW_FIFO;
    200  1.29  mycroft 			printf(": ns16550a, working fifo\n");
    201  1.21  mycroft 		} else
    202  1.56      jtc 			printf(": ns16550, broken fifo\n");
    203  1.21  mycroft 	else
    204  1.56      jtc 		printf(": ns8250 or ns16450, no fifo\n");
    205  1.21  mycroft 	outb(iobase + com_fifo, 0);
    206  1.21  mycroft 
    207  1.21  mycroft 	/* disable interrupts */
    208  1.21  mycroft 	outb(iobase + com_ier, 0);
    209  1.21  mycroft 	outb(iobase + com_mcr, 0);
    210   1.1      cgd 
    211  1.49      cgd 	if (ia->ia_irq != IRQUNK)
    212  1.49      cgd 		sc->sc_ih = isa_intr_establish(ia->ia_irq, ISA_IST_EDGE,
    213  1.49      cgd 		    ISA_IPL_TTY, comintr, sc);
    214  1.30  mycroft 
    215   1.1      cgd #ifdef KGDB
    216   1.2      cgd 	if (kgdb_dev == makedev(commajor, unit)) {
    217   1.1      cgd 		if (comconsole == unit)
    218   1.1      cgd 			kgdb_dev = -1;	/* can't debug over console port */
    219   1.1      cgd 		else {
    220   1.1      cgd 			(void) cominit(unit, kgdb_rate);
    221   1.1      cgd 			if (kgdb_debug_init) {
    222   1.1      cgd 				/*
    223   1.1      cgd 				 * Print prefix of device name,
    224   1.1      cgd 				 * let kgdb_connect print the rest.
    225   1.1      cgd 				 */
    226  1.21  mycroft 				printf("%s: ", sc->sc_dev.dv_xname);
    227   1.1      cgd 				kgdb_connect(1);
    228   1.1      cgd 			} else
    229  1.21  mycroft 				printf("%s: kgdb enabled\n",
    230  1.21  mycroft 				    sc->sc_dev.dv_xname);
    231   1.1      cgd 		}
    232   1.1      cgd 	}
    233   1.1      cgd #endif
    234  1.21  mycroft 
    235  1.29  mycroft 	if (sc->sc_dev.dv_unit == comconsole) {
    236  1.29  mycroft 		/*
    237  1.29  mycroft 		 * Need to reset baud rate, etc. of next print so reset
    238  1.29  mycroft 		 * comconsinit.  Also make sure console is always "hardwired".
    239  1.29  mycroft 		 */
    240   1.1      cgd 		comconsinit = 0;
    241  1.22      cgd 		sc->sc_hwflags |= COM_HW_CONSOLE;
    242  1.22      cgd 		sc->sc_swflags |= COM_SW_SOFTCAR;
    243   1.1      cgd 	}
    244   1.1      cgd }
    245   1.1      cgd 
    246  1.21  mycroft int
    247  1.21  mycroft comopen(dev, flag, mode, p)
    248  1.21  mycroft 	dev_t dev;
    249  1.21  mycroft 	int flag, mode;
    250  1.21  mycroft 	struct proc *p;
    251   1.1      cgd {
    252  1.21  mycroft 	int unit = COMUNIT(dev);
    253  1.21  mycroft 	struct com_softc *sc;
    254  1.41  mycroft 	int iobase;
    255  1.21  mycroft 	struct tty *tp;
    256  1.21  mycroft 	int s;
    257   1.1      cgd 	int error = 0;
    258   1.1      cgd 
    259  1.29  mycroft 	if (unit >= comcd.cd_ndevs)
    260  1.21  mycroft 		return ENXIO;
    261  1.29  mycroft 	sc = comcd.cd_devs[unit];
    262  1.29  mycroft 	if (!sc)
    263  1.21  mycroft 		return ENXIO;
    264  1.21  mycroft 
    265  1.21  mycroft 	s = spltty();
    266  1.21  mycroft 
    267  1.50  mycroft 	if (!sc->sc_tty)
    268  1.50  mycroft 		tp = sc->sc_tty = ttymalloc();
    269  1.21  mycroft 	else
    270  1.50  mycroft 		tp = sc->sc_tty;
    271  1.21  mycroft 
    272   1.1      cgd 	tp->t_oproc = comstart;
    273   1.1      cgd 	tp->t_param = comparam;
    274   1.1      cgd 	tp->t_dev = dev;
    275   1.1      cgd 	if ((tp->t_state & TS_ISOPEN) == 0) {
    276   1.1      cgd 		tp->t_state |= TS_WOPEN;
    277   1.1      cgd 		ttychars(tp);
    278  1.16       ws 		tp->t_iflag = TTYDEF_IFLAG;
    279  1.16       ws 		tp->t_oflag = TTYDEF_OFLAG;
    280  1.16       ws 		tp->t_cflag = TTYDEF_CFLAG;
    281  1.22      cgd 		if (sc->sc_swflags & COM_SW_CLOCAL)
    282  1.22      cgd 			tp->t_cflag |= CLOCAL;
    283  1.22      cgd 		if (sc->sc_swflags & COM_SW_CRTSCTS)
    284  1.22      cgd 			tp->t_cflag |= CRTSCTS;
    285  1.25      cgd 		if (sc->sc_swflags & COM_SW_MDMBUF)
    286  1.25      cgd 			tp->t_cflag |= MDMBUF;
    287  1.16       ws 		tp->t_lflag = TTYDEF_LFLAG;
    288  1.16       ws 		tp->t_ispeed = tp->t_ospeed = comdefaultrate;
    289   1.1      cgd 		comparam(tp, &tp->t_termios);
    290   1.1      cgd 		ttsetwater(tp);
    291  1.21  mycroft 
    292  1.21  mycroft 		iobase = sc->sc_iobase;
    293  1.36  mycroft 		/* Set the FIFO threshold based on the receive speed. */
    294  1.36  mycroft 		if (sc->sc_hwflags & COM_HW_FIFO)
    295  1.36  mycroft 			outb(iobase + com_fifo,
    296  1.36  mycroft 			    FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST |
    297  1.36  mycroft 			    (tp->t_ispeed <= 1200 ? FIFO_TRIGGER_1 : FIFO_TRIGGER_8));
    298  1.21  mycroft 		/* flush any pending I/O */
    299  1.21  mycroft 		(void) inb(iobase + com_lsr);
    300  1.21  mycroft 		(void) inb(iobase + com_data);
    301  1.21  mycroft 		/* you turn me on, baby */
    302  1.26      cgd 		sc->sc_mcr = MCR_DTR | MCR_RTS;
    303  1.29  mycroft 		if (!(sc->sc_hwflags & COM_HW_NOIEN))
    304  1.26      cgd 			sc->sc_mcr |= MCR_IENABLE;
    305  1.26      cgd 		outb(iobase + com_mcr, sc->sc_mcr);
    306  1.21  mycroft 		outb(iobase + com_ier,
    307  1.21  mycroft 		    IER_ERXRDY | IER_ETXRDY | IER_ERLS | IER_EMSC);
    308  1.21  mycroft 
    309  1.21  mycroft 		sc->sc_msr = inb(iobase + com_msr);
    310  1.25      cgd 		if (sc->sc_swflags & COM_SW_SOFTCAR || sc->sc_msr & MSR_DCD ||
    311  1.34  mycroft 		    tp->t_cflag & MDMBUF)
    312  1.21  mycroft 			tp->t_state |= TS_CARR_ON;
    313  1.21  mycroft 		else
    314  1.21  mycroft 			tp->t_state &= ~TS_CARR_ON;
    315  1.21  mycroft 	} else if (tp->t_state&TS_XCLUDE && p->p_ucred->cr_uid != 0) {
    316  1.21  mycroft 		splx(s);
    317  1.21  mycroft 		return EBUSY;
    318  1.21  mycroft 	}
    319  1.21  mycroft 
    320  1.21  mycroft 	/* wait for carrier if necessary */
    321  1.21  mycroft 	if ((flag & O_NONBLOCK) == 0)
    322  1.21  mycroft 		while ((tp->t_cflag & CLOCAL) == 0 &&
    323  1.21  mycroft 		    (tp->t_state & TS_CARR_ON) == 0) {
    324  1.21  mycroft 			tp->t_state |= TS_WOPEN;
    325  1.21  mycroft 			error = ttysleep(tp, (caddr_t)&tp->t_rawq,
    326  1.21  mycroft 			    TTIPRI | PCATCH, ttopen, 0);
    327  1.21  mycroft 			if (error) {
    328  1.21  mycroft 				/* XXX should turn off chip if we're the
    329  1.21  mycroft 				   only waiter */
    330  1.21  mycroft 				splx(s);
    331  1.21  mycroft 				return error;
    332  1.21  mycroft 			}
    333  1.21  mycroft 		}
    334  1.21  mycroft 	splx(s);
    335  1.21  mycroft 
    336  1.21  mycroft 	return (*linesw[tp->t_line].l_open)(dev, tp);
    337   1.1      cgd }
    338   1.1      cgd 
    339  1.21  mycroft int
    340   1.1      cgd comclose(dev, flag, mode, p)
    341   1.1      cgd 	dev_t dev;
    342   1.1      cgd 	int flag, mode;
    343   1.1      cgd 	struct proc *p;
    344   1.1      cgd {
    345  1.21  mycroft 	int unit = COMUNIT(dev);
    346  1.29  mycroft 	struct com_softc *sc = comcd.cd_devs[unit];
    347  1.50  mycroft 	struct tty *tp = sc->sc_tty;
    348  1.41  mycroft 	int iobase = sc->sc_iobase;
    349  1.21  mycroft 
    350   1.1      cgd 	(*linesw[tp->t_line].l_close)(tp, flag);
    351   1.1      cgd #ifdef KGDB
    352   1.1      cgd 	/* do not disable interrupts if debugging */
    353   1.2      cgd 	if (kgdb_dev != makedev(commajor, unit))
    354   1.1      cgd #endif
    355  1.21  mycroft 	{
    356  1.21  mycroft 		bic(iobase + com_cfcr, CFCR_SBREAK);
    357  1.21  mycroft 		outb(iobase + com_ier, 0);
    358  1.22      cgd 		if (tp->t_cflag & HUPCL &&
    359  1.22      cgd 		    (sc->sc_swflags & COM_SW_SOFTCAR) == 0)
    360  1.21  mycroft 			/* XXX perhaps only clear DTR */
    361  1.21  mycroft 			outb(iobase + com_mcr, 0);
    362  1.21  mycroft 	}
    363   1.1      cgd 	ttyclose(tp);
    364  1.21  mycroft #ifdef notyet /* XXXX */
    365  1.21  mycroft 	if (unit != comconsole) {
    366  1.21  mycroft 		ttyfree(tp);
    367  1.50  mycroft 		sc->sc_tty = 0;
    368  1.21  mycroft 	}
    369  1.13      cgd #endif
    370  1.21  mycroft 	return 0;
    371   1.1      cgd }
    372   1.1      cgd 
    373  1.21  mycroft int
    374   1.1      cgd comread(dev, uio, flag)
    375   1.1      cgd 	dev_t dev;
    376   1.1      cgd 	struct uio *uio;
    377  1.21  mycroft 	int flag;
    378   1.1      cgd {
    379  1.52  mycroft 	struct com_softc *sc = comcd.cd_devs[COMUNIT(dev)];
    380  1.52  mycroft 	struct tty *tp = sc->sc_tty;
    381   1.1      cgd 
    382   1.1      cgd 	return ((*linesw[tp->t_line].l_read)(tp, uio, flag));
    383   1.1      cgd }
    384   1.1      cgd 
    385  1.21  mycroft int
    386   1.1      cgd comwrite(dev, uio, flag)
    387   1.1      cgd 	dev_t dev;
    388   1.1      cgd 	struct uio *uio;
    389  1.21  mycroft 	int flag;
    390   1.1      cgd {
    391  1.52  mycroft 	struct com_softc *sc = comcd.cd_devs[COMUNIT(dev)];
    392  1.52  mycroft 	struct tty *tp = sc->sc_tty;
    393   1.1      cgd 
    394   1.1      cgd 	return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
    395   1.1      cgd }
    396  1.50  mycroft 
    397  1.50  mycroft struct tty *
    398  1.50  mycroft comtty(dev)
    399  1.50  mycroft 	dev_t dev;
    400  1.50  mycroft {
    401  1.52  mycroft 	struct com_softc *sc = comcd.cd_devs[COMUNIT(dev)];
    402  1.52  mycroft 	struct tty *tp = sc->sc_tty;
    403  1.50  mycroft 
    404  1.52  mycroft 	return (tp);
    405  1.50  mycroft }
    406   1.1      cgd 
    407  1.21  mycroft static u_char
    408  1.21  mycroft tiocm_xxx2mcr(data)
    409  1.21  mycroft 	int data;
    410  1.21  mycroft {
    411  1.21  mycroft 	u_char m = 0;
    412  1.21  mycroft 
    413  1.21  mycroft 	if (data & TIOCM_DTR)
    414  1.21  mycroft 		m |= MCR_DTR;
    415  1.21  mycroft 	if (data & TIOCM_RTS)
    416  1.21  mycroft 		m |= MCR_RTS;
    417  1.21  mycroft 	return m;
    418   1.1      cgd }
    419   1.1      cgd 
    420  1.21  mycroft int
    421  1.19  mycroft comioctl(dev, cmd, data, flag, p)
    422   1.1      cgd 	dev_t dev;
    423  1.39      cgd 	u_long cmd;
    424   1.1      cgd 	caddr_t data;
    425  1.19  mycroft 	int flag;
    426  1.19  mycroft 	struct proc *p;
    427   1.1      cgd {
    428  1.21  mycroft 	int unit = COMUNIT(dev);
    429  1.29  mycroft 	struct com_softc *sc = comcd.cd_devs[unit];
    430  1.50  mycroft 	struct tty *tp = sc->sc_tty;
    431  1.41  mycroft 	int iobase = sc->sc_iobase;
    432  1.21  mycroft 	int error;
    433  1.21  mycroft 
    434  1.19  mycroft 	error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
    435   1.1      cgd 	if (error >= 0)
    436  1.21  mycroft 		return error;
    437  1.19  mycroft 	error = ttioctl(tp, cmd, data, flag, p);
    438   1.1      cgd 	if (error >= 0)
    439  1.21  mycroft 		return error;
    440   1.1      cgd 
    441   1.1      cgd 	switch (cmd) {
    442   1.1      cgd 	case TIOCSBRK:
    443  1.21  mycroft 		bis(iobase + com_cfcr, CFCR_SBREAK);
    444   1.1      cgd 		break;
    445   1.1      cgd 	case TIOCCBRK:
    446  1.21  mycroft 		bic(iobase + com_cfcr, CFCR_SBREAK);
    447   1.1      cgd 		break;
    448   1.1      cgd 	case TIOCSDTR:
    449  1.21  mycroft 		outb(iobase + com_mcr, sc->sc_mcr |= (MCR_DTR | MCR_RTS));
    450   1.1      cgd 		break;
    451   1.1      cgd 	case TIOCCDTR:
    452  1.21  mycroft 		outb(iobase + com_mcr, sc->sc_mcr &= ~(MCR_DTR | MCR_RTS));
    453   1.1      cgd 		break;
    454   1.1      cgd 	case TIOCMSET:
    455  1.21  mycroft 		sc->sc_mcr &= ~(MCR_DTR | MCR_RTS);
    456   1.1      cgd 	case TIOCMBIS:
    457  1.21  mycroft 		outb(iobase + com_mcr,
    458  1.21  mycroft 		    sc->sc_mcr |= tiocm_xxx2mcr(*(int *)data));
    459   1.1      cgd 		break;
    460   1.1      cgd 	case TIOCMBIC:
    461  1.21  mycroft 		outb(iobase + com_mcr,
    462  1.21  mycroft 		    sc->sc_mcr &= ~tiocm_xxx2mcr(*(int *)data));
    463   1.1      cgd 		break;
    464  1.21  mycroft 	case TIOCMGET: {
    465  1.21  mycroft 		u_char m;
    466  1.21  mycroft 		int bits = 0;
    467  1.21  mycroft 
    468  1.21  mycroft 		m = sc->sc_mcr;
    469  1.21  mycroft 		if (m & MCR_DTR)
    470  1.21  mycroft 			bits |= TIOCM_DTR;
    471  1.21  mycroft 		if (m & MCR_RTS)
    472  1.21  mycroft 			bits |= TIOCM_RTS;
    473  1.21  mycroft 		m = sc->sc_msr;
    474  1.21  mycroft 		if (m & MSR_DCD)
    475  1.21  mycroft 			bits |= TIOCM_CD;
    476  1.21  mycroft 		if (m & MSR_CTS)
    477  1.21  mycroft 			bits |= TIOCM_CTS;
    478  1.21  mycroft 		if (m & MSR_DSR)
    479  1.21  mycroft 			bits |= TIOCM_DSR;
    480  1.21  mycroft 		if (m & (MSR_RI | MSR_TERI))
    481  1.21  mycroft 			bits |= TIOCM_RI;
    482  1.21  mycroft 		if (inb(iobase + com_ier))
    483  1.21  mycroft 			bits |= TIOCM_LE;
    484  1.21  mycroft 		*(int *)data = bits;
    485   1.1      cgd 		break;
    486  1.21  mycroft 	}
    487  1.22      cgd 	case TIOCGFLAGS: {
    488  1.22      cgd 		int bits = 0;
    489  1.22      cgd 
    490  1.22      cgd 		if (sc->sc_swflags & COM_SW_SOFTCAR)
    491  1.22      cgd 			bits |= TIOCFLAG_SOFTCAR;
    492  1.22      cgd 		if (sc->sc_swflags & COM_SW_CLOCAL)
    493  1.22      cgd 			bits |= TIOCFLAG_CLOCAL;
    494  1.22      cgd 		if (sc->sc_swflags & COM_SW_CRTSCTS)
    495  1.22      cgd 			bits |= TIOCFLAG_CRTSCTS;
    496  1.25      cgd 		if (sc->sc_swflags & COM_SW_MDMBUF)
    497  1.25      cgd 			bits |= TIOCFLAG_MDMBUF;
    498  1.22      cgd 
    499  1.22      cgd 		*(int *)data = bits;
    500  1.22      cgd 		break;
    501  1.22      cgd 	}
    502  1.22      cgd 	case TIOCSFLAGS: {
    503  1.22      cgd 		int userbits, driverbits = 0;
    504  1.22      cgd 
    505  1.23      cgd 		error = suser(p->p_ucred, &p->p_acflag);
    506  1.23      cgd 		if (error != 0)
    507  1.23      cgd 			return(EPERM);
    508  1.22      cgd 
    509  1.22      cgd 		userbits = *(int *)data;
    510  1.23      cgd 		if ((userbits & TIOCFLAG_SOFTCAR) ||
    511  1.22      cgd 		    (sc->sc_hwflags & COM_HW_CONSOLE))
    512  1.23      cgd 			driverbits |= COM_SW_SOFTCAR;
    513  1.22      cgd 		if (userbits & TIOCFLAG_CLOCAL)
    514  1.22      cgd 			driverbits |= COM_SW_CLOCAL;
    515  1.22      cgd 		if (userbits & TIOCFLAG_CRTSCTS)
    516  1.22      cgd 			driverbits |= COM_SW_CRTSCTS;
    517  1.31      cgd 		if (userbits & TIOCFLAG_MDMBUF)
    518  1.31      cgd 			driverbits |= COM_SW_MDMBUF;
    519  1.22      cgd 
    520  1.23      cgd 		sc->sc_swflags = driverbits;
    521  1.22      cgd 		break;
    522  1.22      cgd 	}
    523   1.1      cgd 	default:
    524  1.21  mycroft 		return ENOTTY;
    525   1.1      cgd 	}
    526  1.21  mycroft 
    527  1.21  mycroft 	return 0;
    528   1.1      cgd }
    529   1.1      cgd 
    530  1.21  mycroft int
    531   1.1      cgd comparam(tp, t)
    532  1.21  mycroft 	struct tty *tp;
    533  1.21  mycroft 	struct termios *t;
    534   1.1      cgd {
    535  1.29  mycroft 	struct com_softc *sc = comcd.cd_devs[COMUNIT(tp->t_dev)];
    536  1.41  mycroft 	int iobase = sc->sc_iobase;
    537  1.21  mycroft 	int ospeed = comspeed(t->c_ospeed);
    538  1.21  mycroft 	u_char cfcr;
    539  1.21  mycroft 	int s;
    540  1.21  mycroft 
    541   1.1      cgd 	/* check requested parameters */
    542  1.21  mycroft 	if (ospeed < 0 || (t->c_ispeed && t->c_ispeed != t->c_ospeed))
    543  1.21  mycroft 		return EINVAL;
    544  1.21  mycroft 
    545  1.21  mycroft 	switch (t->c_cflag & CSIZE) {
    546   1.1      cgd 	case CS5:
    547  1.21  mycroft 		cfcr = CFCR_5BITS;
    548  1.21  mycroft 		break;
    549   1.1      cgd 	case CS6:
    550  1.21  mycroft 		cfcr = CFCR_6BITS;
    551  1.21  mycroft 		break;
    552   1.1      cgd 	case CS7:
    553  1.21  mycroft 		cfcr = CFCR_7BITS;
    554  1.21  mycroft 		break;
    555   1.1      cgd 	case CS8:
    556  1.21  mycroft 		cfcr = CFCR_8BITS;
    557  1.21  mycroft 		break;
    558   1.1      cgd 	}
    559  1.21  mycroft 	if (t->c_cflag & PARENB) {
    560   1.1      cgd 		cfcr |= CFCR_PENAB;
    561  1.21  mycroft 		if ((t->c_cflag & PARODD) == 0)
    562   1.1      cgd 			cfcr |= CFCR_PEVEN;
    563   1.1      cgd 	}
    564  1.21  mycroft 	if (t->c_cflag & CSTOPB)
    565   1.1      cgd 		cfcr |= CFCR_STOPB;
    566   1.1      cgd 
    567  1.21  mycroft 	s = spltty();
    568  1.35  mycroft 
    569  1.21  mycroft 	if (ospeed == 0)
    570  1.21  mycroft 		outb(iobase + com_mcr, sc->sc_mcr &= ~MCR_DTR);
    571  1.36  mycroft 
    572  1.36  mycroft 	/*
    573  1.36  mycroft 	 * Set the FIFO threshold based on the receive speed, if we are
    574  1.36  mycroft 	 * changing it.
    575  1.36  mycroft 	 *
    576  1.36  mycroft 	 * XXX
    577  1.36  mycroft 	 * It would be better if we waited for the FIFO to empty, so we don't
    578  1.36  mycroft 	 * lose any in-transit characters.
    579  1.36  mycroft 	 */
    580  1.36  mycroft 	if (tp->t_ispeed != t->c_ispeed) {
    581  1.36  mycroft 		if (sc->sc_hwflags & COM_HW_FIFO)
    582  1.36  mycroft 			outb(iobase + com_fifo,
    583  1.36  mycroft 			    FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST |
    584  1.36  mycroft 			    (t->c_ispeed <= 1200 ? FIFO_TRIGGER_1 : FIFO_TRIGGER_8));
    585  1.36  mycroft 	}
    586  1.21  mycroft 
    587  1.21  mycroft 	outb(iobase + com_cfcr, cfcr | CFCR_DLAB);
    588  1.21  mycroft 	outb(iobase + com_dlbl, ospeed);
    589  1.21  mycroft 	outb(iobase + com_dlbh, ospeed>>8);
    590  1.21  mycroft 	outb(iobase + com_cfcr, cfcr);
    591  1.36  mycroft 
    592  1.36  mycroft 	if (ospeed != 0)
    593  1.36  mycroft 		outb(iobase + com_mcr, sc->sc_mcr |= MCR_DTR);
    594  1.21  mycroft 
    595  1.22      cgd 	/* When not using CRTSCTS, RTS follows DTR. */
    596  1.22      cgd 	if ((t->c_cflag & CRTSCTS) == 0) {
    597  1.21  mycroft 		if (sc->sc_mcr & MCR_DTR) {
    598  1.21  mycroft 			if ((sc->sc_mcr & MCR_RTS) == 0)
    599  1.21  mycroft 				outb(iobase + com_mcr, sc->sc_mcr |= MCR_RTS);
    600  1.21  mycroft 		} else {
    601  1.21  mycroft 			if (sc->sc_mcr & MCR_RTS)
    602  1.21  mycroft 				outb(iobase + com_mcr, sc->sc_mcr &= ~MCR_RTS);
    603  1.21  mycroft 		}
    604  1.21  mycroft 	}
    605  1.21  mycroft 
    606  1.25      cgd 	/*
    607  1.25      cgd 	 * If CTS is off and CRTSCTS is changed, we must toggle TS_TTSTOP.
    608  1.25      cgd 	 * XXX should be done at tty layer.
    609  1.25      cgd 	 */
    610  1.21  mycroft 	if ((sc->sc_msr & MSR_CTS) == 0 &&
    611  1.22      cgd 	    (tp->t_cflag & CRTSCTS) != (t->c_cflag & CRTSCTS)) {
    612  1.22      cgd 		if ((t->c_cflag & CRTSCTS) == 0) {
    613  1.25      cgd 			tp->t_state &= ~TS_TTSTOP;
    614  1.32  mycroft 			(*linesw[tp->t_line].l_start)(tp);
    615  1.25      cgd 		} else
    616  1.25      cgd 			tp->t_state |= TS_TTSTOP;
    617  1.25      cgd 	}
    618  1.25      cgd 
    619  1.25      cgd 	/*
    620  1.25      cgd 	 * If DCD is off and MDMBUF is changed, we must toggle TS_TTSTOP.
    621  1.25      cgd 	 * XXX should be done at tty layer.
    622  1.25      cgd 	 */
    623  1.25      cgd 	if ((sc->sc_swflags & COM_SW_SOFTCAR) == 0 &&
    624  1.25      cgd 	    (sc->sc_msr & MSR_DCD) == 0 &&
    625  1.25      cgd 	    (tp->t_cflag & MDMBUF) != (t->c_cflag & MDMBUF)) {
    626  1.25      cgd 		if ((t->c_cflag & MDMBUF) == 0) {
    627  1.21  mycroft 			tp->t_state &= ~TS_TTSTOP;
    628  1.32  mycroft 			(*linesw[tp->t_line].l_start)(tp);
    629  1.21  mycroft 		} else
    630  1.21  mycroft 			tp->t_state |= TS_TTSTOP;
    631  1.21  mycroft 	}
    632   1.1      cgd 
    633  1.32  mycroft 	/* and copy to tty */
    634  1.32  mycroft 	tp->t_ispeed = t->c_ispeed;
    635  1.32  mycroft 	tp->t_ospeed = t->c_ospeed;
    636  1.32  mycroft 	tp->t_cflag = t->c_cflag;
    637  1.32  mycroft 
    638  1.21  mycroft 	splx(s);
    639  1.21  mycroft 	return 0;
    640   1.1      cgd }
    641  1.21  mycroft 
    642  1.12  deraadt void
    643   1.1      cgd comstart(tp)
    644  1.21  mycroft 	struct tty *tp;
    645   1.1      cgd {
    646  1.29  mycroft 	struct com_softc *sc = comcd.cd_devs[COMUNIT(tp->t_dev)];
    647  1.41  mycroft 	int iobase = sc->sc_iobase;
    648  1.21  mycroft 	int s;
    649  1.21  mycroft 
    650   1.1      cgd 	s = spltty();
    651  1.21  mycroft 	if (tp->t_state & (TS_TTSTOP | TS_BUSY))
    652  1.21  mycroft 		goto out;
    653  1.21  mycroft #if 0 /* XXXX I think this is handled adequately by commint() and comparam(). */
    654  1.22      cgd 	if (tp->t_cflag & CRTSCTS && (sc->sc_mcr & MSR_CTS) == 0)
    655   1.1      cgd 		goto out;
    656  1.21  mycroft #endif
    657  1.11  mycroft 	if (tp->t_outq.c_cc <= tp->t_lowat) {
    658  1.21  mycroft 		if (tp->t_state & TS_ASLEEP) {
    659   1.1      cgd 			tp->t_state &= ~TS_ASLEEP;
    660  1.11  mycroft 			wakeup((caddr_t)&tp->t_outq);
    661   1.1      cgd 		}
    662   1.7      cgd 		selwakeup(&tp->t_wsel);
    663   1.1      cgd 	}
    664  1.11  mycroft 	if (tp->t_outq.c_cc == 0)
    665   1.1      cgd 		goto out;
    666  1.21  mycroft 	tp->t_state |= TS_BUSY;
    667  1.22      cgd 	if (sc->sc_hwflags & COM_HW_FIFO) {
    668  1.21  mycroft 		u_char buffer[16], *cp = buffer;
    669  1.21  mycroft 		int n = q_to_b(&tp->t_outq, cp, sizeof buffer);
    670  1.21  mycroft 		do {
    671  1.21  mycroft 			outb(iobase + com_data, *cp++);
    672  1.21  mycroft 		} while (--n);
    673  1.21  mycroft 	} else
    674  1.21  mycroft 		outb(iobase + com_data, getc(&tp->t_outq));
    675   1.1      cgd out:
    676   1.1      cgd 	splx(s);
    677   1.1      cgd }
    678  1.21  mycroft 
    679   1.1      cgd /*
    680   1.1      cgd  * Stop output on a line.
    681   1.1      cgd  */
    682  1.21  mycroft void
    683   1.1      cgd comstop(tp, flag)
    684  1.21  mycroft 	struct tty *tp;
    685   1.1      cgd {
    686  1.21  mycroft 	int s;
    687   1.1      cgd 
    688   1.1      cgd 	s = spltty();
    689  1.21  mycroft 	if (tp->t_state & TS_BUSY)
    690  1.21  mycroft 		if ((tp->t_state & TS_TTSTOP) == 0)
    691   1.1      cgd 			tp->t_state |= TS_FLUSH;
    692   1.1      cgd 	splx(s);
    693   1.1      cgd }
    694   1.1      cgd 
    695  1.21  mycroft static inline void
    696  1.21  mycroft comeint(sc, stat)
    697  1.21  mycroft 	struct com_softc *sc;
    698  1.21  mycroft 	int stat;
    699  1.21  mycroft {
    700  1.50  mycroft 	struct tty *tp = sc->sc_tty;
    701  1.41  mycroft 	int iobase = sc->sc_iobase;
    702  1.21  mycroft 	int c;
    703   1.1      cgd 
    704  1.21  mycroft 	c = inb(iobase + com_data);
    705  1.54      cgd #ifdef DDB
    706  1.54      cgd 	if ((stat & LSR_BI) && (sc->sc_dev.dv_unit == comconsole)) {
    707  1.54      cgd 		Debugger();
    708  1.54      cgd 		return;
    709  1.54      cgd 	}
    710  1.54      cgd #endif
    711  1.21  mycroft 	if ((tp->t_state & TS_ISOPEN) == 0) {
    712  1.21  mycroft #ifdef KGDB
    713  1.21  mycroft 		/* we don't care about parity errors */
    714  1.21  mycroft 		if (((stat & (LSR_BI | LSR_FE | LSR_PE)) == LSR_PE) &&
    715  1.21  mycroft 		    kgdb_dev == makedev(commajor, unit) && c == FRAME_END)
    716  1.21  mycroft 			kgdb_connect(0); /* trap into kgdb */
    717  1.21  mycroft #endif
    718  1.21  mycroft 		return;
    719  1.21  mycroft 	}
    720  1.21  mycroft 	if (stat & (LSR_BI | LSR_FE))
    721  1.21  mycroft 		c |= TTY_FE;
    722  1.21  mycroft 	else if (stat & LSR_PE)
    723  1.21  mycroft 		c |= TTY_PE;
    724  1.33  mycroft 	if (stat & LSR_OE) {
    725  1.33  mycroft 		if (sc->sc_overflows++ == 0)
    726  1.33  mycroft 			timeout(comdiag, sc, 60 * hz);
    727  1.33  mycroft 	}
    728  1.21  mycroft 	/* XXXX put in FIFO and process later */
    729  1.21  mycroft 	(*linesw[tp->t_line].l_rint)(c, tp);
    730  1.21  mycroft }
    731  1.21  mycroft 
    732  1.33  mycroft void
    733  1.33  mycroft comdiag(arg)
    734  1.33  mycroft 	void *arg;
    735  1.33  mycroft {
    736  1.33  mycroft 	struct com_softc *sc = arg;
    737  1.33  mycroft 	int overflows;
    738  1.33  mycroft 	int s;
    739  1.33  mycroft 
    740  1.33  mycroft 	s = spltty();
    741  1.33  mycroft 	overflows = sc->sc_overflows;
    742  1.33  mycroft 	sc->sc_overflows = 0;
    743  1.33  mycroft 	splx(s);
    744  1.33  mycroft 
    745  1.33  mycroft 	if (overflows)
    746  1.33  mycroft 		log(LOG_WARNING, "%s: %d silo overflow%s\n",
    747  1.33  mycroft 		    sc->sc_dev.dv_xname, overflows, overflows == 1 ? "" : "s");
    748  1.21  mycroft }
    749   1.1      cgd 
    750  1.21  mycroft int
    751  1.49      cgd comintr(arg)
    752  1.49      cgd 	void *arg;
    753  1.21  mycroft {
    754  1.49      cgd 	struct com_softc *sc = arg;
    755  1.41  mycroft 	int iobase = sc->sc_iobase;
    756  1.21  mycroft 	struct tty *tp;
    757  1.55  mycroft 	u_char lsr, data, msr, delta;
    758  1.55  mycroft 
    759  1.55  mycroft 	if (inb(iobase + com_iir) & IIR_NOPEND)
    760  1.55  mycroft 		return (0);
    761  1.21  mycroft 
    762  1.55  mycroft 	tp = sc->sc_tty;
    763  1.21  mycroft 
    764  1.21  mycroft 	for (;;) {
    765  1.55  mycroft 		lsr = inb(iobase + com_lsr);
    766  1.55  mycroft 
    767  1.55  mycroft 		if (lsr & LSR_RCV_MASK) {
    768  1.21  mycroft 			/* XXXX put in FIFO and process later */
    769  1.55  mycroft 			do {
    770  1.55  mycroft 				if (lsr & (LSR_BI|LSR_FE|LSR_PE|LSR_OE))
    771  1.55  mycroft 					comeint(sc, lsr);
    772  1.55  mycroft 				else {
    773  1.55  mycroft 					data = inb(iobase + com_data);
    774  1.21  mycroft 					if (tp->t_state & TS_ISOPEN)
    775  1.55  mycroft 						(*linesw[tp->t_line].l_rint)(data, tp);
    776  1.21  mycroft #ifdef KGDB
    777  1.21  mycroft 					else {
    778  1.21  mycroft 						if (kgdb_dev == makedev(commajor, unit) &&
    779  1.55  mycroft 						    data == FRAME_END)
    780  1.21  mycroft 							kgdb_connect(0);
    781  1.21  mycroft 					}
    782  1.21  mycroft #endif
    783  1.55  mycroft 				}
    784  1.55  mycroft 				lsr = inb(iobase + com_lsr);
    785  1.55  mycroft 			} while (lsr & LSR_RCV_MASK);
    786  1.55  mycroft 		}
    787  1.55  mycroft 
    788  1.55  mycroft 		if (lsr & LSR_TXRDY && (tp->t_state & TS_BUSY) != 0) {
    789  1.21  mycroft 			tp->t_state &= ~TS_BUSY;
    790  1.21  mycroft 			if (tp->t_state & TS_FLUSH)
    791  1.21  mycroft 				tp->t_state &= ~TS_FLUSH;
    792  1.21  mycroft 			else
    793  1.21  mycroft 				if (tp->t_line)
    794  1.21  mycroft 					(*linesw[tp->t_line].l_start)(tp);
    795  1.21  mycroft 				else
    796  1.21  mycroft 					comstart(tp);
    797  1.21  mycroft 		}
    798  1.55  mycroft 
    799  1.55  mycroft 		msr = inb(iobase + com_msr);
    800  1.55  mycroft 
    801  1.55  mycroft 		if (msr != sc->sc_msr) {
    802  1.55  mycroft 			delta = msr ^ sc->sc_msr;
    803  1.55  mycroft 			sc->sc_msr = msr;
    804  1.55  mycroft 			if (delta & MSR_DCD && (sc->sc_swflags & COM_SW_SOFTCAR) == 0) {
    805  1.55  mycroft 				if (msr & MSR_DCD)
    806  1.55  mycroft 					(void)(*linesw[tp->t_line].l_modem)(tp, 1);
    807  1.55  mycroft 				else if ((*linesw[tp->t_line].l_modem)(tp, 0) == 0)
    808  1.55  mycroft 					outb(iobase + com_mcr,
    809  1.55  mycroft 					     sc->sc_mcr &= ~(MCR_DTR | MCR_RTS));
    810  1.55  mycroft 			}
    811  1.55  mycroft 			if (delta & MSR_CTS && (tp->t_cflag & CRTSCTS) != 0) {
    812  1.55  mycroft 				/* the line is up and we want to do rts/cts flow control */
    813  1.55  mycroft 				if (msr & MSR_CTS) {
    814  1.55  mycroft 					tp->t_state &= ~TS_TTSTOP;
    815  1.55  mycroft 					(*linesw[tp->t_line].l_start)(tp);
    816  1.55  mycroft 				} else
    817  1.55  mycroft 					tp->t_state |= TS_TTSTOP;
    818  1.55  mycroft 			}
    819  1.55  mycroft 		}
    820  1.55  mycroft 
    821  1.55  mycroft 		if (inb(iobase + com_iir) & IIR_NOPEND)
    822  1.55  mycroft 			return (1);
    823   1.1      cgd 	}
    824   1.1      cgd }
    825   1.1      cgd 
    826   1.1      cgd /*
    827   1.1      cgd  * Following are all routines needed for COM to act as console
    828   1.1      cgd  */
    829  1.17      cgd #include <dev/cons.h>
    830   1.1      cgd 
    831  1.48  mycroft void
    832   1.1      cgd comcnprobe(cp)
    833   1.1      cgd 	struct consdev *cp;
    834   1.1      cgd {
    835  1.21  mycroft 
    836  1.21  mycroft 	if (!comprobe1(CONADDR)) {
    837  1.21  mycroft 		cp->cn_pri = CN_DEAD;
    838  1.21  mycroft 		return;
    839  1.21  mycroft 	}
    840   1.1      cgd 
    841   1.1      cgd 	/* locate the major number */
    842   1.1      cgd 	for (commajor = 0; commajor < nchrdev; commajor++)
    843   1.1      cgd 		if (cdevsw[commajor].d_open == comopen)
    844   1.1      cgd 			break;
    845   1.1      cgd 
    846   1.1      cgd 	/* initialize required fields */
    847  1.29  mycroft 	cp->cn_dev = makedev(commajor, CONUNIT);
    848   1.1      cgd #ifdef	COMCONSOLE
    849   1.1      cgd 	cp->cn_pri = CN_REMOTE;		/* Force a serial port console */
    850   1.1      cgd #else
    851   1.1      cgd 	cp->cn_pri = CN_NORMAL;
    852   1.1      cgd #endif
    853   1.1      cgd }
    854   1.1      cgd 
    855  1.48  mycroft void
    856   1.1      cgd comcninit(cp)
    857   1.1      cgd 	struct consdev *cp;
    858   1.1      cgd {
    859   1.1      cgd 
    860  1.29  mycroft 	cominit(CONUNIT, comdefaultrate);
    861  1.29  mycroft 	comconsole = CONUNIT;
    862  1.21  mycroft 	comconsinit = 0;
    863   1.1      cgd }
    864   1.1      cgd 
    865   1.1      cgd cominit(unit, rate)
    866   1.1      cgd 	int unit, rate;
    867   1.1      cgd {
    868  1.21  mycroft 	int s = splhigh();
    869  1.41  mycroft 	int iobase = CONADDR;
    870  1.21  mycroft 	u_char stat;
    871   1.1      cgd 
    872  1.21  mycroft 	outb(iobase + com_cfcr, CFCR_DLAB);
    873  1.21  mycroft 	rate = comspeed(comdefaultrate);
    874  1.21  mycroft 	outb(iobase + com_dlbl, rate);
    875  1.21  mycroft 	outb(iobase + com_dlbh, rate >> 8);
    876  1.21  mycroft 	outb(iobase + com_cfcr, CFCR_8BITS);
    877  1.21  mycroft 	outb(iobase + com_ier, IER_ERXRDY | IER_ETXRDY);
    878  1.21  mycroft 	outb(iobase + com_fifo, FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_4);
    879  1.21  mycroft 	stat = inb(iobase + com_iir);
    880   1.1      cgd 	splx(s);
    881   1.1      cgd }
    882   1.1      cgd 
    883   1.1      cgd comcngetc(dev)
    884  1.21  mycroft 	dev_t dev;
    885   1.1      cgd {
    886  1.21  mycroft 	int s = splhigh();
    887  1.41  mycroft 	int iobase = CONADDR;
    888  1.21  mycroft 	u_char stat, c;
    889   1.1      cgd 
    890  1.21  mycroft 	while (((stat = inb(iobase + com_lsr)) & LSR_RXRDY) == 0)
    891   1.1      cgd 		;
    892  1.21  mycroft 	c = inb(iobase + com_data);
    893  1.21  mycroft 	stat = inb(iobase + com_iir);
    894   1.1      cgd 	splx(s);
    895  1.21  mycroft 	return c;
    896   1.1      cgd }
    897   1.1      cgd 
    898   1.1      cgd /*
    899   1.1      cgd  * Console kernel output character routine.
    900   1.1      cgd  */
    901  1.48  mycroft void
    902   1.1      cgd comcnputc(dev, c)
    903   1.1      cgd 	dev_t dev;
    904  1.21  mycroft 	int c;
    905   1.1      cgd {
    906  1.21  mycroft 	int s = splhigh();
    907  1.41  mycroft 	int iobase = CONADDR;
    908  1.21  mycroft 	u_char stat;
    909   1.1      cgd 	register int timo;
    910   1.1      cgd 
    911   1.1      cgd #ifdef KGDB
    912   1.1      cgd 	if (dev != kgdb_dev)
    913   1.1      cgd #endif
    914   1.1      cgd 	if (comconsinit == 0) {
    915  1.21  mycroft 		(void) cominit(COMUNIT(dev), comdefaultrate);
    916   1.1      cgd 		comconsinit = 1;
    917   1.1      cgd 	}
    918   1.1      cgd 	/* wait for any pending transmission to finish */
    919   1.1      cgd 	timo = 50000;
    920  1.21  mycroft 	while (((stat = inb(iobase + com_lsr)) & LSR_TXRDY) == 0 && --timo)
    921   1.1      cgd 		;
    922  1.21  mycroft 	outb(iobase + com_data, c);
    923   1.1      cgd 	/* wait for this transmission to complete */
    924   1.1      cgd 	timo = 1500000;
    925  1.21  mycroft 	while (((stat = inb(iobase + com_lsr)) & LSR_TXRDY) == 0 && --timo)
    926   1.1      cgd 		;
    927   1.1      cgd 	/* clear any interrupts generated by this transmission */
    928  1.21  mycroft 	stat = inb(iobase + com_iir);
    929   1.1      cgd 	splx(s);
    930  1.37  mycroft }
    931  1.37  mycroft 
    932  1.37  mycroft void
    933  1.37  mycroft comcnpollc(dev, on)
    934  1.37  mycroft 	dev_t dev;
    935  1.37  mycroft 	int on;
    936  1.37  mycroft {
    937  1.37  mycroft 
    938   1.2      cgd }
    939