init: introduce soc and board hooks
Introduce soc and board hooks to replace arch specific code and replace usages of SYS_INIT for platform initialization. include/zephyr/platform/hooks.h introduces the hooks to be implemented by boards and SoCs. Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
parent
736289a691
commit
e260d03686
14 changed files with 179 additions and 0 deletions
|
@ -23,6 +23,7 @@
|
||||||
#include <zephyr/arch/arc/cluster.h>
|
#include <zephyr/arch/arc/cluster.h>
|
||||||
#include <zephyr/kernel_structs.h>
|
#include <zephyr/kernel_structs.h>
|
||||||
#include <kernel_internal.h>
|
#include <kernel_internal.h>
|
||||||
|
#include <zephyr/platform/hooks.h>
|
||||||
|
|
||||||
/* XXX - keep for future use in full-featured cache APIs */
|
/* XXX - keep for future use in full-featured cache APIs */
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -121,6 +122,10 @@ extern FUNC_NORETURN void z_cstart(void);
|
||||||
|
|
||||||
void z_prep_c(void)
|
void z_prep_c(void)
|
||||||
{
|
{
|
||||||
|
#if defined(CONFIG_SOC_PREP_HOOK)
|
||||||
|
soc_prep_hook();
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_ISA_ARCV3
|
#ifdef CONFIG_ISA_ARCV3
|
||||||
arc_cluster_scm_enable();
|
arc_cluster_scm_enable();
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include <zephyr/linker/linker-defs.h>
|
#include <zephyr/linker/linker-defs.h>
|
||||||
#include <zephyr/sys/barrier.h>
|
#include <zephyr/sys/barrier.h>
|
||||||
#include <zephyr/arch/arm/cortex_a_r/lib_helpers.h>
|
#include <zephyr/arch/arm/cortex_a_r/lib_helpers.h>
|
||||||
|
#include <zephyr/platform/hooks.h>
|
||||||
|
|
||||||
#if defined(CONFIG_ARMV7_R) || defined(CONFIG_ARMV7_A)
|
#if defined(CONFIG_ARMV7_R) || defined(CONFIG_ARMV7_A)
|
||||||
#include <cortex_a_r/stack.h>
|
#include <cortex_a_r/stack.h>
|
||||||
|
@ -147,6 +148,9 @@ extern FUNC_NORETURN void z_cstart(void);
|
||||||
*/
|
*/
|
||||||
void z_prep_c(void)
|
void z_prep_c(void)
|
||||||
{
|
{
|
||||||
|
#if defined(CONFIG_SOC_PREP_HOOK)
|
||||||
|
soc_prep_hook();
|
||||||
|
#endif
|
||||||
/* Initialize tpidruro with our struct _cpu instance address */
|
/* Initialize tpidruro with our struct _cpu instance address */
|
||||||
write_tpidruro((uintptr_t)&_kernel.cpus[0]);
|
write_tpidruro((uintptr_t)&_kernel.cpus[0]);
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include <kernel_internal.h>
|
#include <kernel_internal.h>
|
||||||
#include <zephyr/linker/linker-defs.h>
|
#include <zephyr/linker/linker-defs.h>
|
||||||
#include <zephyr/sys/barrier.h>
|
#include <zephyr/sys/barrier.h>
|
||||||
|
#include <zephyr/platform/hooks.h>
|
||||||
|
|
||||||
#if defined(__GNUC__)
|
#if defined(__GNUC__)
|
||||||
/*
|
/*
|
||||||
|
@ -181,6 +182,10 @@ extern FUNC_NORETURN void z_cstart(void);
|
||||||
*/
|
*/
|
||||||
void z_prep_c(void)
|
void z_prep_c(void)
|
||||||
{
|
{
|
||||||
|
#if defined(CONFIG_SOC_PREP_HOOK)
|
||||||
|
soc_prep_hook();
|
||||||
|
#endif
|
||||||
|
|
||||||
relocate_vector_table();
|
relocate_vector_table();
|
||||||
#if defined(CONFIG_CPU_HAS_FPU)
|
#if defined(CONFIG_CPU_HAS_FPU)
|
||||||
z_arm_floating_point_init();
|
z_arm_floating_point_init();
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
#include <kernel_internal.h>
|
#include <kernel_internal.h>
|
||||||
#include <zephyr/linker/linker-defs.h>
|
#include <zephyr/linker/linker-defs.h>
|
||||||
|
#include <zephyr/platform/hooks.h>
|
||||||
|
|
||||||
extern void z_arm64_mm_init(bool is_primary_core);
|
extern void z_arm64_mm_init(bool is_primary_core);
|
||||||
|
|
||||||
|
@ -30,6 +31,10 @@ __weak void z_arm64_mm_init(bool is_primary_core) { }
|
||||||
*/
|
*/
|
||||||
void z_prep_c(void)
|
void z_prep_c(void)
|
||||||
{
|
{
|
||||||
|
#if defined(CONFIG_SOC_PREP_HOOK)
|
||||||
|
soc_prep_hook();
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Initialize tpidrro_el0 with our struct _cpu instance address */
|
/* Initialize tpidrro_el0 with our struct _cpu instance address */
|
||||||
write_tpidrro_el0((uintptr_t)&_kernel.cpus[0]);
|
write_tpidrro_el0((uintptr_t)&_kernel.cpus[0]);
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
#include <kernel_internal.h>
|
#include <kernel_internal.h>
|
||||||
#include <zephyr/irq.h>
|
#include <zephyr/irq.h>
|
||||||
|
#include <zephyr/platform/hooks.h>
|
||||||
|
|
||||||
static void interrupt_init(void)
|
static void interrupt_init(void)
|
||||||
{
|
{
|
||||||
|
@ -44,6 +45,9 @@ static void interrupt_init(void)
|
||||||
|
|
||||||
void z_prep_c(void)
|
void z_prep_c(void)
|
||||||
{
|
{
|
||||||
|
#if defined(CONFIG_SOC_PREP_HOOK)
|
||||||
|
soc_prep_hook();
|
||||||
|
#endif
|
||||||
z_bss_zero();
|
z_bss_zero();
|
||||||
|
|
||||||
interrupt_init();
|
interrupt_init();
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include <zephyr/linker/linker-defs.h>
|
#include <zephyr/linker/linker-defs.h>
|
||||||
#include <zephyr/kernel_structs.h>
|
#include <zephyr/kernel_structs.h>
|
||||||
#include <kernel_internal.h>
|
#include <kernel_internal.h>
|
||||||
|
#include <zephyr/platform/hooks.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Prepare to and run C code
|
* @brief Prepare to and run C code
|
||||||
|
@ -30,6 +31,10 @@
|
||||||
|
|
||||||
void z_prep_c(void)
|
void z_prep_c(void)
|
||||||
{
|
{
|
||||||
|
#if defined(CONFIG_SOC_PREP_HOOK)
|
||||||
|
soc_prep_hook();
|
||||||
|
#endif
|
||||||
|
|
||||||
z_bss_zero();
|
z_bss_zero();
|
||||||
z_data_copy();
|
z_data_copy();
|
||||||
/* In most XIP scenarios we copy the exception code into RAM, so need
|
/* In most XIP scenarios we copy the exception code into RAM, so need
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include <zephyr/toolchain.h>
|
#include <zephyr/toolchain.h>
|
||||||
#include <zephyr/kernel_structs.h>
|
#include <zephyr/kernel_structs.h>
|
||||||
#include <kernel_internal.h>
|
#include <kernel_internal.h>
|
||||||
|
#include <zephyr/platform/hooks.h>
|
||||||
|
|
||||||
#if defined(CONFIG_RISCV_SOC_INTERRUPT_INIT)
|
#if defined(CONFIG_RISCV_SOC_INTERRUPT_INIT)
|
||||||
void soc_interrupt_init(void);
|
void soc_interrupt_init(void);
|
||||||
|
@ -33,6 +34,10 @@ void soc_interrupt_init(void);
|
||||||
|
|
||||||
void z_prep_c(void)
|
void z_prep_c(void)
|
||||||
{
|
{
|
||||||
|
#if defined(CONFIG_SOC_PREP_HOOK)
|
||||||
|
soc_prep_hook();
|
||||||
|
#endif
|
||||||
|
|
||||||
z_bss_zero();
|
z_bss_zero();
|
||||||
z_data_copy();
|
z_data_copy();
|
||||||
#if defined(CONFIG_RISCV_SOC_INTERRUPT_INIT)
|
#if defined(CONFIG_RISCV_SOC_INTERRUPT_INIT)
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <kernel_internal.h>
|
#include <kernel_internal.h>
|
||||||
|
#include <zephyr/platform/hooks.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Prepare to and run C code
|
* @brief Prepare to and run C code
|
||||||
|
@ -19,6 +20,9 @@
|
||||||
|
|
||||||
void z_prep_c(void)
|
void z_prep_c(void)
|
||||||
{
|
{
|
||||||
|
#if defined(CONFIG_SOC_PREP_HOOK)
|
||||||
|
soc_prep_hook();
|
||||||
|
#endif
|
||||||
z_data_copy();
|
z_data_copy();
|
||||||
z_cstart();
|
z_cstart();
|
||||||
CODE_UNREACHABLE;
|
CODE_UNREACHABLE;
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <zephyr/arch/x86/multiboot.h>
|
#include <zephyr/arch/x86/multiboot.h>
|
||||||
#include <zephyr/arch/x86/efi.h>
|
#include <zephyr/arch/x86/efi.h>
|
||||||
#include <x86_mmu.h>
|
#include <x86_mmu.h>
|
||||||
|
#include <zephyr/platform/hooks.h>
|
||||||
|
|
||||||
extern FUNC_NORETURN void z_cstart(void);
|
extern FUNC_NORETURN void z_cstart(void);
|
||||||
extern void x86_64_irq_init(void);
|
extern void x86_64_irq_init(void);
|
||||||
|
@ -25,6 +26,9 @@ FUNC_NORETURN void z_prep_c(void *arg)
|
||||||
{
|
{
|
||||||
x86_boot_arg_t *cpu_arg = arg;
|
x86_boot_arg_t *cpu_arg = arg;
|
||||||
|
|
||||||
|
#if defined(CONFIG_SOC_PREP_HOOK)
|
||||||
|
soc_prep_hook();
|
||||||
|
#endif
|
||||||
_kernel.cpus[0].nested = 0;
|
_kernel.cpus[0].nested = 0;
|
||||||
|
|
||||||
#ifdef CONFIG_MMU
|
#ifdef CONFIG_MMU
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
#include <zephyr/kernel.h>
|
#include <zephyr/kernel.h>
|
||||||
#include <kernel_internal.h>
|
#include <kernel_internal.h>
|
||||||
|
#include <zephyr/platform/hooks.h>
|
||||||
|
|
||||||
extern FUNC_NORETURN void z_cstart(void);
|
extern FUNC_NORETURN void z_cstart(void);
|
||||||
|
|
||||||
|
@ -20,6 +21,9 @@ extern void soc_num_cpus_init(void);
|
||||||
*/
|
*/
|
||||||
void z_prep_c(void)
|
void z_prep_c(void)
|
||||||
{
|
{
|
||||||
|
#if defined(CONFIG_SOC_PREP_HOOK)
|
||||||
|
soc_prep_hook();
|
||||||
|
#endif
|
||||||
#if CONFIG_SOC_HAS_RUNTIME_NUM_CPUS
|
#if CONFIG_SOC_HAS_RUNTIME_NUM_CPUS
|
||||||
soc_num_cpus_init();
|
soc_num_cpus_init();
|
||||||
#endif
|
#endif
|
||||||
|
|
74
include/zephyr/platform/hooks.h
Normal file
74
include/zephyr/platform/hooks.h
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024 Intel Corporation
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef ZEPHYR_INCLUDE_PLATFORM_PLATFORM_H_
|
||||||
|
#define ZEPHYR_INCLUDE_PLATFORM_PLATFORM_H_
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief Soc and Board hooks
|
||||||
|
*
|
||||||
|
* This header file contains function prototypes for the interfaces between
|
||||||
|
* zephyr architecture and initialization code and the SoC and board specific logic
|
||||||
|
* that resides under boards/ and soc/
|
||||||
|
*
|
||||||
|
* @note These are all standard soc and board interfaces that are exported from
|
||||||
|
* soc and board specific logic to OS internal logic. These should never be accessed
|
||||||
|
* directly from application code but may be freely used within the OS.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief SoC hook executed at the beginning of the reset vector.
|
||||||
|
*
|
||||||
|
* This hook is implemented by the SoC and can be used to perform any
|
||||||
|
* SoC-specific initialization.
|
||||||
|
*/
|
||||||
|
void soc_reset_hook(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief SoC hook executed after the reset vector.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* This hook is implemented by the SoC and can be used to perform any
|
||||||
|
* SoC-specific initialization.
|
||||||
|
*/
|
||||||
|
void soc_prep_hook(void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @brief SoC hook executed before the kernel and devices are initialized.
|
||||||
|
*
|
||||||
|
* This hook is implemented by the SoC and can be used to perform any
|
||||||
|
* SoC-specific initialization.
|
||||||
|
*/
|
||||||
|
void soc_early_init_hook(void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @brief SoC hook executed after the kernel and devices are initialized.
|
||||||
|
*
|
||||||
|
* This hook is implemented by the SoC and can be used to perform any
|
||||||
|
* SoC-specific initialization.
|
||||||
|
*/
|
||||||
|
void soc_late_init_hook(void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @brief Board hook executed before the kernel starts.
|
||||||
|
*
|
||||||
|
* This is called before the kernel has started. This hook
|
||||||
|
* is implemented by the board and can be used to perform any board-specific
|
||||||
|
* initialization.
|
||||||
|
*/
|
||||||
|
void board_early_init_hook(void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @brief Board hook executed after the kernel starts.
|
||||||
|
|
||||||
|
* This is called after the kernel has started, but before the main function is
|
||||||
|
* called. This hook is implemented by the board and can be used to perform
|
||||||
|
* any board-specific initialization.
|
||||||
|
*/
|
||||||
|
void board_late_init_hook(void);
|
||||||
|
|
||||||
|
#endif
|
|
@ -1027,3 +1027,4 @@ endmenu
|
||||||
|
|
||||||
rsource "Kconfig.device"
|
rsource "Kconfig.device"
|
||||||
rsource "Kconfig.vm"
|
rsource "Kconfig.vm"
|
||||||
|
rsource "Kconfig.init"
|
||||||
|
|
45
kernel/Kconfig.init
Normal file
45
kernel/Kconfig.init
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
# Kernel init hook options
|
||||||
|
|
||||||
|
# Copyright (c) 2024 Intel Corporation
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
|
||||||
|
menu "SoC and Board Hooks"
|
||||||
|
|
||||||
|
config SOC_RESET_HOOK
|
||||||
|
bool "Run early SoC reset hook"
|
||||||
|
help
|
||||||
|
Run an early SoC reset hook.
|
||||||
|
|
||||||
|
A custom hook soc_reset_hook() is executed at the beginning of the
|
||||||
|
startup code (__start). soc_reset_hook() must be implemented by the SoC.
|
||||||
|
|
||||||
|
config SOC_PREP_HOOK
|
||||||
|
bool "Run early SoC preparation hook"
|
||||||
|
help
|
||||||
|
Run an early SoC preparation hook.
|
||||||
|
|
||||||
|
A custom hook soc_prep_hook() is executed at the beginning of the
|
||||||
|
c prep code (prep_c). soc_prep_hook() must be implemented by the SoC.
|
||||||
|
|
||||||
|
config SOC_EARLY_INIT_HOOK
|
||||||
|
bool "Run early SoC hook"
|
||||||
|
help
|
||||||
|
Run an early SoC initialization hook.
|
||||||
|
|
||||||
|
config SOC_LATE_INIT_HOOK
|
||||||
|
bool "Run late SoC hook"
|
||||||
|
help
|
||||||
|
Run a late SoC initialization hook.
|
||||||
|
|
||||||
|
config BOARD_EARLY_INIT_HOOK
|
||||||
|
bool "Run early board hook"
|
||||||
|
help
|
||||||
|
Run an early board initialization hook.
|
||||||
|
|
||||||
|
config BOARD_LATE_INIT_HOOK
|
||||||
|
bool "Run late board hook"
|
||||||
|
help
|
||||||
|
Run a late board initialization hook.
|
||||||
|
|
||||||
|
endmenu
|
|
@ -25,6 +25,7 @@
|
||||||
#include <zephyr/device.h>
|
#include <zephyr/device.h>
|
||||||
#include <zephyr/init.h>
|
#include <zephyr/init.h>
|
||||||
#include <zephyr/linker/linker-defs.h>
|
#include <zephyr/linker/linker-defs.h>
|
||||||
|
#include <zephyr/platform/hooks.h>
|
||||||
#include <ksched.h>
|
#include <ksched.h>
|
||||||
#include <kthread.h>
|
#include <kthread.h>
|
||||||
#include <zephyr/sys/dlist.h>
|
#include <zephyr/sys/dlist.h>
|
||||||
|
@ -516,6 +517,13 @@ static void bg_thread_main(void *unused1, void *unused2, void *unused3)
|
||||||
z_sys_post_kernel = true;
|
z_sys_post_kernel = true;
|
||||||
|
|
||||||
z_sys_init_run_level(INIT_LEVEL_POST_KERNEL);
|
z_sys_init_run_level(INIT_LEVEL_POST_KERNEL);
|
||||||
|
#if CONFIG_SOC_LATE_INIT_HOOK
|
||||||
|
soc_late_init_hook();
|
||||||
|
#endif
|
||||||
|
#if CONFIG_BOARD_LATE_INIT_HOOK
|
||||||
|
board_late_init_hook();
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_STACK_POINTER_RANDOM) && (CONFIG_STACK_POINTER_RANDOM != 0)
|
#if defined(CONFIG_STACK_POINTER_RANDOM) && (CONFIG_STACK_POINTER_RANDOM != 0)
|
||||||
z_stack_adjust_initialized = 1;
|
z_stack_adjust_initialized = 1;
|
||||||
#endif /* CONFIG_STACK_POINTER_RANDOM */
|
#endif /* CONFIG_STACK_POINTER_RANDOM */
|
||||||
|
@ -757,6 +765,12 @@ FUNC_NORETURN void z_cstart(void)
|
||||||
/* do any necessary initialization of static devices */
|
/* do any necessary initialization of static devices */
|
||||||
z_device_state_init();
|
z_device_state_init();
|
||||||
|
|
||||||
|
#if CONFIG_SOC_EARLY_INIT_HOOK
|
||||||
|
soc_early_init_hook();
|
||||||
|
#endif
|
||||||
|
#if CONFIG_BOARD_EARLY_INIT_HOOK
|
||||||
|
board_early_init_hook();
|
||||||
|
#endif
|
||||||
/* perform basic hardware initialization */
|
/* perform basic hardware initialization */
|
||||||
z_sys_init_run_level(INIT_LEVEL_PRE_KERNEL_1);
|
z_sys_init_run_level(INIT_LEVEL_PRE_KERNEL_1);
|
||||||
#if defined(CONFIG_SMP)
|
#if defined(CONFIG_SMP)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue