hw/arm/smmuv3: Translate CD and TT using stage-2 table
[qemu/ar7.git] / monitor / qemu-config-qmp.c
blob24477a0e4486feb956830939b3e4ff5f26cf7cb5
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 #include "qemu/osdep.h"
3 #include "qapi/error.h"
4 #include "qapi/qapi-commands-misc.h"
5 #include "qapi/qmp/qlist.h"
6 #include "qemu/option.h"
7 #include "qemu/config-file.h"
8 #include "hw/boards.h"
10 static CommandLineParameterInfoList *query_option_descs(const QemuOptDesc *desc)
12 CommandLineParameterInfoList *param_list = NULL;
13 CommandLineParameterInfo *info;
14 int i;
16 for (i = 0; desc[i].name != NULL; i++) {
17 info = g_malloc0(sizeof(*info));
18 info->name = g_strdup(desc[i].name);
20 switch (desc[i].type) {
21 case QEMU_OPT_STRING:
22 info->type = COMMAND_LINE_PARAMETER_TYPE_STRING;
23 break;
24 case QEMU_OPT_BOOL:
25 info->type = COMMAND_LINE_PARAMETER_TYPE_BOOLEAN;
26 break;
27 case QEMU_OPT_NUMBER:
28 info->type = COMMAND_LINE_PARAMETER_TYPE_NUMBER;
29 break;
30 case QEMU_OPT_SIZE:
31 info->type = COMMAND_LINE_PARAMETER_TYPE_SIZE;
32 break;
35 info->help = g_strdup(desc[i].help);
36 info->q_default = g_strdup(desc[i].def_value_str);
38 QAPI_LIST_PREPEND(param_list, info);
41 return param_list;
44 /* remove repeated entry from the info list */
45 static void cleanup_infolist(CommandLineParameterInfoList *head)
47 CommandLineParameterInfoList *pre_entry, *cur, *del_entry;
49 cur = head;
50 while (cur->next) {
51 pre_entry = head;
52 while (pre_entry != cur->next) {
53 if (!strcmp(pre_entry->value->name, cur->next->value->name)) {
54 del_entry = cur->next;
55 cur->next = cur->next->next;
56 del_entry->next = NULL;
57 qapi_free_CommandLineParameterInfoList(del_entry);
58 break;
60 pre_entry = pre_entry->next;
62 cur = cur->next;
66 /* merge the description items of two parameter infolists */
67 static void connect_infolist(CommandLineParameterInfoList *head,
68 CommandLineParameterInfoList *new)
70 CommandLineParameterInfoList *cur;
72 cur = head;
73 while (cur->next) {
74 cur = cur->next;
76 cur->next = new;
79 /* access all the local QemuOptsLists for drive option */
80 static CommandLineParameterInfoList *get_drive_infolist(void)
82 CommandLineParameterInfoList *head = NULL, *cur;
83 int i;
85 for (i = 0; drive_config_groups[i] != NULL; i++) {
86 if (!head) {
87 head = query_option_descs(drive_config_groups[i]->desc);
88 } else {
89 cur = query_option_descs(drive_config_groups[i]->desc);
90 connect_infolist(head, cur);
93 cleanup_infolist(head);
95 return head;
98 static CommandLineParameterInfo *objprop_to_cmdline_prop(ObjectProperty *prop)
100 CommandLineParameterInfo *info;
102 info = g_malloc0(sizeof(*info));
103 info->name = g_strdup(prop->name);
105 if (g_str_equal(prop->type, "bool") || g_str_equal(prop->type, "OnOffAuto")) {
106 info->type = COMMAND_LINE_PARAMETER_TYPE_BOOLEAN;
107 } else if (g_str_equal(prop->type, "int")) {
108 info->type = COMMAND_LINE_PARAMETER_TYPE_NUMBER;
109 } else if (g_str_equal(prop->type, "size")) {
110 info->type = COMMAND_LINE_PARAMETER_TYPE_SIZE;
111 } else {
112 info->type = COMMAND_LINE_PARAMETER_TYPE_STRING;
115 if (prop->description) {
116 info->help = g_strdup(prop->description);
119 return info;
122 static CommandLineParameterInfoList *query_all_machine_properties(void)
124 CommandLineParameterInfoList *params = NULL, *clpiter;
125 CommandLineParameterInfo *info;
126 GSList *machines, *curr_mach;
127 ObjectPropertyIterator op_iter;
128 ObjectProperty *prop;
129 bool is_new;
131 machines = object_class_get_list(TYPE_MACHINE, false);
132 assert(machines);
134 /* Loop over all machine classes */
135 for (curr_mach = machines; curr_mach; curr_mach = curr_mach->next) {
136 object_class_property_iter_init(&op_iter, curr_mach->data);
137 /* ... and over the properties of each machine: */
138 while ((prop = object_property_iter_next(&op_iter))) {
139 if (!prop->set) {
140 continue;
143 * Check whether the property has already been put into the list
144 * (via another machine class)
146 is_new = true;
147 for (clpiter = params; clpiter != NULL; clpiter = clpiter->next) {
148 if (g_str_equal(clpiter->value->name, prop->name)) {
149 is_new = false;
150 break;
153 /* If it hasn't been added before, add it now to the list */
154 if (is_new) {
155 info = objprop_to_cmdline_prop(prop);
156 QAPI_LIST_PREPEND(params, info);
161 g_slist_free(machines);
163 /* Add entry for the "type" parameter */
164 info = g_malloc0(sizeof(*info));
165 info->name = g_strdup("type");
166 info->type = COMMAND_LINE_PARAMETER_TYPE_STRING;
167 info->help = g_strdup("machine type");
168 QAPI_LIST_PREPEND(params, info);
170 return params;
173 CommandLineOptionInfoList *qmp_query_command_line_options(const char *option,
174 Error **errp)
176 CommandLineOptionInfoList *conf_list = NULL;
177 CommandLineOptionInfo *info;
178 int i;
180 for (i = 0; vm_config_groups[i] != NULL; i++) {
181 if (!option || !strcmp(option, vm_config_groups[i]->name)) {
182 info = g_malloc0(sizeof(*info));
183 info->option = g_strdup(vm_config_groups[i]->name);
184 if (!strcmp("drive", vm_config_groups[i]->name)) {
185 info->parameters = get_drive_infolist();
186 } else {
187 info->parameters =
188 query_option_descs(vm_config_groups[i]->desc);
190 QAPI_LIST_PREPEND(conf_list, info);
194 if (!option || !strcmp(option, "machine")) {
195 info = g_malloc0(sizeof(*info));
196 info->option = g_strdup("machine");
197 info->parameters = query_all_machine_properties();
198 QAPI_LIST_PREPEND(conf_list, info);
201 if (conf_list == NULL) {
202 error_setg(errp, "invalid option name: %s", option);
205 return conf_list;