Skip to contentSkip to conversation

usb/ehci: Refactor ehci-sysbus to add exynos4210 ehci support

PATCH In review Liming Wang 2 participants 3 messages Dec 1, 2012 Arm Samsung Exynos

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 usb/ehci: Refactor ehci-sysbus to add exynos4210 ehci support

Refactor ehci-sysbus to accept different capsbase and opregbase. And then add exynos4210 ehci support to ehci-sysbus.

---
 hw/usb/hcd-ehci-sysbus.c |   48 ++++++++++++++++++++++++++++++++++++----------
 1 file changed, 38 insertions(+), 10 deletions(-)
hw/usb/hcd-ehci-sysbus.c +38 -10
index 803df92..f4f3ffe 100644
@@ -23,6 +23,11 @@ typedef struct EHCISysBusState {
     EHCIState ehci;
 } EHCISysBusState;
 
+typedef struct EHCISysBusClass {
+    SysBusDeviceClass sdc;
+    EHCIState ehci;
+} EHCISysBusClass;
+
 static const VMStateDescription vmstate_ehci_sysbus = {
     .name        = "ehci-sysbus",
     .version_id  = 2,
@@ -41,10 +46,11 @@ static Property ehci_sysbus_properties[] = {
 static int usb_ehci_sysbus_initfn(SysBusDevice *dev)
 {
     EHCISysBusState *i = FROM_SYSBUS(EHCISysBusState, dev);
+    EHCISysBusClass *c = (EHCISysBusClass *)object_get_class(OBJECT(dev));
     EHCIState *s = &i->ehci;
 
-    s->capsbase = 0x100;
-    s->opregbase = 0x140;
+    s->capsbase = c->ehci.capsbase;
+    s->opregbase = c->ehci.opregbase;
     s->dma = &dma_context_memory;
 
     usb_ehci_initfn(s, DEVICE(dev));
@@ -56,23 +62,45 @@ static int usb_ehci_sysbus_initfn(SysBusDevice *dev)
 static void ehci_sysbus_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+    EHCISysBusClass *k = (EHCISysBusClass *)klass;
+    EHCISysBusClass *c = (EHCISysBusClass *)data;
 
-    k->init = usb_ehci_sysbus_initfn;
+    k->sdc.init = usb_ehci_sysbus_initfn;
+    k->ehci = c->ehci;
     dc->vmsd = &vmstate_ehci_sysbus;
     dc->props = ehci_sysbus_properties;
 }
 
-TypeInfo ehci_xlnx_type_info = {
-    .name          = "xlnx,ps7-usb",
-    .parent        = TYPE_SYS_BUS_DEVICE,
-    .instance_size = sizeof(EHCISysBusState),
-    .class_init    = ehci_sysbus_class_init,
+static TypeInfo ehci_sysbus_type_info[] = {
+    {
+        .name          = "xlnx,ps7-usb",
+        .parent        = TYPE_SYS_BUS_DEVICE,
+        .instance_size = sizeof(EHCISysBusState),
+        .class_init    = ehci_sysbus_class_init,
+        .class_size    = sizeof(EHCISysBusClass),
+        .class_data    = (EHCISysBusClass[]) {{
+	    .ehci.capsbase  = 0x100,
+	    .ehci.opregbase = 0x140,
+        } }
+    }, {
+        .name          = "exynos4210.usb",
+        .parent        = TYPE_SYS_BUS_DEVICE,
+        .instance_size = sizeof(EHCISysBusState),
+        .class_init    = ehci_sysbus_class_init,
+        .class_size    = sizeof(EHCISysBusClass),
+        .class_data    = (EHCISysBusClass[]) {{
+            .ehci.capsbase  = 0x0,
+            .ehci.opregbase = 0x40,
+        } }
+    },
 };
 
 static void ehci_sysbus_register_types(void)
 {
-    type_register_static(&ehci_xlnx_type_info);
+    int i;
+    for (i = 0; i < ARRAY_SIZE(ehci_sysbus_type_info); i++) {
+        type_register_static(&ehci_sysbus_type_info[i]);
+    }
 }
 
 type_init(ehci_sysbus_register_types)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 2/2 exynos4210: Add ehci support

Add ehci host controller to exynos4210.

---
 hw/exynos4210.c     |    6 ++++++
 hw/exynos4210_gic.c |    2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)
hw/exynos4210.c +6 -0
index 00d4db8..e0913a5 100644
@@ -72,6 +72,9 @@
 /* Display controllers (FIMD) */
 #define EXYNOS4210_FIMD0_BASE_ADDR          0x11C00000
 
+/* EHCI */
+#define EXYNOS4210_EHCI_BASE_ADDR           0x12580000
+
 static uint8_t chipid_and_omr[] = { 0x11, 0x02, 0x21, 0x43,
                                     0x09, 0x00, 0x00, 0x00 };
 
@@ -334,5 +337,8 @@ Exynos4210State *exynos4210_init(MemoryRegion *system_mem,
             s->irq_table[exynos4210_get_irq(11, 2)],
             NULL);
 
+    sysbus_create_simple("exynos4210.usb", EXYNOS4210_EHCI_BASE_ADDR,
+            s->irq_table[exynos4210_get_irq(28, 3)]);
+
     return s;
 }
hw/exynos4210_gic.c +1 -1
index 4fea098..959de56 100644
@@ -140,7 +140,7 @@ combiner_grp_to_gic_id[64-EXYNOS4210_MAX_EXT_COMBINER_OUT_IRQ][8] = {
             EXT_GIC_ID_I2C4, EXT_GIC_ID_I2C5, EXT_GIC_ID_I2C6,
             EXT_GIC_ID_I2C7 },
     /* int combiner group 28 */
-    { EXT_GIC_ID_SPI0, EXT_GIC_ID_SPI1, EXT_GIC_ID_SPI2 },
+    { EXT_GIC_ID_SPI0, EXT_GIC_ID_SPI1, EXT_GIC_ID_SPI2 , EXT_GIC_ID_USB_HOST},
     /* int combiner group 29 */
     { EXT_GIC_ID_HSMMC0, EXT_GIC_ID_HSMMC1, EXT_GIC_ID_HSMMC2,
      EXT_GIC_ID_HSMMC3, EXT_GIC_ID_SDMMC },
Signature · 1 line
1.7.9.5
#2 lore raw
In reply to Liming Wang

Am 01.12.2012 16:27, schrieb Liming Wang:

Quoted 13 lines

Refactor ehci-sysbus to accept different capsbase and opregbase. And then add exynos4210 ehci support to ehci-sysbus.

---
 hw/usb/hcd-ehci-sysbus.c |   48 ++++++++++++++++++++++++++++++++++++----------
 1 file changed, 38 insertions(+), 10 deletions(-)
hw/usb/hcd-ehci-sysbus.c +0 -0
index 803df92..f4f3ffe 100644

hw/usb/hcd-ehci-sysbus.c typedef struct EHCISysBusState { · line 29

Quoted 7 lines
hw/usb/hcd-ehci-sysbus.c +4 -0
@@ -23,6 +23,11 @@ typedef struct EHCISysBusState {
     EHCIState ehci;
 } EHCISysBusState;
 
+typedef struct EHCISysBusClass {
+    SysBusDeviceClass sdc;
+    EHCIState ehci;
+} EHCISysBusClass;

This is still not the right way to do this. And please keep me CC'ed.

FWIW sdc should be named parent_class and separated from normal fields.

hw/usb/hcd-ehci-sysbus.c static Property ehci_sysbus_properties[] = { · line 49

Quoted 9 lines
hw/usb/hcd-ehci-sysbus.c +2 -0
+
 static const VMStateDescription vmstate_ehci_sysbus = {
     .name        = "ehci-sysbus",
     .version_id  = 2,
@@ -41,10 +46,11 @@ static Property ehci_sysbus_properties[] = {
 static int usb_ehci_sysbus_initfn(SysBusDevice *dev)
 {
     EHCISysBusState *i = FROM_SYSBUS(EHCISysBusState, dev);
+    EHCISysBusClass *c = (EHCISysBusClass *)object_get_class(OBJECT(dev));

If you add a class, you also need to add a matching cast macro (and in this case TypeInfo) and use that. I'm not aware of any other example that does it like this, otherwise please point it out so that it can be fixed.

Quoted 10 lines
hw/usb/hcd-ehci-sysbus.c +2 -2
     EHCIState *s = &i->ehci;
 
-    s->capsbase = 0x100;
-    s->opregbase = 0x140;
+    s->capsbase = c->ehci.capsbase;
+    s->opregbase = c->ehci.opregbase;
     s->dma = &dma_context_memory;
 
     usb_ehci_initfn(s, DEVICE(dev));

hw/usb/hcd-ehci-sysbus.c static int usb_ehci_sysbus_initfn(SysBusDevice *dev) · line 68

Quoted 9 lines
hw/usb/hcd-ehci-sysbus.c +3 -2
@@ -56,23 +62,45 @@ static int usb_ehci_sysbus_initfn(SysBusDevice *dev)
 static void ehci_sysbus_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+    EHCISysBusClass *k = (EHCISysBusClass *)klass;
+    EHCISysBusClass *c = (EHCISysBusClass *)data;
 
-    k->init = usb_ehci_sysbus_initfn;
+    k->sdc.init = usb_ehci_sysbus_initfn;

Never access the parent field directly, use a cast macro.

Quoted 11 lines
hw/usb/hcd-ehci-sysbus.c +2 -5
+    k->ehci = c->ehci;
     dc->vmsd = &vmstate_ehci_sysbus;
     dc->props = ehci_sysbus_properties;
 }
 
-TypeInfo ehci_xlnx_type_info = {
-    .name          = "xlnx,ps7-usb",
-    .parent        = TYPE_SYS_BUS_DEVICE,
-    .instance_size = sizeof(EHCISysBusState),
-    .class_init    = ehci_sysbus_class_init,
+static TypeInfo ehci_sysbus_type_info[] = {

hw/usb/hcd-ehci-sysbus.c static int usb_ehci_sysbus_initfn(SysBusDevice *dev) · line 84

Quoted 10 lines
hw/usb/hcd-ehci-sysbus.c +10 -0
+    {
+        .name          = "xlnx,ps7-usb",
+        .parent        = TYPE_SYS_BUS_DEVICE,
+        .instance_size = sizeof(EHCISysBusState),
+        .class_init    = ehci_sysbus_class_init,
+        .class_size    = sizeof(EHCISysBusClass),
+        .class_data    = (EHCISysBusClass[]) {{
+	    .ehci.capsbase  = 0x100,
+	    .ehci.opregbase = 0x140,
+        } }

Neither is this. As discussed before, this is misusing QOM concepts. The instance state has no business being stored in the class, and the class shouldn't be duplicated to initialize itself, even less so when it's only about two integer values.

Quoted 9 lines
hw/usb/hcd-ehci-sysbus.c +9 -0
+    }, {
+        .name          = "exynos4210.usb",
+        .parent        = TYPE_SYS_BUS_DEVICE,
+        .instance_size = sizeof(EHCISysBusState),
+        .class_init    = ehci_sysbus_class_init,
+        .class_size    = sizeof(EHCISysBusClass),
+        .class_data    = (EHCISysBusClass[]) {{
+            .ehci.capsbase  = 0x0,
+            .ehci.opregbase = 0x40,

hw/usb/hcd-ehci-sysbus.c static int usb_ehci_sysbus_initfn(SysBusDevice *dev) · line 102

Quoted 10 lines
hw/usb/hcd-ehci-sysbus.c +5 -1
+        } }
+    },
 };
 
 static void ehci_sysbus_register_types(void)
 {
-    type_register_static(&ehci_xlnx_type_info);
+    int i;
+    for (i = 0; i < ARRAY_SIZE(ehci_sysbus_type_info); i++) {
+        type_register_static(&ehci_sysbus_type_info[i]);

If a loop becomes necessary, this is indicating that something is in the odds, complicating things. As indicated to Gerd at KVM Forum, I didn't get around to sending out a cleanup yet (and have been busy since):

We need an abstract intermediate type whose class specifies only the needed fields (capsbase, opregbase), has cast macros to access them and stores the majority of TypeInfo cruft that you are duplicating here. The specific types (xlnx, exynos, tegra) would then add their own class_init on top to set/override those two values, and the base class' instance_init would copy them over. I'll try to find some spare minutes tomorrow.

Regards,
Andreas

Quoted 5 lines
hw/usb/hcd-ehci-sysbus.c +1 -0
+    }
 }
 
 type_init(ehci_sysbus_register_types)
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg