From patchwork Sun May 23 10:59:18 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 53309 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 520B4B7D47 for ; Sun, 23 May 2010 21:08:21 +1000 (EST) Received: from localhost ([127.0.0.1]:47276 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OG928-00005u-Mf for incoming@patchwork.ozlabs.org; Sun, 23 May 2010 07:07:52 -0400 Received: from [140.186.70.92] (port=48608 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OG8uI-0004FE-Fi for qemu-devel@nongnu.org; Sun, 23 May 2010 07:00:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OG8uA-0004PR-A0 for qemu-devel@nongnu.org; Sun, 23 May 2010 06:59:46 -0400 Received: from fmmailgate02.web.de ([217.72.192.227]:37036) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OG8u9-0004Od-Md for qemu-devel@nongnu.org; Sun, 23 May 2010 06:59:38 -0400 Received: from smtp01.web.de ( [172.20.0.243]) by fmmailgate02.web.de (Postfix) with ESMTP id 0AF63162176A0; Sun, 23 May 2010 12:59:37 +0200 (CEST) Received: from [88.65.39.229] (helo=localhost.localdomain) by smtp01.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #4) id 1OG8u7-0003cZ-00; Sun, 23 May 2010 12:59:35 +0200 From: Jan Kiszka To: qemu-devel@nongnu.org, Anthony Liguori Date: Sun, 23 May 2010 12:59:18 +0200 Message-Id: <0325ebb79b2c4fd8e09aa458dfced80c8cc64af8.1274612367.git.jan.kiszka@web.de> X-Mailer: git-send-email 1.6.0.2 In-Reply-To: References: In-Reply-To: References: X-Sender: jan.kiszka@web.de X-Provags-ID: V01U2FsdGVkX1/wqemFm+SaV1Q1MKeytfiVdUfv+3l9QPYQLNVx Fu5jbQs/wK5C+FgjEbjxCoYCxrKuDbKCzisw9b2u++V8xa5StC ALP1+giBU= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 Cc: Juan Quintela , Jan Kiszka , Markus Armbruster , Luiz Capitulino , Blue Swirl , Avi Kivity Subject: [Qemu-devel] [PATCH v3 05/17] qdev: Convert device and bus lists to QTAILQ 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 From: Jan Kiszka Cosmetic change to align the instance number assignment with bus ordering. The current ordering due to QLIST_INSERT_HEAD is a bit annoying when you dump the qtree or address devices via 'driver.instance'. Signed-off-by: Jan Kiszka --- hw/acpi_piix4.c | 2 +- hw/i2c.c | 2 +- hw/pci-hotplug.c | 2 +- hw/qdev.c | 43 ++++++++++++++++++++++--------------------- hw/qdev.h | 8 ++++---- hw/ssi.c | 6 +++--- 6 files changed, 32 insertions(+), 31 deletions(-) diff --git a/hw/acpi_piix4.c b/hw/acpi_piix4.c index 0fce958..3cb3d11 100644 --- a/hw/acpi_piix4.c +++ b/hw/acpi_piix4.c @@ -536,7 +536,7 @@ static void pciej_write(void *opaque, uint32_t addr, uint32_t val) PCIDevice *dev; int slot = ffs(val) - 1; - QLIST_FOREACH_SAFE(qdev, &bus->children, sibling, next) { + QTAILQ_FOREACH_SAFE(qdev, &bus->children, sibling, next) { dev = DO_UPCAST(PCIDevice, qdev, qdev); if (PCI_SLOT(dev->devfn) == slot) { qdev_free(qdev); diff --git a/hw/i2c.c b/hw/i2c.c index bee8e88..61ab6fa 100644 --- a/hw/i2c.c +++ b/hw/i2c.c @@ -84,7 +84,7 @@ int i2c_start_transfer(i2c_bus *bus, uint8_t address, int recv) DeviceState *qdev; i2c_slave *slave = NULL; - QLIST_FOREACH(qdev, &bus->qbus.children, sibling) { + QTAILQ_FOREACH(qdev, &bus->qbus.children, sibling) { i2c_slave *candidate = I2C_SLAVE_FROM_QDEV(qdev); if (candidate->address == address) { slave = candidate; diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c index cc45c50..a226d3c 100644 --- a/hw/pci-hotplug.c +++ b/hw/pci-hotplug.c @@ -77,7 +77,7 @@ static int scsi_hot_add(Monitor *mon, DeviceState *adapter, SCSIBus *scsibus; SCSIDevice *scsidev; - scsibus = DO_UPCAST(SCSIBus, qbus, QLIST_FIRST(&adapter->child_bus)); + scsibus = DO_UPCAST(SCSIBus, qbus, QTAILQ_FIRST(&adapter->child_bus)); if (!scsibus || strcmp(scsibus->qbus.info->name, "SCSI") != 0) { error_report("Device is not a SCSI adapter"); return -1; diff --git a/hw/qdev.c b/hw/qdev.c index eeadf4a..b3d375a 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -85,10 +85,11 @@ static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info) dev = qemu_mallocz(info->size); dev->info = info; dev->parent_bus = bus; + QTAILQ_INIT(&dev->child_bus); qdev_prop_set_defaults(dev, dev->info->props); qdev_prop_set_defaults(dev, dev->parent_bus->info->props); qdev_prop_set_globals(dev); - QLIST_INSERT_HEAD(&bus->children, dev, sibling); + QTAILQ_INSERT_TAIL(&bus->children, dev, sibling); if (qdev_hotplug) { assert(bus->allow_hotplug); dev->hotplugged = 1; @@ -337,7 +338,7 @@ void qdev_free(DeviceState *dev) if (dev->state == DEV_STATE_INITIALIZED) { while (dev->num_child_bus) { - bus = QLIST_FIRST(&dev->child_bus); + bus = QTAILQ_FIRST(&dev->child_bus); qbus_free(bus); } if (dev->info->vmsd) @@ -348,7 +349,7 @@ void qdev_free(DeviceState *dev) qemu_opts_del(dev->opts); } qemu_unregister_reset(qdev_reset, dev); - QLIST_REMOVE(dev, sibling); + QTAILQ_REMOVE(&dev->parent_bus->children, dev, sibling); qemu_free(dev); } @@ -432,7 +433,7 @@ BusState *qdev_get_child_bus(DeviceState *dev, const char *name) { BusState *bus; - QLIST_FOREACH(bus, &dev->child_bus, sibling) { + QTAILQ_FOREACH(bus, &dev->child_bus, sibling) { if (strcmp(name, bus->name) == 0) { return bus; } @@ -457,8 +458,8 @@ static BusState *qbus_find_recursive(BusState *bus, const char *name, return bus; } - QLIST_FOREACH(dev, &bus->children, sibling) { - QLIST_FOREACH(child, &dev->child_bus, sibling) { + QTAILQ_FOREACH(dev, &bus->children, sibling) { + QTAILQ_FOREACH(child, &dev->child_bus, sibling) { ret = qbus_find_recursive(child, name, info); if (ret) { return ret; @@ -473,10 +474,10 @@ static DeviceState *qdev_find_recursive(BusState *bus, const char *id) DeviceState *dev, *ret; BusState *child; - QLIST_FOREACH(dev, &bus->children, sibling) { + QTAILQ_FOREACH(dev, &bus->children, sibling) { if (dev->id && strcmp(dev->id, id) == 0) return dev; - QLIST_FOREACH(child, &dev->child_bus, sibling) { + QTAILQ_FOREACH(child, &dev->child_bus, sibling) { ret = qdev_find_recursive(child, id); if (ret) { return ret; @@ -493,7 +494,7 @@ static void qbus_list_bus(DeviceState *dev) error_printf("child busses at \"%s\":", dev->id ? dev->id : dev->info->name); - QLIST_FOREACH(child, &dev->child_bus, sibling) { + QTAILQ_FOREACH(child, &dev->child_bus, sibling) { error_printf("%s\"%s\"", sep, child->name); sep = ", "; } @@ -506,7 +507,7 @@ static void qbus_list_dev(BusState *bus) const char *sep = " "; error_printf("devices at \"%s\":", bus->name); - QLIST_FOREACH(dev, &bus->children, sibling) { + QTAILQ_FOREACH(dev, &bus->children, sibling) { error_printf("%s\"%s\"", sep, dev->info->name); if (dev->id) error_printf("/\"%s\"", dev->id); @@ -519,7 +520,7 @@ static BusState *qbus_find_bus(DeviceState *dev, char *elem) { BusState *child; - QLIST_FOREACH(child, &dev->child_bus, sibling) { + QTAILQ_FOREACH(child, &dev->child_bus, sibling) { if (strcmp(child->name, elem) == 0) { return child; } @@ -546,21 +547,21 @@ static DeviceState *qbus_find_dev(BusState *bus, const char *elem) } n = 0; - QLIST_FOREACH(dev, &bus->children, sibling) { + QTAILQ_FOREACH(dev, &bus->children, sibling) { if (strcmp(dev->info->name, elem) == 0 && n++ == instance) { return dev; } } n = 0; - QLIST_FOREACH(dev, &bus->children, sibling) { + QTAILQ_FOREACH(dev, &bus->children, sibling) { if (dev->info->alias && strcmp(dev->info->alias, elem) == 0 && n++ == instance) { return dev; } } - QLIST_FOREACH(dev, &bus->children, sibling) { + QTAILQ_FOREACH(dev, &bus->children, sibling) { if (dev->id && strcmp(dev->id, elem) == 0) { return dev; } @@ -629,7 +630,7 @@ search_dev_bus: qerror_report(QERR_DEVICE_NO_BUS, elem); return NULL; case 1: - return QLIST_FIRST(&dev->child_bus); + return QTAILQ_FIRST(&dev->child_bus); default: qerror_report(QERR_DEVICE_MULTIPLE_BUSSES, elem); if (!monitor_cur_is_qmp()) { @@ -694,9 +695,9 @@ void qbus_create_inplace(BusState *bus, BusInfo *info, bus->name = buf; } - QLIST_INIT(&bus->children); + QTAILQ_INIT(&bus->children); if (parent) { - QLIST_INSERT_HEAD(&parent->child_bus, bus, sibling); + QTAILQ_INSERT_TAIL(&parent->child_bus, bus, sibling); parent->num_child_bus++; } @@ -716,11 +717,11 @@ void qbus_free(BusState *bus) { DeviceState *dev; - while ((dev = QLIST_FIRST(&bus->children)) != NULL) { + while ((dev = QTAILQ_FIRST(&bus->children)) != NULL) { qdev_free(dev); } if (bus->parent) { - QLIST_REMOVE(bus, sibling); + QTAILQ_REMOVE(&bus->parent->child_bus, bus, sibling); bus->parent->num_child_bus--; } if (bus->qdev_allocated) { @@ -769,7 +770,7 @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent) qdev_print_props(mon, dev, dev->parent_bus->info->props, "bus", indent); if (dev->parent_bus->info->print_dev) dev->parent_bus->info->print_dev(mon, dev, indent); - QLIST_FOREACH(child, &dev->child_bus, sibling) { + QTAILQ_FOREACH(child, &dev->child_bus, sibling) { qbus_print(mon, child, indent); } } @@ -781,7 +782,7 @@ static void qbus_print(Monitor *mon, BusState *bus, int indent) qdev_printf("bus: %s\n", bus->name); indent += 2; qdev_printf("type %s\n", bus->info->name); - QLIST_FOREACH(dev, &bus->children, sibling) { + QTAILQ_FOREACH(dev, &bus->children, sibling) { qdev_print(mon, dev, indent); } } diff --git a/hw/qdev.h b/hw/qdev.h index a44060e..53f5565 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -41,9 +41,9 @@ struct DeviceState { qemu_irq *gpio_out; int num_gpio_in; qemu_irq *gpio_in; - QLIST_HEAD(, BusState) child_bus; + QTAILQ_HEAD(, BusState) child_bus; int num_child_bus; - QLIST_ENTRY(DeviceState) sibling; + QTAILQ_ENTRY(DeviceState) sibling; int instance_id_alias; int alias_required_for_version; }; @@ -62,8 +62,8 @@ struct BusState { const char *name; int allow_hotplug; int qdev_allocated; - QLIST_HEAD(, DeviceState) children; - QLIST_ENTRY(BusState) sibling; + QTAILQ_HEAD(, DeviceState) children; + QTAILQ_ENTRY(BusState) sibling; }; struct Property { diff --git a/hw/ssi.c b/hw/ssi.c index cfe7c07..2c18436 100644 --- a/hw/ssi.c +++ b/hw/ssi.c @@ -25,8 +25,8 @@ static int ssi_slave_init(DeviceState *dev, DeviceInfo *base_info) SSIBus *bus; bus = FROM_QBUS(SSIBus, qdev_get_parent_bus(dev)); - if (QLIST_FIRST(&bus->qbus.children) != dev - || QLIST_NEXT(dev, sibling) != NULL) { + if (QTAILQ_FIRST(&bus->qbus.children) != dev + || QTAILQ_NEXT(dev, sibling) != NULL) { hw_error("Too many devices on SSI bus"); } @@ -61,7 +61,7 @@ uint32_t ssi_transfer(SSIBus *bus, uint32_t val) { DeviceState *dev; SSISlave *slave; - dev = QLIST_FIRST(&bus->qbus.children); + dev = QTAILQ_FIRST(&bus->qbus.children); if (!dev) { return 0; }