Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/qbus Moved from ../dec/qbus/dl.c,v



details:   https://anonhg.NetBSD.org/src/rev/284ed4960d7a
branches:  trunk
changeset: 473274:284ed4960d7a
user:      ragge <ragge%NetBSD.org@localhost>
date:      Thu May 27 16:00:45 1999 +0000

description:
Moved from ../dec/qbus/dl.c,v

diffstat:

 sys/dev/qbus/dl.c |  523 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 523 insertions(+), 0 deletions(-)

diffs (truncated from 527 to 300 lines):

diff -r aa15695ef866 -r 284ed4960d7a sys/dev/qbus/dl.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/qbus/dl.c Thu May 27 16:00:45 1999 +0000
@@ -0,0 +1,523 @@
+/*     $NetBSD: dl.c,v 1.9 1999/05/27 16:00:45 ragge Exp $     */
+
+/*-
+ * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the NetBSD
+ *     Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Copyright (c) 1997  Ben Harris.  All rights reserved.
+ * Copyright (c) 1996  Ken C. Wellsch.  All rights reserved.
+ * Copyright (c) 1982, 1986, 1990, 1992, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Ralph Campbell and Rick Macklem.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * dl.c -- Device driver for the DL11 and DLV11 serial cards.
+ *
+ * OS-interface code derived from the dz and dca (hp300) drivers.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/ioctl.h>
+#include <sys/tty.h>
+#include <sys/proc.h>
+#include <sys/map.h>
+#include <sys/buf.h>
+#include <sys/conf.h>
+#include <sys/file.h>
+#include <sys/uio.h>
+#include <sys/kernel.h>
+#include <sys/syslog.h>
+#include <sys/device.h>
+
+#include <machine/bus.h>
+#include <machine/scb.h>
+
+#include <dev/dec/qbus/ubareg.h>
+#include <dev/dec/qbus/ubavar.h>
+
+#include <dev/dec/qbus/dlreg.h>
+
+#include "ioconf.h"
+
+struct dl_softc {
+       struct device   sc_dev;
+       bus_space_tag_t sc_iot;
+       bus_space_handle_t sc_ioh;
+       struct tty      *sc_tty;
+};
+
+static int     dl_match __P((struct device *, struct cfdata *, void *));
+static void    dl_attach __P((struct device *, struct device *, void *));
+static void    dlrint __P((int));
+static void    dlxint __P((int));
+static void    dlstart __P((struct tty *));
+static int     dlparam __P((struct tty *, struct termios *));
+static void    dlbrk __P((struct dl_softc *, int));
+struct tty *   dltty __P((dev_t));
+       int     dlopen __P((dev_t, int, int, struct proc *));
+       int     dlclose __P((dev_t, int, int, struct proc *));
+       int     dlread __P((dev_t, struct uio *, int));
+       int     dlwrite __P((dev_t, struct uio *, int));
+       int     dlioctl __P((dev_t, int, caddr_t, int, struct proc *));
+       void    dlstop __P((struct tty *, int));
+
+struct cfattach dl_ca = {
+       sizeof(struct dl_softc), dl_match, dl_attach
+};
+
+#define        DL_READ_WORD(reg) \
+       bus_space_read_2(sc->sc_iot, sc->sc_ioh, reg)
+#define        DL_WRITE_WORD(reg, val) \
+       bus_space_write_2(sc->sc_iot, sc->sc_ioh, reg, val)
+#define        DL_WRITE_BYTE(reg, val) \
+       bus_space_write_1(sc->sc_iot, sc->sc_ioh, reg, val)
+
+/* Autoconfig handles: setup the controller to interrupt, */
+/* then complete the housecleaning for full operation */
+
+static int
+dl_match (parent, cf, aux)
+       struct device * parent;
+       struct cfdata *cf;
+       void *aux;
+{
+       struct uba_attach_args *ua = aux;
+
+#ifdef DL_DEBUG
+       printf("Probing for dl at %lo ... ", (long)ua->ua_iaddr);
+#endif
+
+       bus_space_write_2(ua->ua_iot, ua->ua_ioh, DL_UBA_XCSR, DL_XCSR_TXIE);
+       if (bus_space_read_2(ua->ua_iot, ua->ua_ioh, DL_UBA_XCSR) !=
+           (DL_XCSR_TXIE | DL_XCSR_TX_READY)) {
+#ifdef DL_DEBUG
+               printf("failed (step 1; XCSR = %.4b)\n", 
+                   bus_space_read_2(ua->ua_iot, ua->ua_ioh, DL_UBA_XCSR), 
+                   DL_XCSR_BITS);
+#endif
+               return 0;
+       }
+       
+       /*
+        * We have to force an interrupt so the uba driver can work
+        * out where we are.  Unfortunately, the only way to make a
+        * DL11 interrupt is to get it to send or receive a
+        * character.  We'll send a NUL and hope it doesn't hurt
+        * anything.
+        */
+
+       bus_space_write_1(ua->ua_iot, ua->ua_ioh, DL_UBA_XBUFL, '\0');
+#if 0 /* This test seems to fail 2/3 of the time :-( */
+       if (dladdr->dl_xcsr != (DL_XCSR_TXIE)) {
+#ifdef DL_DEBUG
+               printf("failed (step 2; XCSR = %.4b)\n", dladdr->dl_xcsr,
+                      DL_XCSR_BITS);
+#endif
+               return 0;
+       }
+#endif
+       DELAY(100000); /* delay 1/10 s for character to transmit */
+       if (bus_space_read_2(ua->ua_iot, ua->ua_ioh, DL_UBA_XCSR) !=
+           (DL_XCSR_TXIE | DL_XCSR_TX_READY)) {
+#ifdef DL_DEBUG
+               printf("failed (step 3; XCSR = %.4b)\n", 
+                   bus_space_read_2(ua->ua_iot, ua->ua_ioh, DL_UBA_XCSR),
+                   DL_XCSR_BITS);
+#endif
+               return 0;
+       }
+
+       /* Register the TX interrupt handler */
+       ua->ua_ivec = dlxint;
+
+        /* What else do I need to do? */
+
+       return 1;
+
+}
+
+static void
+dl_attach (parent, self, aux)
+       struct device *parent, *self;
+       void *aux;
+{
+       struct dl_softc *sc = (void *)self;
+       register struct uba_attach_args *ua = aux;
+
+       sc->sc_iot = ua->ua_iot;
+       sc->sc_ioh = ua->ua_ioh;
+       
+       /* Tidy up the device */
+
+       DL_WRITE_WORD(DL_UBA_RCSR, DL_RCSR_RXIE);
+       DL_WRITE_WORD(DL_UBA_XCSR, DL_XCSR_TXIE);
+
+       /* Initialize our softc structure. Should be done in open? */
+       
+       sc->sc_tty = ttymalloc();
+       tty_attach(sc->sc_tty);
+
+       /* Now register the RX interrupt handler */
+       scb_vecalloc(ua->ua_cvec - 4, dlrint, self->dv_unit, SCB_ISTACK);
+
+       printf("\n");
+}
+
+/* Receiver Interrupt Handler */
+
+static void
+dlrint(cntlr)
+       int cntlr;
+{
+       struct  dl_softc *sc = dl_cd.cd_devs[cntlr];
+       register struct tty *tp;
+       register int cc;
+       register unsigned c;
+
+       if (DL_READ_WORD(DL_UBA_RCSR) & DL_RCSR_RX_DONE) {
+               c = DL_READ_WORD(DL_UBA_RBUF);
+               cc = c & 0xFF;
+               tp = sc->sc_tty;
+
+               if (!(tp->t_state & TS_ISOPEN)) {
+                       wakeup((caddr_t)&tp->t_rawq);
+                       return;
+               }
+
+               if (c & DL_RBUF_OVERRUN_ERR)
+                       /*
+                        * XXX: This should really be logged somwhere
+                        * else where we can afford the time.
+                        */
+                       log(LOG_WARNING, "%s: rx overrun\n",
+                           sc->sc_dev.dv_xname);
+               if (c & DL_RBUF_FRAMING_ERR)
+                       cc |= TTY_FE;
+               if (c & DL_RBUF_PARITY_ERR)
+                       cc |= TTY_PE;
+
+               (*linesw[tp->t_line].l_rint)(cc, tp);
+       } else
+               log(LOG_WARNING, "%s: stray rx interrupt\n",
+                   sc->sc_dev.dv_xname);
+       return;
+}
+
+/* Transmitter Interrupt Handler */
+
+static void
+dlxint(cntlr)
+       int cntlr;
+{
+       struct  dl_softc *sc = dl_cd.cd_devs[cntlr];
+       register struct tty *tp;
+       
+       tp = sc->sc_tty;
+       tp->t_state &= ~(TS_BUSY | TS_FLUSH);
+       if (tp->t_line)
+               (*linesw[tp->t_line].l_start)(tp);
+       else
+               dlstart(tp);
+       
+       return;
+}
+
+int
+dlopen(dev, flag, mode, p)
+       dev_t dev;
+       int flag, mode;
+       struct proc *p;
+{
+       register struct tty *tp;



Home | Main Index | Thread Index | Old Index