From fff91cb5425c75a0118a61fe69089a7fcfc3c0e4 Mon Sep 17 00:00:00 2001 From: Flavio Ceolin Date: Wed, 1 Nov 2023 22:55:43 -0700 Subject: [PATCH] xtensa: mmu: Simplify initialization Simplify the logic around xtensa_mmu_init. - Do not have a different path to init part of kernel - Call xtensa_mmu_init from C Signed-off-by: Flavio Ceolin --- arch/xtensa/core/crt1.S | 8 -------- arch/xtensa/core/xtensa_mmu.c | 17 +++-------------- arch/xtensa/include/kernel_arch_func.h | 16 +++++----------- include/zephyr/arch/xtensa/xtensa_mmu.h | 2 -- 4 files changed, 8 insertions(+), 35 deletions(-) diff --git a/arch/xtensa/core/crt1.S b/arch/xtensa/core/crt1.S index 0fa3ad23099..c616b0889d7 100644 --- a/arch/xtensa/core/crt1.S +++ b/arch/xtensa/core/crt1.S @@ -24,10 +24,6 @@ .global __start .type z_cstart, @function -#ifdef CONFIG_XTENSA_MMU -.type z_xtensa_mmu_init, @function -#endif - /* Macros to abstract away ABI differences */ @@ -192,10 +188,6 @@ _start: #endif /* !XCHAL_HAVE_BOOTLOADER */ -#ifdef CONFIG_XTENSA_MMU - CALL z_xtensa_mmu_init -#endif - /* Enter C domain, never returns from here */ CALL z_cstart diff --git a/arch/xtensa/core/xtensa_mmu.c b/arch/xtensa/core/xtensa_mmu.c index e50c51a3848..18ce5f22f63 100644 --- a/arch/xtensa/core/xtensa_mmu.c +++ b/arch/xtensa/core/xtensa_mmu.c @@ -213,19 +213,18 @@ __weak void arch_xtensa_mmu_post_init(bool is_core0) ARG_UNUSED(is_core0); } -static void xtensa_mmu_init(bool is_core0) +void z_xtensa_mmu_init(void) { volatile uint8_t entry; uint32_t ps, vecbase; - if (is_core0) { + if (_current_cpu->id == 0) { /* This is normally done via arch_kernel_init() inside z_cstart(). * However, before that is called, we go through the sys_init of * INIT_LEVEL_EARLY, which is going to result in TLB misses. * So setup whatever necessary so the exception handler can work * properly. */ - z_xtensa_kernel_init(); xtensa_init_page_tables(); } @@ -326,17 +325,7 @@ static void xtensa_mmu_init(bool is_core0) xtensa_dtlb_entry_invalidate_sync(Z_XTENSA_TLB_ENTRY(Z_XTENSA_PTEVADDR + MB(4), 3)); xtensa_itlb_entry_invalidate_sync(Z_XTENSA_TLB_ENTRY(Z_XTENSA_PTEVADDR + MB(4), 3)); - arch_xtensa_mmu_post_init(is_core0); -} - -void z_xtensa_mmu_init(void) -{ - xtensa_mmu_init(true); -} - -void z_xtensa_mmu_smp_init(void) -{ - xtensa_mmu_init(false); + arch_xtensa_mmu_post_init(_current_cpu->id == 0); } #ifdef CONFIG_ARCH_HAS_RESERVED_PAGE_FRAMES diff --git a/arch/xtensa/include/kernel_arch_func.h b/arch/xtensa/include/kernel_arch_func.h index 6427b306e62..2256f72f645 100644 --- a/arch/xtensa/include/kernel_arch_func.h +++ b/arch/xtensa/include/kernel_arch_func.h @@ -25,7 +25,7 @@ extern void z_xtensa_fatal_error(unsigned int reason, const z_arch_esf_t *esf); K_KERNEL_STACK_ARRAY_DECLARE(z_interrupt_stacks, CONFIG_MP_MAX_NUM_CPUS, CONFIG_ISR_STACK_SIZE); -static ALWAYS_INLINE void z_xtensa_kernel_init(void) +static ALWAYS_INLINE void arch_kernel_init(void) { _cpu_t *cpu0 = &_kernel.cpus[0]; @@ -51,21 +51,15 @@ static ALWAYS_INLINE void z_xtensa_kernel_init(void) * win. */ XTENSA_WSR(ZSR_CPU_STR, cpu0); -} - -static ALWAYS_INLINE void arch_kernel_init(void) -{ -#ifndef CONFIG_XTENSA_MMU - /* This is called in z_xtensa_mmu_init() before z_cstart() - * so we do not need to call it again. - */ - z_xtensa_kernel_init(); -#endif #ifdef CONFIG_INIT_STACKS memset(Z_KERNEL_STACK_BUFFER(z_interrupt_stacks[0]), 0xAA, K_KERNEL_STACK_SIZEOF(z_interrupt_stacks[0])); #endif + +#ifdef CONFIG_XTENSA_MMU + z_xtensa_mmu_init(); +#endif } void xtensa_switch(void *switch_to, void **switched_from); diff --git a/include/zephyr/arch/xtensa/xtensa_mmu.h b/include/zephyr/arch/xtensa/xtensa_mmu.h index d03f876af30..2ee3dc6c9ab 100644 --- a/include/zephyr/arch/xtensa/xtensa_mmu.h +++ b/include/zephyr/arch/xtensa/xtensa_mmu.h @@ -26,6 +26,4 @@ extern int xtensa_soc_mmu_ranges_num; void z_xtensa_mmu_init(void); -void z_xtensa_mmu_smp_init(void); - #endif /* ZEPHYR_INCLUDE_ARCH_XTENSA_XTENSA_MMU_H */