aboutsummaryrefslogtreecommitdiff
path: root/hw/usb-musb.c
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2011-05-23 17:37:12 +0200
committerGerd Hoffmann <kraxel@redhat.com>2011-06-14 12:56:49 +0200
commit07771f6fcebdb12de6dca537423f56299ed9b4b9 (patch)
tree374f2b5049bf5dc38984921b76250c590ab65403 /hw/usb-musb.c
parent8e4faf3de9d1a8bd3289e5cc69d4ed206e2ed0cf (diff)
usb: cancel async packets on unplug
This patch adds USBBusOps struct with (for now) only a single callback which is called when a device is about to be destroyed. The USB Host adapters are implementing this callback and use it to cancel any async requests which might be in flight before the device actually goes away. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'hw/usb-musb.c')
-rw-r--r--hw/usb-musb.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/hw/usb-musb.c b/hw/usb-musb.c
index 6037193db8..21f35afa92 100644
--- a/hw/usb-musb.c
+++ b/hw/usb-musb.c
@@ -262,6 +262,7 @@
static void musb_attach(USBPort *port);
static void musb_detach(USBPort *port);
static void musb_schedule_cb(USBDevice *dev, USBPacket *p);
+static void musb_device_destroy(USBBus *bus, USBDevice *dev);
static USBPortOps musb_port_ops = {
.attach = musb_attach,
@@ -269,6 +270,10 @@ static USBPortOps musb_port_ops = {
.complete = musb_schedule_cb,
};
+static USBBusOps musb_bus_ops = {
+ .device_destroy = musb_device_destroy,
+};
+
typedef struct MUSBPacket MUSBPacket;
typedef struct MUSBEndPoint MUSBEndPoint;
@@ -361,7 +366,7 @@ struct MUSBState *musb_init(qemu_irq *irqs)
s->ep[i].epnum = i;
}
- usb_bus_new(&s->bus, NULL /* FIXME */);
+ usb_bus_new(&s->bus, &musb_bus_ops, NULL /* FIXME */);
usb_register_port(&s->bus, &s->port, s, 0, &musb_port_ops,
USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL);
usb_port_location(&s->port, NULL, 1);
@@ -778,6 +783,22 @@ static void musb_rx_packet_complete(USBPacket *packey, void *opaque)
musb_rx_intr_set(s, epnum, 1);
}
+static void musb_device_destroy(USBBus *bus, USBDevice *dev)
+{
+ MUSBState *s = container_of(bus, MUSBState, bus);
+ int ep, dir;
+
+ for (ep = 0; ep < 16; ep++) {
+ for (dir = 0; dir < 2; dir++) {
+ if (s->ep[ep].packey[dir].p.owner != dev) {
+ continue;
+ }
+ usb_cancel_packet(&s->ep[ep].packey[dir].p);
+ /* status updates needed here? */
+ }
+ }
+}
+
static void musb_tx_rdy(MUSBState *s, int epnum)
{
MUSBEndPoint *ep = s->ep + epnum;