[PATCH 1/7] m68k: Implement a default flush_dcache_all

Implement a weak default version of flush_dcache_all which is based on the ARM default, which is to flush the entire range via flush_dcache_range(...).
Signed-off-by: Tom Rini trini@konsulko.com --- Cc: Huan Wang alison.wang@nxp.com Cc: Angelo Dureghello angelo@kernel-space.org --- arch/m68k/lib/cache.c | 9 +++++++++ 1 file changed, 9 insertions(+)
diff --git a/arch/m68k/lib/cache.c b/arch/m68k/lib/cache.c index de04124404cf..dab834c1cbd8 100644 --- a/arch/m68k/lib/cache.c +++ b/arch/m68k/lib/cache.c @@ -134,6 +134,15 @@ void dcache_invalid(void) #endif }
+/* + * Default implementation: + * do a range flush for the entire range + */ +__weak void flush_dcache_all(void) +{ + flush_dcache_range(0, ~0); +} + __weak void invalidate_dcache_range(unsigned long start, unsigned long stop) { /* An empty stub, real implementation should be in platform code */

The implementation of icache_invalid appears to be doing what other architectures call invalidate_icache_all so rename to match.
Signed-off-by: Tom Rini trini@konsulko.com --- Huan Wang alison.wang@nxp.com Angelo Dureghello angelo@kernel-space.org --- arch/m68k/include/asm/cache.h | 1 - arch/m68k/lib/cache.c | 6 +++--- drivers/net/mcffec.c | 5 +++-- 3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h index 6ef7f7be1af8..aa8d2edb40ba 100644 --- a/arch/m68k/include/asm/cache.h +++ b/arch/m68k/include/asm/cache.h @@ -185,7 +185,6 @@
#ifndef __ASSEMBLY__ /* put C only stuff in this section */
-void icache_invalid(void); void dcache_invalid(void);
#endif diff --git a/arch/m68k/lib/cache.c b/arch/m68k/lib/cache.c index dab834c1cbd8..370ad40f1423 100644 --- a/arch/m68k/lib/cache.c +++ b/arch/m68k/lib/cache.c @@ -29,7 +29,7 @@ int dcache_status(void)
void icache_enable(void) { - icache_invalid(); + invalidate_icache_all();
*cf_icache_status = 1;
@@ -53,7 +53,7 @@ void icache_disable(void) u32 temp = 0;
*cf_icache_status = 0; - icache_invalid(); + invalidate_icache_all();
#if defined(CONFIG_CF_V4) || defined(CFG_CF_V4E) __asm__ __volatile__("movec %0, %%acr2"::"r"(temp)); @@ -68,7 +68,7 @@ void icache_disable(void) #endif }
-void icache_invalid(void) +void invalidate_icache_all(void) { u32 temp;
diff --git a/drivers/net/mcffec.c b/drivers/net/mcffec.c index 04b711e4f650..7e53492733ed 100644 --- a/drivers/net/mcffec.c +++ b/drivers/net/mcffec.c @@ -11,6 +11,7 @@ */
#include <config.h> +#include <cpu_func.h> #include <env.h> #include <hang.h> #include <malloc.h> @@ -399,7 +400,7 @@ static int mcffec_send(struct udevice *dev, void *packet, int length) #endif
#ifdef CONFIG_SYS_UNIFY_CACHE - icache_invalid(); + invalidate_icache_all(); #endif
j = 0; @@ -433,7 +434,7 @@ static int mcffec_recv(struct udevice *dev, int flags, uchar **packetp)
for (;;) { #ifdef CONFIG_SYS_UNIFY_CACHE - icache_invalid(); + invalidate_icache_all(); #endif /* If nothing received - leave for() loop */ if (info->rxbd[info->rx_idx].cbd_sc & BD_ENET_RX_EMPTY)

On Thu, 20 Jun 2024 at 00:28, Tom Rini trini@konsulko.com wrote:
The implementation of icache_invalid appears to be doing what other architectures call invalidate_icache_all so rename to match.
Signed-off-by: Tom Rini trini@konsulko.com
Huan Wang alison.wang@nxp.com Angelo Dureghello angelo@kernel-space.org
arch/m68k/include/asm/cache.h | 1 - arch/m68k/lib/cache.c | 6 +++--- drivers/net/mcffec.c | 5 +++-- 3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h index 6ef7f7be1af8..aa8d2edb40ba 100644 --- a/arch/m68k/include/asm/cache.h +++ b/arch/m68k/include/asm/cache.h @@ -185,7 +185,6 @@
#ifndef __ASSEMBLY__ /* put C only stuff in this section */
-void icache_invalid(void); void dcache_invalid(void);
#endif diff --git a/arch/m68k/lib/cache.c b/arch/m68k/lib/cache.c index dab834c1cbd8..370ad40f1423 100644 --- a/arch/m68k/lib/cache.c +++ b/arch/m68k/lib/cache.c @@ -29,7 +29,7 @@ int dcache_status(void)
void icache_enable(void) {
icache_invalid();
invalidate_icache_all(); *cf_icache_status = 1;
@@ -53,7 +53,7 @@ void icache_disable(void) u32 temp = 0;
*cf_icache_status = 0;
icache_invalid();
invalidate_icache_all();
#if defined(CONFIG_CF_V4) || defined(CFG_CF_V4E) __asm__ __volatile__("movec %0, %%acr2"::"r"(temp)); @@ -68,7 +68,7 @@ void icache_disable(void) #endif }
-void icache_invalid(void) +void invalidate_icache_all(void) { u32 temp;
diff --git a/drivers/net/mcffec.c b/drivers/net/mcffec.c index 04b711e4f650..7e53492733ed 100644 --- a/drivers/net/mcffec.c +++ b/drivers/net/mcffec.c @@ -11,6 +11,7 @@ */
#include <config.h> +#include <cpu_func.h> #include <env.h> #include <hang.h> #include <malloc.h> @@ -399,7 +400,7 @@ static int mcffec_send(struct udevice *dev, void *packet, int length) #endif
#ifdef CONFIG_SYS_UNIFY_CACHE
icache_invalid();
invalidate_icache_all();
#endif
j = 0;
@@ -433,7 +434,7 @@ static int mcffec_recv(struct udevice *dev, int flags, uchar **packetp)
for (;;) {
#ifdef CONFIG_SYS_UNIFY_CACHE
icache_invalid();
invalidate_icache_all();
#endif /* If nothing received - leave for() loop */ if (info->rxbd[info->rx_idx].cbd_sc & BD_ENET_RX_EMPTY) -- 2.34.1
Reviewed-by: Ilias Apalodimas ilias.apalodimas@linaro.org

Implement a weak default version of flush_dcache_all which is based on the ARM default, which is to flush the entire range via flush_dcache_range(...).
Signed-off-by: Tom Rini trini@konsulko.com --- Cc: Marek Vasut marex@denx.de Cc: Nobuhiro Iwamatsu iwamatsu@nigauri.org --- arch/sh/cpu/sh4/cache.c | 9 +++++++++ 1 file changed, 9 insertions(+)
diff --git a/arch/sh/cpu/sh4/cache.c b/arch/sh/cpu/sh4/cache.c index 8c1839935ca1..f0cb39d6a923 100644 --- a/arch/sh/cpu/sh4/cache.c +++ b/arch/sh/cpu/sh4/cache.c @@ -65,6 +65,15 @@ void flush_dcache_range(unsigned long start, unsigned long end) } }
+/* + * Default implementation: + * do a range flush for the entire range + */ +void flush_dcache_all(void) +{ + flush_dcache_range(0, ~0); +} + void invalidate_dcache_range(unsigned long start, unsigned long end) { u32 v;

On Thu, 20 Jun 2024 at 00:28, Tom Rini trini@konsulko.com wrote:
Implement a weak default version of flush_dcache_all which is based on the ARM default, which is to flush the entire range via flush_dcache_range(...).
Signed-off-by: Tom Rini trini@konsulko.com
Cc: Marek Vasut marex@denx.de Cc: Nobuhiro Iwamatsu iwamatsu@nigauri.org
arch/sh/cpu/sh4/cache.c | 9 +++++++++ 1 file changed, 9 insertions(+)
diff --git a/arch/sh/cpu/sh4/cache.c b/arch/sh/cpu/sh4/cache.c index 8c1839935ca1..f0cb39d6a923 100644 --- a/arch/sh/cpu/sh4/cache.c +++ b/arch/sh/cpu/sh4/cache.c @@ -65,6 +65,15 @@ void flush_dcache_range(unsigned long start, unsigned long end) } }
+/*
- Default implementation:
- do a range flush for the entire range
- */
+void flush_dcache_all(void) +{
flush_dcache_range(0, ~0);
+}
void invalidate_dcache_range(unsigned long start, unsigned long end) { u32 v; -- 2.34.1
Acked-by: Ilias Apalodimas ilias.apalodimas@linaro.org

On 6/19/24 11:27 PM, Tom Rini wrote:
Implement a weak default version of flush_dcache_all which is based on the ARM default, which is to flush the entire range via flush_dcache_range(...).
Signed-off-by: Tom Rini trini@konsulko.com
Cc: Marek Vasut marex@denx.de Cc: Nobuhiro Iwamatsu iwamatsu@nigauri.org
arch/sh/cpu/sh4/cache.c | 9 +++++++++ 1 file changed, 9 insertions(+)
diff --git a/arch/sh/cpu/sh4/cache.c b/arch/sh/cpu/sh4/cache.c index 8c1839935ca1..f0cb39d6a923 100644 --- a/arch/sh/cpu/sh4/cache.c +++ b/arch/sh/cpu/sh4/cache.c @@ -65,6 +65,15 @@ void flush_dcache_range(unsigned long start, unsigned long end) } }
+/*
- Default implementation:
- do a range flush for the entire range
- */
+void flush_dcache_all(void) +{
- flush_dcache_range(0, ~0);
+}
The current implementation that is in tree should be fine, thanks.

Add the old invalidate_icache_all function that prints a warning that was previously found in cmd/cache.c
Signed-off-by: Tom Rini trini@konsulko.com --- Cc: Marek Vasut marex@denx.de Cc: Nobuhiro Iwamatsu iwamatsu@nigauri.org --- arch/sh/cpu/sh4/cache.c | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/arch/sh/cpu/sh4/cache.c b/arch/sh/cpu/sh4/cache.c index f0cb39d6a923..d3c480e79ed2 100644 --- a/arch/sh/cpu/sh4/cache.c +++ b/arch/sh/cpu/sh4/cache.c @@ -6,6 +6,7 @@
#include <command.h> #include <cpu_func.h> +#include <stdio.h> #include <asm/cache.h> #include <asm/io.h> #include <asm/processor.h> @@ -100,6 +101,11 @@ void icache_disable(void) cache_control(CACHE_DISABLE); }
+void invalidate_icache_all(void) +{ + puts("No arch specific invalidate_icache_all available!\n"); +} + int icache_status(void) { return 0;

On 6/19/24 11:27 PM, Tom Rini wrote:
Add the old invalidate_icache_all function that prints a warning that was previously found in cmd/cache.c
Signed-off-by: Tom Rini trini@konsulko.com
Cc: Marek Vasut marex@denx.de Cc: Nobuhiro Iwamatsu iwamatsu@nigauri.org
arch/sh/cpu/sh4/cache.c | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/arch/sh/cpu/sh4/cache.c b/arch/sh/cpu/sh4/cache.c index f0cb39d6a923..d3c480e79ed2 100644 --- a/arch/sh/cpu/sh4/cache.c +++ b/arch/sh/cpu/sh4/cache.c @@ -6,6 +6,7 @@
#include <command.h> #include <cpu_func.h> +#include <stdio.h> #include <asm/cache.h> #include <asm/io.h> #include <asm/processor.h> @@ -100,6 +101,11 @@ void icache_disable(void) cache_control(CACHE_DISABLE); }
+void invalidate_icache_all(void) +{
- puts("No arch specific invalidate_icache_all available!\n");
+}
- int icache_status(void) { return 0;
I just posted
sh: cache: Fill in invalidate_icache_all()

Implement a weak default version of flush_dcache_all which is based on the ARM default, which is to flush the entire range via flush_dcache_range(...).
Signed-off-by: Tom Rini trini@konsulko.com --- arch/powerpc/lib/cache.c | 9 +++++++++ 1 file changed, 9 insertions(+)
diff --git a/arch/powerpc/lib/cache.c b/arch/powerpc/lib/cache.c index e480b2696494..130318d745aa 100644 --- a/arch/powerpc/lib/cache.c +++ b/arch/powerpc/lib/cache.c @@ -43,3 +43,12 @@ void flush_cache(ulong start_addr, ulong size) /* flush prefetch queue */ asm volatile("isync" : : : "memory"); } + +/* + * Default implementation: + * do a range flush for the entire range + */ +void flush_dcache_all(void) +{ + flush_dcache_range(0, ~0); +}

On Thu, 20 Jun 2024 at 00:28, Tom Rini trini@konsulko.com wrote:
Implement a weak default version of flush_dcache_all which is based on the ARM default, which is to flush the entire range via flush_dcache_range(...).
Signed-off-by: Tom Rini trini@konsulko.com
arch/powerpc/lib/cache.c | 9 +++++++++ 1 file changed, 9 insertions(+)
diff --git a/arch/powerpc/lib/cache.c b/arch/powerpc/lib/cache.c index e480b2696494..130318d745aa 100644 --- a/arch/powerpc/lib/cache.c +++ b/arch/powerpc/lib/cache.c @@ -43,3 +43,12 @@ void flush_cache(ulong start_addr, ulong size) /* flush prefetch queue */ asm volatile("isync" : : : "memory"); }
+/*
- Default implementation:
- do a range flush for the entire range
- */
+void flush_dcache_all(void) +{
flush_dcache_range(0, ~0);
+}
2.34.1
Acked-by: Ilias Apalodimas ilias.apalodimas@linaro.org

Add the old invalidate_icache_all function that prints a warning that was previously found in cmd/cache.c
Signed-off-by: Tom Rini trini@konsulko.com --- arch/powerpc/lib/cache.c | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/arch/powerpc/lib/cache.c b/arch/powerpc/lib/cache.c index 130318d745aa..a9cd7b8d30ac 100644 --- a/arch/powerpc/lib/cache.c +++ b/arch/powerpc/lib/cache.c @@ -5,6 +5,7 @@ */
#include <cpu_func.h> +#include <stdio.h> #include <asm/cache.h> #include <watchdog.h>
@@ -52,3 +53,8 @@ void flush_dcache_all(void) { flush_dcache_range(0, ~0); } + +void invalidate_icache_all(void) +{ + puts("No arch specific invalidate_icache_all available!\n"); +}

It should be up to an architecture to decide how to implement cache functions, and if they need to use weak functions or not. Allowing the cache command to be built without cache functionality implemented is unhelpful. Further, guard the call to noncached_set_region with CONFIG_SYS_NONCACHED_MEMORY as that's when it's implemented and again is an architecture specific detail.
Signed-off-by: Tom Rini trini@konsulko.com --- This patch series is intended to replace https://patchwork.ozlabs.org/project/uboot/patch/20240616173105.7430-2-heinr... --- cmd/cache.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-)
diff --git a/cmd/cache.c b/cmd/cache.c index 0254ff17f9b2..7a2068296ef1 100644 --- a/cmd/cache.c +++ b/cmd/cache.c @@ -13,16 +13,6 @@
static int parse_argv(const char *);
-void __weak invalidate_icache_all(void) -{ - /* please define arch specific invalidate_icache_all */ - puts("No arch specific invalidate_icache_all available!\n"); -} - -__weak void noncached_set_region(void) -{ -} - static int do_icache(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { @@ -52,12 +42,6 @@ static int do_icache(struct cmd_tbl *cmdtp, int flag, int argc, return 0; }
-void __weak flush_dcache_all(void) -{ - puts("No arch specific flush_dcache_all available!\n"); - /* please define arch specific flush_dcache_all */ -} - static int do_dcache(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { @@ -69,7 +53,9 @@ static int do_dcache(struct cmd_tbl *cmdtp, int flag, int argc, break; case 1: dcache_enable(); +#ifdef CONFIG_SYS_NONCACHED_MEMORY noncached_set_region(); +#endif break; case 2: flush_dcache_all();

On Thu, 20 Jun 2024 at 00:28, Tom Rini trini@konsulko.com wrote:
It should be up to an architecture to decide how to implement cache functions, and if they need to use weak functions or not. Allowing the cache command to be built without cache functionality implemented is unhelpful. Further, guard the call to noncached_set_region with CONFIG_SYS_NONCACHED_MEMORY as that's when it's implemented and again is an architecture specific detail.
Signed-off-by: Tom Rini trini@konsulko.com
This patch series is intended to replace https://patchwork.ozlabs.org/project/uboot/patch/20240616173105.7430-2-heinr...
cmd/cache.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-)
diff --git a/cmd/cache.c b/cmd/cache.c index 0254ff17f9b2..7a2068296ef1 100644 --- a/cmd/cache.c +++ b/cmd/cache.c @@ -13,16 +13,6 @@
static int parse_argv(const char *);
-void __weak invalidate_icache_all(void) -{
/* please define arch specific invalidate_icache_all */
puts("No arch specific invalidate_icache_all available!\n");
-}
-__weak void noncached_set_region(void) -{ -}
static int do_icache(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { @@ -52,12 +42,6 @@ static int do_icache(struct cmd_tbl *cmdtp, int flag, int argc, return 0; }
-void __weak flush_dcache_all(void) -{
puts("No arch specific flush_dcache_all available!\n");
/* please define arch specific flush_dcache_all */
-}
static int do_dcache(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { @@ -69,7 +53,9 @@ static int do_dcache(struct cmd_tbl *cmdtp, int flag, int argc, break; case 1: dcache_enable(); +#ifdef CONFIG_SYS_NONCACHED_MEMORY noncached_set_region(); +#endif break; case 2: flush_dcache_all(); -- 2.34.1
Reviewed-by: Ilias Apalodimas ilias.apalodimas@linaro.org

Hi Tom,
Acked-by: Angelo Dureghello angelo@kernel-space.org
thanks, angelo
On 19/06/24 11:27 PM, Tom Rini wrote:
Implement a weak default version of flush_dcache_all which is based on the ARM default, which is to flush the entire range via flush_dcache_range(...).
Signed-off-by: Tom Rini trini@konsulko.com
Cc: Huan Wang alison.wang@nxp.com Cc: Angelo Dureghello angelo@kernel-space.org
arch/m68k/lib/cache.c | 9 +++++++++ 1 file changed, 9 insertions(+)
diff --git a/arch/m68k/lib/cache.c b/arch/m68k/lib/cache.c index de04124404cf..dab834c1cbd8 100644 --- a/arch/m68k/lib/cache.c +++ b/arch/m68k/lib/cache.c @@ -134,6 +134,15 @@ void dcache_invalid(void) #endif }
+/*
- Default implementation:
- do a range flush for the entire range
- */
+__weak void flush_dcache_all(void) +{
- flush_dcache_range(0, ~0);
+}
- __weak void invalidate_dcache_range(unsigned long start, unsigned long stop) { /* An empty stub, real implementation should be in platform code */

On Thu, 20 Jun 2024 at 00:28, Tom Rini trini@konsulko.com wrote:
Implement a weak default version of flush_dcache_all which is based on the ARM default, which is to flush the entire range via flush_dcache_range(...).
Signed-off-by: Tom Rini trini@konsulko.com
Cc: Huan Wang alison.wang@nxp.com Cc: Angelo Dureghello angelo@kernel-space.org
arch/m68k/lib/cache.c | 9 +++++++++ 1 file changed, 9 insertions(+)
diff --git a/arch/m68k/lib/cache.c b/arch/m68k/lib/cache.c index de04124404cf..dab834c1cbd8 100644 --- a/arch/m68k/lib/cache.c +++ b/arch/m68k/lib/cache.c @@ -134,6 +134,15 @@ void dcache_invalid(void) #endif }
+/*
- Default implementation:
- do a range flush for the entire range
- */
+__weak void flush_dcache_all(void) +{
flush_dcache_range(0, ~0);
+}
__weak void invalidate_dcache_range(unsigned long start, unsigned long stop) { /* An empty stub, real implementation should be in platform code */ -- 2.34.1
Acked-by: Ilias Apalodimas ilias.apalodimas@linaro.org
participants (4)
-
Angelo Dureghello
-
Ilias Apalodimas
-
Marek Vasut
-
Tom Rini