qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 12/25] usb: kill handle_packet callback


From: Gerd Hoffmann
Subject: [Qemu-devel] [PATCH 12/25] usb: kill handle_packet callback
Date: Mon, 23 Jan 2012 15:54:58 +0100

All drivers except usb-hub use usb_generic_handle_packet.  The only
reason the usb hub has its own function is that it used to be called
with packets which are intended for downstream devices.  With the new,
separate device lookup step this doesn't happen any more, so the need
for a different handle_packet callback is gone.

So we can kill the handle_packet callback and just call
usb_generic_handle_packet directly.  The special hub handling in
usb_handle_packet() can go away for the same reason.

Signed-off-by: Gerd Hoffmann <address@hidden>
---
 hw/usb-audio.c  |    1 -
 hw/usb-bt.c     |    1 -
 hw/usb-ccid.c   |    1 -
 hw/usb-hid.c    |    3 ---
 hw/usb-hub.c    |   39 ---------------------------------------
 hw/usb-msd.c    |    1 -
 hw/usb-net.c    |    1 -
 hw/usb-serial.c |    2 --
 hw/usb-wacom.c  |    1 -
 hw/usb.c        |   15 ++++-----------
 hw/usb.h        |   10 ----------
 usb-bsd.c       |    1 -
 usb-linux.c     |    1 -
 usb-redir.c     |    1 -
 14 files changed, 4 insertions(+), 74 deletions(-)

