diff mbox series

[for-5.0,8/8] ppc/pnv: Link "chip" property to PnvXive::chip pointer

Message ID 157381884958.136087.2386559512465741955.stgit@bahia.lan
State New
Headers show
Series ppc: Consolidate QOM links and pointers to the same object | expand

Commit Message

Greg Kurz Nov. 15, 2019, 11:54 a.m. UTC
The XIVE object has both a pointer and a "chip" property pointing to the
chip object. Confusing bugs could arise if these ever go out of sync.

Change the property definition so that it explicitely sets the pointer.

While here, rename pnv_xive_init() to pnv_xive_instance_init() for
clarity.

Signed-off-by: Greg Kurz <groug@kaod.org>
---
 hw/intc/pnv_xive.c   |   21 +++++++++------------
 hw/ppc/pnv.c         |    4 ++--
 include/hw/ppc/pnv.h |    2 +-
 3 files changed, 12 insertions(+), 15 deletions(-)

Comments

Cédric Le Goater Nov. 15, 2019, 12:25 p.m. UTC | #1
> diff --git a/include/hw/ppc/pnv.h b/include/hw/ppc/pnv.h
> index 5ecd3ba6ed24..d82484ecf669 100644
> --- a/include/hw/ppc/pnv.h
> +++ b/include/hw/ppc/pnv.h
> @@ -87,9 +87,9 @@ typedef struct Pnv8Chip {
>  typedef struct Pnv9Chip {
>      /*< private >*/
>      PnvChip      parent_obj;
> +    PnvXive      xive;
>  
>      /*< public >*/
> -    PnvXive      xive;
>      Pnv9Psi      psi;
>      PnvLpcController lpc;
>      PnvOCC       occ;
> 

Why this change ? 

C.
Greg Kurz Nov. 15, 2019, 12:46 p.m. UTC | #2
On Fri, 15 Nov 2019 13:25:01 +0100
Cédric Le Goater <clg@kaod.org> wrote:

> > diff --git a/include/hw/ppc/pnv.h b/include/hw/ppc/pnv.h
> > index 5ecd3ba6ed24..d82484ecf669 100644
> > --- a/include/hw/ppc/pnv.h
> > +++ b/include/hw/ppc/pnv.h
> > @@ -87,9 +87,9 @@ typedef struct Pnv8Chip {
> >  typedef struct Pnv9Chip {
> >      /*< private >*/
> >      PnvChip      parent_obj;
> > +    PnvXive      xive;
> >  
> >      /*< public >*/
> > -    PnvXive      xive;
> >      Pnv9Psi      psi;
> >      PnvLpcController lpc;
> >      PnvOCC       occ;
> > 
> 
> Why this change ? 
> 

Same reason as in patch 7/8.

> C.
diff mbox series

Patch

diff --git a/hw/intc/pnv_xive.c b/hw/intc/pnv_xive.c
index 6aa7aeed6f83..158d16b328e3 100644
--- a/hw/intc/pnv_xive.c
+++ b/hw/intc/pnv_xive.c
@@ -1651,7 +1651,7 @@  static void pnv_xive_reset(void *dev)
     }
 }
 
-static void pnv_xive_init(Object *obj)
+static void pnv_xive_instance_init(Object *obj)
 {
     PnvXive *xive = PNV_XIVE(obj);
 
@@ -1661,6 +1661,12 @@  static void pnv_xive_init(Object *obj)
     object_initialize_child(obj, "end_source", &xive->end_source,
                             sizeof(xive->end_source), TYPE_XIVE_END_SOURCE,
                             &error_abort, NULL);
+
+    /* The PnvChip id identifies the XIVE interrupt controller. */
+    object_property_add_link(obj, "chip", TYPE_PNV_CHIP,
+                             (Object **) &PNV_XIVE(obj)->chip,
+                             qdev_prop_allow_set_link_before_realize,
+                             OBJ_PROP_LINK_STRONG, &error_abort);
 }
 
 /*
@@ -1675,17 +1681,8 @@  static void pnv_xive_realize(DeviceState *dev, Error **errp)
     XiveSource *xsrc = &xive->ipi_source;
     XiveENDSource *end_xsrc = &xive->end_source;
     Error *local_err = NULL;
-    Object *obj;
 
-    obj = object_property_get_link(OBJECT(dev), "chip", &local_err);
-    if (!obj) {
-        error_propagate(errp, local_err);
-        error_prepend(errp, "required link 'chip' not found: ");
-        return;
-    }
-
-    /* The PnvChip id identifies the XIVE interrupt controller. */
-    xive->chip = PNV_CHIP(obj);
+    assert(xive->chip);
 
     /*
      * The XiveSource and XiveENDSource objects are realized with the
@@ -1829,7 +1826,7 @@  static void pnv_xive_class_init(ObjectClass *klass, void *data)
 static const TypeInfo pnv_xive_info = {
     .name          = TYPE_PNV_XIVE,
     .parent        = TYPE_XIVE_ROUTER,
-    .instance_init = pnv_xive_init,
+    .instance_init = pnv_xive_instance_init,
     .instance_size = sizeof(PnvXive),
     .class_init    = pnv_xive_class_init,
     .interfaces    = (InterfaceInfo[]) {
diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c
index 8851875bcfd7..d7130c3304f0 100644
--- a/hw/ppc/pnv.c
+++ b/hw/ppc/pnv.c
@@ -1088,8 +1088,6 @@  static void pnv_chip_power9_instance_init(Object *obj)
 
     object_initialize_child(obj, "xive", &chip9->xive, sizeof(chip9->xive),
                             TYPE_PNV_XIVE, &error_abort, NULL);
-    object_property_add_const_link(OBJECT(&chip9->xive), "chip", obj,
-                                   &error_abort);
 
     object_initialize_child(obj, "psi",  &chip9->psi, sizeof(chip9->psi),
                             TYPE_PNV9_PSI, &error_abort, NULL);
@@ -1171,6 +1169,8 @@  static void pnv_chip_power9_realize(DeviceState *dev, Error **errp)
                             "pc-bar", &error_fatal);
     object_property_set_int(OBJECT(&chip9->xive), PNV9_XIVE_TM_BASE(chip),
                             "tm-bar", &error_fatal);
+    object_property_set_link(OBJECT(&chip9->xive), OBJECT(chip), "chip",
+                             &error_abort);
     object_property_set_bool(OBJECT(&chip9->xive), true, "realized",
                              &local_err);
     if (local_err) {
diff --git a/include/hw/ppc/pnv.h b/include/hw/ppc/pnv.h
index 5ecd3ba6ed24..d82484ecf669 100644
--- a/include/hw/ppc/pnv.h
+++ b/include/hw/ppc/pnv.h
@@ -87,9 +87,9 @@  typedef struct Pnv8Chip {
 typedef struct Pnv9Chip {
     /*< private >*/
     PnvChip      parent_obj;
+    PnvXive      xive;
 
     /*< public >*/
-    PnvXive      xive;
     Pnv9Psi      psi;
     PnvLpcController lpc;
     PnvOCC       occ;