vfio/pci: Expose shadow ROM as PCI option ROM
authorAlex Williamson <alex.williamson@redhat.com>
Mon, 22 Feb 2016 23:02:46 +0000 (16:02 -0700)
committerAlex Williamson <alex.williamson@redhat.com>
Mon, 22 Feb 2016 23:10:09 +0000 (16:10 -0700)
Integrated graphics may have their ROM shadowed at 0xc0000 rather than
implement a PCI option ROM.  Make this ROM appear to the user using
the ROM BAR.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
drivers/vfio/pci/vfio_pci.c
drivers/vfio/pci/vfio_pci_config.c
drivers/vfio/pci/vfio_pci_rdwr.c

index 74a3752974945147c4c2f89dfd4dae7d7701a58c..1ce1d364308c1795bc634a074e7b2d89ec3fd76c 100644 (file)
@@ -609,8 +609,14 @@ static long vfio_pci_ioctl(void *device_data,
 
                        /* Report the BAR size, not the ROM size */
                        info.size = pci_resource_len(pdev, info.index);
-                       if (!info.size)
-                               break;
+                       if (!info.size) {
+                               /* Shadow ROMs appear as PCI option ROMs */
+                               if (pdev->resource[PCI_ROM_RESOURCE].flags &
+                                                       IORESOURCE_ROM_SHADOW)
+                                       info.size = 0x20000;
+                               else
+                                       break;
+                       }
 
                        /* Is it really there? */
                        io = pci_map_rom(pdev, &size);
index 88dc646c01448bcd5656ed5f17c9b487a0c5f49b..142c533efec7592be65bf8354db2c0c0d16b05c1 100644 (file)
@@ -475,14 +475,19 @@ static void vfio_bar_fixup(struct vfio_pci_device *vdev)
        bar = (__le32 *)&vdev->vconfig[PCI_ROM_ADDRESS];
 
        /*
-        * NB. we expose the actual BAR size here, regardless of whether
-        * we can read it.  When we report the REGION_INFO for the ROM
-        * we report what PCI tells us is the actual ROM size.
+        * NB. REGION_INFO will have reported zero size if we weren't able
+        * to read the ROM, but we still return the actual BAR size here if
+        * it exists (or the shadow ROM space).
         */
        if (pci_resource_start(pdev, PCI_ROM_RESOURCE)) {
                mask = ~(pci_resource_len(pdev, PCI_ROM_RESOURCE) - 1);
                mask |= PCI_ROM_ADDRESS_ENABLE;
                *bar &= cpu_to_le32((u32)mask);
+       } else if (pdev->resource[PCI_ROM_RESOURCE].flags &
+                                       IORESOURCE_ROM_SHADOW) {
+               mask = ~(0x20000 - 1);
+               mask |= PCI_ROM_ADDRESS_ENABLE;
+               *bar &= cpu_to_le32((u32)mask);
        } else
                *bar = 0;
 
index 210db24d220472dba65d78225d192e7b9bb0bbcc..5ffd1d9ad4bdf8111a35a9b6b0c217109d238ebf 100644 (file)
@@ -124,11 +124,14 @@ ssize_t vfio_pci_bar_rw(struct vfio_pci_device *vdev, char __user *buf,
        void __iomem *io;
        ssize_t done;
 
-       if (!pci_resource_start(pdev, bar))
+       if (pci_resource_start(pdev, bar))
+               end = pci_resource_len(pdev, bar);
+       else if (bar == PCI_ROM_RESOURCE &&
+                pdev->resource[bar].flags & IORESOURCE_ROM_SHADOW)
+               end = 0x20000;
+       else
                return -EINVAL;
 
-       end = pci_resource_len(pdev, bar);
-
        if (pos >= end)
                return -EINVAL;