From patchwork Mon Nov 25 22:48:40 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bandan Das X-Patchwork-Id: 294131 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E56C92C00B3 for ; Tue, 26 Nov 2013 09:50:17 +1100 (EST) Received: from localhost ([::1]:55482 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vl4yt-000488-EE for incoming@patchwork.ozlabs.org; Mon, 25 Nov 2013 17:50:15 -0500 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 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rAPMnbRC011391 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 25 Nov 2013 17:49:37 -0500 Received: from nelium.bos.redhat.com ([10.18.25.173]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rAPMnTxT006408; Mon, 25 Nov 2013 17:49:36 -0500 From: Bandan Das To: qemu-devel@nongnu.org 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> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [RFC PATCH 1/3] qdev: add realize/unrealize interfaces for BusState X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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; };