Skip to contentSkip to conversation

common: DMA-mapping: add DMA_ATTR_ALLOC_EXACT_SIZE attribute

PATCH New Vandana Salve 1 participant 1 message Nov 28, 2013

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 common: DMA-mapping: add DMA_ATTR_ALLOC_EXACT_SIZE attribute

This patch adds DMA_ATTR_ALLOC_EXACT_SIZE attribute to the DMA-mapping subsystem

By default dma coherent alloc/free functions allocates/release memory in order of 2^pages. By specifying this attribute, allocation/release can be done for exact size of memory there by reducing internal memory fragmentation when allocation is in large chunks of MBs

Added attr version of dma_alloc/release_from_coherent()

---
 arch/arm/mm/dma-mapping.c          |  6 ++---
 drivers/base/dma-coherent.c        | 51 ++++++++++++++++++++++++++++----------
 include/asm-generic/dma-coherent.h | 15 ++++++++---
 include/linux/dma-attrs.h          |  1 +
 4 files changed, 54 insertions(+), 19 deletions(-)
arch/arm/mm/dma-mapping.c +3 -3
index 79f8b39..a39c1c1 100644
@@ -710,7 +710,7 @@ void *arm_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
 	pgprot_t prot = __get_dma_pgprot(attrs, PAGE_KERNEL);
 	void *memory;
 
-	if (dma_alloc_from_coherent(dev, size, handle, &memory))
+	if (dma_alloc_from_coherent_attr(dev, size, handle, &memory, attrs))
 		return memory;
 
 	return __dma_alloc(dev, size, handle, gfp, prot, false,
@@ -723,7 +723,7 @@ static void *arm_coherent_dma_alloc(struct device *dev, size_t size,
 	pgprot_t prot = __get_dma_pgprot(attrs, PAGE_KERNEL);
 	void *memory;
 
-	if (dma_alloc_from_coherent(dev, size, handle, &memory))
+	if (dma_alloc_from_coherent_attr(dev, size, handle, &memory, attrs))
 		return memory;
 
 	return __dma_alloc(dev, size, handle, gfp, prot, true,
@@ -769,7 +769,7 @@ static void __arm_dma_free(struct device *dev, size_t size, void *cpu_addr,
 {
 	struct page *page = pfn_to_page(dma_to_pfn(dev, handle));
 
-	if (dma_release_from_coherent(dev, get_order(size), cpu_addr))
+	if (dma_release_from_coherent_attr(dev, size, cpu_addr, attrs))
 		return;
 
 	size = PAGE_ALIGN(size);
drivers/base/dma-coherent.c +38 -13

110 lines not on this page · raw message

include/asm-generic/dma-coherent.h +12 -3
index 2be8a2d..55e49bd 100644
@@ -6,9 +6,16 @@
  * These three functions are only for dma allocator.
  * Don't use them in device drivers.
  */
-int dma_alloc_from_coherent(struct device *dev, ssize_t size,
-				       dma_addr_t *dma_handle, void **ret);
-int dma_release_from_coherent(struct device *dev, int order, void *vaddr);
+int dma_alloc_from_coherent_attr(struct device *dev, ssize_t size,
+				       dma_addr_t *dma_handle, void **ret,
+				       struct dma_attrs *attrs);
+int dma_release_from_coherent_attr(struct device *dev, size_t size, void *vaddr,
+				       struct dma_attrs *attrs);
+#define dma_alloc_from_coherent(d, s, h, r) \
+	dma_alloc_from_coherent_attr(d, s, h, r, NULL)
+
+#define dma_release_from_coherent(d, s, v) \
+	dma_release_from_coherent_attr(d, s, v, NULL)
 
 int dma_mmap_from_coherent(struct device *dev, struct vm_area_struct *vma,
 			    void *cpu_addr, size_t size, int *ret);
@@ -27,6 +34,8 @@ extern void *
 dma_mark_declared_memory_occupied(struct device *dev,
 				  dma_addr_t device_addr, size_t size);
 #else
+#define dma_alloc_from_coherent_attr(dev, size, handle, ret, attr) (0)
+#define dma_release_from_coherent_attr(dev, size, vaddr, attr) (0)
 #define dma_alloc_from_coherent(dev, size, handle, ret) (0)
 #define dma_release_from_coherent(dev, order, vaddr) (0)
 #define dma_mmap_from_coherent(dev, vma, vaddr, order, ret) (0)
include/linux/dma-attrs.h +1 -0
index c8e1831..d23f28f 100644
@@ -18,6 +18,7 @@ enum dma_attr {
 	DMA_ATTR_NO_KERNEL_MAPPING,
 	DMA_ATTR_SKIP_CPU_SYNC,
 	DMA_ATTR_FORCE_CONTIGUOUS,
+	DMA_ATTR_ALLOC_EXACT_SIZE,
 	DMA_ATTR_MAX,
 };
 
Signature · 1 line
1.8.1.5