From patchwork Sun Nov 14 15:39:36 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gleb Natapov X-Patchwork-Id: 71128 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 28BA0B710C for ; Mon, 15 Nov 2010 02:50:06 +1100 (EST) Received: from localhost ([127.0.0.1]:51946 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PHeq9-0003zs-O3 for incoming@patchwork.ozlabs.org; Sun, 14 Nov 2010 10:50:01 -0500 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 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 oAEFdhb6002262 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 14 Nov 2010 10:39:44 -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 oAEFdhW5010654; Sun, 14 Nov 2010 10:39:43 -0500 Received: by dhcp-1-237.tlv.redhat.com (Postfix, from userid 13519) id 87AAD133A0B; Sun, 14 Nov 2010 17:39:41 +0200 (IST) From: Gleb Natapov To: qemu-devel@nongnu.org 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> 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: kvm@vger.kernel.org, mst@redhat.com, armbru@redhat.com, blauwirbel@gmail.com, alex.williamson@redhat.com, kevin@koconnor.net Subject: [Qemu-devel] [PATCHv4 10/15] Add get_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); +}