summary refs log tree commit diff stats
path: root/hw/usb.c
diff options
context:
space:
mode:
authorAnthony Liguori <aliguori@us.ibm.com>2011-09-08 08:57:33 -0500
committerAnthony Liguori <aliguori@us.ibm.com>2011-09-08 08:57:33 -0500
commita60fce0bcc193c37c92972b8217341d81f7a9860 (patch)
tree57f7977faa534d05d969d5e4a23154d8381866ae /hw/usb.c
parent63236c15e93e18d37ce657171a42af1f809d0aa6 (diff)
parent5b1cdb4ead0b3d2190492fce0a17e809ef915f26 (diff)
downloadfocaccia-qemu-a60fce0bcc193c37c92972b8217341d81f7a9860.tar.gz
focaccia-qemu-a60fce0bcc193c37c92972b8217341d81f7a9860.zip
Merge remote-tracking branch 'kraxel/usb.26' into staging
Diffstat (limited to 'hw/usb.c')
-rw-r--r--hw/usb.c37
1 files changed, 17 insertions, 20 deletions
diff --git a/hw/usb.c b/hw/usb.c
index 685e775a00..fa90204c5e 100644
--- a/hw/usb.c
+++ b/hw/usb.c
@@ -27,26 +27,23 @@
 #include "usb.h"
 #include "iov.h"
 
-void usb_attach(USBPort *port, USBDevice *dev)
+void usb_attach(USBPort *port)
 {
-    if (dev != NULL) {
-        /* attach */
-        if (port->dev) {
-            usb_attach(port, NULL);
-        }
-        dev->port = port;
-        port->dev = dev;
-        port->ops->attach(port);
-        usb_send_msg(dev, USB_MSG_ATTACH);
-    } else {
-        /* detach */
-        dev = port->dev;
-        assert(dev);
-        port->ops->detach(port);
-        usb_send_msg(dev, USB_MSG_DETACH);
-        dev->port = NULL;
-        port->dev = NULL;
-    }
+    USBDevice *dev = port->dev;
+
+    assert(dev != NULL);
+    assert(dev->attached);
+    port->ops->attach(port);
+    usb_send_msg(dev, USB_MSG_ATTACH);
+}
+
+void usb_detach(USBPort *port)
+{
+    USBDevice *dev = port->dev;
+
+    assert(dev != NULL);
+    port->ops->detach(port);
+    usb_send_msg(dev, USB_MSG_DETACH);
 }
 
 void usb_wakeup(USBDevice *dev)
@@ -338,8 +335,8 @@ 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->port, p);
     p->owner = NULL;
+    dev->port->ops->complete(dev->port, p);
 }
 
 /* Cancel an active packet.  The packed must have been deferred by