From: Guenter Roeck <linux@roeck-us.net>
To: hrishabh.rajput@oss.qualcomm.com,
Bjorn Andersson <andersson@kernel.org>,
Konrad Dybcio <konradybcio@kernel.org>,
Wim Van Sebroeck <wim@linux-watchdog.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>
Cc: linux-arm-msm@vger.kernel.org, linux-watchdog@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
Pavan Kondeti <pavan.kondeti@oss.qualcomm.com>,
Neil Armstrong <neil.armstrong@linaro.org>,
Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Subject: Re: [PATCH v7 2/2] watchdog: Add driver for Gunyah Watchdog
Date: Fri, 14 Nov 2025 05:36:02 -0800 [thread overview]
Message-ID: <55fba1a9-a24d-40b7-b97a-171f4a60a7dc@roeck-us.net> (raw)
In-Reply-To: <20251114-gunyah_watchdog-v7-2-f5c155b941d5@oss.qualcomm.com>
On 11/13/25 23:57, Hrishabh Rajput via B4 Relay wrote:
> From: Hrishabh Rajput <hrishabh.rajput@oss.qualcomm.com>
>
> On Qualcomm SoCs running under the Gunyah hypervisor, access to watchdog
> through MMIO is not available on all platforms. 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.
>
> Add driver to support the SMC-based watchdog provided by the Gunyah
> Hypervisor. Device registration is done in the QCOM SCM driver after
> checks to restrict the watchdog initialization to Qualcomm devices
> running under Gunyah.
>
> Gunyah watchdog is not a hardware but an SMC-based vendor-specific
> hypervisor interface provided by the Gunyah hypervisor. The design
> involving QCOM SCM driver for registering the platform device has been
> devised to avoid adding non-hardware nodes to devicetree.
>
> Signed-off-by: Hrishabh Rajput <hrishabh.rajput@oss.qualcomm.com>
> ---
> MAINTAINERS | 1 +
> drivers/watchdog/Kconfig | 13 +++
> drivers/watchdog/Makefile | 1 +
> drivers/watchdog/gunyah_wdt.c | 260 ++++++++++++++++++++++++++++++++++++++++++
> 4 files changed, 275 insertions(+)
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index ddecf1ef3bed..f80e762aa324 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -3215,6 +3215,7 @@ 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*
> diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
> index 05008d937e40..bc6db9a1c116 100644
> --- a/drivers/watchdog/Kconfig
> +++ b/drivers/watchdog/Kconfig
> @@ -2354,4 +2354,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 gunyah_wdt.
> +
> endif # WATCHDOG
> diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
> index b680e4d3c1bc..1215efb7816d 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..addfd1733ad1
> --- /dev/null
> +++ b/drivers/watchdog/gunyah_wdt.c
> @@ -0,0 +1,260 @@
> +// 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/errno.h>
> +#include <linux/kernel.h>
> +#include <linux/mod_devicetable.h>
> +#include <linux/module.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)
> +
> +enum gunyah_error {
> + GUNYAH_ERROR_OK = 0,
> + GUNYAH_ERROR_UNIMPLEMENTED = -1,
> + GUNYAH_ERROR_ARG_INVAL = 1,
> +};
> +
> +/**
> + * 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_UNIMPLEMENTED:
> + return -EOPNOTSUPP;
> + default:
> + return -EINVAL;
> + }
> +}
> +
> +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)
> +{
> + unsigned int timeout_ms;
> + struct device *dev = wdd->parent;
> + int ret;
> +
> + ret = gunyah_wdt_call(GUNYAH_WDT_CONTROL, WDT_CTRL_DISABLE, 0);
> + if (ret && watchdog_active(wdd)) {
> + dev_err(dev, "%s: Failed to stop gunyah wdt %d\n", __func__, ret);
> + return ret;
> + }
> +
> + timeout_ms = wdd->timeout * 1000;
> + ret = gunyah_wdt_call(GUNYAH_WDT_SET_TIME, timeout_ms, timeout_ms);
> + if (ret) {
> + dev_err(dev, "%s: Failed to set timeout for gunyah wdt %d\n",
> + __func__, ret);
> + return ret;
> + }
> +
> + ret = gunyah_wdt_call(GUNYAH_WDT_CONTROL, WDT_CTRL_ENABLE, 0);
> + if (ret)
> + dev_err(dev, "%s: Failed to start gunyah wdt %d\n", __func__, ret);
> +
> + return ret;
> +}
> +
> +static int gunyah_wdt_stop(struct watchdog_device *wdd)
> +{
> + return gunyah_wdt_call(GUNYAH_WDT_CONTROL, WDT_CTRL_DISABLE, 0);
> +}
> +
> +static int gunyah_wdt_ping(struct watchdog_device *wdd)
> +{
> + return gunyah_wdt_call(GUNYAH_WDT_PING, 0, 0);
> +}
> +
> +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_get_time_since_last_ping(void)
> +{
> + struct arm_smccc_res res;
> +
> + arm_smccc_1_1_smc(GUNYAH_WDT_STATUS, 0, 0, &res);
> + if (res.a0)
> + return gunyah_error_remap(res.a0);
> +
> + return res.a2 / 1000;
> +}
> +
> +static unsigned int gunyah_wdt_get_timeleft(struct watchdog_device *wdd)
> +{
> + int seconds_since_last_ping;
> +
> + seconds_since_last_ping = gunyah_wdt_get_time_since_last_ping();
> + if (seconds_since_last_ping < 0 ||
> + 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)
> +{
> + /* Set timeout to 1ms and send a ping */
> + gunyah_wdt_call(GUNYAH_WDT_CONTROL, WDT_CTRL_DISABLE, 0);
> + gunyah_wdt_call(GUNYAH_WDT_SET_TIME, 1, 1);
> + gunyah_wdt_call(GUNYAH_WDT_CONTROL, WDT_CTRL_ENABLE, 0);
> + gunyah_wdt_call(GUNYAH_WDT_PING, 0, 0);
> +
> + /* Wait to make sure reset occurs */
> + mdelay(100);
> +
> + return 0;
> +}
> +
> +static const struct watchdog_info gunyah_wdt_info = {
> + .identity = "Gunyah Watchdog",
> + .options = WDIOF_SETTIMEOUT
> + | 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,
> + .get_timeleft = gunyah_wdt_get_timeleft,
> + .restart = gunyah_wdt_restart
> +};
> +
> +static int gunyah_wdt_probe(struct platform_device *pdev)
> +{
> + struct watchdog_device *wdd;
> + struct device *dev = &pdev->dev;
> + int ret;
> +
> + ret = gunyah_wdt_call(GUNYAH_WDT_STATUS, 0, 0);
> + if (ret) {
> + dev_err_probe(dev, ret, "status check failed\n");
> + return ret;
From the context, it seems to me that this should fail silently with -ENODEV
if the function returns -EOPNOTSUPP (not implemented).
Guenter
next prev parent reply other threads:[~2025-11-14 13:36 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-14 7:57 [PATCH v7 0/2] Add support for Gunyah Watchdog Hrishabh Rajput via B4 Relay
2025-11-14 7:57 ` [PATCH v7 1/2] firmware: qcom: scm: Register gunyah watchdog device Hrishabh Rajput via B4 Relay
2025-11-14 11:10 ` Dmitry Baryshkov
2025-11-14 7:57 ` [PATCH v7 2/2] watchdog: Add driver for Gunyah Watchdog Hrishabh Rajput via B4 Relay
2025-11-14 13:36 ` Guenter Roeck [this message]
2025-11-17 14:45 ` [PATCH v7 0/2] Add support " Neil Armstrong
2025-11-18 5:11 ` Shivendra Pratap
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=55fba1a9-a24d-40b7-b97a-171f4a60a7dc@roeck-us.net \
--to=linux@roeck-us.net \
--cc=andersson@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.baryshkov@oss.qualcomm.com \
--cc=hrishabh.rajput@oss.qualcomm.com \
--cc=konradybcio@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-watchdog@vger.kernel.org \
--cc=neil.armstrong@linaro.org \
--cc=pavan.kondeti@oss.qualcomm.com \
--cc=robh@kernel.org \
--cc=wim@linux-watchdog.org \
/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;
as well as URLs for NNTP newsgroup(s).