drivers/watchdog/pika_wdt.c
Source file repositories/reference/linux-study-clean/drivers/watchdog/pika_wdt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/watchdog/pika_wdt.c- Extension
.c- Size
- 6936 bytes
- Lines
- 303
- Domain
- Driver Families
- Bucket
- drivers/watchdog
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/init.hlinux/errno.hlinux/module.hlinux/moduleparam.hlinux/types.hlinux/kernel.hlinux/fs.hlinux/miscdevice.hlinux/watchdog.hlinux/reboot.hlinux/jiffies.hlinux/timer.hlinux/bitops.hlinux/uaccess.hlinux/io.hlinux/of.hlinux/of_address.h
Detected Declarations
function pikawdt_resetfunction pikawdt_pingfunction pikawdt_keepalivefunction pikawdt_startfunction pikawdt_openfunction pikawdt_releasefunction pikawdt_writefunction pikawdt_ioctlfunction pikawdt_initfunction pikawdt_exitmodule init pikawdt_init
Annotated Snippet
static const struct file_operations pikawdt_fops = {
.owner = THIS_MODULE,
.open = pikawdt_open,
.release = pikawdt_release,
.write = pikawdt_write,
.unlocked_ioctl = pikawdt_ioctl,
.compat_ioctl = compat_ptr_ioctl,
};
static struct miscdevice pikawdt_miscdev = {
.minor = WATCHDOG_MINOR,
.name = "watchdog",
.fops = &pikawdt_fops,
};
static int __init pikawdt_init(void)
{
struct device_node *np;
void __iomem *fpga;
u32 post1;
int ret;
np = of_find_compatible_node(NULL, NULL, "pika,fpga");
if (np == NULL) {
pr_err("Unable to find fpga\n");
return -ENOENT;
}
pikawdt_private.fpga = of_iomap(np, 0);
of_node_put(np);
if (pikawdt_private.fpga == NULL) {
pr_err("Unable to map fpga\n");
return -ENOMEM;
}
ident.firmware_version = in_be32(pikawdt_private.fpga + 0x1c) & 0xffff;
/* POST information is in the sd area. */
np = of_find_compatible_node(NULL, NULL, "pika,fpga-sd");
if (np == NULL) {
pr_err("Unable to find fpga-sd\n");
ret = -ENOENT;
goto out;
}
fpga = of_iomap(np, 0);
of_node_put(np);
if (fpga == NULL) {
pr_err("Unable to map fpga-sd\n");
ret = -ENOMEM;
goto out;
}
/* -- FPGA: POST Test Results Register 1 (32bit R/W) (Offset: 0x4040) --
* Bit 31, WDOG: Set to 1 when the last reset was caused by a watchdog
* timeout.
*/
post1 = in_be32(fpga + 0x40);
if (post1 & 0x80000000)
pikawdt_private.bootstatus = WDIOF_CARDRESET;
iounmap(fpga);
timer_setup(&pikawdt_private.timer, pikawdt_ping, 0);
ret = misc_register(&pikawdt_miscdev);
if (ret) {
pr_err("Unable to register miscdev\n");
goto out;
}
pr_info("initialized. heartbeat=%d sec (nowayout=%d)\n",
heartbeat, nowayout);
return 0;
out:
iounmap(pikawdt_private.fpga);
return ret;
}
static void __exit pikawdt_exit(void)
{
misc_deregister(&pikawdt_miscdev);
iounmap(pikawdt_private.fpga);
}
module_init(pikawdt_init);
module_exit(pikawdt_exit);
Annotation
- Immediate include surface: `linux/init.h`, `linux/errno.h`, `linux/module.h`, `linux/moduleparam.h`, `linux/types.h`, `linux/kernel.h`, `linux/fs.h`, `linux/miscdevice.h`.
- Detected declarations: `function pikawdt_reset`, `function pikawdt_ping`, `function pikawdt_keepalive`, `function pikawdt_start`, `function pikawdt_open`, `function pikawdt_release`, `function pikawdt_write`, `function pikawdt_ioctl`, `function pikawdt_init`, `function pikawdt_exit`.
- Atlas domain: Driver Families / drivers/watchdog.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.