socfpga: Agilex5: Fix dcache usage in SPL and SMC mailbox flow
Subsystems (3)
cover socfpga: Agilex5: Fix dcache usage in SPL and SMC mailbox flow
Hi all,
Proposing the following fix to address data cache handling issues and missing weak functions in the Agilex5 platform, particularly in the SPL build and SMC mailbox communication path. It ensures correctness in cache operations, resolves 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] arch: arm: lib: cache_v8: agilex5: Add weak function in cache_v8
Adds weak implementations for dcache_disable, dcache_status, and mmu_status to prevent undefined symbol errors during SPL build when data cache is not enabled.
These stubs are used by other SPL components like QSPI driver logic.
[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!
Boon Khai Ng (3):
arch: arm: mach-socfpga: smc: Add dcache flushing and invalidation in
smc_send_mailbox()
arch: arm: lib: cache_v8: agilex5: Add weak function in cache_v8
configs: agilex5: Enable config SPL_SYS_DCACHE_OFF
arch/arm/lib/cache.c | 17 +++++++++++++++++ arch/arm/mach-socfpga/smc_api.c | 1 + configs/socfpga_agilex5_defconfig | 1 + 3 files changed, 19 insertions(+)
Signature · 1 line
2.35.3
PATCH 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
@@ -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
PATCH 2/3 arch: arm: lib: cache_v8: agilex5: Add weak function in cache_v8
In reply to Boon Khai NgAdd weak function dcache_disable for undefined symbol error when dcache for SPL is not enabled. The dcache_disable function is being called from spl_atf.c file
Add weak function dcache_status for undefined symbol error when dcache for SPL is not enabled. The dcache_status function is being called from common/memsize.c file "get_ram_size" function, which in-turn was called from "sdram_size_check" function defined in sdram_soc64.c file
Add weak function mmu_status for undefined symbol error when dcache for SPL is not enabled. The mmu_status function is being called from arch/arm/include/asm/io.h file "__memcpy_fromio" and "__memcpy_toio "functions, which in-turn was called from "cadence_qspi_apb_write_execute" and "cadence_qspi_apb_read_execute" functions defined in cadence_qspi_apb.c file
--- arch/arm/lib/cache.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
arch/arm/lib/cache.c +17 -0
@@ -42,6 +42,17 @@ __weak void enable_caches(void)puts ("WARNING: Caches not enabled\n" ); } +__weak void dcache_disable (void ) +{ +puts ("WARNING: Data cache not enabled\n" ); +} + +__weak int dcache_status (void ) +{ +debug ("WARNING: Data cache not enabled\n" ); +return 0 ; +} +__weak void invalidate_dcache_range (unsigned long start,unsigned long stop) {/* An empty stub, real implementation should be in platform code */
@@ -51,6 +62,12 @@ __weak void flush_dcache_range(unsigned long start, unsigned long stop)/* An empty stub, real implementation should be in platform code */ } +__weak int mmu_status (void ) +{ +puts ("WARNING: MMU not enabled\n" ); +return 0 ; +} +int check_cache_range (unsigned long start,unsigned long stop) {int ok =1 ;
Signature · 1 line
2.35.3
Re: [PATCH v1 2/3] arch: arm: lib: cache_v8: agilex5: Add weak function in cache_v8
Quoted 17 lines · Boon Khai Ng
Add weak function
dcache_disablefor undefined symbol error when dcache for SPL is not enabled. Thedcache_disablefunction is being called fromspl_atf.cfileAdd weak function
dcache_statusfor undefined symbol error when dcache for SPL is not enabled. Thedcache_statusfunction is being called fromcommon/memsize.cfile "get_ram_size" function, which in-turn was called from "sdram_size_check" function defined insdram_soc64.cfileAdd weak function
mmu_statusfor undefined symbol error when dcache for SPL is not enabled. Themmu_statusfunction is being called fromarch/arm/include/asm/io.hfile "__memcpy_fromio" and "__memcpy_toio"functions, which in-turn was called from "cadence_qspi_apb_write_execute" and "cadence_qspi_apb_read_execute" functions defined incadence_qspi_apb.cfile
Quoted 2 lines
Signed-off-by Tanmay Kathpalia <[email protected]>Signed-off-by Boon Khai Ng <[email protected]>
The callers of dcache_disable/etc should be doing:
if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
...
Signature · 1 line
Tom
RE: [PATCH v1 2/3] arch: arm: lib: cache_v8: agilex5: Add weak function in cache_v8
Quoted 2 lines
The callers of dcache_disable/etc should be doing:
if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
Hi Tom, just get to know that the spl_atf.c already implemented with the fix above, will follow the fix in spl_atf.c and submit in v2
https://github.com/u-boot/u-boot/blob/3526f990b
77fca1c933f1d8b24eb9385010a05bf/common/spl/spl_atf.c#L206
Thanks
Regards,
Boon Khai.
A message that is not in the archive (sent off-list or not yet received): SA3PR03MB71870FAC5AC6E398C2652C47B42AA@SA3PR03MB7187.namprd03.prod.outlook.com
Re: [PATCH v1 2/3] arch: arm: lib: cache_v8: agilex5: Add weak function in cache_v8
Quoted 23 lines · Boon Khai
Hi Tom,
Quoted 9 lines
Quoted 2 lines
The callers of dcache_disable/etc should be doing:
if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF))Hi Tom, just get to know that the
spl_atf.calready implemented with the fix above, will follow the fix inspl_atf.cand submit in v2https://github.com/u-boot/u-boot/blob/3526f990b
77fca1c933f1d8b24eb9385010a05bf/common/spl/spl_atf.c#L206After carefully analyzing the code, I noticed that after adding the if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF)) check and removing the weak function, U-Boot still fails to compile. This is because the config check has now shifted from being preprocessor-based to runtime-based.
Given this, I have two points I'd like to clarify:
1) Retaining the Weak Function: Since the weak function effectively resolves the compilation issue, would it be sufficient to retain just the weak function declaration?
Quoted 7 lines
2) Config Check Necessity: If the weak function alone solves the issue by preventing the compilation failure, would the addition of the runtime-based if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF)) check still be necessary?
I'd appreciate your thoughts on whether it would be acceptable to keep the weak function without the config check as a solution.
What does your patch and config look like that shows this problem? It's fine to have an undefined function when if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF)) becomes if (0) once evaluated.
Signature · 1 line
Tom
RE: [PATCH v1 2/3] arch: arm: lib: cache_v8: agilex5: Add weak function in cache_v8
Hi Tom,
Quoted 5 lines
What does your patch and config look like that shows this problem? It's fine to have an undefined function when if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF)) becomes if (0) once evaluated.
--
I apologies, it was my mistake, where I have a script compiling the wrong folder without both weak function, and (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF)) changes.
I'm preparing v2 patches, to include the (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF)) and remove the weak function.
Regards,
Boon Khai.
PATCH 3/3 configs: agilex5: Enable config SPL_SYS_DCACHE_OFF
In reply to Boon Khai NgAdd 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
@@ -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