diff --git a/hw/usb-audio.c b/hw/usb-audio.c
index b22d578..560f8e3 100644
--- a/hw/usb-audio.c
+++ b/hw/usb-audio.c
@@ -682,7 +682,6 @@ static struct USBDeviceInfo usb_audio_info = {
     .qdev.vmsd      = &vmstate_usb_audio,
     .usb_desc       = &desc_audio,
     .init           = usb_audio_initfn,
-    .handle_packet  = usb_generic_handle_packet,
     .handle_reset   = usb_audio_handle_reset,
     .handle_control = usb_audio_handle_control,
     .handle_data    = usb_audio_handle_data,
diff --git a/hw/usb-bt.c b/hw/usb-bt.c
index 0c1270b..ab1f5e5 100644
--- a/hw/usb-bt.c
+++ b/hw/usb-bt.c
@@ -534,7 +534,6 @@ static struct USBDeviceInfo bt_info = {
     .qdev.vmsd      = &vmstate_usb_bt,
     .usb_desc       = &desc_bluetooth,
     .init           = usb_bt_initfn,
-    .handle_packet  = usb_generic_handle_packet,
     .handle_reset   = usb_bt_handle_reset,
     .handle_control = usb_bt_handle_control,
     .handle_data    = usb_bt_handle_data,
diff --git a/hw/usb-ccid.c b/hw/usb-ccid.c
index e9935ad..63c4bcf 100644
--- a/hw/usb-ccid.c
+++ b/hw/usb-ccid.c
@@ -1293,7 +1293,6 @@ static struct USBDeviceInfo ccid_info = {
     .qdev.size      = sizeof(USBCCIDState),
     .init           = ccid_initfn,
     .usb_desc       = &desc_ccid,
-    .handle_packet  = usb_generic_handle_packet,
     .handle_reset   = ccid_handle_reset,
     .handle_control = ccid_handle_control,
     .handle_data    = ccid_handle_data,
diff --git a/hw/usb-hid.c b/hw/usb-hid.c
index 997f828..e40bb80 100644
--- a/hw/usb-hid.c
+++ b/hw/usb-hid.c
@@ -562,7 +562,6 @@ static struct USBDeviceInfo hid_info[] = {
         .qdev.vmsd      = &vmstate_usb_ptr,
         .usb_desc       = &desc_tablet,
         .init           = usb_tablet_initfn,
-        .handle_packet  = usb_generic_handle_packet,
         .handle_reset   = usb_hid_handle_reset,
         .handle_control = usb_hid_handle_control,
         .handle_data    = usb_hid_handle_data,
@@ -575,7 +574,6 @@ static struct USBDeviceInfo hid_info[] = {
         .qdev.vmsd      = &vmstate_usb_ptr,
         .usb_desc       = &desc_mouse,
         .init           = usb_mouse_initfn,
-        .handle_packet  = usb_generic_handle_packet,
         .handle_reset   = usb_hid_handle_reset,
         .handle_control = usb_hid_handle_control,
         .handle_data    = usb_hid_handle_data,
@@ -588,7 +586,6 @@ static struct USBDeviceInfo hid_info[] = {
         .qdev.vmsd      = &vmstate_usb_kbd,
         .usb_desc       = &desc_keyboard,
         .init           = usb_keyboard_initfn,
-        .handle_packet  = usb_generic_handle_packet,
         .handle_reset   = usb_hid_handle_reset,
         .handle_control = usb_hid_handle_control,
         .handle_data    = usb_hid_handle_data,
diff --git a/hw/usb-hub.c b/hw/usb-hub.c
index c9f30d9..49fc349 100644
--- a/hw/usb-hub.c
+++ b/hw/usb-hub.c
@@ -455,44 +455,6 @@ static int usb_hub_handle_data(USBDevice *dev, USBPacket 
*p)
     return ret;
 }
 
-static int usb_hub_broadcast_packet(USBHubState *s, USBPacket *p)
-{
-    USBHubPort *port;
-    USBDevice *dev;
-    int i, ret;
-
-    for(i = 0; i < NUM_PORTS; i++) {
-        port = &s->ports[i];
-        dev = port->port.dev;
-        if (dev && dev->attached && (port->wPortStatus & PORT_STAT_ENABLE)) {
-            ret = usb_handle_packet(dev, p);
-            if (ret != USB_RET_NODEV) {
-                return ret;
-            }
-        }
-    }
-    return USB_RET_NODEV;
-}
-
-static int usb_hub_handle_packet(USBDevice *dev, USBPacket *p)
-{
-    USBHubState *s = (USBHubState *)dev;
-
-#if defined(DEBUG) && 0
-    printf("usb_hub: pid=0x%x\n", pid);
-#endif
-    if (dev->state == USB_STATE_DEFAULT &&
-        dev->addr != 0 &&
-        p->devaddr != dev->addr &&
-        (p->pid == USB_TOKEN_SETUP ||
-         p->pid == USB_TOKEN_OUT ||
-         p->pid == USB_TOKEN_IN)) {
-        /* broadcast the packet to the devices */
-        return usb_hub_broadcast_packet(s, p);
-    }
-    return usb_generic_handle_packet(dev, p);
-}
-
 static void usb_hub_handle_destroy(USBDevice *dev)
 {
     USBHubState *s = (USBHubState *)dev;
@@ -562,7 +524,6 @@ static struct USBDeviceInfo hub_info = {
     .usb_desc       = &desc_hub,
     .init           = usb_hub_initfn,
     .find_device    = usb_hub_find_device,
-    .handle_packet  = usb_hub_handle_packet,
     .handle_reset   = usb_hub_handle_reset,
     .handle_control = usb_hub_handle_control,
     .handle_data    = usb_hub_handle_data,
diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index 186831d..46681fd 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -644,7 +644,6 @@ static struct USBDeviceInfo msd_info = {
     .qdev.vmsd      = &vmstate_usb_msd,
     .usb_desc       = &desc,
     .init           = usb_msd_initfn,
-    .handle_packet  = usb_generic_handle_packet,
     .cancel_packet  = usb_msd_cancel_io,
     .handle_attach  = usb_desc_attach,
     .handle_reset   = usb_msd_handle_reset,
diff --git a/hw/usb-net.c b/hw/usb-net.c
index 2f527a8..6a35f0f 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -1393,7 +1393,6 @@ static struct USBDeviceInfo net_info = {
     .qdev.vmsd      = &vmstate_usb_net,
     .usb_desc       = &desc_net,
     .init           = usb_net_initfn,
-    .handle_packet  = usb_generic_handle_packet,
     .handle_reset   = usb_net_handle_reset,
     .handle_control = usb_net_handle_control,
     .handle_data    = usb_net_handle_data,
diff --git a/hw/usb-serial.c b/hw/usb-serial.c
index e3c8238..391f41e 100644
--- a/hw/usb-serial.c
+++ b/hw/usb-serial.c
@@ -577,7 +577,6 @@ static struct USBDeviceInfo serial_info = {
     .qdev.vmsd      = &vmstate_usb_serial,
     .usb_desc       = &desc_serial,
     .init           = usb_serial_initfn,
-    .handle_packet  = usb_generic_handle_packet,
     .handle_reset   = usb_serial_handle_reset,
     .handle_control = usb_serial_handle_control,
     .handle_data    = usb_serial_handle_data,
@@ -597,7 +596,6 @@ static struct USBDeviceInfo braille_info = {
     .qdev.vmsd      = &vmstate_usb_serial,
     .usb_desc       = &desc_braille,
     .init           = usb_serial_initfn,
-    .handle_packet  = usb_generic_handle_packet,
     .handle_reset   = usb_serial_handle_reset,
     .handle_control = usb_serial_handle_control,
     .handle_data    = usb_serial_handle_data,
diff --git a/hw/usb-wacom.c b/hw/usb-wacom.c
index 61d5b18..6ebaed1 100644
--- a/hw/usb-wacom.c
+++ b/hw/usb-wacom.c
@@ -358,7 +358,6 @@ static struct USBDeviceInfo wacom_info = {
     .qdev.size      = sizeof(USBWacomState),
     .qdev.vmsd      = &vmstate_usb_wacom,
     .init           = usb_wacom_initfn,
-    .handle_packet  = usb_generic_handle_packet,
     .handle_reset   = usb_wacom_handle_reset,
     .handle_control = usb_wacom_handle_control,
     .handle_data    = usb_wacom_handle_data,
diff --git a/hw/usb.c b/hw/usb.c
index 80afd99..70a4bc5 100644
--- a/hw/usb.c
+++ b/hw/usb.c
@@ -231,7 +231,7 @@ static int do_token_out(USBDevice *s, USBPacket *p)
  *
  * Returns length of the transaction or one of the USB_RET_XXX codes.
  */
-int usb_generic_handle_packet(USBDevice *s, USBPacket *p)
+static int usb_generic_handle_packet(USBDevice *s, USBPacket *p)
 {
     /* Rest of the PIDs must match our address */
     if (s->state < USB_STATE_DEFAULT || p->devaddr != s->addr)
@@ -325,18 +325,12 @@ int usb_handle_packet(USBDevice *dev, USBPacket *p)
     if (dev == NULL) {
         return USB_RET_NODEV;
     }
+    assert(dev->addr == p->devaddr);
 
     assert(p->owner == NULL);
-    ret = dev->info->handle_packet(dev, p);
+    ret = usb_generic_handle_packet(dev, p);
     if (ret == USB_RET_ASYNC) {
-        if (p->owner == NULL) {
-            p->owner = usb_ep_get(dev, p->pid, p->devep);
-        } else {
-            /* We'll end up here when usb_handle_packet is called
-             * recursively due to a hub being in the chain.  Nothing
-             * to do.  Leave p->owner pointing to the device, not the
-             * hub. */;
-        }
+        p->owner = usb_ep_get(dev, p->pid, p->devep);
     }
     return ret;
 }
@@ -346,7 +340,6 @@ int usb_handle_packet(USBDevice *dev, USBPacket *p)
    handle_packet. */
 void usb_packet_complete(USBDevice *dev, USBPacket *p)
 {
-    /* Note: p->owner != dev is possible in case dev is a hub */
     assert(p->owner != NULL);
     p->owner = NULL;
     dev->port->ops->complete(dev->port, p);
diff --git a/hw/usb.h b/hw/usb.h
index b0ba3e0..82ca924 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -225,15 +225,6 @@ struct USBDeviceInfo {
     USBDevice *(*find_device)(USBDevice *dev, uint8_t addr);
 
     /*
-     * Process USB packet.
-     * Called by the HC (Host Controller).
-     *
-     * Returns length of the transaction
-     * or one of the USB_RET_XXX codes.
-     */
-    int (*handle_packet)(USBDevice *dev, USBPacket *p);
-
-    /*
      * Called when a packet is canceled.
      */
     void (*cancel_packet)(USBDevice *dev, USBPacket *p);
@@ -354,7 +345,6 @@ void usb_detach(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);
 int set_usb_string(uint8_t *buf, const char *str);
 
diff --git a/usb-bsd.c b/usb-bsd.c
index 1187552..2f34f1b 100644
--- a/usb-bsd.c
+++ b/usb-bsd.c
@@ -402,7 +402,6 @@ static struct USBDeviceInfo usb_host_dev_info = {
     .qdev.name      = "usb-host",
     .qdev.size      = sizeof(USBHostDevice),
     .init           = usb_host_initfn,
-    .handle_packet  = usb_generic_handle_packet,
     .handle_reset   = usb_host_handle_reset,
     .handle_control = usb_host_handle_control,
     .handle_data    = usb_host_handle_data,
diff --git a/usb-linux.c b/usb-linux.c
index 56898dd..26d1cc4 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -1408,7 +1408,6 @@ static struct USBDeviceInfo usb_host_dev_info = {
     .qdev.size      = sizeof(USBHostDevice),
     .qdev.vmsd      = &vmstate_usb_host,
     .init           = usb_host_initfn,
-    .handle_packet  = usb_generic_handle_packet,
     .cancel_packet  = usb_host_async_cancel,
     .handle_data    = usb_host_handle_data,
     .handle_control = usb_host_handle_control,
diff --git a/usb-redir.c b/usb-redir.c
index 79d29ec..459eae8 100644
--- a/usb-redir.c
+++ b/usb-redir.c
@@ -1321,7 +1321,6 @@ static struct USBDeviceInfo usbredir_dev_info = {
     .qdev.size      = sizeof(USBRedirDevice),
     .init           = usbredir_initfn,
     .handle_destroy = usbredir_handle_destroy,
-    .handle_packet  = usb_generic_handle_packet,
     .cancel_packet  = usbredir_cancel_packet,
     .handle_reset   = usbredir_handle_reset,
     .handle_data    = usbredir_handle_data,
-- 
1.7.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]