diff mbox series

[v4,8/9] aspeed: Add an AST1030 eval board

Message ID 20220401034651.9066-9-jamin_lin@aspeedtech.com (mailing list archive)
State New, archived
Headers show
Series Add support for AST1030 SoC | expand

Commit Message

Jamin Lin April 1, 2022, 3:46 a.m. UTC
The image should be supplied with ELF binary.
$ qemu-system-arm -M ast1030-evb -kernel zephyr.elf -nographic

Signed-off-by: Troy Lee <troy_lee@aspeedtech.com>
Signed-off-by: Jamin Lin <jamin_lin@aspeedtech.com>
Signed-off-by: Steven Lee <steven_lee@aspeedtech.com>
---
 hw/arm/aspeed.c         | 97 +++++++++++++++++++++++++++++++++++++++++
 include/hw/arm/aspeed.h |  6 +--
 2 files changed, 100 insertions(+), 3 deletions(-)

Comments

Cédric Le Goater April 1, 2022, 6:59 a.m. UTC | #1
On 4/1/22 05:46, Jamin Lin wrote:
> The image should be supplied with ELF binary.
> $ qemu-system-arm -M ast1030-evb -kernel zephyr.elf -nographic
> 
> Signed-off-by: Troy Lee <troy_lee@aspeedtech.com>
> Signed-off-by: Jamin Lin <jamin_lin@aspeedtech.com>
> Signed-off-by: Steven Lee <steven_lee@aspeedtech.com>
> ---
>   hw/arm/aspeed.c         | 97 +++++++++++++++++++++++++++++++++++++++++
>   include/hw/arm/aspeed.h |  6 +--
>   2 files changed, 100 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c
> index d205384d98..30b49d2db1 100644
> --- a/hw/arm/aspeed.c
> +++ b/hw/arm/aspeed.c
> @@ -24,6 +24,7 @@
>   #include "hw/loader.h"
>   #include "qemu/error-report.h"
>   #include "qemu/units.h"
> +#include "hw/qdev-clock.h"
>   
>   static struct arm_boot_info aspeed_board_binfo = {
>       .board_id = -1, /* device-tree-only board */
> @@ -1361,3 +1362,99 @@ static const TypeInfo aspeed_machine_types[] = {
>   };
>   
>   DEFINE_TYPES(aspeed_machine_types)
> +
> +#define AST1030_INTERNAL_FLASH_SIZE (1024 * 1024)
> +/* Main SYSCLK frequency in Hz (200MHz) */
> +#define SYSCLK_FRQ 200000000ULL
> +
> +static void aspeed_minibmc_machine_ast1030_evb_class_init(ObjectClass *oc,
> +                                                          void *data)
> +{
> +    MachineClass *mc = MACHINE_CLASS(oc);
> +    AspeedMachineClass *amc = ASPEED_MINIBMC_MACHINE_CLASS(oc);

I don't think we need a ASPEED_MINIBMC type (yet)

> +
> +    mc->desc = "Aspeed AST1030 MiniBMC (Cortex-M4)";
> +    amc->soc_name = "ast1030-a1";
> +    amc->hw_strap1 = 0;
> +    amc->hw_strap2 = 0;
> +    mc->default_ram_size = 0;
> +    mc->default_cpus = mc->min_cpus = mc->max_cpus = 1;
> +    amc->fmc_model = "sst25vf032b";
> +    amc->spi_model = "sst25vf032b";
> +    amc->num_cs = 2;

In this routine, you could add :

  amc->macs_mask = 0;

Since the NICs are not modeled yet.

> +}
> +
> +static void ast1030_machine_instance_init(Object *obj)
> +{
> +    ASPEED_MINIBMC_MACHINE(obj)->mmio_exec = false;
> +}

ast1030_machine_instance_init() is not that useful either.

> +
> +static void aspeed_minibmc_machine_init(MachineState *machine)
> +{
> +    AspeedMachineState *bmc = ASPEED_MINIBMC_MACHINE(machine);
> +    AspeedMachineClass *amc = ASPEED_MINIBMC_MACHINE_GET_CLASS(machine);
> +    Clock *sysclk;
> +
> +    sysclk = clock_new(OBJECT(machine), "SYSCLK");
> +    clock_set_hz(sysclk, SYSCLK_FRQ);
> +
> +    object_initialize_child(OBJECT(machine), "soc", &bmc->soc, amc->soc_name);
> +    qdev_connect_clock_in(DEVICE(&bmc->soc), "sysclk", sysclk);
> +
> +    qdev_prop_set_uint32(DEVICE(&bmc->soc), "uart-default",
> +                         amc->uart_default);
> +    qdev_realize(DEVICE(&bmc->soc), NULL, &error_abort);
> +
> +    aspeed_board_init_flashes(&bmc->soc.fmc,
> +                              bmc->fmc_model ? bmc->fmc_model : amc->fmc_model,
> +                              amc->num_cs,
> +                              0);
> +
> +    aspeed_board_init_flashes(&bmc->soc.spi[0],
> +                              bmc->spi_model ? bmc->spi_model : amc->spi_model,
> +                              amc->num_cs, amc->num_cs);
> +
> +    aspeed_board_init_flashes(&bmc->soc.spi[1],
> +                              bmc->spi_model ? bmc->spi_model : amc->spi_model,
> +                              amc->num_cs, (amc->num_cs * 2));
> +
> +    if (amc->i2c_init) {
> +        amc->i2c_init(bmc);
> +    }
> +
> +    armv7m_load_kernel(ARM_CPU(first_cpu),
> +                       machine->kernel_filename,
> +                       AST1030_INTERNAL_FLASH_SIZE);
> +}
> +
> +static void aspeed_minibmc_machine_class_init(ObjectClass *oc, void *data)
> +{
> +    MachineClass *mc = MACHINE_CLASS(oc);
> +    AspeedMachineClass *amc = ASPEED_MINIBMC_MACHINE_CLASS(oc);
> +
> +    mc->init = aspeed_minibmc_machine_init;
> +    mc->no_floppy = 1;
> +    mc->no_cdrom = 1;
> +    mc->no_parallel = 1;
> +    mc->default_ram_id = "ram";
> +    amc->uart_default = ASPEED_DEV_UART5;

This is very much like aspeed_machine_class_init()


> +}
> +
> +static const TypeInfo aspeed_minibmc_machine_types[] = {
> +    {
> +        .name           = MACHINE_TYPE_NAME("ast1030-evb"),
> +        .parent         = TYPE_ASPEED_MINIBMC_MACHINE,

Why don't you inherit directly from TYPE_ASPEED_MACHINE and simplify
the model by removing the duplicate TYPE_ASPEED_MINIBMC_MACHINE ?

> +        .class_init     = aspeed_minibmc_machine_ast1030_evb_class_init,
> +    }, {
> +        .name           = TYPE_ASPEED_MINIBMC_MACHINE,
> +        .parent         = TYPE_MACHINE,
> +        .instance_size  = sizeof(AspeedMachineState),
> +        .instance_init  = ast1030_machine_instance_init,
> +        .class_size    = sizeof(AspeedMachineClass),
> +        .class_init    = aspeed_minibmc_machine_class_init,
> +        .abstract      = true,
> +    }
> +};
> +
> +DEFINE_TYPES(aspeed_minibmc_machine_types)
> +
> diff --git a/include/hw/arm/aspeed.h b/include/hw/arm/aspeed.h
> index cbeacb214c..b7411c860d 100644
> --- a/include/hw/arm/aspeed.h
> +++ b/include/hw/arm/aspeed.h
> @@ -13,18 +13,19 @@
>   #include "qom/object.h"
>   
>   typedef struct AspeedMachineState AspeedMachineState;
> -
>   #define TYPE_ASPEED_MACHINE       MACHINE_TYPE_NAME("aspeed")
> +#define TYPE_ASPEED_MINIBMC_MACHINE MACHINE_TYPE_NAME("aspeed-minibmc")
>   typedef struct AspeedMachineClass AspeedMachineClass;
>   DECLARE_OBJ_CHECKERS(AspeedMachineState, AspeedMachineClass,
>                        ASPEED_MACHINE, TYPE_ASPEED_MACHINE)
> +DECLARE_OBJ_CHECKERS(AspeedMachineState, AspeedMachineClass,
> +                     ASPEED_MINIBMC_MACHINE, TYPE_ASPEED_MINIBMC_MACHINE)

This looks useless to me.

We might want a new type of Aspeed machines someday but I don't see
the need yet.

Thanks,

C.

>   
>   #define ASPEED_MAC0_ON   (1 << 0)
>   #define ASPEED_MAC1_ON   (1 << 1)
>   #define ASPEED_MAC2_ON   (1 << 2)
>   #define ASPEED_MAC3_ON   (1 << 3)
>   
> -
>   struct AspeedMachineClass {
>       MachineClass parent_obj;
>   
> @@ -41,5 +42,4 @@ struct AspeedMachineClass {
>       uint32_t uart_default;
>   };
>   
> -
>   #endif
Jamin Lin April 1, 2022, 8:45 a.m. UTC | #2
The 04/01/2022 06:59, Cédric Le Goater wrote:
> On 4/1/22 05:46, Jamin Lin wrote:
> > The image should be supplied with ELF binary.
> > $ qemu-system-arm -M ast1030-evb -kernel zephyr.elf -nographic
> > 
> > Signed-off-by: Troy Lee <troy_lee@aspeedtech.com>
> > Signed-off-by: Jamin Lin <jamin_lin@aspeedtech.com>
> > Signed-off-by: Steven Lee <steven_lee@aspeedtech.com>
> > ---
> >   hw/arm/aspeed.c         | 97 +++++++++++++++++++++++++++++++++++++++++
> >   include/hw/arm/aspeed.h |  6 +--
> >   2 files changed, 100 insertions(+), 3 deletions(-)
> > 
> > diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c
> > index d205384d98..30b49d2db1 100644
> > --- a/hw/arm/aspeed.c
> > +++ b/hw/arm/aspeed.c
> > @@ -24,6 +24,7 @@
> >   #include "hw/loader.h"
> >   #include "qemu/error-report.h"
> >   #include "qemu/units.h"
> > +#include "hw/qdev-clock.h"
> >   
> >   static struct arm_boot_info aspeed_board_binfo = {
> >       .board_id = -1, /* device-tree-only board */
> > @@ -1361,3 +1362,99 @@ static const TypeInfo aspeed_machine_types[] = {
> >   };
> >   
> >   DEFINE_TYPES(aspeed_machine_types)
> > +
> > +#define AST1030_INTERNAL_FLASH_SIZE (1024 * 1024)
> > +/* Main SYSCLK frequency in Hz (200MHz) */
> > +#define SYSCLK_FRQ 200000000ULL
> > +
> > +static void aspeed_minibmc_machine_ast1030_evb_class_init(ObjectClass *oc,
> > +                                                          void *data)
> > +{
> > +    MachineClass *mc = MACHINE_CLASS(oc);
> > +    AspeedMachineClass *amc = ASPEED_MINIBMC_MACHINE_CLASS(oc);
> 
> I don't think we need a ASPEED_MINIBMC type (yet)
>
Fixed
> > +
> > +    mc->desc = "Aspeed AST1030 MiniBMC (Cortex-M4)";
> > +    amc->soc_name = "ast1030-a1";
> > +    amc->hw_strap1 = 0;
> > +    amc->hw_strap2 = 0;
> > +    mc->default_ram_size = 0;
> > +    mc->default_cpus = mc->min_cpus = mc->max_cpus = 1;
> > +    amc->fmc_model = "sst25vf032b";
> > +    amc->spi_model = "sst25vf032b";
> > +    amc->num_cs = 2;
> 
> In this routine, you could add :
> 
>   amc->macs_mask = 0;
> 
> Since the NICs are not modeled yet.
> 
Thanks for your review and suggestion. Added in v5 patch.
> > +}
> > +
> > +static void ast1030_machine_instance_init(Object *obj)
> > +{
> > +    ASPEED_MINIBMC_MACHINE(obj)->mmio_exec = false;
> > +}
> 
> ast1030_machine_instance_init() is not that useful either.
> 
Fixed
> > +
> > +static void aspeed_minibmc_machine_init(MachineState *machine)
> > +{
> > +    AspeedMachineState *bmc = ASPEED_MINIBMC_MACHINE(machine);
> > +    AspeedMachineClass *amc = ASPEED_MINIBMC_MACHINE_GET_CLASS(machine);
> > +    Clock *sysclk;
> > +
> > +    sysclk = clock_new(OBJECT(machine), "SYSCLK");
> > +    clock_set_hz(sysclk, SYSCLK_FRQ);
> > +
> > +    object_initialize_child(OBJECT(machine), "soc", &bmc->soc, amc->soc_name);
> > +    qdev_connect_clock_in(DEVICE(&bmc->soc), "sysclk", sysclk);
> > +
> > +    qdev_prop_set_uint32(DEVICE(&bmc->soc), "uart-default",
> > +                         amc->uart_default);
> > +    qdev_realize(DEVICE(&bmc->soc), NULL, &error_abort);
> > +
> > +    aspeed_board_init_flashes(&bmc->soc.fmc,
> > +                              bmc->fmc_model ? bmc->fmc_model : amc->fmc_model,
> > +                              amc->num_cs,
> > +                              0);
> > +
> > +    aspeed_board_init_flashes(&bmc->soc.spi[0],
> > +                              bmc->spi_model ? bmc->spi_model : amc->spi_model,
> > +                              amc->num_cs, amc->num_cs);
> > +
> > +    aspeed_board_init_flashes(&bmc->soc.spi[1],
> > +                              bmc->spi_model ? bmc->spi_model : amc->spi_model,
> > +                              amc->num_cs, (amc->num_cs * 2));
> > +
> > +    if (amc->i2c_init) {
> > +        amc->i2c_init(bmc);
> > +    }
> > +
> > +    armv7m_load_kernel(ARM_CPU(first_cpu),
> > +                       machine->kernel_filename,
> > +                       AST1030_INTERNAL_FLASH_SIZE);
> > +}
> > +
> > +static void aspeed_minibmc_machine_class_init(ObjectClass *oc, void *data)
> > +{
> > +    MachineClass *mc = MACHINE_CLASS(oc);
> > +    AspeedMachineClass *amc = ASPEED_MINIBMC_MACHINE_CLASS(oc);
> > +
> > +    mc->init = aspeed_minibmc_machine_init;
> > +    mc->no_floppy = 1;
> > +    mc->no_cdrom = 1;
> > +    mc->no_parallel = 1;
> > +    mc->default_ram_id = "ram";
> > +    amc->uart_default = ASPEED_DEV_UART5;
> 
> This is very much like aspeed_machine_class_init()
> 
> 
> > +}
> > +
> > +static const TypeInfo aspeed_minibmc_machine_types[] = {
> > +    {
> > +        .name           = MACHINE_TYPE_NAME("ast1030-evb"),
> > +        .parent         = TYPE_ASPEED_MINIBMC_MACHINE,
> 
> Why don't you inherit directly from TYPE_ASPEED_MACHINE and simplify
> the model by removing the duplicate TYPE_ASPEED_MINIBMC_MACHINE ?
> 
Fixed and removed TYPE_ASPEED_MINIBMC_MACHINE in v5 patch.
> > +        .class_init     = aspeed_minibmc_machine_ast1030_evb_class_init,
> > +    }, {
> > +        .name           = TYPE_ASPEED_MINIBMC_MACHINE,
> > +        .parent         = TYPE_MACHINE,
> > +        .instance_size  = sizeof(AspeedMachineState),
> > +        .instance_init  = ast1030_machine_instance_init,
> > +        .class_size    = sizeof(AspeedMachineClass),
> > +        .class_init    = aspeed_minibmc_machine_class_init,
> > +        .abstract      = true,
> > +    }
> > +};
> > +
> > +DEFINE_TYPES(aspeed_minibmc_machine_types)
> > +
> > diff --git a/include/hw/arm/aspeed.h b/include/hw/arm/aspeed.h
> > index cbeacb214c..b7411c860d 100644
> > --- a/include/hw/arm/aspeed.h
> > +++ b/include/hw/arm/aspeed.h
> > @@ -13,18 +13,19 @@
> >   #include "qom/object.h"
> >   
> >   typedef struct AspeedMachineState AspeedMachineState;
> > -
> >   #define TYPE_ASPEED_MACHINE       MACHINE_TYPE_NAME("aspeed")
> > +#define TYPE_ASPEED_MINIBMC_MACHINE MACHINE_TYPE_NAME("aspeed-minibmc")
> >   typedef struct AspeedMachineClass AspeedMachineClass;
> >   DECLARE_OBJ_CHECKERS(AspeedMachineState, AspeedMachineClass,
> >                        ASPEED_MACHINE, TYPE_ASPEED_MACHINE)
> > +DECLARE_OBJ_CHECKERS(AspeedMachineState, AspeedMachineClass,
> > +                     ASPEED_MINIBMC_MACHINE, TYPE_ASPEED_MINIBMC_MACHINE)
> 
> This looks useless to me.
> 
> We might want a new type of Aspeed machines someday but I don't see
> the need yet.
> 
> Thanks,
> 
> C.
> 
removed and fixed in v5 patch.
Thanks for your review.
> >   
> >   #define ASPEED_MAC0_ON   (1 << 0)
> >   #define ASPEED_MAC1_ON   (1 << 1)
> >   #define ASPEED_MAC2_ON   (1 << 2)
> >   #define ASPEED_MAC3_ON   (1 << 3)
> >   
> > -
> >   struct AspeedMachineClass {
> >       MachineClass parent_obj;
> >   
> > @@ -41,5 +42,4 @@ struct AspeedMachineClass {
> >       uint32_t uart_default;
> >   };
> >   
> > -
> >   #endif
>
diff mbox series

Patch

diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c
index d205384d98..30b49d2db1 100644
--- a/hw/arm/aspeed.c
+++ b/hw/arm/aspeed.c
@@ -24,6 +24,7 @@ 
 #include "hw/loader.h"
 #include "qemu/error-report.h"
 #include "qemu/units.h"
+#include "hw/qdev-clock.h"
 
 static struct arm_boot_info aspeed_board_binfo = {
     .board_id = -1, /* device-tree-only board */
@@ -1361,3 +1362,99 @@  static const TypeInfo aspeed_machine_types[] = {
 };
 
 DEFINE_TYPES(aspeed_machine_types)
+
+#define AST1030_INTERNAL_FLASH_SIZE (1024 * 1024)
+/* Main SYSCLK frequency in Hz (200MHz) */
+#define SYSCLK_FRQ 200000000ULL
+
+static void aspeed_minibmc_machine_ast1030_evb_class_init(ObjectClass *oc,
+                                                          void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    AspeedMachineClass *amc = ASPEED_MINIBMC_MACHINE_CLASS(oc);
+
+    mc->desc = "Aspeed AST1030 MiniBMC (Cortex-M4)";
+    amc->soc_name = "ast1030-a1";
+    amc->hw_strap1 = 0;
+    amc->hw_strap2 = 0;
+    mc->default_ram_size = 0;
+    mc->default_cpus = mc->min_cpus = mc->max_cpus = 1;
+    amc->fmc_model = "sst25vf032b";
+    amc->spi_model = "sst25vf032b";
+    amc->num_cs = 2;
+}
+
+static void ast1030_machine_instance_init(Object *obj)
+{
+    ASPEED_MINIBMC_MACHINE(obj)->mmio_exec = false;
+}
+
+static void aspeed_minibmc_machine_init(MachineState *machine)
+{
+    AspeedMachineState *bmc = ASPEED_MINIBMC_MACHINE(machine);
+    AspeedMachineClass *amc = ASPEED_MINIBMC_MACHINE_GET_CLASS(machine);
+    Clock *sysclk;
+
+    sysclk = clock_new(OBJECT(machine), "SYSCLK");
+    clock_set_hz(sysclk, SYSCLK_FRQ);
+
+    object_initialize_child(OBJECT(machine), "soc", &bmc->soc, amc->soc_name);
+    qdev_connect_clock_in(DEVICE(&bmc->soc), "sysclk", sysclk);
+
+    qdev_prop_set_uint32(DEVICE(&bmc->soc), "uart-default",
+                         amc->uart_default);
+    qdev_realize(DEVICE(&bmc->soc), NULL, &error_abort);
+
+    aspeed_board_init_flashes(&bmc->soc.fmc,
+                              bmc->fmc_model ? bmc->fmc_model : amc->fmc_model,
+                              amc->num_cs,
+                              0);
+
+    aspeed_board_init_flashes(&bmc->soc.spi[0],
+                              bmc->spi_model ? bmc->spi_model : amc->spi_model,
+                              amc->num_cs, amc->num_cs);
+
+    aspeed_board_init_flashes(&bmc->soc.spi[1],
+                              bmc->spi_model ? bmc->spi_model : amc->spi_model,
+                              amc->num_cs, (amc->num_cs * 2));
+
+    if (amc->i2c_init) {
+        amc->i2c_init(bmc);
+    }
+
+    armv7m_load_kernel(ARM_CPU(first_cpu),
+                       machine->kernel_filename,
+                       AST1030_INTERNAL_FLASH_SIZE);
+}
+
+static void aspeed_minibmc_machine_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    AspeedMachineClass *amc = ASPEED_MINIBMC_MACHINE_CLASS(oc);
+
+    mc->init = aspeed_minibmc_machine_init;
+    mc->no_floppy = 1;
+    mc->no_cdrom = 1;
+    mc->no_parallel = 1;
+    mc->default_ram_id = "ram";
+    amc->uart_default = ASPEED_DEV_UART5;
+}
+
+static const TypeInfo aspeed_minibmc_machine_types[] = {
+    {
+        .name           = MACHINE_TYPE_NAME("ast1030-evb"),
+        .parent         = TYPE_ASPEED_MINIBMC_MACHINE,
+        .class_init     = aspeed_minibmc_machine_ast1030_evb_class_init,
+    }, {
+        .name           = TYPE_ASPEED_MINIBMC_MACHINE,
+        .parent         = TYPE_MACHINE,
+        .instance_size  = sizeof(AspeedMachineState),
+        .instance_init  = ast1030_machine_instance_init,
+        .class_size    = sizeof(AspeedMachineClass),
+        .class_init    = aspeed_minibmc_machine_class_init,
+        .abstract      = true,
+    }
+};
+
+DEFINE_TYPES(aspeed_minibmc_machine_types)
+
diff --git a/include/hw/arm/aspeed.h b/include/hw/arm/aspeed.h
index cbeacb214c..b7411c860d 100644
--- a/include/hw/arm/aspeed.h
+++ b/include/hw/arm/aspeed.h
@@ -13,18 +13,19 @@ 
 #include "qom/object.h"
 
 typedef struct AspeedMachineState AspeedMachineState;
-
 #define TYPE_ASPEED_MACHINE       MACHINE_TYPE_NAME("aspeed")
+#define TYPE_ASPEED_MINIBMC_MACHINE MACHINE_TYPE_NAME("aspeed-minibmc")
 typedef struct AspeedMachineClass AspeedMachineClass;
 DECLARE_OBJ_CHECKERS(AspeedMachineState, AspeedMachineClass,
                      ASPEED_MACHINE, TYPE_ASPEED_MACHINE)
+DECLARE_OBJ_CHECKERS(AspeedMachineState, AspeedMachineClass,
+                     ASPEED_MINIBMC_MACHINE, TYPE_ASPEED_MINIBMC_MACHINE)
 
 #define ASPEED_MAC0_ON   (1 << 0)
 #define ASPEED_MAC1_ON   (1 << 1)
 #define ASPEED_MAC2_ON   (1 << 2)
 #define ASPEED_MAC3_ON   (1 << 3)
 
-
 struct AspeedMachineClass {
     MachineClass parent_obj;
 
@@ -41,5 +42,4 @@  struct AspeedMachineClass {
     uint32_t uart_default;
 };
 
-
 #endif