summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Kiszka <jan.kiszka@siemens.com>2012-08-17 08:58:57 +0200
committerMarcelo Tosatti <mtosatti@redhat.com>2012-08-23 17:02:33 -0300
commit343c765f3fdb5fb670b18d9580802e5255618899 (patch)
tree892e5c2ecbcbed7a6b64030de856ed43f6755dc7
parentf619a74f47758534727ea4afad1e913c31f4a5cd (diff)
pci-assign: Factor out kvm_device_msix_supported
Encapsulate the ugly check if MSI-X assignment is supported in a separate helper function. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
-rw-r--r--hw/device-assignment.c5
-rw-r--r--target-i386/kvm.c7
-rw-r--r--target-i386/kvm_i386.h1
3 files changed, 9 insertions, 4 deletions
diff --git a/hw/device-assignment.c b/hw/device-assignment.c
index 1d0af3440..80ac2fc5a 100644
--- a/hw/device-assignment.c
+++ b/hw/device-assignment.c
@@ -1283,10 +1283,7 @@ static int assigned_device_pci_cap_init(PCIDevice *pci_dev)
}
/* Expose MSI-X capability */
pos = pci_find_cap_offset(pci_dev, PCI_CAP_ID_MSIX, 0);
- /* Would really like to test kvm_check_extension(, KVM_CAP_DEVICE_MSIX),
- * but the kernel doesn't expose it. Instead do a dummy call to
- * KVM_ASSIGN_SET_MSIX_NR to see if it exists. */
- if (pos != 0 && kvm_assign_set_msix_nr(kvm_state, NULL) == -EFAULT) {
+ if (pos != 0 && kvm_device_msix_supported(kvm_state)) {
int bar_nr;
uint32_t msix_table_entry;
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 51be7b564..789b3612e 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -2155,6 +2155,13 @@ int kvm_device_msi_deassign(KVMState *s, uint32_t dev_id)
KVM_DEV_IRQ_HOST_MSI);
}
+bool kvm_device_msix_supported(KVMState *s)
+{
+ /* The kernel lacks a corresponding KVM_CAP, so we probe by calling
+ * KVM_ASSIGN_SET_MSIX_NR with an invalid parameter. */
+ return kvm_vm_ioctl(s, KVM_ASSIGN_SET_MSIX_NR, NULL) == -EFAULT;
+}
+
int kvm_device_msix_deassign(KVMState *s, uint32_t dev_id)
{
return kvm_deassign_irq_internal(s, dev_id, KVM_DEV_IRQ_GUEST_MSIX |
diff --git a/target-i386/kvm_i386.h b/target-i386/kvm_i386.h
index e827f5b5c..6f66b6d7d 100644
--- a/target-i386/kvm_i386.h
+++ b/target-i386/kvm_i386.h
@@ -27,6 +27,7 @@ int kvm_device_intx_deassign(KVMState *s, uint32_t dev_id, bool use_host_msi);
int kvm_device_msi_assign(KVMState *s, uint32_t dev_id, int virq);
int kvm_device_msi_deassign(KVMState *s, uint32_t dev_id);
+bool kvm_device_msix_supported(KVMState *s);
int kvm_device_msix_deassign(KVMState *s, uint32_t dev_id);
#endif