Skip to contentSkip to conversation

Make hcd-xhci independent of pci hooks

PATCH Superseded Sai Pavan Boddu 5 participants 29 messages Aug 28, 2020 – Sep 10, 2020

v4 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v4 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

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/Makefile.objs                   |   1 +
 hw/misc/xlnx-versal-usb2-regs.c         | 224 ++++++++++++
 hw/usb/Kconfig                          |  11 +
 hw/usb/Makefile.objs                    |   3 +
 hw/usb/hcd-dwc3.c                       | 606 ++++++++++++++++++++++++++++++++
 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 +-
 include/hw/arm/xlnx-versal.h            |  14 +
 include/hw/misc/xlnx-versal-usb2-regs.h |  43 +++
 include/hw/usb/hcd-dwc3.h               |  58 +++
 17 files changed, 1552 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
#1 lore raw

PATCH v4 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 |  3 +++
 2 files changed, 14 insertions(+), 13 deletions(-)
hw/usb/hcd-xhci.c +11 -13
index 67a18fe..2590f7a 100644
@@ -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;
@@ -2101,7 +2098,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);
 
@@ -2439,7 +2436,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;
 }
@@ -3431,6 +3428,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);
@@ -3531,7 +3529,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 +3 -0
index 946af51..edbd926 100644
@@ -22,6 +22,8 @@
 #ifndef HW_USB_HCD_XHCI_H
 #define HW_USB_HCD_XHCI_H
 
+#include "sysemu/dma.h"
+
 #define TYPE_XHCI "base-xhci"
 #define TYPE_NEC_XHCI "nec-usb-xhci"
 #define TYPE_QEMU_XHCI "qemu-xhci"
@@ -189,6 +191,7 @@ struct XHCIState {
 
     USBBus bus;
     MemoryRegion mem;
+    AddressSpace *as;
     MemoryRegion mem_cap;
     MemoryRegion mem_oper;
     MemoryRegion mem_runtime;
Signature · 1 line
2.7.4
Reviewed-by on v4 1/7
#2 lore raw

Re: [PATCH v4 1/7] usb/hcd-xhci: Make dma read/writes hooks pci free

Quoted 137 lines · Sai Pavan Boddu

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 |  3 +++
 2 files changed, 14 insertions(+), 13 deletions(-)
hw/usb/hcd-xhci.c +11 -13
index 67a18fe..2590f7a 100644
@@ -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;
@@ -2101,7 +2098,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);
 
@@ -2439,7 +2436,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;
 }
@@ -3431,6 +3428,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);
@@ -3531,7 +3529,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 +0 -0
index 946af51..edbd926 100644

hw/usb/hcd-xhci.h line 25

Quoted 4 lines
hw/usb/hcd-xhci.h +1 -0
@@ -22,6 +22,8 @@
 #ifndef HW_USB_HCD_XHCI_H
 #define HW_USB_HCD_XHCI_H
 
+#include "sysemu/dma.h"

AddressSpace is forward-declared in "qemu/typedefs.h", so no need to include it here (yes in the sources including hcd-xhci.h).

With that fixed:

Quoted 13 lines
hw/usb/hcd-xhci.h +2 -0
+
 #define TYPE_XHCI "base-xhci"
 #define TYPE_NEC_XHCI "nec-usb-xhci"
 #define TYPE_QEMU_XHCI "qemu-xhci"
@@ -189,6 +191,7 @@ struct XHCIState {
 
     USBBus bus;
     MemoryRegion mem;
+    AddressSpace *as;
     MemoryRegion mem_cap;
     MemoryRegion mem_oper;
     MemoryRegion mem_runtime;
#3 lore raw

RE: [PATCH v4 1/7] usb/hcd-xhci: Make dma read/writes hooks pci free

Hi Philippe,

Quoted 165 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: Tuesday, September 1, 2020 10:05 PM
To: Sai Pavan Boddu <[email protected]>; 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]>
Cc: [email protected]; Alistair Francis <[email protected]>; Eduardo Habkost <[email protected]>; Ying Fang <[email protected]>; Vikram Garhwal <[email protected]>; Paul Zimmerman <[email protected]>
Subject: Re: [PATCH v4 1/7] usb/hcd-xhci: Make dma read/writes hooks pci free

hw/usb/hcd-xhci.c static void xhci_write_event(XHCIState *xhci,

Quoted 41 lines · Sai Pavan Boddu

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 |
3 +++

 2 files changed, 14 insertions(+), 13 deletions(-)
hw/usb/hcd-xhci.c index renamed from hw/usb/hcd-xhci.c +0 -0

67a18fe..2590f7a 100644

hw/usb/hcd-xhci.c +1 -1
@@ -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]);
     }
hw/usb/hcd-xhci.c +1 -1
-    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) {

hw/usb/hcd-xhci.c +0 -1
-    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)

hw/usb/hcd-xhci.c static int xhci_xfer_create_sgl(XHCITransfer

Quoted 48 lines
hw/usb/hcd-xhci.c +1 -1
                                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)  {
hw/usb/hcd-xhci.c +1 -2
-    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;
hw/usb/hcd-xhci.c +2 -2
-        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)

