[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 21/60] ppc/pnv: add helpers for pnv-phb user devices
From: |
Daniel Henrique Barboza |
Subject: |
[PULL 21/60] ppc/pnv: add helpers for pnv-phb user devices |
Date: |
Wed, 31 Aug 2022 15:49:55 -0300 |
pnv_parent_qom_fixup() and pnv_parent_bus_fixup() are versions of the
helpers that were reverted by commit 9c10d86fee "ppc/pnv: Remove
user-created PHB{3,4,5} devices". They are needed to amend the QOM and
bus hierarchies of user created pnv-phbs, matching them with default
pnv-phbs.
A new helper pnv_phb_user_device_init() is created to handle
user-created devices setup. We're going to call it inside
pnv_phb_realize() in case we're realizing an user created device. This
will centralize all user device realated in a single spot, leaving the
realize functions of the phb3/phb4 backends untouched.
Another helper called pnv_chip_add_phb() was added to handle the
particularities of each chip version when adding a new PHB.
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Reviewed-by: Frederic Barrat <fbarrat@linux.ibm.com>
Message-Id: <20220811163950.578927-5-danielhb413@gmail.com>
---
hw/pci-host/pnv_phb.c | 75 +++++++++++++++++++++++++++++++++++++++++++
hw/ppc/pnv.c | 20 ++++++++++++
include/hw/ppc/pnv.h | 1 +
3 files changed, 96 insertions(+)
diff --git a/hw/pci-host/pnv_phb.c b/hw/pci-host/pnv_phb.c
index 826c0c144e..5dc44f45d1 100644
--- a/hw/pci-host/pnv_phb.c
+++ b/hw/pci-host/pnv_phb.c
@@ -18,6 +18,38 @@
#include "hw/qdev-properties.h"
#include "qom/object.h"
+
+/*
+ * Set the QOM parent of an object child. If the device state
+ * associated with the child has an id, use it as QOM id. Otherwise
+ * use object_typename[index] as QOM id.
+ */
+static void pnv_parent_qom_fixup(Object *parent, Object *child, int index)
+{
+ g_autofree char *default_id =
+ g_strdup_printf("%s[%d]", object_get_typename(child), index);
+ const char *dev_id = DEVICE(child)->id;
+
+ if (child->parent == parent) {
+ return;
+ }
+
+ object_ref(child);
+ object_unparent(child);
+ object_property_add_child(parent, dev_id ? dev_id : default_id, child);
+ object_unref(child);
+}
+
+static void pnv_parent_bus_fixup(DeviceState *parent, DeviceState *child,
+ Error **errp)
+{
+ BusState *parent_bus = qdev_get_parent_bus(parent);
+
+ if (!qdev_set_parent_bus(child, parent_bus, errp)) {
+ return;
+ }
+}
+
/*
* Attach a root port device.
*
@@ -41,6 +73,39 @@ static void pnv_phb_attach_root_port(PCIHostState *pci)
pci_realize_and_unref(root, pci->bus, &error_fatal);
}
+/*
+ * User created devices won't have the initial setup that default
+ * devices have. This setup consists of assigning a parent device
+ * (chip for PHB3, PEC for PHB4/5) that will be the QOM/bus parent
+ * of the PHB.
+ */
+static bool pnv_phb_user_device_init(PnvPHB *phb, Error **errp)
+{
+ PnvMachineState *pnv = PNV_MACHINE(qdev_get_machine());
+ PnvChip *chip = pnv_get_chip(pnv, phb->chip_id);
+ Object *parent = NULL;
+
+ if (!chip) {
+ error_setg(errp, "invalid chip id: %d", phb->chip_id);
+ return false;
+ }
+
+ parent = pnv_chip_add_phb(chip, phb, errp);
+ if (!parent) {
+ return false;
+ }
+
+ /*
+ * Reparent user created devices to the chip to build
+ * correctly the device tree. pnv_xscom_dt() needs every
+ * PHB to be a child of the chip to build the DT correctly.
+ */
+ pnv_parent_qom_fixup(parent, OBJECT(phb), phb->phb_id);
+ pnv_parent_bus_fixup(DEVICE(chip), DEVICE(phb), errp);
+
+ return true;
+}
+
static void pnv_phb_realize(DeviceState *dev, Error **errp)
{
PnvPHB *phb = PNV_PHB(dev);
@@ -74,6 +139,16 @@ static void pnv_phb_realize(DeviceState *dev, Error **errp)
object_property_set_uint(phb->backend, "chip-id", phb->chip_id, errp);
object_property_set_link(phb->backend, "phb-base", OBJECT(phb), errp);
+ /*
+ * Handle user created devices. User devices will not have a
+ * pointer to a chip (PHB3) and a PEC (PHB4/5).
+ */
+ if (!phb->chip && !phb->pec) {
+ if (!pnv_phb_user_device_init(phb, errp)) {
+ return;
+ }
+ }
+
if (phb->version == 3) {
object_property_set_link(phb->backend, "chip",
OBJECT(phb->chip), errp);
diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c
index 758e36132d..737dee4980 100644
--- a/hw/ppc/pnv.c
+++ b/hw/ppc/pnv.c
@@ -281,6 +281,26 @@ static void pnv_dt_icp(PnvChip *chip, void *fdt, uint32_t
pir,
g_free(reg);
}
+/*
+ * Adds a PnvPHB to the chip. Returns the parent obj of the
+ * PHB which varies with each version (phb version 3 is parented
+ * by the chip, version 4 and 5 are parented by the PEC
+ * device).
+ *
+ * TODO: for version 3 we're still parenting the PHB with the
+ * chip. We should parent with a (so far not implemented)
+ * PHB3 PEC device.
+ */
+Object *pnv_chip_add_phb(PnvChip *chip, PnvPHB *phb, Error **errp)
+{
+ if (phb->version == 3) {
+ return OBJECT(chip);
+ } else {
+ /* phb4 support will be added later */
+ return NULL;
+ }
+}
+
static void pnv_chip_power8_dt_populate(PnvChip *chip, void *fdt)
{
static const char compat[] = "ibm,power8-xscom\0ibm,xscom";
diff --git a/include/hw/ppc/pnv.h b/include/hw/ppc/pnv.h
index 290adac76c..c44f357bce 100644
--- a/include/hw/ppc/pnv.h
+++ b/include/hw/ppc/pnv.h
@@ -234,6 +234,7 @@ struct PnvMachineState {
};
PnvChip *pnv_get_chip(PnvMachineState *pnv, uint32_t chip_id);
+Object *pnv_chip_add_phb(PnvChip *chip, PnvPHB *phb, Error **errp);
#define PNV_FDT_ADDR 0x01000000
#define PNV_TIMEBASE_FREQ 512000000ULL
--
2.37.2
- [PULL 10/60] ppc/pnv: turn PnvPHB4 into a PnvPHB backend, (continued)
- [PULL 10/60] ppc/pnv: turn PnvPHB4 into a PnvPHB backend, Daniel Henrique Barboza, 2022/08/31
- [PULL 11/60] ppc/pnv: add pnv-phb-root-port device, Daniel Henrique Barboza, 2022/08/31
- [PULL 12/60] ppc/pnv: remove pnv-phb3-root-port, Daniel Henrique Barboza, 2022/08/31
- [PULL 13/60] ppc/pnv: remove pnv-phb4-root-port, Daniel Henrique Barboza, 2022/08/31
- [PULL 15/60] ppc/pnv: remove pecc->rp_model, Daniel Henrique Barboza, 2022/08/31
- [PULL 14/60] ppc/pnv: remove root port name from pnv_phb_attach_root_port(), Daniel Henrique Barboza, 2022/08/31
- [PULL 16/60] ppc/pnv: remove PnvPHB4.version, Daniel Henrique Barboza, 2022/08/31
- [PULL 17/60] ppc/pnv: move attach_root_port helper to pnv-phb.c, Daniel Henrique Barboza, 2022/08/31
- [PULL 18/60] ppc/pnv: add phb-id/chip-id PnvPHB3RootBus properties, Daniel Henrique Barboza, 2022/08/31
- [PULL 20/60] ppc/pnv: set root port chassis and slot using Bus properties, Daniel Henrique Barboza, 2022/08/31
- [PULL 21/60] ppc/pnv: add helpers for pnv-phb user devices,
Daniel Henrique Barboza <=
- [PULL 19/60] ppc/pnv: add phb-id/chip-id PnvPHB4RootBus properties, Daniel Henrique Barboza, 2022/08/31
- [PULL 22/60] ppc/pnv: turn chip8->phbs[] into a PnvPHB* array, Daniel Henrique Barboza, 2022/08/31
- [PULL 24/60] ppc/pnv: add PHB4 helpers for user created pnv-phb, Daniel Henrique Barboza, 2022/08/31
- [PULL 23/60] ppc/pnv: enable user created pnv-phb for powernv8, Daniel Henrique Barboza, 2022/08/31
- [PULL 25/60] ppc/pnv: enable user created pnv-phb for powernv9, Daniel Henrique Barboza, 2022/08/31
- [PULL 26/60] ppc/pnv: change pnv_phb4_get_pec() to also retrieve chip10->pecs, Daniel Henrique Barboza, 2022/08/31
- [PULL 27/60] ppc/pnv: user creatable pnv-phb for powernv10, Daniel Henrique Barboza, 2022/08/31
- [PULL 29/60] ppc/pnv: fix QOM parenting of user creatable root ports, Daniel Henrique Barboza, 2022/08/31
- [PULL 28/60] ppc/pnv: consolidate pnv_parent_*_fixup() helpers, Daniel Henrique Barboza, 2022/08/31
- [PULL 30/60] ppc/ppc405: Remove taihu machine, Daniel Henrique Barboza, 2022/08/31