Skip to content

Commit

Permalink
uhci: QOMify
Browse files Browse the repository at this point in the history
Cc: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Gonglei <arei.gonglei@huawei.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
  • Loading branch information
gongleiarei authored and kraxel committed May 8, 2015
1 parent df0f169 commit 49184b6
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions hw/usb/hcd-uhci.c
Expand Up @@ -154,6 +154,9 @@ static void uhci_async_cancel(UHCIAsync *async);
static void uhci_queue_fill(UHCIQueue *q, UHCI_TD *td);
static void uhci_resume(void *opaque);

#define TYPE_UHCI "pci-uhci-usb"
#define UHCI(obj) OBJECT_CHECK(UHCIState, (obj), TYPE_UHCI)

static inline int32_t uhci_queue_token(UHCI_TD *td)
{
if ((td->token & (0xf << 15)) == 0) {
Expand Down Expand Up @@ -351,7 +354,7 @@ static void uhci_update_irq(UHCIState *s)
static void uhci_reset(DeviceState *dev)
{
PCIDevice *d = PCI_DEVICE(dev);
UHCIState *s = DO_UPCAST(UHCIState, dev, d);
UHCIState *s = UHCI(d);
uint8_t *pci_conf;
int i;
UHCIPort *port;
Expand Down Expand Up @@ -1196,7 +1199,7 @@ static void usb_uhci_common_realize(PCIDevice *dev, Error **errp)
Error *err = NULL;
PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
UHCIPCIDeviceClass *u = container_of(pc, UHCIPCIDeviceClass, parent_class);
UHCIState *s = DO_UPCAST(UHCIState, dev, dev);
UHCIState *s = UHCI(dev);
uint8_t *pci_conf = s->dev.config;
int i;

Expand Down Expand Up @@ -1241,7 +1244,7 @@ static void usb_uhci_common_realize(PCIDevice *dev, Error **errp)

static void usb_uhci_vt82c686b_realize(PCIDevice *dev, Error **errp)
{
UHCIState *s = DO_UPCAST(UHCIState, dev, dev);
UHCIState *s = UHCI(dev);
uint8_t *pci_conf = s->dev.config;

/* USB misc control 1/2 */
Expand All @@ -1256,7 +1259,7 @@ static void usb_uhci_vt82c686b_realize(PCIDevice *dev, Error **errp)

static void usb_uhci_exit(PCIDevice *dev)
{
UHCIState *s = DO_UPCAST(UHCIState, dev, dev);
UHCIState *s = UHCI(dev);

trace_usb_uhci_exit();

Expand Down Expand Up @@ -1294,6 +1297,26 @@ static void uhci_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);

k->class_id = PCI_CLASS_SERIAL_USB;
dc->vmsd = &vmstate_uhci;
dc->reset = uhci_reset;
set_bit(DEVICE_CATEGORY_USB, dc->categories);
}

static const TypeInfo uhci_pci_type_info = {
.name = TYPE_UHCI,
.parent = TYPE_PCI_DEVICE,
.instance_size = sizeof(UHCIState),
.class_size = sizeof(UHCIPCIDeviceClass),
.abstract = true,
.class_init = uhci_class_init,
};

static void uhci_data_class_init(ObjectClass *klass, void *data)
{
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
DeviceClass *dc = DEVICE_CLASS(klass);
UHCIPCIDeviceClass *u = container_of(k, UHCIPCIDeviceClass, parent_class);
UHCIInfo *info = data;

Expand All @@ -1302,17 +1325,13 @@ static void uhci_class_init(ObjectClass *klass, void *data)
k->vendor_id = info->vendor_id;
k->device_id = info->device_id;
k->revision = info->revision;
k->class_id = PCI_CLASS_SERIAL_USB;
dc->vmsd = &vmstate_uhci;
dc->reset = uhci_reset;
if (!info->unplug) {
/* uhci controllers in companion setups can't be hotplugged */
dc->hotpluggable = false;
dc->props = uhci_properties_companion;
} else {
dc->props = uhci_properties_standalone;
}
set_bit(DEVICE_CATEGORY_USB, dc->categories);
u->info = *info;
}

Expand Down Expand Up @@ -1387,13 +1406,13 @@ static UHCIInfo uhci_info[] = {
static void uhci_register_types(void)
{
TypeInfo uhci_type_info = {
.parent = TYPE_PCI_DEVICE,
.instance_size = sizeof(UHCIState),
.class_size = sizeof(UHCIPCIDeviceClass),
.class_init = uhci_class_init,
.parent = TYPE_UHCI,
.class_init = uhci_data_class_init,
};
int i;

type_register_static(&uhci_pci_type_info);

for (i = 0; i < ARRAY_SIZE(uhci_info); i++) {
uhci_type_info.name = uhci_info[i].name;
uhci_type_info.class_data = uhci_info + i;
Expand Down

0 comments on commit 49184b6

Please sign in to comment.