qdev: split out common init to instance_init

This gets us closer to being able to object_new() a qdev type and have a
functioning object verses having to call qdev_create().

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Anthony Liguori 2011-12-22 15:06:37 -06:00
parent 5eeee3fa2e
commit 9674bfe420

View File

@ -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),
};