From patchwork Thu Jul 21 18:14:38 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 996462 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p6LIEseH002893 for ; Thu, 21 Jul 2011 18:15:19 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753094Ab1GUSOy (ORCPT ); Thu, 21 Jul 2011 14:14:54 -0400 Received: from thoth.sbs.de ([192.35.17.2]:22532 "EHLO thoth.sbs.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753091Ab1GUSOr (ORCPT ); Thu, 21 Jul 2011 14:14:47 -0400 Received: from mail1.siemens.de (localhost [127.0.0.1]) by thoth.sbs.de (8.13.6/8.13.6) with ESMTP id p6LIEgVK020287; Thu, 21 Jul 2011 20:14:42 +0200 Received: from mchn199C.mchp.siemens.de ([139.25.109.49]) by mail1.siemens.de (8.13.6/8.13.6) with ESMTP id p6LIEft1006280; Thu, 21 Jul 2011 20:14:42 +0200 From: Jan Kiszka To: Avi Kivity , Marcelo Tosatti Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Alex Williamson Subject: [PATCH v2 4/7] pci-assign: Refactor calc_assigned_dev_id Date: Thu, 21 Jul 2011 20:14:38 +0200 Message-Id: X-Mailer: git-send-email 1.7.3.4 In-Reply-To: References: In-Reply-To: References: Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Thu, 21 Jul 2011 18:15:21 +0000 (UTC) Make calc_assigned_dev_id pick up all required bits from the device passed to it. Signed-off-by: Jan Kiszka --- hw/device-assignment.c | 25 +++++++++---------------- hw/device-assignment.h | 6 +++--- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/hw/device-assignment.c b/hw/device-assignment.c index b341fd9..43a048f 100644 --- a/hw/device-assignment.c +++ b/hw/device-assignment.c @@ -860,9 +860,10 @@ static void free_assigned_device(AssignedDevice *dev) free_dev_irq_entries(dev); } -static uint32_t calc_assigned_dev_id(uint16_t seg, uint8_t bus, uint8_t devfn) +static uint32_t calc_assigned_dev_id(AssignedDevice *dev) { - return (uint32_t)seg << 16 | (uint32_t)bus << 8 | (uint32_t)devfn; + return (uint32_t)dev->h_segnr << 16 | (uint32_t)dev->h_busnr << 8 | + (uint32_t)dev->h_devfn; } static void assign_failed_examine(AssignedDevice *dev) @@ -926,8 +927,7 @@ static int assign_device(AssignedDevice *dev) } memset(&assigned_dev_data, 0, sizeof(assigned_dev_data)); - assigned_dev_data.assigned_dev_id = - calc_assigned_dev_id(dev->h_segnr, dev->h_busnr, dev->h_devfn); + assigned_dev_data.assigned_dev_id = calc_assigned_dev_id(dev); assigned_dev_data.segnr = dev->h_segnr; assigned_dev_data.busnr = dev->h_busnr; assigned_dev_data.devfn = dev->h_devfn; @@ -984,8 +984,7 @@ static int assign_irq(AssignedDevice *dev) return r; memset(&assigned_irq_data, 0, sizeof(assigned_irq_data)); - assigned_irq_data.assigned_dev_id = - calc_assigned_dev_id(dev->h_segnr, dev->h_busnr, dev->h_devfn); + assigned_irq_data.assigned_dev_id = calc_assigned_dev_id(dev); assigned_irq_data.guest_irq = irq; assigned_irq_data.host_irq = dev->real_device.irq; if (dev->irq_requested_type) { @@ -1024,8 +1023,7 @@ static void deassign_device(AssignedDevice *dev) int r; memset(&assigned_dev_data, 0, sizeof(assigned_dev_data)); - assigned_dev_data.assigned_dev_id = - calc_assigned_dev_id(dev->h_segnr, dev->h_busnr, dev->h_devfn); + assigned_dev_data.assigned_dev_id = calc_assigned_dev_id(dev); r = kvm_deassign_pci_device(kvm_state, &assigned_dev_data); if (r < 0) @@ -1079,9 +1077,7 @@ static void assigned_dev_update_msi(PCIDevice *pci_dev, unsigned int ctrl_pos) int r; memset(&assigned_irq_data, 0, sizeof assigned_irq_data); - assigned_irq_data.assigned_dev_id = - calc_assigned_dev_id(assigned_dev->h_segnr, assigned_dev->h_busnr, - (uint8_t)assigned_dev->h_devfn); + assigned_irq_data.assigned_dev_id = calc_assigned_dev_id(assigned_dev); /* Some guests gratuitously disable MSI even if they're not using it, * try to catch this by only deassigning irqs if the guest is using @@ -1166,8 +1162,7 @@ static int assigned_dev_update_msix_mmio(PCIDevice *pci_dev) fprintf(stderr, "MSI-X entry number is zero!\n"); return -EINVAL; } - msix_nr.assigned_dev_id = calc_assigned_dev_id(adev->h_segnr, adev->h_busnr, - (uint8_t)adev->h_devfn); + msix_nr.assigned_dev_id = calc_assigned_dev_id(adev); msix_nr.entry_nr = entries_nr; r = kvm_assign_set_msix_nr(kvm_state, &msix_nr); if (r != 0) { @@ -1234,9 +1229,7 @@ static void assigned_dev_update_msix(PCIDevice *pci_dev, unsigned int ctrl_pos) int r; memset(&assigned_irq_data, 0, sizeof assigned_irq_data); - assigned_irq_data.assigned_dev_id = - calc_assigned_dev_id(assigned_dev->h_segnr, assigned_dev->h_busnr, - (uint8_t)assigned_dev->h_devfn); + assigned_irq_data.assigned_dev_id = calc_assigned_dev_id(assigned_dev); /* Some guests gratuitously disable MSIX even if they're not using it, * try to catch this by only deassigning irqs if the guest is using diff --git a/hw/device-assignment.h b/hw/device-assignment.h index ae1bc58..3d20207 100644 --- a/hw/device-assignment.h +++ b/hw/device-assignment.h @@ -90,9 +90,9 @@ typedef struct AssignedDevice { PCIDevRegions real_device; int run; int girq; - unsigned int h_segnr; - unsigned char h_busnr; - unsigned int h_devfn; + uint16_t h_segnr; + uint8_t h_busnr; + uint8_t h_devfn; int irq_requested_type; int bound; struct {