Skip to contentSkip to conversation

socfpga: Agilex5: Fix dcache usage in SPL and SMC mailbox flow

PATCH In review Boon Khai Ng 3 participants 8 messages Aug 14, 2025 – Aug 21, 2025

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

v2 cover socfpga: Agilex5: Fix dcache usage in SPL and SMC mailbox flow

Hi all,

Proposing the following fix to address data cache handling issues in the Agilex5 platform, particularly in the SPL build and SMC mailbox communication path. It ensures correctness in cache operations. Other than that, trying to resolve undefined symbol errors, and provides the necessary configuration to disable data cache in SPL where required.

Patch Summary:
[1/3] arch: arm: mach-socfpga: smc: Add dcache flushing and invalidation in smc_send_mailbox()

Ensures that the response buffer from the secure monitor call (SMC) is properly invalidated in cache to avoid stale data access.

Updates pointer arithmetic by replacing u64 with uintptr_t to improve portability and correctness.

[2/3] cache: Check dcache availability before calling cache functions

Adds a !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) check before calling dcache_status() and mmu_status() to avoid compilation failures when dcache is disabled.

[3/3] configs: agilex5: Enable config SPL_SYS_DCACHE_OFF

Disables SPL data cache explicitly via CONFIG_SPL_SYS_DCACHE_OFF to align with the above changes and prevent inconsistencies during early boot.

This patchset has been tested on Agilex5 and resolves the SPL build issues related to missing symbols, while also improving runtime robustness in SMC-based communication.

Let me know if there are any concerns or feedback. Thank you!

Changes from previous submitted patches:
v1:
Using weak function to resolve the compilation failed with undefined function when invoking cache related function.
https://patchwork.ozlabs.org/project/uboot/patch/
[email protected]/

Boon Khai Ng (3):
arch: arm: mach-socfpga: smc: Add dcache flushing and invalidation in
smc_send_mailbox()
cache: Check dcache availability before calling cache functions
configs: agilex5: Enable config SPL_SYS_DCACHE_OFF

 arch/arm/include/asm/io.h         | 28 ++++++++++++++++------------
 arch/arm/mach-socfpga/smc_api.c   |  1 +
 common/memsize.c                  |  5 ++++-
 configs/socfpga_agilex5_defconfig |  1 +
 4 files changed, 22 insertions(+), 13 deletions(-)
Signature · 1 line
2.35.3
#1 lore raw

PATCH v2 1/3 arch: arm: mach-socfpga: smc: Add dcache flushing and invalidation in smc_send_mailbox()

Adding the dcache flushing and invalidation in the smc_send_mailbox() At the same time replace the use of u64 with uintptr_t to ensure compatibility across different architectures and correct the pointer arithmetic for buffer end address calculation.

---
 arch/arm/mach-socfpga/smc_api.c | 1 +
 1 file changed, 1 insertion(+)
arch/arm/mach-socfpga/smc_api.c +1 -0
index b212a94b321..a531030f5be 100644
@@ -57,6 +57,7 @@ int smc_send_mailbox(u32 cmd, u32 len, u32 *arg, u8 urgent, u32 *resp_buf_len,
 			 resp, ARRAY_SIZE(resp));
 
 	if (ret == INTEL_SIP_SMC_STATUS_OK && resp_buf && resp_buf_len) {
+		invalidate_dcache_range((uintptr_t)resp_buf, (uintptr_t)(resp_buf + *resp_buf_len));
 		if (!resp[0])
 			*resp_buf_len = resp[1];
 	}
Signature · 1 line
2.35.3
Reviewed-by on v2 1/3
#2 lore raw

RE: [PATCH v2 1/3] arch: arm: mach-socfpga: smc: Add dcache flushing and invalidation in smc_send_mailbox()

Quoted 47 lines

-----Original Message-----
From: Ng, Boon Khai <[email protected]>
Sent: Thursday, August 14, 2025 11:18 AM
To: U-boot Openlist <[email protected]>
Cc: Tom Rini <[email protected]>; Simon Glass <[email protected]>; Marek Vasut <[email protected]>; Simon Goldschmidt <[email protected]>; Chee, Tien Fong <[email protected]>; Maniyam, Dinesh <[email protected]>; Yuslaimi, Alif Zakuan <[email protected]>; Lim, Jit Loon <[email protected]>; Ng, Boon Khai <[email protected]>; Kathpalia, Tanmay <[email protected]>; Ilias Apalodimas <[email protected]>; Jerome Forissier <[email protected]>; Rao, Mahesh <[email protected]>
Subject: [PATCH v2 1/3] arch: arm: mach-socfpga: smc: Add dcache flushing and invalidation in smc_send_mailbox()

Adding the dcache flushing and invalidation in the smc_send_mailbox() At the same time replace the use of u64 with uintptr_t to ensure compatibility across different architectures and correct the pointer arithmetic for buffer end address calculation.

