public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: jamie@jamieiles.com (Jamie Iles)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 2/2] ARM: use cached memory in dma_alloc_coherent() if possible
Date: Tue, 21 Dec 2010 10:20:02 +0000	[thread overview]
Message-ID: <1292926802-12326-2-git-send-email-jamie@jamieiles.com> (raw)
In-Reply-To: <1292926802-12326-1-git-send-email-jamie@jamieiles.com>

For fully coherent architectures or systems using the ARM ACP to provide
coherency to individual device, use cached memory as the coherent
backing rather than noncached or simply bufferable memory.

Cc: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Jamie Iles <jamie@jamieiles.com>
---
 arch/arm/mm/dma-mapping.c |   30 ++++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index b90f323..2d3c8e4 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -579,6 +579,34 @@ int coherent_map_sg(struct device *dev, struct scatterlist *sg, int nents,
 }
 
 /*
+ * For fully coherent systems/devices we can use normal, cached memory so just
+ * get some free pages.
+ */
+static void *coherent_alloc(struct device *dev, size_t size,
+			    dma_addr_t *dma_handle, gfp_t gfp)
+{
+	void *ret;
+	u64 mask = get_coherent_dma_mask(dev);
+
+	if (!dev || mask >= 0xffffffffUL)
+		gfp &= ~GFP_DMA;
+
+	ret = (void *)__get_free_pages(gfp, get_order(size));
+	if (ret) {
+		memset(ret, 0, size);
+		*dma_handle = virt_to_phys(ret);
+	}
+
+	return ret;
+}
+
+static void coherent_free(struct device *dev, size_t size, void *virt,
+			  dma_addr_t dma_handle)
+{
+	free_pages((unsigned long)dma_handle, get_order(size));
+}
+
+/*
  * Coherent DMA ops. These can either be used for the whole system
  * automatically if arch_is_coherent() is true or on a per device basis if the
  * device is connected to the ACP port to provide coherency for that device.
@@ -586,6 +614,8 @@ int coherent_map_sg(struct device *dev, struct scatterlist *sg, int nents,
  * dev->archdata.dma_ops
  */
 struct dma_map_ops coherent_dma_ops = {
+	.alloc_coherent		= coherent_alloc,
+	.free_coherent		= coherent_free,
 	.map_page		= coherent_map_page,
 	.map_sg			= coherent_map_sg,
 };
-- 
1.7.2.3

  reply	other threads:[~2010-12-21 10:20 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-21 10:20 [PATCH 1/2] ARM: convert dma-mapping to asm-generic API Jamie Iles
2010-12-21 10:20 ` Jamie Iles [this message]
2010-12-21 10:30   ` [PATCH 2/2] ARM: use cached memory in dma_alloc_coherent() if possible Russell King - ARM Linux
2010-12-21 10:34     ` Jamie Iles
2010-12-21 11:11     ` Catalin Marinas
2010-12-21 11:22       ` Jamie Iles
2010-12-21 10:36 ` [PATCH 1/2] ARM: convert dma-mapping to asm-generic API Russell King - ARM Linux
2010-12-21 11:01   ` Jamie Iles
2010-12-21 16:04     ` Jamie Iles
2010-12-22  2:57     ` FUJITA Tomonori
2010-12-21 10:54 ` Arnd Bergmann
2010-12-21 10:59   ` Russell King - ARM Linux
2010-12-21 11:53     ` Arnd Bergmann

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=1292926802-12326-2-git-send-email-jamie@jamieiles.com \
    --to=jamie@jamieiles.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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