linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv4 0/2] CMA for arm64
@ 2013-12-12 19:28 Laura Abbott
  2013-12-12 19:28 ` [PATCHv4 1/2] arm64: Warn on NULL device structure for dma APIs Laura Abbott
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Laura Abbott @ 2013-12-12 19:28 UTC (permalink / raw)
  To: linux-arm-kernel

This adds support for CMA in arm64

v4: Minor typos pointed out by Will. Changed the support for NULL devices
to be a WARN on NULL device.

v3: Fix a missed line to actually set the dma_handle correctly

v2: Move the dma contiguous functions from swiotlb to arm64 directly

 arch/arm64/Kconfig                      |    1 +
 arch/arm64/include/asm/dma-contiguous.h |   29 +++++++++++++++++++++++++
 arch/arm64/mm/dma-mapping.c             |   35 +++++++++++++++++++++++++++++-
 arch/arm64/mm/init.c                    |    3 ++
 4 files changed, 66 insertions(+), 2 deletions(-)

Thanks,
Laura

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCHv4 1/2] arm64: Warn on NULL device structure for dma APIs
  2013-12-12 19:28 [PATCHv4 0/2] CMA for arm64 Laura Abbott
@ 2013-12-12 19:28 ` Laura Abbott
  2013-12-12 19:28 ` [PATCHv4 2/2] arm64: Enable CMA Laura Abbott
  2013-12-18 18:29 ` [PATCHv4 0/2] CMA for arm64 Laura Abbott
  2 siblings, 0 replies; 5+ messages in thread
From: Laura Abbott @ 2013-12-12 19:28 UTC (permalink / raw)
  To: linux-arm-kernel

Although parts of the DMA apis may properly check for NULL devices,
there may be some places that don't. Rather than fix up all the
possible locations, just require a non-NULL device structure to be
used for allocating/freeing.

Cc: Will Deacon <will.deacon@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
---
 arch/arm64/mm/dma-mapping.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c
