From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33566) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1Dxa-0005Ii-Ss for qemu-devel@nongnu.org; Tue, 24 Nov 2015 08:48:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a1DxX-0001FF-M1 for qemu-devel@nongnu.org; Tue, 24 Nov 2015 08:48:42 -0500 Received: from mga11.intel.com ([192.55.52.93]:17095) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1DxX-0001F5-DN for qemu-devel@nongnu.org; Tue, 24 Nov 2015 08:48:39 -0500 From: Lan Tianyu Date: Tue, 24 Nov 2015 21:35:20 +0800 Message-Id: <1448372127-28115-4-git-send-email-tianyu.lan@intel.com> In-Reply-To: <1448372127-28115-1-git-send-email-tianyu.lan@intel.com> References: <1448372127-28115-1-git-send-email-tianyu.lan@intel.com> Subject: [Qemu-devel] [RFC PATCH V2 03/10] Qemu/VFIO: Rework vfio_std_cap_max_size() function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: aik@ozlabs.ru, alex.williamson@redhat.com, amit.shah@redhat.com, anthony@codemonkey.ws, ard.biesheuvel@linaro.org, blauwirbel@gmail.com, cornelia.huck@de.ibm.com, eddie.dong@intel.com, nrupal.jani@intel.com, agraf@suse.de, kvm@vger.kernel.org, pbonzini@redhat.com, qemu-devel@nongnu.org, emil.s.tantilov@intel.com, gerlitz.or@gmail.com, donald.c.skidmore@intel.com, mark.d.rustad@intel.com, mst@redhat.com, kraxel@redhat.com, lcapitulino@redhat.com, quintela@redhat.com Cc: Lan Tianyu 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 --- 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