drivers/watchdog/gunyah_wdt.c
Source file repositories/reference/linux-study-clean/drivers/watchdog/gunyah_wdt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/watchdog/gunyah_wdt.c- Extension
.c- Size
- 6689 bytes
- Lines
- 262
- Domain
- Driver Families
- Bucket
- drivers/watchdog
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/arm-smccc.hlinux/delay.hlinux/errno.hlinux/kernel.hlinux/mod_devicetable.hlinux/module.hlinux/platform_device.hlinux/watchdog.h
Detected Declarations
enum gunyah_errorfunction gunyah_error_remapfunction gunyah_wdt_callfunction gunyah_wdt_startfunction gunyah_wdt_stopfunction gunyah_wdt_pingfunction gunyah_wdt_set_timeoutfunction gunyah_wdt_get_time_since_last_pingfunction gunyah_wdt_get_timeleftfunction gunyah_wdt_restartfunction gunyah_wdt_probefunction gunyah_wdt_removefunction gunyah_wdt_suspendfunction gunyah_wdt_resume
Annotated Snippet
// 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;
Annotation
- Immediate include surface: `linux/arm-smccc.h`, `linux/delay.h`, `linux/errno.h`, `linux/kernel.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/platform_device.h`, `linux/watchdog.h`.
- Detected declarations: `enum gunyah_error`, `function gunyah_error_remap`, `function gunyah_wdt_call`, `function gunyah_wdt_start`, `function gunyah_wdt_stop`, `function gunyah_wdt_ping`, `function gunyah_wdt_set_timeout`, `function gunyah_wdt_get_time_since_last_ping`, `function gunyah_wdt_get_timeleft`, `function gunyah_wdt_restart`.
- Atlas domain: Driver Families / drivers/watchdog.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.