Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: g.liakhovetski@gmx.de (Guennadi Liakhovetski)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 5/5] SH: use dma_preallocate_coherent_memory() for platform device memory
Date: Thu, 19 Aug 2010 16:40:30 +0200 (CEST)	[thread overview]
Message-ID: <Pine.LNX.4.64.1008191637490.26145@axis700.grange> (raw)
In-Reply-To: <Pine.LNX.4.64.1008191623580.26145@axis700.grange>

platform_resource_setup_memory() is used on SuperH to allocate large chunks
of memory at system initialisation time for platform devices. Many of those
devices are then handled by the UIO subsystem, and only one of them - the CEU
has an in-kernel driver. This patch switches platform_resource_setup_memory()
to use dma_preallocate_coherent_memory() and removes now unneeded call to
dma_declare_coherent_memory() from the CEU driver.

Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
---
 arch/sh/mm/consistent.c                    |   19 +++++++++----------
 drivers/media/video/sh_mobile_ceu_camera.c |   19 +------------------
 2 files changed, 10 insertions(+), 28 deletions(-)

diff --git a/arch/sh/mm/consistent.c b/arch/sh/mm/consistent.c
index c86a085..c617b99 100644
--- a/arch/sh/mm/consistent.c
+++ b/arch/sh/mm/consistent.c
@@ -127,8 +127,7 @@ int __init platform_resource_setup_memory(struct platform_device *pdev,
 					  char *name, unsigned long memsize)
 {
 	struct resource *r;
-	dma_addr_t dma_handle;
-	void *buf;
+	int ret;
 
 	r = pdev->resource + pdev->num_resources - 1;
 	if (r->flags) {
@@ -141,17 +140,17 @@ int __init platform_resource_setup_memory(struct platform_device *pdev,
 	if (!memsize)
 		return 0;
 
-	buf = dma_alloc_coherent(NULL, memsize, &dma_handle, GFP_KERNEL);
-	if (!buf) {
-		pr_warning("%s: unable to allocate memory\n", name);
-		return -ENOMEM;
+	ret = dma_preallocate_coherent_memory(&pdev->dev, memsize, GFP_KERNEL,
+					      DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE);
+	if (ret < 0) {
+		pr_warning("%s: unable to allocate memory: %d\n", name, ret);
+		return ret;
 	}
 
-	memset(buf, 0, memsize);
-
 	r->flags = IORESOURCE_MEM;
-	r->start = dma_handle;
-	r->end = r->start + memsize - 1;
+	/* Only the size is needed */
+	r->start = 0;
+	r->end = memsize - 1;
 	r->name = name;
 	return 0;
 }
diff --git a/drivers/media/video/sh_mobile_ceu_camera.c b/drivers/media/video/sh_mobile_ceu_camera.c
index bfddad8..325671e 100644
--- a/drivers/media/video/sh_mobile_ceu_camera.c
+++ b/drivers/media/video/sh_mobile_ceu_camera.c
@@ -1951,20 +1951,8 @@ static int __devinit sh_mobile_ceu_probe(struct platform_device *pdev)
 	pcdev->video_limit = 0; /* only enabled if second resource exists */
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
-	if (res) {
-		err = dma_declare_coherent_memory(&pdev->dev, res->start,
-						  res->start,
-						  resource_size(res),
-						  DMA_MEMORY_MAP |
-						  DMA_MEMORY_EXCLUSIVE);
-		if (!err) {
-			dev_err(&pdev->dev, "Unable to declare CEU memory.\n");
-			err = -ENXIO;
-			goto exit_iounmap;
-		}
-
+	if (res)
 		pcdev->video_limit = resource_size(res);
-	}
 
 	/* request irq */
 	err = request_irq(pcdev->irq, sh_mobile_ceu_irq, IRQF_DISABLED,
@@ -2036,9 +2024,6 @@ exit_free_clk:
 	pm_runtime_disable(&pdev->dev);
 	free_irq(pcdev->irq, pcdev);
 exit_release_mem:
-	if (platform_get_resource(pdev, IORESOURCE_MEM, 1))
-		dma_release_declared_memory(&pdev->dev);
-exit_iounmap:
 	iounmap(base);
 exit_kfree:
 	kfree(pcdev);
@@ -2056,8 +2041,6 @@ static int __devexit sh_mobile_ceu_remove(struct platform_device *pdev)
 	soc_camera_host_unregister(soc_host);
 	pm_runtime_disable(&pdev->dev);
 	free_irq(pcdev->irq, pcdev);
-	if (platform_get_resource(pdev, IORESOURCE_MEM, 1))
-		dma_release_declared_memory(&pdev->dev);
 	iounmap(pcdev->base);
 	if (csi2 && csi2->driver)
 		module_put(csi2->driver->owner);
-- 
1.7.2

      parent reply	other threads:[~2010-08-19 14:40 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-19 14:39 [PATCH 0/5] Add API for DMA memory reservation for devices Guennadi Liakhovetski
2010-08-19 14:40 ` [PATCH 1/5] DMA: Remove unneeded "extern" from function declarations Guennadi Liakhovetski
2010-08-19 14:40 ` [PATCH 2/5] DMA: dma_declare_coherent_memory() should return an error if unsupported Guennadi Liakhovetski
2010-08-19 14:40 ` [PATCH 3/5] DMA: reduce the number of memory allocations Guennadi Liakhovetski
2010-08-19 15:35   ` Greg KH
2010-08-19 15:46     ` Guennadi Liakhovetski
2010-08-19 16:02       ` Greg KH
2010-09-14  8:52         ` Paul Mundt
2010-09-15  7:23           ` Guennadi Liakhovetski
2010-09-16  2:58             ` FUJITA Tomonori
2010-09-16  7:04               ` Russell King - ARM Linux
2010-09-16  7:08                 ` FUJITA Tomonori
2010-09-16  4:22             ` Paul Mundt
2010-08-20  1:15   ` Michał Nazarewicz
2010-08-19 14:40 ` [PATCH 4/5] DMA: Add functions to preallocate DMA memory dor devices Guennadi Liakhovetski
2010-09-02 10:50   ` Russell King - ARM Linux
2010-09-15  7:28     ` Uwe Kleine-König
2010-08-19 14:40 ` Guennadi Liakhovetski [this message]

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=Pine.LNX.4.64.1008191637490.26145@axis700.grange \
    --to=g.liakhovetski@gmx.de \
    --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