Convert the msi_virq array into a struct array so we can easily add
a place to track the MSIMessage for each vector.

Signed-off-by: Alex Williamson <alex.william...@redhat.com>
---
 hw/kvm/pci-assign.c |   51 ++++++++++++++++++++++++++-------------------------
 1 file changed, 26 insertions(+), 25 deletions(-)

diff --git a/hw/kvm/pci-assign.c b/hw/kvm/pci-assign.c
index e80dad0..3e667d1 100644
--- a/hw/kvm/pci-assign.c
+++ b/hw/kvm/pci-assign.c
@@ -130,8 +130,10 @@ typedef struct AssignedDevice {
     } cap;
     uint8_t emulate_config_read[PCI_CONFIG_SPACE_SIZE];
     uint8_t emulate_config_write[PCI_CONFIG_SPACE_SIZE];
-    int msi_virq_nr;
-    int *msi_virq;
+    int msi_nr;
+    struct {
+        int virq;
+    } *msi;
     MSIXTableEntry *msix_table;
     hwaddr msix_table_addr;
     uint16_t msix_max;
@@ -683,19 +685,18 @@ again:
     return 0;
 }
 
-static void free_msi_virqs(AssignedDevice *dev)
+static void free_msi(AssignedDevice *dev)
 {
     int i;
 
-    for (i = 0; i < dev->msi_virq_nr; i++) {
-        if (dev->msi_virq[i] >= 0) {
-            kvm_irqchip_release_virq(kvm_state, dev->msi_virq[i]);
-            dev->msi_virq[i] = -1;
+    for (i = 0; i < dev->msi_nr; i++) {
+        if (dev->msi[i].virq >= 0) {
+            kvm_irqchip_release_virq(kvm_state, dev->msi[i].virq);
         }
     }
-    g_free(dev->msi_virq);
-    dev->msi_virq = NULL;
-    dev->msi_virq_nr = 0;
+    g_free(dev->msi);
+    dev->msi = NULL;
+    dev->msi_nr = 0;
 }
 
 static void free_assigned_device(AssignedDevice *dev)
@@ -750,7 +751,7 @@ static void free_assigned_device(AssignedDevice *dev)
         close(dev->real_device.config_fd);
     }
 
-    free_msi_virqs(dev);
+    free_msi(dev);
 }
 
 static void assign_failed_examine(AssignedDevice *dev)
@@ -989,7 +990,7 @@ static void assigned_dev_update_msi(PCIDevice *pci_dev)
             perror("assigned_dev_update_msi: deassign irq");
         }
 
-        free_msi_virqs(assigned_dev);
+        free_msi(assigned_dev);
 
         assigned_dev->assigned_irq_type = ASSIGNED_IRQ_NONE;
         pci_device_set_intx_routing_notifier(pci_dev, NULL);
@@ -1005,9 +1006,9 @@ static void assigned_dev_update_msi(PCIDevice *pci_dev)
             return;
         }
 
-        assigned_dev->msi_virq = g_malloc(sizeof(*assigned_dev->msi_virq));
-        assigned_dev->msi_virq_nr = 1;
-        assigned_dev->msi_virq[0] = virq;
+        assigned_dev->msi = g_malloc(sizeof(*assigned_dev->msi));
+        assigned_dev->msi_nr = 1;
+        assigned_dev->msi[0].virq = virq;
         if (kvm_device_msi_assign(kvm_state, assigned_dev->dev_id, virq) < 0) {
             perror("assigned_dev_update_msi: kvm_device_msi_assign");
         }
@@ -1055,14 +1056,14 @@ static int assigned_dev_update_msix_mmio(PCIDevice 
*pci_dev)
         return r;
     }
 
-    free_msi_virqs(adev);
+    free_msi(adev);
 
-    adev->msi_virq_nr = adev->msix_max;
-    adev->msi_virq = g_malloc(adev->msix_max * sizeof(*adev->msi_virq));
+    adev->msi_nr = adev->msix_max;
+    adev->msi = g_malloc(adev->msix_max * sizeof(*adev->msi));
 
     entry = adev->msix_table;
     for (i = 0; i < adev->msix_max; i++, entry++) {
-        adev->msi_virq[i] = -1;
+        adev->msi[i].virq = -1;
 
         if (assigned_dev_msix_masked(entry)) {
             continue;
@@ -1074,13 +1075,13 @@ static int assigned_dev_update_msix_mmio(PCIDevice 
*pci_dev)
         if (r < 0) {
             return r;
         }
-        adev->msi_virq[i] = r;
+        adev->msi[i].virq = r;
 
         DEBUG("MSI-X vector %d, gsi %d, addr %08x_%08x, data %08x\n", i,
               r, entry->addr_hi, entry->addr_lo, entry->data);
 
         r = kvm_device_msix_set_vector(kvm_state, adev->dev_id, i,
-                                       adev->msi_virq[i]);
+                                       adev->msi[i].virq);
         if (r) {
             error_report("fail to set MSI-X entry! %s", strerror(-r));
             break;
@@ -1108,7 +1109,7 @@ static void assigned_dev_update_msix(PCIDevice *pci_dev)
             perror("assigned_dev_update_msix: deassign irq");
         }
 
-        free_msi_virqs(assigned_dev);
+        free_msi(assigned_dev);
 
         assigned_dev->assigned_irq_type = ASSIGNED_IRQ_NONE;
         pci_device_set_intx_routing_notifier(pci_dev, NULL);
@@ -1120,7 +1121,7 @@ static void assigned_dev_update_msix(PCIDevice *pci_dev)
             return;
         }
 
-        if (assigned_dev->msi_virq_nr > 0) {
+        if (assigned_dev->msi_nr > 0) {
             if (kvm_device_msix_assign(kvm_state, assigned_dev->dev_id) < 0) {
                 perror("assigned_dev_enable_msix: assign irq");
                 return;
@@ -1548,7 +1549,7 @@ static void assigned_dev_msix_mmio_write(void *opaque, 
hwaddr addr,
         } else if (assigned_dev_msix_masked(&orig) &&
                    !assigned_dev_msix_masked(entry)) {
             /* Vector unmasked */
-            if (i >= adev->msi_virq_nr || adev->msi_virq[i] < 0) {
+            if (i >= adev->msi_nr || adev->msi[i].virq < 0) {
                 /* Previously unassigned vector, start from scratch */
                 assigned_dev_update_msix(pdev);
                 return;
@@ -1562,7 +1563,7 @@ static void assigned_dev_msix_mmio_write(void *opaque, 
hwaddr addr,
                 msg.data = entry->data;
 
                 ret = kvm_irqchip_update_msi_route(kvm_state,
-                                                   adev->msi_virq[i], msg);
+                                                   adev->msi[i].virq, msg);
                 if (ret) {
                     error_report("Error updating irq routing entry (%d)", ret);
                 }


Reply via email to