Blame 0005-usb-Make-port-wakeup-and-complete-ops-take-a-USBPort.patch

3f1f29
From 99a493bf96aa03427633b24653112b43fa7b7131 Mon Sep 17 00:00:00 2001
3f1f29
From: Hans de Goede <hdegoede@redhat.com>
3f1f29
Date: Tue, 21 Jun 2011 11:52:28 +0200
3f1f29
Subject: [PATCH 05/35] usb: Make port wakeup and complete ops take a USBPort
3f1f29
 instead of a Device
3f1f29
3f1f29
This makes them consistent with the attach and detach ops, and in general
3f1f29
it makes sense to make portops take a port as argument. This also makes
3f1f29
adding support for a companion controller easier / cleaner.
3f1f29
3f1f29
[ kraxel: fix usb-musb.c build ]
3f1f29
3f1f29
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
3f1f29
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
3f1f29
---
3f1f29
 hw/usb-ehci.c |    2 +-
3f1f29
 hw/usb-hub.c  |   10 +++++-----
3f1f29
 hw/usb-musb.c |    6 +++---
3f1f29
 hw/usb-ohci.c |   12 +++++-------
3f1f29
 hw/usb-uhci.c |   11 +++++------
3f1f29
 hw/usb.c      |    4 ++--
3f1f29
 hw/usb.h      |    9 +++++++--
3f1f29
 7 files changed, 28 insertions(+), 26 deletions(-)
3f1f29
3f1f29
diff --git a/hw/usb-ehci.c b/hw/usb-ehci.c
3f1f29
index 88cb2c2..428c90b 100644
3f1f29
--- a/hw/usb-ehci.c
3f1f29
+++ b/hw/usb-ehci.c
3f1f29
@@ -1111,7 +1111,7 @@ static int ehci_buffer_rw(EHCIQueue *q, int bytes, int rw)
3f1f29
     return 0;
3f1f29
 }
3f1f29
 
3f1f29
-static void ehci_async_complete_packet(USBDevice *dev, USBPacket *packet)
3f1f29
+static void ehci_async_complete_packet(USBPort *port, USBPacket *packet)
3f1f29
 {
3f1f29
     EHCIQueue *q = container_of(packet, EHCIQueue, packet);
3f1f29
 
3f1f29
diff --git a/hw/usb-hub.c b/hw/usb-hub.c
3f1f29
index 6e2a358..d324bba 100644
3f1f29
--- a/hw/usb-hub.c
3f1f29
+++ b/hw/usb-hub.c
3f1f29
@@ -246,10 +246,10 @@ static void usb_hub_detach(USBPort *port1)
3f1f29
     }
3f1f29
 }
3f1f29
 
3f1f29
-static void usb_hub_wakeup(USBDevice *dev)
3f1f29
+static void usb_hub_wakeup(USBPort *port1)
3f1f29
 {
3f1f29
-    USBHubState *s = dev->port->opaque;
3f1f29
-    USBHubPort *port = &s->ports[dev->port->index];
3f1f29
+    USBHubState *s = port1->opaque;
3f1f29
+    USBHubPort *port = &s->ports[port1->index];
3f1f29
 
3f1f29
     if (port->wPortStatus & PORT_STAT_SUSPEND) {
3f1f29
         port->wPortChange |= PORT_STAT_C_SUSPEND;
3f1f29
@@ -257,9 +257,9 @@ static void usb_hub_wakeup(USBDevice *dev)
3f1f29
     }
3f1f29
 }
3f1f29
 
