qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC PATCH 1/3] qdev: add realize/unrealize interfaces for


From: Bandan Das
Subject: [Qemu-devel] [RFC PATCH 1/3] qdev: add realize/unrealize interfaces for BusState
Date: Mon, 25 Nov 2013 17:48:40 -0500

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 <address@hidden>
---
 hw/core/qdev.c         | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/hw/qdev-core.h |  7 ++++++
 2 files changed, 74 insertions(+)

diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index e374a93..b503cc8 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -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)
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index f2043a6..405b029 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -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;
 };
-- 
1.8.3.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]