Skip to contentSkip to conversation

ARM:dma-mapping:Support DMA-API debugging facility on ARM

PATCH Superseded [email protected] 2 participants 7 messages Jul 11, 2009 – Jul 17, 2009 Arm (32-bit)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover ARM:dma-mapping:Support DMA-API debugging facility on ARM

Hi,
This patch set introduces dma-api debugging facility on ARM, and is against -rc2-next tree.

#1 lore raw

PATCH 1/3 ARM:dma-mapping:wrappers for dma-api

From: Ming Lei <[email protected]>

---
 arch/arm/common/dmabounce.c        |   12 +++---
 arch/arm/include/asm/dma-mapping.h |   67 +++++++++++++++++++++++++++++++-----
 arch/arm/mm/dma-mapping.c          |   24 ++++++------
 3 files changed, 76 insertions(+), 27 deletions(-)
arch/arm/common/dmabounce.c +6 -6
index 734ac91..15353a3 100644
@@ -330,7 +330,7 @@ static inline void unmap_single(struct device *dev, dma_addr_t dma_addr,
  * substitute the safe buffer for the unsafe one.
  * (basically move the buffer from an unsafe area to a safe one)
  */
-dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size,
+dma_addr_t __dma_map_single(struct device *dev, void *ptr, size_t size,
 		enum dma_data_direction dir)
 {
 	dev_dbg(dev, "%s(ptr=%p,size=%d,dir=%x)\n",
@@ -340,9 +340,9 @@ dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size,
 
 	return map_single(dev, ptr, size, dir);
 }
-EXPORT_SYMBOL(dma_map_single);
+EXPORT_SYMBOL(__dma_map_single);
 
-dma_addr_t dma_map_page(struct device *dev, struct page *page,
+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",
@@ -358,7 +358,7 @@ dma_addr_t dma_map_page(struct device *dev, struct page *page,
 
 	return map_single(dev, page_address(page) + offset, size, dir);
 }
-EXPORT_SYMBOL(dma_map_page);
+EXPORT_SYMBOL(__dma_map_page);
 
 /*
  * see if a mapped address was really a "safe" buffer and if so, copy
@@ -367,7 +367,7 @@ EXPORT_SYMBOL(dma_map_page);
  * should be)
  */
 
-void dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
+void __dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
 		enum dma_data_direction dir)
 {
 	dev_dbg(dev, "%s(ptr=%p,size=%d,dir=%x)\n",
@@ -375,7 +375,7 @@ void dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
 
 	unmap_single(dev, dma_addr, size, dir);
 }
-EXPORT_SYMBOL(dma_unmap_single);
+EXPORT_SYMBOL(__dma_unmap_single);
 
 int dmabounce_sync_for_cpu(struct device *dev, dma_addr_t addr,
 		unsigned long off, size_t sz, enum dma_data_direction dir)
arch/arm/include/asm/dma-mapping.h +58 -9

106 lines not on this page · raw message

arch/arm/mm/dma-mapping.c +12 -12
index 510c179..654cd82 100644
@@ -273,7 +273,7 @@ __dma_alloc(struct device *dev, size_t size, dma_addr_t *handle, gfp_t gfp,
  * virtual and bus address for that space.
  */
 void *
-dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *handle, gfp_t gfp)
+__dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *handle, gfp_t gfp)
 {
 	void *memory;
 
@@ -294,7 +294,7 @@ dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *handle, gfp_t gf
 	return __dma_alloc(dev, size, handle, gfp,
 			   pgprot_noncached(pgprot_kernel));
 }
-EXPORT_SYMBOL(dma_alloc_coherent);
+EXPORT_SYMBOL(__dma_alloc_coherent);
 
 /*
  * Allocate a writecombining region, in much the same way as
@@ -358,7 +358,7 @@ EXPORT_SYMBOL(dma_mmap_writecombine);
  * free a page as defined by the above mapping.
  * Must not be called with IRQs disabled.
  */
-void dma_free_coherent(struct device *dev, size_t size, void *cpu_addr, dma_addr_t handle)
+void __dma_free_coherent(struct device *dev, size_t size, void *cpu_addr, dma_addr_t handle)
 {
 	struct arm_vm_region *c;
 	unsigned long flags, addr;
@@ -444,7 +444,7 @@ void dma_free_coherent(struct device *dev, size_t size, void *cpu_addr, dma_addr
 	       __func__, cpu_addr);
 	dump_stack();
 }
-EXPORT_SYMBOL(dma_free_coherent);
+EXPORT_SYMBOL(__dma_free_coherent);
 
 /*
  * Initialise the consistent memory allocation.
@@ -602,7 +602,7 @@ EXPORT_SYMBOL(dma_cache_maint_page);
  * Device ownership issues as mentioned for dma_map_single are the same
  * here.
  */
-int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
+int __dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
 		enum dma_data_direction dir)
 {
 	struct scatterlist *s;
@@ -621,7 +621,7 @@ int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
 		dma_unmap_page(dev, sg_dma_address(s), sg_dma_len(s), dir);
 	return 0;
 }
-EXPORT_SYMBOL(dma_map_sg);
+EXPORT_SYMBOL(__dma_map_sg);
 
 /**
  * dma_unmap_sg - unmap a set of SG buffers mapped by dma_map_sg
@@ -633,7 +633,7 @@ EXPORT_SYMBOL(dma_map_sg);
  * Unmap a set of streaming mode DMA translations.  Again, CPU access
  * rules concerning calls here are the same as for dma_unmap_single().
  */
-void dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
+void __dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
 		enum dma_data_direction dir)
 {
 	struct scatterlist *s;
@@ -642,7 +642,7 @@ void dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
 	for_each_sg(sg, s, nents, i)
 		dma_unmap_page(dev, sg_dma_address(s), sg_dma_len(s), dir);
 }
