Skip to contentSkip to conversation

Add Versal usb model

PATCH Superseded Sai Pavan Boddu 4 participants 12 messages Oct 22, 2020 – Oct 28, 2020 Arm/Amlogic Meson SoC support

v12 of 15 Superseded Latest is v15 →

lore
Share & tools
lore
#0 lore raw

v12 cover Add Versal usb model

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.
Changes for V10:
use vmstate_post_load avaialble in VMStateDescription
tested vmstate cross migration.
Changes for V11:
Removed the patches which got accepted
Changed object name "USB2Reg" -> "ctrl"
Updated Subject line on cover letter.
Changes for V12:
Use reset class for usb2-ctrl-regs module
Move the few register update to realize
Marked registers which are unimplemented in regapi model

Sai Pavan Boddu (1):
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         | 229 +++++++++
 hw/usb/Kconfig                               |   6 +
 hw/usb/hcd-dwc3.c                            | 666 +++++++++++++++++++++++++++
 hw/usb/meson.build                           |   1 +
 include/hw/arm/xlnx-versal.h                 |  14 +
 include/hw/misc/xlnx-versal-usb2-ctrl-regs.h |  45 ++
 include/hw/usb/hcd-dwc3.h                    |  55 +++
 10 files changed, 1109 insertions(+)
 create mode 100644 hw/misc/xlnx-versal-usb2-ctrl-regs.c
 create mode 100644 hw/usb/hcd-dwc3.c
 create mode 100644 include/hw/misc/xlnx-versal-usb2-ctrl-regs.h
 create mode 100644 include/hw/usb/hcd-dwc3.h
Signature · 1 line
2.7.4
#1 lore raw

PATCH v12 1/3 misc: Add versal-usb2-ctrl-regs module

This module emulates control registers of versal usb2 controller, this is added just to make guest happy. In general this module would control the phy-reset signal from usb controller, data coherency of the transactions, signals the host system errors received from controller.

---
 hw/misc/meson.build                          |   1 +
 hw/misc/xlnx-versal-usb2-ctrl-regs.c         | 229 +++++++++++++++++++++++++++
 include/hw/misc/xlnx-versal-usb2-ctrl-regs.h |  45 ++++++
 3 files changed, 275 insertions(+)
 create mode 100644 hw/misc/xlnx-versal-usb2-ctrl-regs.c
 create mode 100644 include/hw/misc/xlnx-versal-usb2-ctrl-regs.h
