Received: from eggs.gnu.org ([2001:4830:134:3::10]:60675) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNqPs-00084R-U0 for qemu-devel@nongnu.org; Wed, 12 Mar 2014 17:10:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WNqPg-000053-1K for qemu-devel@nongnu.org; Wed, 12 Mar 2014 17:10:20 -0400 Received: from cantor2.suse.de ([195.135.220.15]:45531 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNqPf-0008TH-Pt for qemu-devel@nongnu.org; Wed, 12 Mar 2014 17:10:07 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Wed, 12 Mar 2014 22:10:00 +0100 Message-Id: <1394658603-13650-29-git-send-email-afaerber@suse.de> In-Reply-To: <1394658603-13650-1-git-send-email-afaerber@suse.de> References: <1394658603-13650-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL for-2.0-rc0 28/31] qdev: Prepare realize/unrealize hooks for BusState List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Bandan Das , =?UTF-8?q?Andreas=20F=C3=A4rber?= From: Bandan Das Add a "realized" property calling realize/unrealize hooks as for devices. Signed-off-by: Bandan Das Signed-off-by: Andreas F=C3=A4rber --- hw/core/qdev.c | 41 +++++++++++++++++++++++++++++++++++++++++ include/hw/qdev-core.h | 6 ++++++ 2 files changed, 47 insertions(+) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 71b7045..7e58259 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -501,6 +501,45 @@ static void bus_unparent(Object *obj) } } =20 +static bool bus_get_realized(Object *obj, Error **err) +{ + BusState *bus =3D BUS(obj); + + return bus->realized; +} + +static void bus_set_realized(Object *obj, bool value, Error **err) +{ + BusState *bus =3D BUS(obj); + BusClass *bc =3D BUS_GET_CLASS(bus); + Error *local_err =3D NULL; + + if (value && !bus->realized) { + if (bc->realize) { + bc->realize(bus, &local_err); + + if (local_err !=3D NULL) { + goto error; + } + + } + } else if (!value && bus->realized) { + if (bc->unrealize) { + bc->unrealize(bus, &local_err); + + if (local_err !=3D NULL) { + goto error; + } + } + } + + bus->realized =3D 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) { @@ -889,6 +928,8 @@ static void qbus_initfn(Object *obj) object_property_add_link(obj, QDEV_HOTPLUG_HANDLER_PROPERTY, TYPE_HOTPLUG_HANDLER, (Object **)&bus->hotplug_handler, NULL); + object_property_add_bool(obj, "realized", + bus_get_realized, bus_set_realized, NULL); } =20 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 1ed0691..dbe473c 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -36,6 +36,8 @@ 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 *bus, Error **errp); +typedef void (*BusUnrealize)(BusState *bus, Error **errp); =20 struct VMStateDescription; =20 @@ -174,6 +176,9 @@ struct BusClass { */ char *(*get_fw_dev_path)(DeviceState *dev); void (*reset)(BusState *bus); + BusRealize realize; + BusUnrealize unrealize; + /* maximum devices allowed on the bus, 0: no limit. */ int max_dev; /* number of automatically allocated bus ids (e.g. ide.0) */ @@ -199,6 +204,7 @@ struct BusState { int allow_hotplug; HotplugHandler *hotplug_handler; int max_index; + bool realized; QTAILQ_HEAD(ChildrenHead, BusChild) children; QLIST_ENTRY(BusState) sibling; }; --=20 1.8.4.5