]> git.proxmox.com Git - qemu.git/commitdiff
usb: fix port reset
authorGerd Hoffmann <kraxel@redhat.com>
Thu, 15 Sep 2011 10:10:21 +0000 (12:10 +0200)
committerGerd Hoffmann <kraxel@redhat.com>
Thu, 13 Oct 2011 10:58:51 +0000 (12:58 +0200)
commit 891fb2cd4592b6fe76106a69e0ca40efbf82726a removed the implicit
detach before (re-)attaching in usb_attach().  Some usb host controllers
used that behavior though to do a port reset by a detach+attach
sequence.

This patch establishes old behavior by adding a new usb_reset() function
for port resets and putting it into use, thereby also unifying port
reset behavior of all host controllers.  The patch also adds asserts to
usb_attach() and usb_detach() to make sure the calls are symmetrical.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
hw/usb-ehci.c
hw/usb-ohci.c
hw/usb-uhci.c
hw/usb.c
hw/usb.h

index 27376a2351b0d96490358ad2fe266643ba93a0d6..bd374c1de6f1243298485f7a72f1e01ab513fadc 100644 (file)
@@ -880,6 +880,7 @@ static void ehci_reset(void *opaque)
         }
         if (devs[i] && devs[i]->attached) {
             usb_attach(&s->ports[i]);
+            usb_send_msg(devs[i], USB_MSG_RESET);
         }
     }
     ehci_queues_rip_all(s);
@@ -978,8 +979,7 @@ static void handle_port_status_write(EHCIState *s, int port, uint32_t val)
     if (!(val & PORTSC_PRESET) &&(*portsc & PORTSC_PRESET)) {
         trace_usb_ehci_port_reset(port, 0);
         if (dev && dev->attached) {
-            usb_attach(&s->ports[port]);
-            usb_send_msg(dev, USB_MSG_RESET);
+            usb_reset(&s->ports[port]);
             *portsc &= ~PORTSC_CSC;
         }
 
index c3be65a2e9f34589331cbbdd6e61aa9af5522b77..5e10e21506d254c6b0a7f3effcc67f1811da323c 100644 (file)
@@ -449,7 +449,7 @@ static void ohci_reset(void *opaque)
         port = &ohci->rhport[i];
         port->ctrl = 0;
         if (port->port.dev && port->port.dev->attached) {
-            usb_attach(&port->port);
+            usb_reset(&port->port);
         }
       }
     if (ohci->async_td) {
index 17992cf003549e08e2555511e70d643d810ed725..171d7870b7c0621ab13703bd015a2b725463199c 100644 (file)
@@ -341,7 +341,7 @@ static void uhci_reset(void *opaque)
         port = &s->ports[i];
         port->ctrl = 0x0080;
         if (port->port.dev && port->port.dev->attached) {
-            usb_attach(&port->port);
+            usb_reset(&port->port);
         }
     }
 
index fa90204c5e121941b2c61d3c578c865025ebbc27..2216efe077a1f84075005d51ef75cc62261d75e3 100644 (file)
--- a/hw/usb.c
+++ b/hw/usb.c
@@ -33,6 +33,7 @@ void usb_attach(USBPort *port)
 
     assert(dev != NULL);
     assert(dev->attached);
+    assert(dev->state == USB_STATE_NOTATTACHED);
     port->ops->attach(port);
     usb_send_msg(dev, USB_MSG_ATTACH);
 }
@@ -42,10 +43,21 @@ void usb_detach(USBPort *port)
     USBDevice *dev = port->dev;
 
     assert(dev != NULL);
+    assert(dev->state != USB_STATE_NOTATTACHED);
     port->ops->detach(port);
     usb_send_msg(dev, USB_MSG_DETACH);
 }
 
+void usb_reset(USBPort *port)
+{
+    USBDevice *dev = port->dev;
+
+    assert(dev != NULL);
+    usb_detach(port);
+    usb_attach(port);
+    usb_send_msg(dev, USB_MSG_RESET);
+}
+
 void usb_wakeup(USBDevice *dev)
 {
     if (dev->remote_wakeup && dev->port && dev->port->ops->wakeup) {
index c08d46949651eb2183e0c6a51a59393037be8a9f..c6e1870e59acf70b0844e4495f68aa63a69320a6 100644 (file)
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -306,6 +306,7 @@ void usb_cancel_packet(USBPacket * p);
 
 void usb_attach(USBPort *port);
 void usb_detach(USBPort *port);
+void usb_reset(USBPort *port);
 void usb_wakeup(USBDevice *dev);
 int usb_generic_handle_packet(USBDevice *s, USBPacket *p);
 void usb_generic_async_ctrl_complete(USBDevice *s, USBPacket *p);