Patchwork [RFC,33/45] qemu-kvm: Factor out kvm_device_intx_assign

login
register
mail settings
Submitter Jan Kiszka
Date Oct. 17, 2011, 9:28 a.m.
Message ID <5438180d3789308bc022bcc76089233e6f0aea5b.1318843693.git.jan.kiszka@siemens.com>
Download mbox | patch
Permalink /patch/120143/
State New
Headers show

Comments

Jan Kiszka - Oct. 17, 2011, 9:28 a.m.
Avoid passing kvm_assigned_irq on INTx assignment and separate this
function from (to-be-refactored) MSI/MSI-X assignment.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 hw/device-assignment.c |   21 ++++++++++-----------
 qemu-kvm.c             |   17 +++++++++++++++++
 qemu-kvm.h             |    2 ++
 3 files changed, 29 insertions(+), 11 deletions(-)

Patch

diff --git a/hw/device-assignment.c b/hw/device-assignment.c
index e5ac54c..f145a84 100644
--- a/hw/device-assignment.c
+++ b/hw/device-assignment.c
@@ -825,7 +825,7 @@  static void deassign_irq(AssignedDevice *dev)
 
 static int assign_intx(AssignedDevice *dev)
 {
-    struct kvm_assigned_irq assigned_irq_data;
+    uint32_t irq_type = 0;
     int irq, r;
 
     /* Interrupt PIN 0 means don't use INTx */
@@ -841,17 +841,16 @@  static int assign_intx(AssignedDevice *dev)
 
     deassign_irq(dev);
 
-    memset(&assigned_irq_data, 0, sizeof(assigned_irq_data));
-    assigned_irq_data.assigned_dev_id = calc_assigned_dev_id(dev);
-    assigned_irq_data.guest_irq = irq;
-    assigned_irq_data.flags = KVM_DEV_IRQ_GUEST_INTX;
+    irq_type = KVM_DEV_IRQ_GUEST_INTX;
     if (dev->features & ASSIGNED_DEVICE_PREFER_MSI_MASK &&
-        dev->cap.available & ASSIGNED_DEVICE_CAP_MSI)
-        assigned_irq_data.flags |= KVM_DEV_IRQ_HOST_MSI;
-    else
-        assigned_irq_data.flags |= KVM_DEV_IRQ_HOST_INTX;
+        dev->cap.available & ASSIGNED_DEVICE_CAP_MSI) {
+        irq_type |= KVM_DEV_IRQ_HOST_MSI;
+    } else {
+        irq_type |= KVM_DEV_IRQ_HOST_INTX;
+    }
 
-    r = kvm_assign_irq(kvm_state, &assigned_irq_data);
+    r = kvm_device_intx_assign(kvm_state, calc_assigned_dev_id(dev), irq_type,
+                               irq);
     if (r < 0) {
         fprintf(stderr, "Failed to assign irq for \"%s\": %s\n",
                 dev->dev.qdev.id, strerror(-r));
@@ -861,7 +860,7 @@  static int assign_intx(AssignedDevice *dev)
     }
 
     dev->girq = irq;
-    dev->irq_requested_type = assigned_irq_data.flags;
+    dev->irq_requested_type = irq_type;
     return r;
 }
 
diff --git a/qemu-kvm.c b/qemu-kvm.c
index c24e93c..0086514 100644
--- a/qemu-kvm.c
+++ b/qemu-kvm.c
@@ -194,6 +194,23 @@  static int kvm_old_assign_irq(KVMState *s,
     return kvm_vm_ioctl(s, KVM_ASSIGN_IRQ, assigned_irq);
 }
 
+int kvm_device_intx_assign(KVMState *s, uint32_t dev_id,
+                           uint32_t host_irq_type, uint32_t guest_irq)
+{
+    struct kvm_assigned_irq assigned_irq;
+
+    assigned_irq.assigned_dev_id = dev_id;
+    assigned_irq.guest_irq = guest_irq;
+    assigned_irq.flags = KVM_DEV_IRQ_GUEST_INTX |
+        (host_irq_type & (KVM_DEV_IRQ_HOST_INTX | KVM_DEV_IRQ_HOST_MSI));
+    if (kvm_check_extension(s, KVM_CAP_ASSIGN_DEV_IRQ)) {
+        return kvm_vm_ioctl(s, KVM_ASSIGN_DEV_IRQ, &assigned_irq);
+    } else {
+        assigned_irq.host_irq = 0;
+        return kvm_vm_ioctl(s, KVM_ASSIGN_IRQ, &assigned_irq);
+    }
+}
+
 #ifdef KVM_CAP_ASSIGN_DEV_IRQ
 int kvm_assign_irq(KVMState *s, struct kvm_assigned_irq *assigned_irq)
 {
diff --git a/qemu-kvm.h b/qemu-kvm.h
index 7cdb5a8..783df7f 100644
--- a/qemu-kvm.h
+++ b/qemu-kvm.h
@@ -150,6 +150,8 @@  int kvm_assign_pci_device(KVMState *s,
  */
 int kvm_assign_irq(KVMState *s, struct kvm_assigned_irq *assigned_irq);
 
+int kvm_device_intx_assign(KVMState *s, uint32_t dev_id,
+                           uint32_t host_irq_type, uint32_t guest_irq);
 int kvm_device_irq_deassign(KVMState *s, uint32_t dev_id, uint32_t type);
 
 /*!