drivers/virtio/virtio.c
Source file repositories/reference/linux-study-clean/drivers/virtio/virtio.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/virtio/virtio.c- Extension
.c- Size
- 18752 bytes
- Lines
- 740
- Domain
- Driver Families
- Bucket
- drivers/virtio
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/virtio.hlinux/spinlock.hlinux/virtio_config.hlinux/virtio_anchor.hlinux/module.hlinux/idr.hlinux/of.huapi/linux/virtio_ids.h
Detected Declarations
function device_showfunction vendor_showfunction status_showfunction modalias_showfunction features_showfunction virtio_id_matchfunction virtio_dev_matchfunction virtio_ueventfunction virtio_check_driver_offered_featurefunction __virtio_config_changedfunction virtio_config_changedfunction virtio_config_driver_disablefunction virtio_config_driver_enablefunction virtio_config_core_disablefunction virtio_config_core_enablefunction virtio_add_statusfunction virtio_features_okfunction virtio_reset_devicefunction virtio_dev_probefunction virtio_dev_removefunction virtio_dev_shutdownfunction virtio_dev_num_vffunction __register_virtio_driverfunction unregister_virtio_driverfunction virtio_device_of_initfunction register_virtio_devicefunction is_virtio_devicefunction unregister_virtio_devicefunction virtio_device_restore_privfunction virtio_device_freezefunction virtio_device_restorefunction virtio_device_reset_preparefunction virtio_device_reset_donefunction virtio_initfunction virtio_exitmodule init virtio_initexport virtio_check_driver_offered_featureexport virtio_config_changedexport virtio_config_driver_disableexport virtio_config_driver_enableexport virtio_add_statusexport virtio_reset_deviceexport __register_virtio_driverexport unregister_virtio_driverexport register_virtio_deviceexport is_virtio_deviceexport unregister_virtio_deviceexport virtio_device_freeze
Annotated Snippet
static int virtio_dev_match(struct device *_dv, const struct device_driver *_dr)
{
unsigned int i;
struct virtio_device *dev = dev_to_virtio(_dv);
const struct virtio_device_id *ids;
ids = drv_to_virtio(_dr)->id_table;
for (i = 0; ids[i].device; i++)
if (virtio_id_match(dev, &ids[i]))
return 1;
return 0;
}
static int virtio_uevent(const struct device *_dv, struct kobj_uevent_env *env)
{
const struct virtio_device *dev = dev_to_virtio(_dv);
return add_uevent_var(env, "MODALIAS=virtio:d%08Xv%08X",
dev->id.device, dev->id.vendor);
}
void virtio_check_driver_offered_feature(const struct virtio_device *vdev,
unsigned int fbit)
{
unsigned int i;
struct virtio_driver *drv = drv_to_virtio(vdev->dev.driver);
for (i = 0; i < drv->feature_table_size; i++)
if (drv->feature_table[i] == fbit)
return;
if (drv->feature_table_legacy) {
for (i = 0; i < drv->feature_table_size_legacy; i++)
if (drv->feature_table_legacy[i] == fbit)
return;
}
BUG();
}
EXPORT_SYMBOL_GPL(virtio_check_driver_offered_feature);
static void __virtio_config_changed(struct virtio_device *dev)
{
struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
if (!dev->config_core_enabled || dev->config_driver_disabled)
dev->config_change_pending = true;
else if (drv && drv->config_changed) {
drv->config_changed(dev);
dev->config_change_pending = false;
}
}
void virtio_config_changed(struct virtio_device *dev)
{
unsigned long flags;
spin_lock_irqsave(&dev->config_lock, flags);
__virtio_config_changed(dev);
spin_unlock_irqrestore(&dev->config_lock, flags);
}
EXPORT_SYMBOL_GPL(virtio_config_changed);
/**
* virtio_config_driver_disable - disable config change reporting by drivers
* @dev: the device to disable
*
* This is only allowed to be called by a driver and disabling can't
* be nested.
*/
void virtio_config_driver_disable(struct virtio_device *dev)
{
spin_lock_irq(&dev->config_lock);
dev->config_driver_disabled = true;
spin_unlock_irq(&dev->config_lock);
}
EXPORT_SYMBOL_GPL(virtio_config_driver_disable);
/**
* virtio_config_driver_enable - enable config change reporting by drivers
* @dev: the device to enable
*
* This is only allowed to be called by a driver and enabling can't
* be nested.
*/
void virtio_config_driver_enable(struct virtio_device *dev)
{
spin_lock_irq(&dev->config_lock);
dev->config_driver_disabled = false;
if (dev->config_change_pending)
Annotation
- Immediate include surface: `linux/virtio.h`, `linux/spinlock.h`, `linux/virtio_config.h`, `linux/virtio_anchor.h`, `linux/module.h`, `linux/idr.h`, `linux/of.h`, `uapi/linux/virtio_ids.h`.
- Detected declarations: `function device_show`, `function vendor_show`, `function status_show`, `function modalias_show`, `function features_show`, `function virtio_id_match`, `function virtio_dev_match`, `function virtio_uevent`, `function virtio_check_driver_offered_feature`, `function __virtio_config_changed`.
- Atlas domain: Driver Families / drivers/virtio.
- Implementation status: pattern 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.