-EXPORT_SYMBOL(dma_unmap_sg);
+EXPORT_SYMBOL(__dma_unmap_sg);
 
 /**
  * dma_sync_sg_for_cpu
@@ -651,7 +651,7 @@ EXPORT_SYMBOL(dma_unmap_sg);
  * @nents: number of buffers to map (returned from dma_map_sg)
  * @dir: DMA transfer direction (same as was passed to dma_map_sg)
  */
-void dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
+void __dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
 			int nents, enum dma_data_direction dir)
 {
 	struct scatterlist *s;
@@ -662,7 +662,7 @@ void dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
 					sg_dma_len(s), dir);
 	}
 }
-EXPORT_SYMBOL(dma_sync_sg_for_cpu);
+EXPORT_SYMBOL(__dma_sync_sg_for_cpu);
 
 /**
  * dma_sync_sg_for_device
@@ -671,7 +671,7 @@ EXPORT_SYMBOL(dma_sync_sg_for_cpu);
  * @nents: number of buffers to map (returned from dma_map_sg)
  * @dir: DMA transfer direction (same as was passed to dma_map_sg)
  */
-void dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
+void __dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
 			int nents, enum dma_data_direction dir)
 {
 	struct scatterlist *s;
@@ -687,4 +687,4 @@ void dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
 					     s->length, dir);
 	}
 }
-EXPORT_SYMBOL(dma_sync_sg_for_device);
+EXPORT_SYMBOL(__dma_sync_sg_for_device);
Signature · 1 line
1.6.0.GIT
#2 lore raw

PATCH 2/3 ARM:dma-mapping:only provide one set of dma-api wrappers

From: Ming Lei <[email protected]>

---
 arch/arm/include/asm/dma-mapping.h |   53 +++++++++++++++++-------------------
 1 files changed, 25 insertions(+), 28 deletions(-)
arch/arm/include/asm/dma-mapping.h +25 -28
index 0e87498..86f2964 100644
@@ -273,22 +273,6 @@ extern dma_addr_t __dma_map_page(struct device *, struct page *,
 extern void __dma_unmap_single(struct device *, dma_addr_t, size_t,
 		enum dma_data_direction);
 
-static inline dma_addr_t dma_map_single(struct device *dev, void *cpu_addr,
-		size_t size, enum dma_data_direction dir)
-{
-	return __dma_map_single(dev, cpu_addr, size, dir);
-}
-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_page(dev, page, offset, size, dir);
-}
-static inline void dma_unmap_single(struct device *dev, dma_addr_t handle,
-		size_t size, enum dma_data_direction dir)
-{
-	__dma_unmap_single(dev, handle, size, dir);
-}
-
 /*
  * Private functions
  */
