Source-Changes-HG archive

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

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



details:   https://anonhg.NetBSD.org/src/rev/12c1823ca6ef
branches:  trunk
changeset: 949193:12c1823ca6ef
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Mon Jan 04 18:09:01 2021 +0000

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

diffstat:

 sys/arch/mips/adm5120/adm5120_intr.c |  10 +++---
 sys/arch/mips/mips/bus_dma.c         |  49 ++++++++++++++++++++++-------------
 sys/arch/mips/ralink/ralink_intr.c   |  10 +++---
 3 files changed, 40 insertions(+), 29 deletions(-)

diffs (222 lines):

diff -r 22e511c9fdf3 -r 12c1823ca6ef sys/arch/mips/adm5120/adm5120_intr.c
--- a/sys/arch/mips/adm5120/adm5120_intr.c      Mon Jan 04 17:35:12 2021 +0000
+++ b/sys/arch/mips/adm5120/adm5120_intr.c      Mon Jan 04 18:09:01 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: adm5120_intr.c,v 1.8 2019/11/10 21:16:29 chs Exp $     */
+/*     $NetBSD: adm5120_intr.c,v 1.9 2021/01/04 18:11:26 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2007 Ruslan Ermilov and Vsevolod Lobko.
@@ -67,14 +67,14 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: adm5120_intr.c,v 1.8 2019/11/10 21:16:29 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: adm5120_intr.c,v 1.9 2021/01/04 18:11:26 thorpej Exp $");
 
 #include "opt_ddb.h"
 #define __INTR_PRIVATE
 
 #include <sys/param.h>
 #include <sys/intr.h>
-#include <sys/malloc.h>
+#include <sys/kmem.h>
 
 #include <mips/locore.h>
 #include <mips/adm5120/include/adm5120reg.h>
@@ -191,7 +191,7 @@
        if (irq < 0 || irq >= NIRQS)
                panic("adm5120_intr_establish: bogus IRQ %d", irq);
 
-       ih = malloc(sizeof(*ih), M_DEVBUF, M_WAITOK);
+       ih = kmem_alloc(sizeof(*ih), KM_SLEEP);
        ih->ih_func = func;
        ih->ih_arg = arg;
        ih->ih_irq = irq;
@@ -259,7 +259,7 @@
 
        splx(s);
 
-       free(ih, M_DEVBUF);
+       kmem_free(ih, sizeof(*ih));
 }
 void
 evbmips_iointr(int ipl, uint32_t ipending, struct clockframe *cf)
diff -r 22e511c9fdf3 -r 12c1823ca6ef sys/arch/mips/mips/bus_dma.c
--- a/sys/arch/mips/mips/bus_dma.c      Mon Jan 04 17:35:12 2021 +0000
+++ b/sys/arch/mips/mips/bus_dma.c      Mon Jan 04 18:09:01 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bus_dma.c,v 1.42 2020/07/16 13:32:05 simonb Exp $      */
+/*     $NetBSD: bus_dma.c,v 1.43 2021/01/04 18:09:01 thorpej Exp $     */
 
 /*-
  * Copyright (c) 1997, 1998, 2001, 2020 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.42 2020/07/16 13:32:05 simonb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.43 2021/01/04 18:09:01 thorpej Exp $");
 
 #define _MIPS_BUS_DMA_PRIVATE
 
@@ -42,7 +42,7 @@
 #include <sys/device.h>
 #include <sys/evcnt.h>
 #include <sys/kernel.h>
-#include <sys/malloc.h>
+#include <sys/kmem.h>
 #include <sys/mbuf.h>
 #include <sys/proc.h>
 #include <sys/systm.h>
@@ -285,6 +285,22 @@
 }
 #endif /* _MIPS_NEED_BUS_DMA_BOUNCE */
 
+static size_t 
+_bus_dmamap_mapsize(int const nsegments)
+{ 
+       KASSERT(nsegments > 0);
+       return sizeof(struct mips_bus_dmamap) +
+           (sizeof(bus_dma_segment_t) * (nsegments - 1));
+}
+
+static size_t
+_bus_dmamap_cookiesize(int const nsegments)
+{
+       KASSERT(nsegments > 0);
+       return sizeof(struct mips_bus_dma_cookie) +
+           (sizeof(bus_dma_segment_t) * nsegments);
+}
+
 /*
  * Common function for DMA map creation.  May be called by bus-specific
  * DMA map creation functions.
@@ -295,9 +311,8 @@
 {
        struct mips_bus_dmamap *map;
        void *mapstore;
-       size_t mapsize;
-       const int mallocflags = M_ZERO |
-           ((flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK);
+       const int allocflags =
+           ((flags & BUS_DMA_NOWAIT) ? KM_NOSLEEP : KM_SLEEP);
 
        int error = 0;
 
@@ -313,9 +328,8 @@
         * The bus_dmamap_t includes one bus_dma_segment_t, hence
         * the (nsegments - 1).
         */
