Skip to content

Commit f203b65

Browse files
committed
arch/xtensa: Clean up MMU initialization
We were trying to initialize the MMU extremely early (out of crt1.S), which was forcing some odd gymnastics with splitting up the initialization paths. Just don't do that. The MMU boots with a pefectly good mapping for physical memory. Use that until we're set up and about to launch the post-arch initialization in z_cstart(). Just in general, trying to run compiled C code before z_cstart() calls kernel_arch_init() is asking for trouble. We do it only in extreme situations, and we don't need it here. Signed-off-by: Andy Ross <andyross@google.com>
1 parent f71b91a commit f203b65

File tree

3 files changed

+9
-36
lines changed

3 files changed

+9
-36
lines changed

arch/xtensa/core/crt1.S

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@
2525
.type z_cstart, @function
2626
.type z_mp_entry, @function
2727

28-
#ifdef CONFIG_XTENSA_MMU
29-
.type z_xtensa_mmu_init, @function
30-
#endif
31-
32-
3328
/* Macros to abstract away ABI differences */
3429

3530
#if __XTENSA_CALL0_ABI__
@@ -193,10 +188,6 @@ _start:
193188

194189
#endif /* !XCHAL_HAVE_BOOTLOADER */
195190

196-
#ifdef CONFIG_XTENSA_MMU
197-
CALL z_xtensa_mmu_init
198-
#endif
199-
200191
/* Enter C domain, never returns from here */
201192
CALL z_cstart
202193

arch/xtensa/core/ptables.c

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -215,24 +215,12 @@ static inline void xtensa_init_page_tables(void)
215215
PAGE_TABLE_ATTR | Z_XTENSA_MMU_W);
216216
}
217217

218-
/* Called out of pre-z_cstart init code on CPU 0 */
218+
/* Called out of arch_kernel_init() just after entry to z_cstart() */
219219
void z_xtensa_mmu_init(void)
220220
{
221-
/* This is normally done via arch_kernel_init() inside z_cstart().
222-
* However, before that is called, we go through the sys_init of
223-
* INIT_LEVEL_EARLY, which is going to result in TLB misses.
224-
* So setup whatever necessary so the exception handler can work
225-
* properly.
226-
*/
227-
z_xtensa_kernel_init();
228-
229-
xtensa_init_page_tables();
230-
xtensa_init_paging(l1_page_table);
231-
}
232-
233-
/* Called out of early init code on CPU 1+ */
234-
void z_xtensa_mmu_smp_init(void)
235-
{
221+
if (_current_cpu->id == 0) {
222+
xtensa_init_page_tables();
223+
}
236224
xtensa_init_paging(l1_page_table);
237225
}
238226

arch/xtensa/include/kernel_arch_func.h

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extern void z_xtensa_fatal_error(unsigned int reason, const z_arch_esf_t *esf);
2525
K_KERNEL_STACK_ARRAY_DECLARE(z_interrupt_stacks, CONFIG_MP_MAX_NUM_CPUS,
2626
CONFIG_ISR_STACK_SIZE);
2727

28-
static ALWAYS_INLINE void z_xtensa_kernel_init(void)
28+
static ALWAYS_INLINE void arch_kernel_init(void)
2929
{
3030
_cpu_t *cpu0 = &_kernel.cpus[0];
3131

@@ -51,21 +51,15 @@ static ALWAYS_INLINE void z_xtensa_kernel_init(void)
5151
* win.
5252
*/
5353
XTENSA_WSR(ZSR_CPU_STR, cpu0);
54-
}
55-
56-
static ALWAYS_INLINE void arch_kernel_init(void)
57-
{
58-
#ifndef CONFIG_XTENSA_MMU
59-
/* This is called in z_xtensa_mmu_init() before z_cstart()
60-
* so we do not need to call it again.
61-
*/
62-
z_xtensa_kernel_init();
63-
#endif
6454

6555
#ifdef CONFIG_INIT_STACKS
6656
memset(Z_KERNEL_STACK_BUFFER(z_interrupt_stacks[0]), 0xAA,
6757
K_KERNEL_STACK_SIZEOF(z_interrupt_stacks[0]));
6858
#endif
59+
60+
#ifdef CONFIG_XTENSA_MMU
61+
z_xtensa_mmu_init();
62+
#endif
6963
}
7064

7165
void xtensa_switch(void *switch_to, void **switched_from);

0 commit comments

Comments
 (0)