[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC PATCH V2 03/10] Qemu/VFIO: Rework vfio_std_cap_max_siz
From: |
Lan Tianyu |
Subject: |
[Qemu-devel] [RFC PATCH V2 03/10] Qemu/VFIO: Rework vfio_std_cap_max_size() function |
Date: |
Tue, 24 Nov 2015 21:35:20 +0800 |
Use new ioctl cmd VFIO_GET_PCI_CAP_INFO to get PCI cap table size.
This helps to get accurate table size and faciliate to find free
PCI config space regs for faked PCI capability. Current code assigns
PCI config space regs from the start of last PCI capability table to
pos 0xff to the last capability and occupy some free PCI config space
regs.
Signed-off-by: Lan Tianyu <address@hidden>
---
hw/vfio/pci.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 5c3f8a7..29845e3 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -2344,18 +2344,20 @@ static void vfio_unmap_bars(VFIOPCIDevice *vdev)
/*
* General setup
*/
-static uint8_t vfio_std_cap_max_size(PCIDevice *pdev, uint8_t pos)
+static uint8_t vfio_std_cap_max_size(VFIOPCIDevice *vdev, uint8_t cap)
{
- uint8_t tmp, next = 0xff;
+ struct vfio_pci_cap_info reg_info = {
+ .argsz = sizeof(reg_info),
+ .index = VFIO_PCI_CAP_GET_SIZE,
+ .cap = cap
+ };
+ int ret;
- for (tmp = pdev->config[PCI_CAPABILITY_LIST]; tmp;
- tmp = pdev->config[tmp + 1]) {
- if (tmp > pos && tmp < next) {
- next = tmp;
- }
- }
+ ret = ioctl(vdev->vbasedev.fd, VFIO_GET_PCI_CAP_INFO, ®_info);
+ if (ret || reg_info.size == 0)
+ error_report("vfio: Failed to find free PCI config reg: %m\n");
- return next - pos;
+ return reg_info.size;
}
static void vfio_set_word_bits(uint8_t *buf, uint16_t val, uint16_t mask)
@@ -2521,7 +2523,7 @@ static int vfio_add_std_cap(VFIOPCIDevice *vdev, uint8_t
pos)
* Since QEMU doesn't actually handle many of the config accesses,
* exact size doesn't seem worthwhile.
*/
- size = vfio_std_cap_max_size(pdev, pos);
+ size = vfio_std_cap_max_size(vdev, cap_id);
/*
* pci_add_capability always inserts the new capability at the head
--
1.9.3
- [Qemu-devel] [RFC PATCH V2 00/10] Qemu: Add live migration support for SRIOV NIC, Lan Tianyu, 2015/11/24
- [Qemu-devel] [RFC PATCH V2 01/10] Qemu/VFIO: Create head file pci.h to share data struct., Lan Tianyu, 2015/11/24
- [Qemu-devel] [RFC PATCH V2 02/10] Qemu/VFIO: Add new VFIO_GET_PCI_CAP_INFO ioctl cmd definition, Lan Tianyu, 2015/11/24
- [Qemu-devel] [RFC PATCH V2 03/10] Qemu/VFIO: Rework vfio_std_cap_max_size() function,
Lan Tianyu <=
- [Qemu-devel] [RFC PATCH V2 04/10] Qemu/VFIO: Add vfio_find_free_cfg_reg() to find free PCI config space regs, Lan Tianyu, 2015/11/24
- [Qemu-devel] [RFC PATCH V2 05/10] Qemu/VFIO: Expose PCI config space read/write and msix functions, Lan Tianyu, 2015/11/24
- [Qemu-devel] [RFC PATCH V2 07/10] Qemu: Add post_load_state() to run after restoring CPU state, Lan Tianyu, 2015/11/24
- [Qemu-devel] [RFC PATCH V2 06/10] Qemu/PCI: Add macros for faked PCI migration capability, Lan Tianyu, 2015/11/24
- [Qemu-devel] [RFC PATCH V2 08/10] Qemu: Add save_before_stop callback to run just before stopping VCPU during migration, Lan Tianyu, 2015/11/24
- [Qemu-devel] [RFC PATCH V2 09/10] Qemu/VFIO: Add SRIOV VF migration support, Lan Tianyu, 2015/11/24
- [Qemu-devel] [RFC PATCH V2 10/10] Qemu/VFIO: Misc change for enable migration with VFIO, Lan Tianyu, 2015/11/24