2 * Dynamic device configuration and creation.
4 * Copyright (c) 2009 CodeSourcery
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.
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.
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/>.
20 #include "qemu/osdep.h"
22 #include "hw/sysbus.h"
23 #include "monitor/monitor.h"
24 #include "monitor/qdev.h"
25 #include "sysemu/arch_init.h"
26 #include "qapi/error.h"
27 #include "qapi/qapi-commands-misc.h"
28 #include "qapi/qmp/qdict.h"
29 #include "qapi/qmp/qerror.h"
30 #include "qemu/config-file.h"
31 #include "qemu/error-report.h"
32 #include "qemu/help_option.h"
33 #include "qemu/option.h"
34 #include "sysemu/block-backend.h"
35 #include "migration/misc.h"
38 * Aliases were a bad idea from the start. Let's keep them
39 * from spreading further.
41 typedef struct QDevAlias
48 /* Please keep this table sorted by typename. */
49 static const QDevAlias qdev_alias_table
[] = {
50 { "e1000", "e1000-82540em" },
51 { "ich9-ahci", "ahci" },
52 { "lsi53c895a", "lsi" },
53 { "virtio-9p-ccw", "virtio-9p", QEMU_ARCH_S390X
},
54 { "virtio-9p-pci", "virtio-9p", QEMU_ARCH_ALL
& ~QEMU_ARCH_S390X
},
55 { "virtio-balloon-ccw", "virtio-balloon", QEMU_ARCH_S390X
},
56 { "virtio-balloon-pci", "virtio-balloon",
57 QEMU_ARCH_ALL
& ~QEMU_ARCH_S390X
},
58 { "virtio-blk-ccw", "virtio-blk", QEMU_ARCH_S390X
},
59 { "virtio-blk-pci", "virtio-blk", QEMU_ARCH_ALL
& ~QEMU_ARCH_S390X
},
60 { "virtio-gpu-ccw", "virtio-gpu", QEMU_ARCH_S390X
},
61 { "virtio-gpu-pci", "virtio-gpu", QEMU_ARCH_ALL
& ~QEMU_ARCH_S390X
},
62 { "virtio-input-host-ccw", "virtio-input-host", QEMU_ARCH_S390X
},
63 { "virtio-input-host-pci", "virtio-input-host",
64 QEMU_ARCH_ALL
& ~QEMU_ARCH_S390X
},
65 { "virtio-keyboard-ccw", "virtio-keyboard", QEMU_ARCH_S390X
},
66 { "virtio-keyboard-pci", "virtio-keyboard",
67 QEMU_ARCH_ALL
& ~QEMU_ARCH_S390X
},
68 { "virtio-mouse-ccw", "virtio-mouse", QEMU_ARCH_S390X
},
69 { "virtio-mouse-pci", "virtio-mouse", QEMU_ARCH_ALL
& ~QEMU_ARCH_S390X
},
70 { "virtio-net-ccw", "virtio-net", QEMU_ARCH_S390X
},
71 { "virtio-net-pci", "virtio-net", QEMU_ARCH_ALL
& ~QEMU_ARCH_S390X
},
72 { "virtio-rng-ccw", "virtio-rng", QEMU_ARCH_S390X
},
73 { "virtio-rng-pci", "virtio-rng", QEMU_ARCH_ALL
& ~QEMU_ARCH_S390X
},
74 { "virtio-scsi-ccw", "virtio-scsi", QEMU_ARCH_S390X
},
75 { "virtio-scsi-pci", "virtio-scsi", QEMU_ARCH_ALL
& ~QEMU_ARCH_S390X
},
76 { "virtio-serial-ccw", "virtio-serial", QEMU_ARCH_S390X
},
77 { "virtio-serial-pci", "virtio-serial", QEMU_ARCH_ALL
& ~QEMU_ARCH_S390X
},
78 { "virtio-tablet-ccw", "virtio-tablet", QEMU_ARCH_S390X
},
79 { "virtio-tablet-pci", "virtio-tablet", QEMU_ARCH_ALL
& ~QEMU_ARCH_S390X
},
83 static const char *qdev_class_get_alias(DeviceClass
*dc
)
85 const char *typename
= object_class_get_name(OBJECT_CLASS(dc
));
88 for (i
= 0; qdev_alias_table
[i
].typename
; i
++) {
89 if (qdev_alias_table
[i
].arch_mask
&&
90 !(qdev_alias_table
[i
].arch_mask
& arch_type
)) {
94 if (strcmp(qdev_alias_table
[i
].typename
, typename
) == 0) {
95 return qdev_alias_table
[i
].alias
;
102 static bool qdev_class_has_alias(DeviceClass
*dc
)
104 return (qdev_class_get_alias(dc
) != NULL
);
107 static void out_printf(const char *fmt
, ...)
112 monitor_vfprintf(stdout
, fmt
, ap
);
116 static void qdev_print_devinfo(DeviceClass
*dc
)
118 out_printf("name \"%s\"", object_class_get_name(OBJECT_CLASS(dc
)));
120 out_printf(", bus %s", dc
->bus_type
);
122 if (qdev_class_has_alias(dc
)) {
123 out_printf(", alias \"%s\"", qdev_class_get_alias(dc
));
126 out_printf(", desc \"%s\"", dc
->desc
);
128 if (!dc
->user_creatable
) {
129 out_printf(", no-user");
134 static void qdev_print_devinfos(bool show_no_user
)
136 static const char *cat_name
[DEVICE_CATEGORY_MAX
+ 1] = {
137 [DEVICE_CATEGORY_BRIDGE
] = "Controller/Bridge/Hub",
138 [DEVICE_CATEGORY_USB
] = "USB",
139 [DEVICE_CATEGORY_STORAGE
] = "Storage",
140 [DEVICE_CATEGORY_NETWORK
] = "Network",
141 [DEVICE_CATEGORY_INPUT
] = "Input",
142 [DEVICE_CATEGORY_DISPLAY
] = "Display",
143 [DEVICE_CATEGORY_SOUND
] = "Sound",
144 [DEVICE_CATEGORY_MISC
] = "Misc",
145 [DEVICE_CATEGORY_CPU
] = "CPU",
146 [DEVICE_CATEGORY_MAX
] = "Uncategorized",
152 list
= object_class_get_list_sorted(TYPE_DEVICE
, false);
154 for (i
= 0; i
<= DEVICE_CATEGORY_MAX
; i
++) {
156 for (elt
= list
; elt
; elt
= elt
->next
) {
157 DeviceClass
*dc
= OBJECT_CLASS_CHECK(DeviceClass
, elt
->data
,
159 if ((i
< DEVICE_CATEGORY_MAX
160 ? !test_bit(i
, dc
->categories
)
161 : !bitmap_empty(dc
->categories
, DEVICE_CATEGORY_MAX
))
163 && !dc
->user_creatable
)) {
167 out_printf("%s%s devices:\n", i
? "\n" : "", cat_name
[i
]);
170 qdev_print_devinfo(dc
);
177 static int set_property(void *opaque
, const char *name
, const char *value
,
180 Object
*obj
= opaque
;
183 if (strcmp(name
, "driver") == 0)
185 if (strcmp(name
, "bus") == 0)
188 object_property_parse(obj
, value
, name
, &err
);
190 error_propagate(errp
, err
);
196 static const char *find_typename_by_alias(const char *alias
)
200 for (i
= 0; qdev_alias_table
[i
].alias
; i
++) {
201 if (qdev_alias_table
[i
].arch_mask
&&
202 !(qdev_alias_table
[i
].arch_mask
& arch_type
)) {
206 if (strcmp(qdev_alias_table
[i
].alias
, alias
) == 0) {
207 return qdev_alias_table
[i
].typename
;
214 static DeviceClass
*qdev_get_device_class(const char **driver
, Error
**errp
)
218 const char *original_name
= *driver
;
220 oc
= object_class_by_name(*driver
);
222 const char *typename
= find_typename_by_alias(*driver
);
226 oc
= object_class_by_name(*driver
);
230 if (!object_class_dynamic_cast(oc
, TYPE_DEVICE
)) {
231 if (*driver
!= original_name
) {
232 error_setg(errp
, "'%s' (alias '%s') is not a valid device model"
233 " name", original_name
, *driver
);
235 error_setg(errp
, "'%s' is not a valid device model name", *driver
);
240 if (object_class_is_abstract(oc
)) {
241 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "driver",
242 "non-abstract device type");
246 dc
= DEVICE_CLASS(oc
);
247 if (!dc
->user_creatable
||
248 (qdev_hotplug
&& !dc
->hotpluggable
)) {
249 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "driver",
250 "pluggable device type");
258 int qdev_device_help(QemuOpts
*opts
)
260 Error
*local_err
= NULL
;
262 ObjectPropertyInfoList
*prop_list
;
263 ObjectPropertyInfoList
*prop
;
265 driver
= qemu_opt_get(opts
, "driver");
266 if (driver
&& is_help_option(driver
)) {
267 qdev_print_devinfos(false);
271 if (!driver
|| !qemu_opt_has_help_opt(opts
)) {
275 if (!object_class_by_name(driver
)) {
276 const char *typename
= find_typename_by_alias(driver
);
283 prop_list
= qmp_device_list_properties(driver
, &local_err
);
289 out_printf("%s options:\n", driver
);
291 out_printf("There are no options for %s.\n", driver
);
293 for (prop
= prop_list
; prop
; prop
= prop
->next
) {
295 out_printf(" %s=<%s>%n", prop
->value
->name
, prop
->value
->type
, &len
);
296 if (prop
->value
->has_description
) {
298 out_printf("%*s", 24 - len
, "");
300 out_printf(" - %s\n", prop
->value
->description
);
306 qapi_free_ObjectPropertyInfoList(prop_list
);
310 error_report_err(local_err
);
314 static Object
*qdev_get_peripheral(void)
319 dev
= container_get(qdev_get_machine(), "/peripheral");
325 static Object
*qdev_get_peripheral_anon(void)
330 dev
= container_get(qdev_get_machine(), "/peripheral-anon");
336 static void qbus_list_bus(DeviceState
*dev
, Error
**errp
)
339 const char *sep
= " ";
341 error_append_hint(errp
, "child buses at \"%s\":",
342 dev
->id
? dev
->id
: object_get_typename(OBJECT(dev
)));
343 QLIST_FOREACH(child
, &dev
->child_bus
, sibling
) {
344 error_append_hint(errp
, "%s\"%s\"", sep
, child
->name
);
347 error_append_hint(errp
, "\n");
350 static void qbus_list_dev(BusState
*bus
, Error
**errp
)
353 const char *sep
= " ";
355 error_append_hint(errp
, "devices at \"%s\":", bus
->name
);
356 QTAILQ_FOREACH(kid
, &bus
->children
, sibling
) {
357 DeviceState
*dev
= kid
->child
;
358 error_append_hint(errp
, "%s\"%s\"", sep
,
359 object_get_typename(OBJECT(dev
)));
361 error_append_hint(errp
, "/\"%s\"", dev
->id
);
365 error_append_hint(errp
, "\n");
368 static BusState
*qbus_find_bus(DeviceState
*dev
, char *elem
)
372 QLIST_FOREACH(child
, &dev
->child_bus
, sibling
) {
373 if (strcmp(child
->name
, elem
) == 0) {
380 static DeviceState
*qbus_find_dev(BusState
*bus
, char *elem
)
385 * try to match in order:
386 * (1) instance id, if present
388 * (3) driver alias, if present
390 QTAILQ_FOREACH(kid
, &bus
->children
, sibling
) {
391 DeviceState
*dev
= kid
->child
;
392 if (dev
->id
&& strcmp(dev
->id
, elem
) == 0) {
396 QTAILQ_FOREACH(kid
, &bus
->children
, sibling
) {
397 DeviceState
*dev
= kid
->child
;
398 if (strcmp(object_get_typename(OBJECT(dev
)), elem
) == 0) {
402 QTAILQ_FOREACH(kid
, &bus
->children
, sibling
) {
403 DeviceState
*dev
= kid
->child
;
404 DeviceClass
*dc
= DEVICE_GET_CLASS(dev
);
406 if (qdev_class_has_alias(dc
) &&
407 strcmp(qdev_class_get_alias(dc
), elem
) == 0) {
414 static inline bool qbus_is_full(BusState
*bus
)
416 BusClass
*bus_class
= BUS_GET_CLASS(bus
);
417 return bus_class
->max_dev
&& bus
->max_index
>= bus_class
->max_dev
;
421 * Search the tree rooted at @bus for a bus.
422 * If @name, search for a bus with that name. Note that bus names
423 * need not be unique. Yes, that's screwed up.
424 * Else search for a bus that is a subtype of @bus_typename.
425 * If more than one exists, prefer one that can take another device.
426 * Return the bus if found, else %NULL.
428 static BusState
*qbus_find_recursive(BusState
*bus
, const char *name
,
429 const char *bus_typename
)
432 BusState
*pick
, *child
, *ret
;
435 assert(name
|| bus_typename
);
437 match
= !strcmp(bus
->name
, name
);
439 match
= !!object_dynamic_cast(OBJECT(bus
), bus_typename
);
442 if (match
&& !qbus_is_full(bus
)) {
443 return bus
; /* root matches and isn't full */
446 pick
= match
? bus
: NULL
;
448 QTAILQ_FOREACH(kid
, &bus
->children
, sibling
) {
449 DeviceState
*dev
= kid
->child
;
450 QLIST_FOREACH(child
, &dev
->child_bus
, sibling
) {
451 ret
= qbus_find_recursive(child
, name
, bus_typename
);
452 if (ret
&& !qbus_is_full(ret
)) {
453 return ret
; /* a descendant matches and isn't full */
461 /* root or a descendant matches, but is full */
465 static BusState
*qbus_find(const char *path
, Error
**errp
)
472 /* find start element */
473 if (path
[0] == '/') {
474 bus
= sysbus_get_default();
477 if (sscanf(path
, "%127[^/]%n", elem
, &len
) != 1) {
481 bus
= qbus_find_recursive(sysbus_get_default(), elem
, NULL
);
483 error_setg(errp
, "Bus '%s' not found", elem
);
490 assert(path
[pos
] == '/' || !path
[pos
]);
491 while (path
[pos
] == '/') {
494 if (path
[pos
] == '\0') {
499 if (sscanf(path
+pos
, "%127[^/]%n", elem
, &len
) != 1) {
500 g_assert_not_reached();
504 dev
= qbus_find_dev(bus
, elem
);
506 error_set(errp
, ERROR_CLASS_DEVICE_NOT_FOUND
,
507 "Device '%s' not found", elem
);
508 qbus_list_dev(bus
, errp
);
512 assert(path
[pos
] == '/' || !path
[pos
]);
513 while (path
[pos
] == '/') {
516 if (path
[pos
] == '\0') {
517 /* last specified element is a device. If it has exactly
518 * one child bus accept it nevertheless */
519 if (dev
->num_child_bus
== 1) {
520 bus
= QLIST_FIRST(&dev
->child_bus
);
523 if (dev
->num_child_bus
) {
524 error_setg(errp
, "Device '%s' has multiple child buses",
526 qbus_list_bus(dev
, errp
);
528 error_setg(errp
, "Device '%s' has no child bus", elem
);
534 if (sscanf(path
+pos
, "%127[^/]%n", elem
, &len
) != 1) {
535 g_assert_not_reached();
539 bus
= qbus_find_bus(dev
, elem
);
541 error_setg(errp
, "Bus '%s' not found", elem
);
542 qbus_list_bus(dev
, errp
);
547 if (qbus_is_full(bus
)) {
548 error_setg(errp
, "Bus '%s' is full", path
);
554 void qdev_set_id(DeviceState
*dev
, const char *id
)
561 object_property_add_child(qdev_get_peripheral(), dev
->id
,
564 static int anon_count
;
565 gchar
*name
= g_strdup_printf("device[%d]", anon_count
++);
566 object_property_add_child(qdev_get_peripheral_anon(), name
,
572 DeviceState
*qdev_device_add(QemuOpts
*opts
, Error
**errp
)
575 const char *driver
, *path
;
577 BusState
*bus
= NULL
;
580 driver
= qemu_opt_get(opts
, "driver");
582 error_setg(errp
, QERR_MISSING_PARAMETER
, "driver");
587 dc
= qdev_get_device_class(&driver
, errp
);
593 path
= qemu_opt_get(opts
, "bus");
595 bus
= qbus_find(path
, errp
);
599 if (!object_dynamic_cast(OBJECT(bus
), dc
->bus_type
)) {
600 error_setg(errp
, "Device '%s' can't go on %s bus",
601 driver
, object_get_typename(OBJECT(bus
)));
604 } else if (dc
->bus_type
!= NULL
) {
605 bus
= qbus_find_recursive(sysbus_get_default(), NULL
, dc
->bus_type
);
606 if (!bus
|| qbus_is_full(bus
)) {
607 error_setg(errp
, "No '%s' bus found for device '%s'",
608 dc
->bus_type
, driver
);
612 if (qdev_hotplug
&& bus
&& !qbus_is_hotpluggable(bus
)) {
613 error_setg(errp
, QERR_BUS_NO_HOTPLUG
, bus
->name
);
617 if (!migration_is_idle()) {
618 error_setg(errp
, "device_add not allowed while migrating");
623 dev
= DEVICE(object_new(driver
));
626 qdev_set_parent_bus(dev
, bus
);
627 } else if (qdev_hotplug
&& !qdev_get_machine_hotplug_handler(dev
)) {
628 /* No bus, no machine hotplug handler --> device is not hotpluggable */
629 error_setg(&err
, "Device '%s' can not be hotplugged on this machine",
634 qdev_set_id(dev
, qemu_opts_id(opts
));
637 if (qemu_opt_foreach(opts
, set_property
, dev
, &err
)) {
642 object_property_set_bool(OBJECT(dev
), true, "realized", &err
);
650 error_propagate(errp
, err
);
651 object_unparent(OBJECT(dev
));
652 object_unref(OBJECT(dev
));
657 #define qdev_printf(fmt, ...) monitor_printf(mon, "%*s" fmt, indent, "", ## __VA_ARGS__)
658 static void qbus_print(Monitor
*mon
, BusState
*bus
, int indent
);
660 static void qdev_print_props(Monitor
*mon
, DeviceState
*dev
, Property
*props
,
665 for (; props
->name
; props
++) {
668 char *legacy_name
= g_strdup_printf("legacy-%s", props
->name
);
669 if (object_property_get_type(OBJECT(dev
), legacy_name
, NULL
)) {
670 value
= object_property_get_str(OBJECT(dev
), legacy_name
, &err
);
672 value
= object_property_print(OBJECT(dev
), props
->name
, true, &err
);
680 qdev_printf("%s = %s\n", props
->name
,
681 value
&& *value
? value
: "<null>");
686 static void bus_print_dev(BusState
*bus
, Monitor
*mon
, DeviceState
*dev
, int indent
)
688 BusClass
*bc
= BUS_GET_CLASS(bus
);
691 bc
->print_dev(mon
, dev
, indent
);
695 static void qdev_print(Monitor
*mon
, DeviceState
*dev
, int indent
)
701 qdev_printf("dev: %s, id \"%s\"\n", object_get_typename(OBJECT(dev
)),
702 dev
->id
? dev
->id
: "");
704 QLIST_FOREACH(ngl
, &dev
->gpios
, node
) {
706 qdev_printf("gpio-in \"%s\" %d\n", ngl
->name
? ngl
->name
: "",
710 qdev_printf("gpio-out \"%s\" %d\n", ngl
->name
? ngl
->name
: "",
714 class = object_get_class(OBJECT(dev
));
716 qdev_print_props(mon
, dev
, DEVICE_CLASS(class)->props
, indent
);
717 class = object_class_get_parent(class);
718 } while (class != object_class_by_name(TYPE_DEVICE
));
719 bus_print_dev(dev
->parent_bus
, mon
, dev
, indent
);
720 QLIST_FOREACH(child
, &dev
->child_bus
, sibling
) {
721 qbus_print(mon
, child
, indent
);
725 static void qbus_print(Monitor
*mon
, BusState
*bus
, int indent
)
729 qdev_printf("bus: %s\n", bus
->name
);
731 qdev_printf("type %s\n", object_get_typename(OBJECT(bus
)));
732 QTAILQ_FOREACH(kid
, &bus
->children
, sibling
) {
733 DeviceState
*dev
= kid
->child
;
734 qdev_print(mon
, dev
, indent
);
739 void hmp_info_qtree(Monitor
*mon
, const QDict
*qdict
)
741 if (sysbus_get_default())
742 qbus_print(mon
, sysbus_get_default(), 0);
745 void hmp_info_qdm(Monitor
*mon
, const QDict
*qdict
)
747 qdev_print_devinfos(true);
750 typedef struct QOMCompositionState
{
753 } QOMCompositionState
;
755 static void print_qom_composition(Monitor
*mon
, Object
*obj
, int indent
);
757 static int print_qom_composition_child(Object
*obj
, void *opaque
)
759 QOMCompositionState
*s
= opaque
;
761 print_qom_composition(s
->mon
, obj
, s
->indent
);
766 static void print_qom_composition(Monitor
*mon
, Object
*obj
, int indent
)
768 QOMCompositionState s
= {
770 .indent
= indent
+ 2,
774 if (obj
== object_get_root()) {
777 name
= object_get_canonical_path_component(obj
);
779 monitor_printf(mon
, "%*s/%s (%s)\n", indent
, "", name
,
780 object_get_typename(obj
));
782 object_child_foreach(obj
, print_qom_composition_child
, &s
);
785 void hmp_info_qom_tree(Monitor
*mon
, const QDict
*dict
)
787 const char *path
= qdict_get_try_str(dict
, "path");
789 bool ambiguous
= false;
792 obj
= object_resolve_path(path
, &ambiguous
);
794 monitor_printf(mon
, "Path '%s' could not be resolved.\n", path
);
798 monitor_printf(mon
, "Warning: Path '%s' is ambiguous.\n", path
);
802 obj
= qdev_get_machine();
804 print_qom_composition(mon
, obj
, 0);
807 void qmp_device_add(QDict
*qdict
, QObject
**ret_data
, Error
**errp
)
809 Error
*local_err
= NULL
;
813 opts
= qemu_opts_from_qdict(qemu_find_opts("device"), qdict
, &local_err
);
815 error_propagate(errp
, local_err
);
818 if (!monitor_cur_is_qmp() && qdev_device_help(opts
)) {
822 dev
= qdev_device_add(opts
, &local_err
);
824 error_propagate(errp
, local_err
);
828 object_unref(OBJECT(dev
));
831 static DeviceState
*find_device_state(const char *id
, Error
**errp
)
836 obj
= object_resolve_path(id
, NULL
);
838 char *root_path
= object_get_canonical_path(qdev_get_peripheral());
839 char *path
= g_strdup_printf("%s/%s", root_path
, id
);
842 obj
= object_resolve_path_type(path
, TYPE_DEVICE
, NULL
);
847 error_set(errp
, ERROR_CLASS_DEVICE_NOT_FOUND
,
848 "Device '%s' not found", id
);
852 if (!object_dynamic_cast(obj
, TYPE_DEVICE
)) {
853 error_setg(errp
, "%s is not a hotpluggable device", id
);
860 void qdev_unplug(DeviceState
*dev
, Error
**errp
)
862 DeviceClass
*dc
= DEVICE_GET_CLASS(dev
);
863 HotplugHandler
*hotplug_ctrl
;
864 HotplugHandlerClass
*hdc
;
866 if (dev
->parent_bus
&& !qbus_is_hotpluggable(dev
->parent_bus
)) {
867 error_setg(errp
, QERR_BUS_NO_HOTPLUG
, dev
->parent_bus
->name
);
871 if (!dc
->hotpluggable
) {
872 error_setg(errp
, QERR_DEVICE_NO_HOTPLUG
,
873 object_get_typename(OBJECT(dev
)));
877 if (!migration_is_idle()) {
878 error_setg(errp
, "device_del not allowed while migrating");
882 qdev_hot_removed
= true;
884 hotplug_ctrl
= qdev_get_hotplug_handler(dev
);
885 /* hotpluggable device MUST have HotplugHandler, if it doesn't
886 * then something is very wrong with it */
887 g_assert(hotplug_ctrl
);
889 /* If device supports async unplug just request it to be done,
890 * otherwise just remove it synchronously */
891 hdc
= HOTPLUG_HANDLER_GET_CLASS(hotplug_ctrl
);
892 if (hdc
->unplug_request
) {
893 hotplug_handler_unplug_request(hotplug_ctrl
, dev
, errp
);
895 hotplug_handler_unplug(hotplug_ctrl
, dev
, errp
);
899 void qmp_device_del(const char *id
, Error
**errp
)
901 DeviceState
*dev
= find_device_state(id
, errp
);
903 qdev_unplug(dev
, errp
);
907 BlockBackend
*blk_by_qdev_id(const char *id
, Error
**errp
)
912 dev
= find_device_state(id
, errp
);
917 blk
= blk_by_dev(dev
);
919 error_setg(errp
, "Device does not have a block device backend");
924 void qdev_machine_init(void)
926 qdev_get_peripheral_anon();
927 qdev_get_peripheral();
930 QemuOptsList qemu_device_opts
= {
932 .implied_opt_name
= "driver",
933 .head
= QTAILQ_HEAD_INITIALIZER(qemu_device_opts
.head
),
936 * no elements => accept any
937 * sanity checking will happen later
938 * when setting device properties
940 { /* end of list */ }
944 QemuOptsList qemu_global_opts
= {
946 .head
= QTAILQ_HEAD_INITIALIZER(qemu_global_opts
.head
),
950 .type
= QEMU_OPT_STRING
,
953 .type
= QEMU_OPT_STRING
,
956 .type
= QEMU_OPT_STRING
,
958 { /* end of list */ }
962 int qemu_global_option(const char *str
)
964 char driver
[64], property
[64];
968 rc
= sscanf(str
, "%63[^.=].%63[^=]%n", driver
, property
, &offset
);
969 if (rc
== 2 && str
[offset
] == '=') {
970 opts
= qemu_opts_create(&qemu_global_opts
, NULL
, 0, &error_abort
);
971 qemu_opt_set(opts
, "driver", driver
, &error_abort
);
972 qemu_opt_set(opts
, "property", property
, &error_abort
);
973 qemu_opt_set(opts
, "value", str
+ offset
+ 1, &error_abort
);
977 opts
= qemu_opts_parse_noisily(&qemu_global_opts
, str
, false);