From mboxrd@z Thu Jan 1 00:00:00 1970 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 From: Gerd Hoffmann 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> Subject: [Qemu-devel] [PATCH v4 31/32] usb: rewrite fw path, fix numbering List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gerd Hoffmann 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); -} -- 1.7.1