diff mbox

[V2] nios2: iic: Convert CPU prop to qom link

Message ID 20170227193857.9368-1-marex@denx.de (mailing list archive)
State New, archived
Headers show

Commit Message

Marek Vasut Feb. 27, 2017, 7:38 p.m. UTC
Add a const qom link between the CPU and the IIC instead
of passing the CPU link through a qom property.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Alexander Graf <agraf@suse.de>
Cc: Chris Wulff <crwulff@gmail.com>
Cc: Igor Mammedov <imammedo@redhat.com>
Cc: Jeff Da Silva <jdasilva@altera.com>
Cc: Ley Foon Tan <lftan@altera.com>
Cc: Markus Armbruster <armbru@redhat.com>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Sandra Loosemore <sandra@codesourcery.com>
Cc: Yves Vandervennet <yvanderv@altera.com>
---
V2: Retain dc->cannot_instantiate_with_device_add_yet = true
    in altera_iic_class_init() since the device is still not
    device_add() creatable.
---
 hw/intc/nios2_iic.c       | 12 ++++--------
 hw/nios2/10m50_devboard.c |  3 ++-
 2 files changed, 6 insertions(+), 9 deletions(-)

Comments

Marek Vasut March 11, 2017, 8:23 p.m. UTC | #1
On 02/27/2017 08:38 PM, Marek Vasut wrote:
> Add a const qom link between the CPU and the IIC instead
> of passing the CPU link through a qom property.
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Alexander Graf <agraf@suse.de>
> Cc: Chris Wulff <crwulff@gmail.com>
> Cc: Igor Mammedov <imammedo@redhat.com>
> Cc: Jeff Da Silva <jdasilva@altera.com>
> Cc: Ley Foon Tan <lftan@altera.com>
> Cc: Markus Armbruster <armbru@redhat.com>
> Cc: Richard Henderson <rth@twiddle.net>
> Cc: Sandra Loosemore <sandra@codesourcery.com>
> Cc: Yves Vandervennet <yvanderv@altera.com>

Why is this patch not applied yet ?