index 4bd7579..a496a3c 100644
--- a/arch/arm64/mm/dma-mapping.c
+++ b/arch/arm64/mm/dma-mapping.c
@@ -33,6 +33,11 @@ static void *arm64_swiotlb_alloc_coherent(struct device *dev, size_t size,
 					  dma_addr_t *dma_handle, gfp_t flags,
 					  struct dma_attrs *attrs)
 {
+	if (dev == NULL) {
+		WARN(1, "Use an actual device structure for DMA allocation\n");
+		return NULL;
+	}
+
 	if (IS_ENABLED(CONFIG_ZONE_DMA32) &&
 	    dev->coherent_dma_mask <= DMA_BIT_MASK(32))
 		flags |= GFP_DMA32;
@@ -43,6 +48,11 @@ static void arm64_swiotlb_free_coherent(struct device *dev, size_t size,
 					void *vaddr, dma_addr_t dma_handle,
 					struct dma_attrs *attrs)
 {
+	if (dev == NULL) {
+		WARN(1, "Use an actual device structure for DMA allocation\n");
+		return;
+	}
+
 	swiotlb_free_coherent(dev, size, vaddr, dma_handle);
 }
 
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCHv4 2/2] arm64: Enable CMA
  2013-12-12 19:28 [PATCHv4 0/2] CMA for arm64 Laura Abbott
  2013-12-12 19:28 ` [PATCHv4 1/2] arm64: Warn on NULL device structure for dma APIs Laura Abbott
@ 2013-12-12 19:28 ` Laura Abbott
  2013-12-18 18:29 ` [PATCHv4 0/2] CMA for arm64 Laura Abbott
  2 siblings, 0 replies; 5+ messages in thread
From: Laura Abbott @ 2013-12-12 19:28 UTC (permalink / raw)
  To: linux-arm-kernel

arm64 bit targets need the features CMA provides. Add the appropriate
hooks, header files, and Kconfig to allow this to happen.

Cc: Will Deacon <will.deacon@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
---
 arch/arm64/Kconfig                      |    1 +
 arch/arm64/include/asm/dma-contiguous.h |   29 +++++++++++++++++++++++++++++
 arch/arm64/mm/dma-mapping.c             |   25 +++++++++++++++++++++++--
 arch/arm64/mm/init.c                    |    3 +++
 4 files changed, 56 insertions(+), 2 deletions(-)
 create mode 100644 arch/arm64/include/asm/dma-contiguous.h

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 9737e97..26e4bef 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -22,6 +22,7 @@ config ARM64
 	select HAVE_DEBUG_KMEMLEAK
 	select HAVE_DMA_API_DEBUG
 	select HAVE_DMA_ATTRS
+	select HAVE_DMA_CONTIGUOUS
 	select HAVE_GENERIC_DMA_COHERENT
 	select HAVE_GENERIC_HARDIRQS
 	select HAVE_HW_BREAKPOINT if PERF_EVENTS
diff --git a/arch/arm64/include/asm/dma-contiguous.h b/arch/arm64/include/asm/dma-contiguous.h
new file mode 100644
index 0000000..d6aacb6
--- /dev/null
+++ b/arch/arm64/include/asm/dma-contiguous.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef _ASM_DMA_CONTIGUOUS_H
+#define _ASM_DMA_CONTIGUOUS_H
+
+#ifdef __KERNEL__
+#ifdef CONFIG_DMA_CMA
+
+#include <linux/types.h>
+#include <asm-generic/dma-contiguous.h>
+
+static inline void
+dma_contiguous_early_fixup(phys_addr_t base, unsigned long size) { }
+
+#endif
+#endif
+
+#endif
diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c
index a496a3c..b32da89 100644
--- a/arch/arm64/mm/dma-mapping.c
+++ b/arch/arm64/mm/dma-mapping.c
@@ -21,6 +21,7 @@
 #include <linux/export.h>
 #include <linux/slab.h>
 #include <linux/dma-mapping.h>
+#include <linux/dma-contiguous.h>
 #include <linux/vmalloc.h>
 #include <linux/swiotlb.h>
 
@@ -41,7 +42,19 @@ static void *arm64_swiotlb_alloc_coherent(struct device *dev, size_t size,
 	if (IS_ENABLED(CONFIG_ZONE_DMA32) &&
 	    dev->coherent_dma_mask <= DMA_BIT_MASK(32))
 		flags |= GFP_DMA32;
-	return swiotlb_alloc_coherent(dev, size, dma_handle, flags);
+	if (IS_ENABLED(CONFIG_DMA_CMA)) {
+		struct page *page;
+
+		page = dma_alloc_from_contiguous(dev, size >> PAGE_SHIFT,
+							get_order(size));
+		if (!page)
+			return NULL;
+
+		*dma_handle = phys_to_dma(dev, page_to_phys(page));
+		return page_address(page);
+	} else {
+		return swiotlb_alloc_coherent(dev, size, dma_handle, flags);
+	}
 }
 
 static void arm64_swiotlb_free_coherent(struct device *dev, size_t size,
@@ -53,7 +66,15 @@ static void arm64_swiotlb_free_coherent(struct device *dev, size_t size,
 		return;
 	}
 
-	swiotlb_free_coherent(dev, size, vaddr, dma_handle);
+	if (IS_ENABLED(CONFIG_DMA_CMA)) {
+		phys_addr_t paddr = dma_to_phys(dev, dma_handle);
+
+		dma_release_from_contiguous(dev,
+					phys_to_page(paddr),
+					size >> PAGE_SHIFT);
+	} else {
+		swiotlb_free_coherent(dev, size, vaddr, dma_handle);
+	}
 }
 
 static struct dma_map_ops arm64_swiotlb_dma_ops = {
diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index 67e8d7c..74b7da1 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -30,6 +30,7 @@
 #include <linux/memblock.h>
 #include <linux/sort.h>
 #include <linux/of_fdt.h>
+#include <linux/dma-contiguous.h>
 
 #include <asm/prom.h>
 #include <asm/sections.h>
@@ -173,6 +174,8 @@ void __init arm64_memblock_init(void)
 		memblock_reserve(base, size);
 	}
 
+	dma_contiguous_reserve(0);
+
 	memblock_allow_resize();
 	memblock_dump_all();
 }
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCHv4 0/2] CMA for arm64
  2013-12-12 19:28 [PATCHv4 0/2] CMA for arm64 Laura Abbott
  2013-12-12 19:28 ` [PATCHv4 1/2] arm64: Warn on NULL device structure for dma APIs Laura Abbott
  2013-12-12 19:28 ` [PATCHv4 2/2] arm64: Enable CMA Laura Abbott
@ 2013-12-18 18:29 ` Laura Abbott
  2013-12-19 16:09   ` Catalin Marinas
  2 siblings, 1 reply; 5+ messages in thread
From: Laura Abbott @ 2013-12-18 18:29 UTC (permalink / raw)
  To: linux-arm-kernel

On 12/12/2013 11:28 AM, Laura Abbott wrote:
> This adds support for CMA in arm64
>
> v4: Minor typos pointed out by Will. Changed the support for NULL devices
> to be a WARN on NULL device.
>
> v3: Fix a missed line to actually set the dma_handle correctly
>
> v2: Move the dma contiguous functions from swiotlb to arm64 directly
>
>   arch/arm64/Kconfig                      |    1 +
>   arch/arm64/include/asm/dma-contiguous.h |   29 +++++++++++++++++++++++++
>   arch/arm64/mm/dma-mapping.c             |   35 +++++++++++++++++++++++++++++-
>   arch/arm64/mm/init.c                    |    3 ++
>   4 files changed, 66 insertions(+), 2 deletions(-)
>


Any further comments on this or is this going to be queued up somewhere?

Thanks,
Laura

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCHv4 0/2] CMA for arm64
  2013-12-18 18:29 ` [PATCHv4 0/2] CMA for arm64 Laura Abbott
