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 /* The theory here is that it should be possible to create a machine without
21 knowledge of specific devices. Historically board init routines have
22 passed a bunch of arguments to each device, requiring the board know
23 exactly which device it is dealing with. This file provides an abstract
24 API for device configuration and initialization. Devices will generally
25 inherit from a particular bus (e.g. PCI or I2C) rather than
33 static int qdev_hotplug = 0;
34 static bool qdev_hot_added = false;
35 static bool qdev_hot_removed = false;
37 /* This is a nasty hack to allow passing a NULL bus to qdev_create. */
38 static BusState *main_system_bus;
39 static void main_system_bus_create(void);
41 DeviceInfo *device_info_list;
43 static BusState *qbus_find_recursive(BusState *bus, const char *name,
45 static BusState *qbus_find(const char *path);
47 /* Register a new device type. */
48 void qdev_register(DeviceInfo *info)
50 assert(info->size >= sizeof(DeviceState));
53 info->next = device_info_list;
54 device_info_list = info;
57 static DeviceInfo *qdev_find_info(BusInfo *bus_info, const char *name)
61 /* first check device names */
62 for (info = device_info_list; info != NULL; info = info->next) {
63 if (bus_info && info->bus_info != bus_info)
65 if (strcmp(info->name, name) != 0)
70 /* failing that check the aliases */
71 for (info = device_info_list; info != NULL; info = info->next) {
72 if (bus_info && info->bus_info != bus_info)
76 if (strcmp(info->alias, name) != 0)
83 static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info)
88 assert(bus->info == info->bus_info);
89 dev = g_malloc0(info->size);
91 dev->parent_bus = bus;
92 qdev_prop_set_defaults(dev, dev->info->props);
93 qdev_prop_set_defaults(dev, dev->parent_bus->info->props);
94 qdev_prop_set_globals(dev);
95 QTAILQ_INSERT_HEAD(&bus->children, dev, sibling);
97 assert(bus->allow_hotplug);
99 qdev_hot_added = true;
101 dev->instance_id_alias = -1;
102 QTAILQ_INIT(&dev->properties);
103 dev->state = DEV_STATE_CREATED;
105 for (prop = dev->info->props; prop && prop->name; prop++) {
106 qdev_property_add_legacy(dev, prop, NULL);
109 for (prop = dev->info->bus_info->props; prop && prop->name; prop++) {
110 qdev_property_add_legacy(dev, prop, NULL);
116 /* Create a new device. This only initializes the device state structure
117 and allows properties to be set. qdev_init should be called to
118 initialize the actual device emulation. */
119 DeviceState *qdev_create(BusState *bus, const char *name)
123 dev = qdev_try_create(bus, name);
126 hw_error("Unknown device '%s' for bus '%s'\n", name,
129 hw_error("Unknown device '%s' for default sysbus\n", name);
136 DeviceState *qdev_try_create(BusState *bus, const char *name)
141 bus = sysbus_get_default();
144 info = qdev_find_info(bus->info, name);
149 return qdev_create_from_info(bus, info);
152 static void qdev_print_devinfo(DeviceInfo *info)
154 error_printf("name \"%s\", bus %s",
155 info->name, info->bus_info->name);
157 error_printf(", alias \"%s\"", info->alias);
160 error_printf(", desc \"%s\"", info->desc);
163 error_printf(", no-user");
168 static int set_property(const char *name, const char *value, void *opaque)
170 DeviceState *dev = opaque;
172 if (strcmp(name, "driver") == 0)
174 if (strcmp(name, "bus") == 0)
177 if (qdev_prop_parse(dev, name, value) == -1) {
183 int qdev_device_help(QemuOpts *opts)
189 driver = qemu_opt_get(opts, "driver");
190 if (driver && !strcmp(driver, "?")) {
191 for (info = device_info_list; info != NULL; info = info->next) {
193 continue; /* not available, don't show */
195 qdev_print_devinfo(info);
200 if (!driver || !qemu_opt_get(opts, "?")) {
204 info = qdev_find_info(NULL, driver);
209 for (prop = info->props; prop && prop->name; prop++) {
211 * TODO Properties without a parser are just for dirty hacks.
212 * qdev_prop_ptr is the only such PropertyInfo. It's marked
213 * for removal. This conditional should be removed along with
216 if (!prop->info->parse) {
217 continue; /* no way to set it, don't show */
219 error_printf("%s.%s=%s\n", info->name, prop->name, prop->info->name);
221 for (prop = info->bus_info->props; prop && prop->name; prop++) {
222 if (!prop->info->parse) {
223 continue; /* no way to set it, don't show */
225 error_printf("%s.%s=%s\n", info->name, prop->name, prop->info->name);
230 DeviceState *qdev_device_add(QemuOpts *opts)
232 const char *driver, *path, *id;
237 driver = qemu_opt_get(opts, "driver");
239 qerror_report(QERR_MISSING_PARAMETER, "driver");
244 info = qdev_find_info(NULL, driver);
245 if (!info || info->no_user) {
246 qerror_report(QERR_INVALID_PARAMETER_VALUE, "driver", "a driver name");
247 error_printf_unless_qmp("Try with argument '?' for a list.\n");
252 path = qemu_opt_get(opts, "bus");
254 bus = qbus_find(path);
258 if (bus->info != info->bus_info) {
259 qerror_report(QERR_BAD_BUS_FOR_DEVICE,
260 driver, bus->info->name);
264 bus = qbus_find_recursive(main_system_bus, NULL, info->bus_info);
266 qerror_report(QERR_NO_BUS_FOR_DEVICE,
267 info->name, info->bus_info->name);
271 if (qdev_hotplug && !bus->allow_hotplug) {
272 qerror_report(QERR_BUS_NO_HOTPLUG, bus->name);
276 /* create device, set properties */
277 qdev = qdev_create_from_info(bus, info);
278 id = qemu_opts_id(opts);
282 if (qemu_opt_foreach(opts, set_property, qdev, 1) != 0) {
286 if (qdev_init(qdev) < 0) {
287 qerror_report(QERR_DEVICE_INIT_FAILED, driver);
294 /* Initialize a device. Device properties should be set before calling
295 this function. IRQs and MMIO regions should be connected/mapped after
296 calling this function.
297 On failure, destroy the device and return negative value.
298 Return 0 on success. */
299 int qdev_init(DeviceState *dev)
303 assert(dev->state == DEV_STATE_CREATED);
304 rc = dev->info->init(dev, dev->info);
309 if (dev->info->vmsd) {
310 vmstate_register_with_alias_id(dev, -1, dev->info->vmsd, dev,
311 dev->instance_id_alias,
312 dev->alias_required_for_version);
314 dev->state = DEV_STATE_INITIALIZED;
315 if (dev->hotplugged && dev->info->reset) {
316 dev->info->reset(dev);
321 void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
322 int required_for_version)
324 assert(dev->state == DEV_STATE_CREATED);
325 dev->instance_id_alias = alias_id;
326 dev->alias_required_for_version = required_for_version;
329 int qdev_unplug(DeviceState *dev)
331 if (!dev->parent_bus->allow_hotplug) {
332 qerror_report(QERR_BUS_NO_HOTPLUG, dev->parent_bus->name);
335 assert(dev->info->unplug != NULL);
338 qerror_report(QERR_DEVICE_IN_USE, dev->id?:"");
342 qdev_hot_removed = true;
344 return dev->info->unplug(dev);
347 static int qdev_reset_one(DeviceState *dev, void *opaque)
349 if (dev->info->reset) {
350 dev->info->reset(dev);
356 BusState *sysbus_get_default(void)
358 if (!main_system_bus) {
359 main_system_bus_create();
361 return main_system_bus;
364 static int qbus_reset_one(BusState *bus, void *opaque)
366 if (bus->info->reset) {
367 return bus->info->reset(bus);
372 void qdev_reset_all(DeviceState *dev)
374 qdev_walk_children(dev, qdev_reset_one, qbus_reset_one, NULL);
377 void qbus_reset_all_fn(void *opaque)
379 BusState *bus = opaque;
380 qbus_walk_children(bus, qdev_reset_one, qbus_reset_one, NULL);
383 /* can be used as ->unplug() callback for the simple cases */
384 int qdev_simple_unplug_cb(DeviceState *dev)
392 /* Like qdev_init(), but terminate program via error_report() instead of
393 returning an error value. This is okay during machine creation.
394 Don't use for hotplug, because there callers need to recover from
395 failure. Exception: if you know the device's init() callback can't
396 fail, then qdev_init_nofail() can't fail either, and is therefore
397 usable even then. But relying on the device implementation that
398 way is somewhat unclean, and best avoided. */
399 void qdev_init_nofail(DeviceState *dev)
401 DeviceInfo *info = dev->info;
403 if (qdev_init(dev) < 0) {
404 error_report("Initialization of device %s failed", info->name);
409 static void qdev_property_del_all(DeviceState *dev)
411 while (!QTAILQ_EMPTY(&dev->properties)) {
412 DeviceProperty *prop = QTAILQ_FIRST(&dev->properties);
414 QTAILQ_REMOVE(&dev->properties, prop, node);
417 prop->release(dev, prop->name, prop->opaque);
426 /* Unlink device from bus and free the structure. */
427 void qdev_free(DeviceState *dev)
432 qdev_property_del_all(dev);
434 if (dev->state == DEV_STATE_INITIALIZED) {
435 while (dev->num_child_bus) {
436 bus = QLIST_FIRST(&dev->child_bus);
440 vmstate_unregister(dev, dev->info->vmsd, dev);
442 dev->info->exit(dev);
444 qemu_opts_del(dev->opts);
446 QTAILQ_REMOVE(&dev->parent_bus->children, dev, sibling);
447 for (prop = dev->info->props; prop && prop->name; prop++) {
448 if (prop->info->free) {
449 prop->info->free(dev, prop);
455 void qdev_machine_creation_done(void)
458 * ok, initial machine setup is done, starting from now we can
459 * only create hotpluggable devices
464 bool qdev_machine_modified(void)
466 return qdev_hot_added || qdev_hot_removed;
469 /* Get a character (serial) device interface. */
470 CharDriverState *qdev_init_chardev(DeviceState *dev)
472 static int next_serial;
474 /* FIXME: This function needs to go away: use chardev properties! */
475 return serial_hds[next_serial++];
478 BusState *qdev_get_parent_bus(DeviceState *dev)
480 return dev->parent_bus;
483 void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n)
485 assert(dev->num_gpio_in == 0);
486 dev->num_gpio_in = n;
487 dev->gpio_in = qemu_allocate_irqs(handler, dev, n);
490 void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n)
492 assert(dev->num_gpio_out == 0);
493 dev->num_gpio_out = n;
494 dev->gpio_out = pins;
497 qemu_irq qdev_get_gpio_in(DeviceState *dev, int n)
499 assert(n >= 0 && n < dev->num_gpio_in);
500 return dev->gpio_in[n];
503 void qdev_connect_gpio_out(DeviceState * dev, int n, qemu_irq pin)
505 assert(n >= 0 && n < dev->num_gpio_out);
506 dev->gpio_out[n] = pin;
509 void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd)
511 qdev_prop_set_macaddr(dev, "mac", nd->macaddr.a);
513 qdev_prop_set_vlan(dev, "vlan", nd->vlan);
515 qdev_prop_set_netdev(dev, "netdev", nd->netdev);
516 if (nd->nvectors != DEV_NVECTORS_UNSPECIFIED &&
517 qdev_prop_exists(dev, "vectors")) {
518 qdev_prop_set_uint32(dev, "vectors", nd->nvectors);
520 nd->instantiated = 1;
523 BusState *qdev_get_child_bus(DeviceState *dev, const char *name)
527 QLIST_FOREACH(bus, &dev->child_bus, sibling) {
528 if (strcmp(name, bus->name) == 0) {
535 int qbus_walk_children(BusState *bus, qdev_walkerfn *devfn,
536 qbus_walkerfn *busfn, void *opaque)
542 err = busfn(bus, opaque);
548 QTAILQ_FOREACH(dev, &bus->children, sibling) {
549 err = qdev_walk_children(dev, devfn, busfn, opaque);
558 int qdev_walk_children(DeviceState *dev, qdev_walkerfn *devfn,
559 qbus_walkerfn *busfn, void *opaque)
565 err = devfn(dev, opaque);
571 QLIST_FOREACH(bus, &dev->child_bus, sibling) {
572 err = qbus_walk_children(bus, devfn, busfn, opaque);
581 static BusState *qbus_find_recursive(BusState *bus, const char *name,
585 BusState *child, *ret;
588 if (name && (strcmp(bus->name, name) != 0)) {
591 if (info && (bus->info != info)) {
598 QTAILQ_FOREACH(dev, &bus->children, sibling) {
599 QLIST_FOREACH(child, &dev->child_bus, sibling) {
600 ret = qbus_find_recursive(child, name, info);
609 DeviceState *qdev_find_recursive(BusState *bus, const char *id)
611 DeviceState *dev, *ret;
614 QTAILQ_FOREACH(dev, &bus->children, sibling) {
615 if (dev->id && strcmp(dev->id, id) == 0)
617 QLIST_FOREACH(child, &dev->child_bus, sibling) {
618 ret = qdev_find_recursive(child, id);
627 static void qbus_list_bus(DeviceState *dev)
630 const char *sep = " ";
632 error_printf("child busses at \"%s\":",
633 dev->id ? dev->id : dev->info->name);
634 QLIST_FOREACH(child, &dev->child_bus, sibling) {
635 error_printf("%s\"%s\"", sep, child->name);
641 static void qbus_list_dev(BusState *bus)
644 const char *sep = " ";
646 error_printf("devices at \"%s\":", bus->name);
647 QTAILQ_FOREACH(dev, &bus->children, sibling) {
648 error_printf("%s\"%s\"", sep, dev->info->name);
650 error_printf("/\"%s\"", dev->id);
656 static BusState *qbus_find_bus(DeviceState *dev, char *elem)
660 QLIST_FOREACH(child, &dev->child_bus, sibling) {
661 if (strcmp(child->name, elem) == 0) {
668 static DeviceState *qbus_find_dev(BusState *bus, char *elem)
673 * try to match in order:
674 * (1) instance id, if present
676 * (3) driver alias, if present
678 QTAILQ_FOREACH(dev, &bus->children, sibling) {
679 if (dev->id && strcmp(dev->id, elem) == 0) {
683 QTAILQ_FOREACH(dev, &bus->children, sibling) {
684 if (strcmp(dev->info->name, elem) == 0) {
688 QTAILQ_FOREACH(dev, &bus->children, sibling) {
689 if (dev->info->alias && strcmp(dev->info->alias, elem) == 0) {
696 static BusState *qbus_find(const char *path)
703 /* find start element */
704 if (path[0] == '/') {
705 bus = main_system_bus;
708 if (sscanf(path, "%127[^/]%n", elem, &len) != 1) {
712 bus = qbus_find_recursive(main_system_bus, elem, NULL);
714 qerror_report(QERR_BUS_NOT_FOUND, elem);
721 assert(path[pos] == '/' || !path[pos]);
722 while (path[pos] == '/') {
725 if (path[pos] == '\0') {
730 if (sscanf(path+pos, "%127[^/]%n", elem, &len) != 1) {
735 dev = qbus_find_dev(bus, elem);
737 qerror_report(QERR_DEVICE_NOT_FOUND, elem);
738 if (!monitor_cur_is_qmp()) {
744 assert(path[pos] == '/' || !path[pos]);
745 while (path[pos] == '/') {
748 if (path[pos] == '\0') {
749 /* last specified element is a device. If it has exactly
750 * one child bus accept it nevertheless */
751 switch (dev->num_child_bus) {
753 qerror_report(QERR_DEVICE_NO_BUS, elem);
756 return QLIST_FIRST(&dev->child_bus);
758 qerror_report(QERR_DEVICE_MULTIPLE_BUSSES, elem);
759 if (!monitor_cur_is_qmp()) {
767 if (sscanf(path+pos, "%127[^/]%n", elem, &len) != 1) {
772 bus = qbus_find_bus(dev, elem);
774 qerror_report(QERR_BUS_NOT_FOUND, elem);
775 if (!monitor_cur_is_qmp()) {
783 void qbus_create_inplace(BusState *bus, BusInfo *info,
784 DeviceState *parent, const char *name)
790 bus->parent = parent;
793 /* use supplied name */
794 bus->name = g_strdup(name);
795 } else if (parent && parent->id) {
796 /* parent device has id -> use it for bus name */
797 len = strlen(parent->id) + 16;
799 snprintf(buf, len, "%s.%d", parent->id, parent->num_child_bus);
802 /* no id -> use lowercase bus type for bus name */
803 len = strlen(info->name) + 16;
805 len = snprintf(buf, len, "%s.%d", info->name,
806 parent ? parent->num_child_bus : 0);
807 for (i = 0; i < len; i++)
808 buf[i] = qemu_tolower(buf[i]);
812 QTAILQ_INIT(&bus->children);
814 QLIST_INSERT_HEAD(&parent->child_bus, bus, sibling);
815 parent->num_child_bus++;
816 } else if (bus != main_system_bus) {
817 /* TODO: once all bus devices are qdevified,
818 only reset handler for main_system_bus should be registered here. */
819 qemu_register_reset(qbus_reset_all_fn, bus);
823 BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name)
827 bus = g_malloc0(info->size);
828 bus->qdev_allocated = 1;
829 qbus_create_inplace(bus, info, parent, name);
833 static void main_system_bus_create(void)
835 /* assign main_system_bus before qbus_create_inplace()
836 * in order to make "if (bus != main_system_bus)" work */
837 main_system_bus = g_malloc0(system_bus_info.size);
838 main_system_bus->qdev_allocated = 1;
839 qbus_create_inplace(main_system_bus, &system_bus_info, NULL,
843 void qbus_free(BusState *bus)
847 while ((dev = QTAILQ_FIRST(&bus->children)) != NULL) {
851 QLIST_REMOVE(bus, sibling);
852 bus->parent->num_child_bus--;
854 assert(bus != main_system_bus); /* main_system_bus is never freed */
855 qemu_unregister_reset(qbus_reset_all_fn, bus);
857 g_free((void*)bus->name);
858 if (bus->qdev_allocated) {
863 #define qdev_printf(fmt, ...) monitor_printf(mon, "%*s" fmt, indent, "", ## __VA_ARGS__)
864 static void qbus_print(Monitor *mon, BusState *bus, int indent);
866 static void qdev_print_props(Monitor *mon, DeviceState *dev, Property *props,
867 const char *prefix, int indent)
873 while (props->name) {
875 * TODO Properties without a print method are just for dirty
876 * hacks. qdev_prop_ptr is the only such PropertyInfo. It's
877 * marked for removal. The test props->info->print should be
878 * removed along with it.
880 if (props->info->print) {
881 props->info->print(dev, props, buf, sizeof(buf));
882 qdev_printf("%s-prop: %s = %s\n", prefix, props->name, buf);
888 static void qdev_print(Monitor *mon, DeviceState *dev, int indent)
891 qdev_printf("dev: %s, id \"%s\"\n", dev->info->name,
892 dev->id ? dev->id : "");
894 if (dev->num_gpio_in) {
895 qdev_printf("gpio-in %d\n", dev->num_gpio_in);
897 if (dev->num_gpio_out) {
898 qdev_printf("gpio-out %d\n", dev->num_gpio_out);
900 qdev_print_props(mon, dev, dev->info->props, "dev", indent);
901 qdev_print_props(mon, dev, dev->parent_bus->info->props, "bus", indent);
902 if (dev->parent_bus->info->print_dev)
903 dev->parent_bus->info->print_dev(mon, dev, indent);
904 QLIST_FOREACH(child, &dev->child_bus, sibling) {
905 qbus_print(mon, child, indent);
909 static void qbus_print(Monitor *mon, BusState *bus, int indent)
911 struct DeviceState *dev;
913 qdev_printf("bus: %s\n", bus->name);
915 qdev_printf("type %s\n", bus->info->name);
916 QTAILQ_FOREACH(dev, &bus->children, sibling) {
917 qdev_print(mon, dev, indent);
922 void do_info_qtree(Monitor *mon)
925 qbus_print(mon, main_system_bus, 0);
928 void do_info_qdm(Monitor *mon)
932 for (info = device_info_list; info != NULL; info = info->next) {
933 qdev_print_devinfo(info);
937 int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data)
941 opts = qemu_opts_from_qdict(qemu_find_opts("device"), qdict);
945 if (!monitor_cur_is_qmp() && qdev_device_help(opts)) {
949 if (!qdev_device_add(opts)) {
956 int do_device_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
958 const char *id = qdict_get_str(qdict, "id");
961 dev = qdev_find_recursive(main_system_bus, id);
963 qerror_report(QERR_DEVICE_NOT_FOUND, id);
966 return qdev_unplug(dev);
969 static int qdev_get_fw_dev_path_helper(DeviceState *dev, char *p, int size)
973 if (dev && dev->parent_bus) {
975 l = qdev_get_fw_dev_path_helper(dev->parent_bus->parent, p, size);
976 if (dev->parent_bus->info->get_fw_dev_path) {
977 d = dev->parent_bus->info->get_fw_dev_path(dev);
978 l += snprintf(p + l, size - l, "%s", d);
981 l += snprintf(p + l, size - l, "%s", dev->info->name);
984 l += snprintf(p + l , size - l, "/");
989 char* qdev_get_fw_dev_path(DeviceState *dev)
994 l = qdev_get_fw_dev_path_helper(dev, path, 128);
1001 void qdev_ref(DeviceState *dev)
1006 void qdev_unref(DeviceState *dev)
1008 g_assert(dev->ref > 0);
1012 void qdev_property_add(DeviceState *dev, const char *name, const char *type,
1013 DevicePropertyAccessor *get, DevicePropertyAccessor *set,
1014 DevicePropertyRelease *release,
1015 void *opaque, Error **errp)
1017 DeviceProperty *prop = g_malloc0(sizeof(*prop));
1019 prop->name = g_strdup(name);
1020 prop->type = g_strdup(type);
1024 prop->release = release;
1025 prop->opaque = opaque;
1027 QTAILQ_INSERT_TAIL(&dev->properties, prop, node);
1030 static DeviceProperty *qdev_property_find(DeviceState *dev, const char *name)
1032 DeviceProperty *prop;
1034 QTAILQ_FOREACH(prop, &dev->properties, node) {
1035 if (strcmp(prop->name, name) == 0) {
1043 void qdev_property_get(DeviceState *dev, Visitor *v, const char *name,
1046 DeviceProperty *prop = qdev_property_find(dev, name);
1049 error_set(errp, QERR_PROPERTY_NOT_FOUND, dev->id?:"", name);
1054 error_set(errp, QERR_PERMISSION_DENIED);
1056 prop->get(dev, v, prop->opaque, name, errp);
1060 void qdev_property_set(DeviceState *dev, Visitor *v, const char *name,
1063 DeviceProperty *prop = qdev_property_find(dev, name);
1066 error_set(errp, QERR_PROPERTY_NOT_FOUND, dev->id?:"", name);
1071 error_set(errp, QERR_PERMISSION_DENIED);
1073 prop->set(dev, prop->opaque, v, name, errp);
1077 const char *qdev_property_get_type(DeviceState *dev, const char *name, Error **errp)
1079 DeviceProperty *prop = qdev_property_find(dev, name);
1082 error_set(errp, QERR_PROPERTY_NOT_FOUND, dev->id?:"", name);
1090 * Legacy property handling
1093 static void qdev_get_legacy_property(DeviceState *dev, Visitor *v, void *opaque,
1094 const char *name, Error **errp)
1096 Property *prop = opaque;
1098 if (prop->info->print) {
1102 prop->info->print(dev, prop, buffer, sizeof(buffer));
1103 visit_type_str(v, &ptr, name, errp);
1105 error_set(errp, QERR_PERMISSION_DENIED);
1109 static void qdev_set_legacy_property(DeviceState *dev, Visitor *v, void *opaque,
1110 const char *name, Error **errp)
1112 Property *prop = opaque;
1114 if (dev->state != DEV_STATE_CREATED) {
1115 error_set(errp, QERR_PERMISSION_DENIED);
1119 if (prop->info->parse) {
1120 Error *local_err = NULL;
1123 visit_type_str(v, &ptr, name, &local_err);
1126 ret = prop->info->parse(dev, prop, ptr);
1128 error_set(errp, QERR_INVALID_PARAMETER_VALUE,
1129 name, prop->info->name);
1133 error_propagate(errp, local_err);
1136 error_set(errp, QERR_PERMISSION_DENIED);
1141 * @qdev_add_legacy_property - adds a legacy property
1143 * Do not use this is new code! Properties added through this interface will
1144 * be given types in the "legacy<>" type namespace.
1146 * Legacy properties are always processed as strings. The format of the string
1147 * depends on the property type.
1149 void qdev_property_add_legacy(DeviceState *dev, Property *prop,
1154 type = g_strdup_printf("legacy<%s>", prop->info->name);
1156 qdev_property_add(dev, prop->name, type,
1157 qdev_get_legacy_property,
1158 qdev_set_legacy_property,