public inbox for opensbi@lists.infradead.org
 help / color / mirror / Atom feed
From: Raymond Mao <raymondmaoca@gmail.com>
To: opensbi@lists.infradead.org
Cc: scott@riscstar.com, dave.patel@riscstar.com,
	raymond.mao@riscstar.com, robin.randhawa@sifive.com,
	samuel.holland@sifive.com, anup.patel@qti.qualcomm.com,
	anuppate@qti.qualcomm.com, dhaval@rivosinc.com,
	peter.lin@sifive.com
Subject: [PATCH RFC 3/3] lib: sbi: Add VIRQ ecall extension
Date: Fri, 13 Feb 2026 14:04:59 -0500	[thread overview]
Message-ID: <20260213190459.2540597-4-raymondmaoca@gmail.com> (raw)
In-Reply-To: <20260213190459.2540597-1-raymondmaoca@gmail.com>

From: Raymond Mao <raymond.mao@riscstar.com>

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 <raymond.mao@riscstar.com>
---
 include/sbi/sbi_ecall_interface.h | 18 ++++++++++
 lib/sbi/Kconfig                   |  5 +++
 lib/sbi/objects.mk                |  3 ++
 lib/sbi/sbi_ecall_virq.c          | 57 +++++++++++++++++++++++++++++++
 4 files changed, 83 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 76624e3f..9cb9a7eb 100644
--- a/include/sbi/sbi_ecall_interface.h
+++ b/include/sbi/sbi_ecall_interface.h
@@ -126,6 +126,24 @@
 #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 hwirq (0 if none pending)
+ */
+
+#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..8479f861 100644
--- a/lib/sbi/Kconfig
+++ b/lib/sbi/Kconfig
@@ -69,4 +69,9 @@ config SBI_ECALL_SSE
 config SBI_ECALL_MPXY
 	bool "MPXY extension"
 	default y
+
+config SBI_ECALL_VIRQ
+	bool "VIRQ extension"
+	default y
+
 endmenu
diff --git a/lib/sbi/objects.mk b/lib/sbi/objects.mk
index 07d13229..18e590ab 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..b192598e
--- /dev/null
+++ b/lib/sbi/sbi_ecall_virq.c
@@ -0,0 +1,57 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2026 RISCstar Solutions.
+ *
+ * Author: Raymond Mao <raymond.mao@riscstar.com>
+ */
+
+#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 hwirq = (u32)regs->a0;
+
+		sbi_virq_complete_thishart(hwirq);
+		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
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

  parent reply	other threads:[~2026-02-13 19:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-13 19:04 [PATCH RFC 0/2] VIRQ (Virtual IRQ) layer to support paravirtual interrupt delivery Raymond Mao
2026-02-13 19:04 ` [PATCH RFC 1/3] lib: sbi: Prototype of Virtual IRQ (VIRQ) layer for mapping/routing/courier/ IRQs Raymond Mao
2026-02-13 19:04 ` [PATCH RFC 2/3] platform: generic: Add sample dts overlay for testing hwirq/domain route rules Raymond Mao
2026-02-13 19:04 ` Raymond Mao [this message]
2026-02-13 21:03   ` [PATCH RFC 3/3] lib: sbi: Add VIRQ ecall extension Andrew Jones
2026-02-13 22:07     ` Raymond Mao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260213190459.2540597-4-raymondmaoca@gmail.com \
    --to=raymondmaoca@gmail.com \
    --cc=anup.patel@qti.qualcomm.com \
    --cc=anuppate@qti.qualcomm.com \
    --cc=dave.patel@riscstar.com \
    --cc=dhaval@rivosinc.com \
    --cc=opensbi@lists.infradead.org \
    --cc=peter.lin@sifive.com \
    --cc=raymond.mao@riscstar.com \
    --cc=robin.randhawa@sifive.com \
    --cc=samuel.holland@sifive.com \
    --cc=scott@riscstar.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox