Patchwork [v3,045/197] usb: get rid of info pointer

login
register
mail settings
Submitter Anthony Liguori
Date Dec. 12, 2011, 8:18 p.m.
Message ID <1323721273-32404-46-git-send-email-aliguori@us.ibm.com>
Download mbox | patch
Permalink /patch/130827/
State New
Headers show

Comments

Anthony Liguori - Dec. 12, 2011, 8:18 p.m.
---
 hw/usb-bus.c |  154 ++++++++++++++++++++++++++++++++-------------------------
 hw/usb.h     |    1 -
 2 files changed, 86 insertions(+), 69 deletions(-)

Patch

diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index 24a805d..8d9c82d 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -67,21 +67,103 @@  USBBus *usb_bus_find(int busnr)
 
 static int usb_device_init(USBDevice *dev)
 {
-    if (dev->info->init) {
-        return dev->info->init(dev);
+    USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
+                                    qdev_get_info(DEVICE(dev)));
+    if (info->init) {
+        return info->init(dev);
     }
     return 0;
 }
 
+static void usb_device_handle_destroy(USBDevice *dev)
+{
+    USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
+                                    qdev_get_info(DEVICE(dev)));
+    if (info->handle_destroy) {
+        info->handle_destroy(dev);
+    }
+}
+
+int usb_device_handle_packet(USBDevice *dev, USBPacket *p)
+{
+    USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
+                                    qdev_get_info(DEVICE(dev)));
+    if (info->handle_packet) {
+        return info->handle_packet(dev, p);
+    }
+    return -ENOSYS;
+}
+
+void usb_device_cancel_packet(USBDevice *dev, USBPacket *p)
+{
+    USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
+                                    qdev_get_info(DEVICE(dev)));
+    if (info->cancel_packet) {
+        info->cancel_packet(dev, p);
+    }
+}
+
+void usb_device_handle_attach(USBDevice *dev)
+{
+    USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
+                                    qdev_get_info(DEVICE(dev)));
+    if (info->handle_attach) {
+        info->handle_attach(dev);
+    }
+}
+
+void usb_device_handle_reset(USBDevice *dev)
+{
+    USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
+                                    qdev_get_info(DEVICE(dev)));
+    if (info->handle_reset) {
+        info->handle_reset(dev);
+    }
+}
+
+int usb_device_handle_control(USBDevice *dev, USBPacket *p, int request,
+                              int value, int index, int length, uint8_t *data)
+{
+    USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
+                                    qdev_get_info(DEVICE(dev)));
+    if (info->handle_control) {
+        return info->handle_control(dev, p, request, value, index, length,
+                                         data);
+    }
+    return -ENOSYS;
+}
+
+int usb_device_handle_data(USBDevice *dev, USBPacket *p)
+{
+    USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
+                                    qdev_get_info(DEVICE(dev)));
+    if (info->handle_data) {
+        return info->handle_data(dev, p);
+    }
+    return -ENOSYS;
+}
+
+const char *usb_device_get_product_desc(USBDevice *dev)
+{
+    USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
+                                    qdev_get_info(DEVICE(dev)));
+    return info->product_desc;
+}
+
+const USBDesc *usb_device_get_usb_desc(USBDevice *dev)
+{
+    USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
+                                    qdev_get_info(DEVICE(dev)));
+    return info->usb_desc;
+}
+
 static int usb_qdev_init(DeviceState *qdev, DeviceInfo *base)
 {
     USBDevice *dev = USB_DEVICE(qdev);
-    USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev, base);
     int rc;
 
     pstrcpy(dev->product_desc, sizeof(dev->product_desc),
             usb_device_get_product_desc(dev));
-    dev->info = info;
     dev->auto_attach = 1;
     QLIST_INIT(&dev->strings);
     rc = usb_claim_port(dev);
@@ -105,13 +187,6 @@  err:
     return rc;
 }
 
-static void usb_device_handle_destroy(USBDevice *dev)
-{
-    if (dev->info->handle_destroy) {
-        dev->info->handle_destroy(dev);
-    }
-}
-
 static int usb_qdev_exit(DeviceState *qdev)
 {
     USBDevice *dev = USB_DEVICE(qdev);
@@ -495,63 +570,6 @@  USBDevice *usbdevice_create(const char *cmdline)
     return usb->usbdevice_init(params);
 }
 
-int usb_device_handle_packet(USBDevice *dev, USBPacket *p)
-{
-    if (dev->info->handle_packet) {
-        return dev->info->handle_packet(dev, p);
-    }
-    return -ENOSYS;
-}
-
-void usb_device_cancel_packet(USBDevice *dev, USBPacket *p)
-{
-    if (dev->info->cancel_packet) {
-        dev->info->cancel_packet(dev, p);
-    }
-}
-
-void usb_device_handle_attach(USBDevice *dev)
-{
-    if (dev->info->handle_attach) {
-        dev->info->handle_attach(dev);
-    }
-}
-
-void usb_device_handle_reset(USBDevice *dev)
-{
-    if (dev->info->handle_reset) {
-        dev->info->handle_reset(dev);
-    }
-}
-
-int usb_device_handle_control(USBDevice *dev, USBPacket *p, int request,
-                              int value, int index, int length, uint8_t *data)
-{
-    if (dev->info->handle_control) {
-        return dev->info->handle_control(dev, p, request, value, index, length,
-                                         data);
-    }
-    return -ENOSYS;
-}
-
-int usb_device_handle_data(USBDevice *dev, USBPacket *p)
-{
-    if (dev->info->handle_data) {
-        return dev->info->handle_data(dev, p);
-    }
-    return -ENOSYS;
-}
-
-const char *usb_device_get_product_desc(USBDevice *dev)
-{
-    return dev->info->product_desc;
-}
-
-const USBDesc *usb_device_get_usb_desc(USBDevice *dev)
-{
-    return dev->info->usb_desc;
-}
-
 static TypeInfo usb_device_type_info = {
     .name = TYPE_USB_DEVICE,
     .parent = TYPE_DEVICE,
diff --git a/hw/usb.h b/hw/usb.h
index e05c00d..ee780b0 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -179,7 +179,6 @@  typedef struct USBDeviceClass {
 /* definition of a USB device */
 struct USBDevice {
     DeviceState qdev;
-    USBDeviceInfo *info;
     USBPort *port;
     char *port_path;
     void *opaque;