thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
958e1b
From d7852bf27b3c4bb0fa932d171325c3d386550ebe Mon Sep 17 00:00:00 2001
958e1b
From: Gerd Hoffmann <kraxel@redhat.com>
958e1b
Date: Fri, 11 Jul 2014 14:20:35 +0200
958e1b
Subject: [PATCH 02/43] usb/hcd-xhci: QOM parent field cleanup
958e1b
MIME-Version: 1.0
958e1b
Content-Type: text/plain; charset=UTF-8
958e1b
Content-Transfer-Encoding: 8bit
958e1b
958e1b
Message-id: <1405088470-24115-3-git-send-email-kraxel@redhat.com>
958e1b
Patchwork-id: 59826
958e1b
O-Subject: [RHEL-7.1 qemu-kvm PATCH 02/37] usb/hcd-xhci: QOM parent field cleanup
958e1b
Bugzilla: 980747
958e1b
RH-Acked-by: Dr. David Alan Gilbert (git) <dgilbert@redhat.com>
958e1b
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
958e1b
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
958e1b
958e1b
From: Andreas Färber <afaerber@suse.de>
958e1b
958e1b
Replace direct uses of XHCIState::pci_dev with QOM casts and rename it
958e1b
to parent_obj.
958e1b
958e1b
Acked-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
958e1b
Signed-off-by: Andreas Färber <afaerber@suse.de>
958e1b
(cherry picked from commit 9b7d3334d062e8c9e4f1b0ad3df35abb08cd8bf0)
958e1b
---
958e1b
 hw/usb/hcd-xhci.c | 83 ++++++++++++++++++++++++++++++++-----------------------
958e1b
 1 file changed, 48 insertions(+), 35 deletions(-)
958e1b
958e1b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
958e1b
---
958e1b
 hw/usb/hcd-xhci.c | 83 ++++++++++++++++++++++++++++++++-----------------------
958e1b
 1 file changed, 48 insertions(+), 35 deletions(-)
958e1b
958e1b
diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
958e1b
index 8fa1c6e..724c412 100644
958e1b
--- a/hw/usb/hcd-xhci.c
958e1b
+++ b/hw/usb/hcd-xhci.c
958e1b
@@ -446,7 +446,10 @@ typedef struct XHCIInterrupter {
958e1b
 } XHCIInterrupter;
958e1b
 
958e1b
 struct XHCIState {
958e1b
-    PCIDevice pci_dev;
958e1b
+    /*< private >*/
958e1b
+    PCIDevice parent_obj;
958e1b
+    /*< public >*/
958e1b
+
958e1b
     USBBus bus;
958e1b
     qemu_irq irq;
958e1b
     MemoryRegion mem;
958e1b
@@ -662,7 +665,7 @@ static inline void xhci_dma_read_u32s(XHCIState *xhci, dma_addr_t addr,
958e1b
 
958e1b
     assert((len % sizeof(uint32_t)) == 0);
958e1b
 
958e1b
-    pci_dma_read(&xhci->pci_dev, addr, buf, len);
958e1b
+    pci_dma_read(PCI_DEVICE(xhci), addr, buf, len);
958e1b
 
958e1b
     for (i = 0; i < (len / sizeof(uint32_t)); i++) {
958e1b
         buf[i] = le32_to_cpu(buf[i]);
958e1b
@@ -680,7 +683,7 @@ static inline void xhci_dma_write_u32s(XHCIState *xhci, dma_addr_t addr,
958e1b
     for (i = 0; i < (len / sizeof(uint32_t)); i++) {
958e1b
         tmp[i] = cpu_to_le32(buf[i]);
958e1b
     }
958e1b
-    pci_dma_write(&xhci->pci_dev, addr, tmp, len);
958e1b
+    pci_dma_write(PCI_DEVICE(xhci), addr, tmp, len);
958e1b
 }
958e1b
 
958e1b
 static XHCIPort *xhci_lookup_port(XHCIState *xhci, struct USBPort *uport)
958e1b
@@ -707,10 +710,11 @@ static XHCIPort *xhci_lookup_port(XHCIState *xhci, struct USBPort *uport)
958e1b
 
958e1b
 static void xhci_intx_update(XHCIState *xhci)
958e1b
 {
958e1b
+    PCIDevice *pci_dev = PCI_DEVICE(xhci);
958e1b
     int level = 0;
958e1b
 
958e1b
-    if (msix_enabled(&xhci->pci_dev) ||
958e1b
-        msi_enabled(&xhci->pci_dev)) {
958e1b
+    if (msix_enabled(pci_dev) ||
958e1b
+        msi_enabled(pci_dev)) {
958e1b
         return;
958e1b
     }
958e1b
 
958e1b
@@ -726,9 +730,10 @@ static void xhci_intx_update(XHCIState *xhci)
958e1b
 
958e1b
 static void xhci_msix_update(XHCIState *xhci, int v)
958e1b
 {
958e1b
+    PCIDevice *pci_dev = PCI_DEVICE(xhci);
958e1b
     bool enabled;
958e1b
 
958e1b
-    if (!msix_enabled(&xhci->pci_dev)) {
958e1b
+    if (!msix_enabled(pci_dev)) {
958e1b
         return;
958e1b
     }
958e1b
 
958e1b
@@ -739,17 +744,19 @@ static void xhci_msix_update(XHCIState *xhci, int v)
958e1b
 
958e1b
     if (enabled) {
958e1b
         trace_usb_xhci_irq_msix_use(v);
958e1b
-        msix_vector_use(&xhci->pci_dev, v);
958e1b
+        msix_vector_use(pci_dev, v);
958e1b
         xhci->intr[v].msix_used = true;
958e1b
     } else {
958e1b
         trace_usb_xhci_irq_msix_unuse(v);
958e1b
-        msix_vector_unuse(&xhci->pci_dev, v);
958e1b
+        msix_vector_unuse(pci_dev, v);
958e1b
         xhci->intr[v].msix_used = false;
958e1b
     }
958e1b
 }
958e1b
 
958e1b
 static void xhci_intr_raise(XHCIState *xhci, int v)
958e1b
 {
958e1b
+    PCIDevice *pci_dev = PCI_DEVICE(xhci);
958e1b
+
958e1b
     xhci->intr[v].erdp_low |= ERDP_EHB;
958e1b
     xhci->intr[v].iman |= IMAN_IP;
958e1b
     xhci->usbsts |= USBSTS_EINT;
958e1b
@@ -762,15 +769,15 @@ static void xhci_intr_raise(XHCIState *xhci, int v)
958e1b
         return;
958e1b
     }
958e1b
 
958e1b
-    if (msix_enabled(&xhci->pci_dev)) {
958e1b
+    if (msix_enabled(pci_dev)) {
958e1b
         trace_usb_xhci_irq_msix(v);
958e1b
-        msix_notify(&xhci->pci_dev, v);
958e1b
+        msix_notify(pci_dev, v);
958e1b
         return;
958e1b
     }
958e1b
 
958e1b
-    if (msi_enabled(&xhci->pci_dev)) {
958e1b
+    if (msi_enabled(pci_dev)) {
958e1b
         trace_usb_xhci_irq_msi(v);
958e1b
-        msi_notify(&xhci->pci_dev, v);
958e1b
+        msi_notify(pci_dev, v);
958e1b
         return;
958e1b
     }
958e1b
 
958e1b
@@ -793,6 +800,7 @@ static void xhci_die(XHCIState *xhci)
958e1b
 
958e1b
 static void xhci_write_event(XHCIState *xhci, XHCIEvent *event, int v)
958e1b
 {
958e1b
+    PCIDevice *pci_dev = PCI_DEVICE(xhci);
958e1b
     XHCIInterrupter *intr = &xhci->intr[v];
958e1b
     XHCITRB ev_trb;
958e1b
     dma_addr_t addr;
958e1b
@@ -811,7 +819,7 @@ static void xhci_write_event(XHCIState *xhci, XHCIEvent *event, int v)
958e1b
                                ev_trb.status, ev_trb.control);
958e1b
 
958e1b
     addr = intr->er_start + TRB_SIZE*intr->er_ep_idx;
958e1b
-    pci_dma_write(&xhci->pci_dev, addr, &ev_trb, TRB_SIZE);
958e1b
+    pci_dma_write(pci_dev, addr, &ev_trb, TRB_SIZE);
958e1b
 
958e1b
     intr->er_ep_idx++;
958e1b
     if (intr->er_ep_idx >= intr->er_size) {
958e1b
@@ -958,9 +966,11 @@ static void xhci_ring_init(XHCIState *xhci, XHCIRing *ring,
958e1b
 static TRBType xhci_ring_fetch(XHCIState *xhci, XHCIRing *ring, XHCITRB *trb,
958e1b
                                dma_addr_t *addr)
958e1b
 {
958e1b
+    PCIDevice *pci_dev = PCI_DEVICE(xhci);
958e1b
+
958e1b
     while (1) {
958e1b
         TRBType type;
958e1b
-        pci_dma_read(&xhci->pci_dev, ring->dequeue, trb, TRB_SIZE);
958e1b
+        pci_dma_read(pci_dev, ring->dequeue, trb, TRB_SIZE);
958e1b
         trb->addr = ring->dequeue;
958e1b
         trb->ccs = ring->ccs;
958e1b
         le64_to_cpus(&trb->parameter);
958e1b
@@ -993,6 +1003,7 @@ static TRBType xhci_ring_fetch(XHCIState *xhci, XHCIRing *ring, XHCITRB *trb,
958e1b
 
958e1b
 static int xhci_ring_chain_length(XHCIState *xhci, const XHCIRing *ring)
958e1b
 {
958e1b
+    PCIDevice *pci_dev = PCI_DEVICE(xhci);
958e1b
     XHCITRB trb;
958e1b
     int length = 0;
958e1b
     dma_addr_t dequeue = ring->dequeue;
958e1b
@@ -1002,7 +1013,7 @@ static int xhci_ring_chain_length(XHCIState *xhci, const XHCIRing *ring)
958e1b
 
958e1b
     while (1) {
958e1b
         TRBType type;
958e1b
-        pci_dma_read(&xhci->pci_dev, dequeue, &trb, TRB_SIZE);
958e1b
+        pci_dma_read(pci_dev, dequeue, &trb, TRB_SIZE);
958e1b
         le64_to_cpus(&trb.parameter);
958e1b
         le32_to_cpus(&trb.status);
958e1b
         le32_to_cpus(&trb.control);
958e1b
@@ -1054,7 +1065,7 @@ static void xhci_er_reset(XHCIState *xhci, int v)
958e1b
         return;
958e1b
     }
958e1b
     dma_addr_t erstba = xhci_addr64(intr->erstba_low, intr->erstba_high);
958e1b
-    pci_dma_read(&xhci->pci_dev, erstba, &seg, sizeof(seg));
958e1b
+    pci_dma_read(PCI_DEVICE(xhci), erstba, &seg, sizeof(seg));
958e1b
     le32_to_cpus(&seg.addr_low);
958e1b
     le32_to_cpus(&seg.addr_high);
958e1b
     le32_to_cpus(&seg.size);
958e1b
@@ -1528,7 +1539,7 @@ static int xhci_xfer_create_sgl(XHCITransfer *xfer, int in_xfer)
958e1b
     int i;
958e1b
 
958e1b
     xfer->int_req = false;
958e1b
-    pci_dma_sglist_init(&xfer->sgl, &xhci->pci_dev, xfer->trb_count);
958e1b
+    pci_dma_sglist_init(&xfer->sgl, PCI_DEVICE(xhci), xfer->trb_count);
958e1b
     for (i = 0; i < xfer->trb_count; i++) {
958e1b
         XHCITRB *trb = &xfer->trbs[i];
958e1b
         dma_addr_t addr;
958e1b
@@ -2144,7 +2155,7 @@ static TRBCCode xhci_address_slot(XHCIState *xhci, unsigned int slotid,
958e1b
     assert(slotid >= 1 && slotid <= xhci->numslots);
958e1b
 
958e1b
     dcbaap = xhci_addr64(xhci->dcbaap_low, xhci->dcbaap_high);
958e1b
-    poctx = ldq_le_pci_dma(&xhci->pci_dev, dcbaap + 8*slotid);
958e1b
+    poctx = ldq_le_pci_dma(PCI_DEVICE(xhci), dcbaap + 8 * slotid);
958e1b
     ictx = xhci_mask64(pictx);
958e1b
     octx = xhci_mask64(poctx);
958e1b
 
958e1b
@@ -2465,7 +2476,7 @@ static TRBCCode xhci_get_port_bandwidth(XHCIState *xhci, uint64_t pctx)
958e1b
     /* TODO: actually implement real values here */
958e1b
     bw_ctx[0] = 0;
958e1b
     memset(&bw_ctx[1], 80, xhci->numports); /* 80% */
958e1b
-    pci_dma_write(&xhci->pci_dev, ctx, bw_ctx, sizeof(bw_ctx));
958e1b
+    pci_dma_write(PCI_DEVICE(xhci), ctx, bw_ctx, sizeof(bw_ctx));
958e1b
 
958e1b
     return CC_SUCCESS;
958e1b
 }
958e1b
@@ -2488,11 +2499,12 @@ static uint32_t xhci_nec_challenge(uint32_t hi, uint32_t lo)
958e1b
 
958e1b
 static void xhci_via_challenge(XHCIState *xhci, uint64_t addr)
958e1b
 {
958e1b
+    PCIDevice *pci_dev = PCI_DEVICE(xhci);
958e1b
     uint32_t buf[8];
958e1b
     uint32_t obuf[8];
958e1b
     dma_addr_t paddr = xhci_mask64(addr);
958e1b
 
958e1b
-    pci_dma_read(&xhci->pci_dev, paddr, &buf, 32);
958e1b
+    pci_dma_read(pci_dev, paddr, &buf, 32);
958e1b
 
958e1b
     memcpy(obuf, buf, sizeof(obuf));
958e1b
 
958e1b
@@ -2508,7 +2520,7 @@ static void xhci_via_challenge(XHCIState *xhci, uint64_t addr)
958e1b
         obuf[7] = obuf[2] ^ obuf[3] ^ 0x65866593;
958e1b
     }
958e1b
 
958e1b
-    pci_dma_write(&xhci->pci_dev, paddr, &obuf, 32);
958e1b
+    pci_dma_write(pci_dev, paddr, &obuf, 32);
958e1b
 }
958e1b
 
958e1b
 static void xhci_process_commands(XHCIState *xhci)
958e1b
@@ -3372,10 +3384,10 @@ static int usb_xhci_initfn(struct PCIDevice *dev)
958e1b
 
958e1b
     XHCIState *xhci = XHCI(dev);
958e1b
 
958e1b
-    xhci->pci_dev.config[PCI_CLASS_PROG] = 0x30;    /* xHCI */
958e1b
-    xhci->pci_dev.config[PCI_INTERRUPT_PIN] = 0x01; /* interrupt pin 1 */
958e1b
-    xhci->pci_dev.config[PCI_CACHE_LINE_SIZE] = 0x10;
958e1b
-    xhci->pci_dev.config[0x60] = 0x30; /* release number */
958e1b
+    dev->config[PCI_CLASS_PROG] = 0x30;    /* xHCI */
958e1b
+    dev->config[PCI_INTERRUPT_PIN] = 0x01; /* interrupt pin 1 */
958e1b
+    dev->config[PCI_CACHE_LINE_SIZE] = 0x10;
958e1b
+    dev->config[0x60] = 0x30; /* release number */
958e1b
 
958e1b
     usb_xhci_init(xhci);
958e1b
 
958e1b
@@ -3397,7 +3409,7 @@ static int usb_xhci_initfn(struct PCIDevice *dev)
958e1b
 
958e1b
     xhci->mfwrap_timer = qemu_new_timer_ns(vm_clock, xhci_mfwrap_timer, xhci);
958e1b
 
958e1b
-    xhci->irq = xhci->pci_dev.irq[0];
958e1b
+    xhci->irq = dev->irq[0];
958e1b
 
958e1b
     memory_region_init(&xhci->mem, "xhci", LEN_REGS);
958e1b
     memory_region_init_io(&xhci->mem_cap, &xhci_cap_ops, xhci,
958e1b
@@ -3423,18 +3435,18 @@ static int usb_xhci_initfn(struct PCIDevice *dev)
958e1b
         memory_region_add_subregion(&xhci->mem, offset, &port->mem);
958e1b
     }
958e1b
 
958e1b
-    pci_register_bar(&xhci->pci_dev, 0,
958e1b
+    pci_register_bar(dev, 0,
958e1b
                      PCI_BASE_ADDRESS_SPACE_MEMORY|PCI_BASE_ADDRESS_MEM_TYPE_64,
958e1b
                      &xhci->mem);
958e1b
 
958e1b
-    ret = pcie_endpoint_cap_init(&xhci->pci_dev, 0xa0);
958e1b
+    ret = pcie_endpoint_cap_init(dev, 0xa0);
958e1b
     assert(ret >= 0);
958e1b
 
958e1b
     if (xhci->flags & (1 << XHCI_FLAG_USE_MSI)) {
958e1b
-        msi_init(&xhci->pci_dev, 0x70, xhci->numintrs, true, false);
958e1b
+        msi_init(dev, 0x70, xhci->numintrs, true, false);
958e1b
     }
958e1b
     if (xhci->flags & (1 << XHCI_FLAG_USE_MSI_X)) {
958e1b
-        msix_init(&xhci->pci_dev, xhci->numintrs,
958e1b
+        msix_init(dev, xhci->numintrs,
958e1b
                   &xhci->mem, 0, OFF_MSIX_TABLE,
958e1b
                   &xhci->mem, 0, OFF_MSIX_PBA,
958e1b
                   0x90);
958e1b
@@ -3446,6 +3458,7 @@ static int usb_xhci_initfn(struct PCIDevice *dev)
958e1b
 static int usb_xhci_post_load(void *opaque, int version_id)
958e1b
 {
958e1b
     XHCIState *xhci = opaque;
958e1b
+    PCIDevice *pci_dev = PCI_DEVICE(xhci);
958e1b
     XHCISlot *slot;
958e1b
     XHCIEPContext *epctx;
958e1b
     dma_addr_t dcbaap, pctx;
958e1b
@@ -3461,7 +3474,7 @@ static int usb_xhci_post_load(void *opaque, int version_id)
958e1b
             continue;
958e1b
         }
958e1b
         slot->ctx =
958e1b
-            xhci_mask64(ldq_le_pci_dma(&xhci->pci_dev, dcbaap + 8*slotid));
958e1b
+            xhci_mask64(ldq_le_pci_dma(pci_dev, dcbaap + 8 * slotid));
958e1b
         xhci_dma_read_u32s(xhci, slot->ctx, slot_ctx, sizeof(slot_ctx));
958e1b
         slot->uport = xhci_lookup_uport(xhci, slot_ctx);
958e1b
         assert(slot->uport && slot->uport->dev);
958e1b
@@ -3486,9 +3499,9 @@ static int usb_xhci_post_load(void *opaque, int version_id)
958e1b
 
958e1b
     for (intr = 0; intr < xhci->numintrs; intr++) {
958e1b
         if (xhci->intr[intr].msix_used) {
958e1b
-            msix_vector_use(&xhci->pci_dev, intr);
958e1b
+            msix_vector_use(pci_dev, intr);
958e1b
         } else {
958e1b
-            msix_vector_unuse(&xhci->pci_dev, intr);
958e1b
+            msix_vector_unuse(pci_dev, intr);
958e1b
         }
958e1b
     }
958e1b
 
958e1b
@@ -3593,8 +3606,8 @@ static const VMStateDescription vmstate_xhci = {
958e1b
     .version_id = 1,
958e1b
     .post_load = usb_xhci_post_load,
958e1b
     .fields = (VMStateField[]) {
958e1b
-        VMSTATE_PCIE_DEVICE(pci_dev, XHCIState),
958e1b
-        VMSTATE_MSIX(pci_dev, XHCIState),
958e1b
+        VMSTATE_PCIE_DEVICE(parent_obj, XHCIState),
958e1b
+        VMSTATE_MSIX(parent_obj, XHCIState),
958e1b
 
958e1b
         VMSTATE_STRUCT_VARRAY_UINT32(ports, XHCIState, numports, 1,
958e1b
                                      vmstate_xhci_port, XHCIPort),
958e1b
-- 
958e1b
1.8.3.1
958e1b