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
29 #include "hw/fw-path-provider.h"
30 #include "sysemu/sysemu.h"
31 #include "qapi/error.h"
32 #include "qapi/qmp/qerror.h"
33 #include "qapi/visitor.h"
34 #include "qapi/qmp/qjson.h"
35 #include "monitor/monitor.h"
36 #include "hw/hotplug.h"
39 static bool qdev_hot_added
= false;
40 static bool qdev_hot_removed
= false;
42 const VMStateDescription
*qdev_get_vmsd(DeviceState
*dev
)
44 DeviceClass
*dc
= DEVICE_GET_CLASS(dev
);
48 const char *qdev_fw_name(DeviceState
*dev
)
50 DeviceClass
*dc
= DEVICE_GET_CLASS(dev
);
56 return object_get_typename(OBJECT(dev
));
59 static void qdev_property_add_legacy(DeviceState
*dev
, Property
*prop
,
62 static void bus_remove_child(BusState
*bus
, DeviceState
*child
)
66 QTAILQ_FOREACH(kid
, &bus
->children
, sibling
) {
67 if (kid
->child
== child
) {
70 snprintf(name
, sizeof(name
), "child[%d]", kid
->index
);
71 QTAILQ_REMOVE(&bus
->children
, kid
, sibling
);
73 /* This gives back ownership of kid->child back to us. */
74 object_property_del(OBJECT(bus
), name
, NULL
);
75 object_unref(OBJECT(kid
->child
));
82 static void bus_add_child(BusState
*bus
, DeviceState
*child
)
85 BusChild
*kid
= g_malloc0(sizeof(*kid
));
88 assert(bus
->allow_hotplug
);
91 kid
->index
= bus
->max_index
++;
93 object_ref(OBJECT(kid
->child
));
95 QTAILQ_INSERT_HEAD(&bus
->children
, kid
, sibling
);
97 /* This transfers ownership of kid->child to the property. */
98 snprintf(name
, sizeof(name
), "child[%d]", kid
->index
);
99 object_property_add_link(OBJECT(bus
), name
,
100 object_get_typename(OBJECT(child
)),
101 (Object
**)&kid
->child
,
105 void qdev_set_parent_bus(DeviceState
*dev
, BusState
*bus
)
107 dev
->parent_bus
= bus
;
108 object_ref(OBJECT(bus
));
109 bus_add_child(bus
, dev
);
112 /* Create a new device. This only initializes the device state structure
113 and allows properties to be set. qdev_init should be called to
114 initialize the actual device emulation. */
115 DeviceState
*qdev_create(BusState
*bus
, const char *name
)
119 dev
= qdev_try_create(bus
, name
);
122 error_report("Unknown device '%s' for bus '%s'", name
,
123 object_get_typename(OBJECT(bus
)));
125 error_report("Unknown device '%s' for default sysbus", name
);
133 DeviceState
*qdev_try_create(BusState
*bus
, const char *type
)
137 if (object_class_by_name(type
) == NULL
) {
140 dev
= DEVICE(object_new(type
));
146 bus
= sysbus_get_default();
149 qdev_set_parent_bus(dev
, bus
);
150 object_unref(OBJECT(dev
));
154 /* Initialize a device. Device properties should be set before calling
155 this function. IRQs and MMIO regions should be connected/mapped after
156 calling this function.
157 On failure, destroy the device and return negative value.
158 Return 0 on success. */
159 int qdev_init(DeviceState
*dev
)
161 Error
*local_err
= NULL
;
163 assert(!dev
->realized
);
165 object_property_set_bool(OBJECT(dev
), true, "realized", &local_err
);
166 if (local_err
!= NULL
) {
167 qerror_report_err(local_err
);
168 error_free(local_err
);
169 object_unparent(OBJECT(dev
));
175 static void device_realize(DeviceState
*dev
, Error
**err
)
177 DeviceClass
*dc
= DEVICE_GET_CLASS(dev
);
180 int rc
= dc
->init(dev
);
182 error_setg(err
, "Device initialization failed.");
188 static void device_unrealize(DeviceState
*dev
, Error
**errp
)
190 DeviceClass
*dc
= DEVICE_GET_CLASS(dev
);
193 int rc
= dc
->exit(dev
);
195 error_setg(errp
, "Device exit failed.");
201 void qdev_set_legacy_instance_id(DeviceState
*dev
, int alias_id
,
202 int required_for_version
)
204 assert(!dev
->realized
);
205 dev
->instance_id_alias
= alias_id
;
206 dev
->alias_required_for_version
= required_for_version
;
209 void qdev_unplug(DeviceState
*dev
, Error
**errp
)
211 DeviceClass
*dc
= DEVICE_GET_CLASS(dev
);
213 if (dev
->parent_bus
&& !dev
->parent_bus
->allow_hotplug
) {
214 error_set(errp
, QERR_BUS_NO_HOTPLUG
, dev
->parent_bus
->name
);
218 if (!dc
->hotpluggable
) {
219 error_set(errp
, QERR_DEVICE_NO_HOTPLUG
,
220 object_get_typename(OBJECT(dev
)));
224 qdev_hot_removed
= true;
226 if (dev
->parent_bus
&& dev
->parent_bus
->hotplug_handler
) {
227 hotplug_handler_unplug(dev
->parent_bus
->hotplug_handler
, dev
, errp
);
229 assert(dc
->unplug
!= NULL
);
230 if (dc
->unplug(dev
) < 0) { /* legacy handler */
231 error_set(errp
, QERR_UNDEFINED_ERROR
);
236 static int qdev_reset_one(DeviceState
*dev
, void *opaque
)
243 static int qbus_reset_one(BusState
*bus
, void *opaque
)
245 BusClass
*bc
= BUS_GET_CLASS(bus
);
252 void qdev_reset_all(DeviceState
*dev
)
254 qdev_walk_children(dev
, NULL
, NULL
, qdev_reset_one
, qbus_reset_one
, NULL
);
257 void qbus_reset_all(BusState
*bus
)
259 qbus_walk_children(bus
, NULL
, NULL
, qdev_reset_one
, qbus_reset_one
, NULL
);
262 void qbus_reset_all_fn(void *opaque
)
264 BusState
*bus
= opaque
;
268 /* can be used as ->unplug() callback for the simple cases */
269 int qdev_simple_unplug_cb(DeviceState
*dev
)
272 object_unparent(OBJECT(dev
));
277 /* Like qdev_init(), but terminate program via error_report() instead of
278 returning an error value. This is okay during machine creation.
279 Don't use for hotplug, because there callers need to recover from
280 failure. Exception: if you know the device's init() callback can't
281 fail, then qdev_init_nofail() can't fail either, and is therefore
282 usable even then. But relying on the device implementation that
283 way is somewhat unclean, and best avoided. */
284 void qdev_init_nofail(DeviceState
*dev
)
286 const char *typename
= object_get_typename(OBJECT(dev
));
288 if (qdev_init(dev
) < 0) {
289 error_report("Initialization of device %s failed", typename
);
294 void qdev_machine_creation_done(void)
297 * ok, initial machine setup is done, starting from now we can
298 * only create hotpluggable devices
303 bool qdev_machine_modified(void)
305 return qdev_hot_added
|| qdev_hot_removed
;
308 BusState
*qdev_get_parent_bus(DeviceState
*dev
)
310 return dev
->parent_bus
;
313 void qdev_init_gpio_in(DeviceState
*dev
, qemu_irq_handler handler
, int n
)
315 dev
->gpio_in
= qemu_extend_irqs(dev
->gpio_in
, dev
->num_gpio_in
, handler
,
317 dev
->num_gpio_in
+= n
;
320 void qdev_init_gpio_out(DeviceState
*dev
, qemu_irq
*pins
, int n
)
322 assert(dev
->num_gpio_out
== 0);
323 dev
->num_gpio_out
= n
;
324 dev
->gpio_out
= pins
;
327 qemu_irq
qdev_get_gpio_in(DeviceState
*dev
, int n
)
329 assert(n
>= 0 && n
< dev
->num_gpio_in
);
330 return dev
->gpio_in
[n
];
333 void qdev_connect_gpio_out(DeviceState
* dev
, int n
, qemu_irq pin
)
335 assert(n
>= 0 && n
< dev
->num_gpio_out
);
336 dev
->gpio_out
[n
] = pin
;
339 BusState
*qdev_get_child_bus(DeviceState
*dev
, const char *name
)
343 QLIST_FOREACH(bus
, &dev
->child_bus
, sibling
) {
344 if (strcmp(name
, bus
->name
) == 0) {
351 int qbus_walk_children(BusState
*bus
,
352 qdev_walkerfn
*pre_devfn
, qbus_walkerfn
*pre_busfn
,
353 qdev_walkerfn
*post_devfn
, qbus_walkerfn
*post_busfn
,
360 err
= pre_busfn(bus
, opaque
);
366 QTAILQ_FOREACH(kid
, &bus
->children
, sibling
) {
367 err
= qdev_walk_children(kid
->child
,
368 pre_devfn
, pre_busfn
,
369 post_devfn
, post_busfn
, opaque
);
376 err
= post_busfn(bus
, opaque
);
385 int qdev_walk_children(DeviceState
*dev
,
386 qdev_walkerfn
*pre_devfn
, qbus_walkerfn
*pre_busfn
,
387 qdev_walkerfn
*post_devfn
, qbus_walkerfn
*post_busfn
,
394 err
= pre_devfn(dev
, opaque
);
400 QLIST_FOREACH(bus
, &dev
->child_bus
, sibling
) {
401 err
= qbus_walk_children(bus
, pre_devfn
, pre_busfn
,
402 post_devfn
, post_busfn
, opaque
);
409 err
= post_devfn(dev
, opaque
);
418 DeviceState
*qdev_find_recursive(BusState
*bus
, const char *id
)
424 QTAILQ_FOREACH(kid
, &bus
->children
, sibling
) {
425 DeviceState
*dev
= kid
->child
;
427 if (dev
->id
&& strcmp(dev
->id
, id
) == 0) {
431 QLIST_FOREACH(child
, &dev
->child_bus
, sibling
) {
432 ret
= qdev_find_recursive(child
, id
);
441 static void qbus_realize(BusState
*bus
, DeviceState
*parent
, const char *name
)
443 const char *typename
= object_get_typename(OBJECT(bus
));
448 bus
->parent
= parent
;
451 bus
->name
= g_strdup(name
);
452 } else if (bus
->parent
&& bus
->parent
->id
) {
453 /* parent device has id -> use it plus parent-bus-id for bus name */
454 bus_id
= bus
->parent
->num_child_bus
;
456 len
= strlen(bus
->parent
->id
) + 16;
458 snprintf(buf
, len
, "%s.%d", bus
->parent
->id
, bus_id
);
461 /* no id -> use lowercase bus type plus global bus-id for bus name */
462 bc
= BUS_GET_CLASS(bus
);
463 bus_id
= bc
->automatic_ids
++;
465 len
= strlen(typename
) + 16;
467 len
= snprintf(buf
, len
, "%s.%d", typename
, bus_id
);
468 for (i
= 0; i
< len
; i
++) {
469 buf
[i
] = qemu_tolower(buf
[i
]);
475 QLIST_INSERT_HEAD(&bus
->parent
->child_bus
, bus
, sibling
);
476 bus
->parent
->num_child_bus
++;
477 object_property_add_child(OBJECT(bus
->parent
), bus
->name
, OBJECT(bus
), NULL
);
478 object_unref(OBJECT(bus
));
479 } else if (bus
!= sysbus_get_default()) {
480 /* TODO: once all bus devices are qdevified,
481 only reset handler for main_system_bus should be registered here. */
482 qemu_register_reset(qbus_reset_all_fn
, bus
);
486 static void bus_unparent(Object
*obj
)
488 BusState
*bus
= BUS(obj
);
491 while ((kid
= QTAILQ_FIRST(&bus
->children
)) != NULL
) {
492 DeviceState
*dev
= kid
->child
;
493 object_unparent(OBJECT(dev
));
496 QLIST_REMOVE(bus
, sibling
);
497 bus
->parent
->num_child_bus
--;
500 assert(bus
!= sysbus_get_default()); /* main_system_bus is never freed */
501 qemu_unregister_reset(qbus_reset_all_fn
, bus
);
505 static bool bus_get_realized(Object
*obj
, Error
**err
)
507 BusState
*bus
= BUS(obj
);
509 return bus
->realized
;
512 static void bus_set_realized(Object
*obj
, bool value
, Error
**err
)
514 BusState
*bus
= BUS(obj
);
515 BusClass
*bc
= BUS_GET_CLASS(bus
);
516 Error
*local_err
= NULL
;
518 if (value
&& !bus
->realized
) {
520 bc
->realize(bus
, &local_err
);
522 if (local_err
!= NULL
) {
527 } else if (!value
&& bus
->realized
) {
529 bc
->unrealize(bus
, &local_err
);
531 if (local_err
!= NULL
) {
537 bus
->realized
= value
;
541 error_propagate(err
, local_err
);
544 void qbus_create_inplace(void *bus
, size_t size
, const char *typename
,
545 DeviceState
*parent
, const char *name
)
547 object_initialize(bus
, size
, typename
);
548 qbus_realize(bus
, parent
, name
);
551 BusState
*qbus_create(const char *typename
, DeviceState
*parent
, const char *name
)
555 bus
= BUS(object_new(typename
));
556 qbus_realize(bus
, parent
, name
);
561 static char *bus_get_fw_dev_path(BusState
*bus
, DeviceState
*dev
)
563 BusClass
*bc
= BUS_GET_CLASS(bus
);
565 if (bc
->get_fw_dev_path
) {
566 return bc
->get_fw_dev_path(dev
);
572 static char *qdev_get_fw_dev_path_from_handler(BusState
*bus
, DeviceState
*dev
)
574 Object
*obj
= OBJECT(dev
);
577 while (!d
&& obj
->parent
) {
579 d
= fw_path_provider_try_get_dev_path(obj
, bus
, dev
);
584 static int qdev_get_fw_dev_path_helper(DeviceState
*dev
, char *p
, int size
)
588 if (dev
&& dev
->parent_bus
) {
590 l
= qdev_get_fw_dev_path_helper(dev
->parent_bus
->parent
, p
, size
);
591 d
= qdev_get_fw_dev_path_from_handler(dev
->parent_bus
, dev
);
593 d
= bus_get_fw_dev_path(dev
->parent_bus
, dev
);
596 l
+= snprintf(p
+ l
, size
- l
, "%s", d
);
602 l
+= snprintf(p
+ l
, size
- l
, "/");
607 char* qdev_get_fw_dev_path(DeviceState
*dev
)
612 l
= qdev_get_fw_dev_path_helper(dev
, path
, 128);
616 return g_strdup(path
);
619 char *qdev_get_dev_path(DeviceState
*dev
)
623 if (!dev
|| !dev
->parent_bus
) {
627 bc
= BUS_GET_CLASS(dev
->parent_bus
);
628 if (bc
->get_dev_path
) {
629 return bc
->get_dev_path(dev
);
636 * Legacy property handling
639 static void qdev_get_legacy_property(Object
*obj
, Visitor
*v
, void *opaque
,
640 const char *name
, Error
**errp
)
642 DeviceState
*dev
= DEVICE(obj
);
643 Property
*prop
= opaque
;
648 prop
->info
->print(dev
, prop
, buffer
, sizeof(buffer
));
649 visit_type_str(v
, &ptr
, name
, errp
);
653 * @qdev_add_legacy_property - adds a legacy property
655 * Do not use this is new code! Properties added through this interface will
656 * be given names and types in the "legacy" namespace.
658 * Legacy properties are string versions of other OOM properties. The format
659 * of the string depends on the property type.
661 void qdev_property_add_legacy(DeviceState
*dev
, Property
*prop
,
666 /* Register pointer properties as legacy properties */
667 if (!prop
->info
->print
&& prop
->info
->get
) {
671 name
= g_strdup_printf("legacy-%s", prop
->name
);
672 object_property_add(OBJECT(dev
), name
, "str",
673 prop
->info
->print
? qdev_get_legacy_property
: prop
->info
->get
,
682 * @qdev_property_add_static - add a @Property to a device.
684 * Static properties access data in a struct. The actual type of the
685 * property and the field depends on the property type.
687 void qdev_property_add_static(DeviceState
*dev
, Property
*prop
,
690 Error
*local_err
= NULL
;
691 Object
*obj
= OBJECT(dev
);
694 * TODO qdev_prop_ptr does not have getters or setters. It must
695 * go now that it can be replaced with links. The test should be
696 * removed along with it: all static properties are read/write.
698 if (!prop
->info
->get
&& !prop
->info
->set
) {
702 object_property_add(obj
, prop
->name
, prop
->info
->name
,
703 prop
->info
->get
, prop
->info
->set
,
708 error_propagate(errp
, local_err
);
711 if (prop
->qtype
== QTYPE_NONE
) {
715 if (prop
->qtype
== QTYPE_QBOOL
) {
716 object_property_set_bool(obj
, prop
->defval
, prop
->name
, &error_abort
);
717 } else if (prop
->info
->enum_table
) {
718 object_property_set_str(obj
, prop
->info
->enum_table
[prop
->defval
],
719 prop
->name
, &error_abort
);
720 } else if (prop
->qtype
== QTYPE_QINT
) {
721 object_property_set_int(obj
, prop
->defval
, prop
->name
, &error_abort
);
725 static bool device_get_realized(Object
*obj
, Error
**err
)
727 DeviceState
*dev
= DEVICE(obj
);
728 return dev
->realized
;
731 static void device_set_realized(Object
*obj
, bool value
, Error
**err
)
733 DeviceState
*dev
= DEVICE(obj
);
734 DeviceClass
*dc
= DEVICE_GET_CLASS(dev
);
736 Error
*local_err
= NULL
;
738 if (dev
->hotplugged
&& !dc
->hotpluggable
) {
739 error_set(err
, QERR_DEVICE_NO_HOTPLUG
, object_get_typename(obj
));
743 if (value
&& !dev
->realized
) {
744 if (!obj
->parent
&& local_err
== NULL
) {
745 static int unattached_count
;
746 gchar
*name
= g_strdup_printf("device[%d]", unattached_count
++);
748 object_property_add_child(container_get(qdev_get_machine(),
750 name
, obj
, &local_err
);
755 dc
->realize(dev
, &local_err
);
758 if (dev
->parent_bus
&& dev
->parent_bus
->hotplug_handler
&&
760 hotplug_handler_plug(dev
->parent_bus
->hotplug_handler
,
764 if (qdev_get_vmsd(dev
) && local_err
== NULL
) {
765 vmstate_register_with_alias_id(dev
, -1, qdev_get_vmsd(dev
), dev
,
766 dev
->instance_id_alias
,
767 dev
->alias_required_for_version
);
769 if (local_err
== NULL
) {
770 QLIST_FOREACH(bus
, &dev
->child_bus
, sibling
) {
771 object_property_set_bool(OBJECT(bus
), true, "realized",
773 if (local_err
!= NULL
) {
778 if (dev
->hotplugged
&& local_err
== NULL
) {
781 } else if (!value
&& dev
->realized
) {
782 QLIST_FOREACH(bus
, &dev
->child_bus
, sibling
) {
783 object_property_set_bool(OBJECT(bus
), false, "realized",
785 if (local_err
!= NULL
) {
789 if (qdev_get_vmsd(dev
) && local_err
== NULL
) {
790 vmstate_unregister(dev
, qdev_get_vmsd(dev
), dev
);
792 if (dc
->unrealize
&& local_err
== NULL
) {
793 dc
->unrealize(dev
, &local_err
);
797 if (local_err
!= NULL
) {
798 error_propagate(err
, local_err
);
802 dev
->realized
= value
;
805 static bool device_get_hotpluggable(Object
*obj
, Error
**err
)
807 DeviceClass
*dc
= DEVICE_GET_CLASS(obj
);
808 DeviceState
*dev
= DEVICE(obj
);
810 return dc
->hotpluggable
&& (dev
->parent_bus
== NULL
||
811 dev
->parent_bus
->allow_hotplug
);
814 static void device_initfn(Object
*obj
)
816 DeviceState
*dev
= DEVICE(obj
);
822 qdev_hot_added
= true;
825 dev
->instance_id_alias
= -1;
826 dev
->realized
= false;
828 object_property_add_bool(obj
, "realized",
829 device_get_realized
, device_set_realized
, NULL
);
830 object_property_add_bool(obj
, "hotpluggable",
831 device_get_hotpluggable
, NULL
, NULL
);
833 class = object_get_class(OBJECT(dev
));
835 for (prop
= DEVICE_CLASS(class)->props
; prop
&& prop
->name
; prop
++) {
836 qdev_property_add_legacy(dev
, prop
, &error_abort
);
837 qdev_property_add_static(dev
, prop
, &error_abort
);
839 class = object_class_get_parent(class);
840 } while (class != object_class_by_name(TYPE_DEVICE
));
842 object_property_add_link(OBJECT(dev
), "parent_bus", TYPE_BUS
,
843 (Object
**)&dev
->parent_bus
, &error_abort
);
846 static void device_post_init(Object
*obj
)
848 qdev_prop_set_globals(DEVICE(obj
), &error_abort
);
851 /* Unlink device from bus and free the structure. */
852 static void device_finalize(Object
*obj
)
854 DeviceState
*dev
= DEVICE(obj
);
856 qemu_opts_del(dev
->opts
);
860 static void device_class_base_init(ObjectClass
*class, void *data
)
862 DeviceClass
*klass
= DEVICE_CLASS(class);
864 /* We explicitly look up properties in the superclasses,
865 * so do not propagate them to the subclasses.
870 static void device_unparent(Object
*obj
)
872 DeviceState
*dev
= DEVICE(obj
);
875 bool have_realized
= dev
->realized
;
878 object_property_set_bool(obj
, false, "realized", NULL
);
880 while (dev
->num_child_bus
) {
881 bus
= QLIST_FIRST(&dev
->child_bus
);
882 object_unparent(OBJECT(bus
));
884 if (dev
->parent_bus
) {
885 bus_remove_child(dev
->parent_bus
, dev
);
886 object_unref(OBJECT(dev
->parent_bus
));
887 dev
->parent_bus
= NULL
;
890 /* Only send event if the device had been completely realized */
892 gchar
*path
= object_get_canonical_path(OBJECT(dev
));
895 event_data
= qobject_from_jsonf("{ 'device': %s, 'path': %s }",
898 event_data
= qobject_from_jsonf("{ 'path': %s }", path
);
900 monitor_protocol_event(QEVENT_DEVICE_DELETED
, event_data
);
901 qobject_decref(event_data
);
906 static void device_class_init(ObjectClass
*class, void *data
)
908 DeviceClass
*dc
= DEVICE_CLASS(class);
910 class->unparent
= device_unparent
;
911 dc
->realize
= device_realize
;
912 dc
->unrealize
= device_unrealize
;
914 /* by default all devices were considered as hotpluggable,
915 * so with intent to check it in generic qdev_unplug() /
916 * device_set_realized() functions make every device
917 * hotpluggable. Devices that shouldn't be hotpluggable,
918 * should override it in their class_init()
920 dc
->hotpluggable
= true;
923 void device_reset(DeviceState
*dev
)
925 DeviceClass
*klass
= DEVICE_GET_CLASS(dev
);
932 Object
*qdev_get_machine(void)
937 dev
= container_get(object_get_root(), "/machine");
943 static const TypeInfo device_type_info
= {
945 .parent
= TYPE_OBJECT
,
946 .instance_size
= sizeof(DeviceState
),
947 .instance_init
= device_initfn
,
948 .instance_post_init
= device_post_init
,
949 .instance_finalize
= device_finalize
,
950 .class_base_init
= device_class_base_init
,
951 .class_init
= device_class_init
,
953 .class_size
= sizeof(DeviceClass
),
956 static void qbus_initfn(Object
*obj
)
958 BusState
*bus
= BUS(obj
);
960 QTAILQ_INIT(&bus
->children
);
961 object_property_add_link(obj
, QDEV_HOTPLUG_HANDLER_PROPERTY
,
962 TYPE_HOTPLUG_HANDLER
,
963 (Object
**)&bus
->hotplug_handler
, NULL
);
964 object_property_add_bool(obj
, "realized",
965 bus_get_realized
, bus_set_realized
, NULL
);
968 static char *default_bus_get_fw_dev_path(DeviceState
*dev
)
970 return g_strdup(object_get_typename(OBJECT(dev
)));
973 static void bus_class_init(ObjectClass
*class, void *data
)
975 BusClass
*bc
= BUS_CLASS(class);
977 class->unparent
= bus_unparent
;
978 bc
->get_fw_dev_path
= default_bus_get_fw_dev_path
;
981 static void qbus_finalize(Object
*obj
)
983 BusState
*bus
= BUS(obj
);
985 g_free((char *)bus
->name
);
988 static const TypeInfo bus_info
= {
990 .parent
= TYPE_OBJECT
,
991 .instance_size
= sizeof(BusState
),
993 .class_size
= sizeof(BusClass
),
994 .instance_init
= qbus_initfn
,
995 .instance_finalize
= qbus_finalize
,
996 .class_init
= bus_class_init
,
999 static void qdev_register_types(void)
1001 type_register_static(&bus_info
);
1002 type_register_static(&device_type_info
);
1005 type_init(qdev_register_types
)