All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/8] remove PnvPhb4PecStack from Powernv9
@ 2022-01-14 18:07 Daniel Henrique Barboza
  2022-01-14 18:07 ` [PATCH v2 1/8] ppc/pnv: introduce PnvPHB4 'pec' property Daniel Henrique Barboza
                   ` (8 more replies)
  0 siblings, 9 replies; 13+ messages in thread
From: Daniel Henrique Barboza @ 2022-01-14 18:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: Daniel Henrique Barboza, qemu-ppc, clg, david

Hi,

This second version contains improvements suggested by Cedric in the
v1 review.

Patches 1-10 from v1 are already accepted and aren't included in this
v2.


Changes from v1:
- v1 patches 1-10: already accepted, not included in the v2
- 'stack-stack_no' use is eliminated. We're now deriving stack_no from
phb->phb_id
- no longer use phb->phb_number
- no longer use pec->phbs[]
- v1 link: https://lists.gnu.org/archive/html/qemu-devel/2022-01/msg03000.html

Daniel Henrique Barboza (8):
  ppc/pnv: introduce PnvPHB4 'pec' property
  ppc/pnv: reduce stack->stack_no usage
  ppc/pnv: remove stack pointer from PnvPHB4
  ppc/pnv: move default_phb_realize() to pec_realize()
  ppc/pnv: remove PnvPhb4PecStack::stack_no
  ppc/pnv: make PECs create and realize PHB4s
  ppc/pnv: remove PnvPhb4PecStack object
  ppc/pnv: rename pnv_pec_stk_update_map()

 hw/pci-host/pnv_phb4.c         |  88 ++++++++++++++----------
 hw/pci-host/pnv_phb4_pec.c     | 118 ++++++++-------------------------
 include/hw/pci-host/pnv_phb4.h |  33 ++-------
 3 files changed, 86 insertions(+), 153 deletions(-)

-- 
2.33.1



^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v2 1/8] ppc/pnv: introduce PnvPHB4 'pec' property
  2022-01-14 18:07 [PATCH v2 0/8] remove PnvPhb4PecStack from Powernv9 Daniel Henrique Barboza
@ 2022-01-14 18:07 ` Daniel Henrique Barboza
  2022-01-14 18:07 ` [PATCH v2 2/8] ppc/pnv: reduce stack->stack_no usage Daniel Henrique Barboza
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Daniel Henrique Barboza @ 2022-01-14 18:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: Daniel Henrique Barboza, qemu-ppc, clg, david

This property will track the owner PEC of this PHB. For now it's
redundant since we can retrieve the PEC via phb->stack->pec but it
will not be redundant when we get rid of the stack device.

Reviewed-by: Cédric Le Goater <clg@kaod.org>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
 hw/pci-host/pnv_phb4.c         | 19 +++++++++++++------
 hw/pci-host/pnv_phb4_pec.c     |  2 ++
 include/hw/pci-host/pnv_phb4.h |  3 +++
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/hw/pci-host/pnv_phb4.c b/hw/pci-host/pnv_phb4.c
index b5045fca64..2658ef2d84 100644
--- a/hw/pci-host/pnv_phb4.c
+++ b/hw/pci-host/pnv_phb4.c
@@ -895,7 +895,7 @@ static void pnv_phb4_update_regions(PnvPHB4 *phb)
 static void pnv_pec_stk_update_map(PnvPHB4 *phb)
 {
     PnvPhb4PecStack *stack = phb->stack;
-    PnvPhb4PecState *pec = stack->pec;
+    PnvPhb4PecState *pec = phb->pec;
     MemoryRegion *sysmem = get_system_memory();
     uint64_t bar_en = phb->nest_regs[PEC_NEST_STK_BAR_EN];
     uint64_t bar, mask, size;
@@ -969,7 +969,7 @@ static void pnv_pec_stk_update_map(PnvPHB4 *phb)
         bar = phb->nest_regs[PEC_NEST_STK_INT_BAR] >> 8;
         size = PNV_PHB4_MAX_INTs << 16;
         snprintf(name, sizeof(name), "pec-%d.%d-phb-%d-int",
-                 stack->pec->chip_id, stack->pec->index, stack->stack_no);
+                 phb->pec->chip_id, phb->pec->index, stack->stack_no);
         memory_region_init(&phb->intbar, OBJECT(phb), name, size);
         memory_region_add_subregion(sysmem, bar, &phb->intbar);
     }
@@ -982,7 +982,7 @@ static void pnv_pec_stk_nest_xscom_write(void *opaque, hwaddr addr,
                                          uint64_t val, unsigned size)
 {
     PnvPHB4 *phb = PNV_PHB4(opaque);
-    PnvPhb4PecState *pec = phb->stack->pec;
+    PnvPhb4PecState *pec = phb->pec;
     uint32_t reg = addr >> 3;
 
     switch (reg) {
@@ -1459,7 +1459,7 @@ static AddressSpace *pnv_phb4_dma_iommu(PCIBus *bus, void *opaque, int devfn)
 static void pnv_phb4_xscom_realize(PnvPHB4 *phb)
 {
     PnvPhb4PecStack *stack = phb->stack;
-    PnvPhb4PecState *pec = stack->pec;
+    PnvPhb4PecState *pec = phb->pec;
     PnvPhb4PecClass *pecc = PNV_PHB4_PEC_GET_CLASS(pec);
     uint32_t pec_nest_base;
     uint32_t pec_pci_base;
@@ -1568,8 +1568,13 @@ static void pnv_phb4_realize(DeviceState *dev, Error **errp)
             return;
         }
 
-        /* All other phb properties but 'version' are already set */
-        pecc = PNV_PHB4_PEC_GET_CLASS(phb->stack->pec);
+        /*
+         * All other phb properties but 'pec' ad 'version' are
+         * already set.
+         */
+        object_property_set_link(OBJECT(phb), "pec", OBJECT(phb->stack->pec),
+                                 &error_abort);
+        pecc = PNV_PHB4_PEC_GET_CLASS(phb->pec);
         object_property_set_int(OBJECT(phb), "version", pecc->version,
                                 &error_fatal);
 
@@ -1682,6 +1687,8 @@ static Property pnv_phb4_properties[] = {
         DEFINE_PROP_UINT64("version", PnvPHB4, version, 0),
         DEFINE_PROP_LINK("stack", PnvPHB4, stack, TYPE_PNV_PHB4_PEC_STACK,
                          PnvPhb4PecStack *),
+        DEFINE_PROP_LINK("pec", PnvPHB4, pec, TYPE_PNV_PHB4_PEC,
+                         PnvPhb4PecState *),
         DEFINE_PROP_END_OF_LIST(),
 };
 
diff --git a/hw/pci-host/pnv_phb4_pec.c b/hw/pci-host/pnv_phb4_pec.c
index 7fe7f1f007..22194b8de2 100644
--- a/hw/pci-host/pnv_phb4_pec.c
+++ b/hw/pci-host/pnv_phb4_pec.c
@@ -285,6 +285,8 @@ static void pnv_pec_stk_default_phb_realize(PnvPhb4PecStack *stack,
 
     stack->phb = PNV_PHB4(qdev_new(TYPE_PNV_PHB4));
 
+    object_property_set_link(OBJECT(stack->phb), "pec", OBJECT(pec),
+                             &error_abort);
     object_property_set_int(OBJECT(stack->phb), "chip-id", pec->chip_id,
                             &error_fatal);
     object_property_set_int(OBJECT(stack->phb), "index", phb_id,
diff --git a/include/hw/pci-host/pnv_phb4.h b/include/hw/pci-host/pnv_phb4.h
index 6968efaba8..1d27e4c0cb 100644
--- a/include/hw/pci-host/pnv_phb4.h
+++ b/include/hw/pci-host/pnv_phb4.h
@@ -84,6 +84,9 @@ struct PnvPHB4 {
 
     uint64_t version;
 
+    /* The owner PEC */
+    PnvPhb4PecState *pec;
+
     char bus_path[8];
 
     /* Main register images */
-- 
2.33.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 2/8] ppc/pnv: reduce stack->stack_no usage
  2022-01-14 18:07 [PATCH v2 0/8] remove PnvPhb4PecStack from Powernv9 Daniel Henrique Barboza
  2022-01-14 18:07 ` [PATCH v2 1/8] ppc/pnv: introduce PnvPHB4 'pec' property Daniel Henrique Barboza
@ 2022-01-14 18:07 ` Daniel Henrique Barboza
  2022-01-17 10:52   ` Cédric Le Goater
  2022-01-14 18:07 ` [PATCH v2 3/8] ppc/pnv: remove stack pointer from PnvPHB4 Daniel Henrique Barboza
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 13+ messages in thread
From: Daniel Henrique Barboza @ 2022-01-14 18:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: Daniel Henrique Barboza, qemu-ppc, clg, david

'stack->stack_no' represents the order that a stack appears in its PEC.
Its primary use is in XSCOM address space calculation in
pnv_phb4_xscom_realize() when calculating the memory region offset.

This attribute is redundant with phb->phb_id, which is calculated via
pnv_phb4_pec_get_phb_id() using stack->stack_no information. It'll also
be awkward to assign it when dealing with PECs and PHBs only in a future
patch.

A new pnv_phb4_get_phb_stack_no() helper is introduced to eliminate most
of the stack->stack_no uses we have. The only use left after this patch
is during pnv_pec_stk_default_phb_realize() when calculating phb_id,
which will also handled in the next patches.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
 hw/pci-host/pnv_phb4.c | 46 +++++++++++++++++++++++++++++++-----------
 1 file changed, 34 insertions(+), 12 deletions(-)

diff --git a/hw/pci-host/pnv_phb4.c b/hw/pci-host/pnv_phb4.c
index 2658ef2d84..4933fe57fe 100644
--- a/hw/pci-host/pnv_phb4.c
+++ b/hw/pci-host/pnv_phb4.c
@@ -868,6 +868,28 @@ static uint64_t pnv_pec_stk_nest_xscom_read(void *opaque, hwaddr addr,
     return phb->nest_regs[reg];
 }
 
+/*
+ * Return the 'stack_no' of a PHB4. 'stack_no' is the order
+ * the PHB4 occupies in the PEC. This is the reverse of what
+ * pnv_phb4_pec_get_phb_id() does.
+ *
+ * E.g. a phb with phb_id = 4 and pec->index = 1 (PEC1) will
+ * be the second phb (stack_no = 1) of the PEC.
+ */
+static int pnv_phb4_get_phb_stack_no(PnvPHB4 *phb)
+{
+    PnvPhb4PecState *pec = phb->pec;
+    PnvPhb4PecClass *pecc = PNV_PHB4_PEC_GET_CLASS(pec);
+    int index = pec->index;
+    int stack_no = phb->phb_id;
+
+    while (index--) {
+        stack_no -= pecc->num_stacks[index];
+    }
+
+    return stack_no;
+}
+
 static void pnv_phb4_update_regions(PnvPHB4 *phb)
 {
     /* Unmap first always */
@@ -894,10 +916,10 @@ static void pnv_phb4_update_regions(PnvPHB4 *phb)
 
 static void pnv_pec_stk_update_map(PnvPHB4 *phb)
 {
-    PnvPhb4PecStack *stack = phb->stack;
     PnvPhb4PecState *pec = phb->pec;
     MemoryRegion *sysmem = get_system_memory();
     uint64_t bar_en = phb->nest_regs[PEC_NEST_STK_BAR_EN];
+    int stack_no = pnv_phb4_get_phb_stack_no(phb);
     uint64_t bar, mask, size;
     char name[64];
 
@@ -937,7 +959,7 @@ static void pnv_pec_stk_update_map(PnvPHB4 *phb)
         mask = phb->nest_regs[PEC_NEST_STK_MMIO_BAR0_MASK];
         size = ((~mask) >> 8) + 1;
         snprintf(name, sizeof(name), "pec-%d.%d-phb-%d-mmio0",
-                 pec->chip_id, pec->index, stack->stack_no);
+                 pec->chip_id, pec->index, stack_no);
         memory_region_init(&phb->mmbar0, OBJECT(phb), name, size);
         memory_region_add_subregion(sysmem, bar, &phb->mmbar0);
         phb->mmio0_base = bar;
@@ -949,7 +971,7 @@ static void pnv_pec_stk_update_map(PnvPHB4 *phb)
         mask = phb->nest_regs[PEC_NEST_STK_MMIO_BAR1_MASK];
         size = ((~mask) >> 8) + 1;
         snprintf(name, sizeof(name), "pec-%d.%d-phb-%d-mmio1",
-                 pec->chip_id, pec->index, stack->stack_no);
+                 pec->chip_id, pec->index, stack_no);
         memory_region_init(&phb->mmbar1, OBJECT(phb), name, size);
         memory_region_add_subregion(sysmem, bar, &phb->mmbar1);
         phb->mmio1_base = bar;
@@ -960,7 +982,7 @@ static void pnv_pec_stk_update_map(PnvPHB4 *phb)
         bar = phb->nest_regs[PEC_NEST_STK_PHB_REGS_BAR] >> 8;
         size = PNV_PHB4_NUM_REGS << 3;
         snprintf(name, sizeof(name), "pec-%d.%d-phb-%d",
-                 pec->chip_id, pec->index, stack->stack_no);
+                 pec->chip_id, pec->index, stack_no);
         memory_region_init(&phb->phbbar, OBJECT(phb), name, size);
         memory_region_add_subregion(sysmem, bar, &phb->phbbar);
     }
@@ -969,7 +991,7 @@ static void pnv_pec_stk_update_map(PnvPHB4 *phb)
         bar = phb->nest_regs[PEC_NEST_STK_INT_BAR] >> 8;
         size = PNV_PHB4_MAX_INTs << 16;
         snprintf(name, sizeof(name), "pec-%d.%d-phb-%d-int",
-                 phb->pec->chip_id, phb->pec->index, stack->stack_no);
+                 phb->pec->chip_id, phb->pec->index, stack_no);
         memory_region_init(&phb->intbar, OBJECT(phb), name, size);
         memory_region_add_subregion(sysmem, bar, &phb->intbar);
     }
