[PATCH 04/10] lib: sbi: Add VIRQ ecall extension
Raymond Mao <[email protected]>
| Newsgroups | org.infradead.lists.opensbi |
|---|---|
| Message-ID | <[email protected]> |
From: Raymond Mao <[email protected]> Add vendor SBI extension ecall for VIRQ. This allows S-mode payload to pop/complete the next pending VIRQ has couried into the current domain. Signed-off-by: Raymond Mao <[email protected]> --- include/sbi/sbi_ecall_interface.h | 26 ++++++++++++++ lib/sbi/Kconfig | 10 ++++++ lib/sbi/objects.mk | 3 ++ lib/sbi/sbi_ecall_virq.c | 56 +++++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+) create mode 100644 lib/sbi/sbi_ecall_virq.c diff --git a/include/sbi/sbi_ecall_interface.h b/include/sbi/sbi_ecall_interface.h index 9a776f79..37937a0c 100644 --- a/include/sbi/sbi_ecall_interface.h +++ b/include/sbi/sbi_ecall_interface.h @@ -126,6 +126,32 @@ #define SBI_EXT_FWFT_SET 0x0 #define SBI_EXT_FWFT_GET 0x1 +#ifdef CONFIG_SBI_ECALL_VIRQ + +/* Vendor extension base range is defined by the SBI spec. Choose a private ID. */ +#define SBI_EXT_VIRQ 0x0900524d + +/* Function IDs for SBI_EXT_VIRQ */ +#define SBI_EXT_VIRQ_POP 0 +#define SBI_EXT_VIRQ_COMPLETE 1 + +/* + * SBI_EXT_VIRQ_POP + * Returns: + * a0: SBI error code (0 for success) + * a1: next pending VIRQ (VIRQ_INVALID if none pending) + */ + +/* + * SBI_EXT_VIRQ_COMPLETE + * Input: + * a0: VIRQ to complete + * Returns: + * a0: SBI error code (0 for success) + */ + +#endif + enum sbi_fwft_feature_t { SBI_FWFT_MISALIGNED_EXC_DELEG = 0x0, SBI_FWFT_LANDING_PAD = 0x1, diff --git a/lib/sbi/Kconfig b/lib/sbi/Kconfig index c6cc04bc..cbb74640 100644 --- a/lib/sbi/Kconfig +++ b/lib/sbi/Kconfig @@ -69,4 +69,14 @@ config SBI_ECALL_SSE config SBI_ECALL_MPXY bool "MPXY extension" default y + +config SBI_ECALL_VIRQ + bool "VIRQ extension" + default y + help + Enable the OpenSBI VIRQ ecall extension. + This extension allows an S-mode payload to pop a pending + virtual interrupt and complete its deferred host interrupt + handling after the payload has consumed the event. + endmenu diff --git a/lib/sbi/objects.mk b/lib/sbi/objects.mk index 184bf173..ea816e92 100644 --- a/lib/sbi/objects.mk +++ b/lib/sbi/objects.mk @@ -64,6 +64,9 @@ libsbi-objs-$(CONFIG_SBI_ECALL_SSE) += sbi_ecall_sse.o carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_MPXY) += ecall_mpxy libsbi-objs-$(CONFIG_SBI_ECALL_MPXY) += sbi_ecall_mpxy.o +carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_VIRQ) += ecall_virq +libsbi-objs-$(CONFIG_SBI_ECALL_VIRQ) += sbi_ecall_virq.o + libsbi-objs-y += sbi_bitmap.o libsbi-objs-y += sbi_bitops.o libsbi-objs-y += sbi_console.o diff --git a/lib/sbi/sbi_ecall_virq.c b/lib/sbi/sbi_ecall_virq.c new file mode 100644 index 00000000..a84a83d7 --- /dev/null +++ b/lib/sbi/sbi_ecall_virq.c @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: BSD-2-Clause +/* + * Copyright (c) 2026 RISCstar Solutions. + * + * Author: Raymond Mao <[email protected]> + */ + +#include <sbi/sbi_console.h> +#include <sbi/sbi_ecall.h> +#include <sbi/sbi_ecall_interface.h> +#include <sbi/sbi_error.h> +#include <sbi/sbi_trap.h> +#include <sbi/sbi_virq.h> + +static int sbi_ecall_virq_handler(unsigned long extid, + unsigned long funcid, + struct sbi_trap_regs *regs, + struct sbi_ecall_return *out) +{ + (void)extid; + + sbi_printf("[ECALL VIRQ] VIRQ ecall handler, funcid: %ld\n", funcid); + + switch (funcid) { + case SBI_EXT_VIRQ_POP: + out->value = (unsigned long)sbi_virq_pop_thishart(); + return SBI_OK; + case SBI_EXT_VIRQ_COMPLETE: + u32 virq = (u32)regs->a0; + + sbi_virq_complete_thishart(virq); + regs->a0 = 0; + return SBI_OK; + default: + return SBI_ENOTSUPP; + } +} + +struct sbi_ecall_extension ecall_virq; + +static int sbi_ecall_virq_register_extensions(void) +{ + int ret; + + ret = sbi_ecall_register_extension(&ecall_virq); + sbi_printf("[ECALL VIRQ] register VIRQ ecall extensions, ret=%d\n", ret); + return ret; +} + +struct sbi_ecall_extension ecall_virq = { + .name = "virq", + .extid_start = SBI_EXT_VIRQ, + .extid_end = SBI_EXT_VIRQ, + .register_extensions = sbi_ecall_virq_register_extensions, + .handle = sbi_ecall_virq_handler, +}; -- 2.25.1 -- opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi