Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/atari/isa malloc(9) -> kmem(9)



details:   https://anonhg.NetBSD.org/src/rev/540b804f77b7
branches:  trunk
changeset: 979653:540b804f77b7
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Mon Jan 04 18:23:10 2021 +0000

description:
malloc(9) -> kmem(9)

diffstat:

 sys/arch/atari/isa/isa_dma.c |  116 ++++++++++++++++++++++++++++--------------
 1 files changed, 76 insertions(+), 40 deletions(-)

diffs (178 lines):

diff -r c19de3293ee9 -r 540b804f77b7 sys/arch/atari/isa/isa_dma.c
--- a/sys/arch/atari/isa/isa_dma.c      Mon Jan 04 18:22:19 2021 +0000
+++ b/sys/arch/atari/isa/isa_dma.c      Mon Jan 04 18:23:10 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: isa_dma.c,v 1.12 2016/02/26 18:16:51 christos Exp $    */
+/*     $NetBSD: isa_dma.c,v 1.13 2021/01/04 18:23:10 thorpej Exp $     */
 
 #define ISA_DMA_STATS
 
@@ -33,14 +33,14 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: isa_dma.c,v 1.12 2016/02/26 18:16:51 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: isa_dma.c,v 1.13 2021/01/04 18:23:10 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/kernel.h>
 #include <sys/syslog.h>
 #include <sys/device.h>
-#include <sys/malloc.h>
+#include <sys/kmem.h>
 #include <sys/proc.h>
 #include <sys/mbuf.h>
 
@@ -150,28 +150,11 @@
 #define        STAT_DECR(v)
 #endif
 
-/*
- * Create an ISA DMA map.
- */
-int
-_isa_bus_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 *dmamp)
+static int
+isadma_bounce_cookieflags(bus_dma_tag_t const t, bus_dmamap_t const map,
+    int const flags)
 {
-       struct atari_isa_dma_cookie *cookie;
-       bus_dmamap_t map;
-       int error, cookieflags;
-       void *cookiestore;
-       size_t cookiesize;
-
-       /* Call common function to create the basic map. */
-       error = _bus_dmamap_create(t, size, nsegments, maxsegsz, boundary,
-           flags, dmamp);
-       if (error)
-               return (error);
-
-       map = *dmamp;
-       map->_dm_cookie = NULL;
-
-       cookiesize = sizeof(struct atari_isa_dma_cookie);
+       int cookieflags = 0;
 
        /*
         * ISA only has 24-bits of address space.  This means
@@ -200,41 +183,94 @@
                /* Bouncing not necessary due to memory size. */ 
                map->_dm_bounce_thresh = 0;
        }
-       cookieflags = 0;
        if (map->_dm_bounce_thresh != 0 ||
            ((map->_dm_size / PAGE_SIZE) + 1) > map->_dm_segcnt) {
                cookieflags |= ID_MIGHT_NEED_BOUNCE;
+       }
+       return cookieflags;
+}
+
+static size_t
+isadma_bounce_cookiesize(bus_dmamap_t const map, int cookieflags)
+{
+       size_t cookiesize = sizeof(struct atari_isa_dma_cookie);
+
+       if (cookieflags & ID_MIGHT_NEED_BOUNCE) {
                cookiesize += (sizeof(bus_dma_segment_t) * map->_dm_segcnt);
        }
+       return cookiesize;
+}
+
+static int
+isadma_bounce_cookie_alloc(bus_dma_tag_t const t, bus_dmamap_t const map,
+    int const flags)
+{
+       struct atari_isa_dma_cookie *cookie;
+       int cookieflags = isadma_bounce_cookieflags(t, map, flags);
+
+       if ((cookie = kmem_zalloc(isadma_bounce_cookiesize(map, cookieflags),
+            (flags & BUS_DMA_NOWAIT) ? KM_NOSLEEP : KM_SLEEP)) == NULL) {
+               return ENOMEM;
+       }
+
+       cookie->id_flags = cookieflags;
+       map->_dm_cookie = cookie;
+
+       return 0;
+}
+
+static void
+isadma_bounce_cookie_free(bus_dmamap_t const map)
+{
+       struct atari_isa_dma_cookie *cookie = map->_dm_cookie;
+
+       if (cookie != NULL) {
+               kmem_free(map->_dm_cookie,
+                   isadma_bounce_cookiesize(map, cookie->id_flags));
+               map->_dm_cookie = NULL;
+       }
+}
+
+/*
+ * Create an ISA DMA map.
+ */
+int
+_isa_bus_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 *dmamp)
+{
+       struct atari_isa_dma_cookie *cookie;
+       bus_dmamap_t map;
+       int error;
+
+       /* Call common function to create the basic map. */
+       error = _bus_dmamap_create(t, size, nsegments, maxsegsz, boundary,
+           flags, dmamp);
+       if (error)
+               return (error);
+
+       map = *dmamp;
+       map->_dm_cookie = NULL;
 
        /*
         * Allocate our cookie.
         */
-       if ((cookiestore = malloc(cookiesize, M_DMAMAP,
-           (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK)) == NULL) {
-               error = ENOMEM;
+       if ((error = isadma_bounce_cookie_alloc(t, map, flags)) != 0) {
                goto out;
        }
-       memset(cookiestore, 0, cookiesize);
-       cookie = (struct atari_isa_dma_cookie *)cookiestore;
-       cookie->id_flags = cookieflags;
-       map->_dm_cookie = cookie;
+       cookie = map->_dm_cookie;
 
-       if (cookieflags & ID_MIGHT_NEED_BOUNCE) {
+       if (cookie->id_flags & ID_MIGHT_NEED_BOUNCE) {
                /*
                 * Allocate the bounce pages now if the caller
                 * wishes us to do so.
                 */
-               if ((flags & BUS_DMA_ALLOCNOW) == 0)
-                       goto out;
-
-               error = _isa_dma_alloc_bouncebuf(t, map, size, flags);
+               if (flags & BUS_DMA_ALLOCNOW) {
+                       error = _isa_dma_alloc_bouncebuf(t, map, size, flags);
+               }
        }
 
  out:
        if (error) {
-               if (map->_dm_cookie != NULL)
-                       free(map->_dm_cookie, M_DMAMAP);
+               isadma_bounce_cookie_free(map);
                _bus_dmamap_destroy(t, map);
        }
        return (error);
@@ -254,7 +290,7 @@
        if (cookie->id_flags & ID_HAS_BOUNCE)
                _isa_dma_free_bouncebuf(t, map);
 
-       free(cookie, M_DMAMAP);
+       isadma_bounce_cookie_free(map);
        _bus_dmamap_destroy(t, map);
 }
 



Home | Main Index | Thread Index | Old Index