[PATCH v2 2/8] kvm: drop kvm_context parameter from msix-related kvm functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The kvm_context parameter serves no useful purpose since it's a global (and
all callers reference that global); on the other hand it prevents the build
when kvm is not configured in since the kvm_context symbol is not defined.

Remove the parameter and replace it by the global kvm_context in callees.

Signed-off-by: Avi Kivity <avi@xxxxxxxxxx>
---
 hw/device-assignment.c |   14 +++++++-------
 hw/msix.c              |   20 ++++++++++----------
 qemu-kvm-x86.c         |   14 +++++++-------
 qemu-kvm.c             |   33 +++++++++++++++++++--------------
 qemu-kvm.h             |   36 ++++++++++--------------------------
 5 files changed, 53 insertions(+), 64 deletions(-)

diff --git a/hw/device-assignment.c b/hw/device-assignment.c
index 26cb797..2605bd1 100644
--- a/hw/device-assignment.c
+++ b/hw/device-assignment.c
@@ -767,7 +767,7 @@ static void free_dev_irq_entries(AssignedDevice *dev)
     int i;
 
     for (i = 0; i < dev->irq_entries_nr; i++)
-        kvm_del_routing_entry(kvm_context, &dev->entry[i]);
+        kvm_del_routing_entry(&dev->entry[i]);
     free(dev->entry);
     dev->entry = NULL;
     dev->irq_entries_nr = 0;
@@ -1080,15 +1080,15 @@ static void assigned_dev_update_msi(PCIDevice *pci_dev, unsigned int ctrl_pos)
         assigned_dev->entry->u.msi.data = *(uint16_t *)(pci_dev->config +
                 pci_dev->cap.start + PCI_MSI_DATA_32);
         assigned_dev->entry->type = KVM_IRQ_ROUTING_MSI;
-        r = kvm_get_irq_route_gsi(kvm_context);
+        r = kvm_get_irq_route_gsi();
         if (r < 0) {
             perror("assigned_dev_update_msi: kvm_get_irq_route_gsi");
             return;
         }
         assigned_dev->entry->gsi = r;
 
