From patchwork Wed Dec 8 11:35:03 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gleb Natapov X-Patchwork-Id: 74689 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 F330DB6EF0 for ; Wed, 8 Dec 2010 23:12:49 +1100 (EST) Received: from localhost ([127.0.0.1]:35814 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQIt4-0005Vr-Py for incoming@patchwork.ozlabs.org; Wed, 08 Dec 2010 07:12:46 -0500 Received: from [140.186.70.92] (port=55975 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQIIw-0005aE-R9 for qemu-devel@nongnu.org; Wed, 08 Dec 2010 06:35:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PQIIp-0007Oz-Va for qemu-devel@nongnu.org; Wed, 08 Dec 2010 06:35:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:21823) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PQIIp-0007Oj-Nx for qemu-devel@nongnu.org; Wed, 08 Dec 2010 06:35:19 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oB8BZB6O006734 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 8 Dec 2010 06:35:12 -0500 Received: from dhcp-1-237.tlv.redhat.com (dhcp-1-237.tlv.redhat.com [10.35.1.237]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id oB8BZB98025615; Wed, 8 Dec 2010 06:35:11 -0500 Received: by dhcp-1-237.tlv.redhat.com (Postfix, from userid 13519) id E7E27137AA7; Wed, 8 Dec 2010 13:35:09 +0200 (IST) From: Gleb Natapov To: qemu-devel@nongnu.org Date: Wed, 8 Dec 2010 13:35:03 +0200 Message-Id: <1291808109-22563-11-git-send-email-gleb@redhat.com> In-Reply-To: <1291808109-22563-1-git-send-email-gleb@redhat.com> References: <1291808109-22563-1-git-send-email-gleb@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: blauwirbel@gmail.com, kevin@koconnor.net, kvm@vger.kernel.org Subject: [Qemu-devel] [PATCHv8 10/16] Add get_fw_dev_path callback for usb bus. 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 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); +}