diff mbox series

[14/17] ppc/pnv: move default_phb_realize() to pec_realize()

Message ID 20220113192952.911188-15-danielhb413@gmail.com (mailing list archive)
State New, archived
Headers show
Series remove PnvPhb4PecStack from Powernv9 | expand

Commit Message

Daniel Henrique Barboza Jan. 13, 2022, 7:29 p.m. UTC
This is the last step before making the PEC device uses PHB4s directly.
Move the current pnv_pec_stk_default_phb_realize() call to
pec_realize(), renaming the function to pnv_pec_default_phb_realize(),
and set the PHB attributes using the PEC object directly.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
 hw/pci-host/pnv_phb4_pec.c | 67 ++++++++++++++++++++------------------
 1 file changed, 35 insertions(+), 32 deletions(-)

Comments

Cédric Le Goater Jan. 14, 2022, 10:49 a.m. UTC | #1
On 1/13/22 20:29, Daniel Henrique Barboza wrote:
> This is the last step before making the PEC device uses PHB4s directly.
> Move the current pnv_pec_stk_default_phb_realize() call to
> pec_realize(), renaming the function to pnv_pec_default_phb_realize(),
> and set the PHB attributes using the PEC object directly.
> 
> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>


Reviewed-by: Cédric Le Goater <clg@kaod.org>

Thanks,

C.

