[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 09/17] ppc/pnv: user creatable pnv-phb for powernv9
From: |
Daniel Henrique Barboza |
Subject: |
[PATCH 09/17] ppc/pnv: user creatable pnv-phb for powernv9 |
Date: |
Sat, 7 May 2022 16:06:16 -0300 |
This patch reintroduces the powernv8 bits of the code what was removed
in commit 9c10d86fee "ppc/pnv: Remove user-created PHB{3,4,5} devices",
using the pnv-phb device instead of the now late pnv-phb4 device,
allowing us to enable user creatable pnv-phb devices for the powernv9
machine.
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
hw/pci-host/pnv_phb4.c | 58 +++++++++++++++++++++++++++++++++++++-
hw/pci-host/pnv_phb4_pec.c | 6 ++--
hw/ppc/pnv.c | 2 ++
3 files changed, 63 insertions(+), 3 deletions(-)
diff --git a/hw/pci-host/pnv_phb4.c b/hw/pci-host/pnv_phb4.c
index becfd366f1..262251ebcf 100644
--- a/hw/pci-host/pnv_phb4.c
+++ b/hw/pci-host/pnv_phb4.c
@@ -1544,14 +1544,70 @@ void pnv_phb4_instance_init(Object *obj)
object_initialize_child(obj, "source", &phb->xsrc, TYPE_XIVE_SOURCE);
}
+static PnvPhb4PecState *pnv_phb4_get_pec(PnvChip *chip, PnvPHB *phb,
+ Error **errp)
+{
+ Pnv9Chip *chip9 = PNV9_CHIP(chip);
+ int chip_id = phb->chip_id;
+ int index = phb->phb_id;
+ int i, j;
+
+ for (i = 0; i < chip->num_pecs; i++) {
+ /*
+ * 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_phbs; j++) {
+ if (index == pnv_phb4_pec_get_phb_id(pec, j)) {
+ return pec;
+ }
+ }
+ }
+
+ error_setg(errp,
+ "pnv-phb chip-id %d index %d didn't match any existing PEC",
+ chip_id, index);
+
+ return NULL;
+}
+
void pnv_phb4_realize(DeviceState *dev, Error **errp)
{
PnvPHB *phb = PNV_PHB(dev);
+ PnvMachineState *pnv = PNV_MACHINE(qdev_get_machine());
+ PnvChip *chip = pnv_get_chip(pnv, phb->chip_id);
PCIHostState *pci = PCI_HOST_BRIDGE(dev);
XiveSource *xsrc = &phb->xsrc;
+ BusState *s;
+ Error *local_err = NULL;
int nr_irqs;
char name[32];
+ if (!chip) {
+ error_setg(errp, "invalid chip id: %d", phb->chip_id);
+ return;
+ }
+
+ /* User created PHBs need to be assigned to a PEC */
+ if (!phb->pec) {
+ phb->pec = pnv_phb4_get_pec(chip, phb, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
+ }
+
+ /* Reparent the PHB to the chip to build the device tree */
+ pnv_chip_parent_fixup(chip, OBJECT(phb), phb->phb_id);
+
+ s = qdev_get_parent_bus(DEVICE(chip));
+ if (!qdev_set_parent_bus(DEVICE(phb), s, &local_err)) {
+ error_propagate(errp, local_err);
+ return;
+ }
+
/* Set the "big_phb" flag */
phb->big_phb = phb->phb_id == 0 || phb->phb_id == 3;
@@ -1763,7 +1819,7 @@ static void pnv_phb4_root_port_class_init(ObjectClass
*klass, void *data)
PCIERootPortClass *rpc = PCIE_ROOT_PORT_CLASS(klass);
dc->desc = "IBM PHB4 PCIE Root Port";
- dc->user_creatable = false;
+ dc->user_creatable = true;
device_class_set_parent_realize(dc, pnv_phb4_root_port_realize,
&rpc->parent_realize);
diff --git a/hw/pci-host/pnv_phb4_pec.c b/hw/pci-host/pnv_phb4_pec.c
index 3eed560e44..243a079ea7 100644
--- a/hw/pci-host/pnv_phb4_pec.c
+++ b/hw/pci-host/pnv_phb4_pec.c
@@ -150,8 +150,10 @@ static void pnv_pec_realize(DeviceState *dev, Error **errp)
pec->num_phbs = pecc->num_phbs[pec->index];
/* Create PHBs if running with defaults */
- for (i = 0; i < pec->num_phbs; i++) {
- pnv_pec_default_phb_realize(pec, i, errp);
+ if (defaults_enabled()) {
+ for (i = 0; i < pec->num_phbs; i++) {
+ pnv_pec_default_phb_realize(pec, i, errp);
+ }
}
/* Initialize the XSCOM regions for the PEC registers */
diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c
index 34a200a29c..1a3cafcb7a 100644
--- a/hw/ppc/pnv.c
+++ b/hw/ppc/pnv.c
@@ -2155,6 +2155,8 @@ static void pnv_machine_power9_class_init(ObjectClass
*oc, void *data)
pmc->compat = compat;
pmc->compat_size = sizeof(compat);
pmc->dt_power_mgt = pnv_dt_power_mgt;
+
+ machine_class_allow_dynamic_sysbus_dev(mc, TYPE_PNV_PHB);
}
static void pnv_machine_power10_class_init(ObjectClass *oc, void *data)
--
2.32.0
- [PATCH 00/17] powernv: introduce pnv-phb unified devices, Daniel Henrique Barboza, 2022/05/07
- [PATCH 01/17] ppc/pnv: rename PnvPHB3.ioda* to PnvPHB3.ioda2*, Daniel Henrique Barboza, 2022/05/07
- [PATCH 02/17] ppc/pnv: rename PnvPHB3.regs[] to PnvPHB3.regs3[], Daniel Henrique Barboza, 2022/05/07
- [PATCH 03/17] ppc/pnv: rename PnvPHB3.dma_spaces to PnvPHB3.v3_dma_spaces, Daniel Henrique Barboza, 2022/05/07
- [PATCH 04/17] ppc/pnv: add unified pnv-phb header, Daniel Henrique Barboza, 2022/05/07
- [PATCH 05/17] ppc/pnv: add pnv-phb device, Daniel Henrique Barboza, 2022/05/07
- [PATCH 06/17] ppc/pnv: remove PnvPHB3, Daniel Henrique Barboza, 2022/05/07
- [PATCH 07/17] ppc/pnv: user created pnv-phb for powernv8, Daniel Henrique Barboza, 2022/05/07
- [PATCH 08/17] ppc/pnv: remove PnvPHB4, Daniel Henrique Barboza, 2022/05/07
- [PATCH 09/17] ppc/pnv: user creatable pnv-phb for powernv9,
Daniel Henrique Barboza <=
- [PATCH 10/17] ppc/pnv: use PnvPHB.version, Daniel Henrique Barboza, 2022/05/07
- [PATCH 11/17] ppc/pnv: change pnv_phb4_get_pec() to also retrieve chip10->pecs, Daniel Henrique Barboza, 2022/05/07
- [PATCH 14/17] ppc/pnv: add pnv-phb-root-port device, Daniel Henrique Barboza, 2022/05/07
- [PATCH 12/17] ppc/pnv: user creatable pnv-phb for powernv10, Daniel Henrique Barboza, 2022/05/07
- [PATCH 16/17] ppc/pnv: remove pnv-phb4-root-port, Daniel Henrique Barboza, 2022/05/07
- [PATCH 13/17] ppc/pnv: add pnv_phb_get_current_machine(), Daniel Henrique Barboza, 2022/05/07
- [PATCH 15/17] ppc/pnv: remove pnv-phb3-root-port, Daniel Henrique Barboza, 2022/05/07
- [PATCH 17/17] ppc/pnv: remove pecc->rp_model, Daniel Henrique Barboza, 2022/05/07
- Re: [PATCH 00/17] powernv: introduce pnv-phb unified devices, Mark Cave-Ayland, 2022/05/09