aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hw/qdev.c41
1 files changed, 28 insertions, 13 deletions
diff --git a/hw/qdev.c b/hw/qdev.c
index 5830befbc6..9933ea210a 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -130,31 +130,22 @@ static DeviceState *qdev_create_from_info(BusState *bus, const char *typename)
Property *prop;
dev = DEVICE(object_new(typename));
+
dev->parent_bus = bus;
- qdev_prop_set_defaults(dev, qdev_get_props(dev));
qdev_prop_set_defaults(dev, dev->parent_bus->info->props);
- qdev_prop_set_globals(dev);
- QTAILQ_INSERT_HEAD(&bus->children, dev, sibling);
+
if (qdev_hotplug) {
assert(bus->allow_hotplug);
- dev->hotplugged = 1;
- qdev_hot_added = true;
}
- dev->instance_id_alias = -1;
- QTAILQ_INIT(&dev->properties);
- dev->state = DEV_STATE_CREATED;
- for (prop = qdev_get_props(dev); prop && prop->name; prop++) {
- qdev_property_add_legacy(dev, prop, NULL);
- qdev_property_add_static(dev, prop, NULL);
- }
+ QTAILQ_INSERT_HEAD(&bus->children, dev, sibling);
for (prop = qdev_get_bus_info(dev)->props; prop && prop->name; prop++) {
qdev_property_add_legacy(dev, prop, NULL);
qdev_property_add_static(dev, prop, NULL);
}
- qdev_property_add_str(dev, "type", qdev_get_type, NULL, NULL);
+ qdev_prop_set_globals(dev);
return dev;
}
@@ -1647,6 +1638,29 @@ void qdev_machine_init(void)
qdev_get_peripheral();
}
+static void device_initfn(Object *obj)
+{
+ DeviceState *dev = DEVICE(obj);
+ Property *prop;
+
+ if (qdev_hotplug) {
+ dev->hotplugged = 1;
+ qdev_hot_added = true;
+ }
+
+ dev->instance_id_alias = -1;
+ QTAILQ_INIT(&dev->properties);
+ dev->state = DEV_STATE_CREATED;
+
+ qdev_prop_set_defaults(dev, qdev_get_props(dev));
+ for (prop = qdev_get_props(dev); prop && prop->name; prop++) {
+ qdev_property_add_legacy(dev, prop, NULL);
+ qdev_property_add_static(dev, prop, NULL);
+ }
+
+ qdev_property_add_str(dev, "type", qdev_get_type, NULL, NULL);
+}
+
void device_reset(DeviceState *dev)
{
DeviceClass *klass = DEVICE_GET_CLASS(dev);
@@ -1660,6 +1674,7 @@ static TypeInfo device_type_info = {
.name = TYPE_DEVICE,
.parent = TYPE_OBJECT,
.instance_size = sizeof(DeviceState),
+ .instance_init = device_initfn,
.abstract = true,
.class_size = sizeof(DeviceClass),
};