drivers/vfio/mdev/mdev_core.c
Source file repositories/reference/linux-study-clean/drivers/vfio/mdev/mdev_core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/vfio/mdev/mdev_core.c- Extension
.c- Size
- 6717 bytes
- Lines
- 276
- Domain
- Driver Families
- Bucket
- drivers/vfio
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/module.hlinux/slab.hlinux/sysfs.hlinux/mdev.hmdev_private.h
Detected Declarations
function mdev_device_remove_commonfunction mdev_device_remove_cbfunction mdev_unregister_parentfunction mdev_unregister_parentfunction mdev_device_releasefunction mdev_device_createfunction mdev_device_removefunction mdev_initfunction mdev_exitmodule init mdev_initexport mdev_register_parentexport mdev_unregister_parent
Annotated Snippet
ret = device_add(&mdev->dev);
if (ret)
goto out_unlock;
ret = device_driver_attach(&drv->driver, &mdev->dev);
if (ret)
goto out_del;
ret = mdev_create_sysfs_files(mdev);
if (ret)
goto out_del;
mdev->active = true;
dev_dbg(&mdev->dev, "MDEV: created\n");
up_read(&parent->unreg_sem);
return 0;
out_del:
device_del(&mdev->dev);
out_unlock:
up_read(&parent->unreg_sem);
out_put_device:
put_device(&mdev->dev);
return ret;
}
int mdev_device_remove(struct mdev_device *mdev)
{
struct mdev_device *tmp;
struct mdev_parent *parent = mdev->type->parent;
mutex_lock(&mdev_list_lock);
list_for_each_entry(tmp, &mdev_list, next) {
if (tmp == mdev)
break;
}
if (tmp != mdev) {
mutex_unlock(&mdev_list_lock);
return -ENODEV;
}
if (!mdev->active) {
mutex_unlock(&mdev_list_lock);
return -EAGAIN;
}
mdev->active = false;
mutex_unlock(&mdev_list_lock);
/* Check if parent unregistration has started */
if (!down_read_trylock(&parent->unreg_sem))
return -ENODEV;
mdev_device_remove_common(mdev);
up_read(&parent->unreg_sem);
return 0;
}
static int __init mdev_init(void)
{
int ret;
ret = bus_register(&mdev_bus_type);
if (ret)
return ret;
mdev_bus_compat_class = class_compat_register("mdev_bus");
if (!mdev_bus_compat_class) {
bus_unregister(&mdev_bus_type);
return -ENOMEM;
}
return 0;
}
static void __exit mdev_exit(void)
{
class_compat_unregister(mdev_bus_compat_class);
bus_unregister(&mdev_bus_type);
}
subsys_initcall(mdev_init)
module_exit(mdev_exit)
MODULE_VERSION(DRIVER_VERSION);
MODULE_LICENSE("GPL v2");
MODULE_AUTHOR(DRIVER_AUTHOR);
MODULE_DESCRIPTION(DRIVER_DESC);
Annotation
- Immediate include surface: `linux/module.h`, `linux/slab.h`, `linux/sysfs.h`, `linux/mdev.h`, `mdev_private.h`.
- Detected declarations: `function mdev_device_remove_common`, `function mdev_device_remove_cb`, `function mdev_unregister_parent`, `function mdev_unregister_parent`, `function mdev_device_release`, `function mdev_device_create`, `function mdev_device_remove`, `function mdev_init`, `function mdev_exit`, `module init mdev_init`.
- Atlas domain: Driver Families / drivers/vfio.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.