From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=56239 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PcylB-0006Hs-Vh for qemu-devel@nongnu.org; Wed, 12 Jan 2011 06:21:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pcyl8-0001dm-SU for qemu-devel@nongnu.org; Wed, 12 Jan 2011 06:21:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:1025) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pcyl8-0001dN-J0 for qemu-devel@nongnu.org; Wed, 12 Jan 2011 06:20:58 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id p0CBKvN4014449 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 12 Jan 2011 06:20:58 -0500 From: Gerd Hoffmann Date: Wed, 12 Jan 2011 12:20:12 +0100 Message-Id: <1294831214-4499-31-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 30/32] usb: add port property. 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 allows to explictily set the physical port where you want to plug the usb device. Example: -device usb-tablet,bus=usb.0,port=2 With explicit port addressing qemu can and will not automagically add USB Hubs. This means that: (a) You can plug two devices of your choice into the two uhci root ports. (b) If you want plug in more that two devices you have to care about adding a hub yourself. Plugging a hub works this way: -device usb-hub,bus=usb.0,port=1 Use this to add a device to the hub: -device usb-tablet,bus=usb.0,port=1.1 Signed-off-by: Gerd Hoffmann --- hw/usb-bus.c | 26 ++++++++++++++++++++++---- hw/usb.h | 1 + 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/hw/usb-bus.c b/hw/usb-bus.c index 0cb03c9..1f59f9a 100644 --- a/hw/usb-bus.c +++ b/hw/usb-bus.c @@ -15,6 +15,10 @@ static struct BusInfo usb_bus_info = { .print_dev = usb_bus_dev_print, .get_dev_path = usb_get_dev_path, .get_fw_dev_path = usbbus_get_fw_dev_path, + .props = (Property[]) { + DEFINE_PROP_STRING("port", USBDevice, port_path), + DEFINE_PROP_END_OF_LIST() + }, }; static int next_usb_bus = 0; static QTAILQ_HEAD(, USBBus) busses = QTAILQ_HEAD_INITIALIZER(busses); @@ -157,9 +161,22 @@ static void do_attach(USBDevice *dev) dev->product_desc); return; } - dev->attached++; + if (dev->port_path) { + QTAILQ_FOREACH(port, &bus->free, next) { + if (strcmp(port->path, dev->port_path) == 0) { + break; + } + } + if (port == NULL) { + fprintf(stderr, "Warning: usb port %s (bus %s) not found\n", + dev->port_path, bus->qbus.name); + return; + } + } else { + port = QTAILQ_FIRST(&bus->free); + } - port = QTAILQ_FIRST(&bus->free); + dev->attached++; QTAILQ_REMOVE(&bus->free, port, next); bus->nfree--; @@ -173,8 +190,9 @@ int usb_device_attach(USBDevice *dev) { USBBus *bus = usb_bus_from_device(dev); - if (bus->nfree == 1) { - /* Create a new hub and chain it on. */ + if (bus->nfree == 1 && dev->port_path == NULL) { + /* Create a new hub and chain it on + (unless a physical port location is specified). */ usb_create_simple(bus, "usb-hub"); } do_attach(dev); diff --git a/hw/usb.h b/hw/usb.h index 8fdda29..c6e3e25 100644 --- a/hw/usb.h +++ b/hw/usb.h @@ -156,6 +156,7 @@ struct USBDevice { DeviceState qdev; USBDeviceInfo *info; USBPort *port; + char *port_path; void *opaque; int speed; -- 1.7.1