> ---
> V2: Retain dc->cannot_instantiate_with_device_add_yet = true
>     in altera_iic_class_init() since the device is still not
>     device_add() creatable.
> ---
>  hw/intc/nios2_iic.c       | 12 ++++--------
>  hw/nios2/10m50_devboard.c |  3 ++-
>  2 files changed, 6 insertions(+), 9 deletions(-)
> 
> diff --git a/hw/intc/nios2_iic.c b/hw/intc/nios2_iic.c
> index 818ab1b315..fe15621202 100644
> --- a/hw/intc/nios2_iic.c
> +++ b/hw/intc/nios2_iic.c
> @@ -62,17 +62,15 @@ static void altera_iic_init(Object *obj)
>      sysbus_init_irq(SYS_BUS_DEVICE(obj), &pv->parent_irq);
>  }
>  
> -static Property altera_iic_properties[] = {
> -    DEFINE_PROP_PTR("cpu", AlteraIIC, cpu),
> -    DEFINE_PROP_END_OF_LIST(),
> -};
> -
>  static void altera_iic_realize(DeviceState *dev, Error **errp)
>  {
>      struct AlteraIIC *pv = ALTERA_IIC(dev);
> +    Error *err = NULL;
>  
> +    pv->cpu = object_property_get_link(OBJECT(dev), "cpu", &err);
>      if (!pv->cpu) {
> -        error_setg(errp, "altera,iic: CPU not connected");
> +        error_setg(errp, "altera,iic: CPU link not found: %s",
> +                   error_get_pretty(err));
>          return;
>      }
>  }
> @@ -81,8 +79,6 @@ static void altera_iic_class_init(ObjectClass *klass, void *data)
>  {
>      DeviceClass *dc = DEVICE_CLASS(klass);
>  
> -    dc->props = altera_iic_properties;
> -    /* Reason: pointer property "cpu" */
>      dc->cannot_instantiate_with_device_add_yet = true;
>      dc->realize = altera_iic_realize;
>  }
> diff --git a/hw/nios2/10m50_devboard.c b/hw/nios2/10m50_devboard.c
> index 0d8b9aa58f..c18e0b2a17 100644
> --- a/hw/nios2/10m50_devboard.c
> +++ b/hw/nios2/10m50_devboard.c
> @@ -83,7 +83,8 @@ static void nios2_10m50_ghrd_init(MachineState *machine)
>  
>      /* Register: Internal Interrupt Controller (IIC) */
>      dev = qdev_create(NULL, "altera,iic");
> -    qdev_prop_set_ptr(dev, "cpu", cpu);
> +    object_property_add_const_link(OBJECT(dev), "cpu", OBJECT(cpu),
> +                                   &error_abort);
>      qdev_init_nofail(dev);
>      sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, cpu_irq[0]);
>      for (i = 0; i < 32; i++) {
>
Peter Maydell March 17, 2017, 4:51 p.m. UTC | #2
On 27 February 2017 at 19:38, Marek Vasut <marex@denx.de> wrote:
> Add a const qom link between the CPU and the IIC instead
> of passing the CPU link through a qom property.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Alexander Graf <agraf@suse.de>
> Cc: Chris Wulff <crwulff@gmail.com>
> Cc: Igor Mammedov <imammedo@redhat.com>
> Cc: Jeff Da Silva <jdasilva@altera.com>
> Cc: Ley Foon Tan <lftan@altera.com>
> Cc: Markus Armbruster <armbru@redhat.com>
> Cc: Richard Henderson <rth@twiddle.net>
> Cc: Sandra Loosemore <sandra@codesourcery.com>
> Cc: Yves Vandervennet <yvanderv@altera.com>
> ---
> V2: Retain dc->cannot_instantiate_with_device_add_yet = true
>     in altera_iic_class_init() since the device is still not
>     device_add() creatable.
> ---
>  hw/intc/nios2_iic.c       | 12 ++++--------
>  hw/nios2/10m50_devboard.c |  3 ++-
>  2 files changed, 6 insertions(+), 9 deletions(-)
>
> diff --git a/hw/intc/nios2_iic.c b/hw/intc/nios2_iic.c
> index 818ab1b315..fe15621202 100644
> --- a/hw/intc/nios2_iic.c
> +++ b/hw/intc/nios2_iic.c
> @@ -62,17 +62,15 @@ static void altera_iic_init(Object *obj)
>      sysbus_init_irq(SYS_BUS_DEVICE(obj), &pv->parent_irq);
>  }
>
> -static Property altera_iic_properties[] = {
> -    DEFINE_PROP_PTR("cpu", AlteraIIC, cpu),
> -    DEFINE_PROP_END_OF_LIST(),
> -};
> -
>  static void altera_iic_realize(DeviceState *dev, Error **errp)
>  {
>      struct AlteraIIC *pv = ALTERA_IIC(dev);
> +    Error *err = NULL;
>
> +    pv->cpu = object_property_get_link(OBJECT(dev), "cpu", &err);
>      if (!pv->cpu) {
> -        error_setg(errp, "altera,iic: CPU not connected");
> +        error_setg(errp, "altera,iic: CPU link not found: %s",
> +                   error_get_pretty(err));
>          return;
>      }
>  }
> @@ -81,8 +79,6 @@ static void altera_iic_class_init(ObjectClass *klass, void *data)
>  {
>      DeviceClass *dc = DEVICE_CLASS(klass);
>
> -    dc->props = altera_iic_properties;
> -    /* Reason: pointer property "cpu" */

This comment goes with the line below it:

>      dc->cannot_instantiate_with_device_add_yet = true;

as it's explaining why we cannot instantiate with device add.

Either the cannot_instantiate assignment should go,
or the comment needs to be updated to explain why we
cannot-instantiate (since it's no longer because of a
pointer property).

>      dc->realize = altera_iic_realize;
>  }
> diff --git a/hw/nios2/10m50_devboard.c b/hw/nios2/10m50_devboard.c
> index 0d8b9aa58f..c18e0b2a17 100644
> --- a/hw/nios2/10m50_devboard.c
> +++ b/hw/nios2/10m50_devboard.c
> @@ -83,7 +83,8 @@ static void nios2_10m50_ghrd_init(MachineState *machine)
>
>      /* Register: Internal Interrupt Controller (IIC) */
>      dev = qdev_create(NULL, "altera,iic");
> -    qdev_prop_set_ptr(dev, "cpu", cpu);
> +    object_property_add_const_link(OBJECT(dev), "cpu", OBJECT(cpu),
> +                                   &error_abort);
>      qdev_init_nofail(dev);
>      sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, cpu_irq[0]);
>      for (i = 0; i < 32; i++) {
> --
> 2.11.0

thanks
-- PMM
Markus Armbruster March 17, 2017, 5:09 p.m. UTC | #3
Marek Vasut <marex@denx.de> writes:

> Add a const qom link between the CPU and the IIC instead
> of passing the CPU link through a qom property.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Alexander Graf <agraf@suse.de>
> Cc: Chris Wulff <crwulff@gmail.com>
> Cc: Igor Mammedov <imammedo@redhat.com>
> Cc: Jeff Da Silva <jdasilva@altera.com>
> Cc: Ley Foon Tan <lftan@altera.com>
> Cc: Markus Armbruster <armbru@redhat.com>
> Cc: Richard Henderson <rth@twiddle.net>
> Cc: Sandra Loosemore <sandra@codesourcery.com>
> Cc: Yves Vandervennet <yvanderv@altera.com>
> ---
> V2: Retain dc->cannot_instantiate_with_device_add_yet = true
>     in altera_iic_class_init() since the device is still not
>     device_add() creatable.
> ---
>  hw/intc/nios2_iic.c       | 12 ++++--------
>  hw/nios2/10m50_devboard.c |  3 ++-
>  2 files changed, 6 insertions(+), 9 deletions(-)
>
> diff --git a/hw/intc/nios2_iic.c b/hw/intc/nios2_iic.c
> index 818ab1b315..fe15621202 100644
> --- a/hw/intc/nios2_iic.c
> +++ b/hw/intc/nios2_iic.c
> @@ -62,17 +62,15 @@ static void altera_iic_init(Object *obj)
>      sysbus_init_irq(SYS_BUS_DEVICE(obj), &pv->parent_irq);
>  }
>  
> -static Property altera_iic_properties[] = {
> -    DEFINE_PROP_PTR("cpu", AlteraIIC, cpu),
> -    DEFINE_PROP_END_OF_LIST(),
> -};
> -
>  static void altera_iic_realize(DeviceState *dev, Error **errp)
>  {
>      struct AlteraIIC *pv = ALTERA_IIC(dev);
> +    Error *err = NULL;
>  
> +    pv->cpu = object_property_get_link(OBJECT(dev), "cpu", &err);
>      if (!pv->cpu) {
> -        error_setg(errp, "altera,iic: CPU not connected");
> +        error_setg(errp, "altera,iic: CPU link not found: %s",
> +                   error_get_pretty(err));
>          return;
>      }
>  }
> @@ -81,8 +79,6 @@ static void altera_iic_class_init(ObjectClass *klass, void *data)
>  {
>      DeviceClass *dc = DEVICE_CLASS(klass);
>  
> -    dc->props = altera_iic_properties;
> -    /* Reason: pointer property "cpu" */

You need to update, not delete this comment.  I think

       /* Reason: needs to be wired up, e.g. by nios2_10m50_ghrd_init() */

would do.

>      dc->cannot_instantiate_with_device_add_yet = true;
>      dc->realize = altera_iic_realize;
>  }
> diff --git a/hw/nios2/10m50_devboard.c b/hw/nios2/10m50_devboard.c
> index 0d8b9aa58f..c18e0b2a17 100644
> --- a/hw/nios2/10m50_devboard.c
> +++ b/hw/nios2/10m50_devboard.c
> @@ -83,7 +83,8 @@ static void nios2_10m50_ghrd_init(MachineState *machine)
>  
>      /* Register: Internal Interrupt Controller (IIC) */
>      dev = qdev_create(NULL, "altera,iic");
> -    qdev_prop_set_ptr(dev, "cpu", cpu);
> +    object_property_add_const_link(OBJECT(dev), "cpu", OBJECT(cpu),
> +                                   &error_abort);
>      qdev_init_nofail(dev);
>      sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, cpu_irq[0]);
>      for (i = 0; i < 32; i++) {

With a suitable comment next to
dc->cannot_instantiate_with_device_add_yet = true:
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Marek Vasut March 17, 2017, 9:01 p.m. UTC | #4
On 03/17/2017 06:09 PM, Markus Armbruster wrote:
> Marek Vasut <marex@denx.de> writes:
> 
>> Add a const qom link between the CPU and the IIC instead
>> of passing the CPU link through a qom property.
>>
>> Signed-off-by: Marek Vasut <marex@denx.de>
>> Cc: Alexander Graf <agraf@suse.de>
>> Cc: Chris Wulff <crwulff@gmail.com>
>> Cc: Igor Mammedov <imammedo@redhat.com>
>> Cc: Jeff Da Silva <jdasilva@altera.com>
>> Cc: Ley Foon Tan <lftan@altera.com>
>> Cc: Markus Armbruster <armbru@redhat.com>
>> Cc: Richard Henderson <rth@twiddle.net>
>> Cc: Sandra Loosemore <sandra@codesourcery.com>
>> Cc: Yves Vandervennet <yvanderv@altera.com>
>> ---
>> V2: Retain dc->cannot_instantiate_with_device_add_yet = true
>>     in altera_iic_class_init() since the device is still not
>>     device_add() creatable.
>> ---
>>  hw/intc/nios2_iic.c       | 12 ++++--------
>>  hw/nios2/10m50_devboard.c |  3 ++-
>>  2 files changed, 6 insertions(+), 9 deletions(-)
>>
>> diff --git a/hw/intc/nios2_iic.c b/hw/intc/nios2_iic.c
>> index 818ab1b315..fe15621202 100644
>> --- a/hw/intc/nios2_iic.c
>> +++ b/hw/intc/nios2_iic.c
>> @@ -62,17 +62,15 @@ static void altera_iic_init(Object *obj)
>>      sysbus_init_irq(SYS_BUS_DEVICE(obj), &pv->parent_irq);
>>  }
>>  
>> -static Property altera_iic_properties[] = {
>> -    DEFINE_PROP_PTR("cpu", AlteraIIC, cpu),
>> -    DEFINE_PROP_END_OF_LIST(),
>> -};
>> -
>>  static void altera_iic_realize(DeviceState *dev, Error **errp)
>>  {
>>      struct AlteraIIC *pv = ALTERA_IIC(dev);
>> +    Error *err = NULL;
>>  
>> +    pv->cpu = object_property_get_link(OBJECT(dev), "cpu", &err);
>>      if (!pv->cpu) {
>> -        error_setg(errp, "altera,iic: CPU not connected");
>> +        error_setg(errp, "altera,iic: CPU link not found: %s",
>> +                   error_get_pretty(err));
>>          return;
>>      }
>>  }
>> @@ -81,8 +79,6 @@ static void altera_iic_class_init(ObjectClass *klass, void *data)
>>  {
>>      DeviceClass *dc = DEVICE_CLASS(klass);
>>  
>> -    dc->props = altera_iic_properties;
>> -    /* Reason: pointer property "cpu" */
> 
> You need to update, not delete this comment.  I think
> 
>        /* Reason: needs to be wired up, e.g. by nios2_10m50_ghrd_init() */
> 
> would do.
> 
>>      dc->cannot_instantiate_with_device_add_yet = true;
>>      dc->realize = altera_iic_realize;
>>  }
>> diff --git a/hw/nios2/10m50_devboard.c b/hw/nios2/10m50_devboard.c
>> index 0d8b9aa58f..c18e0b2a17 100644
>> --- a/hw/nios2/10m50_devboard.c
>> +++ b/hw/nios2/10m50_devboard.c
>> @@ -83,7 +83,8 @@ static void nios2_10m50_ghrd_init(MachineState *machine)
>>  
>>      /* Register: Internal Interrupt Controller (IIC) */
>>      dev = qdev_create(NULL, "altera,iic");
>> -    qdev_prop_set_ptr(dev, "cpu", cpu);
>> +    object_property_add_const_link(OBJECT(dev), "cpu", OBJECT(cpu),
>> +                                   &error_abort);
>>      qdev_init_nofail(dev);
>>      sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, cpu_irq[0]);
>>      for (i = 0; i < 32; i++) {
> 
> With a suitable comment next to
> dc->cannot_instantiate_with_device_add_yet = true:
> Reviewed-by: Markus Armbruster <armbru@redhat.com>
> 
OK, done and added the R-B , thanks
Marek Vasut March 17, 2017, 9:01 p.m. UTC | #5
On 03/17/2017 05:51 PM, Peter Maydell wrote:
> On 27 February 2017 at 19:38, Marek Vasut <marex@denx.de> wrote:
>> Add a const qom link between the CPU and the IIC instead
>> of passing the CPU link through a qom property.
>>
>> Signed-off-by: Marek Vasut <marex@denx.de>
>> Cc: Alexander Graf <agraf@suse.de>
>> Cc: Chris Wulff <crwulff@gmail.com>
>> Cc: Igor Mammedov <imammedo@redhat.com>
>> Cc: Jeff Da Silva <jdasilva@altera.com>
>> Cc: Ley Foon Tan <lftan@altera.com>
>> Cc: Markus Armbruster <armbru@redhat.com>
>> Cc: Richard Henderson <rth@twiddle.net>
>> Cc: Sandra Loosemore <sandra@codesourcery.com>
>> Cc: Yves Vandervennet <yvanderv@altera.com>
>> ---
>> V2: Retain dc->cannot_instantiate_with_device_add_yet = true
>>     in altera_iic_class_init() since the device is still not
>>     device_add() creatable.
>> ---
>>  hw/intc/nios2_iic.c       | 12 ++++--------
>>  hw/nios2/10m50_devboard.c |  3 ++-
>>  2 files changed, 6 insertions(+), 9 deletions(-)
>>
>> diff --git a/hw/intc/nios2_iic.c b/hw/intc/nios2_iic.c
>> index 818ab1b315..fe15621202 100644
>> --- a/hw/intc/nios2_iic.c
>> +++ b/hw/intc/nios2_iic.c
>> @@ -62,17 +62,15 @@ static void altera_iic_init(Object *obj)
>>      sysbus_init_irq(SYS_BUS_DEVICE(obj), &pv->parent_irq);
>>  }
>>
>> -static Property altera_iic_properties[] = {
>> -    DEFINE_PROP_PTR("cpu", AlteraIIC, cpu),
>> -    DEFINE_PROP_END_OF_LIST(),
>> -};
>> -
>>  static void altera_iic_realize(DeviceState *dev, Error **errp)
>>  {
>>      struct AlteraIIC *pv = ALTERA_IIC(dev);
>> +    Error *err = NULL;
>>
>> +    pv->cpu = object_property_get_link(OBJECT(dev), "cpu", &err);
>>      if (!pv->cpu) {
>> -        error_setg(errp, "altera,iic: CPU not connected");
>> +        error_setg(errp, "altera,iic: CPU link not found: %s",
>> +                   error_get_pretty(err));
>>          return;
>>      }
>>  }
>> @@ -81,8 +79,6 @@ static void altera_iic_class_init(ObjectClass *klass, void *data)
>>  {
>>      DeviceClass *dc = DEVICE_CLASS(klass);
>>
>> -    dc->props = altera_iic_properties;
>> -    /* Reason: pointer property "cpu" */
> 
> This comment goes with the line below it:
> 
>>      dc->cannot_instantiate_with_device_add_yet = true;
> 
> as it's explaining why we cannot instantiate with device add.
> 
> Either the cannot_instantiate assignment should go,
> or the comment needs to be updated to explain why we
> cannot-instantiate (since it's no longer because of a
> pointer property).

Fixed, will send V3 shortly, thanks.

>>      dc->realize = altera_iic_realize;
>>  }
>> diff --git a/hw/nios2/10m50_devboard.c b/hw/nios2/10m50_devboard.c
>> index 0d8b9aa58f..c18e0b2a17 100644
>> --- a/hw/nios2/10m50_devboard.c
>> +++ b/hw/nios2/10m50_devboard.c
>> @@ -83,7 +83,8 @@ static void nios2_10m50_ghrd_init(MachineState *machine)
>>
>>      /* Register: Internal Interrupt Controller (IIC) */
>>      dev = qdev_create(NULL, "altera,iic");
>> -    qdev_prop_set_ptr(dev, "cpu", cpu);
>> +    object_property_add_const_link(OBJECT(dev), "cpu", OBJECT(cpu),
>> +                                   &error_abort);
>>      qdev_init_nofail(dev);
>>      sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, cpu_irq[0]);
>>      for (i = 0; i < 32; i++) {
>> --
>> 2.11.0
> 
> thanks
> -- PMM
>
diff mbox

Patch

diff --git a/hw/intc/nios2_iic.c b/hw/intc/nios2_iic.c
index 818ab1b315..fe15621202 100644
--- a/hw/intc/nios2_iic.c
+++ b/hw/intc/nios2_iic.c
@@ -62,17 +62,15 @@  static void altera_iic_init(Object *obj)
     sysbus_init_irq(SYS_BUS_DEVICE(obj), &pv->parent_irq);
 }
 