@ 2013-12-19 16:09   ` Catalin Marinas
  0 siblings, 0 replies; 5+ messages in thread
From: Catalin Marinas @ 2013-12-19 16:09 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Dec 18, 2013 at 06:29:01PM +0000, Laura Abbott wrote:
> On 12/12/2013 11:28 AM, Laura Abbott wrote:
> > This adds support for CMA in arm64
> >
> > v4: Minor typos pointed out by Will. Changed the support for NULL devices
> > to be a WARN on NULL device.
> >
> > v3: Fix a missed line to actually set the dma_handle correctly
> >
> > v2: Move the dma contiguous functions from swiotlb to arm64 directly
> >
> >   arch/arm64/Kconfig                      |    1 +
> >   arch/arm64/include/asm/dma-contiguous.h |   29 +++++++++++++++++++++++++
> >   arch/arm64/mm/dma-mapping.c             |   35 +++++++++++++++++++++++++++++-
> >   arch/arm64/mm/init.c                    |    3 ++
> >   4 files changed, 66 insertions(+), 2 deletions(-)
> 
> Any further comments on this or is this going to be queued up somewhere?

I'll queue them for the next merging window. I hope to get them into
linux-next by the end of the week.

Thanks.

-- 
Catalin

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-12-19 16:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-12 19:28 [PATCHv4 0/2] CMA for arm64 Laura Abbott
2013-12-12 19:28 ` [PATCHv4 1/2] arm64: Warn on NULL device structure for dma APIs Laura Abbott
2013-12-12 19:28 ` [PATCHv4 2/2] arm64: Enable CMA Laura Abbott
2013-12-18 18:29 ` [PATCHv4 0/2] CMA for arm64 Laura Abbott
2013-12-19 16:09   ` Catalin Marinas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).