Source-Changes-HG archive

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

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



details:   https://anonhg.NetBSD.org/src/rev/12348c268f1e
branches:  trunk
changeset: 978451:12348c268f1e
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sat Nov 21 21:01:16 2020 +0000

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

diffstat:

 sys/arch/hppa/dev/apic.c     |  17 ++++++++---------
 sys/arch/hppa/hppa/mainbus.c |  33 +++++++++++++++++++--------------
 2 files changed, 27 insertions(+), 23 deletions(-)

diffs (172 lines):

diff -r 2ddff69ca032 -r 12348c268f1e sys/arch/hppa/dev/apic.c
--- a/sys/arch/hppa/dev/apic.c  Sat Nov 21 20:55:45 2020 +0000
+++ b/sys/arch/hppa/dev/apic.c  Sat Nov 21 21:01:16 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: apic.c,v 1.3 2019/11/10 21:16:28 chs Exp $     */
+/*     $NetBSD: apic.c,v 1.4 2020/11/21 21:01:16 thorpej Exp $ */
 
 /*     $OpenBSD: apic.c,v 1.14 2011/05/01 21:59:39 kettenis Exp $      */
 
@@ -22,7 +22,7 @@
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/device.h>
-#include <sys/malloc.h>
+#include <sys/kmem.h>
 
 #include <machine/autoconf.h>
 #include <machine/pdc.h>
@@ -109,8 +109,7 @@
        aprint_normal(" APIC ver %x, %d pins",
            data & APIC_VERSION_MASK, sc->sc_nints);
 
-       sc->sc_irq = malloc(sc->sc_nints * sizeof(int), M_DEVBUF,
-           M_WAITOK | M_ZERO);
+       sc->sc_irq = kmem_zalloc(sc->sc_nints * sizeof(int), KM_SLEEP);
 
        apic_get_int_tbl(sc);
 
@@ -171,8 +170,8 @@
        if (irq <= 0 || irq > 31)
                return NULL;
 
-       aiv = malloc(sizeof(struct apic_iv), M_DEVBUF, M_WAITOK);
-       cnt = malloc(sizeof(struct evcnt), M_DEVBUF, M_WAITOK);
+       aiv = kmem_alloc(sizeof(struct apic_iv), KM_SLEEP);
+       cnt = kmem_alloc(sizeof(struct evcnt), KM_SLEEP);
        aiv->sc = sc;
        aiv->ih = ih;
        aiv->handler = handler;
@@ -184,8 +183,8 @@
        if (biv == NULL) {
                iv = hppa_intr_establish(pri, apic_intr, aiv, &ci->ci_ir, irq);
                if (iv == NULL) {
-                       free(aiv, M_DEVBUF);
-                       free(cnt, M_DEVBUF);
+                       kmem_free(aiv, sizeof(*aiv));
+                       kmem_free(cnt, sizeof(*cnt));
 
                        return NULL;
                }
@@ -267,7 +266,7 @@
 
        size = nentries * sizeof(struct pdc_pat_pci_rt);
        sc->sc_int_tbl_sz = nentries;
-       sc->sc_int_tbl = malloc(size, M_DEVBUF, M_WAITOK);
+       sc->sc_int_tbl = kmem_alloc(size, KM_SLEEP);
 
        pdcproc_pci_gettable(nentries, size, sc->sc_int_tbl);
 }
diff -r 2ddff69ca032 -r 12348c268f1e sys/arch/hppa/hppa/mainbus.c
--- a/sys/arch/hppa/hppa/mainbus.c      Sat Nov 21 20:55:45 2020 +0000
+++ b/sys/arch/hppa/hppa/mainbus.c      Sat Nov 21 21:01:16 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mainbus.c,v 1.5 2020/10/16 17:50:44 macallan Exp $     */
+/*     $NetBSD: mainbus.c,v 1.6 2020/11/21 21:01:16 thorpej Exp $      */
 
 /*-
  * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.5 2020/10/16 17:50:44 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.6 2020/11/21 21:01:16 thorpej Exp $");
 
 #include "locators.h"
 #include "power.h"
@@ -71,6 +71,7 @@
 #include <sys/extent.h>
 #include <sys/mbuf.h>
 #include <sys/proc.h>
+#include <sys/kmem.h>
 
 #include <uvm/uvm_page.h>
 #include <uvm/uvm.h>
@@ -729,6 +730,14 @@
        mbus_cp_1,  mbus_cp_2, mbus_cp_4, mbus_cp_8
 };
 
+static size_t
+_bus_dmamap_mapsize(int const nsegments)
+{
+       KASSERT(nsegments > 0);
+       return sizeof(struct hppa_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.
@@ -738,7 +747,6 @@
     bus_size_t boundary, int flags, bus_dmamap_t *dmamp)
 {
        struct hppa_bus_dmamap *map;
-       size_t mapsize;
 
        /*
         * Allocate and initialize the DMA map.  The end of the map is a
@@ -752,14 +760,11 @@
         * The bus_dmamap_t includes one bus_dma_segment_t, hence the
         * (nsegments - 1).
         */
-       mapsize = sizeof(struct hppa_bus_dmamap) +
-           (sizeof(bus_dma_segment_t) * (nsegments - 1));
-       map = malloc(mapsize, M_DMAMAP,
-           (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK);
+       map = kmem_zalloc(_bus_dmamap_mapsize(nsegments),
+           (flags & BUS_DMA_NOWAIT) ? KM_NOSLEEP : KM_SLEEP);
        if (!map)
                return ENOMEM;
 
-       memset(map, 0, mapsize);
        map->_dm_size = size;
        map->_dm_segcnt = nsegments;
        map->_dm_maxsegsz = maxsegsz;
@@ -786,7 +791,7 @@
        if (map->dm_mapsize != 0)
                mbus_dmamap_unload(v, map);
 
-       free(map, M_DMAMAP);
+       kmem_free(map, _bus_dmamap_mapsize(map->_dm_segcnt));
 }
 
 /*
@@ -1067,8 +1072,8 @@
        low = 0;
        high = ((flags & BUS_DMA_24BIT) ? (1 << 24) : 0) - 1;
 
-       if ((mlist = malloc(sizeof(*mlist), M_DEVBUF,
-           (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK)) == NULL)
+       if ((mlist = kmem_alloc(sizeof(*mlist),
+           (flags & BUS_DMA_NOWAIT) ? KM_NOSLEEP : KM_SLEEP)) == NULL)
                return ENOMEM;
 
        /*
@@ -1083,7 +1088,7 @@
                DPRINTF(("%s: uvm_pglistalloc(%lx, %lx, %lx, 0, 0, %p, %d, %0x)"
                    " failed", __func__, size, low, high, mlist, nsegs,
                    (flags & BUS_DMA_NOWAIT) == 0));
-               free(mlist, M_DEVBUF);
+               kmem_free(mlist, sizeof(*mlist));
                return error;
        }
 
@@ -1095,7 +1100,7 @@
                if (pa != pa_next) {
                        if (++seg >= nsegs) {
                                uvm_pglistfree(mlist);
-                               free(mlist, M_DEVBUF);
+                               kmem_free(mlist, sizeof(*mlist));
                                return ENOMEM;
                        }
                        segs[seg].ds_addr = pa;
@@ -1136,7 +1141,7 @@
                return;
 
        uvm_pglistfree(mlist);
-       free(mlist, M_DEVBUF);
+       kmem_free(mlist, sizeof(*mlist));
 }
 
 /*



Home | Main Index | Thread Index | Old Index