>From db63c863456f0914ad96db38544c364eaad787ab Mon Sep 17 00:00:00 2001 From: Konrad Rzeszutek Wilk Date: Mon, 29 Oct 2012 09:35:55 -0400 Subject: [PATCH] swiotlb: Add debugging. Signed-off-by: Konrad Rzeszutek Wilk --- include/linux/swiotlb.h | 2 +- lib/swiotlb.c | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index 8d08b3e..0a17d79 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -46,7 +46,7 @@ extern void swiotlb_tbl_sync_single(struct device *hwdev, char *dma_addr, enum dma_sync_target target); /* Accessory functions. */ -extern void swiotlb_bounce(phys_addr_t phys, char *dma_addr, size_t size, +extern void swiotlb_bounce(struct device *dev, phys_addr_t phys, char *dma_addr, size_t size, enum dma_data_direction dir); extern void diff --git a/lib/swiotlb.c b/lib/swiotlb.c index f114bf6..e5d37a3 100644 --- a/lib/swiotlb.c +++ b/lib/swiotlb.c @@ -346,7 +346,7 @@ static int is_swiotlb_buffer(phys_addr_t paddr) /* * Bounce: copy the swiotlb buffer back to the original dma location */ -void swiotlb_bounce(phys_addr_t phys, char *dma_addr, size_t size, +void swiotlb_bounce(struct device *dev, phys_addr_t phys, char *dma_addr, size_t size, enum dma_data_direction dir) { unsigned long pfn = PFN_DOWN(phys); @@ -376,6 +376,21 @@ void swiotlb_bounce(phys_addr_t phys, char *dma_addr, size_t size, offset = 0; } } else { + if (size >= PAGE_SIZE) { + const char *type; + + if (dir == DMA_TO_DEVICE) + type = " <= "; + else if (dir == DMA_FROM_DEVICE) + type = " => "; + else + type = " <=> "; + dev_info(dev, "0x%lx%s %s 0x%lx%s (sz: %ld)\n", (unsigned long)dma_addr, + is_swiotlb_buffer(virt_to_phys(dma_addr)) ? "(bounce)" : "", + type, (unsigned long)phys_to_virt(phys), + is_swiotlb_buffer(phys) ? "(bounce)" : "", + size); + } if (dir == DMA_TO_DEVICE) memcpy(dma_addr, phys_to_virt(phys), size); else @@ -483,7 +498,7 @@ found: for (i = 0; i < nslots; i++) io_tlb_orig_addr[index+i] = phys + (i << IO_TLB_SHIFT); if (dir == DMA_TO_DEVICE || dir == DMA_BIDIRECTIONAL) - swiotlb_bounce(phys, dma_addr, size, DMA_TO_DEVICE); + swiotlb_bounce(hwdev, phys, dma_addr, size, DMA_TO_DEVICE); return dma_addr; } @@ -518,7 +533,7 @@ swiotlb_tbl_unmap_single(struct device *hwdev, char *dma_addr, size_t size, * First, sync the memory before unmapping the entry */ if (phys && ((dir == DMA_FROM_DEVICE) || (dir == DMA_BIDIRECTIONAL))) - swiotlb_bounce(phys, dma_addr, size, DMA_FROM_DEVICE); + swiotlb_bounce(hwdev, phys, dma_addr, size, DMA_FROM_DEVICE); /* * Return the buffer to the free list by setting the corresponding @@ -560,13 +575,13 @@ swiotlb_tbl_sync_single(struct device *hwdev, char *dma_addr, size_t size, switch (target) { case SYNC_FOR_CPU: if (likely(dir == DMA_FROM_DEVICE || dir == DMA_BIDIRECTIONAL)) - swiotlb_bounce(phys, dma_addr, size, DMA_FROM_DEVICE); + swiotlb_bounce(hwdev, phys, dma_addr, size, DMA_FROM_DEVICE); else BUG_ON(dir != DMA_TO_DEVICE); break; case SYNC_FOR_DEVICE: if (likely(dir == DMA_TO_DEVICE || dir == DMA_BIDIRECTIONAL)) - swiotlb_bounce(phys, dma_addr, size, DMA_TO_DEVICE); + swiotlb_bounce(hwdev, phys, dma_addr, size, DMA_TO_DEVICE); else BUG_ON(dir != DMA_FROM_DEVICE); break; -- 1.7.7.6