As of today we call flush_dcache_all before relocation, to sync
I/D caches so there are two problems:
 * We also flush SLC (on ARCv2) - this is overhead as SLC is
   shared for data and instructions.
 * We don't invalidate I$ - this can be dangerous if have some
   valid lines in I$ in relocation area for some reason.

Fix this by implementing specialized sync_icache_dcache_all
function.

Signed-off-by: Eugeniy Paltsev <eugeniy.palt...@synopsys.com>
---
 arch/arc/include/asm/cache.h |  1 +
 arch/arc/lib/cache.c         | 10 ++++++++++
 arch/arc/lib/init_helpers.c  |  6 +++---
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/arch/arc/include/asm/cache.h b/arch/arc/include/asm/cache.h
index fe75409..6300676 100644
--- a/arch/arc/include/asm/cache.h
+++ b/arch/arc/include/asm/cache.h
@@ -31,6 +31,7 @@
 
 void cache_init(void);
 void flush_n_invalidate_dcache_all(void);
+void sync_icache_dcache_all(void);
 
 static const inline int is_ioc_enabled(void)
 {
diff --git a/arch/arc/lib/cache.c b/arch/arc/lib/cache.c
index df269cf..76602ae 100644
--- a/arch/arc/lib/cache.c
+++ b/arch/arc/lib/cache.c
@@ -491,3 +491,13 @@ void flush_dcache_all(void)
        if (is_isa_arcv2())
                __slc_entire_op(OP_FLUSH);
 }
+
+/*
+ * This is function for making I/D Caches consistent when modifying u-boot code
+ * (relocation, etc...)
+ */
+void sync_icache_dcache_all(void)
+{
+       __dc_entire_op(OP_FLUSH);
+       __ic_entire_invalidate();
+}
diff --git a/arch/arc/lib/init_helpers.c b/arch/arc/lib/init_helpers.c
index dbc8d68..f7022ab 100644
--- a/arch/arc/lib/init_helpers.c
+++ b/arch/arc/lib/init_helpers.c
@@ -4,14 +4,14 @@
  * SPDX-License-Identifier:    GPL-2.0+
  */
 
+#include <asm/cache.h>
 #include <common.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
 int init_cache_f_r(void)
 {
-#ifndef CONFIG_SYS_DCACHE_OFF
-       flush_dcache_all();
-#endif
+       sync_icache_dcache_all();
+
        return 0;
 }
-- 
2.9.3

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot

Reply via email to