summaryrefslogtreecommitdiff
path: root/hw/usb.c
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2011-05-12 13:48:13 +0200
committerGerd Hoffmann <kraxel@redhat.com>2011-05-26 11:55:03 +0200
commit4ff658fb6c4f1cb7f771b16f808547e4f5767d02 (patch)
treeef76e89e2fe1e8a710876f96de06eb104a6000da /hw/usb.c
parent53aa8c0e2af473050fa765533a8d69f3450788ab (diff)
usb: keep track of packet owner.
Keep track of the device which owns the usb packet for async processing. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'hw/usb.c')
-rw-r--r--hw/usb.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/hw/usb.c b/hw/usb.c
index 966cb0ff9e..8a9a7fcb25 100644
--- a/hw/usb.c
+++ b/hw/usb.c
@@ -313,6 +313,38 @@ int usb_handle_packet(USBDevice *dev, USBPacket *p)
{
int ret;
+ assert(p->owner == NULL);
ret = dev->info->handle_packet(dev, p);
+ if (ret == USB_RET_ASYNC) {
+ if (p->owner == NULL) {
+ p->owner = dev;
+ } else {
+ /* We'll end up here when usb_handle_packet is called
+ * recursively due to a hub being in the chain. Nothing
+ * to do. Leave p->owner pointing to the device, not the
+ * hub. */;
+ }
+ }
return ret;
}
+
+/* Notify the controller that an async packet is complete. This should only
+ be called for packets previously deferred by returning USB_RET_ASYNC from
+ handle_packet. */
+void usb_packet_complete(USBDevice *dev, USBPacket *p)
+{
+ /* Note: p->owner != dev is possible in case dev is a hub */
+ assert(p->owner != NULL);
+ dev->port->ops->complete(dev, p);
+ p->owner = NULL;
+}
+
+/* Cancel an active packet. The packed must have been deferred by
+ returning USB_RET_ASYNC from handle_packet, and not yet
+ completed. */
+void usb_cancel_packet(USBPacket * p)
+{
+ assert(p->owner != NULL);
+ p->cancel_cb(p, p->cancel_opaque);
+ p->owner = NULL;
+}