From: Alex Williamson <alex.williamson@redhat.com>
To: qemu-devel@nongnu.org
Cc: kvm@vger.kernel.org
Subject: [Qemu-devel] [RFC PATCH 3/4] pci-assign: Refactor MSI virq array
Date: Tue, 27 Nov 2012 15:00:53 -0700 [thread overview]
Message-ID: <20121127220053.5751.92647.stgit@bling.home> (raw)
In-Reply-To: <20121127215203.5751.6523.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/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);
}
next prev parent reply other threads:[~2012-11-27 22:01 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-27 22:00 [Qemu-devel] [RFC PATCH 0/4] MSI affinity for assigned devices Alex Williamson
2012-11-27 22:00 ` [Qemu-devel] [RFC PATCH 1/4] kvm: Stub kvm_irqchip_update_msi_route Alex Williamson
2012-11-27 22:00 ` [Qemu-devel] [RFC PATCH 2/4] vfio-pci: Add support for MSI affinity Alex Williamson
2012-11-27 22:00 ` Alex Williamson [this message]
2012-11-27 22:01 ` [Qemu-devel] [RFC PATCH 4/4] pci-assign: Add MSI affinity support Alex Williamson
2012-11-27 23:08 ` [Qemu-devel] [RFC PATCH 0/4] MSI affinity for assigned devices Jan Kiszka
2012-11-27 23:21 ` Alex Williamson
2012-11-29 6:57 ` Jan Kiszka
2012-11-28 16:32 ` [Qemu-devel] PCI device pass through support Krishna J
2012-11-28 17:00 ` Alex Williamson
2013-01-07 20:14 ` [Qemu-devel] [RFC PATCH 0/4] MSI affinity for assigned devices Krishna J
2013-01-07 20:52 ` Alex Williamson
2013-01-07 21:22 ` Krishna J
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=20121127220053.5751.92647.stgit@bling.home \
--to=alex.williamson@redhat.com \
--cc=kvm@vger.kernel.org \
--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).