[PATCH v1 07/12] hw/arm/aspeed_ast10x0: Pass SoC name to common init for AST10x0 family reuse

Jamin Lin via posted 12 patches 1 week, 1 day ago
Maintainers: "Cédric Le Goater" <clg@kaod.org>, Peter Maydell <peter.maydell@linaro.org>, Steven Lee <steven_lee@aspeedtech.com>, Troy Lee <leetroy@gmail.com>, Jamin Lin <jamin_lin@aspeedtech.com>, Andrew Jeffery <andrew@codeconstruct.com.au>, Joel Stanley <joel@jms.id.au>, Alistair Francis <alistair@alistair23.me>, Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>
There is a newer version of this series
[PATCH v1 07/12] hw/arm/aspeed_ast10x0: Pass SoC name to common init for AST10x0 family reuse
Posted by Jamin Lin via 1 week, 1 day ago
Refactor the AST10x0 common initialization to accept a socname
parameter.

The AST1030 model can be reused by AST1060 since they share most of the
same controllers. This approach allows AST1060 to leverage the existing
AST1030 initialization flow while keeping separate SoC-specific init
functions for components that differ.

This prepares the framework for AST1060 support, allowing it to reuse
AST1030 device models and initialization flow without code duplication.

No functional changes.

Signed-off-by: Jamin Lin <jamin_lin@aspeedtech.com>
---
 hw/arm/aspeed_ast10x0.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/hw/arm/aspeed_ast10x0.c b/hw/arm/aspeed_ast10x0.c
index 5bbe16af24..c85c21b149 100644
--- a/hw/arm/aspeed_ast10x0.c
+++ b/hw/arm/aspeed_ast10x0.c
@@ -107,19 +107,14 @@ static qemu_irq aspeed_soc_ast1030_get_irq(AspeedSoCState *s, int dev)
     return qdev_get_gpio_in(DEVICE(&a->armv7m), sc->irqmap[dev]);
 }
 
-static void aspeed_soc_ast10x0_init(Object *obj)
+static void aspeed_soc_ast10x0_init(Object *obj, const char *socname)
 {
     Aspeed10x0SoCState *a = ASPEED10X0_SOC(obj);
     AspeedSoCState *s = ASPEED_SOC(obj);
     AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s);
-    char socname[8];
     char typename[64];
     int i;
 
-    if (sscanf(object_get_typename(obj), "%7s", socname) != 1) {
-        g_assert_not_reached();
-    }
-
     object_initialize_child(obj, "armv7m", &a->armv7m, TYPE_ARMV7M);
 
     s->sysclk = qdev_init_clock_in(DEVICE(s), "sysclk", NULL, NULL, 0);
@@ -184,8 +179,13 @@ static void aspeed_soc_ast10x0_init(Object *obj)
 static void aspeed_soc_ast1030_init(Object *obj)
 {
     AspeedSoCState *s = ASPEED_SOC(obj);
+    char socname[8];
+
+    if (sscanf(object_get_typename(obj), "%7s", socname) != 1) {
+        g_assert_not_reached();
+    }
 
-    aspeed_soc_ast10x0_init(obj);
+    aspeed_soc_ast10x0_init(obj, socname);
     object_initialize_child(obj, "lpc", &s->lpc, TYPE_ASPEED_LPC);
     object_initialize_child(obj, "peci", &s->peci, TYPE_ASPEED_PECI);
 }
-- 
2.43.0
Re: [PATCH v1 07/12] hw/arm/aspeed_ast10x0: Pass SoC name to common init for AST10x0 family reuse
Posted by Cédric Le Goater 2 days, 21 hours ago
On 11/6/25 09:49, Jamin Lin wrote:
> Refactor the AST10x0 common initialization to accept a socname
> parameter.
> 
> The AST1030 model can be reused by AST1060 since they share most of the
> same controllers. This approach allows AST1060 to leverage the existing
> AST1030 initialization flow while keeping separate SoC-specific init
> functions for components that differ.
> 
> This prepares the framework for AST1060 support, allowing it to reuse
> AST1030 device models and initialization flow without code duplication.
> 
> No functional changes.
> 
> Signed-off-by: Jamin Lin <jamin_lin@aspeedtech.com>
> ---
>   hw/arm/aspeed_ast10x0.c | 14 +++++++-------
>   1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/hw/arm/aspeed_ast10x0.c b/hw/arm/aspeed_ast10x0.c
> index 5bbe16af24..c85c21b149 100644
> --- a/hw/arm/aspeed_ast10x0.c
> +++ b/hw/arm/aspeed_ast10x0.c
> @@ -107,19 +107,14 @@ static qemu_irq aspeed_soc_ast1030_get_irq(AspeedSoCState *s, int dev)
>       return qdev_get_gpio_in(DEVICE(&a->armv7m), sc->irqmap[dev]);
>   }
>   
> -static void aspeed_soc_ast10x0_init(Object *obj)
> +static void aspeed_soc_ast10x0_init(Object *obj, const char *socname)
>   {
>       Aspeed10x0SoCState *a = ASPEED10X0_SOC(obj);
>       AspeedSoCState *s = ASPEED_SOC(obj);
>       AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s);
> -    char socname[8];
>       char typename[64];
>       int i;
>   
> -    if (sscanf(object_get_typename(obj), "%7s", socname) != 1) {
> -        g_assert_not_reached();
> -    }
> -
>       object_initialize_child(obj, "armv7m", &a->armv7m, TYPE_ARMV7M);
>   
>       s->sysclk = qdev_init_clock_in(DEVICE(s), "sysclk", NULL, NULL, 0);
> @@ -184,8 +179,13 @@ static void aspeed_soc_ast10x0_init(Object *obj)
>   static void aspeed_soc_ast1030_init(Object *obj)
>   {
>       AspeedSoCState *s = ASPEED_SOC(obj);
> +    char socname[8];
> +
> +    if (sscanf(object_get_typename(obj), "%7s", socname) != 1) {
> +        g_assert_not_reached();
> +    }
>   
> -    aspeed_soc_ast10x0_init(obj);
> +    aspeed_soc_ast10x0_init(obj, socname);


As Philippe suggested, why not use directly :

        aspeed_soc_ast10x0_init(obj, "ast1030");


Thanks,

C.



>       object_initialize_child(obj, "lpc", &s->lpc, TYPE_ASPEED_LPC);
>       object_initialize_child(obj, "peci", &s->peci, TYPE_ASPEED_PECI);
>   }
RE: [PATCH v1 07/12] hw/arm/aspeed_ast10x0: Pass SoC name to common init for AST10x0 family reuse
Posted by Jamin Lin 2 days, 14 hours ago
Hi Cédric

