aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBecky Bruce <beckyb@kernel.crashing.org>2009-04-08 10:09:20 -0400
committerIngo Molnar <mingo@elte.hu>2009-04-08 10:18:37 -0400
commit380d687833aee098c4a2c3b35beaefe1c1f48d01 (patch)
treee021403a737ccd040621a17be9d8e545f8d76ea0 /lib
parent7fcebbd2d984eac3fdd6da2f4453e7c43d32de89 (diff)
swiotlb: use swiotlb_sync_single instead of duplicating code
Right now both swiotlb_sync_single_range and swiotlb_sync_sg were duplicating the code in swiotlb_sync_single. Just call it instead. Also rearrange the sync_single code for readability. Note that the swiotlb_sync_sg code was previously doing a complicated comparison to determine if an addresses needed to be unmapped where a simple is_swiotlb_buffer() call would have sufficed. Signed-off-by: Becky Bruce <beckyb@kernel.crashing.org> Acked-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Signed-off-by: Kumar Gala <galak@kernel.crashing.org> Cc: jeremy@goop.org Cc: ian.campbell@citrix.com LKML-Reference: <1239199761-22886-7-git-send-email-galak@kernel.crashing.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'lib')
-rw-r--r--lib/swiotlb.c30
1 files changed, 12 insertions, 18 deletions
diff --git a/lib/swiotlb.c b/lib/swiotlb.c
index 2bde54a40d86..d912f068145c 100644
--- a/lib/swiotlb.c
+++ b/lib/swiotlb.c
@@ -731,10 +731,16 @@ swiotlb_sync_single(struct device *hwdev, dma_addr_t dev_addr,
731 char *dma_addr = swiotlb_bus_to_virt(dev_addr); 731 char *dma_addr = swiotlb_bus_to_virt(dev_addr);
732 732
733 BUG_ON(dir == DMA_NONE); 733 BUG_ON(dir == DMA_NONE);
734 if (is_swiotlb_buffer(dma_addr)) 734
735 if (is_swiotlb_buffer(dma_addr)) {
735 sync_single(hwdev, dma_addr, size, dir, target); 736 sync_single(hwdev, dma_addr, size, dir, target);
736 else if (dir == DMA_FROM_DEVICE) 737 return;
737 dma_mark_clean(dma_addr, size); 738 }
739
740 if (dir != DMA_FROM_DEVICE)
741 return;
742
743 dma_mark_clean(dma_addr, size);
738} 744}
739 745
740void 746void
@@ -761,13 +767,7 @@ swiotlb_sync_single_range(struct device *hwdev, dma_addr_t dev_addr,
761 unsigned long offset, size_t size, 767 unsigned long offset, size_t size,
762 int dir, int target) 768 int dir, int target)
763{ 769{
764 char *dma_addr = swiotlb_bus_to_virt(dev_addr) + offset; 770 swiotlb_sync_single(hwdev, dev_addr + offset, size, dir, target);
765
766 BUG_ON(dir == DMA_NONE);
767 if (is_swiotlb_buffer(dma_addr))
768 sync_single(hwdev, dma_addr, size, dir, target);
769 else if (dir == DMA_FROM_DEVICE)
770 dma_mark_clean(dma_addr, size);
771} 771}
772 772
773void 773void
@@ -890,15 +890,9 @@ swiotlb_sync_sg(struct device *hwdev, struct scatterlist *sgl,
890 struct scatterlist *sg; 890 struct scatterlist *sg;
891 int i; 891 int i;
892 892
893 BUG_ON(dir == DMA_NONE); 893 for_each_sg(sgl, sg, nelems, i)
894 894 swiotlb_sync_single(hwdev, sg->dma_address,
895 for_each_sg(sgl, sg, nelems, i) {
896 if (sg->dma_address != swiotlb_phys_to_bus(hwdev, sg_phys(sg)))
897 sync_single(hwdev, swiotlb_bus_to_virt(sg->dma_address),
898 sg->dma_length, dir, target); 895 sg->dma_length, dir, target);
899 else if (dir == DMA_FROM_DEVICE)
900 dma_mark_clean(swiotlb_bus_to_virt(sg->dma_address), sg->dma_length);
901 }
902} 896}
903 897
904void 898void