All of lore.kernel.org
 help / color / mirror / Atom feed
From: Frederic Barrat <fbarrat@linux.ibm.com>
To: Daniel Henrique Barboza <danielhb413@gmail.com>, qemu-devel@nongnu.org
Cc: qemu-ppc@nongnu.org, david@gibson.dropbear.id.au, clg@kaod.org,
	mark.cave-ayland@ilande.co.uk
Subject: Re: [PATCH v2 08/16] ppc/pnv: user created pnv-phb for powernv9
Date: Thu, 2 Jun 2022 18:33:44 +0200	[thread overview]
Message-ID: <d2ae2236-7a49-22e7-3950-cb635697721a@linux.ibm.com> (raw)
In-Reply-To: <20220531214917.31668-9-danielhb413@gmail.com>



On 31/05/2022 23:49, Daniel Henrique Barboza wrote:
> To enable user creatable PnvPHB devices for powernv9 we'll revert the
> powernv9 related changes made in 9c10d86fee "ppc/pnv: Remove
> user-created PHB{3,4,5} devices".
> 
> This change alone isn't enough to enable user creatable devices for powernv10
> due to how pnv_phb4_get_pec() currently works. For now let's just enable it
> for powernv9 alone.
> 
> 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 22cf1c2a5e..a5c8ae494b 100644
> --- a/hw/pci-host/pnv_phb4.c
> +++ b/hw/pci-host/pnv_phb4.c
> @@ -1571,13 +1571,69 @@ void pnv_phb4_bus_init(DeviceState *dev, PnvPHB4 *phb)
>       pci->bus->flags |= PCI_BUS_EXTENDED_CONFIG_SPACE;
>   }
>   
> +static PnvPhb4PecState *pnv_phb4_get_pec(PnvChip *chip, PnvPHB4 *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-phb4 chip-id %d index %d didn't match any existing PEC",
> +               chip_id, index);
> +
> +    return NULL;
> +}
> +
>   static void pnv_phb4_realize(DeviceState *dev, Error **errp)
>   {
>       PnvPHB4 *phb = PNV_PHB4(dev);
> +    PnvMachineState *pnv = PNV_MACHINE(qdev_get_machine());
> +    PnvChip *chip = pnv_get_chip(pnv, phb->chip_id);
>       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_base), phb->phb_id);


