Make hcd-xhci independent of pci hooks
v5 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
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-regs module
Vikram Garhwal (2):
usb: Add DWC3 model
Versal: Connect DWC3 controller with virt-versal
hw/arm/xlnx-versal-virt.c | 59 +++ hw/arm/xlnx-versal.c | 38 ++ hw/misc/meson.build | 1 + hw/misc/xlnx-versal-usb2-regs.c | 226 ++++++++++ hw/usb/Kconfig | 17 + hw/usb/hcd-dwc3.c | 717 ++++++++++++++++++++++++++++++++ hw/usb/hcd-xhci-nec.c | 18 +- hw/usb/hcd-xhci-pci.c | 244 +++++++++++ hw/usb/hcd-xhci-pci.h | 45 ++ hw/usb/hcd-xhci-sysbus.c | 99 +++++ hw/usb/hcd-xhci-sysbus.h | 32 ++ hw/usb/hcd-xhci.c | 260 +++--------- hw/usb/hcd-xhci.h | 22 +- hw/usb/meson.build | 3 + include/hw/arm/xlnx-versal.h | 14 + include/hw/misc/xlnx-versal-usb2-regs.h | 43 ++ include/hw/usb/hcd-dwc3.h | 55 +++ 17 files changed, 1668 insertions(+), 225 deletions(-) create mode 100644 hw/misc/xlnx-versal-usb2-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-regs.h create mode 100644 include/hw/usb/hcd-dwc3.h
Signature · 1 line
2.7.4
PATCH v5 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
@@ -189,6 +189,7 @@ struct XHCIState {USBBus bus;MemoryRegion mem; +AddressSpace *as;MemoryRegion mem_cap;MemoryRegion mem_oper;MemoryRegion mem_runtime;
Signature · 1 line
2.7.4
Re: [PATCH v5 1/7] usb/hcd-xhci: Make dma read/writes hooks pci free
Quoted 4 lines · Sai Pavan Boddu
This patch starts making the
hcd-xhci.cpci free, as part of this restructuring dma read/writes are handled without passing pci object.Signed-off-by Sai Pavan Boddu <[email protected]>
Quoted 143 lines
--- 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@@ -189,6 +189,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 v5 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
@@ -22,6 +22,8 @@#ifndef HW_USB_HCD_XHCI_H #define HW_USB_HCD_XHCI_H +#include "hw/usb.h" +#define TYPE_XHCI "base-xhci"#define TYPE_NEC_XHCI "nec-usb-xhci"#define TYPE_QEMU_XHCI "qemu-xhci"
@@ -230,4 +232,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 v5 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.
fixup
--- hw/usb/hcd-xhci-nec.c | 18 ++--- hw/usb/hcd-xhci-pci.c | 188 +++++++++++++++++++++++++++++++++++++++++++-- hw/usb/hcd-xhci-pci.h | 45 +++++++++++ hw/usb/hcd-xhci.c | 205 ++++++++++---------------------------------------- hw/usb/hcd-xhci.h | 16 ++-- 5 files changed, 285 insertions(+), 187 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 +183 -5
218 lines not on this page · raw message
hw/usb/hcd-xhci-pci.h new file +45 -0
45 lines not on this page · raw message
hw/usb/hcd-xhci.c +40 -165
364 lines not on this page · raw message
hw/usb/hcd-xhci.h +8 -8
@@ -23,6 +23,7 @@#define HW_USB_HCD_XHCI_H #include "hw/usb.h" +#include "sysemu/dma.h" #define TYPE_XHCI "base-xhci"#define TYPE_NEC_XHCI "nec-usb-xhci"
@@ -170,7 +171,7 @@ typedef struct XHCIInterrupter {uint32_t erdp_low;uint32_t erdp_high; -bool msix_used, er_pcs; +bool er_pcs;dma_addr_t er_start;uint32_t er_size;
@@ -184,10 +185,8 @@ typedef struct XHCIInterrupter { } XHCIInterrupter; -struct XHCIState { -/*< private >*/ -PCIDevice parent_obj; -/*< public >*/ +typedef struct XHCIState { + DeviceState parent; USBBus bus; MemoryRegion mem;
@@ -204,8 +203,9 @@ 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); +DeviceState *hostOpaque;/* Operational Registers */ uint32_t usbcmd;
@@ -230,7 +230,7 @@ struct XHCIState {XHCIRing cmd_ring;bool nec_quirks; -}; +} XHCIState;bool xhci_get_flag (XHCIState *xhci,enum xhci_flags bit);void xhci_set_flag (XHCIState *xhci,enum xhci_flags bit);
Signature · 1 line
2.7.4
PATCH v5 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 | 99 ++++++++++++++++++++++++++++++++++++++++++++++++ hw/usb/hcd-xhci-sysbus.h | 32 ++++++++++++++++ hw/usb/hcd-xhci.h | 1 + hw/usb/meson.build | 1 + 5 files changed, 138 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 +99 -0
99 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
@@ -190,6 +190,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 v5 5/7 misc: Add versal-usb2-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-regs.c | 226 ++++++++++++++++++++++++++++++++ include/hw/misc/xlnx-versal-usb2-regs.h | 43 ++++++ 3 files changed, 270 insertions(+) create mode 100644 hw/misc/xlnx-versal-usb2-regs.c create mode 100644 include/hw/misc/xlnx-versal-usb2-regs.h
hw/misc/meson.build +1 -0
@@ -99,3 +99,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-regs.c'))
hw/misc/xlnx-versal-usb2-regs.c new file +226 -0
226 lines not on this page · raw message
include/hw/misc/xlnx-versal-usb2-regs.h new file +43 -0
43 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH v5 5/7] misc: Add versal-usb2-regs module
Quoted 63 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.
Signed-off-by Sai Pavan Boddu <[email protected]>Signed-off-by Vikram Garhwal <[email protected]>--- hw/misc/meson.build | 1 + hw/misc/xlnx-versal-usb2-regs.c | 226 ++++++++++++++++++++++++++++++++ include/hw/misc/xlnx-versal-usb2-regs.h | 43 ++++++ 3 files changed, 270 insertions(+) create mode 100644 hw/misc/xlnx-versal-usb2-regs.c create mode 100644 include/hw/misc/xlnx-versal-usb2-regs.hhw/misc/meson.build +1
-0@@ -99,3 +99,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-regs.c'))hw/misc/xlnx-versal-usb2-regs.c new file +33
-0@@ -0,0 +1,226 @@ +/* +* QEMU model of the XlnxUsb2Regs Register control block/Status for USB2.0 IP +* +* This module should control phy_reset, permanent device plugs, frame length +* time adjust & setting of coherency paths. None of which are emulated in +* present model. +* +* Copyright (c) 2020 Xilinx Inc. Vikram Garhwal <[email protected]> +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#include "qemu/osdep.h" +#include "hw/sysbus.h" +#include "hw/irq.h" +#include "hw/register.h" +#include "qemu/bitops.h"
hw/misc/xlnx-versal-usb2-regs.c line 43
Quoted 10 lines
hw/misc/xlnx-versal-usb2-regs.c new file +10
-0+#include "qemu/log.h" +#include "qom/object.h" +#include "migration/vmstate.h" +#include "hw/misc/xlnx-versal-usb2-regs.h" + +#ifndef XILINX_USB2_REGS_ERR_DEBUG +#define XILINX_USB2_REGS_ERR_DEBUG 0 +#endif + +#define TYPE_XILINX_USB2_REGS "xlnx.usb2_regs"
I think we need to add versal to the name.
Also, USB2 Regs is not a very good name (I know that's what it's internally called but). Perhaps xlnx.versal-usb2-ctrl-regs?
And XlnxVersalUsb2CtrlRegs
Quoted 189 lines
hw/misc/xlnx-versal-usb2-regs.c new file +183
-0+ +#define XILINX_USB2_REGS (obj) \ + OBJECT_CHECK(XlnxUsb2Regs, (obj), TYPE_XILINX_USB2_REGS) + +REG32(BUS_FILTER, 0x30) + FIELD(BUS_FILTER, BYPASS, 0, 4) +REG32(PORT, 0x34) + FIELD(PORT, HOST_SMI_BAR_WR, 4, 1) + FIELD(PORT, HOST_SMI_PCI_CMD_REG_WR, 3, 1) + FIELD(PORT, HOST_MSI_ENABLE, 2, 1) + FIELD(PORT, PWR_CTRL_PRSNT, 1, 1) + FIELD(PORT, HUB_PERM_ATTACH, 0, 1) +REG32(JITTER_ADJUST, 0x38) + FIELD(JITTER_ADJUST, FLADJ, 0, 6) +REG32(BIGENDIAN, 0x40) + FIELD(BIGENDIAN, ENDIAN_GS, 0, 1) +REG32(COHERENCY, 0x44) + FIELD(COHERENCY, USB_COHERENCY, 0, 1) +REG32(XHC_BME, 0x48) + FIELD(XHC_BME, XHC_BME, 0, 1) +REG32(REG_CTRL, 0x60) + FIELD(REG_CTRL, SLVERR_ENABLE, 0, 1) +REG32(IR_STATUS, 0x64) + FIELD(IR_STATUS, HOST_SYS_ERR, 1, 1) + FIELD(IR_STATUS, ADDR_DEC_ERR, 0, 1) +REG32(IR_MASK, 0x68) + FIELD(IR_MASK, HOST_SYS_ERR, 1, 1) + FIELD(IR_MASK, ADDR_DEC_ERR, 0, 1) +REG32(IR_ENABLE, 0x6c) + FIELD(IR_ENABLE, HOST_SYS_ERR, 1, 1) + FIELD(IR_ENABLE, ADDR_DEC_ERR, 0, 1) +REG32(IR_DISABLE, 0x70) + FIELD(IR_DISABLE, HOST_SYS_ERR, 1, 1) + FIELD(IR_DISABLE, ADDR_DEC_ERR, 0, 1) +REG32(USB3, 0x78) + +static void ir_update_irq (XlnxUsb2Regs *s) +{ +bool pending = s->regs[R_IR_STATUS ] & ~s->regs[R_IR_MASK ]; +qemu_set_irq (s->irq_ir, pending); +} + +static void ir_status_postw (RegisterInfo *reg,uint64_t val64) +{ +XlnxUsb2Regs *s =XILINX_USB2_REGS (reg->opaque); +/* +* TODO: This should also clear USBSTS.HSE field in USB XHCI register. +* May be combine both the modules. +*/ +ir_update_irq (s); +} + +static uint64_t ir_enable_prew (RegisterInfo *reg,uint64_t val64) +{ +XlnxUsb2Regs *s =XILINX_USB2_REGS (reg->opaque); +uint32_t val = val64; + + s->regs[R_IR_MASK ] &= ~val; +ir_update_irq (s); +return 0 ; +} + +static uint64_t ir_disable_prew (RegisterInfo *reg,uint64_t val64) +{ +XlnxUsb2Regs *s =XILINX_USB2_REGS (reg->opaque); +uint32_t val = val64; + + s->regs[R_IR_MASK ] |= val; +ir_update_irq (s); +return 0 ; +} + +static const RegisterAccessInfo usb2_regs_regs_info[] = { + { .name ="BUS_FILTER" , .addr =A_BUS_FILTER , + .rsvd =0xfffffff0 , + },{ .name ="PORT" , .addr =A_PORT , + .rsvd =0xffffffe0 , + },{ .name ="JITTER_ADJUST" , .addr =A_JITTER_ADJUST , + .reset =0x20 , + .rsvd =0xffffffc0 , + },{ .name ="BIGENDIAN" , .addr =A_BIGENDIAN , + .rsvd =0xfffffffe , + },{ .name ="COHERENCY" , .addr =A_COHERENCY , + .rsvd =0xfffffffe , + },{ .name ="XHC_BME" , .addr =A_XHC_BME , + .reset =0x1 , + .rsvd =0xfffffffe , + },{ .name ="REG_CTRL" , .addr =A_REG_CTRL , + .rsvd =0xfffffffe , + },{ .name ="IR_STATUS" , .addr =A_IR_STATUS , + .rsvd =0xfffffffc , + .w1c =0x3 , + .post_write = ir_status_postw, + },{ .name ="IR_MASK" , .addr =A_IR_MASK , + .reset =0x3 , + .rsvd =0xfffffffc , + .ro =0x3 , + },{ .name ="IR_ENABLE" , .addr =A_IR_ENABLE , + .rsvd =0xfffffffc , + .pre_write = ir_enable_prew, + },{ .name ="IR_DISABLE" , .addr =A_IR_DISABLE , + .rsvd =0xfffffffc , + .pre_write = ir_disable_prew, + },{ .name ="USB3" , .addr =A_USB3 , + } +}; + +static void usb2_regs_reset (DeviceState *dev) +{ +XlnxUsb2Regs *s =XILINX_USB2_REGS (dev); +unsigned int i; + +for (i =0 ; i <ARRAY_SIZE (s->regs_info); ++i) { +register_reset (&s->regs_info[i]); + } + +ir_update_irq (s); +} + +static const MemoryRegionOps usb2_regs_ops = { + .read = register_read_memory, + .write = register_write_memory, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 , + }, +}; + +static void usb2_regs_init (Object *obj) +{ +XlnxUsb2Regs *s =XILINX_USB2_REGS (obj); +SysBusDevice *sbd =SYS_BUS_DEVICE (obj); +RegisterInfoArray *reg_array; + +memory_region_init (&s->iomem, obj,TYPE_XILINX_USB2_REGS , +USB2_REGS_R_MAX *4 ); + reg_array = +register_init_block32 (DEVICE (obj), usb2_regs_regs_info, +ARRAY_SIZE (usb2_regs_regs_info), + s->regs_info, s->regs, + &usb2_regs_ops, +XILINX_USB2_REGS_ERR_DEBUG , +USB2_REGS_R_MAX *4 ); +memory_region_add_subregion (&s->iomem, +0x0 , + ®_array->mem); +sysbus_init_mmio (sbd, &s->iomem); +sysbus_init_irq (sbd, &s->irq_ir); +} + +static const VMStateDescription vmstate_usb2_regs = { + .name =TYPE_XILINX_USB2_REGS , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32_ARRAY (regs, XlnxUsb2Regs,USB2_REGS_R_MAX ), +VMSTATE_END_OF_LIST (), + } +}; + +static void usb2_regs_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->reset = usb2_regs_reset; + dc->vmsd = &vmstate_usb2_regs; +} + +static const TypeInfo usb2_regs_info = { + .name =TYPE_XILINX_USB2_REGS , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (XlnxUsb2Regs), + .class_init = usb2_regs_class_init, + .instance_init = usb2_regs_init, +}; + +static void usb2_regs_register_types (void ) +{ +type_register_static (&usb2_regs_info); +} + +type_init (usb2_regs_register_types)include/hw/misc/xlnx-versal-usb2-regs.h new file +0
-0
include/hw/misc/xlnx-versal-usb2-regs.h line 6
Quoted 6 lines
include/hw/misc/xlnx-versal-usb2-regs.h new file +6
-0@@ -0,0 +1,43 @@ +/* +* QEMU model of the XlnxUsb2Regs Register control block/Status for USB2.0 IP +* +* Copyright (c) 2020 Xilinx Inc. +* +* Autogenerated by xregqemu.py 2020-04-08.
We should remove this part...
Quoted 40 lines
include/hw/misc/xlnx-versal-usb2-regs.h new file +37
-0+* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#ifndef _XLNX_USB2_REGS_H_ +#define _XLNX_USB2_REGS_H_ + +#define USB2_REGS_R_MAX ((0x78 / 4) + 1) + +typedef struct XlnxUsb2Regs { +SysBusDevice parent_obj; +MemoryRegion iomem; +qemu_irq irq_ir; + +uint32_t regs[USB2_REGS_R_MAX ]; +RegisterInfo regs_info[USB2_REGS_R_MAX ]; +}XlnxUsb2Regs ; + +#endif + +Signature · 1 line
2.7.4
PATCH v5 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 v5 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 virt-versal. Configure it as dual port host controller.
--- hw/arm/xlnx-versal-virt.c | 59 ++++++++++++++++++++++++++++++++++++++++++++ hw/arm/xlnx-versal.c | 38 ++++++++++++++++++++++++++++ include/hw/arm/xlnx-versal.h | 14 +++++++++++ 3 files changed, 111 insertions(+)
hw/arm/xlnx-versal-virt.c +59 -0
@@ -39,6 +39,8 @@ typedef 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,60 @@ 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 *usb2name =g_strdup_printf ("/usb@ff9d0000" ); +const char dwcCompat[] ="xlnx,versal-dwc3" ; +qemu_fdt_add_subnode (s->fdt, usb2name); +qemu_fdt_setprop (s->fdt, usb2name,"compatible" , + dwcCompat,sizeof (dwcCompat)); +qemu_fdt_setprop_sized_cells (s->fdt, usb2name,"reg" , +2 ,MM_USB2_REGS ,2 ,0x100 ); +qemu_fdt_setprop (s->fdt, usb2name,"clock-names" , + clocknames,sizeof (clocknames)); +qemu_fdt_setprop_cells (s->fdt, usb2name,"clocks" , + s->phandle.clk_25Mhz, s->phandle.clk_125Mhz); +qemu_fdt_setprop (s->fdt, usb2name,"ranges" ,NULL ,0 ); +qemu_fdt_setprop_cell (s->fdt, usb2name,"#address-cells" ,2 ); +qemu_fdt_setprop_cell (s->fdt, usb2name,"#size-cells" ,2 ); +qemu_fdt_setprop_cell (s->fdt, usb2name,"phandle" , s->phandle.usb); +g_free (usb2name); + + { +uint64_t addr =MM_USB_XHCI_0 ; +unsigned int irq =VERSAL_USB0_IRQ_0 ; +const char compat[] ="snps,dwc3" ; +const char intName[] ="dwc_usb3" ; +uint32_t frameLen =0x20 ; + +char *name =g_strdup_printf ("/usb@ff9d0000/dwc3@%" PRIx64, addr); +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 , addr,2 ,MM_USB_XHCI_SIZE_0 ); +qemu_fdt_setprop (s->fdt, name,"interrupt-names" , + intName,sizeof (intName)); +qemu_fdt_setprop_cells (s->fdt, name,"interrupts" , +GIC_FDT_IRQ_TYPE_SPI , irq, +GIC_FDT_IRQ_FLAGS_LEVEL_HI ); +qemu_fdt_setprop_cell (s->fdt, name, +"snps,quirk-frame-length-adjustment" , + frameLen); +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 (s->fdt, name,"snps,usb3_lpm_capable" ,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 +573,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 +38 -0
@@ -145,6 +145,43 @@ static void versal_create_uarts(Versal *s, qemu_irq *pic) } } +static void versal_create_usbs (Versal *s,qemu_irq *pic) +{ +char *name =g_strdup_printf ("dwc3-0" ); +DeviceState *dev, *xhci_dev; +MemoryRegion *mr; + +object_initialize_child (OBJECT (s), name, &s->fpd.iou.dwc3, +TYPE_USB_DWC3 ); + dev =DEVICE (&s->fpd.iou.dwc3); + xhci_dev =DEVICE (&s->fpd.iou.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 +0xC100 , 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 ]); +g_free (name); + + name =g_strdup_printf ("usb2reg-0" ); +object_initialize_child (OBJECT (s), name, &s->fpd.iou.Usb2Regs, +"xlnx.usb2_regs" ); + dev =DEVICE (&s->fpd.iou.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_REGS , mr); +g_free (name); +} +static void versal_create_gems (Versal *s,qemu_irq *pic) {int i;
@@ -332,6 +369,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
@@ -20,6 +20,8 @@#include "hw/dma/xlnx-zdma.h" #include "hw/net/cadence_gem.h" #include "hw/rtc/xlnx-zynqmp-rtc.h" +#include "hw/usb/hcd-dwc3.h" +#include "hw/misc/xlnx-versal-usb2-regs.h" #define TYPE_XLNX_VERSAL "xlnx-versal"#define XLNX_VERSAL (obj) OBJECT_CHECK(Versal, (obj), TYPE_XLNX_VERSAL)
@@ -42,6 +44,11 @@ typedef struct Versal {ARMCPU cpu[XLNX_VERSAL_NR_ACPUS ];GICv3State gic; } apu; + +struct { +USBDWC3 dwc3; +XlnxUsb2Regs Usb2Regs; + } iou; } fpd;MemoryRegion mr_ps;
@@ -87,6 +94,7 @@ typedef 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
@@ -124,6 +132,12 @@ typedef struct Versal {#define MM_OCM 0xfffc0000U#define MM_OCM_SIZE 0x40000 +#define MM_USB2_REGS 0xFF9D0000 +#define MM_USB2_SIZE 0x10000 + +#define MM_USB_XHCI_0 0xFE200000 +#define MM_USB_XHCI_SIZE_0 0x10000 +#define MM_TOP_DDR 0x0#define MM_TOP_DDR_SIZE 0x80000000U#define MM_TOP_DDR_2 0x800000000ULL
Signature · 1 line
2.7.4
Re: [PATCH v5 7/7] Versal: Connect DWC3 controller with virt-versal
Quoted 36 lines · Sai Pavan Boddu
From: Vikram Garhwal <[email protected]>
Connect dwc3 controller and usb2-reg module to virt-versal. Configure it as dual port host controller.
Signed-off-by Vikram Garhwal <[email protected]>Signed-off-by Sai Pavan Boddu <[email protected]>--- hw/arm/xlnx-versal-virt.c | 59 ++++++++++++++++++++++++++++++++++++++++++++ hw/arm/xlnx-versal.c | 38 ++++++++++++++++++++++++++++ include/hw/arm/xlnx-versal.h | 14 +++++++++++ 3 files changed, 111 insertions(+)hw/arm/xlnx-versal-virt.c +4
-0@@ -39,6 +39,8 @@ typedef 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" );
hw/arm/xlnx-versal-virt.c static void fdt_add_timer_nodes(VersalVirt *s) · line 158
Quoted 7 lines
hw/arm/xlnx-versal-virt.c +4
-0@@ -148,6 +152,60 @@ 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 *usb2name =g_strdup_printf ("/usb@ff9d0000" );
This string should be generated using the MM_USB2_REGS macro.
hw/arm/xlnx-versal-virt.c static void fdt_add_timer_nodes(VersalVirt *s) · line 159
Quoted 1 line
hw/arm/xlnx-versal-virt.c +1
-0+const char dwcCompat[] ="xlnx,versal-dwc3" ;
You can use compat[] as we do in other places here.
hw/arm/xlnx-versal-virt.c static void fdt_add_timer_nodes(VersalVirt *s) · line 164
Quoted 5 lines
hw/arm/xlnx-versal-virt.c +5
-0+qemu_fdt_add_subnode (s->fdt, usb2name); +qemu_fdt_setprop (s->fdt, usb2name,"compatible" , + dwcCompat,sizeof (dwcCompat)); +qemu_fdt_setprop_sized_cells (s->fdt, usb2name,"reg" , +2 ,MM_USB2_REGS ,2 ,0x100 );
0x100 as size looks small, you've added a macro for it, why not use it?
hw/arm/xlnx-versal-virt.c static void fdt_add_timer_nodes(VersalVirt *s) · line 177
Quoted 13 lines
hw/arm/xlnx-versal-virt.c +13
-0+qemu_fdt_setprop (s->fdt, usb2name,"clock-names" , + clocknames,sizeof (clocknames)); +qemu_fdt_setprop_cells (s->fdt, usb2name,"clocks" , + s->phandle.clk_25Mhz, s->phandle.clk_125Mhz); +qemu_fdt_setprop (s->fdt, usb2name,"ranges" ,NULL ,0 ); +qemu_fdt_setprop_cell (s->fdt, usb2name,"#address-cells" ,2 ); +qemu_fdt_setprop_cell (s->fdt, usb2name,"#size-cells" ,2 ); +qemu_fdt_setprop_cell (s->fdt, usb2name,"phandle" , s->phandle.usb); +g_free (usb2name); + + { +uint64_t addr =MM_USB_XHCI_0 ; +unsigned int irq =VERSAL_USB0_IRQ_0 ;
You're only using irq once? why not just use VERSAL_USB0_IRQ_0 directly?
hw/arm/xlnx-versal-virt.c static void fdt_add_timer_nodes(VersalVirt *s) · line 179
Quoted 2 lines
hw/arm/xlnx-versal-virt.c +2
-0+const char compat[] ="snps,dwc3" ; +const char intName[] ="dwc_usb3" ;
I'd prefer interrupt_names[] or irq_names[].
hw/arm/xlnx-versal-virt.c static void fdt_add_timer_nodes(VersalVirt *s) · line 180
Quoted 1 line
hw/arm/xlnx-versal-virt.c +1
-0+uint32_t frameLen =0x20 ;
Can't you just directly use 0x20 when setting the prop?
hw/arm/xlnx-versal-virt.c static void fdt_add_timer_nodes(VersalVirt *s) · line 182
Quoted 2 lines
hw/arm/xlnx-versal-virt.c +2
-0+ +char *name =g_strdup_printf ("/usb@ff9d0000/dwc3@%" PRIx64, addr);
We shouldn't hard-code ff9d0000 here.
It also looks weird/wrong to have dwc3 as a subnode of usb like that.
Quoted 42 lines
hw/arm/xlnx-versal-virt.c +27
-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 , addr,2 ,MM_USB_XHCI_SIZE_0 ); +qemu_fdt_setprop (s->fdt, name,"interrupt-names" , + intName,sizeof (intName)); +qemu_fdt_setprop_cells (s->fdt, name,"interrupts" , +GIC_FDT_IRQ_TYPE_SPI , irq, +GIC_FDT_IRQ_FLAGS_LEVEL_HI ); +qemu_fdt_setprop_cell (s->fdt, name, +"snps,quirk-frame-length-adjustment" , + frameLen); +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 (s->fdt, name,"snps,usb3_lpm_capable" ,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 +573,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 +0
-0
hw/arm/xlnx-versal.c static void versal_create_uarts(Versal *s, qemu_irq *pic) · line 150
Quoted 6 lines
hw/arm/xlnx-versal.c +3
-0@@ -145,6 +145,43 @@ static void versal_create_uarts(Versal *s, qemu_irq *pic) } } +static void versal_create_usbs (Versal *s,qemu_irq *pic) +{ +char *name =g_strdup_printf ("dwc3-0" );
There's no need to allocate and format a constant string...
Quoted 14 lines
hw/arm/xlnx-versal.c +14
-0+DeviceState *dev, *xhci_dev; +MemoryRegion *mr; + +object_initialize_child (OBJECT (s), name, &s->fpd.iou.dwc3, +TYPE_USB_DWC3 ); + dev =DEVICE (&s->fpd.iou.dwc3); + xhci_dev =DEVICE (&s->fpd.iou.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);
hw/arm/xlnx-versal.c static void versal_create_uarts(Versal *s, qemu_irq *pic) · line 174
Quoted 10 lines
hw/arm/xlnx-versal.c +10
-0+ + mr =sysbus_mmio_get_region (SYS_BUS_DEVICE (dev),0 ); +memory_region_add_subregion (&s->mr_ps,MM_USB_XHCI_0 +0xC100 , 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 ]); +g_free (name); + + name =g_strdup_printf ("usb2reg-0" );
This one too.
Quoted 70 lines
hw/arm/xlnx-versal.c +11
-0+object_initialize_child (OBJECT (s), name, &s->fpd.iou.Usb2Regs, +"xlnx.usb2_regs" ); + dev =DEVICE (&s->fpd.iou.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_REGS , mr); +g_free (name); +} +static void versal_create_gems (Versal *s,qemu_irq *pic) {int i;@@ -332,6 +369,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@@ -20,6 +20,8 @@#include "hw/dma/xlnx-zdma.h" #include "hw/net/cadence_gem.h" #include "hw/rtc/xlnx-zynqmp-rtc.h" +#include "hw/usb/hcd-dwc3.h" +#include "hw/misc/xlnx-versal-usb2-regs.h" #define TYPE_XLNX_VERSAL "xlnx-versal"#define XLNX_VERSAL (obj) OBJECT_CHECK(Versal, (obj), TYPE_XLNX_VERSAL)@@ -42,6 +44,11 @@ typedef struct Versal {ARMCPU cpu[XLNX_VERSAL_NR_ACPUS ];GICv3State gic; } apu; + +struct { +USBDWC3 dwc3; +XlnxUsb2Regs Usb2Regs; + } iou; } fpd;MemoryRegion mr_ps;@@ -87,6 +94,7 @@ typedef 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@@ -124,6 +132,12 @@ typedef struct Versal {#define MM_OCM 0xfffc0000U#define MM_OCM_SIZE 0x40000 +#define MM_USB2_REGS 0xFF9D0000 +#define MM_USB2_SIZE 0x10000 + +#define MM_USB_XHCI_0 0xFE200000 +#define MM_USB_XHCI_SIZE_0 0x10000 +#define MM_TOP_DDR 0x0#define MM_TOP_DDR_SIZE 0x80000000U#define MM_TOP_DDR_2 0x800000000ULLSignature · 1 line
2.7.4
RE: [PATCH v5 7/7] Versal: Connect DWC3 controller with virt-versal
Hi Edgar,
Thanks, I would try to clean this up as per your comments.
Regards,
Sai Pavan
Quoted 263 lines
-----Original Message-----
From: Edgar E. Iglesias <[email protected]>
Sent: Friday, September 11, 2020 1:33 PM
To: Sai Pavan Boddu <[email protected]>
Cc: Peter Maydell <[email protected]>; 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]>; [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 v5 7/7] Versal: Connect DWC3 controller with virt-versalQuoted 9 lines · Sai Pavan Boddu
From: Vikram Garhwal <[email protected]>
Connect dwc3 controller and usb2-reg module to virt-versal. Configure it as dual port host controller.
Signed-off-by Vikram Garhwal <[email protected]>Signed-off-by Sai Pavan Boddu <[email protected]>--- hw/arm/xlnx-versal-virt.c | 59++++++++++++++++++++++++++++++++++++++++++++
Quoted 27 lines
hw/arm/xlnx-versal.c | 38 ++++++++++++++++++++++++++++ include/hw/arm/xlnx-versal.h | 14 +++++++++++ 3 files changed, 111 insertions(+)hw/arm/xlnx-versal-virt.c +4
-0@@ -39,6 +39,8 @@ typedef 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" );hw/arm/xlnx-versal-virt.c static void fdt_add_timer_nodes(VersalVirt *s) · line 156
Quoted 5 lines
hw/arm/xlnx-versal-virt.c +3
-0@@ -148,6 +152,60 @@ 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 *usb2name =g_strdup_printf ("/usb@ff9d0000" );This string should be generated using the
MM_USB2_REGSmacro.hw/arm/xlnx-versal-virt.c static void fdt_add_timer_nodes(VersalVirt *s) · line 159
Quoted 1 line
hw/arm/xlnx-versal-virt.c +1
-0+const char dwcCompat[] ="xlnx,versal-dwc3" ;You can use compat[] as we do in other places here.
hw/arm/xlnx-versal-virt.c static void fdt_add_timer_nodes(VersalVirt *s) · line 164
Quoted 5 lines
hw/arm/xlnx-versal-virt.c +5
-0+qemu_fdt_add_subnode (s->fdt, usb2name); +qemu_fdt_setprop (s->fdt, usb2name,"compatible" , + dwcCompat,sizeof (dwcCompat)); +qemu_fdt_setprop_sized_cells (s->fdt, usb2name,"reg" , +2 ,MM_USB2_REGS ,2 ,0x100 );
0x100as size looks small, you've added a macro for it, why not use it?hw/arm/xlnx-versal-virt.c static void fdt_add_timer_nodes(VersalVirt *s) · line 177
Quoted 13 lines
hw/arm/xlnx-versal-virt.c +13
-0+qemu_fdt_setprop (s->fdt, usb2name,"clock-names" , + clocknames,sizeof (clocknames)); +qemu_fdt_setprop_cells (s->fdt, usb2name,"clocks" , + s->phandle.clk_25Mhz, s->phandle.clk_125Mhz); +qemu_fdt_setprop (s->fdt, usb2name,"ranges" ,NULL ,0 ); +qemu_fdt_setprop_cell (s->fdt, usb2name,"#address-cells" ,2 ); +qemu_fdt_setprop_cell (s->fdt, usb2name,"#size-cells" ,2 ); +qemu_fdt_setprop_cell (s->fdt, usb2name,"phandle" , s->phandle.usb); +g_free (usb2name); + + { +uint64_t addr =MM_USB_XHCI_0 ; +unsigned int irq =VERSAL_USB0_IRQ_0 ;You're only using irq once? why not just use
VERSAL_USB0_IRQ_0directly?hw/arm/xlnx-versal-virt.c static void fdt_add_timer_nodes(VersalVirt *s) · line 179
Quoted 2 lines
hw/arm/xlnx-versal-virt.c +2
-0+const char compat[] ="snps,dwc3" ; +const char intName[] ="dwc_usb3" ;I'd prefer interrupt_names[] or irq_names[].
hw/arm/xlnx-versal-virt.c static void fdt_add_timer_nodes(VersalVirt *s) · line 180
Quoted 1 line
hw/arm/xlnx-versal-virt.c +1
-0+uint32_t frameLen =0x20 ;Can't you just directly use
0x20when setting the prop?hw/arm/xlnx-versal-virt.c static void fdt_add_timer_nodes(VersalVirt *s) · line 181
Quoted 3 lines
hw/arm/xlnx-versal-virt.c +3
-0+ +char *name =g_strdup_printf ("/usb@ff9d0000/dwc3@%" PRIx64, + addr);We shouldn't hard-code
ff9d0000here.
It also looks weird/wrong to have dwc3 as a subnode of usb like that.Quoted 7 lines
hw/arm/xlnx-versal-virt.c +7
-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 , addr,2 ,MM_USB_XHCI_SIZE_0 ); +qemu_fdt_setprop (s->fdt, name,"interrupt-names" , + intName,sizeof (intName));hw/arm/xlnx-versal-virt.c static void fdt_add_timer_nodes(VersalVirt *s)
Quoted 10 lines
hw/arm/xlnx-versal-virt.c +10
-0+qemu_fdt_setprop_cells (s->fdt, name,"interrupts" , +GIC_FDT_IRQ_TYPE_SPI , irq, +GIC_FDT_IRQ_FLAGS_LEVEL_HI ); +qemu_fdt_setprop_cell (s->fdt, name, +"snps,quirk-frame-length-adjustment" , + frameLen); +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);
hw/arm/xlnx-versal-virt.c static void fdt_add_timer_nodes(VersalVirt *s) · line 199
Quoted 1 line
hw/arm/xlnx-versal-virt.c +1
-0+ qemu_fdt_setprop(s->fdt, name, "snps,dis_u3_susphy_quirk", NULL,0);
hw/arm/xlnx-versal-virt.c static void fdt_add_timer_nodes(VersalVirt *s)
Quoted 5 lines
hw/arm/xlnx-versal-virt.c +5
-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 (s->fdt, name,"snps,usb3_lpm_capable" ,NULL ,0 ); +qemu_fdt_setprop_cell (s->fdt, name,"phandle" , s->phandle.dwc); + qemu_fdt_setprop_string(s->fdt, name, "maximum-speed", "high-speed");
hw/arm/xlnx-versal.c static void versal_create_uarts(Versal *s,
Quoted 18 lines
hw/arm/xlnx-versal-virt.c +3
-0+g_free (name); + } +}static void fdt_add_uart_nodes (VersalVirt *s) { uint64_t addrs[] = { MM_UART1, MM_UART0 }; @@ -515,6 +573,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); diff --git
a/hw/arm/xlnx-versal.cb/hw/arm/xlnx-versal.cindex e3aa4bd..9b241de 100644hw/arm/xlnx-versal.c +0
-0@@ -145,6 +145,43 @@ static void versal_create_uarts(Versal *s,
qemu_irq*pic)hw/arm/xlnx-versal.c static void versal_create_uarts(Versal *s, qemu_irq *pic) · line 150
Quoted 5 lines
hw/arm/xlnx-versal.c +2
-0} } +static void versal_create_usbs (Versal *s,qemu_irq *pic) { +char *name =g_strdup_printf ("dwc3-0" );There's no need to allocate and format a constant string...
Quoted 8 lines
hw/arm/xlnx-versal.c +8
-0+DeviceState *dev, *xhci_dev; +MemoryRegion *mr; + +object_initialize_child (OBJECT (s), name, &s->fpd.iou.dwc3, +TYPE_USB_DWC3 ); + dev =DEVICE (&s->fpd.iou.dwc3); + xhci_dev =DEVICE (&s->fpd.iou.dwc3.sysbus_xhci); +hw/arm/xlnx-versal.c static void versal_create_uarts(Versal *s, qemu_irq *pic)
Quoted 10 lines
hw/arm/xlnx-versal.c +9
-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 +
0xC100, mr);hw/arm/xlnx-versal.c static void versal_create_uarts(Versal *s, qemu_irq *pic)
Quoted 4 lines
hw/arm/xlnx-versal.c +4
-0+ 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]);
hw/arm/xlnx-versal.c static void versal_create_uarts(Versal *s, qemu_irq *pic) · line 174
Quoted 3 lines
hw/arm/xlnx-versal.c +3
-0+g_free (name); + + name =g_strdup_printf ("usb2reg-0" );This one too.
hw/arm/xlnx-versal.c static void versal_realize(DeviceState *dev, Error
Quoted 13 lines
hw/arm/xlnx-versal.c +10
-0+object_initialize_child (OBJECT (s), name, &s->fpd.iou.Usb2Regs, +"xlnx.usb2_regs" ); + dev =DEVICE (&s->fpd.iou.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_REGS , mr); +g_free (name); +} +static void versal_create_gems (Versal *s,qemu_irq *pic) {int i;@@ -332,6 +369,7 @@ static void versal_realize(DeviceState *dev, Error**errp)
Quoted 56 lines
hw/arm/xlnx-versal.c +1
-0versal_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);(quoted diff) +0
-0
b/include/hw/arm/xlnx-versal.hindex 9c9f47b..e19cfd5 100644include/hw/arm/xlnx-versal.h +2
-0@@ -20,6 +20,8 @@#include "hw/dma/xlnx-zdma.h" #include "hw/net/cadence_gem.h" #include "hw/rtc/xlnx-zynqmp-rtc.h" +#include "hw/usb/hcd-dwc3.h" +#include "hw/misc/xlnx-versal-usb2-regs.h" #define TYPE_XLNX_VERSAL "xlnx-versal"#define XLNX_VERSAL (obj) OBJECT_CHECK(Versal, (obj),TYPE_XLNX_VERSAL) @@ -42,6 +44,11 @@ typedef struct Versal { ARMCPU cpu[XLNX_VERSAL_NR_ACPUS]; GICv3State gic; } apu;include/hw/arm/xlnx-versal.h +12
-1+ +struct { +USBDWC3 dwc3; +XlnxUsb2Regs Usb2Regs; + } iou; } fpd;MemoryRegion mr_ps;@@ -87,6 +94,7 @@ typedef 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@@ -124,6 +132,12 @@ typedef struct Versal {#define MM_OCM 0xfffc0000U#define MM_OCM_SIZE 0x40000 +#define MM_USB2_REGS 0xFF9D0000 +#define MM_USB2_SIZE 0x10000 + +#define MM_USB_XHCI_0 0xFE200000 +#define MM_USB_XHCI_SIZE_0 0x10000 +#define MM_TOP_DDR 0x0#define MM_TOP_DDR_SIZE 0x80000000U#define MM_TOP_DDR_2 0x800000000ULL --2.7.4
Quoted 2 lines · 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.
Fails to apply again.
I guess this time the typedef / qom changes (I've just rebased my microvm series because of that ...).
take care,
Gerd
Hi Gerd,
Sending out V6, with few fixes and rebased over latest master.
Thanks,
Sai Pavan
Quoted 26 lines
-----Original Message-----
From: Gerd Hoffmann <[email protected]>
Sent: Tuesday, September 15, 2020 6:44 PM
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]>
Subject: Re: [PATCH v5 0/7] Make hcd-xhci independent of pci hooksQuoted 2 lines · 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.
Fails to apply again.
I guess this time the typedef / qom changes (I've just rebased my microvm series because of that ...).
take care,
Gerd