mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sam Ravnborg <sam@ravnborg.org>
To: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 12/12] ARM: mmu: Make sure DMA coherent memory is zeroed out
Date: Thu, 17 Jan 2019 22:36:48 +0100	[thread overview]
Message-ID: <20190117213648.GC4532@ravnborg.org> (raw)
In-Reply-To: <20190117063840.13674-13-andrew.smirnov@gmail.com>

Hi Andrey.

On Wed, Jan 16, 2019 at 10:38:40PM -0800, Andrey Smirnov wrote:
> In order to avoid passing random/junky values to DMA/HW as well as to
> allow simplifying memory initialization in individual drivers, chagnge
chagnge => change

> dma_alloc_coherent() to guarantee that memory it returs is properly
returs => returns
> zeroed out.
> 
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> ---
>  arch/arm/cpu/mmu-common.c | 3 ++-
>  arch/arm/cpu/mmu-common.h | 1 +
>  arch/arm/cpu/mmu.c        | 2 +-
>  arch/arm/cpu/mmu_64.c     | 8 ++++++++
>  4 files changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm/cpu/mmu-common.c b/arch/arm/cpu/mmu-common.c
> index c5b24bff8..aeefbb2da 100644
> --- a/arch/arm/cpu/mmu-common.c
> +++ b/arch/arm/cpu/mmu-common.c
> @@ -43,7 +43,8 @@ void *dma_alloc_map(size_t size, dma_addr_t *dma_handle, unsigned flags)
>  	if (dma_handle)
>  		*dma_handle = (dma_addr_t)ret;
>  
> -	dma_inv_range(ret, size);
> +	memset(ret, 0, size);
> +	dma_flush_range(ret, size);
>  
>  	arch_remap_range(ret, size, flags);
>  
> diff --git a/arch/arm/cpu/mmu-common.h b/arch/arm/cpu/mmu-common.h
> index 679799c3c..0a33b138e 100644
> --- a/arch/arm/cpu/mmu-common.h
> +++ b/arch/arm/cpu/mmu-common.h
> @@ -2,6 +2,7 @@
>  #define __ARM_MMU_COMMON_H
>  
>  void dma_inv_range(void *ptr, size_t size);
> +void dma_flush_range(void *ptr, size_t size);
>  void *dma_alloc_map(size_t size, dma_addr_t *dma_handle, unsigned flags);
>  void __mmu_init(bool mmu_on);
>  
> diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
> index 9e261a0be..29816ad56 100644
> --- a/arch/arm/cpu/mmu.c
> +++ b/arch/arm/cpu/mmu.c
> @@ -97,7 +97,7 @@ static u32 *find_pte(unsigned long adr)
>  	return &table[(adr >> PAGE_SHIFT) & 0xff];
>  }
>  
> -static void dma_flush_range(void *ptr, size_t size)
> +void dma_flush_range(void *ptr, size_t size)
>  {
>  	unsigned long start = (unsigned long)ptr;
>  	unsigned long end = start + size;
> diff --git a/arch/arm/cpu/mmu_64.c b/arch/arm/cpu/mmu_64.c
> index a3074b10d..b45a69661 100644
> --- a/arch/arm/cpu/mmu_64.c
> +++ b/arch/arm/cpu/mmu_64.c
> @@ -233,6 +233,14 @@ void dma_inv_range(void *ptr, size_t size)
>  	v8_inv_dcache_range(start, end);
>  }
>  
> +void dma_flush_range(void *ptr, size_t size)
> +{
> +	unsigned long start = (unsigned long)ptr;
> +	unsigned long end = start + size - 1;
> +
> +	v8_flush_dcache_range(start, end);
> +}
We should use the existing indirection with struct cache_fns
here, then we could share the code.

	Sam

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2019-01-17 21:36 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-17  6:38 [PATCH 00/12] ARM/ARM64 MMU code consolidation, zeroing of DMA coherent memory Andrey Smirnov
2019-01-17  6:38 ` [PATCH 01/12] ARM: mmu: Drop custom virt_to_phys/phys_to_virt Andrey Smirnov
2019-01-17  6:38 ` [PATCH 02/12] ARM: mmu: Simplify the use of dma_inv_range() Andrey Smirnov
2019-01-17  6:38 ` [PATCH 03/12] ARM: mmu: Share code for dma_(un)map_single() Andrey Smirnov
2019-01-17  6:38 ` [PATCH 04/12] ARM64: mmu: Use arch_remap_range() internaly Andrey Smirnov
2019-01-17  6:38 ` [PATCH 05/12] ARM64: mmu: Merge create_sections() and map_region() together Andrey Smirnov
2019-01-17  6:38 ` [PATCH 06/12] ARM: mmu: Share code for dma_free_coherent() Andrey Smirnov
2019-01-17  6:38 ` [PATCH 07/12] ARM64: mmu: Invalidate memory before remapping as DMA coherent Andrey Smirnov
2019-01-17  6:38 ` [PATCH 08/12] ARM: mmu: Share code for dma_alloc_coherent() Andrey Smirnov
2019-01-17 21:23   ` Sam Ravnborg
2019-01-17 21:54     ` Andrey Smirnov
2019-01-17 22:06       ` Sam Ravnborg
2019-01-17  6:38 ` [PATCH 09/12] ARM: mmu: Share code for dma_sync_single_for_cpu() Andrey Smirnov
2019-01-17 21:28   ` Sam Ravnborg
2019-01-17 21:50     ` Andrey Smirnov
2019-01-17 22:04       ` Sam Ravnborg
2019-01-17  6:38 ` [PATCH 10/12] ARM: mmu: Share sanity checking code in mmu_init() Andrey Smirnov
2019-01-17  6:38 ` [PATCH 11/12] ARM: mmu: Share code for arm_mmu_not_initialized_error() Andrey Smirnov
2019-01-17  6:38 ` [PATCH 12/12] ARM: mmu: Make sure DMA coherent memory is zeroed out Andrey Smirnov
2019-01-17 21:36   ` Sam Ravnborg [this message]
2019-01-17 22:00     ` Andrey Smirnov
2019-01-17 22:11       ` Sam Ravnborg
2019-01-17 21:40 ` [PATCH 00/12] ARM/ARM64 MMU code consolidation, zeroing of DMA coherent memory Sam Ravnborg
2019-01-17 22:01   ` Andrey Smirnov
2019-01-17 22:06   ` Sam Ravnborg

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=20190117213648.GC4532@ravnborg.org \
    --to=sam@ravnborg.org \
    --cc=andrew.smirnov@gmail.com \
    --cc=barebox@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