qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 05/28] usb: kill USB_MSG_RESET
Date: Fri, 10 Feb 2012 12:43:01 +0100	[thread overview]
Message-ID: <1328874204-20920-6-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1328874204-20920-1-git-send-email-kraxel@redhat.com>

The USB subsystem pipes internal reset notifications through
usb_handle_packet() with a special magic PID.  This indirection
is a pretty pointless excercise as it ends up being handled by
usb_generic_handle_packet anyway.

Replace the USB_MSG_RESET with a usb_device_reset() function
which can be called directly.  Also rename the existing usb_reset()
function to usb_port_reset() to avoid confusion.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/usb-ehci.c |    4 ++--
 hw/usb-hub.c  |    2 +-
 hw/usb-musb.c |    2 +-
 hw/usb-ohci.c |    4 ++--
 hw/usb-uhci.c |   10 +++-------
 hw/usb-xhci.c |    4 +---
 hw/usb.c      |   24 +++++++++++++-----------
 hw/usb.h      |    6 ++----
 8 files changed, 25 insertions(+), 31 deletions(-)

diff --git a/hw/usb-ehci.c b/hw/usb-ehci.c
index cdd7415..487214d 100644
--- a/hw/usb-ehci.c
+++ b/hw/usb-ehci.c
@@ -888,7 +888,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);
+            usb_device_reset(devs[i]);
         }
     }
     ehci_queues_rip_all(s);
@@ -987,7 +987,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_reset(&s->ports[port]);
+            usb_port_reset(&s->ports[port]);
             *portsc &= ~PORTSC_CSC;
         }
 
diff --git a/hw/usb-hub.c b/hw/usb-hub.c
index 956b020..0f3b2dd 100644
--- a/hw/usb-hub.c
+++ b/hw/usb-hub.c
@@ -305,7 +305,7 @@ static int usb_hub_handle_control(USBDevice *dev, USBPacket *p,
                 break;
             case PORT_RESET:
                 if (dev && dev->attached) {
-                    usb_send_msg(dev, USB_MSG_RESET);
+                    usb_device_reset(dev);
                     port->wPortChange |= PORT_STAT_C_RESET;
                     /* set enable bit */
                     port->wPortStatus |= PORT_STAT_ENABLE;
diff --git a/hw/usb-musb.c b/hw/usb-musb.c
index 4f528d2..c2753c9 100644
--- a/hw/usb-musb.c
+++ b/hw/usb-musb.c
@@ -1310,7 +1310,7 @@ static void musb_writeb(void *opaque, target_phys_addr_t addr, uint32_t value)
         s->power = (value & 0xef) | (s->power & 0x10);
         /* MGC_M_POWER_RESET is also read-only in Peripheral Mode */
         if ((value & MGC_M_POWER_RESET) && s->port.dev) {
-            usb_send_msg(s->port.dev, USB_MSG_RESET);
+            usb_device_reset(s->port.dev);
             /* Negotiate high-speed operation if MGC_M_POWER_HSENAB is set.  */
             if ((value & MGC_M_POWER_HSENAB) &&
                             s->port.dev->speed == USB_SPEED_HIGH)
diff --git a/hw/usb-ohci.c b/hw/usb-ohci.c
index 425030f..70f0f08 100644
--- a/hw/usb-ohci.c
+++ b/hw/usb-ohci.c
@@ -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_reset(&port->port);
+            usb_port_reset(&port->port);
         }
       }
     if (ohci->async_td) {
@@ -1435,7 +1435,7 @@ static void ohci_port_set_status(OHCIState *ohci, int portnum, uint32_t val)
 
     if (ohci_port_set_if_connected(ohci, portnum, val & OHCI_PORT_PRS)) {
         DPRINTF("usb-ohci: port %d: RESET\n", portnum);
-        usb_send_msg(port->port.dev, USB_MSG_RESET);
+        usb_device_reset(port->port.dev);
         port->ctrl &= ~OHCI_PORT_PRS;
         /* ??? Should this also set OHCI_PORT_PESC.  */
         port->ctrl |= OHCI_PORT_PES | OHCI_PORT_PRSC;
diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c
index e0c7dbb..407e0f3 100644
--- a/hw/usb-uhci.c
+++ b/hw/usb-uhci.c
@@ -342,7 +342,7 @@ static void uhci_reset(void *opaque)
         port = &s->ports[i];
         port->ctrl = 0x0080;
         if (port->port.dev && port->port.dev->attached) {
-            usb_reset(&port->port);
+            usb_port_reset(&port->port);
         }
     }
 
@@ -440,16 +440,12 @@ static void uhci_ioport_writew(void *opaque, uint32_t addr, uint32_t val)
         }
         if (val & UHCI_CMD_GRESET) {
             UHCIPort *port;
-            USBDevice *dev;
             int i;
 
             /* send reset on the USB bus */
             for(i = 0; i < NB_PORTS; i++) {
                 port = &s->ports[i];
-                dev = port->port.dev;
-                if (dev && dev->attached) {
-                    usb_send_msg(dev, USB_MSG_RESET);
-                }
+                usb_device_reset(port->port.dev);
             }
             uhci_reset(s);
             return;
@@ -491,7 +487,7 @@ static void uhci_ioport_writew(void *opaque, uint32_t addr, uint32_t val)
                 /* port reset */
                 if ( (val & UHCI_PORT_RESET) &&
                      !(port->ctrl & UHCI_PORT_RESET) ) {
-                    usb_send_msg(dev, USB_MSG_RESET);
+                    usb_device_reset(dev);
                 }
             }
             port->ctrl &= UHCI_PORT_READ_ONLY;
diff --git a/hw/usb-xhci.c b/hw/usb-xhci.c
index 37e887c..7028338 100644
--- a/hw/usb-xhci.c
+++ b/hw/usb-xhci.c
@@ -2346,9 +2346,7 @@ static void xhci_port_write(XHCIState *xhci, uint32_t reg, uint32_t val)
         /* write-1-to-start bits */
         if (val & PORTSC_PR) {
             DPRINTF("xhci: port %d reset\n", port);
-            if (xhci->ports[port].port.dev) {
-                usb_send_msg(xhci->ports[port].port.dev, USB_MSG_RESET);
-            }
+            usb_device_reset(xhci->ports[port].port.dev);
             portsc |= PORTSC_PRC | PORTSC_PED;
         }
         xhci->ports[port].portsc = portsc;
diff --git a/hw/usb.c b/hw/usb.c
index 800dd83..c8e6be4 100644
--- a/hw/usb.c
+++ b/hw/usb.c
@@ -49,14 +49,25 @@ void usb_detach(USBPort *port)
     dev->state = USB_STATE_NOTATTACHED;
 }
 
