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>
This commit is contained in:
parent
cc0796ab86
commit
de347a4e07
18 changed files with 99 additions and 4 deletions
|
@ -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)
|
|||
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;
|
||||
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
|
||||
#include <v2/irq.h>
|
||||
|
||||
#include <zephyr/platform/hooks.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -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 */
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
|||
*/
|
||||
#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();
|
||||
|
|
|
@ -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" {
|
|||
|
||||
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
|
||||
|
|
|
@ -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)
|
|||
*/
|
||||
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
|
||||
|
|
|
@ -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)
|
|||
#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();
|
||||
|
|
|
@ -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)
|
|||
#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)
|
||||
|
|
|
@ -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" {
|
|||
#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
|
||||
|
|
|
@ -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" {
|
|||
|
||||
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
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
|
||||
#include <kernel_arch_data.h>
|
||||
|
||||
#include <zephyr/platform/hooks.h>
|
||||
|
||||
#ifndef _ASMLANGUAGE
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -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
|
||||
|
|
|
@ -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)
|
|||
/* 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);
|
||||
}
|
||||
|
|
|
@ -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)
|
|||
#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
|
||||
|
|
|
@ -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" {
|
|||
#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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
|||
|
||||
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);
|
||||
|
|
|
@ -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,
|
|||
|
||||
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);
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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…
Add table
Add a link
Reference in a new issue