This is an automated email from the ASF dual-hosted git repository. GUIDINGLI pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 708c9c799b41112388c02fdb2401282c8feaaa5b Author: hujun5 <[email protected]> AuthorDate: Fri Mar 13 19:00:28 2026 +0800 arch/arm64: disable dcache during MPU/MMU initialization Bracket MPU/MMU setup with up_disable_dcache/up_enable_dcache in both primary and secondary CPU boot paths to prevent stale cache entries from causing coherency issues during memory protection transitions. Remove SCTLR_C_BIT management from arm64_mpu_enable/disable and enable_mmu_el1/el3 so that dcache lifecycle is controlled exclusively by the caller rather than scattered across init helpers. Signed-off-by: hujun5 <[email protected]> --- arch/arm64/src/common/arm64_boot.c | 4 ++++ arch/arm64/src/common/arm64_cpustart.c | 4 ++++ arch/arm64/src/common/arm64_mmu.c | 12 ++---------- arch/arm64/src/common/arm64_mpu.c | 5 +---- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/arch/arm64/src/common/arm64_boot.c b/arch/arm64/src/common/arm64_boot.c index 5f5f1bad22b..7911e1ebd85 100644 --- a/arch/arm64/src/common/arm64_boot.c +++ b/arch/arm64/src/common/arm64_boot.c @@ -261,6 +261,10 @@ void arm64_boot_primary_c_routine(void) arm64_mte_init(); #endif +#ifndef CONFIG_ARM64_DCACHE_DISABLE + up_enable_dcache(); +#endif + #ifdef CONFIG_PERCPU_SECTION /* Copy the percpu data segment of cpu0 to the other CPUs. */ diff --git a/arch/arm64/src/common/arm64_cpustart.c b/arch/arm64/src/common/arm64_cpustart.c index 7b460ff24fa..11f5f58df49 100644 --- a/arch/arm64/src/common/arm64_cpustart.c +++ b/arch/arm64/src/common/arm64_cpustart.c @@ -239,6 +239,10 @@ void arm64_boot_secondary_c_routine(void) arm64_mmu_init(false); #endif +#ifndef CONFIG_ARM64_DCACHE_DISABLE + up_enable_dcache(); +#endif + /* We need to confirm that current_task has been initialized. */ while (!current_task(this_cpu())); diff --git a/arch/arm64/src/common/arm64_mmu.c b/arch/arm64/src/common/arm64_mmu.c index 53a123dc491..e0235e71549 100644 --- a/arch/arm64/src/common/arm64_mmu.c +++ b/arch/arm64/src/common/arm64_mmu.c @@ -623,11 +623,7 @@ static void enable_mmu_el3(unsigned int flags) /* Enable the MMU and data cache */ value = read_sysreg(sctlr_el3); - write_sysreg((value | SCTLR_M_BIT -#ifndef CONFIG_ARM64_DCACHE_DISABLE - | SCTLR_C_BIT -#endif - ), sctlr_el3); + write_sysreg((value | SCTLR_M_BIT), sctlr_el3); /* Ensure the MMU enable takes effect immediately */ @@ -656,11 +652,7 @@ static void enable_mmu_el1(unsigned int flags) /* Enable the MMU and data cache */ value = read_sysreg(sctlr_el1); - write_sysreg((value | SCTLR_M_BIT -#ifndef CONFIG_ARM64_DCACHE_DISABLE - | SCTLR_C_BIT -#endif - ), sctlr_el1); + write_sysreg((value | SCTLR_M_BIT), sctlr_el1); /* Ensure the MMU enable takes effect immediately */ diff --git a/arch/arm64/src/common/arm64_mpu.c b/arch/arm64/src/common/arm64_mpu.c index 752615059a2..d92b6649988 100644 --- a/arch/arm64/src/common/arm64_mpu.c +++ b/arch/arm64/src/common/arm64_mpu.c @@ -247,9 +247,6 @@ void arm64_mpu_enable(void) val = read_sysreg(sctlr_el1); val |= (SCTLR_M_BIT -#ifndef CONFIG_ARM64_DCACHE_DISABLE - | SCTLR_C_BIT -#endif | SCTLR_BR_BIT /* Background region enable */ ); write_sysreg(val, sctlr_el1); @@ -279,7 +276,7 @@ void arm64_mpu_disable(void) UP_DMB(); val = read_sysreg(sctlr_el1); - val &= ~(SCTLR_M_BIT | SCTLR_C_BIT); + val &= ~(SCTLR_M_BIT); write_sysreg(val, sctlr_el1); UP_MB(); }