-       mapsize = sizeof(struct mips_bus_dmamap) +
-           (sizeof(bus_dma_segment_t) * (nsegments - 1));
-       if ((mapstore = malloc(mapsize, M_DMAMAP, mallocflags)) == NULL)
+       if ((mapstore = kmem_zalloc(_bus_dmamap_mapsize(nsegments),
+            allocflags)) == NULL)
                return (ENOMEM);
 
        map = mapstore;
@@ -336,7 +350,6 @@
        struct mips_bus_dma_cookie *cookie;
        int cookieflags;
        void *cookiestore;
-       size_t cookiesize;
 
        if (t->_bounce_thresh == 0 || _BUS_AVAIL_END <= t->_bounce_thresh)
                map->_dm_bounce_thresh = 0;
@@ -356,13 +369,11 @@
                return 0;
        }
 
-       cookiesize = sizeof(struct mips_bus_dma_cookie) +
-           (sizeof(bus_dma_segment_t) * map->_dm_segcnt);
-
        /*
         * Allocate our cookie.
         */
-       if ((cookiestore = malloc(cookiesize, M_DMAMAP, mallocflags)) == NULL) {
+       if ((cookiestore = kmem_zalloc(_bus_dmamap_cookiesize(nsegments),
+            allocflags)) == NULL) {
                error = ENOMEM;
                goto out;
        }
@@ -403,13 +414,13 @@
                if (cookie->id_flags & _BUS_DMA_HAS_BOUNCE)
                        _bus_dma_free_bouncebuf(t, map);
                STAT_INCR(bounced_destroys);
-               free(cookie, M_DMAMAP);
+               kmem_free(cookie, _bus_dmamap_cookiesize(map->_dm_segcnt));
        } else
 #endif
        STAT_INCR(destroys);
        if (map->dm_nsegs > 0)
                STAT_INCR(unloads);
-       free(map, M_DMAMAP);
+       kmem_free(map, _bus_dmamap_mapsize(map->_dm_segcnt));
 }
 
 /*
@@ -1325,8 +1336,8 @@
                return 0;
        }
 
-       if ((*newtag = malloc(sizeof(struct mips_bus_dma_tag), M_DMAMAP,
-           (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK)) == NULL)
+       if ((*newtag = kmem_alloc(sizeof(struct mips_bus_dma_tag),
+           (flags & BUS_DMA_NOWAIT) ? KM_NOSLEEP : KM_SLEEP)) == NULL)
                return ENOMEM;
 
        **newtag = *tag;
@@ -1354,7 +1365,7 @@
        case 0:
                break;                          /* not allocated with malloc */
        case 1:
-               free(tag, M_DMAMAP);            /* last reference to tag */
+               kmem_free(tag, sizeof(*tag));   /* last reference to tag */
                break;
        default:
                (tag->_tag_needs_free)--;       /* one less reference */
diff -r 22e511c9fdf3 -r 12c1823ca6ef sys/arch/mips/ralink/ralink_intr.c
--- a/sys/arch/mips/ralink/ralink_intr.c        Mon Jan 04 17:35:12 2021 +0000
+++ b/sys/arch/mips/ralink/ralink_intr.c        Mon Jan 04 18:09:01 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ralink_intr.c,v 1.6 2019/11/10 21:16:30 chs Exp $      */
+/*     $NetBSD: ralink_intr.c,v 1.7 2021/01/04 18:14:38 thorpej Exp $  */
 /*-
  * Copyright (c) 2011 CradlePoint Technology, Inc.
  * All rights reserved.
@@ -29,14 +29,14 @@
 #define __INTR_PRIVATE
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ralink_intr.c,v 1.6 2019/11/10 21:16:30 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ralink_intr.c,v 1.7 2021/01/04 18:14:38 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
 #include <sys/device.h>
 #include <sys/intr.h>
 #include <sys/kernel.h>
-#include <sys/malloc.h>
+#include <sys/kmem.h>
 #include <sys/systm.h>
 
 #include <mips/locore.h>
@@ -267,7 +267,7 @@
 {
        struct evbmips_intrhand *ih;
 
-       ih = malloc(sizeof(*ih), M_DEVBUF, M_WAITOK);
+       ih = kmem_alloc(sizeof(*ih), KM_SLEEP);
        ih->ih_func = func;
        ih->ih_arg = arg;
        ih->ih_irq = intr;
@@ -310,7 +310,7 @@
 
        splx(s);
 
-       free(ih, M_DEVBUF);
+       kmem_free(ih, sizeof(*ih));
 }
 
 /*



Home | Main Index | Thread Index | Old Index