Skip to contentSkip to conversation

arm64: Update memcpy_{from, to}io() helpers

PATCH In review Patrick Delaunay 2 participants 5 messages Jul 19, 2021 – Jul 29, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover arm64: Update memcpy_{from, to}io() helpers

V2 of previous serie [1] sent by Patrice.

The compilation issues raised by Tom are solved [2].

[1] http://patchwork.ozlabs.org/project/uboot/list/?series=231203&state=*

[2] https://source.denx.de/u-boot/custodians/u-boot-stm/-/pipelines/8310

Changes in v2:
- NEW: solve conflicts when cpu_func.h is included

Patrice Chotard (1):
arm64: Update memcpy_{from, to}io() helpers

Patrick Delaunay (1):
arm: use the correct prototype for reset_cpu function

 arch/arm/cpu/armv8/cache_v8.c           | 10 ++++++++++
 arch/arm/include/asm/io.h               | 25 +++++++++++++++----------
 arch/arm/mach-mediatek/mt8183/init.c    |  2 +-
 board/congatec/cgtqmx8/cgtqmx8.c        |  2 +-
 board/hoperun/hihope-rzg2/hihope-rzg2.c |  2 +-
 board/silinux/ek874/ek874.c             |  2 +-
 include/cpu_func.h                      |  1 +
 7 files changed, 30 insertions(+), 14 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/2 arm: use the correct prototype for reset_cpu function

Align reset_cpu function with the next prototypes in sysreset.h or in cpu_func.h to solve compilation issue:

  void reset_cpu(void);

This patch solves the prototype conflict when cpu_func.h is included.

---

Changes in v2:
- NEW: solve conflicts when cpu_func.h is included

 arch/arm/mach-mediatek/mt8183/init.c    | 2 +-
 board/congatec/cgtqmx8/cgtqmx8.c        | 2 +-
 board/hoperun/hihope-rzg2/hihope-rzg2.c | 2 +-
 board/silinux/ek874/ek874.c             | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
arch/arm/mach-mediatek/mt8183/init.c +1 -1
index 877f387102..7496029705 100644
@@ -48,7 +48,7 @@ int mtk_soc_early_init(void)
 	return 0;
 }
 
-void reset_cpu(ulong addr)
+void reset_cpu(void)
 {
 	psci_system_reset();
 }
board/congatec/cgtqmx8/cgtqmx8.c +1 -1
index fb0cf09138..a50a052df7 100644
@@ -374,7 +374,7 @@ void detail_board_ddr_info(void)
 /*
  * Board specific reset that is system reset.
  */
-void reset_cpu(ulong addr)
+void reset_cpu(void)
 {
 	/* TODO */
 }
board/hoperun/hihope-rzg2/hihope-rzg2.c +1 -1
index c1bfdcbc1d..c1db387b27 100644
@@ -65,7 +65,7 @@ int board_init(void)
 	return 0;
 }
 
-void reset_cpu(ulong addr)
+void reset_cpu(void)
 {
 	unsigned long midr, cputype;
 
board/silinux/ek874/ek874.c +1 -1
index 5a219cd98d..1e948489f3 100644
@@ -24,7 +24,7 @@ int board_init(void)
 	return 0;
 }
 
-void reset_cpu(ulong addr)
+void reset_cpu(void)
 {
 	writel(RST_CA53_CODE, RST_CA53RESCNT);
 }
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH v2 1/2] arm: use the correct prototype for reset_cpu function

Quoted 9 lines · Patrick Delaunay

Align reset_cpu function with the next prototypes in sysreset.h or in cpu_func.h to solve compilation issue:

  void reset_cpu(void);

This patch solves the prototype conflict when cpu_func.h is included.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#3 lore raw

PATCH v2 2/2 arm64: Update memcpy_{from, to}io() helpers

In reply to Patrick Delaunay

From: Patrice Chotard <[email protected]>

At early U-Boot stage, before relocation, MMU is not yet configured and disabled. DDR may not be configured with the correct memory attributes (can be configured in MT_DEVICE instead of MT_MEMORY).

In this case, usage of memcpy_{from, to}io() may leads to synchronous abort in AARCH64 in case the normal memory address is not 64Bits aligned.

To avoid such situation, forbid usage of normal memory cast to (u64 *) in case MMU is not enabled.

---

(no changes since v1)

 arch/arm/cpu/armv8/cache_v8.c | 10 ++++++++++
 arch/arm/include/asm/io.h     | 25 +++++++++++++++----------
 include/cpu_func.h            |  1 +
 3 files changed, 26 insertions(+), 10 deletions(-)
arch/arm/cpu/armv8/cache_v8.c +10 -0
index 15cecb5e0b..3de18c7675 100644
@@ -719,6 +719,11 @@ int icache_status(void)
 	return (get_sctlr() & CR_I) != 0;
 }
 
+int mmu_status(void)
+{
+	return (get_sctlr() & CR_M) != 0;
+}
+
 void invalidate_icache_all(void)
 {
 	__asm_invalidate_icache_all();
@@ -740,6 +745,11 @@ int icache_status(void)
 	return 0;
 }
 
+int mmu_status(void)
+{
+	return 0;
+}
+
 void invalidate_icache_all(void)
 {
 }
arch/arm/include/asm/io.h +15 -10
index df264a170b..36b840378a 100644
@@ -338,6 +338,7 @@ extern void __readwrite_bug(const char *fn);
 
 /* Optimized copy functions to read from/write to IO sapce */
 #ifdef CONFIG_ARM64
+#include <cpu_func.h>
 /*
  * Copy data from IO memory space to "real" memory space.
  */
@@ -351,11 +352,13 @@ void __memcpy_fromio(void *to, const volatile void __iomem *from, size_t count)
 		count--;
 	}
 
-	while (count >= 8) {
-		*(u64 *)to = __raw_readq(from);
-		from += 8;
-		to += 8;
-		count -= 8;
+	if (mmu_status()) {
+		while (count >= 8) {
+			*(u64 *)to = __raw_readq(from);
+			from += 8;
+			to += 8;
+			count -= 8;
+		}
 	}
 
 	while (count) {
@@ -379,11 +382,13 @@ void __memcpy_toio(volatile void __iomem *to, const void *from, size_t count)
 		count--;
 	}
 
-	while (count >= 8) {
-		__raw_writeq(*(u64 *)from, to);
-		from += 8;
-		to += 8;
-		count -= 8;
+	if (mmu_status()) {
+		while (count >= 8) {
+			__raw_writeq(*(u64 *)from, to);
+			from += 8;
+			to += 8;
+			count -= 8;
+		}
 	}
 
 	while (count) {
include/cpu_func.h +1 -0
index c3a66f0405..23cd5eca39 100644
@@ -59,6 +59,7 @@ int dcache_status(void);
 void dcache_enable(void);
 void dcache_disable(void);
 void mmu_disable(void);
+int mmu_status(void);
 
 /* arch/$(ARCH)/lib/cache.c */
 void enable_caches(void);
Signature · 1 line
2.25.1
#4 lore raw
Quoted 9 lines · Patrick Delaunay

From: Patrice Chotard <[email protected]>

At early U-Boot stage, before relocation, MMU is not yet configured and disabled. DDR may not be configured with the correct memory attributes (can be configured in MT_DEVICE instead of MT_MEMORY).

In this case, usage of memcpy_{from, to}io() may leads to synchronous abort in AARCH64 in case the normal memory address is not 64Bits aligned.

Quoted 7 lines

To avoid such situation, forbid usage of normal memory cast to (u64 *) in case MMU is not enabled.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom