qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: jan.kiszka@siemens.com, mst@redhat.com
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 1/2] pci-assign: Refactor MSI virq array
Date: Thu, 09 May 2013 10:35:59 -0600	[thread overview]
Message-ID: <20130509163559.22536.97895.stgit@bling.home> (raw)
In-Reply-To: <20130509163157.22536.68566.stgit@bling.home>

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.williamson@redhat.com>
---
 hw/i386/kvm/pci-assign.c |   51 +++++++++++++++++++++++-----------------------
 1 file changed, 26 insertions(+), 25 deletions(-)

diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
index c1e08ec..0f83a4c 100644
--- a/hw/i386/kvm/pci-assign.c
+++ b/hw/i386/kvm/pci-assign.c
@@ -131,8 +131,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;
@@ -689,19 +691,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)
@@ -756,7 +757,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)
@@ -995,7 +996,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);
@@ -1011,9 +1012,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");
         }
@@ -1074,14 +1075,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_skipped(entry)) {
             continue;
@@ -1093,13 +1094,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;
@@ -1127,7 +1128,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);
@@ -1139,7 +1140,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;
@@ -1567,7 +1568,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;
@@ -1581,7 +1582,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	other threads:[~2013-05-09 16:36 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-09 16:35 [Qemu-devel] [PATCH 0/2] pci-assign: MSI affinity support Alex Williamson
2013-05-09 16:35 ` Alex Williamson [this message]
2013-05-09 16:36 ` [Qemu-devel] [PATCH 2/2] pci-assign: Add " Alex Williamson
2013-05-12 11:01   ` Michael S. Tsirkin
2013-05-10 12:40 ` [Qemu-devel] [PATCH 0/2] pci-assign: " Jan Kiszka
2013-05-10 15:47   ` Alex Williamson
2013-05-12 11:23   ` Michael S. Tsirkin
2013-05-22 22:59 ` Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130509163559.22536.97895.stgit@bling.home \
    --to=alex.williamson@redhat.com \
    --cc=jan.kiszka@siemens.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).