* [PATCH 0/2] Add support for Gunyah Watchdog
@ 2025-09-03 19:33 Hrishabh Rajput via B4 Relay
2025-09-03 19:33 ` [PATCH 1/2] dt-bindings: Add binding for gunyah watchdog Hrishabh Rajput via B4 Relay
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Hrishabh Rajput via B4 Relay @ 2025-09-03 19:33 UTC (permalink / raw)
To: Bjorn Andersson, Konrad Dybcio, Wim Van Sebroeck, Guenter Roeck,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: linux-arm-msm, linux-watchdog, devicetree, linux-kernel,
Hrishabh Rajput
Gunyah is a Type-I hypervisor which was introduced in the patch series
[1]. It is an open source hypervisor. The source repo is available at
[2].
The Gunyah Hypervisor doesn't allow its Virtual Machines to directly
access the MMIO watchdog. It either provides the fully emulated MMIO
based watchdog interface or the SMC-based watchdog interface depending
on the hypervisor configuration.
The SMC-based watchdog follows ARM's SMC Calling Convention (SMCCC)
version 1.1 and uses Vendor Specific Hypervisor Service Calls space.
This patch series adds support for the SMC-based watchdog interface
provided by the Gunyah Hypervisor. The driver supports start/stop
operations, timeout and pretimeout configuration, pretimeout interrupt
handling and system restart via watchdog.
This series is tested on SM8750 platform.
[1]
https://lore.kernel.org/all/20240222-gunyah-v17-0-1e9da6763d38@quicinc.com/
[2]
https://github.com/quic/gunyah-hypervisor
Signed-off-by: Hrishabh Rajput <hrishabh.rajput@oss.qualcomm.com>
---
Hrishabh Rajput (2):
dt-bindings: Add binding for gunyah watchdog
watchdog: Add driver for Gunyah Watchdog
.../bindings/watchdog/qcom,gh-watchdog.yaml | 76 ++++++
MAINTAINERS | 3 +
drivers/watchdog/Kconfig | 13 +
drivers/watchdog/Makefile | 1 +
drivers/watchdog/gunyah_wdt.c | 268 +++++++++++++++++++++
include/linux/gunyah_errno.h | 77 ++++++
6 files changed, 438 insertions(+)
---
base-commit: 038d61fd642278bab63ee8ef722c50d10ab01e8f
change-id: 20250903-gunyah_watchdog-2d2649438e29
Best regards,
--
Hrishabh Rajput <hrishabh.rajput@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/2] dt-bindings: Add binding for gunyah watchdog
2025-09-03 19:33 [PATCH 0/2] Add support for Gunyah Watchdog Hrishabh Rajput via B4 Relay
@ 2025-09-03 19:33 ` Hrishabh Rajput via B4 Relay
2025-09-03 23:27 ` Rob Herring (Arm)
2025-09-03 19:34 ` [PATCH 2/2] watchdog: Add driver for Gunyah Watchdog Hrishabh Rajput via B4 Relay
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Hrishabh Rajput via B4 Relay @ 2025-09-03 19:33 UTC (permalink / raw)
To: Bjorn Andersson, Konrad Dybcio, Wim Van Sebroeck, Guenter Roeck,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: linux-arm-msm, linux-watchdog, devicetree, linux-kernel,
Hrishabh Rajput
From: Hrishabh Rajput <hrishabh.rajput@oss.qualcomm.com>
The Gunyah Hypervisor applies a devicetree overlay providing the
pretimeout interrupt for the Gunyah Watchdog that it will be using to
notify watchdog's pretimeout event. Add the DT bindings that Gunyah
adheres to for the hypervisor and watchdog.
Signed-off-by: Hrishabh Rajput <hrishabh.rajput@oss.qualcomm.com>
---
.../bindings/watchdog/qcom,gh-watchdog.yaml | 76 ++++++++++++++++++++++
MAINTAINERS | 1 +
2 files changed, 77 insertions(+)
diff --git a/Documentation/devicetree/bindings/watchdog/qcom,gh-watchdog.yaml b/Documentation/devicetree/bindings/watchdog/qcom,gh-watchdog.yaml
new file mode 100644
index 000000000000..bde8438c6242
--- /dev/null
+++ b/Documentation/devicetree/bindings/watchdog/qcom,gh-watchdog.yaml
@@ -0,0 +1,76 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/watchdog/qcom,gh-watchdog.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm Gunyah Virtual Watchdog
+
+maintainers:
+ - Hrishabh Rajput <hrishabh.rajput@oss.qualcomm.com>
+
+description: |+
+ The Gunyah Hypervisor provides an SMC-based watchdog interface for its virtual
+ machines. The virtual machines use this information to determine the
+ pretimeout IRQ which the hypervisor will be using to communicate pretimeout
+ event.
+ See also: [1]
+
+ [1]: https://github.com/quic/gunyah-resource-manager/blob/1b23ceb0dfa010b3b6b5a5f7a4ec1e95b93ab99d/src/vm_creation/dto_construct.c#L519
+
+properties:
+ compatible:
+ allOf:
+ - const: gunyah-hypervisor
+ - const: simple-bus
+
+ "#address-cells":
+ description: Number of cells needed to represent 64-bit capability IDs.
+ const: 2
+
+ "#size-cells":
+ description: must be 0, because capability IDs are not memory address
+ ranges and do not have a size.
+ const: 0
+
+patternProperties:
+ "^gh-watchdog":
+ type: object
+ description:
+ Watchdog node which provides information about the pretimeout IRQ which
+ will be used to communicate the pretimeout event.
+
+ properties:
+ compatible:
+ const: qcom,gh-watchdog
+
+ interrupts:
+ items:
+ description: Interrupt for the pretimeout.
+
+ additionalProperties: false
+
+ required:
+ - compatible
+ - interrupts
+
+additionalProperties: false
+
+required:
+ - compatible
+ - "#address-cells"
+ - "#size-cells"
+
+examples:
+ - |
+ #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+ hypervisor {
+ compatible = "gunyah-hypervisor", "simple-bus";
+ #address-cells = <2>;
+ #size-cells = <0>;
+
+ gh-watchdog {
+ compatible = "qcom,gh-watchdog";
+ interrupts = <GIC_SPI 0 IRQ_TYPE_EDGE_RISING>; /* Pretimeout IRQ */
+ };
diff --git a/MAINTAINERS b/MAINTAINERS
index c0b444e5fd5a..03b74513e4ac 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3076,6 +3076,7 @@ F: Documentation/devicetree/bindings/cache/qcom,llcc.yaml
F: Documentation/devicetree/bindings/firmware/qcom,scm.yaml
F: Documentation/devicetree/bindings/reserved-memory/qcom*
F: Documentation/devicetree/bindings/soc/qcom/
+F: Documentation/devicetree/bindings/watchdog/qcom,gh-watchdog.yaml
F: arch/arm/boot/dts/qcom/
F: arch/arm/configs/qcom_defconfig
F: arch/arm/mach-qcom/
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2] watchdog: Add driver for Gunyah Watchdog
2025-09-03 19:33 [PATCH 0/2] Add support for Gunyah Watchdog Hrishabh Rajput via B4 Relay
2025-09-03 19:33 ` [PATCH 1/2] dt-bindings: Add binding for gunyah watchdog Hrishabh Rajput via B4 Relay
@ 2025-09-03 19:34 ` Hrishabh Rajput via B4 Relay
2025-09-03 20:13 ` Bjorn Andersson
2025-09-04 0:10 ` [PATCH 0/2] Add support " Rob Herring
2025-09-04 7:13 ` Neil Armstrong
3 siblings, 1 reply; 7+ messages in thread
From: Hrishabh Rajput via B4 Relay @ 2025-09-03 19:34 UTC (permalink / raw)
To: Bjorn Andersson, Konrad Dybcio, Wim Van Sebroeck, Guenter Roeck,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: linux-arm-msm, linux-watchdog, devicetree, linux-kernel,
Hrishabh Rajput
From: Hrishabh Rajput <hrishabh.rajput@oss.qualcomm.com>
Add driver to support the SMC-based watchdog timer provided by the
Gunyah Hypervisor.
On Qualcomm SoCs running under the Gunyah hypervisor, access to watchdog
through MMIO is not available. Depending on the hypervisor
configuration, the watchdog is either fully emulated or exposed via
ARM's SMC Calling Conventions (SMCCC) through the Vendor Specific
Hypervisor Service Calls space.
When the SMC-based interface is enabled, a device tree overlay is used
to provide the pretimeout interrupt configuration.
Signed-off-by: Hrishabh Rajput <hrishabh.rajput@oss.qualcomm.com>
---
MAINTAINERS | 2 +
drivers/watchdog/Kconfig | 13 ++
drivers/watchdog/Makefile | 1 +
drivers/watchdog/gunyah_wdt.c | 268 ++++++++++++++++++++++++++++++++++++++++++
include/linux/gunyah_errno.h | 77 ++++++++++++
5 files changed, 361 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index 03b74513e4ac..5e491211d96c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3084,10 +3084,12 @@ F: arch/arm64/boot/dts/qcom/
F: drivers/bus/qcom*
F: drivers/firmware/qcom/
F: drivers/soc/qcom/
+F: drivers/watchdog/gunyah_wdt.c
F: include/dt-bindings/arm/qcom,ids.h
F: include/dt-bindings/firmware/qcom,scm.h
F: include/dt-bindings/soc/qcom*
F: include/linux/firmware/qcom
+F: include/linux/gunyah_errno.h
F: include/linux/soc/qcom/
F: include/soc/qcom/
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 0c25b2ed44eb..2fed83e06990 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -2343,4 +2343,17 @@ config KEEMBAY_WATCHDOG
To compile this driver as a module, choose M here: the
module will be called keembay_wdt.
+config GUNYAH_WATCHDOG
+ tristate "Qualcomm Gunyah Watchdog"
+ depends on ARCH_QCOM || COMPILE_TEST
+ depends on HAVE_ARM_SMCCC
+ select WATCHDOG_CORE
+ help
+ Say Y here to include support for watchdog timer provided by the
+ Gunyah hypervisor. The driver uses ARM SMC Calling Convention (SMCCC)
+ to interact with Gunyah Watchdog.
+
+ To compile this driver as a module, choose M here: the
+ module will be called gh_wdt.
+
endif # WATCHDOG
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index bbd4d62d2cc3..308379782bc3 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -102,6 +102,7 @@ obj-$(CONFIG_MSC313E_WATCHDOG) += msc313e_wdt.o
obj-$(CONFIG_APPLE_WATCHDOG) += apple_wdt.o
obj-$(CONFIG_SUNPLUS_WATCHDOG) += sunplus_wdt.o
obj-$(CONFIG_MARVELL_GTI_WDT) += marvell_gti_wdt.o
+obj-$(CONFIG_GUNYAH_WATCHDOG) += gunyah_wdt.o
# X86 (i386 + ia64 + x86_64) Architecture
obj-$(CONFIG_ACQUIRE_WDT) += acquirewdt.o
diff --git a/drivers/watchdog/gunyah_wdt.c b/drivers/watchdog/gunyah_wdt.c
new file mode 100644
index 000000000000..56e8e21510d3
--- /dev/null
+++ b/drivers/watchdog/gunyah_wdt.c
@@ -0,0 +1,268 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ */
+
+#include <linux/arm-smccc.h>
+#include <linux/delay.h>
+#include <linux/gunyah_errno.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/watchdog.h>
+
+#define GUNYAH_WDT_SMCCC_CALL_VAL(func_id) \
+ ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_32,\
+ ARM_SMCCC_OWNER_VENDOR_HYP, func_id)
+
+/* SMCCC function IDs for watchdog operations */
+#define GUNYAH_WDT_CONTROL GUNYAH_WDT_SMCCC_CALL_VAL(0x0005)
+#define GUNYAH_WDT_STATUS GUNYAH_WDT_SMCCC_CALL_VAL(0x0006)
+#define GUNYAH_WDT_PING GUNYAH_WDT_SMCCC_CALL_VAL(0x0007)
+#define GUNYAH_WDT_SET_TIME GUNYAH_WDT_SMCCC_CALL_VAL(0x0008)
+
+/*
+ * Control values for GUNYAH_WDT_CONTROL.
+ * Bit 0 is used to enable or disable the watchdog. If this bit is set,
+ * then the watchdog is enabled and vice versa.
+ * Bit 1 should always be set to 1 as this bit is reserved in Gunyah and
+ * it's expected to be 1.
+ */
+#define WDT_CTRL_ENABLE (BIT(1) | BIT(0))
+#define WDT_CTRL_DISABLE BIT(1)
+
+struct gunyah_wdt {
+ unsigned int pretimeout_irq;
+ struct watchdog_device wdd;
+};
+
+static int gunyah_wdt_call(unsigned long func_id, unsigned long arg1,
+ unsigned long arg2, struct arm_smccc_res *res)
+{
+ arm_smccc_1_1_smc(func_id, arg1, arg2, res);
+ return gunyah_error_remap(res->a0);
+}
+
+static int gunyah_wdt_start(struct watchdog_device *wdd)
+{
+ struct arm_smccc_res res;
+ unsigned int timeout_ms;
+ unsigned int pretimeout_ms;
+ int ret;
+
+ ret = gunyah_wdt_call(GUNYAH_WDT_CONTROL, WDT_CTRL_DISABLE, 0, &res);
+ if (ret)
+ return ret;
+
+ timeout_ms = wdd->timeout * 1000;
+ pretimeout_ms = wdd->pretimeout * 1000;
+ ret = gunyah_wdt_call(GUNYAH_WDT_SET_TIME,
+ pretimeout_ms, timeout_ms, &res);
+ if (ret)
+ return ret;
+
+ return gunyah_wdt_call(GUNYAH_WDT_CONTROL, WDT_CTRL_ENABLE, 0, &res);
+}
+
+static int gunyah_wdt_stop(struct watchdog_device *wdd)
+{
+ struct arm_smccc_res res;
+
+ return gunyah_wdt_call(GUNYAH_WDT_CONTROL, WDT_CTRL_DISABLE, 0, &res);
+}
+
+static int gunyah_wdt_ping(struct watchdog_device *wdd)
+{
+ struct arm_smccc_res res;
+
+ return gunyah_wdt_call(GUNYAH_WDT_PING, 0, 0, &res);
+}
+
+static int gunyah_wdt_set_timeout(struct watchdog_device *wdd,
+ unsigned int timeout_sec)
+{
+ wdd->timeout = timeout_sec;
+
+ if (watchdog_active(wdd))
+ return gunyah_wdt_start(wdd);
+
+ return 0;
+}
+
+static int gunyah_wdt_set_pretimeout(struct watchdog_device *wdd,
+ unsigned int pretimeout_sec)
+{
+ wdd->pretimeout = pretimeout_sec;
+
+ if (watchdog_active(wdd))
+ return gunyah_wdt_start(wdd);
+
+ return 0;
+}
+
+static unsigned int gunyah_wdt_get_timeleft(struct watchdog_device *wdd)
+{
+ struct arm_smccc_res res;
+ unsigned int seconds_since_last_ping;
+ int ret;
+
+ ret = gunyah_wdt_call(GUNYAH_WDT_STATUS, 0, 0, &res);
+ if (ret)
+ return 0;
+
+ seconds_since_last_ping = res.a2 / 1000;
+ if (seconds_since_last_ping > wdd->timeout)
+ return 0;
+
+ return wdd->timeout - seconds_since_last_ping;
+}
+
+static int gunyah_wdt_restart(struct watchdog_device *wdd,
+ unsigned long action, void *data)
+{
+ struct arm_smccc_res res;
+
+ /* Set timeout and pretimeout to 1ms and send a ping */
+ gunyah_wdt_call(GUNYAH_WDT_CONTROL, WDT_CTRL_ENABLE, 0, &res);
+ gunyah_wdt_call(GUNYAH_WDT_SET_TIME, 1, 1, &res);
+ gunyah_wdt_call(GUNYAH_WDT_PING, 0, 0, &res);
+
+ /* Wait to make sure reset occurs */
+ mdelay(100);
+
+ return 0;
+}
+
+static const struct watchdog_info gunyah_wdt_info = {
+ .identity = "Gunyah Watchdog",
+ .firmware_version = 0,
+ .options = WDIOF_SETTIMEOUT
+ | WDIOF_PRETIMEOUT
+ | WDIOF_KEEPALIVEPING
+ | WDIOF_MAGICCLOSE,
+};
+
+static const struct watchdog_ops gunyah_wdt_ops = {
+ .owner = THIS_MODULE,
+ .start = gunyah_wdt_start,
+ .stop = gunyah_wdt_stop,
+ .ping = gunyah_wdt_ping,
+ .set_timeout = gunyah_wdt_set_timeout,
+ .set_pretimeout = gunyah_wdt_set_pretimeout,
+ .get_timeleft = gunyah_wdt_get_timeleft,
+ .restart = gunyah_wdt_restart
+};
+
+static irqreturn_t gunyah_wdt_pretimeout_handler(int irq, void *arg)
+{
+ struct watchdog_device *wdd = arg;
+
+ watchdog_notify_pretimeout(wdd);
+
+ return IRQ_HANDLED;
+}
+
+static int gunyah_wdt_probe(struct platform_device *pdev)
+{
+ struct gunyah_wdt *wdt;
+ struct device *dev = &pdev->dev;
+ int ret;
+
+ wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL);
+ if (!wdt)
+ return -ENOMEM;
+
+ wdt->wdd.info = &gunyah_wdt_info;
+ wdt->wdd.ops = &gunyah_wdt_ops;
+ wdt->wdd.parent = dev;
+
+ /*
+ * Although Gunyah expects 16-bit unsigned int values as timeout values
+ * in milliseconds, values above 0x8000 are reserved. This limits the
+ * max timeout value to 32 seconds.
+ */
+ wdt->wdd.max_timeout = 32; /* seconds */
+ wdt->wdd.min_timeout = 1; /* seconds */
+ wdt->wdd.timeout = wdt->wdd.max_timeout;
+ wdt->wdd.pretimeout = wdt->wdd.timeout - 2;
+
+ gunyah_wdt_stop(&wdt->wdd);
+ watchdog_init_timeout(&wdt->wdd, 0, dev);
+
+ platform_set_drvdata(pdev, wdt);
+
+ watchdog_set_restart_priority(&wdt->wdd, 0);
+ ret = devm_watchdog_register_device(dev, &wdt->wdd);
+ if (ret) {
+ dev_err(dev, "Failed to register watchdog device: %d\n", ret);
+ return ret;
+ }
+
+ /*
+ * Register the pretimeout irq as rising edge triggered irrespective of
+ * the irqflags passed by Gunyah to make the driver compatible with
+ * pretimeout governors like noop.
+ */
+ wdt->pretimeout_irq = platform_get_irq(pdev, 0);
+ ret = devm_request_irq(dev, wdt->pretimeout_irq,
+ gunyah_wdt_pretimeout_handler,
+ IRQF_TRIGGER_RISING,
+ "wdt_pretimeout", &wdt->wdd);
+ if (ret) {
+ dev_err(dev, "Failed to register pretimeout irq: %d\n", ret);
+ return ret;
+ }
+
+ dev_dbg(dev, "Gunyah watchdog registered\n");
+ return 0;
+}
+
+static int __maybe_unused gunyah_wdt_suspend(struct device *dev)
+{
+ struct gunyah_wdt *wdt = dev_get_drvdata(dev);
+
+ if (watchdog_active(&wdt->wdd))
+ gunyah_wdt_stop(&wdt->wdd);
+
+ return 0;
+}
+
+static int __maybe_unused gunyah_wdt_resume(struct device *dev)
+{
+ struct gunyah_wdt *wdt = dev_get_drvdata(dev);
+
+ if (watchdog_active(&wdt->wdd))
+ gunyah_wdt_start(&wdt->wdd);
+
+ return 0;
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(gunyah_wdt_pm_ops, gunyah_wdt_suspend, gunyah_wdt_resume);
+
+static const struct of_device_id gunyah_wdt_of_match[] = {
+ { .compatible = "qcom,gh-watchdog" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, gunyah_wdt_of_match);
+
+static struct platform_driver gunyah_wdt_driver = {
+ .probe = gunyah_wdt_probe,
+ .driver = {
+ .name = "gunyah-wdt",
+ .of_match_table = gunyah_wdt_of_match,
+ .pm = pm_sleep_ptr(&gunyah_wdt_pm_ops),
+ },
+};
+
+static int __init gunyah_wdt_init(void)
+{
+ return platform_driver_register(&gunyah_wdt_driver);
+}
+
+module_init(gunyah_wdt_init);
+
+MODULE_DESCRIPTION("Gunyah Watchdog Driver");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/gunyah_errno.h b/include/linux/gunyah_errno.h
new file mode 100644
index 000000000000..518228e333bd
--- /dev/null
+++ b/include/linux/gunyah_errno.h
@@ -0,0 +1,77 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ */
+
+#ifndef _LINUX_GUNYAH_ERRNO_H
+#define _LINUX_GUNYAH_ERRNO_H
+
+#include <linux/errno.h>
+
+enum gunyah_error {
+ GUNYAH_ERROR_OK = 0,
+ GUNYAH_ERROR_UNIMPLEMENTED = -1,
+ GUNYAH_ERROR_RETRY = -2,
+
+ GUNYAH_ERROR_ARG_INVAL = 1,
+ GUNYAH_ERROR_ARG_SIZE = 2,
+ GUNYAH_ERROR_ARG_ALIGN = 3,
+
+ GUNYAH_ERROR_NOMEM = 10,
+
+ GUNYAH_ERROR_ADDR_OVFL = 20,
+ GUNYAH_ERROR_ADDR_UNFL = 21,
+ GUNYAH_ERROR_ADDR_INVAL = 22,
+
+ GUNYAH_ERROR_DENIED = 30,
+ GUNYAH_ERROR_BUSY = 31,
+ GUNYAH_ERROR_IDLE = 32,
+
+ GUNYAH_ERROR_IRQ_BOUND = 40,
+ GUNYAH_ERROR_IRQ_UNBOUND = 41,
+
+ GUNYAH_ERROR_CSPACE_CAP_NULL = 50,
+ GUNYAH_ERROR_CSPACE_CAP_REVOKED = 51,
+ GUNYAH_ERROR_CSPACE_WRONG_OBJ_TYPE = 52,
+ GUNYAH_ERROR_CSPACE_INSUF_RIGHTS = 53,
+ GUNYAH_ERROR_CSPACE_FULL = 54,
+
+ GUNYAH_ERROR_MSGQUEUE_EMPTY = 60,
+ GUNYAH_ERROR_MSGQUEUE_FULL = 61,
+};
+
+/**
+ * gunyah_error_remap() - Remap Gunyah hypervisor errors into a Linux error code
+ * @gunyah_error: Gunyah hypercall return value
+ */
+static inline int gunyah_error_remap(enum gunyah_error gunyah_error)
+{
+ switch (gunyah_error) {
+ case GUNYAH_ERROR_OK:
+ return 0;
+ case GUNYAH_ERROR_NOMEM:
+ return -ENOMEM;
+ case GUNYAH_ERROR_DENIED:
+ case GUNYAH_ERROR_CSPACE_CAP_NULL:
+ case GUNYAH_ERROR_CSPACE_CAP_REVOKED:
+ case GUNYAH_ERROR_CSPACE_WRONG_OBJ_TYPE:
+ case GUNYAH_ERROR_CSPACE_INSUF_RIGHTS:
+ case GUNYAH_ERROR_CSPACE_FULL:
+ return -EACCES;
+ case GUNYAH_ERROR_BUSY:
+ case GUNYAH_ERROR_IDLE:
+ return -EBUSY;
+ case GUNYAH_ERROR_IRQ_BOUND:
+ case GUNYAH_ERROR_IRQ_UNBOUND:
+ case GUNYAH_ERROR_MSGQUEUE_FULL:
+ case GUNYAH_ERROR_MSGQUEUE_EMPTY:
+ return -EIO;
+ case GUNYAH_ERROR_UNIMPLEMENTED:
+ case GUNYAH_ERROR_RETRY:
+ return -EOPNOTSUPP;
+ default:
+ return -EINVAL;
+ }
+}
+
+#endif
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] watchdog: Add driver for Gunyah Watchdog
2025-09-03 19:34 ` [PATCH 2/2] watchdog: Add driver for Gunyah Watchdog Hrishabh Rajput via B4 Relay
@ 2025-09-03 20:13 ` Bjorn Andersson
0 siblings, 0 replies; 7+ messages in thread
From: Bjorn Andersson @ 2025-09-03 20:13 UTC (permalink / raw)
To: hrishabh.rajput
Cc: Konrad Dybcio, Wim Van Sebroeck, Guenter Roeck, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, linux-arm-msm, linux-watchdog,
devicetree, linux-kernel
On Wed, Sep 03, 2025 at 07:34:00PM +0000, Hrishabh Rajput via B4 Relay wrote:
> From: Hrishabh Rajput <hrishabh.rajput@oss.qualcomm.com>
>
> Add driver to support the SMC-based watchdog timer provided by the
> Gunyah Hypervisor.
>
Start the commit message with a problem description, end with a
technical description of the solution. I.e. move this paragraph down.
> On Qualcomm SoCs running under the Gunyah hypervisor, access to watchdog
> through MMIO is not available. Depending on the hypervisor
> configuration, the watchdog is either fully emulated or exposed via
> ARM's SMC Calling Conventions (SMCCC) through the Vendor Specific
> Hypervisor Service Calls space.
>
> When the SMC-based interface is enabled, a device tree overlay is used
> to provide the pretimeout interrupt configuration.
>
> Signed-off-by: Hrishabh Rajput <hrishabh.rajput@oss.qualcomm.com>
[..]
> diff --git a/drivers/watchdog/gunyah_wdt.c b/drivers/watchdog/gunyah_wdt.c
[..]
> +#define GUNYAH_WDT_SMCCC_CALL_VAL(func_id) \
> + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_32,\
> + ARM_SMCCC_OWNER_VENDOR_HYP, func_id)
> +
> +/* SMCCC function IDs for watchdog operations */
> +#define GUNYAH_WDT_CONTROL GUNYAH_WDT_SMCCC_CALL_VAL(0x0005)
> +#define GUNYAH_WDT_STATUS GUNYAH_WDT_SMCCC_CALL_VAL(0x0006)
> +#define GUNYAH_WDT_PING GUNYAH_WDT_SMCCC_CALL_VAL(0x0007)
Uneven indentation.
> +#define GUNYAH_WDT_SET_TIME GUNYAH_WDT_SMCCC_CALL_VAL(0x0008)
> +
> +/*
> + * Control values for GUNYAH_WDT_CONTROL.
> + * Bit 0 is used to enable or disable the watchdog. If this bit is set,
> + * then the watchdog is enabled and vice versa.
> + * Bit 1 should always be set to 1 as this bit is reserved in Gunyah and
> + * it's expected to be 1.
> + */
> +#define WDT_CTRL_ENABLE (BIT(1) | BIT(0))
> +#define WDT_CTRL_DISABLE BIT(1)
> +
> +struct gunyah_wdt {
> + unsigned int pretimeout_irq;
This is only used momentarily in gunyah_wdt_probe(), make it a local
variable.
> + struct watchdog_device wdd;
Which means that gunyah_wdt is just watchdog_device, so you can drop
gunyah_wdt completely, and put wdd directly in drvdata.
> +};
> +
[..]
> +static int __init gunyah_wdt_init(void)
> +{
> + return platform_driver_register(&gunyah_wdt_driver);
> +}
> +
> +module_init(gunyah_wdt_init);
module_platform_driver(gunyah_wdt_driver);
> +
> +MODULE_DESCRIPTION("Gunyah Watchdog Driver");
> +MODULE_LICENSE("GPL");
> diff --git a/include/linux/gunyah_errno.h b/include/linux/gunyah_errno.h
> new file mode 100644
> index 000000000000..518228e333bd
> --- /dev/null
> +++ b/include/linux/gunyah_errno.h
> @@ -0,0 +1,77 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +/*
> + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
> + */
Isn't this content solely used from within gunyah_wdt.c? Why is it a
separate header file? Just move it into the c-file.
Regards,
Bjorn
> +
> +#ifndef _LINUX_GUNYAH_ERRNO_H
> +#define _LINUX_GUNYAH_ERRNO_H
> +
> +#include <linux/errno.h>
> +
> +enum gunyah_error {
> + GUNYAH_ERROR_OK = 0,
> + GUNYAH_ERROR_UNIMPLEMENTED = -1,
> + GUNYAH_ERROR_RETRY = -2,
> +
> + GUNYAH_ERROR_ARG_INVAL = 1,
> + GUNYAH_ERROR_ARG_SIZE = 2,
> + GUNYAH_ERROR_ARG_ALIGN = 3,
> +
> + GUNYAH_ERROR_NOMEM = 10,
> +
> + GUNYAH_ERROR_ADDR_OVFL = 20,
> + GUNYAH_ERROR_ADDR_UNFL = 21,
> + GUNYAH_ERROR_ADDR_INVAL = 22,
> +
> + GUNYAH_ERROR_DENIED = 30,
> + GUNYAH_ERROR_BUSY = 31,
> + GUNYAH_ERROR_IDLE = 32,
> +
> + GUNYAH_ERROR_IRQ_BOUND = 40,
> + GUNYAH_ERROR_IRQ_UNBOUND = 41,
> +
> + GUNYAH_ERROR_CSPACE_CAP_NULL = 50,
> + GUNYAH_ERROR_CSPACE_CAP_REVOKED = 51,
> + GUNYAH_ERROR_CSPACE_WRONG_OBJ_TYPE = 52,
> + GUNYAH_ERROR_CSPACE_INSUF_RIGHTS = 53,
> + GUNYAH_ERROR_CSPACE_FULL = 54,
> +
> + GUNYAH_ERROR_MSGQUEUE_EMPTY = 60,
> + GUNYAH_ERROR_MSGQUEUE_FULL = 61,
> +};
> +
> +/**
> + * gunyah_error_remap() - Remap Gunyah hypervisor errors into a Linux error code
> + * @gunyah_error: Gunyah hypercall return value
> + */
> +static inline int gunyah_error_remap(enum gunyah_error gunyah_error)
> +{
> + switch (gunyah_error) {
> + case GUNYAH_ERROR_OK:
> + return 0;
> + case GUNYAH_ERROR_NOMEM:
> + return -ENOMEM;
> + case GUNYAH_ERROR_DENIED:
> + case GUNYAH_ERROR_CSPACE_CAP_NULL:
> + case GUNYAH_ERROR_CSPACE_CAP_REVOKED:
> + case GUNYAH_ERROR_CSPACE_WRONG_OBJ_TYPE:
> + case GUNYAH_ERROR_CSPACE_INSUF_RIGHTS:
> + case GUNYAH_ERROR_CSPACE_FULL:
> + return -EACCES;
> + case GUNYAH_ERROR_BUSY:
> + case GUNYAH_ERROR_IDLE:
> + return -EBUSY;
> + case GUNYAH_ERROR_IRQ_BOUND:
> + case GUNYAH_ERROR_IRQ_UNBOUND:
> + case GUNYAH_ERROR_MSGQUEUE_FULL:
> + case GUNYAH_ERROR_MSGQUEUE_EMPTY:
> + return -EIO;
> + case GUNYAH_ERROR_UNIMPLEMENTED:
> + case GUNYAH_ERROR_RETRY:
> + return -EOPNOTSUPP;
> + default:
> + return -EINVAL;
> + }
> +}
> +
> +#endif
>
> --
> 2.43.0
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] dt-bindings: Add binding for gunyah watchdog
2025-09-03 19:33 ` [PATCH 1/2] dt-bindings: Add binding for gunyah watchdog Hrishabh Rajput via B4 Relay
@ 2025-09-03 23:27 ` Rob Herring (Arm)
0 siblings, 0 replies; 7+ messages in thread
From: Rob Herring (Arm) @ 2025-09-03 23:27 UTC (permalink / raw)
To: Hrishabh Rajput
Cc: Konrad Dybcio, Guenter Roeck, Krzysztof Kozlowski, Conor Dooley,
devicetree, linux-arm-msm, linux-watchdog, linux-kernel,
Bjorn Andersson, Wim Van Sebroeck
On Wed, 03 Sep 2025 19:33:59 +0000, Hrishabh Rajput wrote:
> The Gunyah Hypervisor applies a devicetree overlay providing the
> pretimeout interrupt for the Gunyah Watchdog that it will be using to
> notify watchdog's pretimeout event. Add the DT bindings that Gunyah
> adheres to for the hypervisor and watchdog.
>
> Signed-off-by: Hrishabh Rajput <hrishabh.rajput@oss.qualcomm.com>
> ---
> .../bindings/watchdog/qcom,gh-watchdog.yaml | 76 ++++++++++++++++++++++
> MAINTAINERS | 1 +
> 2 files changed, 77 insertions(+)
>
My bot found errors running 'make dt_binding_check' on your patch:
yamllint warnings/errors:
dtschema/dtc warnings/errors:
Error: Documentation/devicetree/bindings/watchdog/qcom,gh-watchdog.example.dts:37.3-38.1 syntax error
FATAL ERROR: Unable to parse input tree
make[2]: *** [scripts/Makefile.dtbs:131: Documentation/devicetree/bindings/watchdog/qcom,gh-watchdog.example.dtb] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [/builds/robherring/dt-review-ci/linux/Makefile:1519: dt_binding_check] Error 2
make: *** [Makefile:248: __sub-make] Error 2
doc reference errors (make refcheckdocs):
See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/20250903-gunyah_watchdog-v1-1-3ae690530e4b@oss.qualcomm.com
The base for the series is generally the latest rc1. A different dependency
should be noted in *this* patch.
If you already ran 'make dt_binding_check' and didn't see the above
error(s), then make sure 'yamllint' is installed and dt-schema is up to
date:
pip3 install dtschema --upgrade
Please check and re-submit after running the above command yourself. Note
that DT_SCHEMA_FILES can be set to your schema file to speed up checking
your schema. However, it must be unset to test all examples with your schema.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/2] Add support for Gunyah Watchdog
2025-09-03 19:33 [PATCH 0/2] Add support for Gunyah Watchdog Hrishabh Rajput via B4 Relay
2025-09-03 19:33 ` [PATCH 1/2] dt-bindings: Add binding for gunyah watchdog Hrishabh Rajput via B4 Relay
2025-09-03 19:34 ` [PATCH 2/2] watchdog: Add driver for Gunyah Watchdog Hrishabh Rajput via B4 Relay
@ 2025-09-04 0:10 ` Rob Herring
2025-09-04 7:13 ` Neil Armstrong
3 siblings, 0 replies; 7+ messages in thread
From: Rob Herring @ 2025-09-04 0:10 UTC (permalink / raw)
To: Hrishabh Rajput
Cc: Bjorn Andersson, Konrad Dybcio, Wim Van Sebroeck, Guenter Roeck,
Krzysztof Kozlowski, Conor Dooley, linux-arm-msm, linux-watchdog,
devicetree, linux-kernel
On Wed, Sep 03, 2025 at 07:33:58PM +0000, Hrishabh Rajput wrote:
> Gunyah is a Type-I hypervisor which was introduced in the patch series
> [1]. It is an open source hypervisor. The source repo is available at
> [2].
>
> The Gunyah Hypervisor doesn't allow its Virtual Machines to directly
> access the MMIO watchdog. It either provides the fully emulated MMIO
> based watchdog interface or the SMC-based watchdog interface depending
> on the hypervisor configuration.
EFI provides a standard watchdog interface. Why can't you use that?
> The SMC-based watchdog follows ARM's SMC Calling Convention (SMCCC)
> version 1.1 and uses Vendor Specific Hypervisor Service Calls space.
Is a watchdog really a hypervisor service? Couldn't a non-virtualized
OS want to call a watchdog (in secure mode) as well? But I don't know
how the SMCCC call space is divided up...
> This patch series adds support for the SMC-based watchdog interface
> provided by the Gunyah Hypervisor. The driver supports start/stop
> operations, timeout and pretimeout configuration, pretimeout interrupt
> handling and system restart via watchdog.
Shouldn't system restart be handled by PSCI?
Why can't you probe by trying to see if watchdog smc call succeeds to
see if there is a watchdog? Then you don't need DT for it.
Rob
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/2] Add support for Gunyah Watchdog
2025-09-03 19:33 [PATCH 0/2] Add support for Gunyah Watchdog Hrishabh Rajput via B4 Relay
` (2 preceding siblings ...)
2025-09-04 0:10 ` [PATCH 0/2] Add support " Rob Herring
@ 2025-09-04 7:13 ` Neil Armstrong
3 siblings, 0 replies; 7+ messages in thread
From: Neil Armstrong @ 2025-09-04 7:13 UTC (permalink / raw)
To: hrishabh.rajput, Bjorn Andersson, Konrad Dybcio, Wim Van Sebroeck,
Guenter Roeck, Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: linux-arm-msm, linux-watchdog, devicetree, linux-kernel
On 03/09/2025 21:33, Hrishabh Rajput via B4 Relay wrote:
> Gunyah is a Type-I hypervisor which was introduced in the patch series
> [1]. It is an open source hypervisor. The source repo is available at
> [2].
>
> The Gunyah Hypervisor doesn't allow its Virtual Machines to directly
> access the MMIO watchdog. It either provides the fully emulated MMIO
> based watchdog interface or the SMC-based watchdog interface depending
> on the hypervisor configuration.
> The SMC-based watchdog follows ARM's SMC Calling Convention (SMCCC)
> version 1.1 and uses Vendor Specific Hypervisor Service Calls space.
>
> This patch series adds support for the SMC-based watchdog interface
> provided by the Gunyah Hypervisor. The driver supports start/stop
> operations, timeout and pretimeout configuration, pretimeout interrupt
> handling and system restart via watchdog.
>
> This series is tested on SM8750 platform.
Would this driver work on older platforms like SM8550 & SM8650 ?
Thanks,
Neil
>
> [1]
> https://lore.kernel.org/all/20240222-gunyah-v17-0-1e9da6763d38@quicinc.com/
>
> [2]
> https://github.com/quic/gunyah-hypervisor
>
> Signed-off-by: Hrishabh Rajput <hrishabh.rajput@oss.qualcomm.com>
> ---
> Hrishabh Rajput (2):
> dt-bindings: Add binding for gunyah watchdog
> watchdog: Add driver for Gunyah Watchdog
>
> .../bindings/watchdog/qcom,gh-watchdog.yaml | 76 ++++++
> MAINTAINERS | 3 +
> drivers/watchdog/Kconfig | 13 +
> drivers/watchdog/Makefile | 1 +
> drivers/watchdog/gunyah_wdt.c | 268 +++++++++++++++++++++
> include/linux/gunyah_errno.h | 77 ++++++
> 6 files changed, 438 insertions(+)
> ---
> base-commit: 038d61fd642278bab63ee8ef722c50d10ab01e8f
> change-id: 20250903-gunyah_watchdog-2d2649438e29
>
> Best regards,
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-09-04 7:13 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-03 19:33 [PATCH 0/2] Add support for Gunyah Watchdog Hrishabh Rajput via B4 Relay
2025-09-03 19:33 ` [PATCH 1/2] dt-bindings: Add binding for gunyah watchdog Hrishabh Rajput via B4 Relay
2025-09-03 23:27 ` Rob Herring (Arm)
2025-09-03 19:34 ` [PATCH 2/2] watchdog: Add driver for Gunyah Watchdog Hrishabh Rajput via B4 Relay
2025-09-03 20:13 ` Bjorn Andersson
2025-09-04 0:10 ` [PATCH 0/2] Add support " Rob Herring
2025-09-04 7:13 ` Neil Armstrong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).