[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 09/11] ppc/pnv: add PHB object/bus parenting helpers
From: |
Daniel Henrique Barboza |
Subject: |
[PATCH 09/11] ppc/pnv: add PHB object/bus parenting helpers |
Date: |
Mon, 13 Jun 2022 12:44:54 -0300 |
These helpers are inspired by the changes that were reverted in commit
9c10d86fee "ppc/pnv: Remove user-created PHB{3,4,5} devices". We'll use
them to handle the default case we already support.
Signed-off-by: Daniel Henrique Barboza <danielhb@linux.ibm.com>
---
hw/ppc/pnv.c | 31 +++++++++++++++++++++++++++++++
include/hw/ppc/pnv.h | 2 ++
2 files changed, 33 insertions(+)
diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c
index 6ce9e94e05..d77c90d64a 100644
--- a/hw/ppc/pnv.c
+++ b/hw/ppc/pnv.c
@@ -1983,6 +1983,37 @@ static ICSState *pnv_ics_get(XICSFabric *xi, int irq)
return NULL;
}
+
+/*
+ * 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.
+ */
+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);
+}
+
+void pnv_parent_bus_fixup(DeviceState *parent, DeviceState *phb_dev)
+{
+ BusState *s = qdev_get_parent_bus(parent);
+
+ if (!qdev_set_parent_bus(phb_dev, s, &error_fatal)) {
+ return;
+ }
+}
+
PnvChip *pnv_get_chip(PnvMachineState *pnv, uint32_t chip_id)
{
int i;
diff --git a/include/hw/ppc/pnv.h b/include/hw/ppc/pnv.h
index 11f1089289..c091f23039 100644
--- a/include/hw/ppc/pnv.h
+++ b/include/hw/ppc/pnv.h
@@ -194,6 +194,8 @@ DECLARE_INSTANCE_CHECKER(PnvChip, PNV_CHIP_POWER10,
PowerPCCPU *pnv_chip_find_cpu(PnvChip *chip, uint32_t pir);
void pnv_phb_attach_root_port(PCIHostState *pci, const char *name, int index);
+void pnv_parent_qom_fixup(Object *parent, Object *child, int index);
+void pnv_parent_bus_fixup(DeviceState *parent, DeviceState *child);
#define TYPE_PNV_MACHINE MACHINE_TYPE_NAME("powernv")
typedef struct PnvMachineClass PnvMachineClass;
--
2.36.1