Skip to content

Commit

Permalink
arch: riscv: Add support for custom IPI implementation
Browse files Browse the repository at this point in the history
Allow RISCV implementation to define its own custom IPI
implementation (e.g. Andes usage of PLIC for IPI)

Signed-off-by: Maxim Adelman <[email protected]>

Update arch/riscv/core/smp.c

Co-authored-by: Yong Cong Sin <[email protected]>
  • Loading branch information
Maxim Adelman and ycsin committed Sep 18, 2024
1 parent 119b238 commit ec45018
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
10 changes: 10 additions & 0 deletions arch/riscv/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 14 additions & 5 deletions arch/riscv/core/smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
#include <ipi.h>
#include <zephyr/irq.h>
#include <zephyr/sys/atomic.h>
#include <zephyr/arch/arch_interface.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;
Expand Down Expand Up @@ -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]

Expand All @@ -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)
{
Expand Down Expand Up @@ -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 */
8 changes: 8 additions & 0 deletions include/zephyr/platform/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
5 changes: 5 additions & 0 deletions kernel/Kconfig.init
Original file line number Diff line number Diff line change
Expand Up @@ -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 SoC hook"
help
Per-core initialization during SMP SoC hook

config BOARD_EARLY_INIT_HOOK
bool "Run early board hook"
help
Expand Down

0 comments on commit ec45018

Please sign in to comment.