2 * QEMU monitor.c for ARM.
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 #include "qemu/osdep.h"
24 #include "hw/boards.h"
26 #include "qapi/error.h"
27 #include "qapi/visitor.h"
28 #include "qapi/qobject-input-visitor.h"
29 #include "qapi/qapi-commands-machine-target.h"
30 #include "qapi/qapi-commands-misc-target.h"
31 #include "qapi/qmp/qdict.h"
32 #include "qom/qom-qobject.h"
34 static GICCapability
*gic_cap_new(int version
)
36 GICCapability
*cap
= g_new0(GICCapability
, 1);
37 cap
->version
= version
;
38 /* by default, support none */
39 cap
->emulated
= false;
44 static inline void gic_cap_kvm_probe(GICCapability
*v2
, GICCapability
*v3
)
49 if (!kvm_arm_create_scratch_host_vcpu(NULL
, fdarray
, NULL
)) {
54 if (kvm_device_supported(fdarray
[1], KVM_DEV_TYPE_ARM_VGIC_V2
)) {
59 if (kvm_device_supported(fdarray
[1], KVM_DEV_TYPE_ARM_VGIC_V3
)) {
63 kvm_arm_destroy_scratch_host_vcpu(fdarray
);
67 GICCapabilityList
*qmp_query_gic_capabilities(Error
**errp
)
69 GICCapabilityList
*head
= NULL
;
70 GICCapability
*v2
= gic_cap_new(2), *v3
= gic_cap_new(3);
75 gic_cap_kvm_probe(v2
, v3
);
77 QAPI_LIST_PREPEND(head
, v2
);
78 QAPI_LIST_PREPEND(head
, v3
);
83 QEMU_BUILD_BUG_ON(ARM_MAX_VQ
> 16);
86 * These are cpu model features we want to advertise. The order here
87 * matters as this is the order in which qmp_query_cpu_model_expansion
88 * will attempt to set them. If there are dependencies between features,
89 * then the order that considers those dependencies must be used.
91 static const char *cpu_model_advertised_features
[] = {
92 "aarch64", "pmu", "sve",
93 "sve128", "sve256", "sve384", "sve512",
94 "sve640", "sve768", "sve896", "sve1024", "sve1152", "sve1280",
95 "sve1408", "sve1536", "sve1664", "sve1792", "sve1920", "sve2048",
96 "kvm-no-adjvtime", "kvm-steal-time",
97 "pauth", "pauth-impdef", "pauth-qarma3",
101 CpuModelExpansionInfo
*qmp_query_cpu_model_expansion(CpuModelExpansionType type
,
105 CpuModelExpansionInfo
*expansion_info
;
106 const QDict
*qdict_in
;
113 if (type
!= CPU_MODEL_EXPANSION_TYPE_FULL
) {
114 error_setg(errp
, "The requested expansion type is not supported");
118 if (!kvm_enabled() && !strcmp(model
->name
, "host")) {
119 error_setg(errp
, "The CPU type '%s' requires KVM", model
->name
);
123 oc
= cpu_class_by_name(TYPE_ARM_CPU
, model
->name
);
125 error_setg(errp
, "The CPU type '%s' is not a recognized ARM CPU type",
131 bool supported
= false;
133 if (!strcmp(model
->name
, "host") || !strcmp(model
->name
, "max")) {
134 /* These are kvmarm's recommended cpu types */
136 } else if (current_machine
->cpu_type
) {
137 const char *cpu_type
= current_machine
->cpu_type
;
138 int len
= strlen(cpu_type
) - strlen(ARM_CPU_TYPE_SUFFIX
);
140 if (strlen(model
->name
) == len
&&
141 !strncmp(model
->name
, cpu_type
, len
)) {
142 /* KVM is enabled and we're using this type, so it works. */
147 error_setg(errp
, "We cannot guarantee the CPU type '%s' works "
148 "with KVM on this host", model
->name
);
153 obj
= object_new(object_class_get_name(oc
));
159 visitor
= qobject_input_visitor_new(model
->props
);
160 if (!visit_start_struct(visitor
, "model.props", NULL
, 0, errp
)) {
166 qdict_in
= qobject_to(QDict
, model
->props
);
168 while ((name
= cpu_model_advertised_features
[i
++]) != NULL
) {
169 if (qdict_get(qdict_in
, name
)) {
170 if (!object_property_set(obj
, name
, visitor
, &err
)) {
177 visit_check_struct(visitor
, &err
);
180 arm_cpu_finalize_features(ARM_CPU(obj
), &err
);
182 visit_end_struct(visitor
, NULL
);
186 error_propagate(errp
, err
);
190 arm_cpu_finalize_features(ARM_CPU(obj
), &error_abort
);
193 expansion_info
= g_new0(CpuModelExpansionInfo
, 1);
194 expansion_info
->model
= g_malloc0(sizeof(*expansion_info
->model
));
195 expansion_info
->model
->name
= g_strdup(model
->name
);
197 qdict_out
= qdict_new();
200 while ((name
= cpu_model_advertised_features
[i
++]) != NULL
) {
201 ObjectProperty
*prop
= object_property_find(obj
, name
);
206 value
= object_property_get_qobject(obj
, name
, &error_abort
);
208 qdict_put_obj(qdict_out
, name
, value
);
212 if (!qdict_size(qdict_out
)) {
213 qobject_unref(qdict_out
);
215 expansion_info
->model
->props
= QOBJECT(qdict_out
);
220 return expansion_info
;
223 static void arm_cpu_add_definition(gpointer data
, gpointer user_data
)
225 ObjectClass
*oc
= data
;
226 CpuDefinitionInfoList
**cpu_list
= user_data
;
227 CpuDefinitionInfo
*info
;
228 const char *typename
;
230 typename
= object_class_get_name(oc
);
231 info
= g_malloc0(sizeof(*info
));
232 info
->name
= cpu_model_from_type(typename
);
233 info
->q_typename
= g_strdup(typename
);
235 QAPI_LIST_PREPEND(*cpu_list
, info
);
238 CpuDefinitionInfoList
*qmp_query_cpu_definitions(Error
**errp
)
240 CpuDefinitionInfoList
*cpu_list
= NULL
;
243 list
= object_class_get_list(TYPE_ARM_CPU
, false);
244 g_slist_foreach(list
, arm_cpu_add_definition
, &cpu_list
);