[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 02/11] usb/ehci: Use class_data to init PCI varia
From: |
Peter Crosthwaite |
Subject: |
[Qemu-devel] [PATCH v2 02/11] usb/ehci: Use class_data to init PCI variations |
Date: |
Fri, 26 Oct 2012 15:47:42 +1000 |
Got rid of the duplication of the class init functions for the two PCI EHCI
variants. The PCI specifics are passed in as as class_data and set by a common
class_init function.
Premeptively defined a new Class "EHCICLass" for the upcomming addition of new
fields. The class_data is an instance of EHCICLass that forms a template for the
class to generate.
Signed-off-by: Peter Crosthwaite <address@hidden>
---
hw/usb/hcd-ehci.c | 81 ++++++++++++++++++++++++++++++-----------------------
1 files changed, 46 insertions(+), 35 deletions(-)
diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index 6c65a73..625ec2a 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -2641,46 +2641,54 @@ static Property ehci_properties[] = {
DEFINE_PROP_END_OF_LIST(),
};
-static void ehci_class_init(ObjectClass *klass, void *data)
-{
- DeviceClass *dc = DEVICE_CLASS(klass);
- PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
-
- k->init = usb_ehci_initfn;
- k->vendor_id = PCI_VENDOR_ID_INTEL;
- k->device_id = PCI_DEVICE_ID_INTEL_82801D; /* ich4 */
- k->revision = 0x10;
- k->class_id = PCI_CLASS_SERIAL_USB;
- dc->vmsd = &vmstate_ehci;
- dc->props = ehci_properties;
-}
-
-static TypeInfo ehci_info = {
- .name = "usb-ehci",
- .parent = TYPE_PCI_DEVICE,
- .instance_size = sizeof(EHCIState),
- .class_init = ehci_class_init,
-};
+typedef struct EHCIClass {
+ union {
+ PCIDeviceClass pci;
+ };
+} EHCIClass;
-static void ich9_ehci_class_init(ObjectClass *klass, void *data)
+static void ehci_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
- PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
-
- k->init = usb_ehci_initfn;
- k->vendor_id = PCI_VENDOR_ID_INTEL;
- k->device_id = PCI_DEVICE_ID_INTEL_82801I_EHCI1;
- k->revision = 0x03;
- k->class_id = PCI_CLASS_SERIAL_USB;
+ /* FIXME: how do you do object check for a dynamic class? */
+ EHCIClass *k = (EHCIClass *)klass;
+ EHCIClass *template = data;
+
+ k->pci.init = usb_ehci_initfn;
+ k->pci.vendor_id = template->pci.vendor_id;
+ k->pci.device_id = template->pci.device_id; /* ich4 */
+ k->pci.revision = template->pci.revision;
+ k->pci.class_id = PCI_CLASS_SERIAL_USB;
dc->vmsd = &vmstate_ehci;
dc->props = ehci_properties;
}
-static TypeInfo ich9_ehci_info = {
- .name = "ich9-usb-ehci1",
- .parent = TYPE_PCI_DEVICE,
- .instance_size = sizeof(EHCIState),
- .class_init = ich9_ehci_class_init,
+static TypeInfo ehci_info[] = {
+ {
+ .name = "usb-ehci",
+ .parent = TYPE_PCI_DEVICE,
+ .instance_size = sizeof(EHCIState),
+ .class_init = ehci_class_init,
+ .class_size = sizeof(EHCIClass),
+ .class_data = (EHCIClass[]) {{{
+ .pci.vendor_id = PCI_VENDOR_ID_INTEL,
+ .pci.device_id = PCI_DEVICE_ID_INTEL_82801D,
+ .pci.revision = 0x10,
+ }
+ } }
+ }, {
+ .name = "ich9-usb-ehci1",
+ .parent = TYPE_PCI_DEVICE,
+ .instance_size = sizeof(EHCIState),
+ .class_init = ehci_class_init,
+ .class_size = sizeof(EHCIClass),
+ .class_data = (EHCIClass[]) {{{
+ .pci.vendor_id = PCI_VENDOR_ID_INTEL,
+ .pci.device_id = PCI_DEVICE_ID_INTEL_82801I_EHCI1,
+ .pci.revision = 0x03,
+ }
+ } }
+ }, { .name = NULL }
};
static int usb_ehci_initfn(PCIDevice *dev)
@@ -2769,8 +2777,11 @@ static int usb_ehci_initfn(PCIDevice *dev)
static void ehci_register_types(void)
{
- type_register_static(&ehci_info);
- type_register_static(&ich9_ehci_info);
+ TypeInfo *ti;
+
+ for (ti = ehci_info; ti->name; ti++) {
+ type_register_static(ti);
+ }
}
type_init(ehci_register_types)
--
1.7.0.4