Skip to contentSkip to conversation

Make hcd-xhci independent of pci hooks

PATCH Superseded Sai Pavan Boddu 7 participants 19 messages Jun 24, 2020 – Jul 22, 2020

v2 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v2 cover Make hcd-xhci independent of pci hooks

Hi

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

Sorry for the late followup, below are the changes for V2

V2:
Make XHCIState non-qom
Use container_of functions for retriving pci device instance Initialize the AddressSpace pointer in PATCH 1/3 itself

Sai Pavan Boddu (3):
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

 hw/usb/Kconfig        |   6 ++
 hw/usb/Makefile.objs  |   1 +
 hw/usb/hcd-xhci-nec.c |  14 +--
 hw/usb/hcd-xhci-pci.c | 246 +++++++++++++++++++++++++++++++++++++++++++
 hw/usb/hcd-xhci-pci.h |  47 +++++++++
 hw/usb/hcd-xhci.c     | 287 ++++++++------------------------------------------
 hw/usb/hcd-xhci.h     |  30 +++---
 7 files changed, 369 insertions(+), 262 deletions(-)
 create mode 100644 hw/usb/hcd-xhci-pci.c
 create mode 100644 hw/usb/hcd-xhci-pci.h
Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 1/3 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 b330e36..fa6ce98 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 2fad4df..18bed7e 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 v2 1/3
#2 lore raw

Re: [PATCH v2 1/3] 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 b330e36..fa6ce98 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 2fad4df..18bed7e 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"

Not needed because forward-declared in "qemu/typedefs.h".

Moving the inclusion to hw/usb/hcd-xhci.c:

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

PATCH v2 2/3 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/hcd-xhci-pci.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/usb/hcd-xhci.c     | 32 ++------------------------
 hw/usb/hcd-xhci.h     |  2 ++
 3 files changed, 68 insertions(+), 30 deletions(-)
 create mode 100644 hw/usb/hcd-xhci-pci.c
hw/usb/hcd-xhci-pci.c new file +64 -0
new file mode 100644
index 0000000..26af683
@@ -0,0 +1,64 @@
+/*
+ * USB xHCI controller with PCI system bus emulation
+ *
+ * Copyright (c) 2011 Securiforest
+ * Date: 2011-05-11 ;  Author: Hector Martin <[email protected]>
+ * Based on usb-ohci.c, emulates Renesas NEC USB 3.0
+ * Date: 2020-03-01; Author: Sai Pavan Boddu <[email protected]>
+ * 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 -30
index fa6ce98..d340518 100644
@@ -429,12 +429,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);
 }
@@ -3727,37 +3727,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 +2 -0
index 18bed7e..ca03481 100644
@@ -232,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
Signature · 1 line
2.7.4
#4 lore raw

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

Quoted 17 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/hcd-xhci-pci.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/usb/hcd-xhci.c     | 32 ++------------------------
 hw/usb/hcd-xhci.h     |  2 ++
 3 files changed, 68 insertions(+), 30 deletions(-)
 create mode 100644 hw/usb/hcd-xhci-pci.c
hw/usb/hcd-xhci-pci.c new file +0 -0
new file mode 100644
index 0000000..26af683

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

Quoted 2 lines
hw/usb/hcd-xhci-pci.c new file +2 -0
@@ -0,0 +1,64 @@
+/*
+ * USB xHCI controller with PCI system bus emulation

Scratch "system".

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

Quoted 3 lines
hw/usb/hcd-xhci-pci.c new file +3 -0
+ *
+ * Copyright (c) 2011 Securiforest
+ * Date: 2011-05-11 ;  Author: Hector Martin <[email protected]>

Let's use the opportunity to drop the "Date: " part, because we don't have it anywhere else.

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

Quoted 2 lines
hw/usb/hcd-xhci-pci.c new file +2 -0
+ * Based on usb-ohci.c, emulates Renesas NEC USB 3.0
+ * Date: 2020-03-01; Author: Sai Pavan Boddu <[email protected]>

And no new "Date: " parts, please.

Quoted 15 lines
hw/usb/hcd-xhci-pci.c new file +15 -0
+ * 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/>.
+ */

[...]

#5 lore raw

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

Quoted 24 lines · Markus Armbruster
Quoted 17 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/hcd-xhci-pci.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/usb/hcd-xhci.c     | 32 ++------------------------
 hw/usb/hcd-xhci.h     |  2 ++
 3 files changed, 68 insertions(+), 30 deletions(-)
 create mode 100644 hw/usb/hcd-xhci-pci.c
hw/usb/hcd-xhci-pci.c new file +0 -0
new file mode 100644
index 0000000..26af683

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

Quoted 2 lines
hw/usb/hcd-xhci-pci.c new file +2 -0
@@ -0,0 +1,64 @@
+/*
+ * USB xHCI controller with PCI system bus emulation

Scratch "system".

Quoted 6 lines

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

Quoted 3 lines
hw/usb/hcd-xhci-pci.c new file +3 -0
+ *
+ * Copyright (c) 2011 Securiforest
+ * Date: 2011-05-11 ;  Author: Hector Martin <[email protected]>

Let's use the opportunity to drop the "Date: " part, because we don't have it anywhere else.

Good opportunity to suggest the SPDX tags again :P

/*
* SPDX-FileCopyrightText: 2011 Securiforest
* SPDX-FileContributor: Hector Martin <[email protected]>
* SPDX-FileCopyrightText: 2020 Xilinx Inc.
* SPDX-FileContributor: Sai Pavan Boddu <[email protected]>
* SPDX-License-Identifier: GPL-2.0-or-later
*/

https://spdx.org/rdf/ontology/spdx-2-0-rc/dataproperties/fileContributor___-1635717172.html

Quoted 23 lines

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

Quoted 3 lines
hw/usb/hcd-xhci-pci.c new file +2 -0
+ * Based on usb-ohci.c, emulates Renesas NEC USB 3.0
+ * Date: 2020-03-01; Author: Sai Pavan Boddu <[email protected]>

And no new "Date: " parts, please.

Quoted 15 lines
hw/usb/hcd-xhci-pci.c new file +15 -0
+ * 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/>.
+ */

[...]

#6 lore raw

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

HI Philippe,

Quoted 45 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: Thursday, June 25, 2020 1:48 PM
To: Markus Armbruster <[email protected]>; Sai Pavan Boddu <[email protected]>; Thomas Huth <[email protected]>
Cc: Gerd Hoffmann <[email protected]>; Peter Maydell <[email protected]>; Eduardo Habkost <[email protected]>; [email protected]; Alistair Francis <[email protected]>; 'Marc-André Lureau' <[email protected]>; Ying Fang <[email protected]>; Paolo Bonzini <[email protected]>
Subject: Re: [PATCH v2 2/3] usb/hcd-xhci: Move qemu-xhci device to hcd- xhci-pci.c

Quoted 8 lines · Markus Armbruster
Quoted 6 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/hcd-xhci-pci.c | 64

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

Quoted 15 lines

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

Quoted 12 lines
 hw/usb/hcd-xhci.c     | 32 ++------------------------
 hw/usb/hcd-xhci.h     |  2 ++
 3 files changed, 68 insertions(+), 30 deletions(-)  create mode

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

hw/usb/hcd-xhci-pci.c new file renamed from hw/usb/hcd-xhci-pci.c +0 -0

mode 100644 index 0000000..26af683

hw/usb/hcd-xhci-pci.c new file +2 -0
@@ -0,0 +1,64 @@
+/*
+ * USB xHCI controller with PCI system bus emulation

Scratch "system".

Quoted 6 lines

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

Quoted 3 lines
hw/usb/hcd-xhci-pci.c new file +3 -0
+ *
+ * Copyright (c) 2011 Securiforest
+ * Date: 2011-05-11 ;  Author: Hector Martin <[email protected]>

Let's use the opportunity to drop the "Date: " part, because we don't have it anywhere else.

Quoted 8 lines

Good opportunity to suggest the SPDX tags again :P

/*
* SPDX-FileCopyrightText: 2011 Securiforest
* SPDX-FileContributor: Hector Martin <[email protected]>
* SPDX-FileCopyrightText: 2020 Xilinx Inc.
* SPDX-FileContributor: Sai Pavan Boddu <[email protected]>
* SPDX-License-Identifier: GPL-2.0-or-later */

[Sai Pavan Boddu] I would include this in V4, Forgot them in V3.

Thanks,
Sai Pavan

Quoted 30 lines

https://spdx.org/rdf/ontology/spdx-2-0-
rc/dataproperties/fileContributor___-1635717172.html

Quoted 17 lines

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

Quoted 4 lines
hw/usb/hcd-xhci-pci.c new file +3 -0
+ * Based on usb-ohci.c, emulates Renesas NEC USB 3.0
+ * Date: 2020-03-01; Author: Sai Pavan Boddu
+ <[email protected]>

And no new "Date: " parts, please.

Quoted 10 lines
hw/usb/hcd-xhci-pci.c new file +10 -0
+ * 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

Quoted 4 lines

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 3 lines
Quoted 1 line
hw/usb/hcd-xhci-pci.c new file +1 -0
+ */

[...]

#7 lore raw

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

Quoted 55 lines · Sai Pavan Boddu

HI Philippe,

