Make hcd-xhci independent of pci hooks
v9 cover Make hcd-xhci independent of pci hooks
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
Signature · 1 line
2.7.4
PATCH v9 1/7 usb/hcd-xhci: Make dma read/writes hooks pci free
This patch starts making the hcd-xhci.c pci free, as part of this restructuring dma read/writes are handled without passing pci object.
--- hw/usb/hcd-xhci.c | 24 +++++++++++------------- hw/usb/hcd-xhci.h | 1 + 2 files changed, 12 insertions(+), 13 deletions(-)
hw/usb/hcd-xhci.c +11 -13
@@ -495,7 +495,7 @@ static inline void xhci_dma_read_u32s(XHCIState *xhci, dma_addr_t addr,assert ((len %sizeof (uint32_t )) ==0 ); -pci_dma_read (PCI_DEVICE (xhci), addr, buf, len); +dma_memory_read (xhci->as, addr, buf, len);for (i =0 ; i < (len /sizeof (uint32_t )); i++) { buf[i] =le32_to_cpu (buf[i]);
@@ -515,7 +515,7 @@ static inline void xhci_dma_write_u32s(XHCIState *xhci, dma_addr_t addr,for (i =0 ; i < n; i++) { tmp[i] =cpu_to_le32 (buf[i]); } -pci_dma_write (PCI_DEVICE (xhci), addr, tmp, len); +dma_memory_write (xhci->as, addr, tmp, len); }static XHCIPort *xhci_lookup_port (XHCIState *xhci,struct USBPort *uport)
@@ -644,7 +644,6 @@ static void xhci_die(XHCIState *xhci)static void xhci_write_event (XHCIState *xhci,XHCIEvent *event,int v) { -PCIDevice *pci_dev =PCI_DEVICE (xhci);XHCIInterrupter *intr = &xhci->intr[v];XHCITRB ev_trb;dma_addr_t addr;
@@ -663,7 +662,7 @@ static void xhci_write_event(XHCIState *xhci, XHCIEvent *event, int v) ev_trb.status, ev_trb.control); addr = intr->er_start +TRB_SIZE *intr->er_ep_idx; -pci_dma_write (pci_dev, addr, &ev_trb,TRB_SIZE ); +dma_memory_write (xhci->as, addr, &ev_trb,TRB_SIZE ); intr->er_ep_idx++;if (intr->er_ep_idx >= intr->er_size) {
@@ -720,12 +719,11 @@ static void xhci_ring_init(XHCIState *xhci, XHCIRing *ring,static TRBType xhci_ring_fetch (XHCIState *xhci,XHCIRing *ring,XHCITRB *trb,dma_addr_t *addr) { -PCIDevice *pci_dev =PCI_DEVICE (xhci);uint32_t link_cnt =0 ;while (1 ) {TRBType type; -pci_dma_read (pci_dev, ring->dequeue, trb,TRB_SIZE ); +dma_memory_read (xhci->as, ring->dequeue, trb,TRB_SIZE ); trb->addr = ring->dequeue; trb->ccs = ring->ccs;le64_to_cpus (&trb->parameter);
@@ -762,7 +760,6 @@ static TRBType xhci_ring_fetch(XHCIState *xhci, XHCIRing *ring, XHCITRB *trb,static int xhci_ring_chain_length (XHCIState *xhci,const XHCIRing *ring) { -PCIDevice *pci_dev =PCI_DEVICE (xhci);XHCITRB trb;int length =0 ;dma_addr_t dequeue = ring->dequeue;
@@ -773,7 +770,7 @@ static int xhci_ring_chain_length(XHCIState *xhci, const XHCIRing *ring)while (1 ) {TRBType type; -pci_dma_read (pci_dev, dequeue, &trb,TRB_SIZE ); +dma_memory_read (xhci->as, dequeue, &trb,TRB_SIZE );le64_to_cpus (&trb.parameter);le32_to_cpus (&trb.status);le32_to_cpus (&trb.control);
@@ -828,7 +825,7 @@ static void xhci_er_reset(XHCIState *xhci, int v)xhci_die (xhci);return ; } -pci_dma_read (PCI_DEVICE (xhci), erstba, &seg,sizeof (seg)); +dma_memory_read (xhci->as, erstba, &seg,sizeof (seg));le32_to_cpus (&seg.addr_low);le32_to_cpus (&seg.addr_high);le32_to_cpus (&seg.size);
@@ -1440,7 +1437,7 @@ static int xhci_xfer_create_sgl(XHCITransfer *xfer, int in_xfer)int i; xfer->int_req = false; -pci_dma_sglist_init (&xfer->sgl,PCI_DEVICE (xhci), xfer->trb_count); +qemu_sglist_init (&xfer->sgl,DEVICE (xhci), xfer->trb_count, xhci->as);for (i =0 ; i < xfer->trb_count; i++) {XHCITRB *trb = &xfer->trbs[i];dma_addr_t addr;
@@ -2104,7 +2101,7 @@ static TRBCCode xhci_address_slot(XHCIState *xhci, unsigned int slotid,assert (slotid >=1 && slotid <= xhci->numslots); dcbaap =xhci_addr64 (xhci->dcbaap_low, xhci->dcbaap_high); - poctx =ldq_le_pci_dma (PCI_DEVICE (xhci), dcbaap +8 * slotid); + poctx =ldq_le_dma (xhci->as, dcbaap +8 * slotid); ictx =xhci_mask64 (pictx); octx =xhci_mask64 (poctx);
@@ -2442,7 +2439,7 @@ static TRBCCode xhci_get_port_bandwidth(XHCIState *xhci, uint64_t pctx)/* TODO: actually implement real values here */ bw_ctx[0 ] =0 ;memset (&bw_ctx[1 ],80 , xhci->numports);/* 80% */ -pci_dma_write (PCI_DEVICE (xhci), ctx, bw_ctx,sizeof (bw_ctx)); +dma_memory_write (xhci->as, ctx, bw_ctx,sizeof (bw_ctx));return CC_SUCCESS ; }
@@ -3434,6 +3431,7 @@ static void usb_xhci_realize(struct PCIDevice *dev, Error **errp) }usb_xhci_init (xhci); + xhci->as =pci_get_address_space (dev); xhci->mfwrap_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , xhci_mfwrap_timer, xhci);memory_region_init (&xhci->mem,OBJECT (xhci),"xhci" ,LEN_REGS );
@@ -3534,7 +3532,7 @@ static int usb_xhci_post_load(void *opaque, int version_id)continue ; } slot->ctx = -xhci_mask64 (ldq_le_pci_dma (pci_dev, dcbaap +8 * slotid)); +xhci_mask64 (ldq_le_dma (xhci->as, dcbaap +8 * slotid));xhci_dma_read_u32s (xhci, slot->ctx, slot_ctx,sizeof (slot_ctx)); slot->uport =xhci_lookup_uport (xhci, slot_ctx);if (!slot->uport) {
hw/usb/hcd-xhci.h +1 -0
@@ -188,6 +188,7 @@ struct XHCIState {USBBus bus;MemoryRegion mem; +AddressSpace *as;MemoryRegion mem_cap;MemoryRegion mem_oper;MemoryRegion mem_runtime;
Signature · 1 line
2.7.4
PATCH v9 2/7 usb/hcd-xhci: Move qemu-xhci device to hcd-xhci-pci.c
In reply to Sai Pavan BodduMove pci specific devices to new file. This set the environment to move all pci specific hooks in hcd-xhci.c to hcd-xhci-pci.c.
--- hw/usb/Kconfig | 6 +++++ hw/usb/hcd-xhci-pci.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ hw/usb/hcd-xhci.c | 33 ++------------------------ hw/usb/hcd-xhci.h | 4 ++++ hw/usb/meson.build | 1 + 5 files changed, 79 insertions(+), 31 deletions(-) create mode 100644 hw/usb/hcd-xhci-pci.c
hw/usb/Kconfig +6 -0
@@ -36,6 +36,12 @@ config USB_XHCI depends on PCI select USB +config USB_XHCI_PCI + bool + default y if PCI_DEVICES + depends on PCI + select USB_XHCI + config USB_XHCI_NEC bool default y if PCI_DEVICES
hw/usb/hcd-xhci-pci.c new file +66 -0
66 lines not on this page · raw message
hw/usb/hcd-xhci.c +2 -31
@@ -23,7 +23,6 @@#include "qemu/timer.h" #include "qemu/module.h" #include "qemu/queue.h" -#include "hw/usb.h" #include "migration/vmstate.h" #include "hw/pci/pci.h" #include "hw/qdev-properties.h"
@@ -429,12 +428,12 @@ static const char *ep_state_name(uint32_t state) ARRAY_SIZE(ep_state_names)); } -static bool xhci_get_flag (XHCIState *xhci,enum xhci_flags bit) +bool xhci_get_flag (XHCIState *xhci,enum xhci_flags bit) {return xhci->flags & (1 << bit); } -static void xhci_set_flag (XHCIState *xhci,enum xhci_flags bit) +void xhci_set_flag (XHCIState *xhci,enum xhci_flags bit) { xhci->flags |= (1 << bit); }
@@ -3730,37 +3729,9 @@ static const TypeInfo xhci_info = { }, }; -static void qemu_xhci_class_init (ObjectClass *klass,void *data) -{ -PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); - - k->vendor_id =PCI_VENDOR_ID_REDHAT ; - k->device_id =PCI_DEVICE_ID_REDHAT_XHCI ; - k->revision =0x01 ; -} - -static void qemu_xhci_instance_init (Object *obj) -{ -XHCIState *xhci =XHCI (obj); - - xhci->msi =ON_OFF_AUTO_OFF ; - xhci->msix =ON_OFF_AUTO_AUTO ; - xhci->numintrs =MAXINTRS ; - xhci->numslots =MAXSLOTS ; -xhci_set_flag (xhci,XHCI_FLAG_SS_FIRST ); -} - -static const TypeInfo qemu_xhci_info = { - .name =TYPE_QEMU_XHCI , - .parent =TYPE_XHCI , - .class_init = qemu_xhci_class_init, - .instance_init = qemu_xhci_instance_init, -}; -static void xhci_register_types (void ) {type_register_static (&xhci_info); -type_register_static (&qemu_xhci_info); }type_init (xhci_register_types)
hw/usb/hcd-xhci.h +4 -0
@@ -23,6 +23,8 @@#define HW_USB_HCD_XHCI_H #include "qom/object.h" +#include "hw/usb.h" +#define TYPE_XHCI "base-xhci"#define TYPE_NEC_XHCI "nec-usb-xhci"#define TYPE_QEMU_XHCI "qemu-xhci"
@@ -229,4 +231,6 @@ struct XHCIState { bool nec_quirks; }; +bool xhci_get_flag (XHCIState *xhci,enum xhci_flags bit); +void xhci_set_flag (XHCIState *xhci,enum xhci_flags bit);#endif
hw/usb/meson.build +1 -0
@@ -21,6 +21,7 @@ softmmu_ss.add(when: 'CONFIG_USB_EHCI', if_true: files('hcd-ehci.c')) softmmu_ss.add(when: 'CONFIG_USB_EHCI_PCI', if_true: files('hcd-ehci-pci.c')) softmmu_ss.add(when: 'CONFIG_USB_EHCI_SYSBUS', if_true: files('hcd-ehci.c', 'hcd-ehci-sysbus.c')) softmmu_ss.add(when: 'CONFIG_USB_XHCI', if_true: files('hcd-xhci.c')) +softmmu_ss.add(when: 'CONFIG_USB_XHCI_PCI', if_true: files('hcd-xhci-pci.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'))
Signature · 1 line
2.7.4
PATCH v9 3/7 usb/hcd-xhci: Split pci wrapper for xhci base model
In reply to Sai Pavan BodduThis patch sets the base to use xhci as sysbus model, for which pci specific hooks are moved to hcd-xhci-pci.c. As a part of this requirment msi/msix interrupts handling is moved under XHCIPCIState. Made required changes for qemu-xhci-nec.
--- hw/usb/hcd-xhci-nec.c | 18 ++--- hw/usb/hcd-xhci-pci.c | 204 +++++++++++++++++++++++++++++++++++++++++++++-- hw/usb/hcd-xhci-pci.h | 44 +++++++++++ hw/usb/hcd-xhci.c | 214 +++++++++++--------------------------------------- hw/usb/hcd-xhci.h | 16 ++-- 5 files changed, 305 insertions(+), 191 deletions(-) create mode 100644 hw/usb/hcd-xhci-pci.h
hw/usb/hcd-xhci-nec.c +9 -9
@@ -25,17 +25,17 @@#include "hw/pci/pci.h" #include "hw/qdev-properties.h" -#include "hcd-xhci.h" +#include "hcd-xhci-pci.h" static Property nec_xhci_properties[] = { -DEFINE_PROP_ON_OFF_AUTO ("msi" , XHCIState, msi,ON_OFF_AUTO_AUTO ), -DEFINE_PROP_ON_OFF_AUTO ("msix" , XHCIState, msix,ON_OFF_AUTO_AUTO ), -DEFINE_PROP_BIT ("superspeed-ports-first" , - XHCIState, flags,XHCI_FLAG_SS_FIRST , true), -DEFINE_PROP_BIT ("force-pcie-endcap" , XHCIState, flags, +DEFINE_PROP_ON_OFF_AUTO ("msi" , XHCIPciState, msi,ON_OFF_AUTO_AUTO ), +DEFINE_PROP_ON_OFF_AUTO ("msix" , XHCIPciState, msix,ON_OFF_AUTO_AUTO ), +DEFINE_PROP_BIT ("superspeed-ports-first" , XHCIPciState, + xhci.flags,XHCI_FLAG_SS_FIRST , true), +DEFINE_PROP_BIT ("force-pcie-endcap" , XHCIPciState, xhci.flags,XHCI_FLAG_FORCE_PCIE_ENDCAP , false), -DEFINE_PROP_UINT32 ("intrs" , XHCIState, numintrs,MAXINTRS ), -DEFINE_PROP_UINT32 ("slots" , XHCIState, numslots,MAXSLOTS ), +DEFINE_PROP_UINT32 ("intrs" , XHCIPciState, xhci.numintrs,MAXINTRS ), +DEFINE_PROP_UINT32 ("slots" , XHCIPciState, xhci.numslots,MAXSLOTS ),DEFINE_PROP_END_OF_LIST (), };
@@ -52,7 +52,7 @@ static void nec_xhci_class_init(ObjectClass *klass, void *data)static const TypeInfo nec_xhci_info = { .name =TYPE_NEC_XHCI , - .parent =TYPE_XHCI , + .parent =TYPE_XHCI_PCI , .class_init = nec_xhci_class_init, };
hw/usb/hcd-xhci-pci.c +199 -5
234 lines not on this page · raw message
hw/usb/hcd-xhci-pci.h new file +44 -0
44 lines not on this page · raw message
hw/usb/hcd-xhci.c +44 -170
375 lines not on this page · raw message
hw/usb/hcd-xhci.h +9 -7
@@ -24,6 +24,7 @@#include "qom/object.h" #include "hw/usb.h" +#include "sysemu/dma.h" #define TYPE_XHCI "base-xhci"#define TYPE_NEC_XHCI "nec-usb-xhci"
@@ -183,10 +184,8 @@ typedef struct XHCIInterrupter { } XHCIInterrupter; -struct XHCIState { -/*< private >*/ -PCIDevice parent_obj; -/*< public >*/ +typedef struct XHCIState { + DeviceState parent; USBBus bus; MemoryRegion mem;
@@ -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); +DeviceState *hostOpaque;/* Operational Registers */ uint32_t usbcmd;
@@ -229,8 +230,9 @@ struct XHCIState {XHCIRing cmd_ring; bool nec_quirks; -}; +} XHCIState; +extern const VMStateDescription vmstate_xhci;bool xhci_get_flag (XHCIState *xhci,enum xhci_flags bit);void xhci_set_flag (XHCIState *xhci,enum xhci_flags bit);#endif
Signature · 1 line
2.7.4
Re: [PATCH v9 3/7] usb/hcd-xhci: Split pci wrapper for xhci base model
Hi,
Review struct XHCIState { · line 207
Quoted 9 lines
(quoted diff) +3
-2@@ -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 ]
hw/usb/hcd-xhci.h +0 -1
@@ -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 */
hw/usb/hcd-xhci-pci.c +6 -4
@@ -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),
hw/usb/hcd-xhci.c +0 -3
@@ -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 ; }
RE: [PATCH v9 3/7] usb/hcd-xhci: Split pci wrapper for xhci base model
Hi Gerd,
Quoted 19 lines
-----Original Message-----
From: Gerd Hoffmann <[email protected]>
Sent: Thursday, September 24, 2020 11:45 AM
To: Sai Pavan Boddu <[email protected]>
Cc: Peter Maydell <[email protected]>; Markus Armbruster <[email protected]>; 'Marc-André Lureau' <[email protected]>; Paolo Bonzini <[email protected]>; Edgar Iglesias <[email protected]>; Francisco Eduardo Iglesias <[email protected]>; [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 v9 3/7] usb/hcd-xhci: Split pci wrapper for xhci base modelHi,
Quoted 12 lines
Review struct XHCIState { · line 207
Quoted 9 lines
(quoted diff) +3
-2@@ -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_loadhook, 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
Quoted 78 lines
take care,
Gerd[ I can squash that into 3/7 if you have no objections ]
hw/usb/hcd-xhci.h index renamed from hw/usb/hcd-xhci.h +0
-0
294bdc62aeaf..f859a17e73ee100644hw/usb/hcd-xhci.h +0
-1@@ -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 */ hw/usb/hcd-xhci-pci.c index renamed from hw/usb/hcd-xhci-pci.c +0
-0
f06a2b7f4c57..77608fb78def100644hw/usb/hcd-xhci-pci.c +5
-3@@ -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;hw/usb/hcd-xhci-pci.c +1
-1- 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) staticconst 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.cb/hw/usb/hcd-xhci.cindex4a6c0e7edb1a..b1b95abb9b29100644hw/usb/hcd-xhci.c +0
-3@@ -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 ; }
PATCH v9 4/7 usb: hcd-xhci-sysbus: Attach xhci to sysbus device
In reply to Sai Pavan BodduUse XHCI as sysbus device, add memory region property to get the address space instance for dma read/write.
--- hw/usb/Kconfig | 5 +++ hw/usb/hcd-xhci-sysbus.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++ hw/usb/hcd-xhci-sysbus.h | 32 ++++++++++++++ hw/usb/hcd-xhci.h | 1 + hw/usb/meson.build | 1 + 5 files changed, 148 insertions(+) create mode 100644 hw/usb/hcd-xhci-sysbus.c create mode 100644 hw/usb/hcd-xhci-sysbus.h
hw/usb/Kconfig +5 -0
@@ -48,6 +48,11 @@ config USB_XHCI_NEC depends on PCI select USB_XHCI +config USB_XHCI_SYSBUS + bool + default y if USB_XHCI + select USB + config USB_MUSB bool select USB
hw/usb/hcd-xhci-sysbus.c new file +109 -0
109 lines not on this page · raw message
hw/usb/hcd-xhci-sysbus.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* USB xHCI controller for system-bus interface +* +* SPDX-FileCopyrightText: 2020 Xilinx +* SPDX-FileContributor: Author: Sai Pavan Boddu <[email protected]> +* SPDX-sourceInfo: Based on hcd-echi-sysbus +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef HW_USB_HCD_XHCI_SYSBUS_H +#define HW_USB_HCD_XHCI_SYSBUS_H + +#include "hw/usb.h" +#include "hcd-xhci.h" +#include "hw/sysbus.h" + +#define TYPE_XHCI_SYSBUS "sysbus-xhci" +#define XHCI_SYSBUS (obj) \ + OBJECT_CHECK(XHCISysbusState, (obj), TYPE_XHCI_SYSBUS) + + +typedef struct XHCISysbusState { +/*< private >*/ +SysBusDevice parent_obj; +/*< public >*/ +XHCIState xhci; +qemu_irq *irq; +}XHCISysbusState ; + +void xhci_sysbus_reset (DeviceState *dev); +#endif
hw/usb/hcd-xhci.h +1 -0
@@ -189,6 +189,7 @@ typedef struct XHCIState {USBBus bus;MemoryRegion mem; +MemoryRegion *dma_mr;AddressSpace *as;MemoryRegion mem_cap;MemoryRegion mem_oper;
hw/usb/meson.build +1 -0
@@ -22,6 +22,7 @@ softmmu_ss.add(when: 'CONFIG_USB_EHCI_PCI', if_true: files('hcd-ehci-pci.c')) softmmu_ss.add(when: 'CONFIG_USB_EHCI_SYSBUS', if_true: files('hcd-ehci.c', 'hcd-ehci-sysbus.c')) softmmu_ss.add(when: 'CONFIG_USB_XHCI', if_true: files('hcd-xhci.c')) softmmu_ss.add(when: 'CONFIG_USB_XHCI_PCI', if_true: files('hcd-xhci-pci.c')) +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'))
Signature · 1 line
2.7.4
PATCH v9 5/7 misc: Add versal-usb2-ctrl-regs module
In reply to Sai Pavan BodduThis 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 | 222 +++++++++++++++++++++++++++ include/hw/misc/xlnx-versal-usb2-ctrl-regs.h | 45 ++++++ 3 files changed, 268 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
@@ -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 +222 -0
222 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
PATCH v9 6/7 usb: Add DWC3 model
In reply to Sai Pavan BodduFrom: 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 | 717 ++++++++++++++++++++++++++++++++++++++++++++++ hw/usb/meson.build | 1 + include/hw/usb/hcd-dwc3.h | 55 ++++ 4 files changed, 779 insertions(+) create mode 100644 hw/usb/hcd-dwc3.c create mode 100644 include/hw/usb/hcd-dwc3.h
hw/usb/Kconfig +6 -0
@@ -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 +717 -0
717 lines not on this page · raw message
hw/usb/meson.build +1 -0
@@ -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
PATCH v9 7/7 Versal: Connect DWC3 controller with virt-versal
In reply to Sai Pavan BodduFrom: 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
@@ -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
@@ -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),"usb2reg-0" , &s->lpd.iou.usb.Usb2Regs, +TYPE_XILINX_VERSAL_USB2_CTRL_REGS ); + dev =DEVICE (&s->lpd.iou.usb.Usb2Regs); +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
@@ -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 Usb2Regs; + } 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