Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/pci add driver for the Bit3 PCI-VME adapter, without...



details:   https://anonhg.NetBSD.org/src/rev/24cd46a2f6bb
branches:  trunk
changeset: 474175:24cd46a2f6bb
user:      drochner <drochner%NetBSD.org@localhost>
date:      Wed Jun 30 17:45:38 1999 +0000

description:
add driver for the Bit3 PCI-VME adapter, without the DMA parts for now

diffstat:

 sys/dev/pci/btvmei.c    |  733 ++++++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/pci/btvmeireg.h |  375 ++++++++++++++++++++++++
 sys/dev/pci/btvmeivar.h |  131 ++++++++
 sys/dev/pci/files.pci   |    8 +-
 4 files changed, 1246 insertions(+), 1 deletions(-)

diffs (truncated from 1270 to 300 lines):

diff -r 6cc7107962fb -r 24cd46a2f6bb sys/dev/pci/btvmei.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/pci/btvmei.c      Wed Jun 30 17:45:38 1999 +0000
@@ -0,0 +1,733 @@
+/* $NetBSD: btvmei.c,v 1.1 1999/06/30 17:45:38 drochner Exp $ */
+
+/*
+ * Copyright (c) 1999
+ *     Matthias Drochner.  All rights reserved.
+ *
+ * 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. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ *
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/proc.h>
+#include <sys/malloc.h>
+
+#include <machine/bus.h>
+#include <sys/extent.h>
+
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcivar.h>
+#include <dev/pci/pcidevs.h>
+
+#include <dev/vme/vmereg.h>
+#include <dev/vme/vmevar.h>
+
+#include <dev/pci/btvmeireg.h>
+#include <dev/pci/btvmeivar.h>
+
+static int b3_617_match __P((struct device *, struct cfdata *, void *));
+static void b3_617_attach __P((struct device *, struct device *, void *));
+#ifdef notyet
+static int b3_617_detach __P((struct device *));
+#endif
+void b3_617_slaveconfig __P((struct device *, struct vme_attach_args *));
+
+static void b3_617_vmeintr __P((struct b3_617_softc *, unsigned char));
+
+/*
+ * mapping ressources, needed for deallocation
+ */
+struct b3_617_vmeresc {
+       bus_space_handle_t handle;
+       bus_size_t len;
+       int firstpage, maplen;
+};
+
+struct cfattach btvmei_ca = {
+       sizeof(struct b3_617_softc), b3_617_match, b3_617_attach,
+#ifdef notyet
+       b3_617_detach
+#endif
+};
+
+static int
+b3_617_match(parent, match, aux)
+       struct device *parent;
+       struct cfdata *match;
+       void *aux;
+{
+       struct pci_attach_args *pa = aux;
+
+       if ((PCI_VENDOR(pa->pa_id) != PCI_VENDOR_BIT3)
+           || (PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_BIT3_PCIVME617))
+               return (0);
+       return (1);
+}
+
+static void
+b3_617_attach(parent, self, aux)
+       struct device *parent, *self;
+       void *aux;
+{
+       struct b3_617_softc *sc = (struct b3_617_softc*)self;
+       struct pci_attach_args *pa = aux;
+       pci_chipset_tag_t pc = pa->pa_pc;
+
+       int rev;
+
+       pci_intr_handle_t ih;
+       const char *intrstr;
+       struct vmebus_attach_args vaa;
+
+       sc->sc_pc = pc;
+       sc->sc_dmat = pa->pa_dmat;
+
+       rev = PCI_REVISION(pci_conf_read(pc, pa->pa_tag, PCI_CLASS_REG));
+       printf(": BIT3 PCI-VME 617 rev %d\n", rev);
+
+       /*
+        * Map CSR and mapping table spaces.
+        * Don't map VME window; parts are mapped as needed to
+        * save kernel virtual memory space
+        */
+       if (pci_mapreg_map(pa, 0x14,
+                          PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT,
+                          0, &sc->csrt, &sc->csrh, NULL, NULL) &&
+           pci_mapreg_map(pa, 0x10,
+                          PCI_MAPREG_TYPE_IO,
+                          0, &sc->csrt, &sc->csrh, NULL, NULL)) {
+               printf("%s: can't map CSR space\n", self->dv_xname);
+               return;
+       }
+
+       if (pci_mapreg_map(pa, 0x18,
+                          PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT,
+                          0, &sc->mapt, &sc->maph, NULL, NULL)) {
+               printf("%s: can't map map space\n", self->dv_xname);
+               return;
+       }
+
+       if (pci_mapreg_info(pc, pa->pa_tag, 0x1c,
+                           PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT,
+                           &sc->vmepbase, 0, 0)) {
+               printf("%s: can't get VME range\n", self->dv_xname);
+               return;
+       }
+       sc->sc_vmet = pa->pa_memt; /* XXX needed for VME mappings */
+
+       /* Map and establish the interrupt. */
+       if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
+                        pa->pa_intrline, &ih)) {
+               printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
+               return;
+       }
+       intrstr = pci_intr_string(pc, ih);
+       /*
+        * Use a low interrupt level (the lowest?).
+        * We will raise before calling a subdevice's handler.
+        */
+       sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, b3_617_intr, sc);
+       if (sc->sc_ih == NULL) {
+               printf("%s: couldn't establish interrupt",
+                      sc->sc_dev.dv_xname);
+               if (intrstr != NULL)
+                       printf(" at %s", intrstr);
+               printf("\n");
+               return;
+       }
+       printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
+
+       if (b3_617_init(sc))
+               return;
+
+       /*
+        * set up all the tags for use by VME devices
+        */
+       sc->sc_vct.cookie = self;
+       sc->sc_vct.vct_probe = b3_617_vme_probe;
+       sc->sc_vct.vct_map = b3_617_map_vme;
+       sc->sc_vct.vct_unmap = b3_617_unmap_vme;
+       sc->sc_vct.vct_int_map = b3_617_map_vmeint;
+       sc->sc_vct.vct_int_establish = b3_617_establish_vmeint;
+       sc->sc_vct.vct_int_disestablish = b3_617_disestablish_vmeint;
+       sc->sc_vct.vct_dmamap_create = b3_617_dmamap_create;
+       sc->sc_vct.vct_dmamap_destroy = b3_617_dmamap_destroy;
+       sc->sc_vct.vct_dmamem_alloc = b3_617_dmamem_alloc;
+       sc->sc_vct.vct_dmamem_free = b3_617_dmamem_free;
+
+       vaa.va_vct = &(sc->sc_vct);
+       vaa.va_bdt = pa->pa_dmat;
+       vaa.va_slaveconfig = b3_617_slaveconfig;
+
+       sc->csrwindow.offset = -1;
+       sc->dmawindow24.offset = -1;
+       sc->dmawindow32.offset = -1;
+       config_found(self, &vaa, 0);
+}
+
+#ifdef notyet
+static int
+b3_617_detach(dev)
+       struct device *dev;
+{
+       struct b3_617_softc *sc = (struct b3_617_softc *)dev;
+
+       b3_617_halt(sc);
+
+       if (sc->sc_ih)
+               pci_intr_disestablish(sc->sc_pc, sc->sc_ih);
+
+       bus_space_unmap(sc->sc_bc, sc->csrbase, 32);
+       bus_space_unmap(sc->sc_bc, sc->mapbase, 64*1024);
+
+       return(0);
+}
+#endif
+
+void
+b3_617_slaveconfig(dev, va)
+       struct device *dev;
+       struct vme_attach_args *va;
+{
+       struct b3_617_softc *sc = (struct b3_617_softc *)dev;
+       vme_chipset_tag_t vmect;
+       int i, res;
+       char *name = 0; /* XXX gcc! */
+
+       vmect = &sc->sc_vct;
+       if (!va)
+               goto freeit;
+
+#ifdef DIAGNOSTIC
+       if (vmect != va->va_vct)
+               panic("pcivme_slaveconfig: chipset tag?\n");
+#endif
+
+       for (i = 0; i < va->numcfranges; i++) {
+               res = vme_space_alloc(vmect, va->r[i].offset,
+                                     va->r[i].size, va->r[i].am);
+               if (res)
+                       panic("%s: can't alloc slave window %x/%x/%x",
+                              dev->dv_xname, va->r[i].offset,
+                              va->r[i].size, va->r[i].am);
+
+               switch (va->r[i].am & VME_AM_ADRSIZEMASK) {
+                       /* structure assignments! */
+                   case VME_AM_A16:
+                       sc->csrwindow = va->r[i];
+                       name = "VME CSR";
+                       break;
+                   case VME_AM_A24:
+                       sc->dmawindow24 = va->r[i];
+                       name = "A24 DMA";
+                       break;
+                   case VME_AM_A32:
+                       sc->dmawindow32 = va->r[i];
+                       name = "A32 DMA";
+                       break;
+               }
+               printf("%s: %s window: %x-%x\n", dev->dv_xname,
+                      name, va->r[i].offset,
+                      va->r[i].offset + va->r[i].size - 1);
+       }
+       return;
+
+freeit:
+       if (sc->csrwindow.offset != -1)
+               vme_space_free(vmect, sc->csrwindow.offset,
+                              sc->csrwindow.size, sc->csrwindow.am);
+       if (sc->dmawindow32.offset != -1)
+               vme_space_free(vmect, sc->dmawindow32.offset,
+                              sc->dmawindow32.size, sc->dmawindow32.am);
+       if (sc->dmawindow24.offset != -1)
+               vme_space_free(vmect, sc->dmawindow24.offset,
+                              sc->dmawindow24.size, sc->dmawindow24.am);
+}
+
+int
+b3_617_reset(sc)
+       struct b3_617_softc *sc;
+{
+       unsigned char status;
+
+       /* reset sequence, ch 5.2 */
+       status = read_csr_byte(sc, LOC_STATUS);
+       if (status & LSR_NO_CONNECT) {
+               printf("%s: not connected\n", sc->sc_dev.dv_xname);
+               return (-1);
+       }
+       status = read_csr_byte(sc, REM_STATUS); /* discard */
+       write_csr_byte(sc, LOC_CMD1, LC1_CLR_ERROR);
+       status = read_csr_byte(sc, LOC_STATUS);
+       if (status & LSR_CERROR_MASK) {
+               printf("%s: interface error, lsr=%b\n", sc->sc_dev.dv_xname,
+                      status, BIT3_LSR_BITS);
+               return (-1);
+       }
+       return (0);
+}
+
+int
+b3_617_init(sc)
+       struct b3_617_softc *sc;
+{
+       unsigned int i;



Home | Main Index | Thread Index | Old Index