drivers/power/reset/qemu-virt-ctrl.c
Source file repositories/reference/linux-study-clean/drivers/power/reset/qemu-virt-ctrl.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/reset/qemu-virt-ctrl.c- Extension
.c- Size
- 3004 bytes
- Lines
- 123
- Domain
- Driver Families
- Bucket
- drivers/power
- 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/io.hlinux/module.hlinux/mod_devicetable.hlinux/platform_device.hlinux/reboot.h
Detected Declarations
struct qemu_virt_ctrlfunction virt_ctrl_write32function qemu_virt_ctrl_power_offfunction qemu_virt_ctrl_restartfunction qemu_virt_ctrl_reboot_notifyfunction qemu_virt_ctrl_probe
Annotated Snippet
struct qemu_virt_ctrl {
void __iomem *base;
struct notifier_block reboot_nb;
};
static inline void virt_ctrl_write32(u32 val, void __iomem *addr)
{
if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))
iowrite32be(val, addr);
else
iowrite32(val, addr);
}
static int qemu_virt_ctrl_power_off(struct sys_off_data *data)
{
struct qemu_virt_ctrl *ctrl = data->cb_data;
virt_ctrl_write32(CMD_HALT, ctrl->base + VIRT_CTRL_REG_CMD);
return NOTIFY_DONE;
}
static int qemu_virt_ctrl_restart(struct sys_off_data *data)
{
struct qemu_virt_ctrl *ctrl = data->cb_data;
virt_ctrl_write32(CMD_RESET, ctrl->base + VIRT_CTRL_REG_CMD);
return NOTIFY_DONE;
}
static int qemu_virt_ctrl_reboot_notify(struct notifier_block *nb,
unsigned long action, void *data)
{
struct qemu_virt_ctrl *ctrl = container_of(nb, struct qemu_virt_ctrl, reboot_nb);
if (action == SYS_HALT)
virt_ctrl_write32(CMD_HALT, ctrl->base + VIRT_CTRL_REG_CMD);
return NOTIFY_DONE;
}
static int qemu_virt_ctrl_probe(struct platform_device *pdev)
{
struct qemu_virt_ctrl *ctrl;
int ret;
ctrl = devm_kzalloc(&pdev->dev, sizeof(*ctrl), GFP_KERNEL);
if (!ctrl)
return -ENOMEM;
ctrl->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(ctrl->base))
return PTR_ERR(ctrl->base);
ret = devm_register_sys_off_handler(&pdev->dev,
SYS_OFF_MODE_RESTART,
SYS_OFF_PRIO_DEFAULT,
qemu_virt_ctrl_restart,
ctrl);
if (ret)
return dev_err_probe(&pdev->dev, ret,
"cannot register restart handler\n");
ret = devm_register_sys_off_handler(&pdev->dev,
SYS_OFF_MODE_POWER_OFF,
SYS_OFF_PRIO_DEFAULT,
qemu_virt_ctrl_power_off,
ctrl);
if (ret)
return dev_err_probe(&pdev->dev, ret,
"cannot register power-off handler\n");
ctrl->reboot_nb.notifier_call = qemu_virt_ctrl_reboot_notify;
ret = devm_register_reboot_notifier(&pdev->dev, &ctrl->reboot_nb);
if (ret)
return dev_err_probe(&pdev->dev, ret, "cannot register reboot notifier\n");
return 0;
}
static const struct platform_device_id qemu_virt_ctrl_id[] = {
{ .name = "qemu-virt-ctrl" },
{ }
};
MODULE_DEVICE_TABLE(platform, qemu_virt_ctrl_id);
static struct platform_driver qemu_virt_ctrl_driver = {
.probe = qemu_virt_ctrl_probe,
.driver = {
Annotation
- Immediate include surface: `linux/io.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/platform_device.h`, `linux/reboot.h`.
- Detected declarations: `struct qemu_virt_ctrl`, `function virt_ctrl_write32`, `function qemu_virt_ctrl_power_off`, `function qemu_virt_ctrl_restart`, `function qemu_virt_ctrl_reboot_notify`, `function qemu_virt_ctrl_probe`.
- Atlas domain: Driver Families / drivers/power.
- 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.