> ---
>   hw/pci-host/pnv_phb4_pec.c | 67 ++++++++++++++++++++------------------
>   1 file changed, 35 insertions(+), 32 deletions(-)
> 
> diff --git a/hw/pci-host/pnv_phb4_pec.c b/hw/pci-host/pnv_phb4_pec.c
> index 1de0eb9adc..3339e0ea3d 100644
> --- a/hw/pci-host/pnv_phb4_pec.c
> +++ b/hw/pci-host/pnv_phb4_pec.c
> @@ -112,6 +112,32 @@ static const MemoryRegionOps pnv_pec_pci_xscom_ops = {
>       .endianness = DEVICE_BIG_ENDIAN,
>   };
>   
> +static void pnv_pec_default_phb_realize(PnvPhb4PecStack *stack,
> +                                        int phb_number,
> +                                        Error **errp)
> +{
> +    PnvPhb4PecState *pec = stack->pec;
> +    PnvPhb4PecClass *pecc = PNV_PHB4_PEC_GET_CLASS(pec);
> +    int phb_id = pnv_phb4_pec_get_phb_id(pec, phb_number);
> +
> +    stack->phb = PNV_PHB4(qdev_new(TYPE_PNV_PHB4));
> +
> +    object_property_set_int(OBJECT(stack->phb), "phb-number", phb_number,
> +                            &error_abort);
> +    object_property_set_link(OBJECT(stack->phb), "pec", OBJECT(pec),
> +                             &error_abort);
> +    object_property_set_int(OBJECT(stack->phb), "chip-id", pec->chip_id,
> +                            &error_fatal);
> +    object_property_set_int(OBJECT(stack->phb), "index", phb_id,
> +                            &error_fatal);
> +    object_property_set_int(OBJECT(stack->phb), "version", pecc->version,
> +                            &error_fatal);
> +
> +    if (!sysbus_realize(SYS_BUS_DEVICE(stack->phb), errp)) {
> +        return;
> +    }
> +}
> +
>   static void pnv_pec_instance_init(Object *obj)
>   {
>       PnvPhb4PecState *pec = PNV_PHB4_PEC(obj);
> @@ -144,6 +170,15 @@ static void pnv_pec_realize(DeviceState *dev, Error **errp)
>   
>           object_property_set_int(stk_obj, "stack-no", i, &error_abort);
>           object_property_set_link(stk_obj, "pec", OBJECT(pec), &error_abort);
> +
> +        if (defaults_enabled()) {
> +            pnv_pec_default_phb_realize(stack, i, errp);
> +        }
> +
> +        /*
> +         * qdev gets angry if we don't realize 'stack' here, even
> +         * if stk_realize() is now empty.
> +         */
>           if (!qdev_realize(DEVICE(stk_obj), NULL, errp)) {
>               return;
>           }
> @@ -276,40 +311,8 @@ static const TypeInfo pnv_pec_type_info = {
>       }
>   };
>   
> -static void pnv_pec_stk_default_phb_realize(PnvPhb4PecStack *stack,
> -                                            Error **errp)
> -{
> -    PnvPhb4PecState *pec = stack->pec;
> -    PnvPhb4PecClass *pecc = PNV_PHB4_PEC_GET_CLASS(pec);
> -    int phb_id = pnv_phb4_pec_get_phb_id(pec, stack->stack_no);
> -
> -    stack->phb = PNV_PHB4(qdev_new(TYPE_PNV_PHB4));
> -
> -    object_property_set_int(OBJECT(stack->phb), "phb-number", stack->stack_no,
> -                            &error_abort);
> -    object_property_set_link(OBJECT(stack->phb), "pec", OBJECT(pec),
> -                             &error_abort);
> -    object_property_set_int(OBJECT(stack->phb), "chip-id", pec->chip_id,
> -                            &error_fatal);
> -    object_property_set_int(OBJECT(stack->phb), "index", phb_id,
> -                            &error_fatal);
> -    object_property_set_int(OBJECT(stack->phb), "version", pecc->version,
> -                            &error_fatal);
> -
> -    if (!sysbus_realize(SYS_BUS_DEVICE(stack->phb), errp)) {
> -        return;
> -    }
> -}
> -
>   static void pnv_pec_stk_realize(DeviceState *dev, Error **errp)
>   {
> -    PnvPhb4PecStack *stack = PNV_PHB4_PEC_STACK(dev);
> -
> -    if (!defaults_enabled()) {
> -        return;
> -    }
> -
> -    pnv_pec_stk_default_phb_realize(stack, errp);
>   }
>   
>   static Property pnv_pec_stk_properties[] = {
>
diff mbox series

Patch

diff --git a/hw/pci-host/pnv_phb4_pec.c b/hw/pci-host/pnv_phb4_pec.c
index 1de0eb9adc..3339e0ea3d 100644
--- a/hw/pci-host/pnv_phb4_pec.c
+++ b/hw/pci-host/pnv_phb4_pec.c
@@ -112,6 +112,32 @@  static const MemoryRegionOps pnv_pec_pci_xscom_ops = {
     .endianness = DEVICE_BIG_ENDIAN,
 };
 
+static void pnv_pec_default_phb_realize(PnvPhb4PecStack *stack,
+                                        int phb_number,
+                                        Error **errp)
+{
+    PnvPhb4PecState *pec = stack->pec;
+    PnvPhb4PecClass *pecc = PNV_PHB4_PEC_GET_CLASS(pec);
+    int phb_id = pnv_phb4_pec_get_phb_id(pec, phb_number);
+
+    stack->phb = PNV_PHB4(qdev_new(TYPE_PNV_PHB4));
+
+    object_property_set_int(OBJECT(stack->phb), "phb-number", phb_number,
+                            &error_abort);
+    object_property_set_link(OBJECT(stack->phb), "pec", OBJECT(pec),
+                             &error_abort);
+    object_property_set_int(OBJECT(stack->phb), "chip-id", pec->chip_id,
+                            &error_fatal);
+    object_property_set_int(OBJECT(stack->phb), "index", phb_id,
+                            &error_fatal);
+    object_property_set_int(OBJECT(stack->phb), "version", pecc->version,
+                            &error_fatal);
+
+    if (!sysbus_realize(SYS_BUS_DEVICE(stack->phb), errp)) {
+        return;
+    }
+}
+
 static void pnv_pec_instance_init(Object *obj)
 {
     PnvPhb4PecState *pec = PNV_PHB4_PEC(obj);
@@ -144,6 +170,15 @@  static void pnv_pec_realize(DeviceState *dev, Error **errp)
 
         object_property_set_int(stk_obj, "stack-no", i, &error_abort);
         object_property_set_link(stk_obj, "pec", OBJECT(pec), &error_abort);
+
+        if (defaults_enabled()) {
+            pnv_pec_default_phb_realize(stack, i, errp);
+        }
+
+        /*
+         * qdev gets angry if we don't realize 'stack' here, even
+         * if stk_realize() is now empty.
+         */
         if (!qdev_realize(DEVICE(stk_obj), NULL, errp)) {
             return;
         }
@@ -276,40 +311,8 @@  static const TypeInfo pnv_pec_type_info = {
     }
 };
 
-static void pnv_pec_stk_default_phb_realize(PnvPhb4PecStack *stack,
-                                            Error **errp)
-{
-    PnvPhb4PecState *pec = stack->pec;
-    PnvPhb4PecClass *pecc = PNV_PHB4_PEC_GET_CLASS(pec);
-    int phb_id = pnv_phb4_pec_get_phb_id(pec, stack->stack_no);
-
-    stack->phb = PNV_PHB4(qdev_new(TYPE_PNV_PHB4));
-
-    object_property_set_int(OBJECT(stack->phb), "phb-number", stack->stack_no,
-                            &error_abort);
-    object_property_set_link(OBJECT(stack->phb), "pec", OBJECT(pec),
-                             &error_abort);
-    object_property_set_int(OBJECT(stack->phb), "chip-id", pec->chip_id,
-                            &error_fatal);
-    object_property_set_int(OBJECT(stack->phb), "index", phb_id,
-                            &error_fatal);
-    object_property_set_int(OBJECT(stack->phb), "version", pecc->version,
-                            &error_fatal);
-
-    if (!sysbus_realize(SYS_BUS_DEVICE(stack->phb), errp)) {
-        return;
-    }
-}
-
 static void pnv_pec_stk_realize(DeviceState *dev, Error **errp)
 {
-    PnvPhb4PecStack *stack = PNV_PHB4_PEC_STACK(dev);
-
-    if (!defaults_enabled()) {
-        return;
-    }
-
-    pnv_pec_stk_default_phb_realize(stack, errp);
 }
 
 static Property pnv_pec_stk_properties[] = {