[PATCH v2 10/13] hw/arm/bcm2836: Split out common realize() code

Philippe Mathieu-Daudé posted 13 patches 5 years, 9 months ago
There is a newer version of this series
[PATCH v2 10/13] hw/arm/bcm2836: Split out common realize() code
Posted by Philippe Mathieu-Daudé 5 years, 9 months ago
The realize() function is clearly composed of two parts,
each described by a comment:

  void realize()
  {
     /* common peripherals from bcm2835 */
     ...
     /* bcm2836 interrupt controller (and mailboxes, etc.) */
     ...
   }

Split the two part, so we can reuse the common part with other
SoCs from this family.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/arm/bcm2836.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c
index caaa4b625e..2b6fe31139 100644
--- a/hw/arm/bcm2836.c
+++ b/hw/arm/bcm2836.c
@@ -51,8 +51,10 @@ static void bcm2836_init(Object *obj)
         qdev_prop_set_uint32(DEVICE(obj), "enabled-cpus", bc->core_count);
     }
 
-    sysbus_init_child_obj(obj, "control", &s->control, sizeof(s->control),
-                          TYPE_BCM2836_CONTROL);
+    if (bc->ctrl_base) {
+        sysbus_init_child_obj(obj, "control", &s->control,
+                              sizeof(s->control), TYPE_BCM2836_CONTROL);
+    }
 
     sysbus_init_child_obj(obj, "peripherals", &s->peripherals,
                           sizeof(s->peripherals), TYPE_BCM2835_PERIPHERALS);
@@ -62,13 +64,12 @@ static void bcm2836_init(Object *obj)
                               "vcram-size", &error_abort);
 }
 
-static void bcm2836_realize(DeviceState *dev, Error **errp)
+static void bcm283x_common_realize(DeviceState *dev, Error **errp)
 {
     BCM283XState *s = BCM283X(dev);
     BCM283XClass *bc = BCM283X_GET_CLASS(dev);
     Object *obj;
     Error *err = NULL;
-    int n;
 
     /* common peripherals from bcm2835 */
 
@@ -100,6 +101,20 @@ static void bcm2836_realize(DeviceState *dev, Error **errp)
 
     sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->peripherals), 0,
                             bc->peri_base, 1);
+}
+
+static void bcm2836_realize(DeviceState *dev, Error **errp)
+{
+    BCM283XState *s = BCM283X(dev);
+    BCM283XClass *bc = BCM283X_GET_CLASS(dev);
+    Error *err = NULL;
+    int n;
+
+    bcm283x_common_realize(dev, &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
 
     /* bcm2836 interrupt controller (and mailboxes, etc.) */
     object_property_set_bool(OBJECT(&s->control), true, "realized", &err);
-- 
2.21.1


Re: [PATCH v2 10/13] hw/arm/bcm2836: Split out common realize() code
Posted by Luc Michel 5 years, 8 months ago
On 2/17/20 12:45 PM, Philippe Mathieu-Daudé wrote:
> The realize() function is clearly composed of two parts,
> each described by a comment:
> 
>   void realize()
>   {
>      /* common peripherals from bcm2835 */
>      ...
>      /* bcm2836 interrupt controller (and mailboxes, etc.) */
>      ...
>    }
> 
> Split the two part, so we can reuse the common part with other
> SoCs from this family.
> 
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

Reviewed-by: Luc Michel <luc.michel@greensocs.com>

> ---
>  hw/arm/bcm2836.c | 23 +++++++++++++++++++----
>  1 file changed, 19 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c
> index caaa4b625e..2b6fe31139 100644
> --- a/hw/arm/bcm2836.c
> +++ b/hw/arm/bcm2836.c
> @@ -51,8 +51,10 @@ static void bcm2836_init(Object *obj)
>          qdev_prop_set_uint32(DEVICE(obj), "enabled-cpus", bc->core_count);
>      }
>  
> -    sysbus_init_child_obj(obj, "control", &s->control, sizeof(s->control),
> -                          TYPE_BCM2836_CONTROL);
> +    if (bc->ctrl_base) {
> +        sysbus_init_child_obj(obj, "control", &s->control,
> +                              sizeof(s->control), TYPE_BCM2836_CONTROL);
> +    }
>  
>      sysbus_init_child_obj(obj, "peripherals", &s->peripherals,
>                            sizeof(s->peripherals), TYPE_BCM2835_PERIPHERALS);
> @@ -62,13 +64,12 @@ static void bcm2836_init(Object *obj)
>                                "vcram-size", &error_abort);
>  }
>  
> -static void bcm2836_realize(DeviceState *dev, Error **errp)
> +static void bcm283x_common_realize(DeviceState *dev, Error **errp)
>  {
>      BCM283XState *s = BCM283X(dev);
>      BCM283XClass *bc = BCM283X_GET_CLASS(dev);
>      Object *obj;
>      Error *err = NULL;
> -    int n;
>  
>      /* common peripherals from bcm2835 */
>  
> @@ -100,6 +101,20 @@ static void bcm2836_realize(DeviceState *dev, Error **errp)
>  
>      sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->peripherals), 0,
>                              bc->peri_base, 1);
> +}
> +
> +static void bcm2836_realize(DeviceState *dev, Error **errp)
> +{
> +    BCM283XState *s = BCM283X(dev);
> +    BCM283XClass *bc = BCM283X_GET_CLASS(dev);
> +    Error *err = NULL;
> +    int n;
> +
> +    bcm283x_common_realize(dev, &err);
> +    if (err) {
> +        error_propagate(errp, err);
> +        return;
> +    }
>  
>      /* bcm2836 interrupt controller (and mailboxes, etc.) */
>      object_property_set_bool(OBJECT(&s->control), true, "realized", &err);
>