@@ -309,6 +293,28 @@ static inline int dmabounce_sync_for_device(struct device *d, dma_addr_t addr,
 	return 1;
 }
 
+static inline dma_addr_t __dma_map_single(struct device *dev, void *cpu_addr,
+		size_t size, enum dma_data_direction dir)
+{
+	if (!arch_is_coherent())
+		dma_cache_maint(cpu_addr, size, dir);
+
+	return virt_to_dma(dev, cpu_addr);
+}
+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)
+{
+	if (!arch_is_coherent())
+		dma_cache_maint_page(page, offset, size, dir);
+
+	return page_to_dma(dev, page) + offset;
+}
+static inline void __dma_unmap_single(struct device *dev, dma_addr_t handle,
+		size_t size, enum dma_data_direction dir)
+{
+	/* nothing to do */
+}
+#endif /* CONFIG_DMABOUNCE */
 
 /**
  * dma_map_single - map a single buffer for streaming DMA
@@ -328,11 +334,7 @@ static inline dma_addr_t dma_map_single(struct device *dev, void *cpu_addr,
 		size_t size, enum dma_data_direction dir)
 {
 	BUG_ON(!valid_dma_direction(dir));
-
-	if (!arch_is_coherent())
-		dma_cache_maint(cpu_addr, size, dir);
-
-	return virt_to_dma(dev, cpu_addr);
+	return __dma_map_single(dev, cpu_addr, size, dir);
 }
 
 /**
@@ -353,11 +355,7 @@ 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)
 {
 	BUG_ON(!valid_dma_direction(dir));
-
-	if (!arch_is_coherent())
-		dma_cache_maint_page(page, offset, size, dir);
-
-	return page_to_dma(dev, page) + offset;
+	return __dma_map_page(dev, page, offset, size, dir);
 }
 
 /**
@@ -377,9 +375,8 @@ static inline dma_addr_t dma_map_page(struct device *dev, struct page *page,
 static inline void dma_unmap_single(struct device *dev, dma_addr_t handle,
 		size_t size, enum dma_data_direction dir)
 {
-	/* nothing to do */
+	__dma_unmap_single(dev, handle, size, dir);
 }
