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.
- 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.
- 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/anon_inodes.hlinux/delay.hlinux/file.hlinux/module.hlinux/pci.hlinux/sizes.hlinux/types.hlinux/vfio.hlinux/vfio_pci_core.hdrm/intel/xe_sriov_vfio.hdrm/intel/pciids.h
Detected Declarations
struct xe_vfio_pci_migration_filestruct xe_vfio_pci_core_deviceenum xe_vfio_pci_file_typefunction xe_vfio_pci_disable_filefunction xe_vfio_pci_put_filefunction xe_vfio_pci_resetfunction xe_vfio_pci_state_mutex_lockfunction xe_vfio_pci_state_mutex_unlockfunction xe_vfio_pci_reset_preparefunction xe_vfio_pci_reset_donefunction xe_vfio_pci_open_devicefunction xe_vfio_pci_close_devicefunction xe_vfio_pci_release_filefunction xe_vfio_pci_save_readfunction xe_vfio_pci_resume_writefunction xe_vfio_pci_alloc_filefunction xe_vfio_set_statefunction transfersfunction xe_vfio_pci_set_device_statefunction xe_vfio_pci_get_device_statefunction xe_vfio_pci_get_data_sizefunction xe_vfio_pci_migration_initfunction xe_vfio_pci_vf_initfunction xe_vfio_pci_init_devfunction xe_vfio_pci_release_devfunction xe_vfio_pci_probefunction xe_vfio_pci_remove
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
- Immediate include surface: `linux/anon_inodes.h`, `linux/delay.h`, `linux/file.h`, `linux/module.h`, `linux/pci.h`, `linux/sizes.h`, `linux/types.h`, `linux/vfio.h`.
- Detected declarations: `struct xe_vfio_pci_migration_file`, `struct xe_vfio_pci_core_device`, `enum xe_vfio_pci_file_type`, `function xe_vfio_pci_disable_file`, `function xe_vfio_pci_put_file`, `function xe_vfio_pci_reset`, `function xe_vfio_pci_state_mutex_lock`, `function xe_vfio_pci_state_mutex_unlock`, `function xe_vfio_pci_reset_prepare`, `function xe_vfio_pci_reset_done`.
- Atlas domain: Driver Families / drivers/vfio.
- 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.