Source-Changes-HG archive

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

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



details:   https://anonhg.NetBSD.org/src/rev/c37acb00f6b8
branches:  trunk
changeset: 957119:c37acb00f6b8
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Wed Nov 18 02:04:29 2020 +0000

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

diffstat:

 sys/arch/alpha/common/bus_dma.c          |   24 ++--
 sys/arch/alpha/eisa/eisa_machdep.c       |   49 ++-------
 sys/arch/alpha/isa/isadma_bounce.c       |  124 ++++++++++++++++++--------
 sys/arch/alpha/jensenio/pckbc_jensenio.c |    9 +-
 sys/arch/alpha/pci/dwlpx_dma.c           |   10 +-
 sys/arch/alpha/pci/mcpcia.c              |   10 +-
 sys/arch/alpha/pci/sio.c                 |    9 +-
 sys/arch/alpha/sableio/pckbc_sableio.c   |    9 +-
 sys/arch/alpha/tc/ioasic.c               |   10 +-
 sys/arch/alpha/tc/tc_3000_300.c          |   10 +-
 sys/arch/alpha/tc/tc_3000_500.c          |   10 +-
 sys/arch/alpha/tc/tc_dma_3000_500.c      |    8 +-
 sys/arch/arc/arc/bus_dma.c               |   22 ++-
 sys/arch/arc/arc/p_dti_arcstation.c      |    6 +-
 sys/arch/arc/isa/isabus.c                |    8 +-
 sys/arch/arc/isa/isadma_bounce.c         |  146 ++++++++++++++++++++----------
 sys/arch/arc/jazz/bus_dma_jazz.c         |   15 +-
 sys/arch/arc/jazz/pckbc_jazzio.c         |   10 +-
 sys/arch/arc/pci/necpb.c                 |   10 +-
 19 files changed, 283 insertions(+), 216 deletions(-)

diffs (truncated from 1195 to 300 lines):

diff -r 1b6e82a69e5e -r c37acb00f6b8 sys/arch/alpha/common/bus_dma.c
--- a/sys/arch/alpha/common/bus_dma.c   Wed Nov 18 01:12:00 2020 +0000
+++ b/sys/arch/alpha/common/bus_dma.c   Wed Nov 18 02:04:29 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bus_dma.c,v 1.70 2020/10/11 00:33:30 thorpej Exp $ */
+/* $NetBSD: bus_dma.c,v 1.71 2020/11/18 02:04:29 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -32,13 +32,13 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.70 2020/10/11 00:33:30 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.71 2020/11/18 02:04:29 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/kernel.h>
 #include <sys/device.h>
-#include <sys/malloc.h>
+#include <sys/kmem.h>
 #include <sys/proc.h>
 #include <sys/mbuf.h>
 
@@ -59,6 +59,14 @@
 #define        DMA_COUNT_DECL(cnt)     _DMA_COUNT_DECL(dma_direct, cnt)
 #define        DMA_COUNT(cnt)          _DMA_COUNT(dma_direct, cnt)
 
+static size_t
+_bus_dmamap_mapsize(int const nsegments)
+{
+       KASSERT(nsegments > 0);
+       return sizeof(struct alpha_bus_dmamap) +
+           (sizeof(bus_dma_segment_t) * (nsegments - 1));
+}
+
 /*
  * Common function for DMA map creation.  May be called by bus-specific
  * DMA map creation functions.
@@ -69,7 +77,6 @@
 {
        struct alpha_bus_dmamap *map;
        void *mapstore;
-       size_t mapsize;
 
        /*
         * Allocate and initialize the DMA map.  The end of the map
@@ -83,13 +90,10 @@
         * The bus_dmamap_t includes one bus_dma_segment_t, hence
         * the (nsegments - 1).
         */
-       mapsize = sizeof(struct alpha_bus_dmamap) +
-           (sizeof(bus_dma_segment_t) * (nsegments - 1));
-       if ((mapstore = malloc(mapsize, M_DMAMAP,
-           (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK)) == NULL)
+       if ((mapstore = kmem_zalloc(_bus_dmamap_mapsize(nsegments),
+           (flags & BUS_DMA_NOWAIT) ? KM_NOSLEEP : KM_SLEEP)) == NULL)
                return (ENOMEM);
 
-       memset(mapstore, 0, mapsize);
        map = (struct alpha_bus_dmamap *)mapstore;
        map->_dm_size = size;
        map->_dm_segcnt = nsegments;
@@ -116,7 +120,7 @@
 _bus_dmamap_destroy(bus_dma_tag_t t, bus_dmamap_t map)
 {
 
-       free(map, M_DMAMAP);
+       kmem_free(map, _bus_dmamap_mapsize(map->_dm_segcnt));
 }
 
 /*
diff -r 1b6e82a69e5e -r c37acb00f6b8 sys/arch/alpha/eisa/eisa_machdep.c
--- a/sys/arch/alpha/eisa/eisa_machdep.c        Wed Nov 18 01:12:00 2020 +0000
+++ b/sys/arch/alpha/eisa/eisa_machdep.c        Wed Nov 18 02:04:29 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: eisa_machdep.c,v 1.12 2014/03/29 19:28:25 christos Exp $ */
+/* $NetBSD: eisa_machdep.c,v 1.13 2020/11/18 02:04:29 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -31,12 +31,12 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: eisa_machdep.c,v 1.12 2014/03/29 19:28:25 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: eisa_machdep.c,v 1.13 2020/11/18 02:04:29 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/device.h>
-#include <sys/malloc.h>
+#include <sys/kmem.h>
 #include <sys/queue.h>
 
 #include <machine/intr.h>
@@ -157,10 +157,7 @@
        int i;
 
        for (i = 0; i < ECUF_MEM_ENTRY_CNT; i++) {
-               ecum = malloc(sizeof(*ecum), M_DEVBUF, M_ZERO|M_WAITOK);
-               if (ecum == NULL)
-                       panic("%s: can't allocate memory for ecum", __func__);
-
+               ecum = kmem_zalloc(sizeof(*ecum), KM_SLEEP);
                ecum->ecum_mem.ecm_isram = dp[0] & 0x1;
                ecum->ecum_mem.ecm_unitsize = dp[1] & 0x3;
                ecum->ecum_mem.ecm_decode = (dp[1] >> 2) & 0x3;
@@ -191,10 +188,7 @@
        int i;
 
        for (i = 0; i < ECUF_IRQ_ENTRY_CNT; i++) {
-               ecui = malloc(sizeof(*ecui), M_DEVBUF, M_ZERO|M_WAITOK);
-               if (ecui == NULL)
-                       panic("%s: can't allocate memory for ecui", __func__);
-
+               ecui = kmem_zalloc(sizeof(*ecui), KM_SLEEP);
                ecui->ecui_irq.eci_irq = dp[0] & 0xf;
                ecui->ecui_irq.eci_ist = (dp[0] & 0x20) ? IST_LEVEL : IST_EDGE;
                ecui->ecui_irq.eci_shared = (dp[0] & 0x40) ? 1 : 0;
@@ -219,10 +213,7 @@
        int i;
 
        for (i = 0; i < ECUF_DMA_ENTRY_CNT; i++) {
-               ecud = malloc(sizeof(*ecud), M_DEVBUF, M_ZERO|M_WAITOK);
-               if (ecud == NULL)
-                       panic("%s: can't allocate memory for ecud", __func__);
-
+               ecud = kmem_zalloc(sizeof(*ecud), KM_SLEEP);
                ecud->ecud_dma.ecd_drq = dp[0] & 0x7;
                ecud->ecud_dma.ecd_shared = dp[0] & 0x40;
                ecud->ecud_dma.ecd_size = (dp[1] >> 2) & 0x3;
@@ -248,10 +239,7 @@
        int i;
 
        for (i = 0; i < ECUF_IO_ENTRY_CNT; i++) {
-               ecuio = malloc(sizeof(*ecuio), M_DEVBUF, M_ZERO|M_WAITOK);
-               if (ecuio == NULL)
-                       panic("%s: can't allocate memory for ecuio", __func__);
-
+               ecuio = kmem_zalloc(sizeof(*ecuio), KM_SLEEP);
                ecuio->ecuio_io.ecio_addr = dp[1] | (dp[2] << 8);
                ecuio->ecuio_io.ecio_size = (dp[0] & 0x1f) + 1;
                ecuio->ecuio_io.ecio_shared = (dp[0] & 0x40) ? 1 : 0;
@@ -370,11 +358,7 @@
                        printf("SLOT %d: offset 0x%08x eisaid %s\n",
                            i, offset, eisaid);
 #endif
-                       ecud = malloc(sizeof(*ecud), M_DEVBUF, M_ZERO|M_WAITOK);
-                       if (ecud == NULL)
-                               panic("%s: can't allocate memory for ecud",
-                                   __func__);
-
+                       ecud = kmem_zalloc(sizeof(*ecud), KM_SLEEP);
                        SIMPLEQ_INIT(&ecud->ecud_funcs);
 
                        ecud->ecud_slot = i;
@@ -388,12 +372,8 @@
         * Now traverse the valid slots and read the info.
         */
 
-       cdata = malloc(CBUFSIZE, M_TEMP, M_ZERO|M_WAITOK);
-       if (cdata == NULL)
-               panic("%s: can't allocate memory for cdata", __func__);
-       data = malloc(CBUFSIZE, M_TEMP, M_ZERO|M_WAITOK);
-       if (data == NULL)
-               panic("%s: can't allocate memory for data", __func__);
+       cdata = kmem_zalloc(CBUFSIZE, KM_SLEEP);
+       data = kmem_zalloc(CBUFSIZE, KM_SLEEP);
 
        SIMPLEQ_FOREACH(ecud, &ecu_data_list, ecud_list) {
                cfgaddr = eisa_config_addr + ecud->ecud_offset;
@@ -501,10 +481,7 @@
                                continue;
                        }
 
-                       ecuf = malloc(sizeof(*ecuf), M_DEVBUF, M_WAITOK);
-                       if (ecuf == NULL)
-                               panic("%s: can't allocate memory for ecuf",
-                                   __func__);
+                       ecuf = kmem_zalloc(sizeof(*ecuf), KM_SLEEP);
                        ecuf_init(ecuf);
                        ecuf->ecuf_funcno = func;
                        SIMPLEQ_INSERT_TAIL(&ecud->ecud_funcs, ecuf,
@@ -557,8 +534,8 @@
                }
        }
 
