From: Marek Szyprowski <m.szyprowski@samsung.com>
To: linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-media@vger.kernel.org, linux-mm@kvack.org,
linaro-mm-sig@lists.linaro.org
Cc: Michal Nazarewicz <mina86@mina86.com>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Kyungmin Park <kyungmin.park@samsung.com>,
Andrew Morton <akpm@linux-foundation.org>,
KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
Ankita Garg <ankita@in.ibm.com>,
Daniel Walker <dwalker@codeaurora.org>,
Mel Gorman <mel@csn.ul.ie>, Arnd Bergmann <arnd@arndb.de>,
Jesse Barker <jesse.barker@linaro.org>,
Jonathan Corbet <corbet@lwn.net>,
Chunsang Jeong <chunsang.jeong@linaro.org>
Subject: [PATCH 7/8] ARM: integrate CMA with dma-mapping subsystem
Date: Tue, 05 Jul 2011 09:41:49 +0200 [thread overview]
Message-ID: <1309851710-3828-8-git-send-email-m.szyprowski@samsung.com> (raw)
In-Reply-To: <1309851710-3828-1-git-send-email-m.szyprowski@samsung.com>
This patch adds support for CMA to dma-mapping subsystem for ARM
architecture. By default a global CMA area is used, but specific devices
are allowed to have their private memory areas if required (they can be
created with dma_declare_contiguous() function during board
initialization).
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
---
arch/arm/Kconfig | 1 +
arch/arm/include/asm/device.h | 3 ++
arch/arm/include/asm/dma-mapping.h | 20 ++++++++++++++
arch/arm/mm/dma-mapping.c | 51 +++++++++++++++++++++++++++--------
arch/arm/mm/init.c | 3 ++
5 files changed, 66 insertions(+), 12 deletions(-)
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 9adc278..3cca8cc 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -3,6 +3,7 @@ config ARM
default y
select HAVE_AOUT
select HAVE_DMA_API_DEBUG
+ select HAVE_DMA_CONTIGUOUS
select HAVE_IDE
select HAVE_MEMBLOCK
select RTC_LIB
diff --git a/arch/arm/include/asm/device.h b/arch/arm/include/asm/device.h
index 9f390ce..942913e 100644
--- a/arch/arm/include/asm/device.h
+++ b/arch/arm/include/asm/device.h
@@ -10,6 +10,9 @@ struct dev_archdata {
#ifdef CONFIG_DMABOUNCE
struct dmabounce_device_info *dmabounce;
#endif
+#ifdef CONFIG_CMA
+ struct cma *cma_area;
+#endif
};
struct pdev_archdata {
diff --git a/arch/arm/include/asm/dma-mapping.h b/arch/arm/include/asm/dma-mapping.h
index 4fff837..a3e1e48c 100644
--- a/arch/arm/include/asm/dma-mapping.h
+++ b/arch/arm/include/asm/dma-mapping.h
@@ -6,6 +6,7 @@
#include <linux/mm_types.h>
#include <linux/scatterlist.h>
#include <linux/dma-debug.h>
+#include <linux/dma-contiguous.h>
#include <asm-generic/dma-coherent.h>
#include <asm/memory.h>
@@ -14,6 +15,25 @@
#error Please update to __arch_pfn_to_dma
#endif
+#ifdef CONFIG_CMA
+static inline struct cma *get_dev_cma_area(struct device *dev)
+{
+ if (dev->archdata.cma_area)
+ return dev->archdata.cma_area;
+ return dma_contiguous_default_area;
+}
+
+static inline void set_dev_cma_area(struct device *dev, struct cma *cma)
+{
+ dev->archdata.cma_area = cma;
+}
+#else
+static inline struct cma *get_dev_cma_area(struct device *dev)
+{
+ return NULL;
+}
+#endif
+
/*
* dma_to_pfn/pfn_to_dma/dma_to_virt/virt_to_dma are architecture private
* functions used internally by the DMA-mapping API to provide DMA
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 82a093c..1d4e916 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -17,6 +17,7 @@
#include <linux/init.h>
#include <linux/device.h>
#include <linux/dma-mapping.h>
+#include <linux/dma-contiguous.h>
#include <linux/highmem.h>
#include <asm/memory.h>
@@ -52,16 +53,35 @@ static u64 get_coherent_dma_mask(struct device *dev)
return mask;
}
+
+static struct page *__alloc_system_pages(size_t count, unsigned int order, gfp_t gfp)
+{
+ struct page *page, *p, *e;
+
+ page = alloc_pages(gfp, order);
+ if (!page)
+ return NULL;
+
+ /*
+ * Now split the huge page and free the excess pages
+ */
+ split_page(page, order);
+ for (p = page + count, e = page + (1 << order); p < e; p++)
+ __free_page(p);
+ return page;
+}
+
/*
* Allocate a DMA buffer for 'dev' of size 'size' using the
* specified gfp mask. Note that 'size' must be page aligned.
*/
static struct page *__dma_alloc_buffer(struct device *dev, size_t size, gfp_t gfp)
{
- unsigned long order = get_order(size);
- struct page *page, *p, *e;
+ struct page *page;
+ size_t count = size >> PAGE_SHIFT;
void *ptr;
u64 mask = get_coherent_dma_mask(dev);
+ unsigned long order = get_order(count << PAGE_SHIFT);
#ifdef CONFIG_DMA_API_DEBUG
u64 limit = (mask + 1) & ~mask;
@@ -78,16 +98,19 @@ static struct page *__dma_alloc_buffer(struct device *dev, size_t size, gfp_t gf
if (mask < 0xffffffffULL)
gfp |= GFP_DMA;
- page = alloc_pages(gfp, order);
- if (!page)
- return NULL;
+ /*
+ * First, try to allocate memory from contiguous area
+ */
+ page = dma_alloc_from_contiguous(dev, count, order);
/*
- * Now split the huge page and free the excess pages
+ * Fallback if contiguous alloc fails or is not available
*/
- split_page(page, order);
- for (p = page + (size >> PAGE_SHIFT), e = page + (1 << order); p < e; p++)
- __free_page(p);
+ if (!page)
+ page = __alloc_system_pages(count, order, gfp);
+
+ if (!page)
+ return NULL;
/*
* Ensure that the allocated pages are zeroed, and that any data
@@ -104,9 +127,13 @@ static struct page *__dma_alloc_buffer(struct device *dev, size_t size, gfp_t gf
/*
* Free a DMA buffer. 'size' must be page aligned.
*/
-static void __dma_free_buffer(struct page *page, size_t size)
+static void __dma_free_buffer(struct device *dev, struct page *page, size_t size)
{
- struct page *e = page + (size >> PAGE_SHIFT);
+ size_t count = size >> PAGE_SHIFT;
+ struct page *e = page + count;
+
+ if (dma_release_from_contiguous(dev, page, count))
+ return;
while (page < e) {
__free_page(page);
@@ -416,7 +443,7 @@ void dma_free_coherent(struct device *dev, size_t size, void *cpu_addr, dma_addr
if (!arch_is_coherent())
__dma_free_remap(cpu_addr, size);
- __dma_free_buffer(pfn_to_page(dma_to_pfn(dev, handle)), size);
+ __dma_free_buffer(dev, pfn_to_page(dma_to_pfn(dev, handle)), size);
}
EXPORT_SYMBOL(dma_free_coherent);
diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index c19571c..b2dfdeb 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -20,6 +20,7 @@
#include <linux/gfp.h>
#include <linux/memblock.h>
#include <linux/sort.h>
+#include <linux/dma-contiguous.h>
#include <asm/mach-types.h>
#include <asm/prom.h>
@@ -358,6 +359,8 @@ void __init arm_memblock_init(struct meminfo *mi, struct machine_desc *mdesc)
if (mdesc->reserve)
mdesc->reserve();
+ dma_contiguous_reserve();
+
memblock_analyze();
memblock_dump_all();
}
--
1.7.1.569.g6f426
next prev parent reply other threads:[~2011-07-05 7:42 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-05 7:41 [PATCHv11 0/8] Contiguous Memory Allocator Marek Szyprowski
2011-07-05 7:41 ` [PATCH 1/8] mm: move some functions from memory_hotplug.c to page_isolation.c Marek Szyprowski
2011-07-05 11:27 ` Arnd Bergmann
2011-07-05 7:41 ` [PATCH 2/8] mm: alloc_contig_freed_pages() added Marek Szyprowski
2011-07-05 11:30 ` Arnd Bergmann
2011-07-05 7:41 ` [PATCH 3/8] mm: alloc_contig_range() added Marek Szyprowski
2011-07-05 11:31 ` Arnd Bergmann
2011-07-05 7:41 ` [PATCH 4/8] mm: MIGRATE_CMA migration type added Marek Szyprowski
2011-07-05 11:44 ` Arnd Bergmann
2011-07-05 12:27 ` Russell King - ARM Linux
2011-07-05 7:41 ` [PATCH 5/8] mm: MIGRATE_CMA isolation functions added Marek Szyprowski
2011-07-05 11:45 ` Arnd Bergmann
2011-07-05 7:41 ` [PATCH 6/8] drivers: add Contiguous Memory Allocator Marek Szyprowski
2011-07-05 10:24 ` Marek Szyprowski
2011-07-05 11:02 ` [PATCH 6/8 RESEND] " Marek Szyprowski
2011-07-05 11:50 ` Arnd Bergmann
2011-07-05 11:33 ` [PATCH 6/8] " Russell King - ARM Linux
2011-07-05 12:27 ` Arnd Bergmann
2011-07-05 12:30 ` Russell King - ARM Linux
2011-07-05 13:58 ` Arnd Bergmann
2011-07-08 17:25 ` Russell King - ARM Linux
2011-07-12 13:39 ` Arnd Bergmann
2011-08-03 17:43 ` James Bottomley
2011-09-26 12:06 ` Marek Szyprowski
2011-09-26 13:00 ` Russell King - ARM Linux
2011-07-06 13:58 ` Marek Szyprowski
2011-07-06 14:09 ` Arnd Bergmann
2011-07-06 14:23 ` Russell King - ARM Linux
2011-07-06 14:37 ` [Linaro-mm-sig] " Nicolas Pitre
2011-07-06 14:59 ` Arnd Bergmann
2011-07-09 14:57 ` Janusz Krzysztofik
2011-07-11 13:47 ` Marek Szyprowski
2011-07-11 19:01 ` Janusz Krzysztofik
2011-07-12 5:34 ` Marek Szyprowski
2011-07-06 14:51 ` Arnd Bergmann
2011-07-06 15:48 ` Russell King - ARM Linux
2011-07-06 16:05 ` Christoph Lameter
2011-07-06 16:09 ` Michal Nazarewicz
2011-07-06 16:19 ` Christoph Lameter
2011-07-06 17:15 ` Russell King - ARM Linux
2011-07-06 19:03 ` Christoph Lameter
2011-07-06 17:02 ` Russell King - ARM Linux
2011-07-06 16:31 ` Arnd Bergmann
2011-07-06 19:10 ` Nicolas Pitre
2011-07-06 20:23 ` [Linaro-mm-sig] " Arnd Bergmann
2011-07-07 5:29 ` Nicolas Pitre
2011-07-06 14:56 ` Marek Szyprowski
2011-07-06 15:37 ` Russell King - ARM Linux
2011-07-06 15:47 ` Marek Szyprowski
2011-07-14 12:29 ` Marek Szyprowski
2011-07-05 7:41 ` Marek Szyprowski [this message]
2011-07-05 11:50 ` [PATCH 7/8] ARM: integrate CMA with dma-mapping subsystem Arnd Bergmann
2011-07-05 7:41 ` [PATCH 8/8] ARM: S5PV210: example of CMA private area for FIMC device on Goni board Marek Szyprowski
2011-07-05 11:51 ` Arnd Bergmann
2011-07-05 12:07 ` [PATCHv11 0/8] Contiguous Memory Allocator Arnd Bergmann
2011-07-05 12:28 ` Russell King - ARM Linux
2011-07-06 22:11 ` Andrew Morton
2011-07-07 7:36 ` Arnd Bergmann
2011-07-11 13:24 ` Marek Szyprowski
2011-07-20 8:57 [PATCHv12 " Marek Szyprowski
2011-07-20 8:57 ` [PATCH 7/8] ARM: integrate CMA with dma-mapping subsystem Marek Szyprowski
2011-08-19 14:27 [PATCHv15 0/8] Contiguous Memory Allocator Marek Szyprowski
2011-08-19 14:27 ` [PATCH 7/8] ARM: integrate CMA with DMA-mapping subsystem Marek Szyprowski
[not found] ` <CAMjpGUch=ogFQwBLqOukKVnyh60600jw5tMq-KYeNGSZ2PLQpA@mail.gmail.com>
2011-09-21 13:47 ` Marek Szyprowski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1309851710-3828-8-git-send-email-m.szyprowski@samsung.com \
--to=m.szyprowski@samsung.com \
--cc=akpm@linux-foundation.org \
--cc=ankita@in.ibm.com \
--cc=arnd@arndb.de \
--cc=chunsang.jeong@linaro.org \
--cc=corbet@lwn.net \
--cc=dwalker@codeaurora.org \
--cc=jesse.barker@linaro.org \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=kyungmin.park@samsung.com \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mel@csn.ul.ie \
--cc=mina86@mina86.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®