Skip to contentSkip to conversation

spapr: Small patches to prepare for Dynamic DMA windows

PATCH In review Alexey Kardashevskiy 2 participants 18 messages Feb 23, 2015 – Mar 24, 2015

lore
Share & tools
lore
#0 lore raw

cover spapr: Small patches to prepare for Dynamic DMA windows

These I have in my DDW working tree for quite a while, while I am polishing others, there could go to some tree already.

Please comment. Thanks!

Alexey Kardashevskiy (10):
spapr_iommu: Disable in-kernel IOMMU tables for >4GB windows
spapr_iommu: Make H_PUT_TCE_INDIRECT endian-safe
spapr_pci: Introduce a liobn number generating macros
spapr_vio: Introduce a liobn number generating macros
spapr_pci: Define default DMA window size as a macro
spapr_iommu: Add separate trace points for PCI DMA operations
spapr_pci: Make find_phb()/find_dev() public
spapr_iommu: Make spapr_tce_find_by_liobn() public
spapr_pci: Rework device-tree rendering
spapr_iommu: Give unique QOM name to TCE table

 hw/ppc/spapr_iommu.c        | 44 +++++++++++++++++++++------------
 hw/ppc/spapr_pci.c          | 60 +++++++++++++++------------------------------
 hw/ppc/spapr_vio.c          |  2 +-
 include/hw/pci-host/spapr.h |  6 +++++
 include/hw/ppc/spapr.h      |  7 +++++-
 trace-events                |  4 +++
 6 files changed, 66 insertions(+), 57 deletions(-)
Signature · 1 line
2.0.0
#1 lore raw

PATCH 1/10 spapr_iommu: Disable in-kernel IOMMU tables for >4GB windows

The existing KVM_CREATE_SPAPR_TCE ioctl only support 4G windows max as the window size parameter to the kernel ioctl() is 32-bit so there's no way of expressing a TCE window > 4GB.

We are going to add huge DMA windows support so this will create small window and unexpectedly fail later.

This disables KVM_CREATE_SPAPR_TCE for windows bigger that 4GB.

---
Changes:
v3:
* fixed commit log
* added cast to uint64_t

---
 hw/ppc/spapr_iommu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/ppc/spapr_iommu.c +3 -3