---
 arch/arm/mach-socfpga/smc_api.c | 1 +
 1 file changed, 1 insertion(+)
arch/arm/mach- renamed from arch/arm/mach-socfpga/smc_api.c +0 -0

socfpga/smc_api.c index b212a94b321..a531030f5be 100644

arch/arm/mach-socfpga/smc_api.c +1 -0
@@ -57,6 +57,7 @@ int smc_send_mailbox(u32 cmd, u32 len, u32 *arg, u8
 urgent, u32 *resp_buf_len,
 			 resp, ARRAY_SIZE(resp));
 
 	if (ret == INTEL_SIP_SMC_STATUS_OK && resp_buf &&
 resp_buf_len) {
+		invalidate_dcache_range((uintptr_t)resp_buf,

(uintptr_t)(resp_buf +

arch/arm/mach-socfpga/smc_api.c +1 -1
+*resp_buf_len));
 		if (!resp[0])
 			*resp_buf_len = resp[1];
 	}
--
Quoted 1 line

2.35.3

Best regards,
Tien Fong

Reviewed-by on v2 1/3
#3 lore raw

RE: [PATCH v2 1/3] arch: arm: mach-socfpga: smc: Add dcache flushing and invalidation in smc_send_mailbox()

In reply to Boon Khai Ng
Quoted 47 lines

-----Original Message-----
From: Ng, Boon Khai <[email protected]>
Sent: Thursday, August 14, 2025 11:18 AM
To: U-boot Openlist <[email protected]>
Cc: Tom Rini <[email protected]>; Simon Glass <[email protected]>; Marek Vasut <[email protected]>; Simon Goldschmidt <[email protected]>; Chee, Tien Fong <[email protected]>; Maniyam, Dinesh <[email protected]>; Yuslaimi, Alif Zakuan <[email protected]>; Lim, Jit Loon <[email protected]>; Ng, Boon Khai <[email protected]>; Kathpalia, Tanmay <[email protected]>; Ilias Apalodimas <[email protected]>; Jerome Forissier <[email protected]>; Rao, Mahesh <[email protected]>
Subject: [PATCH v2 1/3] arch: arm: mach-socfpga: smc: Add dcache flushing and invalidation in smc_send_mailbox()

Adding the dcache flushing and invalidation in the smc_send_mailbox() At the same time replace the use of u64 with uintptr_t to ensure compatibility across different architectures and correct the pointer arithmetic for buffer end address calculation.

---
 arch/arm/mach-socfpga/smc_api.c | 1 +
 1 file changed, 1 insertion(+)
arch/arm/mach- renamed from arch/arm/mach-socfpga/smc_api.c +0 -0

socfpga/smc_api.c index b212a94b321..a531030f5be 100644

arch/arm/mach-socfpga/smc_api.c +1 -0
@@ -57,6 +57,7 @@ int smc_send_mailbox(u32 cmd, u32 len, u32 *arg, u8
 urgent, u32 *resp_buf_len,
 			 resp, ARRAY_SIZE(resp));
 
 	if (ret == INTEL_SIP_SMC_STATUS_OK && resp_buf &&
 resp_buf_len) {
+		invalidate_dcache_range((uintptr_t)resp_buf,

(uintptr_t)(resp_buf +

arch/arm/mach-socfpga/smc_api.c +1 -1
+*resp_buf_len));
 		if (!resp[0])
 			*resp_buf_len = resp[1];
 	}
--
Quoted 1 line

2.35.3

Best regards,
Tien Fong

#4 lore raw

PATCH v2 2/3 cache: Check dcache availability before calling cache functions

In reply to Boon Khai Ng

When the data cache (dcache) is disabled, calling related status functions can lead to compilation errors due to undefined references.

Adding a !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) check before invoking dcache_status() (used in common/memsize.c:get_ram_size()) and mmu_status() (from arch/arm/include/asm/io.h).

Without this check, builds with dcache disabled will fail to compile.

---
 arch/arm/include/asm/io.h | 28 ++++++++++++++++------------
 common/memsize.c          |  5 ++++-
 2 files changed, 20 insertions(+), 13 deletions(-)
arch/arm/include/asm/io.h +16 -12
index 85ec0e6937e..cebed7397d4 100644
@@ -386,12 +386,14 @@ void __memcpy_fromio(void *to, const volatile void __iomem *from, size_t count)
 		count--;
 	}
 
-	if (mmu_status()) {
-		while (count >= 8) {
-			*(u64 *)to = __raw_readq(from);
-			from += 8;
-			to += 8;
-			count -= 8;
+	if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF)) {
+		if (mmu_status()) {
+			while (count >= 8) {
+				*(u64 *)to = __raw_readq(from);
+				from += 8;
+				to += 8;
+				count -= 8;
+			}
 		}
 	}
 