@@ -1458,9 +1480,9 @@ static AddressSpace *pnv_phb4_dma_iommu(PCIBus *bus, void *opaque, int devfn)
 
 static void pnv_phb4_xscom_realize(PnvPHB4 *phb)
 {
-    PnvPhb4PecStack *stack = phb->stack;
     PnvPhb4PecState *pec = phb->pec;
     PnvPhb4PecClass *pecc = PNV_PHB4_PEC_GET_CLASS(pec);
+    int stack_no = pnv_phb4_get_phb_stack_no(phb);
     uint32_t pec_nest_base;
     uint32_t pec_pci_base;
     char name[64];
@@ -1469,20 +1491,20 @@ static void pnv_phb4_xscom_realize(PnvPHB4 *phb)
 
     /* Initialize the XSCOM regions for the stack registers */
     snprintf(name, sizeof(name), "xscom-pec-%d.%d-nest-phb-%d",
-             pec->chip_id, pec->index, stack->stack_no);
+             pec->chip_id, pec->index, stack_no);
     pnv_xscom_region_init(&phb->nest_regs_mr, OBJECT(phb),
                           &pnv_pec_stk_nest_xscom_ops, phb, name,
                           PHB4_PEC_NEST_STK_REGS_COUNT);
 
     snprintf(name, sizeof(name), "xscom-pec-%d.%d-pci-phb-%d",
-             pec->chip_id, pec->index, stack->stack_no);
+             pec->chip_id, pec->index, stack_no);
     pnv_xscom_region_init(&phb->pci_regs_mr, OBJECT(phb),
                           &pnv_pec_stk_pci_xscom_ops, phb, name,
                           PHB4_PEC_PCI_STK_REGS_COUNT);
 
     /* PHB pass-through */
     snprintf(name, sizeof(name), "xscom-pec-%d.%d-pci-phb-%d",
-             pec->chip_id, pec->index, stack->stack_no);
+             pec->chip_id, pec->index, stack_no);
     pnv_xscom_region_init(&phb->phb_regs_mr, OBJECT(phb),
                           &pnv_phb4_xscom_ops, phb, name, 0x40);
 
@@ -1491,14 +1513,14 @@ static void pnv_phb4_xscom_realize(PnvPHB4 *phb)
 
     /* Populate the XSCOM address space. */
     pnv_xscom_add_subregion(pec->chip,
-                            pec_nest_base + 0x40 * (stack->stack_no + 1),
+                            pec_nest_base + 0x40 * (stack_no + 1),
                             &phb->nest_regs_mr);
     pnv_xscom_add_subregion(pec->chip,
-                            pec_pci_base + 0x40 * (stack->stack_no + 1),
+                            pec_pci_base + 0x40 * (stack_no + 1),
                             &phb->pci_regs_mr);
     pnv_xscom_add_subregion(pec->chip,
                             pec_pci_base + PNV9_XSCOM_PEC_PCI_STK0 +
-                            0x40 * stack->stack_no,
+                            0x40 * stack_no,
                             &phb->phb_regs_mr);
 }
 
-- 
2.33.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 3/8] ppc/pnv: remove stack pointer from PnvPHB4
  2022-01-14 18:07 [PATCH v2 0/8] remove PnvPhb4PecStack from Powernv9 Daniel Henrique Barboza
  2022-01-14 18:07 ` [PATCH v2 1/8] ppc/pnv: introduce PnvPHB4 'pec' property Daniel Henrique Barboza
  2022-01-14 18:07 ` [PATCH v2 2/8] ppc/pnv: reduce stack->stack_no usage Daniel Henrique Barboza
@ 2022-01-14 18:07 ` Daniel Henrique Barboza
  2022-01-14 18:07 ` [PATCH v2 4/8] ppc/pnv: move default_phb_realize() to pec_realize() Daniel Henrique Barboza
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Daniel Henrique Barboza @ 2022-01-14 18:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: Daniel Henrique Barboza, qemu-ppc, clg, david

This pointer was being used for two reasons: pnv_phb4_update_regions()
was using it to access the PHB and phb4_realize() was using it as a way
to determine if the PHB was user created.

We can determine if the PHB is user created via phb->pec, introduced in
the previous patch, and pnv_phb4_update_regions() is no longer using
stack->phb.

Remove the pointer from the PnvPHB4 device.

Reviewed-by: Cédric Le Goater <clg@kaod.org>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
 hw/pci-host/pnv_phb4.c         | 15 ++++-----------
 hw/pci-host/pnv_phb4_pec.c     |  2 --
 include/hw/pci-host/pnv_phb4.h |  2 --
 3 files changed, 4 insertions(+), 15 deletions(-)

diff --git a/hw/pci-host/pnv_phb4.c b/hw/pci-host/pnv_phb4.c
index 4933fe57fe..2efd34518e 100644
--- a/hw/pci-host/pnv_phb4.c
+++ b/hw/pci-host/pnv_phb4.c
@@ -1573,9 +1573,10 @@ static void pnv_phb4_realize(DeviceState *dev, Error **errp)
     char name[32];
 
     /* User created PHB */
-    if (!phb->stack) {
+    if (!phb->pec) {
         PnvMachineState *pnv = PNV_MACHINE(qdev_get_machine());
         PnvChip *chip = pnv_get_chip(pnv, phb->chip_id);
+        PnvPhb4PecStack *stack;
         PnvPhb4PecClass *pecc;
         BusState *s;
 
@@ -1584,7 +1585,7 @@ static void pnv_phb4_realize(DeviceState *dev, Error **errp)
             return;
         }
 
-        phb->stack = pnv_phb4_get_stack(chip, phb, &local_err);
+        stack = pnv_phb4_get_stack(chip, phb, &local_err);
         if (local_err) {
             error_propagate(errp, local_err);
             return;
@@ -1594,18 +1595,12 @@ static void pnv_phb4_realize(DeviceState *dev, Error **errp)
          * All other phb properties but 'pec' ad 'version' are
          * already set.
          */
-        object_property_set_link(OBJECT(phb), "pec", OBJECT(phb->stack->pec),
+        object_property_set_link(OBJECT(phb), "pec", OBJECT(stack->pec),
                                  &error_abort);
         pecc = PNV_PHB4_PEC_GET_CLASS(phb->pec);
         object_property_set_int(OBJECT(phb), "version", pecc->version,
                                 &error_fatal);
 
-        /*
-         * Assign stack->phb since pnv_phb4_update_regions() uses it
-         * to access the phb.
-         */
-        phb->stack->phb = phb;
-
         /*
          * Reparent user created devices to the chip to build
          * correctly the device tree.
@@ -1707,8 +1702,6 @@ static Property pnv_phb4_properties[] = {
         DEFINE_PROP_UINT32("index", PnvPHB4, phb_id, 0),
         DEFINE_PROP_UINT32("chip-id", PnvPHB4, chip_id, 0),
         DEFINE_PROP_UINT64("version", PnvPHB4, version, 0),
-        DEFINE_PROP_LINK("stack", PnvPHB4, stack, TYPE_PNV_PHB4_PEC_STACK,
-                         PnvPhb4PecStack *),
         DEFINE_PROP_LINK("pec", PnvPHB4, pec, TYPE_PNV_PHB4_PEC,
                          PnvPhb4PecState *),
         DEFINE_PROP_END_OF_LIST(),
diff --git a/hw/pci-host/pnv_phb4_pec.c b/hw/pci-host/pnv_phb4_pec.c
index 22194b8de2..ed1d644182 100644
--- a/hw/pci-host/pnv_phb4_pec.c
+++ b/hw/pci-host/pnv_phb4_pec.c
@@ -293,8 +293,6 @@ static void pnv_pec_stk_default_phb_realize(PnvPhb4PecStack *stack,
                             &error_fatal);
     object_property_set_int(OBJECT(stack->phb), "version", pecc->version,
                             &error_fatal);
-    object_property_set_link(OBJECT(stack->phb), "stack", OBJECT(stack),
-                             &error_abort);
 
     if (!sysbus_realize(SYS_BUS_DEVICE(stack->phb), errp)) {
         return;
diff --git a/include/hw/pci-host/pnv_phb4.h b/include/hw/pci-host/pnv_phb4.h
index 1d27e4c0cb..a9059b7279 100644
--- a/include/hw/pci-host/pnv_phb4.h
+++ b/include/hw/pci-host/pnv_phb4.h
@@ -151,8 +151,6 @@ struct PnvPHB4 {
     XiveSource xsrc;
     qemu_irq *qirqs;
 
-    PnvPhb4PecStack *stack;
-
     QLIST_HEAD(, PnvPhb4DMASpace) dma_spaces;
 };
 
-- 
2.33.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 4/8] ppc/pnv: move default_phb_realize() to pec_realize()
  2022-01-14 18:07 [PATCH v2 0/8] remove PnvPhb4PecStack from Powernv9 Daniel Henrique Barboza
                   ` (2 preceding siblings ...)
  2022-01-14 18:07 ` [PATCH v2 3/8] ppc/pnv: remove stack pointer from PnvPHB4 Daniel Henrique Barboza
@ 2022-01-14 18:07 ` Daniel Henrique Barboza
  2022-01-14 18:07 ` [PATCH v2 5/8] ppc/pnv: remove PnvPhb4PecStack::stack_no Daniel Henrique Barboza
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Daniel Henrique Barboza @ 2022-01-14 18:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: Daniel Henrique Barboza, qemu-ppc, clg, david

Move the current pnv_pec_stk_default_phb_realize() call to
pec_realize(), renaming the function to pnv_pec_default_phb_realize(),
and set the PHB attributes using the PEC object directly.

This will be important to allow for PECs devices to handle PHB4s
directly later on.

Reviewed-by: Cédric Le Goater <clg@kaod.org>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
 hw/pci-host/pnv_phb4_pec.c | 63 ++++++++++++++++++++------------------
 1 file changed, 33 insertions(+), 30 deletions(-)

diff --git a/hw/pci-host/pnv_phb4_pec.c b/hw/pci-host/pnv_phb4_pec.c
index ed1d644182..a80a21db77 100644
--- a/hw/pci-host/pnv_phb4_pec.c
+++ b/hw/pci-host/pnv_phb4_pec.c
@@ -112,6 +112,30 @@ static const MemoryRegionOps pnv_pec_pci_xscom_ops = {
     .endianness = DEVICE_BIG_ENDIAN,
 };
 
+static void pnv_pec_default_phb_realize(PnvPhb4PecStack *stack,
+                                        int stack_no,
+                                        Error **errp)
+{
+    PnvPhb4PecState *pec = stack->pec;
+    PnvPhb4PecClass *pecc = PNV_PHB4_PEC_GET_CLASS(pec);
+    int phb_id = pnv_phb4_pec_get_phb_id(pec, stack_no);
+
+    stack->phb = PNV_PHB4(qdev_new(TYPE_PNV_PHB4));
+
+    object_property_set_link(OBJECT(stack->phb), "pec", OBJECT(pec),
+                             &error_abort);
+    object_property_set_int(OBJECT(stack->phb), "chip-id", pec->chip_id,
+                            &error_fatal);
+    object_property_set_int(OBJECT(stack->phb), "index", phb_id,
+                            &error_fatal);
+    object_property_set_int(OBJECT(stack->phb), "version", pecc->version,
+                            &error_fatal);
+
+    if (!sysbus_realize(SYS_BUS_DEVICE(stack->phb), errp)) {
+        return;
+    }
+}
+
 static void pnv_pec_instance_init(Object *obj)
 {
     PnvPhb4PecState *pec = PNV_PHB4_PEC(obj);
@@ -144,6 +168,15 @@ static void pnv_pec_realize(DeviceState *dev, Error **errp)
 
         object_property_set_int(stk_obj, "stack-no", i, &error_abort);
         object_property_set_link(stk_obj, "pec", OBJECT(pec), &error_abort);
+
+        if (defaults_enabled()) {
+            pnv_pec_default_phb_realize(stack, i, errp);
+        }
+
+        /*
+         * qdev gets angry if we don't realize 'stack' here, even
+         * if stk_realize() is now empty.
+         */
         if (!qdev_realize(DEVICE(stk_obj), NULL, errp)) {
             return;
         }
@@ -276,38 +309,8 @@ static const TypeInfo pnv_pec_type_info = {
     }
 };
 
-static void pnv_pec_stk_default_phb_realize(PnvPhb4PecStack *stack,
-                                            Error **errp)
-{
-    PnvPhb4PecState *pec = stack->pec;
-    PnvPhb4PecClass *pecc = PNV_PHB4_PEC_GET_CLASS(pec);
-    int phb_id = pnv_phb4_pec_get_phb_id(pec, stack->stack_no);
-
-    stack->phb = PNV_PHB4(qdev_new(TYPE_PNV_PHB4));
-
-    object_property_set_link(OBJECT(stack->phb), "pec", OBJECT(pec),
-                             &error_abort);
-    object_property_set_int(OBJECT(stack->phb), "chip-id", pec->chip_id,
-                            &error_fatal);
-    object_property_set_int(OBJECT(stack->phb), "index", phb_id,
-                            &error_fatal);
-    object_property_set_int(OBJECT(stack->phb), "version", pecc->version,
-                            &error_fatal);
-
-    if (!sysbus_realize(SYS_BUS_DEVICE(stack->phb), errp)) {
-        return;
-    }
-}
-
 static void pnv_pec_stk_realize(DeviceState *dev, Error **errp)
 {
-    PnvPhb4PecStack *stack = PNV_PHB4_PEC_STACK(dev);
-
-    if (!defaults_enabled()) {
-        return;
-    }
-
-    pnv_pec_stk_default_phb_realize(stack, errp);
 }
 
 static Property pnv_pec_stk_properties[] = {
-- 
2.33.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 5/8] ppc/pnv: remove PnvPhb4PecStack::stack_no
  2022-01-14 18:07 [PATCH v2 0/8] remove PnvPhb4PecStack from Powernv9 Daniel Henrique Barboza
                   ` (3 preceding siblings ...)
  2022-01-14 18:07 ` [PATCH v2 4/8] ppc/pnv: move default_phb_realize() to pec_realize() Daniel Henrique Barboza
@ 2022-01-14 18:07 ` Daniel Henrique Barboza
  2022-01-17 10:53   ` Cédric Le Goater
  2022-01-14 18:07 ` [PATCH v2 6/8] ppc/pnv: make PECs create and realize PHB4s Daniel Henrique Barboza
                   ` (3 subsequent siblings)
  8 siblings, 1 reply; 13+ messages in thread
From: Daniel Henrique Barboza @ 2022-01-14 18:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: Daniel Henrique Barboza, qemu-ppc, clg, david

pnv_pec_default_phb_realize() stopped using it after the previous patch and
no one else is using it.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
 hw/pci-host/pnv_phb4_pec.c     | 2 --
 include/hw/pci-host/pnv_phb4.h | 3 ---
 2 files changed, 5 deletions(-)

diff --git a/hw/pci-host/pnv_phb4_pec.c b/hw/pci-host/pnv_phb4_pec.c
index a80a21db77..d6405d6ca3 100644
--- a/hw/pci-host/pnv_phb4_pec.c
+++ b/hw/pci-host/pnv_phb4_pec.c
@@ -166,7 +166,6 @@ static void pnv_pec_realize(DeviceState *dev, Error **errp)
         PnvPhb4PecStack *stack = &pec->stacks[i];
         Object *stk_obj = OBJECT(stack);
 
-        object_property_set_int(stk_obj, "stack-no", i, &error_abort);
         object_property_set_link(stk_obj, "pec", OBJECT(pec), &error_abort);
 
         if (defaults_enabled()) {
@@ -314,7 +313,6 @@ static void pnv_pec_stk_realize(DeviceState *dev, Error **errp)
 }
 
 static Property pnv_pec_stk_properties[] = {
-        DEFINE_PROP_UINT32("stack-no", PnvPhb4PecStack, stack_no, 0),
         DEFINE_PROP_LINK("pec", PnvPhb4PecStack, pec, TYPE_PNV_PHB4_PEC,
                          PnvPhb4PecState *),
         DEFINE_PROP_END_OF_LIST(),
diff --git a/include/hw/pci-host/pnv_phb4.h b/include/hw/pci-host/pnv_phb4.h
index a9059b7279..2be56b7afd 100644
--- a/include/hw/pci-host/pnv_phb4.h
+++ b/include/hw/pci-host/pnv_phb4.h
@@ -171,9 +171,6 @@ OBJECT_DECLARE_SIMPLE_TYPE(PnvPhb4PecStack, PNV_PHB4_PEC_STACK)
 struct PnvPhb4PecStack {
     DeviceState parent;
 
-    /* My own stack number */
-    uint32_t stack_no;
-
     /* The owner PEC */
     PnvPhb4PecState *pec;
 
-- 
2.33.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 6/8] ppc/pnv: make PECs create and realize PHB4s
  2022-01-14 18:07 [PATCH v2 0/8] remove PnvPhb4PecStack from Powernv9 Daniel Henrique Barboza
                   ` (4 preceding siblings ...)
  2022-01-14 18:07 ` [PATCH v2 5/8] ppc/pnv: remove PnvPhb4PecStack::stack_no Daniel Henrique Barboza
@ 2022-01-14 18:07 ` Daniel Henrique Barboza
  2022-01-17 10:55   ` Cédric Le Goater
  2022-01-14 18:07 ` [PATCH v2 7/8] ppc/pnv: remove PnvPhb4PecStack object Daniel Henrique Barboza
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 13+ messages in thread
From: Daniel Henrique Barboza @ 2022-01-14 18:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: Daniel Henrique Barboza, qemu-ppc, clg, david

This patch changes the design of the PEC device to create and realize PHB4s
instead of PecStacks. After all the recent changes, PHB4s now contain all
the information needed for their proper functioning, not relying on PecStack
in any capacity.

All changes are being made in a single patch to avoid renaming parts of
the PecState and leaving the code in a strange way. E.g. rename
PecClass->num_stacks to num_phbs, which would then read a
pnv_pec_num_stacks[] array. To avoid mixing the old and new design more
than necessary it's clearer to do these changes in a single step.

The name changes made are:

- in PnvPhb4PecState:
  * rename 'num_stacks' to 'num_phbs'
  * remove the pec->stacks[] array. Current code relies on the
pec->stacks[] obj acting as a simple container, without ever accessing
pec->stacks[] for any other purpose. Instead of converting this into a
pec->phbs[] array, remove it

- in PnvPhb4PecClass, rename *num_stacks to *num_phbs;

- pnv_pec_num_stacks[] is renamed to pnv_pec_num_phbs[].

The logical changes:

- pnv_pec_default_phb_realize():
  * init and set the properties of the PnvPHB4 qdev
  * do not use stack->phb anymore;

- pnv_pec_realize():
  * use the new default_phb_realize() to init/realize each PHB if
running with defaults;

- pnv_pec_instance_init(): removed since we're creating the PHBs during
pec_realize();

- pnv_phb4_get_stack():
  * renamed to pnv_phb4_get_pec() and returns a PnvPhb4PecState*;

- pnv_phb4_realize(): use 'phb->pec' instead of 'stack'.

This design change shouldn't caused any behavioral change in the runtime
of the machine.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
 hw/pci-host/pnv_phb4.c         | 26 ++++++--------
 hw/pci-host/pnv_phb4_pec.c     | 66 ++++++++++------------------------
 include/hw/pci-host/pnv_phb4.h |  8 ++---
 3 files changed, 31 insertions(+), 69 deletions(-)

diff --git a/hw/pci-host/pnv_phb4.c b/hw/pci-host/pnv_phb4.c
index 2efd34518e..3dc3c70cb2 100644
--- a/hw/pci-host/pnv_phb4.c
+++ b/hw/pci-host/pnv_phb4.c
@@ -884,7 +884,7 @@ static int pnv_phb4_get_phb_stack_no(PnvPHB4 *phb)
     int stack_no = phb->phb_id;
 
     while (index--) {
-        stack_no -= pecc->num_stacks[index];
+        stack_no -= pecc->num_phbs[index];
     }
 
     return stack_no;
@@ -1383,7 +1383,7 @@ int pnv_phb4_pec_get_phb_id(PnvPhb4PecState *pec, int stack_index)
     int offset = 0;
 
     while (index--) {
-        offset += pecc->num_stacks[index];
+        offset += pecc->num_phbs[index];
     }
 
     return offset + stack_index;
@@ -1534,8 +1534,8 @@ static void pnv_phb4_instance_init(Object *obj)
     object_initialize_child(obj, "source", &phb->xsrc, TYPE_XIVE_SOURCE);
 }
 
-static PnvPhb4PecStack *pnv_phb4_get_stack(PnvChip *chip, PnvPHB4 *phb,
-                                           Error **errp)
+static PnvPhb4PecState *pnv_phb4_get_pec(PnvChip *chip, PnvPHB4 *phb,
+                                         Error **errp)
 {
     Pnv9Chip *chip9 = PNV9_CHIP(chip);
     int chip_id = phb->chip_id;
@@ -1544,14 +1544,14 @@ static PnvPhb4PecStack *pnv_phb4_get_stack(PnvChip *chip, PnvPHB4 *phb,
 
     for (i = 0; i < chip->num_pecs; i++) {
         /*
-         * For each PEC, check the amount of stacks it supports
-         * and see if the given phb4 index matches a stack.
+         * For each PEC, check the amount of phbs it supports
+         * and see if the given phb4 index matches an index.
          */
         PnvPhb4PecState *pec = &chip9->pecs[i];
 
-        for (j = 0; j < pec->num_stacks; j++) {
+        for (j = 0; j < pec->num_phbs; j++) {
             if (index == pnv_phb4_pec_get_phb_id(pec, j)) {
-                return &pec->stacks[j];
+                return pec;
             }
         }
     }
@@ -1576,7 +1576,6 @@ static void pnv_phb4_realize(DeviceState *dev, Error **errp)
     if (!phb->pec) {
         PnvMachineState *pnv = PNV_MACHINE(qdev_get_machine());
         PnvChip *chip = pnv_get_chip(pnv, phb->chip_id);
-        PnvPhb4PecStack *stack;
         PnvPhb4PecClass *pecc;
         BusState *s;
 
@@ -1585,18 +1584,13 @@ static void pnv_phb4_realize(DeviceState *dev, Error **errp)
             return;
         }
 
-        stack = pnv_phb4_get_stack(chip, phb, &local_err);
+        phb->pec = pnv_phb4_get_pec(chip, phb, &local_err);
         if (local_err) {
             error_propagate(errp, local_err);
             return;
         }
 
-        /*
-         * All other phb properties but 'pec' ad 'version' are
-         * already set.
-         */
-        object_property_set_link(OBJECT(phb), "pec", OBJECT(stack->pec),
-                                 &error_abort);
+        /* All other phb properties are already set */
         pecc = PNV_PHB4_PEC_GET_CLASS(phb->pec);
         object_property_set_int(OBJECT(phb), "version", pecc->version,
                                 &error_fatal);
diff --git a/hw/pci-host/pnv_phb4_pec.c b/hw/pci-host/pnv_phb4_pec.c
index d6405d6ca3..852816b9f8 100644
--- a/hw/pci-host/pnv_phb4_pec.c
+++ b/hw/pci-host/pnv_phb4_pec.c
@@ -112,41 +112,28 @@ static const MemoryRegionOps pnv_pec_pci_xscom_ops = {
     .endianness = DEVICE_BIG_ENDIAN,
 };
 
-static void pnv_pec_default_phb_realize(PnvPhb4PecStack *stack,
+static void pnv_pec_default_phb_realize(PnvPhb4PecState *pec,
                                         int stack_no,
                                         Error **errp)
 {
-    PnvPhb4PecState *pec = stack->pec;
+    PnvPHB4 *phb = PNV_PHB4(qdev_new(TYPE_PNV_PHB4));
     PnvPhb4PecClass *pecc = PNV_PHB4_PEC_GET_CLASS(pec);
     int phb_id = pnv_phb4_pec_get_phb_id(pec, stack_no);
 
-    stack->phb = PNV_PHB4(qdev_new(TYPE_PNV_PHB4));
-
-    object_property_set_link(OBJECT(stack->phb), "pec", OBJECT(pec),
+    object_property_set_link(OBJECT(phb), "pec", OBJECT(pec),
                              &error_abort);
-    object_property_set_int(OBJECT(stack->phb), "chip-id", pec->chip_id,
+    object_property_set_int(OBJECT(phb), "chip-id", pec->chip_id,
                             &error_fatal);
-    object_property_set_int(OBJECT(stack->phb), "index", phb_id,
+    object_property_set_int(OBJECT(phb), "index", phb_id,
                             &error_fatal);
-    object_property_set_int(OBJECT(stack->phb), "version", pecc->version,
+    object_property_set_int(OBJECT(phb), "version", pecc->version,
                             &error_fatal);
 
-    if (!sysbus_realize(SYS_BUS_DEVICE(stack->phb), errp)) {
+    if (!sysbus_realize(SYS_BUS_DEVICE(phb), errp)) {
         return;
     }
 }
 
-static void pnv_pec_instance_init(Object *obj)
-{
-    PnvPhb4PecState *pec = PNV_PHB4_PEC(obj);
-    int i;
-
-    for (i = 0; i < PHB4_PEC_MAX_STACKS; i++) {
-        object_initialize_child(obj, "stack[*]", &pec->stacks[i],
-                                TYPE_PNV_PHB4_PEC_STACK);
-    }
-}
-
 static void pnv_pec_realize(DeviceState *dev, Error **errp)
 {
     PnvPhb4PecState *pec = PNV_PHB4_PEC(dev);
@@ -159,29 +146,13 @@ static void pnv_pec_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    pec->num_stacks = pecc->num_stacks[pec->index];
-
-    /* Create stacks */
-    for (i = 0; i < pec->num_stacks; i++) {
-        PnvPhb4PecStack *stack = &pec->stacks[i];
-        Object *stk_obj = OBJECT(stack);
-
-        object_property_set_link(stk_obj, "pec", OBJECT(pec), &error_abort);
+    pec->num_phbs = pecc->num_phbs[pec->index];
 
-        if (defaults_enabled()) {
-            pnv_pec_default_phb_realize(stack, i, errp);
+    /* Create PHBs if running with defaults */
+    if (defaults_enabled()) {
+        for (i = 0; i < pec->num_phbs; i++) {
+            pnv_pec_default_phb_realize(pec, i, errp);
         }
-
-        /*
-         * qdev gets angry if we don't realize 'stack' here, even
-         * if stk_realize() is now empty.
-         */
-        if (!qdev_realize(DEVICE(stk_obj), NULL, errp)) {
-            return;
-        }
-    }
-    for (; i < PHB4_PEC_MAX_STACKS; i++) {
-        object_unparent(OBJECT(&pec->stacks[i]));
     }
 
     /* Initialize the XSCOM regions for the PEC registers */
@@ -227,7 +198,7 @@ static int pnv_pec_dt_xscom(PnvXScomInterface *dev, void *fdt,
     _FDT((fdt_setprop(fdt, offset, "compatible", pecc->compat,
                       pecc->compat_size)));
 
-    for (i = 0; i < pec->num_stacks; i++) {
+    for (i = 0; i < pec->num_phbs; i++) {
         int phb_id = pnv_phb4_pec_get_phb_id(pec, i);
         int stk_offset;
 
@@ -263,11 +234,11 @@ static uint32_t pnv_pec_xscom_nest_base(PnvPhb4PecState *pec)
 }
 
 /*
- * PEC0 -> 1 stack
- * PEC1 -> 2 stacks
- * PEC2 -> 3 stacks
+ * PEC0 -> 1 phb
+ * PEC1 -> 2 phb
+ * PEC2 -> 3 phbs
  */
-static const uint32_t pnv_pec_num_stacks[] = { 1, 2, 3 };
+static const uint32_t pnv_pec_num_phbs[] = { 1, 2, 3 };
 
 static void pnv_pec_class_init(ObjectClass *klass, void *data)
 {
@@ -292,14 +263,13 @@ static void pnv_pec_class_init(ObjectClass *klass, void *data)
     pecc->stk_compat = stk_compat;
     pecc->stk_compat_size = sizeof(stk_compat);
     pecc->version = PNV_PHB4_VERSION;
-    pecc->num_stacks = pnv_pec_num_stacks;
+    pecc->num_phbs = pnv_pec_num_phbs;
 }
 
 static const TypeInfo pnv_pec_type_info = {
     .name          = TYPE_PNV_PHB4_PEC,
     .parent        = TYPE_DEVICE,
     .instance_size = sizeof(PnvPhb4PecState),
-    .instance_init = pnv_pec_instance_init,
     .class_init    = pnv_pec_class_init,
     .class_size    = sizeof(PnvPhb4PecClass),
     .interfaces    = (InterfaceInfo[]) {
diff --git a/include/hw/pci-host/pnv_phb4.h b/include/hw/pci-host/pnv_phb4.h
index 2be56b7afd..e750165e77 100644
--- a/include/hw/pci-host/pnv_phb4.h
+++ b/include/hw/pci-host/pnv_phb4.h
@@ -200,10 +200,8 @@ struct PnvPhb4PecState {
     uint64_t pci_regs[PHB4_PEC_PCI_REGS_COUNT];
     MemoryRegion pci_regs_mr;
 
-    /* Stacks */
-    #define PHB4_PEC_MAX_STACKS     3
-    uint32_t num_stacks;
-    PnvPhb4PecStack stacks[PHB4_PEC_MAX_STACKS];
+    /* PHBs */
+    uint32_t num_phbs;
 
     PnvChip *chip;
 };
@@ -221,7 +219,7 @@ struct PnvPhb4PecClass {
     const char *stk_compat;
     int stk_compat_size;
     uint64_t version;
-    const uint32_t *num_stacks;
+    const uint32_t *num_phbs;
 };
 
 #endif /* PCI_HOST_PNV_PHB4_H */
-- 
2.33.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 7/8] ppc/pnv: remove PnvPhb4PecStack object
  2022-01-14 18:07 [PATCH v2 0/8] remove PnvPhb4PecStack from Powernv9 Daniel Henrique Barboza
                   ` (5 preceding siblings ...)
  2022-01-14 18:07 ` [PATCH v2 6/8] ppc/pnv: make PECs create and realize PHB4s Daniel Henrique Barboza
@ 2022-01-14 18:07 ` Daniel Henrique Barboza
  2022-01-14 18:07 ` [PATCH v2 8/8] ppc/pnv: rename pnv_pec_stk_update_map() Daniel Henrique Barboza
  2022-01-18 12:03 ` [PATCH v2 0/8] remove PnvPhb4PecStack from Powernv9 Cédric Le Goater
  8 siblings, 0 replies; 13+ messages in thread
From: Daniel Henrique Barboza @ 2022-01-14 18:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: Daniel Henrique Barboza, qemu-ppc, clg, david

All the complexity that was scattered between PnvPhb4PecStack and
PnvPHB4 are now centered in the PnvPHB4 device. PnvPhb4PecStack does not
serve any purpose in the current code base.

Reviewed-by: Cédric Le Goater <clg@kaod.org>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
 hw/pci-host/pnv_phb4_pec.c     | 33 ---------------------------------
 include/hw/pci-host/pnv_phb4.h | 17 -----------------
 2 files changed, 50 deletions(-)

diff --git a/hw/pci-host/pnv_phb4_pec.c b/hw/pci-host/pnv_phb4_pec.c
index 852816b9f8..12aa459628 100644
--- a/hw/pci-host/pnv_phb4_pec.c
+++ b/hw/pci-host/pnv_phb4_pec.c
@@ -278,42 +278,9 @@ static const TypeInfo pnv_pec_type_info = {
     }
 };
 
-static void pnv_pec_stk_realize(DeviceState *dev, Error **errp)
-{
-}
-
-static Property pnv_pec_stk_properties[] = {
-        DEFINE_PROP_LINK("pec", PnvPhb4PecStack, pec, TYPE_PNV_PHB4_PEC,
-                         PnvPhb4PecState *),
-        DEFINE_PROP_END_OF_LIST(),
-};
-
-static void pnv_pec_stk_class_init(ObjectClass *klass, void *data)
-{
-    DeviceClass *dc = DEVICE_CLASS(klass);
-
-    device_class_set_props(dc, pnv_pec_stk_properties);
-    dc->realize = pnv_pec_stk_realize;
-    dc->user_creatable = false;
-
-    /* TODO: reset regs ? */
-}
-
-static const TypeInfo pnv_pec_stk_type_info = {
-    .name          = TYPE_PNV_PHB4_PEC_STACK,
-    .parent        = TYPE_DEVICE,
-    .instance_size = sizeof(PnvPhb4PecStack),
-    .class_init    = pnv_pec_stk_class_init,
-    .interfaces    = (InterfaceInfo[]) {
-        { TYPE_PNV_XSCOM_INTERFACE },
-        { }
-    }
-};
-
 static void pnv_pec_register_types(void)
 {
     type_register_static(&pnv_pec_type_info);
-    type_register_static(&pnv_pec_stk_type_info);
 }
 
 type_init(pnv_pec_register_types);
diff --git a/include/hw/pci-host/pnv_phb4.h b/include/hw/pci-host/pnv_phb4.h
index e750165e77..74fdec2b47 100644
--- a/include/hw/pci-host/pnv_phb4.h
+++ b/include/hw/pci-host/pnv_phb4.h
@@ -164,23 +164,6 @@ extern const MemoryRegionOps pnv_phb4_xscom_ops;
 #define TYPE_PNV_PHB4_PEC "pnv-phb4-pec"
 OBJECT_DECLARE_TYPE(PnvPhb4PecState, PnvPhb4PecClass, PNV_PHB4_PEC)
 
-#define TYPE_PNV_PHB4_PEC_STACK "pnv-phb4-pec-stack"
-OBJECT_DECLARE_SIMPLE_TYPE(PnvPhb4PecStack, PNV_PHB4_PEC_STACK)
-
-/* Per-stack data */
-struct PnvPhb4PecStack {
-    DeviceState parent;
-
-    /* The owner PEC */
-    PnvPhb4PecState *pec;
-
-    /*
-     * PHB4 pointer. pnv_phb4_update_regions() needs to access
-     * the PHB4 via a PnvPhb4PecStack pointer.
-     */
-    PnvPHB4 *phb;
-};
-
 struct PnvPhb4PecState {
     DeviceState parent;
 
-- 
2.33.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 8/8] ppc/pnv: rename pnv_pec_stk_update_map()
  2022-01-14 18:07 [PATCH v2 0/8] remove PnvPhb4PecStack from Powernv9 Daniel Henrique Barboza
                   ` (6 preceding siblings ...)
  2022-01-14 18:07 ` [PATCH v2 7/8] ppc/pnv: remove PnvPhb4PecStack object Daniel Henrique Barboza
@ 2022-01-14 18:07 ` Daniel Henrique Barboza
  2022-01-18 12:03 ` [PATCH v2 0/8] remove PnvPhb4PecStack from Powernv9 Cédric Le Goater
  8 siblings, 0 replies; 13+ messages in thread
From: Daniel Henrique Barboza @ 2022-01-14 18:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: Daniel Henrique Barboza, qemu-ppc, clg, david

This function does not use 'stack' anymore. Rename it to
pnv_pec_phb_update_map().

Reviewed-by: Cédric Le Goater <clg@kaod.org>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
 hw/pci-host/pnv_phb4.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/pci-host/pnv_phb4.c b/hw/pci-host/pnv_phb4.c
index 3dc3c70cb2..1db815b1ab 100644
--- a/hw/pci-host/pnv_phb4.c
+++ b/hw/pci-host/pnv_phb4.c
@@ -914,7 +914,7 @@ static void pnv_phb4_update_regions(PnvPHB4 *phb)
     pnv_phb4_check_all_mbt(phb);
 }
 
-static void pnv_pec_stk_update_map(PnvPHB4 *phb)
+static void pnv_pec_phb_update_map(PnvPHB4 *phb)
 {
     PnvPhb4PecState *pec = phb->pec;
     MemoryRegion *sysmem = get_system_memory();
@@ -1066,7 +1066,7 @@ static void pnv_pec_stk_nest_xscom_write(void *opaque, hwaddr addr,
         break;
     case PEC_NEST_STK_BAR_EN:
         phb->nest_regs[reg] = val & 0xf000000000000000ull;
-        pnv_pec_stk_update_map(phb);
+        pnv_pec_phb_update_map(phb);
         break;
     case PEC_NEST_STK_DATA_FRZ_TYPE:
     case PEC_NEST_STK_PBCQ_TUN_BAR:
-- 
2.33.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 2/8] ppc/pnv: reduce stack->stack_no usage
  2022-01-14 18:07 ` [PATCH v2 2/8] ppc/pnv: reduce stack->stack_no usage Daniel Henrique Barboza
@ 2022-01-17 10:52   ` Cédric Le Goater
  0 siblings, 0 replies; 13+ messages in thread
From: Cédric Le Goater @ 2022-01-17 10:52 UTC (permalink / raw)
  To: Daniel Henrique Barboza, qemu-devel; +Cc: qemu-ppc, david

On 1/14/22 19:07, Daniel Henrique Barboza wrote:
> 'stack->stack_no' represents the order that a stack appears in its PEC.
> Its primary use is in XSCOM address space calculation in
> pnv_phb4_xscom_realize() when calculating the memory region offset.
> 
> This attribute is redundant with phb->phb_id, which is calculated via
> pnv_phb4_pec_get_phb_id() using stack->stack_no information. It'll also
> be awkward to assign it when dealing with PECs and PHBs only in a future
> patch.
> 
> A new pnv_phb4_get_phb_stack_no() helper is introduced to eliminate most
> of the stack->stack_no uses we have. The only use left after this patch
> is during pnv_pec_stk_default_phb_realize() when calculating phb_id,
> which will also handled in the next patches.
> 
> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>

Reviewed-by: Cédric Le Goater <clg@kaod.org>

Thanks

C.

> ---
>   hw/pci-host/pnv_phb4.c | 46 +++++++++++++++++++++++++++++++-----------
>   1 file changed, 34 insertions(+), 12 deletions(-)
> 
> diff --git a/hw/pci-host/pnv_phb4.c b/hw/pci-host/pnv_phb4.c
> index 2658ef2d84..4933fe57fe 100644
> --- a/hw/pci-host/pnv_phb4.c
> +++ b/hw/pci-host/pnv_phb4.c
> @@ -868,6 +868,28 @@ static uint64_t pnv_pec_stk_nest_xscom_read(void *opaque, hwaddr addr,
>       return phb->nest_regs[reg];
>   }
>   
> +/*
> + * Return the 'stack_no' of a PHB4. 'stack_no' is the order
> + * the PHB4 occupies in the PEC. This is the reverse of what
> + * pnv_phb4_pec_get_phb_id() does.
> + *
> + * E.g. a phb with phb_id = 4 and pec->index = 1 (PEC1) will
> + * be the second phb (stack_no = 1) of the PEC.
> + */
> +static int pnv_phb4_get_phb_stack_no(PnvPHB4 *phb)
> +{
> +    PnvPhb4PecState *pec = phb->pec;
> +    PnvPhb4PecClass *pecc = PNV_PHB4_PEC_GET_CLASS(pec);
> +    int index = pec->index;
> +    int stack_no = phb->phb_id;
> +
> +    while (index--) {
> +        stack_no -= pecc->num_stacks[index];
> +    }
> +
> +    return stack_no;
> +}
> +
>   static void pnv_phb4_update_regions(PnvPHB4 *phb)
>   {
>       /* Unmap first always */
> @@ -894,10 +916,10 @@ static void pnv_phb4_update_regions(PnvPHB4 *phb)
>   
>   static void pnv_pec_stk_update_map(PnvPHB4 *phb)
>   {
> -    PnvPhb4PecStack *stack = phb->stack;
>       PnvPhb4PecState *pec = phb->pec;
>       MemoryRegion *sysmem = get_system_memory();
>       uint64_t bar_en = phb->nest_regs[PEC_NEST_STK_BAR_EN];
> +    int stack_no = pnv_phb4_get_phb_stack_no(phb);
>       uint64_t bar, mask, size;
>       char name[64];
>   
> @@ -937,7 +959,7 @@ static void pnv_pec_stk_update_map(PnvPHB4 *phb)
>           mask = phb->nest_regs[PEC_NEST_STK_MMIO_BAR0_MASK];
>           size = ((~mask) >> 8) + 1;
>           snprintf(name, sizeof(name), "pec-%d.%d-phb-%d-mmio0",
> -                 pec->chip_id, pec->index, stack->stack_no);
> +                 pec->chip_id, pec->index, stack_no);
>           memory_region_init(&phb->mmbar0, OBJECT(phb), name, size);
>           memory_region_add_subregion(sysmem, bar, &phb->mmbar0);
>           phb->mmio0_base = bar;
> @@ -949,7 +971,7 @@ static void pnv_pec_stk_update_map(PnvPHB4 *phb)
>           mask = phb->nest_regs[PEC_NEST_STK_MMIO_BAR1_MASK];
>           size = ((~mask) >> 8) + 1;
>           snprintf(name, sizeof(name), "pec-%d.%d-phb-%d-mmio1",
> -                 pec->chip_id, pec->index, stack->stack_no);
> +                 pec->chip_id, pec->index, stack_no);
>           memory_region_init(&phb->mmbar1, OBJECT(phb), name, size);
>           memory_region_add_subregion(sysmem, bar, &phb->mmbar1);
>           phb->mmio1_base = bar;
> @@ -960,7 +982,7 @@ static void pnv_pec_stk_update_map(PnvPHB4 *phb)
>           bar = phb->nest_regs[PEC_NEST_STK_PHB_REGS_BAR] >> 8;
>           size = PNV_PHB4_NUM_REGS << 3;
>           snprintf(name, sizeof(name), "pec-%d.%d-phb-%d",
> -                 pec->chip_id, pec->index, stack->stack_no);
> +                 pec->chip_id, pec->index, stack_no);
>           memory_region_init(&phb->phbbar, OBJECT(phb), name, size);
>           memory_region_add_subregion(sysmem, bar, &phb->phbbar);
>       }
> @@ -969,7 +991,7 @@ static void pnv_pec_stk_update_map(PnvPHB4 *phb)
>           bar = phb->nest_regs[PEC_NEST_STK_INT_BAR] >> 8;
>           size = PNV_PHB4_MAX_INTs << 16;
>           snprintf(name, sizeof(name), "pec-%d.%d-phb-%d-int",
> -                 phb->pec->chip_id, phb->pec->index, stack->stack_no);
> +                 phb->pec->chip_id, phb->pec->index, stack_no);
>           memory_region_init(&phb->intbar, OBJECT(phb), name, size);
>           memory_region_add_subregion(sysmem, bar, &phb->intbar);
>       }
> @@ -1458,9 +1480,9 @@ static AddressSpace *pnv_phb4_dma_iommu(PCIBus *bus, void *opaque, int devfn)
>   
>   static void pnv_phb4_xscom_realize(PnvPHB4 *phb)
>   {
> -    PnvPhb4PecStack *stack = phb->stack;
>       PnvPhb4PecState *pec = phb->pec;
>       PnvPhb4PecClass *pecc = PNV_PHB4_PEC_GET_CLASS(pec);
> +    int stack_no = pnv_phb4_get_phb_stack_no(phb);
>       uint32_t pec_nest_base;
>       uint32_t pec_pci_base;
>       char name[64];
> @@ -1469,20 +1491,20 @@ static void pnv_phb4_xscom_realize(PnvPHB4 *phb)
>   
>       /* Initialize the XSCOM regions for the stack registers */
>       snprintf(name, sizeof(name), "xscom-pec-%d.%d-nest-phb-%d",
> -             pec->chip_id, pec->index, stack->stack_no);
> +             pec->chip_id, pec->index, stack_no);
>       pnv_xscom_region_init(&phb->nest_regs_mr, OBJECT(phb),
>                             &pnv_pec_stk_nest_xscom_ops, phb, name,
>                             PHB4_PEC_NEST_STK_REGS_COUNT);
>   
>       snprintf(name, sizeof(name), "xscom-pec-%d.%d-pci-phb-%d",
> -             pec->chip_id, pec->index, stack->stack_no);
> +             pec->chip_id, pec->index, stack_no);
>       pnv_xscom_region_init(&phb->pci_regs_mr, OBJECT(phb),
>                             &pnv_pec_stk_pci_xscom_ops, phb, name,
>                             PHB4_PEC_PCI_STK_REGS_COUNT);
>   
>       /* PHB pass-through */
>       snprintf(name, sizeof(name), "xscom-pec-%d.%d-pci-phb-%d",
> -             pec->chip_id, pec->index, stack->stack_no);
> +             pec->chip_id, pec->index, stack_no);
>       pnv_xscom_region_init(&phb->phb_regs_mr, OBJECT(phb),
>                             &pnv_phb4_xscom_ops, phb, name, 0x40);
>   
> @@ -1491,14 +1513,14 @@ static void pnv_phb4_xscom_realize(PnvPHB4 *phb)
>   
>       /* Populate the XSCOM address space. */
>       pnv_xscom_add_subregion(pec->chip,
> -                            pec_nest_base + 0x40 * (stack->stack_no + 1),
> +                            pec_nest_base + 0x40 * (stack_no + 1),
>                               &phb->nest_regs_mr);
>       pnv_xscom_add_subregion(pec->chip,
> -                            pec_pci_base + 0x40 * (stack->stack_no + 1),
> +                            pec_pci_base + 0x40 * (stack_no + 1),
>                               &phb->pci_regs_mr);
>       pnv_xscom_add_subregion(pec->chip,
>                               pec_pci_base + PNV9_XSCOM_PEC_PCI_STK0 +
> -                            0x40 * stack->stack_no,
> +                            0x40 * stack_no,
>                               &phb->phb_regs_mr);
>   }
>   
> 



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 5/8] ppc/pnv: remove PnvPhb4PecStack::stack_no
  2022-01-14 18:07 ` [PATCH v2 5/8] ppc/pnv: remove PnvPhb4PecStack::stack_no Daniel Henrique Barboza
@ 2022-01-17 10:53   ` Cédric Le Goater
  0 siblings, 0 replies; 13+ messages in thread
From: Cédric Le Goater @ 2022-01-17 10:53 UTC (permalink / raw)
  To: Daniel Henrique Barboza, qemu-devel; +Cc: qemu-ppc, david

On 1/14/22 19:07, Daniel Henrique Barboza wrote:
> pnv_pec_default_phb_realize() stopped using it after the previous patch and
> no one else is using it.
> 
> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>

Reviewed-by: Cédric Le Goater <clg@kaod.org>

Thanks,

C.


> ---
>   hw/pci-host/pnv_phb4_pec.c     | 2 --
>   include/hw/pci-host/pnv_phb4.h | 3 ---
>   2 files changed, 5 deletions(-)
> 
> diff --git a/hw/pci-host/pnv_phb4_pec.c b/hw/pci-host/pnv_phb4_pec.c
> index a80a21db77..d6405d6ca3 100644
> --- a/hw/pci-host/pnv_phb4_pec.c
> +++ b/hw/pci-host/pnv_phb4_pec.c
> @@ -166,7 +166,6 @@ static void pnv_pec_realize(DeviceState *dev, Error **errp)
>           PnvPhb4PecStack *stack = &pec->stacks[i];
>           Object *stk_obj = OBJECT(stack);
>   
> -        object_property_set_int(stk_obj, "stack-no", i, &error_abort);
>           object_property_set_link(stk_obj, "pec", OBJECT(pec), &error_abort);
>   
>           if (defaults_enabled()) {
> @@ -314,7 +313,6 @@ static void pnv_pec_stk_realize(DeviceState *dev, Error **errp)
>   }
>   
>   static Property pnv_pec_stk_properties[] = {
> -        DEFINE_PROP_UINT32("stack-no", PnvPhb4PecStack, stack_no, 0),
>           DEFINE_PROP_LINK("pec", PnvPhb4PecStack, pec, TYPE_PNV_PHB4_PEC,
>                            PnvPhb4PecState *),
>           DEFINE_PROP_END_OF_LIST(),
> diff --git a/include/hw/pci-host/pnv_phb4.h b/include/hw/pci-host/pnv_phb4.h
> index a9059b7279..2be56b7afd 100644
> --- a/include/hw/pci-host/pnv_phb4.h
> +++ b/include/hw/pci-host/pnv_phb4.h
> @@ -171,9 +171,6 @@ OBJECT_DECLARE_SIMPLE_TYPE(PnvPhb4PecStack, PNV_PHB4_PEC_STACK)
>   struct PnvPhb4PecStack {
>       DeviceState parent;
>   
> -    /* My own stack number */
> -    uint32_t stack_no;
> -
>       /* The owner PEC */
>       PnvPhb4PecState *pec;
>   
> 



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 6/8] ppc/pnv: make PECs create and realize PHB4s
  2022-01-14 18:07 ` [PATCH v2 6/8] ppc/pnv: make PECs create and realize PHB4s Daniel Henrique Barboza
@ 2022-01-17 10:55   ` Cédric Le Goater
  0 siblings, 0 replies; 13+ messages in thread
From: Cédric Le Goater @ 2022-01-17 10:55 UTC (permalink / raw)
  To: Daniel Henrique Barboza, qemu-devel; +Cc: qemu-ppc, david

On 1/14/22 19:07, Daniel Henrique Barboza wrote:
> This patch changes the design of the PEC device to create and realize PHB4s
> instead of PecStacks. After all the recent changes, PHB4s now contain all
> the information needed for their proper functioning, not relying on PecStack
> in any capacity.
> 
> All changes are being made in a single patch to avoid renaming parts of
> the PecState and leaving the code in a strange way. E.g. rename
> PecClass->num_stacks to num_phbs, which would then read a
> pnv_pec_num_stacks[] array. To avoid mixing the old and new design more
> than necessary it's clearer to do these changes in a single step.
> 
> The name changes made are:
> 
> - in PnvPhb4PecState:
>    * rename 'num_stacks' to 'num_phbs'
>    * remove the pec->stacks[] array. Current code relies on the
> pec->stacks[] obj acting as a simple container, without ever accessing
> pec->stacks[] for any other purpose. Instead of converting this into a
> pec->phbs[] array, remove it
> 
> - in PnvPhb4PecClass, rename *num_stacks to *num_phbs;
> 
> - pnv_pec_num_stacks[] is renamed to pnv_pec_num_phbs[].
> 
> The logical changes:
> 
> - pnv_pec_default_phb_realize():
>    * init and set the properties of the PnvPHB4 qdev
>    * do not use stack->phb anymore;
> 
> - pnv_pec_realize():
>    * use the new default_phb_realize() to init/realize each PHB if
> running with defaults;
> 
> - pnv_pec_instance_init(): removed since we're creating the PHBs during
> pec_realize();
> 
> - pnv_phb4_get_stack():
>    * renamed to pnv_phb4_get_pec() and returns a PnvPhb4PecState*;
> 
> - pnv_phb4_realize(): use 'phb->pec' instead of 'stack'.
> 
> This design change shouldn't caused any behavioral change in the runtime
> of the machine.
> 
> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>

Reviewed-by: Cédric Le Goater <clg@kaod.org>

Thanks,

C.

> ---
>   hw/pci-host/pnv_phb4.c         | 26 ++++++--------
>   hw/pci-host/pnv_phb4_pec.c     | 66 ++++++++++------------------------
>   include/hw/pci-host/pnv_phb4.h |  8 ++---
>   3 files changed, 31 insertions(+), 69 deletions(-)
> 
> diff --git a/hw/pci-host/pnv_phb4.c b/hw/pci-host/pnv_phb4.c
> index 2efd34518e..3dc3c70cb2 100644
> --- a/hw/pci-host/pnv_phb4.c
> +++ b/hw/pci-host/pnv_phb4.c
> @@ -884,7 +884,7 @@ static int pnv_phb4_get_phb_stack_no(PnvPHB4 *phb)
>       int stack_no = phb->phb_id;
>   
>       while (index--) {
> -        stack_no -= pecc->num_stacks[index];
> +        stack_no -= pecc->num_phbs[index];
>       }
>   
>       return stack_no;
> @@ -1383,7 +1383,7 @@ int pnv_phb4_pec_get_phb_id(PnvPhb4PecState *pec, int stack_index)
>       int offset = 0;
>   
>       while (index--) {
> -        offset += pecc->num_stacks[index];
> +        offset += pecc->num_phbs[index];
>       }
>   
>       return offset + stack_index;
> @@ -1534,8 +1534,8 @@ static void pnv_phb4_instance_init(Object *obj)
>       object_initialize_child(obj, "source", &phb->xsrc, TYPE_XIVE_SOURCE);
>   }
>   
> -static PnvPhb4PecStack *pnv_phb4_get_stack(PnvChip *chip, PnvPHB4 *phb,
> -                                           Error **errp)
> +static PnvPhb4PecState *pnv_phb4_get_pec(PnvChip *chip, PnvPHB4 *phb,
> +                                         Error **errp)
>   {
>       Pnv9Chip *chip9 = PNV9_CHIP(chip);
>       int chip_id = phb->chip_id;
> @@ -1544,14 +1544,14 @@ static PnvPhb4PecStack *pnv_phb4_get_stack(PnvChip *chip, PnvPHB4 *phb,
>   
>       for (i = 0; i < chip->num_pecs; i++) {
>           /*
> -         * For each PEC, check the amount of stacks it supports
> -         * and see if the given phb4 index matches a stack.
> +         * For each PEC, check the amount of phbs it supports
> +         * and see if the given phb4 index matches an index.
>            */
>           PnvPhb4PecState *pec = &chip9->pecs[i];
>   
> -        for (j = 0; j < pec->num_stacks; j++) {
> +        for (j = 0; j < pec->num_phbs; j++) {
>               if (index == pnv_phb4_pec_get_phb_id(pec, j)) {
> -                return &pec->stacks[j];
> +                return pec;
>               }
>           }
>       }
> @@ -1576,7 +1576,6 @@ static void pnv_phb4_realize(DeviceState *dev, Error **errp)
>       if (!phb->pec) {
>           PnvMachineState *pnv = PNV_MACHINE(qdev_get_machine());
>           PnvChip *chip = pnv_get_chip(pnv, phb->chip_id);
> -        PnvPhb4PecStack *stack;
>           PnvPhb4PecClass *pecc;
>           BusState *s;
>   
> @@ -1585,18 +1584,13 @@ static void pnv_phb4_realize(DeviceState *dev, Error **errp)
>               return;
>           }
>   
> -        stack = pnv_phb4_get_stack(chip, phb, &local_err);
> +        phb->pec = pnv_phb4_get_pec(chip, phb, &local_err);
>           if (local_err) {
>               error_propagate(errp, local_err);
>               return;
>           }
>   
> -        /*
> -         * All other phb properties but 'pec' ad 'version' are
> -         * already set.
> -         */
> -        object_property_set_link(OBJECT(phb), "pec", OBJECT(stack->pec),
> -                                 &error_abort);
> +        /* All other phb properties are already set */
>           pecc = PNV_PHB4_PEC_GET_CLASS(phb->pec);
>           object_property_set_int(OBJECT(phb), "version", pecc->version,
>                                   &error_fatal);
> diff --git a/hw/pci-host/pnv_phb4_pec.c b/hw/pci-host/pnv_phb4_pec.c
> index d6405d6ca3..852816b9f8 100644
> --- a/hw/pci-host/pnv_phb4_pec.c
> +++ b/hw/pci-host/pnv_phb4_pec.c
> @@ -112,41 +112,28 @@ static const MemoryRegionOps pnv_pec_pci_xscom_ops = {
>       .endianness = DEVICE_BIG_ENDIAN,
>   };
>   
> -static void pnv_pec_default_phb_realize(PnvPhb4PecStack *stack,
> +static void pnv_pec_default_phb_realize(PnvPhb4PecState *pec,
>                                           int stack_no,
>                                           Error **errp)
>   {
> -    PnvPhb4PecState *pec = stack->pec;
> +    PnvPHB4 *phb = PNV_PHB4(qdev_new(TYPE_PNV_PHB4));
>       PnvPhb4PecClass *pecc = PNV_PHB4_PEC_GET_CLASS(pec);
>       int phb_id = pnv_phb4_pec_get_phb_id(pec, stack_no);
>   
> -    stack->phb = PNV_PHB4(qdev_new(TYPE_PNV_PHB4));
> -
> -    object_property_set_link(OBJECT(stack->phb), "pec", OBJECT(pec),
> +    object_property_set_link(OBJECT(phb), "pec", OBJECT(pec),
>                                &error_abort);
> -    object_property_set_int(OBJECT(stack->phb), "chip-id", pec->chip_id,
> +    object_property_set_int(OBJECT(phb), "chip-id", pec->chip_id,
>                               &error_fatal);
> -    object_property_set_int(OBJECT(stack->phb), "index", phb_id,
> +    object_property_set_int(OBJECT(phb), "index", phb_id,
>                               &error_fatal);
> -    object_property_set_int(OBJECT(stack->phb), "version", pecc->version,
> +    object_property_set_int(OBJECT(phb), "version", pecc->version,
>                               &error_fatal);
>   
> -    if (!sysbus_realize(SYS_BUS_DEVICE(stack->phb), errp)) {
> +    if (!sysbus_realize(SYS_BUS_DEVICE(phb), errp)) {
>           return;
>       }
>   }
>   
> -static void pnv_pec_instance_init(Object *obj)
> -{
> -    PnvPhb4PecState *pec = PNV_PHB4_PEC(obj);
> -    int i;
> -
> -    for (i = 0; i < PHB4_PEC_MAX_STACKS; i++) {
> -        object_initialize_child(obj, "stack[*]", &pec->stacks[i],
> -                                TYPE_PNV_PHB4_PEC_STACK);
> -    }
> -}
> -
>   static void pnv_pec_realize(DeviceState *dev, Error **errp)
>   {
>       PnvPhb4PecState *pec = PNV_PHB4_PEC(dev);
> @@ -159,29 +146,13 @@ static void pnv_pec_realize(DeviceState *dev, Error **errp)
>           return;
>       }
>   
> -    pec->num_stacks = pecc->num_stacks[pec->index];
> -
> -    /* Create stacks */
> -    for (i = 0; i < pec->num_stacks; i++) {
> -        PnvPhb4PecStack *stack = &pec->stacks[i];
> -        Object *stk_obj = OBJECT(stack);
> -
> -        object_property_set_link(stk_obj, "pec", OBJECT(pec), &error_abort);
> +    pec->num_phbs = pecc->num_phbs[pec->index];
>   
> -        if (defaults_enabled()) {
> -            pnv_pec_default_phb_realize(stack, i, errp);
> +    /* Create PHBs if running with defaults */
> +    if (defaults_enabled()) {
> +        for (i = 0; i < pec->num_phbs; i++) {
> +            pnv_pec_default_phb_realize(pec, i, errp);
>           }
> -
> -        /*
> -         * qdev gets angry if we don't realize 'stack' here, even
> -         * if stk_realize() is now empty.
> -         */
> -        if (!qdev_realize(DEVICE(stk_obj), NULL, errp)) {
> -            return;
> -        }
> -    }
> -    for (; i < PHB4_PEC_MAX_STACKS; i++) {
> -        object_unparent(OBJECT(&pec->stacks[i]));
>       }
>   
>       /* Initialize the XSCOM regions for the PEC registers */
> @@ -227,7 +198,7 @@ static int pnv_pec_dt_xscom(PnvXScomInterface *dev, void *fdt,
>       _FDT((fdt_setprop(fdt, offset, "compatible", pecc->compat,
>                         pecc->compat_size)));
>   
> -    for (i = 0; i < pec->num_stacks; i++) {
> +    for (i = 0; i < pec->num_phbs; i++) {
>           int phb_id = pnv_phb4_pec_get_phb_id(pec, i);
>           int stk_offset;
>   
> @@ -263,11 +234,11 @@ static uint32_t pnv_pec_xscom_nest_base(PnvPhb4PecState *pec)
>   }
>   
>   /*
> - * PEC0 -> 1 stack
> - * PEC1 -> 2 stacks
> - * PEC2 -> 3 stacks
> + * PEC0 -> 1 phb
> + * PEC1 -> 2 phb
> + * PEC2 -> 3 phbs
>    */
> -static const uint32_t pnv_pec_num_stacks[] = { 1, 2, 3 };
> +static const uint32_t pnv_pec_num_phbs[] = { 1, 2, 3 };
>   
>   static void pnv_pec_class_init(ObjectClass *klass, void *data)
>   {
> @@ -292,14 +263,13 @@ static void pnv_pec_class_init(ObjectClass *klass, void *data)
>       pecc->stk_compat = stk_compat;
>       pecc->stk_compat_size = sizeof(stk_compat);
>       pecc->version = PNV_PHB4_VERSION;
> -    pecc->num_stacks = pnv_pec_num_stacks;
> +    pecc->num_phbs = pnv_pec_num_phbs;
>   }
>   
>   static const TypeInfo pnv_pec_type_info = {
>       .name          = TYPE_PNV_PHB4_PEC,
>       .parent        = TYPE_DEVICE,
>       .instance_size = sizeof(PnvPhb4PecState),
> -    .instance_init = pnv_pec_instance_init,
>       .class_init    = pnv_pec_class_init,
>       .class_size    = sizeof(PnvPhb4PecClass),
>       .interfaces    = (InterfaceInfo[]) {
> diff --git a/include/hw/pci-host/pnv_phb4.h b/include/hw/pci-host/pnv_phb4.h
> index 2be56b7afd..e750165e77 100644
> --- a/include/hw/pci-host/pnv_phb4.h
> +++ b/include/hw/pci-host/pnv_phb4.h
> @@ -200,10 +200,8 @@ struct PnvPhb4PecState {
>       uint64_t pci_regs[PHB4_PEC_PCI_REGS_COUNT];
>       MemoryRegion pci_regs_mr;
>   
> -    /* Stacks */
> -    #define PHB4_PEC_MAX_STACKS     3
> -    uint32_t num_stacks;
> -    PnvPhb4PecStack stacks[PHB4_PEC_MAX_STACKS];
> +    /* PHBs */
> +    uint32_t num_phbs;
>   
>       PnvChip *chip;
>   };
> @@ -221,7 +219,7 @@ struct PnvPhb4PecClass {
>       const char *stk_compat;
>       int stk_compat_size;
>       uint64_t version;
> -    const uint32_t *num_stacks;
> +    const uint32_t *num_phbs;
>   };
>   
>   #endif /* PCI_HOST_PNV_PHB4_H */
> 



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 0/8] remove PnvPhb4PecStack from Powernv9
  2022-01-14 18:07 [PATCH v2 0/8] remove PnvPhb4PecStack from Powernv9 Daniel Henrique Barboza
                   ` (7 preceding siblings ...)
  2022-01-14 18:07 ` [PATCH v2 8/8] ppc/pnv: rename pnv_pec_stk_update_map() Daniel Henrique Barboza
@ 2022-01-18 12:03 ` Cédric Le Goater
  8 siblings, 0 replies; 13+ messages in thread
From: Cédric Le Goater @ 2022-01-18 12:03 UTC (permalink / raw)
  To: Daniel Henrique Barboza, qemu-devel; +Cc: qemu-ppc, david

On 1/14/22 19:07, Daniel Henrique Barboza wrote:
> Hi,
> 
> This second version contains improvements suggested by Cedric in the
> v1 review.
> 
> Patches 1-10 from v1 are already accepted and aren't included in this
> v2.
> 
> 
> Changes from v1:
> - v1 patches 1-10: already accepted, not included in the v2
> - 'stack-stack_no' use is eliminated. We're now deriving stack_no from
> phb->phb_id
> - no longer use phb->phb_number
> - no longer use pec->phbs[]
> - v1 link: https://lists.gnu.org/archive/html/qemu-devel/2022-01/msg03000.html
> 
> Daniel Henrique Barboza (8):
>    ppc/pnv: introduce PnvPHB4 'pec' property
>    ppc/pnv: reduce stack->stack_no usage
>    ppc/pnv: remove stack pointer from PnvPHB4
>    ppc/pnv: move default_phb_realize() to pec_realize()
>    ppc/pnv: remove PnvPhb4PecStack::stack_no
>    ppc/pnv: make PECs create and realize PHB4s
>    ppc/pnv: remove PnvPhb4PecStack object
>    ppc/pnv: rename pnv_pec_stk_update_map()
> 
>   hw/pci-host/pnv_phb4.c         |  88 ++++++++++++++----------
>   hw/pci-host/pnv_phb4_pec.c     | 118 ++++++++-------------------------
>   include/hw/pci-host/pnv_phb4.h |  33 ++-------
>   3 files changed, 86 insertions(+), 153 deletions(-)
> 

Applied to ppc-7.0

Thanks,

C.



^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-01-18 12:36 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-14 18:07 [PATCH v2 0/8] remove PnvPhb4PecStack from Powernv9 Daniel Henrique Barboza
2022-01-14 18:07 ` [PATCH v2 1/8] ppc/pnv: introduce PnvPHB4 'pec' property Daniel Henrique Barboza
2022-01-14 18:07 ` [PATCH v2 2/8] ppc/pnv: reduce stack->stack_no usage Daniel Henrique Barboza
2022-01-17 10:52   ` Cédric Le Goater
2022-01-14 18:07 ` [PATCH v2 3/8] ppc/pnv: remove stack pointer from PnvPHB4 Daniel Henrique Barboza
2022-01-14 18:07 ` [PATCH v2 4/8] ppc/pnv: move default_phb_realize() to pec_realize() Daniel Henrique Barboza
2022-01-14 18:07 ` [PATCH v2 5/8] ppc/pnv: remove PnvPhb4PecStack::stack_no Daniel Henrique Barboza
2022-01-17 10:53   ` Cédric Le Goater
2022-01-14 18:07 ` [PATCH v2 6/8] ppc/pnv: make PECs create and realize PHB4s Daniel Henrique Barboza
2022-01-17 10:55   ` Cédric Le Goater
2022-01-14 18:07 ` [PATCH v2 7/8] ppc/pnv: remove PnvPhb4PecStack object Daniel Henrique Barboza
2022-01-14 18:07 ` [PATCH v2 8/8] ppc/pnv: rename pnv_pec_stk_update_map() Daniel Henrique Barboza
2022-01-18 12:03 ` [PATCH v2 0/8] remove PnvPhb4PecStack from Powernv9 Cédric Le Goater

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.