Didn't you mean to do that only for the user-created case? And why not 
attaching the PHB to the PEC instead of the chip, like in 
pnv_pec_default_phb_realize() ? I think it makes more sense to keep the 
chip->PEC->PHB parenting in the qom tree (and incidentally, that's where 
I'd prefer to have the phb3 model move to).
Also, the comment seems wrong to me. The qom parenting doesn't matter 
when building the device tree. We only iterate over the PHBs found in 
the array of the PEC object (cf. pnv_pec_dt_xscom())



> +    s = qdev_get_parent_bus(DEVICE(chip));
> +    if (!qdev_set_parent_bus(DEVICE(phb->phb_base), s, &local_err)) {
> +        error_propagate(errp, local_err);
> +        return;
> +    }


Same comment, I think that's only desirable for user-created devices. 
We're already calling sysbus_realize() for the default case.


Silly question: where does it break if a user tries to create 2 PHBs 
with the same index?


   Fred




>       /* Set the "big_phb" flag */
>       phb->big_phb = phb->phb_id == 0 || phb->phb_id == 3;
>   
> @@ -1803,7 +1859,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 888ecbe8f3..0e67f3a338 100644
> --- a/hw/pci-host/pnv_phb4_pec.c
> +++ b/hw/pci-host/pnv_phb4_pec.c
> @@ -146,8 +146,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 3b0b230e49..697a2b5302 100644
> --- a/hw/ppc/pnv.c
> +++ b/hw/ppc/pnv.c
> @@ -2186,6 +2186,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)


  reply	other threads:[~2022-06-02 16:41 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-31 21:49 [PATCH v2 00/16] powernv: introduce pnv-phb base/proxy devices Daniel Henrique Barboza
2022-05-31 21:49 ` [PATCH v2 01/16] ppc/pnv: add PHB3 bus init helper Daniel Henrique Barboza
2022-05-31 21:49 ` [PATCH v2 02/16] ppc/pnv: add pnv_get_phb3_child() Daniel Henrique Barboza
2022-05-31 21:49 ` [PATCH v2 03/16] ppc/pnv: add PnvPHB base/proxy device Daniel Henrique Barboza
2022-06-02  7:18   ` Mark Cave-Ayland
2022-06-02 20:45     ` Daniel Henrique Barboza
2022-06-02 16:16   ` Frederic Barrat
2022-06-02 20:55     ` Daniel Henrique Barboza
2022-06-07  6:42     ` Cédric Le Goater
2022-06-07  8:44       ` Frederic Barrat
2022-06-07 13:27         ` Daniel Henrique Barboza
2022-05-31 21:49 ` [PATCH v2 04/16] ppc/pnv: change PnvPHB3 to be a PnvPHB backend Daniel Henrique Barboza
2022-06-02  7:56   ` Mark Cave-Ayland
2022-06-03 20:30     ` Daniel Henrique Barboza
2022-06-06 12:26       ` Mark Cave-Ayland
2022-05-31 21:49 ` [PATCH v2 05/16] ppc/pnv: user created pnv-phb for powernv8 Daniel Henrique Barboza
2022-05-31 21:49 ` [PATCH v2 06/16] ppc/pnv: add PHB4 bus init helper Daniel Henrique Barboza
2022-05-31 21:49 ` [PATCH v2 07/16] ppc/pnv: change PnvPHB4 to be a PnvPHB backend Daniel Henrique Barboza
2022-06-02  8:02   ` Mark Cave-Ayland
2022-06-07  6:17     ` Cédric Le Goater
2022-06-02 16:21   ` Frederic Barrat
2022-05-31 21:49 ` [PATCH v2 08/16] ppc/pnv: user created pnv-phb for powernv9 Daniel Henrique Barboza
2022-06-02 16:33   ` Frederic Barrat [this message]
2022-06-03 21:00     ` Daniel Henrique Barboza
2022-06-07  6:35       ` Cédric Le Goater
2022-06-07  6:44         ` Cédric Le Goater
2022-06-08 20:22           ` Daniel Henrique Barboza
2022-06-07  8:52         ` Frederic Barrat
2022-06-07  8:41       ` Frederic Barrat
2022-05-31 21:49 ` [PATCH v2 09/16] ppc/pnv: change pnv_phb4_get_pec() to also retrieve chip10->pecs Daniel Henrique Barboza
2022-05-31 21:49 ` [PATCH v2 10/16] ppc/pnv: user creatable pnv-phb for powernv10 Daniel Henrique Barboza
2022-05-31 21:49 ` [PATCH v2 11/16] ppc/pnv: add pnv-phb-root-port device Daniel Henrique Barboza
2022-06-01  5:56   ` Cédric Le Goater
2022-06-01  8:04     ` Daniel Henrique Barboza
2022-06-02  7:06       ` Mark Cave-Ayland
2022-06-07  6:37         ` Cédric Le Goater
2022-06-02  8:12   ` Mark Cave-Ayland
2022-06-03 20:47     ` Daniel Henrique Barboza
2022-06-06 12:41       ` Mark Cave-Ayland
2022-05-31 21:49 ` [PATCH v2 12/16] ppc/pnv: remove pnv-phb3-root-port Daniel Henrique Barboza
2022-06-01  7:29   ` Daniel Henrique Barboza
2022-05-31 21:49 ` [PATCH v2 13/16] ppc/pnv: remove pnv-phb4-root-port Daniel Henrique Barboza
2022-05-31 21:49 ` [PATCH v2 14/16] ppc/pnv: remove 'phb_rootport_typename' in pnv_phb_realize() Daniel Henrique Barboza
2022-05-31 21:49 ` [PATCH v2 15/16] ppc/pnv: remove pecc->rp_model Daniel Henrique Barboza
2022-05-31 21:49 ` [PATCH v2 16/16] ppc/pnv: remove PnvPHB4.version Daniel Henrique Barboza
2022-06-02  8:42 ` [PATCH v2 00/16] powernv: introduce pnv-phb base/proxy devices Mark Cave-Ayland
2022-06-02 16:08 ` Frederic Barrat

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=d2ae2236-7a49-22e7-3950-cb635697721a@linux.ibm.com \
    --to=fbarrat@linux.ibm.com \
    --cc=clg@kaod.org \
    --cc=danielhb413@gmail.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=mark.cave-ayland@ilande.co.uk \
    --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 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.