@@ -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, ®_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;
@@ -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);
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(+)