-static Property altera_iic_properties[] = {
-    DEFINE_PROP_PTR("cpu", AlteraIIC, cpu),
-    DEFINE_PROP_END_OF_LIST(),
-};
-
 static void altera_iic_realize(DeviceState *dev, Error **errp)
 {
     struct AlteraIIC *pv = ALTERA_IIC(dev);
+    Error *err = NULL;
 
+    pv->cpu = object_property_get_link(OBJECT(dev), "cpu", &err);
     if (!pv->cpu) {
-        error_setg(errp, "altera,iic: CPU not connected");
+        error_setg(errp, "altera,iic: CPU link not found: %s",
+                   error_get_pretty(err));
         return;
     }
 }
@@ -81,8 +79,6 @@  static void altera_iic_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
 
-    dc->props = altera_iic_properties;
-    /* Reason: pointer property "cpu" */
     dc->cannot_instantiate_with_device_add_yet = true;
     dc->realize = altera_iic_realize;
 }
diff --git a/hw/nios2/10m50_devboard.c b/hw/nios2/10m50_devboard.c
index 0d8b9aa58f..c18e0b2a17 100644
--- a/hw/nios2/10m50_devboard.c
+++ b/hw/nios2/10m50_devboard.c
@@ -83,7 +83,8 @@  static void nios2_10m50_ghrd_init(MachineState *machine)
 
     /* Register: Internal Interrupt Controller (IIC) */
     dev = qdev_create(NULL, "altera,iic");
-    qdev_prop_set_ptr(dev, "cpu", cpu);
+    object_property_add_const_link(OBJECT(dev), "cpu", OBJECT(cpu),
+                                   &error_abort);
     qdev_init_nofail(dev);
     sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, cpu_irq[0]);
     for (i = 0; i < 32; i++) {