2 * QEMU LoongArch CPU (monitor definitions)
4 * SPDX-FileCopyrightText: 2021 Loongson Technology Corporation Limited
6 * SPDX-License-Identifier: GPL-2.0-or-later
9 #include "qemu/osdep.h"
10 #include "qapi/error.h"
11 #include "qapi/qapi-commands-machine-target.h"
13 #include "qapi/qmp/qerror.h"
14 #include "qapi/qmp/qdict.h"
15 #include "qapi/qobject-input-visitor.h"
16 #include "qom/qom-qobject.h"
18 static void loongarch_cpu_add_definition(gpointer data
, gpointer user_data
)
20 ObjectClass
*oc
= data
;
21 CpuDefinitionInfoList
**cpu_list
= user_data
;
22 CpuDefinitionInfo
*info
= g_new0(CpuDefinitionInfo
, 1);
23 const char *typename
= object_class_get_name(oc
);
25 info
->name
= cpu_model_from_type(typename
);
26 info
->q_typename
= g_strdup(typename
);
28 QAPI_LIST_PREPEND(*cpu_list
, info
);
31 CpuDefinitionInfoList
*qmp_query_cpu_definitions(Error
**errp
)
33 CpuDefinitionInfoList
*cpu_list
= NULL
;
36 list
= object_class_get_list(TYPE_LOONGARCH_CPU
, false);
37 g_slist_foreach(list
, loongarch_cpu_add_definition
, &cpu_list
);
43 static const char *cpu_model_advertised_features
[] = {
47 CpuModelExpansionInfo
*qmp_query_cpu_model_expansion(CpuModelExpansionType type
,
51 CpuModelExpansionInfo
*expansion_info
;
58 if (type
!= CPU_MODEL_EXPANSION_TYPE_STATIC
) {
59 error_setg(errp
, "The requested expansion type is not supported");
63 oc
= cpu_class_by_name(TYPE_LOONGARCH_CPU
, model
->name
);
65 error_setg(errp
, "The CPU type '%s' is not a recognized LoongArch CPU type",
70 obj
= object_new(object_class_get_name(oc
));
72 expansion_info
= g_new0(CpuModelExpansionInfo
, 1);
73 expansion_info
->model
= g_malloc0(sizeof(*expansion_info
->model
));
74 expansion_info
->model
->name
= g_strdup(model
->name
);
76 qdict_out
= qdict_new();
79 while ((name
= cpu_model_advertised_features
[i
++]) != NULL
) {
80 ObjectProperty
*prop
= object_property_find(obj
, name
);
85 value
= object_property_get_qobject(obj
, name
, &error_abort
);
87 qdict_put_obj(qdict_out
, name
, value
);
91 if (!qdict_size(qdict_out
)) {
92 qobject_unref(qdict_out
);
94 expansion_info
->model
->props
= QOBJECT(qdict_out
);
99 return expansion_info
;