qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Bandan Das <bsd@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Andreas Färber" <afaerber@suse.de>
Subject: [Qemu-devel] [RFC PATCH 1/3] qdev: add realize/unrealize interfaces for BusState
Date: Mon, 25 Nov 2013 17:48:40 -0500	[thread overview]
Message-ID: <1385419722-22205-2-git-send-email-bsd@redhat.com> (raw)
In-Reply-To: <1385419722-22205-1-git-send-email-bsd@redhat.com>

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(+)

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	other threads:[~2013-11-25 22:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-25 22:48 [Qemu-devel] [RFC PATCH 0/3] Add realize unrealize interfaces for BusState Bandan Das
2013-11-25 22:48 ` Bandan Das [this message]
2013-11-25 22:48 ` [Qemu-devel] [RFC PATCH 2/3] qdev: Integrate the bus realized property to get Bandan Das
2013-11-25 22:48 ` [Qemu-devel] [RFC PATCH 3/3] pci: move vmstate_pcibus registration/unregistration to realize and unrealize interfaces Bandan Das
2014-03-12 20:29   ` Michael S. Tsirkin
2013-12-11 15:27 ` [Qemu-devel] [RFC PATCH 0/3] Add realize unrealize interfaces for BusState Bandan Das
2014-03-12 20:38   ` Andreas Färber

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1385419722-22205-2-git-send-email-bsd@redhat.com \
    --to=bsd@redhat.com \
    --cc=afaerber@suse.de \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).