Home | History | Annotate | Line # | Download | only in qbus
dl.c revision 1.46
      1  1.46     rmind /*	$NetBSD: dl.c,v 1.46 2011/04/24 16:27:00 rmind Exp $	*/
      2   1.2   thorpej 
      3   1.2   thorpej /*-
      4   1.2   thorpej  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
      5   1.2   thorpej  * All rights reserved.
      6   1.2   thorpej  *
      7   1.2   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8   1.2   thorpej  * by Jason R. Thorpe.
      9   1.2   thorpej  *
     10   1.2   thorpej  * Redistribution and use in source and binary forms, with or without
     11   1.2   thorpej  * modification, are permitted provided that the following conditions
     12   1.2   thorpej  * are met:
     13   1.2   thorpej  * 1. Redistributions of source code must retain the above copyright
     14   1.2   thorpej  *    notice, this list of conditions and the following disclaimer.
     15   1.2   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.2   thorpej  *    notice, this list of conditions and the following disclaimer in the
     17   1.2   thorpej  *    documentation and/or other materials provided with the distribution.
     18   1.2   thorpej  *
     19   1.2   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.2   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.2   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.2   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.2   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.2   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.2   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.2   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.2   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.2   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.2   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     30   1.2   thorpej  */
     31   1.2   thorpej 
     32   1.1     ragge /*
     33  1.28     bjh21  * Copyright (c) 1997  Ben Harris.  All rights reserved.
     34  1.27       agc  * Copyright (c) 1982, 1986, 1990, 1992, 1993
     35  1.27       agc  *	The Regents of the University of California.  All rights reserved.
     36  1.27       agc  *
     37  1.27       agc  * This code is derived from software contributed to Berkeley by
     38  1.27       agc  * Ralph Campbell and Rick Macklem.
     39  1.27       agc  *
     40  1.27       agc  * Redistribution and use in source and binary forms, with or without
     41  1.27       agc  * modification, are permitted provided that the following conditions
     42  1.27       agc  * are met:
     43  1.27       agc  * 1. Redistributions of source code must retain the above copyright
     44  1.27       agc  *    notice, this list of conditions and the following disclaimer.
     45  1.27       agc  * 2. Redistributions in binary form must reproduce the above copyright
     46  1.27       agc  *    notice, this list of conditions and the following disclaimer in the
     47  1.27       agc  *    documentation and/or other materials provided with the distribution.
     48  1.27       agc  * 3. Neither the name of the University nor the names of its contributors
     49  1.27       agc  *    may be used to endorse or promote products derived from this software
     50  1.27       agc  *    without specific prior written permission.
     51  1.27       agc  *
     52  1.27       agc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     53  1.27       agc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     54  1.27       agc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     55  1.27       agc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     56  1.27       agc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     57  1.27       agc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     58  1.27       agc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     59  1.27       agc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     60  1.27       agc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     61  1.27       agc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     62  1.27       agc  * SUCH DAMAGE.
     63  1.27       agc  */
     64  1.27       agc 
     65  1.27       agc /*
     66   1.1     ragge  * Copyright (c) 1996  Ken C. Wellsch.  All rights reserved.
     67   1.1     ragge  *
     68   1.1     ragge  * This code is derived from software contributed to Berkeley by
     69   1.1     ragge  * Ralph Campbell and Rick Macklem.
     70   1.1     ragge  *
     71   1.1     ragge  * Redistribution and use in source and binary forms, with or without
     72   1.1     ragge  * modification, are permitted provided that the following conditions
     73   1.1     ragge  * are met:
     74   1.1     ragge  * 1. Redistributions of source code must retain the above copyright
     75   1.1     ragge  *    notice, this list of conditions and the following disclaimer.
     76   1.1     ragge  * 2. Redistributions in binary form must reproduce the above copyright
     77   1.1     ragge  *    notice, this list of conditions and the following disclaimer in the
     78   1.1     ragge  *    documentation and/or other materials provided with the distribution.
     79   1.1     ragge  * 3. All advertising materials mentioning features or use of this software
     80   1.1     ragge  *    must display the following acknowledgement:
     81   1.1     ragge  *	This product includes software developed by the University of
     82   1.1     ragge  *	California, Berkeley and its contributors.
     83   1.1     ragge  * 4. Neither the name of the University nor the names of its contributors
     84   1.1     ragge  *    may be used to endorse or promote products derived from this software
     85   1.1     ragge  *    without specific prior written permission.
     86   1.1     ragge  *
     87   1.1     ragge  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     88   1.1     ragge  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     89   1.1     ragge  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     90   1.1     ragge  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     91   1.1     ragge  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     92   1.1     ragge  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     93   1.1     ragge  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     94   1.1     ragge  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     95   1.1     ragge  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     96   1.1     ragge  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     97   1.1     ragge  * SUCH DAMAGE.
     98   1.1     ragge  */
     99   1.1     ragge 
    100   1.1     ragge /*
    101   1.1     ragge  * dl.c -- Device driver for the DL11 and DLV11 serial cards.
    102   1.1     ragge  *
    103   1.1     ragge  * OS-interface code derived from the dz and dca (hp300) drivers.
    104   1.1     ragge  */
    105  1.19     lukem 
    106  1.19     lukem #include <sys/cdefs.h>
    107  1.46     rmind __KERNEL_RCSID(0, "$NetBSD: dl.c,v 1.46 2011/04/24 16:27:00 rmind Exp $");
    108   1.1     ragge 
    109   1.1     ragge #include <sys/param.h>
    110   1.1     ragge #include <sys/systm.h>
    111   1.1     ragge #include <sys/ioctl.h>
    112   1.1     ragge #include <sys/tty.h>
    113   1.1     ragge #include <sys/proc.h>
    114   1.1     ragge #include <sys/buf.h>
    115   1.1     ragge #include <sys/conf.h>
    116   1.1     ragge #include <sys/file.h>
    117   1.1     ragge #include <sys/uio.h>
    118   1.1     ragge #include <sys/kernel.h>
    119   1.1     ragge #include <sys/syslog.h>
    120   1.1     ragge #include <sys/device.h>
    121  1.34      yamt #include <sys/kauth.h>
    122   1.1     ragge 
    123  1.38        ad #include <sys/bus.h>
    124   1.1     ragge 
    125  1.10     ragge #include <dev/qbus/ubavar.h>
    126   1.1     ragge 
    127  1.10     ragge #include <dev/qbus/dlreg.h>
    128   1.1     ragge 
    129   1.7     ragge #include "ioconf.h"
    130   1.1     ragge 
    131   1.1     ragge struct dl_softc {
    132   1.1     ragge 	struct device	sc_dev;
    133  1.13      matt 	struct evcnt	sc_rintrcnt;
    134  1.13      matt 	struct evcnt	sc_tintrcnt;
    135   1.7     ragge 	bus_space_tag_t	sc_iot;
    136   1.7     ragge 	bus_space_handle_t sc_ioh;
    137   1.7     ragge 	struct tty	*sc_tty;
    138   1.1     ragge };
    139   1.1     ragge 
    140  1.45    cegger static	int	dl_match (device_t, cfdata_t, void *);
    141  1.45    cegger static	void	dl_attach (device_t, device_t, void *);
    142  1.13      matt static	void	dlrint (void *);
    143  1.13      matt static	void	dlxint (void *);
    144  1.13      matt static	void	dlstart (struct tty *);
    145  1.13      matt static	int	dlparam (struct tty *, struct termios *);
    146  1.13      matt static	void	dlbrk (struct dl_softc *, int);
    147   1.1     ragge 
    148  1.24   thorpej CFATTACH_DECL(dl, sizeof(struct dl_softc),
    149  1.25   thorpej     dl_match, dl_attach, NULL, NULL);
    150  1.21   gehenna 
    151  1.21   gehenna dev_type_open(dlopen);
    152  1.21   gehenna dev_type_close(dlclose);
    153  1.21   gehenna dev_type_read(dlread);
    154  1.21   gehenna dev_type_write(dlwrite);
    155  1.21   gehenna dev_type_ioctl(dlioctl);
    156  1.21   gehenna dev_type_stop(dlstop);
    157  1.21   gehenna dev_type_tty(dltty);
    158  1.21   gehenna dev_type_poll(dlpoll);
    159  1.21   gehenna 
    160  1.21   gehenna const struct cdevsw dl_cdevsw = {
    161  1.21   gehenna 	dlopen, dlclose, dlread, dlwrite, dlioctl,
    162  1.26  jdolecek 	dlstop, dltty, dlpoll, nommap, ttykqfilter, D_TTY
    163   1.1     ragge };
    164   1.3   thorpej 
    165   1.7     ragge #define	DL_READ_WORD(reg) \
    166   1.7     ragge 	bus_space_read_2(sc->sc_iot, sc->sc_ioh, reg)
    167   1.7     ragge #define	DL_WRITE_WORD(reg, val) \
    168   1.7     ragge 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, reg, val)
    169   1.7     ragge #define	DL_WRITE_BYTE(reg, val) \
    170   1.7     ragge 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, reg, val)
    171   1.1     ragge 
    172   1.1     ragge /* Autoconfig handles: setup the controller to interrupt, */
    173   1.1     ragge /* then complete the housecleaning for full operation */
    174   1.1     ragge 
    175   1.1     ragge static int
    176  1.45    cegger dl_match (device_t parent, cfdata_t cf, void *aux)
    177   1.1     ragge {
    178   1.1     ragge 	struct uba_attach_args *ua = aux;
    179   1.1     ragge 
    180   1.1     ragge #ifdef DL_DEBUG
    181   1.7     ragge 	printf("Probing for dl at %lo ... ", (long)ua->ua_iaddr);
    182   1.1     ragge #endif
    183   1.1     ragge 
    184   1.7     ragge 	bus_space_write_2(ua->ua_iot, ua->ua_ioh, DL_UBA_XCSR, DL_XCSR_TXIE);
    185   1.7     ragge 	if (bus_space_read_2(ua->ua_iot, ua->ua_ioh, DL_UBA_XCSR) !=
    186   1.7     ragge 	    (DL_XCSR_TXIE | DL_XCSR_TX_READY)) {
    187   1.1     ragge #ifdef DL_DEBUG
    188  1.29    simonb 		printf("failed (step 1; XCSR = %.4b)\n",
    189  1.29    simonb 		    bus_space_read_2(ua->ua_iot, ua->ua_ioh, DL_UBA_XCSR),
    190   1.7     ragge 		    DL_XCSR_BITS);
    191   1.1     ragge #endif
    192   1.1     ragge 		return 0;
    193   1.1     ragge 	}
    194  1.29    simonb 
    195   1.1     ragge 	/*
    196   1.1     ragge 	 * We have to force an interrupt so the uba driver can work
    197   1.1     ragge 	 * out where we are.  Unfortunately, the only way to make a
    198   1.1     ragge 	 * DL11 interrupt is to get it to send or receive a
    199   1.1     ragge 	 * character.  We'll send a NUL and hope it doesn't hurt
    200   1.1     ragge 	 * anything.
    201   1.1     ragge 	 */
    202   1.1     ragge 
    203   1.7     ragge 	bus_space_write_1(ua->ua_iot, ua->ua_ioh, DL_UBA_XBUFL, '\0');
    204   1.1     ragge #if 0 /* This test seems to fail 2/3 of the time :-( */
    205   1.1     ragge 	if (dladdr->dl_xcsr != (DL_XCSR_TXIE)) {
    206   1.1     ragge #ifdef DL_DEBUG
    207  1.29    simonb 		printf("failed (step 2; XCSR = %.4b)\n", dladdr->dl_xcsr,
    208  1.29    simonb 		    DL_XCSR_BITS);
    209   1.1     ragge #endif
    210   1.1     ragge 		return 0;
    211   1.1     ragge 	}
    212   1.1     ragge #endif
    213   1.1     ragge 	DELAY(100000); /* delay 1/10 s for character to transmit */
    214   1.7     ragge 	if (bus_space_read_2(ua->ua_iot, ua->ua_ioh, DL_UBA_XCSR) !=
    215   1.7     ragge 	    (DL_XCSR_TXIE | DL_XCSR_TX_READY)) {
    216   1.1     ragge #ifdef DL_DEBUG
    217  1.29    simonb 		printf("failed (step 3; XCSR = %.4b)\n",
    218   1.7     ragge 		    bus_space_read_2(ua->ua_iot, ua->ua_ioh, DL_UBA_XCSR),
    219   1.7     ragge 		    DL_XCSR_BITS);
    220   1.1     ragge #endif
    221   1.1     ragge 		return 0;
    222   1.1     ragge 	}
    223   1.1     ragge 
    224   1.1     ragge 
    225  1.29    simonb 	/* What else do I need to do? */
    226   1.1     ragge 
    227   1.1     ragge 	return 1;
    228   1.1     ragge 
    229   1.1     ragge }
    230   1.1     ragge 
    231   1.1     ragge static void
    232  1.45    cegger dl_attach (device_t parent, device_t self, void *aux)
    233   1.1     ragge {
    234  1.32   thorpej 	struct dl_softc *sc = device_private(self);
    235  1.12  augustss 	struct uba_attach_args *ua = aux;
    236   1.1     ragge 
    237   1.7     ragge 	sc->sc_iot = ua->ua_iot;
    238   1.7     ragge 	sc->sc_ioh = ua->ua_ioh;
    239  1.29    simonb 
    240   1.1     ragge 	/* Tidy up the device */
    241   1.1     ragge 
    242   1.7     ragge 	DL_WRITE_WORD(DL_UBA_RCSR, DL_RCSR_RXIE);
    243   1.7     ragge 	DL_WRITE_WORD(DL_UBA_XCSR, DL_XCSR_TXIE);
    244   1.1     ragge 
    245   1.1     ragge 	/* Initialize our softc structure. Should be done in open? */
    246  1.29    simonb 
    247  1.46     rmind 	sc->sc_tty = tty_alloc();
    248   1.1     ragge 	tty_attach(sc->sc_tty);
    249   1.1     ragge 
    250  1.11      matt 	/* Now register the TX & RX interrupt handlers */
    251  1.13      matt 	uba_intr_establish(ua->ua_icookie, ua->ua_cvec,
    252  1.13      matt 		dlxint, sc, &sc->sc_tintrcnt);
    253  1.13      matt 	uba_intr_establish(ua->ua_icookie, ua->ua_cvec - 4,
    254  1.13      matt 		dlrint, sc, &sc->sc_rintrcnt);
    255  1.14      matt 	evcnt_attach_dynamic(&sc->sc_rintrcnt, EVCNT_TYPE_INTR, ua->ua_evcnt,
    256  1.40    cegger 		device_xname(&sc->sc_dev), "rintr");
    257  1.14      matt 	evcnt_attach_dynamic(&sc->sc_tintrcnt, EVCNT_TYPE_INTR, ua->ua_evcnt,
    258  1.40    cegger 		device_xname(&sc->sc_dev), "tintr");
    259   1.1     ragge 
    260   1.1     ragge 	printf("\n");
    261   1.1     ragge }
    262   1.1     ragge 
    263   1.1     ragge /* Receiver Interrupt Handler */
    264   1.1     ragge 
    265   1.1     ragge static void
    266  1.14      matt dlrint(void *arg)
    267   1.1     ragge {
    268  1.14      matt 	struct dl_softc *sc = arg;
    269   1.1     ragge 
    270   1.7     ragge 	if (DL_READ_WORD(DL_UBA_RCSR) & DL_RCSR_RX_DONE) {
    271  1.14      matt 		struct tty *tp = sc->sc_tty;
    272  1.14      matt 		unsigned c;
    273  1.14      matt 		int cc;
    274  1.14      matt 
    275  1.29    simonb 		c = DL_READ_WORD(DL_UBA_RBUF);
    276   1.1     ragge 		cc = c & 0xFF;
    277   1.1     ragge 
    278   1.1     ragge 		if (!(tp->t_state & TS_ISOPEN)) {
    279  1.42        ad 			cv_broadcast(&tp->t_rawcv);
    280   1.1     ragge 			return;
    281   1.1     ragge 		}
    282   1.1     ragge 
    283  1.14      matt 		if (c & DL_RBUF_OVERRUN_ERR) {
    284   1.1     ragge 			/*
    285   1.1     ragge 			 * XXX: This should really be logged somwhere
    286   1.1     ragge 			 * else where we can afford the time.
    287   1.1     ragge 			 */
    288   1.1     ragge 			log(LOG_WARNING, "%s: rx overrun\n",
    289  1.40    cegger 			    device_xname(&sc->sc_dev));
    290  1.14      matt 		}
    291   1.1     ragge 		if (c & DL_RBUF_FRAMING_ERR)
    292   1.1     ragge 			cc |= TTY_FE;
    293   1.1     ragge 		if (c & DL_RBUF_PARITY_ERR)
    294   1.1     ragge 			cc |= TTY_PE;
    295   1.1     ragge 
    296  1.15       eeh 		(*tp->t_linesw->l_rint)(cc, tp);
    297  1.14      matt #if defined(DIAGNOSTIC)
    298  1.14      matt 	} else {
    299   1.1     ragge 		log(LOG_WARNING, "%s: stray rx interrupt\n",
    300  1.40    cegger 		    device_xname(&sc->sc_dev));
    301  1.14      matt #endif
    302  1.14      matt 	}
    303   1.1     ragge }
    304   1.1     ragge 
    305   1.1     ragge /* Transmitter Interrupt Handler */
    306   1.1     ragge 
    307   1.1     ragge static void
    308  1.14      matt dlxint(void *arg)
    309   1.1     ragge {
    310  1.11      matt 	struct dl_softc *sc = arg;
    311  1.14      matt 	struct tty *tp = sc->sc_tty;
    312  1.14      matt 
    313   1.1     ragge 	tp->t_state &= ~(TS_BUSY | TS_FLUSH);
    314  1.16     enami 	(*tp->t_linesw->l_start)(tp);
    315  1.29    simonb 
    316   1.1     ragge 	return;
    317   1.1     ragge }
    318   1.1     ragge 
    319   1.1     ragge int
    320  1.31  christos dlopen(dev_t dev, int flag, int mode, struct lwp *l)
    321   1.1     ragge {
    322  1.12  augustss 	struct tty *tp;
    323  1.14      matt 	struct dl_softc *sc;
    324  1.12  augustss 	int unit;
    325   1.1     ragge 
    326   1.7     ragge 	unit = minor(dev);
    327   1.1     ragge 
    328  1.43  drochner 	sc = device_lookup_private(&dl_cd, unit);
    329  1.43  drochner 	if (!sc)
    330   1.1     ragge 		return ENXIO;
    331   1.1     ragge 
    332   1.1     ragge 	tp = sc->sc_tty;
    333   1.1     ragge 	if (tp == NULL)
    334   1.1     ragge 		return ENODEV;
    335   1.1     ragge 	tp->t_oproc = dlstart;
    336   1.1     ragge 	tp->t_param = dlparam;
    337   1.1     ragge 	tp->t_dev = dev;
    338   1.1     ragge 
    339  1.36      elad 	if (kauth_authorize_device_tty(l->l_cred, KAUTH_DEVICE_TTY_OPEN, tp))
    340  1.36      elad 		return (EBUSY);
    341  1.36      elad 
    342   1.1     ragge 	if (!(tp->t_state & TS_ISOPEN)) {
    343   1.1     ragge 		ttychars(tp);
    344   1.1     ragge 		tp->t_iflag = TTYDEF_IFLAG;
    345   1.1     ragge 		tp->t_oflag = TTYDEF_OFLAG;
    346   1.1     ragge 		/* No modem control, so set CLOCAL. */
    347   1.1     ragge 		tp->t_cflag = TTYDEF_CFLAG | CLOCAL;
    348   1.1     ragge 		tp->t_lflag = TTYDEF_LFLAG;
    349   1.1     ragge 		tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
    350  1.29    simonb 
    351   1.1     ragge 		dlparam(tp, &tp->t_termios);
    352   1.1     ragge 		ttsetwater(tp);
    353  1.29    simonb 
    354  1.36      elad 	}
    355   1.1     ragge 
    356  1.15       eeh 	return ((*tp->t_linesw->l_open)(dev, tp));
    357   1.1     ragge }
    358   1.1     ragge 
    359   1.1     ragge /*ARGSUSED*/
    360   1.1     ragge int
    361  1.31  christos dlclose(dev_t dev, int flag, int mode, struct lwp *l)
    362   1.1     ragge {
    363  1.43  drochner 	struct dl_softc *sc = device_lookup_private(&dl_cd, minor(dev));
    364  1.14      matt 	struct tty *tp = sc->sc_tty;
    365   1.1     ragge 
    366  1.15       eeh 	(*tp->t_linesw->l_close)(tp, flag);
    367   1.1     ragge 
    368   1.1     ragge 	/* Make sure a BREAK state is not left enabled. */
    369   1.1     ragge 	dlbrk(sc, 0);
    370   1.1     ragge 
    371   1.1     ragge 	return (ttyclose(tp));
    372   1.1     ragge }
    373   1.1     ragge 
    374   1.1     ragge int
    375  1.14      matt dlread(dev_t dev, struct uio *uio, int flag)
    376   1.1     ragge {
    377  1.43  drochner 	struct dl_softc *sc = device_lookup_private(&dl_cd, minor(dev));
    378  1.14      matt 	struct tty *tp = sc->sc_tty;
    379   1.1     ragge 
    380  1.15       eeh 	return ((*tp->t_linesw->l_read)(tp, uio, flag));
    381   1.1     ragge }
    382   1.1     ragge 
    383   1.1     ragge int
    384  1.14      matt dlwrite(dev_t dev, struct uio *uio, int flag)
    385   1.1     ragge {
    386  1.43  drochner 	struct dl_softc *sc = device_lookup_private(&dl_cd, minor(dev));
    387  1.14      matt 	struct tty *tp = sc->sc_tty;
    388   1.1     ragge 
    389  1.15       eeh 	return ((*tp->t_linesw->l_write)(tp, uio, flag));
    390  1.17       scw }
    391  1.17       scw 
    392  1.17       scw int
    393  1.31  christos dlpoll(dev_t dev, int events, struct lwp *l)
    394  1.17       scw {
    395  1.43  drochner 	struct dl_softc *sc = device_lookup_private(&dl_cd, minor(dev));
    396  1.17       scw 	struct tty *tp = sc->sc_tty;
    397  1.29    simonb 
    398  1.31  christos 	return ((*tp->t_linesw->l_poll)(tp, events, l));
    399   1.1     ragge }
    400   1.1     ragge 
    401   1.1     ragge int
    402  1.37  christos dlioctl(dev_t dev, unsigned long cmd, void *data, int flag, struct lwp *l)
    403   1.1     ragge {
    404  1.43  drochner 	struct dl_softc *sc = device_lookup_private(&dl_cd, minor(dev));
    405  1.29    simonb 	struct tty *tp = sc->sc_tty;
    406  1.29    simonb 	int error;
    407   1.1     ragge 
    408   1.1     ragge 
    409  1.31  christos 	error = (*tp->t_linesw->l_ioctl)(tp, cmd, data, flag, l);
    410  1.29    simonb 	if (error != EPASSTHROUGH)
    411  1.29    simonb 		return (error);
    412  1.20    atatat 
    413  1.31  christos 	error = ttioctl(tp, cmd, data, flag, l);
    414  1.29    simonb 	if (error != EPASSTHROUGH)
    415  1.29    simonb 		return (error);
    416   1.1     ragge 
    417   1.1     ragge 	switch (cmd) {
    418   1.1     ragge 
    419  1.29    simonb 	case TIOCSBRK:
    420  1.29    simonb 		dlbrk(sc, 1);
    421  1.29    simonb 		break;
    422  1.29    simonb 
    423  1.29    simonb 	case TIOCCBRK:
    424  1.29    simonb 		dlbrk(sc, 0);
    425  1.29    simonb 		break;
    426  1.29    simonb 
    427  1.29    simonb 	case TIOCMGET:
    428   1.1     ragge 		/* No modem control, assume they're all low. */
    429  1.29    simonb 		*(int *)data = 0;
    430  1.29    simonb 		break;
    431   1.1     ragge 
    432  1.29    simonb 	default:
    433  1.29    simonb 		return (EPASSTHROUGH);
    434  1.29    simonb 	}
    435  1.29    simonb 	return (0);
    436   1.1     ragge }
    437   1.1     ragge 
    438   1.1     ragge struct tty *
    439  1.14      matt dltty(dev_t dev)
    440   1.1     ragge {
    441  1.43  drochner 	struct dl_softc *sc = device_lookup_private(&dl_cd, minor(dev));
    442  1.14      matt 
    443   1.1     ragge 	return sc->sc_tty;
    444   1.1     ragge }
    445   1.1     ragge 
    446   1.1     ragge void
    447  1.14      matt dlstop(struct tty *tp, int flag)
    448   1.1     ragge {
    449  1.14      matt 	int s = spltty();
    450   1.1     ragge 
    451  1.14      matt 	if ((tp->t_state & (TS_BUSY|TS_TTSTOP)) == TS_BUSY)
    452  1.14      matt 		tp->t_state |= TS_FLUSH;
    453  1.29    simonb 	splx(s);
    454   1.1     ragge }
    455   1.1     ragge 
    456   1.1     ragge static void
    457  1.14      matt dlstart(struct tty *tp)
    458   1.1     ragge {
    459  1.43  drochner 	struct dl_softc *sc = device_lookup_private(&dl_cd, minor(tp->t_dev));
    460  1.14      matt 	int s = spltty();
    461   1.1     ragge 
    462  1.29    simonb 	if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP))
    463  1.29    simonb 		goto out;
    464  1.39        ad 	if (!ttypull(tp))
    465  1.29    simonb 		goto out;
    466   1.7     ragge 	if (DL_READ_WORD(DL_UBA_XCSR) & DL_XCSR_TX_READY) {
    467   1.1     ragge 		tp->t_state |= TS_BUSY;
    468   1.7     ragge 		DL_WRITE_BYTE(DL_UBA_XBUFL, getc(&tp->t_outq));
    469   1.1     ragge 	}
    470   1.1     ragge out:
    471   1.1     ragge 	splx(s);
    472   1.1     ragge 	return;
    473   1.1     ragge }
    474   1.1     ragge 
    475   1.1     ragge /*ARGSUSED*/
    476   1.1     ragge static int
    477  1.14      matt dlparam(struct tty *tp, struct termios *t)
    478   1.1     ragge {
    479   1.1     ragge 	/*
    480   1.1     ragge 	 * All this kind of stuff (speed, character format, whatever)
    481   1.1     ragge 	 * is set by jumpers on the card.  Changing it is thus rather
    482   1.1     ragge 	 * tricky for a mere device driver.
    483   1.1     ragge 	 */
    484   1.1     ragge 	return 0;
    485   1.1     ragge }
    486   1.1     ragge 
    487   1.1     ragge static void
    488  1.14      matt dlbrk(struct dl_softc *sc, int state)
    489   1.1     ragge {
    490   1.7     ragge 	int s = spltty();
    491   1.7     ragge 
    492   1.7     ragge 	if (state) {
    493   1.7     ragge 		DL_WRITE_WORD(DL_UBA_XCSR, DL_READ_WORD(DL_UBA_XCSR) |
    494   1.7     ragge 		    DL_XCSR_TX_BREAK);
    495   1.7     ragge 	} else {
    496   1.7     ragge 		DL_WRITE_WORD(DL_UBA_XCSR, DL_READ_WORD(DL_UBA_XCSR) &
    497   1.7     ragge 		    ~DL_XCSR_TX_BREAK);
    498   1.7     ragge 	}
    499   1.1     ragge 	splx(s);
    500   1.1     ragge }
    501