> Subject: Re: [PATCH v1 07/12] hw/arm/aspeed_ast10x0: Pass SoC name to
> common init for AST10x0 family reuse
> 
> On 11/6/25 09:49, Jamin Lin wrote:
> > Refactor the AST10x0 common initialization to accept a socname
> > parameter.
> >
> > The AST1030 model can be reused by AST1060 since they share most of
> > the same controllers. This approach allows AST1060 to leverage the
> > existing
> > AST1030 initialization flow while keeping separate SoC-specific init
> > functions for components that differ.
> >
> > This prepares the framework for AST1060 support, allowing it to reuse
> > AST1030 device models and initialization flow without code duplication.
> >
> > No functional changes.
> >
> > Signed-off-by: Jamin Lin <jamin_lin@aspeedtech.com>
> > ---
> >   hw/arm/aspeed_ast10x0.c | 14 +++++++-------
> >   1 file changed, 7 insertions(+), 7 deletions(-)
> >
> > diff --git a/hw/arm/aspeed_ast10x0.c b/hw/arm/aspeed_ast10x0.c index
> > 5bbe16af24..c85c21b149 100644
> > --- a/hw/arm/aspeed_ast10x0.c
> > +++ b/hw/arm/aspeed_ast10x0.c
> > @@ -107,19 +107,14 @@ static qemu_irq
> aspeed_soc_ast1030_get_irq(AspeedSoCState *s, int dev)
> >       return qdev_get_gpio_in(DEVICE(&a->armv7m), sc->irqmap[dev]);
> >   }
> >
> > -static void aspeed_soc_ast10x0_init(Object *obj)
> > +static void aspeed_soc_ast10x0_init(Object *obj, const char *socname)
> >   {
> >       Aspeed10x0SoCState *a = ASPEED10X0_SOC(obj);
> >       AspeedSoCState *s = ASPEED_SOC(obj);
> >       AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s);
> > -    char socname[8];
> >       char typename[64];
> >       int i;
> >
> > -    if (sscanf(object_get_typename(obj), "%7s", socname) != 1) {
> > -        g_assert_not_reached();
> > -    }
> > -
> >       object_initialize_child(obj, "armv7m", &a->armv7m,
> TYPE_ARMV7M);
> >
> >       s->sysclk = qdev_init_clock_in(DEVICE(s), "sysclk", NULL, NULL,
> > 0); @@ -184,8 +179,13 @@ static void aspeed_soc_ast10x0_init(Object
> *obj)
> >   static void aspeed_soc_ast1030_init(Object *obj)
> >   {
> >       AspeedSoCState *s = ASPEED_SOC(obj);
> > +    char socname[8];
> > +
> > +    if (sscanf(object_get_typename(obj), "%7s", socname) != 1) {
> > +        g_assert_not_reached();
> > +    }
> >
> > -    aspeed_soc_ast10x0_init(obj);
> > +    aspeed_soc_ast10x0_init(obj, socname);
> 
> 
> As Philippe suggested, why not use directly :
> 
>         aspeed_soc_ast10x0_init(obj, "ast1030");
> 
Thanks for the review and suggestion.
Will update it.

Thanks-Jamin
> 
> Thanks,
> 
> C.
> 
> 
> 
> >       object_initialize_child(obj, "lpc", &s->lpc, TYPE_ASPEED_LPC);
> >       object_initialize_child(obj, "peci", &s->peci, TYPE_ASPEED_PECI);
> >   }