Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NVqZO-000520-PB for qemu-devel@nongnu.org; Fri, 15 Jan 2010 13:06:50 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NVqZK-00051c-AB for qemu-devel@nongnu.org; Fri, 15 Jan 2010 13:06:50 -0500 Received: from [199.232.76.173] (port=45137 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NVqZK-00051Z-3v for qemu-devel@nongnu.org; Fri, 15 Jan 2010 13:06:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:12969) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NVqZJ-00028Z-BQ for qemu-devel@nongnu.org; Fri, 15 Jan 2010 13:06:45 -0500 From: Markus Armbruster Subject: Re: [Qemu-devel] [RFC,PATCH 04/11] qdev: pcibus_dev_info References: <1261861899-1984-1-git-send-email-nathan@parenthephobia.org.uk> <1261861899-1984-5-git-send-email-nathan@parenthephobia.org.uk> Date: Fri, 15 Jan 2010 19:06:40 +0100 In-Reply-To: <1261861899-1984-5-git-send-email-nathan@parenthephobia.org.uk> (Nathan Baum's message of "Sat, 26 Dec 2009 21:11:32 +0000") Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Nathan Baum Cc: qemu-devel@nongnu.org Nathan Baum writes: > This returns a QObject detailing the PCI-specific data about the device. > > Signed-off-by: Nathan Baum > --- > hw/pci.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ > 1 files changed, 48 insertions(+), 0 deletions(-) > > diff --git a/hw/pci.c b/hw/pci.c > index 9722fce..8688d8a 100644 > --- a/hw/pci.c > +++ b/hw/pci.c > @@ -27,6 +27,8 @@ > #include "net.h" > #include "sysemu.h" > #include "loader.h" > +#include "qjson.h" > +#include "qint.h" > > //#define DEBUG_PCI > #ifdef DEBUG_PCI > @@ -1585,6 +1587,52 @@ static void pcibus_dev_print(Monitor *mon, DeviceState *dev, int indent) > } > } > > +static QObject *pcibus_dev_info(Monitor *mon, DeviceState *dev) > +{ > + PCIDevice *d = (PCIDevice *)dev; > + const pci_class_desc *desc; > + PCIIORegion *r; > + int i, class; > + QObject *retval; > + QList *regions; > + > + retval = qobject_from_jsonf("{ 'addr': { 'bus' : %d, 'slot' : %d, 'func': %d }, " 'bus' doesn't really belong here, it's a property of the bus, not the device. That's why device property "addr" is just device, function. If we want to have it here anyway, we should have 'domain' as well. Even though we don't support PCI domains, yet. > + " 'device': { 'vendor': %d, 'id': %d }, " > + " 'subsystem': { 'vendor': %d, 'id': %d } " > + "}", > + d->config[PCI_SECONDARY_BUS], > + PCI_SLOT(d->devfn), > + PCI_FUNC(d->devfn), > + pci_get_word(d->config + PCI_VENDOR_ID), > + pci_get_word(d->config + PCI_DEVICE_ID), > + pci_get_word(d->config + PCI_SUBSYSTEM_VENDOR_ID), > + pci_get_word(d->config + PCI_SUBSYSTEM_ID)); > + class = pci_get_word(d->config + PCI_CLASS_DEVICE); > + desc = pci_class_descriptions; > + while (desc->desc && class != desc->class) > + desc++; > + if (desc->desc) { > + qdict_put(qobject_to_qdict(retval), "class", qstring_from_str(desc->desc)); > + } else { > + qdict_put(qobject_to_qdict(retval), "class", qint_from_int(class)); > + } > + > + regions = qlist_new(); > + qdict_put(qobject_to_qdict(retval), "regions", regions); > + > + for (i = 0; i < PCI_NUM_REGIONS; i++) { > + r = &d->io_regions[i]; > + if (!r->size) > + continue; > + qlist_append_obj(regions, > + qobject_from_jsonf("{'type':%s,'addr':%d,'size':%d}", > + r->type & PCI_BASE_ADDRESS_SPACE_IO ? "i/o" : "mem", > + (int) r->addr, > + (int) r->size)); You need to print pcibus_t values with %FMT_PCIBUS, just like pcibus_dev_print(). Casting to int so you can use %d can truncate the value. > + } > + return retval; > +} > + > static PCIDeviceInfo bridge_info = { > .qdev.name = "pci-bridge", > .qdev.size = sizeof(PCIBridge),