summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJeremy Fitzhardinge <jeremy@goop.org>2008-12-16 12:17:32 -0800
committerIngo Molnar <mingo@elte.hu>2008-12-17 18:58:14 +0100
commit1b548f667c1487d92e794a9f7a67788f49b952d8 (patch)
tree5d3dc337430be7a13ab0235e44e8ee3697608113 /lib
parentb81ea27b2329bf44b30c427800954f845896d476 (diff)
downloadlinux-1b548f667c1487d92e794a9f7a67788f49b952d8.tar.gz
linux-1b548f667c1487d92e794a9f7a67788f49b952d8.tar.bz2
linux-1b548f667c1487d92e794a9f7a67788f49b952d8.zip
swiotlb: factor out copy to/from device
Impact: generalize IO bounce memcpys Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'lib')
-rw-r--r--lib/swiotlb.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/swiotlb.c b/lib/swiotlb.c
index d8b09051c455..a0b4039e2880 100644
--- a/lib/swiotlb.c
+++ b/lib/swiotlb.c
@@ -312,6 +312,15 @@ static int is_swiotlb_buffer(char *addr)
return addr >= io_tlb_start && addr < io_tlb_end;
}
+static void
+__sync_single(char *buffer, char *dma_addr, size_t size, int dir)
+{
+ if (dir == DMA_TO_DEVICE)
+ memcpy(dma_addr, buffer, size);
+ else
+ memcpy(buffer, dma_addr, size);
+}
+
/*
* Allocates bounce buffer and returns its kernel virtual address.
*/
@@ -413,7 +422,7 @@ found:
for (i = 0; i < nslots; i++)
io_tlb_orig_addr[index+i] = buffer + (i << IO_TLB_SHIFT);
if (dir == DMA_TO_DEVICE || dir == DMA_BIDIRECTIONAL)
- memcpy(dma_addr, buffer, size);
+ __sync_single(buffer, dma_addr, size, DMA_TO_DEVICE);
return dma_addr;
}
@@ -437,7 +446,7 @@ unmap_single(struct device *hwdev, char *dma_addr, size_t size, int dir)
* bounce... copy the data back into the original buffer * and
* delete the bounce buffer.
*/
- memcpy(buffer, dma_addr, size);
+ __sync_single(buffer, dma_addr, size, DMA_FROM_DEVICE);
/*
* Return the buffer to the free list by setting the corresponding
@@ -477,13 +486,13 @@ 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))
- memcpy(buffer, dma_addr, size);
+ __sync_single(buffer, 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))
- memcpy(dma_addr, buffer, size);
+ __sync_single(buffer, dma_addr, size, DMA_TO_DEVICE);
else
BUG_ON(dir != DMA_FROM_DEVICE);
break;