qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 04/25] usb: add usb_find_device()


From: Gerd Hoffmann
Subject: [Qemu-devel] [PATCH 04/25] usb: add usb_find_device()
Date: Mon, 23 Jan 2012 15:54:50 +0100

Add usb_find_device().  This function will check whenever a device with
a specific address is connected to the specified port.  Usually this
will just check state and address of the device hooked up to the port,
but in case of a hub it will ask the hub to check all hub ports for a
matching device.

This patch doesn't put the code into use yet, see the following patches
for details.

The master plan is to separate device lookup and packet processing.
Right now the usb code simply walks all devices, calls
usb_handle_packet() on each until one accepts the packet (by returning
something different that USB_RET_NODEV).  I want to have a device lookup
first, then call usb_handle_packet() once, for the device which actually
processes the packet.

Signed-off-by: Gerd Hoffmann <address@hidden>
---
 hw/usb.c |   16 ++++++++++++++++
 hw/usb.h |    8 ++++++++
 2 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/hw/usb.c b/hw/usb.c
index a6eea99..5482c92 100644
--- a/hw/usb.c
+++ b/hw/usb.c
@@ -299,6 +299,22 @@ int set_usb_string(uint8_t *buf, const char *str)
     return q - buf;
 }
 
+USBDevice *usb_find_device(USBPort *port, uint8_t addr)
+{
+    USBDevice *dev = port->dev;
+
+    if (dev == NULL || !dev->attached || dev->state != USB_STATE_DEFAULT) {
+        return NULL;
+    }
+    if (dev->addr == addr) {
+        return dev;
+    }
+    if (dev->info->find_device) {
+        return dev->info->find_device(dev, addr);
+    }
+    return NULL;
+}
+
 /* Hand over a packet to a device for processing.  Return value
    USB_RET_ASYNC indicates the processing isn't finished yet, the
    driver will call usb_packet_complete() when done processing it. */
diff --git a/hw/usb.h b/hw/usb.h
index b1afea3..b0ba3e0 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -219,6 +219,12 @@ struct USBDeviceInfo {
     int (*init)(USBDevice *dev);
 
     /*
+     * Walk (enabled) downstream ports, check for a matching device.
+     * Only hubs implement this.
+     */
+    USBDevice *(*find_device)(USBDevice *dev, uint8_t addr);
+
+    /*
      * Process USB packet.
      * Called by the HC (Host Controller).
      *
@@ -326,6 +332,8 @@ void usb_packet_copy(USBPacket *p, void *ptr, size_t bytes);
 void usb_packet_skip(USBPacket *p, size_t bytes);
 void usb_packet_cleanup(USBPacket *p);
 
+USBDevice *usb_find_device(USBPort *port, uint8_t addr);
+
 int usb_handle_packet(USBDevice *dev, USBPacket *p);
 void usb_packet_complete(USBDevice *dev, USBPacket *p);
 void usb_cancel_packet(USBPacket * p);
-- 
1.7.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]