diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 575c9871c13041..433a20c58529e4 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -112,6 +112,16 @@ config RISCV_SOC_HAS_CUSTOM_SYS_IO the RISC-V SoC needs to do something different and more than reading and writing the registers. +config RISCV_SOC_HAS_CUSTOM_SMP_IPI + bool + select SCHED_IPI_SUPPORTED + help + Hidden option to allow SoC to overwrite SMP IPI implementation + Enable this hidden option and do the following: + - implement arch_smp_init() which registers a custom SW IRQ handler + - implement arch_sched_directed_ipi() + - implement arch_flush_fpu_ipi() + config RISCV_SOC_CONTEXT_SAVE bool "SOC-based context saving in IRQ handlers" select RISCV_SOC_OFFSETS diff --git a/arch/riscv/core/smp.c b/arch/riscv/core/smp.c index 4ef287c4a7a561..43f006f9196a52 100644 --- a/arch/riscv/core/smp.c +++ b/arch/riscv/core/smp.c @@ -10,8 +10,10 @@ #include #include #include +#include #include #include +#include volatile struct { arch_cpustart_t fn; @@ -74,12 +76,17 @@ void arch_secondary_cpu_init(int hartid) #endif #ifdef CONFIG_SMP irq_enable(RISCV_IRQ_MSOFT); +#endif +#ifdef CONFIG_SOC_SMP_PER_CORE_INIT_HOOK + soc_smp_per_core_init_hook(); #endif riscv_cpu_init[cpu_num].fn(riscv_cpu_init[cpu_num].arg); } #ifdef CONFIG_SMP +#ifndef CONFIG_RISCV_SOC_HAS_CUSTOM_SMP_IPI + #define MSIP_BASE 0x2000000UL #define MSIP(hartid) ((volatile uint32_t *)MSIP_BASE)[hartid] @@ -104,11 +111,6 @@ void arch_sched_directed_ipi(uint32_t cpu_bitmap) arch_irq_unlock(key); } -void arch_sched_broadcast_ipi(void) -{ - arch_sched_directed_ipi(IPI_ALL_CPUS_MASK); -} - #ifdef CONFIG_FPU_SHARING void arch_flush_fpu_ipi(unsigned int cpu) { @@ -172,4 +174,11 @@ int arch_smp_init(void) return 0; } + +#endif /* CONFIG_RISCV_SOC_HAS_CUSTOM_SMP_IPI */ + +void arch_sched_broadcast_ipi(void) +{ + arch_sched_directed_ipi(IPI_ALL_CPUS_MASK); +} #endif /* CONFIG_SMP */ diff --git a/include/zephyr/platform/hooks.h b/include/zephyr/platform/hooks.h index 765b886a638034..157c313792357d 100644 --- a/include/zephyr/platform/hooks.h +++ b/include/zephyr/platform/hooks.h @@ -53,6 +53,14 @@ void soc_early_init_hook(void); */ void soc_late_init_hook(void); +/** + * @brief SoC per-core initialization during SMP bringup + * + * This hook is implemented by the SoC and can be used to perform any + * SoC-specific per-core initialization during SMP bringup + */ +void soc_smp_per_core_init_hook(void); + /* * @brief Board hook executed before the kernel starts. * diff --git a/kernel/Kconfig.init b/kernel/Kconfig.init index 79121a961282ff..0144cadd06dfdc 100644 --- a/kernel/Kconfig.init +++ b/kernel/Kconfig.init @@ -32,6 +32,11 @@ config SOC_LATE_INIT_HOOK help Run a late SoC initialization hook. +config SOC_SMP_PER_CORE_INIT_HOOK + bool "Per-core initialization during SMP bringup SoC hook" + help + Per-core initialization during SMP bringup SoC hook + config BOARD_EARLY_INIT_HOOK bool "Run early board hook" help