-void usb_reset(USBPort *port)
+void usb_port_reset(USBPort *port)
 {
     USBDevice *dev = port->dev;
 
     assert(dev != NULL);
     usb_detach(port);
     usb_attach(port);
-    usb_send_msg(dev, USB_MSG_RESET);
+    usb_device_reset(dev);
+}
+
+void usb_device_reset(USBDevice *dev)
+{
+    if (dev == NULL || !dev->attached) {
+        return;
+    }
+    dev->remote_wakeup = 0;
+    dev->addr = 0;
+    dev->state = USB_STATE_DEFAULT;
+    usb_device_handle_reset(dev);
 }
 
 void usb_wakeup(USBDevice *dev)
@@ -218,15 +229,6 @@ static int do_token_out(USBDevice *s, USBPacket *p)
  */
 int usb_generic_handle_packet(USBDevice *s, USBPacket *p)
 {
-    switch(p->pid) {
-    case USB_MSG_RESET:
-        s->remote_wakeup = 0;
-        s->addr = 0;
-        s->state = USB_STATE_DEFAULT;
-        usb_device_handle_reset(s);
-        return 0;
-    }
-
     /* Rest of the PIDs must match our address */
     if (s->state < USB_STATE_DEFAULT || p->devaddr != s->addr)
         return USB_RET_NODEV;
diff --git a/hw/usb.h b/hw/usb.h
index 0bd9098..b56e812 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -39,9 +39,6 @@
 #define USB_TOKEN_IN    0x69 /* device -> host */
 #define USB_TOKEN_OUT   0xe1 /* host -> device */
 
-/* specific usb messages, also sent in the 'pid' parameter */
-#define USB_MSG_RESET    0x102
-
 #define USB_RET_NODEV  (-1)
 #define USB_RET_NAK    (-2)
 #define USB_RET_STALL  (-3)
@@ -352,7 +349,8 @@ int usb_ep_get_max_packet_size(USBDevice *dev, int pid, int ep);
 
 void usb_attach(USBPort *port);
 void usb_detach(USBPort *port);
-void usb_reset(USBPort *port);
+void usb_port_reset(USBPort *port);
+void usb_device_reset(USBDevice *dev);
 void usb_wakeup(USBDevice *dev);
 int usb_generic_handle_packet(USBDevice *s, USBPacket *p);
 void usb_generic_async_ctrl_complete(USBDevice *s, USBPacket *p);
-- 
1.7.1

  parent reply	other threads:[~2012-02-10 11:43 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-10 11:42 [Qemu-devel] [PULL 00/28] usb patch queue Gerd Hoffmann
2012-02-10 11:42 ` [Qemu-devel] [PATCH 01/28] usb-uhci: implement bandwidth management Gerd Hoffmann
2012-02-10 11:42 ` [Qemu-devel] [PATCH 02/28] usb-ehci: Clear the portstatus powner bit on device disconnect Gerd Hoffmann
2012-02-10 11:42 ` [Qemu-devel] [PATCH 03/28] usb-redir: Add the posibility to filter out certain devices from redirecion Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 04/28] usb: kill USB_MSG_{ATTACH,DETACH} Gerd Hoffmann
2012-02-10 11:43 ` Gerd Hoffmann [this message]
2012-02-10 11:43 ` [Qemu-devel] [PATCH 06/28] usb: kill usb_send_msg Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 07/28] usb: add usb_find_device() Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 08/28] usb-hub: implement find_device Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 09/28] usb: handle dev == NULL in usb_handle_packet() Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 10/28] usb-uhci: switch to usb_find_device() Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 11/28] usb-ehci: " Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 12/28] usb-ohci: " Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 13/28] usb-musb: " Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 14/28] usb-xhci: " Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 15/28] usb: kill handle_packet callback Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 16/28] usb: fold usb_generic_handle_packet into usb_handle_packet Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 17/28] usb: USBPacket: add status, rename owner -> ep Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 18/28] usb: add USBEndpoint->{nr,pid} Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 19/28] usb: Set USBEndpoint in usb_packet_setup() Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 20/28] usb: maintain async packet list per endpoint Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 21/28] usb: pass USBEndpoint to usb_wakeup Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 22/28] usb: add USBBusOps->wakeup_endpoint Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 23/28] xhci: signal low- and fullspeed support Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 24/28] xhci: add trb type name lookup support Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 25/28] xhci: stop on errors Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 26/28] xhci: kill port arg from xhci_setup_packet Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 27/28] xhci: remote wakeup support Gerd Hoffmann
2012-02-10 11:43 ` [Qemu-devel] [PATCH 28/28] xhci: handle USB_RET_NAK Gerd Hoffmann
2012-02-16  0:32 ` [Qemu-devel] [PULL 00/28] usb patch queue Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1328874204-20920-6-git-send-email-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).