mbox series

[v9,0/7] Make hcd-xhci independent of pci hooks

Message ID 1600883407-15147-1-git-send-email-sai.pavan.boddu@xilinx.com
Headers show
Series Make hcd-xhci independent of pci hooks | expand

Message

Sai Pavan Boddu Sept. 23, 2020, 5:50 p.m. UTC
This patch series attempts to make 'hcd-xhci' an independent model so
it can be used by both pci and system-bus interface.

Changes for V2:
    Make XHCIState non-qom
    Use container_of functions for retriving pci device instance
    Initialize the AddressSpace pointer in PATCH 1/3 itself
Changes for V3:
    Convert XHCIState to TYPE_DEVICE and register as a child of XHCIPciState.
Changes for V4:
    Add DWC3 usb controller
    Add versal, usb2-reg module
    Connect sysbus xhci to versal virt board
Changes for V5:
    Add extra info about dwc3 and usb2_regs devices in commit messages
    Use only one irq for versal usb controller
    Mark the unimplemented registers in dwc3 controller
    Rebase the patches over master.
    Move few mispalced contents from patch 2/7 to 3/7.
    Fix the author names in the header.
    Move the inclusion of "sysemu/dma.h" from patch 1/7 to 3/7
Changes for V6:
    Fixed style issue in patch 7/7
    Renamed usb2_reg model to VersalUsb2CtrlReg
    Fixed author in headers
Changes for V7:
    Create a usb structure to keep things clean
    Remove the repeated patch in the series i.e 5/7
Changes for V8:
    Fix vmstate sturcts to support cross version migration.
Changes for V9:
    Added recommended changes to fix vmstate migration.
    Fixed commit message on 3/7.

Sai Pavan Boddu (5):
  usb/hcd-xhci: Make dma read/writes hooks pci free
  usb/hcd-xhci: Move qemu-xhci device to hcd-xhci-pci.c
  usb/hcd-xhci: Split pci wrapper for xhci base model
  usb: hcd-xhci-sysbus: Attach xhci to sysbus device
  misc: Add versal-usb2-ctrl-regs module

Vikram Garhwal (2):
  usb: Add DWC3 model
  Versal: Connect DWC3 controller with virt-versal

 hw/arm/xlnx-versal-virt.c                    |  58 +++
 hw/arm/xlnx-versal.c                         |  34 ++
 hw/misc/meson.build                          |   1 +
 hw/misc/xlnx-versal-usb2-ctrl-regs.c         | 222 +++++++++
 hw/usb/Kconfig                               |  17 +
 hw/usb/hcd-dwc3.c                            | 717 +++++++++++++++++++++++++++
 hw/usb/hcd-xhci-nec.c                        |  18 +-
 hw/usb/hcd-xhci-pci.c                        | 260 ++++++++++
 hw/usb/hcd-xhci-pci.h                        |  44 ++
 hw/usb/hcd-xhci-sysbus.c                     | 109 ++++
 hw/usb/hcd-xhci-sysbus.h                     |  32 ++
 hw/usb/hcd-xhci.c                            | 269 +++-------
 hw/usb/hcd-xhci.h                            |  22 +-
 hw/usb/meson.build                           |   3 +
 include/hw/arm/xlnx-versal.h                 |  14 +
 include/hw/misc/xlnx-versal-usb2-ctrl-regs.h |  45 ++
 include/hw/usb/hcd-dwc3.h                    |  55 ++
 17 files changed, 1691 insertions(+), 229 deletions(-)
 create mode 100644 hw/misc/xlnx-versal-usb2-ctrl-regs.c
 create mode 100644 hw/usb/hcd-dwc3.c
 create mode 100644 hw/usb/hcd-xhci-pci.c
 create mode 100644 hw/usb/hcd-xhci-pci.h
 create mode 100644 hw/usb/hcd-xhci-sysbus.c
 create mode 100644 hw/usb/hcd-xhci-sysbus.h
 create mode 100644 include/hw/misc/xlnx-versal-usb2-ctrl-regs.h
 create mode 100644 include/hw/usb/hcd-dwc3.h

Comments

Gerd Hoffmann Sept. 24, 2020, 6:15 a.m. UTC | #1
Hi,

> @@ -203,8 +202,10 @@ struct XHCIState {
>      uint32_t numslots;
>      uint32_t flags;
>      uint32_t max_pstreams_mask;
> -    OnOffAuto msi;
> -    OnOffAuto msix;
> +    void (*intr_update)(XHCIState *s, int n, bool enable);
> +    void (*intr_raise)(XHCIState *s, int n, bool level);
> +    void (*vmstate_post_load)(XHCIState *xhci);

No need to create your own post_load hook, there is one in
VMStateDescription ready for use ;)

