RE: [PATCHv8 05/10] ARM: dma-mapping: use asm-generic/dma-mapping-common.h

2012-04-11 Thread Marek Szyprowski
Hi Arnd,

On Tuesday, April 10, 2012 1:47 PM Arnd Bergmann wrote:

 On Tuesday 10 April 2012, Marek Szyprowski wrote:
  This patch modifies dma-mapping implementation on ARM architecture to
  use common dma_map_ops structure and asm-generic/dma-mapping-common.h
  helpers.
 
  Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
  Acked-by: Kyungmin Park kyungmin.p...@samsung.com
  ---
   arch/arm/Kconfig   |1 +
   arch/arm/include/asm/device.h  |1 +
   arch/arm/include/asm/dma-mapping.h |  196 
  +---
   arch/arm/mm/dma-mapping.c  |  148 ---
   4 files changed, 115 insertions(+), 231 deletions(-)
 
 Looks good in principle. One question: Now that many of the functions are only
 used in the dma_map_ops, can you make them 'static' instead?

Some of these non static functions (mainly arm_dma_*_sg_* family) are also used 
by dma bounce
code introduced in the next patch, that's why I left them without static 
attribute.

Best regards
-- 
Marek Szyprowski
Samsung Poland RD Center


___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


[PATCHv8 05/10] ARM: dma-mapping: use asm-generic/dma-mapping-common.h

2012-04-10 Thread Marek Szyprowski
This patch modifies dma-mapping implementation on ARM architecture to
use common dma_map_ops structure and asm-generic/dma-mapping-common.h
helpers.

Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
Acked-by: Kyungmin Park kyungmin.p...@samsung.com
---
 arch/arm/Kconfig   |1 +
 arch/arm/include/asm/device.h  |1 +
 arch/arm/include/asm/dma-mapping.h |  196 +---
 arch/arm/mm/dma-mapping.c  |  148 ---
 4 files changed, 115 insertions(+), 231 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index cf006d4..0fd27d4 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -4,6 +4,7 @@ config ARM
select HAVE_AOUT
select HAVE_DMA_API_DEBUG
select HAVE_IDE if PCI || ISA || PCMCIA
+   select HAVE_DMA_ATTRS
select HAVE_MEMBLOCK
select RTC_LIB
select SYS_SUPPORTS_APM_EMULATION
diff --git a/arch/arm/include/asm/device.h b/arch/arm/include/asm/device.h
index 7aa3680..6e2cb0e 100644
--- a/arch/arm/include/asm/device.h
+++ b/arch/arm/include/asm/device.h
@@ -7,6 +7,7 @@
 #define ASMARM_DEVICE_H
 
 struct dev_archdata {
+   struct dma_map_ops  *dma_ops;
 #ifdef CONFIG_DMABOUNCE
struct dmabounce_device_info *dmabounce;
 #endif
diff --git a/arch/arm/include/asm/dma-mapping.h 
b/arch/arm/include/asm/dma-mapping.h
index 02d651f..424b67a 100644
--- a/arch/arm/include/asm/dma-mapping.h
+++ b/arch/arm/include/asm/dma-mapping.h
@@ -11,6 +11,27 @@
 #include asm/memory.h
 
 #define ARM_DMA_ERROR  (~0)
+extern struct dma_map_ops arm_dma_ops;
+
+static inline struct dma_map_ops *get_dma_ops(struct device *dev)
+{
+   if (dev  dev-archdata.dma_ops)
+   return dev-archdata.dma_ops;
+   return arm_dma_ops;
+}
+
+static inline void set_dma_ops(struct device *dev, struct dma_map_ops *ops)
+{
+   BUG_ON(!dev);
+   dev-archdata.dma_ops = ops;
+}
+
+#include asm-generic/dma-mapping-common.h
+
+static inline int dma_set_mask(struct device *dev, u64 mask)
+{
+   return get_dma_ops(dev)-set_dma_mask(dev, mask);
+}
 
 #ifdef __arch_page_to_dma
 #error Please update to __arch_pfn_to_dma
@@ -119,7 +140,6 @@ static inline void __dma_page_dev_to_cpu(struct page *page, 
unsigned long off,
 
 extern int dma_supported(struct device *, u64);
 extern int dma_set_mask(struct device *, u64);
-
 /*
  * DMA errors are defined by all-bits-set in the DMA address.
  */
@@ -297,179 +317,17 @@ static inline void __dma_unmap_page(struct device *dev, 
dma_addr_t handle,
 }
 #endif /* CONFIG_DMABOUNCE */
 
-/**
- * dma_map_single - map a single buffer for streaming DMA
- * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
- * @cpu_addr: CPU direct mapped address of buffer
- * @size: size of buffer to map
- * @dir: DMA transfer direction
- *
- * Ensure that any data held in the cache is appropriately discarded
- * or written back.
- *
- * The device owns this memory once this call has completed.  The CPU
- * can regain ownership by calling dma_unmap_single() or
- * dma_sync_single_for_cpu().
- */
-static inline dma_addr_t dma_map_single(struct device *dev, void *cpu_addr,
-   size_t size, enum dma_data_direction dir)
-{
-   unsigned long offset;
-   struct page *page;
-   dma_addr_t addr;
-
-   BUG_ON(!virt_addr_valid(cpu_addr));
-   BUG_ON(!virt_addr_valid(cpu_addr + size - 1));
-   BUG_ON(!valid_dma_direction(dir));
-
-   page = virt_to_page(cpu_addr);
-   offset = (unsigned long)cpu_addr  ~PAGE_MASK;
-   addr = __dma_map_page(dev, page, offset, size, dir);
-   debug_dma_map_page(dev, page, offset, size, dir, addr, true);
-
-   return addr;
-}
-
-/**
- * dma_map_page - map a portion of a page for streaming DMA
- * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
- * @page: page that buffer resides in
- * @offset: offset into page for start of buffer
- * @size: size of buffer to map
- * @dir: DMA transfer direction
- *
- * Ensure that any data held in the cache is appropriately discarded
- * or written back.
- *
- * The device owns this memory once this call has completed.  The CPU
- * can regain ownership by calling dma_unmap_page().
- */
-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)
-{
-   dma_addr_t addr;
-
-   BUG_ON(!valid_dma_direction(dir));
-
-   addr = __dma_map_page(dev, page, offset, size, dir);
-   debug_dma_map_page(dev, page, offset, size, dir, addr, false);
-
-   return addr;
-}
-
-/**
- * dma_unmap_single - unmap a single buffer previously mapped
- * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
- * @handle: DMA address of buffer
- * @size: size of buffer (same as passed to dma_map_single)
- * @dir: DMA transfer direction (same as passed to dma_map_single)
- *
- * Unmap a single streaming 

Re: [PATCHv8 05/10] ARM: dma-mapping: use asm-generic/dma-mapping-common.h

2012-04-10 Thread Arnd Bergmann
On Tuesday 10 April 2012, Marek Szyprowski wrote:
 This patch modifies dma-mapping implementation on ARM architecture to
 use common dma_map_ops structure and asm-generic/dma-mapping-common.h
 helpers.
 
 Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
 Acked-by: Kyungmin Park kyungmin.p...@samsung.com
 ---
  arch/arm/Kconfig   |1 +
  arch/arm/include/asm/device.h  |1 +
  arch/arm/include/asm/dma-mapping.h |  196 
 +---
  arch/arm/mm/dma-mapping.c  |  148 ---
  4 files changed, 115 insertions(+), 231 deletions(-)

Looks good in principle. One question: Now that many of the functions are only
used in the dma_map_ops, can you make them 'static' instead?

Arnd
___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu