[for-5.0,2/2] aspeed: change the "nic" property definition
diff mbox series

Message ID 20191118161712.6712-3-clg@kaod.org
State New
Headers show
Series
  • aspeed: rework inter model link properties
Related show

Commit Message

Cédric Le Goater Nov. 18, 2019, 4:17 p.m. UTC
The Aspeed MII model has a link pointing to its associated FTGMAC100
NIC in the machine.

Change the "nic" property definition so that it explicitly sets the
pointer. The property isn't optional : not being able to set the link
is a bug and QEMU should rather abort than exit in this case.

Signed-off-by: Cédric Le Goater <clg@kaod.org>
---
 hw/arm/aspeed_ast2600.c |  5 ++---
 hw/net/ftgmac100.c      | 19 +++++++++----------
 2 files changed, 11 insertions(+), 13 deletions(-)

Comments

Greg Kurz Nov. 18, 2019, 7:46 p.m. UTC | #1
On Mon, 18 Nov 2019 17:17:12 +0100
Cédric Le Goater <clg@kaod.org> wrote:

> The Aspeed MII model has a link pointing to its associated FTGMAC100
> NIC in the machine.
> 
> Change the "nic" property definition so that it explicitly sets the
> pointer. The property isn't optional : not being able to set the link
> is a bug and QEMU should rather abort than exit in this case.
> 
> Signed-off-by: Cédric Le Goater <clg@kaod.org>
> ---

Reviewed-by: Greg Kurz <groug@kaod.org>

