[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 14/22] qdev: refactor away qdev_create_from_info
From: |
Anthony Liguori |
Subject: |
[Qemu-devel] [PATCH 14/22] qdev: refactor away qdev_create_from_info |
Date: |
Wed, 1 Feb 2012 13:50:55 -0600 |
Note that the FIXME gets fixed in series 4/4. We need to convert BusState to
QOM before we can make parent_bus a link.
Signed-off-by: Anthony Liguori <address@hidden>
---
hw/qdev.c | 35 ++++++++++++++++++++++-------------
hw/qdev.h | 3 +++
2 files changed, 25 insertions(+), 13 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index 9933ea2..e2263cb 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -124,30 +124,22 @@ bool qdev_exists(const char *name)
static void qdev_property_add_legacy(DeviceState *dev, Property *prop,
Error **errp);
-static DeviceState *qdev_create_from_info(BusState *bus, const char *typename)
+void qdev_set_parent_bus(DeviceState *dev, BusState *bus)
{
- DeviceState *dev;
Property *prop;
- dev = DEVICE(object_new(typename));
-
- dev->parent_bus = bus;
- qdev_prop_set_defaults(dev, dev->parent_bus->info->props);
-
if (qdev_hotplug) {
assert(bus->allow_hotplug);
}
+ dev->parent_bus = bus;
QTAILQ_INSERT_HEAD(&bus->children, dev, sibling);
+ qdev_prop_set_defaults(dev, dev->parent_bus->info->props);
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_prop_set_globals(dev);
-
- return dev;
}
/* Create a new device. This only initializes the device state structure
@@ -172,11 +164,21 @@ DeviceState *qdev_create(BusState *bus, const char *name)
DeviceState *qdev_try_create(BusState *bus, const char *name)
{
+ DeviceState *dev;
+
+ dev = DEVICE(object_new(name));
+ if (!dev) {
+ return NULL;
+ }
+
if (!bus) {
bus = sysbus_get_default();
}
- return qdev_create_from_info(bus, name);
+ qdev_set_parent_bus(dev, bus);
+ qdev_prop_set_globals(dev);
+
+ return dev;
}
static void qdev_print_devinfo(ObjectClass *klass, void *opaque)
@@ -373,8 +375,15 @@ DeviceState *qdev_device_add(QemuOpts *opts)
return NULL;
}
+ if (!bus) {
+ bus = sysbus_get_default();
+ }
+
/* create device, set properties */
- qdev = qdev_create_from_info(bus, driver);
+ qdev = DEVICE(object_new(driver));
+ qdev_set_parent_bus(qdev, bus);
+ qdev_prop_set_globals(qdev);
+
id = qemu_opts_id(opts);
if (id) {
qdev->id = id;
diff --git a/hw/qdev.h b/hw/qdev.h
index 5aea4bf..e611804 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -636,4 +636,7 @@ BusInfo *qdev_get_bus_info(DeviceState *dev);
Property *qdev_get_props(DeviceState *dev);
+/* FIXME: make this a link<> */
+void qdev_set_parent_bus(DeviceState *dev, BusState *bus);
+
#endif
--
1.7.4.1
- [Qemu-devel] [PATCH 12/22] qom: add new command to search for types, (continued)
- [Qemu-devel] [PATCH 12/22] qom: add new command to search for types, Anthony Liguori, 2012/02/01
- [Qemu-devel] [PATCH 17/22] qom: move properties from qdev to object, Anthony Liguori, 2012/02/01
- [Qemu-devel] [PATCH 20/22] info qdm: do not require a parent_bus to be set, Anthony Liguori, 2012/02/01
- [Qemu-devel] [PATCH 21/22] object: sure up reference counting, Anthony Liguori, 2012/02/01
- [Qemu-devel] [PATCH 09/22] qdev: register all types natively through QEMU Object Model, Anthony Liguori, 2012/02/01
- [Qemu-devel] [PATCH 22/22] container: make a decendent of Object, Anthony Liguori, 2012/02/01
- [Qemu-devel] [PATCH 19/22] qdev: implement cleanup logic in finalize, Anthony Liguori, 2012/02/01
- [Qemu-devel] [PATCH 07/22] qom: allow object_class_foreach to take additional parameters to refine search, Anthony Liguori, 2012/02/01
- [Qemu-devel] [PATCH 14/22] qdev: refactor away qdev_create_from_info,
Anthony Liguori <=
- [Qemu-devel] [PATCH 13/22] qdev: split out common init to instance_init, Anthony Liguori, 2012/02/01
- [Qemu-devel] [PATCH 18/22] qom: accept any compatible type when setting a link property, Anthony Liguori, 2012/02/01
- Re: [Qemu-devel] [PATCH 00/22] qom: use Type system to register all devices (v2), Anthony Liguori, 2012/02/03