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.

Dependency Surface

Detected Declarations

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

Implementation Notes