diff mbox

[RFC,V2,04/10] Qemu/VFIO: Add vfio_find_free_cfg_reg() to find free PCI config space regs

Message ID 1448372127-28115-5-git-send-email-tianyu.lan@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

lan,Tianyu Nov. 24, 2015, 1:35 p.m. UTC
This patch is to add ioctl wrap to find free PCI config sapce regs.

Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
---
 hw/vfio/pci.c | 19 +++++++++++++++++++
 hw/vfio/pci.h |  2 ++
 2 files changed, 21 insertions(+)
diff mbox

Patch

diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 29845e3..d0354a0 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -2508,6 +2508,25 @@  static void vfio_check_af_flr(VFIOPCIDevice *vdev, uint8_t pos)
     }
 }
 
+uint8_t vfio_find_free_cfg_reg(VFIOPCIDevice *vdev, int pos, uint8_t size)
+{
+    struct vfio_pci_cap_info reg_info = {
+        .argsz = sizeof(reg_info),
+        .offset = pos,
+        .index = VFIO_PCI_CAP_GET_FREE_REGION,
+        .size = size,
+    };
+    int ret;
+
+    ret = ioctl(vdev->vbasedev.fd, VFIO_GET_PCI_CAP_INFO, &reg_info);
+    if (ret || reg_info.offset == 0) { 
+        error_report("vfio: Failed to find free PCI config reg: %m\n");
+        return -EFAULT;
+    }
+
+    return reg_info.offset; 
+}
+
 static int vfio_add_std_cap(VFIOPCIDevice *vdev, uint8_t pos)
 {
     PCIDevice *pdev = &vdev->pdev;
diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h
index 9f360bf..6083300 100644
--- a/hw/vfio/pci.h
+++ b/hw/vfio/pci.h
@@ -156,3 +156,5 @@  typedef struct VFIORomBlacklistEntry {
 } VFIORomBlacklistEntry;
 
 #define MSIX_CAP_LENGTH 12
+
+uint8_t vfio_find_free_cfg_reg(VFIOPCIDevice *vdev, int pos, uint8_t size);