Patchwork [v3,046/197] usb: promote all of the methods for USBDevice to class methods

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

Comments

Anthony Liguori - Dec. 12, 2011, 8:18 p.m.
---
 hw/usb-bt.c     |   23 +++++++++++------
 hw/usb-bus.c    |   66 ++++++++++++++++++++----------------------------
 hw/usb-ccid.c   |   27 ++++++++++++-------
 hw/usb-hid.c    |   75 +++++++++++++++++++++++++++++++++++-------------------
 hw/usb-hub.c    |   25 +++++++++++------
 hw/usb-msd.c    |   31 ++++++++++++++---------
 hw/usb-net.c    |   32 ++++++++++++++---------
 hw/usb-serial.c |   55 +++++++++++++++++++++++++--------------
 hw/usb-wacom.c  |   25 +++++++++++------
 hw/usb.h        |   64 +++++++++++++++++++++++-----------------------
 usb-linux.c     |   27 ++++++++++++-------
 11 files changed, 263 insertions(+), 187 deletions(-)

Patch

diff --git a/hw/usb-bt.c b/hw/usb-bt.c
index f30eec1..fd71f1f 100644
--- a/hw/usb-bt.c
+++ b/hw/usb-bt.c
@@ -549,18 +549,25 @@  static const VMStateDescription vmstate_usb_bt = {
     .unmigratable = 1,
 };
 
+static void usb_bt_class_initfn(ObjectClass *klass, void *data)
+{
+    USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+    uc->init           = usb_bt_initfn;
+    uc->product_desc   = "QEMU BT dongle";
+    uc->usb_desc       = &desc_bluetooth;
+    uc->handle_packet  = usb_generic_handle_packet;
+    uc->handle_reset   = usb_bt_handle_reset;
+    uc->handle_control = usb_bt_handle_control;
+    uc->handle_data    = usb_bt_handle_data;
+    uc->handle_destroy = usb_bt_handle_destroy;
+}
+
 static struct USBDeviceInfo bt_info = {
-    .product_desc   = "QEMU BT dongle",
     .qdev.name      = "usb-bt-dongle",
     .qdev.size      = sizeof(struct USBBtState),
     .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,
-    .handle_destroy = usb_bt_handle_destroy,
+    .qdev.class_init= usb_bt_class_initfn,
 };
 
 static void usb_bt_register_devices(void)
diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index 8d9c82d..46426db 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -67,67 +67,60 @@  USBBus *usb_bus_find(int busnr)
 
 static int usb_device_init(USBDevice *dev)
 {
-    USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
-                                    qdev_get_info(DEVICE(dev)));
-    if (info->init) {
-        return info->init(dev);
+    USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+    if (klass->init) {
+        return klass->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);
+    USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+    if (klass->handle_destroy) {
+        klass->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);
+    USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+    if (klass->handle_packet) {
+        return klass->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);
+    USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+    if (klass->cancel_packet) {
+        klass->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);
+    USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+    if (klass->handle_attach) {
+        klass->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);
+    USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+    if (klass->handle_reset) {
+        klass->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,
+    USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+    if (klass->handle_control) {
+        return klass->handle_control(dev, p, request, value, index, length,
                                          data);
     }
     return -ENOSYS;
@@ -135,26 +128,23 @@  int usb_device_handle_control(USBDevice *dev, USBPacket *p, int request,
 
 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);
+    USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+    if (klass->handle_data) {
+        return klass->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;
+    USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+    return klass->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;
+    USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+    return klass->usb_desc;
 }
 
 static int usb_qdev_init(DeviceState *qdev, DeviceInfo *base)
diff --git a/hw/usb-ccid.c b/hw/usb-ccid.c
index 997ef31..db67837 100644
--- a/hw/usb-ccid.c
+++ b/hw/usb-ccid.c
@@ -1294,24 +1294,31 @@  static VMStateDescription ccid_vmstate = {
     }
 };
 
+static void ccid_class_initfn(ObjectClass *klass, void *data)
+{
+    USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+    uc->init           = ccid_initfn;
+    uc->product_desc   = "QEMU USB CCID";
+    uc->usb_desc       = &desc_ccid;
+    uc->handle_packet  = usb_generic_handle_packet;
+    uc->handle_reset   = ccid_handle_reset;
+    uc->handle_control = ccid_handle_control;
+    uc->handle_data    = ccid_handle_data;
+    uc->handle_destroy = ccid_handle_destroy;
+}
+
 static struct USBDeviceInfo ccid_info = {
-    .product_desc   = "QEMU USB CCID",
     .qdev.name      = CCID_DEV_NAME,
     .qdev.desc      = "CCID Rev 1.1 smartcard reader",
     .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,
-    .handle_destroy = ccid_handle_destroy,
-    .usbdevice_name = "ccid",
+    .qdev.class_init= ccid_class_initfn,
+    .qdev.vmsd      = &ccid_vmstate,
     .qdev.props     = (Property[]) {
         DEFINE_PROP_UINT8("debug", USBCCIDState, debug, 0),
         DEFINE_PROP_END_OF_LIST(),
     },
-    .qdev.vmsd      = &ccid_vmstate,
+    .usbdevice_name = "ccid",
 };
 
 static TypeInfo ccid_card_type_info = {
diff --git a/hw/usb-hid.c b/hw/usb-hid.c
index a110c74..dc6bc78 100644
--- a/hw/usb-hid.c
+++ b/hw/usb-hid.c
@@ -560,46 +560,67 @@  static const VMStateDescription vmstate_usb_kbd = {
     }
 };
 
+static void usb_tablet_class_initfn(ObjectClass *klass, void *data)
+{
+    USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+    uc->init           = usb_tablet_initfn;
+    uc->product_desc   = "QEMU USB Tablet";
+    uc->usb_desc       = &desc_tablet;
+    uc->handle_packet  = usb_generic_handle_packet;
+    uc->handle_reset   = usb_hid_handle_reset;
+    uc->handle_control = usb_hid_handle_control;
+    uc->handle_data    = usb_hid_handle_data;
+    uc->handle_destroy = usb_hid_handle_destroy;
+}
+
+static void usb_mouse_class_initfn(ObjectClass *klass, void *data)
+{
+    USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+    uc->init           = usb_mouse_initfn;
+    uc->product_desc   = "QEMU USB Mouse";
+    uc->usb_desc       = &desc_mouse;
+    uc->handle_packet  = usb_generic_handle_packet;
+    uc->handle_reset   = usb_hid_handle_reset;
+    uc->handle_control = usb_hid_handle_control;
+    uc->handle_data    = usb_hid_handle_data;
+    uc->handle_destroy = usb_hid_handle_destroy;
+}
+
+static void usb_keyboard_class_initfn(ObjectClass *klass, void *data)
+{
+    USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+    uc->init           = usb_keyboard_initfn;
+    uc->product_desc   = "QEMU USB Keyboard";
+    uc->usb_desc       = &desc_keyboard;
+    uc->handle_packet  = usb_generic_handle_packet;
+    uc->handle_reset   = usb_hid_handle_reset;
+    uc->handle_control = usb_hid_handle_control;
+    uc->handle_data    = usb_hid_handle_data;
+    uc->handle_destroy = usb_hid_handle_destroy;
+}
+
 static struct USBDeviceInfo hid_info[] = {
     {
-        .product_desc   = "QEMU USB Tablet",
         .qdev.name      = "usb-tablet",
-        .usbdevice_name = "tablet",
         .qdev.size      = sizeof(USBHIDState),
         .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,
-        .handle_destroy = usb_hid_handle_destroy,
+        .qdev.class_init= usb_tablet_class_initfn,
+        .usbdevice_name = "tablet",
     },{
-        .product_desc   = "QEMU USB Mouse",
         .qdev.name      = "usb-mouse",
-        .usbdevice_name = "mouse",
         .qdev.size      = sizeof(USBHIDState),
         .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,
-        .handle_destroy = usb_hid_handle_destroy,
+        .qdev.class_init= usb_mouse_class_initfn,
+        .usbdevice_name = "mouse",
     },{
-        .product_desc   = "QEMU USB Keyboard",
         .qdev.name      = "usb-kbd",
-        .usbdevice_name = "keyboard",
         .qdev.size      = sizeof(USBHIDState),
         .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,
-        .handle_destroy = usb_hid_handle_destroy,
+        .qdev.class_init= usb_keyboard_class_initfn,
+        .usbdevice_name = "keyboard",
     },{
         /* end of list */
     }
diff --git a/hw/usb-hub.c b/hw/usb-hub.c
index e195937..5a52964 100644
--- a/hw/usb-hub.c
+++ b/hw/usb-hub.c
@@ -540,19 +540,26 @@  static const VMStateDescription vmstate_usb_hub = {
     }
 };
 
+static void  usb_hub_class_initfn(ObjectClass *klass, void *data)
+{
+    USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+    uc->init           = usb_hub_initfn;
+    uc->product_desc   = "QEMU USB Hub";
+    uc->usb_desc       = &desc_hub;
+    uc->handle_packet  = usb_hub_handle_packet;
+    uc->handle_reset   = usb_hub_handle_reset;
+    uc->handle_control = usb_hub_handle_control;
+    uc->handle_data    = usb_hub_handle_data;
+    uc->handle_destroy = usb_hub_handle_destroy;
+}
+
 static struct USBDeviceInfo hub_info = {
-    .product_desc   = "QEMU USB Hub",
     .qdev.name      = "usb-hub",
-    .qdev.fw_name    = "hub",
+    .qdev.fw_name   = "hub",
     .qdev.size      = sizeof(USBHubState),
     .qdev.vmsd      = &vmstate_usb_hub,
-    .usb_desc       = &desc_hub,
-    .init           = usb_hub_initfn,
-    .handle_packet  = usb_hub_handle_packet,
-    .handle_reset   = usb_hub_handle_reset,
-    .handle_control = usb_hub_handle_control,
-    .handle_data    = usb_hub_handle_data,
-    .handle_destroy = usb_hub_handle_destroy,
+    .qdev.class_init= usb_hub_class_initfn,
 };
 
 static void usb_hub_register_devices(void)
diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index 4c06950..bb63a6a 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -634,28 +634,35 @@  static const VMStateDescription vmstate_usb_msd = {
     }
 };
 