index f9f85c5..4de6ba1 100644
@@ -125,11 +125,11 @@ static MemoryRegionIOMMUOps spapr_iommu_ops = {
 static int spapr_tce_table_realize(DeviceState *dev)
 {
     sPAPRTCETable *tcet = SPAPR_TCE_TABLE(dev);
+    uint64_t window_size = (uint64_t)tcet->nb_table << tcet->page_shift;
 
-    if (kvm_enabled()) {
+    if (kvm_enabled() && !(window_size >> 32)) {
         tcet->table = kvmppc_create_spapr_tce(tcet->liobn,
-                                              tcet->nb_table <<
-                                              tcet->page_shift,
+                                              window_size,
                                               &tcet->fd,
                                               tcet->vfio_accel);
     }
Signature · 1 line
2.0.0
#2 lore raw

PATCH 2/10 spapr_iommu: Make H_PUT_TCE_INDIRECT endian-safe

In reply to Alexey Kardashevskiy

PAPR is defined as big endian so TCEs need an adjustment so does this patch.

This changes code to have ldq_be_phys() in one place.

---
 hw/ppc/spapr_iommu.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
hw/ppc/spapr_iommu.c +3 -4
index 4de6ba1..4b857e8 100644
@@ -246,7 +246,7 @@ static target_ulong h_put_tce_indirect(PowerPCCPU *cpu,
     target_ulong ioba1 = ioba;
     target_ulong tce_list = args[2];
     target_ulong npages = args[3];
-    target_ulong ret = H_PARAMETER;
+    target_ulong ret = H_PARAMETER, tce = 0;
     sPAPRTCETable *tcet = spapr_tce_find_by_liobn(liobn);
     CPUState *cs = CPU(cpu);
     hwaddr page_mask, page_size;
@@ -266,7 +266,7 @@ static target_ulong h_put_tce_indirect(PowerPCCPU *cpu,
     for (i = 0; i < npages; ++i, ioba += page_size) {
         target_ulong off = (tce_list & ~SPAPR_TCE_RW) +
                                 i * sizeof(target_ulong);
-        target_ulong tce = ldq_phys(cs->as, off);
+        tce = ldq_be_phys(cs->as, off);
 
         ret = put_tce_emu(tcet, ioba, tce);
         if (ret) {
@@ -277,8 +277,7 @@ static target_ulong h_put_tce_indirect(PowerPCCPU *cpu,
     /* Trace last successful or the first problematic entry */
     i = i ? (i - 1) : 0;
     trace_spapr_iommu_indirect(liobn, ioba1, tce_list, i,
-                               ldq_phys(cs->as,
-                               tce_list + i * sizeof(target_ulong)),
+                               tce,
                                ret);
 
     return ret;
Signature · 1 line
2.0.0
#3 lore raw

PATCH 3/10 spapr_pci: Introduce a liobn number generating macros

In reply to Alexey Kardashevskiy

We are going to have multiple DMA windows per PHB and we want them to migrate so we need a predictable way of assigning LIOBNs.

This introduces a macro which makes up a LIOBN from fixed prefix, PHB index (unique PHB id) and window number.

This introduces a SPAPR_PCI_DMA_WINDOW_NUM() to know the window number from LIOBN. It is used to distinguish the default 32bit windows from dynamic windows and avoid picking default DMA window properties from a wrong TCE table.

---
Changes:
v5:
* renamed parameters in SPAPR_PCI_LIOBN()

---
 hw/ppc/spapr_pci.c     | 4 ++--
 include/hw/ppc/spapr.h | 4 +++-
 2 files changed, 5 insertions(+), 3 deletions(-)
hw/ppc/spapr_pci.c +2 -2
index cebdeb3..388fd53 100644
@@ -508,7 +508,7 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)
         }
 
         sphb->buid = SPAPR_PCI_BASE_BUID + sphb->index;
-        sphb->dma_liobn = SPAPR_PCI_BASE_LIOBN + sphb->index;
+        sphb->dma_liobn = SPAPR_PCI_LIOBN(sphb->index, 0);
 
         windows_base = SPAPR_PCI_WINDOW_BASE
             + sphb->index * SPAPR_PCI_WINDOW_SPACING;
@@ -849,7 +849,7 @@ static int spapr_phb_children_dt(Object *child, void *opaque)
     sPAPRTCETable *tcet;
 
     tcet = (sPAPRTCETable *) object_dynamic_cast(child, TYPE_SPAPR_TCE_TABLE);
-    if (!tcet) {
+    if (!tcet || SPAPR_PCI_DMA_WINDOW_NUM(tcet->liobn)) {
         return 0;
     }
 
include/hw/ppc/spapr.h +3 -1
index a8e6817..6c702ca 100644
@@ -443,7 +443,9 @@ int spapr_rtas_device_tree_setup(void *fdt, hwaddr rtas_addr,
 #define SPAPR_TCE_PAGE_MASK    (SPAPR_TCE_PAGE_SIZE - 1)
 
 #define SPAPR_VIO_BASE_LIOBN    0x00000000
-#define SPAPR_PCI_BASE_LIOBN    0x80000000
+#define SPAPR_PCI_LIOBN(phb_index, window_num) \
+    (0x80000000 | ((phb_index) << 8) | (window_num))
+#define SPAPR_PCI_DMA_WINDOW_NUM(liobn) ((liobn) & 0xff)
 
 #define RTAS_ERROR_LOG_MAX      2048
 
Signature · 1 line
2.0.0
#4 lore raw

PATCH 4/10 spapr_vio: Introduce a liobn number generating macros

In reply to Alexey Kardashevskiy

This introduces a macro which makes up a LIOBN from fixed prefix and VIO device address (@reg property).

This is to keep LIOBN macros rendering consistent - the same macro for PCI has been added by the previous patch.

---
 hw/ppc/spapr_vio.c     | 2 +-
 include/hw/ppc/spapr.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
hw/ppc/spapr_vio.c +1 -1
index 245cdd7..8baab0a 100644
@@ -468,7 +468,7 @@ static int spapr_vio_busdev_init(DeviceState *qdev)
     }
 
     if (pc->rtce_window_size) {
-        uint32_t liobn = SPAPR_VIO_BASE_LIOBN | dev->reg;
+        uint32_t liobn = SPAPR_VIO_LIOBN(dev->reg);
 
         memory_region_init(&dev->mrroot, OBJECT(dev), "iommu-spapr-root",
                            ram_size);
include/hw/ppc/spapr.h +1 -0
index 6c702ca..0dc72db 100644
@@ -443,6 +443,7 @@ int spapr_rtas_device_tree_setup(void *fdt, hwaddr rtas_addr,
 #define SPAPR_TCE_PAGE_MASK    (SPAPR_TCE_PAGE_SIZE - 1)
 
 #define SPAPR_VIO_BASE_LIOBN    0x00000000
+#define SPAPR_VIO_LIOBN(reg)    (0x00000000 | (reg))
 #define SPAPR_PCI_LIOBN(phb_index, window_num) \
     (0x80000000 | ((phb_index) << 8) | (window_num))
 #define SPAPR_PCI_DMA_WINDOW_NUM(liobn) ((liobn) & 0xff)
Signature · 1 line
2.0.0
#5 lore raw

PATCH 5/10 spapr_pci: Define default DMA window size as a macro

In reply to Alexey Kardashevskiy

This gets rid of a magic constant describing the default DMA window size for an emulated PHB.

---
 hw/ppc/spapr_pci.c          | 6 +++---
 include/hw/pci-host/spapr.h | 2 ++
 2 files changed, 5 insertions(+), 3 deletions(-)
hw/ppc/spapr_pci.c +3 -3
index 388fd53..130c532 100644
@@ -641,11 +641,11 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)
 static void spapr_phb_finish_realize(sPAPRPHBState *sphb, Error **errp)
 {
     sPAPRTCETable *tcet;
+    uint32_t nb_table;
 
+    nb_table = SPAPR_PCI_DMA32_SIZE >> SPAPR_TCE_PAGE_SHIFT;
     tcet = spapr_tce_new_table(DEVICE(sphb), sphb->dma_liobn,
-                               0,
-                               SPAPR_TCE_PAGE_SHIFT,
-                               0x40000000 >> SPAPR_TCE_PAGE_SHIFT, false);
+                               0, SPAPR_TCE_PAGE_SHIFT, nb_table, false);
     if (!tcet) {
         error_setg(errp, "Unable to create TCE table for %s",
                    sphb->dtbusname);
include/hw/pci-host/spapr.h +2 -0
index d725f0e..718bf59 100644
@@ -110,6 +110,8 @@ struct sPAPRPHBVFIOState {
 
 #define SPAPR_PCI_MSI_WINDOW         0x40000000000ULL
 
+#define SPAPR_PCI_DMA32_SIZE         0x40000000
+
 static inline qemu_irq spapr_phb_lsi_qirq(struct sPAPRPHBState *phb, int pin)
 {
     return xics_get_qirq(spapr->icp, phb->lsi_table[pin].irq);
Signature · 1 line
2.0.0
Reviewed-by on v1 5/10
#6 lore raw

Re: [Qemu-devel] [PATCH 05/10] spapr_pci: Define default DMA window size as a macro

Quoted 4 lines · Alexey Kardashevskiy

This gets rid of a magic constant describing the default DMA window size for an emulated PHB.

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

PATCH 6/10 spapr_iommu: Add separate trace points for PCI DMA operations

In reply to Alexey Kardashevskiy

This is to reduce VIO noise while debugging PCI DMA.

---
 hw/ppc/spapr_iommu.c   | 27 ++++++++++++++++++++-------
 include/hw/ppc/spapr.h |  1 +
 trace-events           |  4 ++++
 3 files changed, 25 insertions(+), 7 deletions(-)
hw/ppc/spapr_iommu.c +20 -7
index 4b857e8..1d6d4d8 100644
@@ -276,10 +276,11 @@ static target_ulong h_put_tce_indirect(PowerPCCPU *cpu,
 
     /* Trace last successful or the first problematic entry */
     i = i ? (i - 1) : 0;
-    trace_spapr_iommu_indirect(liobn, ioba1, tce_list, i,
-                               tce,
-                               ret);
-
+    if (SPAPR_IS_PCI_LIOBN(liobn)) {
+        trace_spapr_iommu_pci_indirect(liobn, ioba1, tce_list, i, tce, ret);
+    } else {
+        trace_spapr_iommu_indirect(liobn, ioba1, tce_list, i, tce, ret);
+    }
     return ret;
 }
 
@@ -313,7 +314,11 @@ static target_ulong h_stuff_tce(PowerPCCPU *cpu, sPAPREnvironment *spapr,
             break;
         }
     }
-    trace_spapr_iommu_stuff(liobn, ioba, tce_value, npages, ret);
+    if (SPAPR_IS_PCI_LIOBN(liobn)) {
+        trace_spapr_iommu_pci_stuff(liobn, ioba, tce_value, npages, ret);
+    } else {
+        trace_spapr_iommu_stuff(liobn, ioba, tce_value, npages, ret);
+    }
 
     return ret;
 }
@@ -334,7 +339,11 @@ static target_ulong h_put_tce(PowerPCCPU *cpu, sPAPREnvironment *spapr,
 
         ret = put_tce_emu(tcet, ioba, tce);
     }
-    trace_spapr_iommu_put(liobn, ioba, tce, ret);
+    if (SPAPR_IS_PCI_LIOBN(liobn)) {
+        trace_spapr_iommu_pci_put(liobn, ioba, tce, ret);
+    } else {
+        trace_spapr_iommu_put(liobn, ioba, tce, ret);
+    }
 
     return ret;
 }
@@ -374,7 +383,11 @@ static target_ulong h_get_tce(PowerPCCPU *cpu, sPAPREnvironment *spapr,
             args[0] = tce;
         }
     }
-    trace_spapr_iommu_get(liobn, ioba, ret, tce);
+    if (SPAPR_IS_PCI_LIOBN(liobn)) {
+        trace_spapr_iommu_pci_get(liobn, ioba, ret, tce);
+    } else {
+        trace_spapr_iommu_get(liobn, ioba, ret, tce);
+    }
 
     return ret;
 }
include/hw/ppc/spapr.h +1 -0
index 0dc72db..9fadbe0 100644
@@ -446,6 +446,7 @@ int spapr_rtas_device_tree_setup(void *fdt, hwaddr rtas_addr,
 #define SPAPR_VIO_LIOBN(reg)    (0x00000000 | (reg))
 #define SPAPR_PCI_LIOBN(phb_index, window_num) \
     (0x80000000 | ((phb_index) << 8) | (window_num))
+#define SPAPR_IS_PCI_LIOBN(liobn)   (!!((liobn) & 0x80000000))
 #define SPAPR_PCI_DMA_WINDOW_NUM(liobn) ((liobn) & 0xff)
 
 #define RTAS_ERROR_LOG_MAX      2048
trace-events +4 -0
index f87b077..481c30e 100644
@@ -1334,6 +1334,10 @@ spapr_iommu_put(uint64_t liobn, uint64_t ioba, uint64_t tce, uint64_t ret) "liob
 spapr_iommu_get(uint64_t liobn, uint64_t ioba, uint64_t ret, uint64_t tce) "liobn=%"PRIx64" ioba=0x%"PRIx64" ret=%"PRId64" tce=0x%"PRIx64
 spapr_iommu_indirect(uint64_t liobn, uint64_t ioba, uint64_t tce, uint64_t iobaN, uint64_t tceN, uint64_t ret) "liobn=%"PRIx64" ioba=0x%"PRIx64" tcelist=0x%"PRIx64" iobaN=0x%"PRIx64" tceN=0x%"PRIx64" ret=%"PRId64
 spapr_iommu_stuff(uint64_t liobn, uint64_t ioba, uint64_t tce_value, uint64_t npages, uint64_t ret) "liobn=%"PRIx64" ioba=0x%"PRIx64" tcevalue=0x%"PRIx64" npages=%"PRId64" ret=%"PRId64
+spapr_iommu_pci_put(uint64_t liobn, uint64_t ioba, uint64_t tce, uint64_t ret) "liobn=%"PRIx64" ioba=0x%"PRIx64" tce=0x%"PRIx64" ret=%"PRId64
+spapr_iommu_pci_get(uint64_t liobn, uint64_t ioba, uint64_t ret, uint64_t tce) "liobn=%"PRIx64" ioba=0x%"PRIx64" ret=%"PRId64" tce=0x%"PRIx64
+spapr_iommu_pci_indirect(uint64_t liobn, uint64_t ioba, uint64_t tce, uint64_t iobaN, uint64_t tceN, uint64_t ret) "liobn=%"PRIx64" ioba=0x%"PRIx64" tcelist=0x%"PRIx64" iobaN=0x%"PRIx64" tceN=0x%"PRIx64" ret=%"PRId64
+spapr_iommu_pci_stuff(uint64_t liobn, uint64_t ioba, uint64_t tce_value, uint64_t npages, uint64_t ret) "liobn=%"PRIx64" ioba=0x%"PRIx64" tcevalue=0x%"PRIx64" npages=%"PRId64" ret=%"PRId64
 spapr_iommu_xlate(uint64_t liobn, uint64_t ioba, uint64_t tce, unsigned perm, unsigned pgsize) "liobn=%"PRIx64" 0x%"PRIx64" -> 0x%"PRIx64" perm=%u mask=%x"
 spapr_iommu_new_table(uint64_t liobn, void *tcet, void *table, int fd) "liobn=%"PRIx64" tcet=%p table=%p fd=%d"
 
Signature · 1 line
2.0.0
Reviewed-by on v1 6/10
#8 lore raw

Re: [Qemu-devel] [PATCH 06/10] spapr_iommu: Add separate trace points for PCI DMA operations

Quoted 3 lines · Alexey Kardashevskiy

This is to reduce VIO noise while debugging PCI DMA.

So, in terms of mechanical correctness:

I see the rationale, but the idea of conditional tracepoints seems a bit icky to me. Don't know if the trace infrastructure people would have any opinion on this.

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
#9 lore raw

PATCH 7/10 spapr_pci: Make find_phb()/find_dev() public

In reply to Alexey Kardashevskiy

This makes find_phb()/find_dev() public and changed its names to spapr_pci_find_phb()/spapr_pci_find_dev() as they are going to be used from other parts of QEMU such as VFIO DDW (dynamic DMA window) or VFIO PCI error injection or VFIO EEH handling - in all these cases there are RTAS calls which are addressed to BUID+config_addr in IEEE1275 format.

---
 hw/ppc/spapr_pci.c          | 22 +++++++++++-----------
 include/hw/pci-host/spapr.h |  4 ++++
 2 files changed, 15 insertions(+), 11 deletions(-)
hw/ppc/spapr_pci.c +11 -11
index 130c532..040b901 100644
@@ -47,7 +47,7 @@
 #define RTAS_TYPE_MSI           1
 #define RTAS_TYPE_MSIX          2
 
-static sPAPRPHBState *find_phb(sPAPREnvironment *spapr, uint64_t buid)
+sPAPRPHBState *spapr_pci_find_phb(sPAPREnvironment *spapr, uint64_t buid)
 {
     sPAPRPHBState *sphb;
 
@@ -61,10 +61,10 @@ static sPAPRPHBState *find_phb(sPAPREnvironment *spapr, uint64_t buid)
     return NULL;
 }
 
-static PCIDevice *find_dev(sPAPREnvironment *spapr, uint64_t buid,
-                           uint32_t config_addr)
+PCIDevice *spapr_pci_find_dev(sPAPREnvironment *spapr, uint64_t buid,
+                              uint32_t config_addr)
 {
-    sPAPRPHBState *sphb = find_phb(spapr, buid);
+    sPAPRPHBState *sphb = spapr_pci_find_phb(spapr, buid);
     PCIHostState *phb = PCI_HOST_BRIDGE(sphb);
     int bus_num = (config_addr >> 16) & 0xFF;
     int devfn = (config_addr >> 8) & 0xFF;
@@ -95,7 +95,7 @@ static void finish_read_pci_config(sPAPREnvironment *spapr, uint64_t buid,
         return;
     }
 
-    pci_dev = find_dev(spapr, buid, addr);
+    pci_dev = spapr_pci_find_dev(spapr, buid, addr);
     addr = rtas_pci_cfgaddr(addr);
 
     if (!pci_dev || (addr % size) || (addr >= pci_config_size(pci_dev))) {
@@ -162,7 +162,7 @@ static void finish_write_pci_config(sPAPREnvironment *spapr, uint64_t buid,
         return;
     }
 
-    pci_dev = find_dev(spapr, buid, addr);
+    pci_dev = spapr_pci_find_dev(spapr, buid, addr);
     addr = rtas_pci_cfgaddr(addr);
 
     if (!pci_dev || (addr % size) || (addr >= pci_config_size(pci_dev))) {
@@ -280,9 +280,9 @@ static void rtas_ibm_change_msi(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     }
 
     /* Fins sPAPRPHBState */
-    phb = find_phb(spapr, buid);
+    phb = spapr_pci_find_phb(spapr, buid);
     if (phb) {
-        pdev = find_dev(spapr, buid, config_addr);
+        pdev = spapr_pci_find_dev(spapr, buid, config_addr);
     }
     if (!phb || !pdev) {
         rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
@@ -381,9 +381,9 @@ static void rtas_ibm_query_interrupt_source_number(PowerPCCPU *cpu,
     spapr_pci_msi *msi;
 
     /* Find sPAPRPHBState */
-    phb = find_phb(spapr, buid);
+    phb = spapr_pci_find_phb(spapr, buid);
     if (phb) {
-        pdev = find_dev(spapr, buid, config_addr);
+        pdev = spapr_pci_find_dev(spapr, buid, config_addr);
     }
     if (!phb || !pdev) {
         rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
@@ -536,7 +536,7 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    if (find_phb(spapr, sphb->buid)) {
+    if (spapr_pci_find_phb(spapr, sphb->buid)) {
         error_setg(errp, "PCI host bridges must have unique BUIDs");
         return;
     }
include/hw/pci-host/spapr.h +4 -0
index 718bf59..1fa63db 100644
@@ -127,4 +127,8 @@ void spapr_pci_msi_init(sPAPREnvironment *spapr, hwaddr addr);
 
 void spapr_pci_rtas_init(void);
 
+sPAPRPHBState *spapr_pci_find_phb(sPAPREnvironment *spapr, uint64_t buid);
+PCIDevice *spapr_pci_find_dev(sPAPREnvironment *spapr, uint64_t buid,
+                              uint32_t config_addr);
+
 #endif /* __HW_SPAPR_PCI_H__ */
Signature · 1 line
2.0.0
#10 lore raw

PATCH 8/10 spapr_iommu: Make spapr_tce_find_by_liobn() public

In reply to Alexey Kardashevskiy

At the moment spapr_tce_find_by_liobn() is used by H_PUT_TCE/... handlers to find an IOMMU by LIOBN.

We are going to implement Dynamic DMA windows (DDW), new code will go to a new file and we will use spapr_tce_find_by_liobn() there too so let's make it public.

---
 hw/ppc/spapr_iommu.c   | 2 +-
 include/hw/ppc/spapr.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
hw/ppc/spapr_iommu.c +1 -1
index 1d6d4d8..65ee001 100644
@@ -41,7 +41,7 @@ enum sPAPRTCEAccess {
 
 static QLIST_HEAD(spapr_tce_tables, sPAPRTCETable) spapr_tce_tables;
 
-static sPAPRTCETable *spapr_tce_find_by_liobn(uint32_t liobn)
+sPAPRTCETable *spapr_tce_find_by_liobn(uint32_t liobn)
 {
     sPAPRTCETable *tcet;
 
include/hw/ppc/spapr.h +1 -0
index 9fadbe0..45be9a6 100644
@@ -472,6 +472,7 @@ struct sPAPRTCETable {
     QLIST_ENTRY(sPAPRTCETable) list;
 };
 
+sPAPRTCETable *spapr_tce_find_by_liobn(uint32_t liobn);
 void spapr_events_init(sPAPREnvironment *spapr);
 void spapr_events_fdt_skel(void *fdt, uint32_t epow_irq);
 int spapr_h_cas_compose_response(target_ulong addr, target_ulong size);
Signature · 1 line
2.0.0
#11 lore raw

PATCH 9/10 spapr_pci: Rework device-tree rendering

In reply to Alexey Kardashevskiy

This replaces object_child_foreach() and callback with existing SPAPR_PCI_LIOBN() and spapr_tce_find_by_liobn() to make the code easier to read.

This is a mechanical patch so no behaviour change is expected.

---
 hw/ppc/spapr_pci.c | 30 +++++-------------------------
 1 file changed, 5 insertions(+), 25 deletions(-)
hw/ppc/spapr_pci.c +5 -25
index 040b901..5b53f4e 100644
@@ -838,29 +838,6 @@ PCIHostState *spapr_create_phb(sPAPREnvironment *spapr, int index)
 #define b_fff(x)        b_x((x), 8, 3)  /* function number */
 #define b_rrrrrrrr(x)   b_x((x), 0, 8)  /* register number */
 
-typedef struct sPAPRTCEDT {
-    void *fdt;
-    int node_off;
-} sPAPRTCEDT;
-
-static int spapr_phb_children_dt(Object *child, void *opaque)
-{
-    sPAPRTCEDT *p = opaque;
-    sPAPRTCETable *tcet;
-
-    tcet = (sPAPRTCETable *) object_dynamic_cast(child, TYPE_SPAPR_TCE_TABLE);
-    if (!tcet || SPAPR_PCI_DMA_WINDOW_NUM(tcet->liobn)) {
-        return 0;
-    }
-
-    spapr_dma_dt(p->fdt, p->node_off, "ibm,dma-window",
-                 tcet->liobn, tcet->bus_offset,
-                 tcet->nb_table << tcet->page_shift);
-    /* Stop after the first window */
-
-    return 1;
-}
-
 int spapr_populate_pci_dt(sPAPRPHBState *phb,
                           uint32_t xics_phandle,
                           void *fdt)
@@ -899,6 +876,7 @@ int spapr_populate_pci_dt(sPAPRPHBState *phb,
     uint32_t interrupt_map_mask[] = {
         cpu_to_be32(b_ddddd(-1)|b_fff(0)), 0x0, 0x0, cpu_to_be32(-1)};
     uint32_t interrupt_map[PCI_SLOT_MAX * PCI_NUM_PINS][7];
+    sPAPRTCETable *tcet;
 
     /* Start populating the FDT */
     sprintf(nodename, "pci@%" PRIx64, phb->buid);
@@ -951,8 +929,10 @@ int spapr_populate_pci_dt(sPAPRPHBState *phb,
     _FDT(fdt_setprop(fdt, bus_off, "interrupt-map", &interrupt_map,
                      sizeof(interrupt_map)));
 
-    object_child_foreach(OBJECT(phb), spapr_phb_children_dt,
-                         &((sPAPRTCEDT){ .fdt = fdt, .node_off = bus_off }));
+    tcet = spapr_tce_find_by_liobn(SPAPR_PCI_LIOBN(phb->index, 0));
+    spapr_dma_dt(fdt, bus_off, "ibm,dma-window",
+                 tcet->liobn, tcet->bus_offset,
+                 tcet->nb_table << tcet->page_shift);
 
     return 0;
 }
Signature · 1 line
2.0.0
Reviewed-by on v1 9/10
#12 lore raw

Re: [Qemu-devel] [PATCH 09/10] spapr_pci: Rework device-tree rendering

Quoted 7 lines · Alexey Kardashevskiy

This replaces object_child_foreach() and callback with existing SPAPR_PCI_LIOBN() and spapr_tce_find_by_liobn() to make the code easier to read.

This is a mechanical patch so no behaviour change is expected.

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
#13 lore raw

PATCH 10/10 spapr_iommu: Give unique QOM name to TCE table

In reply to Alexey Kardashevskiy

Useful for debugging.

---
 hw/ppc/spapr_iommu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/ppc/spapr_iommu.c +3 -1
index 65ee001..4f4836c 100644
@@ -160,6 +160,7 @@ sPAPRTCETable *spapr_tce_new_table(DeviceState *owner, uint32_t liobn,
                                    bool vfio_accel)
 {
     sPAPRTCETable *tcet;
+    char tmp[64];
 
     if (spapr_tce_find_by_liobn(liobn)) {
         fprintf(stderr, "Attempted to create TCE table with duplicate"
@@ -178,7 +179,8 @@ sPAPRTCETable *spapr_tce_new_table(DeviceState *owner, uint32_t liobn,
     tcet->nb_table = nb_table;
     tcet->vfio_accel = vfio_accel;
 
-    object_property_add_child(OBJECT(owner), "tce-table", OBJECT(tcet), NULL);
+    snprintf(tmp, sizeof(tmp), "tce-table-%x", liobn);
+    object_property_add_child(OBJECT(owner), tmp, OBJECT(tcet), NULL);
 
     object_property_set_bool(OBJECT(tcet), true, "realized", NULL);
 
Signature · 1 line
2.0.0
Reviewed-by on v1 10/10
#14 lore raw

Re: [Qemu-devel] [PATCH 10/10] spapr_iommu: Give unique QOM name to TCE table

Quoted 3 lines · Alexey Kardashevskiy

Useful for debugging.

Quoted 26 lines
---
 hw/ppc/spapr_iommu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/ppc/spapr_iommu.c +3 -1
index 65ee001..4f4836c 100644
@@ -160,6 +160,7 @@ sPAPRTCETable *spapr_tce_new_table(DeviceState *owner, uint32_t liobn,
                                    bool vfio_accel)
 {
     sPAPRTCETable *tcet;
+    char tmp[64];
 
     if (spapr_tce_find_by_liobn(liobn)) {
         fprintf(stderr, "Attempted to create TCE table with duplicate"
@@ -178,7 +179,8 @@ sPAPRTCETable *spapr_tce_new_table(DeviceState *owner, uint32_t liobn,
     tcet->nb_table = nb_table;
     tcet->vfio_accel = vfio_accel;
 
-    object_property_add_child(OBJECT(owner), "tce-table", OBJECT(tcet), NULL);
+    snprintf(tmp, sizeof(tmp), "tce-table-%x", liobn);
+    object_property_add_child(OBJECT(owner), tmp, OBJECT(tcet), NULL);
 
     object_property_set_bool(OBJECT(tcet), true, "realized", NULL);
 
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
#15 lore raw
In reply to Alexey Kardashevskiy
Quoted 4 lines · Alexey Kardashevskiy

These I have in my DDW working tree for quite a while, while I am polishing others, there could go to some tree already.

Please comment. Thanks!

Alex, ping.

"spapr_pci: Make find_phb()/find_dev() public" won't apply after Gavin's EEH patches but the others would, should I repost them together with DDW patches or separately or any other suggestion about these? Thanks.

Quoted 22 lines

Alexey Kardashevskiy (10):
spapr_iommu: Disable in-kernel IOMMU tables for >4GB windows
spapr_iommu: Make H_PUT_TCE_INDIRECT endian-safe
spapr_pci: Introduce a liobn number generating macros
spapr_vio: Introduce a liobn number generating macros
spapr_pci: Define default DMA window size as a macro
spapr_iommu: Add separate trace points for PCI DMA operations
spapr_pci: Make find_phb()/find_dev() public
spapr_iommu: Make spapr_tce_find_by_liobn() public
spapr_pci: Rework device-tree rendering
spapr_iommu: Give unique QOM name to TCE table

  hw/ppc/spapr_iommu.c        | 44 +++++++++++++++++++++------------
  hw/ppc/spapr_pci.c          | 60 +++++++++++++++------------------------------
  hw/ppc/spapr_vio.c          |  2 +-
  include/hw/pci-host/spapr.h |  6 +++++
  include/hw/ppc/spapr.h      |  7 +++++-
  trace-events                |  4 +++
  6 files changed, 66 insertions(+), 57 deletions(-)
Signature · 1 line
Alexey
#16 lore raw
Quoted 11 lines · Alexey Kardashevskiy
Quoted 4 lines · Alexey Kardashevskiy

These I have in my DDW working tree for quite a while, while I am polishing others, there could go to some tree already.

Please comment. Thanks!

Alex, ping.

"spapr_pci: Make find_phb()/find_dev() public" won't apply after Gavin's EEH patches but the others would, should I repost them together with DDW patches or separately or any other suggestion about these? Thanks.

Ping?
Do I need to repost those when I'll be posting next respin of DDW for QEMU or you can take them into your ppc-next-2.4? Thanks

Quoted 27 lines
Quoted 25 lines

Alexey Kardashevskiy (10):
spapr_iommu: Disable in-kernel IOMMU tables for >4GB windows
spapr_iommu: Make H_PUT_TCE_INDIRECT endian-safe
spapr_pci: Introduce a liobn number generating macros
spapr_vio: Introduce a liobn number generating macros
spapr_pci: Define default DMA window size as a macro
spapr_iommu: Add separate trace points for PCI DMA operations
spapr_pci: Make find_phb()/find_dev() public
spapr_iommu: Make spapr_tce_find_by_liobn() public
spapr_pci: Rework device-tree rendering
spapr_iommu: Give unique QOM name to TCE table

  hw/ppc/spapr_iommu.c        | 44 +++++++++++++++++++++------------
  hw/ppc/spapr_pci.c          | 60
+++++++++++++++------------------------------
  hw/ppc/spapr_vio.c          |  2 +-
  include/hw/pci-host/spapr.h |  6 +++++
  include/hw/ppc/spapr.h      |  7 +++++-
  trace-events                |  4 +++
  6 files changed, 66 insertions(+), 57 deletions(-)
Signature · 1 line
Alexey
#17 lore raw
Quoted 9 lines · Alexey Kardashevskiy
Quoted 8 lines · Alexey Kardashevskiy
Quoted 4 lines · Alexey Kardashevskiy

These I have in my DDW working tree for quite a while, while I am polishing others, there could go to some tree already.

Please comment. Thanks!

Alex, ping.

Quoted 8 lines
Quoted 3 lines

"spapr_pci: Make find_phb()/find_dev() public" won't apply after Gavin's EEH patches but the others would, should I repost them together with DDW patches or separately or any other suggestion about these? Thanks.

Ping?
Do I need to repost those when I'll be posting next respin of DDW for QEMU or you can take them into your ppc-next-2.4? Thanks

I've merged these into my new spapr-next tree (branch 'spapr-next' at
git://github.com/dgibson/qemu.git). I'll be pushing that tree to Alex in future.

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