From d4ab3a8d4f06855892423f95b979697781660213 Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Thu, 21 Apr 2022 10:42:14 -0700 Subject: [PATCH] busdma_bounce: Add free_bounce_pages helper function. Deduplicate code to iterate over the bpages list in a bus_dmamap_t freeing bounce pages during bus_dmamap_unload. Reviewed by: imp Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D34967 --- sys/arm/arm/busdma_machdep.c | 6 +----- sys/arm64/arm64/busdma_bounce.c | 8 +------- sys/kern/subr_busdma_bounce.c | 11 +++++++++++ sys/powerpc/powerpc/busdma_machdep.c | 7 +------ sys/riscv/riscv/busdma_bounce.c | 8 +------- sys/x86/x86/busdma_bounce.c | 7 +------ 6 files changed, 16 insertions(+), 31 deletions(-) diff --git a/sys/arm/arm/busdma_machdep.c b/sys/arm/arm/busdma_machdep.c index ccf593b11aa5..b4110a9c7d84 100644 --- a/sys/arm/arm/busdma_machdep.c +++ b/sys/arm/arm/busdma_machdep.c @@ -1178,14 +1178,10 @@ _bus_dmamap_complete(bus_dma_tag_t dmat, bus_dmamap_t map, void bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map) { - struct bounce_page *bpage; struct bounce_zone *bz; if ((bz = dmat->bounce_zone) != NULL) { - while ((bpage = STAILQ_FIRST(&map->bpages)) != NULL) { - STAILQ_REMOVE_HEAD(&map->bpages, links); - free_bounce_page(dmat, bpage); - } + free_bounce_pages(dmat, map); bz = dmat->bounce_zone; bz->free_bpages += map->pagesreserved; diff --git a/sys/arm64/arm64/busdma_bounce.c b/sys/arm64/arm64/busdma_bounce.c index afaa1ef8510d..ce28e07d83a6 100644 --- a/sys/arm64/arm64/busdma_bounce.c +++ b/sys/arm64/arm64/busdma_bounce.c @@ -969,13 +969,7 @@ bounce_bus_dmamap_complete(bus_dma_tag_t dmat, bus_dmamap_t map, static void bounce_bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map) { - struct bounce_page *bpage; - - while ((bpage = STAILQ_FIRST(&map->bpages)) != NULL) { - STAILQ_REMOVE_HEAD(&map->bpages, links); - free_bounce_page(dmat, bpage); - } - + free_bounce_pages(dmat, map); map->sync_count = 0; map->flags &= ~DMAMAP_MBUF; } diff --git a/sys/kern/subr_busdma_bounce.c b/sys/kern/subr_busdma_bounce.c index 586998e01673..243da8e9487f 100644 --- a/sys/kern/subr_busdma_bounce.c +++ b/sys/kern/subr_busdma_bounce.c @@ -420,6 +420,17 @@ free_bounce_page(bus_dma_tag_t dmat, struct bounce_page *bpage) wakeup(&bounce_map_callbacklist); } +static void +free_bounce_pages(bus_dma_tag_t dmat, bus_dmamap_t map) +{ + struct bounce_page *bpage; + + while ((bpage = STAILQ_FIRST(&map->bpages)) != NULL) { + STAILQ_REMOVE_HEAD(&map->bpages, links); + free_bounce_page(dmat, bpage); + } +} + static void busdma_thread(void *dummy __unused) { diff --git a/sys/powerpc/powerpc/busdma_machdep.c b/sys/powerpc/powerpc/busdma_machdep.c index 666f40d4edd7..3108b60599d4 100644 --- a/sys/powerpc/powerpc/busdma_machdep.c +++ b/sys/powerpc/powerpc/busdma_machdep.c @@ -801,17 +801,12 @@ _bus_dmamap_complete(bus_dma_tag_t dmat, bus_dmamap_t map, void bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map) { - struct bounce_page *bpage; - if (dmat->iommu) { IOMMU_UNMAP(dmat->iommu, map->segments, map->nsegs, dmat->iommu_cookie); map->nsegs = 0; } - while ((bpage = STAILQ_FIRST(&map->bpages)) != NULL) { - STAILQ_REMOVE_HEAD(&map->bpages, links); - free_bounce_page(dmat, bpage); - } + free_bounce_pages(dmat, map); } void diff --git a/sys/riscv/riscv/busdma_bounce.c b/sys/riscv/riscv/busdma_bounce.c index 25e676203fbb..5680e7702a2a 100644 --- a/sys/riscv/riscv/busdma_bounce.c +++ b/sys/riscv/riscv/busdma_bounce.c @@ -810,13 +810,7 @@ bounce_bus_dmamap_complete(bus_dma_tag_t dmat, bus_dmamap_t map, static void bounce_bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map) { - struct bounce_page *bpage; - - while ((bpage = STAILQ_FIRST(&map->bpages)) != NULL) { - STAILQ_REMOVE_HEAD(&map->bpages, links); - free_bounce_page(dmat, bpage); - } - + free_bounce_pages(dmat, map); map->sync_count = 0; } diff --git a/sys/x86/x86/busdma_bounce.c b/sys/x86/x86/busdma_bounce.c index abbf64fd3965..925a1d633f7c 100644 --- a/sys/x86/x86/busdma_bounce.c +++ b/sys/x86/x86/busdma_bounce.c @@ -907,15 +907,10 @@ bounce_bus_dmamap_complete(bus_dma_tag_t dmat, bus_dmamap_t map, static void bounce_bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map) { - struct bounce_page *bpage; - if (map == NULL) return; - while ((bpage = STAILQ_FIRST(&map->bpages)) != NULL) { - STAILQ_REMOVE_HEAD(&map->bpages, links); - free_bounce_page(dmat, bpage); - } + free_bounce_pages(dmat, map); } static void