Browse Source

init: support per-core init hook

Allow SoC to implement their custom per-core initialization function by
selecting `CONFIG_SOC_PER_CORE_INIT_HOOK` and implement
`soc_per_core_init_hook()`.

Signed-off-by: Maxim Adelman <imax@meta.com>
Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
pull/81485/head
Yong Cong Sin 8 months ago committed by Anas Nashif
parent
commit
de347a4e07
  1. 6
      arch/arc/core/smp.c
  2. 6
      arch/arc/include/kernel_arch_func.h
  3. 5
      arch/arm/core/cortex_a_r/smp.c
  4. 5
      arch/arm/include/cortex_a_r/kernel_arch_func.h
  5. 6
      arch/arm/include/cortex_m/kernel_arch_func.h
  6. 5
      arch/arm64/core/smp.c
  7. 6
      arch/arm64/include/kernel_arch_func.h
  8. 5
      arch/mips/include/kernel_arch_func.h
  9. 5
      arch/nios2/include/kernel_arch_func.h
  10. 6
      arch/posix/include/kernel_arch_func.h
  11. 4
      arch/riscv/core/smp.c
  12. 5
      arch/riscv/include/kernel_arch_func.h
  13. 5
      arch/sparc/include/kernel_arch_func.h
  14. 6
      arch/x86/include/ia32/kernel_arch_func.h
  15. 6
      arch/x86/include/intel64/kernel_arch_func.h
  16. 5
      arch/xtensa/include/kernel_arch_func.h
  17. 8
      include/zephyr/platform/hooks.h
  18. 9
      kernel/Kconfig.init

6
arch/arc/core/smp.c

@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
#include <ipi.h>
#include <zephyr/init.h>
#include <zephyr/irq.h>
#include <zephyr/platform/hooks.h>
#include <arc_irq_offload.h>
volatile struct {
@ -115,6 +116,11 @@ void arch_secondary_cpu_init(int cpu_num) @@ -115,6 +116,11 @@ void arch_secondary_cpu_init(int cpu_num)
DT_IRQ(DT_NODELABEL(ici), priority), 0);
irq_enable(DT_IRQN(DT_NODELABEL(ici)));
#endif
#ifdef CONFIG_SOC_PER_CORE_INIT_HOOK
soc_per_core_init_hook();
#endif /* CONFIG_SOC_PER_CORE_INIT_HOOK */
/* call the function set by arch_cpu_start */
fn = arc_cpu_init[cpu_num].fn;

6
arch/arc/include/kernel_arch_func.h

