Patchwork [12/30] usb: move USB_REQ_SET_ADDRESS handling to common code

login
register
mail settings
Submitter Gerd Hoffmann
Date Dec. 17, 2010, 11:26 a.m.
Message ID <1292585206-24862-13-git-send-email-kraxel@redhat.com>
Download mbox | patch
Permalink /patch/75889/
State New
Headers show

Comments

Gerd Hoffmann - Dec. 17, 2010, 11:26 a.m.
USB_REQ_SET_ADDRESS handling is identical in *all* emulated devices.
Move it to common code.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/usb-bt.c     |    4 ----
 hw/usb-desc.c   |    6 ++++++
 hw/usb-hid.c    |    4 ----
 hw/usb-hub.c    |    4 ----
 hw/usb-msd.c    |    4 ----
 hw/usb-net.c    |    5 -----
 hw/usb-serial.c |    4 ----
 hw/usb-wacom.c  |    4 ----
 trace-events    |    1 +
 9 files changed, 7 insertions(+), 29 deletions(-)

Patch

diff --git a/hw/usb-bt.c b/hw/usb-bt.c
index d7959ad..c0bfc35 100644
--- a/hw/usb-bt.c
+++ b/hw/usb-bt.c
@@ -413,10 +413,6 @@  static int usb_bt_handle_control(USBDevice *dev, int request, int value,
         }
         ret = 0;
         break;
-    case DeviceOutRequest | USB_REQ_SET_ADDRESS:
-        dev->addr = value;
-        ret = 0;
-        break;
     case DeviceRequest | USB_REQ_GET_CONFIGURATION:
         data[0] = 1;
         ret = 1;
diff --git a/hw/usb-desc.c b/hw/usb-desc.c
index 69ab207..3e87f46 100644
--- a/hw/usb-desc.c
+++ b/hw/usb-desc.c
@@ -266,6 +266,12 @@  int usb_desc_handle_control(USBDevice *dev, int request, int value,
 
     assert(desc != NULL);
     switch(request) {
+    case DeviceOutRequest | USB_REQ_SET_ADDRESS:
+        dev->addr = value;
+        trace_usb_set_addr(dev->addr);
+        ret = 0;
+        break;
+
     case DeviceRequest | USB_REQ_GET_DESCRIPTOR:
         ret = usb_desc_get_descriptor(dev, value, data, length);
         break;
diff --git a/hw/usb-hid.c b/hw/usb-hid.c
index 74d17fc..72daddf 100644
--- a/hw/usb-hid.c
+++ b/hw/usb-hid.c
@@ -695,10 +695,6 @@  static int usb_hid_handle_control(USBDevice *dev, int request, int value,
         }
         ret = 0;
         break;
-    case DeviceOutRequest | USB_REQ_SET_ADDRESS:
-        dev->addr = value;
-        ret = 0;
-        break;
     case DeviceRequest | USB_REQ_GET_CONFIGURATION:
         data[0] = 1;
         ret = 1;
diff --git a/hw/usb-hub.c b/hw/usb-hub.c
index 0f8d060..51a67a2 100644
--- a/hw/usb-hub.c
+++ b/hw/usb-hub.c
@@ -297,10 +297,6 @@  static int usb_hub_handle_control(USBDevice *dev, int request, int value,
         }
         ret = 0;
         break;
-    case DeviceOutRequest | USB_REQ_SET_ADDRESS:
-        dev->addr = value;
-        ret = 0;
-        break;
     case DeviceRequest | USB_REQ_GET_CONFIGURATION:
         data[0] = 1;
         ret = 1;
diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index 9aa8888..b54ccbc 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -261,10 +261,6 @@  static int usb_msd_handle_control(USBDevice *dev, int request, int value,
         }
         ret = 0;
         break;
-    case DeviceOutRequest | USB_REQ_SET_ADDRESS:
-        dev->addr = value;
-        ret = 0;
-        break;
     case DeviceRequest | USB_REQ_GET_CONFIGURATION:
         data[0] = 1;
         ret = 1;
diff --git a/hw/usb-net.c b/hw/usb-net.c
index 3a34414..1a57ef7 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -1075,11 +1075,6 @@  static int usb_net_handle_control(USBDevice *dev, int request, int value,
         ret = 0;
         break;
 
-    case DeviceOutRequest | USB_REQ_SET_ADDRESS:
-        dev->addr = value;
-        ret = 0;
-        break;
-
     case ClassInterfaceOutRequest | USB_CDC_SEND_ENCAPSULATED_COMMAND:
         if (!s->rndis || value || index != 0)
             goto fail;
diff --git a/hw/usb-serial.c b/hw/usb-serial.c
index f89eb9b..c1f31c7 100644
--- a/hw/usb-serial.c
+++ b/hw/usb-serial.c
@@ -254,10 +254,6 @@  static int usb_serial_handle_control(USBDevice *dev, int request, int value,
         }
         ret = 0;
         break;
-    case DeviceOutRequest | USB_REQ_SET_ADDRESS:
-        dev->addr = value;
-        ret = 0;
-        break;
     case DeviceRequest | USB_REQ_GET_CONFIGURATION:
         data[0] = 1;
         ret = 1;
diff --git a/hw/usb-wacom.c b/hw/usb-wacom.c
index ffe6ac7..ad1c3ae 100644
--- a/hw/usb-wacom.c
+++ b/hw/usb-wacom.c
@@ -284,10 +284,6 @@  static int usb_wacom_handle_control(USBDevice *dev, int request, int value,
         }
         ret = 0;
         break;
-    case DeviceOutRequest | USB_REQ_SET_ADDRESS:
-        dev->addr = value;
-        ret = 0;
-        break;
     case DeviceRequest | USB_REQ_GET_CONFIGURATION:
         data[0] = 1;
         ret = 1;
diff --git a/trace-events b/trace-events
index 23303c4..3372b78 100644
--- a/trace-events
+++ b/trace-events
@@ -194,6 +194,7 @@  disable sun4m_iommu_bad_addr(uint64_t addr) "bad addr %"PRIx64""
 disable usb_desc_device(int addr, int len, int ret) "dev %d query device, len %d, ret %d"
 disable usb_desc_config(int addr, int index, int len, int ret) "dev %d query config %d, len %d, ret %d"
 disable usb_desc_string(int addr, int index, int len, int ret) "dev %d query string %d, len %d, ret %d"
+disable usb_set_addr(int addr) "dev %d"
 
 # vl.c
 disable vm_state_notify(int running, int reason) "running %d reason %d"