Patchwork [RFC,32/45] pci-assign: Factor out deassign_irq

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

Comments

Jan Kiszka - Oct. 17, 2011, 9:28 a.m.
Will have more users soon.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 hw/device-assignment.c |   30 ++++++++++++++++++------------
 1 files changed, 18 insertions(+), 12 deletions(-)

Patch

diff --git a/hw/device-assignment.c b/hw/device-assignment.c
index e0b9cfe..e5ac54c 100644
--- a/hw/device-assignment.c
+++ b/hw/device-assignment.c
@@ -807,10 +807,25 @@  static int assign_device(AssignedDevice *dev)
     return r;
 }
 
+static void deassign_irq(AssignedDevice *dev)
+{
+    int ret;
+
+    if (dev->irq_requested_type) {
+        ret = kvm_device_irq_deassign(kvm_state,
+                                      calc_assigned_dev_id(dev),
+                                      dev->irq_requested_type);
+        if (ret) {
+            perror("assigned_dev: deassign irq");
+        }
+        dev->girq = -1;
+        dev->irq_requested_type = 0;
+    }
+}
+
 static int assign_intx(AssignedDevice *dev)
 {
     struct kvm_assigned_irq assigned_irq_data;
-    uint32_t dev_id;
     int irq, r;
 
     /* Interrupt PIN 0 means don't use INTx */
@@ -824,19 +839,10 @@  static int assign_intx(AssignedDevice *dev)
         return 0;
     }
 
-    dev_id = calc_assigned_dev_id(dev);
-
-    if (dev->irq_requested_type) {
-        r = kvm_device_irq_deassign(kvm_state, dev_id,
-                                    dev->irq_requested_type);
-        if (r) {
-            perror("assign_intx: deassign");
-        }
-        dev->irq_requested_type = 0;
-    }
+    deassign_irq(dev);
 
     memset(&assigned_irq_data, 0, sizeof(assigned_irq_data));
-    assigned_irq_data.assigned_dev_id = dev_id;
+    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;
     if (dev->features & ASSIGNED_DEVICE_PREFER_MSI_MASK &&