take care,
  Gerd

[ I can squash that into 3/7 if you have no objections ]

diff --git a/hw/usb/hcd-xhci.h b/hw/usb/hcd-xhci.h
index 294bdc62aeaf..f859a17e73ee 100644
--- a/hw/usb/hcd-xhci.h
+++ b/hw/usb/hcd-xhci.h
@@ -205,7 +205,6 @@ typedef struct XHCIState {
     uint32_t max_pstreams_mask;
     void (*intr_update)(XHCIState *s, int n, bool enable);
     void (*intr_raise)(XHCIState *s, int n, bool level);
-    void (*vmstate_post_load)(XHCIState *xhci);
     DeviceState *hostOpaque;
 
     /* Operational Registers */
diff --git a/hw/usb/hcd-xhci-pci.c b/hw/usb/hcd-xhci-pci.c
index f06a2b7f4c57..77608fb78def 100644
--- a/hw/usb/hcd-xhci-pci.c
+++ b/hw/usb/hcd-xhci-pci.c
@@ -85,19 +85,21 @@ static void xhci_pci_reset(DeviceState *dev)
     device_legacy_reset(DEVICE(&s->xhci));
 }
 
-static void xhci_pci_vmstate_post_load(XHCIState *xhci)
+static int xhci_pci_post_load(void *opaque, int version_id)
 {
-    XHCIPciState *s = container_of(xhci, XHCIPciState, xhci);
+    XHCIPciState *s = opaque;
+    XHCIState *xhci = &s->xhci;
     PCIDevice *pci_dev = PCI_DEVICE(s);
     int intr;
 
-   for (intr = 0; intr < xhci->numintrs; intr++) {
+    for (intr = 0; intr < xhci->numintrs; intr++) {
         if (xhci->intr[intr].msix_used) {
             msix_vector_use(pci_dev, intr);
         } else {
             msix_vector_unuse(pci_dev, intr);
         }
     }
+    return 0;
 }
 
 static void usb_xhci_pci_realize(struct PCIDevice *dev, Error **errp)
@@ -114,7 +116,6 @@ static void usb_xhci_pci_realize(struct PCIDevice *dev, Error **errp)
     object_property_set_link(OBJECT(&s->xhci), "host", OBJECT(s), NULL);
     s->xhci.intr_update = xhci_pci_intr_update;
     s->xhci.intr_raise = xhci_pci_intr_raise;
-    s->xhci.vmstate_post_load = xhci_pci_vmstate_post_load;
     object_property_set_bool(OBJECT(&s->xhci), "realized", true, &err);
     if (err) {
         error_propagate(errp, err);
@@ -176,6 +177,7 @@ static void usb_xhci_pci_exit(PCIDevice *dev)
 static const VMStateDescription vmstate_xhci_pci = {
     .name = "xhci",
     .version_id = 1,
+    .post_load = xhci_pci_post_load,
     .fields = (VMStateField[]) {
         VMSTATE_PCI_DEVICE(parent_obj, XHCIPciState),
         VMSTATE_MSIX(parent_obj, XHCIPciState),
diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index 4a6c0e7edb1a..b1b95abb9b29 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -3457,9 +3457,6 @@ static int usb_xhci_post_load(void *opaque, int version_id)
         }
     }
 
-    if (xhci->vmstate_post_load) {
-        xhci->vmstate_post_load(xhci);
-    }
     return 0;
 }
Sai Pavan Boddu Sept. 24, 2020, 2:16 p.m. UTC | #2
Hi Gerd,

> -----Original Message-----

> From: Gerd Hoffmann <kraxel@redhat.com>

> Sent: Thursday, September 24, 2020 11:45 AM

> To: Sai Pavan Boddu <saipava@xilinx.com>

> Cc: Peter Maydell <peter.maydell@linaro.org>; Markus Armbruster

> <armbru@redhat.com>; 'Marc-André Lureau'

> <marcandre.lureau@redhat.com>; Paolo Bonzini <pbonzini@redhat.com>;

> Edgar Iglesias <edgari@xilinx.com>; Francisco Eduardo Iglesias

> <figlesia@xilinx.com>; qemu-devel@nongnu.org; Alistair Francis

> <alistair.francis@wdc.com>; Eduardo Habkost <ehabkost@redhat.com>;

> Ying Fang <fangying1@huawei.com>; 'Philippe Mathieu-Daudé'

> <philmd@redhat.com>; Vikram Garhwal <fnuv@xilinx.com>; Paul

> Zimmerman <pauldzim@gmail.com>; Sai Pavan Boddu

> <saipava@xilinx.com>

> Subject: Re: [PATCH v9 3/7] usb/hcd-xhci: Split pci wrapper for xhci base

> model

> 

>   Hi,

> 

> > @@ -203,8 +202,10 @@ struct XHCIState {

> >      uint32_t numslots;

> >      uint32_t flags;

> >      uint32_t max_pstreams_mask;

> > -    OnOffAuto msi;

> > -    OnOffAuto msix;

> > +    void (*intr_update)(XHCIState *s, int n, bool enable);

> > +    void (*intr_raise)(XHCIState *s, int n, bool level);

> > +    void (*vmstate_post_load)(XHCIState *xhci);

> 

> No need to create your own post_load hook, there is one in

> VMStateDescription ready for use ;)

[Sai Pavan Boddu] Yes thanks, I did not realize this can be used aswell.

Regards,
Sai Pavan
> 

> take care,

>   Gerd

> 

> [ I can squash that into 3/7 if you have no objections ]

> 

> diff --git a/hw/usb/hcd-xhci.h b/hw/usb/hcd-xhci.h index

> 294bdc62aeaf..f859a17e73ee 100644

> --- a/hw/usb/hcd-xhci.h

> +++ b/hw/usb/hcd-xhci.h

> @@ -205,7 +205,6 @@ typedef struct XHCIState {

>      uint32_t max_pstreams_mask;

>      void (*intr_update)(XHCIState *s, int n, bool enable);

>      void (*intr_raise)(XHCIState *s, int n, bool level);

> -    void (*vmstate_post_load)(XHCIState *xhci);

>      DeviceState *hostOpaque;

> 

>      /* Operational Registers */

> diff --git a/hw/usb/hcd-xhci-pci.c b/hw/usb/hcd-xhci-pci.c index

> f06a2b7f4c57..77608fb78def 100644

> --- a/hw/usb/hcd-xhci-pci.c

> +++ b/hw/usb/hcd-xhci-pci.c

> @@ -85,19 +85,21 @@ static void xhci_pci_reset(DeviceState *dev)

>      device_legacy_reset(DEVICE(&s->xhci));

>  }

> 

> -static void xhci_pci_vmstate_post_load(XHCIState *xhci)

> +static int xhci_pci_post_load(void *opaque, int version_id)

>  {

> -    XHCIPciState *s = container_of(xhci, XHCIPciState, xhci);

> +    XHCIPciState *s = opaque;

> +    XHCIState *xhci = &s->xhci;

>      PCIDevice *pci_dev = PCI_DEVICE(s);

>      int intr;

> 

> -   for (intr = 0; intr < xhci->numintrs; intr++) {

> +    for (intr = 0; intr < xhci->numintrs; intr++) {

>          if (xhci->intr[intr].msix_used) {

>              msix_vector_use(pci_dev, intr);

>          } else {

>              msix_vector_unuse(pci_dev, intr);

>          }

>      }

> +    return 0;

>  }

> 

>  static void usb_xhci_pci_realize(struct PCIDevice *dev, Error **errp) @@ -

> 114,7 +116,6 @@ static void usb_xhci_pci_realize(struct PCIDevice *dev,

> Error **errp)

>      object_property_set_link(OBJECT(&s->xhci), "host", OBJECT(s), NULL);

>      s->xhci.intr_update = xhci_pci_intr_update;

>      s->xhci.intr_raise = xhci_pci_intr_raise;

> -    s->xhci.vmstate_post_load = xhci_pci_vmstate_post_load;

>      object_property_set_bool(OBJECT(&s->xhci), "realized", true, &err);

>      if (err) {

>          error_propagate(errp, err);

> @@ -176,6 +177,7 @@ static void usb_xhci_pci_exit(PCIDevice *dev)  static

> const VMStateDescription vmstate_xhci_pci = {

>      .name = "xhci",

>      .version_id = 1,

> +    .post_load = xhci_pci_post_load,

>      .fields = (VMStateField[]) {

>          VMSTATE_PCI_DEVICE(parent_obj, XHCIPciState),

>          VMSTATE_MSIX(parent_obj, XHCIPciState), diff --git a/hw/usb/hcd-

> xhci.c b/hw/usb/hcd-xhci.c index 4a6c0e7edb1a..b1b95abb9b29 100644

> --- a/hw/usb/hcd-xhci.c

> +++ b/hw/usb/hcd-xhci.c

> @@ -3457,9 +3457,6 @@ static int usb_xhci_post_load(void *opaque, int

> version_id)

>          }

>      }

> 

> -    if (xhci->vmstate_post_load) {

> -        xhci->vmstate_post_load(xhci);

> -    }

>      return 0;

>  }

>