aboutsummaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorAnthony Liguori <aliguori@us.ibm.com>2011-12-22 15:06:37 -0600
committerAnthony Liguori <aliguori@us.ibm.com>2012-02-03 10:41:08 -0600
commit9674bfe42070e58242f0048f4f03fde69d570a75 (patch)
tree3b01d1e207d1b1645ae6579feced9f55ed50e465 /hw
parent5eeee3fa2e646dadeea2c10515956b11ed0de877 (diff)
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>
Diffstat (limited to 'hw')
-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),
};