drivers/vfio/pci/xe/main.c

Source file repositories/reference/linux-study-clean/drivers/vfio/pci/xe/main.c

File Facts

System
Linux kernel
Corpus path
drivers/vfio/pci/xe/main.c
Extension
.c
Size
15887 bytes
Lines
597
Domain
Driver Families
Bucket
drivers/vfio
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 const struct file_operations xe_vfio_pci_save_fops = {
	.owner = THIS_MODULE,
	.read = xe_vfio_pci_save_read,
	.release = xe_vfio_pci_release_file,
	.llseek = noop_llseek,
};

static ssize_t xe_vfio_pci_resume_write(struct file *filp, const char __user *buf,
					size_t len, loff_t *pos)
{
	struct xe_vfio_pci_migration_file *migf = filp->private_data;
	ssize_t ret;

	if (pos)
		return -ESPIPE;

	mutex_lock(&migf->lock);
	if (migf->disabled) {
		mutex_unlock(&migf->lock);
		return -ENODEV;
	}

	ret = xe_sriov_vfio_data_write(migf->xe_vdev->xe, migf->xe_vdev->vfid, buf, len);
	mutex_unlock(&migf->lock);

	return ret;
}

static const struct file_operations xe_vfio_pci_resume_fops = {
	.owner = THIS_MODULE,
	.write = xe_vfio_pci_resume_write,
	.release = xe_vfio_pci_release_file,
	.llseek = noop_llseek,
};

static const char *vfio_dev_state_str(u32 state)
{
	switch (state) {
	case VFIO_DEVICE_STATE_RUNNING: return "running";
	case VFIO_DEVICE_STATE_RUNNING_P2P: return "running_p2p";
	case VFIO_DEVICE_STATE_STOP_COPY: return "stopcopy";
	case VFIO_DEVICE_STATE_STOP: return "stop";
	case VFIO_DEVICE_STATE_RESUMING: return "resuming";
	case VFIO_DEVICE_STATE_ERROR: return "error";
	default: return "";
	}
}

enum xe_vfio_pci_file_type {
	XE_VFIO_FILE_SAVE = 0,
	XE_VFIO_FILE_RESUME,
};

static struct xe_vfio_pci_migration_file *
xe_vfio_pci_alloc_file(struct xe_vfio_pci_core_device *xe_vdev,
		       enum xe_vfio_pci_file_type type)
{
	struct xe_vfio_pci_migration_file *migf;
	const struct file_operations *fops;
	int flags;
	int ret;

	migf = kzalloc_obj(*migf, GFP_KERNEL_ACCOUNT);
	if (!migf)
		return ERR_PTR(-ENOMEM);

	fops = type == XE_VFIO_FILE_SAVE ? &xe_vfio_pci_save_fops : &xe_vfio_pci_resume_fops;
	flags = type == XE_VFIO_FILE_SAVE ? O_RDONLY : O_WRONLY;
	migf->filp = anon_inode_getfile("xe_vfio_mig", fops, migf, flags);
	if (IS_ERR(migf->filp)) {
		ret = PTR_ERR(migf->filp);
		kfree(migf);
		return ERR_PTR(ret);
	}

	mutex_init(&migf->lock);
	migf->xe_vdev = xe_vdev;
	xe_vdev->migf = migf;

	stream_open(migf->filp->f_inode, migf->filp);

	return migf;
}

static struct file *
xe_vfio_set_state(struct xe_vfio_pci_core_device *xe_vdev, u32 new)
{
	u32 cur = xe_vdev->mig_state;
	int ret;

Annotation

Implementation Notes