]>
Commit | Line | Data |
---|---|---|
ee46d8a5 AL |
1 | /* |
2 | * Dynamic device configuration and creation. | |
3 | * | |
4 | * Copyright (c) 2009 CodeSourcery | |
5 | * | |
6 | * This library is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU Lesser General Public | |
8 | * License as published by the Free Software Foundation; either | |
9 | * version 2 of the License, or (at your option) any later version. | |
10 | * | |
11 | * This library is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * Lesser General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU Lesser General Public | |
17 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
b4a42f81 | 20 | #include "hw/qdev.h" |
83c9089e | 21 | #include "monitor/monitor.h" |
b4a42f81 | 22 | #include "monitor/qdev.h" |
a15fef21 | 23 | #include "qmp-commands.h" |
9c17d615 | 24 | #include "sysemu/arch_init.h" |
1de7afc9 | 25 | #include "qemu/config-file.h" |
ee46d8a5 AL |
26 | |
27 | /* | |
28 | * Aliases were a bad idea from the start. Let's keep them | |
29 | * from spreading further. | |
30 | */ | |
31 | typedef struct QDevAlias | |
32 | { | |
33 | const char *typename; | |
34 | const char *alias; | |
5f629d94 | 35 | uint32_t arch_mask; |
ee46d8a5 AL |
36 | } QDevAlias; |
37 | ||
38 | static const QDevAlias qdev_alias_table[] = { | |
5f629d94 AG |
39 | { "virtio-blk-pci", "virtio-blk", QEMU_ARCH_ALL & ~QEMU_ARCH_S390X }, |
40 | { "virtio-net-pci", "virtio-net", QEMU_ARCH_ALL & ~QEMU_ARCH_S390X }, | |
41 | { "virtio-serial-pci", "virtio-serial", QEMU_ARCH_ALL & ~QEMU_ARCH_S390X }, | |
42 | { "virtio-balloon-pci", "virtio-balloon", | |
43 | QEMU_ARCH_ALL & ~QEMU_ARCH_S390X }, | |
44 | { "virtio-blk-s390", "virtio-blk", QEMU_ARCH_S390X }, | |
45 | { "virtio-net-s390", "virtio-net", QEMU_ARCH_S390X }, | |
46 | { "virtio-serial-s390", "virtio-serial", QEMU_ARCH_S390X }, | |
ee46d8a5 AL |
47 | { "lsi53c895a", "lsi" }, |
48 | { "ich9-ahci", "ahci" }, | |
c3ebd3ba | 49 | { "kvm-pci-assign", "pci-assign" }, |
ee46d8a5 AL |
50 | { } |
51 | }; | |
52 | ||
53 | static const char *qdev_class_get_alias(DeviceClass *dc) | |
54 | { | |
55 | const char *typename = object_class_get_name(OBJECT_CLASS(dc)); | |
56 | int i; | |
57 | ||
58 | for (i = 0; qdev_alias_table[i].typename; i++) { | |
5f629d94 AG |
59 | if (qdev_alias_table[i].arch_mask && |
60 | !(qdev_alias_table[i].arch_mask & arch_type)) { | |
61 | continue; | |
62 | } | |
63 | ||
ee46d8a5 AL |
64 | if (strcmp(qdev_alias_table[i].typename, typename) == 0) { |
65 | return qdev_alias_table[i].alias; | |
66 | } | |
67 | } | |
68 | ||
69 | return NULL; | |
70 | } | |
71 | ||
72 | static bool qdev_class_has_alias(DeviceClass *dc) | |
73 | { | |
74 | return (qdev_class_get_alias(dc) != NULL); | |
75 | } | |
76 | ||
77 | static void qdev_print_devinfo(ObjectClass *klass, void *opaque) | |
78 | { | |
79 | DeviceClass *dc; | |
80 | bool *show_no_user = opaque; | |
81 | ||
82 | dc = (DeviceClass *)object_class_dynamic_cast(klass, TYPE_DEVICE); | |
83 | ||
84 | if (!dc || (show_no_user && !*show_no_user && dc->no_user)) { | |
85 | return; | |
86 | } | |
87 | ||
88 | error_printf("name \"%s\"", object_class_get_name(klass)); | |
0d936928 AL |
89 | if (dc->bus_type) { |
90 | error_printf(", bus %s", dc->bus_type); | |
ee46d8a5 AL |
91 | } |
92 | if (qdev_class_has_alias(dc)) { | |
93 | error_printf(", alias \"%s\"", qdev_class_get_alias(dc)); | |
94 | } | |
95 | if (dc->desc) { | |
96 | error_printf(", desc \"%s\"", dc->desc); | |
97 | } | |
98 | if (dc->no_user) { | |
99 | error_printf(", no-user"); | |
100 | } | |
101 | error_printf("\n"); | |
102 | } | |
103 | ||
104 | static int set_property(const char *name, const char *value, void *opaque) | |
105 | { | |
106 | DeviceState *dev = opaque; | |
107 | ||
108 | if (strcmp(name, "driver") == 0) | |
109 | return 0; | |
110 | if (strcmp(name, "bus") == 0) | |
111 | return 0; | |
112 | ||
113 | if (qdev_prop_parse(dev, name, value) == -1) { | |
114 | return -1; | |
115 | } | |
116 | return 0; | |
117 | } | |
118 | ||
119 | static const char *find_typename_by_alias(const char *alias) | |
120 | { | |
121 | int i; | |
122 | ||
123 | for (i = 0; qdev_alias_table[i].alias; i++) { | |
5f629d94 AG |
124 | if (qdev_alias_table[i].arch_mask && |
125 | !(qdev_alias_table[i].arch_mask & arch_type)) { | |
126 | continue; | |
127 | } | |
128 | ||
ee46d8a5 AL |
129 | if (strcmp(qdev_alias_table[i].alias, alias) == 0) { |
130 | return qdev_alias_table[i].typename; | |
131 | } | |
132 | } | |
133 | ||
134 | return NULL; | |
135 | } | |
136 | ||
137 | int qdev_device_help(QemuOpts *opts) | |
138 | { | |
139 | const char *driver; | |
140 | Property *prop; | |
141 | ObjectClass *klass; | |
ee46d8a5 AL |
142 | |
143 | driver = qemu_opt_get(opts, "driver"); | |
c8057f95 | 144 | if (driver && is_help_option(driver)) { |
ee46d8a5 AL |
145 | bool show_no_user = false; |
146 | object_class_foreach(qdev_print_devinfo, TYPE_DEVICE, false, &show_no_user); | |
147 | return 1; | |
148 | } | |
149 | ||
c8057f95 | 150 | if (!driver || !qemu_opt_has_help_opt(opts)) { |
ee46d8a5 AL |
151 | return 0; |
152 | } | |
153 | ||
154 | klass = object_class_by_name(driver); | |
155 | if (!klass) { | |
156 | const char *typename = find_typename_by_alias(driver); | |
157 | ||
158 | if (typename) { | |
159 | driver = typename; | |
160 | klass = object_class_by_name(driver); | |
161 | } | |
162 | } | |
163 | ||
164 | if (!klass) { | |
165 | return 0; | |
166 | } | |
bce54474 PB |
167 | do { |
168 | for (prop = DEVICE_CLASS(klass)->props; prop && prop->name; prop++) { | |
169 | /* | |
170 | * TODO Properties without a parser are just for dirty hacks. | |
171 | * qdev_prop_ptr is the only such PropertyInfo. It's marked | |
172 | * for removal. This conditional should be removed along with | |
173 | * it. | |
174 | */ | |
90ca64a9 | 175 | if (!prop->info->set) { |
d03d6b4e AL |
176 | continue; /* no way to set it, don't show */ |
177 | } | |
178 | error_printf("%s.%s=%s\n", driver, prop->name, | |
179 | prop->info->legacy_name ?: prop->info->name); | |
ee46d8a5 | 180 | } |
bce54474 PB |
181 | klass = object_class_get_parent(klass); |
182 | } while (klass != object_class_by_name(TYPE_DEVICE)); | |
ee46d8a5 AL |
183 | return 1; |
184 | } | |
185 | ||
57c9fafe | 186 | static Object *qdev_get_peripheral(void) |
ee46d8a5 | 187 | { |
8b45d447 | 188 | static Object *dev; |
ee46d8a5 AL |
189 | |
190 | if (dev == NULL) { | |
dfe47e70 | 191 | dev = container_get(qdev_get_machine(), "/peripheral"); |
ee46d8a5 AL |
192 | } |
193 | ||
8b45d447 | 194 | return dev; |
ee46d8a5 AL |
195 | } |
196 | ||
57c9fafe | 197 | static Object *qdev_get_peripheral_anon(void) |
ee46d8a5 | 198 | { |
8b45d447 | 199 | static Object *dev; |
ee46d8a5 AL |
200 | |
201 | if (dev == NULL) { | |
dfe47e70 | 202 | dev = container_get(qdev_get_machine(), "/peripheral-anon"); |
ee46d8a5 AL |
203 | } |
204 | ||
8b45d447 | 205 | return dev; |
ee46d8a5 AL |
206 | } |
207 | ||
208 | static void qbus_list_bus(DeviceState *dev) | |
209 | { | |
210 | BusState *child; | |
211 | const char *sep = " "; | |
212 | ||
213 | error_printf("child busses at \"%s\":", | |
214 | dev->id ? dev->id : object_get_typename(OBJECT(dev))); | |
215 | QLIST_FOREACH(child, &dev->child_bus, sibling) { | |
216 | error_printf("%s\"%s\"", sep, child->name); | |
217 | sep = ", "; | |
218 | } | |
219 | error_printf("\n"); | |
220 | } | |
221 | ||
222 | static void qbus_list_dev(BusState *bus) | |
223 | { | |
0866aca1 | 224 | BusChild *kid; |
ee46d8a5 AL |
225 | const char *sep = " "; |
226 | ||
227 | error_printf("devices at \"%s\":", bus->name); | |
0866aca1 AL |
228 | QTAILQ_FOREACH(kid, &bus->children, sibling) { |
229 | DeviceState *dev = kid->child; | |
ee46d8a5 AL |
230 | error_printf("%s\"%s\"", sep, object_get_typename(OBJECT(dev))); |
231 | if (dev->id) | |
232 | error_printf("/\"%s\"", dev->id); | |
233 | sep = ", "; | |
234 | } | |
235 | error_printf("\n"); | |
236 | } | |
237 | ||
238 | static BusState *qbus_find_bus(DeviceState *dev, char *elem) | |
239 | { | |
240 | BusState *child; | |
241 | ||
242 | QLIST_FOREACH(child, &dev->child_bus, sibling) { | |
243 | if (strcmp(child->name, elem) == 0) { | |
244 | return child; | |
245 | } | |
246 | } | |
247 | return NULL; | |
248 | } | |
249 | ||
250 | static DeviceState *qbus_find_dev(BusState *bus, char *elem) | |
251 | { | |
0866aca1 | 252 | BusChild *kid; |
ee46d8a5 AL |
253 | |
254 | /* | |
255 | * try to match in order: | |
256 | * (1) instance id, if present | |
257 | * (2) driver name | |
258 | * (3) driver alias, if present | |
259 | */ | |
0866aca1 AL |
260 | QTAILQ_FOREACH(kid, &bus->children, sibling) { |
261 | DeviceState *dev = kid->child; | |
ee46d8a5 AL |
262 | if (dev->id && strcmp(dev->id, elem) == 0) { |
263 | return dev; | |
264 | } | |
265 | } | |
0866aca1 AL |
266 | QTAILQ_FOREACH(kid, &bus->children, sibling) { |
267 | DeviceState *dev = kid->child; | |
ee46d8a5 AL |
268 | if (strcmp(object_get_typename(OBJECT(dev)), elem) == 0) { |
269 | return dev; | |
270 | } | |
271 | } | |
0866aca1 AL |
272 | QTAILQ_FOREACH(kid, &bus->children, sibling) { |
273 | DeviceState *dev = kid->child; | |
ee46d8a5 AL |
274 | DeviceClass *dc = DEVICE_GET_CLASS(dev); |
275 | ||
276 | if (qdev_class_has_alias(dc) && | |
277 | strcmp(qdev_class_get_alias(dc), elem) == 0) { | |
278 | return dev; | |
279 | } | |
280 | } | |
281 | return NULL; | |
282 | } | |
283 | ||
284 | static BusState *qbus_find_recursive(BusState *bus, const char *name, | |
0d936928 | 285 | const char *bus_typename) |
ee46d8a5 | 286 | { |
1395af6f | 287 | BusClass *bus_class = BUS_GET_CLASS(bus); |
0866aca1 | 288 | BusChild *kid; |
ee46d8a5 AL |
289 | BusState *child, *ret; |
290 | int match = 1; | |
291 | ||
292 | if (name && (strcmp(bus->name, name) != 0)) { | |
293 | match = 0; | |
294 | } | |
e912c96f | 295 | if (bus_typename && !object_dynamic_cast(OBJECT(bus), bus_typename)) { |
ee46d8a5 AL |
296 | match = 0; |
297 | } | |
1395af6f FK |
298 | if ((bus_class->max_dev != 0) && (bus_class->max_dev <= bus->max_index)) { |
299 | if (name != NULL) { | |
300 | /* bus was explicitly specified: return an error. */ | |
301 | qerror_report(ERROR_CLASS_GENERIC_ERROR, "Bus '%s' is full", | |
302 | bus->name); | |
303 | return NULL; | |
304 | } else { | |
305 | /* bus was not specified: try to find another one. */ | |
306 | match = 0; | |
307 | } | |
308 | } | |
ee46d8a5 AL |
309 | if (match) { |
310 | return bus; | |
311 | } | |
312 | ||
0866aca1 AL |
313 | QTAILQ_FOREACH(kid, &bus->children, sibling) { |
314 | DeviceState *dev = kid->child; | |
ee46d8a5 | 315 | QLIST_FOREACH(child, &dev->child_bus, sibling) { |
0d936928 | 316 | ret = qbus_find_recursive(child, name, bus_typename); |
ee46d8a5 AL |
317 | if (ret) { |
318 | return ret; | |
319 | } | |
320 | } | |
321 | } | |
322 | return NULL; | |
323 | } | |
324 | ||
325 | static BusState *qbus_find(const char *path) | |
326 | { | |
327 | DeviceState *dev; | |
328 | BusState *bus; | |
329 | char elem[128]; | |
330 | int pos, len; | |
331 | ||
332 | /* find start element */ | |
333 | if (path[0] == '/') { | |
334 | bus = sysbus_get_default(); | |
335 | pos = 0; | |
336 | } else { | |
337 | if (sscanf(path, "%127[^/]%n", elem, &len) != 1) { | |
338 | assert(!path[0]); | |
339 | elem[0] = len = 0; | |
340 | } | |
341 | bus = qbus_find_recursive(sysbus_get_default(), elem, NULL); | |
342 | if (!bus) { | |
343 | qerror_report(QERR_BUS_NOT_FOUND, elem); | |
344 | return NULL; | |
345 | } | |
346 | pos = len; | |
347 | } | |
348 | ||
349 | for (;;) { | |
350 | assert(path[pos] == '/' || !path[pos]); | |
351 | while (path[pos] == '/') { | |
352 | pos++; | |
353 | } | |
354 | if (path[pos] == '\0') { | |
355 | return bus; | |
356 | } | |
357 | ||
358 | /* find device */ | |
359 | if (sscanf(path+pos, "%127[^/]%n", elem, &len) != 1) { | |
360 | assert(0); | |
361 | elem[0] = len = 0; | |
362 | } | |
363 | pos += len; | |
364 | dev = qbus_find_dev(bus, elem); | |
365 | if (!dev) { | |
366 | qerror_report(QERR_DEVICE_NOT_FOUND, elem); | |
367 | if (!monitor_cur_is_qmp()) { | |
368 | qbus_list_dev(bus); | |
369 | } | |
370 | return NULL; | |
371 | } | |
372 | ||
373 | assert(path[pos] == '/' || !path[pos]); | |
374 | while (path[pos] == '/') { | |
375 | pos++; | |
376 | } | |
377 | if (path[pos] == '\0') { | |
378 | /* last specified element is a device. If it has exactly | |
379 | * one child bus accept it nevertheless */ | |
380 | switch (dev->num_child_bus) { | |
381 | case 0: | |
382 | qerror_report(QERR_DEVICE_NO_BUS, elem); | |
383 | return NULL; | |
384 | case 1: | |
385 | return QLIST_FIRST(&dev->child_bus); | |
386 | default: | |
387 | qerror_report(QERR_DEVICE_MULTIPLE_BUSSES, elem); | |
388 | if (!monitor_cur_is_qmp()) { | |
389 | qbus_list_bus(dev); | |
390 | } | |
391 | return NULL; | |
392 | } | |
393 | } | |
394 | ||
395 | /* find bus */ | |
396 | if (sscanf(path+pos, "%127[^/]%n", elem, &len) != 1) { | |
397 | assert(0); | |
398 | elem[0] = len = 0; | |
399 | } | |
400 | pos += len; | |
401 | bus = qbus_find_bus(dev, elem); | |
402 | if (!bus) { | |
403 | qerror_report(QERR_BUS_NOT_FOUND, elem); | |
404 | if (!monitor_cur_is_qmp()) { | |
405 | qbus_list_bus(dev); | |
406 | } | |
407 | return NULL; | |
408 | } | |
409 | } | |
410 | } | |
411 | ||
412 | DeviceState *qdev_device_add(QemuOpts *opts) | |
413 | { | |
414 | ObjectClass *obj; | |
415 | DeviceClass *k; | |
416 | const char *driver, *path, *id; | |
417 | DeviceState *qdev; | |
418 | BusState *bus; | |
419 | ||
420 | driver = qemu_opt_get(opts, "driver"); | |
421 | if (!driver) { | |
422 | qerror_report(QERR_MISSING_PARAMETER, "driver"); | |
423 | return NULL; | |
424 | } | |
425 | ||
426 | /* find driver */ | |
427 | obj = object_class_by_name(driver); | |
428 | if (!obj) { | |
429 | const char *typename = find_typename_by_alias(driver); | |
430 | ||
431 | if (typename) { | |
432 | driver = typename; | |
433 | obj = object_class_by_name(driver); | |
434 | } | |
435 | } | |
436 | ||
437 | if (!obj) { | |
438 | qerror_report(QERR_INVALID_PARAMETER_VALUE, "driver", "device type"); | |
439 | return NULL; | |
440 | } | |
441 | ||
442 | k = DEVICE_CLASS(obj); | |
443 | ||
444 | /* find bus */ | |
445 | path = qemu_opt_get(opts, "bus"); | |
446 | if (path != NULL) { | |
447 | bus = qbus_find(path); | |
448 | if (!bus) { | |
449 | return NULL; | |
450 | } | |
e912c96f | 451 | if (!object_dynamic_cast(OBJECT(bus), k->bus_type)) { |
ee46d8a5 | 452 | qerror_report(QERR_BAD_BUS_FOR_DEVICE, |
0d936928 | 453 | driver, object_get_typename(OBJECT(bus))); |
ee46d8a5 AL |
454 | return NULL; |
455 | } | |
456 | } else { | |
0d936928 | 457 | bus = qbus_find_recursive(sysbus_get_default(), NULL, k->bus_type); |
ee46d8a5 AL |
458 | if (!bus) { |
459 | qerror_report(QERR_NO_BUS_FOR_DEVICE, | |
c3594ed7 | 460 | k->bus_type, driver); |
ee46d8a5 AL |
461 | return NULL; |
462 | } | |
463 | } | |
464 | if (qdev_hotplug && !bus->allow_hotplug) { | |
465 | qerror_report(QERR_BUS_NO_HOTPLUG, bus->name); | |
466 | return NULL; | |
467 | } | |
468 | ||
469 | if (!bus) { | |
470 | bus = sysbus_get_default(); | |
471 | } | |
472 | ||
473 | /* create device, set properties */ | |
474 | qdev = DEVICE(object_new(driver)); | |
475 | qdev_set_parent_bus(qdev, bus); | |
ee46d8a5 AL |
476 | |
477 | id = qemu_opts_id(opts); | |
478 | if (id) { | |
479 | qdev->id = id; | |
b2d4b3f7 AL |
480 | } |
481 | if (qemu_opt_foreach(opts, set_property, qdev, 1) != 0) { | |
482 | qdev_free(qdev); | |
483 | return NULL; | |
484 | } | |
b2d4b3f7 | 485 | if (qdev->id) { |
57c9fafe AL |
486 | object_property_add_child(qdev_get_peripheral(), qdev->id, |
487 | OBJECT(qdev), NULL); | |
ee46d8a5 AL |
488 | } else { |
489 | static int anon_count; | |
490 | gchar *name = g_strdup_printf("device[%d]", anon_count++); | |
57c9fafe AL |
491 | object_property_add_child(qdev_get_peripheral_anon(), name, |
492 | OBJECT(qdev), NULL); | |
ee46d8a5 AL |
493 | g_free(name); |
494 | } | |
f424d5c4 PB |
495 | if (qdev_init(qdev) < 0) { |
496 | qerror_report(QERR_DEVICE_INIT_FAILED, driver); | |
497 | return NULL; | |
498 | } | |
ee46d8a5 AL |
499 | qdev->opts = opts; |
500 | return qdev; | |
501 | } | |
502 | ||
503 | ||
504 | #define qdev_printf(fmt, ...) monitor_printf(mon, "%*s" fmt, indent, "", ## __VA_ARGS__) | |
505 | static void qbus_print(Monitor *mon, BusState *bus, int indent); | |
506 | ||
507 | static void qdev_print_props(Monitor *mon, DeviceState *dev, Property *props, | |
bce54474 | 508 | int indent) |
ee46d8a5 | 509 | { |
ee46d8a5 AL |
510 | if (!props) |
511 | return; | |
d822979b PB |
512 | for (; props->name; props++) { |
513 | Error *err = NULL; | |
514 | char *value; | |
515 | char *legacy_name = g_strdup_printf("legacy-%s", props->name); | |
516 | if (object_property_get_type(OBJECT(dev), legacy_name, NULL)) { | |
517 | value = object_property_get_str(OBJECT(dev), legacy_name, &err); | |
518 | } else { | |
8185bfc1 | 519 | value = object_property_print(OBJECT(dev), props->name, &err); |
d822979b PB |
520 | } |
521 | g_free(legacy_name); | |
522 | ||
523 | if (err) { | |
524 | error_free(err); | |
525 | continue; | |
ee46d8a5 | 526 | } |
bce54474 | 527 | qdev_printf("%s = %s\n", props->name, |
d822979b PB |
528 | value && *value ? value : "<null>"); |
529 | g_free(value); | |
ee46d8a5 AL |
530 | } |
531 | } | |
532 | ||
0d936928 AL |
533 | static void bus_print_dev(BusState *bus, Monitor *mon, DeviceState *dev, int indent) |
534 | { | |
535 | BusClass *bc = BUS_GET_CLASS(bus); | |
536 | ||
537 | if (bc->print_dev) { | |
538 | bc->print_dev(mon, dev, indent); | |
539 | } | |
540 | } | |
541 | ||
ee46d8a5 AL |
542 | static void qdev_print(Monitor *mon, DeviceState *dev, int indent) |
543 | { | |
bce54474 | 544 | ObjectClass *class; |
ee46d8a5 AL |
545 | BusState *child; |
546 | qdev_printf("dev: %s, id \"%s\"\n", object_get_typename(OBJECT(dev)), | |
547 | dev->id ? dev->id : ""); | |
548 | indent += 2; | |
549 | if (dev->num_gpio_in) { | |
550 | qdev_printf("gpio-in %d\n", dev->num_gpio_in); | |
551 | } | |
552 | if (dev->num_gpio_out) { | |
553 | qdev_printf("gpio-out %d\n", dev->num_gpio_out); | |
554 | } | |
bce54474 PB |
555 | class = object_get_class(OBJECT(dev)); |
556 | do { | |
557 | qdev_print_props(mon, dev, DEVICE_CLASS(class)->props, indent); | |
558 | class = object_class_get_parent(class); | |
559 | } while (class != object_class_by_name(TYPE_DEVICE)); | |
da9fbe76 | 560 | bus_print_dev(dev->parent_bus, mon, dev, indent); |
ee46d8a5 AL |
561 | QLIST_FOREACH(child, &dev->child_bus, sibling) { |
562 | qbus_print(mon, child, indent); | |
563 | } | |
564 | } | |
565 | ||
566 | static void qbus_print(Monitor *mon, BusState *bus, int indent) | |
567 | { | |
0866aca1 | 568 | BusChild *kid; |
ee46d8a5 AL |
569 | |
570 | qdev_printf("bus: %s\n", bus->name); | |
571 | indent += 2; | |
0d936928 | 572 | qdev_printf("type %s\n", object_get_typename(OBJECT(bus))); |
0866aca1 AL |
573 | QTAILQ_FOREACH(kid, &bus->children, sibling) { |
574 | DeviceState *dev = kid->child; | |
ee46d8a5 AL |
575 | qdev_print(mon, dev, indent); |
576 | } | |
577 | } | |
578 | #undef qdev_printf | |
579 | ||
84f2d0ea | 580 | void do_info_qtree(Monitor *mon, const QDict *qdict) |
ee46d8a5 AL |
581 | { |
582 | if (sysbus_get_default()) | |
583 | qbus_print(mon, sysbus_get_default(), 0); | |
584 | } | |
585 | ||
84f2d0ea | 586 | void do_info_qdm(Monitor *mon, const QDict *qdict) |
ee46d8a5 AL |
587 | { |
588 | object_class_foreach(qdev_print_devinfo, TYPE_DEVICE, false, NULL); | |
589 | } | |
590 | ||
591 | int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data) | |
592 | { | |
4e89978e | 593 | Error *local_err = NULL; |
ee46d8a5 | 594 | QemuOpts *opts; |
b09995ae | 595 | DeviceState *dev; |
ee46d8a5 | 596 | |
4e89978e LC |
597 | opts = qemu_opts_from_qdict(qemu_find_opts("device"), qdict, &local_err); |
598 | if (error_is_set(&local_err)) { | |
599 | qerror_report_err(local_err); | |
600 | error_free(local_err); | |
ee46d8a5 AL |
601 | return -1; |
602 | } | |
603 | if (!monitor_cur_is_qmp() && qdev_device_help(opts)) { | |
604 | qemu_opts_del(opts); | |
605 | return 0; | |
606 | } | |
b09995ae PB |
607 | dev = qdev_device_add(opts); |
608 | if (!dev) { | |
ee46d8a5 AL |
609 | qemu_opts_del(opts); |
610 | return -1; | |
611 | } | |
b09995ae | 612 | object_unref(OBJECT(dev)); |
ee46d8a5 AL |
613 | return 0; |
614 | } | |
615 | ||
a15fef21 | 616 | void qmp_device_del(const char *id, Error **errp) |
ee46d8a5 | 617 | { |
ee46d8a5 AL |
618 | DeviceState *dev; |
619 | ||
620 | dev = qdev_find_recursive(sysbus_get_default(), id); | |
621 | if (NULL == dev) { | |
a15fef21 LC |
622 | error_set(errp, QERR_DEVICE_NOT_FOUND, id); |
623 | return; | |
56f9107e LC |
624 | } |
625 | ||
a15fef21 | 626 | qdev_unplug(dev, errp); |
ee46d8a5 AL |
627 | } |
628 | ||
629 | void qdev_machine_init(void) | |
630 | { | |
631 | qdev_get_peripheral_anon(); | |
632 | qdev_get_peripheral(); | |
633 | } | |
4d454574 PB |
634 | |
635 | QemuOptsList qemu_device_opts = { | |
636 | .name = "device", | |
637 | .implied_opt_name = "driver", | |
638 | .head = QTAILQ_HEAD_INITIALIZER(qemu_device_opts.head), | |
639 | .desc = { | |
640 | /* | |
641 | * no elements => accept any | |
642 | * sanity checking will happen later | |
643 | * when setting device properties | |
644 | */ | |
645 | { /* end of list */ } | |
646 | }, | |
647 | }; | |
648 | ||
649 | QemuOptsList qemu_global_opts = { | |
650 | .name = "global", | |
651 | .head = QTAILQ_HEAD_INITIALIZER(qemu_global_opts.head), | |
652 | .desc = { | |
653 | { | |
654 | .name = "driver", | |
655 | .type = QEMU_OPT_STRING, | |
656 | },{ | |
657 | .name = "property", | |
658 | .type = QEMU_OPT_STRING, | |
659 | },{ | |
660 | .name = "value", | |
661 | .type = QEMU_OPT_STRING, | |
662 | }, | |
663 | { /* end of list */ } | |
664 | }, | |
665 | }; | |
666 | ||
667 | int qemu_global_option(const char *str) | |
668 | { | |
669 | char driver[64], property[64]; | |
670 | QemuOpts *opts; | |
671 | int rc, offset; | |
672 | ||
673 | rc = sscanf(str, "%63[^.].%63[^=]%n", driver, property, &offset); | |
674 | if (rc < 2 || str[offset] != '=') { | |
675 | error_report("can't parse: \"%s\"", str); | |
676 | return -1; | |
677 | } | |
678 | ||
679 | opts = qemu_opts_create_nofail(&qemu_global_opts); | |
680 | qemu_opt_set(opts, "driver", driver); | |
681 | qemu_opt_set(opts, "property", property); | |
682 | qemu_opt_set(opts, "value", str+offset+1); | |
683 | return 0; | |
684 | } |