public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Siarhei Siamashka <siarhei.siamashka@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] sunxi: mctl_mem_matches: Add missing memory barrier
Date: Fri, 15 Apr 2016 03:46:58 +0300	[thread overview]
Message-ID: <20160415034658.37fd0ae0@i7> (raw)
In-Reply-To: <1460653084-32197-1-git-send-email-hdegoede@redhat.com>

Hello Hans,

On Thu, 14 Apr 2016 18:58:04 +0200
Hans de Goede <hdegoede@redhat.com> wrote:

> We are running with the caches disabled when mctl_mem_matches gets called,
> but the cpu's write buffer is still there and can still get in the way,

This does not make much sense to me. The SPL is running with the MMU
disabled, because disabling the MMU is one of the first things done by
the SPL at the very start. And when the MMU is disabled, all the data
accesses are treated as Strongly-ordered and are not supposed to use
the write buffer. A quote from the ARMv7 Architecture Manual:

   "a write to Strongly-ordered memory can complete only when it
   reaches the peripheral or memory component accessed by the write"

We can even verify whether the write buffer is actually in use by simply
benchmarking something like the memset function. If the write buffer is
working, then the sequential write speed will be around 1 GB/s or more.

> add a memory barrier to fix this.
> 
> This avoids mctl_mem_matches always returning false in some cases, which
> was resulting in:
> 
> U-Boot SPL 2015.07 (Apr 14 2016 - 18:47:26)
> DRAM: 1024 MiB
> 
> U-Boot 2015.07 (Apr 14 2016 - 18:47:26 +0200) Allwinner Technology
> 
> CPU:   Allwinner A23 (SUN8I)
> DRAM:  512 MiB
> 
> Where 512 MiB is the right amount, but the DRAM controller would be
> initialized for 1024 MiB.

Is it just a single device or board? Has anybody seen anything like
this on other devices with the same SoC?

I wonder if what you are observing could be possibly explained by just
a usual data corruption problem? Which may be happening when the DRAM
clock speed is set higher than this particular device is able to handle
in a reliable way. Inserting just one or more NOP instructions instead
of the barrier could possibly change some timings too.

If this patch helps, then it's fine. But I wonder if it is not merely
making the problem latent instead of fixing the root cause?

> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  arch/arm/mach-sunxi/dram_helpers.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/arch/arm/mach-sunxi/dram_helpers.c b/arch/arm/mach-sunxi/dram_helpers.c
> index 50318d2..e0c823a 100644
> --- a/arch/arm/mach-sunxi/dram_helpers.c
> +++ b/arch/arm/mach-sunxi/dram_helpers.c
> @@ -7,6 +7,7 @@
>   */
>  
>  #include <common.h>
> +#include <asm/armv7.h>
>  #include <asm/io.h>
>  #include <asm/arch/dram.h>
>  
> @@ -31,6 +32,7 @@ bool mctl_mem_matches(u32 offset)
>  	/* Try to write different values to RAM at two addresses */
>  	writel(0, CONFIG_SYS_SDRAM_BASE);
>  	writel(0xaa55aa55, (ulong)CONFIG_SYS_SDRAM_BASE + offset);
> +	DSB;
>  	/* Check if the same value is actually observed when reading back */
>  	return readl(CONFIG_SYS_SDRAM_BASE) ==
>  	       readl((ulong)CONFIG_SYS_SDRAM_BASE + offset);

-- 
Best regards,
Siarhei Siamashka

  reply	other threads:[~2016-04-15  0:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-14 16:58 [U-Boot] [PATCH] sunxi: mctl_mem_matches: Add missing memory barrier Hans de Goede
2016-04-15  0:46 ` Siarhei Siamashka [this message]
2016-04-15  7:34   ` Hans de Goede
2016-04-22  9:32     ` Ian Campbell
2016-04-22 10:48       ` Hans de Goede
2016-04-22 11:46         ` Andre Przywara
2016-04-22 12:09           ` Hans de Goede
2016-04-22 13:12             ` Andre Przywara
2016-04-22 13:20               ` Ian Campbell

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=20160415034658.37fd0ae0@i7 \
    --to=siarhei.siamashka@gmail.com \
    --cc=u-boot@lists.denx.de \
    /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