>  hw/arm/aspeed_ast2600.c |  5 ++---
>  hw/net/ftgmac100.c      | 19 +++++++++----------
>  2 files changed, 11 insertions(+), 13 deletions(-)
> 
> diff --git a/hw/arm/aspeed_ast2600.c b/hw/arm/aspeed_ast2600.c
> index 810fd7de0c06..be88005dab8f 100644
> --- a/hw/arm/aspeed_ast2600.c
> +++ b/hw/arm/aspeed_ast2600.c
> @@ -183,9 +183,6 @@ static void aspeed_soc_ast2600_init(Object *obj)
>  
>          sysbus_init_child_obj(obj, "mii[*]", &s->mii[i], sizeof(s->mii[i]),
>                                TYPE_ASPEED_MII);
> -        object_property_add_const_link(OBJECT(&s->mii[i]), "nic",
> -                                       OBJECT(&s->ftgmac100[i]),
> -                                       &error_abort);
>      }
>  
>      sysbus_init_child_obj(obj, "xdma", OBJECT(&s->xdma), sizeof(s->xdma),
> @@ -441,6 +438,8 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)
>          sysbus_connect_irq(SYS_BUS_DEVICE(&s->ftgmac100[i]), 0,
>                             aspeed_soc_get_irq(s, ASPEED_ETH1 + i));
>  
> +        object_property_set_link(OBJECT(&s->mii[i]), OBJECT(&s->ftgmac100[i]),
> +                                 "nic", &error_abort);
>          object_property_set_bool(OBJECT(&s->mii[i]), true, "realized",
>                                   &err);
>          if (err) {
> diff --git a/hw/net/ftgmac100.c b/hw/net/ftgmac100.c
> index eb8b441461a1..86ac25894a89 100644
> --- a/hw/net/ftgmac100.c
> +++ b/hw/net/ftgmac100.c
> @@ -1204,17 +1204,8 @@ static void aspeed_mii_realize(DeviceState *dev, Error **errp)
>  {
>      AspeedMiiState *s = ASPEED_MII(dev);
>      SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
> -    Object *obj;
> -    Error *local_err = NULL;
>  
> -    obj = object_property_get_link(OBJECT(dev), "nic", &local_err);
> -    if (!obj) {
> -        error_propagate(errp, local_err);
> -        error_prepend(errp, "required link 'nic' not found: ");
> -        return;
> -    }
> -
> -    s->nic = FTGMAC100(obj);
> +    assert(s->nic);
>  
>      memory_region_init_io(&s->iomem, OBJECT(dev), &aspeed_mii_ops, s,
>                            TYPE_ASPEED_MII, 0x8);
> @@ -1231,6 +1222,13 @@ static const VMStateDescription vmstate_aspeed_mii = {
>          VMSTATE_END_OF_LIST()
>      }
>  };
> +
> +static Property aspeed_mii_properties[] = {
> +    DEFINE_PROP_LINK("nic", AspeedMiiState, nic, TYPE_FTGMAC100,
> +                     FTGMAC100State *),
> +    DEFINE_PROP_END_OF_LIST(),
> +};
> +
>  static void aspeed_mii_class_init(ObjectClass *klass, void *data)
>  {
>      DeviceClass *dc = DEVICE_CLASS(klass);
> @@ -1239,6 +1237,7 @@ static void aspeed_mii_class_init(ObjectClass *klass, void *data)
>      dc->reset = aspeed_mii_reset;
>      dc->realize = aspeed_mii_realize;
>      dc->desc = "Aspeed MII controller";
> +    dc->props = aspeed_mii_properties;
>  }
>  
>  static const TypeInfo aspeed_mii_info = {
Joel Stanley Nov. 18, 2019, 10:39 p.m. UTC | #2
On Mon, 18 Nov 2019 at 16:17, Cédric Le Goater <clg@kaod.org> wrote:
>
> The Aspeed MII model has a link pointing to its associated FTGMAC100
> NIC in the machine.
>
> Change the "nic" property definition so that it explicitly sets the
> pointer. The property isn't optional : not being able to set the link
> is a bug and QEMU should rather abort than exit in this case.
>
> Signed-off-by: Cédric Le Goater <clg@kaod.org>

Reviewed-by: Joel Stanley <joel@jms.id.au>

> ---
>  hw/arm/aspeed_ast2600.c |  5 ++---
>  hw/net/ftgmac100.c      | 19 +++++++++----------
>  2 files changed, 11 insertions(+), 13 deletions(-)
>
> diff --git a/hw/arm/aspeed_ast2600.c b/hw/arm/aspeed_ast2600.c
> index 810fd7de0c06..be88005dab8f 100644
> --- a/hw/arm/aspeed_ast2600.c
> +++ b/hw/arm/aspeed_ast2600.c
> @@ -183,9 +183,6 @@ static void aspeed_soc_ast2600_init(Object *obj)
>
>          sysbus_init_child_obj(obj, "mii[*]", &s->mii[i], sizeof(s->mii[i]),
>                                TYPE_ASPEED_MII);
> -        object_property_add_const_link(OBJECT(&s->mii[i]), "nic",
> -                                       OBJECT(&s->ftgmac100[i]),
> -                                       &error_abort);
>      }
>
>      sysbus_init_child_obj(obj, "xdma", OBJECT(&s->xdma), sizeof(s->xdma),
> @@ -441,6 +438,8 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)
>          sysbus_connect_irq(SYS_BUS_DEVICE(&s->ftgmac100[i]), 0,
>                             aspeed_soc_get_irq(s, ASPEED_ETH1 + i));
>
> +        object_property_set_link(OBJECT(&s->mii[i]), OBJECT(&s->ftgmac100[i]),
> +                                 "nic", &error_abort);
>          object_property_set_bool(OBJECT(&s->mii[i]), true, "realized",
>                                   &err);
>          if (err) {
> diff --git a/hw/net/ftgmac100.c b/hw/net/ftgmac100.c
> index eb8b441461a1..86ac25894a89 100644
> --- a/hw/net/ftgmac100.c
> +++ b/hw/net/ftgmac100.c
> @@ -1204,17 +1204,8 @@ static void aspeed_mii_realize(DeviceState *dev, Error **errp)
>  {
>      AspeedMiiState *s = ASPEED_MII(dev);
>      SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
> -    Object *obj;
> -    Error *local_err = NULL;
>
> -    obj = object_property_get_link(OBJECT(dev), "nic", &local_err);
> -    if (!obj) {
> -        error_propagate(errp, local_err);
> -        error_prepend(errp, "required link 'nic' not found: ");
> -        return;
> -    }
> -
> -    s->nic = FTGMAC100(obj);
> +    assert(s->nic);
>
>      memory_region_init_io(&s->iomem, OBJECT(dev), &aspeed_mii_ops, s,
>                            TYPE_ASPEED_MII, 0x8);
> @@ -1231,6 +1222,13 @@ static const VMStateDescription vmstate_aspeed_mii = {
>          VMSTATE_END_OF_LIST()
>      }
>  };
> +
> +static Property aspeed_mii_properties[] = {
> +    DEFINE_PROP_LINK("nic", AspeedMiiState, nic, TYPE_FTGMAC100,
> +                     FTGMAC100State *),
> +    DEFINE_PROP_END_OF_LIST(),
> +};
> +
>  static void aspeed_mii_class_init(ObjectClass *klass, void *data)
>  {
>      DeviceClass *dc = DEVICE_CLASS(klass);
> @@ -1239,6 +1237,7 @@ static void aspeed_mii_class_init(ObjectClass *klass, void *data)
>      dc->reset = aspeed_mii_reset;
>      dc->realize = aspeed_mii_realize;
>      dc->desc = "Aspeed MII controller";
> +    dc->props = aspeed_mii_properties;
>  }
>
>  static const TypeInfo aspeed_mii_info = {
> --
> 2.21.0
>

Patch
diff mbox series

diff --git a/hw/arm/aspeed_ast2600.c b/hw/arm/aspeed_ast2600.c
index 810fd7de0c06..be88005dab8f 100644
--- a/hw/arm/aspeed_ast2600.c
+++ b/hw/arm/aspeed_ast2600.c
@@ -183,9 +183,6 @@  static void aspeed_soc_ast2600_init(Object *obj)
 
         sysbus_init_child_obj(obj, "mii[*]", &s->mii[i], sizeof(s->mii[i]),
                               TYPE_ASPEED_MII);
-        object_property_add_const_link(OBJECT(&s->mii[i]), "nic",
-                                       OBJECT(&s->ftgmac100[i]),
-                                       &error_abort);
     }
 
     sysbus_init_child_obj(obj, "xdma", OBJECT(&s->xdma), sizeof(s->xdma),
@@ -441,6 +438,8 @@  static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)
         sysbus_connect_irq(SYS_BUS_DEVICE(&s->ftgmac100[i]), 0,
                            aspeed_soc_get_irq(s, ASPEED_ETH1 + i));
 
+        object_property_set_link(OBJECT(&s->mii[i]), OBJECT(&s->ftgmac100[i]),
+                                 "nic", &error_abort);
         object_property_set_bool(OBJECT(&s->mii[i]), true, "realized",
                                  &err);
         if (err) {
diff --git a/hw/net/ftgmac100.c b/hw/net/ftgmac100.c
index eb8b441461a1..86ac25894a89 100644
--- a/hw/net/ftgmac100.c
+++ b/hw/net/ftgmac100.c
@@ -1204,17 +1204,8 @@  static void aspeed_mii_realize(DeviceState *dev, Error **errp)
 {
     AspeedMiiState *s = ASPEED_MII(dev);
     SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
-    Object *obj;
-    Error *local_err = NULL;
 
-    obj = object_property_get_link(OBJECT(dev), "nic", &local_err);
-    if (!obj) {
-        error_propagate(errp, local_err);
-        error_prepend(errp, "required link 'nic' not found: ");
-        return;
-    }
-
-    s->nic = FTGMAC100(obj);
+    assert(s->nic);
 
     memory_region_init_io(&s->iomem, OBJECT(dev), &aspeed_mii_ops, s,
                           TYPE_ASPEED_MII, 0x8);
@@ -1231,6 +1222,13 @@  static const VMStateDescription vmstate_aspeed_mii = {
         VMSTATE_END_OF_LIST()
     }
 };
+
+static Property aspeed_mii_properties[] = {
+    DEFINE_PROP_LINK("nic", AspeedMiiState, nic, TYPE_FTGMAC100,
+                     FTGMAC100State *),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static void aspeed_mii_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -1239,6 +1237,7 @@  static void aspeed_mii_class_init(ObjectClass *klass, void *data)
     dc->reset = aspeed_mii_reset;
     dc->realize = aspeed_mii_realize;
     dc->desc = "Aspeed MII controller";
+    dc->props = aspeed_mii_properties;
 }
 
 static const TypeInfo aspeed_mii_info = {