-#endif /* CONFIG_DMABOUNCE */
 
 /**
  * dma_unmap_page - unmap a buffer previously mapped through dma_map_page()
Signature · 1 line
1.6.0.GIT
#3 lore raw

PATCH 3/3 ARM:dma-mapping:Support DMA-API debugging facility on ARM

From: Ming Lei <[email protected]>

---
 arch/arm/Kconfig                   |    1 +
 arch/arm/include/asm/dma-mapping.h |   38 ++++++++++++++++++++++++++++++-----
 arch/arm/mm/dma-mapping.c          |   11 ++++++++++
 3 files changed, 44 insertions(+), 6 deletions(-)
arch/arm/Kconfig +1 -0
index a91da50..867e7c1 100644
@@ -18,6 +18,7 @@ config ARM
 	select HAVE_KRETPROBES if (HAVE_KPROBES)
 	select HAVE_FUNCTION_TRACER if (!XIP_KERNEL)
 	select HAVE_GENERIC_DMA_COHERENT
+	select HAVE_DMA_API_DEBUG
 	help
 	  The ARM series is a line of low-power-consumption RISC chip designs
 	  licensed by ARM Ltd and targeted at embedded applications and
arch/arm/include/asm/dma-mapping.h +32 -6
index 86f2964..a288bab 100644
@@ -5,7 +5,7 @@
 
 #include <linux/mm_types.h>
 #include <linux/scatterlist.h>
-
+#include <linux/dma-debug.h>
 #include <asm-generic/dma-coherent.h>
 #include <asm/memory.h>
 
@@ -146,7 +146,11 @@ extern void __dma_free_coherent(struct device *, size_t, void *, dma_addr_t);
 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
 	dma_addr_t *handle, gfp_t gfp)
 {
-	return __dma_alloc_coherent(dev, size, handle, gfp);
+	void *mem;
+
+	mem = __dma_alloc_coherent(dev, size, handle, gfp);
+	debug_dma_alloc_coherent(dev, size, *handle, mem);
+	return mem;
 }
 
 /**
@@ -165,6 +169,7 @@ static inline void *dma_alloc_coherent(struct device *dev, size_t size,
 static inline void dma_free_coherent(struct device *dev, size_t size,
 	void *cpu_addr, dma_addr_t handle)
 {
+	debug_dma_free_coherent(dev, size, cpu_addr, handle);
 	__dma_free_coherent(dev, size, cpu_addr, handle);
 }
 
@@ -333,8 +338,14 @@ static inline void __dma_unmap_single(struct device *dev, dma_addr_t handle,
 static inline dma_addr_t dma_map_single(struct device *dev, void *cpu_addr,
 		size_t size, enum dma_data_direction dir)
 {
+	dma_addr_t addr;
 	BUG_ON(!valid_dma_direction(dir));
-	return __dma_map_single(dev, cpu_addr, size, dir);
+
+	addr = __dma_map_single(dev, cpu_addr, size, dir);
+	debug_dma_map_page(dev, virt_to_page(cpu_addr),
+			   (unsigned long)cpu_addr & ~PAGE_MASK, size,
+			   dir, addr, true);
+	return addr;
 }
 
 /**
@@ -354,8 +365,12 @@ static inline dma_addr_t dma_map_single(struct device *dev, void *cpu_addr,
 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));
-	return __dma_map_page(dev, page, offset, size, dir);
+
+	addr = __dma_map_page(dev, page, offset, size, dir);
+	debug_dma_map_page(dev, page, offset, size, dir, addr, false);
+	return addr;
 }
 
 /**
@@ -376,6 +391,7 @@ static inline void dma_unmap_single(struct device *dev, dma_addr_t handle,
 		size_t size, enum dma_data_direction dir)
 {
 	__dma_unmap_single(dev, handle, size, dir);
+	debug_dma_unmap_page(dev, handle, size, dir, true);
 }
 
 /**
@@ -395,7 +411,8 @@ static inline void dma_unmap_single(struct device *dev, dma_addr_t handle,
 static inline void dma_unmap_page(struct device *dev, dma_addr_t handle,
 		size_t size, enum dma_data_direction dir)
 {
-	dma_unmap_single(dev, handle, size, dir);
+	__dma_unmap_single(dev, handle, size, dir);
+	debug_dma_unmap_page(dev, handle, size, dir, false);
 }
 
 /**
@@ -422,6 +439,7 @@ static inline void dma_sync_single_range_for_cpu(struct device *dev,
 {
 	BUG_ON(!valid_dma_direction(dir));
 
+	debug_dma_sync_single_range_for_cpu(dev, handle, offset, size, dir);
 	dmabounce_sync_for_cpu(dev, handle, offset, size, dir);
 }
 
@@ -431,6 +449,8 @@ static inline void dma_sync_single_range_for_device(struct device *dev,
 {
 	BUG_ON(!valid_dma_direction(dir));
 
+	debug_dma_sync_single_range_for_device(dev, handle, offset, size, dir);
+
 	if (!dmabounce_sync_for_device(dev, handle, offset, size, dir))
 		return;
 
@@ -465,11 +485,15 @@ extern void __dma_sync_sg_for_device(struct device *, struct scatterlist *, int,
 static inline int dma_map_sg(struct device *dev, struct scatterlist *sg,
 		int nents, enum dma_data_direction dir)
 {
-	return __dma_map_sg(dev, sg, nents, dir);
+	int ents;
+	ents = __dma_map_sg(dev, sg, nents, dir);
+	debug_dma_map_sg(dev, sg, nents, ents, dir);
+	return ents;
 }
 static inline void dma_unmap_sg(struct device *dev, struct scatterlist *sg,
 		int nents, enum dma_data_direction dir)
 {
+	debug_dma_unmap_sg(dev, sg, nents, dir);
 	 __dma_unmap_sg(dev, sg, nents, dir);
 }
 static inline void dma_sync_sg_for_cpu(struct device *dev,
@@ -477,12 +501,14 @@ static inline void dma_sync_sg_for_cpu(struct device *dev,
 		enum dma_data_direction dir)
 {
 	 __dma_sync_sg_for_cpu(dev, sg, nents, dir);
+	debug_dma_sync_sg_for_cpu(dev, sg, nents, dir);
 }
 static inline void dma_sync_sg_for_device(struct device *dev,
 		struct scatterlist *sg, int nents,
 		enum dma_data_direction dir)
 {
 	 __dma_sync_sg_for_device(dev, sg, nents, dir);
+	debug_dma_sync_sg_for_device(dev, sg, nents, dir);
 }
 
 #endif /* __KERNEL__ */
