Home | History | Annotate | Line # | Download | only in ixp12x0
ixp12x0_com.c revision 1.8
      1  1.8    ichiro /*	$NetBSD: ixp12x0_com.c,v 1.8 2002/12/02 14:10:13 ichiro Exp $ */
      2  1.1    ichiro /*
      3  1.1    ichiro  * Copyright (c) 1998, 1999, 2001, 2002 The NetBSD Foundation, Inc.
      4  1.1    ichiro  * All rights reserved.
      5  1.1    ichiro  *
      6  1.1    ichiro  * This code is derived from software contributed to The NetBSD Foundation
      7  1.1    ichiro  * by Ichiro FUKUHARA and Naoto Shimazaki.
      8  1.1    ichiro  *
      9  1.1    ichiro  * This code is derived from software contributed to The NetBSD Foundation
     10  1.1    ichiro  * by IWAMOTO Toshihiro.
     11  1.1    ichiro  *
     12  1.1    ichiro  * This code is derived from software contributed to The NetBSD Foundation
     13  1.1    ichiro  * by Charles M. Hannum.
     14  1.1    ichiro  *
     15  1.1    ichiro  * Redistribution and use in source and binary forms, with or without
     16  1.1    ichiro  * modification, are permitted provided that the following conditions
     17  1.1    ichiro  * are met:
     18  1.1    ichiro  * 1. Redistributions of source code must retain the above copyright
     19  1.1    ichiro  *    notice, this list of conditions and the following disclaimer.
     20  1.1    ichiro  * 2. Redistributions in binary form must reproduce the above copyright
     21  1.1    ichiro  *    notice, this list of conditions and the following disclaimer in the
     22  1.1    ichiro  *    documentation and/or other materials provided with the distribution.
     23  1.1    ichiro  * 3. All advertising materials mentioning features or use of this software
     24  1.1    ichiro  *    must display the following acknowledgement:
     25  1.1    ichiro  *        This product includes software developed by the NetBSD
     26  1.1    ichiro  *        Foundation, Inc. and its contributors.
     27  1.1    ichiro  * 4. Neither the name of The NetBSD Foundation nor the names of its
     28  1.1    ichiro  *    contributors may be used to endorse or promote products derived
     29  1.1    ichiro  *    from this software without specific prior written permission.
     30  1.1    ichiro  *
     31  1.1    ichiro  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     32  1.1    ichiro  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     33  1.1    ichiro  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     34  1.1    ichiro  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     35  1.1    ichiro  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     36  1.1    ichiro  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     37  1.1    ichiro  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     38  1.1    ichiro  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     39  1.1    ichiro  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     40  1.1    ichiro  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  1.1    ichiro  * POSSIBILITY OF SUCH DAMAGE.
     42  1.1    ichiro  */
     43  1.1    ichiro 
     44  1.1    ichiro /*
     45  1.1    ichiro  * Copyright (c) 1991 The Regents of the University of California.
     46  1.1    ichiro  * All rights reserved.
     47  1.1    ichiro  *
     48  1.1    ichiro  * Redistribution and use in source and binary forms, with or without
     49  1.1    ichiro  * modification, are permitted provided that the following conditions
     50  1.1    ichiro  * are met:
     51  1.1    ichiro  * 1. Redistributions of source code must retain the above copyright
     52  1.1    ichiro  *    notice, this list of conditions and the following disclaimer.
     53  1.1    ichiro  * 2. Redistributions in binary form must reproduce the above copyright
     54  1.1    ichiro  *    notice, this list of conditions and the following disclaimer in the
     55  1.1    ichiro  *    documentation and/or other materials provided with the distribution.
     56  1.1    ichiro  * 3. All advertising materials mentioning features or use of this software
     57  1.1    ichiro  *    must display the following acknowledgement:
     58  1.1    ichiro  *      This product includes software developed by the University of
     59  1.1    ichiro  *      California, Berkeley and its contributors.
     60  1.1    ichiro  * 4. Neither the name of the University nor the names of its contributors
     61  1.1    ichiro  *    may be used to endorse or promote products derived from this software
     62  1.1    ichiro  *    without specific prior written permission.
     63  1.1    ichiro  *
     64  1.1    ichiro  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     65  1.1    ichiro  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     66  1.1    ichiro  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     67  1.1    ichiro  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     68  1.1    ichiro  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     69  1.1    ichiro  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     70  1.1    ichiro  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     71  1.1    ichiro  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     72  1.1    ichiro  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     73  1.1    ichiro  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     74  1.1    ichiro  * SUCH DAMAGE.
     75  1.1    ichiro  *
     76  1.1    ichiro  *      @(#)com.c       7.5 (Berkeley) 5/16/91
     77  1.1    ichiro  */
     78  1.1    ichiro 
     79  1.1    ichiro 
     80  1.1    ichiro #include "opt_com.h"
     81  1.1    ichiro #include "opt_ddb.h"
     82  1.1    ichiro #include "opt_kgdb.h"
     83  1.1    ichiro 
     84  1.1    ichiro #include "rnd.h"
     85  1.1    ichiro #if NRND > 0 && defined(RND_COM)
     86  1.1    ichiro #include <sys/rnd.h>
     87  1.1    ichiro #endif
     88  1.1    ichiro 
     89  1.1    ichiro #include <sys/param.h>
     90  1.1    ichiro #include <sys/systm.h>
     91  1.1    ichiro #include <sys/types.h>
     92  1.1    ichiro #include <sys/conf.h>
     93  1.1    ichiro #include <sys/file.h>
     94  1.1    ichiro #include <sys/device.h>
     95  1.1    ichiro #include <sys/kernel.h>
     96  1.1    ichiro #include <sys/malloc.h>
     97  1.1    ichiro #include <sys/tty.h>
     98  1.1    ichiro #include <sys/uio.h>
     99  1.1    ichiro #include <sys/vnode.h>
    100  1.1    ichiro 
    101  1.2    ichiro #include <machine/intr.h>
    102  1.1    ichiro #include <machine/bus.h>
    103  1.1    ichiro 
    104  1.1    ichiro #include <arm/ixp12x0/ixp12x0_comreg.h>
    105  1.1    ichiro #include <arm/ixp12x0/ixp12x0_comvar.h>
    106  1.1    ichiro #include <arm/ixp12x0/ixp12x0reg.h>
    107  1.1    ichiro #include <arm/ixp12x0/ixp12x0var.h>
    108  1.1    ichiro 
    109  1.1    ichiro #include <arm/ixp12x0/ixpsipvar.h>
    110  1.1    ichiro 
    111  1.2    ichiro #include <dev/cons.h>
    112  1.1    ichiro #include "ixpcom.h"
    113  1.1    ichiro 
    114  1.1    ichiro static int	ixpcomparam(struct tty *, struct termios *);
    115  1.1    ichiro static void	ixpcomstart(struct tty *);
    116  1.1    ichiro static int	ixpcomhwiflow(struct tty *, int);
    117  1.1    ichiro 
    118  1.1    ichiro static u_int	cflag2cr(tcflag_t);
    119  1.2    ichiro static void	ixpcom_iflush(struct ixpcom_softc *);
    120  1.2    ichiro static void	ixpcom_set_cr(struct ixpcom_softc *);
    121  1.1    ichiro 
    122  1.1    ichiro int             ixpcomcngetc(dev_t);
    123  1.1    ichiro void            ixpcomcnputc(dev_t, int);
    124  1.1    ichiro void            ixpcomcnpollc(dev_t, int);
    125  1.1    ichiro 
    126  1.1    ichiro static void	ixpcomsoft(void* arg);
    127  1.1    ichiro inline static void	ixpcom_txsoft(struct ixpcom_softc *, struct tty *);
    128  1.1    ichiro inline static void	ixpcom_rxsoft(struct ixpcom_softc *, struct tty *);
    129  1.1    ichiro 
    130  1.1    ichiro void            ixpcomcnprobe(struct consdev *);
    131  1.1    ichiro void            ixpcomcninit(struct consdev *);
    132  1.1    ichiro 
    133  1.1    ichiro u_int32_t	ixpcom_cr = 0;		/* tell cr to *_intr.c */
    134  1.1    ichiro u_int32_t	ixpcom_imask = 0;	/* intrrupt mask from *_intr.c */
    135  1.1    ichiro 
    136  1.1    ichiro static bus_space_tag_t ixpcomconstag;
    137  1.1    ichiro static bus_space_handle_t ixpcomconsioh;
    138  1.8    ichiro static bus_addr_t ixpcomconsaddr;
    139  1.1    ichiro 
    140  1.1    ichiro static int ixpcomconsattached;
    141  1.1    ichiro static int ixpcomconsrate;
    142  1.1    ichiro static tcflag_t ixpcomconscflag;
    143  1.2    ichiro static struct cnm_state ixpcom_cnm_state;
    144  1.1    ichiro 
    145  1.8    ichiro struct ixpcom_softc* ixpcom_sc = NULL;
    146  1.8    ichiro 
    147  1.1    ichiro extern struct cfdriver ixpcom_cd;
    148  1.1    ichiro 
    149  1.4   gehenna dev_type_open(ixpcomopen);
    150  1.4   gehenna dev_type_close(ixpcomclose);
    151  1.4   gehenna dev_type_read(ixpcomread);
    152  1.4   gehenna dev_type_write(ixpcomwrite);
    153  1.4   gehenna dev_type_stop(ixpcomstop);
    154  1.4   gehenna dev_type_tty(ixpcomtty);
    155  1.4   gehenna dev_type_poll(ixpcompoll);
    156  1.4   gehenna 
    157  1.4   gehenna const struct cdevsw ixpcom_cdevsw = {
    158  1.4   gehenna 	ixpcomopen, ixpcomclose, ixpcomread, ixpcomwrite, nullioctl,
    159  1.7  jdolecek 	ixpcomstop, ixpcomtty, ixpcompoll, nommap, ttykqfilter, D_TTY
    160  1.4   gehenna };
    161  1.4   gehenna 
    162  1.1    ichiro struct consdev ixpcomcons = {
    163  1.1    ichiro 	NULL, NULL, ixpcomcngetc, ixpcomcnputc, ixpcomcnpollc, NULL,
    164  1.1    ichiro 	NODEV, CN_NORMAL
    165  1.1    ichiro };
    166  1.1    ichiro 
    167  1.1    ichiro #ifndef DEFAULT_COMSPEED
    168  1.1    ichiro #define DEFAULT_COMSPEED 38400
    169  1.1    ichiro #endif
    170  1.1    ichiro 
    171  1.1    ichiro #define COMUNIT_MASK    0x7ffff
    172  1.1    ichiro #define COMDIALOUT_MASK 0x80000
    173  1.1    ichiro 
    174  1.1    ichiro #define COMUNIT(x)	(minor(x) & COMUNIT_MASK)
    175  1.1    ichiro #define COMDIALOUT(x)	(minor(x) & COMDIALOUT_MASK)
    176  1.1    ichiro 
    177  1.1    ichiro #define COM_ISALIVE(sc)	((sc)->enabled != 0 && \
    178  1.1    ichiro 			ISSET((sc)->sc_dev.dv_flags, DVF_ACTIVE))
    179  1.1    ichiro 
    180  1.1    ichiro #define COM_BARRIER(t, h, f) bus_space_barrier((t), (h), 0, COM_NPORTS, (f))
    181  1.1    ichiro 
    182  1.1    ichiro #define	COM_LOCK(sc);
    183  1.1    ichiro #define	COM_UNLOCK(sc);
    184  1.1    ichiro 
    185  1.1    ichiro #define SET(t, f)	(t) |= (f)
    186  1.1    ichiro #define CLR(t, f)	(t) &= ~(f)
    187  1.1    ichiro #define ISSET(t, f)	((t) & (f))
    188  1.1    ichiro 
    189  1.2    ichiro #define CFLAGS2CR_MASK	(CR_PE | CR_OES | CR_SBS | CR_DSS | CR_BRD)
    190  1.1    ichiro 
    191  1.1    ichiro void
    192  1.1    ichiro ixpcom_attach_subr(sc)
    193  1.1    ichiro 	struct ixpcom_softc *sc;
    194  1.1    ichiro {
    195  1.1    ichiro 	bus_addr_t iobase = sc->sc_baseaddr;
    196  1.1    ichiro 	bus_space_tag_t iot = sc->sc_iot;
    197  1.1    ichiro 	struct tty *tp;
    198  1.8    ichiro 
    199  1.8    ichiro 	ixpcom_sc = sc;
    200  1.1    ichiro 
    201  1.1    ichiro 	if (iot == ixpcomconstag && iobase == ixpcomconsaddr) {
    202  1.1    ichiro 		ixpcomconsattached = 1;
    203  1.2    ichiro 		sc->sc_speed = IXPCOMSPEED2BRD(ixpcomconsrate);
    204  1.1    ichiro 
    205  1.1    ichiro 		/* Make sure the console is always "hardwired". */
    206  1.1    ichiro 		delay(10000);	/* wait for output to finish */
    207  1.1    ichiro 		SET(sc->sc_hwflags, COM_HW_CONSOLE);
    208  1.1    ichiro 		SET(sc->sc_swflags, TIOCFLAG_SOFTCAR);
    209  1.1    ichiro 	}
    210  1.1    ichiro 
    211  1.1    ichiro 	tp = ttymalloc();
    212  1.1    ichiro 	tp->t_oproc = ixpcomstart;
    213  1.1    ichiro 	tp->t_param = ixpcomparam;
    214  1.1    ichiro 	tp->t_hwiflow = ixpcomhwiflow;
    215  1.1    ichiro 
    216  1.1    ichiro 	sc->sc_tty = tp;
    217  1.1    ichiro 	sc->sc_rbuf = malloc(IXPCOM_RING_SIZE << 1, M_DEVBUF, M_NOWAIT);
    218  1.1    ichiro 	sc->sc_rbput = sc->sc_rbget = sc->sc_rbuf;
    219  1.1    ichiro 	sc->sc_rbavail = IXPCOM_RING_SIZE;
    220  1.1    ichiro 	if (sc->sc_rbuf == NULL) {
    221  1.1    ichiro 		printf("%s: unable to allocate ring buffer\n",
    222  1.1    ichiro 		    sc->sc_dev.dv_xname);
    223  1.1    ichiro 		return;
    224  1.1    ichiro 	}
    225  1.1    ichiro 	sc->sc_ebuf = sc->sc_rbuf + (IXPCOM_RING_SIZE << 1);
    226  1.1    ichiro 	sc->sc_tbc = 0;
    227  1.1    ichiro 
    228  1.1    ichiro 	sc->sc_rie = sc->sc_xie = 0;
    229  1.1    ichiro 	ixpcom_cr = IXPCOMSPEED2BRD(DEFAULT_COMSPEED)
    230  1.1    ichiro 		| CR_UE | sc->sc_rie | sc->sc_xie | DSS_8BIT;
    231  1.1    ichiro 
    232  1.1    ichiro 	tty_attach(tp);
    233  1.1    ichiro 
    234  1.1    ichiro 	if (ISSET(sc->sc_hwflags, COM_HW_CONSOLE)) {
    235  1.1    ichiro 		int maj;
    236  1.1    ichiro 
    237  1.1    ichiro 		/* locate the major number */
    238  1.4   gehenna 		maj = cdevsw_lookup_major(&ixpcom_cdevsw);
    239  1.1    ichiro 
    240  1.1    ichiro 		cn_tab->cn_dev = makedev(maj, sc->sc_dev.dv_unit);
    241  1.1    ichiro 
    242  1.1    ichiro 		delay(10000); /* XXX */
    243  1.1    ichiro 		printf("%s: console\n", sc->sc_dev.dv_xname);
    244  1.1    ichiro 		delay(10000); /* XXX */
    245  1.1    ichiro 	}
    246  1.1    ichiro 
    247  1.1    ichiro 	sc->sc_si = softintr_establish(IPL_SOFTSERIAL, ixpcomsoft, sc);
    248  1.1    ichiro 
    249  1.1    ichiro #if NRND > 0 && defined(RND_COM)
    250  1.1    ichiro 	rnd_attach_source(&sc->rnd_source, sc->sc_dev.dv_xname,
    251  1.1    ichiro 			  RND_TYPE_TTY, 0);
    252  1.1    ichiro #endif
    253  1.1    ichiro 
    254  1.1    ichiro 	/* if there are no enable/disable functions, assume the device
    255  1.1    ichiro 	   is always enabled */
    256  1.1    ichiro 	if (!sc->enable)
    257  1.1    ichiro 		sc->enabled = 1;
    258  1.1    ichiro 
    259  1.1    ichiro 	/* XXX configure register */
    260  1.1    ichiro 	/* xxx_config(sc) */
    261  1.1    ichiro 
    262  1.1    ichiro 	SET(sc->sc_hwflags, COM_HW_DEV_OK);
    263  1.1    ichiro }
    264  1.1    ichiro 
    265  1.2    ichiro static int
    266  1.2    ichiro ixpcomparam(tp, t)
    267  1.2    ichiro 	struct tty *tp;
    268  1.2    ichiro 	struct termios *t;
    269  1.2    ichiro {
    270  1.2    ichiro 	struct ixpcom_softc *sc
    271  1.2    ichiro 		= device_lookup(&ixpcom_cd, COMUNIT(tp->t_dev));
    272  1.2    ichiro 	u_int32_t cr;
    273  1.2    ichiro 	int s;
    274  1.2    ichiro 
    275  1.2    ichiro 	if (COM_ISALIVE(sc) == 0)
    276  1.2    ichiro 		return (EIO);
    277  1.2    ichiro 
    278  1.2    ichiro 	cr = IXPCOMSPEED2BRD(t->c_ospeed);
    279  1.1    ichiro 
    280  1.2    ichiro 	if (t->c_ispeed && t->c_ispeed != t->c_ospeed)
    281  1.2    ichiro 		return (EINVAL);
    282  1.1    ichiro 
    283  1.2    ichiro 	/*
    284  1.2    ichiro 	 * For the console, always force CLOCAL and !HUPCL, so that the port
    285  1.2    ichiro 	 * is always active.
    286  1.2    ichiro 	 */
    287  1.2    ichiro 	if (ISSET(sc->sc_swflags, TIOCFLAG_SOFTCAR) ||
    288  1.2    ichiro 	    ISSET(sc->sc_hwflags, COM_HW_CONSOLE)) {
    289  1.2    ichiro 		SET(t->c_cflag, CLOCAL);
    290  1.2    ichiro 		CLR(t->c_cflag, HUPCL);
    291  1.2    ichiro 	}
    292  1.1    ichiro 
    293  1.2    ichiro 	/*
    294  1.2    ichiro 	 * If there were no changes, don't do anything.  This avoids dropping
    295  1.2    ichiro 	 * input and improves performance when all we did was frob things like
    296  1.2    ichiro 	 * VMIN and VTIME.
    297  1.2    ichiro 	 */
    298  1.2    ichiro 	if (tp->t_ospeed == t->c_ospeed &&
    299  1.2    ichiro 	    tp->t_cflag == t->c_cflag)
    300  1.2    ichiro 		return (0);
    301  1.1    ichiro 
    302  1.2    ichiro 	cr |= cflag2cr(t->c_cflag);
    303  1.1    ichiro 
    304  1.1    ichiro 	s = splserial();
    305  1.2    ichiro 	COM_LOCK(sc);
    306  1.2    ichiro 
    307  1.2    ichiro 	ixpcom_cr = (ixpcom_cr & ~CFLAGS2CR_MASK) | cr;
    308  1.2    ichiro 
    309  1.2    ichiro 	/*
    310  1.2    ichiro 	 * ixpcom don't have any hardware flow control.
    311  1.2    ichiro 	 * we skip it.
    312  1.2    ichiro 	 */
    313  1.2    ichiro 
    314  1.2    ichiro 	/* And copy to tty. */
    315  1.2    ichiro 	tp->t_ispeed = 0;
    316  1.2    ichiro 	tp->t_ospeed = t->c_ospeed;
    317  1.2    ichiro 	tp->t_cflag = t->c_cflag;
    318  1.2    ichiro 
    319  1.2    ichiro 	if (!sc->sc_heldchange) {
    320  1.2    ichiro 		if (sc->sc_tx_busy) {
    321  1.2    ichiro 			sc->sc_heldtbc = sc->sc_tbc;
    322  1.2    ichiro 			sc->sc_tbc = 0;
    323  1.2    ichiro 			sc->sc_heldchange = 1;
    324  1.2    ichiro 		} else
    325  1.2    ichiro 			ixpcom_set_cr(sc);
    326  1.1    ichiro 	}
    327  1.1    ichiro 
    328  1.2    ichiro 	COM_UNLOCK(sc);
    329  1.1    ichiro 	splx(s);
    330  1.1    ichiro 
    331  1.2    ichiro 	/*
    332  1.2    ichiro 	 * Update the tty layer's idea of the carrier bit.
    333  1.2    ichiro 	 * We tell tty the carrier is always on.
    334  1.2    ichiro 	 */
    335  1.2    ichiro 	(void) (*tp->t_linesw->l_modem)(tp, 1);
    336  1.2    ichiro 
    337  1.2    ichiro #ifdef COM_DEBUG
    338  1.2    ichiro 	if (com_debug)
    339  1.2    ichiro 		comstatus(sc, "comparam ");
    340  1.2    ichiro #endif
    341  1.2    ichiro 
    342  1.2    ichiro 	if (!ISSET(t->c_cflag, CHWFLOW)) {
    343  1.2    ichiro 		if (sc->sc_tx_stopped) {
    344  1.2    ichiro 			sc->sc_tx_stopped = 0;
    345  1.2    ichiro 			ixpcomstart(tp);
    346  1.2    ichiro 		}
    347  1.2    ichiro 	}
    348  1.2    ichiro 
    349  1.1    ichiro 	return (0);
    350  1.1    ichiro }
    351  1.1    ichiro 
    352  1.2    ichiro static int
    353  1.1    ichiro ixpcomhwiflow(tp, block)
    354  1.1    ichiro 	struct tty *tp;
    355  1.1    ichiro 	int block;
    356  1.1    ichiro {
    357  1.1    ichiro 	return (0);
    358  1.1    ichiro }
    359  1.1    ichiro 
    360  1.2    ichiro static void
    361  1.6   thorpej ixpcom_filltx(struct ixpcom_softc *sc)
    362  1.2    ichiro {
    363  1.2    ichiro 	bus_space_tag_t iot = sc->sc_iot;
    364  1.2    ichiro 	bus_space_handle_t ioh = sc->sc_ioh;
    365  1.2    ichiro 	int n;
    366  1.2    ichiro 
    367  1.2    ichiro 	n = 0;
    368  1.2    ichiro         while (bus_space_read_4(iot, ioh, IXPCOM_SR) & SR_TXR) {
    369  1.2    ichiro 		if (n >= sc->sc_tbc)
    370  1.2    ichiro 			break;
    371  1.2    ichiro 		bus_space_write_4(iot, ioh, IXPCOM_DR,
    372  1.2    ichiro 				  0xff & *(sc->sc_tba + n));
    373  1.2    ichiro 		n++;
    374  1.2    ichiro         }
    375  1.2    ichiro         sc->sc_tbc -= n;
    376  1.2    ichiro         sc->sc_tba += n;
    377  1.2    ichiro }
    378  1.2    ichiro 
    379  1.2    ichiro static void
    380  1.1    ichiro ixpcomstart(tp)
    381  1.1    ichiro 	struct tty *tp;
    382  1.1    ichiro {
    383  1.2    ichiro 	struct ixpcom_softc *sc
    384  1.2    ichiro 		= device_lookup(&ixpcom_cd, COMUNIT(tp->t_dev));
    385  1.2    ichiro 	int s;
    386  1.2    ichiro 
    387  1.2    ichiro 	if (COM_ISALIVE(sc) == 0)
    388  1.2    ichiro 		return;
    389  1.2    ichiro 
    390  1.2    ichiro 	s = spltty();
    391  1.2    ichiro 	if (ISSET(tp->t_state, TS_BUSY | TS_TIMEOUT | TS_TTSTOP))
    392  1.2    ichiro 		goto out;
    393  1.2    ichiro 	if (sc->sc_tx_stopped)
    394  1.2    ichiro 		goto out;
    395  1.2    ichiro 
    396  1.2    ichiro 	if (tp->t_outq.c_cc <= tp->t_lowat) {
    397  1.2    ichiro 		if (ISSET(tp->t_state, TS_ASLEEP)) {
    398  1.2    ichiro 			CLR(tp->t_state, TS_ASLEEP);
    399  1.2    ichiro 			wakeup(&tp->t_outq);
    400  1.2    ichiro 		}
    401  1.2    ichiro 		selwakeup(&tp->t_wsel);
    402  1.2    ichiro 		if (tp->t_outq.c_cc == 0)
    403  1.2    ichiro 			goto out;
    404  1.2    ichiro 	}
    405  1.2    ichiro 
    406  1.2    ichiro 	/* Grab the first contiguous region of buffer space. */
    407  1.2    ichiro 	{
    408  1.2    ichiro 		u_char *tba;
    409  1.2    ichiro 		int tbc;
    410  1.2    ichiro 
    411  1.2    ichiro 		tba = tp->t_outq.c_cf;
    412  1.2    ichiro 		tbc = ndqb(&tp->t_outq, 0);
    413  1.2    ichiro 
    414  1.2    ichiro 		(void)splserial();
    415  1.2    ichiro 		COM_LOCK(sc);
    416  1.2    ichiro 
    417  1.2    ichiro 		sc->sc_tba = tba;
    418  1.2    ichiro 		sc->sc_tbc = tbc;
    419  1.2    ichiro 	}
    420  1.2    ichiro 
    421  1.2    ichiro 	SET(tp->t_state, TS_BUSY);
    422  1.2    ichiro 	sc->sc_tx_busy = 1;
    423  1.2    ichiro 
    424  1.2    ichiro 	/* Enable transmit completion interrupts if necessary. */
    425  1.2    ichiro 	if (!ISSET(sc->sc_xie, CR_XIE)) {
    426  1.2    ichiro 		SET(sc->sc_xie, CR_XIE);
    427  1.2    ichiro 		ixpcom_set_cr(sc);
    428  1.2    ichiro 	}
    429  1.2    ichiro 
    430  1.2    ichiro 	/* Output the first chunk of the contiguous buffer. */
    431  1.2    ichiro 	ixpcom_filltx(sc);
    432  1.2    ichiro 
    433  1.2    ichiro 	COM_UNLOCK(sc);
    434  1.2    ichiro out:
    435  1.2    ichiro 	splx(s);
    436  1.1    ichiro 	return;
    437  1.1    ichiro }
    438  1.1    ichiro 
    439  1.2    ichiro static void
    440  1.6   thorpej ixpcom_break(struct ixpcom_softc *sc, int onoff)
    441  1.2    ichiro {
    442  1.2    ichiro 	if (onoff)
    443  1.2    ichiro 		SET(ixpcom_cr, CR_BRK);
    444  1.2    ichiro 	else
    445  1.2    ichiro 		CLR(ixpcom_cr, CR_BRK);
    446  1.2    ichiro 	if (!sc->sc_heldchange) {
    447  1.2    ichiro 		if (sc->sc_tx_busy) {
    448  1.2    ichiro 			sc->sc_heldtbc = sc->sc_tbc;
    449  1.2    ichiro 			sc->sc_tbc = 0;
    450  1.2    ichiro 			sc->sc_heldchange = 1;
    451  1.2    ichiro 		} else
    452  1.2    ichiro 			ixpcom_set_cr(sc);
    453  1.2    ichiro 	}
    454  1.2    ichiro }
    455  1.2    ichiro 
    456  1.2    ichiro static void
    457  1.6   thorpej ixpcom_shutdown(struct ixpcom_softc *sc)
    458  1.2    ichiro {
    459  1.2    ichiro 	int s;
    460  1.2    ichiro 
    461  1.2    ichiro 	s = splserial();
    462  1.2    ichiro 	COM_LOCK(sc);
    463  1.2    ichiro 
    464  1.2    ichiro 	/* Clear any break condition set with TIOCSBRK. */
    465  1.2    ichiro 	ixpcom_break(sc, 0);
    466  1.2    ichiro 
    467  1.2    ichiro 	/* Turn off interrupts. */
    468  1.2    ichiro 	sc->sc_rie = sc->sc_xie = 0;
    469  1.2    ichiro 	ixpcom_set_cr(sc);
    470  1.2    ichiro 
    471  1.2    ichiro 	if (sc->disable) {
    472  1.2    ichiro #ifdef DIAGNOSTIC
    473  1.2    ichiro 		if (!sc->enabled)
    474  1.2    ichiro 			panic("ixpcom_shutdown: not enabled?");
    475  1.2    ichiro #endif
    476  1.2    ichiro 		(*sc->disable)(sc);
    477  1.2    ichiro 		sc->enabled = 0;
    478  1.2    ichiro 	}
    479  1.2    ichiro 	COM_UNLOCK(sc);
    480  1.2    ichiro 	splx(s);
    481  1.2    ichiro }
    482  1.2    ichiro 
    483  1.1    ichiro int
    484  1.1    ichiro ixpcomopen(dev, flag, mode, p)
    485  1.1    ichiro 	dev_t dev;
    486  1.1    ichiro 	int flag, mode;
    487  1.1    ichiro 	struct proc *p;
    488  1.1    ichiro {
    489  1.2    ichiro 	struct ixpcom_softc *sc;
    490  1.2    ichiro 	struct tty *tp;
    491  1.2    ichiro 	int s, s2;
    492  1.2    ichiro 	int error;
    493  1.2    ichiro 
    494  1.2    ichiro 	sc = device_lookup(&ixpcom_cd, COMUNIT(dev));
    495  1.2    ichiro 	if (sc == NULL || !ISSET(sc->sc_hwflags, COM_HW_DEV_OK) ||
    496  1.2    ichiro 		sc->sc_rbuf == NULL)
    497  1.2    ichiro 		return (ENXIO);
    498  1.2    ichiro 
    499  1.2    ichiro 	if (ISSET(sc->sc_dev.dv_flags, DVF_ACTIVE) == 0)
    500  1.2    ichiro 		return (ENXIO);
    501  1.2    ichiro 
    502  1.2    ichiro #ifdef KGDB
    503  1.2    ichiro 	/*
    504  1.2    ichiro 	 * If this is the kgdb port, no other use is permitted.
    505  1.2    ichiro 	 */
    506  1.2    ichiro 	if (ISSET(sc->sc_hwflags, COM_HW_KGDB))
    507  1.2    ichiro 		return (EBUSY);
    508  1.2    ichiro #endif
    509  1.2    ichiro 
    510  1.2    ichiro 	tp = sc->sc_tty;
    511  1.2    ichiro 
    512  1.2    ichiro 	if (ISSET(tp->t_state, TS_ISOPEN) &&
    513  1.2    ichiro 	    ISSET(tp->t_state, TS_XCLUDE) &&
    514  1.2    ichiro 		p->p_ucred->cr_uid != 0)
    515  1.2    ichiro 		return (EBUSY);
    516  1.2    ichiro 
    517  1.2    ichiro 	s = spltty();
    518  1.2    ichiro 
    519  1.2    ichiro 	/*
    520  1.2    ichiro 	 * Do the following iff this is a first open.
    521  1.2    ichiro 	 */
    522  1.2    ichiro 	if (!ISSET(tp->t_state, TS_ISOPEN) && tp->t_wopen == 0) {
    523  1.2    ichiro 		struct termios t;
    524  1.2    ichiro 
    525  1.2    ichiro 		tp->t_dev = dev;
    526  1.2    ichiro 
    527  1.2    ichiro 		s2 = splserial();
    528  1.2    ichiro 		COM_LOCK(sc);
    529  1.2    ichiro 
    530  1.2    ichiro 		if (sc->enable) {
    531  1.2    ichiro 			if ((*sc->enable)(sc)) {
    532  1.2    ichiro 				COM_UNLOCK(sc);
    533  1.2    ichiro 				splx(s2);
    534  1.2    ichiro 				splx(s);
    535  1.2    ichiro 				printf("%s: device enable failed\n",
    536  1.2    ichiro 				       sc->sc_dev.dv_xname);
    537  1.2    ichiro 				return (EIO);
    538  1.2    ichiro 			}
    539  1.2    ichiro 			sc->enabled = 1;
    540  1.2    ichiro #if 0
    541  1.2    ichiro /* XXXXXXXXXXXXXXX */
    542  1.2    ichiro 			com_config(sc);
    543  1.2    ichiro #endif
    544  1.2    ichiro 		}
    545  1.2    ichiro 
    546  1.2    ichiro 		/* Turn on interrupts. */
    547  1.2    ichiro 		SET(sc->sc_rie, CR_RIE);
    548  1.2    ichiro 		ixpcom_set_cr(sc);
    549  1.2    ichiro 
    550  1.2    ichiro #if 0
    551  1.2    ichiro 		/* Fetch the current modem control status, needed later. */
    552  1.2    ichiro 		sc->sc_msr = bus_space_read_1(sc->sc_iot, sc->sc_ioh, com_msr);
    553  1.2    ichiro 
    554  1.2    ichiro 		/* Clear PPS capture state on first open. */
    555  1.2    ichiro 		sc->sc_ppsmask = 0;
    556  1.2    ichiro 		sc->ppsparam.mode = 0;
    557  1.2    ichiro #endif
    558  1.2    ichiro 
    559  1.2    ichiro 		COM_UNLOCK(sc);
    560  1.2    ichiro 		splx(s2);
    561  1.2    ichiro 
    562  1.2    ichiro 		/*
    563  1.2    ichiro 		 * Initialize the termios status to the defaults.  Add in the
    564  1.2    ichiro 		 * sticky bits from TIOCSFLAGS.
    565  1.2    ichiro 		 */
    566  1.2    ichiro 		t.c_ispeed = 0;
    567  1.2    ichiro 		if (ISSET(sc->sc_hwflags, COM_HW_CONSOLE)) {
    568  1.2    ichiro 			t.c_ospeed = ixpcomconsrate;
    569  1.2    ichiro 			t.c_cflag = ixpcomconscflag;
    570  1.2    ichiro 		} else {
    571  1.2    ichiro 			t.c_ospeed = TTYDEF_SPEED;
    572  1.2    ichiro 			t.c_cflag = TTYDEF_CFLAG;
    573  1.2    ichiro 		}
    574  1.2    ichiro 		if (ISSET(sc->sc_swflags, TIOCFLAG_CLOCAL))
    575  1.2    ichiro 			SET(t.c_cflag, CLOCAL);
    576  1.2    ichiro 		if (ISSET(sc->sc_swflags, TIOCFLAG_CRTSCTS))
    577  1.2    ichiro 			SET(t.c_cflag, CRTSCTS);
    578  1.2    ichiro 		if (ISSET(sc->sc_swflags, TIOCFLAG_MDMBUF))
    579  1.2    ichiro 			SET(t.c_cflag, MDMBUF);
    580  1.2    ichiro 		/* Make sure ixpcomparam() will do something. */
    581  1.2    ichiro 		tp->t_ospeed = 0;
    582  1.2    ichiro 		(void) ixpcomparam(tp, &t);
    583  1.2    ichiro 		tp->t_iflag = TTYDEF_IFLAG;
    584  1.2    ichiro 		tp->t_oflag = TTYDEF_OFLAG;
    585  1.2    ichiro 		tp->t_lflag = TTYDEF_LFLAG;
    586  1.2    ichiro 		ttychars(tp);
    587  1.2    ichiro 		ttsetwater(tp);
    588  1.2    ichiro 
    589  1.2    ichiro 		s2 = splserial();
    590  1.2    ichiro 		COM_LOCK(sc);
    591  1.2    ichiro 
    592  1.2    ichiro 		/* Clear the input ring, and unblock. */
    593  1.2    ichiro 		sc->sc_rbput = sc->sc_rbget = sc->sc_rbuf;
    594  1.2    ichiro 		sc->sc_rbavail = IXPCOM_RING_SIZE;
    595  1.2    ichiro 		ixpcom_iflush(sc);
    596  1.2    ichiro 		CLR(sc->sc_rx_flags, RX_ANY_BLOCK);
    597  1.2    ichiro 
    598  1.2    ichiro #ifdef COM_DEBUG
    599  1.2    ichiro 		if (ixpcom_debug)
    600  1.2    ichiro 			comstatus(sc, "ixpcomopen  ");
    601  1.2    ichiro #endif
    602  1.2    ichiro 
    603  1.2    ichiro 		COM_UNLOCK(sc);
    604  1.2    ichiro 		splx(s2);
    605  1.2    ichiro 	}
    606  1.2    ichiro 
    607  1.2    ichiro 	splx(s);
    608  1.2    ichiro 
    609  1.2    ichiro 	error = ttyopen(tp, COMDIALOUT(dev), ISSET(flag, O_NONBLOCK));
    610  1.2    ichiro 	if (error)
    611  1.2    ichiro 		goto bad;
    612  1.2    ichiro 
    613  1.2    ichiro 	error = (*tp->t_linesw->l_open)(dev, tp);
    614  1.2    ichiro 	if (error)
    615  1.2    ichiro 		goto bad;
    616  1.2    ichiro 
    617  1.2    ichiro 	return (0);
    618  1.2    ichiro 
    619  1.2    ichiro bad:
    620  1.2    ichiro 	if (!ISSET(tp->t_state, TS_ISOPEN) && tp->t_wopen == 0) {
    621  1.2    ichiro 		/*
    622  1.2    ichiro 		 * We failed to open the device, and nobody else had it opened.
    623  1.2    ichiro 		 * Clean up the state as appropriate.
    624  1.2    ichiro 		 */
    625  1.2    ichiro 		ixpcom_shutdown(sc);
    626  1.2    ichiro 	}
    627  1.2    ichiro 
    628  1.2    ichiro 	return (error);
    629  1.2    ichiro }
    630  1.2    ichiro 
    631  1.2    ichiro int
    632  1.2    ichiro ixpcomclose(dev, flag, mode, p)
    633  1.2    ichiro 	dev_t dev;
    634  1.2    ichiro 	int flag, mode;
    635  1.2    ichiro 	struct proc *p;
    636  1.2    ichiro {
    637  1.2    ichiro 	struct ixpcom_softc *sc = device_lookup(&ixpcom_cd, COMUNIT(dev));
    638  1.2    ichiro 	struct tty *tp = sc->sc_tty;
    639  1.2    ichiro 
    640  1.2    ichiro 	/* XXX This is for cons.c. */
    641  1.2    ichiro 	if (!ISSET(tp->t_state, TS_ISOPEN))
    642  1.2    ichiro 		return (0);
    643  1.2    ichiro 
    644  1.2    ichiro 	(*tp->t_linesw->l_close)(tp, flag);
    645  1.2    ichiro 	ttyclose(tp);
    646  1.2    ichiro 
    647  1.2    ichiro 	if (COM_ISALIVE(sc) == 0)
    648  1.2    ichiro 		return (0);
    649  1.2    ichiro 
    650  1.2    ichiro 	if (!ISSET(tp->t_state, TS_ISOPEN) && tp->t_wopen == 0) {
    651  1.2    ichiro 		/*
    652  1.2    ichiro 		 * Although we got a last close, the device may still be in
    653  1.2    ichiro 		 * use; e.g. if this was the dialout node, and there are still
    654  1.2    ichiro 		 * processes waiting for carrier on the non-dialout node.
    655  1.2    ichiro 		 */
    656  1.2    ichiro 		ixpcom_shutdown(sc);
    657  1.2    ichiro 	}
    658  1.2    ichiro 
    659  1.1    ichiro 	return (0);
    660  1.1    ichiro }
    661  1.2    ichiro 
    662  1.2    ichiro int
    663  1.2    ichiro ixpcomread(dev, uio, flag)
    664  1.2    ichiro 	dev_t dev;
    665  1.2    ichiro 	struct uio *uio;
    666  1.2    ichiro 	int flag;
    667  1.2    ichiro {
    668  1.2    ichiro 	struct ixpcom_softc *sc = device_lookup(&ixpcom_cd, COMUNIT(dev));
    669  1.2    ichiro 	struct tty *tp = sc->sc_tty;
    670  1.2    ichiro 
    671  1.2    ichiro 	if (COM_ISALIVE(sc) == 0)
    672  1.2    ichiro 		return (EIO);
    673  1.2    ichiro 
    674  1.2    ichiro 	return ((*tp->t_linesw->l_read)(tp, uio, flag));
    675  1.2    ichiro }
    676  1.2    ichiro 
    677  1.2    ichiro int
    678  1.2    ichiro ixpcomwrite(dev, uio, flag)
    679  1.2    ichiro 	dev_t dev;
    680  1.2    ichiro 	struct uio *uio;
    681  1.2    ichiro 	int flag;
    682  1.2    ichiro {
    683  1.2    ichiro 	struct ixpcom_softc *sc = device_lookup(&ixpcom_cd, COMUNIT(dev));
    684  1.2    ichiro 	struct tty *tp = sc->sc_tty;
    685  1.2    ichiro 
    686  1.2    ichiro 	if (COM_ISALIVE(sc) == 0)
    687  1.2    ichiro 		return (EIO);
    688  1.2    ichiro 
    689  1.2    ichiro 	return ((*tp->t_linesw->l_write)(tp, uio, flag));
    690  1.2    ichiro }
    691  1.2    ichiro 
    692  1.2    ichiro int
    693  1.2    ichiro ixpcompoll(dev, events, p)
    694  1.2    ichiro 	dev_t dev;
    695  1.2    ichiro 	int events;
    696  1.2    ichiro 	struct proc *p;
    697  1.2    ichiro {
    698  1.2    ichiro 	struct ixpcom_softc *sc = device_lookup(&ixpcom_cd, COMUNIT(dev));
    699  1.2    ichiro 	struct tty *tp = sc->sc_tty;
    700  1.2    ichiro 
    701  1.2    ichiro 	if (COM_ISALIVE(sc) == 0)
    702  1.2    ichiro 		return (EIO);
    703  1.2    ichiro 
    704  1.2    ichiro 	return ((*tp->t_linesw->l_poll)(tp, events, p));
    705  1.2    ichiro }
    706  1.2    ichiro 
    707  1.2    ichiro struct tty *
    708  1.2    ichiro ixpcomtty(dev)
    709  1.2    ichiro 	dev_t dev;
    710  1.2    ichiro {
    711  1.2    ichiro 	struct ixpcom_softc *sc = device_lookup(&ixpcom_cd, COMUNIT(dev));
    712  1.2    ichiro 	struct tty *tp = sc->sc_tty;
    713  1.2    ichiro 
    714  1.2    ichiro 	return (tp);
    715  1.2    ichiro }
    716  1.2    ichiro 
    717  1.2    ichiro /*
    718  1.2    ichiro  * Stop output on a line.
    719  1.2    ichiro  */
    720  1.2    ichiro void
    721  1.2    ichiro ixpcomstop(tp, flag)
    722  1.2    ichiro 	struct tty *tp;
    723  1.2    ichiro 	int flag;
    724  1.2    ichiro {
    725  1.2    ichiro 	struct ixpcom_softc *sc
    726  1.2    ichiro 		= device_lookup(&ixpcom_cd, COMUNIT(tp->t_dev));
    727  1.2    ichiro 	int s;
    728  1.2    ichiro 
    729  1.2    ichiro 	s = splserial();
    730  1.2    ichiro 	COM_LOCK(sc);
    731  1.2    ichiro 	if (ISSET(tp->t_state, TS_BUSY)) {
    732  1.2    ichiro 		/* Stop transmitting at the next chunk. */
    733  1.2    ichiro 		sc->sc_tbc = 0;
    734  1.2    ichiro 		sc->sc_heldtbc = 0;
    735  1.2    ichiro 		if (!ISSET(tp->t_state, TS_TTSTOP))
    736  1.2    ichiro 			SET(tp->t_state, TS_FLUSH);
    737  1.2    ichiro 	}
    738  1.2    ichiro 	COM_UNLOCK(sc);
    739  1.2    ichiro 	splx(s);
    740  1.2    ichiro }
    741  1.2    ichiro 
    742  1.1    ichiro static u_int
    743  1.1    ichiro cflag2cr(cflag)
    744  1.1    ichiro 	tcflag_t cflag;
    745  1.1    ichiro {
    746  1.1    ichiro 	u_int cr;
    747  1.1    ichiro 
    748  1.1    ichiro 	cr  = (cflag & PARENB) ? CR_PE : 0;
    749  1.1    ichiro 	cr |= (cflag & PARODD) ? CR_OES : 0;
    750  1.1    ichiro 	cr |= (cflag & CSTOPB) ? CR_SBS : 0;
    751  1.1    ichiro 	cr |= ((cflag & CSIZE) == CS8) ? DSS_8BIT : 0;
    752  1.1    ichiro 
    753  1.1    ichiro 	return (cr);
    754  1.1    ichiro }
    755  1.1    ichiro 
    756  1.1    ichiro static void
    757  1.2    ichiro ixpcom_iflush(sc)
    758  1.2    ichiro 	struct ixpcom_softc *sc;
    759  1.2    ichiro {
    760  1.2    ichiro 	bus_space_tag_t iot = sc->sc_iot;
    761  1.2    ichiro 	bus_space_handle_t ioh = sc->sc_ioh;
    762  1.2    ichiro #ifdef DIAGNOSTIC
    763  1.2    ichiro 	int reg;
    764  1.2    ichiro #endif
    765  1.2    ichiro 	int timo;
    766  1.2    ichiro 
    767  1.2    ichiro #ifdef DIAGNOSTIC
    768  1.2    ichiro 	reg = 0xffff;
    769  1.2    ichiro #endif
    770  1.2    ichiro 	timo = 50000;
    771  1.2    ichiro 	/* flush any pending I/O */
    772  1.2    ichiro 	while (ISSET(bus_space_read_4(iot, ioh, IXPCOM_SR), SR_RXR)
    773  1.2    ichiro 	       && --timo)
    774  1.2    ichiro #ifdef DIAGNOSTIC
    775  1.2    ichiro 		reg =
    776  1.2    ichiro #else
    777  1.2    ichiro 			(void)
    778  1.2    ichiro #endif
    779  1.2    ichiro 			bus_space_read_4(iot, ioh, IXPCOM_DR);
    780  1.2    ichiro #ifdef DIAGNOSTIC
    781  1.2    ichiro 	if (!timo)
    782  1.2    ichiro 		printf("%s: com_iflush timeout %02x\n", sc->sc_dev.dv_xname,
    783  1.2    ichiro 		       reg);
    784  1.2    ichiro #endif
    785  1.2    ichiro }
    786  1.2    ichiro 
    787  1.2    ichiro static void
    788  1.6   thorpej ixpcom_set_cr(struct ixpcom_softc *sc)
    789  1.1    ichiro {
    790  1.1    ichiro 	/* XXX */
    791  1.1    ichiro 	ixpcom_cr &= ~(CR_RIE | CR_XIE);
    792  1.1    ichiro 	ixpcom_cr |= sc->sc_rie | sc->sc_xie;
    793  1.2    ichiro 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, IXPCOM_CR,
    794  1.2    ichiro 			  ixpcom_cr & ~ixpcom_imask);
    795  1.1    ichiro }
    796  1.1    ichiro 
    797  1.1    ichiro /* Initialization for serial console */
    798  1.6   thorpej static int
    799  1.6   thorpej ixpcominit(bus_space_tag_t iot, bus_addr_t iobase, int baud,
    800  1.6   thorpej     tcflag_t cflag, bus_space_handle_t *iohp)
    801  1.1    ichiro {
    802  1.1    ichiro 	int cr;
    803  1.1    ichiro 
    804  1.1    ichiro 	if (bus_space_map(iot, iobase, IXPCOM_UART_SIZE, 0, iohp))
    805  1.1    ichiro 		printf("register map failed\n");
    806  1.1    ichiro 
    807  1.1    ichiro 	cr = cflag2cr(cflag);
    808  1.2    ichiro 	cr |= IXPCOMSPEED2BRD(baud);
    809  1.1    ichiro 	cr |= CR_UE;
    810  1.1    ichiro 	ixpcom_cr = cr;
    811  1.1    ichiro 
    812  1.1    ichiro 	/* enable the UART */
    813  1.1    ichiro 	bus_space_write_4(iot, *iohp, IXPCOM_CR, cr);
    814  1.1    ichiro 
    815  1.1    ichiro 	return (0);
    816  1.1    ichiro }
    817  1.1    ichiro 
    818  1.1    ichiro int
    819  1.1    ichiro ixpcomcnattach(iot, iobase, rate, cflag)
    820  1.1    ichiro 	bus_space_tag_t iot;
    821  1.1    ichiro 	bus_addr_t iobase;
    822  1.1    ichiro 	int rate;
    823  1.1    ichiro 	tcflag_t cflag;
    824  1.1    ichiro {
    825  1.1    ichiro 	int res;
    826  1.1    ichiro 
    827  1.1    ichiro 	if ((res = ixpcominit(iot, iobase, rate, cflag, &ixpcomconsioh)))
    828  1.1    ichiro 		return (res);
    829  1.1    ichiro 	cn_tab = &ixpcomcons;
    830  1.2    ichiro 	cn_init_magic(&ixpcom_cnm_state);
    831  1.2    ichiro 	/*
    832  1.2    ichiro 	 * XXX
    833  1.2    ichiro 	 *
    834  1.2    ichiro 	 * ixpcom cannot detect a break.  It can only detect framing
    835  1.2    ichiro 	 * errors.  And, a sequence of "framing error, framing error"
    836  1.2    ichiro 	 * meens a break.  So I made this hack:
    837  1.2    ichiro 	 *
    838  1.2    ichiro 	 * 1. Set default magic is a sequence of "BREAK, BREAK".
    839  1.2    ichiro 	 * 2. Tell cn_check_magic() a "framing error" as BREAK.
    840  1.2    ichiro 	 *
    841  1.2    ichiro 	 * see ixpcom_intr() too.
    842  1.2    ichiro 	 *
    843  1.2    ichiro 	 */
    844  1.2    ichiro 	/* default magic is a couple of BREAK. */
    845  1.2    ichiro 	cn_set_magic("\047\001\047\001");
    846  1.1    ichiro 
    847  1.1    ichiro 	ixpcomconstag = iot;
    848  1.1    ichiro 	ixpcomconsaddr = iobase;
    849  1.1    ichiro 	ixpcomconsrate = rate;
    850  1.1    ichiro 	ixpcomconscflag = cflag;
    851  1.1    ichiro 
    852  1.1    ichiro 	return (0);
    853  1.1    ichiro }
    854  1.1    ichiro 
    855  1.1    ichiro void
    856  1.1    ichiro ixpcomcninit(cp)
    857  1.1    ichiro 	struct consdev *cp;
    858  1.1    ichiro {
    859  1.2    ichiro 	printf("ixpcomcninit called\n");
    860  1.2    ichiro #if 0
    861  1.1    ichiro 	if (cp == NULL) {
    862  1.1    ichiro 		/* XXX cp == NULL means that MMU is disabled. */
    863  1.1    ichiro 		ixpcomconsioh = IXPCOM_UART_BASE;
    864  1.1    ichiro 		ixpcomconstag = &ixpcom_bs_tag;
    865  1.1    ichiro 		cn_tab = &ixpcomcons;
    866  1.1    ichiro 
    867  1.1    ichiro 		IXPREG(IXPCOM_UART_BASE + IXPCOM_CR)
    868  1.2    ichiro 			= IXPCOMSPEED2BRD(DEFAULT_COMSPEED)
    869  1.1    ichiro 			| DSS_8BIT
    870  1.1    ichiro 			| (CR_UE | CR_RIE | CR_XIE);
    871  1.1    ichiro 		return;
    872  1.1    ichiro 	}
    873  1.1    ichiro 
    874  1.1    ichiro 	if (ixpcominit(&ixpcom_bs_tag, CONADDR, CONSPEED,
    875  1.1    ichiro                           CONMODE, &ixpcomconsioh))
    876  1.1    ichiro 		panic("can't init serial console @%x", CONADDR);
    877  1.1    ichiro 	cn_tab = &ixpcomcons;
    878  1.1    ichiro 	ixpcomconstag = &ixpcom_bs_tag;
    879  1.2    ichiro #endif
    880  1.1    ichiro }
    881  1.1    ichiro 
    882  1.1    ichiro void
    883  1.1    ichiro ixpcomcnprobe(cp)
    884  1.1    ichiro 	struct consdev *cp;
    885  1.1    ichiro {
    886  1.1    ichiro 	cp->cn_pri = CN_REMOTE;
    887  1.1    ichiro }
    888  1.1    ichiro 
    889  1.1    ichiro void
    890  1.1    ichiro ixpcomcnpollc(dev, on)
    891  1.1    ichiro 	dev_t dev;
    892  1.1    ichiro 	int on;
    893  1.1    ichiro {
    894  1.1    ichiro }
    895  1.1    ichiro 
    896  1.1    ichiro void
    897  1.1    ichiro ixpcomcnputc(dev, c)
    898  1.1    ichiro 	dev_t dev;
    899  1.1    ichiro 	int c;
    900  1.1    ichiro {
    901  1.1    ichiro 	int s;
    902  1.1    ichiro 
    903  1.1    ichiro 	s = spltty();   /* XXX do we need this? */
    904  1.1    ichiro 
    905  1.1    ichiro 	while(!(bus_space_read_4(ixpcomconstag, ixpcomconsioh, IXPCOM_SR)
    906  1.1    ichiro 	    & SR_TXR))
    907  1.1    ichiro 		;
    908  1.1    ichiro 
    909  1.1    ichiro 	bus_space_write_4(ixpcomconstag, ixpcomconsioh, IXPCOM_DR, c);
    910  1.2    ichiro 
    911  1.2    ichiro #ifdef DEBUG
    912  1.2    ichiro 	if (c == '\r') {
    913  1.2    ichiro 		while(!(bus_space_read_4(ixpcomconstag, ixpcomconsioh,
    914  1.2    ichiro 					 IXPCOM_SR)
    915  1.2    ichiro 			& SR_TXE))
    916  1.2    ichiro 			;
    917  1.2    ichiro 	}
    918  1.2    ichiro #endif
    919  1.2    ichiro 
    920  1.1    ichiro 	splx(s);
    921  1.1    ichiro }
    922  1.1    ichiro 
    923  1.1    ichiro int
    924  1.1    ichiro ixpcomcngetc(dev)
    925  1.1    ichiro         dev_t dev;
    926  1.1    ichiro {
    927  1.1    ichiro         int c, s;
    928  1.1    ichiro 
    929  1.1    ichiro         s = spltty();   /* XXX do we need this? */
    930  1.1    ichiro 
    931  1.1    ichiro 	while(!(bus_space_read_4(ixpcomconstag, ixpcomconsioh, IXPCOM_SR)
    932  1.1    ichiro 	    & SR_RXR))
    933  1.1    ichiro 		;
    934  1.1    ichiro 
    935  1.1    ichiro 	c = bus_space_read_4(ixpcomconstag, ixpcomconsioh, IXPCOM_DR);
    936  1.1    ichiro 	c &= 0xff;
    937  1.1    ichiro 	splx(s);
    938  1.1    ichiro 
    939  1.1    ichiro 	return (c);
    940  1.1    ichiro }
    941  1.1    ichiro 
    942  1.1    ichiro inline static void
    943  1.1    ichiro ixpcom_txsoft(sc, tp)
    944  1.1    ichiro 	struct ixpcom_softc *sc;
    945  1.1    ichiro 	struct tty *tp;
    946  1.1    ichiro {
    947  1.2    ichiro 	CLR(tp->t_state, TS_BUSY);
    948  1.2    ichiro 	if (ISSET(tp->t_state, TS_FLUSH))
    949  1.2    ichiro 		CLR(tp->t_state, TS_FLUSH);
    950  1.2    ichiro         else
    951  1.2    ichiro 		ndflush(&tp->t_outq, (int)(sc->sc_tba - tp->t_outq.c_cf));
    952  1.2    ichiro 	(*tp->t_linesw->l_start)(tp);
    953  1.1    ichiro }
    954  1.1    ichiro 
    955  1.1    ichiro inline static void
    956  1.1    ichiro ixpcom_rxsoft(sc, tp)
    957  1.1    ichiro 	struct ixpcom_softc *sc;
    958  1.1    ichiro 	struct tty *tp;
    959  1.1    ichiro {
    960  1.1    ichiro 	int (*rint) __P((int c, struct tty *tp)) = tp->t_linesw->l_rint;
    961  1.1    ichiro 	u_char *get, *end;
    962  1.1    ichiro 	u_int cc, scc;
    963  1.1    ichiro 	u_char lsr;
    964  1.1    ichiro 	int code;
    965  1.1    ichiro 	int s;
    966  1.1    ichiro 
    967  1.1    ichiro 	end = sc->sc_ebuf;
    968  1.1    ichiro 	get = sc->sc_rbget;
    969  1.1    ichiro 	scc = cc = IXPCOM_RING_SIZE - sc->sc_rbavail;
    970  1.1    ichiro #if 0
    971  1.1    ichiro 	if (cc == IXPCOM_RING_SIZE) {
    972  1.1    ichiro 		sc->sc_floods++;
    973  1.1    ichiro 		if (sc->sc_errors++ == 0)
    974  1.1    ichiro 			callout_reset(&sc->sc_diag_callout, 60 * hz,
    975  1.1    ichiro 			    comdiag, sc);
    976  1.1    ichiro 	}
    977  1.1    ichiro #endif
    978  1.1    ichiro 	while (cc) {
    979  1.1    ichiro 		code = get[0];
    980  1.1    ichiro 		lsr = get[1];
    981  1.1    ichiro 		if (ISSET(lsr, DR_ROR | DR_FRE | DR_PRE)) {
    982  1.1    ichiro #if 0
    983  1.1    ichiro 			if (ISSET(lsr, DR_ROR)) {
    984  1.1    ichiro 				sc->sc_overflows++;
    985  1.1    ichiro 				if (sc->sc_errors++ == 0)
    986  1.1    ichiro 					callout_reset(&sc->sc_diag_callout,
    987  1.1    ichiro 					    60 * hz, comdiag, sc);
    988  1.1    ichiro 			}
    989  1.1    ichiro #endif
    990  1.1    ichiro 			if (ISSET(lsr, DR_FRE))
    991  1.1    ichiro 				SET(code, TTY_FE);
    992  1.1    ichiro 			if (ISSET(lsr, DR_PRE))
    993  1.1    ichiro 				SET(code, TTY_PE);
    994  1.1    ichiro 		}
    995  1.1    ichiro 		if ((*rint)(code, tp) == -1) {
    996  1.1    ichiro 			/*
    997  1.1    ichiro 			 * The line discipline's buffer is out of space.
    998  1.1    ichiro 			 */
    999  1.1    ichiro 			if (!ISSET(sc->sc_rx_flags, RX_TTY_BLOCKED)) {
   1000  1.1    ichiro 				/*
   1001  1.1    ichiro 				 * We're either not using flow control, or the
   1002  1.1    ichiro 				 * line discipline didn't tell us to block for
   1003  1.1    ichiro 				 * some reason.  Either way, we have no way to
   1004  1.1    ichiro 				 * know when there's more space available, so
   1005  1.1    ichiro 				 * just drop the rest of the data.
   1006  1.1    ichiro 				 */
   1007  1.1    ichiro 				get += cc << 1;
   1008  1.1    ichiro 				if (get >= end)
   1009  1.1    ichiro 					get -= IXPCOM_RING_SIZE << 1;
   1010  1.1    ichiro 				cc = 0;
   1011  1.1    ichiro 			} else {
   1012  1.1    ichiro 				/*
   1013  1.1    ichiro 				 * Don't schedule any more receive processing
   1014  1.1    ichiro 				 * until the line discipline tells us there's
   1015  1.1    ichiro 				 * space available (through comhwiflow()).
   1016  1.1    ichiro 				 * Leave the rest of the data in the input
   1017  1.1    ichiro 				 * buffer.
   1018  1.1    ichiro 				 */
   1019  1.1    ichiro 				SET(sc->sc_rx_flags, RX_TTY_OVERFLOWED);
   1020  1.1    ichiro 			}
   1021  1.1    ichiro 			break;
   1022  1.1    ichiro 		}
   1023  1.1    ichiro 		get += 2;
   1024  1.1    ichiro 		if (get >= end)
   1025  1.1    ichiro 			get = sc->sc_rbuf;
   1026  1.1    ichiro 		cc--;
   1027  1.1    ichiro 	}
   1028  1.1    ichiro 
   1029  1.1    ichiro 	if (cc != scc) {
   1030  1.1    ichiro 		sc->sc_rbget = get;
   1031  1.1    ichiro 		s = splserial();
   1032  1.1    ichiro 		COM_LOCK(sc);
   1033  1.1    ichiro 
   1034  1.1    ichiro 		cc = sc->sc_rbavail += scc - cc;
   1035  1.1    ichiro 		/* Buffers should be ok again, release possible block. */
   1036  1.1    ichiro 		if (cc >= 1) {
   1037  1.1    ichiro 			if (ISSET(sc->sc_rx_flags, RX_IBUF_OVERFLOWED)) {
   1038  1.1    ichiro 				CLR(sc->sc_rx_flags, RX_IBUF_OVERFLOWED);
   1039  1.1    ichiro 				SET(sc->sc_rie, CR_RIE);
   1040  1.2    ichiro 				ixpcom_set_cr(sc);
   1041  1.1    ichiro 			}
   1042  1.1    ichiro 			if (ISSET(sc->sc_rx_flags, RX_IBUF_BLOCKED)) {
   1043  1.1    ichiro 				CLR(sc->sc_rx_flags, RX_IBUF_BLOCKED);
   1044  1.1    ichiro #if 0
   1045  1.1    ichiro 				com_hwiflow(sc);
   1046  1.1    ichiro #endif
   1047  1.1    ichiro 			}
   1048  1.1    ichiro 		}
   1049  1.1    ichiro 		COM_UNLOCK(sc);
   1050  1.1    ichiro 		splx(s);
   1051  1.1    ichiro 	}
   1052  1.1    ichiro }
   1053  1.1    ichiro 
   1054  1.1    ichiro static void
   1055  1.1    ichiro ixpcomsoft(void* arg)
   1056  1.1    ichiro {
   1057  1.1    ichiro 	struct ixpcom_softc *sc = arg;
   1058  1.1    ichiro 
   1059  1.1    ichiro 	if (COM_ISALIVE(sc) == 0)
   1060  1.1    ichiro 		return;
   1061  1.1    ichiro 
   1062  1.1    ichiro 	if (sc->sc_rx_ready) {
   1063  1.1    ichiro 		sc->sc_rx_ready = 0;
   1064  1.1    ichiro 		ixpcom_rxsoft(sc, sc->sc_tty);
   1065  1.1    ichiro 	}
   1066  1.1    ichiro 	if (sc->sc_tx_done) {
   1067  1.1    ichiro 		sc->sc_tx_done = 0;
   1068  1.1    ichiro 		ixpcom_txsoft(sc, sc->sc_tty);
   1069  1.1    ichiro 	}
   1070  1.1    ichiro }
   1071  1.1    ichiro 
   1072  1.2    ichiro int
   1073  1.1    ichiro ixpcomintr(void* arg)
   1074  1.1    ichiro {
   1075  1.1    ichiro 	struct ixpcom_softc *sc = arg;
   1076  1.1    ichiro 	bus_space_tag_t iot = sc->sc_iot;
   1077  1.1    ichiro 	bus_space_handle_t ioh = sc->sc_ioh;
   1078  1.1    ichiro 	u_char *put, *end;
   1079  1.1    ichiro 	u_int cc;
   1080  1.1    ichiro 	u_int cr;
   1081  1.1    ichiro 	u_int sr;
   1082  1.1    ichiro 	u_int32_t c;
   1083  1.1    ichiro 
   1084  1.1    ichiro 	if (COM_ISALIVE(sc) == 0)
   1085  1.1    ichiro 		return (0);
   1086  1.1    ichiro 
   1087  1.1    ichiro 	COM_LOCK(sc);
   1088  1.1    ichiro 	cr = bus_space_read_4(iot, ioh, IXPCOM_CR) & CR_UE;
   1089  1.1    ichiro 
   1090  1.1    ichiro 	if (!cr) {
   1091  1.1    ichiro 		COM_UNLOCK(sc);
   1092  1.1    ichiro 		return (0);
   1093  1.1    ichiro 	}
   1094  1.1    ichiro 
   1095  1.1    ichiro 	sr = bus_space_read_4(iot, ioh, IXPCOM_SR);
   1096  1.1    ichiro 	if (!ISSET(sr, SR_TXR | SR_RXR))
   1097  1.1    ichiro 		return (0);
   1098  1.1    ichiro 
   1099  1.1    ichiro 	/*
   1100  1.2    ichiro 	 * XXX
   1101  1.2    ichiro 	 *
   1102  1.2    ichiro 	 * ixpcom cannot detect a break.  It can only detect framing
   1103  1.2    ichiro 	 * errors.  And, a sequence of "framing error, framing error"
   1104  1.2    ichiro 	 * meens a break.  So I made this hack:
   1105  1.2    ichiro 	 *
   1106  1.2    ichiro 	 * 1. Set default magic is a sequence of "BREAK, BREAK".
   1107  1.2    ichiro 	 * 2. Tell cn_check_magic() a "framing error" as BREAK.
   1108  1.2    ichiro 	 *
   1109  1.2    ichiro 	 * see ixpcomcnattach() too.
   1110  1.2    ichiro 	 *
   1111  1.1    ichiro 	 */
   1112  1.2    ichiro 	if (ISSET(sr, SR_FRE)) {
   1113  1.2    ichiro 		cn_check_magic(sc->sc_tty->t_dev,
   1114  1.2    ichiro 			       CNC_BREAK, ixpcom_cnm_state);
   1115  1.1    ichiro 	}
   1116  1.1    ichiro 
   1117  1.1    ichiro 	end = sc->sc_ebuf;
   1118  1.1    ichiro 	put = sc->sc_rbput;
   1119  1.1    ichiro 	cc = sc->sc_rbavail;
   1120  1.1    ichiro 
   1121  1.1    ichiro 	if (ISSET(sr, SR_RXR)) {
   1122  1.1    ichiro 		if (!ISSET(sc->sc_rx_flags, RX_IBUF_OVERFLOWED)) {
   1123  1.1    ichiro 			while (cc > 0) {
   1124  1.1    ichiro 				if (!ISSET(sr, SR_RXR))
   1125  1.1    ichiro 					break;
   1126  1.1    ichiro 				c = bus_space_read_4(iot, ioh, IXPCOM_DR);
   1127  1.2    ichiro 				if (ISSET(c, DR_FRE)) {
   1128  1.2    ichiro 					cn_check_magic(sc->sc_tty->t_dev,
   1129  1.2    ichiro 						       CNC_BREAK,
   1130  1.2    ichiro 						       ixpcom_cnm_state);
   1131  1.2    ichiro 				}
   1132  1.1    ichiro 				put[0] = c & 0xff;
   1133  1.1    ichiro 				put[1] = (c >> 8) & 0xff;
   1134  1.2    ichiro 				cn_check_magic(sc->sc_tty->t_dev,
   1135  1.2    ichiro 					       put[0], ixpcom_cnm_state);
   1136  1.1    ichiro 				put += 2;
   1137  1.1    ichiro 				if (put >= end)
   1138  1.1    ichiro 					put = sc->sc_rbuf;
   1139  1.1    ichiro 				cc--;
   1140  1.1    ichiro 
   1141  1.1    ichiro 				sr = bus_space_read_4(iot, ioh, IXPCOM_SR);
   1142  1.1    ichiro 			}
   1143  1.1    ichiro 
   1144  1.1    ichiro 			/*
   1145  1.1    ichiro 			 * Current string of incoming characters ended because
   1146  1.1    ichiro 			 * no more data was available or we ran out of space.
   1147  1.1    ichiro 			 * Schedule a receive event if any data was received.
   1148  1.1    ichiro 			 * If we're out of space, turn off receive interrupts.
   1149  1.1    ichiro 			 */
   1150  1.1    ichiro 			sc->sc_rbput = put;
   1151  1.1    ichiro 			sc->sc_rbavail = cc;
   1152  1.1    ichiro 			if (!ISSET(sc->sc_rx_flags, RX_TTY_OVERFLOWED))
   1153  1.1    ichiro 				sc->sc_rx_ready = 1;
   1154  1.1    ichiro 
   1155  1.2    ichiro 			/*
   1156  1.2    ichiro 			 * See if we are in danger of overflowing a buffer. If
   1157  1.2    ichiro 			 * so, use hardware flow control to ease the pressure.
   1158  1.2    ichiro 			 */
   1159  1.2    ichiro 
   1160  1.2    ichiro 			/* but ixpcom cannot. X-( */
   1161  1.1    ichiro 
   1162  1.1    ichiro 			/*
   1163  1.1    ichiro 			 * If we're out of space, disable receive interrupts
   1164  1.1    ichiro 			 * until the queue has drained a bit.
   1165  1.1    ichiro 			 */
   1166  1.1    ichiro 			if (!cc) {
   1167  1.1    ichiro 				SET(sc->sc_rx_flags, RX_IBUF_OVERFLOWED);
   1168  1.1    ichiro 				CLR(sc->sc_rie, CR_RIE);
   1169  1.2    ichiro 				ixpcom_set_cr(sc);
   1170  1.1    ichiro 			}
   1171  1.1    ichiro 		} else {
   1172  1.1    ichiro #ifdef DIAGNOSTIC
   1173  1.5    provos 			panic("ixpcomintr: we shouldn't reach here");
   1174  1.1    ichiro #endif
   1175  1.1    ichiro 			CLR(sc->sc_rie, CR_RIE);
   1176  1.2    ichiro 			ixpcom_set_cr(sc);
   1177  1.1    ichiro 		}
   1178  1.1    ichiro 	}
   1179  1.1    ichiro 
   1180  1.1    ichiro 	/*
   1181  1.1    ichiro 	 * Done handling any receive interrupts. See if data can be
   1182  1.1    ichiro 	 * transmitted as well. Schedule tx done event if no data left
   1183  1.1    ichiro 	 * and tty was marked busy.
   1184  1.1    ichiro 	 */
   1185  1.1    ichiro 	sr = bus_space_read_4(iot, ioh, IXPCOM_SR);
   1186  1.1    ichiro 	if (ISSET(sr, SR_TXR)) {
   1187  1.1    ichiro 		/*
   1188  1.1    ichiro 		 * If we've delayed a parameter change, do it now, and restart
   1189  1.1    ichiro 		 * output.
   1190  1.1    ichiro 		 */
   1191  1.1    ichiro 		if (sc->sc_heldchange) {
   1192  1.2    ichiro 			ixpcom_set_cr(sc);
   1193  1.1    ichiro 			sc->sc_heldchange = 0;
   1194  1.1    ichiro 			sc->sc_tbc = sc->sc_heldtbc;
   1195  1.1    ichiro 			sc->sc_heldtbc = 0;
   1196  1.1    ichiro 		}
   1197  1.1    ichiro 
   1198  1.1    ichiro 		/* Output the next chunk of the contiguous buffer, if any. */
   1199  1.1    ichiro 		if (sc->sc_tbc > 0) {
   1200  1.2    ichiro 			ixpcom_filltx(sc);
   1201  1.1    ichiro 		} else {
   1202  1.1    ichiro 			/* Disable transmit completion interrupts if necessary. */
   1203  1.2    ichiro 			if (ISSET(sc->sc_xie, CR_XIE)) {
   1204  1.2    ichiro 				CLR(sc->sc_xie, CR_XIE);
   1205  1.2    ichiro 				ixpcom_set_cr(sc);
   1206  1.1    ichiro 			}
   1207  1.1    ichiro 			if (sc->sc_tx_busy) {
   1208  1.1    ichiro 				sc->sc_tx_busy = 0;
   1209  1.1    ichiro 				sc->sc_tx_done = 1;
   1210  1.1    ichiro 			}
   1211  1.1    ichiro 		}
   1212  1.1    ichiro 	}
   1213  1.1    ichiro 	COM_UNLOCK(sc);
   1214  1.1    ichiro 
   1215  1.1    ichiro 	/* Wake up the poller. */
   1216  1.1    ichiro #ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
   1217  1.1    ichiro 	softintr_schedule(sc->sc_si);
   1218  1.1    ichiro #else
   1219  1.1    ichiro 	setsoftserial();
   1220  1.1    ichiro #endif
   1221  1.1    ichiro 
   1222  1.1    ichiro #if NRND > 0 && defined(RND_COM)
   1223  1.1    ichiro 	rnd_add_uint32(&sc->rnd_source, iir | lsr);
   1224  1.1    ichiro #endif
   1225  1.1    ichiro 	return (1);
   1226  1.1    ichiro }
   1227  1.2    ichiro 
   1228