#define VFIO_DEVICE_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 7)
#define VFIO_DEVICE_GET_REGION_INFO _IO(VFIO_TYPE, VFIO_BASE + 8)
#define VFIO_DEVICE_GET_IRQ_INFO _IO(VFIO_TYPE, VFIO_BASE + 9)
$ sudo modprobe vfio_pci $ sudo vfio-bind 0000:01:00.0
static int __init vfio_pci_init(void) // Allocate shared config space permision data used by all devices vfio_pci_init_perm_bits(); // Register and scan for devices pci_register_device(&vfio_pci_driver); vfio_pci_fill_ids(); return 0; >
static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) struct vfio_pci_device* vdev; vdev = kzalloc(sizeof(*vdev), GFP_KERNEL); vdev->pdev = pdev; vdev->irq_type = VFIO_PCI_NUM_IRQS; vfio_add_group_dev(&pdev->dev, &vfio_pci_ops, vdev); . >
static int vfio_pci_open(void *device_data) struct vfio_pci_device* vdev = device_data; try_module_get(THIS_MODULE); vfio_pci_enable(vdev); vfio_spapr_pci_eeh_open(vdev->pdev); vdev->refcnt++; . >
static const struct vfio_device_ops vfio_pci_ops = .name = "vfio-pci", .open = vfio_pci_open, .release = vfio_pci_release, .ioctl = vfio_pci_ioctl, .read = vfio_pci_read, .write = vfio_pci_write, .mmap = vfio_pci_mmap, .request = vfio_pci_request, >;
in terms of the index passed to the function.
For GPU, vfio_pci_rw() is mostly called with the index 7 (= VFIO_PCI_CONFIG_REGION_INDEX ) and 8 (= VFIO_PCI_VGA_REGION_INDEX ). Small number of calls are done with index 0 (= VFIO_PCI_BAR0_REGION_INDEX ). Note that each index can be found in /linux/include/uapi/linux/vfio.h:418 .