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"
21 #include "hw/sysbus.h"
22 #include "monitor/hmp.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-qdev.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 "qemu/qemu-print.h"
35 #include "sysemu/block-backend.h"
36 #include "sysemu/sysemu.h"
37 #include "migration/misc.h"
40 * Aliases were a bad idea from the start. Let's keep them
41 * from spreading further.
43 typedef struct QDevAlias
50 /* Please keep this table sorted by typename. */
51 static const QDevAlias qdev_alias_table
[] = {
52 { "e1000", "e1000-82540em" },
53 { "ich9-ahci", "ahci" },
54 { "lsi53c895a", "lsi" },
55 { "virtio-9p-ccw", "virtio-9p", QEMU_ARCH_S390X
},
56 { "virtio-9p-pci", "virtio-9p", QEMU_ARCH_ALL
& ~QEMU_ARCH_S390X
},
57 { "virtio-balloon-ccw", "virtio-balloon", QEMU_ARCH_S390X
},
58 { "virtio-balloon-pci", "virtio-balloon",
59 QEMU_ARCH_ALL
& ~QEMU_ARCH_S390X
},
60 { "virtio-blk-ccw", "virtio-blk", QEMU_ARCH_S390X
},
61 { "virtio-blk-pci", "virtio-blk", QEMU_ARCH_ALL
& ~QEMU_ARCH_S390X
},
62 { "virtio-gpu-ccw", "virtio-gpu", QEMU_ARCH_S390X
},
63 { "virtio-gpu-pci", "virtio-gpu", QEMU_ARCH_ALL
& ~QEMU_ARCH_S390X
},
64 { "virtio-input-host-ccw", "virtio-input-host", QEMU_ARCH_S390X
},
65 { "virtio-input-host-pci", "virtio-input-host",
66 QEMU_ARCH_ALL
& ~QEMU_ARCH_S390X
},
67 { "virtio-keyboard-ccw", "virtio-keyboard", QEMU_ARCH_S390X
},
68 { "virtio-keyboard-pci", "virtio-keyboard",
69 QEMU_ARCH_ALL
& ~QEMU_ARCH_S390X
},
70 { "virtio-mouse-ccw", "virtio-mouse", QEMU_ARCH_S390X
},
71 { "virtio-mouse-pci", "virtio-mouse", QEMU_ARCH_ALL
& ~QEMU_ARCH_S390X
},
72 { "virtio-net-ccw", "virtio-net", QEMU_ARCH_S390X
},
73 { "virtio-net-pci", "virtio-net", QEMU_ARCH_ALL
& ~QEMU_ARCH_S390X
},
74 { "virtio-rng-ccw", "virtio-rng", QEMU_ARCH_S390X
},
75 { "virtio-rng-pci", "virtio-rng", QEMU_ARCH_ALL
& ~QEMU_ARCH_S390X
},
76 { "virtio-scsi-ccw", "virtio-scsi", QEMU_ARCH_S390X
},
77 { "virtio-scsi-pci", "virtio-scsi", QEMU_ARCH_ALL
& ~QEMU_ARCH_S390X
},
78 { "virtio-serial-ccw", "virtio-serial", QEMU_ARCH_S390X
},
79 { "virtio-serial-pci", "virtio-serial", QEMU_ARCH_ALL
& ~QEMU_ARCH_S390X
},
80 { "virtio-tablet-ccw", "virtio-tablet", QEMU_ARCH_S390X
},
81 { "virtio-tablet-pci", "virtio-tablet", QEMU_ARCH_ALL
& ~QEMU_ARCH_S390X
},
85 static const char *qdev_class_get_alias(DeviceClass
*dc
)
87 const char *typename
= object_class_get_name(OBJECT_CLASS(dc
));
90 for (i
= 0; qdev_alias_table
[i
].typename
; i
++) {
91 if (qdev_alias_table
[i
].arch_mask
&&
92 !(qdev_alias_table
[i
].arch_mask
& arch_type
)) {
96 if (strcmp(qdev_alias_table
[i
].typename
, typename
) == 0) {
97 return qdev_alias_table
[i
].alias
;
104 static bool qdev_class_has_alias(DeviceClass
*dc
)
106 return (qdev_class_get_alias(dc
) != NULL
);
109 static void qdev_print_devinfo(DeviceClass
*dc
)
111 qemu_printf("name \"%s\"", object_class_get_name(OBJECT_CLASS(dc
)));
113 qemu_printf(", bus %s", dc
->bus_type
);
115 if (qdev_class_has_alias(dc
)) {
116 qemu_printf(", alias \"%s\"", qdev_class_get_alias(dc
));
119 qemu_printf(", desc \"%s\"", dc
->desc
);
121 if (!dc
->user_creatable
) {
122 qemu_printf(", no-user");
127 static void qdev_print_devinfos(bool show_no_user
)
129 static const char *cat_name
[DEVICE_CATEGORY_MAX
+ 1] = {
130 [DEVICE_CATEGORY_BRIDGE
] = "Controller/Bridge/Hub",
131 [DEVICE_CATEGORY_USB
] = "USB",
132 [DEVICE_CATEGORY_STORAGE
] = "Storage",
133 [DEVICE_CATEGORY_NETWORK
] = "Network",
134 [DEVICE_CATEGORY_INPUT
] = "Input",
135 [DEVICE_CATEGORY_DISPLAY
] = "Display",
136 [DEVICE_CATEGORY_SOUND
] = "Sound",
137 [DEVICE_CATEGORY_MISC
] = "Misc",
138 [DEVICE_CATEGORY_CPU
] = "CPU",
139 [DEVICE_CATEGORY_MAX
] = "Uncategorized",
145 list
= object_class_get_list_sorted(TYPE_DEVICE
, false);
147 for (i
= 0; i
<= DEVICE_CATEGORY_MAX
; i
++) {
149 for (elt
= list
; elt
; elt
= elt
->next
) {
150 DeviceClass
*dc
= OBJECT_CLASS_CHECK(DeviceClass
, elt
->data
,
152 if ((i
< DEVICE_CATEGORY_MAX
153 ? !test_bit(i
, dc
->categories
)
154 : !bitmap_empty(dc
->categories
, DEVICE_CATEGORY_MAX
))
156 && !dc
->user_creatable
)) {
160 qemu_printf("%s%s devices:\n", i
? "\n" : "", cat_name
[i
]);
163 qdev_print_devinfo(dc
);
170 static int set_property(void *opaque
, const char *name
, const char *value
,
173 Object
*obj
= opaque
;
176 if (strcmp(name
, "driver") == 0)
178 if (strcmp(name
, "bus") == 0)
181 object_property_parse(obj
, value
, name
, &err
);
183 error_propagate(errp
, err
);
189 static const char *find_typename_by_alias(const char *alias
)
193 for (i
= 0; qdev_alias_table
[i
].alias
; i
++) {
194 if (qdev_alias_table
[i
].arch_mask
&&
195 !(qdev_alias_table
[i
].arch_mask
& arch_type
)) {
199 if (strcmp(qdev_alias_table
[i
].alias
, alias
) == 0) {
200 return qdev_alias_table
[i
].typename
;
207 static DeviceClass
*qdev_get_device_class(const char **driver
, Error
**errp
)
211 const char *original_name
= *driver
;
213 oc
= object_class_by_name(*driver
);
215 const char *typename
= find_typename_by_alias(*driver
);
219 oc
= object_class_by_name(*driver
);
223 if (!object_class_dynamic_cast(oc
, TYPE_DEVICE
)) {
224 if (*driver
!= original_name
) {
225 error_setg(errp
, "'%s' (alias '%s') is not a valid device model"
226 " name", original_name
, *driver
);
228 error_setg(errp
, "'%s' is not a valid device model name", *driver
);
233 if (object_class_is_abstract(oc
)) {
234 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "driver",
235 "non-abstract device type");
239 dc
= DEVICE_CLASS(oc
);
240 if (!dc
->user_creatable
||
241 (qdev_hotplug
&& !dc
->hotpluggable
)) {
242 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
, "driver",
243 "pluggable device type");
251 int qdev_device_help(QemuOpts
*opts
)
253 Error
*local_err
= NULL
;
255 ObjectPropertyInfoList
*prop_list
;
256 ObjectPropertyInfoList
*prop
;
258 driver
= qemu_opt_get(opts
, "driver");
259 if (driver
&& is_help_option(driver
)) {
260 qdev_print_devinfos(false);
264 if (!driver
|| !qemu_opt_has_help_opt(opts
)) {
268 if (!object_class_by_name(driver
)) {
269 const char *typename
= find_typename_by_alias(driver
);
276 prop_list
= qmp_device_list_properties(driver
, &local_err
);
282 qemu_printf("%s options:\n", driver
);
284 qemu_printf("There are no options for %s.\n", driver
);
286 for (prop
= prop_list
; prop
; prop
= prop
->next
) {
288 qemu_printf(" %s=<%s>%n", prop
->value
->name
, prop
->value
->type
, &len
);
289 if (prop
->value
->has_description
) {
291 qemu_printf("%*s", 24 - len
, "");
293 qemu_printf(" - %s\n", prop
->value
->description
);
299 qapi_free_ObjectPropertyInfoList(prop_list
);
303 error_report_err(local_err
);
307 static Object
*qdev_get_peripheral(void)
312 dev
= container_get(qdev_get_machine(), "/peripheral");
318 static Object
*qdev_get_peripheral_anon(void)
323 dev
= container_get(qdev_get_machine(), "/peripheral-anon");
329 static void qbus_list_bus(DeviceState
*dev
, Error
**errp
)
332 const char *sep
= " ";
334 error_append_hint(errp
, "child buses at \"%s\":",
335 dev
->id
? dev
->id
: object_get_typename(OBJECT(dev
)));
336 QLIST_FOREACH(child
, &dev
->child_bus
, sibling
) {
337 error_append_hint(errp
, "%s\"%s\"", sep
, child
->name
);
340 error_append_hint(errp
, "\n");
343 static void qbus_list_dev(BusState
*bus
, Error
**errp
)
346 const char *sep
= " ";
348 error_append_hint(errp
, "devices at \"%s\":", bus
->name
);
349 QTAILQ_FOREACH(kid
, &bus
->children
, sibling
) {
350 DeviceState
*dev
= kid
->child
;
351 error_append_hint(errp
, "%s\"%s\"", sep
,
352 object_get_typename(OBJECT(dev
)));
354 error_append_hint(errp
, "/\"%s\"", dev
->id
);
358 error_append_hint(errp
, "\n");
361 static BusState
*qbus_find_bus(DeviceState
*dev
, char *elem
)
365 QLIST_FOREACH(child
, &dev
->child_bus
, sibling
) {
366 if (strcmp(child
->name
, elem
) == 0) {
373 static DeviceState
*qbus_find_dev(BusState
*bus
, char *elem
)
378 * try to match in order:
379 * (1) instance id, if present
381 * (3) driver alias, if present
383 QTAILQ_FOREACH(kid
, &bus
->children
, sibling
) {
384 DeviceState
*dev
= kid
->child
;
385 if (dev
->id
&& strcmp(dev
->id
, elem
) == 0) {
389 QTAILQ_FOREACH(kid
, &bus
->children
, sibling
) {
390 DeviceState
*dev
= kid
->child
;
391 if (strcmp(object_get_typename(OBJECT(dev
)), elem
) == 0) {
395 QTAILQ_FOREACH(kid
, &bus
->children
, sibling
) {
396 DeviceState
*dev
= kid
->child
;
397 DeviceClass
*dc
= DEVICE_GET_CLASS(dev
);
399 if (qdev_class_has_alias(dc
) &&
400 strcmp(qdev_class_get_alias(dc
), elem
) == 0) {
407 static inline bool qbus_is_full(BusState
*bus
)
409 BusClass
*bus_class
= BUS_GET_CLASS(bus
);
410 return bus_class
->max_dev
&& bus
->num_children
>= bus_class
->max_dev
;
414 * Search the tree rooted at @bus for a bus.
415 * If @name, search for a bus with that name. Note that bus names
416 * need not be unique. Yes, that's screwed up.
417 * Else search for a bus that is a subtype of @bus_typename.
418 * If more than one exists, prefer one that can take another device.
419 * Return the bus if found, else %NULL.
421 static BusState
*qbus_find_recursive(BusState
*bus
, const char *name
,
422 const char *bus_typename
)
425 BusState
*pick
, *child
, *ret
;
428 assert(name
|| bus_typename
);
430 match
= !strcmp(bus
->name
, name
);
432 match
= !!object_dynamic_cast(OBJECT(bus
), bus_typename
);
435 if (match
&& !qbus_is_full(bus
)) {
436 return bus
; /* root matches and isn't full */
439 pick
= match
? bus
: NULL
;
441 QTAILQ_FOREACH(kid
, &bus
->children
, sibling
) {
442 DeviceState
*dev
= kid
->child
;
443 QLIST_FOREACH(child
, &dev
->child_bus
, sibling
) {
444 ret
= qbus_find_recursive(child
, name
, bus_typename
);
445 if (ret
&& !qbus_is_full(ret
)) {
446 return ret
; /* a descendant matches and isn't full */
454 /* root or a descendant matches, but is full */
458 static BusState
*qbus_find(const char *path
, Error
**errp
)
465 /* find start element */
466 if (path
[0] == '/') {
467 bus
= sysbus_get_default();
470 if (sscanf(path
, "%127[^/]%n", elem
, &len
) != 1) {
474 bus
= qbus_find_recursive(sysbus_get_default(), elem
, NULL
);
476 error_setg(errp
, "Bus '%s' not found", elem
);
483 assert(path
[pos
] == '/' || !path
[pos
]);
484 while (path
[pos
] == '/') {
487 if (path
[pos
] == '\0') {
492 if (sscanf(path
+pos
, "%127[^/]%n", elem
, &len
) != 1) {
493 g_assert_not_reached();
497 dev
= qbus_find_dev(bus
, elem
);
499 error_set(errp
, ERROR_CLASS_DEVICE_NOT_FOUND
,
500 "Device '%s' not found", elem
);
501 qbus_list_dev(bus
, errp
);
505 assert(path
[pos
] == '/' || !path
[pos
]);
506 while (path
[pos
] == '/') {
509 if (path
[pos
] == '\0') {
510 /* last specified element is a device. If it has exactly
511 * one child bus accept it nevertheless */
512 if (dev
->num_child_bus
== 1) {
513 bus
= QLIST_FIRST(&dev
->child_bus
);
516 if (dev
->num_child_bus
) {
517 error_setg(errp
, "Device '%s' has multiple child buses",
519 qbus_list_bus(dev
, errp
);
521 error_setg(errp
, "Device '%s' has no child bus", elem
);
527 if (sscanf(path
+pos
, "%127[^/]%n", elem
, &len
) != 1) {
528 g_assert_not_reached();
532 bus
= qbus_find_bus(dev
, elem
);
534 error_setg(errp
, "Bus '%s' not found", elem
);
535 qbus_list_bus(dev
, errp
);
540 if (qbus_is_full(bus
)) {
541 error_setg(errp
, "Bus '%s' is full", path
);
547 void qdev_set_id(DeviceState
*dev
, const char *id
)
554 object_property_add_child(qdev_get_peripheral(), dev
->id
,
557 static int anon_count
;
558 gchar
*name
= g_strdup_printf("device[%d]", anon_count
++);
559 object_property_add_child(qdev_get_peripheral_anon(), name
,
565 DeviceState
*qdev_device_add(QemuOpts
*opts
, Error
**errp
)
568 const char *driver
, *path
;
570 BusState
*bus
= NULL
;
573 driver
= qemu_opt_get(opts
, "driver");
575 error_setg(errp
, QERR_MISSING_PARAMETER
, "driver");
580 dc
= qdev_get_device_class(&driver
, errp
);
586 path
= qemu_opt_get(opts
, "bus");
588 bus
= qbus_find(path
, errp
);
592 if (!object_dynamic_cast(OBJECT(bus
), dc
->bus_type
)) {
593 error_setg(errp
, "Device '%s' can't go on %s bus",
594 driver
, object_get_typename(OBJECT(bus
)));
597 } else if (dc
->bus_type
!= NULL
) {
598 bus
= qbus_find_recursive(sysbus_get_default(), NULL
, dc
->bus_type
);
599 if (!bus
|| qbus_is_full(bus
)) {
600 error_setg(errp
, "No '%s' bus found for device '%s'",
601 dc
->bus_type
, driver
);
605 if (qdev_hotplug
&& bus
&& !qbus_is_hotpluggable(bus
)) {
606 error_setg(errp
, QERR_BUS_NO_HOTPLUG
, bus
->name
);
610 if (!migration_is_idle()) {
611 error_setg(errp
, "device_add not allowed while migrating");
616 dev
= DEVICE(object_new(driver
));
619 qdev_set_parent_bus(dev
, bus
);
620 } else if (qdev_hotplug
&& !qdev_get_machine_hotplug_handler(dev
)) {
621 /* No bus, no machine hotplug handler --> device is not hotpluggable */
622 error_setg(&err
, "Device '%s' can not be hotplugged on this machine",
627 qdev_set_id(dev
, qemu_opts_id(opts
));
630 if (qemu_opt_foreach(opts
, set_property
, dev
, &err
)) {
635 object_property_set_bool(OBJECT(dev
), true, "realized", &err
);
643 error_propagate(errp
, err
);
644 object_unparent(OBJECT(dev
));
645 object_unref(OBJECT(dev
));
650 #define qdev_printf(fmt, ...) monitor_printf(mon, "%*s" fmt, indent, "", ## __VA_ARGS__)
651 static void qbus_print(Monitor
*mon
, BusState
*bus
, int indent
);
653 static void qdev_print_props(Monitor
*mon
, DeviceState
*dev
, Property
*props
,
658 for (; props
->name
; props
++) {
661 char *legacy_name
= g_strdup_printf("legacy-%s", props
->name
);
662 if (object_property_get_type(OBJECT(dev
), legacy_name
, NULL
)) {
663 value
= object_property_get_str(OBJECT(dev
), legacy_name
, &err
);
665 value
= object_property_print(OBJECT(dev
), props
->name
, true, &err
);
673 qdev_printf("%s = %s\n", props
->name
,
674 value
&& *value
? value
: "<null>");
679 static void bus_print_dev(BusState
*bus
, Monitor
*mon
, DeviceState
*dev
, int indent
)
681 BusClass
*bc
= BUS_GET_CLASS(bus
);
684 bc
->print_dev(mon
, dev
, indent
);
688 static void qdev_print(Monitor
*mon
, DeviceState
*dev
, int indent
)
694 qdev_printf("dev: %s, id \"%s\"\n", object_get_typename(OBJECT(dev
)),
695 dev
->id
? dev
->id
: "");
697 QLIST_FOREACH(ngl
, &dev
->gpios
, node
) {
699 qdev_printf("gpio-in \"%s\" %d\n", ngl
->name
? ngl
->name
: "",
703 qdev_printf("gpio-out \"%s\" %d\n", ngl
->name
? ngl
->name
: "",
707 class = object_get_class(OBJECT(dev
));
709 qdev_print_props(mon
, dev
, DEVICE_CLASS(class)->props
, indent
);
710 class = object_class_get_parent(class);
711 } while (class != object_class_by_name(TYPE_DEVICE
));
712 bus_print_dev(dev
->parent_bus
, mon
, dev
, indent
);
713 QLIST_FOREACH(child
, &dev
->child_bus
, sibling
) {
714 qbus_print(mon
, child
, indent
);
718 static void qbus_print(Monitor
*mon
, BusState
*bus
, int indent
)
722 qdev_printf("bus: %s\n", bus
->name
);
724 qdev_printf("type %s\n", object_get_typename(OBJECT(bus
)));
725 QTAILQ_FOREACH(kid
, &bus
->children
, sibling
) {
726 DeviceState
*dev
= kid
->child
;
727 qdev_print(mon
, dev
, indent
);
732 void hmp_info_qtree(Monitor
*mon
, const QDict
*qdict
)
734 if (sysbus_get_default())
735 qbus_print(mon
, sysbus_get_default(), 0);
738 void hmp_info_qdm(Monitor
*mon
, const QDict
*qdict
)
740 qdev_print_devinfos(true);
743 void qmp_device_add(QDict
*qdict
, QObject
**ret_data
, Error
**errp
)
745 Error
*local_err
= NULL
;
749 opts
= qemu_opts_from_qdict(qemu_find_opts("device"), qdict
, &local_err
);
751 error_propagate(errp
, local_err
);
754 if (!monitor_cur_is_qmp() && qdev_device_help(opts
)) {
758 dev
= qdev_device_add(opts
, &local_err
);
760 error_propagate(errp
, local_err
);
764 object_unref(OBJECT(dev
));
767 static DeviceState
*find_device_state(const char *id
, Error
**errp
)
772 obj
= object_resolve_path(id
, NULL
);
774 char *root_path
= object_get_canonical_path(qdev_get_peripheral());
775 char *path
= g_strdup_printf("%s/%s", root_path
, id
);
778 obj
= object_resolve_path_type(path
, TYPE_DEVICE
, NULL
);
783 error_set(errp
, ERROR_CLASS_DEVICE_NOT_FOUND
,
784 "Device '%s' not found", id
);
788 if (!object_dynamic_cast(obj
, TYPE_DEVICE
)) {
789 error_setg(errp
, "%s is not a hotpluggable device", id
);
796 void qdev_unplug(DeviceState
*dev
, Error
**errp
)
798 DeviceClass
*dc
= DEVICE_GET_CLASS(dev
);
799 HotplugHandler
*hotplug_ctrl
;
800 HotplugHandlerClass
*hdc
;
801 Error
*local_err
= NULL
;
803 if (dev
->parent_bus
&& !qbus_is_hotpluggable(dev
->parent_bus
)) {
804 error_setg(errp
, QERR_BUS_NO_HOTPLUG
, dev
->parent_bus
->name
);
808 if (!dc
->hotpluggable
) {
809 error_setg(errp
, QERR_DEVICE_NO_HOTPLUG
,
810 object_get_typename(OBJECT(dev
)));
814 if (!migration_is_idle()) {
815 error_setg(errp
, "device_del not allowed while migrating");
819 qdev_hot_removed
= true;
821 hotplug_ctrl
= qdev_get_hotplug_handler(dev
);
822 /* hotpluggable device MUST have HotplugHandler, if it doesn't
823 * then something is very wrong with it */
824 g_assert(hotplug_ctrl
);
826 /* If device supports async unplug just request it to be done,
827 * otherwise just remove it synchronously */
828 hdc
= HOTPLUG_HANDLER_GET_CLASS(hotplug_ctrl
);
829 if (hdc
->unplug_request
) {
830 hotplug_handler_unplug_request(hotplug_ctrl
, dev
, &local_err
);
832 hotplug_handler_unplug(hotplug_ctrl
, dev
, &local_err
);
834 object_unparent(OBJECT(dev
));
837 error_propagate(errp
, local_err
);
840 void qmp_device_del(const char *id
, Error
**errp
)
842 DeviceState
*dev
= find_device_state(id
, errp
);
844 qdev_unplug(dev
, errp
);
848 void hmp_device_add(Monitor
*mon
, const QDict
*qdict
)
852 qmp_device_add((QDict
*)qdict
, NULL
, &err
);
853 hmp_handle_error(mon
, &err
);
856 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
858 const char *id
= qdict_get_str(qdict
, "id");
861 qmp_device_del(id
, &err
);
862 hmp_handle_error(mon
, &err
);
865 BlockBackend
*blk_by_qdev_id(const char *id
, Error
**errp
)
870 dev
= find_device_state(id
, errp
);
875 blk
= blk_by_dev(dev
);
877 error_setg(errp
, "Device does not have a block device backend");
882 void qdev_machine_init(void)
884 qdev_get_peripheral_anon();
885 qdev_get_peripheral();
888 QemuOptsList qemu_device_opts
= {
890 .implied_opt_name
= "driver",
891 .head
= QTAILQ_HEAD_INITIALIZER(qemu_device_opts
.head
),
894 * no elements => accept any
895 * sanity checking will happen later
896 * when setting device properties
898 { /* end of list */ }
902 QemuOptsList qemu_global_opts
= {
904 .head
= QTAILQ_HEAD_INITIALIZER(qemu_global_opts
.head
),
908 .type
= QEMU_OPT_STRING
,
911 .type
= QEMU_OPT_STRING
,
914 .type
= QEMU_OPT_STRING
,
916 { /* end of list */ }
920 int qemu_global_option(const char *str
)
922 char driver
[64], property
[64];
926 rc
= sscanf(str
, "%63[^.=].%63[^=]%n", driver
, property
, &offset
);
927 if (rc
== 2 && str
[offset
] == '=') {
928 opts
= qemu_opts_create(&qemu_global_opts
, NULL
, 0, &error_abort
);
929 qemu_opt_set(opts
, "driver", driver
, &error_abort
);
930 qemu_opt_set(opts
, "property", property
, &error_abort
);
931 qemu_opt_set(opts
, "value", str
+ offset
+ 1, &error_abort
);
935 opts
= qemu_opts_parse_noisily(&qemu_global_opts
, str
, false);