On 1/5/22 22:23, Daniel Henrique Barboza wrote:
> The next step before enabling user creatable pnv-phb4 devices is to
> decople the init of the stack->phb object from
> pnv_pec_stk_instance_init().
>
> First, use 'defaults_enabled()' inside pnv_pec_realize() to create the
> stack->phb object, while removing the equivalent object_initiate_child()
> call from stk_instance_init(). Create a new "phb" stack property link so
> we can assign stack->phb in an idiomatic manner.
>
> Then we need to handle stack->phb->index assignment. The value is
> retrieved with pnv_phb4_pec_get_phd_id() and, until this patch, this was
> being assigned to a 'phb-id' stack link to phb->index. It is simpler to
> assign this directly given that now we need to interact with the PnvPHB4
> object directly to set its other attributes. Assign phb->index directly
> with the value of pnv_phb4_pec_get_phb_id(), and remove the now unused
> link.
>
> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
> ---
> hw/pci-host/pnv_phb4_pec.c | 29 +++++++++++++++++++++++------
> 1 file changed, 23 insertions(+), 6 deletions(-)
>
> diff --git a/hw/pci-host/pnv_phb4_pec.c b/hw/pci-host/pnv_phb4_pec.c
> index be6eefdbb1..638691783b 100644
> --- a/hw/pci-host/pnv_phb4_pec.c
> +++ b/hw/pci-host/pnv_phb4_pec.c
> @@ -19,6 +19,7 @@
> #include "hw/pci/pci_bus.h"
> #include "hw/ppc/pnv.h"
> #include "hw/qdev-properties.h"
> +#include "sysemu/sysemu.h"
>
> #include <libfdt.h>
>
> @@ -392,11 +393,29 @@ static void pnv_pec_realize(DeviceState *dev, Error **errp)
> for (i = 0; i < pec->num_stacks; i++) {
> PnvPhb4PecStack *stack = &pec->stacks[i];
> Object *stk_obj = OBJECT(stack);
> - int phb_id = pnv_phb4_pec_get_phb_id(pec, i);
>
> object_property_set_int(stk_obj, "stack-no", i, &error_abort);
> - object_property_set_int(stk_obj, "phb-id", phb_id, &error_abort);
This setting of "phb-id" is indeed a problem if the phb object becomes
dynamic. This is because the property is an alias.
> object_property_set_link(stk_obj, "pec", OBJECT(pec), &error_abort);
> +
> + /* Create and realize the default stack->phb */
> + if (defaults_enabled()) {
This should be under pnv_pec_stk_realize() and not pnv_pec_realize()
> + PnvPHB4 *phb = PNV_PHB4(qdev_new(TYPE_PNV_PHB4));
> + int phb_id = pnv_phb4_pec_get_phb_id(pec, i);
> +
> + object_property_set_int(OBJECT(phb), "index",
> + phb_id, &error_abort);
> + object_property_set_link(OBJECT(phb), "stack",
> + stk_obj, &error_abort);
> +
> + pnv_phb4_set_stack_phb_props(stack, phb);
> + if (!sysbus_realize_and_unref(SYS_BUS_DEVICE(phb), errp)) {
> + return;
> + }
> +
> + object_property_set_link(stk_obj, "phb", OBJECT(phb),
> + &error_abort);
> + }
> +
> if (!qdev_realize(DEVICE(stk_obj), NULL, errp)) {
AFAICT, pnv_pec_stk_realize() still realizes the PHB object but when
defaults_enabled(), pnv_pec_realize() also realizes the PHB object.
How does that work ?
> return;
> }
> @@ -531,10 +550,6 @@ static const TypeInfo pnv_pec_type_info = {
>
> static void pnv_pec_stk_instance_init(Object *obj)
> {
> - PnvPhb4PecStack *stack = PNV_PHB4_PEC_STACK(obj);
> -
> - object_initialize_child(obj, "phb", &stack->phb, TYPE_PNV_PHB4);
> - object_property_add_alias(obj, "phb-id", OBJECT(&stack->phb), "index");
I think this belongs to the previous patch.
> }
>
> static void pnv_pec_stk_realize(DeviceState *dev, Error **errp)
> @@ -588,6 +603,8 @@ static Property pnv_pec_stk_properties[] = {
> DEFINE_PROP_UINT32("stack-no", PnvPhb4PecStack, stack_no, 0),
> DEFINE_PROP_LINK("pec", PnvPhb4PecStack, pec, TYPE_PNV_PHB4_PEC,
> PnvPhb4PecState *),
> + DEFINE_PROP_LINK("phb", PnvPhb4PecStack, phb, TYPE_PNV_PHB4,
> + PnvPHB4 *),
That's weird. I think I understand why. See next email.
Thanks,
C.
> DEFINE_PROP_END_OF_LIST(),
> };
>
>