@samitouri / QOSamiQemu / commits / de0a0d2036

hw/arm/aspeed: Convert SRAM MemoryRegion to array type

Several kinds of RAM are supported across Aspeed SoCs, including SRAM, SDRAM, HyperRAM, secure SRAM, and generic SRAM. In addition, different SoCs may expose multiple SRAM regions at different MMIO addresses. The current implementation models SRAM with a single MemoryRegion instance, which makes future expansion cumbersome when additional SRAM types or regions are introduced. Prepare for future SoC designs by converting the SRAM MemoryRegion from a single object into an array-based structure. This change introduces ASPEED_SRAM_NUM and converts existing SRAM users to reference sram[0]. No functional change. Signed-off-by: Jamin Lin <jamin_lin@aspeedtech.com> Reviewed-by: Cédric Le Goater <clg@redhat.com> Link: https://lore.kernel.org/qemu-devel/20260525053036.3305181-2-jamin_lin@aspeedtech.com Signed-off-by: Cédric Le Goater <clg@redhat.com>

Jamin Lin committed May 25, 2026 at 05:30 UTC de0a0d2036d4ce5ef2626b2967f12af6e88e3f39
5 files changed +13 -11
hw/arm/aspeed_ast10x0.c
+3 -2
@@ -240,14 +240,15 @@ static bool aspeed_soc_ast10x0_realize(Aspeed10x0SoCState *a, Error **errp)
240 /* Internal SRAM */
241 sram_name = g_strdup_printf("aspeed.sram.%d",
242 CPU(a->armv7m.cpu)->cpu_index);
243 - memory_region_init_ram(&s->sram, OBJECT(s), sram_name, sc->sram_size, &err);
243 + memory_region_init_ram(&s->sram[0], OBJECT(s), sram_name, sc->sram_size,
244 + &err);
245 if (err != NULL) {
246 error_propagate(errp, err);
247 return false;
248 }
249 memory_region_add_subregion(s->memory,
250 sc->memmap[ASPEED_DEV_SRAM],
250 - &s->sram);
251 + &s->sram[0]);
252 memory_region_init_ram(&s->secsram, OBJECT(s), "sec.sram",
253 sc->secsram_size, &err);
254 if (err != NULL) {
hw/arm/aspeed_ast2400.c
+3 -3
@@ -281,12 +281,12 @@ static void aspeed_ast2400_soc_realize(DeviceState *dev, Error **errp)
281
282 /* SRAM */
283 sram_name = g_strdup_printf("aspeed.sram.%d", CPU(&a->cpu[0])->cpu_index);
284 - if (!memory_region_init_ram(&s->sram, OBJECT(s), sram_name, sc->sram_size,
285 - errp)) {
284 + if (!memory_region_init_ram(&s->sram[0], OBJECT(s), sram_name,
285 + sc->sram_size, errp)) {
286 return;
287 }
288 memory_region_add_subregion(s->memory,
289 - sc->memmap[ASPEED_DEV_SRAM], &s->sram);
289 + sc->memmap[ASPEED_DEV_SRAM], &s->sram[0]);
290
291 /* SCU */
292 if (!sysbus_realize(SYS_BUS_DEVICE(&s->scu), errp)) {
hw/arm/aspeed_ast2600.c
+3 -3
@@ -437,12 +437,12 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)
437
438 /* SRAM */
439 sram_name = g_strdup_printf("aspeed.sram.%d", CPU(&a->cpu[0])->cpu_index);
440 - if (!memory_region_init_ram(&s->sram, OBJECT(s), sram_name, sc->sram_size,
441 - errp)) {
440 + if (!memory_region_init_ram(&s->sram[0], OBJECT(s), sram_name,
441 + sc->sram_size, errp)) {
442 return;
443 }
444 memory_region_add_subregion(s->memory,
445 - sc->memmap[ASPEED_DEV_SRAM], &s->sram);
445 + sc->memmap[ASPEED_DEV_SRAM], &s->sram[0]);
446
447 /* DPMCU */
448 aspeed_mmio_map_unimplemented(s->memory, SYS_BUS_DEVICE(&s->dpmcu),
hw/arm/aspeed_ast27x0.c
+2 -2
@@ -778,12 +778,12 @@ static void aspeed_soc_ast2700_realize(DeviceState *dev, Error **errp)
778
779 /* SRAM */
780 name = g_strdup_printf("aspeed.sram.%d", CPU(&a->cpu[0])->cpu_index);
781 - if (!memory_region_init_ram(&s->sram, OBJECT(s), name, sc->sram_size,
781 + if (!memory_region_init_ram(&s->sram[0], OBJECT(s), name, sc->sram_size,
782 errp)) {
783 return;
784 }
785 memory_region_add_subregion(s->memory,
786 - sc->memmap[ASPEED_DEV_SRAM], &s->sram);
786 + sc->memmap[ASPEED_DEV_SRAM], &s->sram[0]);
787
788 /* VBOOTROM */
789 if (!memory_region_init_ram(&s->vbootrom, OBJECT(s), "aspeed.vbootrom",
include/hw/arm/aspeed_soc.h
+2 -1
@@ -60,6 +60,7 @@
60 #define ASPEED_PCIE_NUM 3
61 #define ASPEED_INTC_NUM 2
62 #define ASPEED_IOEXP_NUM 2
63 +#define ASPEED_SRAM_NUM 1
64
65 struct AspeedSoCState {
66 DeviceState parent;
@@ -67,7 +68,7 @@ struct AspeedSoCState {
68 MemoryRegion *memory;
69 MemoryRegion *dram_mr;
70 MemoryRegion dram_container;
70 - MemoryRegion sram;
71 + MemoryRegion sram[ASPEED_SRAM_NUM];
72 MemoryRegion spi_boot_container;
73 MemoryRegion spi_boot;
74 MemoryRegion vbootrom;