Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/hppa/dev malloc -> kmem



details:   https://anonhg.NetBSD.org/src/rev/ad4f615ff813
branches:  trunk
changeset: 371215:ad4f615ff813
user:      skrll <skrll%NetBSD.org@localhost>
date:      Thu Sep 29 06:42:14 2022 +0000

description:
malloc -> kmem

diffstat:

 sys/arch/hppa/dev/astro.c |  22 ++++++++++++++--------
 sys/arch/hppa/dev/uturn.c |  26 +++++++++++++++-----------
 2 files changed, 29 insertions(+), 19 deletions(-)

diffs (154 lines):

diff -r 1908aa6608d5 -r ad4f615ff813 sys/arch/hppa/dev/astro.c
--- a/sys/arch/hppa/dev/astro.c Thu Sep 29 06:39:58 2022 +0000
+++ b/sys/arch/hppa/dev/astro.c Thu Sep 29 06:42:14 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: astro.c,v 1.4 2021/08/07 16:18:55 thorpej Exp $        */
+/*     $NetBSD: astro.c,v 1.5 2022/09/29 06:42:14 skrll Exp $  */
 
 /*     $OpenBSD: astro.c,v 1.8 2007/10/06 23:50:54 krw Exp $   */
 
@@ -19,10 +19,11 @@
  */
 
 #include <sys/param.h>
+
 #include <sys/systm.h>
 #include <sys/device.h>
 #include <sys/extent.h>
-#include <sys/malloc.h>
+#include <sys/kmem.h>
 #include <sys/reboot.h>
 #include <sys/tree.h>
 
@@ -185,7 +186,7 @@
 void   iommu_enter(struct astro_softc *, bus_addr_t, paddr_t, vaddr_t, int);
 void   iommu_remove(struct astro_softc *, bus_addr_t);
 
-struct iommu_map_state *iommu_iomap_create(int);
+struct iommu_map_state *iommu_iomap_create(int, int);
 void   iommu_iomap_destroy(struct iommu_map_state *);
 int    iommu_iomap_insert_page(struct iommu_map_state *, vaddr_t, paddr_t);
 bus_addr_t iommu_iomap_translate(struct iommu_map_state *, paddr_t);
@@ -362,7 +363,7 @@
        if (error)
                return (error);
 
-       ims = iommu_iomap_create(atop(round_page(size)));
+       ims = iommu_iomap_create(atop(round_page(size)), flags);
        if (ims == NULL) {
                bus_dmamap_destroy(sc->sc_dmat, map);
                return (ENOMEM);
@@ -604,7 +605,7 @@
  * Create a new iomap.
  */
 struct iommu_map_state *
-iommu_iomap_create(int n)
+iommu_iomap_create(int n, int flags)
 {
        struct iommu_map_state *ims;
 
@@ -613,8 +614,10 @@
        if (n < 16)
                n = 16;
 
-       ims = malloc(sizeof(*ims) + (n - 1) * sizeof(ims->ims_map.ipm_map[0]),
-           M_DEVBUF, M_NOWAIT | M_ZERO);
+       const size_t sz =
+           sizeof(*ims) + (n - 1) * sizeof(ims->ims_map.ipm_map[0]);
+
+       ims = kmem_zalloc(sz, (flags & BUS_DMA_NOWAIT) ? KM_NOSLEEP : KM_SLEEP);
        if (ims == NULL)
                return (NULL);
 
@@ -636,8 +639,11 @@
                printf("iommu_iomap_destroy: %d page entries in use\n",
                    ims->ims_map.ipm_pagecnt);
 #endif
+       const int n = ims->ims_map.ipm_maxpage;
+       const size_t sz =
+           sizeof(*ims) + (n - 1) * sizeof(ims->ims_map.ipm_map[0]);
 
-       free(ims, M_DEVBUF);
+       kmem_free(ims, sz);
 }
 
 /*
diff -r 1908aa6608d5 -r ad4f615ff813 sys/arch/hppa/dev/uturn.c
--- a/sys/arch/hppa/dev/uturn.c Thu Sep 29 06:39:58 2022 +0000
+++ b/sys/arch/hppa/dev/uturn.c Thu Sep 29 06:42:14 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uturn.c,v 1.5 2021/08/07 16:18:55 thorpej Exp $        */
+/*     $NetBSD: uturn.c,v 1.6 2022/09/29 06:42:14 skrll Exp $  */
 
 /*     $OpenBSD: uturn.c,v 1.6 2007/12/29 01:26:14 kettenis Exp $      */
 
@@ -82,12 +82,13 @@
  */
 
 #include <sys/param.h>
+
 #include <sys/systm.h>
 #include <sys/device.h>
+#include <sys/extent.h>
+#include <sys/kmem.h>
+#include <sys/mbuf.h>
 #include <sys/reboot.h>
-#include <sys/malloc.h>
-#include <sys/extent.h>
-#include <sys/mbuf.h>
 #include <sys/tree.h>
 
 #include <uvm/uvm.h>
@@ -240,7 +241,7 @@
     vaddr_t, paddr_t);
 static void uturn_iommu_remove(struct uturn_softc *, bus_addr_t, bus_size_t);
 
-struct uturn_map_state *uturn_iomap_create(int);
+struct uturn_map_state *uturn_iomap_create(int, int);
 void   uturn_iomap_destroy(struct uturn_map_state *);
 int    uturn_iomap_insert_page(struct uturn_map_state *, vaddr_t, paddr_t);
 bus_addr_t uturn_iomap_translate(struct uturn_map_state *, paddr_t);
@@ -500,7 +501,7 @@
        if (error)
                return (error);
 
-       ums = uturn_iomap_create(atop(round_page(size)));
+       ums = uturn_iomap_create(atop(round_page(size)), flags);
        if (ums == NULL) {
                bus_dmamap_destroy(sc->sc_dmat, map);
                return (ENOMEM);
@@ -743,7 +744,7 @@
  * Create a new iomap.
  */
 struct uturn_map_state *
-uturn_iomap_create(int n)
+uturn_iomap_create(int n, int flags)
 {
        struct uturn_map_state *ums;
 
@@ -751,9 +752,9 @@
        n += 4;
        if (n < 16)
                n = 16;
-
-       ums = malloc(sizeof(*ums) + (n - 1) * sizeof(ums->ums_map.upm_map[0]),
-           M_DEVBUF, M_NOWAIT | M_ZERO);
+       const size_t sz =
+           sizeof(*ums) + (n - 1) * sizeof(ums->ums_map.upm_map[0]);
+       ums = kmem_zalloc(sz, (flags & BUS_DMA_NOWAIT) ? KM_NOSLEEP : KM_SLEEP);
        if (ums == NULL)
                return (NULL);
 
@@ -771,8 +772,11 @@
 uturn_iomap_destroy(struct uturn_map_state *ums)
 {
        KASSERT(ums->ums_map.upm_pagecnt == 0);
+       const int n = ums->ums_map.upm_maxpage;
+       const size_t sz =
+           sizeof(*ums) + (n - 1) * sizeof(ums->ums_map.upm_map[0]);
 
-       free(ums, M_DEVBUF);
+       kmem_free(ums, sz);
 }
 
 /*



Home | Main Index | Thread Index | Old Index