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] ARM: mx3/pcm037: properly allocate memory for mx3-camera
Date: Tue, 23 Nov 2010 23:54:48 +0100 (CET)	[thread overview]
Message-ID: <Pine.LNX.4.64.1011232354180.25676@axis700.grange> (raw)
In-Reply-To: <1290505382-16110-1-git-send-email-u.kleine-koenig@pengutronix.de>

On Tue, 23 Nov 2010, Uwe Kleine-K?nig wrote:

> There is no need to memzero the buffer because dma_alloc_coherent zeros
> the memory for us.
> 
> This fixes:
> 
> 	BUG: Your driver calls ioremap() on system memory.  This leads
> 	<4>to architecturally unpredictable behaviour on ARMv6+, and ioremap()
> 	<4>will fail in the next kernel release.  Please fix your driver.
> 
> Tested-by: Michael Grzeschik <mgr@pengutronix.de>
> Signed-off-by: Uwe Kleine-K?nig <u.kleine-koenig@pengutronix.de>
> ---
> Hello,
> 
> it seems to work this way, still I'd like to have some feedback if this
> is done right.  Russell?
> 
> I assume sending a patch to remove the <4> is just a waste of time,
> isn't it?
> 
> Best regards
> Uwe
> 
>  arch/arm/mach-mx3/mach-pcm037.c |   36 ++++++++++++++++++++----------------
>  1 files changed, 20 insertions(+), 16 deletions(-)
> 
> diff --git a/arch/arm/mach-mx3/mach-pcm037.c b/arch/arm/mach-mx3/mach-pcm037.c
> index 2ff3f66..265757f 100644
> --- a/arch/arm/mach-mx3/mach-pcm037.c
> +++ b/arch/arm/mach-mx3/mach-pcm037.c
> @@ -32,6 +32,7 @@
>  #include <linux/usb/otg.h>
>  #include <linux/usb/ulpi.h>
>  #include <linux/gfp.h>
> +#include <linux/memblock.h>
>  
>  #include <media/soc_camera.h>
>  
> @@ -413,29 +414,22 @@ struct mx3_camera_pdata camera_pdata = {
>  	.mclk_10khz	= 2000,
>  };
>  
> +static phys_addr_t mx3_camera_base __initdata;
> +#define MX3_CAMERA_BUF_SIZE SZ_4M
> +
>  static int __init pcm037_camera_alloc_dma(const size_t buf_size)
>  {
> -	dma_addr_t dma_handle;
> -	void *buf;
>  	int dma;
>  
> -	if (buf_size < 2 * 1024 * 1024)
> -		return -EINVAL;
> -
> -	buf = dma_alloc_coherent(NULL, buf_size, &dma_handle, GFP_KERNEL);
> -	if (!buf) {
> -		pr_err("%s: cannot allocate camera buffer-memory\n", __func__);
> -		return -ENOMEM;
> -	}
> -
> -	memset(buf, 0, buf_size);
> -
>  	dma = dma_declare_coherent_memory(&mx3_camera.dev,
> -					dma_handle, dma_handle, buf_size,
> +					mx3_camera_base, mx3_camera_base,
> +					MX3_CAMERA_BUF_SIZE,
>  					DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE);
>  
> -	/* The way we call dma_declare_coherent_memory only a malloc can fail */
> -	return dma & DMA_MEMORY_MAP ? 0 : -ENOMEM;

What was wrong with the original return statement?

Thanks
Guennadi

> +	if (!(dma & DMA_MEMORY_MAP))
> +		return -ENOMEM;
> +
> +	return 0;
>  }
>  
>  static struct platform_device *devices[] __initdata = {
> @@ -676,6 +670,15 @@ struct sys_timer pcm037_timer = {
>  	.init	= pcm037_timer_init,
>  };
>  
> +static void __init pcm037_reserve(void)
> +{
> +	/* reserve 4 MiB for mx3-camera */
> +	mx3_camera_base = memblock_alloc(MX3_CAMERA_BUF_SIZE,
> +			/* ??? */ MX3_CAMERA_BUF_SIZE);
> +	memblock_free(mx3_camera_base, MX3_CAMERA_BUF_SIZE);
> +	memblock_remove(mx3_camera_base, MX3_CAMERA_BUF_SIZE);
> +}
> +
>  MACHINE_START(PCM037, "Phytec Phycore pcm037")
>  	/* Maintainer: Pengutronix */
>  	.boot_params    = MX3x_PHYS_OFFSET + 0x100,
> @@ -683,4 +686,5 @@ MACHINE_START(PCM037, "Phytec Phycore pcm037")
>  	.init_irq       = mx31_init_irq,
>  	.init_machine   = mxc_board_init,
>  	.timer          = &pcm037_timer,
> +	.reserve	= pcm037_reserve,
>  MACHINE_END
> -- 
> 1.7.2.3
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
> 

---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

  parent reply	other threads:[~2010-11-23 22:54 UTC|newest]

Thread overview: 101+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-07  9:44 [PATCH] ARM: allow, but warn, when issuing ioremap() on RAM Felipe Contreras
2010-10-07 11:51 ` Baruch Siach
2010-10-07 12:29   ` [PATCH v2] " Felipe Contreras
2010-10-07 18:00     ` Uwe Kleine-König
2010-10-07 19:22 ` [PATCH] " Russell King - ARM Linux
2010-10-08  9:32   ` Felipe Contreras
2010-10-08 17:53     ` Russell King - ARM Linux
2010-10-08 19:37       ` Felipe Contreras
2010-10-08 23:04         ` Russell King - ARM Linux
2010-10-08 23:25           ` Greg KH
2010-10-08 23:44             ` Russell King - ARM Linux
2010-10-09  0:00               ` Greg KH
2010-10-09  0:25                 ` Russell King - ARM Linux
2010-10-09  0:54                   ` Greg KH
2010-10-09  2:41                   ` Nicolas Pitre
2010-10-09  3:04                     ` Greg KH
2010-10-09  9:32                       ` Felipe Contreras
2010-10-11 10:05                     ` Catalin Marinas
2010-10-11 10:39                       ` Felipe Contreras
2010-10-11 10:52                         ` Russell King - ARM Linux
2010-10-11 11:23                         ` Catalin Marinas
2010-10-11 12:03                           ` Felipe Contreras
2010-10-11 12:30                             ` Catalin Marinas
2010-10-11 22:53                               ` Nicolas Pitre
2010-10-14 15:02                               ` Felipe Contreras
2010-10-14 17:18                                 ` Catalin Marinas
2010-10-14 17:44                                   ` Felipe Contreras
2010-10-11 11:01                       ` Pawel Moll
2010-10-11 11:03                         ` Catalin Marinas
2010-10-16  2:39                 ` Benjamin Herrenschmidt
2010-10-16  9:43                   ` Felipe Contreras
2010-10-09  0:10               ` Russell King - ARM Linux
2010-10-09  0:56               ` Felipe Contreras
2010-10-09  9:21                 ` Russell King - ARM Linux
2010-10-09 10:28                   ` Felipe Contreras
2010-10-09 11:11                     ` Arnd Bergmann
2010-10-09 11:43                       ` Dave Airlie
2010-10-09 11:55                         ` Christoph Hellwig
2010-10-09 12:17                           ` Felipe Contreras
2010-10-09 12:10                         ` Felipe Contreras
2010-10-09 14:37                           ` Russell King - ARM Linux
2010-10-09 16:18                             ` Felipe Contreras
2010-10-09 11:44                       ` Uwe Kleine-König
2010-10-09 12:05                         ` Russell King - ARM Linux
2010-10-09 11:59                       ` Felipe Contreras
2010-10-09 14:43                         ` Arnd Bergmann
2010-10-09 18:59                           ` Guennadi Liakhovetski
2010-10-10  1:52                   ` Felipe Contreras
2010-10-11  8:35                     ` Uwe Kleine-König
2010-10-11  9:02                       ` Russell King - ARM Linux
2010-10-11  9:24                         ` Uwe Kleine-König
2010-10-11 10:08                           ` Felipe Contreras
2010-10-11 10:15                             ` Russell King - ARM Linux
2010-10-11 15:25                     ` Russell King - ARM Linux
2010-10-14 14:47                       ` Felipe Contreras
2010-10-19  8:13                       ` Colin Cross
2010-10-19 18:12                         ` Russell King - ARM Linux
2010-10-19 19:21                         ` Russell King - ARM Linux
2010-11-23  9:43                       ` [PATCH] ARM: mx3/pcm037: properly allocate memory for mx3-camera Uwe Kleine-König
2010-11-23 10:12                         ` Russell King - ARM Linux
2010-11-23 10:26                           ` Uwe Kleine-König
2010-11-23 14:08                             ` Alberto Panizzo
2010-11-23 14:17                               ` Uwe Kleine-König
2010-11-24  8:02                                 ` Uwe Kleine-König
2010-12-06  8:33                                   ` Uwe Kleine-König
2010-12-06 10:14                                     ` Alberto Panizzo
2010-12-06 10:26                                       ` Russell King - ARM Linux
2010-12-06 11:37                                         ` Alberto Panizzo
2010-12-06 11:46                                           ` Russell King - ARM Linux
2010-12-06 14:09                                             ` Alberto Panizzo
2010-12-06 14:34                                               ` Russell King - ARM Linux
2010-12-06 14:54                                                 ` Alberto Panizzo
2010-12-06 16:54                                                   ` Alberto Panizzo
2010-11-23 10:39                           ` About multi-line printk and the need (not) to repeat loglevel markers [Was: Re: [PATCH] ARM: mx3/pcm037: properly allocate memory for mx3-camera] Uwe Kleine-König
2010-11-23 10:58                             ` Uwe Kleine-König
2010-11-23 22:16                               ` Linus Torvalds
2010-11-23 22:33                                 ` Russell King - ARM Linux
2010-11-23 23:23                                   ` Joe Perches
2010-11-24  8:17                                 ` Uwe Kleine-König
2010-11-24  9:09                                   ` Michał Mirosław
2010-11-23 22:54                         ` Guennadi Liakhovetski [this message]
2010-10-09  0:45             ` [PATCH] ARM: allow, but warn, when issuing ioremap() on RAM Felipe Contreras
2010-10-09  8:56               ` Russell King - ARM Linux
2010-10-08 23:19       ` Greg KH
2010-10-09  3:36         ` Nicolas Pitre
2010-10-09 10:00           ` Felipe Contreras
2010-10-09 17:38             ` Nicolas Pitre
2010-10-09 20:16               ` Felipe Contreras
2010-10-13 16:17             ` Woodruff, Richard
2010-10-14 13:48               ` Felipe Contreras
2010-10-14 15:29                 ` Woodruff, Richard
2010-10-16  2:36       ` Benjamin Herrenschmidt
2010-10-17 13:05         ` Woodruff, Richard
2010-10-17 23:17           ` Benjamin Herrenschmidt
2010-10-08 19:58   ` Andrew Morton
2010-10-09 13:52 ` Russell King - ARM Linux
2010-10-09 16:07   ` Felipe Contreras
2010-10-09 16:45     ` Russell King - ARM Linux
2010-10-09 19:25       ` Felipe Contreras
2010-10-10 14:23       ` Pedanekar, Hemant
2010-10-11  9:26       ` Catalin Marinas

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.1011232354180.25676@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