+static void usb_msd_class_initfn(ObjectClass *klass, void *data)
+{
+    USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+    uc->init           = usb_msd_initfn;
+    uc->product_desc   = "QEMU USB MSD";
+    uc->usb_desc       = &desc;
+    uc->handle_packet  = usb_generic_handle_packet;
+    uc->cancel_packet  = usb_msd_cancel_io;
+    uc->handle_attach  = usb_desc_attach;
+    uc->handle_reset   = usb_msd_handle_reset;
+    uc->handle_control = usb_msd_handle_control;
+    uc->handle_data    = usb_msd_handle_data;
+}
+
 static struct USBDeviceInfo msd_info = {
-    .product_desc   = "QEMU USB MSD",
     .qdev.name      = "usb-storage",
-    .qdev.fw_name      = "storage",
+    .qdev.fw_name   = "storage",
     .qdev.size      = sizeof(MSDState),
     .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,
-    .handle_control = usb_msd_handle_control,
-    .handle_data    = usb_msd_handle_data,
-    .usbdevice_name = "disk",
-    .usbdevice_init = usb_msd_init,
+    .qdev.class_init= usb_msd_class_initfn,
     .qdev.props     = (Property[]) {
         DEFINE_BLOCK_PROPERTIES(MSDState, conf),
         DEFINE_PROP_STRING("serial", MSDState, serial),
         DEFINE_PROP_BIT("removable", MSDState, removable, 0, false),
         DEFINE_PROP_END_OF_LIST(),
     },
+    .usbdevice_name = "disk",
+    .usbdevice_init = usb_msd_init,
 };
 
 static void usb_msd_register_devices(void)
diff --git a/hw/usb-net.c b/hw/usb-net.c
index c4b29a9..50c66d7 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -1398,25 +1398,33 @@  static const VMStateDescription vmstate_usb_net = {
     .unmigratable = 1,
 };
 
+static void usb_net_class_initfn(ObjectClass *klass, void *data)
+{
+    USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+    uc->init           = usb_net_initfn;
+    uc->product_desc   = "QEMU USB Network Interface";
+    uc->usb_desc       = &desc_net;
+    uc->handle_packet  = usb_generic_handle_packet;
+    uc->handle_reset   = usb_net_handle_reset;
+    uc->handle_control = usb_net_handle_control;
+    uc->handle_data    = usb_net_handle_data;
+    uc->handle_destroy = usb_net_handle_destroy;
+}
+
 static struct USBDeviceInfo net_info = {
-    .product_desc   = "QEMU USB Network Interface",
     .qdev.name      = "usb-net",
-    .qdev.fw_name    = "network",
+    .qdev.fw_name   = "network",
     .qdev.size      = sizeof(USBNetState),
     .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,
-    .handle_destroy = usb_net_handle_destroy,
-    .usbdevice_name = "net",
-    .usbdevice_init = usb_net_init,
+    .qdev.class_init= usb_net_class_initfn,
     .qdev.props     = (Property[]) {
         DEFINE_NIC_PROPERTIES(USBNetState, conf),
         DEFINE_PROP_END_OF_LIST(),
-    }
+    },
+
+    .usbdevice_name = "net",
+    .usbdevice_init = usb_net_init,
 };
 
 static void usb_net_register_devices(void)