hw/misc/meson.build +1 -0
index 793d45b..b336dd1 100644
@@ -109,3 +109,4 @@ specific_ss.add(when: 'CONFIG_MIPS_CPS', if_true: files('mips_cmgcr.c', 'mips_cp
 specific_ss.add(when: 'CONFIG_MIPS_ITU', if_true: files('mips_itu.c'))
 
 specific_ss.add(when: 'CONFIG_SBSA_REF', if_true: files('sbsa_ec.c'))
+specific_ss.add(when: 'CONFIG_XLNX_VERSAL', if_true: files('xlnx-versal-usb2-ctrl-regs.c'))
hw/misc/xlnx-versal-usb2-ctrl-regs.c new file +229 -0

229 lines not on this page · raw message

include/hw/misc/xlnx-versal-usb2-ctrl-regs.h new file +45 -0

45 lines not on this page · raw message

Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH v12 1/3] misc: Add versal-usb2-ctrl-regs module

Quoted 6 lines · Sai Pavan Boddu

This module emulates control registers of versal usb2 controller, this is added just to make guest happy. In general this module would control the phy-reset signal from usb controller, data coherency of the transactions, signals the host system errors received from controller.

Quoted 6 lines
---
 hw/misc/meson.build                          |   1 +
 hw/misc/xlnx-versal-usb2-ctrl-regs.c         | 229 +++++++++++++++++++++++++++
 include/hw/misc/xlnx-versal-usb2-ctrl-regs.h |  45 ++++++

This seems a bit odd. If it's a USB device (or part of a USB device) then it should be under hw/usb, shouldn't it?

hw/misc/xlnx-versal-usb2-ctrl-regs.c line 88

Quoted 7 lines
hw/misc/xlnx-versal-usb2-ctrl-regs.c new file +7 -0
+static void ir_status_postw(RegisterInfo *reg, uint64_t val64)
+{
+    VersalUsb2CtrlRegs *s = XILINX_VERSAL_USB2_CTRL_REGS(reg->opaque);
+    /*
+     * TODO: This should also clear USBSTS.HSE field in USB XHCI register.
+     * May be combine both the modules.
+     */

What does the hardware for this look like? You've modelled it as two completely separate devices (this one and the TYPE_USB_DWC3) but would it be closer to the hardware structure to have a top-level device which has-a DWC3 ?

thanks
-- PMM

#3 lore raw

RE: [PATCH v12 1/3] misc: Add versal-usb2-ctrl-regs module

Hi Peter,

Quoted 28 lines

-----Original Message-----
From: Peter Maydell <[email protected]>
Sent: Monday, October 26, 2020 9:33 PM
To: Sai Pavan Boddu <[email protected]>
Cc: Markus Armbruster <[email protected]>; Marc-André Lureau <[email protected]>; Paolo Bonzini <[email protected]>; Gerd Hoffmann <[email protected]>; Edgar Iglesias <[email protected]>; Francisco Eduardo Iglesias <[email protected]>; QEMU Developers <qemu- [email protected]>; Alistair Francis <[email protected]>; Eduardo Habkost <[email protected]>; Ying Fang <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Vikram Garhwal <[email protected]>; Paul Zimmerman <[email protected]>; Sai Pavan Boddu <[email protected]>
Subject: Re: [PATCH v12 1/3] misc: Add versal-usb2-ctrl-regs module

Quoted 11 lines · Sai Pavan Boddu

This module emulates control registers of versal usb2 controller, this is added just to make guest happy. In general this module would control the phy-reset signal from usb controller, data coherency of the transactions, signals the host system errors received from controller.

---
 hw/misc/meson.build                          |   1 +
 hw/misc/xlnx-versal-usb2-ctrl-regs.c         | 229
Quoted 5 lines

+++++++++++++++++++++++++++

Quoted 1 line
 include/hw/misc/xlnx-versal-usb2-ctrl-regs.h |  45 ++++++

This seems a bit odd. If it's a USB device (or part of a USB device) then it should be under hw/usb, shouldn't it?

[Sai Pavan Boddu] This is a top level wrapper over hcd-dwc3 device, which is specific to versal soc. It's mostly dummy which controls the phy-reset and does frame length adjustments. It was added just to make guest happy, that is the reason it has been added to misc devices.

Quoted 8 lines

hw/misc/xlnx-versal-usb2-ctrl-regs.c line 88

Quoted 7 lines
hw/misc/xlnx-versal-usb2-ctrl-regs.c new file +6 -0
+static void ir_status_postw(RegisterInfo *reg, uint64_t val64) {
+    VersalUsb2CtrlRegs *s = XILINX_VERSAL_USB2_CTRL_REGS(reg->opaque);
+    /*
+     * TODO: This should also clear USBSTS.HSE field in USB XHCI register.
+     * May be combine both the modules.
+     */
Quoted 4 lines

What does the hardware for this look like? You've modelled it as two completely separate devices (this one and the
TYPE_USB_DWC3) but would it be closer to the hardware structure to have a top-level device which has-a DWC3 ?

[Sai Pavan Boddu] Yes, we can look at it such way. But as its specific to versal SOC, we have crafted it out and stitched them in SOC file.

Regards,
Sai Pavan

Quoted 3 lines

thanks
-- PMM

#4 lore raw

RE: [PATCH v12 1/3] misc: Add versal-usb2-ctrl-regs module

Hi Peter,

Quoted 68 lines

-----Original Message-----
From: Sai Pavan Boddu
Sent: Monday, October 26, 2020 10:59 PM
To: Peter Maydell <[email protected]>
Cc: Markus Armbruster <[email protected]>; Marc-André Lureau <[email protected]>; Paolo Bonzini <[email protected]>; Gerd Hoffmann <[email protected]>; Edgar Iglesias <[email protected]>; Francisco Eduardo Iglesias <[email protected]>; QEMU Developers <qemu- [email protected]>; Alistair Francis <[email protected]>; Eduardo Habkost <[email protected]>; Ying Fang <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Vikram Garhwal <[email protected]>; Paul Zimmerman <[email protected]>
Subject: RE: [PATCH v12 1/3] misc: Add versal-usb2-ctrl-regs module

Hi Peter,

Quoted 4 lines

-----Original Message-----
From: Peter Maydell <[email protected]>
Sent: Monday, October 26, 2020 9:33 PM
To: Sai Pavan Boddu <[email protected]>

Quoted 8 lines

Cc: Markus Armbruster <[email protected]>; Marc-André Lureau <[email protected]>; Paolo Bonzini <[email protected]>; Gerd Hoffmann <[email protected]>; Edgar Iglesias <[email protected]>; Francisco Eduardo Iglesias <[email protected]>; QEMU Developers <qemu- [email protected]>; Alistair Francis <[email protected]>; Eduardo Habkost <[email protected]>; Ying Fang <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Vikram Garhwal <[email protected]>; Paul Zimmerman

<[email protected]>;

Quoted 17 lines

Sai Pavan Boddu <[email protected]>
Subject: Re: [PATCH v12 1/3] misc: Add versal-usb2-ctrl-regs module

Quoted 11 lines · Sai Pavan Boddu

This module emulates control registers of versal usb2 controller, this is added just to make guest happy. In general this module would control the phy-reset signal from usb controller, data coherency of the transactions, signals the host system errors received from controller.

---
 hw/misc/meson.build                          |   1 +
 hw/misc/xlnx-versal-usb2-ctrl-regs.c         | 229
Quoted 5 lines

+++++++++++++++++++++++++++

Quoted 1 line
 include/hw/misc/xlnx-versal-usb2-ctrl-regs.h |  45 ++++++

This seems a bit odd. If it's a USB device (or part of a USB device) then it should be under hw/usb, shouldn't it?

[Sai Pavan Boddu] This is a top level wrapper over hcd-dwc3 device, which is specific to versal soc. It's mostly dummy which controls the phy-reset and does frame length adjustments. It was added just to make guest happy, that is the reason it has been added to misc devices.

Quoted 9 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+static void ir_status_postw(RegisterInfo *reg, uint64_t val64) {
+    VersalUsb2CtrlRegs *s = XILINX_VERSAL_USB2_CTRL_REGS(reg-

opaque);

hw/misc/xlnx-versal-usb2-ctrl-regs.c line 88

Quoted 4 lines
hw/misc/xlnx-versal-usb2-ctrl-regs.c new file +4 -0
+    /*
+     * TODO: This should also clear USBSTS.HSE field in USB XHCI register.
+     * May be combine both the modules.
+     */
Quoted 4 lines

What does the hardware for this look like? You've modelled it as two completely separate devices (this one and the TYPE_USB_DWC3) but would it be closer to the hardware structure to have a top-level device which has-a DWC3 ?

Quoted 5 lines

[Sai Pavan Boddu] Yes, we can look at it such way. But as its specific to versal SOC, we have crafted it out and stitched them in SOC file.

Regards,
Sai Pavan

[Sai Pavan Boddu] I would be sending V13 without doing any changes with this patch and addressing other comments, Please review over V13.

Thanks,
Sai Pavan

Quoted 3 lines
Quoted 3 lines

thanks
-- PMM

#5 lore raw

Re: [PATCH v12 1/3] misc: Add versal-usb2-ctrl-regs module

Quoted 71 lines · Sai Pavan Boddu

Hi Peter,

Quoted 68 lines

-----Original Message-----
From: Sai Pavan Boddu
Sent: Monday, October 26, 2020 10:59 PM
To: Peter Maydell <[email protected]>
Cc: Markus Armbruster <[email protected]>; Marc-André Lureau <[email protected]>; Paolo Bonzini <[email protected]>; Gerd Hoffmann <[email protected]>; Edgar Iglesias <[email protected]>; Francisco Eduardo Iglesias <[email protected]>; QEMU Developers <qemu- [email protected]>; Alistair Francis <[email protected]>; Eduardo Habkost <[email protected]>; Ying Fang <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Vikram Garhwal <[email protected]>; Paul Zimmerman <[email protected]>
Subject: RE: [PATCH v12 1/3] misc: Add versal-usb2-ctrl-regs module

Hi Peter,

Quoted 4 lines

-----Original Message-----
From: Peter Maydell <[email protected]>
Sent: Monday, October 26, 2020 9:33 PM
To: Sai Pavan Boddu <[email protected]>

Quoted 8 lines

Cc: Markus Armbruster <[email protected]>; Marc-André Lureau <[email protected]>; Paolo Bonzini <[email protected]>; Gerd Hoffmann <[email protected]>; Edgar Iglesias <[email protected]>; Francisco Eduardo Iglesias <[email protected]>; QEMU Developers <qemu- [email protected]>; Alistair Francis <[email protected]>; Eduardo Habkost <[email protected]>; Ying Fang <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Vikram Garhwal <[email protected]>; Paul Zimmerman

<[email protected]>;

Quoted 17 lines

Sai Pavan Boddu <[email protected]>
Subject: Re: [PATCH v12 1/3] misc: Add versal-usb2-ctrl-regs module

Quoted 11 lines · Sai Pavan Boddu

This module emulates control registers of versal usb2 controller, this is added just to make guest happy. In general this module would control the phy-reset signal from usb controller, data coherency of the transactions, signals the host system errors received from controller.

---
 hw/misc/meson.build                          |   1 +
 hw/misc/xlnx-versal-usb2-ctrl-regs.c         | 229
Quoted 5 lines

+++++++++++++++++++++++++++

Quoted 1 line
 include/hw/misc/xlnx-versal-usb2-ctrl-regs.h |  45 ++++++

This seems a bit odd. If it's a USB device (or part of a USB device) then it should be under hw/usb, shouldn't it?

[Sai Pavan Boddu] This is a top level wrapper over hcd-dwc3 device, which is specific to versal soc. It's mostly dummy which controls the phy-reset and does frame length adjustments. It was added just to make guest happy, that is the reason it has been added to misc devices.

Quoted 13 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+static void ir_status_postw(RegisterInfo *reg, uint64_t val64) {
+    VersalUsb2CtrlRegs *s = XILINX_VERSAL_USB2_CTRL_REGS(reg-

opaque);

hw/misc/xlnx-versal-usb2-ctrl-regs.c line 88

Quoted 4 lines
hw/misc/xlnx-versal-usb2-ctrl-regs.c new file +4 -0
+    /*
+     * TODO: This should also clear USBSTS.HSE field in USB XHCI register.
+     * May be combine both the modules.
+     */

What does the hardware for this look like? You've modelled it as two completely separate devices (this one and the TYPE_USB_DWC3) but would it be closer to the hardware structure to have a top-level device which has-a DWC3 ?

Quoted 6 lines
Quoted 5 lines

[Sai Pavan Boddu] Yes, we can look at it such way. But as its specific to versal SOC, we have crafted it out and stitched them in SOC file.

Regards,
Sai Pavan

[Sai Pavan Boddu] I would be sending V13 without doing any changes with this patch and addressing other comments, Please review over V13.

You have my review comments above. I think the way you've structured this isn't really the best way to do it.

thanks
-- PMM

#6 lore raw

RE: [PATCH v12 1/3] misc: Add versal-usb2-ctrl-regs module

Hi Peter,

Quoted 96 lines

-----Original Message-----
From: Peter Maydell <[email protected]>
Sent: Wednesday, October 28, 2020 6:44 PM
To: Sai Pavan Boddu <[email protected]>
Cc: Markus Armbruster <[email protected]>; Marc-André Lureau <[email protected]>; Paolo Bonzini <[email protected]>; Gerd Hoffmann <[email protected]>; Edgar Iglesias <[email protected]>; Francisco Eduardo Iglesias <[email protected]>; QEMU Developers <qemu- [email protected]>; Alistair Francis <[email protected]>; Eduardo Habkost <[email protected]>; Ying Fang <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Vikram Garhwal <[email protected]>; Paul Zimmerman <[email protected]>
Subject: Re: [PATCH v12 1/3] misc: Add versal-usb2-ctrl-regs module

Quoted 15 lines · Sai Pavan Boddu

Hi Peter,

Quoted 12 lines

-----Original Message-----
From: Sai Pavan Boddu
Sent: Monday, October 26, 2020 10:59 PM
To: Peter Maydell <[email protected]>
Cc: Markus Armbruster <[email protected]>; Marc-André Lureau <[email protected]>; Paolo Bonzini <[email protected]>; Gerd Hoffmann <[email protected]>; Edgar Iglesias <[email protected]>; Francisco Eduardo Iglesias <[email protected]>; QEMU Developers <qemu- [email protected]>; Alistair Francis <[email protected]>; Eduardo Habkost <[email protected]>; Ying Fang <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Vikram Garhwal

<[email protected]>;

Quoted 24 lines
Quoted 24 lines

Paul Zimmerman <[email protected]>
Subject: RE: [PATCH v12 1/3] misc: Add versal-usb2-ctrl-regs module

Hi Peter,

Quoted 6 lines

-----Original Message-----
From: Peter Maydell <[email protected]>
Sent: Monday, October 26, 2020 9:33 PM
To: Sai Pavan Boddu <[email protected]>
Cc: Markus Armbruster <[email protected]>; Marc-André Lureau <[email protected]>; Paolo Bonzini

Quoted 8 lines

<[email protected]>; Gerd Hoffmann <[email protected]>; Edgar Iglesias <[email protected]>; Francisco Eduardo Iglesias <[email protected]>; QEMU Developers
<qemu- [email protected]>; Alistair Francis <[email protected]>; Eduardo Habkost <[email protected]>; Ying Fang <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Vikram Garhwal <[email protected]>; Paul Zimmerman

<[email protected]>;

Quoted 4 lines

Sai Pavan Boddu <[email protected]>
Subject: Re: [PATCH v12 1/3] misc: Add versal-usb2-ctrl-regs module

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines · Sai Pavan Boddu

This module emulates control registers of versal usb2 controller, this is added just to make guest happy. In general this module would control the phy-reset signal from usb controller, data coherency of the transactions, signals the host system

errors received from controller.

Quoted 16 lines
Quoted 16 lines
Quoted 11 lines
Quoted 6 lines
---
 hw/misc/meson.build                          |   1 +
 hw/misc/xlnx-versal-usb2-ctrl-regs.c         | 229

+++++++++++++++++++++++++++

Quoted 1 line
 include/hw/misc/xlnx-versal-usb2-ctrl-regs.h |  45 ++++++

This seems a bit odd. If it's a USB device (or part of a USB device) then it should be under hw/usb, shouldn't it?

[Sai Pavan Boddu] This is a top level wrapper over hcd-dwc3 device, which is specific to versal soc. It's mostly dummy which controls the phy-reset and does frame length adjustments. It was added just to make guest happy, that is the reason it has been added to misc devices.

Quoted 1 line
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+static void ir_status_postw(RegisterInfo *reg, uint64_t val64) {
+    VersalUsb2CtrlRegs *s = XILINX_VERSAL_USB2_CTRL_REGS(reg-

opaque);

Quoted 2 lines
(quoted diff) +2 -0
+    /*
+     * TODO: This should also clear USBSTS.HSE field in USB XHCI

register.

Quoted 10 lines
Quoted 10 lines
Quoted 7 lines

hw/misc/xlnx-versal-usb2-ctrl-regs.c line 88

Quoted 2 lines
hw/misc/xlnx-versal-usb2-ctrl-regs.c new file +2 -0
+     * May be combine both the modules.
+     */

What does the hardware for this look like? You've modelled it as two completely separate devices (this one and the TYPE_USB_DWC3) but would it be closer to the hardware structure to have a top-level device which has-a DWC3 ?

[Sai Pavan Boddu] Yes, we can look at it such way. But as its specific to versal SOC, we have crafted it out and stitched them in SOC file.

Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

Regards,
Sai Pavan

[Sai Pavan Boddu] I would be sending V13 without doing any changes with

this patch and addressing other comments, Please review over V13.

You have my review comments above. I think the way you've structured this isn't really the best way to do it.

[Sai Pavan Boddu] Ok, I would move this into USB folder as its related.
But this device is not like a top level module of DWC3 model, is used for handling phy-reset signal & power management of usb port. It's not a good idea to embedded this device into DWC3 module.

Anyway, I would attempt to create a subsystem by making dwc3 and usb2-ctrl-regs child of one device.

Regards,
Sai Pavan

Quoted 3 lines

thanks
-- PMM

#7 lore raw

PATCH v12 2/3 usb: Add DWC3 model

In reply to Sai Pavan Boddu

From: Vikram Garhwal <[email protected]>

This patch adds skeleton model of dwc3 usb controller attached to xhci-sysbus device. It defines global register space of DWC3 controller, global registers control the AXI/AHB interfaces properties, external FIFO support and event count support. All of which are unimplemented at present,we are only supporting core reset and read of ID register.

---
 hw/usb/Kconfig            |   6 +
 hw/usb/hcd-dwc3.c         | 666 ++++++++++++++++++++++++++++++++++++++++++++++
 hw/usb/meson.build        |   1 +
 include/hw/usb/hcd-dwc3.h |  55 ++++
 4 files changed, 728 insertions(+)
 create mode 100644 hw/usb/hcd-dwc3.c
 create mode 100644 include/hw/usb/hcd-dwc3.h
hw/usb/Kconfig +6 -0
index 4dd2ba9..f5762f0 100644
@@ -116,3 +116,9 @@ config IMX_USBPHY
     bool
     default y
     depends on USB
+
+config USB_DWC3
+    bool
+    default y if USB_XHCI_SYSBUS
+    select USB
+    select REGISTER
hw/usb/hcd-dwc3.c new file +666 -0

666 lines not on this page · raw message

hw/usb/meson.build +1 -0
index 934e4fa..962fbc0 100644
@@ -26,6 +26,7 @@ softmmu_ss.add(when: 'CONFIG_USB_XHCI_SYSBUS', if_true: files('hcd-xhci-sysbus.c
 softmmu_ss.add(when: 'CONFIG_USB_XHCI_NEC', if_true: files('hcd-xhci-nec.c'))
 softmmu_ss.add(when: 'CONFIG_USB_MUSB', if_true: files('hcd-musb.c'))
 softmmu_ss.add(when: 'CONFIG_USB_DWC2', if_true: files('hcd-dwc2.c'))
+softmmu_ss.add(when: 'CONFIG_USB_DWC3', if_true: files('hcd-dwc3.c'))
 
 softmmu_ss.add(when: 'CONFIG_TUSB6010', if_true: files('tusb6010.c'))
 softmmu_ss.add(when: 'CONFIG_IMX', if_true: files('chipidea.c'))
include/hw/usb/hcd-dwc3.h new file +55 -0

55 lines not on this page · raw message

Signature · 1 line
2.7.4
#8 lore raw

PATCH v12 3/3 Versal: Connect DWC3 controller with virt-versal

In reply to Sai Pavan Boddu

From: Vikram Garhwal <[email protected]>

Connect dwc3 controller and usb2-reg module to xlnx-versal SOC, its placed in iou of lpd domain and configure it as dual port host controller. Add the respective guest dts nodes for "xlnx-versal-virt" machine.

---
 hw/arm/xlnx-versal-virt.c    | 58 ++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/xlnx-versal.c         | 34 ++++++++++++++++++++++++++
 include/hw/arm/xlnx-versal.h | 14 +++++++++++
 3 files changed, 106 insertions(+)
hw/arm/xlnx-versal-virt.c +58 -0
index 03e2320..f0ac5ba 100644
@@ -39,6 +39,8 @@ struct VersalVirt {
         uint32_t ethernet_phy[2];
         uint32_t clk_125Mhz;
         uint32_t clk_25Mhz;
+        uint32_t usb;
+        uint32_t dwc;
     } phandle;
     struct arm_boot_info binfo;
 
@@ -66,6 +68,8 @@ static void fdt_create(VersalVirt *s)
     s->phandle.clk_25Mhz = qemu_fdt_alloc_phandle(s->fdt);
     s->phandle.clk_125Mhz = qemu_fdt_alloc_phandle(s->fdt);
 
+    s->phandle.usb = qemu_fdt_alloc_phandle(s->fdt);
+    s->phandle.dwc = qemu_fdt_alloc_phandle(s->fdt);
     /* Create /chosen node for load_dtb.  */
     qemu_fdt_add_subnode(s->fdt, "/chosen");
 
@@ -148,6 +152,59 @@ static void fdt_add_timer_nodes(VersalVirt *s)
                      compat, sizeof(compat));
 }
 
+static void fdt_add_usb_xhci_nodes(VersalVirt *s)
+{
+    const char clocknames[] = "bus_clk\0ref_clk";
+    char *name = g_strdup_printf("/usb@%" PRIx32, MM_USB2_CTRL_REGS);
+    const char compat[] = "xlnx,versal-dwc3";
+
+    qemu_fdt_add_subnode(s->fdt, name);
+    qemu_fdt_setprop(s->fdt, name, "compatible",
+                         compat, sizeof(compat));
+    qemu_fdt_setprop_sized_cells(s->fdt, name, "reg",
+                                 2, MM_USB2_CTRL_REGS,
+                                 2, MM_USB2_CTRL_REGS_SIZE);
+    qemu_fdt_setprop(s->fdt, name, "clock-names",
+                         clocknames, sizeof(clocknames));
+    qemu_fdt_setprop_cells(s->fdt, name, "clocks",
+                               s->phandle.clk_25Mhz, s->phandle.clk_125Mhz);
+    qemu_fdt_setprop(s->fdt, name, "ranges", NULL, 0);
+    qemu_fdt_setprop_cell(s->fdt, name, "#address-cells", 2);
+    qemu_fdt_setprop_cell(s->fdt, name, "#size-cells", 2);
+    qemu_fdt_setprop_cell(s->fdt, name, "phandle", s->phandle.usb);
+    g_free(name);
+
+    {
+        const char irq_name[] = "dwc_usb3";
+        const char compat[] = "snps,dwc3";
+
+        name = g_strdup_printf("/usb@%" PRIx32 "/dwc3@%" PRIx32,
+                               MM_USB2_CTRL_REGS, MM_USB_XHCI_0);
+        qemu_fdt_add_subnode(s->fdt, name);
+        qemu_fdt_setprop(s->fdt, name, "compatible",
+                         compat, sizeof(compat));
+        qemu_fdt_setprop_sized_cells(s->fdt, name, "reg",
+                                     2, MM_USB_XHCI_0, 2, MM_USB_XHCI_0_SIZE);
+        qemu_fdt_setprop(s->fdt, name, "interrupt-names",
+                         irq_name, sizeof(irq_name));
+        qemu_fdt_setprop_cells(s->fdt, name, "interrupts",
+                                   GIC_FDT_IRQ_TYPE_SPI, VERSAL_USB0_IRQ_0,
+                                   GIC_FDT_IRQ_FLAGS_LEVEL_HI);
+        qemu_fdt_setprop_cell(s->fdt, name,
+                              "snps,quirk-frame-length-adjustment", 0x20);
+        qemu_fdt_setprop_cells(s->fdt, name, "#stream-id-cells", 1);
+        qemu_fdt_setprop_string(s->fdt, name, "dr_mode", "host");
+        qemu_fdt_setprop_string(s->fdt, name, "phy-names", "usb3-phy");
+        qemu_fdt_setprop(s->fdt, name, "snps,dis_u2_susphy_quirk", NULL, 0);
+        qemu_fdt_setprop(s->fdt, name, "snps,dis_u3_susphy_quirk", NULL, 0);
+        qemu_fdt_setprop(s->fdt, name, "snps,refclk_fladj", NULL, 0);
+        qemu_fdt_setprop(s->fdt, name, "snps,mask_phy_reset", NULL, 0);
+        qemu_fdt_setprop_cell(s->fdt, name, "phandle", s->phandle.dwc);
+        qemu_fdt_setprop_string(s->fdt, name, "maximum-speed", "high-speed");
+        g_free(name);
+    }
+}
+
 static void fdt_add_uart_nodes(VersalVirt *s)
 {
     uint64_t addrs[] = { MM_UART1, MM_UART0 };
@@ -515,6 +572,7 @@ static void versal_virt_init(MachineState *machine)
     fdt_add_gic_nodes(s);
     fdt_add_timer_nodes(s);
     fdt_add_zdma_nodes(s);
+    fdt_add_usb_xhci_nodes(s);
     fdt_add_sd_nodes(s);
     fdt_add_rtc_node(s);
     fdt_add_cpu_nodes(s, psci_conduit);
hw/arm/xlnx-versal.c +34 -0
index 12ba6c4..ddf43db 100644
@@ -145,6 +145,39 @@ static void versal_create_uarts(Versal *s, qemu_irq *pic)
     }
 }
 
+static void versal_create_usbs(Versal *s, qemu_irq *pic)
+{
+    DeviceState *dev, *xhci_dev;
+    MemoryRegion *mr;
+
+    object_initialize_child(OBJECT(s), "dwc3-0", &s->lpd.iou.usb.dwc3,
+                            TYPE_USB_DWC3);
+    dev = DEVICE(&s->lpd.iou.usb.dwc3);
+    xhci_dev = DEVICE(&s->lpd.iou.usb.dwc3.sysbus_xhci);
+
+    object_property_set_link(OBJECT(xhci_dev), "dma", OBJECT(&s->mr_ps),
+                             &error_abort);
+    qdev_prop_set_uint32(xhci_dev, "intrs", 1);
+    qdev_prop_set_uint32(xhci_dev, "slots", 2);
+
+    sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
+
+    mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0);
+    memory_region_add_subregion(&s->mr_ps, MM_USB_XHCI_0_DWC3_GLOBAL, mr);
+    mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(xhci_dev), 0);
+    memory_region_add_subregion(&s->mr_ps, MM_USB_XHCI_0, mr);
+
+    sysbus_connect_irq(SYS_BUS_DEVICE(xhci_dev), 0, pic[VERSAL_USB0_IRQ_0]);
+
+    object_initialize_child(OBJECT(s), "usb2ctrl-0", &s->lpd.iou.usb.ctrl,
+                           TYPE_XILINX_VERSAL_USB2_CTRL_REGS);
+    dev = DEVICE(&s->lpd.iou.usb.ctrl);
+    sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
+
+    mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0);
+    memory_region_add_subregion(&s->mr_ps, MM_USB2_CTRL_REGS, mr);
+}
+
 static void versal_create_gems(Versal *s, qemu_irq *pic)
 {
     int i;
@@ -333,6 +366,7 @@ static void versal_realize(DeviceState *dev, Error **errp)
     versal_create_apu_cpus(s);
     versal_create_apu_gic(s, pic);
     versal_create_uarts(s, pic);
+    versal_create_usbs(s, pic);
     versal_create_gems(s, pic);
     versal_create_admas(s, pic);
     versal_create_sds(s, pic);
include/hw/arm/xlnx-versal.h +14 -0
index 8ce8e63..e0a6c66 100644
@@ -21,6 +21,8 @@
 #include "hw/net/cadence_gem.h"
 #include "hw/rtc/xlnx-zynqmp-rtc.h"
 #include "qom/object.h"
+#include "hw/usb/hcd-dwc3.h"
+#include "hw/misc/xlnx-versal-usb2-ctrl-regs.h"
 
 #define TYPE_XLNX_VERSAL "xlnx-versal"
 OBJECT_DECLARE_SIMPLE_TYPE(Versal, XLNX_VERSAL)
@@ -59,6 +61,10 @@ struct Versal {
             PL011State uart[XLNX_VERSAL_NR_UARTS];
             CadenceGEMState gem[XLNX_VERSAL_NR_GEMS];
             XlnxZDMA adma[XLNX_VERSAL_NR_ADMAS];
+            struct {
+                USBDWC3 dwc3;
+                VersalUsb2CtrlRegs ctrl;
+            } usb;
         } iou;
     } lpd;
 
@@ -88,6 +94,7 @@ struct Versal {
 
 #define VERSAL_UART0_IRQ_0         18
 #define VERSAL_UART1_IRQ_0         19
+#define VERSAL_USB0_IRQ_0          22
 #define VERSAL_GEM0_IRQ_0          56
 #define VERSAL_GEM0_WAKE_IRQ_0     57
 #define VERSAL_GEM1_IRQ_0          58
@@ -125,6 +132,13 @@ struct Versal {
 #define MM_OCM                      0xfffc0000U
 #define MM_OCM_SIZE                 0x40000
 
+#define MM_USB2_CTRL_REGS           0xFF9D0000
+#define MM_USB2_CTRL_REGS_SIZE      0x10000
+
+#define MM_USB_XHCI_0               0xFE200000
+#define MM_USB_XHCI_0_SIZE          0x10000
+#define MM_USB_XHCI_0_DWC3_GLOBAL   (MM_USB_XHCI_0 + 0xC100)
+
 #define MM_TOP_DDR                  0x0
 #define MM_TOP_DDR_SIZE             0x80000000U
 #define MM_TOP_DDR_2                0x800000000ULL
Signature · 1 line
2.7.4
#9 lore raw

Re: [PATCH v12 3/3] Versal: Connect DWC3 controller with virt-versal

Quoted 11 lines · Sai Pavan Boddu

From: Vikram Garhwal <[email protected]>

Connect dwc3 controller and usb2-reg module to xlnx-versal SOC, its placed in iou of lpd domain and configure it as dual port host controller. Add the respective guest dts nodes for "xlnx-versal-virt" machine.

hw/arm/xlnx-versal.c static void versal_create_uarts(Versal *s, qemu_irq *pic) · line 156

Quoted 9 lines
hw/arm/xlnx-versal.c +9 -0
+static void versal_create_usbs(Versal *s, qemu_irq *pic)
+{
+    DeviceState *dev, *xhci_dev;
+    MemoryRegion *mr;
+
+    object_initialize_child(OBJECT(s), "dwc3-0", &s->lpd.iou.usb.dwc3,
+                            TYPE_USB_DWC3);
+    dev = DEVICE(&s->lpd.iou.usb.dwc3);
+    xhci_dev = DEVICE(&s->lpd.iou.usb.dwc3.sysbus_xhci);

If you find yourself fishing around in the internals of another device, especially to this depth, then something's probably not right in the structure of that device.

hw/arm/xlnx-versal.c static void versal_create_uarts(Versal *s, qemu_irq *pic) · line 168

Quoted 12 lines
hw/arm/xlnx-versal.c +12 -0
+
+    object_property_set_link(OBJECT(xhci_dev), "dma", OBJECT(&s->mr_ps),
+                             &error_abort);
+    qdev_prop_set_uint32(xhci_dev, "intrs", 1);
+    qdev_prop_set_uint32(xhci_dev, "slots", 2);
+
+    sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
+
+    mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0);
+    memory_region_add_subregion(&s->mr_ps, MM_USB_XHCI_0_DWC3_GLOBAL, mr);
+    mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(xhci_dev), 0);
+    memory_region_add_subregion(&s->mr_ps, MM_USB_XHCI_0, mr);

For instance, rather than having to find the xhci device and map its memory regions and connect its IRQs directly, the usb-dwc3 device could provide and pass through those MRs and IRQs, so that board code is only wiring up what the usb-dwc3 provides and doesn't need to know about its internals.

thanks
-- PMM

#10 lore raw

RE: [PATCH v12 3/3] Versal: Connect DWC3 controller with virt-versal

Hi Peter

Quoted 28 lines

-----Original Message-----
From: Peter Maydell <[email protected]>
Sent: Monday, October 26, 2020 9:35 PM
To: Sai Pavan Boddu <[email protected]>
Cc: Markus Armbruster <[email protected]>; Marc-André Lureau <[email protected]>; Paolo Bonzini <[email protected]>; Gerd Hoffmann <[email protected]>; Edgar Iglesias <[email protected]>; Francisco Eduardo Iglesias <[email protected]>; QEMU Developers <qemu- [email protected]>; Alistair Francis <[email protected]>; Eduardo Habkost <[email protected]>; Ying Fang <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Vikram Garhwal <[email protected]>; Paul Zimmerman <[email protected]>; Sai Pavan Boddu <[email protected]>
Subject: Re: [PATCH v12 3/3] Versal: Connect DWC3 controller with virt-versal

Quoted 9 lines · Sai Pavan Boddu

From: Vikram Garhwal <[email protected]>

Connect dwc3 controller and usb2-reg module to xlnx-versal SOC, its placed in iou of lpd domain and configure it as dual port host controller. Add the respective guest dts nodes for "xlnx-versal-virt" machine.

Quoted 12 lines

hw/arm/xlnx-versal.c static void versal_create_uarts(Versal *s, qemu_irq *pic) · line 156

Quoted 8 lines
hw/arm/xlnx-versal.c +8 -0
+static void versal_create_usbs(Versal *s, qemu_irq *pic) {
+    DeviceState *dev, *xhci_dev;
+    MemoryRegion *mr;
+
+    object_initialize_child(OBJECT(s), "dwc3-0", &s->lpd.iou.usb.dwc3,
+                            TYPE_USB_DWC3);
+    dev = DEVICE(&s->lpd.iou.usb.dwc3);
+    xhci_dev = DEVICE(&s->lpd.iou.usb.dwc3.sysbus_xhci);

If you find yourself fishing around in the internals of another device, especially to this depth, then something's probably not right in the structure of that device.

[Sai Pavan Boddu] Yeah, it look pretty long. But, "s->lpd.iou.usb" defines soc domains for us. Ex. Usb is part of low-power domain(i.e lpd) in IOU module.
And " dwc3.sysbus_xhci ", is specific to usb and is result of parenting dwc3 to xhci.

Quoted 12 lines

hw/arm/xlnx-versal.c static void versal_create_uarts(Versal *s, qemu_irq *pic)

Quoted 11 lines
hw/arm/xlnx-versal.c +10 -0
+
+    object_property_set_link(OBJECT(xhci_dev), "dma", OBJECT(&s->mr_ps),
+                             &error_abort);
+    qdev_prop_set_uint32(xhci_dev, "intrs", 1);
+    qdev_prop_set_uint32(xhci_dev, "slots", 2);
+
+    sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
+
+    mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0);
+    memory_region_add_subregion(&s->mr_ps,

MM_USB_XHCI_0_DWC3_GLOBAL, mr);

Quoted 8 lines

hw/arm/xlnx-versal.c static void versal_create_uarts(Versal *s, qemu_irq *pic) · line 168

Quoted 2 lines
hw/arm/xlnx-versal.c +2 -0
+    mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(xhci_dev), 0);
+    memory_region_add_subregion(&s->mr_ps, MM_USB_XHCI_0, mr);

For instance, rather than having to find the xhci device and map its memory regions and connect its IRQs directly, the
usb-dwc3 device could provide and pass through those MRs and IRQs, so that board code is only wiring up what the usb-dwc3 provides and doesn't need to know about its internals.

[Sai Pavan Boddu] Yes, xhci registers can be mapped internally. We can make those changes.

Regards,
Sai Pavan

Quoted 4 lines

thanks
-- PMM

Reviewed-by on the v12 series
#11 lore raw
In reply to Sai Pavan Boddu
Quoted 1 line · Sai Pavan Boddu

This patch series attempts to make 'hcd-xhci' an independent model so it can be used by both pci and system-bus interface.

On the series:

Quoted 66 lines

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.
Changes for V10:
use vmstate_post_load avaialble in VMStateDescription
tested vmstate cross migration.
Changes for V11:
Removed the patches which got accepted
Changed object name "USB2Reg" -> "ctrl"
Updated Subject line on cover letter.
Changes for V12:
Use reset class for usb2-ctrl-regs module
Move the few register update to realize
Marked registers which are unimplemented in regapi model

Sai Pavan Boddu (1):
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         | 229 +++++++++
 hw/usb/Kconfig                               |   6 +
 hw/usb/hcd-dwc3.c                            | 666 +++++++++++++++++++++++++++
 hw/usb/meson.build                           |   1 +
 include/hw/arm/xlnx-versal.h                 |  14 +
 include/hw/misc/xlnx-versal-usb2-ctrl-regs.h |  45 ++
 include/hw/usb/hcd-dwc3.h                    |  55 +++
 10 files changed, 1109 insertions(+)
 create mode 100644 hw/misc/xlnx-versal-usb2-ctrl-regs.c
 create mode 100644 hw/usb/hcd-dwc3.c
 create mode 100644 include/hw/misc/xlnx-versal-usb2-ctrl-regs.h
 create mode 100644 include/hw/usb/hcd-dwc3.h
Signature · 1 line
2.7.4