1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include "qemu/osdep.h"
23#include "qmp-commands.h"
24#include "hw/boards.h"
25#include "kvm_arm.h"
26
27static GICCapability *gic_cap_new(int version)
28{
29 GICCapability *cap = g_new0(GICCapability, 1);
30 cap->version = version;
31
32 cap->emulated = false;
33 cap->kernel = false;
34 return cap;
35}
36
37static GICCapabilityList *gic_cap_list_add(GICCapabilityList *head,
38 GICCapability *cap)
39{
40 GICCapabilityList *item = g_new0(GICCapabilityList, 1);
41 item->value = cap;
42 item->next = head;
43 return item;
44}
45
46static inline void gic_cap_kvm_probe(GICCapability *v2, GICCapability *v3)
47{
48#ifdef CONFIG_KVM
49 int fdarray[3];
50
51 if (!kvm_arm_create_scratch_host_vcpu(NULL, fdarray, NULL)) {
52 return;
53 }
54
55
56 if (kvm_device_supported(fdarray[1], KVM_DEV_TYPE_ARM_VGIC_V2)) {
57 v2->kernel = true;
58 }
59
60
61 if (kvm_device_supported(fdarray[1], KVM_DEV_TYPE_ARM_VGIC_V3)) {
62 v3->kernel = true;
63 }
64
65 kvm_arm_destroy_scratch_host_vcpu(fdarray);
66#endif
67}
68
69GICCapabilityList *qmp_query_gic_capabilities(Error **errp)
70{
71 GICCapabilityList *head = NULL;
72 GICCapability *v2 = gic_cap_new(2), *v3 = gic_cap_new(3);
73
74 v2->emulated = true;
75 v3->emulated = true;
76
77 gic_cap_kvm_probe(v2, v3);
78
79 head = gic_cap_list_add(head, v2);
80 head = gic_cap_list_add(head, v3);
81
82 return head;
83}
84