[ARM] dma: provide a better dma_map_page() implementation
authorRussell King <rmk@dyn-67.arm.linux.org.uk>
Thu, 25 Sep 2008 19:59:12 +0000 (20:59 +0100)
committerRussell King <rmk+kernel@arm.linux.org.uk>
Thu, 25 Sep 2008 22:39:24 +0000 (23:39 +0100)
We can translate a struct page directly to a DMA address using
page_to_dma().  No need to use page_address() followed by
virt_to_dma().

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
arch/arm/common/dmabounce.c
arch/arm/include/asm/dma-mapping.h

index 35c72bcf3d0b280345cd273e61f19235ba65d9f6..c7f23ced0a360c4ceee2dba7c0261d3161d72765 100644 (file)
@@ -412,6 +412,19 @@ dma_map_single(struct device *dev, void *ptr, size_t size,
        return dma_addr;
 }
 
+dma_addr_t dma_map_page(struct device *dev, struct page *page,
+                       unsigned long offset, size_t size,
+                       enum dma_data_direction dir)
+{
+       dev_dbg(dev, "%s(page=%p,off=%#lx,size=%zx,dir=%x)\n",
+               __func__, page, offset, size, dir);
+
+       BUG_ON(dir == DMA_NONE);
+
+       return map_single(dev, page_address(page) + offset, size, dir);
+}
+EXPORT_SYMBOL(dma_map_page);
+
 /*
  * see if a mapped address was really a "safe" buffer and if so, copy
  * the data from the safe buffer back to the unsafe buffer and free up
index eff954852c2bf12f6ddfbcdcdfea4dbd8c1e9478..856ee1bdee57e45315d125646f7653e9504b0407 100644 (file)
@@ -227,13 +227,22 @@ extern dma_addr_t dma_map_single(struct device *,void *, size_t, enum dma_data_d
  * can regain ownership by calling dma_unmap_page() or
  * dma_sync_single_for_cpu().
  */
+#ifndef CONFIG_DMABOUNCE
 static inline dma_addr_t
 dma_map_page(struct device *dev, struct page *page,
             unsigned long offset, size_t size,
             enum dma_data_direction dir)
 {
-       return dma_map_single(dev, page_address(page) + offset, size, dir);
+       if (!arch_is_coherent())
+               dma_cache_maint(page_address(page) + offset, size, dir);
+
+       return page_to_dma(dev, page) + offset;
 }
+#else
+extern dma_addr_t dma_map_page(struct device *dev, struct page *page,
+                       unsigned long offset, size_t size,
+                       enum dma_data_direction dir);
+#endif
 
 /**
  * dma_unmap_single - unmap a single buffer previously mapped