diff mbox series

[3/5] arm: qemu: implement enable_caches()

Message ID 20200606171534.736365-4-ardb@kernel.org
State Superseded
Headers show
Series Fixes for running U-boot under QEMU/KVM | expand

Commit Message

Ard Biesheuvel June 6, 2020, 5:15 p.m. UTC
Add an override for enable_caches to enable the I and D caches, along
with the cached 1:1 mapping of all of DRAM. This is needed for running
U-Boot under virtualization with QEMU/kvm.

Signed-off-by: Ard Biesheuvel <ardb at kernel.org>
---
 board/emulation/qemu-arm/qemu-arm.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Heinrich Schuchardt June 6, 2020, 8:50 p.m. UTC | #1
On 6/6/20 7:15 PM, Ard Biesheuvel wrote:
> Add an override for enable_caches to enable the I and D caches, along
> with the cached 1:1 mapping of all of DRAM. This is needed for running
> U-Boot under virtualization with QEMU/kvm.
>
> Signed-off-by: Ard Biesheuvel <ardb at kernel.org>
> ---
>  board/emulation/qemu-arm/qemu-arm.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/board/emulation/qemu-arm/qemu-arm.c b/board/emulation/qemu-arm/qemu-arm.c
> index 69e8ef46f1f5..1b0d543b93c1 100644
> --- a/board/emulation/qemu-arm/qemu-arm.c
> +++ b/board/emulation/qemu-arm/qemu-arm.c
> @@ -4,6 +4,7 @@
>   */
>
>  #include <common.h>
> +#include <cpu_func.h>
>  #include <dm.h>
>  #include <fdtdec.h>
>  #include <init.h>
> @@ -94,6 +95,12 @@ void *board_fdt_blob_setup(void)
>  	return (void *)CONFIG_SYS_SDRAM_BASE;
>  }
>
> +void enable_caches(void)
> +{
> +	 icache_enable();
> +	 dcache_enable();
> +}
> +

For other ARM architectures I have seen:

int arch_cpu_init(void)
{
????????icache_enable();
??????? return 0;
}

void enable_caches(void)
{
??????? dcache_enable();
}

Some boards have

if (!icache_status())
	icache_enable();

others

#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
	icache_enable();
#endif

Tom could you, please, advice what is the correct way to do it.

Best regards

Heinrich

>  #if defined(CONFIG_EFI_RNG_PROTOCOL)
>  #include <efi_loader.h>
>  #include <efi_rng.h>
>
Tom Rini June 8, 2020, 1:17 p.m. UTC | #2
On Sat, Jun 06, 2020 at 10:50:59PM +0200, Heinrich Schuchardt wrote:
> On 6/6/20 7:15 PM, Ard Biesheuvel wrote:
> > Add an override for enable_caches to enable the I and D caches, along
> > with the cached 1:1 mapping of all of DRAM. This is needed for running
> > U-Boot under virtualization with QEMU/kvm.
> >
> > Signed-off-by: Ard Biesheuvel <ardb at kernel.org>
> > ---
> >  board/emulation/qemu-arm/qemu-arm.c | 7 +++++++
> >  1 file changed, 7 insertions(+)
> >
> > diff --git a/board/emulation/qemu-arm/qemu-arm.c b/board/emulation/qemu-arm/qemu-arm.c
> > index 69e8ef46f1f5..1b0d543b93c1 100644
> > --- a/board/emulation/qemu-arm/qemu-arm.c
> > +++ b/board/emulation/qemu-arm/qemu-arm.c
> > @@ -4,6 +4,7 @@
> >   */
> >
> >  #include <common.h>
> > +#include <cpu_func.h>
> >  #include <dm.h>
> >  #include <fdtdec.h>
> >  #include <init.h>
> > @@ -94,6 +95,12 @@ void *board_fdt_blob_setup(void)
> >  	return (void *)CONFIG_SYS_SDRAM_BASE;
> >  }
> >
> > +void enable_caches(void)
> > +{
> > +	 icache_enable();
> > +	 dcache_enable();
> > +}
> > +
> 
> For other ARM architectures I have seen:
> 
> int arch_cpu_init(void)
> {
> ????????icache_enable();
> ??????? return 0;
> }
> 
> void enable_caches(void)
> {
> ??????? dcache_enable();
> }
> 
> Some boards have
> 
> if (!icache_status())
> 	icache_enable();
> 
> others
> 
> #if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
> 	icache_enable();
> #endif
> 
> Tom could you, please, advice what is the correct way to do it.

Off-hand?  Dealing with it per SoC/mach/board as we do today.  Sometimes
we need a dcache_disable() before the dcache_enable() as well to clear
out previous mappings.  So dropping this in here is probably the best
choice for qemu-arm.  Thanks!
diff mbox series

Patch

diff --git a/board/emulation/qemu-arm/qemu-arm.c b/board/emulation/qemu-arm/qemu-arm.c
index 69e8ef46f1f5..1b0d543b93c1 100644
--- a/board/emulation/qemu-arm/qemu-arm.c
+++ b/board/emulation/qemu-arm/qemu-arm.c
@@ -4,6 +4,7 @@ 
  */
 
 #include <common.h>
+#include <cpu_func.h>
 #include <dm.h>
 #include <fdtdec.h>
 #include <init.h>
@@ -94,6 +95,12 @@  void *board_fdt_blob_setup(void)
 	return (void *)CONFIG_SYS_SDRAM_BASE;
 }
 
+void enable_caches(void)
+{
+	 icache_enable();
+	 dcache_enable();
+}
+
 #if defined(CONFIG_EFI_RNG_PROTOCOL)
 #include <efi_loader.h>
 #include <efi_rng.h>