samples/vfio-mdev/mbochs.c
Source file repositories/reference/linux-study-clean/samples/vfio-mdev/mbochs.c
File Facts
- System
- Linux kernel
- Corpus path
samples/vfio-mdev/mbochs.c- Extension
.c- Size
- 36304 bytes
- Lines
- 1452
- Domain
- Support Tooling And Documentation
- Bucket
- samples
- Inferred role
- Support Tooling And Documentation: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/init.hlinux/module.hlinux/kernel.hlinux/slab.hlinux/vmalloc.hlinux/cdev.hlinux/vfio.hlinux/iommu.hlinux/sysfs.hlinux/mdev.hlinux/pci.hlinux/dma-buf.hlinux/highmem.hdrm/drm_fourcc.hdrm/drm_rect.hdrm/drm_modeset_lock.hdrm/drm_property.hdrm/drm_plane.h
Detected Declarations
struct mbochs_modestruct mbochs_dmabufstruct mdev_statefunction mbochs_create_config_spacefunction mbochs_check_framebufferfunction mbochs_modes_equalfunction handle_pci_cfg_writefunction handle_mmio_writefunction handle_mmio_readfunction handle_edid_regsfunction handle_edid_blobfunction mdev_accessfunction mbochs_resetfunction mbochs_init_devfunction mbochs_probefunction mbochs_release_devfunction mbochs_removefunction mbochs_readfunction mbochs_writefunction mbochs_put_pagesfunction mbochs_region_vm_faultfunction mbochs_mmapfunction mbochs_dmabuf_vm_faultfunction mbochs_mmap_dmabuffunction mbochs_print_dmabuffunction mbochs_unmap_dmabuffunction mbochs_release_dmabuffunction mbochs_dmabuf_find_by_modefunction mbochs_dmabuf_find_by_idfunction mbochs_dmabuf_exportfunction mbochs_ioctl_get_region_infofunction mbochs_get_irq_infofunction mbochs_get_device_infofunction mbochs_query_gfx_planefunction mbochs_get_gfx_dmabuffunction mbochs_ioctlfunction mbochs_close_devicefunction list_for_each_entry_safefunction memory_showfunction mbochs_show_descriptionfunction mbochs_get_availablefunction mbochs_device_releasefunction mbochs_dev_exitmodule init mbochs_dev_init
Annotated Snippet
static const struct file_operations vd_fops = {
.owner = THIS_MODULE,
};
static void mbochs_device_release(struct device *dev)
{
/* nothing */
}
static int __init mbochs_dev_init(void)
{
int ret = 0;
atomic_set(&mbochs_avail_mbytes, max_mbytes);
ret = alloc_chrdev_region(&mbochs_devt, 0, MINORMASK + 1, MBOCHS_NAME);
if (ret < 0) {
pr_err("Error: failed to register mbochs_dev, err: %d\n", ret);
return ret;
}
cdev_init(&mbochs_cdev, &vd_fops);
cdev_add(&mbochs_cdev, mbochs_devt, MINORMASK + 1);
pr_info("%s: major %d\n", __func__, MAJOR(mbochs_devt));
ret = mdev_register_driver(&mbochs_driver);
if (ret)
goto err_cdev;
ret = class_register(&mbochs_class);
if (ret)
goto err_driver;
mbochs_dev.class = &mbochs_class;
mbochs_dev.release = mbochs_device_release;
dev_set_name(&mbochs_dev, "%s", MBOCHS_NAME);
ret = device_register(&mbochs_dev);
if (ret)
goto err_put;
ret = mdev_register_parent(&mbochs_parent, &mbochs_dev, &mbochs_driver,
mbochs_mdev_types,
ARRAY_SIZE(mbochs_mdev_types));
if (ret)
goto err_device;
return 0;
err_device:
device_del(&mbochs_dev);
err_put:
put_device(&mbochs_dev);
class_unregister(&mbochs_class);
err_driver:
mdev_unregister_driver(&mbochs_driver);
err_cdev:
cdev_del(&mbochs_cdev);
unregister_chrdev_region(mbochs_devt, MINORMASK + 1);
return ret;
}
static void __exit mbochs_dev_exit(void)
{
mbochs_dev.bus = NULL;
mdev_unregister_parent(&mbochs_parent);
device_unregister(&mbochs_dev);
mdev_unregister_driver(&mbochs_driver);
cdev_del(&mbochs_cdev);
unregister_chrdev_region(mbochs_devt, MINORMASK + 1);
class_unregister(&mbochs_class);
}
MODULE_IMPORT_NS("DMA_BUF");
module_init(mbochs_dev_init)
module_exit(mbochs_dev_exit)
Annotation
- Immediate include surface: `linux/init.h`, `linux/module.h`, `linux/kernel.h`, `linux/slab.h`, `linux/vmalloc.h`, `linux/cdev.h`, `linux/vfio.h`, `linux/iommu.h`.
- Detected declarations: `struct mbochs_mode`, `struct mbochs_dmabuf`, `struct mdev_state`, `function mbochs_create_config_space`, `function mbochs_check_framebuffer`, `function mbochs_modes_equal`, `function handle_pci_cfg_write`, `function handle_mmio_write`, `function handle_mmio_read`, `function handle_edid_regs`.
- Atlas domain: Support Tooling And Documentation / samples.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.