Patchwork [17/18] usb: move cancel callback to USBDeviceInfo

login
register
mail settings
Submitter Gerd Hoffmann
Date May 23, 2011, 2:53 p.m.
Message ID <4DDA74E2.4030401@redhat.com>
Download mbox | patch
Permalink /patch/96964/
State New
Headers show

Comments

Gerd Hoffmann - May 23, 2011, 2:53 p.m.
Hi,

> Good spotting, this is indeed a issue which needs fixing. It isn't
> introduced by this patch though, it exists even without the usb patch
> queue.

Something like the attached patch should fix it.

cheers,
   Gerd
Hans de Goede - May 23, 2011, 5:31 p.m.
Hi,

On 05/23/2011 04:53 PM, Gerd Hoffmann wrote:
> Hi,
>
>> Good spotting, this is indeed a issue which needs fixing. It isn't
>> introduced by this patch though, it exists even without the usb patch
>> queue.
>
> Something like the attached patch should fix it.

The diff looks incomplete (missing changes to usbbus.c), but I
see you send a more complete patch in a separate mail, I'll
take a look at that one instead.

Regards,

Hans

Patch

diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c
index bc31850..e9993a7 100644
--- a/hw/usb-uhci.c
+++ b/hw/usb-uhci.c
@@ -234,6 +234,19 @@  static void uhci_async_validate_end(UHCIState *s)
     }
 }
 
+static void uhci_async_cancel_device(UHCIState *s, USBDevice *dev)
+{
+    UHCIAsync *curr, *n;
+
+    QTAILQ_FOREACH_SAFE(curr, &s->async_pending, next, n) {
+        if (curr->packet.owner != dev) {
+            continue;
+        }
+        uhci_async_unlink(s, curr);
+        uhci_async_cancel(s, curr);
+    }
+}
+
 static void uhci_async_cancel_all(UHCIState *s)
 {
     UHCIAsync *curr, *n;
@@ -1097,6 +1110,13 @@  static void uhci_map(PCIDevice *pci_dev, int region_num,
     register_ioport_read(addr, 32, 1, uhci_ioport_readb, s);
 }
 
+static void uhci_device_destroy(USBBus *bus, USBDevice *dev)
+{
+    UHCIState *s = container_of(bus, UHCIState, bus);
+
+    uhci_async_cancel_device(s, dev);
+}
+
 static USBPortOps uhci_port_ops = {
     .attach = uhci_attach,
     .detach = uhci_detach,
@@ -1104,6 +1124,10 @@  static USBPortOps uhci_port_ops = {
     .complete = uhci_async_complete,
 };
 
+static USBBusOps uhci_bus_ops = {
+    .device_destroy = uhci_device_destroy,
+};
+
 static int usb_uhci_common_initfn(UHCIState *s)
 {
     uint8_t *pci_conf = s->dev.config;
@@ -1116,7 +1140,7 @@  static int usb_uhci_common_initfn(UHCIState *s)
     pci_conf[PCI_INTERRUPT_PIN] = 4; // interrupt pin 3
     pci_conf[0x60] = 0x10; // release number
 
-    usb_bus_new(&s->bus, &s->dev.qdev);
+    usb_bus_new(&s->bus, &uhci_bus_ops, &s->dev.qdev);
     for(i = 0; i < NB_PORTS; i++) {
         usb_register_port(&s->bus, &s->ports[i].port, s, i, &uhci_port_ops,
                           USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL);
diff --git a/hw/usb.h b/hw/usb.h
index 0fa86a3..097d789 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -139,6 +139,7 @@ 
 #define USB_ENDPOINT_XFER_INT		3
 
 typedef struct USBBus USBBus;
+typedef struct USBBusOps USBBusOps;
 typedef struct USBPort USBPort;
 typedef struct USBDevice USBDevice;
 typedef struct USBDeviceInfo USBDeviceInfo;
@@ -330,6 +331,7 @@  void musb_set_size(MUSBState *s, int epnum, int size, int is_tx);
 
 struct USBBus {
     BusState qbus;
+    USBBusOps *ops;
     int busnr;
     int nfree;
     int nused;
@@ -338,7 +340,11 @@  struct USBBus {
     QTAILQ_ENTRY(USBBus) next;
 };
 
-void usb_bus_new(USBBus *bus, DeviceState *host);
+struct USBBusOps {
+    void (*device_destroy)(USBBus *bus, USBDevice *dev);
+};
+
+void usb_bus_new(USBBus *bus, USBBusOps *ops, DeviceState *host);
 USBBus *usb_bus_find(int busnr);
 void usb_qdev_register(USBDeviceInfo *info);
 void usb_qdev_register_many(USBDeviceInfo *info);