drivers/watchdog/arm_smc_wdt.c
Source file repositories/reference/linux-study-clean/drivers/watchdog/arm_smc_wdt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/watchdog/arm_smc_wdt.c- Extension
.c- Size
- 4518 bytes
- Lines
- 200
- 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/err.hlinux/module.hlinux/moduleparam.hlinux/of.hlinux/platform_device.hlinux/types.hlinux/watchdog.huapi/linux/psci.h
Detected Declarations
enum smcwd_callfunction smcwd_callfunction smcwd_pingfunction smcwd_get_timeleftfunction smcwd_set_timeoutfunction smcwd_stopfunction smcwd_startfunction smcwd_probe
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* ARM Secure Monitor Call watchdog driver
*
* Copyright 2020 Google LLC.
* Julius Werner <jwerner@chromium.org>
* Based on mtk_wdt.c
*/
#include <linux/arm-smccc.h>
#include <linux/err.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/types.h>
#include <linux/watchdog.h>
#include <uapi/linux/psci.h>
#define DRV_NAME "arm_smc_wdt"
#define DRV_VERSION "1.0"
enum smcwd_call {
SMCWD_INIT = 0,
SMCWD_SET_TIMEOUT = 1,
SMCWD_ENABLE = 2,
SMCWD_PET = 3,
SMCWD_GET_TIMELEFT = 4,
};
static bool nowayout = WATCHDOG_NOWAYOUT;
static unsigned int timeout;
static int smcwd_call(struct watchdog_device *wdd, enum smcwd_call call,
unsigned long arg, struct arm_smccc_res *res)
{
struct arm_smccc_res local_res;
if (!res)
res = &local_res;
arm_smccc_smc((u32)(uintptr_t)watchdog_get_drvdata(wdd), call, arg, 0,
0, 0, 0, 0, res);
if (res->a0 == PSCI_RET_NOT_SUPPORTED)
return -ENODEV;
if (res->a0 == PSCI_RET_INVALID_PARAMS)
return -EINVAL;
if (res->a0 == PSCI_RET_DISABLED)
return -ENODATA;
if (res->a0 != PSCI_RET_SUCCESS)
return -EIO;
return 0;
}
static int smcwd_ping(struct watchdog_device *wdd)
{
return smcwd_call(wdd, SMCWD_PET, 0, NULL);
}
static unsigned int smcwd_get_timeleft(struct watchdog_device *wdd)
{
struct arm_smccc_res res;
smcwd_call(wdd, SMCWD_GET_TIMELEFT, 0, &res);
if (res.a0)
return 0;
return res.a1;
}
static int smcwd_set_timeout(struct watchdog_device *wdd, unsigned int timeout)
{
int res;
res = smcwd_call(wdd, SMCWD_SET_TIMEOUT, timeout, NULL);
if (!res)
wdd->timeout = timeout;
return res;
}
static int smcwd_stop(struct watchdog_device *wdd)
{
return smcwd_call(wdd, SMCWD_ENABLE, 0, NULL);
}
static int smcwd_start(struct watchdog_device *wdd)
{
return smcwd_call(wdd, SMCWD_ENABLE, 1, NULL);
}
Annotation
- Immediate include surface: `linux/arm-smccc.h`, `linux/err.h`, `linux/module.h`, `linux/moduleparam.h`, `linux/of.h`, `linux/platform_device.h`, `linux/types.h`, `linux/watchdog.h`.
- Detected declarations: `enum smcwd_call`, `function smcwd_call`, `function smcwd_ping`, `function smcwd_get_timeleft`, `function smcwd_set_timeout`, `function smcwd_stop`, `function smcwd_start`, `function smcwd_probe`.
- 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.