diff mbox series

[14/14] ppc/pnv: Introduce support for user created PHB4 devices

Message ID 20211202144235.1276352-15-clg@kaod.org (mailing list archive)
State New, archived
Headers show
Series ppc/pnv: Add support for user created PHB3/PHB4 devices | expand

Commit Message

Cédric Le Goater Dec. 2, 2021, 2:42 p.m. UTC
PHB4 devices and PCI devices can now be added to the powernv9 machine
using:

  -device pnv-phb4-pec,chip-id=0,index=0
  -device nec-usb-xhci,bus=pci.0,addr=0x0

In case of user created devices, a lookup on 'chip-id' is required to
assign the owning chip.

To be noted, that the PEC PHB4 devices can add more than one PHB4
devices:

  * PEC0 provides 1 PHB  (PHB0)
  * PEC1 provides 2 PHBs (PHB1 and PHB2)
  * PEC2 provides 3 PHBs (PHB3, PHB4 and PHB5)

Signed-off-by: Cédric Le Goater <clg@kaod.org>
---
 hw/pci-host/pnv_phb4_pec.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

Comments

Daniel Henrique Barboza Dec. 2, 2021, 5:49 p.m. UTC | #1
On 12/2/21 11:42, Cédric Le Goater wrote:
> PHB4 devices and PCI devices can now be added to the powernv9 machine
> using:
> 
>    -device pnv-phb4-pec,chip-id=0,index=0
>    -device nec-usb-xhci,bus=pci.0,addr=0x0
> 
> In case of user created devices, a lookup on 'chip-id' is required to
> assign the owning chip.
> 
> To be noted, that the PEC PHB4 devices can add more than one PHB4
> devices:
> 
>    * PEC0 provides 1 PHB  (PHB0)
>    * PEC1 provides 2 PHBs (PHB1 and PHB2)
>    * PEC2 provides 3 PHBs (PHB3, PHB4 and PHB5)
> 
> Signed-off-by: Cédric Le Goater <clg@kaod.org>
> ---

Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>

