diff mbox

[3/3] arm: implement query-gic-capability

Message ID 1456224728-28163-4-git-send-email-peterx@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Peter Xu Feb. 23, 2016, 10:52 a.m. UTC
For emulated ARM VM, only gicv2 is supported. We need to add gicv3 in
when emulated gicv3 ready. For KVM accelerated ARM VM, we detect the
capability bits using ioctls.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 target-arm/machine.c | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/target-arm/machine.c b/target-arm/machine.c
index 9e10232..7915096 100644
--- a/target-arm/machine.c
+++ b/target-arm/machine.c
@@ -1,3 +1,4 @@ 
+#include <linux/kvm.h>
 #include "qemu/osdep.h"
 #include "hw/hw.h"
 #include "hw/boards.h"
@@ -348,9 +349,38 @@  const char *gicv3_class_name(void)
     exit(1);
 }
 
+static GICTypeList *gic_capability_add(GICTypeList *head, GICType type)
+{
+    GICTypeList *item = g_new0(GICTypeList, 1);
+    item->value = type;
+    item->next = head;
+    return item;
+}
+
 GICTypeList *qmp_query_gic_capability(Error **errp);
 
 GICTypeList *qmp_query_gic_capability(Error **errp)
 {
-    return NULL;
+    /* We by default support emulated gicv2 */
+    GICTypeList *head = gic_capability_add(NULL, GIC_TYPE_GICV2);
+
+    /* TODO: add emulated gicv3 type when ready */
+
+#ifdef CONFIG_KVM
+    if (kvm_enabled()) {
+        /* Test KVM GICv2 */
+        if (kvm_create_device(kvm_state, KVM_DEV_TYPE_ARM_VGIC_V2,
+                              true) >= 0) {
+            head = gic_capability_add(head, GIC_TYPE_GICV2_KVM);
+        }
+
+        /* Test KVM GICv3 */
+        if (kvm_create_device(kvm_state, KVM_DEV_TYPE_ARM_VGIC_V3,
+                              true) >= 0) {
+            head = gic_capability_add(head, GIC_TYPE_GICV3_KVM);
+        }
+    }
+#endif
+
+    return head;
 }