From a594ca7c8f43fa6a31ef39eddc5f1d3d04282c49 Mon Sep 17 00:00:00 2001 From: Andrew Boie Date: Fri, 10 Jan 2020 12:51:38 -0800 Subject: [PATCH] kernel: cleanup and formally define CPU start fn The "key" parameter is legacy, remove it. Add a typedef for the expected function pointer type. Signed-off-by: Andrew Boie --- arch/arc/core/arc_smp.c | 8 ++++---- arch/x86/core/ia32/crt0.S | 1 - arch/x86/core/intel64/cpu.c | 4 ++-- arch/x86/core/intel64/locore.S | 2 +- arch/x86/core/prep_c.c | 7 +++++-- arch/x86/include/intel64/kernel_arch_data.h | 2 +- arch/x86/include/kernel_arch_func.h | 2 +- include/sys/arch_interface.h | 12 +++++++++--- kernel/smp.c | 2 +- soc/xtensa/esp32/esp32-mp.c | 6 +++--- tests/kernel/mp/src/main.c | 4 +--- 11 files changed, 28 insertions(+), 22 deletions(-) diff --git a/arch/arc/core/arc_smp.c b/arch/arc/core/arc_smp.c index 8a43bc39aad..0efcbad185a 100644 --- a/arch/arc/core/arc_smp.c +++ b/arch/arc/core/arc_smp.c @@ -24,7 +24,7 @@ #define ARCV2_ICI_IRQ_PRIORITY 1 volatile struct { - void (*fn)(int, void*); + arch_cpustart_t fn; void *arg; } arc_cpu_init[CONFIG_MP_NUM_CPUS]; @@ -46,7 +46,7 @@ volatile _cpu_t *_curr_cpu[CONFIG_MP_NUM_CPUS]; /* Called from Zephyr initialization */ void arch_start_cpu(int cpu_num, k_thread_stack_t *stack, int sz, - void (*fn)(int, void *), void *arg) + arch_cpustart_t fn, void *arg) { _curr_cpu[cpu_num] = &(_kernel.cpus[cpu_num]); arc_cpu_init[cpu_num].fn = fn; @@ -69,7 +69,7 @@ void arch_start_cpu(int cpu_num, k_thread_stack_t *stack, int sz, /* the C entry of slave cores */ void z_arc_slave_start(int cpu_num) { - void (*fn)(int, void*); + arch_cpustart_t fn; #ifdef CONFIG_SMP z_icache_setup(); @@ -82,7 +82,7 @@ void z_arc_slave_start(int cpu_num) /* call the function set by arch_start_cpu */ fn = arc_cpu_init[cpu_num].fn; - fn(cpu_num, arc_cpu_init[cpu_num].arg); + fn(arc_cpu_init[cpu_num].arg); } #ifdef CONFIG_SMP diff --git a/arch/x86/core/ia32/crt0.S b/arch/x86/core/ia32/crt0.S index 1f431489bfe..e611c884274 100644 --- a/arch/x86/core/ia32/crt0.S +++ b/arch/x86/core/ia32/crt0.S @@ -240,7 +240,6 @@ __csSet: #endif pushl %ebx /* pointer to multiboot info, or NULL */ - pushl %eax /* junk, unused argument */ call z_x86_prep_c /* enter kernel; never returns */ _x86_bss_zero: diff --git a/arch/x86/core/intel64/cpu.c b/arch/x86/core/intel64/cpu.c index cd268cff1ad..f960e9ee60f 100644 --- a/arch/x86/core/intel64/cpu.c +++ b/arch/x86/core/intel64/cpu.c @@ -94,11 +94,11 @@ struct x86_cpuboot x86_cpuboot[] = { /* * Send the INIT/STARTUP IPI sequence required to start up CPU 'cpu_num', which - * will enter the kernel at fn(---, arg), running on the specified stack. + * will enter the kernel at fn(arg), running on the specified stack. */ void arch_start_cpu(int cpu_num, k_thread_stack_t *stack, int sz, - void (*fn)(int key, void *data), void *arg) + arch_cpustart_t fn, void *arg) { u8_t vector = ((unsigned long) x86_ap_start) >> 12; u8_t apic_id = x86_cpu_loapics[cpu_num]; diff --git a/arch/x86/core/intel64/locore.S b/arch/x86/core/intel64/locore.S index fb340838eb1..fc5f2468be8 100644 --- a/arch/x86/core/intel64/locore.S +++ b/arch/x86/core/intel64/locore.S @@ -196,7 +196,7 @@ go64: movl %cr4, %eax /* enable PAE and SSE */ /* don't replace CALL with JMP; honor the ABI stack alignment! */ incl __x86_cpuboot_t_ready_OFFSET(%rbp) - movq __x86_cpuboot_t_arg_OFFSET(%rbp), %rsi + movq __x86_cpuboot_t_arg_OFFSET(%rbp), %rdi call *__x86_cpuboot_t_fn_OFFSET(%rbp) /* enter kernel; never return */ /* diff --git a/arch/x86/core/prep_c.c b/arch/x86/core/prep_c.c index ced015b3052..8501823ce63 100644 --- a/arch/x86/core/prep_c.c +++ b/arch/x86/core/prep_c.c @@ -11,9 +11,12 @@ extern FUNC_NORETURN void z_cstart(void); -FUNC_NORETURN void z_x86_prep_c(int unused, struct multiboot_info *info) +/* Early global initialization functions, C domain. This runs only on the first + * CPU for SMP systems. + */ +FUNC_NORETURN void z_x86_prep_c(void *arg) { - ARG_UNUSED(unused); + struct multiboot_info *info = arg; _kernel.cpus[0].nested = 0; _kernel.cpus[0].irq_stack = Z_THREAD_STACK_BUFFER(_interrupt_stack) + diff --git a/arch/x86/include/intel64/kernel_arch_data.h b/arch/x86/include/intel64/kernel_arch_data.h index 3fc27aa671f..bf8f7740a41 100644 --- a/arch/x86/include/intel64/kernel_arch_data.h +++ b/arch/x86/include/intel64/kernel_arch_data.h @@ -23,7 +23,7 @@ struct x86_cpuboot { u16_t tr; /* selector for task register */ struct x86_tss64 *gs_base; /* Base address for GS segment */ u64_t sp; /* initial stack pointer */ - void *fn; /* kernel entry function */ + arch_cpustart_t fn; /* kernel entry function */ void *arg; /* argument for above function */ #ifdef CONFIG_X86_MMU struct x86_page_tables *ptables; /* Runtime page tables to install */ diff --git a/arch/x86/include/kernel_arch_func.h b/arch/x86/include/kernel_arch_func.h index 3191e79d298..f05fc592273 100644 --- a/arch/x86/include/kernel_arch_func.h +++ b/arch/x86/include/kernel_arch_func.h @@ -36,7 +36,7 @@ extern K_THREAD_STACK_DEFINE(_interrupt_stack3, CONFIG_ISR_STACK_SIZE); struct multiboot_info; -extern FUNC_NORETURN void z_x86_prep_c(int dummy, struct multiboot_info *info); +extern FUNC_NORETURN void z_x86_prep_c(void *arg); #ifdef CONFIG_X86_VERY_EARLY_CONSOLE /* Setup ultra-minimal serial driver for printk() */ diff --git a/include/sys/arch_interface.h b/include/sys/arch_interface.h index f11f9f0eec1..b883c3b80ca 100644 --- a/include/sys/arch_interface.h +++ b/include/sys/arch_interface.h @@ -159,6 +159,13 @@ void arch_cpu_atomic_idle(unsigned int key); * @{ */ +/** + * Per-cpu entry function + * + * @param context parameter, implementation specific + */ +typedef FUNC_NORETURN void (*arch_cpustart_t)(void *data); + /** * @brief Start a numbered CPU on a MP-capable system * @@ -176,12 +183,11 @@ void arch_cpu_atomic_idle(unsigned int key); * @param cpu_num Integer number of the CPU * @param stack Stack memory for the CPU * @param sz Stack buffer size, in bytes - * @param fn Function to begin running on the CPU. First argument is - * an irq_unlock() key. + * @param fn Function to begin running on the CPU. * @param arg Untyped argument to be passed to "fn" */ void arch_start_cpu(int cpu_num, k_thread_stack_t *stack, int sz, - void (*fn)(int key, void *data), void *arg); + arch_cpustart_t fn, void *arg); /** @} */ diff --git a/kernel/smp.c b/kernel/smp.c index 8692d19c232..ed17fa5ac06 100644 --- a/kernel/smp.c +++ b/kernel/smp.c @@ -65,7 +65,7 @@ extern k_thread_stack_t _interrupt_stack2[]; extern k_thread_stack_t _interrupt_stack3[]; #if CONFIG_MP_NUM_CPUS > 1 -static void smp_init_top(int key, void *arg) +static FUNC_NORETURN void smp_init_top(void *arg) { atomic_t *start_flag = arg; diff --git a/soc/xtensa/esp32/esp32-mp.c b/soc/xtensa/esp32/esp32-mp.c index 1892b612de7..4eb89601f36 100644 --- a/soc/xtensa/esp32/esp32-mp.c +++ b/soc/xtensa/esp32/esp32-mp.c @@ -24,7 +24,7 @@ struct cpustart_rec { int cpu; - void (*fn)(int, void *); + arch_cpustart_t fn; char *stack_top; void *arg; int vecbase; @@ -93,7 +93,7 @@ static void appcpu_entry2(void) __asm__ volatile("wsr.MISC0 %0" : : "r"(cpu)); *start_rec->alive = 1; - start_rec->fn(ps, start_rec->arg); + start_rec->fn(start_rec->arg); } /* Defines a locally callable "function" named _stack-switch(). The @@ -191,7 +191,7 @@ static void appcpu_start(void) } void arch_start_cpu(int cpu_num, k_thread_stack_t *stack, int sz, - void (*fn)(int, void *), void *arg) + arch_cpustart_t fn, void *arg) { volatile struct cpustart_rec sr; int vb; diff --git a/tests/kernel/mp/src/main.c b/tests/kernel/mp/src/main.c index 96710f2c865..4cd50c5fc15 100644 --- a/tests/kernel/mp/src/main.c +++ b/tests/kernel/mp/src/main.c @@ -33,10 +33,8 @@ volatile int cpu_running; * @{ * @} */ -void cpu1_fn(int key, void *arg) +FUNC_NORETURN void cpu1_fn(void *arg) { - ARG_UNUSED(key); - zassert_true(arg == &cpu_arg && *(int *)arg == 12345, "wrong arg"); cpu_running = 1;