>   hw/pci-host/pnv_phb4_pec.c | 19 ++++++++++++++++++-
>   1 file changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/pci-host/pnv_phb4_pec.c b/hw/pci-host/pnv_phb4_pec.c
> index 9b081d543057..4ee92f11945c 100644
> --- a/hw/pci-host/pnv_phb4_pec.c
> +++ b/hw/pci-host/pnv_phb4_pec.c
> @@ -394,6 +394,17 @@ static void pnv_pec_realize(DeviceState *dev, Error **errp)
>       char name[64];
>       int i;
>   
> +    /* User created devices */
> +    if (!pec->chip) {
> +        PnvMachineState *pnv = PNV_MACHINE(qdev_get_machine());
> +
> +        pec->chip = pnv_get_chip(pnv, pec->chip_id);
> +        if (!pec->chip) {
> +            error_setg(errp, "invalid chip id: %d", pec->chip_id);
> +            return;
> +        }
> +    }
> +
>       if (pec->index >= PNV_CHIP_GET_CLASS(pec->chip)->num_pecs) {
>           error_setg(errp, "invalid PEC index: %d", pec->index);
>           return;
> @@ -401,6 +412,12 @@ static void pnv_pec_realize(DeviceState *dev, Error **errp)
>   
>       pec->num_stacks = pecc->num_stacks[pec->index];
>   
> +    /*
> +     * Reparent user created devices to the chip to build correctly
> +     * the device tree.
> +     */
> +    pnv_chip_parent_fixup(pec->chip, OBJECT(pec), pec->index);
> +
>       /* Create stacks */
>       for (i = 0; i < pec->num_stacks; i++) {
>           PnvPhb4PecStack *stack = &pec->stacks[i];
> @@ -516,7 +533,7 @@ static void pnv_pec_class_init(ObjectClass *klass, void *data)
>   
>       dc->realize = pnv_pec_realize;
>       device_class_set_props(dc, pnv_pec_properties);
> -    dc->user_creatable = false;
> +    dc->user_creatable = true;
>   
>       pecc->xscom_nest_base = pnv_pec_xscom_nest_base;
>       pecc->xscom_pci_base  = pnv_pec_xscom_pci_base;
>
Frederic Barrat Dec. 7, 2021, 10:12 a.m. UTC | #2
On 02/12/2021 15:42, Cédric Le Goater wrote:
> PHB4 devices and PCI devices can now be added to the powernv9 machine
> using:
> 
>    -device pnv-phb4-pec,chip-id=0,index=0
>    -device nec-usb-xhci,bus=pci.0,addr=0x0
> 
> In case of user created devices, a lookup on 'chip-id' is required to
> assign the owning chip.
> 
> To be noted, that the PEC PHB4 devices can add more than one PHB4
> devices:
> 
>    * PEC0 provides 1 PHB  (PHB0)
>    * PEC1 provides 2 PHBs (PHB1 and PHB2)
>    * PEC2 provides 3 PHBs (PHB3, PHB4 and PHB5)
> 
> Signed-off-by: Cédric Le Goater <clg@kaod.org>
> ---


Reviewed-by: Frederic Barrat <fbarrat@linux.ibm.com>


>   hw/pci-host/pnv_phb4_pec.c | 19 ++++++++++++++++++-
>   1 file changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/pci-host/pnv_phb4_pec.c b/hw/pci-host/pnv_phb4_pec.c
> index 9b081d543057..4ee92f11945c 100644
> --- a/hw/pci-host/pnv_phb4_pec.c
> +++ b/hw/pci-host/pnv_phb4_pec.c
> @@ -394,6 +394,17 @@ static void pnv_pec_realize(DeviceState *dev, Error **errp)
>       char name[64];
>       int i;
>   
> +    /* User created devices */
> +    if (!pec->chip) {
> +        PnvMachineState *pnv = PNV_MACHINE(qdev_get_machine());
> +
> +        pec->chip = pnv_get_chip(pnv, pec->chip_id);
> +        if (!pec->chip) {
> +            error_setg(errp, "invalid chip id: %d", pec->chip_id);
> +            return;
> +        }
> +    }
> +
>       if (pec->index >= PNV_CHIP_GET_CLASS(pec->chip)->num_pecs) {
>           error_setg(errp, "invalid PEC index: %d", pec->index);
>           return;
> @@ -401,6 +412,12 @@ static void pnv_pec_realize(DeviceState *dev, Error **errp)
>   
>       pec->num_stacks = pecc->num_stacks[pec->index];
>   
> +    /*
> +     * Reparent user created devices to the chip to build correctly
> +     * the device tree.
> +     */
> +    pnv_chip_parent_fixup(pec->chip, OBJECT(pec), pec->index);
> +
>       /* Create stacks */
>       for (i = 0; i < pec->num_stacks; i++) {
>           PnvPhb4PecStack *stack = &pec->stacks[i];
> @@ -516,7 +533,7 @@ static void pnv_pec_class_init(ObjectClass *klass, void *data)
>   
>       dc->realize = pnv_pec_realize;
>       device_class_set_props(dc, pnv_pec_properties);
> -    dc->user_creatable = false;
> +    dc->user_creatable = true;
>   
>       pecc->xscom_nest_base = pnv_pec_xscom_nest_base;
>       pecc->xscom_pci_base  = pnv_pec_xscom_pci_base;
>
diff mbox series

Patch

diff --git a/hw/pci-host/pnv_phb4_pec.c b/hw/pci-host/pnv_phb4_pec.c
index 9b081d543057..4ee92f11945c 100644
--- a/hw/pci-host/pnv_phb4_pec.c
+++ b/hw/pci-host/pnv_phb4_pec.c
@@ -394,6 +394,17 @@  static void pnv_pec_realize(DeviceState *dev, Error **errp)
     char name[64];
     int i;
 
+    /* User created devices */
+    if (!pec->chip) {
+        PnvMachineState *pnv = PNV_MACHINE(qdev_get_machine());
+
+        pec->chip = pnv_get_chip(pnv, pec->chip_id);
+        if (!pec->chip) {
+            error_setg(errp, "invalid chip id: %d", pec->chip_id);
+            return;
+        }
+    }
+
     if (pec->index >= PNV_CHIP_GET_CLASS(pec->chip)->num_pecs) {
         error_setg(errp, "invalid PEC index: %d", pec->index);
         return;
@@ -401,6 +412,12 @@  static void pnv_pec_realize(DeviceState *dev, Error **errp)
 
     pec->num_stacks = pecc->num_stacks[pec->index];
 
+    /*
+     * Reparent user created devices to the chip to build correctly
+     * the device tree.
+     */
+    pnv_chip_parent_fixup(pec->chip, OBJECT(pec), pec->index);
+
     /* Create stacks */
     for (i = 0; i < pec->num_stacks; i++) {
         PnvPhb4PecStack *stack = &pec->stacks[i];
@@ -516,7 +533,7 @@  static void pnv_pec_class_init(ObjectClass *klass, void *data)
 
     dc->realize = pnv_pec_realize;
     device_class_set_props(dc, pnv_pec_properties);
-    dc->user_creatable = false;
+    dc->user_creatable = true;
 
     pecc->xscom_nest_base = pnv_pec_xscom_nest_base;
     pecc->xscom_pci_base  = pnv_pec_xscom_pci_base;