hw/usb/hcd-xhci.c static TRBCCode xhci_address_slot(XHCIState

Quoted 10 lines
hw/usb/hcd-xhci.c +2 -1
     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;
@@ -2101,7 +2098,7 @@ static TRBCCode xhci_address_slot(XHCIState

*xhci, unsigned int slotid,

hw/usb/hcd-xhci.c static TRBCCode

Quoted 9 lines
hw/usb/hcd-xhci.c +1 -1
     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);
 
@@ -2439,7 +2436,7 @@ static TRBCCode

xhci_get_port_bandwidth(XHCIState *xhci, uint64_t pctx)

hw/usb/hcd-xhci.c static void usb_xhci_realize(struct PCIDevice

Quoted 9 lines
hw/usb/hcd-xhci.c +1 -1
     /* 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;
 }
@@ -3431,6 +3428,7 @@ static void usb_xhci_realize(struct PCIDevice

*dev, Error **errp)

hw/usb/hcd-xhci.c static int usb_xhci_post_load(void *opaque, int

Quoted 9 lines
hw/usb/hcd-xhci.c +1 -0
     }
 
     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);
hw/usb/hcd-xhci.c +0 -0
@@ -3531,7 +3529,7 @@ static int usb_xhci_post_load(void *opaque, int

version_id)

Quoted 16 lines
hw/usb/hcd-xhci.c +1 -1
             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 index renamed from hw/usb/hcd-xhci.h +0 -0

946af51..edbd926 100644

hw/usb/hcd-xhci.h +0 -0
@@ -22,6 +22,8 @@
 #ifndef HW_USB_HCD_XHCI_H
 #define HW_USB_HCD_XHCI_H
 
Quoted 4 lines

hw/usb/hcd-xhci.h line 25

Quoted 1 line
hw/usb/hcd-xhci.h +1 -0
+#include "sysemu/dma.h"

AddressSpace is forward-declared in "qemu/typedefs.h", so no need to include it here (yes in the sources including hcd-xhci.h).

[Sai Pavan Boddu] Yes you are right!, but without this " dma_addr_t " is undefined.
At this point of the patch, hcd-xhci.h is compiled along with pci.h which would provide 'dma_addr_t', but when we strip the pci wrapper around hcd-xhci we would miss it. Let me know, if its good to add later in the patch series when the split happens.

Regards,
Sai Pavan

Quoted 17 lines

With that fixed:

Quoted 13 lines
hw/usb/hcd-xhci.h +2 -0
+
 #define TYPE_XHCI "base-xhci"
 #define TYPE_NEC_XHCI "nec-usb-xhci"
 #define TYPE_QEMU_XHCI "qemu-xhci"
@@ -189,6 +191,7 @@ struct XHCIState {
 
     USBBus bus;
     MemoryRegion mem;
+    AddressSpace *as;
     MemoryRegion mem_cap;
     MemoryRegion mem_oper;
     MemoryRegion mem_runtime;
#4 lore raw

Re: [PATCH v4 1/7] usb/hcd-xhci: Make dma read/writes hooks pci free

Quoted 10 lines
Quoted 10 lines · Sai Pavan Boddu
Quoted 9 lines

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 |
3 +++

 2 files changed, 14 insertions(+), 13 deletions(-)

[...]

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
hw/usb/hcd-xhci.h +0 -0
@@ -22,6 +22,8 @@
 #ifndef HW_USB_HCD_XHCI_H
 #define HW_USB_HCD_XHCI_H
 
Quoted 6 lines
Quoted 4 lines

hw/usb/hcd-xhci.h line 25

Quoted 1 line
hw/usb/hcd-xhci.h +1 -0
+#include "sysemu/dma.h"

AddressSpace is forward-declared in "qemu/typedefs.h", so no need to include it here (yes in the sources including hcd-xhci.h).

[Sai Pavan Boddu] Yes you are right!, but without this " dma_addr_t " is undefined.
At this point of the patch, hcd-xhci.h is compiled along with pci.h which would provide 'dma_addr_t', but when we strip the pci wrapper around hcd-xhci we would miss it. Let me know, if its good to add later in the patch series when the split happens.

OK :( I'd prefer to only include "sysemu/dma.h" in hw/usb/hcd-xhci.c.

Cc'ing David who added dma_addr_t in commit e5332e6334f ("iommu: Introduce IOMMU emulation infrastructure"), it might be simpler to move its declaration to "qemu/typedefs.h" too.

So no change needed for this patch.

Quoted 21 lines

Regards,
Sai Pavan

Quoted 17 lines

With that fixed:

Quoted 13 lines
hw/usb/hcd-xhci.h +2 -0
+
 #define TYPE_XHCI "base-xhci"
 #define TYPE_NEC_XHCI "nec-usb-xhci"
 #define TYPE_QEMU_XHCI "qemu-xhci"
@@ -189,6 +191,7 @@ struct XHCIState {
 
     USBBus bus;
     MemoryRegion mem;
+    AddressSpace *as;
     MemoryRegion mem_cap;
     MemoryRegion mem_oper;
     MemoryRegion mem_runtime;
#5 lore raw

Re: [PATCH v4 1/7] usb/hcd-xhci: Make dma read/writes hooks pci free

Quoted 24 lines · Philippe Mathieu-Daudé
Quoted 10 lines
Quoted 10 lines · Sai Pavan Boddu
Quoted 9 lines

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 |
3 +++

 2 files changed, 14 insertions(+), 13 deletions(-)

[...]

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
hw/usb/hcd-xhci.h +0 -0
@@ -22,6 +22,8 @@
 #ifndef HW_USB_HCD_XHCI_H
 #define HW_USB_HCD_XHCI_H
 
Quoted 6 lines
Quoted 4 lines

hw/usb/hcd-xhci.h line 25

Quoted 1 line
hw/usb/hcd-xhci.h +1 -0
+#include "sysemu/dma.h"

AddressSpace is forward-declared in "qemu/typedefs.h", so no need to include it here (yes in the sources including hcd-xhci.h).

[Sai Pavan Boddu] Yes you are right!, but without this " dma_addr_t " is undefined.
At this point of the patch, hcd-xhci.h is compiled along with pci.h which would provide 'dma_addr_t', but when we strip the pci wrapper around hcd-xhci we would miss it. Let me know, if its good to add later in the patch series when the split happens.

Quoted 6 lines

OK :( I'd prefer to only include "sysemu/dma.h" in hw/usb/hcd-xhci.c.

Cc'ing David who added dma_addr_t in commit e5332e6334f ("iommu: Introduce IOMMU emulation infrastructure"), it might be simpler to move its declaration to "qemu/typedefs.h" too.

Btw this type should be poisoned for user-mode.

Quoted 25 lines

So no change needed for this patch.

Quoted 21 lines

Regards,
Sai Pavan

Quoted 17 lines

With that fixed:

Quoted 13 lines
hw/usb/hcd-xhci.h +2 -0
+
 #define TYPE_XHCI "base-xhci"
 #define TYPE_NEC_XHCI "nec-usb-xhci"
 #define TYPE_QEMU_XHCI "qemu-xhci"
@@ -189,6 +191,7 @@ struct XHCIState {
 
     USBBus bus;
     MemoryRegion mem;
+    AddressSpace *as;
     MemoryRegion mem_cap;
     MemoryRegion mem_oper;
     MemoryRegion mem_runtime;
#6 lore raw

RE: [PATCH v4 1/7] usb/hcd-xhci: Make dma read/writes hooks pci free

Hi Philippe,

Quoted 46 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: Tuesday, September 8, 2020 4:05 PM
To: Sai Pavan Boddu <[email protected]>; 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]>; David Gibson <[email protected]>
Cc: [email protected]; Alistair Francis <[email protected]>; Eduardo Habkost <[email protected]>; Ying Fang <[email protected]>; Vikram Garhwal <[email protected]>; Paul Zimmerman <[email protected]>
Subject: Re: [PATCH v4 1/7] usb/hcd-xhci: Make dma read/writes hooks pci free

Quoted 18 lines · Philippe Mathieu-Daudé
Quoted 11 lines
Quoted 11 lines · Sai Pavan Boddu
Quoted 10 lines

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
|
3 +++

 2 files changed, 14 insertions(+), 13 deletions(-)

[...]

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
hw/usb/hcd-xhci.h +0 -0
@@ -22,6 +22,8 @@
 #ifndef HW_USB_HCD_XHCI_H
 #define HW_USB_HCD_XHCI_H
 
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

hw/usb/hcd-xhci.h line 25

Quoted 1 line
hw/usb/hcd-xhci.h +1 -0
+#include "sysemu/dma.h"

AddressSpace is forward-declared in "qemu/typedefs.h", so no need to include it here (yes in the sources including hcd-xhci.h).

[Sai Pavan Boddu] Yes you are right!, but without this " dma_addr_t " is

undefined.

Quoted 1 line
Quoted 1 line

At this point of the patch, hcd-xhci.h is compiled along with pci.h which

would provide 'dma_addr_t', but when we strip the pci wrapper around hcd- xhci we would miss it. Let me know, if its good to add later in the patch series when the split happens.

Quoted 1 line
Quoted 8 lines
Quoted 6 lines

OK :( I'd prefer to only include "sysemu/dma.h" in hw/usb/hcd-xhci.c.

Cc'ing David who added dma_addr_t in commit e5332e6334f ("iommu: Introduce IOMMU emulation infrastructure"), it might be simpler to move its declaration to "qemu/typedefs.h" too.

Btw this type should be poisoned for user-mode.

[Sai Pavan Boddu] Thanks, I would try to define them in typedefs.h.
BTW I'm not clear about poisoning then in user-mode. Do you mean hide these defines for user-mode ?

Regards
Sai Pavan

Quoted 26 lines
Quoted 26 lines

So no change needed for this patch.

Quoted 21 lines

Regards,
Sai Pavan

Quoted 17 lines

With that fixed:

Quoted 13 lines
hw/usb/hcd-xhci.h +2 -0
+
 #define TYPE_XHCI "base-xhci"
 #define TYPE_NEC_XHCI "nec-usb-xhci"
 #define TYPE_QEMU_XHCI "qemu-xhci"
@@ -189,6 +191,7 @@ struct XHCIState {
 
     USBBus bus;
     MemoryRegion mem;
+    AddressSpace *as;
     MemoryRegion mem_cap;
     MemoryRegion mem_oper;
     MemoryRegion mem_runtime;
#7 lore raw

Re: [PATCH v4 1/7] usb/hcd-xhci: Make dma read/writes hooks pci free

Quoted 50 lines · Sai Pavan Boddu

Hi Philippe,

Quoted 48 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: Tuesday, September 8, 2020 4:05 PM
To: Sai Pavan Boddu <[email protected]>; 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]>; David Gibson <[email protected]>
Cc: [email protected]; Alistair Francis <[email protected]>; Eduardo Habkost <[email protected]>; Ying Fang <[email protected]>; Vikram Garhwal <[email protected]>; Paul Zimmerman <[email protected]>
Subject: Re: [PATCH v4 1/7] usb/hcd-xhci: Make dma read/writes hooks pci free

Quoted 18 lines · Philippe Mathieu-Daudé
Quoted 11 lines
Quoted 11 lines · Sai Pavan Boddu
Quoted 10 lines

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
|
3 +++

 2 files changed, 14 insertions(+), 13 deletions(-)

[...]

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
hw/usb/hcd-xhci.h +0 -0
@@ -22,6 +22,8 @@
 #ifndef HW_USB_HCD_XHCI_H
 #define HW_USB_HCD_XHCI_H
 
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

hw/usb/hcd-xhci.h line 25

Quoted 1 line
hw/usb/hcd-xhci.h +1 -0
+#include "sysemu/dma.h"

AddressSpace is forward-declared in "qemu/typedefs.h", so no need to include it here (yes in the sources including hcd-xhci.h).

[Sai Pavan Boddu] Yes you are right!, but without this " dma_addr_t " is

undefined.

Quoted 1 line
Quoted 1 line

At this point of the patch, hcd-xhci.h is compiled along with pci.h which

would provide 'dma_addr_t', but when we strip the pci wrapper around hcd- xhci we would miss it. Let me know, if its good to add later in the patch series when the split happens.

Quoted 3 lines

OK :( I'd prefer to only include "sysemu/dma.h" in hw/usb/hcd-xhci.c.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Cc'ing David who added dma_addr_t in commit e5332e6334f ("iommu: Introduce IOMMU emulation infrastructure"), it might be simpler to move its declaration to "qemu/typedefs.h" too.

Btw this type should be poisoned for user-mode.

[Sai Pavan Boddu] Thanks, I would try to define them in typedefs.h.
BTW I'm not clear about poisoning then in user-mode. Do you mean hide these defines for user-mode ?

This doesn't "hide" but poison them: if you try to use them the compiler (cpp actually) will raise an error.

This was not a direct comment for you, more something to discuss out of the scope of your series ;) No need to try to declare it poisoned now.

Quoted 30 lines

Regards
Sai Pavan

Quoted 26 lines
Quoted 26 lines

So no change needed for this patch.

Quoted 21 lines

Regards,
Sai Pavan

Quoted 17 lines

With that fixed:

Quoted 13 lines
hw/usb/hcd-xhci.h +2 -0
+
 #define TYPE_XHCI "base-xhci"
 #define TYPE_NEC_XHCI "nec-usb-xhci"
 #define TYPE_QEMU_XHCI "qemu-xhci"
@@ -189,6 +191,7 @@ struct XHCIState {
 
     USBBus bus;
     MemoryRegion mem;
+    AddressSpace *as;
     MemoryRegion mem_cap;
     MemoryRegion mem_oper;
     MemoryRegion mem_runtime;
#8 lore raw

RE: [PATCH v4 1/7] usb/hcd-xhci: Make dma read/writes hooks pci free

Hi Philippe,

Quoted 79 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: Tuesday, September 8, 2020 5:57 PM
To: Sai Pavan Boddu <[email protected]>; 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]>; David Gibson <[email protected]>
Cc: [email protected]; Alistair Francis <[email protected]>; Eduardo Habkost <[email protected]>; Ying Fang <[email protected]>; Vikram Garhwal <[email protected]>; Paul Zimmerman <[email protected]>
Subject: Re: [PATCH v4 1/7] usb/hcd-xhci: Make dma read/writes hooks pci free

Quoted 22 lines · Sai Pavan Boddu

Hi Philippe,

Quoted 20 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: Tuesday, September 8, 2020 4:05 PM
To: Sai Pavan Boddu <[email protected]>; 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]>; David Gibson <[email protected]>
Cc: [email protected]; Alistair Francis <[email protected]>; Eduardo Habkost <[email protected]>; Ying Fang <[email protected]>; Vikram Garhwal <[email protected]>; Paul Zimmerman <[email protected]>
Subject: Re: [PATCH v4 1/7] usb/hcd-xhci: Make dma read/writes hooks pci free

Quoted 3 lines · Philippe Mathieu-Daudé
Quoted 3 lines
Quoted 3 lines · Sai Pavan Boddu
Quoted 2 lines

This patch starts making the hcd-xhci.c pci free, as part of this restructuring dma read/writes are handled without passing pci

object.

Quoted 31 lines
Quoted 31 lines
Quoted 16 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
---
 hw/usb/hcd-xhci.c | 24 +++++++++++-------------
hw/usb/hcd-xhci.h
|
3 +++
 2 files changed, 14 insertions(+), 13 deletions(-)

[...]

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
hw/usb/hcd-xhci.h +0 -0
@@ -22,6 +22,8 @@
 #ifndef HW_USB_HCD_XHCI_H
 #define HW_USB_HCD_XHCI_H
 
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

hw/usb/hcd-xhci.h line 25

Quoted 1 line
hw/usb/hcd-xhci.h +1 -0
+#include "sysemu/dma.h"

AddressSpace is forward-declared in "qemu/typedefs.h", so no need to include it here (yes in the sources including hcd-xhci.h).

[Sai Pavan Boddu] Yes you are right!, but without this " dma_addr_t " is

undefined.

Quoted 2 lines
Quoted 2 lines

At this point of the patch, hcd-xhci.h is compiled along with pci.h which

would provide 'dma_addr_t', but when we strip the pci wrapper around hcd- xhci we would miss it. Let me know, if its good to add later in the patch series when the split happens.

Quoted 3 lines

OK :( I'd prefer to only include "sysemu/dma.h" in hw/usb/hcd-xhci.c.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Cc'ing David who added dma_addr_t in commit e5332e6334f ("iommu: Introduce IOMMU emulation infrastructure"), it might be simpler to move its declaration to "qemu/typedefs.h" too.

Btw this type should be poisoned for user-mode.

[Sai Pavan Boddu] Thanks, I would try to define them in typedefs.h. BTW I'm not clear about poisoning then in user-mode. Do you mean hide

Quoted 7 lines

these defines for user-mode ?

This doesn't "hide" but poison them: if you try to use them the compiler (cpp actually) will raise an error.

This was not a direct comment for you, more something to discuss out of the scope of your series ;) No need to try to declare it poisoned now.

[Sai Pavan Boddu] One more thing, which came up during implementation is dma_memory_read/ dma_memory_write functions which used in this patch would require that header.

Regards,
Sai Pavan

Quoted 31 lines
Quoted 31 lines

Regards
Sai Pavan

Quoted 26 lines
Quoted 26 lines

So no change needed for this patch.

Quoted 21 lines

Regards,
Sai Pavan

Quoted 17 lines

With that fixed:

Quoted 13 lines
hw/usb/hcd-xhci.h +2 -0
+
 #define TYPE_XHCI "base-xhci"
 #define TYPE_NEC_XHCI "nec-usb-xhci"
 #define TYPE_QEMU_XHCI "qemu-xhci"
@@ -189,6 +191,7 @@ struct XHCIState {
 
     USBBus bus;
     MemoryRegion mem;
+    AddressSpace *as;
     MemoryRegion mem_cap;
     MemoryRegion mem_oper;
     MemoryRegion mem_runtime;
#9 lore raw

Re: [PATCH v4 1/7] usb/hcd-xhci: Make dma read/writes hooks pci free

In reply to Philippe Mathieu-Daudé
Quoted 25 lines · Philippe Mathieu-Daudé
Quoted 24 lines · Philippe Mathieu-Daudé
Quoted 10 lines
Quoted 10 lines · Sai Pavan Boddu
Quoted 9 lines

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 |
3 +++

 2 files changed, 14 insertions(+), 13 deletions(-)

[...]

Quoted 12 lines
Quoted 10 lines

hw/usb/hcd-xhci.h line 25

Quoted 7 lines
hw/usb/hcd-xhci.h +1 -0
@@ -22,6 +22,8 @@
 #ifndef HW_USB_HCD_XHCI_H
 #define HW_USB_HCD_XHCI_H
 
+#include "sysemu/dma.h"

AddressSpace is forward-declared in "qemu/typedefs.h", so no need to include it here (yes in the sources including hcd-xhci.h).

[Sai Pavan Boddu] Yes you are right!, but without this " dma_addr_t " is undefined.
At this point of the patch, hcd-xhci.h is compiled along with pci.h which would provide 'dma_addr_t', but when we strip the pci wrapper around hcd-xhci we would miss it. Let me know, if its good to add later in the patch series when the split happens.

Quoted 8 lines
Quoted 6 lines

OK :( I'd prefer to only include "sysemu/dma.h" in hw/usb/hcd-xhci.c.

Cc'ing David who added dma_addr_t in commit e5332e6334f ("iommu: Introduce IOMMU emulation infrastructure"), it might be simpler to move its declaration to "qemu/typedefs.h" too.

Btw this type should be poisoned for user-mode.

Yes, yes it should.

Quoted 27 lines
Quoted 26 lines

So no change needed for this patch.

Quoted 21 lines

Regards,
Sai Pavan

Quoted 17 lines

With that fixed:

Quoted 13 lines
hw/usb/hcd-xhci.h +2 -0
+
 #define TYPE_XHCI "base-xhci"
 #define TYPE_NEC_XHCI "nec-usb-xhci"
 #define TYPE_QEMU_XHCI "qemu-xhci"
@@ -189,6 +191,7 @@ struct XHCIState {
 
     USBBus bus;
     MemoryRegion mem;
+    AddressSpace *as;
     MemoryRegion mem_cap;
     MemoryRegion mem_oper;
     MemoryRegion mem_runtime;
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#10 lore raw

Re: [PATCH v4 1/7] usb/hcd-xhci: Make dma read/writes hooks pci free

In reply to Philippe Mathieu-Daudé
Quoted 24 lines · Philippe Mathieu-Daudé
Quoted 10 lines
Quoted 10 lines · Sai Pavan Boddu
Quoted 9 lines

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 |
3 +++

 2 files changed, 14 insertions(+), 13 deletions(-)

[...]

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
hw/usb/hcd-xhci.h +0 -0
@@ -22,6 +22,8 @@
 #ifndef HW_USB_HCD_XHCI_H
 #define HW_USB_HCD_XHCI_H
 
Quoted 6 lines
Quoted 4 lines

hw/usb/hcd-xhci.h line 25

Quoted 1 line
hw/usb/hcd-xhci.h +1 -0
+#include "sysemu/dma.h"

AddressSpace is forward-declared in "qemu/typedefs.h", so no need to include it here (yes in the sources including hcd-xhci.h).

[Sai Pavan Boddu] Yes you are right!, but without this " dma_addr_t " is undefined.
At this point of the patch, hcd-xhci.h is compiled along with pci.h which would provide 'dma_addr_t', but when we strip the pci wrapper around hcd-xhci we would miss it. Let me know, if its good to add later in the patch series when the split happens.

Quoted 6 lines

OK :( I'd prefer to only include "sysemu/dma.h" in hw/usb/hcd-xhci.c.

Cc'ing David who added dma_addr_t in commit e5332e6334f ("iommu: Introduce IOMMU emulation infrastructure"), it might be simpler to move its declaration to "qemu/typedefs.h" too.

Moving it to qemu/typedefs.h seems fine to me fwiw.

Quoted 25 lines

So no change needed for this patch.

Quoted 21 lines

Regards,
Sai Pavan

Quoted 17 lines

With that fixed:

Quoted 13 lines
hw/usb/hcd-xhci.h +2 -0
+
 #define TYPE_XHCI "base-xhci"
 #define TYPE_NEC_XHCI "nec-usb-xhci"
 #define TYPE_QEMU_XHCI "qemu-xhci"
@@ -189,6 +191,7 @@ struct XHCIState {
 
     USBBus bus;
     MemoryRegion mem;
+    AddressSpace *as;
     MemoryRegion mem_cap;
     MemoryRegion mem_oper;
     MemoryRegion mem_runtime;
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#11 lore raw

PATCH v4 2/7 usb/hcd-xhci: Move qemu-xhci device to hcd-xhci-pci.c

In reply to Sai Pavan Boddu

Move 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/Makefile.objs  |  1 +
 hw/usb/hcd-xhci-pci.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/usb/hcd-xhci.c     | 41 ++------------------------------
 hw/usb/hcd-xhci.h     |  3 +++
 5 files changed, 78 insertions(+), 39 deletions(-)
 create mode 100644 hw/usb/hcd-xhci-pci.c
hw/usb/Kconfig +6 -0
index d4d8c37..d9965c1 100644
@@ -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/Makefile.objs +1 -0
index e342ff5..029b040 100644
@@ -11,6 +11,7 @@ common-obj-$(CONFIG_USB_EHCI_PCI) += hcd-ehci-pci.o
 common-obj-$(CONFIG_USB_EHCI_SYSBUS) += hcd-ehci-sysbus.o
 common-obj-$(CONFIG_USB_XHCI) += hcd-xhci.o
 common-obj-$(CONFIG_USB_XHCI_NEC) += hcd-xhci-nec.o
+common-obj-$(CONFIG_USB_XHCI_PCI) += hcd-xhci-pci.o
 common-obj-$(CONFIG_USB_MUSB) += hcd-musb.o
 common-obj-$(CONFIG_USB_DWC2) += hcd-dwc2.o
 
hw/usb/hcd-xhci-pci.c new file +66 -0

66 lines not on this page · raw message

hw/usb/hcd-xhci.c +2 -39

78 lines not on this page · raw message

hw/usb/hcd-xhci.h +3 -0
index edbd926..dd5fcd4 100644
@@ -23,6 +23,7 @@
 #define HW_USB_HCD_XHCI_H
 
 #include "sysemu/dma.h"
+#include "hw/usb.h"
 
 #define TYPE_XHCI "base-xhci"
 #define TYPE_NEC_XHCI "nec-usb-xhci"
@@ -232,4 +233,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
Signature · 1 line
2.7.4
#12 lore raw

Re: [PATCH v4 2/7] usb/hcd-xhci: Move qemu-xhci device to hcd-xhci-pci.c

Quoted 142 lines · Sai Pavan Boddu

Move 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/Makefile.objs  |  1 +
 hw/usb/hcd-xhci-pci.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/usb/hcd-xhci.c     | 41 ++------------------------------
 hw/usb/hcd-xhci.h     |  3 +++
 5 files changed, 78 insertions(+), 39 deletions(-)
 create mode 100644 hw/usb/hcd-xhci-pci.c
hw/usb/Kconfig +6 -0
index d4d8c37..d9965c1 100644
@@ -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/Makefile.objs +1 -0
index e342ff5..029b040 100644
@@ -11,6 +11,7 @@ common-obj-$(CONFIG_USB_EHCI_PCI) += hcd-ehci-pci.o
 common-obj-$(CONFIG_USB_EHCI_SYSBUS) += hcd-ehci-sysbus.o
 common-obj-$(CONFIG_USB_XHCI) += hcd-xhci.o
 common-obj-$(CONFIG_USB_XHCI_NEC) += hcd-xhci-nec.o
+common-obj-$(CONFIG_USB_XHCI_PCI) += hcd-xhci-pci.o
 common-obj-$(CONFIG_USB_MUSB) += hcd-musb.o
 common-obj-$(CONFIG_USB_DWC2) += hcd-dwc2.o
 
hw/usb/hcd-xhci-pci.c new file +66 -0
new file mode 100644
index 0000000..1562757
@@ -0,0 +1,66 @@
+/*
+ * USB xHCI controller with PCI bus emulation
+ *
+ * SPDX-FileCopyrightText: 2011 Securiforest
+ * SPDX-FileContributor: Hector Martin <[email protected]>
+ * SPDX-sourceInfo: Based on usb-ohci.c, emulates Renesas NEC USB 3.0
+ * SPDX-FileCopyrightText: 2020 Xilinx
+ * SPDX-FileContributor: Sai Pavan Boddu <[email protected]>
+ * SPDX-sourceInfo: Moved the pci specific content for hcd-xhci.c to
+ *                  hcd-xhci-pci.c
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+#include "qemu/osdep.h"
+#include "hw/pci/pci.h"
+#include "hw/qdev-properties.h"
+#include "hw/pci/msi.h"
+#include "hw/pci/msix.h"
+#include "hcd-xhci.h"
+#include "trace.h"
+#include "qapi/error.h"
+
+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(&qemu_xhci_info);
+}
+
+type_init(xhci_register_types)
hw/usb/hcd-xhci.c +2 -3
index 2590f7a..b15c53b 100644
@@ -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);
 }

hw/usb/hcd-xhci.c static Property xhci_properties[] = { · line 3699

Quoted 8 lines
hw/usb/hcd-xhci.c +0 -5
@@ -3692,13 +3691,6 @@ static Property xhci_properties[] = {
     DEFINE_PROP_END_OF_LIST(),
 };
 
-static void xhci_instance_init(Object *obj)
-{
-    /* QEMU_PCI_CAP_EXPRESS initialization does not depend on QEMU command
-     * line, therefore, no need to wait to realize like other devices */
-    PCI_DEVICE(obj)->cap_present |= QEMU_PCI_CAP_EXPRESS;

What happened to this flag?

Quoted 71 lines
hw/usb/hcd-xhci.c +0 -31
-}
-
 static void xhci_class_init(ObjectClass *klass, void *data)
 {
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
@@ -3718,7 +3710,6 @@ static const TypeInfo xhci_info = {
     .parent        = TYPE_PCI_DEVICE,
     .instance_size = sizeof(XHCIState),
     .class_init    = xhci_class_init,
-    .instance_init = xhci_instance_init,
     .abstract      = true,
     .interfaces = (InterfaceInfo[]) {
         { INTERFACE_PCIE_DEVICE },
@@ -3727,37 +3718,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 +3 -0
index edbd926..dd5fcd4 100644
@@ -23,6 +23,7 @@
 #define HW_USB_HCD_XHCI_H
 
 #include "sysemu/dma.h"
+#include "hw/usb.h"
 
 #define TYPE_XHCI "base-xhci"
 #define TYPE_NEC_XHCI "nec-usb-xhci"
@@ -232,4 +233,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
#13 lore raw

RE: [PATCH v4 2/7] usb/hcd-xhci: Move qemu-xhci device to hcd-xhci-pci.c

Hi Philippe,

Quoted 159 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: Tuesday, September 1, 2020 10:08 PM
To: Sai Pavan Boddu <[email protected]>; 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]>
Cc: [email protected]; Alistair Francis <[email protected]>; Eduardo Habkost <[email protected]>; Ying Fang <[email protected]>; Vikram Garhwal <[email protected]>; Paul Zimmerman <[email protected]>
Subject: Re: [PATCH v4 2/7] usb/hcd-xhci: Move qemu-xhci device to hcd- xhci-pci.c

Quoted 8 lines · Sai Pavan Boddu

Move 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/Makefile.objs  |  1 +
 hw/usb/hcd-xhci-pci.c | 66

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

hw/usb/Makefile.objs common-obj-$(CONFIG_USB_EHCI_PCI) += hcd-ehci-

Quoted 27 lines
 hw/usb/hcd-xhci.c     | 41 ++------------------------------
 hw/usb/hcd-xhci.h     |  3 +++
 5 files changed, 78 insertions(+), 39 deletions(-)  create mode

100644 hw/usb/hcd-xhci-pci.c

hw/usb/Kconfig index d4d8c37..d9965c1 renamed from hw/usb/Kconfig +0 -0

100644

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/Makefile.objs index renamed from hw/usb/Makefile.objs +0 -0

e342ff5..029b040 100644

hw/usb/Makefile.objs +0 -0
@@ -11,6 +11,7 @@ common-obj-$(CONFIG_USB_EHCI_PCI) += hcd-ehci-

pci.o

Quoted 21 lines
hw/usb/Makefile.objs +1 -0
 common-obj-$(CONFIG_USB_EHCI_SYSBUS) += hcd-ehci-sysbus.o
 common-obj-$(CONFIG_USB_XHCI) += hcd-xhci.o
 common-obj-$(CONFIG_USB_XHCI_NEC) += hcd-xhci-nec.o
+common-obj-$(CONFIG_USB_XHCI_PCI) += hcd-xhci-pci.o
 common-obj-$(CONFIG_USB_MUSB) += hcd-musb.o
 common-obj-$(CONFIG_USB_DWC2) += hcd-dwc2.o
 
hw/usb/hcd-xhci-pci.c new file renamed from hw/usb/hcd-xhci-pci.c +0 -0

mode 100644 index 0000000..1562757

hw/usb/hcd-xhci-pci.c new file +9 -0
@@ -0,0 +1,66 @@
+/*
+ * USB xHCI controller with PCI bus emulation
+ *
+ * SPDX-FileCopyrightText: 2011 Securiforest
+ * SPDX-FileContributor: Hector Martin <[email protected]>
+ * SPDX-sourceInfo: Based on usb-ohci.c, emulates Renesas NEC USB 3.0
+ * SPDX-FileCopyrightText: 2020 Xilinx
+ * SPDX-FileContributor: Sai Pavan Boddu <[email protected]>
+ * SPDX-sourceInfo: Moved the pci specific content for hcd-xhci.c to

hw/usb/hcd-xhci-pci.c line 19

Quoted 10 lines
hw/usb/hcd-xhci-pci.c new file +10 -0
+ *                  hcd-xhci-pci.c
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

GNU

hw/usb/hcd-xhci-pci.c

Quoted 4 lines
hw/usb/hcd-xhci-pci.c new file +4 -0
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see

<http://www.gnu.org/licenses/>.

Quoted 68 lines
hw/usb/hcd-xhci-pci.c new file +38 -0
+ */
+#include "qemu/osdep.h"
+#include "hw/pci/pci.h"
+#include "hw/qdev-properties.h"
+#include "hw/pci/msi.h"
+#include "hw/pci/msix.h"
+#include "hcd-xhci.h"
+#include "trace.h"
+#include "qapi/error.h"
+
+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(&qemu_xhci_info);
+}
+
+type_init(xhci_register_types)
hw/usb/hcd-xhci.c index renamed from hw/usb/hcd-xhci.c +0 -0

2590f7a..b15c53b 100644

hw/usb/hcd-xhci.c +2 -3
@@ -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);
 }
