2023-02-23 18:55:39 +03:00
|
|
|
/*
|
|
|
|
* QEMU LoongArch CPU (monitor definitions)
|
|
|
|
*
|
|
|
|
* SPDX-FileCopyrightText: 2021 Loongson Technology Corporation Limited
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qemu/osdep.h"
|
target/loongarch: Implement query-cpu-model-expansion
Add support for the query-cpu-model-expansion QMP command to LoongArch.
We support query the cpu features.
e.g
la464 and max cpu support LSX/LASX, default enable,
la132 not support LSX/LASX.
1. start with '-cpu max,lasx=off'
(QEMU) query-cpu-model-expansion type=static model={"name":"max"}
{"return": {"model": {"name": "max", "props": {"lasx": false, "lsx": true}}}}
2. start with '-cpu la464,lasx=off'
(QEMU) query-cpu-model-expansion type=static model={"name":"la464"}
{"return": {"model": {"name": "max", "props": {"lasx": false, "lsx": true}}}
3. start with '-cpu la132,lasx=off'
qemu-system-loongarch64: can't apply global la132-loongarch-cpu.lasx=off: Property 'la132-loongarch-cpu.lasx' not found
4. start with '-cpu max,lasx=off' or start with '-cpu la464,lasx=off' query cpu model la132
(QEMU) query-cpu-model-expansion type=static model={"name":"la132"}
{"return": {"model": {"name": "la132"}}}
Acked-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Song Gao <gaosong@loongson.cn>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20231020084925.3457084-4-gaosong@loongson.cn>
2023-10-20 11:49:25 +03:00
|
|
|
#include "qapi/error.h"
|
2023-02-23 18:55:39 +03:00
|
|
|
#include "qapi/qapi-commands-machine-target.h"
|
|
|
|
#include "cpu.h"
|
target/loongarch: Implement query-cpu-model-expansion
Add support for the query-cpu-model-expansion QMP command to LoongArch.
We support query the cpu features.
e.g
la464 and max cpu support LSX/LASX, default enable,
la132 not support LSX/LASX.
1. start with '-cpu max,lasx=off'
(QEMU) query-cpu-model-expansion type=static model={"name":"max"}
{"return": {"model": {"name": "max", "props": {"lasx": false, "lsx": true}}}}
2. start with '-cpu la464,lasx=off'
(QEMU) query-cpu-model-expansion type=static model={"name":"la464"}
{"return": {"model": {"name": "max", "props": {"lasx": false, "lsx": true}}}
3. start with '-cpu la132,lasx=off'
qemu-system-loongarch64: can't apply global la132-loongarch-cpu.lasx=off: Property 'la132-loongarch-cpu.lasx' not found
4. start with '-cpu max,lasx=off' or start with '-cpu la464,lasx=off' query cpu model la132
(QEMU) query-cpu-model-expansion type=static model={"name":"la132"}
{"return": {"model": {"name": "la132"}}}
Acked-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Song Gao <gaosong@loongson.cn>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20231020084925.3457084-4-gaosong@loongson.cn>
2023-10-20 11:49:25 +03:00
|
|
|
#include "qapi/qmp/qdict.h"
|
|
|
|
#include "qapi/qobject-input-visitor.h"
|
|
|
|
#include "qom/qom-qobject.h"
|
2023-02-23 18:55:39 +03:00
|
|
|
|
|
|
|
static void loongarch_cpu_add_definition(gpointer data, gpointer user_data)
|
|
|
|
{
|
|
|
|
ObjectClass *oc = data;
|
|
|
|
CpuDefinitionInfoList **cpu_list = user_data;
|
|
|
|
CpuDefinitionInfo *info = g_new0(CpuDefinitionInfo, 1);
|
|
|
|
const char *typename = object_class_get_name(oc);
|
|
|
|
|
2023-11-15 02:56:19 +03:00
|
|
|
info->name = cpu_model_from_type(typename);
|
2023-02-23 18:55:39 +03:00
|
|
|
info->q_typename = g_strdup(typename);
|
|
|
|
|
|
|
|
QAPI_LIST_PREPEND(*cpu_list, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
|
|
|
|
{
|
|
|
|
CpuDefinitionInfoList *cpu_list = NULL;
|
|
|
|
GSList *list;
|
|
|
|
|
|
|
|
list = object_class_get_list(TYPE_LOONGARCH_CPU, false);
|
|
|
|
g_slist_foreach(list, loongarch_cpu_add_definition, &cpu_list);
|
|
|
|
g_slist_free(list);
|
|
|
|
|
|
|
|
return cpu_list;
|
|
|
|
}
|
target/loongarch: Implement query-cpu-model-expansion
Add support for the query-cpu-model-expansion QMP command to LoongArch.
We support query the cpu features.
e.g
la464 and max cpu support LSX/LASX, default enable,
la132 not support LSX/LASX.
1. start with '-cpu max,lasx=off'
(QEMU) query-cpu-model-expansion type=static model={"name":"max"}
{"return": {"model": {"name": "max", "props": {"lasx": false, "lsx": true}}}}
2. start with '-cpu la464,lasx=off'
(QEMU) query-cpu-model-expansion type=static model={"name":"la464"}
{"return": {"model": {"name": "max", "props": {"lasx": false, "lsx": true}}}
3. start with '-cpu la132,lasx=off'
qemu-system-loongarch64: can't apply global la132-loongarch-cpu.lasx=off: Property 'la132-loongarch-cpu.lasx' not found
4. start with '-cpu max,lasx=off' or start with '-cpu la464,lasx=off' query cpu model la132
(QEMU) query-cpu-model-expansion type=static model={"name":"la132"}
{"return": {"model": {"name": "la132"}}}
Acked-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Song Gao <gaosong@loongson.cn>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20231020084925.3457084-4-gaosong@loongson.cn>
2023-10-20 11:49:25 +03:00
|
|
|
|
|
|
|
static const char *cpu_model_advertised_features[] = {
|
|
|
|
"lsx", "lasx", NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
|
|
|
|
CpuModelInfo *model,
|
|
|
|
Error **errp)
|
|
|
|
{
|
target/loongarch: Fix query-cpu-model-expansion to reject props
query-cpu-model-expansion takes a CpuModelInfo argument. The
loongarch version of the command silently ignores the argument's
member @props. For instance,
{"execute": "query-cpu-model-expansion", "arguments": {"type": "static", "model": {"name": "la464", "props": null}}}
and
{"execute": "query-cpu-model-expansion", "arguments": {"type": "static", "model": {"name": "la464", "props": {"prop": null}}}}
succeed.
Add skeleton code for property processing that recognizes no
properties. Now the two commands fail as they should:
{"error": {"class": "GenericError", "desc": "Invalid parameter type for 'model.props', expected: object"}}
and
{"error": {"class": "GenericError", "desc": "Parameter 'model.props.prop' is unexpected"}}
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-ID: <20240305145919.2186971-5-armbru@redhat.com>
[Drop #include now superfluous]
2024-03-05 17:59:18 +03:00
|
|
|
Visitor *visitor;
|
|
|
|
bool ok;
|
target/loongarch: Implement query-cpu-model-expansion
Add support for the query-cpu-model-expansion QMP command to LoongArch.
We support query the cpu features.
e.g
la464 and max cpu support LSX/LASX, default enable,
la132 not support LSX/LASX.
1. start with '-cpu max,lasx=off'
(QEMU) query-cpu-model-expansion type=static model={"name":"max"}
{"return": {"model": {"name": "max", "props": {"lasx": false, "lsx": true}}}}
2. start with '-cpu la464,lasx=off'
(QEMU) query-cpu-model-expansion type=static model={"name":"la464"}
{"return": {"model": {"name": "max", "props": {"lasx": false, "lsx": true}}}
3. start with '-cpu la132,lasx=off'
qemu-system-loongarch64: can't apply global la132-loongarch-cpu.lasx=off: Property 'la132-loongarch-cpu.lasx' not found
4. start with '-cpu max,lasx=off' or start with '-cpu la464,lasx=off' query cpu model la132
(QEMU) query-cpu-model-expansion type=static model={"name":"la132"}
{"return": {"model": {"name": "la132"}}}
Acked-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Song Gao <gaosong@loongson.cn>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20231020084925.3457084-4-gaosong@loongson.cn>
2023-10-20 11:49:25 +03:00
|
|
|
CpuModelExpansionInfo *expansion_info;
|
|
|
|
QDict *qdict_out;
|
|
|
|
ObjectClass *oc;
|
|
|
|
Object *obj;
|
|
|
|
const char *name;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (type != CPU_MODEL_EXPANSION_TYPE_STATIC) {
|
|
|
|
error_setg(errp, "The requested expansion type is not supported");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
target/loongarch: Fix query-cpu-model-expansion to reject props
query-cpu-model-expansion takes a CpuModelInfo argument. The
loongarch version of the command silently ignores the argument's
member @props. For instance,
{"execute": "query-cpu-model-expansion", "arguments": {"type": "static", "model": {"name": "la464", "props": null}}}
and
{"execute": "query-cpu-model-expansion", "arguments": {"type": "static", "model": {"name": "la464", "props": {"prop": null}}}}
succeed.
Add skeleton code for property processing that recognizes no
properties. Now the two commands fail as they should:
{"error": {"class": "GenericError", "desc": "Invalid parameter type for 'model.props', expected: object"}}
and
{"error": {"class": "GenericError", "desc": "Parameter 'model.props.prop' is unexpected"}}
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-ID: <20240305145919.2186971-5-armbru@redhat.com>
[Drop #include now superfluous]
2024-03-05 17:59:18 +03:00
|
|
|
if (model->props) {
|
|
|
|
visitor = qobject_input_visitor_new(model->props);
|
|
|
|
if (!visit_start_struct(visitor, "model.props", NULL, 0, errp)) {
|
|
|
|
visit_free(visitor);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ok = visit_check_struct(visitor, errp);
|
|
|
|
visit_end_struct(visitor, NULL);
|
|
|
|
visit_free(visitor);
|
|
|
|
if (!ok) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
target/loongarch: Implement query-cpu-model-expansion
Add support for the query-cpu-model-expansion QMP command to LoongArch.
We support query the cpu features.
e.g
la464 and max cpu support LSX/LASX, default enable,
la132 not support LSX/LASX.
1. start with '-cpu max,lasx=off'
(QEMU) query-cpu-model-expansion type=static model={"name":"max"}
{"return": {"model": {"name": "max", "props": {"lasx": false, "lsx": true}}}}
2. start with '-cpu la464,lasx=off'
(QEMU) query-cpu-model-expansion type=static model={"name":"la464"}
{"return": {"model": {"name": "max", "props": {"lasx": false, "lsx": true}}}
3. start with '-cpu la132,lasx=off'
qemu-system-loongarch64: can't apply global la132-loongarch-cpu.lasx=off: Property 'la132-loongarch-cpu.lasx' not found
4. start with '-cpu max,lasx=off' or start with '-cpu la464,lasx=off' query cpu model la132
(QEMU) query-cpu-model-expansion type=static model={"name":"la132"}
{"return": {"model": {"name": "la132"}}}
Acked-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Song Gao <gaosong@loongson.cn>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20231020084925.3457084-4-gaosong@loongson.cn>
2023-10-20 11:49:25 +03:00
|
|
|
oc = cpu_class_by_name(TYPE_LOONGARCH_CPU, model->name);
|
|
|
|
if (!oc) {
|
|
|
|
error_setg(errp, "The CPU type '%s' is not a recognized LoongArch CPU type",
|
|
|
|
model->name);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
obj = object_new(object_class_get_name(oc));
|
|
|
|
|
|
|
|
expansion_info = g_new0(CpuModelExpansionInfo, 1);
|
|
|
|
expansion_info->model = g_malloc0(sizeof(*expansion_info->model));
|
|
|
|
expansion_info->model->name = g_strdup(model->name);
|
|
|
|
|
|
|
|
qdict_out = qdict_new();
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while ((name = cpu_model_advertised_features[i++]) != NULL) {
|
|
|
|
ObjectProperty *prop = object_property_find(obj, name);
|
|
|
|
if (prop) {
|
|
|
|
QObject *value;
|
|
|
|
|
|
|
|
assert(prop->get);
|
|
|
|
value = object_property_get_qobject(obj, name, &error_abort);
|
|
|
|
|
|
|
|
qdict_put_obj(qdict_out, name, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!qdict_size(qdict_out)) {
|
|
|
|
qobject_unref(qdict_out);
|
|
|
|
} else {
|
|
|
|
expansion_info->model->props = QOBJECT(qdict_out);
|
|
|
|
}
|
|
|
|
|
|
|
|
object_unref(obj);
|
|
|
|
|
|
|
|
return expansion_info;
|
|
|
|
}
|