From patchwork Tue Aug 25 09:49:58 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 32031 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 2CA1CB7B60 for ; Tue, 25 Aug 2009 19:51:21 +1000 (EST) Received: from localhost ([127.0.0.1]:59463 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MfsgN-0005Yv-Oz for incoming@patchwork.ozlabs.org; Tue, 25 Aug 2009 05:51:15 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mfsfc-0005XY-RA for qemu-devel@nongnu.org; Tue, 25 Aug 2009 05:50:28 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MfsfX-0005Qj-U3 for qemu-devel@nongnu.org; Tue, 25 Aug 2009 05:50:28 -0400 Received: from [199.232.76.173] (port=38088 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MfsfX-0005QU-Ll for qemu-devel@nongnu.org; Tue, 25 Aug 2009 05:50:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:28172) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MfsfX-0002JD-1C for qemu-devel@nongnu.org; Tue, 25 Aug 2009 05:50:23 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n7P9oLmb016541 for ; Tue, 25 Aug 2009 05:50:21 -0400 Received: from zweiblum.home.kraxel.org (vpn2-8-228.ams2.redhat.com [10.36.8.228]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id n7P9oDsZ032504; Tue, 25 Aug 2009 05:50:16 -0400 Received: by zweiblum.home.kraxel.org (Postfix, from userid 500) id A495C700D9; Tue, 25 Aug 2009 11:50:01 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Tue, 25 Aug 2009 11:49:58 +0200 Message-Id: <1251193798-14984-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH] qdev: switch device and bus lists from LIST to TAILQ 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 Tail queues allow to append elements to the tail if the list. That way we can maintain the ordering, i.e. devices/busses created first are also first in the list. Signed-off-by: Gerd Hoffmann --- hw/i2c.c | 2 +- hw/qdev.c | 32 ++++++++++++++++---------------- hw/qdev.h | 8 ++++---- hw/ssi.c | 6 +++--- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/hw/i2c.c b/hw/i2c.c index 7a1b358..6f827fc 100644 --- a/hw/i2c.c +++ b/hw/i2c.c @@ -76,7 +76,7 @@ int i2c_start_transfer(i2c_bus *bus, int address, int recv) DeviceState *qdev; i2c_slave *slave = NULL; - LIST_FOREACH(qdev, &bus->qbus.children, sibling) { + TAILQ_FOREACH(qdev, &bus->qbus.children, sibling) { slave = I2C_SLAVE_FROM_QDEV(qdev); if (slave->address == address) break; diff --git a/hw/qdev.c b/hw/qdev.c index c1a7779..479a7bf 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -101,7 +101,7 @@ DeviceState *qdev_create(BusState *bus, const char *name) qdev_prop_set_defaults(dev, dev->info->props); qdev_prop_set_defaults(dev, dev->parent_bus->info->props); qdev_prop_set_compat(dev); - LIST_INSERT_HEAD(&bus->children, dev, sibling); + TAILQ_INSERT_TAIL(&bus->children, dev, sibling); return dev; } @@ -214,7 +214,7 @@ void qdev_init(DeviceState *dev) /* Unlink device from bus and free the structure. */ void qdev_free(DeviceState *dev) { - LIST_REMOVE(dev, sibling); + TAILQ_REMOVE(&dev->parent_bus->children, dev, sibling); qemu_free(dev); } @@ -300,7 +300,7 @@ BusState *qdev_get_child_bus(DeviceState *dev, const char *name) { BusState *bus; - LIST_FOREACH(bus, &dev->child_bus, sibling) { + TAILQ_FOREACH(bus, &dev->child_bus, sibling) { if (strcmp(name, bus->name) == 0) { return bus; } @@ -344,8 +344,8 @@ static BusState *qbus_find_recursive(BusState *bus, const char *name, return bus; } - LIST_FOREACH(dev, &bus->children, sibling) { - LIST_FOREACH(child, &dev->child_bus, sibling) { + TAILQ_FOREACH(dev, &bus->children, sibling) { + TAILQ_FOREACH(child, &dev->child_bus, sibling) { ret = qbus_find_recursive(child, name, info); if (ret) { return ret; @@ -363,7 +363,7 @@ static void qbus_list_bus(DeviceState *dev, char *dest, int len) pos += snprintf(dest+pos, len-pos,"child busses at \"%s\":", dev->id ? dev->id : dev->info->name); - LIST_FOREACH(child, &dev->child_bus, sibling) { + TAILQ_FOREACH(child, &dev->child_bus, sibling) { pos += snprintf(dest+pos, len-pos, "%s\"%s\"", sep, child->name); sep = ", "; } @@ -377,7 +377,7 @@ static void qbus_list_dev(BusState *bus, char *dest, int len) pos += snprintf(dest+pos, len-pos, "devices at \"%s\":", bus->name); - LIST_FOREACH(dev, &bus->children, sibling) { + TAILQ_FOREACH(dev, &bus->children, sibling) { pos += snprintf(dest+pos, len-pos, "%s\"%s\"", sep, dev->info->name); if (dev->id) @@ -390,7 +390,7 @@ static BusState *qbus_find_bus(DeviceState *dev, char *elem) { BusState *child; - LIST_FOREACH(child, &dev->child_bus, sibling) { + TAILQ_FOREACH(child, &dev->child_bus, sibling) { if (strcmp(child->name, elem) == 0) { return child; } @@ -408,17 +408,17 @@ static DeviceState *qbus_find_dev(BusState *bus, char *elem) * (2) driver name * (3) driver alias, if present */ - LIST_FOREACH(dev, &bus->children, sibling) { + TAILQ_FOREACH(dev, &bus->children, sibling) { if (dev->id && strcmp(dev->id, elem) == 0) { return dev; } } - LIST_FOREACH(dev, &bus->children, sibling) { + TAILQ_FOREACH(dev, &bus->children, sibling) { if (strcmp(dev->info->name, elem) == 0) { return dev; } } - LIST_FOREACH(dev, &bus->children, sibling) { + TAILQ_FOREACH(dev, &bus->children, sibling) { if (dev->info->alias && strcmp(dev->info->alias, elem) == 0) { return dev; } @@ -476,7 +476,7 @@ static BusState *qbus_find(const char *path) fprintf(stderr, "device has no child bus (%s)\n", path); return NULL; case 1: - return LIST_FIRST(&dev->child_bus); + return TAILQ_FIRST(&dev->child_bus); default: qbus_list_bus(dev, msg, sizeof(msg)); fprintf(stderr, "device has multiple child busses (%s)\n%s\n", @@ -530,9 +530,9 @@ BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name) bus->name = buf; } - LIST_INIT(&bus->children); + TAILQ_INIT(&bus->children); if (parent) { - LIST_INSERT_HEAD(&parent->child_bus, bus, sibling); + TAILQ_INSERT_HEAD(&parent->child_bus, bus, sibling); parent->num_child_bus++; } return bus; @@ -573,7 +573,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); - LIST_FOREACH(child, &dev->child_bus, sibling) { + TAILQ_FOREACH(child, &dev->child_bus, sibling) { qbus_print(mon, child, indent); } } @@ -585,7 +585,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); - LIST_FOREACH(dev, &bus->children, sibling) { + TAILQ_FOREACH(dev, &bus->children, sibling) { qdev_print(mon, dev, indent); } } diff --git a/hw/qdev.h b/hw/qdev.h index 204c4e5..1be5133 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -29,10 +29,10 @@ struct DeviceState { qemu_irq *gpio_out; int num_gpio_in; qemu_irq *gpio_in; - LIST_HEAD(, BusState) child_bus; + TAILQ_HEAD(, BusState) child_bus; int num_child_bus; NICInfo *nd; - LIST_ENTRY(DeviceState) sibling; + TAILQ_ENTRY(DeviceState) sibling; }; typedef void (*bus_dev_printfn)(Monitor *mon, DeviceState *dev, int indent); @@ -47,8 +47,8 @@ struct BusState { DeviceState *parent; BusInfo *info; const char *name; - LIST_HEAD(, DeviceState) children; - LIST_ENTRY(BusState) sibling; + TAILQ_HEAD(, DeviceState) children; + TAILQ_ENTRY(BusState) sibling; }; struct Property { diff --git a/hw/ssi.c b/hw/ssi.c index a5133be..7e92579 100644 --- a/hw/ssi.c +++ b/hw/ssi.c @@ -25,8 +25,8 @@ static void ssi_slave_init(DeviceState *dev, DeviceInfo *base_info) SSIBus *bus; bus = FROM_QBUS(SSIBus, qdev_get_parent_bus(dev)); - if (LIST_FIRST(&bus->qbus.children) != dev - || LIST_NEXT(dev, sibling) != NULL) { + if (TAILQ_FIRST(&bus->qbus.children) != dev + || TAILQ_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 = LIST_FIRST(&bus->qbus.children); + dev = TAILQ_FIRST(&bus->qbus.children); if (!dev) { return 0; }