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.1 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
28 #include "qemu/osdep.h"
29 #include "qapi/error.h"
30 #include "qapi/qapi-events-qdev.h"
31 #include "qapi/qmp/qdict.h"
32 #include "qapi/qmp/qerror.h"
33 #include "qapi/visitor.h"
34 #include "qemu/error-report.h"
35 #include "qemu/option.h"
37 #include "hw/qdev-properties.h"
38 #include "hw/boards.h"
39 #include "hw/sysbus.h"
40 #include "hw/qdev-clock.h"
41 #include "migration/vmstate.h"
44 static bool qdev_hot_added
= false;
45 bool qdev_hot_removed
= false;
47 const VMStateDescription
*qdev_get_vmsd(DeviceState
*dev
)
49 DeviceClass
*dc
= DEVICE_GET_CLASS(dev
);
53 static void bus_free_bus_child(BusChild
*kid
)
55 object_unref(OBJECT(kid
->child
));
59 static void bus_remove_child(BusState
*bus
, DeviceState
*child
)
63 QTAILQ_FOREACH(kid
, &bus
->children
, sibling
) {
64 if (kid
->child
== child
) {
67 snprintf(name
, sizeof(name
), "child[%d]", kid
->index
);
68 QTAILQ_REMOVE_RCU(&bus
->children
, kid
, sibling
);
72 /* This gives back ownership of kid->child back to us. */
73 object_property_del(OBJECT(bus
), name
);
75 /* free the bus kid, when it is safe to do so*/
76 call_rcu(kid
, bus_free_bus_child
, rcu
);
82 static void bus_add_child(BusState
*bus
, DeviceState
*child
)
85 BusChild
*kid
= g_malloc0(sizeof(*kid
));
88 kid
->index
= bus
->max_index
++;
90 object_ref(OBJECT(kid
->child
));
92 QTAILQ_INSERT_HEAD_RCU(&bus
->children
, kid
, sibling
);
94 /* This transfers ownership of kid->child to the property. */
95 snprintf(name
, sizeof(name
), "child[%d]", kid
->index
);
96 object_property_add_link(OBJECT(bus
), name
,
97 object_get_typename(OBJECT(child
)),
98 (Object
**)&kid
->child
,
99 NULL
, /* read-only property */
103 static bool bus_check_address(BusState
*bus
, DeviceState
*child
, Error
**errp
)
105 BusClass
*bc
= BUS_GET_CLASS(bus
);
106 return !bc
->check_address
|| bc
->check_address(bus
, child
, errp
);
109 bool qdev_set_parent_bus(DeviceState
*dev
, BusState
*bus
, Error
**errp
)
111 BusState
*old_parent_bus
= dev
->parent_bus
;
112 DeviceClass
*dc
= DEVICE_GET_CLASS(dev
);
114 assert(dc
->bus_type
&& object_dynamic_cast(OBJECT(bus
), dc
->bus_type
));
116 if (!bus_check_address(bus
, dev
, errp
)) {
120 if (old_parent_bus
) {
121 trace_qdev_update_parent_bus(dev
, object_get_typename(OBJECT(dev
)),
122 old_parent_bus
, object_get_typename(OBJECT(old_parent_bus
)),
123 OBJECT(bus
), object_get_typename(OBJECT(bus
)));
125 * Keep a reference to the device while it's not plugged into
126 * any bus, to avoid it potentially evaporating when it is
127 * dereffed in bus_remove_child().
128 * Also keep the ref of the parent bus until the end, so that
129 * we can safely call resettable_change_parent() below.
131 object_ref(OBJECT(dev
));
132 bus_remove_child(dev
->parent_bus
, dev
);
134 dev
->parent_bus
= bus
;
135 object_ref(OBJECT(bus
));
136 bus_add_child(bus
, dev
);
138 resettable_change_parent(OBJECT(dev
), OBJECT(bus
),
139 OBJECT(old_parent_bus
));
141 if (old_parent_bus
) {
142 object_unref(OBJECT(old_parent_bus
));
143 object_unref(OBJECT(dev
));
148 DeviceState
*qdev_new(const char *name
)
150 if (!object_class_by_name(name
)) {
151 module_load_qom_one(name
);
153 return DEVICE(object_new(name
));
156 DeviceState
*qdev_try_new(const char *name
)
158 if (!module_object_class_by_name(name
)) {
161 return DEVICE(object_new(name
));
164 static QTAILQ_HEAD(, DeviceListener
) device_listeners
165 = QTAILQ_HEAD_INITIALIZER(device_listeners
);
167 enum ListenerDirection
{ Forward
, Reverse
};
169 #define DEVICE_LISTENER_CALL(_callback, _direction, _args...) \
171 DeviceListener *_listener; \
173 switch (_direction) { \
175 QTAILQ_FOREACH(_listener, &device_listeners, link) { \
176 if (_listener->_callback) { \
177 _listener->_callback(_listener, ##_args); \
182 QTAILQ_FOREACH_REVERSE(_listener, &device_listeners, \
184 if (_listener->_callback) { \
185 _listener->_callback(_listener, ##_args); \
194 static int device_listener_add(DeviceState
*dev
, void *opaque
)
196 DEVICE_LISTENER_CALL(realize
, Forward
, dev
);
201 void device_listener_register(DeviceListener
*listener
)
203 QTAILQ_INSERT_TAIL(&device_listeners
, listener
, link
);
205 qbus_walk_children(sysbus_get_default(), NULL
, NULL
, device_listener_add
,
209 void device_listener_unregister(DeviceListener
*listener
)
211 QTAILQ_REMOVE(&device_listeners
, listener
, link
);
214 bool qdev_should_hide_device(const QDict
*opts
, bool from_json
, Error
**errp
)
217 DeviceListener
*listener
;
219 QTAILQ_FOREACH(listener
, &device_listeners
, link
) {
220 if (listener
->hide_device
) {
221 if (listener
->hide_device(listener
, opts
, from_json
, errp
)) {
232 void qdev_set_legacy_instance_id(DeviceState
*dev
, int alias_id
,
233 int required_for_version
)
235 assert(!dev
->realized
);
236 dev
->instance_id_alias
= alias_id
;
237 dev
->alias_required_for_version
= required_for_version
;
240 static int qdev_prereset(DeviceState
*dev
, void *opaque
)
242 trace_qdev_reset_tree(dev
, object_get_typename(OBJECT(dev
)));
246 static int qbus_prereset(BusState
*bus
, void *opaque
)
248 trace_qbus_reset_tree(bus
, object_get_typename(OBJECT(bus
)));
252 static int qdev_reset_one(DeviceState
*dev
, void *opaque
)
254 device_legacy_reset(dev
);
259 static int qbus_reset_one(BusState
*bus
, void *opaque
)
261 BusClass
*bc
= BUS_GET_CLASS(bus
);
262 trace_qbus_reset(bus
, object_get_typename(OBJECT(bus
)));
269 void qdev_reset_all(DeviceState
*dev
)
271 trace_qdev_reset_all(dev
, object_get_typename(OBJECT(dev
)));
272 qdev_walk_children(dev
, qdev_prereset
, qbus_prereset
,
273 qdev_reset_one
, qbus_reset_one
, NULL
);
276 void qdev_reset_all_fn(void *opaque
)
278 qdev_reset_all(DEVICE(opaque
));
281 void qbus_reset_all(BusState
*bus
)
283 trace_qbus_reset_all(bus
, object_get_typename(OBJECT(bus
)));
284 qbus_walk_children(bus
, qdev_prereset
, qbus_prereset
,
285 qdev_reset_one
, qbus_reset_one
, NULL
);
288 void qbus_reset_all_fn(void *opaque
)
290 BusState
*bus
= opaque
;
294 void device_cold_reset(DeviceState
*dev
)
296 resettable_reset(OBJECT(dev
), RESET_TYPE_COLD
);
299 bool device_is_in_reset(DeviceState
*dev
)
301 return resettable_is_in_reset(OBJECT(dev
));
304 static ResettableState
*device_get_reset_state(Object
*obj
)
306 DeviceState
*dev
= DEVICE(obj
);
310 static void device_reset_child_foreach(Object
*obj
, ResettableChildCallback cb
,
311 void *opaque
, ResetType type
)
313 DeviceState
*dev
= DEVICE(obj
);
316 QLIST_FOREACH(bus
, &dev
->child_bus
, sibling
) {
317 cb(OBJECT(bus
), opaque
, type
);
321 bool qdev_realize(DeviceState
*dev
, BusState
*bus
, Error
**errp
)
323 assert(!dev
->realized
&& !dev
->parent_bus
);
326 if (!qdev_set_parent_bus(dev
, bus
, errp
)) {
330 assert(!DEVICE_GET_CLASS(dev
)->bus_type
);
333 return object_property_set_bool(OBJECT(dev
), "realized", true, errp
);
336 bool qdev_realize_and_unref(DeviceState
*dev
, BusState
*bus
, Error
**errp
)
340 ret
= qdev_realize(dev
, bus
, errp
);
341 object_unref(OBJECT(dev
));
345 void qdev_unrealize(DeviceState
*dev
)
347 object_property_set_bool(OBJECT(dev
), "realized", false, &error_abort
);
350 static int qdev_assert_realized_properly_cb(Object
*obj
, void *opaque
)
352 DeviceState
*dev
= DEVICE(object_dynamic_cast(obj
, TYPE_DEVICE
));
356 dc
= DEVICE_GET_CLASS(dev
);
357 assert(dev
->realized
);
358 assert(dev
->parent_bus
|| !dc
->bus_type
);
363 void qdev_assert_realized_properly(void)
365 object_child_foreach_recursive(object_get_root(),
366 qdev_assert_realized_properly_cb
, NULL
);
369 bool qdev_machine_modified(void)
371 return qdev_hot_added
|| qdev_hot_removed
;
374 BusState
*qdev_get_parent_bus(DeviceState
*dev
)
376 return dev
->parent_bus
;
379 BusState
*qdev_get_child_bus(DeviceState
*dev
, const char *name
)
382 Object
*child
= object_resolve_path_component(OBJECT(dev
), name
);
384 bus
= (BusState
*)object_dynamic_cast(child
, TYPE_BUS
);
389 QLIST_FOREACH(bus
, &dev
->child_bus
, sibling
) {
390 if (strcmp(name
, bus
->name
) == 0) {
397 int qdev_walk_children(DeviceState
*dev
,
398 qdev_walkerfn
*pre_devfn
, qbus_walkerfn
*pre_busfn
,
399 qdev_walkerfn
*post_devfn
, qbus_walkerfn
*post_busfn
,
406 err
= pre_devfn(dev
, opaque
);
412 QLIST_FOREACH(bus
, &dev
->child_bus
, sibling
) {
413 err
= qbus_walk_children(bus
, pre_devfn
, pre_busfn
,
414 post_devfn
, post_busfn
, opaque
);
421 err
= post_devfn(dev
, opaque
);
430 DeviceState
*qdev_find_recursive(BusState
*bus
, const char *id
)
436 WITH_RCU_READ_LOCK_GUARD() {
437 QTAILQ_FOREACH_RCU(kid
, &bus
->children
, sibling
) {
438 DeviceState
*dev
= kid
->child
;
440 if (dev
->id
&& strcmp(dev
->id
, id
) == 0) {
444 QLIST_FOREACH(child
, &dev
->child_bus
, sibling
) {
445 ret
= qdev_find_recursive(child
, id
);
455 char *qdev_get_dev_path(DeviceState
*dev
)
459 if (!dev
|| !dev
->parent_bus
) {
463 bc
= BUS_GET_CLASS(dev
->parent_bus
);
464 if (bc
->get_dev_path
) {
465 return bc
->get_dev_path(dev
);
471 void qdev_add_unplug_blocker(DeviceState
*dev
, Error
*reason
)
473 dev
->unplug_blockers
= g_slist_prepend(dev
->unplug_blockers
, reason
);
476 void qdev_del_unplug_blocker(DeviceState
*dev
, Error
*reason
)
478 dev
->unplug_blockers
= g_slist_remove(dev
->unplug_blockers
, reason
);
481 bool qdev_unplug_blocked(DeviceState
*dev
, Error
**errp
)
485 if (dev
->unplug_blockers
) {
486 error_propagate(errp
, error_copy(dev
->unplug_blockers
->data
));
493 static bool device_get_realized(Object
*obj
, Error
**errp
)
495 DeviceState
*dev
= DEVICE(obj
);
496 return dev
->realized
;
499 static bool check_only_migratable(Object
*obj
, Error
**errp
)
501 DeviceClass
*dc
= DEVICE_GET_CLASS(obj
);
503 if (!vmstate_check_only_migratable(dc
->vmsd
)) {
504 error_setg(errp
, "Device %s is not migratable, but "
505 "--only-migratable was specified",
506 object_get_typename(obj
));
513 static void device_set_realized(Object
*obj
, bool value
, Error
**errp
)
515 DeviceState
*dev
= DEVICE(obj
);
516 DeviceClass
*dc
= DEVICE_GET_CLASS(dev
);
517 HotplugHandler
*hotplug_ctrl
;
520 Error
*local_err
= NULL
;
521 bool unattached_parent
= false;
522 static int unattached_count
;
524 if (dev
->hotplugged
&& !dc
->hotpluggable
) {
525 error_setg(errp
, QERR_DEVICE_NO_HOTPLUG
, object_get_typename(obj
));
529 if (value
&& !dev
->realized
) {
530 if (!check_only_migratable(obj
, errp
)) {
535 gchar
*name
= g_strdup_printf("device[%d]", unattached_count
++);
537 object_property_add_child(container_get(qdev_get_machine(),
540 unattached_parent
= true;
544 hotplug_ctrl
= qdev_get_hotplug_handler(dev
);
546 hotplug_handler_pre_plug(hotplug_ctrl
, dev
, &local_err
);
547 if (local_err
!= NULL
) {
553 dc
->realize(dev
, &local_err
);
554 if (local_err
!= NULL
) {
559 DEVICE_LISTENER_CALL(realize
, Forward
, dev
);
562 * always free/re-initialize here since the value cannot be cleaned up
563 * in device_unrealize due to its usage later on in the unplug path
565 g_free(dev
->canonical_path
);
566 dev
->canonical_path
= object_get_canonical_path(OBJECT(dev
));
567 QLIST_FOREACH(ncl
, &dev
->clocks
, node
) {
571 clock_setup_canonical_path(ncl
->clock
);
575 if (qdev_get_vmsd(dev
)) {
576 if (vmstate_register_with_alias_id(VMSTATE_IF(dev
),
577 VMSTATE_INSTANCE_ID_ANY
,
578 qdev_get_vmsd(dev
), dev
,
579 dev
->instance_id_alias
,
580 dev
->alias_required_for_version
,
582 goto post_realize_fail
;
587 * Clear the reset state, in case the object was previously unrealized
588 * with a dirty state.
590 resettable_state_clear(&dev
->reset
);
592 QLIST_FOREACH(bus
, &dev
->child_bus
, sibling
) {
593 if (!qbus_realize(bus
, errp
)) {
594 goto child_realize_fail
;
597 if (dev
->hotplugged
) {
599 * Reset the device, as well as its subtree which, at this point,
600 * should be realized too.
602 resettable_assert_reset(OBJECT(dev
), RESET_TYPE_COLD
);
603 resettable_change_parent(OBJECT(dev
), OBJECT(dev
->parent_bus
),
605 resettable_release_reset(OBJECT(dev
), RESET_TYPE_COLD
);
607 dev
->pending_deleted_event
= false;
610 hotplug_handler_plug(hotplug_ctrl
, dev
, &local_err
);
611 if (local_err
!= NULL
) {
612 goto child_realize_fail
;
616 qatomic_store_release(&dev
->realized
, value
);
618 } else if (!value
&& dev
->realized
) {
621 * Change the value so that any concurrent users are aware
622 * that the device is going to be unrealized
624 * TODO: change .realized property to enum that states
625 * each phase of the device realization/unrealization
628 qatomic_set(&dev
->realized
, value
);
630 * Ensure that concurrent users see this update prior to
631 * any other changes done by unrealize.
635 QLIST_FOREACH(bus
, &dev
->child_bus
, sibling
) {
638 if (qdev_get_vmsd(dev
)) {
639 vmstate_unregister(VMSTATE_IF(dev
), qdev_get_vmsd(dev
), dev
);
644 dev
->pending_deleted_event
= true;
645 DEVICE_LISTENER_CALL(unrealize
, Reverse
, dev
);
648 assert(local_err
== NULL
);
652 QLIST_FOREACH(bus
, &dev
->child_bus
, sibling
) {
656 if (qdev_get_vmsd(dev
)) {
657 vmstate_unregister(VMSTATE_IF(dev
), qdev_get_vmsd(dev
), dev
);
661 g_free(dev
->canonical_path
);
662 dev
->canonical_path
= NULL
;
668 error_propagate(errp
, local_err
);
669 if (unattached_parent
) {
671 * Beware, this doesn't just revert
672 * object_property_add_child(), it also runs bus_remove()!
674 object_unparent(OBJECT(dev
));
679 static bool device_get_hotpluggable(Object
*obj
, Error
**errp
)
681 DeviceClass
*dc
= DEVICE_GET_CLASS(obj
);
682 DeviceState
*dev
= DEVICE(obj
);
684 return dc
->hotpluggable
&& (dev
->parent_bus
== NULL
||
685 qbus_is_hotpluggable(dev
->parent_bus
));
688 static bool device_get_hotplugged(Object
*obj
, Error
**errp
)
690 DeviceState
*dev
= DEVICE(obj
);
692 return dev
->hotplugged
;
695 static void device_initfn(Object
*obj
)
697 DeviceState
*dev
= DEVICE(obj
);
699 if (phase_check(PHASE_MACHINE_READY
)) {
701 qdev_hot_added
= true;
704 dev
->instance_id_alias
= -1;
705 dev
->realized
= false;
706 dev
->allow_unplug_during_migration
= false;
708 QLIST_INIT(&dev
->gpios
);
709 QLIST_INIT(&dev
->clocks
);
712 static void device_post_init(Object
*obj
)
715 * Note: ordered so that the user's global properties take
718 object_apply_compat_props(obj
);
719 qdev_prop_set_globals(DEVICE(obj
));
722 /* Unlink device from bus and free the structure. */
723 static void device_finalize(Object
*obj
)
725 NamedGPIOList
*ngl
, *next
;
727 DeviceState
*dev
= DEVICE(obj
);
729 g_assert(!dev
->unplug_blockers
);
731 QLIST_FOREACH_SAFE(ngl
, &dev
->gpios
, node
, next
) {
732 QLIST_REMOVE(ngl
, node
);
733 qemu_free_irqs(ngl
->in
, ngl
->num_in
);
736 /* ngl->out irqs are owned by the other end and should not be freed
741 qdev_finalize_clocklist(dev
);
743 /* Only send event if the device had been completely realized */
744 if (dev
->pending_deleted_event
) {
745 g_assert(dev
->canonical_path
);
747 qapi_event_send_device_deleted(!!dev
->id
, dev
->id
, dev
->canonical_path
);
748 g_free(dev
->canonical_path
);
749 dev
->canonical_path
= NULL
;
752 qobject_unref(dev
->opts
);
756 static void device_class_base_init(ObjectClass
*class, void *data
)
758 DeviceClass
*klass
= DEVICE_CLASS(class);
760 /* We explicitly look up properties in the superclasses,
761 * so do not propagate them to the subclasses.
763 klass
->props_
= NULL
;
766 static void device_unparent(Object
*obj
)
768 DeviceState
*dev
= DEVICE(obj
);
774 while (dev
->num_child_bus
) {
775 bus
= QLIST_FIRST(&dev
->child_bus
);
776 object_unparent(OBJECT(bus
));
778 if (dev
->parent_bus
) {
779 bus_remove_child(dev
->parent_bus
, dev
);
780 object_unref(OBJECT(dev
->parent_bus
));
781 dev
->parent_bus
= NULL
;
786 device_vmstate_if_get_id(VMStateIf
*obj
)
788 DeviceState
*dev
= DEVICE(obj
);
790 return qdev_get_dev_path(dev
);
794 * device_phases_reset:
795 * Transition reset method for devices to allow moving
796 * smoothly from legacy reset method to multi-phases
798 static void device_phases_reset(DeviceState
*dev
)
800 ResettableClass
*rc
= RESETTABLE_GET_CLASS(dev
);
802 if (rc
->phases
.enter
) {
803 rc
->phases
.enter(OBJECT(dev
), RESET_TYPE_COLD
);
805 if (rc
->phases
.hold
) {
806 rc
->phases
.hold(OBJECT(dev
));
808 if (rc
->phases
.exit
) {
809 rc
->phases
.exit(OBJECT(dev
));
813 static void device_transitional_reset(Object
*obj
)
815 DeviceClass
*dc
= DEVICE_GET_CLASS(obj
);
818 * This will call either @device_phases_reset (for multi-phases transitioned
819 * devices) or a device's specific method for not-yet transitioned devices.
820 * In both case, it does not reset children.
823 dc
->reset(DEVICE(obj
));
828 * device_get_transitional_reset:
829 * check if the device's class is ready for multi-phase
831 static ResettableTrFunction
device_get_transitional_reset(Object
*obj
)
833 DeviceClass
*dc
= DEVICE_GET_CLASS(obj
);
834 if (dc
->reset
!= device_phases_reset
) {
836 * dc->reset has been overridden by a subclass,
837 * the device is not ready for multi phase yet.
839 return device_transitional_reset
;
844 static void device_class_init(ObjectClass
*class, void *data
)
846 DeviceClass
*dc
= DEVICE_CLASS(class);
847 VMStateIfClass
*vc
= VMSTATE_IF_CLASS(class);
848 ResettableClass
*rc
= RESETTABLE_CLASS(class);
850 class->unparent
= device_unparent
;
852 /* by default all devices were considered as hotpluggable,
853 * so with intent to check it in generic qdev_unplug() /
854 * device_set_realized() functions make every device
855 * hotpluggable. Devices that shouldn't be hotpluggable,
856 * should override it in their class_init()
858 dc
->hotpluggable
= true;
859 dc
->user_creatable
= true;
860 vc
->get_id
= device_vmstate_if_get_id
;
861 rc
->get_state
= device_get_reset_state
;
862 rc
->child_foreach
= device_reset_child_foreach
;
865 * @device_phases_reset is put as the default reset method below, allowing
866 * to do the multi-phase transition from base classes to leaf classes. It
867 * allows a legacy-reset Device class to extend a multi-phases-reset
868 * Device class for the following reason:
869 * + If a base class B has been moved to multi-phase, then it does not
870 * override this default reset method and may have defined phase methods.
871 * + A child class C (extending class B) which uses
872 * device_class_set_parent_reset() (or similar means) to override the
873 * reset method will still work as expected. @device_phases_reset function
874 * will be registered as the parent reset method and effectively call
875 * parent reset phases.
877 dc
->reset
= device_phases_reset
;
878 rc
->get_transitional_function
= device_get_transitional_reset
;
880 object_class_property_add_bool(class, "realized",
881 device_get_realized
, device_set_realized
);
882 object_class_property_add_bool(class, "hotpluggable",
883 device_get_hotpluggable
, NULL
);
884 object_class_property_add_bool(class, "hotplugged",
885 device_get_hotplugged
, NULL
);
886 object_class_property_add_link(class, "parent_bus", TYPE_BUS
,
887 offsetof(DeviceState
, parent_bus
), NULL
, 0);
890 void device_class_set_parent_reset(DeviceClass
*dc
,
891 DeviceReset dev_reset
,
892 DeviceReset
*parent_reset
)
894 *parent_reset
= dc
->reset
;
895 dc
->reset
= dev_reset
;
898 void device_class_set_parent_realize(DeviceClass
*dc
,
899 DeviceRealize dev_realize
,
900 DeviceRealize
*parent_realize
)
902 *parent_realize
= dc
->realize
;
903 dc
->realize
= dev_realize
;
906 void device_class_set_parent_unrealize(DeviceClass
*dc
,
907 DeviceUnrealize dev_unrealize
,
908 DeviceUnrealize
*parent_unrealize
)
910 *parent_unrealize
= dc
->unrealize
;
911 dc
->unrealize
= dev_unrealize
;
914 void device_legacy_reset(DeviceState
*dev
)
916 DeviceClass
*klass
= DEVICE_GET_CLASS(dev
);
918 trace_qdev_reset(dev
, object_get_typename(OBJECT(dev
)));
924 Object
*qdev_get_machine(void)
929 dev
= container_get(object_get_root(), "/machine");
935 static MachineInitPhase machine_phase
;
937 bool phase_check(MachineInitPhase phase
)
939 return machine_phase
>= phase
;
942 void phase_advance(MachineInitPhase phase
)
944 assert(machine_phase
== phase
- 1);
945 machine_phase
= phase
;
948 static const TypeInfo device_type_info
= {
950 .parent
= TYPE_OBJECT
,
951 .instance_size
= sizeof(DeviceState
),
952 .instance_init
= device_initfn
,
953 .instance_post_init
= device_post_init
,
954 .instance_finalize
= device_finalize
,
955 .class_base_init
= device_class_base_init
,
956 .class_init
= device_class_init
,
958 .class_size
= sizeof(DeviceClass
),
959 .interfaces
= (InterfaceInfo
[]) {
961 { TYPE_RESETTABLE_INTERFACE
},
966 static void qdev_register_types(void)
968 type_register_static(&device_type_info
);
971 type_init(qdev_register_types
)