-        kvm_add_routing_entry(kvm_context, assigned_dev->entry);
-        if (kvm_commit_irq_routes(kvm_context) < 0) {
+        kvm_add_routing_entry(assigned_dev->entry);
+        if (kvm_commit_irq_routes() < 0) {
             perror("assigned_dev_update_msi: kvm_commit_irq_routes");
             assigned_dev->cap.state &= ~ASSIGNED_DEVICE_MSI_ENABLED;
             return;
@@ -1170,7 +1170,7 @@ static int assigned_dev_update_msix_mmio(PCIDevice *pci_dev)
         memcpy(&msg_addr, va + i * 16, 4);
         memcpy(&msg_upper_addr, va + i * 16 + 4, 4);
 
-        r = kvm_get_irq_route_gsi(kvm_context);
+        r = kvm_get_irq_route_gsi();
         if (r < 0)
             return r;
 
@@ -1181,7 +1181,7 @@ static int assigned_dev_update_msix_mmio(PCIDevice *pci_dev)
         adev->entry[entries_nr].u.msi.address_hi = msg_upper_addr;
         adev->entry[entries_nr].u.msi.data = msg_data;
         DEBUG("MSI-X data 0x%x, MSI-X addr_lo 0x%x\n!", msg_data, msg_addr);
-	kvm_add_routing_entry(kvm_context, &adev->entry[entries_nr]);
+	kvm_add_routing_entry(&adev->entry[entries_nr]);
 
         msix_entry.gsi = adev->entry[entries_nr].gsi;
         msix_entry.entry = i;
@@ -1195,7 +1195,7 @@ static int assigned_dev_update_msix_mmio(PCIDevice *pci_dev)
         entries_nr ++;
     }
 
-    if (r == 0 && kvm_commit_irq_routes(kvm_context) < 0) {
+    if (r == 0 && kvm_commit_irq_routes() < 0) {
 	    perror("assigned_dev_update_msix_mmio: kvm_commit_irq_routes");
 	    return -EINVAL;
     }
diff --git a/hw/msix.c b/hw/msix.c
index 162faa7..6abf059 100644
--- a/hw/msix.c
+++ b/hw/msix.c
@@ -54,12 +54,12 @@ static void kvm_msix_free(PCIDevice *dev)
     int vector, changed = 0;
     for (vector = 0; vector < dev->msix_entries_nr; ++vector) {
         if (dev->msix_entry_used[vector]) {
-            kvm_del_routing_entry(kvm_context, &dev->msix_irq_entries[vector]);
+            kvm_del_routing_entry(&dev->msix_irq_entries[vector]);
             changed = 1;
         }
     }
     if (changed) {
-        kvm_commit_irq_routes(kvm_context);
+        kvm_commit_irq_routes();
     }
 }
 
@@ -92,14 +92,14 @@ static void kvm_msix_update(PCIDevice *dev, int vector,
     kvm_msix_routing_entry(dev, vector, &e);
     if (memcmp(&entry->u.msi, &e.u.msi, sizeof entry->u.msi)) {
         int r;
-        r = kvm_update_routing_entry(kvm_context, entry, &e);
+        r = kvm_update_routing_entry(entry, &e);
         if (r) {
             fprintf(stderr, "%s: kvm_update_routing_entry failed: %s\n", __func__,
 		    strerror(-r));
             exit(1);
         }
         memcpy(&entry->u.msi, &e.u.msi, sizeof entry->u.msi);
-        r = kvm_commit_irq_routes(kvm_context);
+        r = kvm_commit_irq_routes();
         if (r) {
             fprintf(stderr, "%s: kvm_commit_irq_routes failed: %s\n", __func__,
 		    strerror(-r));
@@ -113,27 +113,27 @@ static int kvm_msix_add(PCIDevice *dev, unsigned vector)
     struct kvm_irq_routing_entry *entry = dev->msix_irq_entries + vector;
     int r;
 
-    if (!kvm_has_gsi_routing(kvm_context)) {
+    if (!kvm_has_gsi_routing()) {
         fprintf(stderr, "Warning: no MSI-X support found. "
                 "At least kernel 2.6.30 is required for MSI-X support.\n"
                );
         return -EOPNOTSUPP;
     }
 
-    r = kvm_get_irq_route_gsi(kvm_context);
+    r = kvm_get_irq_route_gsi();
     if (r < 0) {
         fprintf(stderr, "%s: kvm_get_irq_route_gsi failed: %s\n", __func__, strerror(-r));
         return r;
     }
     entry->gsi = r;
     kvm_msix_routing_entry(dev, vector, entry);
-    r = kvm_add_routing_entry(kvm_context, entry);
+    r = kvm_add_routing_entry(entry);
     if (r < 0) {
         fprintf(stderr, "%s: kvm_add_routing_entry failed: %s\n", __func__, strerror(-r));
         return r;
     }
 
-    r = kvm_commit_irq_routes(kvm_context);
+    r = kvm_commit_irq_routes();
     if (r < 0) {
         fprintf(stderr, "%s: kvm_commit_irq_routes failed: %s\n", __func__, strerror(-r));
         return r;
@@ -146,8 +146,8 @@ static void kvm_msix_del(PCIDevice *dev, unsigned vector)
     if (dev->msix_entry_used[vector]) {
         return;
     }
-    kvm_del_routing_entry(kvm_context, &dev->msix_irq_entries[vector]);
-    kvm_commit_irq_routes(kvm_context);
+    kvm_del_routing_entry(&dev->msix_irq_entries[vector]);
+    kvm_commit_irq_routes();
 }
 #else
 
diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c
index bb09fd8..59aacd0 100644
--- a/qemu-kvm-x86.c
+++ b/qemu-kvm-x86.c
@@ -1370,34 +1370,34 @@ int kvm_arch_init_irq_routing(void)
 {
     int i, r;
 
-    if (kvm_irqchip && kvm_has_gsi_routing(kvm_context)) {
-        kvm_clear_gsi_routes(kvm_context);
+    if (kvm_irqchip && kvm_has_gsi_routing()) {
+        kvm_clear_gsi_routes();
         for (i = 0; i < 8; ++i) {
             if (i == 2) {
                 continue;
             }
-            r = kvm_add_irq_route(kvm_context, i, KVM_IRQCHIP_PIC_MASTER, i);
+            r = kvm_add_irq_route(i, KVM_IRQCHIP_PIC_MASTER, i);
             if (r < 0) {
                 return r;
             }
         }
         for (i = 8; i < 16; ++i) {
-            r = kvm_add_irq_route(kvm_context, i, KVM_IRQCHIP_PIC_SLAVE, i - 8);
+            r = kvm_add_irq_route(i, KVM_IRQCHIP_PIC_SLAVE, i - 8);
             if (r < 0) {
                 return r;
             }
         }
         for (i = 0; i < 24; ++i) {
             if (i == 0 && irq0override) {
-                r = kvm_add_irq_route(kvm_context, i, KVM_IRQCHIP_IOAPIC, 2);
+                r = kvm_add_irq_route(i, KVM_IRQCHIP_IOAPIC, 2);
             } else if (i != 2 || !irq0override) {
-                r = kvm_add_irq_route(kvm_context, i, KVM_IRQCHIP_IOAPIC, i);
+                r = kvm_add_irq_route(i, KVM_IRQCHIP_IOAPIC, i);
             }
             if (r < 0) {
                 return r;
             }
         }
-        kvm_commit_irq_routes(kvm_context);
+        kvm_commit_irq_routes();
     }
     return 0;
 }
diff --git a/qemu-kvm.c b/qemu-kvm.c
index e78d850..3966523 100644
--- a/qemu-kvm.c
+++ b/qemu-kvm.c
@@ -800,7 +800,7 @@ int kvm_reinject_control(kvm_context_t kvm, int pit_reinject)
     return -ENOSYS;
 }
 
-int kvm_has_gsi_routing(kvm_context_t kvm)
+int kvm_has_gsi_routing(void)
 {
     int r = 0;
 
@@ -819,9 +819,11 @@ int kvm_get_gsi_count(kvm_context_t kvm)
 #endif
 }
 
-int kvm_clear_gsi_routes(kvm_context_t kvm)
+int kvm_clear_gsi_routes(void)
 {
 #ifdef KVM_CAP_IRQ_ROUTING
+    kvm_context_t kvm = kvm_context;
+
     kvm->irq_routes->nr = 0;
     return 0;
 #else
@@ -829,10 +831,10 @@ int kvm_clear_gsi_routes(kvm_context_t kvm)
 #endif
 }
 
-int kvm_add_routing_entry(kvm_context_t kvm,
-                          struct kvm_irq_routing_entry *entry)
+int kvm_add_routing_entry(struct kvm_irq_routing_entry *entry)
 {
 #ifdef KVM_CAP_IRQ_ROUTING
+    kvm_context_t kvm = kvm_context;
     struct kvm_irq_routing *z;
     struct kvm_irq_routing_entry *new;
     int n, size;
@@ -867,7 +869,7 @@ int kvm_add_routing_entry(kvm_context_t kvm,
 #endif
 }
 
-int kvm_add_irq_route(kvm_context_t kvm, int gsi, int irqchip, int pin)
+int kvm_add_irq_route(int gsi, int irqchip, int pin)
 {
 #ifdef KVM_CAP_IRQ_ROUTING
     struct kvm_irq_routing_entry e;
@@ -877,16 +879,16 @@ int kvm_add_irq_route(kvm_context_t kvm, int gsi, int irqchip, int pin)
     e.flags = 0;
     e.u.irqchip.irqchip = irqchip;
     e.u.irqchip.pin = pin;
-    return kvm_add_routing_entry(kvm, &e);
+    return kvm_add_routing_entry(&e);
 #else
     return -ENOSYS;
 #endif
 }
 
-int kvm_del_routing_entry(kvm_context_t kvm,
-                          struct kvm_irq_routing_entry *entry)
+int kvm_del_routing_entry(struct kvm_irq_routing_entry *entry)
 {
 #ifdef KVM_CAP_IRQ_ROUTING
+    kvm_context_t kvm = kvm_context;
     struct kvm_irq_routing_entry *e, *p;
     int i, gsi, found = 0;
 
@@ -943,11 +945,11 @@ int kvm_del_routing_entry(kvm_context_t kvm,
 #endif
 }
 
-int kvm_update_routing_entry(kvm_context_t kvm,
-                             struct kvm_irq_routing_entry *entry,
+int kvm_update_routing_entry(struct kvm_irq_routing_entry *entry,
                              struct kvm_irq_routing_entry *newentry)
 {
 #ifdef KVM_CAP_IRQ_ROUTING
+    kvm_context_t kvm = kvm_context;
     struct kvm_irq_routing_entry *e;
     int i;
 
@@ -987,7 +989,7 @@ int kvm_update_routing_entry(kvm_context_t kvm,
 #endif
 }
 
-int kvm_del_irq_route(kvm_context_t kvm, int gsi, int irqchip, int pin)
+int kvm_del_irq_route(int gsi, int irqchip, int pin)
 {
 #ifdef KVM_CAP_IRQ_ROUTING
     struct kvm_irq_routing_entry e;
@@ -997,15 +999,17 @@ int kvm_del_irq_route(kvm_context_t kvm, int gsi, int irqchip, int pin)
     e.flags = 0;
     e.u.irqchip.irqchip = irqchip;
     e.u.irqchip.pin = pin;
-    return kvm_del_routing_entry(kvm, &e);
+    return kvm_del_routing_entry(&e);
 #else
     return -ENOSYS;
 #endif
 }
 
-int kvm_commit_irq_routes(kvm_context_t kvm)
+int kvm_commit_irq_routes(void)
 {
 #ifdef KVM_CAP_IRQ_ROUTING
+    kvm_context_t kvm = kvm_context;
+
     kvm->irq_routes->flags = 0;
     return kvm_vm_ioctl(kvm_state, KVM_SET_GSI_ROUTING, kvm->irq_routes);
 #else
@@ -1013,8 +1017,9 @@ int kvm_commit_irq_routes(kvm_context_t kvm)
 #endif
 }
 
-int kvm_get_irq_route_gsi(kvm_context_t kvm)
+int kvm_get_irq_route_gsi(void)
 {
+    kvm_context_t kvm = kvm_context;
     int i, bit;
     uint32_t *buf = kvm->used_gsi_bitmap;
 
diff --git a/qemu-kvm.h b/qemu-kvm.h
index 9809574..1030a02 100644
--- a/qemu-kvm.h
+++ b/qemu-kvm.h
@@ -665,10 +665,8 @@ int kvm_deassign_pci_device(kvm_context_t kvm,
  *
  * Checks whether kvm can reroute interrupts among the various interrupt
  * controllers.
- *
- * \param kvm Pointer to the current kvm_context
  */
-int kvm_has_gsi_routing(kvm_context_t kvm);
+int kvm_has_gsi_routing(void);
 
 /*!
  * \brief Determines the number of gsis that can be routed
@@ -687,29 +685,24 @@ int kvm_get_gsi_count(kvm_context_t kvm);
  * Clears the temporary irq routing table.  Nothing is committed to the
  * running VM.
  *
- * \param kvm Pointer to the current kvm_context
  */
-int kvm_clear_gsi_routes(kvm_context_t kvm);
+int kvm_clear_gsi_routes(void);
 
 /*!
  * \brief Adds an irq route to the temporary irq routing table
  *
  * Adds an irq route to the temporary irq routing table.  Nothing is
  * committed to the running VM.
- *
- * \param kvm Pointer to the current kvm_context
  */
-int kvm_add_irq_route(kvm_context_t kvm, int gsi, int irqchip, int pin);
+int kvm_add_irq_route(int gsi, int irqchip, int pin);
 
 /*!
  * \brief Removes an irq route from the temporary irq routing table
  *
  * Adds an irq route to the temporary irq routing table.  Nothing is
  * committed to the running VM.
- *
- * \param kvm Pointer to the current kvm_context
  */
-int kvm_del_irq_route(kvm_context_t kvm, int gsi, int irqchip, int pin);
+int kvm_del_irq_route(int gsi, int irqchip, int pin);
 
 struct kvm_irq_routing_entry;
 /*!
@@ -717,22 +710,16 @@ struct kvm_irq_routing_entry;
  *
  * Adds a filled routing entry to the temporary irq routing table. Nothing is
  * committed to the running VM.
- *
- * \param kvm Pointer to the current kvm_context
  */
-int kvm_add_routing_entry(kvm_context_t kvm,
-                          struct kvm_irq_routing_entry *entry);
+int kvm_add_routing_entry(struct kvm_irq_routing_entry *entry);
 
 /*!
  * \brief Removes a routing from the temporary irq routing table
  *
  * Remove a routing to the temporary irq routing table.  Nothing is
  * committed to the running VM.
- *
- * \param kvm Pointer to the current kvm_context
  */
-int kvm_del_routing_entry(kvm_context_t kvm,
-                          struct kvm_irq_routing_entry *entry);
+int kvm_del_routing_entry(struct kvm_irq_routing_entry *entry);
 
 /*!
  * \brief Updates a routing in the temporary irq routing table
@@ -740,11 +727,8 @@ int kvm_del_routing_entry(kvm_context_t kvm,
  * Update a routing in the temporary irq routing table
  * with a new value. entry type and GSI can not be changed.
  * Nothing is committed to the running VM.
- *
- * \param kvm Pointer to the current kvm_context
  */
-int kvm_update_routing_entry(kvm_context_t kvm,
-                             struct kvm_irq_routing_entry *entry,
+int kvm_update_routing_entry(struct kvm_irq_routing_entry *entry,
                              struct kvm_irq_routing_entry *newentry);
 
 /*!
@@ -754,7 +738,7 @@ int kvm_update_routing_entry(kvm_context_t kvm,
  *
  * \param kvm Pointer to the current kvm_context
  */
-int kvm_commit_irq_routes(kvm_context_t kvm);
+int kvm_commit_irq_routes(void);
 
 /*!
  * \brief Get unused GSI number for irq routing table
@@ -763,7 +747,7 @@ int kvm_commit_irq_routes(kvm_context_t kvm);
  *
  * \param kvm Pointer to the current kvm_context
  */
-int kvm_get_irq_route_gsi(kvm_context_t kvm);
+int kvm_get_irq_route_gsi(void);
 
 /*!
  * \brief Create a file descriptor for injecting interrupts
@@ -903,7 +887,7 @@ int kvm_arch_halt(CPUState *env);
 int handle_tpr_access(void *opaque, CPUState *env, uint64_t rip,
                       int is_write);
 
-#define qemu_kvm_has_gsi_routing() kvm_has_gsi_routing(kvm_context)
+#define qemu_kvm_has_gsi_routing() kvm_has_gsi_routing()
 #ifdef TARGET_I386
 #define qemu_kvm_has_pit_state2() kvm_has_pit_state2(kvm_context)
 #endif
-- 
1.7.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux