@@ -464,6 +464,70 @@ static void bus_unparent(Object *obj)
}
}
+static bool bus_get_realized(Object *obj, Error **err)
+{
+ BusState *bus = BUS(obj);
+ return bus->realized;
+}
+
+static void bus_set_realized(Object *obj, bool value, Error **err)
+{
+ BusState *bus = BUS(obj);
+ BusClass *bc = BUS_GET_CLASS(bus);
+ Error *local_err = NULL;
+ BusChild *kid;
+
+ if (value && !bus->realized) {
+
+ if (bc->realize) {
+ bc->realize(bus, &local_err);
+
+ if (local_err != NULL) {
+ goto error;
+ }
+
+ }
+
+ QTAILQ_FOREACH(kid, &bus->children, sibling) {
+
+ DeviceState *dev = kid->child;
+ object_property_set_bool(OBJECT(dev), true,
+ "realized", &local_err);
+
+ if (local_err != NULL) {
+ goto error;
+ }
+ }
+
+ } else if (!value && bus->realized) {
+
+ QTAILQ_FOREACH(kid, &bus->children, sibling) {
+
+ DeviceState *dev = kid->child;
+ object_property_set_bool(OBJECT(dev), false,
+ "realized", &local_err);
+
+ if (local_err != NULL) {
+ goto error;
+ }
+ }
+
+ if (bc->unrealize) {
+ bc->unrealize(bus, &local_err);
+
+ if (local_err != NULL) {
+ goto error;
+ }
+ }
+ }
+
+ bus->realized = value;
+ return;
+
+error:
+ error_propagate(err, local_err);
+}
+
void qbus_create_inplace(void *bus, size_t size, const char *typename,
DeviceState *parent, const char *name)
{
@@ -868,6 +932,9 @@ static void qbus_initfn(Object *obj)
BusState *bus = BUS(obj);
QTAILQ_INIT(&bus->children);
+ object_property_add_bool(obj, "realized",
+ bus_get_realized, bus_set_realized, NULL);
+
}
static char *default_bus_get_fw_dev_path(DeviceState *dev)
@@ -35,6 +35,9 @@ typedef int (*qdev_event)(DeviceState *dev);
typedef void (*qdev_resetfn)(DeviceState *dev);
typedef void (*DeviceRealize)(DeviceState *dev, Error **errp);
typedef void (*DeviceUnrealize)(DeviceState *dev, Error **errp);
+typedef void (*BusRealize)(BusState *dev, Error **errp);
+typedef void (*BusUnrealize)(BusState *dev, Error **errp);
+
struct VMStateDescription;
@@ -159,6 +162,9 @@ struct BusClass {
*/
char *(*get_fw_dev_path)(DeviceState *dev);
int (*reset)(BusState *bus);
+ BusRealize realize;
+ BusUnrealize unrealize;
+
/* maximum devices allowed on the bus, 0: no limit. */
int max_dev;
};
@@ -178,6 +184,7 @@ struct BusState {
const char *name;
int allow_hotplug;
int max_index;
+ bool realized;
QTAILQ_HEAD(ChildrenHead, BusChild) children;
QLIST_ENTRY(BusState) sibling;
};
Add simple set/get functions for bus. The setter also checks if it has children devices and sets "realize" accordingly. Signed-off-by: Bandan Das <bsd@redhat.com> --- hw/core/qdev.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/qdev-core.h | 7 ++++++ 2 files changed, 74 insertions(+)