arch/arm/mm/dma-mapping.c +11 -0
index 654cd82..64e5d82 100644
@@ -16,6 +16,7 @@
 #include <linux/list.h>
 #include <linux/init.h>
 #include <linux/device.h>
+#include <linux/dma-debug.h>
 #include <linux/dma-mapping.h>
 
 #include <asm/memory.h>
@@ -688,3 +689,13 @@ void __dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
 	}
 }
 EXPORT_SYMBOL(__dma_sync_sg_for_device);
+
+#define PREALLOC_DMA_DEBUG_ENTRIES             8192
+
+static int __init dma_debug_init_arm(void)
+{
+       dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
+       return 0;
+}
+fs_initcall(dma_debug_init_arm);
+
Signature · 1 line
1.6.0.GIT
author
#4 lore raw
In reply to [email protected]

2009/7/12 <[email protected]>:

Quoted 4 lines

Hi,
This patch set introduces dma-api debugging facility on ARM, and is against -rc2-next tree.

Hi, Russell and All,

Care to give any suggestions or objections on the patches?

thanks.

Signature · 1 line
Lei Ming
#5 lore raw
Quoted 9 lines · Ming Lei

2009/7/12 <[email protected]>:

Quoted 4 lines

Hi,
This patch set introduces dma-api debugging facility on ARM, and is against -rc2-next tree.

Hi, Russell and All,

Care to give any suggestions or objections on the patches?

I don't think it's suitable, because our implementation calls back into the DMA API for dma_map_sg() - this means that the debugging code will end up seeing each scatterlist entry twice. I'm not sure what effect that will have, but it's probably not good.

author
#6 lore raw
Quoted 4 lines · On Fri, 17 Jul 2009 09:11:49 +0100 Russell King - ARM Linux…

I don't think it's suitable, because our implementation calls back into the DMA API for dma_map_sg() - this means that the debugging code will end up seeing each scatterlist entry twice. I'm not sure what effect that will have, but it's probably not good.

Thank you for the review, and does the patch fix the problem?
If yes, I'll sumbmit the v2 version if necessary or you can use it directly.

Quoted 1 line

From cd2ef8fc869a2e3442fc37d695ca95d286ac6a4d Mon Sep 17 00:00:00 2001

From: Ming Lei <[email protected]>
Date: Fri, 17 Jul 2009 22:54:01 +0800
Subject: [PATCH 4/4] ARM:dma-mapping:fix dma_map_sg and dma_unmap_sg

This patch removes unnecessary calling of debug_dma_map_page and debug_dma_unmap_page in dma_map_sg and dma_unmap_sg.

---
 arch/arm/mm/dma-mapping.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
arch/arm/mm/dma-mapping.c +3 -3
index 64e5d82..584018c 100644
@@ -610,7 +610,7 @@ int __dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
 	int i, j;
 
 	for_each_sg(sg, s, nents, i) {
-		s->dma_address = dma_map_page(dev, sg_page(s), s->offset,
+		s->dma_address = __dma_map_page(dev, sg_page(s), s->offset,
 						s->length, dir);
 		if (dma_mapping_error(dev, s->dma_address))
 			goto bad_mapping;
@@ -619,7 +619,7 @@ int __dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
 
  bad_mapping:
 	for_each_sg(sg, s, i, j)
-		dma_unmap_page(dev, sg_dma_address(s), sg_dma_len(s), dir);
+		__dma_unmap_single(dev, sg_dma_address(s), sg_dma_len(s), dir);
 	return 0;
 }
 EXPORT_SYMBOL(__dma_map_sg);
@@ -641,7 +641,7 @@ void __dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
 	int i;
 
 	for_each_sg(sg, s, nents, i)
-		dma_unmap_page(dev, sg_dma_address(s), sg_dma_len(s), dir);
+		__dma_unmap_single(dev, sg_dma_address(s), sg_dma_len(s), dir);
 }
 EXPORT_SYMBOL(__dma_unmap_sg);
 
Signature · 7 lines
1.6.0.GIT




-- 
Lei Ming