Patchwork [v1,4/8] usb/ehci: Add usb-ehci-sysbus

login
register
mail settings
Submitter Peter Crosthwaite
Date Oct. 25, 2012, 9:47 a.m.
Message ID <ea740ca8be71158d5d5e58e79a16b5a0cba692d1.1351157627.git.peter.crosthwaite@xilinx.com>
Download mbox | patch
Permalink /patch/194104/
State New
Headers show

Comments

Peter Crosthwaite - Oct. 25, 2012, 9:47 a.m.
Add QOM device definition for sysbus attached EHCI.

Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
---

 hw/usb/hcd-ehci.c |   53 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 52 insertions(+), 1 deletions(-)
Gerd Hoffmann - Oct. 25, 2012, 12:10 p.m.
>  typedef struct EHCIItfState {
> -    PCIDevice pcidev;
> +    /* FIXME: Figure out a better way to share one Property[] array between two
> +     * QOM types with different parents
> +     */
> +    union {
> +        PCIDevice pcidev;
> +        SysBusDevice busdev;
> +    };

Ah, I see where this hack comes from.  I don't think they should share
the properties in the first place ...

cheers,
  Gerd
Peter Crosthwaite - Oct. 25, 2012, 12:39 p.m.
On Thu, Oct 25, 2012 at 10:10 PM, Gerd Hoffmann <kraxel@redhat.com> wrote:
>>  typedef struct EHCIItfState {
>> -    PCIDevice pcidev;
>> +    /* FIXME: Figure out a better way to share one Property[] array between two
>> +     * QOM types with different parents
>> +     */
>> +    union {
>> +        PCIDevice pcidev;
>> +        SysBusDevice busdev;
>> +    };
>
> Ah, I see where this hack comes from.  I don't think they should share
> the properties in the first place ...
>

Kind of annoying to not share them as it really is a copy paste job
with the exception of the wrapping struct type.

> cheers,
>   Gerd
>
Avi Kivity - Oct. 25, 2012, 1:17 p.m.
On 10/25/2012 11:55 AM, Peter Maydell wrote:
> On 25 October 2012 10:47, Peter Crosthwaite
> <peter.crosthwaite@xilinx.com> wrote:
>> +static int usb_ehci_sysbus_initfn(SysBusDevice *dev)
>> +{
>> +    EHCIItfState *i = FROM_SYSBUS(EHCIItfState, dev);
>> +    EHCIState *s = &i->ehci;
>> +
>> +    s->dma = g_new(DMAContext, 1);
>> +    dma_context_init(s->dma, &address_space_memory, NULL, NULL, NULL);
> 
> Assuming Avi doesn't reject it, better to use the dma_context_memory
> I introduced in this patch (not yet applied to master):
>   http://patchwork.ozlabs.org/patch/193550/
> 

Patch is good, sorry if you were expecting an explicit ack.

Patch

diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index 862564c..17482f7 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -35,6 +35,8 @@ 
 #include "trace.h"
 #include "dma.h"
 #include "sysemu.h"
+#include "hw/sysbus.h"
+#include "exec-memory.h"
 
 #define EHCI_DEBUG   0
 
@@ -446,7 +448,13 @@  struct EHCIState {
 };
 
 typedef struct EHCIItfState {
-    PCIDevice pcidev;
+    /* FIXME: Figure out a better way to share one Property[] array between two
+     * QOM types with different parents
+     */
+    union {
+        PCIDevice pcidev;
+        SysBusDevice busdev;
+    };
     struct EHCIState ehci;
 } EHCIItfState;
 
@@ -2544,6 +2552,7 @@  static const MemoryRegionOps ehci_mmio_port_ops = {
 };
 
 static int usb_ehci_pci_initfn(PCIDevice *dev);
+static int usb_ehci_sysbus_initfn(SysBusDevice *dev);
 
 static USBPortOps ehci_port_ops = {
     .attach = ehci_attach,
@@ -2699,6 +2708,32 @@  static TypeInfo ich9_ehci_info = {
     .class_init    = ich9_ehci_class_init,
 };
 
+static const VMStateDescription vmstate_ehci_sysbus = {
+    .name        = "ehci-sysbus",
+    .version_id  = 3,
+    .minimum_version_id  = 2,
+    .fields      = (VMStateField[]) {
+        VMSTATE_STRUCT(ehci, EHCIItfState, 3, vmstate_ehci, EHCIState),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static void ehci_sysbus_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = usb_ehci_sysbus_initfn;
+    dc->vmsd = &vmstate_ehci_sysbus;
+    dc->props = ehci_properties;
+}
+
+static TypeInfo ehci_sysbus_info = {
+    .name          = "ehci-sysbus",
+    .parent        = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(EHCIItfState),
+    .class_init    = ehci_sysbus_class_init,
+};
 
 static void usb_ehci_initfn(EHCIState *s, DeviceState *dev)
 {
@@ -2750,6 +2785,21 @@  static void usb_ehci_initfn(EHCIState *s, DeviceState *dev)
                                 &s->mem_ports);
 }
 
+static int usb_ehci_sysbus_initfn(SysBusDevice *dev)
+{
+    EHCIItfState *i = FROM_SYSBUS(EHCIItfState, dev);
+    EHCIState *s = &i->ehci;
+
+    s->dma = g_new(DMAContext, 1);
+    dma_context_init(s->dma, &address_space_memory, NULL, NULL, NULL);
+
+    usb_ehci_initfn(s, DEVICE(dev));
+    sysbus_init_irq(dev, &s->irq);
+    sysbus_init_mmio(dev, &s->mem);
+
+    return 0;
+}
+
 static int usb_ehci_pci_initfn(PCIDevice *dev)
 {
     EHCIItfState *i = DO_UPCAST(EHCIItfState, pcidev, dev);
@@ -2798,6 +2848,7 @@  static void ehci_register_types(void)
 {
     type_register_static(&ehci_pci_info);
     type_register_static(&ich9_ehci_info);
+    type_register_static(&ehci_sysbus_info);
 }
 
 type_init(ehci_register_types)