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/faeccd9ffc3b
branches:  trunk
changeset: 946233:faeccd9ffc3b
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sat Nov 21 18:23:36 2020 +0000

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

diffstat:

 sys/arch/mipsco/isa/isa_machdep.c |  10 +++++-----
 sys/arch/mipsco/mipsco/bus_dma.c  |  23 ++++++++++++++---------
 sys/arch/mmeye/dev/mmeyepcmcia.c  |  18 +++++++++---------
 3 files changed, 28 insertions(+), 23 deletions(-)

diffs (184 lines):

diff -r f0c811699479 -r faeccd9ffc3b sys/arch/mipsco/isa/isa_machdep.c
--- a/sys/arch/mipsco/isa/isa_machdep.c Sat Nov 21 18:12:55 2020 +0000
+++ b/sys/arch/mipsco/isa/isa_machdep.c Sat Nov 21 18:23:36 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: isa_machdep.c,v 1.16 2019/11/10 21:16:30 chs Exp $     */
+/*     $NetBSD: isa_machdep.c,v 1.17 2020/11/21 18:28:32 thorpej Exp $ */
 
 /*
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -30,12 +30,12 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: isa_machdep.c,v 1.16 2019/11/10 21:16:30 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: isa_machdep.c,v 1.17 2020/11/21 18:28:32 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/sysconf.h>
@@ -179,7 +179,7 @@
 {
        struct mipsco_intrhand *ih;
 
-       ih = malloc(sizeof *ih, M_DEVBUF, M_WAITOK);
+       ih = kmem_alloc(sizeof *ih, KM_SLEEP);
        ih->ih_fun = ih_fun;
        ih->ih_arg  = ih_arg;
        LIST_INSERT_HEAD(&ic->intr_q, ih, ih_q);
@@ -192,7 +192,7 @@
        struct mipsco_intrhand *ih = cookie;
 
        LIST_REMOVE(ih, ih_q);
-       free(ih, M_DEVBUF);
+       kmem_free(ih, sizeof(*ih));
 }
 
 int
diff -r f0c811699479 -r faeccd9ffc3b sys/arch/mipsco/mipsco/bus_dma.c
--- a/sys/arch/mipsco/mipsco/bus_dma.c  Sat Nov 21 18:12:55 2020 +0000
+++ b/sys/arch/mipsco/mipsco/bus_dma.c  Sat Nov 21 18:23:36 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bus_dma.c,v 1.29 2015/06/11 08:22:09 matt Exp $        */
+/*     $NetBSD: bus_dma.c,v 1.30 2020/11/21 18:28:33 thorpej Exp $     */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -31,13 +31,14 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.29 2015/06/11 08:22:09 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.30 2020/11/21 18:28:33 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/mbuf.h>
 #include <sys/device.h>
 #include <sys/proc.h>
+#include <sys/kmem.h>
 
 #include <uvm/uvm_extern.h>
 
@@ -74,6 +75,14 @@
        t->_dmamem_mmap = _bus_dmamem_mmap;
 }
 
+static size_t 
+_bus_dmamap_mapsize(int const nsegments)
+{ 
+       KASSERT(nsegments > 0);
+       return sizeof(struct mipsco_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.
@@ -83,7 +92,6 @@
 {
        struct mipsco_bus_dmamap *map;
        void *mapstore;
-       size_t mapsize;
 
        /*
         * Allocate and initialize the DMA map.  The end of the map
@@ -97,13 +105,10 @@
         * The bus_dmamap_t includes one bus_dma_segment_t, hence
         * the (nsegments - 1).
         */
-       mapsize = sizeof(struct mipsco_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 mipsco_bus_dmamap *)mapstore;
        map->_dm_size = size;
        map->_dm_segcnt = nsegments;
@@ -126,7 +131,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 f0c811699479 -r faeccd9ffc3b sys/arch/mmeye/dev/mmeyepcmcia.c
--- a/sys/arch/mmeye/dev/mmeyepcmcia.c  Sat Nov 21 18:12:55 2020 +0000
+++ b/sys/arch/mmeye/dev/mmeyepcmcia.c  Sat Nov 21 18:23:36 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mmeyepcmcia.c,v 1.22 2012/10/27 17:18:03 chs Exp $     */
+/*     $NetBSD: mmeyepcmcia.c,v 1.23 2020/11/21 18:23:36 thorpej Exp $ */
 
 /*
  * Copyright (c) 1997 Marc Horowitz.  All rights reserved.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mmeyepcmcia.c,v 1.22 2012/10/27 17:18:03 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mmeyepcmcia.c,v 1.23 2020/11/21 18:23:36 thorpej Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -46,7 +46,7 @@
 #include <sys/proc.h>
 #include <sys/device.h>
 #include <sys/extent.h>
-#include <sys/malloc.h>
+#include <sys/kmem.h>
 #include <sys/kthread.h>
 #include <sys/bus.h>
 
@@ -408,9 +408,9 @@
                                        break;
                                if (pe2->pe_type == MMEYEPCMCIA_EVENT_INSERTION) {
                                        SIMPLEQ_REMOVE_HEAD(&h->events, pe_q);
-                                       free(pe1, M_TEMP);
+                                       kmem_free(pe1, sizeof(*pe1));
                                        SIMPLEQ_REMOVE_HEAD(&h->events, pe_q);
-                                       free(pe2, M_TEMP);
+                                       kmem_free(pe2, sizeof(*pe2));
                                }
                        }
                        splx(s);
@@ -432,9 +432,9 @@
                                        break;
                                if (pe2->pe_type == MMEYEPCMCIA_EVENT_REMOVAL) {
                                        SIMPLEQ_REMOVE_HEAD(&h->events, pe_q);
-                                       free(pe1, M_TEMP);
+                                       kmem_free(pe1, sizeof(*pe1));
                                        SIMPLEQ_REMOVE_HEAD(&h->events, pe_q);
-                                       free(pe2, M_TEMP);
+                                       kmem_free(pe2, sizeof(*pe2));
                                }
                        }
                        splx(s);
@@ -447,7 +447,7 @@
                        panic("mmeyepcmcia_event_thread: unknown event %d",
                            pe->pe_type);
                }
-               free(pe, M_TEMP);
+               kmem_free(pe, sizeof(*pe));
        }
 
        h->event_thread = NULL;
@@ -590,7 +590,7 @@
        struct mmeyepcmcia_event *pe;
        int s;
 
-       pe = malloc(sizeof(*pe), M_TEMP, M_NOWAIT);
+       pe = kmem_intr_alloc(sizeof(*pe), KM_NOSLEEP);
        if (pe == NULL)
                panic("mmeyepcmcia_queue_event: can't allocate event");
 



Home | Main Index | Thread Index | Old Index