diff mbox series

[v2,02/12] lib: sbi: add experimental Yield ECALL extension

Message ID 20261029155929.586597-3-raymondmaoca@gmail.com
State New
Headers show
Series Introduce Virtual IRQ (VIRQ) framework | expand

Commit Message

Raymond Mao Oct. 29, 2026, 3:59 p.m. UTC
From: Raymond Mao <raymond.mao@riscstar.com>

Add a Yield extension with EID 0x0800594c and FID 0.
The ID is experimental and is not an official SBI assignment.

Complete the calling domain and hart's outstanding SYSIRQ batches
using the same completion mechanism as the next CLAIM. Return the number
completed, including partial progress on error, without claiming new IRQs.
Ask the backend to consider a drained return only after completion
succeeds.

Enable the extension with CONFIG_SBI_ECALL_YIELD and register it only
when SYSIRQ channels exist.

Signed-off-by: Raymond Mao <raymond.mao@riscstar.com>
---
 include/sbi/sbi_ecall_interface.h |  6 +++++
 lib/sbi/Kconfig                   |  9 +++++++
 lib/sbi/objects.mk                |  3 +++
 lib/sbi/sbi_ecall_yield.c         | 42 +++++++++++++++++++++++++++++++
 4 files changed, 60 insertions(+)
 create mode 100644 lib/sbi/sbi_ecall_yield.c
diff mbox series

Patch

diff --git a/include/sbi/sbi_ecall_interface.h b/include/sbi/sbi_ecall_interface.h
index fd4e77ca..287d3151 100644
--- a/include/sbi/sbi_ecall_interface.h
+++ b/include/sbi/sbi_ecall_interface.h
@@ -39,6 +39,9 @@ 
 #define SBI_EXT_FWFT				0x46574654
 #define SBI_EXT_MPXY				0x4D505859
 
+/* SBI extension ID for Yield. */
+#define SBI_EXT_YIELD				0x0800594c
+
 /* SBI function IDs for BASE extension*/
 #define SBI_EXT_BASE_GET_SPEC_VERSION		0x0
 #define SBI_EXT_BASE_GET_IMP_ID			0x1
@@ -122,6 +125,9 @@ 
 #define SBI_EXT_DBTR_TRIGGER_ENABLE	0x6
 #define SBI_EXT_DBTR_TRIGGER_DISABLE	0x7
 
+/* SBI function IDs for the Yield extension. */
+#define SBI_EXT_YIELD_YIELD	0x0
+
 /* SBI function IDs for FW feature extension */
 #define SBI_EXT_FWFT_SET		0x0
 #define SBI_EXT_FWFT_GET		0x1
diff --git a/lib/sbi/Kconfig b/lib/sbi/Kconfig
index 24132eaa..894ce22f 100644
--- a/lib/sbi/Kconfig
+++ b/lib/sbi/Kconfig
@@ -76,6 +76,15 @@  config SBI_ECALL_LEGACY
 	bool "SBI v0.1 legacy extensions"
 	default y
 
+config SBI_ECALL_YIELD
+	bool "Yield extension"
+	default y
+	help
+	  Enable the Yield ECALL extension.
+	  Yield completes the calling domain and hart's claimed SYSIRQs.
+	  A delivery backend may request a context return once work is drained.
+	  Interrupt claiming still uses RPMI SYSTEM_IRQ through SBI MPXY.
+
 config SBI_ECALL_VENDOR
 	bool "Platform-defined vendor extensions"
 	default y
diff --git a/lib/sbi/objects.mk b/lib/sbi/objects.mk
index ae27d0c5..16c141fe 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_YIELD) += ecall_yield
+libsbi-objs-$(CONFIG_SBI_ECALL_YIELD) += sbi_ecall_yield.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_yield.c b/lib/sbi/sbi_ecall_yield.c
new file mode 100644
index 00000000..fddc2d6c
--- /dev/null
+++ b/lib/sbi/sbi_ecall_yield.c
@@ -0,0 +1,42 @@ 
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * Copyright (c) 2026 RISCstar Solutions Corporation.
+ *
+ * Author: Raymond Mao <raymond.mao@riscstar.com>
+ */
+
+#include <sbi/sbi_ecall.h>
+#include <sbi/sbi_ecall_interface.h>
+#include <sbi/sbi_error.h>
+#include <sbi_utils/sysirq/rpmi_sysirq.h>
+
+static int sbi_ecall_yield_handler(unsigned long extid, unsigned long funcid,
+				   struct sbi_trap_regs *regs,
+				   struct sbi_ecall_return *out)
+{
+	u32 completed = 0;
+	int rc;
+
+	if (funcid != SBI_EXT_YIELD_YIELD)
+		return SBI_ENOTSUPP;
+	rc = rpmi_sysirq_complete_thishart(&completed);
+	out->value = completed;
+	return rc;
+}
+
+struct sbi_ecall_extension ecall_yield;
+
+static int sbi_ecall_yield_register_extensions(void)
+{
+	if (!rpmi_sysirq_available())
+		return SBI_OK;
+	return sbi_ecall_register_extension(&ecall_yield);
+}
+
+struct sbi_ecall_extension ecall_yield = {
+	.name = "yield",
+	.extid_start = SBI_EXT_YIELD,
+	.extid_end = SBI_EXT_YIELD,
+	.register_extensions = sbi_ecall_yield_register_extensions,
+	.handle = sbi_ecall_yield_handler,
+};