-       free(cdata, M_TEMP);
-       free(data, M_TEMP);
+       kmem_free(cdata, CBUFSIZE);
+       kmem_free(data, CBUFSIZE);
 }
 
 static struct ecu_data *
diff -r 1b6e82a69e5e -r c37acb00f6b8 sys/arch/alpha/isa/isadma_bounce.c
--- a/sys/arch/alpha/isa/isadma_bounce.c        Wed Nov 18 01:12:00 2020 +0000
+++ b/sys/arch/alpha/isa/isadma_bounce.c        Wed Nov 18 02:04:29 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: isadma_bounce.c,v 1.13 2016/02/29 15:28:35 christos Exp $ */
+/* $NetBSD: isadma_bounce.c,v 1.14 2020/11/18 02:04:29 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000 The NetBSD Foundation, Inc.
@@ -32,13 +32,13 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: isadma_bounce.c,v 1.13 2016/02/29 15:28:35 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: isadma_bounce.c,v 1.14 2020/11/18 02:04:29 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.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>
 
@@ -91,28 +91,19 @@
 void   isadma_bounce_free_bouncebuf(bus_dma_tag_t, bus_dmamap_t);
 
 /*
- * Create an ISA DMA map.
+ * Returns true if the system memory configuration exceeds the
+ * capabilities of ISA DMA.
  */
-int
-isadma_bounce_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 bool
+isadma_bounce_check_range(bus_dma_tag_t const t)
 {
-       struct isadma_bounce_cookie *cookie;
-       bus_dmamap_t map;
-       int error, cookieflags;
-       void *cookiestore;
-       size_t cookiesize;
+       return avail_end > (t->_wbase + t->_wsize);
+}
 
-       /* 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(*cookie);
+static int
+isadma_bounce_cookieflags(bus_dma_tag_t const t, bus_dmamap_t const map)
+{
+       int cookieflags = 0;
 
        /*
         * ISA only has 24-bits of address space.  This means
@@ -133,42 +124,97 @@
         * the caller can't handle that many segments (e.g. the
         * ISA DMA controller), we may have to bounce it as well.
         */
-       cookieflags = 0;
-       if (avail_end > (t->_wbase + t->_wsize) ||
+       if (isadma_bounce_check_range(t) ||
            ((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 isadma_bounce_cookie);
+
+       if (cookieflags & ID_MIGHT_NEED_BOUNCE) {
                cookiesize += (sizeof(bus_dma_segment_t) *
                    (map->_dm_segcnt - 1));
        }
+       return cookiesize;
+}
+
+static int
+isadma_bounce_cookie_alloc(bus_dma_tag_t const t, bus_dmamap_t const map,
+    int const flags)
+{
+       struct isadma_bounce_cookie *cookie;
+       int cookieflags = isadma_bounce_cookieflags(t, map);
+
+       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;
+



Home | Main Index | Thread Index | Old Index