From: Daniel Henrique Barboza <danielhb413@gmail.com>
To: qemu-devel@nongnu.org
Cc: Daniel Henrique Barboza <danielhb413@gmail.com>,
qemu-ppc@nongnu.org, clg@kaod.org, david@gibson.dropbear.id.au
Subject: [PATCH 15/17] ppc/pnv: Introduce user creatable pnv-phb4 devices
Date: Tue, 28 Dec 2021 16:38:04 -0300 [thread overview]
Message-ID: <20211228193806.1198496-16-danielhb413@gmail.com> (raw)
In-Reply-To: <20211228193806.1198496-1-danielhb413@gmail.com>
This patch introduces pnv-phb4 user creatable devices that are created
in a similar manner as pnv-phb3 devices, allowing the user to interact
with the PHBs directly instead of creating PCI Express Controllers that
will create a certain amount of PHBs per controller index.
First thing we need is to discover which stack will host the created
PHB, which is done by the new pnv_phb4_get_stack() function. During
pnv_phb4_realize() we'll inspect phb->stack to see if we're dealing with
an user creatable device or not. When using default settings, the
automatically created PHB4 devices will be realized with phb->stack
already assigned beforehand during PEC realize. In case we're dealing
with an user device, find its stack, set the PHB attributes based on the
stack it belongs and assign the PHB to the stack.
The xscom stack initialization takes place in pnv_pec_stk_realize() when
using default settings, but at that point we aren't aware of any user
PHB4 devices that will belong to the stack. In that case we'll postpone
xscom stack init until the the end of pnv_phb4_realize(), after all the
memory mappings of the PHB are done.
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
hw/pci-host/pnv_phb4.c | 84 +++++++++++++++++++++++++++++++++++++-
hw/pci-host/pnv_phb4_pec.c | 12 +++---
hw/ppc/pnv.c | 2 +
3 files changed, 90 insertions(+), 8 deletions(-)
diff --git a/hw/pci-host/pnv_phb4.c b/hw/pci-host/pnv_phb4.c
index 5b2f644662..7b53c12b7c 100644
--- a/hw/pci-host/pnv_phb4.c
+++ b/hw/pci-host/pnv_phb4.c
@@ -1244,6 +1244,41 @@ 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)
+{
+ Pnv9Chip *chip9 = NULL;
+ int chip_id = phb->chip_id;
+ int index = phb->phb_id;
+ int i, j;
+
+ if (chip->num_pecs == 0) {
+ /* Something weird happened. Bail out */
+ error_setg(errp, "chip id %d has no PCIE controllers", chip_id);
+ return NULL;
+ }
+
+ chip9 = PNV9_CHIP(chip);
+
+ 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.
+ */
+ PnvPhb4PecState *pec = &chip9->pecs[i];
+
+ for (j = 0; j < pec->num_stacks; j++) {
+ if (index == pnv_pec_get_phb_id(pec, j)) {
+ return &pec->stacks[j];
+ }
+ }
+ }
+
+ error_setg(errp, "pnv-phb4 index %d didn't match any existing PEC",
+ chip_id);
+ return NULL;
+}
+
static void pnv_phb4_realize(DeviceState *dev, Error **errp)
{
PnvPHB4 *phb = PNV_PHB4(dev);
@@ -1251,8 +1286,49 @@ static void pnv_phb4_realize(DeviceState *dev, Error **errp)
XiveSource *xsrc = &phb->xsrc;
int nr_irqs;
char name[32];
+ PnvPhb4PecStack *stack = NULL;
+ bool stack_init_xscom = false;
+ Error *local_err = NULL;
- assert(phb->stack);
+ /* User created PHB */
+ if (!phb->stack) {
+ PnvMachineState *pnv = PNV_MACHINE(qdev_get_machine());
+ PnvChip *chip = pnv_get_chip(pnv, phb->chip_id);
+ BusState *s;
+
+ if (!chip) {
+ error_setg(errp, "invalid chip id: %d", phb->chip_id);
+ return;
+ }
+
+ stack = pnv_phb4_get_stack(chip, phb, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
+
+ object_property_set_int(OBJECT(phb), "index",
+ phb->phb_id, &error_abort);
+
+ pnv_phb4_set_stack_phb_props(stack, phb);
+
+ /* Assign the phb to the stack */
+ stack->phb = phb;
+
+ /*
+ * Reparent user created devices to the chip to build
+ * correctly 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;
+ }
+
+ stack_init_xscom = true;
+ }
/* Set the "big_phb" flag */
phb->big_phb = phb->phb_id == 0 || phb->phb_id == 3;
@@ -1305,6 +1381,10 @@ static void pnv_phb4_realize(DeviceState *dev, Error **errp)
pnv_phb_attach_root_port(PCI_HOST_BRIDGE(phb),
TYPE_PNV_PHB4_ROOT_PORT);
}
+
+ if (stack_init_xscom) {
+ pnv_pec_init_stack_xscom(stack);
+ }
}
static const char *pnv_phb4_root_bus_path(PCIHostState *host_bridge,
@@ -1416,7 +1496,7 @@ static void pnv_phb4_class_init(ObjectClass *klass, void *data)
dc->realize = pnv_phb4_realize;
device_class_set_props(dc, pnv_phb4_properties);
set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
- dc->user_creatable = false;
+ dc->user_creatable = true;
xfc->notify = pnv_phb4_xive_notify;
}
diff --git a/hw/pci-host/pnv_phb4_pec.c b/hw/pci-host/pnv_phb4_pec.c
index aa93ad3f10..27973779c5 100644
--- a/hw/pci-host/pnv_phb4_pec.c
+++ b/hw/pci-host/pnv_phb4_pec.c
@@ -574,13 +574,13 @@ static void pnv_pec_stk_realize(DeviceState *dev, Error **errp)
&pnv_pec_stk_pci_xscom_ops, stack, name,
PHB4_PEC_PCI_STK_REGS_COUNT);
- /* PHB pass-through */
- pnv_phb4_set_stack_phb_props(stack, stack->phb);
- if (!sysbus_realize(SYS_BUS_DEVICE(&stack->phb), errp)) {
- return;
+ /*
+ * There is no guarantee that stack->phb will be available
+ * at this point.
+ */
+ if (stack->phb) {
+ pnv_pec_init_stack_xscom(stack);
}
-
- pnv_pec_init_stack_xscom(stack);
}
static Property pnv_pec_stk_properties[] = {
diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c
index bf2607446a..e93e77cb2e 100644
--- a/hw/ppc/pnv.c
+++ b/hw/ppc/pnv.c
@@ -2270,6 +2270,8 @@ static void pnv_machine_power9_class_init(ObjectClass *oc, void *data)
pnv_machine_get_endian, pnv_machine_set_endian);
object_class_property_set_description(oc, "endianness",
"Change CPU initial endianness (default is big)");
+
+ machine_class_allow_dynamic_sysbus_dev(mc, TYPE_PNV_PHB4);
}
static void pnv_machine_power10_class_init(ObjectClass *oc, void *data)
--
2.33.1
next prev parent reply other threads:[~2021-12-28 20:00 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-28 19:37 [PATCH 00/17] ppc/pnv: enable pnv-phb4 user devices Daniel Henrique Barboza
2021-12-28 19:37 ` [PATCH 01/17] pnv_phb3.c: add unique chassis and slot for pnv_phb3_root_port Daniel Henrique Barboza
2022-01-03 8:24 ` Cédric Le Goater
2022-01-04 19:33 ` Daniel Henrique Barboza
2022-01-05 14:04 ` Daniel Henrique Barboza
2021-12-28 19:37 ` [PATCH 02/17] pnv_phb3.c: do not set 'root-bus' as bus name Daniel Henrique Barboza
2022-01-03 8:25 ` Cédric Le Goater
2022-01-03 8:26 ` Cédric Le Goater
2021-12-28 19:37 ` [PATCH 03/17] pnv_phb3.h: change TYPE_PNV_PHB3_ROOT_BUS name Daniel Henrique Barboza
2022-01-03 8:28 ` Cédric Le Goater
2022-01-03 19:01 ` Daniel Henrique Barboza
2021-12-28 19:37 ` [PATCH 04/17] pnv_phb4.c: add unique chassis and slot for pnv_phb4_root_port Daniel Henrique Barboza
2021-12-28 19:37 ` [PATCH 05/17] pnv.c: simplify pnv_phb_attach_root_port() Daniel Henrique Barboza
2022-01-03 8:32 ` Cédric Le Goater
2021-12-28 19:37 ` [PATCH 06/17] pnv_phb4.c: attach default root port in phb4 realize() Daniel Henrique Barboza
2022-01-03 8:33 ` Cédric Le Goater
2021-12-28 19:37 ` [PATCH 07/17] pnv_phb4.c: check if root port exists in rc_config functions Daniel Henrique Barboza
2022-01-03 8:53 ` Cédric Le Goater
2021-12-28 19:37 ` [PATCH 08/17] pnv_phb4.c: introduce pnv_phb4_set_stack_phb_props() Daniel Henrique Barboza
2021-12-28 19:37 ` [PATCH 09/17] pnv_phb4_pec.c: move pnv_pec_phb_offset() to pnv_phb4.c Daniel Henrique Barboza
2022-01-03 9:00 ` Cédric Le Goater
2022-01-05 19:14 ` Daniel Henrique Barboza
2021-12-28 19:37 ` [PATCH 10/17] pnv_phb4.c: introduce pnv_pec_init_stack_xscom() Daniel Henrique Barboza
2021-12-28 19:38 ` [PATCH 11/17] pnv_phb4_pec.c: use pnv_pec_get_phb_id() in pnv_pec_dt_xscom() Daniel Henrique Barboza
2022-01-03 9:08 ` Cédric Le Goater
2022-01-05 18:55 ` Daniel Henrique Barboza
2021-12-28 19:38 ` [PATCH 12/17] pnv_phb4_pec.c: use 'default_enabled()' to init stack->phb Daniel Henrique Barboza
2021-12-28 19:38 ` [PATCH 13/17] pnv_phb4.h: turn phb into a pointer in struct PnvPhb4PecStack Daniel Henrique Barboza
2021-12-28 19:38 ` [PATCH 14/17] Revert "ppc/pnv: Introduce support for user created PHB4 devices" Daniel Henrique Barboza
2021-12-28 19:38 ` Daniel Henrique Barboza [this message]
2021-12-28 19:38 ` [PATCH 16/17] pnv_phb4.c: do not set 'root-bus' as bus name Daniel Henrique Barboza
2022-01-03 8:40 ` Cédric Le Goater
2021-12-28 19:38 ` [PATCH 17/17] pnv_phb4.c: change TYPE_PNV_PHB4_ROOT_BUS name Daniel Henrique Barboza
2022-01-03 8:21 ` [PATCH 00/17] ppc/pnv: enable pnv-phb4 user devices Cédric Le Goater
2022-01-03 18:58 ` Daniel Henrique Barboza
2022-01-03 21:20 ` Cédric Le Goater
2022-01-03 21:37 ` Daniel Henrique Barboza
2022-01-04 7:39 ` Cédric Le Goater
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211228193806.1198496-16-danielhb413@gmail.com \
--to=danielhb413@gmail.com \
--cc=clg@kaod.org \
--cc=david@gibson.dropbear.id.au \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).