From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57760) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vl4yO-00042C-8z for qemu-devel@nongnu.org; Mon, 25 Nov 2013 17:49:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vl4yI-00078P-94 for qemu-devel@nongnu.org; Mon, 25 Nov 2013 17:49:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57111) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vl4yI-00077N-0s for qemu-devel@nongnu.org; Mon, 25 Nov 2013 17:49:38 -0500 From: Bandan Das Date: Mon, 25 Nov 2013 17:48:40 -0500 Message-Id: <1385419722-22205-2-git-send-email-bsd@redhat.com> In-Reply-To: <1385419722-22205-1-git-send-email-bsd@redhat.com> References: <1385419722-22205-1-git-send-email-bsd@redhat.com> Subject: [Qemu-devel] [RFC PATCH 1/3] qdev: add realize/unrealize interfaces for BusState List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= 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 --- 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