From patchwork Sat Dec 26 21:19:21 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Baum X-Patchwork-Id: 41817 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 58D58B7BE0 for ; Sun, 27 Dec 2009 08:41:16 +1100 (EST) Received: from localhost ([127.0.0.1]:60802 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NOeNt-0005VX-1L for incoming@patchwork.ozlabs.org; Sat, 26 Dec 2009 16:41:13 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NOe3D-0004JY-Oj for qemu-devel@nongnu.org; Sat, 26 Dec 2009 16:19:52 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NOe32-0004Db-Fm for qemu-devel@nongnu.org; Sat, 26 Dec 2009 16:19:44 -0500 Received: from [199.232.76.173] (port=43622 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NOe32-0004DO-2G for qemu-devel@nongnu.org; Sat, 26 Dec 2009 16:19:40 -0500 Received: from smarthost.c4l.co.uk ([82.197.83.77]:53793) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NOe31-0005Ev-C3 for qemu-devel@nongnu.org; Sat, 26 Dec 2009 16:19:39 -0500 Received: from [93.97.162.229] (helo=mx.parenthephobia.org.uk) by smarthost.c4l.co.uk with esmtp (Exim 4.69) (envelope-from ) id 1NOe2v-0007uS-Mh for qemu-devel@nongnu.org; Sat, 26 Dec 2009 21:19:34 +0000 Received: from athens (93-97-162-231.zone5.bethere.co.uk [93.97.162.231]) by mx.parenthephobia.org.uk (Postfix) with ESMTP id D9B6553788 for ; Sat, 26 Dec 2009 21:26:49 +0000 (GMT) Received: by athens (Postfix, from userid 1000) id E80835EEF0; Sat, 26 Dec 2009 21:19:23 +0000 (GMT) From: Nathan Baum To: qemu-devel@nongnu.org Date: Sat, 26 Dec 2009 21:19:21 +0000 Message-Id: <1261862362-2530-11-git-send-email-nathan@parenthephobia.org.uk> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <1261862362-2530-1-git-send-email-nathan@parenthephobia.org.uk> References: <1261862362-2530-1-git-send-email-nathan@parenthephobia.org.uk> X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCH 10/11] qdev: Add do_info_qbus and friends. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Places information about a bus and the devices on into a QObject. Signed-off-by: Nathan Baum --- hw/qdev.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 73 insertions(+), 0 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index b6bd4ae..f5d68c6 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -30,6 +30,8 @@ #include "sysemu.h" #include "monitor.h" #include "qerror.h" +#include "qint.h" +#include "qbool.h" static int qdev_hotplug = 0; @@ -654,6 +656,77 @@ void qbus_free(BusState *bus) } } +static void do_info_qbus(Monitor *mon, BusState *bus, QObject **ret_data); + +static void do_info_qdev_props(Monitor *mon, DeviceState *dev, Property *props, const char *prefix, + QDict *qdict) +{ + char name[64]; + char value[64]; + + if (!props) + return; + while (props->name) { + if (props->info->print) { + props->info->print(dev, props, value, sizeof(value)); + snprintf(name, sizeof(name), "%s-%s", prefix, props->name); + qdict_put(qdict, name, qstring_from_str(value)); + } + props++; + } +} + +static void do_info_qdev(Monitor *mon, DeviceState *dev, QObject **ret_data) +{ + BusState *child; + QDict *qdict; + QList *children; + + qdict = qdict_new(); + qdict_put(qdict, "name", qstring_from_str(dev->info->name)); + if (dev->id) + qdict_put(qdict, "id", qstring_from_str(dev->id)); + qdict_put(qdict, "gpio-in", qint_from_int(dev->num_gpio_in)); + qdict_put(qdict, "gpio-out", qint_from_int(dev->num_gpio_out)); + do_info_qdev_props(mon, dev, dev->info->props, "dev", qdict); + do_info_qdev_props(mon, dev, dev->parent_bus->info->props, "bus", qdict); + children = qlist_new(); + QLIST_FOREACH(child, &dev->child_bus, sibling) { + QObject *data = NULL; + do_info_qbus(mon, child, &data); + if (data) + qlist_append_obj(children, data); + } + if (!qlist_empty(children)) + qdict_put(qdict, "children", children); + if (dev->parent_bus->info->info_dev) { + qdict_put_obj(qdict, "info", dev->parent_bus->info->info_dev(mon, dev)); + } + *ret_data = (QObject *) qdict; +} + +static void do_info_qbus(Monitor *mon, BusState *bus, QObject **ret_data) +{ + struct DeviceState *dev; + QDict *qdict; + QList *children; + + qdict = qdict_new(); + qdict_put(qdict, "bus", qstring_from_str(bus->name)); + qdict_put(qdict, "type", qstring_from_str(bus->info->name)); + qdict_put(qdict, "allow_hotplug", qbool_from_int(bus->allow_hotplug)); + children = qlist_new(); + qdict_put(qdict, "children", children); + QLIST_FOREACH(dev, &bus->children, sibling) { + QObject *data = NULL; + do_info_qdev(mon, dev, &data); + if (data) + qlist_append_obj(children, data); + } + + *ret_data = (QObject *) qdict; +} + #define qdev_printf(fmt, ...) monitor_printf(mon, "%*s" fmt, indent, "", ## __VA_ARGS__) static void qbus_print(Monitor *mon, BusState *bus, int indent);