@@ -416,12 +418,14 @@ void __memcpy_toio(volatile void __iomem *to, const void *from, size_t count)
 		count--;
 	}
 
-	if (mmu_status()) {
-		while (count >= 8) {
-			__raw_writeq(*(u64 *)from, to);
-			from += 8;
-			to += 8;
-			count -= 8;
+	if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF)) {
+		if (mmu_status()) {
+			while (count >= 8) {
+				__raw_writeq(*(u64 *)from, to);
+				from += 8;
+				to += 8;
+				count -= 8;
+			}
 		}
 	}
 
common/memsize.c +4 -1
index 86109579c95..3c3ae6f1eba 100644
@@ -52,7 +52,10 @@ long get_ram_size(long *base, long maxsize)
 	long           val;
 	long           size;
 	int            i = 0;
-	int            dcache_en = dcache_status();
+	int            dcache_en = 0;
+
+	if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
+		dcache_en = dcache_status();
 
 	for (cnt = (maxsize / sizeof(long)) >> 1; cnt > 0; cnt >>= 1) {
 		addr = base + cnt;	/* pointer arith! */
Signature · 1 line
2.35.3
Reviewed-by on v2 2/3
#5 lore raw

Re: [PATCH v2 2/3] cache: Check dcache availability before calling cache functions

Quoted 11 lines · Boon Khai Ng

When the data cache (dcache) is disabled, calling related status functions can lead to compilation errors due to undefined references.

Adding a !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) check before invoking dcache_status() (used in common/memsize.c:get_ram_size()) and mmu_status() (from arch/arm/include/asm/io.h).

Without this check, builds with dcache disabled will fail to compile.

Signature · 1 line
Tom
#6 lore raw

PATCH v2 3/3 configs: agilex5: Enable config SPL_SYS_DCACHE_OFF

In reply to Boon Khai Ng

Add SPL_SYS_DCACHE_OFF to Agilex5 defconfig to disable data cache for SPL

---
 configs/socfpga_agilex5_defconfig | 1 +
 1 file changed, 1 insertion(+)
configs/socfpga_agilex5_defconfig +1 -0
index 33a6221979a..8c31dcfea11 100644
@@ -45,6 +45,7 @@ CONFIG_SPL_HAS_CUSTOM_MALLOC_START=y
 CONFIG_SPL_CUSTOM_SYS_MALLOC_ADDR=0xbfa00000
 CONFIG_SPL_SYS_MALLOC_SIZE=0x500000
 CONFIG_SPL_CACHE=y
+CONFIG_SPL_SYS_DCACHE_OFF=y
 CONFIG_SPL_MTD=y
 CONFIG_SPL_SPI_FLASH_MTD=y
 CONFIG_SPL_SPI_LOAD=y
Signature · 1 line
2.35.3
Reviewed-by on v2 3/3
#7 lore raw

RE: [PATCH v2 3/3] configs: agilex5: Enable config SPL_SYS_DCACHE_OFF

Quoted 40 lines

-----Original Message-----
From: Ng, Boon Khai <[email protected]>
Sent: Thursday, August 14, 2025 11:18 AM
To: U-boot Openlist <[email protected]>
Cc: Tom Rini <[email protected]>; Simon Glass <[email protected]>; Marek Vasut <[email protected]>; Simon Goldschmidt <[email protected]>; Chee, Tien Fong <[email protected]>; Maniyam, Dinesh <[email protected]>; Yuslaimi, Alif Zakuan <[email protected]>; Lim, Jit Loon <[email protected]>; Ng, Boon Khai <[email protected]>; Kathpalia, Tanmay <[email protected]>; Ilias Apalodimas <[email protected]>; Jerome Forissier <[email protected]>; Rao, Mahesh <[email protected]>
Subject: [PATCH v2 3/3] configs: agilex5: Enable config SPL_SYS_DCACHE_OFF

Add SPL_SYS_DCACHE_OFF to Agilex5 defconfig to disable data cache for SPL

---
 configs/socfpga_agilex5_defconfig | 1 +
 1 file changed, 1 insertion(+)
configs/socfpga_agilex5_defconfig +1 -1
index 33a6221979a..8c31dcfea11 100644
@@ -45,6 +45,7 @@ CONFIG_SPL_HAS_CUSTOM_MALLOC_START=y
 CONFIG_SPL_CUSTOM_SYS_MALLOC_ADDR=0xbfa00000
 CONFIG_SPL_SYS_MALLOC_SIZE=0x500000
 CONFIG_SPL_CACHE=y
+CONFIG_SPL_SYS_DCACHE_OFF=y
 CONFIG_SPL_MTD=y
 CONFIG_SPL_SPI_FLASH_MTD=y
 CONFIG_SPL_SPI_LOAD=y
--
Quoted 1 line

2.35.3

Best regards,
Tien Fong