Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/mvme68k Revamp the bus_space(9) implementation:



details:   https://anonhg.NetBSD.org/src/rev/ed1d03c90042
branches:  trunk
changeset: 499592:ed1d03c90042
user:      scw <scw%NetBSD.org@localhost>
date:      Fri Nov 24 09:36:40 2000 +0000

description:
Revamp the bus_space(9) implementation:
 . use a structure for the tag instead of an integer constant,
 . add bus_space_{peek,poke}_N() (and G/C `badaddr()'),
 . fix a few drivers which have dependencies on the implementation.

diffstat:

 sys/arch/mvme68k/dev/clmpcc_pcctwo.c |   25 +-
 sys/arch/mvme68k/dev/mainbus.c       |   73 ++++++----
 sys/arch/mvme68k/dev/mainbus.h       |    5 +-
 sys/arch/mvme68k/dev/mvmebus.c       |   39 +++-
 sys/arch/mvme68k/dev/pcc.c           |    5 +-
 sys/arch/mvme68k/dev/pcctwo.c        |    5 +-
 sys/arch/mvme68k/dev/pcctwovar.h     |    4 +-
 sys/arch/mvme68k/dev/pccvar.h        |    4 +-
 sys/arch/mvme68k/dev/zs_pcc.c        |    6 +-
 sys/arch/mvme68k/dev/zs_pcctwo.c     |    6 +-
 sys/arch/mvme68k/include/bus_dma.h   |    5 +-
 sys/arch/mvme68k/include/cpu.h       |    3 +-
 sys/arch/mvme68k/mvme68k/bus_space.c |  236 ++++++++++++++++++++++++++++++----
 sys/arch/mvme68k/mvme68k/machdep.c   |   61 +--------
 14 files changed, 316 insertions(+), 161 deletions(-)

diffs (truncated from 863 to 300 lines):

diff -r d5acdb0ea34d -r ed1d03c90042 sys/arch/mvme68k/dev/clmpcc_pcctwo.c
--- a/sys/arch/mvme68k/dev/clmpcc_pcctwo.c      Fri Nov 24 09:27:42 2000 +0000
+++ b/sys/arch/mvme68k/dev/clmpcc_pcctwo.c      Fri Nov 24 09:36:40 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: clmpcc_pcctwo.c,v 1.5 2000/09/06 19:51:43 scw Exp $ */
+/*     $NetBSD: clmpcc_pcctwo.c,v 1.6 2000/11/24 09:36:40 scw Exp $ */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -181,19 +181,10 @@
        struct clmpcc_softc *sc;
        int which;
 {
-       bus_space_tag_t bust;
        bus_space_handle_t bush;
        bus_size_t offset;
        volatile u_char foo;
 
-       /*
-        * We need to fake the tag and handle since 'sys_pcctwo' will
-        * be NULL during early system startup...
-        */
-       bust = MVME68K_INTIO_BUS_SPACE;
-       bush = (bus_space_tag_t) & (intiobase[MAINBUS_PCCTWO_OFFSET +
-               PCCTWO_REG_OFF]);
-
        switch (which) {
        case CLMPCC_IACK_MODEM:
                offset = PCC2REG_SCC_MODEM_PIACK;
@@ -214,7 +205,14 @@
 #endif
        }
 
-       foo = bus_space_read_1(bust, bush, offset);
+       /*
+        * We need to fake the tag and handle since 'sys_pcctwo' will
+        * be NULL during early system startup...
+        */
+       bush = (bus_space_handle_t) & (intiobase[MAINBUS_PCCTWO_OFFSET +
+               PCCTWO_REG_OFF]);
+
+       foo = bus_space_read_1(&_mainbus_space_tag, bush, offset);
 }
 
 
@@ -255,8 +253,9 @@
 {
        static struct clmpcc_softc cons_sc;
 
-       cons_sc.sc_iot = MVME68K_INTIO_BUS_SPACE;
-       bus_space_map(cons_sc.sc_iot, MAINBUS_PCCTWO_OFFSET + PCCTWO_SCC_OFF,
+       cons_sc.sc_iot = &_mainbus_space_tag;
+       bus_space_map(&_mainbus_space_tag,
+           intiobase_phys + MAINBUS_PCCTWO_OFFSET + PCCTWO_SCC_OFF,
            PCC2REG_SIZE, 0, &cons_sc.sc_ioh);
        cons_sc.sc_clk = 20000000;
        cons_sc.sc_byteswap = CLMPCC_BYTESWAP_LOW;
diff -r d5acdb0ea34d -r ed1d03c90042 sys/arch/mvme68k/dev/mainbus.c
--- a/sys/arch/mvme68k/dev/mainbus.c    Fri Nov 24 09:27:42 2000 +0000
+++ b/sys/arch/mvme68k/dev/mainbus.c    Fri Nov 24 09:36:40 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mainbus.c,v 1.4 2000/11/20 19:35:29 scw Exp $  */
+/*     $NetBSD: mainbus.c,v 1.5 2000/11/24 09:36:40 scw Exp $  */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -46,8 +46,10 @@
 #include <sys/device.h>
 
 #define _MVME68K_BUS_DMA_PRIVATE
+#define _MVME68K_BUS_SPACE_PRIVATE
 #include <machine/bus.h>
 #undef _MVME68K_BUS_DMA_PRIVATE
+#undef _MVME68K_BUS_SPACE_PRIVATE
 #include <machine/cpu.h>
 
 #include <mvme68k/dev/mainbus.h>
@@ -57,13 +59,8 @@
 int mainbus_match __P((struct device *, struct cfdata *, void *));
 int mainbus_print __P((void *, const char *));
 
-struct mainbus_softc {
-       struct device sc_dev;
-       struct mvme68k_bus_dma_tag sc_dmat;
-};
-
 struct cfattach mainbus_ca = {
-       sizeof(struct mainbus_softc), mainbus_match, mainbus_attach
+       sizeof(struct device), mainbus_match, mainbus_attach
 };
 
 
@@ -87,6 +84,37 @@
 };
 #endif
 
+
+struct mvme68k_bus_dma_tag _mainbus_dma_tag = {
+       NULL,
+       _bus_dmamap_create,
+       _bus_dmamap_destroy,
+       _bus_dmamap_load_direct,
+       _bus_dmamap_load_mbuf_direct,
+       _bus_dmamap_load_uio_direct,
+       _bus_dmamap_load_raw_direct,
+       _bus_dmamap_unload,
+       NULL,                   /* Set up at run-time */
+       _bus_dmamem_alloc,
+       _bus_dmamem_free,
+       _bus_dmamem_map,
+       _bus_dmamem_unmap,
+       _bus_dmamem_mmap
+};
+
+struct mvme68k_bus_space_tag _mainbus_space_tag = {
+       NULL,
+       _bus_space_map,
+       _bus_space_unmap,
+       _bus_space_peek_1,
+       _bus_space_peek_2,
+       _bus_space_peek_4,
+       _bus_space_poke_1,
+       _bus_space_poke_2,
+       _bus_space_poke_4
+};
+
+
 /* ARGSUSED */
 int
 mainbus_match(parent, cf, args)
@@ -109,31 +137,10 @@
        struct device *self;
        void *args;
 {
-       struct mainbus_softc *sc;
        struct mainbus_attach_args ma;
        struct mainbus_devices *devices;
        int i;
 
-       sc = (struct mainbus_softc *) self;
-
-       /*
-        * Initialise the mainbus Bus DMA tag.
-        */
-       sc->sc_dmat._cookie = sc;
-       sc->sc_dmat._dmamap_create = _bus_dmamap_create;
-       sc->sc_dmat._dmamap_destroy = _bus_dmamap_destroy;
-       sc->sc_dmat._dmamap_load = _bus_dmamap_load_direct;
-       sc->sc_dmat._dmamap_load_mbuf = _bus_dmamap_load_mbuf_direct;
-       sc->sc_dmat._dmamap_load_uio = _bus_dmamap_load_uio_direct;
-       sc->sc_dmat._dmamap_load_raw = _bus_dmamap_load_raw_direct;
-       sc->sc_dmat._dmamap_unload = _bus_dmamap_unload;
-       sc->sc_dmat._dmamap_sync = _bus_dmamap_sync;
-       sc->sc_dmat._dmamem_alloc = _bus_dmamem_alloc;
-       sc->sc_dmat._dmamem_free = _bus_dmamem_free;
-       sc->sc_dmat._dmamem_map = _bus_dmamem_map;
-       sc->sc_dmat._dmamem_unmap = _bus_dmamem_unmap;
-       sc->sc_dmat._dmamem_mmap = _bus_dmamem_mmap;
-
        printf("\n");
 
        /*
@@ -143,6 +150,7 @@
 #ifdef MVME147
        case MVME_147:
                devices = mainbusdevs_147;
+               _mainbus_dma_tag._dmamap_sync = _bus_dmamap_sync_030;
                break;
 #endif
 
@@ -152,6 +160,7 @@
        case MVME_172:
        case MVME_177:
                devices = mainbusdevs_1x7;
+               _mainbus_dma_tag._dmamap_sync = _bus_dmamap_sync_0460;
                break;
 #endif
 
@@ -161,9 +170,9 @@
 
        for (i = 0; devices[i].md_name != NULL; ++i) {
                ma.ma_name = devices[i].md_name;
-               ma.ma_dmat = &sc->sc_dmat;
-               ma.ma_bust = MVME68K_INTIO_BUS_SPACE;
-               ma.ma_offset = devices[i].md_offset;
+               ma.ma_dmat = &_mainbus_dma_tag;
+               ma.ma_bust = &_mainbus_space_tag;
+               ma.ma_offset = devices[i].md_offset + intiobase_phys;
 
                (void) config_found(self, &ma, mainbus_print);
        }
@@ -181,7 +190,7 @@
        if (cp)
                printf("%s at %s", ma->ma_name, cp);
 
-       printf(" offset 0x%lx", ma->ma_offset);
+       printf(" offset 0x%lx", ma->ma_offset - intiobase_phys);
 
        return (UNCONF);
 }
diff -r d5acdb0ea34d -r ed1d03c90042 sys/arch/mvme68k/dev/mainbus.h
--- a/sys/arch/mvme68k/dev/mainbus.h    Fri Nov 24 09:27:42 2000 +0000
+++ b/sys/arch/mvme68k/dev/mainbus.h    Fri Nov 24 09:36:40 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mainbus.h,v 1.2 2000/03/18 22:33:03 scw Exp $  */
+/*     $NetBSD: mainbus.h,v 1.3 2000/11/24 09:36:40 scw Exp $  */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -57,4 +57,7 @@
 #define MAINBUS_VMETWO_OFFSET  0x0000u
 #define        MAINBUS_PCCTWO_OFFSET   0x2000u
 
+extern struct mvme68k_bus_space_tag _mainbus_space_tag;
+extern struct mvme68k_bus_dma_tag   _mainbus_dma_tag;
+
 #endif /* _MVME68K_MAINBUS_H */
diff -r d5acdb0ea34d -r ed1d03c90042 sys/arch/mvme68k/dev/mvmebus.c
--- a/sys/arch/mvme68k/dev/mvmebus.c    Fri Nov 24 09:27:42 2000 +0000
+++ b/sys/arch/mvme68k/dev/mvmebus.c    Fri Nov 24 09:36:40 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mvmebus.c,v 1.5 2000/09/19 19:35:52 scw Exp $  */
+/*     $NetBSD: mvmebus.c,v 1.6 2000/11/24 09:36:40 scw Exp $  */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -282,13 +282,13 @@
        if (paddr == 0)
                return (ENOMEM);
 
-       rv = bus_space_map(MVME68K_VME_BUS_SPACE, paddr, len, 0, handle);
+       rv = bus_space_map(sc->sc_bust, paddr, len, 0, handle);
        if (rv != 0)
                return (rv);
 
        /* Allocate space for the resource tag */
        if ((mr = malloc(sizeof(*mr), M_DEVBUF, M_NOWAIT)) == NULL) {
-               bus_space_unmap(MVME68K_VME_BUS_SPACE, *handle, len);
+               bus_space_unmap(sc->sc_bust, *handle, len);
                return (ENOMEM);
        }
 
@@ -300,7 +300,7 @@
        mr->mr_handle = *handle;
        mr->mr_range = i;
 
-       *tag = MVME68K_VME_BUS_SPACE;
+       *tag = sc->sc_bust;
        *resc = (vme_mapresc_t *) mr;
 
        return (0);
@@ -312,9 +312,10 @@
        void *vsc;
        vme_mapresc_t resc;
 {
+       struct mvmebus_softc *sc = vsc;
        struct mvmebus_mapresc *mr = (struct mvmebus_mapresc *) resc;
 
-       bus_space_unmap(MVME68K_VME_BUS_SPACE, mr->mr_handle, mr->mr_size);
+       bus_space_unmap(sc->sc_bust, mr->mr_handle, mr->mr_size);
 
        free(mr, M_DEVBUF);
 }
@@ -332,6 +333,7 @@
        bus_space_tag_t tag;
        bus_space_handle_t handle;
        vme_mapresc_t resc;
+       vme_size_t offs;
        int rv;
 
        /* Get a temporary mapping to the VMEbus range */
@@ -342,14 +344,25 @@
 
        if (callback)
                rv = (*callback) (arg, tag, handle);
-       else {
-               /*
-                * FIXME: Using badaddr() in this way may cause several
-                * accesses to each VMEbus address. Also, using 'handle' in
-                * this way is a bit presumptuous...
-                */
-               rv = badaddr((caddr_t) handle, (int) len) ? EIO : 0;
-       }
+       else
+               for (offs = 0; offs < len && rv == 0;) {
+                       switch (datasize) {
+                       case VME_D8:
+                               rv = bus_space_peek_1(tag, handle, offs, NULL);
+                               offs += 1;
+                               break;
+
+                       case VME_D16:
+                               rv = bus_space_peek_2(tag, handle, offs, NULL);
+                               offs += 2;
+                               break;
+
+                       case VME_D32:
+                               rv = bus_space_peek_4(tag, handle, offs, NULL);
+                               offs += 4;
+                               break;



Home | Main Index | Thread Index | Old Index