diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2022-11-09 16:27:23 +0200 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2022-11-09 17:27:11 +0200 |
| commit | a3e45d5dcaf1bf3a9e684b5fcc301413ec994a9b (patch) | |
| tree | ae319c8f389e7ca39bbdd4b114655f8604563305 /arch/riscv64/kernel/cpu.c | |
| parent | 2b5533aefef026fe7bada314ebdb2651b809979a (diff) | |
| download | kmi-a3e45d5dcaf1bf3a9e684b5fcc301413ec994a9b.tar.gz kmi-a3e45d5dcaf1bf3a9e684b5fcc301413ec994a9b.zip | |
add basic IPI structure
Diffstat (limited to 'arch/riscv64/kernel/cpu.c')
| -rw-r--r-- | arch/riscv64/kernel/cpu.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/arch/riscv64/kernel/cpu.c b/arch/riscv64/kernel/cpu.c index d6d07ec..60140e6 100644 --- a/arch/riscv64/kernel/cpu.c +++ b/arch/riscv64/kernel/cpu.c @@ -11,6 +11,8 @@ #include <arch/cpu.h> +#include "sbi.h" + /** Keeps track of initialized cpus. */ static atomic_long cpus = 0; @@ -40,3 +42,35 @@ struct tcb *cur_tcb() register struct tcb *t __asm__ ("tp"); return t; } + +/** + * Helper for cpu_send_ipi() to convert linear \p cpu_id to SBI \c + * hart_mask_base. + * + * @param cpu_id CPU id to convert. + * @return Corresponding \c hart_mask_base. + */ +static long __cpu_offset(id_t cpu_id) +{ + return cpu_id / (sizeof(long) * 8); +} + +/** + * Helper for cpu_send_ipi() to convert linear \p cpu_id to SBI \c + * hart_mask. + * + * @param cpu_id CPU id to convert. + * @param offset Offset from __cpu_offset(). + * @return Corresponding \c hart_mask. + */ +static long __cpu_mask(id_t cpu_id, long offset) +{ + return cpu_id - offset * sizeof(long) * 8; +} + +void cpu_send_ipi(id_t cpu_id) +{ + long offset = __cpu_offset(cpu_id); + long mask = __cpu_mask(cpu_id, offset); + sbi_send_ipi(mask, offset); +} |