diff --git a/hw/usb-serial.c b/hw/usb-serial.c
index 7dbf6df..33d6163 100644
--- a/hw/usb-serial.c
+++ b/hw/usb-serial.c
@@ -577,44 +577,59 @@  static const VMStateDescription vmstate_usb_serial = {
     .unmigratable = 1,
 };
 
+static void usb_serial_class_initfn(ObjectClass *klass, void *data)
+{
+    USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+    uc->init = usb_serial_initfn;
+    uc->product_desc   = "QEMU USB Serial";
+    uc->usb_desc       = &desc_serial;
+    uc->handle_packet  = usb_generic_handle_packet;
+    uc->handle_reset   = usb_serial_handle_reset;
+    uc->handle_control = usb_serial_handle_control;
+    uc->handle_data    = usb_serial_handle_data;
+    uc->handle_destroy = usb_serial_handle_destroy;
+}
+
 static struct USBDeviceInfo serial_info = {
-    .product_desc   = "QEMU USB Serial",
     .qdev.name      = "usb-serial",
     .qdev.size      = sizeof(USBSerialState),
     .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,
-    .handle_destroy = usb_serial_handle_destroy,
-    .usbdevice_name = "serial",
-    .usbdevice_init = usb_serial_init,
+    .qdev.class_init= usb_serial_class_initfn,
     .qdev.props     = (Property[]) {
         DEFINE_PROP_CHR("chardev", USBSerialState, cs),
         DEFINE_PROP_END_OF_LIST(),
     },
+
+    .usbdevice_name = "serial",
+    .usbdevice_init = usb_serial_init,
 };
 
+static void usb_braille_class_initfn(ObjectClass *klass, void *data)
+{
+    USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+    uc->init           = usb_serial_initfn;
+    uc->product_desc   = "QEMU USB Braille";
+    uc->usb_desc       = &desc_braille;
+    uc->handle_packet  = usb_generic_handle_packet;
+    uc->handle_reset   = usb_serial_handle_reset;
+    uc->handle_control = usb_serial_handle_control;
+    uc->handle_data    = usb_serial_handle_data;
+    uc->handle_destroy = usb_serial_handle_destroy;
+}
+
 static struct USBDeviceInfo braille_info = {
-    .product_desc   = "QEMU USB Braille",
     .qdev.name      = "usb-braille",
     .qdev.size      = sizeof(USBSerialState),
     .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,
-    .handle_destroy = usb_serial_handle_destroy,
-    .usbdevice_name = "braille",
-    .usbdevice_init = usb_braille_init,
+    .qdev.class_init= usb_braille_class_initfn,
     .qdev.props     = (Property[]) {
         DEFINE_PROP_CHR("chardev", USBSerialState, cs),
         DEFINE_PROP_END_OF_LIST(),
     },
+    .usbdevice_name = "braille",
+    .usbdevice_init = usb_braille_init,
 };
 
 static void usb_serial_register_devices(void)
diff --git a/hw/usb-wacom.c b/hw/usb-wacom.c
index 2558006..448b8f2 100644
--- a/hw/usb-wacom.c
+++ b/hw/usb-wacom.c
@@ -356,20 +356,27 @@  static const VMStateDescription vmstate_usb_wacom = {
     .unmigratable = 1,
 };
 
+static void usb_wacom_class_init(ObjectClass *class, void *data)
+{
+    USBDeviceClass *uc = USB_DEVICE_CLASS(class);
+
+    uc->product_desc   = "QEMU PenPartner Tablet";
+    uc->usb_desc       = &desc_wacom;
+    uc->init           = usb_wacom_initfn;
+    uc->handle_packet  = usb_generic_handle_packet;
+    uc->handle_reset   = usb_wacom_handle_reset;
+    uc->handle_control = usb_wacom_handle_control;
+    uc->handle_data    = usb_wacom_handle_data;
+    uc->handle_destroy = usb_wacom_handle_destroy;
+}
+
 static struct USBDeviceInfo wacom_info = {
-    .product_desc   = "QEMU PenPartner Tablet",
     .qdev.name      = "usb-wacom-tablet",
     .qdev.desc      = "QEMU PenPartner Tablet",
-    .usbdevice_name = "wacom-tablet",
-    .usb_desc       = &desc_wacom,
     .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,
-    .handle_destroy = usb_wacom_handle_destroy,
+    .qdev.class_init= usb_wacom_class_init,
+    .usbdevice_name = "wacom-tablet",
 };
 
 static void usb_wacom_register_devices(void)