@@ -3692,13 +3691,6 @@ static Property xhci_properties[] = {
     DEFINE_PROP_END_OF_LIST(),
 };
 
Quoted 7 lines

hw/usb/hcd-xhci.c static Property xhci_properties[] = { · line 3696

Quoted 2 lines
hw/usb/hcd-xhci.c +0 -2
-static void xhci_instance_init(Object *obj) -{
-    /* QEMU_PCI_CAP_EXPRESS initialization does not depend on QEMU

command

hw/usb/hcd-xhci.c static Property xhci_properties[] = { · line 3699

Quoted 2 lines
hw/usb/hcd-xhci.c +0 -2
-     * line, therefore, no need to wait to realize like other devices */
-    PCI_DEVICE(obj)->cap_present |= QEMU_PCI_CAP_EXPRESS;

What happened to this flag?

[Sai Pavan Boddu] During a patch split this has been moved into patch 3/7. I would make these changes come into one patch.

Regards,
Sai Pavan

Quoted 68 lines
Quoted 68 lines
hw/usb/hcd-xhci.c +0 -29
-}
-
 static void xhci_class_init(ObjectClass *klass, void *data)  {
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); @@ -3718,7 +3710,6
 @@ static const TypeInfo xhci_info = {
     .parent        = TYPE_PCI_DEVICE,
     .instance_size = sizeof(XHCIState),
     .class_init    = xhci_class_init,
-    .instance_init = xhci_instance_init,
     .abstract      = true,
     .interfaces = (InterfaceInfo[]) {
         { INTERFACE_PCIE_DEVICE },
@@ -3727,37 +3718,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 index renamed from hw/usb/hcd-xhci.h +0 -0

edbd926..dd5fcd4 100644

hw/usb/hcd-xhci.h +3 -0
@@ -23,6 +23,7 @@
 #define HW_USB_HCD_XHCI_H
 
 #include "sysemu/dma.h"
+#include "hw/usb.h"
 
 #define TYPE_XHCI "base-xhci"
 #define TYPE_NEC_XHCI "nec-usb-xhci"
@@ -232,4 +233,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
#14 lore raw

PATCH v4 3/7 usb/hcd-xhci: Split pci wrapper for xhci base model

In reply to Sai Pavan Boddu

This 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 | 188 +++++++++++++++++++++++++++++++++++++++++++++--
 hw/usb/hcd-xhci-pci.h |  45 ++++++++++++
 hw/usb/hcd-xhci.c     | 197 ++++++++++----------------------------------------
 hw/usb/hcd-xhci.h     |  15 ++--
 5 files changed, 284 insertions(+), 179 deletions(-)
 create mode 100644 hw/usb/hcd-xhci-pci.h
hw/usb/hcd-xhci-nec.c +9 -9
index e6a5a22..2efa6fa 100644
@@ -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 -157

356 lines not on this page · raw message

hw/usb/hcd-xhci.h +7 -8
index dd5fcd4..fea1761 100644
@@ -171,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;
@@ -185,10 +185,8 @@ typedef struct XHCIInterrupter {
 
 } XHCIInterrupter;
 
-struct XHCIState {
-    /*< private >*/
-    PCIDevice parent_obj;
-    /*< public >*/
+typedef struct XHCIState {
+    DeviceState parent;
 
     USBBus bus;
     MemoryRegion mem;
@@ -205,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;
@@ -231,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
#15 lore raw

PATCH v4 4/7 usb: hcd-xhci-sysbus: Attach xhci to sysbus device

In reply to Sai Pavan Boddu

Use XHCI as sysbus device, add memory region property to get the address space instance for dma read/write.

---
 hw/usb/Kconfig           |  5 +++
 hw/usb/Makefile.objs     |  1 +
 hw/usb/hcd-xhci-sysbus.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++
 hw/usb/hcd-xhci-sysbus.h | 32 ++++++++++++++++
 hw/usb/hcd-xhci.h        |  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
index d9965c1..a251501 100644
@@ -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/Makefile.objs +1 -0
index 029b040..f16a3c3 100644
@@ -12,6 +12,7 @@ common-obj-$(CONFIG_USB_EHCI_SYSBUS) += hcd-ehci-sysbus.o
 common-obj-$(CONFIG_USB_XHCI) += hcd-xhci.o
 common-obj-$(CONFIG_USB_XHCI_NEC) += hcd-xhci-nec.o
 common-obj-$(CONFIG_USB_XHCI_PCI) += hcd-xhci-pci.o
+common-obj-$(CONFIG_USB_XHCI_SYSBUS) += hcd-xhci-sysbus.o
 common-obj-$(CONFIG_USB_MUSB) += hcd-musb.o
 common-obj-$(CONFIG_USB_DWC2) += hcd-dwc2.o
 
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
new file mode 100644
index 0000000..a308753
@@ -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
index fea1761..b951df4 100644
@@ -190,6 +190,7 @@ typedef struct XHCIState {
 
     USBBus bus;
     MemoryRegion mem;
+    MemoryRegion *dma_mr;
     AddressSpace *as;
     MemoryRegion mem_cap;
     MemoryRegion mem_oper;
Signature · 1 line
2.7.4
#16 lore raw

Re: [PATCH v4 4/7] usb: hcd-xhci-sysbus: Attach xhci to sysbus device

Quoted 9 lines · Sai Pavan Boddu

Use XHCI as sysbus device, add memory region property to get the address space instance for dma read/write.

---
 hw/usb/Kconfig           |  5 +++
 hw/usb/Makefile.objs     |  1 +
 hw/usb/hcd-xhci-sysbus.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++
 hw/usb/hcd-xhci-sysbus.h | 32 ++++++++++++++++

Please consider using scripts/git.orderfile to ease review (less scrolling required by reviewer).

Quoted 2 lines
 hw/usb/hcd-xhci.h        |  1 +
 5 files changed, 138 insertions(+)

...

Quoted 25 lines
hw/usb/hcd-xhci-sysbus.c new file +19 -0
new file mode 100644
index 0000000..d5b4656
@@ -0,0 +1,99 @@
+/*
+ * USB xHCI controller for system-bus interface
+ * Based on hcd-echi-sysbus.c
+
+ * SPDX-FileCopyrightText: 2020 Xilinx
+ * SPDX-FileContributor: Author: Sai Pavan Boddu <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include "qemu/osdep.h"
+#include "hw/qdev-properties.h"
+#include "migration/vmstate.h"
+#include "trace.h"
+#include "qapi/error.h"
+#include "hcd-xhci-sysbus.h"
+#include "hw/irq.h"
+
+static void xhci_sysbus_intr_raise(XHCIState *xhci, int n, bool level)
+{

hw/usb/hcd-xhci-sysbus.c line 29

Quoted 10 lines
hw/usb/hcd-xhci-sysbus.c new file +10 -0
+    XHCISysbusState *s = container_of(xhci, XHCISysbusState, xhci);
+
+    qemu_set_irq(s->irq[n], level);
+}
+
+void xhci_sysbus_reset(DeviceState *dev)
+{
+    XHCISysbusState *s = XHCI_SYSBUS(dev);
+
+    device_legacy_reset(DEVICE(&s->xhci));

Documentation comment:

"This function is deprecated and will be removed when it becomes unused.
Please use device_cold_reset() now."

Quoted 2 lines
hw/usb/hcd-xhci-sysbus.c new file +2 -0
+}
+
#17 lore raw

PATCH v4 5/7 misc: Add versal-usb2-regs module

In reply to Sai Pavan Boddu

This is a dummy module to emulate control registers of versal usb2 controller.

---
 hw/misc/Makefile.objs                   |   1 +
 hw/misc/xlnx-versal-usb2-regs.c         | 224 ++++++++++++++++++++++++++++++++
 include/hw/misc/xlnx-versal-usb2-regs.h |  43 ++++++
 3 files changed, 268 insertions(+)
 create mode 100644 hw/misc/xlnx-versal-usb2-regs.c
 create mode 100644 include/hw/misc/xlnx-versal-usb2-regs.h
hw/misc/Makefile.objs +1 -0
index 6be3d25..6d12ca7 100644
@@ -64,6 +64,7 @@ common-obj-$(CONFIG_RASPI) += bcm2835_thermal.o
 common-obj-$(CONFIG_SLAVIO) += slavio_misc.o
 common-obj-$(CONFIG_ZYNQ) += zynq_slcr.o
 common-obj-$(CONFIG_ZYNQ) += zynq-xadc.o
+common-obj-$(CONFIG_XLNX_VERSAL) += xlnx-versal-usb2-regs.o
 common-obj-$(CONFIG_STM32F2XX_SYSCFG) += stm32f2xx_syscfg.o
 common-obj-$(CONFIG_STM32F4XX_SYSCFG) += stm32f4xx_syscfg.o
 common-obj-$(CONFIG_STM32F4XX_EXTI) += stm32f4xx_exti.o
hw/misc/xlnx-versal-usb2-regs.c new file +224 -0

224 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
#18 lore raw

Re: [PATCH v4 5/7] misc: Add versal-usb2-regs module

Quoted 2 lines · Sai Pavan Boddu

This is a dummy module to emulate control registers of versal usb2 controller.

--verbose please. xhci supports all usb speeds, including usb2.

So why this hardware is here, what does it on a real device and what is the emulation doing? "dummy" sounds like it does just enough to make the guest driver happy, probably pretending nothing is connected?

thanks,
Gerd

#19 lore raw

RE: [PATCH v4 5/7] misc: Add versal-usb2-regs module

Hi Gred,

Quoted 15 lines

-----Original Message-----
From: Gerd Hoffmann <[email protected]>
Sent: Monday, August 31, 2020 12: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]>; 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 v4 5/7] misc: Add versal-usb2-regs module

Quoted 5 lines
Quoted 2 lines · Sai Pavan Boddu

This is a dummy module to emulate control registers of versal usb2 controller.

--verbose please. xhci supports all usb speeds, including usb2.

[Sai Pavan Boddu] This module is has soc specific control/status register to control the phy-reset, adjust frame length time and coherency properties for the transactions.

Quoted 4 lines

So why this hardware is here, what does it on a real device and what is the emulation doing? "dummy" sounds like it does just enough to make the guest driver happy, probably pretending nothing is connected?

Yes, this is added to make guest happy.

I will the commit message with more info

Regards,
Sai Pavan

Quoted 3 lines

thanks,
Gerd

#20 lore raw

PATCH v4 6/7 usb: Add DWC3 model

In reply to Sai Pavan Boddu

From: Vikram Garhwal <[email protected]>

This patch adds skeleton model of dwc3 usb controller attached to xhci-sysbus device.

---
 hw/usb/Makefile.objs      |   1 +
 hw/usb/hcd-dwc3.c         | 606 ++++++++++++++++++++++++++++++++++++++++++++++
 include/hw/usb/hcd-dwc3.h |  58 +++++
 3 files changed, 665 insertions(+)
 create mode 100644 hw/usb/hcd-dwc3.c
 create mode 100644 include/hw/usb/hcd-dwc3.h
hw/usb/Makefile.objs +1 -0
index f16a3c3..af0487b 100644
@@ -15,6 +15,7 @@ common-obj-$(CONFIG_USB_XHCI_PCI) += hcd-xhci-pci.o
 common-obj-$(CONFIG_USB_XHCI_SYSBUS) += hcd-xhci-sysbus.o
 common-obj-$(CONFIG_USB_MUSB) += hcd-musb.o
 common-obj-$(CONFIG_USB_DWC2) += hcd-dwc2.o
+common-obj-$(CONFIG_XLNX_VERSAL) += hcd-dwc3.o
 
 common-obj-$(CONFIG_TUSB6010) += tusb6010.o
 common-obj-$(CONFIG_IMX)      += chipidea.o
hw/usb/hcd-dwc3.c new file +606 -0

606 lines not on this page · raw message

include/hw/usb/hcd-dwc3.h new file +58 -0

58 lines not on this page · raw message

Signature · 1 line
2.7.4
#21 lore raw

Re: [PATCH v4 6/7] usb: Add DWC3 model

Quoted 4 lines · Sai Pavan Boddu

From: Vikram Garhwal <[email protected]>

This patch adds skeleton model of dwc3 usb controller attached to xhci-sysbus device.

--verbose.

This looks like xhci with a bunch of extra registers? What these registers are good for?

Quoted 2 lines

+/*
+ * QEMU model of the USB DWC3 host controller emulation.

(answer should go to both this comment and the commit message).

thanks,
Gerd

#22 lore raw

RE: [PATCH v4 6/7] usb: Add DWC3 model

HI Gred,

Quoted 16 lines

-----Original Message-----
From: Gerd Hoffmann <[email protected]>
Sent: Monday, August 31, 2020 12:36 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 v4 6/7] usb: Add DWC3 model

On Sat, Aug 29, 2020 at 12:49:39AM +0530, Sai Pavan Boddu wrote:

Quoted 8 lines
Quoted 4 lines

From: Vikram Garhwal <[email protected]>

This patch adds skeleton model of dwc3 usb controller attached to xhci-sysbus device.

--verbose.

This looks like xhci with a bunch of extra registers?

[Sai Pavan Boddu]

Quoted 1 line

What these registers are good for?

These are also put to make the guest happy.
This module contain dwc3 global registers which deal with power management, phy config and ID registers. And also has Device and OTG registers which are incomplete at present.

What I realized is, we could clean many of these registers and only emulate ID registers at present. As others are meaningless. I would just define a reserved space, to skip io access errors.

Thanks,
Sai Pavan

Quoted 8 lines
Quoted 3 lines

+/*
+ * QEMU model of the USB DWC3 host controller emulation.

(answer should go to both this comment and the commit message).

thanks,
Gerd

#23 lore raw

PATCH v4 7/7 Versal: Connect DWC3 controller with virt-versal

In reply to Sai Pavan Boddu

From: Vikram Garhwal <[email protected]>

Connect dwc3 controller and usb2-reg module to 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
index 4b3152e..398693d 100644
@@ -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
index e3aa4bd..5cb03a1 100644
@@ -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", 4);
+    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
index 9c9f47b..e19cfd5 100644
@@ -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
#24 lore raw

Re: [PATCH v4 7/7] Versal: Connect DWC3 controller with virt-versal

Hi,

hw/arm/xlnx-versal-virt.c static void fdt_add_timer_nodes(VersalVirt *s) · line 192

Quoted 7 lines
hw/arm/xlnx-versal-virt.c +7 -0
+        unsigned int irq = VERSAL_USB0_IRQ_0;
+        const char intName[] = "dwc_usb3";
+        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);

This seems to declare one IRQ in the FDT.

Quoted 1 line

+ qdev_prop_set_uint32(xhci_dev, "intrs", 4);

Here you configure 4 IRQs for xhci-sysbus.

Quoted 1 line

+ sysbus_connect_irq(SYS_BUS_DEVICE(xhci_dev), 0, pic[VERSAL_USB0_IRQ_0]);

Also a single IRQ only.

I'm wondering which is correct? Probably one IRQ? Do we need support for multiple IRQs in xhci-sysbus in the first place?

take care,
Gerd

#25 lore raw

RE: [PATCH v4 7/7] Versal: Connect DWC3 controller with virt-versal

Hi Gred,

Quoted 31 lines

-----Original Message-----
From: Gerd Hoffmann <[email protected]>
Sent: Monday, August 31, 2020 12:43 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 v4 7/7] Versal: Connect DWC3 controller with virt-versal

Hi,

hw/arm/xlnx-versal-virt.c static void fdt_add_timer_nodes(VersalVirt *s) · line 192

Quoted 7 lines
hw/arm/xlnx-versal-virt.c +7 -0
+        unsigned int irq = VERSAL_USB0_IRQ_0;
+        const char intName[] = "dwc_usb3";
+        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);

This seems to declare one IRQ in the FDT.

Quoted 1 line

+ qdev_prop_set_uint32(xhci_dev, "intrs", 4);

Here you configure 4 IRQs for xhci-sysbus.

Quoted 7 lines
Quoted 2 lines

+ sysbus_connect_irq(SYS_BUS_DEVICE(xhci_dev), 0,
+ pic[VERSAL_USB0_IRQ_0]);

Also a single IRQ only.

I'm wondering which is correct? Probably one IRQ? Do we need support for multiple IRQs in xhci-sysbus in the first place?

[Sai Pavan Boddu] It should be only one, as others seems to be define for device and OTG modes. I would fix this

Thanks,
Sai Pavan

Quoted 3 lines

take care,
Gerd

#26 lore raw

Re: [PATCH v4 7/7] Versal: Connect DWC3 controller with virt-versal

Hi,

Quoted 5 lines
Quoted 4 lines

Also a single IRQ only.

I'm wondering which is correct? Probably one IRQ? Do we need support for multiple IRQs in xhci-sysbus in the first place?

[Sai Pavan Boddu] It should be only one, as others seems to be define for device and OTG modes.

Documenting the registers/irqs used for device & otg in comments would be nice.

thanks,
Gerd

#27 lore raw
In reply to Sai Pavan Boddu
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.

Doesn't apply to git master.
Seems the series needs a rebase and adaption to the meson build system.

take care,
Gerd

#28 lore raw

Hi Gred,

Quoted 15 lines

-----Original Message-----
From: Gerd Hoffmann <[email protected]>
Sent: Monday, August 31, 2020 5:28 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 v4 0/7] Make hcd-xhci independent of pci hooks

Quoted 6 lines
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.

Doesn't apply to git master.
Seems the series needs a rebase and adaption to the meson build system.

[Sai Pavan Boddu] Ok, I missed rebasing patches over master branch. I will update this in V5.

Thanks,
Sai Pavan

Quoted 3 lines

take care,
Gerd