Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/ic Comply with bus_dma(9) specs.



details:   https://anonhg.NetBSD.org/src/rev/75721b590c7f
branches:  trunk
changeset: 487997:75721b590c7f
user:      pk <pk%NetBSD.org@localhost>
date:      Fri Jun 16 11:47:34 2000 +0000

description:
Comply with bus_dma(9) specs.

diffstat:

 sys/dev/ic/apcdmareg.h |  11 +++++----
 sys/dev/ic/cs4231.c    |  60 ++++++++++++++++++++++++++++++++-----------------
 2 files changed, 45 insertions(+), 26 deletions(-)

diffs (139 lines):

diff -r 729853ff19ed -r 75721b590c7f sys/dev/ic/apcdmareg.h
--- a/sys/dev/ic/apcdmareg.h    Fri Jun 16 11:34:55 2000 +0000
+++ b/sys/dev/ic/apcdmareg.h    Fri Jun 16 11:47:34 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: apcdmareg.h,v 1.1 1999/06/05 14:29:10 mrg Exp $        */
+/*     $NetBSD: apcdmareg.h,v 1.2 2000/06/16 11:47:34 pk Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
@@ -103,9 +103,10 @@
  * List of device memory allocations (see cs4231_malloc/cs4231_free).
  */
 struct cs_dma {
-       struct  cs_dma *next;
-       caddr_t addr;
+       struct  cs_dma  *next;
+       caddr_t         addr;
+       bus_dmamap_t    dmamap;
        bus_dma_segment_t segs[1];
-       int     nsegs;
-       size_t  size;
+       int             nsegs;
+       size_t          size;
 };
diff -r 729853ff19ed -r 75721b590c7f sys/dev/ic/cs4231.c
--- a/sys/dev/ic/cs4231.c       Fri Jun 16 11:34:55 2000 +0000
+++ b/sys/dev/ic/cs4231.c       Fri Jun 16 11:47:34 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cs4231.c,v 1.3 2000/03/30 12:45:30 augustss Exp $      */
+/*     $NetBSD: cs4231.c,v 1.4 2000/06/16 11:47:35 pk Exp $    */
 
 /*-
  * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
@@ -238,33 +238,48 @@
        int pool, flags;
 {
        struct cs4231_softc *sc = addr;
+       bus_dma_tag_t dmatag = sc->sc_dmatag;
        struct cs_dma *p;
-       int error;
 
        p = malloc(sizeof(*p), pool, flags);
        if (p == NULL)
                return (NULL);
 
+       /* Allocate a DMA map */
+       if (bus_dmamap_create(dmatag, size, 1, size, 0,
+                               BUS_DMA_NOWAIT, &p->dmamap) != 0)
+               goto fail1;
+
+       /* Allocate DMA memory */
        p->size = size;
-       error = bus_dmamem_alloc(sc->sc_dmatag, size, 64*1024, 0,
-                                p->segs, sizeof(p->segs)/sizeof(p->segs[0]),
-                                &p->nsegs, BUS_DMA_NOWAIT);
-       if (error) {
-               free(p, pool);
-               return (NULL);
-       }
+       if (bus_dmamem_alloc(dmatag, size, 64*1024, 0,
+                               p->segs, sizeof(p->segs)/sizeof(p->segs[0]),
+                               &p->nsegs, BUS_DMA_NOWAIT) != 0)
+               goto fail2;
 
-       error = bus_dmamem_map(sc->sc_dmatag, p->segs, p->nsegs, p->size, 
-                              &p->addr, BUS_DMA_NOWAIT|BUS_DMA_COHERENT);
-       if (error) {
-               bus_dmamem_free(sc->sc_dmatag, p->segs, p->nsegs);
-               free(p, pool);
-               return (NULL);
-       }
+       /* Map DMA memory into kernel space */
+       if (bus_dmamem_map(dmatag, p->segs, p->nsegs, p->size, 
+                          &p->addr, BUS_DMA_NOWAIT|BUS_DMA_COHERENT) != 0)
+               goto fail3;
+
+       /* Load the buffer */
+       if (bus_dmamap_load(dmatag, p->dmamap,
+                           p->addr, size, NULL, BUS_DMA_NOWAIT) != 0)
+               goto fail4;
 
        p->next = sc->sc_dmas;
        sc->sc_dmas = p;
        return (p->addr);
+
+fail4:
+       bus_dmamem_unmap(dmatag, p->addr, p->size);
+fail3:
+       bus_dmamem_free(dmatag, p->segs, p->nsegs);
+fail2:
+       bus_dmamap_destroy(dmatag, p->dmamap);
+fail1:
+       free(p, pool);
+       return (NULL);
 }
 
 void
@@ -274,13 +289,16 @@
        int pool;
 {
        struct cs4231_softc *sc = addr;
+       bus_dma_tag_t dmatag = sc->sc_dmatag;
        struct cs_dma *p, **pp;
 
        for (pp = &sc->sc_dmas; (p = *pp) != NULL; pp = &(*pp)->next) {
                if (p->addr != ptr)
                        continue;
-               bus_dmamem_unmap(sc->sc_dmatag, p->addr, p->size);
-               bus_dmamem_free(sc->sc_dmatag, p->segs, p->nsegs);
+               bus_dmamap_unload(dmatag, p->dmamap);
+               bus_dmamem_unmap(dmatag, p->addr, p->size);
+               bus_dmamem_free(dmatag, p->segs, p->nsegs);
+               bus_dmamap_destroy(dmatag, p->dmamap);
                *pp = p->next;
                free(p, pool);
                return;
@@ -653,11 +671,11 @@
        DPRINTF(("trigger_out: start %p, end %p, size %lu; "
                 "dmaaddr 0x%lx, dmacnt %lu, segsize %lu\n",
                 start, end, (u_long)sc->sc_playsegsz, 
-                (u_long)p->segs[0].ds_addr,
+                (u_long)p->dmamap->dm_segs[0].ds_addr,
                 (u_long)n, (u_long)p->size));
 
        csr = dma->dmacsr;
-       dma->dmapnva = (u_long)p->segs[0].ds_addr;
+       dma->dmapnva = (u_long)p->dmamap->dm_segs[0].ds_addr;
        dma->dmapnc = (u_long)n;
        if ((csr & PDMA_GO) == 0 || (csr & APC_PPAUSE) != 0) {
                int reg;
@@ -784,7 +802,7 @@
                togo = sc->sc_playsegsz - sc->sc_playcnt;
                if (togo == 0) {
                        /* Roll over */
-                       nextaddr = (u_long)p->segs[0].ds_addr;
+                       nextaddr = (u_long)p->dmamap->dm_segs[0].ds_addr;
                        sc->sc_playcnt = togo = APC_MAX;
                } else {
                        nextaddr = dma->dmapnva + APC_MAX;



Home | Main Index | Thread Index | Old Index