diff mbox

[19/19] pci-assign: Gracefully handle missing in-kernel irqchip support

Message ID bf4b8895f913dc6d8356a5f4560c41f022ddf448.1345125266.git.jan.kiszka@siemens.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jan Kiszka Aug. 16, 2012, 1:54 p.m. UTC
Inform the user properly when trying to register an IRQ-using device
without in-kernel irqchip enabled.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 hw/kvm/pci-assign.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)
diff mbox

Patch

diff --git a/hw/kvm/pci-assign.c b/hw/kvm/pci-assign.c
index 4f5daf3..9cce02c 100644
--- a/hw/kvm/pci-assign.c
+++ b/hw/kvm/pci-assign.c
@@ -862,6 +862,16 @@  static int assign_device(AssignedDevice *dev)
     return r;
 }
 
+static bool check_irqchip_in_kernel(void)
+{
+    if (kvm_irqchip_in_kernel()) {
+        return true;
+    }
+    error_report("pci-assign: error: requires KVM with in-kernel irqchip "
+                 "enabled");
+    return false;
+}
+
 static int assign_intx(AssignedDevice *dev)
 {
     AssignedIRQType new_type;
@@ -875,6 +885,10 @@  static int assign_intx(AssignedDevice *dev)
         return 0;
     }
 
+    if (!check_irqchip_in_kernel()) {
+        return -ENOTSUP;
+    }
+
     pci_device_set_intx_routing_notifier(&dev->dev,
                                          assigned_dev_update_irq_routing);
 
@@ -1236,6 +1250,9 @@  static int assigned_device_pci_cap_init(PCIDevice *pci_dev)
      * MSI capability is the 1st capability in capability config */
     pos = pci_find_cap_offset(pci_dev, PCI_CAP_ID_MSI, 0);
     if (pos != 0 && kvm_check_extension(kvm_state, KVM_CAP_ASSIGN_DEV_IRQ)) {
+        if (!check_irqchip_in_kernel()) {
+            return -ENOTSUP;
+        }
         dev->cap.available |= ASSIGNED_DEVICE_CAP_MSI;
         /* Only 32-bit/no-mask currently supported */
         ret = pci_add_capability(pci_dev, PCI_CAP_ID_MSI, pos, 10);
@@ -1262,6 +1279,9 @@  static int assigned_device_pci_cap_init(PCIDevice *pci_dev)
         int bar_nr;
         uint32_t msix_table_entry;
 
+        if (!check_irqchip_in_kernel()) {
+            return -ENOTSUP;
+        }
         dev->cap.available |= ASSIGNED_DEVICE_CAP_MSIX;
         ret = pci_add_capability(pci_dev, PCI_CAP_ID_MSIX, pos, 12);
         if (ret < 0) {