kernel - Add BUS_DMA_KEEP_PG_OFFSET (i386)
authorMarkus Pfeiffer <markus.pfeiffer@morphism.de>
Wed, 4 Jul 2012 13:31:38 +0000 (13:31 +0000)
committerMarkus Pfeiffer <markus.pfeiffer@morphism.de>
Wed, 4 Jul 2012 13:31:38 +0000 (13:31 +0000)
Add BUS_DMA_KEEP_PG_OFFSET from FreeBSD in preparation of import of
FreeBSD's USB stack

sys/platform/pc32/i386/busdma_machdep.c

index b6e7a8a..a8cff4e 100644 (file)
@@ -1371,6 +1371,11 @@ add_bounce_page(bus_dma_tag_t dmat, bus_dmamap_t map, vm_offset_t vaddr,
 
        BZ_UNLOCK(bz);
 
+       if (dmat->flags & BUS_DMA_KEEP_PG_OFFSET) {
+               /* Page offset needs to be preserved. */
+               bpage->vaddr |= vaddr & PAGE_MASK;
+               bpage->busaddr |= vaddr & PAGE_MASK;
+       }
        bpage->datavaddr = vaddr;
        bpage->datacount = size;
        STAILQ_INSERT_TAIL(&map->bpages, bpage, links);
@@ -1386,6 +1391,16 @@ free_bounce_page(bus_dma_tag_t dmat, struct bounce_page *bpage)
        bpage->datavaddr = 0;
        bpage->datacount = 0;
 
+       if (dmat->flags & BUS_DMA_KEEP_PG_OFFSET) {
+               /*
+                * Reset the bounce page to start at offset 0.  Other uses
+                * of this bounce page may need to store a full page of
+                * data and/or assume it starts on a page boundary.
+                */
+               bpage->vaddr &= ~PAGE_MASK;
+               bpage->busaddr &= ~PAGE_MASK;
+       }
+
        BZ_LOCK(bz);
 
        STAILQ_INSERT_HEAD(&bz->bounce_page_list, bpage, links);