diff --git a/hw/usb.h b/hw/usb.h
index ee780b0..602ddb9 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -174,39 +174,7 @@  struct USBDescString {
 
 typedef struct USBDeviceClass {
     DeviceClass parent_class;
-} USBDeviceClass;
-
-/* definition of a USB device */
-struct USBDevice {
-    DeviceState qdev;
-    USBPort *port;
-    char *port_path;
-    void *opaque;
-
-    /* Actual connected speed */
-    int speed;
-    /* Supported speeds, not in info because it may be variable (hostdevs) */
-    int speedmask;
-    uint8_t addr;
-    char product_desc[32];
-    int auto_attach;
-    int attached;
-
-    int32_t state;
-    uint8_t setup_buf[8];
-    uint8_t data_buf[4096];
-    int32_t remote_wakeup;
-    int32_t setup_state;
-    int32_t setup_len;
-    int32_t setup_index;
-
-    QLIST_HEAD(, USBDescString) strings;
-    const USBDescDevice *device;
-    const USBDescConfig *config;
-};
 
-struct USBDeviceInfo {
-    DeviceInfo qdev;
     int (*init)(USBDevice *dev);
 
     /*
@@ -257,7 +225,39 @@  struct USBDeviceInfo {
 
     const char *product_desc;
     const USBDesc *usb_desc;
+} USBDeviceClass;
+
+/* definition of a USB device */
+struct USBDevice {
+    DeviceState qdev;
+    USBPort *port;
+    char *port_path;
+    void *opaque;
+
+    /* Actual connected speed */
+    int speed;
+    /* Supported speeds, not in info because it may be variable (hostdevs) */
+    int speedmask;
+    uint8_t addr;
+    char product_desc[32];
+    int auto_attach;
+    int attached;
+
+    int32_t state;
+    uint8_t setup_buf[8];
+    uint8_t data_buf[4096];
+    int32_t remote_wakeup;
+    int32_t setup_state;
+    int32_t setup_len;
+    int32_t setup_index;
+
+    QLIST_HEAD(, USBDescString) strings;
+    const USBDescDevice *device;
+    const USBDescConfig *config;
+};
 
+struct USBDeviceInfo {
+    DeviceInfo qdev;
     /* handle legacy -usbdevice command line options */
     const char *usbdevice_name;
     USBDevice *(*usbdevice_init)(const char *params);
diff --git a/usb-linux.c b/usb-linux.c
index ab4c693..15e3d5e 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -1428,20 +1428,25 @@  static const VMStateDescription vmstate_usb_host = {
     .unmigratable = 1,
 };
 
+static void usb_host_class_initfn(ObjectClass *klass, void *data)
+{
+    USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+    uc->init           = usb_host_initfn;
+    uc->product_desc   = "USB Host Device";
+    uc->handle_packet  = usb_generic_handle_packet;
+    uc->cancel_packet  = usb_host_async_cancel;
+    uc->handle_data    = usb_host_handle_data;
+    uc->handle_control = usb_host_handle_control;
+    uc->handle_reset   = usb_host_handle_reset;
+    uc->handle_destroy = usb_host_handle_destroy;
+}
+
 static struct USBDeviceInfo usb_host_dev_info = {
-    .product_desc   = "USB Host Device",
     .qdev.name      = "usb-host",
     .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,
-    .handle_reset   = usb_host_handle_reset,
-    .handle_destroy = usb_host_handle_destroy,
-    .usbdevice_name = "host",
-    .usbdevice_init = usb_host_device_open,
+    .qdev.class_init= usb_host_class_initfn,
     .qdev.props     = (Property[]) {
         DEFINE_PROP_UINT32("hostbus",  USBHostDevice, match.bus_num,    0),
         DEFINE_PROP_UINT32("hostaddr", USBHostDevice, match.addr,       0),
@@ -1451,6 +1456,8 @@  static struct USBDeviceInfo usb_host_dev_info = {
         DEFINE_PROP_UINT32("isobufs",  USBHostDevice, iso_urb_count,    4),
         DEFINE_PROP_END_OF_LIST(),
     },
+    .usbdevice_name = "host",
+    .usbdevice_init = usb_host_device_open,
 };
 
 static void usb_host_register_devices(void)