3f1f29
-static void usb_hub_complete(USBDevice *dev, USBPacket *packet)
3f1f29
+static void usb_hub_complete(USBPort *port, USBPacket *packet)
3f1f29
 {
3f1f29
-    USBHubState *s = dev->port->opaque;
3f1f29
+    USBHubState *s = port->opaque;
3f1f29
 
3f1f29
     /*
3f1f29
      * Just pass it along upstream for now.
3f1f29
diff --git a/hw/usb-musb.c b/hw/usb-musb.c
3f1f29
index 84e6017..580bdc8 100644
3f1f29
--- a/hw/usb-musb.c
3f1f29
+++ b/hw/usb-musb.c
3f1f29
@@ -261,7 +261,7 @@
3f1f29
 
3f1f29
 static void musb_attach(USBPort *port);
3f1f29
 static void musb_detach(USBPort *port);
3f1f29
-static void musb_schedule_cb(USBDevice *dev, USBPacket *p);
3f1f29
+static void musb_schedule_cb(USBPort *port, USBPacket *p);
3f1f29
 static void musb_device_destroy(USBBus *bus, USBDevice *dev);
3f1f29
 
3f1f29
 static USBPortOps musb_port_ops = {
3f1f29
@@ -517,7 +517,7 @@ static void musb_cb_tick1(void *opaque)
3f1f29
 
3f1f29
 #define musb_cb_tick	(dir ? musb_cb_tick1 : musb_cb_tick0)
3f1f29
 
3f1f29
-static void musb_schedule_cb(USBDevice *dev, USBPacket *packey)
3f1f29
+static void musb_schedule_cb(USBPort *port, USBPacket *packey)
3f1f29
 {
3f1f29
     MUSBPacket *p = container_of(packey, MUSBPacket, p);
3f1f29
     MUSBEndPoint *ep = p->ep;
3f1f29
@@ -615,7 +615,7 @@ static void musb_packet(MUSBState *s, MUSBEndPoint *ep,
3f1f29
     }
3f1f29
 
3f1f29
     ep->status[dir] = ret;
3f1f29
-    musb_schedule_cb(s->port.dev, &ep->packey[dir].p);
3f1f29
+    musb_schedule_cb(&s->port, &ep->packey[dir].p);
3f1f29
 }
3f1f29
 
3f1f29
 static void musb_tx_packet_complete(USBPacket *packey, void *opaque)
3f1f29
diff --git a/hw/usb-ohci.c b/hw/usb-ohci.c
3f1f29
index 95e4623..bd92c31 100644
3f1f29
--- a/hw/usb-ohci.c
3f1f29
+++ b/hw/usb-ohci.c
3f1f29
@@ -367,15 +367,13 @@ static void ohci_detach(USBPort *port1)
3f1f29
         ohci_set_interrupt(s, OHCI_INTR_RHSC);
3f1f29
 }
3f1f29
 
3f1f29
-static void ohci_wakeup(USBDevice *dev)
3f1f29
+static void ohci_wakeup(USBPort *port1)
3f1f29
 {
3f1f29
-    USBBus *bus = usb_bus_from_device(dev);
3f1f29
-    OHCIState *s = container_of(bus, OHCIState, bus);
3f1f29
-    int portnum = dev->port->index;
3f1f29
-    OHCIPort *port = &s->rhport[portnum];
3f1f29
+    OHCIState *s = port1->opaque;
3f1f29
+    OHCIPort *port = &s->rhport[port1->index];
3f1f29
     uint32_t intr = 0;
3f1f29
     if (port->ctrl & OHCI_PORT_PSS) {
3f1f29
-        DPRINTF("usb-ohci: port %d: wakeup\n", portnum);
3f1f29
+        DPRINTF("usb-ohci: port %d: wakeup\n", port1->index);
3f1f29
         port->ctrl |= OHCI_PORT_PSSC;
3f1f29
         port->ctrl &= ~OHCI_PORT_PSS;
3f1f29
         intr = OHCI_INTR_RHSC;
3f1f29
@@ -602,7 +600,7 @@ static void ohci_copy_iso_td(OHCIState *ohci,
3f1f29
 
3f1f29
 static void ohci_process_lists(OHCIState *ohci, int completion);
3f1f29
 
3f1f29
-static void ohci_async_complete_packet(USBDevice *dev, USBPacket *packet)
3f1f29
+static void ohci_async_complete_packet(USBPort *port, USBPacket *packet)
3f1f29
 {
3f1f29
     OHCIState *ohci = container_of(packet, OHCIState, usb_packet);
3f1f29
 #ifdef DEBUG_PACKET
3f1f29
diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c
3f1f29
index fd25d2a..ab635f6 100644
3f1f29
--- a/hw/usb-uhci.c
3f1f29
+++ b/hw/usb-uhci.c
3f1f29
@@ -620,11 +620,10 @@ static void uhci_detach(USBPort *port1)
3f1f29
     uhci_resume(s);
3f1f29
 }
3f1f29
 
3f1f29
-static void uhci_wakeup(USBDevice *dev)
3f1f29
+static void uhci_wakeup(USBPort *port1)
3f1f29
 {
3f1f29
-    USBBus *bus = usb_bus_from_device(dev);
3f1f29
-    UHCIState *s = container_of(bus, UHCIState, bus);
3f1f29
-    UHCIPort *port = s->ports + dev->port->index;
3f1f29
+    UHCIState *s = port1->opaque;
3f1f29
+    UHCIPort *port = &s->ports[port1->index];
3f1f29
 
3f1f29
     if (port->ctrl & UHCI_PORT_SUSPEND && !(port->ctrl & UHCI_PORT_RD)) {
3f1f29
         port->ctrl |= UHCI_PORT_RD;
3f1f29
@@ -657,7 +656,7 @@ static int uhci_broadcast_packet(UHCIState *s, USBPacket *p)
3f1f29
     return ret;
3f1f29
 }
3f1f29
 
3f1f29
-static void uhci_async_complete(USBDevice *dev, USBPacket *packet);
3f1f29
+static void uhci_async_complete(USBPort *port, USBPacket *packet);
3f1f29
 static void uhci_process_frame(UHCIState *s);
3f1f29
 
3f1f29
 /* return -1 if fatal error (frame must be stopped)
3f1f29
@@ -849,7 +848,7 @@ done:
3f1f29
     return len;
3f1f29
 }
3f1f29
 
3f1f29
-static void uhci_async_complete(USBDevice *dev, USBPacket *packet)
3f1f29
+static void uhci_async_complete(USBPort *port, USBPacket *packet)
3f1f29
 {
3f1f29
     UHCIAsync *async = container_of(packet, UHCIAsync, packet);
3f1f29
     UHCIState *s = async->uhci;
3f1f29
diff --git a/hw/usb.c b/hw/usb.c
3f1f29
index 4a39cbc..735ffd1 100644
3f1f29
--- a/hw/usb.c
3f1f29
+++ b/hw/usb.c
3f1f29
@@ -52,7 +52,7 @@ void usb_attach(USBPort *port, USBDevice *dev)
3f1f29
 void usb_wakeup(USBDevice *dev)
3f1f29
 {
3f1f29
     if (dev->remote_wakeup && dev->port && dev->port->ops->wakeup) {
3f1f29
-        dev->port->ops->wakeup(dev);
3f1f29
+        dev->port->ops->wakeup(dev->port);
3f1f29
     }
3f1f29
 }
3f1f29
 
3f1f29
@@ -335,7 +335,7 @@ void usb_packet_complete(USBDevice *dev, USBPacket *p)
3f1f29
 {
3f1f29
     /* Note: p->owner != dev is possible in case dev is a hub */
3f1f29
     assert(p->owner != NULL);
3f1f29
-    dev->port->ops->complete(dev, p);
3f1f29
+    dev->port->ops->complete(dev->port, p);
3f1f29
     p->owner = NULL;
3f1f29
 }
3f1f29
 
3f1f29
diff --git a/hw/usb.h b/hw/usb.h
3f1f29
index a5f2efa..65f45a0 100644
3f1f29
--- a/hw/usb.h
3f1f29
+++ b/hw/usb.h
3f1f29
@@ -252,8 +252,13 @@ struct USBDeviceInfo {
3f1f29
 typedef struct USBPortOps {
3f1f29
     void (*attach)(USBPort *port);
3f1f29
     void (*detach)(USBPort *port);
3f1f29
-    void (*wakeup)(USBDevice *dev);
3f1f29
-    void (*complete)(USBDevice *dev, USBPacket *p);
3f1f29
+    void (*wakeup)(USBPort *port);
3f1f29
+    /*
3f1f29
+     * Note that port->dev will be different then the device from which
3f1f29
+     * the packet originated when a hub is involved, if you want the orginating
3f1f29
+     * device use p->owner
3f1f29
+     */
3f1f29
+    void (*complete)(USBPort *port, USBPacket *p);
3f1f29
 } USBPortOps;
3f1f29
 
3f1f29
 /* USB port on which a device can be connected */
3f1f29
-- 
3f1f29
1.7.5.1
3f1f29