Quoted 45 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: Thursday, June 25, 2020 1:48 PM
To: Markus Armbruster <[email protected]>; Sai Pavan Boddu <[email protected]>; Thomas Huth <[email protected]>
Cc: Gerd Hoffmann <[email protected]>; Peter Maydell <[email protected]>; Eduardo Habkost <[email protected]>; [email protected]; Alistair Francis <[email protected]>; 'Marc-André Lureau' <[email protected]>; Ying Fang <[email protected]>; Paolo Bonzini <[email protected]>
Subject: Re: [PATCH v2 2/3] usb/hcd-xhci: Move qemu-xhci device to hcd- xhci-pci.c

Quoted 8 lines · Markus Armbruster
Quoted 6 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/hcd-xhci-pci.c | 64

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

Quoted 15 lines

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

Quoted 12 lines
 hw/usb/hcd-xhci.c     | 32 ++------------------------
 hw/usb/hcd-xhci.h     |  2 ++
 3 files changed, 68 insertions(+), 30 deletions(-)  create mode

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

hw/usb/hcd-xhci-pci.c new file renamed from hw/usb/hcd-xhci-pci.c +0 -0

mode 100644 index 0000000..26af683

hw/usb/hcd-xhci-pci.c new file +2 -0
@@ -0,0 +1,64 @@
+/*
+ * USB xHCI controller with PCI system bus emulation

Scratch "system".

Quoted 6 lines

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

Quoted 3 lines
hw/usb/hcd-xhci-pci.c new file +3 -0
+ *
+ * Copyright (c) 2011 Securiforest
+ * Date: 2011-05-11 ;  Author: Hector Martin <[email protected]>

Let's use the opportunity to drop the "Date: " part, because we don't have it anywhere else.

Quoted 8 lines

Good opportunity to suggest the SPDX tags again :P

/*
* SPDX-FileCopyrightText: 2011 Securiforest
* SPDX-FileContributor: Hector Martin <[email protected]>
* SPDX-FileCopyrightText: 2020 Xilinx Inc.
* SPDX-FileContributor: Sai Pavan Boddu <[email protected]>
* SPDX-License-Identifier: GPL-2.0-or-later */

Quoted 21 lines

[Sai Pavan Boddu] I would include this in V4, Forgot them in V3.

Thanks,
Sai Pavan

Quoted 17 lines

https://spdx.org/rdf/ontology/spdx-2-0-
rc/dataproperties/fileContributor___-1635717172.html

Quoted 13 lines

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

Quoted 4 lines
hw/usb/hcd-xhci-pci.c new file +3 -0
+ * Based on usb-ohci.c, emulates Renesas NEC USB 3.0
+ * Date: 2020-03-01; Author: Sai Pavan Boddu
+ <[email protected]>

And no new "Date: " parts, please.

Quoted 6 lines
hw/usb/hcd-xhci-pci.c new file +6 -0
+ * 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.

And while you're at it: There was never a "version 2" of the Lesser GPL. In version 2.0, it was still called "Library" GPL. So it is quite likely that version 2.1 is meant here instead.

Thomas

#8 lore raw

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

Hi Thomas,

Quoted 92 lines

-----Original Message-----
From: Thomas Huth <[email protected]>
Sent: Monday, July 20, 2020 1:37 PM
To: Sai Pavan Boddu <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Markus Armbruster <[email protected]>
Cc: Gerd Hoffmann <[email protected]>; Peter Maydell <[email protected]>; Eduardo Habkost <[email protected]>; [email protected]; Alistair Francis <[email protected]>; 'Marc-André Lureau' <[email protected]>; Ying Fang <[email protected]>; Paolo Bonzini <[email protected]>
Subject: Re: [PATCH v2 2/3] usb/hcd-xhci: Move qemu-xhci device to hcd- xhci-pci.c

Quoted 56 lines · Sai Pavan Boddu

HI Philippe,

Quoted 46 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: Thursday, June 25, 2020 1:48 PM
To: Markus Armbruster <[email protected]>; Sai Pavan Boddu <[email protected]>; Thomas Huth <[email protected]>
Cc: Gerd Hoffmann <[email protected]>; Peter Maydell <[email protected]>; Eduardo Habkost <[email protected]>; [email protected]; Alistair Francis <[email protected]>; 'Marc-André Lureau' <[email protected]>; Ying Fang <[email protected]>; Paolo Bonzini <[email protected]>
Subject: Re: [PATCH v2 2/3] usb/hcd-xhci: Move qemu-xhci device to hcd- xhci-pci.c

Quoted 8 lines · Markus Armbruster
Quoted 6 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/hcd-xhci-pci.c | 64

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

Quoted 15 lines

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

