[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 30/30] usb: add port property.
From: |
Gerd Hoffmann |
Subject: |
[Qemu-devel] [PATCH 30/30] usb: add port property. |
Date: |
Fri, 17 Dec 2010 12:26:46 +0100 |
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 <address@hidden>
---
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 cfed593..b0ddf04 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -12,6 +12,10 @@ static struct BusInfo usb_bus_info = {
.size = sizeof(USBBus),
.print_dev = usb_bus_dev_print,
.get_dev_path = usb_get_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);
@@ -151,9 +155,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--;
@@ -167,8 +184,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 08bcd1c..5c1da3e 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
- [Qemu-devel] [PATCH 27/30] usb storage: fix status reporting, (continued)
- [Qemu-devel] [PATCH 27/30] usb storage: fix status reporting, Gerd Hoffmann, 2010/12/17
- [Qemu-devel] [PATCH 28/30] usb storage: handle long responses, Gerd Hoffmann, 2010/12/17
- [Qemu-devel] [PATCH 24/30] usb: add usb_desc_attach, Gerd Hoffmann, 2010/12/17
- [Qemu-devel] [PATCH 16/30] usb: rework attach/detach workflow, Gerd Hoffmann, 2010/12/17
- [Qemu-devel] [PATCH 22/30] usb: add speed mask to ports, Gerd Hoffmann, 2010/12/17
- [Qemu-devel] [PATCH 26/30] usb storage: high speed support, Gerd Hoffmann, 2010/12/17
- [Qemu-devel] [PATCH 23/30] usb: add attach callback, Gerd Hoffmann, 2010/12/17
- [Qemu-devel] [PATCH 25/30] usb: add device qualifier support, Gerd Hoffmann, 2010/12/17
- [Qemu-devel] [PATCH 18/30] usb: uhci: remote wakeup support., Gerd Hoffmann, 2010/12/17
- [Qemu-devel] [PATCH 29/30] usb: keep track of physical port address., Gerd Hoffmann, 2010/12/17
- [Qemu-devel] [PATCH 30/30] usb: add port property.,
Gerd Hoffmann <=