Module Name: src Committed By: thorpej Date: Wed Nov 18 02:14:13 UTC 2020
Modified Files: src/sys/arch/arc/arc: bus_dma.c p_dti_arcstation.c src/sys/arch/arc/isa: isabus.c isadma_bounce.c src/sys/arch/arc/jazz: bus_dma_jazz.c pckbc_jazzio.c src/sys/arch/arc/pci: necpb.c Log Message: malloc(9) -> kmem(9) To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/sys/arch/arc/arc/bus_dma.c cvs rdiff -u -r1.19 -r1.20 src/sys/arch/arc/arc/p_dti_arcstation.c cvs rdiff -u -r1.50 -r1.51 src/sys/arch/arc/isa/isabus.c cvs rdiff -u -r1.15 -r1.16 src/sys/arch/arc/isa/isadma_bounce.c cvs rdiff -u -r1.17 -r1.18 src/sys/arch/arc/jazz/bus_dma_jazz.c cvs rdiff -u -r1.18 -r1.19 src/sys/arch/arc/jazz/pckbc_jazzio.c cvs rdiff -u -r1.45 -r1.46 src/sys/arch/arc/pci/necpb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/arc/arc/bus_dma.c diff -u src/sys/arch/arc/arc/bus_dma.c:1.34 src/sys/arch/arc/arc/bus_dma.c:1.35 --- src/sys/arch/arc/arc/bus_dma.c:1.34 Thu Jun 11 08:22:08 2015 +++ src/sys/arch/arc/arc/bus_dma.c Wed Nov 18 02:14:13 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: bus_dma.c,v 1.34 2015/06/11 08:22:08 matt Exp $ */ +/* $NetBSD: bus_dma.c,v 1.35 2020/11/18 02:14:13 thorpej Exp $ */ /* NetBSD: bus_dma.c,v 1.20 2000/01/10 03:24:36 simonb Exp */ /*- @@ -32,13 +32,14 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.34 2015/06/11 08:22:08 matt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.35 2020/11/18 02:14:13 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.h> @@ -74,6 +75,14 @@ _bus_dma_tag_init(bus_dma_tag_t t) t->_dmamem_mmap = _bus_dmamem_mmap; } +static size_t +_bus_dmamap_mapsize(int const nsegments) +{ + KASSERT(nsegments > 0); + return sizeof(struct arc_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. @@ -84,7 +93,6 @@ _bus_dmamap_create(bus_dma_tag_t t, bus_ { struct arc_bus_dmamap *map; void *mapstore; - size_t mapsize; /* * Allocate and initialize the DMA map. The end of the map @@ -98,10 +106,8 @@ _bus_dmamap_create(bus_dma_tag_t t, bus_ * The bus_dmamap_t includes one bus_dma_segment_t, hence * the (nsegments - 1). */ - mapsize = sizeof(struct arc_bus_dmamap) + - (sizeof(bus_dma_segment_t) * (nsegments - 1)); - if ((mapstore = malloc(mapsize, M_DMAMAP, - ((flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK) | M_ZERO)) == NULL) + if ((mapstore = kmem_zalloc(_bus_dmamap_mapsize(nsegments), + (flags & BUS_DMA_NOWAIT) ? KM_NOSLEEP : KM_SLEEP)) == NULL) return ENOMEM; map = (struct arc_bus_dmamap *)mapstore; @@ -127,7 +133,7 @@ void _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)); } /* Index: src/sys/arch/arc/arc/p_dti_arcstation.c diff -u src/sys/arch/arc/arc/p_dti_arcstation.c:1.19 src/sys/arch/arc/arc/p_dti_arcstation.c:1.20 --- src/sys/arch/arc/arc/p_dti_arcstation.c:1.19 Sat Jun 13 20:01:27 2020 +++ src/sys/arch/arc/arc/p_dti_arcstation.c Wed Nov 18 02:14:13 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: p_dti_arcstation.c,v 1.19 2020/06/13 20:01:27 ad Exp $ */ +/* $NetBSD: p_dti_arcstation.c,v 1.20 2020/11/18 02:14:13 thorpej Exp $ */ /* $OpenBSD: machdep.c,v 1.36 1999/05/22 21:22:19 weingart Exp $ */ /* @@ -39,7 +39,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: p_dti_arcstation.c,v 1.19 2020/06/13 20:01:27 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: p_dti_arcstation.c,v 1.20 2020/11/18 02:14:13 thorpej Exp $"); #define __INTR_PRIVATE #include <sys/param.h> @@ -165,7 +165,7 @@ btl_dti_arcstation_bouncemem(u_int *base *sizep = TYNE_S_BOUNCE; /* Good enough? XXX */ #if 0 - *basep = (u_int) malloc(*sizep, M_DEVBUF, M_WAITOK); + *basep = (u_int) kmem_alloc(*sizep, KM_SLEEP); #else *basep = (u_int) rpc44_buffer | 0xa0000000; #endif Index: src/sys/arch/arc/isa/isabus.c diff -u src/sys/arch/arc/isa/isabus.c:1.50 src/sys/arch/arc/isa/isabus.c:1.51 --- src/sys/arch/arc/isa/isabus.c:1.50 Sun Nov 10 21:16:22 2019 +++ src/sys/arch/arc/isa/isabus.c Wed Nov 18 02:14:13 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: isabus.c,v 1.50 2019/11/10 21:16:22 chs Exp $ */ +/* $NetBSD: isabus.c,v 1.51 2020/11/18 02:14:13 thorpej Exp $ */ /* $OpenBSD: isabus.c,v 1.15 1998/03/16 09:38:46 pefo Exp $ */ /* NetBSD: isa.c,v 1.33 1995/06/28 04:30:51 cgd Exp */ @@ -120,7 +120,7 @@ WITH THE USE OR PERFORMANCE OF THIS SOFT */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: isabus.c,v 1.50 2019/11/10 21:16:22 chs Exp $"); +__KERNEL_RCSID(0, "$NetBSD: isabus.c,v 1.51 2020/11/18 02:14:13 thorpej Exp $"); #include <sys/param.h> #include <sys/proc.h> @@ -129,7 +129,7 @@ __KERNEL_RCSID(0, "$NetBSD: isabus.c,v 1 #include <sys/time.h> #include <sys/kernel.h> #include <sys/device.h> -#include <sys/malloc.h> +#include <sys/kmem.h> #include <sys/extent.h> #include <uvm/uvm_extern.h> @@ -340,7 +340,7 @@ isabr_intr_establish(isa_chipset_tag_t i struct isa_intrhand **p, *q, *ih; static struct isa_intrhand fakehand = {NULL, fakeintr}; - ih = malloc(sizeof *ih, M_DEVBUF, M_WAITOK); + ih = kmem_alloc(sizeof *ih, KM_SLEEP); if (!LEGAL_IRQ(irq) || type == IST_NONE) panic("intr_establish: bogus irq or type"); Index: src/sys/arch/arc/isa/isadma_bounce.c diff -u src/sys/arch/arc/isa/isadma_bounce.c:1.15 src/sys/arch/arc/isa/isadma_bounce.c:1.16 --- src/sys/arch/arc/isa/isadma_bounce.c:1.15 Fri Feb 26 18:14:38 2016 +++ src/sys/arch/arc/isa/isadma_bounce.c Wed Nov 18 02:14:13 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: isadma_bounce.c,v 1.15 2016/02/26 18:14:38 christos Exp $ */ +/* $NetBSD: isadma_bounce.c,v 1.16 2020/11/18 02:14:13 thorpej Exp $ */ /* NetBSD: isadma_bounce.c,v 1.2 2000/06/01 05:49:36 thorpej Exp */ /*- @@ -33,13 +33,13 @@ #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ -__KERNEL_RCSID(0, "$NetBSD: isadma_bounce.c,v 1.15 2016/02/26 18:14:38 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: isadma_bounce.c,v 1.16 2020/11/18 02:14:13 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> @@ -108,6 +108,89 @@ static int isadma_bounce_alloc_bouncebuf bus_size_t, int); static void isadma_bounce_free_bouncebuf(bus_dma_tag_t, bus_dmamap_t); +/* + * Returns true if the system memory configuration exceeds the + * capabilities of ISA DMA. + */ +static bool +isadma_bounce_check_range(bus_dma_tag_t const t) +{ + return pmap_limits.avail_end > ISA_DMA_BOUNCE_THRESHOLD; +} + +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 + * we can't DMA to pages over 16M. In order to DMA to + * arbitrary buffers, we use "bounce buffers" - pages + * in memory below the 16M boundary. On DMA reads, + * DMA happens to the bounce buffers, and is copied into + * the caller's buffer. On writes, data is copied into + * but bounce buffer, and the DMA happens from those + * pages. To software using the DMA mapping interface, + * this looks simply like a data cache. + * + * If we have more than 16M of RAM in the system, we may + * need bounce buffers. We check and remember that here. + * + * ...or, there is an opposite case. The most segments + * a transfer will require is (maxxfer / PAGE_SIZE) + 1. If + * the caller can't handle that many segments (e.g. the + * ISA DMA controller), we may have to bounce it as well. + */ + 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; + + return 0; +} + +static void +isadma_bounce_cookie_free(bus_dmamap_t const map) +{ + struct isadma_bounce_cookie *cookie = map->_dm_cookie; + + if (cookie != NULL) { + kmem_free(map->_dm_cookie, + isadma_bounce_cookiesize(map, cookie->id_flags)); + map->_dm_cookie = NULL; + } +} + void isadma_bounce_tag_init(bus_dma_tag_t t) { @@ -137,9 +220,7 @@ isadma_bounce_dmamap_create(bus_dma_tag_ { struct isadma_bounce_cookie *cookie; bus_dmamap_t map; - int error, cookieflags; - void *cookiestore; - size_t cookiesize; + int error; /* Call common function to create the basic map. */ error = _bus_dmamap_create(t, size, nsegments, maxsegsz, boundary, @@ -150,63 +231,28 @@ isadma_bounce_dmamap_create(bus_dma_tag_ map = *dmamp; map->_dm_cookie = NULL; - cookiesize = sizeof(*cookie); - - /* - * ISA only has 24-bits of address space. This means - * we can't DMA to pages over 16M. In order to DMA to - * arbitrary buffers, we use "bounce buffers" - pages - * in memory below the 16M boundary. On DMA reads, - * DMA happens to the bounce buffers, and is copied into - * the caller's buffer. On writes, data is copied into - * but bounce buffer, and the DMA happens from those - * pages. To software using the DMA mapping interface, - * this looks simply like a data cache. - * - * If we have more than 16M of RAM in the system, we may - * need bounce buffers. We check and remember that here. - * - * ...or, there is an opposite case. The most segments - * a transfer will require is (maxxfer / PAGE_SIZE) + 1. If - * 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 (pmap_limits.avail_end > ISA_DMA_BOUNCE_THRESHOLD || - ((map->_dm_size / PAGE_SIZE) + 1) > map->_dm_segcnt) { - cookieflags |= ID_MIGHT_NEED_BOUNCE; - cookiesize += (sizeof(bus_dma_segment_t) * - (map->_dm_segcnt - 1)); - } - /* * Allocate our cookie. */ - if ((cookiestore = malloc(cookiesize, M_DMAMAP, - (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK)) == NULL) { - error = ENOMEM; + if ((error = isadma_bounce_cookie_alloc(t, map, flags)) != 0) { goto out; } - memset(cookiestore, 0, cookiesize); - cookie = (struct isadma_bounce_cookie *)cookiestore; - cookie->id_flags = cookieflags; - map->_dm_cookie = cookie; + cookie = map->_dm_cookie; - if (cookieflags & ID_MIGHT_NEED_BOUNCE) { + if (cookie->id_flags & ID_MIGHT_NEED_BOUNCE) { /* * Allocate the bounce pages now if the caller * wishes us to do so. */ - if ((flags & BUS_DMA_ALLOCNOW) == 0) - goto out; - - error = isadma_bounce_alloc_bouncebuf(t, map, size, flags); + if (flags & BUS_DMA_ALLOCNOW) { + error = isadma_bounce_alloc_bouncebuf(t, map, size, + flags); + } } out: if (error) { - if (map->_dm_cookie != NULL) - free(map->_dm_cookie, M_DMAMAP); + isadma_bounce_cookie_free(map); _bus_dmamap_destroy(t, map); } return error; @@ -226,7 +272,7 @@ isadma_bounce_dmamap_destroy(bus_dma_tag if (cookie->id_flags & ID_HAS_BOUNCE) isadma_bounce_free_bouncebuf(t, map); - free(cookie, M_DMAMAP); + isadma_bounce_cookie_free(map); _bus_dmamap_destroy(t, map); } Index: src/sys/arch/arc/jazz/bus_dma_jazz.c diff -u src/sys/arch/arc/jazz/bus_dma_jazz.c:1.17 src/sys/arch/arc/jazz/bus_dma_jazz.c:1.18 --- src/sys/arch/arc/jazz/bus_dma_jazz.c:1.17 Fri Jul 1 19:25:41 2011 +++ src/sys/arch/arc/jazz/bus_dma_jazz.c Wed Nov 18 02:14:13 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: bus_dma_jazz.c,v 1.17 2011/07/01 19:25:41 dyoung Exp $ */ +/* $NetBSD: bus_dma_jazz.c,v 1.18 2020/11/18 02:14:13 thorpej Exp $ */ /*- * Copyright (c) 2003 Izumi Tsutsui. All rights reserved. @@ -51,13 +51,14 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: bus_dma_jazz.c,v 1.17 2011/07/01 19:25:41 dyoung Exp $"); +__KERNEL_RCSID(0, "$NetBSD: bus_dma_jazz.c,v 1.18 2020/11/18 02:14:13 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> @@ -171,8 +172,8 @@ jazz_bus_dmamap_create(bus_dma_tag_t t, return _bus_dmamap_create(t, size, nsegments, maxsegsz, boundary, flags, dmamp); - tlbmap = malloc(sizeof(struct jazz_tlbmap), M_DMAMAP, - (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK); + tlbmap = kmem_alloc(sizeof(struct jazz_tlbmap), + (flags & BUS_DMA_NOWAIT) ? KM_NOSLEEP : KM_SLEEP); if (tlbmap == NULL) return ENOMEM; @@ -180,7 +181,7 @@ jazz_bus_dmamap_create(bus_dma_tag_t t, tlbmap->ptebase = jazz_dmatlb_alloc(npte, boundary, flags, &tlbmap->vaddr); if (tlbmap->ptebase == NULL) { - free(tlbmap, M_DMAMAP); + kmem_free(tlbmap, sizeof(struct jazz_tlbmap)); return ENOMEM; } @@ -188,7 +189,7 @@ jazz_bus_dmamap_create(bus_dma_tag_t t, flags, dmamp); if (error != 0) { jazz_dmatlb_free(tlbmap->vaddr, npte); - free(tlbmap, M_DMAMAP); + kmem_free(tlbmap, sizeof(struct jazz_tlbmap)); return error; } map = *dmamp; @@ -213,7 +214,7 @@ jazz_bus_dmamap_destroy(bus_dma_tag_t t, npte = jazz_dma_page_round(map->dm_maxsegsz) / JAZZ_DMA_PAGE_SIZE + 1; jazz_dmatlb_free(tlbmap->vaddr, npte); - free(tlbmap, M_DMAMAP); + kmem_free(tlbmap, sizeof(struct jazz_tlbmap)); } _bus_dmamap_destroy(t, map); Index: src/sys/arch/arc/jazz/pckbc_jazzio.c diff -u src/sys/arch/arc/jazz/pckbc_jazzio.c:1.18 src/sys/arch/arc/jazz/pckbc_jazzio.c:1.19 --- src/sys/arch/arc/jazz/pckbc_jazzio.c:1.18 Sat Mar 15 13:23:24 2008 +++ src/sys/arch/arc/jazz/pckbc_jazzio.c Wed Nov 18 02:14:13 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: pckbc_jazzio.c,v 1.18 2008/03/15 13:23:24 cube Exp $ */ +/* $NetBSD: pckbc_jazzio.c,v 1.19 2020/11/18 02:14:13 thorpej Exp $ */ /* NetBSD: pckbc_isa.c,v 1.2 2000/03/23 07:01:35 thorpej Exp */ /* @@ -27,14 +27,14 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: pckbc_jazzio.c,v 1.18 2008/03/15 13:23:24 cube Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pckbc_jazzio.c,v 1.19 2020/11/18 02:14:13 thorpej Exp $"); #include <sys/param.h> #include <sys/systm.h> #include <sys/kernel.h> #include <sys/proc.h> #include <sys/device.h> -#include <sys/malloc.h> +#include <sys/kmem.h> #include <sys/errno.h> #include <sys/queue.h> #include <sys/bus.h> @@ -144,8 +144,8 @@ pckbc_jazzio_attach(device_t parent, dev bus_space_map(iot, PICA_KBCMDP, 1, 0, &ioh_c)) panic("pckbc_attach: couldn't map"); - t = malloc(sizeof(struct pckbc_internal), M_DEVBUF, - M_WAITOK | M_ZERO); + t = kmem_zalloc(sizeof(struct pckbc_internal), + KM_SLEEP); t->t_iot = iot; t->t_ioh_d = ioh_d; t->t_ioh_c = ioh_c; Index: src/sys/arch/arc/pci/necpb.c diff -u src/sys/arch/arc/pci/necpb.c:1.45 src/sys/arch/arc/pci/necpb.c:1.46 --- src/sys/arch/arc/pci/necpb.c:1.45 Tue Jul 7 03:38:45 2020 +++ src/sys/arch/arc/pci/necpb.c Wed Nov 18 02:14:13 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: necpb.c,v 1.45 2020/07/07 03:38:45 thorpej Exp $ */ +/* $NetBSD: necpb.c,v 1.46 2020/11/18 02:14:13 thorpej Exp $ */ /*- * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. @@ -61,7 +61,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: necpb.c,v 1.45 2020/07/07 03:38:45 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: necpb.c,v 1.46 2020/11/18 02:14:13 thorpej Exp $"); #include "opt_pci.h" @@ -71,7 +71,7 @@ __KERNEL_RCSID(0, "$NetBSD: necpb.c,v 1. #include <sys/systm.h> #include <sys/errno.h> #include <sys/device.h> -#include <sys/malloc.h> +#include <sys/kmem.h> #include <sys/extent.h> #include <uvm/uvm_extern.h> @@ -416,7 +416,7 @@ necpb_intr_establish(pci_chipset_tag_t p if (ih >= 4) panic("%s: bogus handle", __func__); - n = malloc(sizeof(struct necpb_intrhand), M_DEVBUF, M_WAITOK); + n = kmem_alloc(sizeof(*n), KM_SLEEP); n->ih_func = func; n->ih_arg = arg; n->ih_next = NULL; @@ -470,7 +470,7 @@ necpb_intr_disestablish(pci_chipset_tag_ evcnt_detach(&n->ih_evcnt); - free(n, M_DEVBUF); + kmem_free(n, sizeof(*n)); } /*