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
This commit is contained in:
John Baldwin 2022-04-21 10:42:14 -07:00
parent 10fe9a1fb4
commit d4ab3a8d4f
6 changed files with 16 additions and 31 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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)
{

View File

@ -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

View File

@ -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;
}

View File

@ -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