Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/dreamcast/dev/g2 GAPS PCI bridge support. Low-leve...



details:   https://anonhg.NetBSD.org/src/rev/2d1bc49f97a9
branches:  trunk
changeset: 503125:2d1bc49f97a9
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Thu Feb 01 01:04:55 2001 +0000

description:
GAPS PCI bridge support.  Low-level stuff from Marcus, bus_dma
implementation from me.

diffstat:

 sys/arch/dreamcast/dev/g2/gapspci.c     |  138 +++++++
 sys/arch/dreamcast/dev/g2/gapspci_dma.c |  627 ++++++++++++++++++++++++++++++++
 sys/arch/dreamcast/dev/g2/gapspci_pci.c |  199 ++++++++++
 sys/arch/dreamcast/dev/g2/gapspcivar.h  |   52 ++
 4 files changed, 1016 insertions(+), 0 deletions(-)

diffs (truncated from 1032 to 300 lines):

diff -r b624dbe2634b -r 2d1bc49f97a9 sys/arch/dreamcast/dev/g2/gapspci.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/dreamcast/dev/g2/gapspci.c       Thu Feb 01 01:04:55 2001 +0000
@@ -0,0 +1,138 @@
+/*     $NetBSD: gapspci.c,v 1.1 2001/02/01 01:04:55 thorpej Exp $      */
+
+/*-
+ * Copyright (c) 2001 Marcus Comstedt
+ * 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. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by Marcus Comstedt.
+ * 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.
+ */
+
+#include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/device.h>
+#include <sys/malloc.h>
+#include <sys/conf.h>
+#include <sys/mbuf.h>
+
+#include <machine/cpu.h>
+#include <machine/bus.h>
+
+#include <dev/pci/pcivar.h>
+#include <dev/pci/pcireg.h>
+
+#include <dev/pci/pcidevs.h>
+
+#include <dreamcast/dev/g2/g2busvar.h>
+#include <dreamcast/dev/g2/gapspcivar.h>
+
+int    gaps_match(struct device *, struct cfdata *, void *);
+void   gaps_attach(struct device *, struct device *, void *);
+
+int    gaps_print(void *, const char *);
+
+struct cfattach gapspci_ca = {
+       sizeof(struct gaps_softc), 
+       gaps_match,
+       gaps_attach,
+};
+
+int
+gaps_match(struct device *parent, struct cfdata *match, void *aux)
+{
+  /*   struct g2bus_attach_args *ga = aux; */
+       char idbuf[16];
+
+       if(strcmp("gapspci", match->cf_driver->cd_name))
+               return 0;
+
+       /* FIXME */
+       memcpy(idbuf, (void *)0xa1001400, sizeof(idbuf));
+
+       if(strncmp(idbuf, "GAPSPCI_BRIDGE_2", 16))
+               return 0;
+
+       return (1);
+}
+
+void
+gaps_attach(struct device *parent, struct device *self, void *aux)
+{
+       struct g2bus_attach_args *ga = aux;
+       struct gaps_softc *sc = (void *) self;
+       struct pcibus_attach_args pba;
+       int i;
+
+       printf(": SEGA GAPS PCI Bridge\n");
+
+       sc->sc_dmabase = 0x1840000;
+       sc->sc_memt = ga->ga_memt;
+
+  /* FIXME */  
+       *(volatile unsigned int *)(void *)(0xa1001418) = 0x5a14a501;
+
+       for(i=0; i<1000000; i++)
+         ;
+       
+       if(*(volatile unsigned int *)(void *)(0xa1001418) != 1)
+         return;
+
+       *(volatile unsigned int *)(void *)(0xa1001420) = 0x1000000;
+       *(volatile unsigned int *)(void *)(0xa1001424) = 0x1000000;
+       *(volatile unsigned int *)(void *)(0xa1001428) = sc->sc_dmabase;
+       *(volatile unsigned int *)(void *)(0xa1001414) = 1;
+       *(volatile unsigned int *)(void *)(0xa1001434) = 1;
+
+       gaps_pci_init(sc);
+       gaps_dma_init(sc);
+
+       memset(&pba, 0, sizeof(pba));
+
+       pba.pba_busname = "pci";
+       pba.pba_memt = sc->sc_memt;
+       pba.pba_dmat = &sc->sc_dmat;
+       pba.pba_bus = 0;
+       pba.pba_flags = PCI_FLAGS_MEM_ENABLED;
+       pba.pba_pc = &sc->sc_pc;
+
+       (void) config_found(self, &pba, gaps_print);
+}
+
+int
+gaps_print(void *aux, const char *pnp)
+{
+       struct pcibus_attach_args *pba = aux;
+
+       if (pnp)
+               printf("%s at %s", pba->pba_busname, pnp);
+       printf(" bus %d", pba->pba_bus);
+
+       return (UNCONF);
+}
diff -r b624dbe2634b -r 2d1bc49f97a9 sys/arch/dreamcast/dev/g2/gapspci_dma.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/dreamcast/dev/g2/gapspci_dma.c   Thu Feb 01 01:04:55 2001 +0000
@@ -0,0 +1,627 @@
+/*     $NetBSD: gapspci_dma.c,v 1.1 2001/02/01 01:04:55 thorpej Exp $  */
+
+/*-
+ * Copyright (c) 2001 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.
+ */
+
+/*
+ * Bus DMA implementation for the SEGA GAPS PCI bridge.
+ *
+ * NOTE: We only implement a small subset of what the bus_space(9)
+ * API specifies.  Right now, the GAPS PCI bridge is only used for
+ * the Dreamcast Broadband Adatper, so we only provide what the
+ * pci(4) and rtk(4) drivers need.
+ */
+
+#include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
+
+#include <sys/param.h>
+#include <sys/systm.h> 
+#include <sys/device.h>
+#include <sys/mbuf.h>
+#include <sys/extent.h>
+#include <sys/malloc.h>
+
+#include <machine/cpu.h> 
+#include <machine/bus.h>
+
+#include <dev/pci/pcivar.h>
+
+#include <dreamcast/dev/g2/gapspcivar.h>
+
+#include <uvm/uvm_extern.h>
+
+int    gaps_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t,
+           bus_size_t, int, bus_dmamap_t *);
+void   gaps_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t);
+int    gaps_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, bus_size_t,
+           struct proc *, int);
+int    gaps_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, struct mbuf *, int);
+int    gaps_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, struct uio *, int);
+int    gaps_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, bus_dma_segment_t *,
+           int, bus_size_t, int);
+void   gaps_dmamap_unload(bus_dma_tag_t, bus_dmamap_t);
+void   gaps_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
+           bus_size_t, int);
+
+int    gaps_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size,
+           bus_size_t alignment, bus_size_t boundary, bus_dma_segment_t *segs,
+           int nsegs, int *rsegs, int flags);
+void   gaps_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs, int nsegs);
+int    gaps_dmamem_map(bus_dma_tag_t tag, bus_dma_segment_t *segs, int nsegs,
+           size_t size, caddr_t *kvap, int flags);
+void   gaps_dmamem_unmap(bus_dma_tag_t tag, caddr_t kva, size_t size);
+paddr_t        gaps_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs, int nsegs,
+           off_t off, int prot, int flags);
+
+void
+gaps_dma_init(struct gaps_softc *sc)
+{
+       bus_dma_tag_t t = &sc->sc_dmat;
+
+       memset(t, 0, sizeof(*t));
+
+       t->_cookie = sc;
+       t->_dmamap_create = gaps_dmamap_create;
+       t->_dmamap_destroy = gaps_dmamap_destroy;
+       t->_dmamap_load = gaps_dmamap_load;
+       t->_dmamap_load_mbuf = gaps_dmamap_load_mbuf;
+       t->_dmamap_load_uio = gaps_dmamap_load_uio;
+       t->_dmamap_load_raw = gaps_dmamap_load_raw;
+       t->_dmamap_unload = gaps_dmamap_unload;
+       t->_dmamap_sync = gaps_dmamap_sync;
+
+       t->_dmamem_alloc = gaps_dmamem_alloc;
+       t->_dmamem_free = gaps_dmamem_free;
+       t->_dmamem_map = gaps_dmamem_map;
+       t->_dmamem_unmap = gaps_dmamem_unmap;
+       t->_dmamem_mmap = gaps_dmamem_mmap;
+
+       /*
+        * The GAPS PCI bridge has 32k of DMA memory.  We manage it
+        * with an extent map.
+        */
+       sc->sc_dma_ex = extent_create("gaps dma",
+           sc->sc_dmabase, sc->sc_dmabase + (32768 - 1),
+           M_DEVBUF, NULL, 0, EX_WAITOK | EXF_NOCOALESCE);
+
+       if (bus_space_map(sc->sc_memt, sc->sc_dmabase, 32768,
+           0, &sc->sc_dma_memh) != 0)
+               panic("gaps_dma_init: can't map SRAM buffer");
+}
+
+/*
+ * A GAPS DMA map -- has the standard DMA map, plus some extra
+ * housekeeping data.
+ */
+struct gaps_dmamap {
+       struct dreamcast_bus_dmamap gd_dmamap;
+       void *gd_origbuf;
+       int gd_buftype;
+};
+
+#define        GAPS_DMA_BUFTYPE_INVALID        0
+#define        GAPS_DMA_BUFTYPE_LINEAR         1
+#define        GAPS_DMA_BUFTYPE_MBUF           2
+
+int
+gaps_dmamap_create(bus_dma_tag_t t, bus_size_t size, int nsegments,
+    bus_size_t maxsegsz, bus_size_t boundary, int flags, bus_dmamap_t *dmamap)
+{
+       struct gaps_softc *sc = t->_cookie;
+       struct gaps_dmamap *gmap;
+       bus_dmamap_t map;
+
+       /*
+        * Allocate an initialize the DMA map.  The end of the map is
+        * a variable-sized array of segments, so we allocate enough
+        * room for them in one shot.  Since the DMA map always includes
+        * one segment, and we only support one segment, this is really
+        * easy.
+        *
+        * Note we don't preserve the WAITOK or NOWAIT flags.  Preservation



Home | Main Index | Thread Index | Old Index