From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MLZbX-0008Iz-UV for qemu-devel@nongnu.org; Tue, 30 Jun 2009 05:26:20 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MLZbU-0008Fw-7B for qemu-devel@nongnu.org; Tue, 30 Jun 2009 05:26:19 -0400 Received: from [199.232.76.173] (port=57909 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MLZbS-0008F6-Hd for qemu-devel@nongnu.org; Tue, 30 Jun 2009 05:26:14 -0400 Received: from mx2.redhat.com ([66.187.237.31]:44729) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MLZbR-0001w8-RD for qemu-devel@nongnu.org; Tue, 30 Jun 2009 05:26:14 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n5U9QD9c005993 for ; Tue, 30 Jun 2009 05:26:13 -0400 From: Gerd Hoffmann Date: Tue, 30 Jun 2009 11:25:58 +0200 Message-Id: <1246353962-32308-5-git-send-email-kraxel@redhat.com> In-Reply-To: <1246353962-32308-1-git-send-email-kraxel@redhat.com> References: <1246353962-32308-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH 4/8] qdev/core: bus list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gerd Hoffmann * maintain a list of busses. * maintain bus numbers. * add function to find busses by type / name / number. * add monitor command to list busses. Use case for the bus list is hot-plugging devices via monitor, where qemu needs some way to find the bus specified in the monitor command. The usb patches in the patch queue make use of this. Signed-off-by: Gerd Hoffmann --- hw/qdev.c | 41 ++++++++++++++++++++++++++++++++++++++++- hw/qdev.h | 5 +++++ monitor.c | 2 ++ 3 files changed, 47 insertions(+), 1 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index 3dc7076..1fb73b1 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -306,22 +306,50 @@ void scsi_bus_new(DeviceState *host, SCSIAttachFn attach) attach(host, drives_table[index].bdrv, unit); } } +static TAILQ_HEAD(, BusState) buslist = TAILQ_HEAD_INITIALIZER(buslist); BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name) { BusState *bus; + char buf[32]; + int i; bus = qemu_mallocz(info->size); bus->info = info; + bus->busnr = info->next_busnr++; bus->parent = parent; + if (!name) { + /* default name: lowercase(type) + busnr, i.e. "scsi0" */ + snprintf(buf, sizeof(buf), "%s%d", info->name, bus->busnr); + for (i = 0; buf[i]; i++) + buf[i] = tolower(buf[i]); + name = buf; + } bus->name = qemu_strdup(name); LIST_INIT(&bus->children); if (parent) { LIST_INSERT_HEAD(&parent->child_bus, bus, sibling); } + TAILQ_INSERT_TAIL(&buslist, bus, next); return bus; } +BusState *qbus_find(const char *type, const char *name, int busnr) +{ + BusState *bus; + + TAILQ_FOREACH(bus, &buslist, next) { + if (type && strcmp(type, bus->info->name) != 0) + continue; + if (name && strcmp(name, bus->name) != 0) + continue; + if (busnr != -1 && busnr != bus->busnr) + continue; + return bus; + } + return NULL; +} + #define qdev_printf(fmt, ...) monitor_printf(mon, "%*s" fmt, indent, "", ## __VA_ARGS__) static void qbus_print(Monitor *mon, BusState *bus, int indent); @@ -368,7 +396,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); + qdev_printf("type %s, nr %d\n", bus->info->name, bus->busnr); LIST_FOREACH(dev, &bus->children, sibling) { qdev_print(mon, dev, indent); } @@ -380,3 +408,14 @@ void do_info_qtree(Monitor *mon) if (main_system_bus) qbus_print(mon, main_system_bus, 0); } + +void do_info_qbus(Monitor *mon) +{ + BusState *bus; + + TAILQ_FOREACH(bus, &buslist, next) { + monitor_printf(mon, "%s: type %s, nr %d, parent %s\n", + bus->name, bus->info->name, bus->busnr, + bus->parent ? bus->parent->info->name : ""); + } +} diff --git a/hw/qdev.h b/hw/qdev.h index 18321b3..c4b04c1 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -32,14 +32,17 @@ struct BusInfo { const char *name; size_t size; bus_dev_print print; + int next_busnr; }; struct BusState { DeviceState *parent; BusInfo *info; + int busnr; const char *name; LIST_HEAD(, DeviceState) children; LIST_ENTRY(BusState) sibling; + TAILQ_ENTRY(BusState) next; }; /*** Board API. This should go away once we have a machine config file. ***/ @@ -117,11 +120,13 @@ void *qdev_get_prop_ptr(DeviceState *dev, const char *name); /*** BUS API. ***/ BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name); +BusState *qbus_find(const char *type, const char *name, int busnr); #define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev) /*** monitor commands ***/ void do_info_qtree(Monitor *mon); +void do_info_qbus(Monitor *mon); #endif diff --git a/monitor.c b/monitor.c index bad79fe..39ce99f 100644 --- a/monitor.c +++ b/monitor.c @@ -1759,6 +1759,8 @@ static const mon_cmd_t info_cmds[] = { "", "show balloon information" }, { "qtree", "", do_info_qtree, "", "show device tree" }, + { "qbus", "", do_info_qbus, + "", "show qdev bus list" }, { NULL, NULL, }, }; -- 1.6.2.5