drivers/firmware/efi/ovmf-debug-log.c
Source file repositories/reference/linux-study-clean/drivers/firmware/efi/ovmf-debug-log.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/firmware/efi/ovmf-debug-log.c- Extension
.c- Size
- 2550 bytes
- Lines
- 112
- Domain
- Driver Families
- Bucket
- drivers/firmware
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/efi.hlinux/init.hlinux/io.hlinux/kernel.hlinux/kobject.hlinux/module.hlinux/platform_device.hlinux/sysfs.h
Detected Declarations
struct ovmf_debug_log_headerfunction ovmf_log_readfunction ovmf_log_probe
Annotated Snippet
struct ovmf_debug_log_header {
u64 magic1;
u64 magic2;
u64 hdr_size;
u64 log_size;
u64 lock; // edk2 spinlock
u64 head_off;
u64 tail_off;
u64 truncated;
u8 fw_version[128];
};
static struct ovmf_debug_log_header *hdr;
static u8 *logbuf;
static u64 logbufsize;
static ssize_t ovmf_log_read(struct file *filp, struct kobject *kobj,
const struct bin_attribute *attr, char *buf,
loff_t offset, size_t count)
{
u64 start, end;
start = hdr->head_off + offset;
if (hdr->head_off > hdr->tail_off && start >= hdr->log_size)
start -= hdr->log_size;
end = start + count;
if (start > hdr->tail_off) {
if (end > hdr->log_size)
end = hdr->log_size;
} else {
if (end > hdr->tail_off)
end = hdr->tail_off;
}
if (start > logbufsize || end > logbufsize)
return 0;
if (start >= end)
return 0;
memcpy(buf, logbuf + start, end - start);
return end - start;
}
static struct bin_attribute ovmf_log_bin_attr = {
.attr = {
.name = "ovmf_debug_log",
.mode = 0444,
},
.read = ovmf_log_read,
};
int __init ovmf_log_probe(unsigned long ovmf_debug_log_table)
{
int ret = -EINVAL;
u64 size;
/* map + verify header */
hdr = memremap(ovmf_debug_log_table, sizeof(*hdr), MEMREMAP_WB);
if (!hdr) {
pr_err("OVMF debug log: header map failed\n");
return -EINVAL;
}
if (hdr->magic1 != OVMF_DEBUG_LOG_MAGIC1 ||
hdr->magic2 != OVMF_DEBUG_LOG_MAGIC2) {
printk(KERN_ERR "OVMF debug log: magic mismatch\n");
goto err_unmap;
}
size = hdr->hdr_size + hdr->log_size;
pr_info("OVMF debug log: firmware version: \"%s\"\n", hdr->fw_version);
pr_info("OVMF debug log: buffer size: %lluk\n", size / 1024);
/* map complete log buffer */
memunmap(hdr);
hdr = memremap(ovmf_debug_log_table, size, MEMREMAP_WB);
if (!hdr) {
pr_err("OVMF debug log: buffer map failed\n");
return -EINVAL;
}
logbuf = (void *)hdr + hdr->hdr_size;
logbufsize = hdr->log_size;
ovmf_log_bin_attr.size = size;
ret = sysfs_create_bin_file(efi_kobj, &ovmf_log_bin_attr);
if (ret != 0) {
pr_err("OVMF debug log: sysfs register failed\n");
goto err_unmap;
}
Annotation
- Immediate include surface: `linux/efi.h`, `linux/init.h`, `linux/io.h`, `linux/kernel.h`, `linux/kobject.h`, `linux/module.h`, `linux/platform_device.h`, `linux/sysfs.h`.
- Detected declarations: `struct ovmf_debug_log_header`, `function ovmf_log_read`, `function ovmf_log_probe`.
- Atlas domain: Driver Families / drivers/firmware.
- 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.