14 #include <linux/device.h>
18 #include <linux/module.h>
21 #include <linux/pci.h>
23 #include <linux/slab.h>
24 #include <linux/types.h>
26 #include <linux/vfio.h>
30 #define DRIVER_VERSION "0.2"
31 #define DRIVER_AUTHOR "Alex Williamson <alex.williamson@redhat.com>"
32 #define DRIVER_DESC "VFIO PCI - User Level meta-driver"
34 static bool nointxmask;
37 "Disable support for PCI 2.3 style INTx masking. If this resolves problems for specific devices, report lspci -vvvxxx to linux-pci@vger.kernel.org so the device can be fixed automatically via the broken_intx_masking flag.");
50 pr_debug(
"%s: Couldn't store %s saved state\n",
51 __func__, dev_name(&pdev->
dev));
62 cmd &= ~PCI_COMMAND_INTX_DISABLE;
75 vdev->
msix_offset = table & ~PCI_MSIX_FLAGS_BIRMASK;
113 pr_info(
"%s: Couldn't reload %s saved state\n",
114 __func__, dev_name(&vdev->
pdev->dev));
125 static void vfio_pci_release(
void *device_data)
130 vfio_pci_disable(vdev);
135 static int vfio_pci_open(
void *device_data)
143 int ret = vfio_pci_enable(vdev);
167 pci_read_config_word(vdev->
pdev,
178 pci_read_config_word(vdev->
pdev,
188 static long vfio_pci_ioctl(
void *device_data,
189 unsigned int cmd,
unsigned long arg)
202 if (
info.argsz < minsz)
224 if (
info.argsz < minsz)
227 switch (
info.index) {
291 info.count = vfio_pci_get_irq_count(vdev,
info.index);
326 if (
hdr.argsz - minsz <
hdr.count * size ||
327 hdr.count > vfio_pci_get_irq_count(vdev,
hdr.index))
344 hdr.start,
hdr.count, data);
358 static ssize_t vfio_pci_read(
void *device_data,
char __user *
buf,
359 size_t count, loff_t *ppos)
380 static ssize_t vfio_pci_write(
void *device_data,
const char __user *buf,
381 size_t count, loff_t *ppos)
406 static int vfio_pci_mmap(
void *device_data,
struct vm_area_struct *vma)
418 if ((vma->
vm_flags & VM_SHARED) == 0)
431 if (phys_len < PAGE_SIZE || req_start + req_len > phys_len)
446 req_start + req_len <= vdev->msix_offset))
454 if (!vdev->
barmap[index]) {
456 1 << index,
"vfio-pci");
464 vma->
vm_flags |= VM_IO | VM_DONTEXPAND | VM_DONTDUMP;
474 .open = vfio_pci_open,
475 .release = vfio_pci_release,
476 .ioctl = vfio_pci_ioctl,
477 .read = vfio_pci_read,
478 .write = vfio_pci_write,
479 .mmap = vfio_pci_mmap,
518 static void vfio_pci_remove(
struct pci_dev *pdev)
533 .probe = vfio_pci_probe,
534 .remove = vfio_pci_remove,
537 static void __exit vfio_pci_cleanup(
void)
544 static int __init vfio_pci_init(
void)
559 ret = pci_register_driver(&vfio_pci_driver);