Skip to content

Commit e260d03

Browse files
nashifcarlescufi
authored andcommitted
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 <[email protected]>
1 parent 736289a commit e260d03

File tree

14 files changed

+179
-0
lines changed

14 files changed

+179
-0
lines changed

arch/arc/core/prep_c.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <zephyr/arch/arc/cluster.h>
2424
#include <zephyr/kernel_structs.h>
2525
#include <kernel_internal.h>
26+
#include <zephyr/platform/hooks.h>
2627

2728
/* XXX - keep for future use in full-featured cache APIs */
2829
#if 0
@@ -121,6 +122,10 @@ extern FUNC_NORETURN void z_cstart(void);
121122

122123
void z_prep_c(void)
123124
{
125+
#if defined(CONFIG_SOC_PREP_HOOK)
126+
soc_prep_hook();
127+
#endif
128+
124129
#ifdef CONFIG_ISA_ARCV3
125130
arc_cluster_scm_enable();
126131
#endif

arch/arm/core/cortex_a_r/prep_c.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <zephyr/linker/linker-defs.h>
2222
#include <zephyr/sys/barrier.h>
2323
#include <zephyr/arch/arm/cortex_a_r/lib_helpers.h>
24+
#include <zephyr/platform/hooks.h>
2425

2526
#if defined(CONFIG_ARMV7_R) || defined(CONFIG_ARMV7_A)
2627
#include <cortex_a_r/stack.h>
@@ -147,6 +148,9 @@ extern FUNC_NORETURN void z_cstart(void);
147148
*/
148149
void z_prep_c(void)
149150
{
151+
#if defined(CONFIG_SOC_PREP_HOOK)
152+
soc_prep_hook();
153+
#endif
150154
/* Initialize tpidruro with our struct _cpu instance address */
151155
write_tpidruro((uintptr_t)&_kernel.cpus[0]);
152156

arch/arm/core/cortex_m/prep_c.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <kernel_internal.h>
2121
#include <zephyr/linker/linker-defs.h>
2222
#include <zephyr/sys/barrier.h>
23+
#include <zephyr/platform/hooks.h>
2324

2425
#if defined(__GNUC__)
2526
/*
@@ -181,6 +182,10 @@ extern FUNC_NORETURN void z_cstart(void);
181182
*/
182183
void z_prep_c(void)
183184
{
185+
#if defined(CONFIG_SOC_PREP_HOOK)
186+
soc_prep_hook();
187+
#endif
188+
184189
relocate_vector_table();
185190
#if defined(CONFIG_CPU_HAS_FPU)
186191
z_arm_floating_point_init();

arch/arm64/core/prep_c.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <kernel_internal.h>
1818
#include <zephyr/linker/linker-defs.h>
19+
#include <zephyr/platform/hooks.h>
1920

2021
extern void z_arm64_mm_init(bool is_primary_core);
2122

@@ -30,6 +31,10 @@ __weak void z_arm64_mm_init(bool is_primary_core) { }
3031
*/
3132
void z_prep_c(void)
3233
{
34+
#if defined(CONFIG_SOC_PREP_HOOK)
35+
soc_prep_hook();
36+
#endif
37+
3338
/* Initialize tpidrro_el0 with our struct _cpu instance address */
3439
write_tpidrro_el0((uintptr_t)&_kernel.cpus[0]);
3540

arch/mips/core/prep_c.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <kernel_internal.h>
1313
#include <zephyr/irq.h>
14+
#include <zephyr/platform/hooks.h>
1415

1516
static void interrupt_init(void)
1617
{
@@ -44,6 +45,9 @@ static void interrupt_init(void)
4445

4546
void z_prep_c(void)
4647
{
48+
#if defined(CONFIG_SOC_PREP_HOOK)
49+
soc_prep_hook();
50+
#endif
4751
z_bss_zero();
4852

4953
interrupt_init();

arch/nios2/core/prep_c.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <zephyr/linker/linker-defs.h>
2222
#include <zephyr/kernel_structs.h>
2323
#include <kernel_internal.h>
24+
#include <zephyr/platform/hooks.h>
2425

2526
/**
2627
* @brief Prepare to and run C code
@@ -30,6 +31,10 @@
3031

3132
void z_prep_c(void)
3233
{
34+
#if defined(CONFIG_SOC_PREP_HOOK)
35+
soc_prep_hook();
36+
#endif
37+
3338
z_bss_zero();
3439
z_data_copy();
3540
/* In most XIP scenarios we copy the exception code into RAM, so need

arch/riscv/core/prep_c.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <zephyr/toolchain.h>
2020
#include <zephyr/kernel_structs.h>
2121
#include <kernel_internal.h>
22+
#include <zephyr/platform/hooks.h>
2223

2324
#if defined(CONFIG_RISCV_SOC_INTERRUPT_INIT)
2425
void soc_interrupt_init(void);
@@ -33,6 +34,10 @@ void soc_interrupt_init(void);
3334

3435
void z_prep_c(void)
3536
{
37+
#if defined(CONFIG_SOC_PREP_HOOK)
38+
soc_prep_hook();
39+
#endif
40+
3641
z_bss_zero();
3742
z_data_copy();
3843
#if defined(CONFIG_RISCV_SOC_INTERRUPT_INIT)

arch/sparc/core/prep_c.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
#include <kernel_internal.h>
13+
#include <zephyr/platform/hooks.h>
1314

1415
/**
1516
* @brief Prepare to and run C code
@@ -19,6 +20,9 @@
1920

2021
void z_prep_c(void)
2122
{
23+
#if defined(CONFIG_SOC_PREP_HOOK)
24+
soc_prep_hook();
25+
#endif
2226
z_data_copy();
2327
z_cstart();
2428
CODE_UNREACHABLE;

arch/x86/core/prep_c.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <zephyr/arch/x86/multiboot.h>
1010
#include <zephyr/arch/x86/efi.h>
1111
#include <x86_mmu.h>
12+
#include <zephyr/platform/hooks.h>
1213

1314
extern FUNC_NORETURN void z_cstart(void);
1415
extern void x86_64_irq_init(void);
@@ -25,6 +26,9 @@ FUNC_NORETURN void z_prep_c(void *arg)
2526
{
2627
x86_boot_arg_t *cpu_arg = arg;
2728

29+
#if defined(CONFIG_SOC_PREP_HOOK)
30+
soc_prep_hook();
31+
#endif
2832
_kernel.cpus[0].nested = 0;
2933

3034
#ifdef CONFIG_MMU

arch/xtensa/core/prep_c.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
#include <zephyr/kernel.h>
77
#include <kernel_internal.h>
8+
#include <zephyr/platform/hooks.h>
89

910
extern FUNC_NORETURN void z_cstart(void);
1011

@@ -20,6 +21,9 @@ extern void soc_num_cpus_init(void);
2021
*/
2122
void z_prep_c(void)
2223
{
24+
#if defined(CONFIG_SOC_PREP_HOOK)
25+
soc_prep_hook();
26+
#endif
2327
#if CONFIG_SOC_HAS_RUNTIME_NUM_CPUS
2428
soc_num_cpus_init();
2529
#endif

0 commit comments

Comments
 (0)