Quoted 12 lines
 hw/usb/hcd-xhci.c     | 32 ++------------------------
 hw/usb/hcd-xhci.h     |  2 ++
 3 files changed, 68 insertions(+), 30 deletions(-)  create mode

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

hw/usb/hcd-xhci-pci.c new file renamed from hw/usb/hcd-xhci-pci.c +0 -0

mode 100644 index 0000000..26af683

hw/usb/hcd-xhci-pci.c new file +2 -0
@@ -0,0 +1,64 @@
+/*
+ * USB xHCI controller with PCI system bus emulation

Scratch "system".

Quoted 7 lines

hw/usb/hcd-xhci-pci.c

Quoted 4 lines
hw/usb/hcd-xhci-pci.c new file +4 -0
+ *
+ * Copyright (c) 2011 Securiforest
+ * Date: 2011-05-11 ;  Author: Hector Martin
+ <[email protected]>

Let's use the opportunity to drop the "Date: " part, because we don't have it anywhere else.

Quoted 8 lines

Good opportunity to suggest the SPDX tags again :P

/*
* SPDX-FileCopyrightText: 2011 Securiforest
* SPDX-FileContributor: Hector Martin <[email protected]>
* SPDX-FileCopyrightText: 2020 Xilinx Inc.
* SPDX-FileContributor: Sai Pavan Boddu <[email protected]>
* SPDX-License-Identifier: GPL-2.0-or-later */

Quoted 21 lines

[Sai Pavan Boddu] I would include this in V4, Forgot them in V3.

Thanks,
Sai Pavan

Quoted 17 lines

https://spdx.org/rdf/ontology/spdx-2-0-
rc/dataproperties/fileContributor___-1635717172.html

Quoted 13 lines

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

Quoted 4 lines
hw/usb/hcd-xhci-pci.c new file +3 -0
+ * Based on usb-ohci.c, emulates Renesas NEC USB 3.0
+ * Date: 2020-03-01; Author: Sai Pavan Boddu
+ <[email protected]>

And no new "Date: " parts, please.

Quoted 6 lines
hw/usb/hcd-xhci-pci.c new file +6 -0
+ * 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.
Quoted 3 lines

And while you're at it: There was never a "version 2" of the Lesser GPL. In version 2.0, it was still called "Library" GPL. So it is quite likely that version 2.1 is meant here instead.

[Sai Pavan Boddu] I have less knowledge here. But indeed I don’t find LGPL 2.0 https://www.gnu.org/licenses/licenses.html#LicenseURLs

BTW, I still see our repository use combination of GPL and LGPL. Is there any general rule to follow at high level.

Regards,
Sai Pavan

Quoted 2 lines

Thomas

#9 lore raw

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

Hi,

On 22/07/2020 09.49, Sai Pavan Boddu wrote:
[...]

Quoted 9 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

+ * 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.

And while you're at it: There was never a "version 2" of the Lesser GPL. In version 2.0, it was still called "Library" GPL. So it is quite likely that version 2.1 is meant here instead.

[Sai Pavan Boddu] I have less knowledge here. But indeed I don’t find LGPL 2.0 https://www.gnu.org/licenses/licenses.html#LicenseURLs

You can find version 2.0 here, for example:

https://www.gnu.org/licenses/old-licenses/old-licenses.html#LGPL

... but as I said, v2.0 is called "Library" GPL instead of "Lesser" GPL.

Quoted 1 line

BTW, I still see our repository use combination of GPL and LGPL. Is there any general rule to follow at high level.

As long as the license is a standard license that is compatible with the GPLv2 or any later version, you should be fine. See the LICENSE file in the top directory of the sources for details.

As a general rule, I'd say either use "GPLv2 or later" (see the file COPYING in the main directory) or "LGPLv2.1 or later" (see COPYING.LIB in the main directory) for new code, unless you contribute to the tcg/ folder where MIT or BSD is preferred instead.

Thomas

#10 lore raw

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

Quoted 22 lines · Thomas Huth

Hi,

On 22/07/2020 09.49, Sai Pavan Boddu wrote:
[...]

Quoted 9 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

+ * 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.

And while you're at it: There was never a "version 2" of the Lesser GPL. In version 2.0, it was still called "Library" GPL. So it is quite likely that version 2.1 is meant here instead.

[Sai Pavan Boddu] I have less knowledge here. But indeed I don’t find LGPL 2.0 https://www.gnu.org/licenses/licenses.html#LicenseURLs

You can find version 2.0 here, for example:

https://www.gnu.org/licenses/old-licenses/old-licenses.html#LGPL

... but as I said, v2.0 is called "Library" GPL instead of "Lesser" GPL.

Quoted 1 line

BTW, I still see our repository use combination of GPL and LGPL. Is there any general rule to follow at high level.

Quoted 8 lines

As long as the license is a standard license that is compatible with the GPLv2 or any later version, you should be fine. See the LICENSE file in the top directory of the sources for details.

As a general rule, I'd say either use "GPLv2 or later" (see the file COPYING in the main directory) or "LGPLv2.1 or later" (see COPYING.LIB in the main directory) for new code, unless you contribute to the tcg/ folder where MIT or BSD is preferred instead.

Please use "GPLv2 or later".

If you believe you have a compelling reason for using a different license (compatible with GPLv2, of course), then explain yourself in the commit message.

#11 lore raw

PATCH v2 3/3 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, and XHCIState is non qom object, make use of 'container_of' calls to retrive XHCIPciState. Made required changes for qemu-xhci-nec.

---
 hw/usb/Kconfig        |   6 ++
 hw/usb/Makefile.objs  |   1 +
 hw/usb/hcd-xhci-nec.c |  14 +--
 hw/usb/hcd-xhci-pci.c | 192 +++++++++++++++++++++++++++++++++++++++--
 hw/usb/hcd-xhci-pci.h |  47 ++++++++++
 hw/usb/hcd-xhci.c     | 235 ++++++++------------------------------------------
 hw/usb/hcd-xhci.h     |  23 +++--
 7 files changed, 293 insertions(+), 225 deletions(-)
 create mode 100644 hw/usb/hcd-xhci-pci.h
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 fa5c3fa..98b1899 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-nec.c +7 -7
index e6a5a22..1756d97 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_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",
                     XHCIState, flags, XHCI_FLAG_SS_FIRST, true),
-    DEFINE_PROP_BIT("force-pcie-endcap", XHCIState, flags,
+    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 +187 -5

222 lines not on this page · raw message

hw/usb/hcd-xhci-pci.h new file +47 -0

47 lines not on this page · raw message

hw/usb/hcd-xhci.c +35 -200

393 lines not on this page · raw message

hw/usb/hcd-xhci.h +10 -13
index ca03481..33ed327 100644
@@ -24,13 +24,9 @@
 
 #include "sysemu/dma.h"
 
-#define TYPE_XHCI "base-xhci"
 #define TYPE_NEC_XHCI "nec-usb-xhci"
 #define TYPE_QEMU_XHCI "qemu-xhci"
 
-#define XHCI(obj) \
-    OBJECT_CHECK(XHCIState, (obj), TYPE_XHCI)
-
 #define MAXPORTS_2 15
 #define MAXPORTS_3 15
 
@@ -170,7 +166,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,11 +180,7 @@ typedef struct XHCIInterrupter {
 
 } XHCIInterrupter;
 
-struct XHCIState {
-    /*< private >*/
-    PCIDevice parent_obj;
-    /*< public >*/
-
+typedef struct XHCIState {
     USBBus bus;
     MemoryRegion mem;
     AddressSpace *as;
@@ -204,8 +196,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,8 +223,12 @@ struct XHCIState {
     XHCIRing cmd_ring;
 
     bool nec_quirks;
-};
+} XHCIState;
 
+extern const VMStateDescription vmstate_xhci;
+void xhci_reset(XHCIState *xhci);
+void usb_xhci_realize(XHCIState *xhci, DeviceState *dev, Error **errp);
+void usb_xhci_unrealize(XHCIState *xhci, DeviceState *dev, Error **errp);
 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 v2 3/3] usb/hcd-xhci: Split pci wrapper for xhci base model

Quoted 7 lines · 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, and XHCIState is non qom object, make use of 'container_of' calls to retrive XHCIPciState. Made required changes for qemu-xhci-nec.

I can't see a "sysbus model". What I can see is

         TYPE_DEVICE
              |
       TYPE_PCI_DEVICE
              |
        TYPE_XHCI_PCI (renamed from TYPE_XHCI)
          /       \

TYPE_QEMU_XHCI TYPE_NEC_XHCI

All but the two leaves are abstract.

Do you intend to add a "sysbus model" in a future patch?

#13 lore raw

RE: [PATCH v2 3/3] usb/hcd-xhci: Split pci wrapper for xhci base model

Hi Markus,

Quoted 32 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>
Sent: Thursday, June 25, 2020 1:42 PM
To: Sai Pavan Boddu <[email protected]>
Cc: Gerd Hoffmann <[email protected]>; Peter Maydell <[email protected]>; Thomas Huth <[email protected]>; Eduardo Habkost <[email protected]>; [email protected]; Alistair Francis <[email protected]>; 'Marc-André Lureau' <[email protected]>; Ying Fang <[email protected]>; Paolo Bonzini <[email protected]>; 'Philippe Mathieu-Daudé' <[email protected]>
Subject: Re: [PATCH v2 3/3] usb/hcd-xhci: Split pci wrapper for xhci base model

Quoted 7 lines · 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, and XHCIState is non qom object, make use of 'container_of' calls to retrive XHCIPciState. Made required changes for qemu-xhci-nec.

I can't see a "sysbus model". What I can see is

         TYPE_DEVICE
              |
       TYPE_PCI_DEVICE
              |
        TYPE_XHCI_PCI (renamed from TYPE_XHCI)
          /       \
Quoted 5 lines

TYPE_QEMU_XHCI TYPE_NEC_XHCI

All but the two leaves are abstract.

Do you intend to add a "sysbus model" in a future patch?

[Sai Pavan Boddu] Yes. I would be sending it along with that a device which would be using it. (i.e for zynqmp soc ) Let me know, if its good to include hcd-xhci-sysbus.c here ?

Regards,
Sai Pavan

#14 lore raw

Re: [PATCH v2 3/3] usb/hcd-xhci: Split pci wrapper for xhci base model

Quoted 36 lines · Sai Pavan Boddu

Hi Markus,

Quoted 34 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>
Sent: Thursday, June 25, 2020 1:42 PM
To: Sai Pavan Boddu <[email protected]>
Cc: Gerd Hoffmann <[email protected]>; Peter Maydell <[email protected]>; Thomas Huth <[email protected]>; Eduardo Habkost <[email protected]>; [email protected]; Alistair Francis <[email protected]>; 'Marc-André Lureau' <[email protected]>; Ying Fang <[email protected]>; Paolo Bonzini <[email protected]>; 'Philippe Mathieu-Daudé' <[email protected]>
Subject: Re: [PATCH v2 3/3] usb/hcd-xhci: Split pci wrapper for xhci base model

Quoted 7 lines · 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, and XHCIState is non qom object, make use of 'container_of' calls to retrive XHCIPciState. Made required changes for qemu-xhci-nec.

I can't see a "sysbus model". What I can see is

         TYPE_DEVICE
              |
       TYPE_PCI_DEVICE
              |
        TYPE_XHCI_PCI (renamed from TYPE_XHCI)
          /       \

TYPE_QEMU_XHCI TYPE_NEC_XHCI

Quoted 5 lines
Quoted 3 lines

All but the two leaves are abstract.

Do you intend to add a "sysbus model" in a future patch?

[Sai Pavan Boddu] Yes. I would be sending it along with that a device which would be using it. (i.e for zynqmp soc ) Let me know, if its good to include hcd-xhci-sysbus.c here ?

I'm not sure this series is worthwhile this future patch. Up to the maintainer.

Here's a clean way to provide different bus connectors (say PCI and sysbus) for the same core device:

Make the core device a TYPE_DEVICE.

For each desired bus, have a bus-specific device that contains a core device. Use object_initialize_child() for the component.

Example: core device TYPE_SERIAL, PCI device TYPE_PCI_SERIAL, ISA device TYPE_ISA_SERIAL, sysbus devices TYPE_SERIAL_IO. TYPE_SERIAL_MM.

#15 lore raw

RE: [PATCH v2 3/3] usb/hcd-xhci: Split pci wrapper for xhci base model

HI Markus,

Quoted 63 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>
Sent: Friday, June 26, 2020 11:42 AM
To: Sai Pavan Boddu <[email protected]>
Cc: Peter Maydell <[email protected]>; Thomas Huth <[email protected]>; Eduardo Habkost <[email protected]>; qemu- [email protected]; Alistair Francis <[email protected]>; Gerd Hoffmann <[email protected]>; Paolo Bonzini <[email protected]>; Ying Fang <[email protected]>; 'Marc-André Lureau' <[email protected]>; 'Philippe Mathieu-Daudé' <[email protected]>
Subject: Re: [PATCH v2 3/3] usb/hcd-xhci: Split pci wrapper for xhci base model

Quoted 8 lines · Sai Pavan Boddu

Hi Markus,

Quoted 6 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>
Sent: Thursday, June 25, 2020 1:42 PM
To: Sai Pavan Boddu <[email protected]>
Cc: Gerd Hoffmann <[email protected]>; Peter Maydell <[email protected]>; Thomas Huth <[email protected]>;

Eduardo

Quoted 8 lines
Quoted 8 lines

Habkost <[email protected]>; [email protected]; Alistair Francis <[email protected]>; 'Marc-André Lureau' <[email protected]>; Ying Fang <[email protected]>; Paolo Bonzini <[email protected]>; 'Philippe Mathieu-Daudé' <[email protected]>
Subject: Re: [PATCH v2 3/3] usb/hcd-xhci: Split pci wrapper for xhci base model

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines · 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, and XHCIState is non qom object, make use of 'container_of' calls to retrive XHCIPciState. Made required changes for

qemu-xhci-nec.

Quoted 13 lines
Quoted 13 lines
Quoted 2 lines

I can't see a "sysbus model". What I can see is

         TYPE_DEVICE
              |
       TYPE_PCI_DEVICE
              |
        TYPE_XHCI_PCI (renamed from TYPE_XHCI)
          /       \

TYPE_QEMU_XHCI TYPE_NEC_XHCI

Quoted 5 lines
Quoted 3 lines

All but the two leaves are abstract.

Do you intend to add a "sysbus model" in a future patch?

[Sai Pavan Boddu] Yes. I would be sending it along with that a device which would be using it. (i.e for zynqmp soc ) Let me know, if its good to

include hcd-xhci-sysbus.c here ?

I'm not sure this series is worthwhile this future patch. Up to the maintainer.

Quoted 7 lines

Here's a clean way to provide different bus connectors (say PCI and sysbus) for the same core device:

Make the core device a TYPE_DEVICE.

For each desired bus, have a bus-specific device that contains a core device. Use object_initialize_child() for the component.

[Sai Pavan Boddu] This was my V1 implementation.
Changed it to non-qom structure after some feedback from @Gred. Felt like XHCIState will not be used standalone.

Thanks,
sai Pavan

Quoted 3 lines

Example: core device TYPE_SERIAL, PCI device TYPE_PCI_SERIAL, ISA device TYPE_ISA_SERIAL, sysbus devices TYPE_SERIAL_IO. TYPE_SERIAL_MM.

#16 lore raw

Re: [PATCH v2 3/3] usb/hcd-xhci: Split pci wrapper for xhci base model

Quoted 68 lines · Sai Pavan Boddu

HI Markus,

Quoted 66 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>
Sent: Friday, June 26, 2020 11:42 AM
To: Sai Pavan Boddu <[email protected]>
Cc: Peter Maydell <[email protected]>; Thomas Huth <[email protected]>; Eduardo Habkost <[email protected]>; qemu- [email protected]; Alistair Francis <[email protected]>; Gerd Hoffmann <[email protected]>; Paolo Bonzini <[email protected]>; Ying Fang <[email protected]>; 'Marc-André Lureau' <[email protected]>; 'Philippe Mathieu-Daudé' <[email protected]>
Subject: Re: [PATCH v2 3/3] usb/hcd-xhci: Split pci wrapper for xhci base model

Quoted 8 lines · Sai Pavan Boddu

Hi Markus,

Quoted 6 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>
Sent: Thursday, June 25, 2020 1:42 PM
To: Sai Pavan Boddu <[email protected]>
Cc: Gerd Hoffmann <[email protected]>; Peter Maydell <[email protected]>; Thomas Huth <[email protected]>;

Eduardo

Quoted 8 lines
Quoted 8 lines

Habkost <[email protected]>; [email protected]; Alistair Francis <[email protected]>; 'Marc-André Lureau' <[email protected]>; Ying Fang <[email protected]>; Paolo Bonzini <[email protected]>; 'Philippe Mathieu-Daudé' <[email protected]>
Subject: Re: [PATCH v2 3/3] usb/hcd-xhci: Split pci wrapper for xhci base model

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines · 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, and XHCIState is non qom object, make use of 'container_of' calls to retrive XHCIPciState. Made required changes for

qemu-xhci-nec.

Quoted 13 lines
Quoted 13 lines
Quoted 2 lines

I can't see a "sysbus model". What I can see is

         TYPE_DEVICE
              |
       TYPE_PCI_DEVICE
              |
        TYPE_XHCI_PCI (renamed from TYPE_XHCI)
          /       \

TYPE_QEMU_XHCI TYPE_NEC_XHCI

Quoted 5 lines
Quoted 3 lines

All but the two leaves are abstract.

Do you intend to add a "sysbus model" in a future patch?

[Sai Pavan Boddu] Yes. I would be sending it along with that a device which would be using it. (i.e for zynqmp soc ) Let me know, if its good to

include hcd-xhci-sysbus.c here ?

I'm not sure this series is worthwhile this future patch. Up to the maintainer.

Here's a clean way to provide different bus connectors (say PCI and sysbus) for the same core device:

Quoted 6 lines
Quoted 4 lines

Make the core device a TYPE_DEVICE.

For each desired bus, have a bus-specific device that contains a core device. Use object_initialize_child() for the component.

[Sai Pavan Boddu] This was my V1 implementation.
Changed it to non-qom structure after some feedback from @Gred. Felt like XHCIState will not be used standalone.

I'll gladly defer to Gerd's judgement here.

#17 lore raw

Re: [PATCH v2 3/3] usb/hcd-xhci: Split pci wrapper for xhci base model

In reply to Sai Pavan Boddu

Hi,

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line

Do you intend to add a "sysbus model" in a future patch?

[Sai Pavan Boddu] Yes. I would be sending it along with that a device which would be using it. (i.e for zynqmp soc ) Let me know, if its good to

include hcd-xhci-sysbus.c here ?

I think this would be useful, to see how the code separation plays out on the sysbus side.

Quoted 13 lines
Quoted 7 lines

Here's a clean way to provide different bus connectors (say PCI and sysbus) for the same core device:

Make the core device a TYPE_DEVICE.

For each desired bus, have a bus-specific device that contains a core device. Use object_initialize_child() for the component.

This was my V1 implementation.
Changed it to non-qom structure after some feedback from @Gred. Felt like XHCIState will not be used standalone.

Quoted 2 lines

Example: core device TYPE_SERIAL, PCI device TYPE_PCI_SERIAL, ISA device TYPE_ISA_SERIAL, sysbus devices TYPE_SERIAL_IO. TYPE_SERIAL_MM.

/me goes check out the serial code ...

For reference: commit which transforms serial into the structure above is this:

commit 7781b88ee458ff933459503ade0b0a6ddaad08de
Author: Marc-André Lureau <[email protected]>
Date: Mon Oct 21 23:32:12 2019 +0200

serial: initial qom-ification

Note that this patch doesn't change structs, so ISASerialState still looks this way:

struct ISASerialState {
    ISADevice parent_obj;
    [ ... ]
    SerialState state;
};

So you can likewise keep your current "struct XHCIPciState" struct layout and still turn XHCIState into a device object. Which is nice to have as it better models the hardware (xhci core behind pci connector).

take care,
Gerd

#18 lore raw

RE: [PATCH v2 3/3] usb/hcd-xhci: Split pci wrapper for xhci base model

Hi Gred,

Quoted 62 lines

-----Original Message-----
From: Gerd Hoffmann <[email protected]>
Sent: Tuesday, June 30, 2020 1:09 AM
To: Sai Pavan Boddu <[email protected]>
Cc: Markus Armbruster <[email protected]>; Peter Maydell <[email protected]>; Thomas Huth <[email protected]>; Eduardo Habkost <[email protected]>; [email protected]; Alistair Francis <[email protected]>; Paolo Bonzini <[email protected]>; Ying Fang <[email protected]>; 'Marc-André Lureau' <[email protected]>; 'Philippe Mathieu-Daudé' <[email protected]>
Subject: Re: [PATCH v2 3/3] usb/hcd-xhci: Split pci wrapper for xhci base model

Hi,

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

Do you intend to add a "sysbus model" in a future patch?

[Sai Pavan Boddu] Yes. I would be sending it along with that a device which would be using it. (i.e for zynqmp soc ) Let me know, if its good to

include hcd-xhci-sysbus.c here ?

I think this would be useful, to see how the code separation plays out on the sysbus side.

Quoted 6 lines
Quoted 6 lines

Here's a clean way to provide different bus connectors (say PCI and sysbus) for the same core device:

Make the core device a TYPE_DEVICE.

For each desired bus, have a bus-specific device that contains a core

device.

Quoted 4 lines
Quoted 1 line

Use object_initialize_child() for the component.

This was my V1 implementation.
Changed it to non-qom structure after some feedback from @Gred. Felt

like XHCIState will not be used standalone.

Quoted 2 lines
Quoted 2 lines

Example: core device TYPE_SERIAL, PCI device TYPE_PCI_SERIAL, ISA device TYPE_ISA_SERIAL, sysbus devices TYPE_SERIAL_IO.

TYPE_SERIAL_MM.

/me goes check out the serial code ...

For reference: commit which transforms serial into the structure above is this:

commit 7781b88ee458ff933459503ade0b0a6ddaad08de
Author: Marc-André Lureau <[email protected]>
Date: Mon Oct 21 23:32:12 2019 +0200

serial: initial qom-ification

Note that this patch doesn't change structs, so ISASerialState still looks this way:

struct ISASerialState {
    ISADevice parent_obj;
    [ ... ]
    SerialState state;
};
Quoted 3 lines

So you can likewise keep your current "struct XHCIPciState" struct layout and still turn XHCIState into a device object. Which is nice to have as it better models the hardware (xhci core behind pci connector).

[Sai Pavan Boddu] Ok, as marcus pointed. We might be able to use it just as, child of a pci/sysbus based controller. Rather than using it standalone. I agree it looks nice that way.

Thanks,
Sai Pavan

Quoted 3 lines

take care,
Gerd