From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=53731 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PHegK-0006ty-1E for qemu-devel@nongnu.org; Sun, 14 Nov 2010 10:39:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PHegF-0000au-GR for qemu-devel@nongnu.org; Sun, 14 Nov 2010 10:39:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51133) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PHegF-0000aL-8t for qemu-devel@nongnu.org; Sun, 14 Nov 2010 10:39:47 -0500 From: Gleb Natapov Date: Sun, 14 Nov 2010 17:39:36 +0200 Message-Id: <1289749181-12070-11-git-send-email-gleb@redhat.com> In-Reply-To: <1289749181-12070-1-git-send-email-gleb@redhat.com> References: <1289749181-12070-1-git-send-email-gleb@redhat.com> Subject: [Qemu-devel] [PATCHv4 10/15] Add get_dev_path callback for usb bus. List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, mst@redhat.com, armbru@redhat.com, blauwirbel@gmail.com, alex.williamson@redhat.com, kevin@koconnor.net Signed-off-by: Gleb Natapov --- hw/usb-bus.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 42 insertions(+), 0 deletions(-) diff --git a/hw/usb-bus.c b/hw/usb-bus.c index 256b881..8b4583c 100644 --- a/hw/usb-bus.c +++ b/hw/usb-bus.c @@ -5,11 +5,13 @@ #include "monitor.h" static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent); +static char *usbbus_get_fw_dev_path(DeviceState *dev); static struct BusInfo usb_bus_info = { .name = "USB", .size = sizeof(USBBus), .print_dev = usb_bus_dev_print, + .get_fw_dev_path = usbbus_get_fw_dev_path, }; static int next_usb_bus = 0; static QTAILQ_HEAD(, USBBus) busses = QTAILQ_HEAD_INITIALIZER(busses); @@ -307,3 +309,43 @@ 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