[PATCH 4/4] lib: sbi: Add ecall handler for SBI watchdog
Prajwal N
prajwal.n at oss.qualcomm.com
Fri Oct 2 01:30:40 PDT 2026
Update the Kconfig and build infrastructure to include
SBI ecall handler for watchdog.
Implement ecall handler functionality to delegate the
ecall to SBI watchdog framework
Signed-off-by: Prajwal N <prajwal.n at oss.qualcomm.com>
---
lib/sbi/Kconfig | 4 +++
lib/sbi/objects.mk | 3 ++
lib/sbi/sbi_ecall_wdt.c | 79 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 86 insertions(+)
create mode 100644 lib/sbi/sbi_ecall_wdt.c
diff --git a/lib/sbi/Kconfig b/lib/sbi/Kconfig
index 24132eaa..6fd965d5 100644
--- a/lib/sbi/Kconfig
+++ b/lib/sbi/Kconfig
@@ -95,4 +95,8 @@ config SBI_ECALL_SSE
config SBI_ECALL_MPXY
bool "MPXY extension"
default y
+
+config SBI_ECALL_WDT
+ bool "WDT extension"
+ default y
endmenu
diff --git a/lib/sbi/objects.mk b/lib/sbi/objects.mk
index c8bdc94a..847aee89 100644
--- a/lib/sbi/objects.mk
+++ b/lib/sbi/objects.mk
@@ -46,6 +46,9 @@ libsbi-objs-$(CONFIG_SBI_ECALL_DBCN) += sbi_ecall_dbcn.o
carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_CPPC) += ecall_cppc
libsbi-objs-$(CONFIG_SBI_ECALL_CPPC) += sbi_ecall_cppc.o
+carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_WDT) += ecall_wdt
+libsbi-objs-$(CONFIG_SBI_ECALL_WDT) += sbi_ecall_wdt.o
+
carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_FWFT) += ecall_fwft
libsbi-objs-$(CONFIG_SBI_ECALL_FWFT) += sbi_ecall_fwft.o
diff --git a/lib/sbi/sbi_ecall_wdt.c b/lib/sbi/sbi_ecall_wdt.c
new file mode 100644
index 00000000..81b3e174
--- /dev/null
+++ b/lib/sbi/sbi_ecall_wdt.c
@@ -0,0 +1,79 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2026 Qualcomm Inc.
+ *
+ * Authors:
+ * Prajwal N <prajwal.n at oss.qualcomm.com>
+ */
+
+#include <sbi/sbi_ecall.h>
+#include <sbi/sbi_ecall_interface.h>
+#include <sbi/sbi_error.h>
+#include <sbi/sbi_trap.h>
+#include <sbi/sbi_wdt.h>
+
+/**
+ * OpenSBI watchdog ecall handler
+ * @param extid OpenSBI extension ID
+ * @param funcid OpenSBI function ID corresponding to the extension ID
+ * @param regs Trap registers for arguments
+ * @param out Carry the return value
+ * @return integer error value
+ */
+static int sbi_ecall_wdt_handler(unsigned long extid, unsigned long funcid,
+ struct sbi_trap_regs *regs,
+ struct sbi_ecall_return *out)
+{
+ int ret;
+ u32 attribute_value = 0;
+ ret = SBI_ERR_FAILED;
+
+ switch (funcid) {
+ case SBI_EXT_WATCHDOG_READ_ATTRIBUTE:
+ ret = sbi_watchdog_read_attribute(regs->a0, &attribute_value);
+ out->value = attribute_value;
+ break;
+
+ case SBI_EXT_WATCHDOG_WRITE_ATTRIBUTE:
+ ret = sbi_watchdog_write_attribute(regs->a0, regs->a1);
+ break;
+
+ case SBI_EXT_WATCHDOG_WRITE_NOTIF_MSI_MESSAGE:
+ ret = sbi_watchdog_write_notif_msi_message(regs->a0, regs->a1, regs->a2);
+ break;
+
+ case SBI_EXT_WATCHDOG_START:
+ ret = sbi_watchdog_start();
+ break;
+
+ case SBI_EXT_WATCHDOG_STOP:
+ ret = sbi_watchdog_stop();
+ break;
+
+ case SBI_EXT_WATCHDOG_PAT:
+ ret = sbi_watchdog_pat();
+ break;
+
+ default:
+ break;
+ }
+
+ return ret;
+}
+
+struct sbi_ecall_extension ecall_wdt;
+
+static int sbi_ecall_wdt_register_extensions(void)
+{
+ return sbi_ecall_register_extension(&ecall_wdt);
+}
+
+struct sbi_ecall_extension ecall_wdt = {
+ .name = "sbi-wdt",
+ .extid_start = SBI_EXT_WDT,
+ .extid_end = SBI_EXT_WDT,
+ .experimental = true,
+ .register_extensions = sbi_ecall_wdt_register_extensions,
+ .handle = sbi_ecall_wdt_handler,
+};
--
2.43.0
More information about the opensbi
mailing list