From patchwork Wed Jan 12 11:20:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 78573 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 73182B6F1E for ; Thu, 13 Jan 2011 00:38:35 +1100 (EST) Received: from localhost ([127.0.0.1]:54092 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PczEq-0007Rb-CZ for incoming@patchwork.ozlabs.org; Wed, 12 Jan 2011 06:51:40 -0500 Received: from [140.186.70.92] (port=56116 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pcyl4-0006BL-HF for qemu-devel@nongnu.org; Wed, 12 Jan 2011 06:20:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pcyl1-0001ah-Ue for qemu-devel@nongnu.org; Wed, 12 Jan 2011 06:20:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43969) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pcyl1-0001aQ-Ly for qemu-devel@nongnu.org; Wed, 12 Jan 2011 06:20:51 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id p0CBKoXk009265 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 12 Jan 2011 06:20:50 -0500 Received: from rincewind.home.kraxel.org (vpn2-8-125.ams2.redhat.com [10.36.8.125]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p0CBKjHR015135; Wed, 12 Jan 2011 06:20:47 -0500 Received: by rincewind.home.kraxel.org (Postfix, from userid 500) id 7BAD741635; Wed, 12 Jan 2011 12:20:16 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Wed, 12 Jan 2011 12:20:13 +0100 Message-Id: <1294831214-4499-32-git-send-email-kraxel@redhat.com> In-Reply-To: <1294831214-4499-1-git-send-email-kraxel@redhat.com> References: <1294831214-4499-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH v4 31/32] usb: rewrite fw path, fix numbering 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 This patch rewrites the firmware path code to use the physical port location tracking just added to the qemu usb core. It also fixes the port numbering to start with "1" in the firmware path. Signed-off-by: Gerd Hoffmann --- hw/usb-bus.c | 68 ++++++++++++++++++++++----------------------------------- 1 files changed, 26 insertions(+), 42 deletions(-) diff --git a/hw/usb-bus.c b/hw/usb-bus.c index 1f59f9a..f89176b 100644 --- a/hw/usb-bus.c +++ b/hw/usb-bus.c @@ -7,14 +7,14 @@ static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent); static char *usb_get_dev_path(DeviceState *dev); -static char *usbbus_get_fw_dev_path(DeviceState *dev); +static char *usb_get_fw_dev_path(DeviceState *qdev); static struct BusInfo usb_bus_info = { .name = "USB", .size = sizeof(USBBus), .print_dev = usb_bus_dev_print, .get_dev_path = usb_get_dev_path, - .get_fw_dev_path = usbbus_get_fw_dev_path, + .get_fw_dev_path = usb_get_fw_dev_path, .props = (Property[]) { DEFINE_PROP_STRING("port", USBDevice, port_path), DEFINE_PROP_END_OF_LIST() @@ -279,6 +279,30 @@ static char *usb_get_dev_path(DeviceState *qdev) return qemu_strdup(dev->port->path); } +static char *usb_get_fw_dev_path(DeviceState *qdev) +{ + USBDevice *dev = DO_UPCAST(USBDevice, qdev, qdev); + char *fw_path, *in; + int pos = 0; + long nr; + + fw_path = qemu_malloc(32 + strlen(dev->port->path) * 6); + in = dev->port->path; + while (true) { + nr = strtol(in, &in, 10); + if (in[0] == '.') { + /* some hub between root port and device */ + pos += sprintf(fw_path + pos, "hub@%ld/", nr); + in++; + } else { + /* the device itself */ + pos += sprintf(fw_path + pos, "%s@%ld", qdev_fw_name(qdev), nr); + break; + } + } + return fw_path; +} + void usb_info(Monitor *mon) { USBBus *bus; @@ -351,43 +375,3 @@ USBDevice *usbdevice_create(const char *cmdline) } return usb->usbdevice_init(params); } - -static int usbbus_get_fw_dev_path_helper(USBDevice *d, USBBus *bus, char *p, - int len) -{ - int l = 0; - USBPort *port; - - QTAILQ_FOREACH(port, &bus->used, next) { - if (port->dev == d) { - if (port->pdev) { - l = usbbus_get_fw_dev_path_helper(port->pdev, bus, p, len); - } - l += snprintf(p + l, len - l, "%s@%x/", qdev_fw_name(&d->qdev), - port->index); - break; - } - } - - return l; -} - -static char *usbbus_get_fw_dev_path(DeviceState *dev) -{ - USBDevice *d = (USBDevice*)dev; - USBBus *bus = usb_bus_from_device(d); - char path[100]; - int l; - - assert(d->attached != 0); - - l = usbbus_get_fw_dev_path_helper(d, bus, path, sizeof(path)); - - if (l == 0) { - abort(); - } - - path[l-1] = '\0'; - - return strdup(path); -}