@ -26,6 +26,8 @@ @@ -26,6 +26,8 @@
#include <v2/irq.h>
#include <zephyr/platform/hooks.h>
#ifdef __cplusplus
extern "C" {
#endif
@ -33,6 +35,10 @@ extern "C" { @@ -33,6 +35,10 @@ extern "C" {
static ALWAYS_INLINE void arch_kernel_init(void)
{
z_irq_setup();
#ifdef CONFIG_SOC_PER_CORE_INIT_HOOK
soc_per_core_init_hook();
#endif /* CONFIG_SOC_PER_CORE_INIT_HOOK */
}

5
arch/arm/core/cortex_a_r/smp.c

@ -12,6 +12,7 @@ @@ -12,6 +12,7 @@
#include "zephyr/cache.h"
#include "zephyr/kernel/thread_stack.h"
#include "zephyr/toolchain/gcc.h"
#include <zephyr/platform/hooks.h>
#define INV_MPID UINT32_MAX
@ -198,6 +199,10 @@ void arch_secondary_cpu_init(void) @@ -198,6 +199,10 @@ void arch_secondary_cpu_init(void)
*/
#endif
#ifdef CONFIG_SOC_PER_CORE_INIT_HOOK
soc_per_core_init_hook();
#endif /* CONFIG_SOC_PER_CORE_INIT_HOOK */
fn = arm_cpu_boot_params.fn;
arg = arm_cpu_boot_params.arg;
barrier_dsync_fence_full();

5
arch/arm/include/cortex_a_r/kernel_arch_func.h

@ -20,6 +20,8 @@ @@ -20,6 +20,8 @@
#ifndef ZEPHYR_ARCH_ARM_INCLUDE_CORTEX_A_R_KERNEL_ARCH_FUNC_H_
#define ZEPHYR_ARCH_ARM_INCLUDE_CORTEX_A_R_KERNEL_ARCH_FUNC_H_
#include <zephyr/platform/hooks.h>
#ifdef __cplusplus
extern "C" {
#endif
@ -28,6 +30,9 @@ extern "C" { @@ -28,6 +30,9 @@ extern "C" {
static ALWAYS_INLINE void arch_kernel_init(void)
{
#ifdef CONFIG_SOC_PER_CORE_INIT_HOOK
soc_per_core_init_hook();
#endif /* CONFIG_SOC_PER_CORE_INIT_HOOK */
}
#ifndef CONFIG_USE_SWITCH

6
arch/arm/include/cortex_m/kernel_arch_func.h

@ -20,6 +20,8 @@ @@ -20,6 +20,8 @@
#ifndef ZEPHYR_ARCH_ARM_INCLUDE_CORTEX_M_KERNEL_ARCH_FUNC_H_
#define ZEPHYR_ARCH_ARM_INCLUDE_CORTEX_M_KERNEL_ARCH_FUNC_H_
#include <zephyr/platform/hooks.h>
#ifdef __cplusplus
extern "C" {
#endif
@ -53,6 +55,10 @@ static ALWAYS_INLINE void arch_kernel_init(void) @@ -53,6 +55,10 @@ static ALWAYS_INLINE void arch_kernel_init(void)
*/
z_arm_configure_static_mpu_regions();
#endif /* CONFIG_ARM_MPU */
#ifdef CONFIG_SOC_PER_CORE_INIT_HOOK
soc_per_core_init_hook();
#endif /* CONFIG_SOC_PER_CORE_INIT_HOOK */
}
static ALWAYS_INLINE void

5
arch/arm64/core/smp.c

@ -23,6 +23,7 @@ @@ -23,6 +23,7 @@
#include <zephyr/drivers/interrupt_controller/gic.h>
#include <zephyr/drivers/pm_cpu_ops.h>
#include <zephyr/arch/arch_interface.h>
#include <zephyr/platform/hooks.h>
#include <zephyr/sys/barrier.h>
#include <zephyr/irq.h>
#include "boot.h"
@ -163,6 +164,10 @@ void arch_secondary_cpu_init(int cpu_num) @@ -163,6 +164,10 @@ void arch_secondary_cpu_init(int cpu_num)
#endif
#endif
#ifdef CONFIG_SOC_PER_CORE_INIT_HOOK
soc_per_core_init_hook();
#endif /* CONFIG_SOC_PER_CORE_INIT_HOOK */
fn = arm64_cpu_boot_params.fn;
arg = arm64_cpu_boot_params.arg;
barrier_dsync_fence_full();

6
arch/arm64/include/kernel_arch_func.h

@ -22,6 +22,8 @@ @@ -22,6 +22,8 @@
#include <kernel_arch_data.h>
#include <zephyr/platform/hooks.h>
#ifdef __cplusplus
extern "C" {
#endif
@ -35,6 +37,10 @@ static ALWAYS_INLINE void arch_kernel_init(void) @@ -35,6 +37,10 @@ static ALWAYS_INLINE void arch_kernel_init(void)
#ifdef CONFIG_XEN
xen_enlighten_init();
#endif
#ifdef CONFIG_SOC_PER_CORE_INIT_HOOK
soc_per_core_init_hook();
#endif /* CONFIG_SOC_PER_CORE_INIT_HOOK */
}
static inline void arch_switch(void *switch_to, void **switched_from)

5
arch/mips/include/kernel_arch_func.h

@ -19,6 +19,8 @@ @@ -19,6 +19,8 @@
#include <kernel_arch_data.h>
#include <zephyr/platform/hooks.h>
#ifdef __cplusplus
extern "C" {
#endif
@ -26,6 +28,9 @@ extern "C" { @@ -26,6 +28,9 @@ extern "C" {
#ifndef _ASMLANGUAGE
static ALWAYS_INLINE void arch_kernel_init(void)
{
#ifdef CONFIG_SOC_PER_CORE_INIT_HOOK
soc_per_core_init_hook();
#endif /* CONFIG_SOC_PER_CORE_INIT_HOOK */
}
static ALWAYS_INLINE void

5
arch/nios2/include/kernel_arch_func.h

@ -22,6 +22,8 @@ @@ -22,6 +22,8 @@
#include <kernel_arch_data.h>
#include <zephyr/platform/hooks.h>
#ifdef __cplusplus
extern "C" {
#endif
@ -30,6 +32,9 @@ extern "C" { @@ -30,6 +32,9 @@ extern "C" {
static ALWAYS_INLINE void arch_kernel_init(void)
{
#ifdef CONFIG_SOC_PER_CORE_INIT_HOOK
soc_per_core_init_hook();
#endif /* CONFIG_SOC_PER_CORE_INIT_HOOK */
}
static ALWAYS_INLINE void

6
arch/posix/include/kernel_arch_func.h

@ -12,6 +12,8 @@ @@ -12,6 +12,8 @@
#include <kernel_arch_data.h>
#include <zephyr/platform/hooks.h>
#ifndef _ASMLANGUAGE
#ifdef __cplusplus
@ -20,7 +22,9 @@ extern "C" { @@ -20,7 +22,9 @@ extern "C" {
static inline void arch_kernel_init(void)
{
/* Nothing to be done */
#ifdef CONFIG_SOC_PER_CORE_INIT_HOOK
soc_per_core_init_hook();
#endif /* CONFIG_SOC_PER_CORE_INIT_HOOK */
}
static ALWAYS_INLINE void

4
arch/riscv/core/smp.c

@ -11,6 +11,7 @@ @@ -11,6 +11,7 @@
#include <zephyr/sys/atomic.h>
#include <zephyr/arch/riscv/irq.h>
#include <zephyr/drivers/pm_cpu_ops.h>
#include <zephyr/platform/hooks.h>
volatile struct {
arch_cpustart_t fn;
@ -78,5 +79,8 @@ void arch_secondary_cpu_init(int hartid) @@ -78,5 +79,8 @@ void arch_secondary_cpu_init(int hartid)
/* Enable on secondary cores so that they can respond to PLIC */
irq_enable(RISCV_IRQ_MEXT);
#endif /* CONFIG_PLIC_IRQ_AFFINITY */
#ifdef CONFIG_SOC_PER_CORE_INIT_HOOK
soc_per_core_init_hook();
#endif /* CONFIG_SOC_PER_CORE_INIT_HOOK */
riscv_cpu_init[cpu_num].fn(riscv_cpu_init[cpu_num].arg);
}

5
arch/riscv/include/kernel_arch_func.h

@ -18,6 +18,8 @@ @@ -18,6 +18,8 @@
#include <kernel_arch_data.h>
#include <pmp.h>
#include <zephyr/platform/hooks.h>
#ifdef __cplusplus
extern "C" {
#endif
@ -53,6 +55,9 @@ static ALWAYS_INLINE void arch_kernel_init(void) @@ -53,6 +55,9 @@ static ALWAYS_INLINE void arch_kernel_init(void)
#ifdef CONFIG_RISCV_PMP
z_riscv_pmp_init();
#endif
#ifdef CONFIG_SOC_PER_CORE_INIT_HOOK
soc_per_core_init_hook();
#endif /* CONFIG_SOC_PER_CORE_INIT_HOOK */
}
static ALWAYS_INLINE void

5
arch/sparc/include/kernel_arch_func.h

@ -17,6 +17,8 @@ @@ -17,6 +17,8 @@
#include <kernel_arch_data.h>
#include <zephyr/platform/hooks.h>
#ifdef __cplusplus
extern "C" {
#endif
@ -24,6 +26,9 @@ extern "C" { @@ -24,6 +26,9 @@ extern "C" {
#ifndef _ASMLANGUAGE
static ALWAYS_INLINE void arch_kernel_init(void)
{
#ifdef CONFIG_SOC_PER_CORE_INIT_HOOK
soc_per_core_init_hook();
#endif /* CONFIG_SOC_PER_CORE_INIT_HOOK */
}
void z_sparc_context_switch(struct k_thread *newt, struct k_thread *oldt);

6
arch/x86/include/ia32/kernel_arch_func.h

@ -14,13 +14,17 @@ @@ -14,13 +14,17 @@
#include <stddef.h> /* For size_t */
#include <zephyr/platform/hooks.h>
#ifdef __cplusplus
extern "C" {
#endif
static inline void arch_kernel_init(void)
{
/* No-op on this arch */
#ifdef CONFIG_SOC_PER_CORE_INIT_HOOK
soc_per_core_init_hook();
#endif /* CONFIG_SOC_PER_CORE_INIT_HOOK */
}
static ALWAYS_INLINE void

6
arch/x86/include/intel64/kernel_arch_func.h

@ -8,6 +8,8 @@ @@ -8,6 +8,8 @@
#include <zephyr/kernel_structs.h>
#include <zephyr/platform/hooks.h>
#ifndef _ASMLANGUAGE
extern void z_x86_switch(void *switch_to, void **switched_from);
@ -27,7 +29,9 @@ extern void z_x86_ipi_setup(void); @@ -27,7 +29,9 @@ extern void z_x86_ipi_setup(void);
static inline void arch_kernel_init(void)
{
/* nothing */;
#ifdef CONFIG_SOC_PER_CORE_INIT_HOOK
soc_per_core_init_hook();
#endif /* CONFIG_SOC_PER_CORE_INIT_HOOK */
}
FUNC_NORETURN void z_x86_cpu_init(struct x86_cpuboot *cpuboot);

5
arch/xtensa/include/kernel_arch_func.h

@ -14,6 +14,7 @@ @@ -14,6 +14,7 @@
#include <kernel_internal.h>
#include <string.h>
#include <zephyr/cache.h>
#include <zephyr/platform/hooks.h>
#include <zephyr/zsr.h>
#ifdef __cplusplus
@ -25,7 +26,9 @@ K_KERNEL_STACK_ARRAY_DECLARE(z_interrupt_stacks, CONFIG_MP_MAX_NUM_CPUS, @@ -25,7 +26,9 @@ K_KERNEL_STACK_ARRAY_DECLARE(z_interrupt_stacks, CONFIG_MP_MAX_NUM_CPUS,
static ALWAYS_INLINE void arch_kernel_init(void)
{
#ifdef CONFIG_SOC_PER_CORE_INIT_HOOK
soc_per_core_init_hook();
#endif /* CONFIG_SOC_PER_CORE_INIT_HOOK */
}
void xtensa_switch(void *switch_to, void **switched_from);

8
include/zephyr/platform/hooks.h

@ -53,6 +53,14 @@ void soc_early_init_hook(void); @@ -53,6 +53,14 @@ void soc_early_init_hook(void);
*/
void soc_late_init_hook(void);
/**
* @brief SoC per-core initialization
*
* This hook is implemented by the SoC and can be used to perform any
* SoC-specific per-core initialization
*/
void soc_per_core_init_hook(void);
/*
* @brief Board hook executed before the kernel starts.
*

9
kernel/Kconfig.init

@ -38,6 +38,15 @@ config SOC_LATE_INIT_HOOK @@ -38,6 +38,15 @@ config SOC_LATE_INIT_HOOK
A custom SoC hook soc_late_init_hook() is executed after the kernel and
devices are initialized
config SOC_PER_CORE_INIT_HOOK
bool "Run SoC per-core initialization hook"
help
Run an SoC initialization hook for every core
A custom SoC hook soc_per_core_init_hook() is executeds at the end of
arch_kernel_init() for the primary core, and at the end of arch_secondary_cpu_init()
for secondary cores.
config BOARD_EARLY_INIT_HOOK
bool "Run early board hook"
help

Loading…
Cancel
Save