usb-hub: implement find_device
authorGerd Hoffmann <kraxel@redhat.com>
Tue, 10 Jan 2012 16:08:13 +0000 (17:08 +0100)
committerGerd Hoffmann <kraxel@redhat.com>
Fri, 10 Feb 2012 10:31:57 +0000 (11:31 +0100)
Implement the find_device callback for the usb hub.  It'll loop over all
ports, calling usb_find_device for all enabled ports until it finds a
matching device.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
hw/usb-hub.c

index 0f3b2dda0e87e3fb43fc060e645728d3838a638f..bd7641c4bf00ea8e633bfb489b3eee384d9e00b1 100644 (file)
@@ -220,6 +220,26 @@ static void usb_hub_complete(USBPort *port, USBPacket *packet)
     s->dev.port->ops->complete(s->dev.port, packet);
 }
 
+static USBDevice *usb_hub_find_device(USBDevice *dev, uint8_t addr)
+{
+    USBHubState *s = DO_UPCAST(USBHubState, dev, dev);
+    USBHubPort *port;
+    USBDevice *downstream;
+    int i;
+
+    for (i = 0; i < NUM_PORTS; i++) {
+        port = &s->ports[i];
+        if (!(port->wPortStatus & PORT_STAT_ENABLE)) {
+            continue;
+        }
+        downstream = usb_find_device(&port->port, addr);
+        if (downstream != NULL) {
+            return downstream;
+        }
+    }
+    return NULL;
+}
+
 static void usb_hub_handle_reset(USBDevice *dev)
 {
     USBHubState *s = DO_UPCAST(USBHubState, dev, dev);
@@ -541,6 +561,7 @@ static void usb_hub_class_initfn(ObjectClass *klass, void *data)
     uc->init           = usb_hub_initfn;
     uc->product_desc   = "QEMU USB Hub";
     uc->usb_desc       = &desc_hub;
+    uc->find_device    = usb_hub_find_device;
     uc->handle_packet  = usb_hub_handle_packet;
     uc->handle_reset   = usb_hub_handle_reset;
     uc->handle_control = usb_hub_handle_control;