hw/arm/aspeed: Use a table for unimplemented devices
v2 cover hw/arm/aspeed: Use a table for unimplemented devices
v1:
1. Use unimp array and table for unimplemented devices
2. Sort device IDs alphabetically
v2:
1. Add a common create_unimplemented_devices() helper and UnimplementedDeviceConfig in hw/misc/unimp, as suggested by Philippe.
2. Define the unimplemented device table at the SoC class level
3. Drop the "unimp" array and the AspeedUnimpDevice table.
4. Remove aspeed_mmio_map_unimplemented(), which is not used anymore.
Jamin Lin (12):
hw/misc/unimp: Add create_unimplemented_devices() helper hw/arm/aspeed_ast2400: Use a table for unimplemented devices hw/arm/aspeed_ast2600: Use a table for unimplemented devices hw/arm/aspeed_ast27x0: Use a table for unimplemented devices hw/arm/aspeed_ast10x0: Use a table for unimplemented devices hw/arm/aspeed_ast1040: Use a table for unimplemented devices hw/arm/aspeed: Remove unused unimplemented device fields hw/arm/aspeed_ast27x0: Use a table for unimplemented devices for
SSP/TSP
hw/arm/aspeed_coprocessor: Remove unused unimplemented device fields hw/arm/aspeed_ast1700: Use a table for unimplemented devices hw/arm/aspeed_ast1700: Remove unused unimplemented device field hw/arm/aspeed: Remove unused aspeed_mmio_map_unimplemented()
include/hw/arm/aspeed_ast1700.h | 2 -- include/hw/arm/aspeed_coprocessor.h | 5 +-- include/hw/arm/aspeed_soc.h | 14 +------- include/hw/misc/unimp.h | 21 +++++++++++ hw/arm/aspeed_ast1040.c | 40 +++++++-------------- hw/arm/aspeed_ast10x0.c | 55 ++++++++--------------------- hw/arm/aspeed_ast1700.c | 21 +++++------ hw/arm/aspeed_ast2400.c | 25 ++++++------- hw/arm/aspeed_ast2600.c | 44 +++++++---------------- hw/arm/aspeed_ast27x0-ssp.c | 44 +++++++---------------- hw/arm/aspeed_ast27x0-tsp.c | 44 +++++++---------------- hw/arm/aspeed_ast27x0.c | 41 +++++++-------------- hw/arm/aspeed_soc_common.c | 11 ------ hw/misc/unimp.c | 20 +++++++++++ 14 files changed, 138 insertions(+), 249 deletions(-)
Signature · 1 line
2.53.0
PATCH v2 1/12 hw/misc/unimp: Add create_unimplemented_devices() helper
Several boards and SoCs create many unimplemented devices. Each of them uses its own structure and helper to describe and map these devices.
Add an UnimplementedDeviceConfig structure and a create_unimplemented_devices() helper. The helper creates an unimplemented device for each entry of a table, adds it as a QOM child of the parent object, and maps it in a memory region container with the given priority. The table is terminated by an empty entry.
--- include/hw/misc/unimp.h | 21 +++++++++++++++++++++ hw/misc/unimp.c | 20 ++++++++++++++++++++ 2 files changed, 41 insertions(+)
include/hw/misc/unimp.h +21 -0
@@ -25,6 +25,27 @@ struct UnimplementedDeviceState {uint64_t size; }; +typedef struct UnimplementedDeviceConfig { +const char *qom_name; +const char *region_name; +uint64_t offset; +uint64_t size; +int priority; +}UnimplementedDeviceConfig ; + +/** +* create_unimplemented_devices: +* @parentobj: the parent object +* @container: a #MemoryRegion within which @addr is a relative address +* @devconfigs: NULL terminated array of #UnimplementedDeviceConfig +* +* For each entries in @devconfigs, create a TYPE_UNIMPLEMENTED_DEVICE +* and mmap it in @container at UnimplementedDeviceConfig::offset. +* @container is expected to be a QOM child of @parentobj. +*/ +void create_unimplemented_devices (Object *parentobj,MemoryRegion *container, +const UnimplementedDeviceConfig *devconfigs); +/** * create_unimplemented_device: create and map a dummy device * @name: name of the device for debug logging
hw/misc/unimp.c +20 -0
@@ -96,3 +96,23 @@ static void unimp_register_types(void) }type_init (unimp_register_types) + +void create_unimplemented_devices(Object *parentobj, MemoryRegion *container, +const UnimplementedDeviceConfig *devconfigs) +{ +const UnimplementedDeviceConfig *cfg; + +for (cfg = devconfigs; cfg->qom_name; cfg++) { +DeviceState *dev =qdev_new (TYPE_UNIMPLEMENTED_DEVICE ); +SysBusDevice *sbd =SYS_BUS_DEVICE (dev); + +object_property_add_child (parentobj, cfg->qom_name,OBJECT (dev)); +qdev_prop_set_string (dev,"name" , cfg->region_name); +qdev_prop_set_uint64 (dev,"size" , cfg->size); +sysbus_realize_and_unref (sbd, &error_fatal); + +memory_region_add_subregion_overlap (container, cfg->offset, +sysbus_mmio_get_region (sbd,0 ), + cfg->priority); + } +}
Signature · 1 line
2.53.0
PATCH v2 6/12 hw/arm/aspeed_ast1040: Use a table for unimplemented devices
In reply to Jamin LinBefore this change, each unimplemented device needed its own field in AspeedSoCState. This made the variable names confusing. For example, AspeedSoCState has "udc" as an unimplemented device, but Aspeed2600SoCState also has "udc" as the real UDC model.
Use the unimp_devs table in AspeedSoCClass to describe the unimplemented devices, and use create_unimplemented_devices() to create and map them. This makes the code easier to maintain and read. Convert AST1040 to use them.
This also fixes a type mismatch. AST1040 used the "pwm" field (AspeedPWMState) to create an unimplemented device. It is not used for that anymore.
No functional change.
--- hw/arm/aspeed_ast1040.c | 40 ++++++++++++---------------------------- 1 file changed, 12 insertions(+), 28 deletions(-)
hw/arm/aspeed_ast1040.c +12 -28
@@ -81,6 +81,15 @@ static const int aspeed_soc_ast1040_irqmap[] = { [ASPEED_DEV_PECI] = 164, }; +static const UnimplementedDeviceConfig aspeed_soc_ast1040_unimp_devs[] = { + {"pwm" ,"aspeed.pwm" ,0x740C0000 ,0x10000 ,-1000 }, + {"espi" ,"aspeed.espi" ,0x74C05000 ,0x1000 ,-1000 }, + {"udc" ,"aspeed.udc" ,0x74120000 ,0x4000 ,-1000 }, + {"jtag[0]" ,"aspeed.jtag0" ,0x74C01000 ,0x100 ,-1000 }, + {"jtag[1]" ,"aspeed.jtag1" ,0x74C09000 ,0x100 ,-1000 }, + { } +}; +static qemu_irq aspeed_soc_ast1040_get_irq (AspeedSoCState *s,int dev) {Aspeed10x0SoCState *a =ASPEED10X0_SOC (s);
@@ -123,14 +132,6 @@ static void aspeed_soc_ast1040_init(Object *obj)object_initialize_child (obj,"wdt[*]" , &s->wdt[i],"aspeed.wdt-ast2700" ); } - -object_initialize_child (obj,"pwm" , &s->pwm,TYPE_UNIMPLEMENTED_DEVICE ); -object_initialize_child (obj,"espi" , &s->espi,TYPE_UNIMPLEMENTED_DEVICE ); -object_initialize_child (obj,"udc" , &s->udc,TYPE_UNIMPLEMENTED_DEVICE ); -object_initialize_child (obj,"jtag[0]" , &s->jtag[0 ], -TYPE_UNIMPLEMENTED_DEVICE ); -object_initialize_child (obj,"jtag[1]" , &s->jtag[1 ], -TYPE_UNIMPLEMENTED_DEVICE ); }static void aspeed_soc_ast1040_realize (DeviceState *dev_soc,Error **errp)
@@ -267,26 +268,8 @@ static void aspeed_soc_ast1040_realize(DeviceState *dev_soc, Error **errp)aspeed_mmio_map (s->memory,SYS_BUS_DEVICE (&s->wdt[i]),0 , wdt_offset); } -/* Unimplemented peripherals */ -aspeed_mmio_map_unimplemented (s->memory,SYS_BUS_DEVICE (&s->pwm), -"aspeed.pwm" , - sc->memmap[ASPEED_DEV_PWM ],0x10000 ); - -aspeed_mmio_map_unimplemented (s->memory,SYS_BUS_DEVICE (&s->espi), -"aspeed.espi" , - sc->memmap[ASPEED_DEV_ESPI ],0x1000 ); - -aspeed_mmio_map_unimplemented (s->memory,SYS_BUS_DEVICE (&s->udc), -"aspeed.udc" , - sc->memmap[ASPEED_DEV_UDC ],0x4000 ); - -aspeed_mmio_map_unimplemented (s->memory,SYS_BUS_DEVICE (&s->jtag[0 ]), -"aspeed.jtag0" , - sc->memmap[ASPEED_DEV_JTAG0 ],0x100 ); - -aspeed_mmio_map_unimplemented (s->memory,SYS_BUS_DEVICE (&s->jtag[1 ]), -"aspeed.jtag1" , - sc->memmap[ASPEED_DEV_JTAG1 ],0x100 ); +/* Unimplemented devices */ +create_unimplemented_devices (OBJECT (s), s->memory, sc->unimp_devs); }static void aspeed_soc_ast1040_class_init (ObjectClass *klass,const void *data)
@@ -312,6 +295,7 @@ static void aspeed_soc_ast1040_class_init(ObjectClass *klass, const void *data) sc->uarts_base =ASPEED_DEV_UART0 ; sc->irqmap = aspeed_soc_ast1040_irqmap; sc->memmap = aspeed_soc_ast1040_memmap; + sc->unimp_devs = aspeed_soc_ast1040_unimp_devs; sc->num_cpus =1 ; }
Signature · 1 line
2.53.0
PATCH v2 8/12 hw/arm/aspeed_ast27x0: Use a table for unimplemented devices for SSP/TSP
In reply to Jamin LinBefore this change, each unimplemented device needed its own field in the coprocessor state. This made the code hard to maintain.
Add an unimp_devs table in AspeedCoprocessorClass to describe the unimplemented devices, and use create_unimplemented_devices() to create and map them. This makes the code easier to maintain and read. Convert AST2700 SSP and TSP to use them.
This also fixes a type mismatch. SSP and TSP used the "timerctrl" field (AspeedTimerCtrlState) to create an unimplemented device. It is not used for that anymore.
No functional change.
--- include/hw/arm/aspeed_coprocessor.h | 1 + hw/arm/aspeed_ast27x0-ssp.c | 44 +++++++++-------------------- hw/arm/aspeed_ast27x0-tsp.c | 44 +++++++++-------------------- 3 files changed, 27 insertions(+), 62 deletions(-)
include/hw/arm/aspeed_coprocessor.h +1 -0
@@ -37,6 +37,7 @@ struct AspeedCoprocessorClass {/** valid_cpu_types: NULL terminated array of a single CPU type. */ const char *const *valid_cpu_types;const hwaddr *memmap; +const UnimplementedDeviceConfig *unimp_devs;const int *irqmap; };
hw/arm/aspeed_ast27x0-ssp.c +13 -31
68 lines not on this page · raw message
hw/arm/aspeed_ast27x0-tsp.c +13 -31
68 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v2 5/12 hw/arm/aspeed_ast10x0: Use a table for unimplemented devices
In reply to Jamin LinBefore this change, each unimplemented device needed its own field in AspeedSoCState. This made the variable names confusing. For example, AspeedSoCState has "udc" as an unimplemented device, but Aspeed2600SoCState also has "udc" as the real UDC model.
Use the unimp_devs table in AspeedSoCClass to describe the unimplemented devices, and use create_unimplemented_devices() to create and map them. This makes the code easier to maintain and read. Convert AST1030/AST1060 to use them.
This also fixes a type mismatch. AST10x0 used the "pwm" field (AspeedPWMState) and the "sgpiom" field (AspeedSGPIOState array) to create unimplemented devices. They are not used for that anymore.
No functional change.
--- hw/arm/aspeed_ast10x0.c | 55 +++++++++++------------------------------ 1 file changed, 15 insertions(+), 40 deletions(-)
hw/arm/aspeed_ast10x0.c +15 -40
@@ -17,8 +17,6 @@#include "hw/misc/unimp.h" #include "hw/arm/aspeed_soc.h" -#define ASPEED_SOC_IOMEM_SIZE 0x00200000 -static const hwaddr aspeed_soc_ast1030_memmap[] = { [ASPEED_DEV_SRAM0 ] =0x00000000 , [ASPEED_DEV_SRAM1 ] =0x79000000 ,/* SEC SRAM */
@@ -99,6 +97,17 @@ static const int aspeed_soc_ast1030_irqmap[] = { [ASPEED_DEV_JTAG1] = 53, }; +static const UnimplementedDeviceConfig aspeed_soc_ast10x0_unimp_devs[] = { + {"iomem" ,"aspeed.io" ,0x7E600000 ,0x00200000 ,-1000 }, + {"pwm" ,"aspeed.pwm" ,0x7E610000 ,0x100 ,-1000 }, + {"espi" ,"aspeed.espi" ,0x7E6EE000 ,0x800 ,-1000 }, + {"udc" ,"aspeed.udc" ,0x7E6A2000 ,0x1000 ,-1000 }, + {"sgpiom" ,"aspeed.sgpiom" ,0x7E780500 ,0x100 ,-1000 }, + {"jtag[0]" ,"aspeed.jtag0" ,0x7E6E4000 ,0x20 ,-1000 }, + {"jtag[1]" ,"aspeed.jtag1" ,0x7E6E4100 ,0x20 ,-1000 }, + { } +}; +static qemu_irq aspeed_soc_ast1030_get_irq (AspeedSoCState *s,int dev) {Aspeed10x0SoCState *a =ASPEED10X0_SOC (s);
@@ -161,17 +170,6 @@ static void aspeed_soc_ast10x0_init(Object *obj, const char *socname)snprintf (typename,sizeof (typename),"aspeed.hace-%s" , socname);object_initialize_child (obj,"hace" , &s->hace, typename); - -object_initialize_child (obj,"iomem" , &s->iomem,TYPE_UNIMPLEMENTED_DEVICE ); -object_initialize_child (obj,"pwm" , &s->pwm,TYPE_UNIMPLEMENTED_DEVICE ); -object_initialize_child (obj,"espi" , &s->espi,TYPE_UNIMPLEMENTED_DEVICE ); -object_initialize_child (obj,"udc" , &s->udc,TYPE_UNIMPLEMENTED_DEVICE ); -object_initialize_child (obj,"sgpiom" , &s->sgpiom, -TYPE_UNIMPLEMENTED_DEVICE ); -object_initialize_child (obj,"jtag[0]" , &s->jtag[0 ], -TYPE_UNIMPLEMENTED_DEVICE ); -object_initialize_child (obj,"jtag[1]" , &s->jtag[1 ], -TYPE_UNIMPLEMENTED_DEVICE ); }static void aspeed_soc_ast1030_init (Object *obj)
@@ -215,11 +213,8 @@ static bool aspeed_soc_ast10x0_realize(Aspeed10x0SoCState *a, Error **errp)return false; } -/* General I/O memory space to catch all unimplemented device */ -aspeed_mmio_map_unimplemented (s->memory,SYS_BUS_DEVICE (&s->iomem), -"aspeed.io" , - sc->memmap[ASPEED_DEV_IOMEM ], -ASPEED_SOC_IOMEM_SIZE ); +/* Unimplemented devices */ +create_unimplemented_devices (OBJECT (s), s->memory, sc->unimp_devs);/* AST10x0 CPU Core */ armv7m =DEVICE (&a->armv7m);qdev_prop_set_uint32 (armv7m,"num-irq" ,256 );
@@ -394,28 +389,6 @@ static bool aspeed_soc_ast10x0_realize(Aspeed10x0SoCState *a, Error **errp)sysbus_connect_irq (SYS_BUS_DEVICE (&s->gpio),0 ,aspeed_soc_ast1030_get_irq (s,ASPEED_DEV_GPIO )); -aspeed_mmio_map_unimplemented (s->memory,SYS_BUS_DEVICE (&s->pwm), -"aspeed.pwm" , - sc->memmap[ASPEED_DEV_PWM ],0x100 ); - -aspeed_mmio_map_unimplemented (s->memory,SYS_BUS_DEVICE (&s->espi), -"aspeed.espi" , - sc->memmap[ASPEED_DEV_ESPI ],0x800 ); - -aspeed_mmio_map_unimplemented (s->memory,SYS_BUS_DEVICE (&s->udc), -"aspeed.udc" , - sc->memmap[ASPEED_DEV_UDC ],0x1000 ); -aspeed_mmio_map_unimplemented (s->memory,SYS_BUS_DEVICE (&s->sgpiom), -"aspeed.sgpiom" , - sc->memmap[ASPEED_DEV_SGPIOM0 ],0x100 ); - -aspeed_mmio_map_unimplemented (s->memory,SYS_BUS_DEVICE (&s->jtag[0 ]), -"aspeed.jtag" , - sc->memmap[ASPEED_DEV_JTAG0 ],0x20 ); -aspeed_mmio_map_unimplemented (s->memory,SYS_BUS_DEVICE (&s->jtag[1 ]), -"aspeed.jtag" , - sc->memmap[ASPEED_DEV_JTAG1 ],0x20 ); -return true; }
@@ -503,6 +476,7 @@ static void aspeed_soc_ast1030_class_init(ObjectClass *klass, const void *data) sc->uarts_base =ASPEED_DEV_UART1 ; sc->irqmap = aspeed_soc_ast1030_irqmap; sc->memmap = aspeed_soc_ast1030_memmap; + sc->unimp_devs = aspeed_soc_ast10x0_unimp_devs; sc->num_cpus =1 ; }
@@ -529,6 +503,7 @@ static void aspeed_soc_ast1060_class_init(ObjectClass *klass, const void *data) sc->uarts_base =ASPEED_DEV_UART5 ; sc->irqmap = aspeed_soc_ast1030_irqmap; sc->memmap = aspeed_soc_ast1030_memmap; + sc->unimp_devs = aspeed_soc_ast10x0_unimp_devs; sc->num_cpus =1 ; }
Signature · 1 line
2.53.0
PATCH v2 4/12 hw/arm/aspeed_ast27x0: Use a table for unimplemented devices
In reply to Jamin LinBefore this change, each unimplemented device needed its own field in AspeedSoCState. This made the variable names confusing. For example, AspeedSoCState has "udc" as an unimplemented device, but Aspeed2600SoCState also has "udc" as the real UDC model.
Use the unimp_devs table in AspeedSoCClass to describe the unimplemented devices, and use create_unimplemented_devices() to create and map them. This makes the code easier to maintain and read. Convert AST2700 to use them.
No functional change.
--- hw/arm/aspeed_ast27x0.c | 41 ++++++++++++----------------------------- 1 file changed, 12 insertions(+), 29 deletions(-)
hw/arm/aspeed_ast27x0.c +12 -29
@@ -24,10 +24,6 @@#include "qobject/qlist.h" #include "qemu/log.h" -#define AST2700_SOC_IO_SIZE 0x00FE0000 -#define AST2700_SOC_IOMEM_SIZE 0x01000000 -#define AST2700_SOC_DPMCU_SIZE 0x00040000 -static const hwaddr aspeed_soc_ast2700_memmap[] = { [ASPEED_DEV_VBOOTROM ] =0x00000000 , [ASPEED_DEV_IOMEM ] =0x00020000 ,
@@ -263,6 +259,14 @@ static const struct gic_intc_irq_info ast2700_gic_intcmap[] = { {201, 3, 1, ast2700_gic201_intcmap}, }; +static const UnimplementedDeviceConfig aspeed_soc_ast2700_unimp_devs[] = { + {"dpmcu" ,"aspeed.dpmcu" ,0x11000000 ,0x00040000 ,-1000 }, + {"iomem" ,"aspeed.io" ,0x00020000 ,0x00FE0000 ,-1000 }, + {"iomem0" ,"aspeed.iomem0" ,0x12000000 ,0x01000000 ,-1000 }, + {"iomem1" ,"aspeed.iomem1" ,0x14000000 ,0x01000000 ,-1000 }, + { } +}; +static qemu_irq aspeed_soc_ast2700_get_irq (AspeedSoCState *s,int dev) {Aspeed27x0SoCState *a =ASPEED27X0_SOC (s);
@@ -558,15 +562,6 @@ static void aspeed_soc_ast2700_init(Object *obj)qdev_prop_set_uint32 (DEVICE (&s->ioexp[i]),"silicon-rev" , sc->silicon_rev); } - -object_initialize_child (obj,"dpmcu" , &s->dpmcu, -TYPE_UNIMPLEMENTED_DEVICE ); -object_initialize_child (obj,"iomem" , &s->iomem, -TYPE_UNIMPLEMENTED_DEVICE ); -object_initialize_child (obj,"iomem0" , &s->iomem0, -TYPE_UNIMPLEMENTED_DEVICE ); -object_initialize_child (obj,"iomem1" , &s->iomem1, -TYPE_UNIMPLEMENTED_DEVICE ); }/*
@@ -1137,22 +1132,8 @@ static void aspeed_soc_ast2700_realize(DeviceState *dev, Error **errp) } } -aspeed_mmio_map_unimplemented (s->memory,SYS_BUS_DEVICE (&s->dpmcu), -"aspeed.dpmcu" , - sc->memmap[ASPEED_DEV_DPMCU ], -AST2700_SOC_DPMCU_SIZE ); -aspeed_mmio_map_unimplemented (s->memory,SYS_BUS_DEVICE (&s->iomem), -"aspeed.io" , - sc->memmap[ASPEED_DEV_IOMEM ], -AST2700_SOC_IO_SIZE ); -aspeed_mmio_map_unimplemented (s->memory,SYS_BUS_DEVICE (&s->iomem0), -"aspeed.iomem0" , - sc->memmap[ASPEED_DEV_IOMEM0 ], -AST2700_SOC_IOMEM_SIZE ); -aspeed_mmio_map_unimplemented (s->memory,SYS_BUS_DEVICE (&s->iomem1), -"aspeed.iomem1" , - sc->memmap[ASPEED_DEV_IOMEM1 ], -AST2700_SOC_IOMEM_SIZE ); +/* Unimplemented devices */ +create_unimplemented_devices (OBJECT (s), s->memory, sc->unimp_devs); }static void aspeed_soc_ast2700a1_class_init (ObjectClass *oc,const void *data)
@@ -1183,6 +1164,7 @@ static void aspeed_soc_ast2700a1_class_init(ObjectClass *oc, const void *data) sc->uarts_base =ASPEED_DEV_UART0 ; sc->irqmap = aspeed_soc_ast2700a1_irqmap; sc->memmap = aspeed_soc_ast2700_memmap; + sc->unimp_devs = aspeed_soc_ast2700_unimp_devs; }static void aspeed_soc_ast2700a2_class_init (ObjectClass *oc,const void *data)
@@ -1213,6 +1195,7 @@ static void aspeed_soc_ast2700a2_class_init(ObjectClass *oc, const void *data) sc->uarts_base =ASPEED_DEV_UART0 ; sc->irqmap = aspeed_soc_ast2700a1_irqmap; sc->memmap = aspeed_soc_ast2700_memmap; + sc->unimp_devs = aspeed_soc_ast2700_unimp_devs; }static const TypeInfo aspeed_soc_ast27x0_types[] = {
Signature · 1 line
2.53.0
PATCH v2 2/12 hw/arm/aspeed_ast2400: Use a table for unimplemented devices
In reply to Jamin LinBefore this change, each unimplemented device needed its own field in AspeedSoCState. This made the variable names confusing. For example, AspeedSoCState has "udc" as an unimplemented device, but Aspeed2600SoCState also has "udc" as the real UDC model.
Add an unimp_devs table in AspeedSoCClass to describe the unimplemented devices, and use create_unimplemented_devices() to create and map them. This makes the code easier to maintain and read. Convert AST2400/AST2500 to use them.
No functional change.
--- include/hw/arm/aspeed_soc.h | 1 + hw/arm/aspeed_ast2400.c | 25 ++++++++++--------------- 2 files changed, 11 insertions(+), 15 deletions(-)
include/hw/arm/aspeed_soc.h +1 -0
@@ -190,6 +190,7 @@ struct AspeedSoCClass {int ioexp_num;const int *irqmap;const hwaddr *memmap; +const UnimplementedDeviceConfig *unimp_devs;uint32_t num_cpus;bool (*boot_from_emmc)(AspeedSoCState *s); };
hw/arm/aspeed_ast2400.c +10 -15
@@ -23,8 +23,6 @@#include "system/system.h" #include "target/arm/cpu-qom.h" -#define ASPEED_SOC_IOMEM_SIZE 0x00200000 -static const hwaddr aspeed_soc_ast2400_memmap[] = { [ASPEED_DEV_SPI_BOOT ] =0x00000000 , [ASPEED_DEV_IOMEM ] =0x1E600000 ,
@@ -134,6 +132,12 @@ static const int aspeed_soc_ast2400_irqmap[] = {#define aspeed_soc_ast2500_irqmap aspeed_soc_ast2400_irqmap +static const UnimplementedDeviceConfig aspeed_soc_ast2400_unimp_devs[] = { + {"iomem" ,"aspeed.io" ,0x1E600000 ,0x00200000 ,-1000 }, + {"video" ,"aspeed.video" ,0x1E700000 ,0x1000 ,-1000 }, + { } +}; +static qemu_irq aspeed_soc_ast2400_get_irq (AspeedSoCState *s,int dev) {Aspeed2400SoCState *a =ASPEED2400_SOC (s);
@@ -239,9 +243,6 @@ static void aspeed_ast2400_soc_init(Object *obj)snprintf (typename,sizeof (typename),"aspeed.hace-%s" , socname);object_initialize_child (obj,"hace" , &s->hace, typename); - -object_initialize_child (obj,"iomem" , &s->iomem,TYPE_UNIMPLEMENTED_DEVICE ); -object_initialize_child (obj,"video" , &s->video,TYPE_UNIMPLEMENTED_DEVICE ); }static void aspeed_ast2400_soc_realize (DeviceState *dev,Error **errp)
@@ -259,16 +260,8 @@ static void aspeed_ast2400_soc_realize(DeviceState *dev, Error **errp)memory_region_add_subregion (s->memory, sc->memmap[ASPEED_DEV_SPI_BOOT ], &s->spi_boot_container); -/* IO space */ -aspeed_mmio_map_unimplemented (s->memory,SYS_BUS_DEVICE (&s->iomem), -"aspeed.io" , - sc->memmap[ASPEED_DEV_IOMEM ], -ASPEED_SOC_IOMEM_SIZE ); - -/* Video engine stub */ -aspeed_mmio_map_unimplemented (s->memory,SYS_BUS_DEVICE (&s->video), -"aspeed.video" , - sc->memmap[ASPEED_DEV_VIDEO ],0x1000 ); +/* Unimplemented devices */ +create_unimplemented_devices (OBJECT (s), s->memory, sc->unimp_devs);/* CPU */ for (i =0 ; i < sc->num_cpus; i++) {
@@ -542,6 +535,7 @@ static void aspeed_soc_ast2400_class_init(ObjectClass *oc, const void *data) sc->uarts_base =ASPEED_DEV_UART1 ; sc->irqmap = aspeed_soc_ast2400_irqmap; sc->memmap = aspeed_soc_ast2400_memmap; + sc->unimp_devs = aspeed_soc_ast2400_unimp_devs; sc->num_cpus =1 ; }
@@ -569,6 +563,7 @@ static void aspeed_soc_ast2500_class_init(ObjectClass *oc, const void *data) sc->uarts_base =ASPEED_DEV_UART1 ; sc->irqmap = aspeed_soc_ast2500_irqmap; sc->memmap = aspeed_soc_ast2500_memmap; + sc->unimp_devs = aspeed_soc_ast2400_unimp_devs; sc->num_cpus =1 ; }
Signature · 1 line
2.53.0
PATCH v2 3/12 hw/arm/aspeed_ast2600: Use a table for unimplemented devices
In reply to Jamin LinBefore this change, each unimplemented device needed its own field in AspeedSoCState. This made the variable names confusing. For example, AspeedSoCState has "udc" as an unimplemented device, but Aspeed2600SoCState also has "udc" as the real UDC model.
Use the unimp_devs table in AspeedSoCClass to describe the unimplemented devices, and use create_unimplemented_devices() to create and map them. This makes the code easier to maintain and read. Convert AST2600 to use them.
No functional change.
--- hw/arm/aspeed_ast2600.c | 44 +++++++++++------------------------------ 1 file changed, 12 insertions(+), 32 deletions(-)
hw/arm/aspeed_ast2600.c +12 -32
@@ -19,9 +19,6 @@#include "system/system.h" #include "target/arm/cpu-qom.h" -#define ASPEED_SOC_IOMEM_SIZE 0x00200000 -#define ASPEED_SOC_DPMCU_SIZE 0x00040000 -static const hwaddr aspeed_soc_ast2600_memmap[] = { [ASPEED_DEV_SPI_BOOT ] =0x00000000 , [ASPEED_DEV_SRAM0 ] =0x10000000 ,
@@ -149,6 +146,15 @@ static const int aspeed_soc_ast2600_irqmap[] = { [ASPEED_DEV_ACRY] = 160, }; +static const UnimplementedDeviceConfig aspeed_soc_ast2600_unimp_devs[] = { + {"iomem" ,"aspeed.io" ,0x1E600000 ,0x00200000 ,-1000 }, + {"video" ,"aspeed.video" ,0x1E700000 ,0x1000 ,-1000 }, + {"dpmcu" ,"aspeed.dpmcu" ,0x18000000 ,0x00040000 ,-1000 }, + {"emmc-boot-controller" ,"aspeed.emmc-boot-controller" , +0x1E6F5000 ,0x1000 ,-1000 }, + { } +}; +static qemu_irq aspeed_soc_ast2600_get_irq (AspeedSoCState *s,int dev) {Aspeed2600SoCState *a =ASPEED2600_SOC (s);
@@ -282,13 +288,6 @@ static void aspeed_soc_ast2600_init(Object *obj)object_initialize_child (obj,"sbc" , &s->sbc,TYPE_ASPEED_AST2600_SBC ); -object_initialize_child (obj,"iomem" , &s->iomem,TYPE_UNIMPLEMENTED_DEVICE ); -object_initialize_child (obj,"video" , &s->video,TYPE_UNIMPLEMENTED_DEVICE ); -object_initialize_child (obj,"dpmcu" , &s->dpmcu,TYPE_UNIMPLEMENTED_DEVICE ); -object_initialize_child (obj,"emmc-boot-controller" , - &s->emmc_boot_controller, -TYPE_UNIMPLEMENTED_DEVICE ); -for (i =0 ; i <ASPEED_FSI_NUM ; i++) {object_initialize_child (obj,"fsi[*]" , &s->fsi[i],TYPE_ASPEED_APB2OPB ); }
@@ -382,22 +381,8 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)memory_region_add_subregion (s->memory, sc->memmap[ASPEED_DEV_SPI_BOOT ], &s->spi_boot_container); -/* IO space */ -aspeed_mmio_map_unimplemented (s->memory,SYS_BUS_DEVICE (&s->iomem), -"aspeed.io" , - sc->memmap[ASPEED_DEV_IOMEM ], -ASPEED_SOC_IOMEM_SIZE ); - -/* Video engine stub */ -aspeed_mmio_map_unimplemented (s->memory,SYS_BUS_DEVICE (&s->video), -"aspeed.video" , - sc->memmap[ASPEED_DEV_VIDEO ],0x1000 ); - -/* eMMC Boot Controller stub */ -aspeed_mmio_map_unimplemented (s->memory, -SYS_BUS_DEVICE (&s->emmc_boot_controller), -"aspeed.emmc-boot-controller" , - sc->memmap[ASPEED_DEV_EMMC_BC ],0x1000 ); +/* Unimplemented devices */ +create_unimplemented_devices (OBJECT (s), s->memory, sc->unimp_devs);/* CPU */ for (i =0 ; i < sc->num_cpus; i++) {
@@ -469,12 +454,6 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)memory_region_add_subregion (s->memory, sc->memmap[ASPEED_DEV_SRAM1 ], &s->sram_container[1 ]); -/* DPMCU */ -aspeed_mmio_map_unimplemented (s->memory,SYS_BUS_DEVICE (&s->dpmcu), -"aspeed.dpmcu" , - sc->memmap[ASPEED_DEV_DPMCU ], -ASPEED_SOC_DPMCU_SIZE ); -/* SCU */ if (!sysbus_realize (SYS_BUS_DEVICE (&s->scu), errp)) {return ;
@@ -838,6 +817,7 @@ static void aspeed_soc_ast2600_class_init(ObjectClass *oc, const void *data) sc->uarts_base =ASPEED_DEV_UART1 ; sc->irqmap = aspeed_soc_ast2600_irqmap; sc->memmap = aspeed_soc_ast2600_memmap; + sc->unimp_devs = aspeed_soc_ast2600_unimp_devs; sc->num_cpus =2 ; sc->boot_from_emmc = aspeed_soc_ast2600_boot_from_emmc; }
Signature · 1 line
2.53.0
PATCH v2 7/12 hw/arm/aspeed: Remove unused unimplemented device fields
In reply to Jamin LinAll Aspeed SoCs now use the unimp_devs table and create_unimplemented_devices() for their unimplemented devices. Remove the old fields in AspeedSoCState and the ASPEED_JTAG_NUM define, which are not used anymore.
No functional change.
--- include/hw/arm/aspeed_soc.h | 10 ---------- 1 file changed, 10 deletions(-)
include/hw/arm/aspeed_soc.h +0 -10
@@ -59,7 +59,6 @@#define ASPEED_CPUS_NUM 4#define ASPEED_MACS_NUM 4#define ASPEED_UARTS_NUM 13 -#define ASPEED_JTAG_NUM 2#define ASPEED_PCIE_NUM 3#define ASPEED_INTC_NUM 2#define ASPEED_IOEXP_NUM 2
@@ -110,15 +109,6 @@ struct AspeedSoCState {AspeedPECIState peci;SerialMM uart[ASPEED_UARTS_NUM ];Clock *sysclk; -UnimplementedDeviceState iomem; -UnimplementedDeviceState iomem0; -UnimplementedDeviceState iomem1; -UnimplementedDeviceState video; -UnimplementedDeviceState emmc_boot_controller; -UnimplementedDeviceState dpmcu; -UnimplementedDeviceState espi; -UnimplementedDeviceState udc; -UnimplementedDeviceState jtag[ASPEED_JTAG_NUM ];AspeedAPB2OPBState fsi[2 ];AspeedLTPIState ltpi_ctrl[ASPEED_IOEXP_NUM ];AspeedAST1700SoCState ioexp[ASPEED_IOEXP_NUM ];
Signature · 1 line
2.53.0
PATCH v2 10/12 hw/arm/aspeed_ast1700: Use a table for unimplemented devices
In reply to Jamin LinBefore this change, the I3C unimplemented device of AST1700 needed its own field in AspeedAST1700SoCState and was created and mapped with open-coded calls.
Describe it in a table and use create_unimplemented_devices() to create and map it in the AST1700 memory region. This makes the code easier to maintain and read.
No functional change.
--- hw/arm/aspeed_ast1700.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-)
hw/arm/aspeed_ast1700.c +8 -13
@@ -15,7 +15,6 @@#define AST2700_SOC_LTPI_SIZE 0x01000000#define AST1700_SOC_SRAM_SIZE 0x00040000 -#define AST1700_SOC_I3C_SIZE 0x00010000enum {ASPEED_AST1700_DEV_SPI0 ,
@@ -51,6 +50,11 @@ static const hwaddr aspeed_ast1700_io_memmap[] = { [ASPEED_AST1700_DEV_SPI0_MEM] = 0x04000000, }; +static const UnimplementedDeviceConfig aspeed_ast1700_unimp_devs[] = { + {"ioexp-i3c" ,"ioexp-i3c" ,0x00C20000 ,0x00010000 ,-1000 }, + { } +}; +static void aspeed_ast1700_realize (DeviceState *dev,Error **errp) {AspeedAST1700SoCState *s =ASPEED_AST1700 (dev);
@@ -181,14 +185,9 @@ static void aspeed_ast1700_realize(DeviceState *dev, Error **errp) sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->wdt[i]), 0)); } -/* I3C */ -qdev_prop_set_string (DEVICE (&s->i3c),"name" ,"ioexp-i3c" ); -qdev_prop_set_uint64 (DEVICE (&s->i3c),"size" ,AST1700_SOC_I3C_SIZE ); -sysbus_realize (SYS_BUS_DEVICE (&s->i3c), errp); -memory_region_add_subregion_overlap (&s->iomem, - aspeed_ast1700_io_memmap[ASPEED_AST1700_DEV_I3C ], -sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->i3c),0 ), --1000 ); +/* Unimplemented devices */ +create_unimplemented_devices (OBJECT (s), &s->iomem, + aspeed_ast1700_unimp_devs); }static void aspeed_ast1700_instance_init (Object *obj)
@@ -238,10 +237,6 @@ static void aspeed_ast1700_instance_init(Object *obj) &s->wdt[i], "aspeed.wdt-ast2700"); } -/* I3C */ -object_initialize_child (obj,"ioexp-i3c" , &s->i3c, -TYPE_UNIMPLEMENTED_DEVICE ); -return ; }
Signature · 1 line
2.53.0
PATCH v2 12/12 hw/arm/aspeed: Remove unused aspeed_mmio_map_unimplemented()
In reply to Jamin LinAll Aspeed SoCs now use create_unimplemented_devices() to create and map their unimplemented devices. Remove aspeed_mmio_map_unimplemented(), which is not used anymore.
No functional change.
--- include/hw/arm/aspeed_soc.h | 3 --- hw/arm/aspeed_soc_common.c | 11 ----------- 2 files changed, 14 deletions(-)
include/hw/arm/aspeed_soc.h +0 -3
@@ -307,9 +307,6 @@ void aspeed_soc_uart_set_chr(SerialMM *uart, int dev, int uarts_base,bool aspeed_soc_dram_init (AspeedSoCState *s,Error **errp);void aspeed_mmio_map (MemoryRegion *memory,SysBusDevice *dev,int n,hwaddr addr); -void aspeed_mmio_map_unimplemented (MemoryRegion *memory,SysBusDevice *dev, -const char *name,hwaddr addr, -uint64_t size);void aspeed_board_init_flashes (AspeedSMCState *s,const char *flashtype,unsigned int count,int unit0); void aspeed_write_boot_rom(BlockBackend *blk, hwaddr addr, size_t rom_size,
hw/arm/aspeed_soc_common.c +0 -11
@@ -104,17 +104,6 @@ void aspeed_mmio_map(MemoryRegion *memory, SysBusDevice *dev, int n,memory_region_add_subregion (memory, addr,sysbus_mmio_get_region (dev, n)); } -void aspeed_mmio_map_unimplemented (MemoryRegion *memory,SysBusDevice *dev, -const char *name,hwaddr addr,uint64_t size) -{ -qdev_prop_set_string (DEVICE (dev),"name" , name); -qdev_prop_set_uint64 (DEVICE (dev),"size" , size); -sysbus_realize (dev, &error_abort); - -memory_region_add_subregion_overlap (memory, addr, -sysbus_mmio_get_region (dev,0 ),-1000 ); -} -void aspeed_board_init_flashes (AspeedSMCState *s,const char *flashtype,unsigned int count,int unit0) {
Signature · 1 line
2.53.0
PATCH v2 9/12 hw/arm/aspeed_coprocessor: Remove unused unimplemented device fields
In reply to Jamin LinAST2700 SSP and TSP now use the unimp_devs table and create_unimplemented_devices() for their unimplemented devices. Remove the old "ipc", "pric" and "otp" fields in Aspeed27x0CoprocessorState and the "timerctrl" field in AspeedCoprocessorState, which are not used anymore.
No functional change.
--- include/hw/arm/aspeed_coprocessor.h | 4 ---- 1 file changed, 4 deletions(-)
include/hw/arm/aspeed_coprocessor.h +0 -4
@@ -22,7 +22,6 @@ struct AspeedCoprocessorState {MemoryRegion uart_alias;Clock *sysclk; -AspeedTimerCtrlState timerctrl;SerialMM *uart;int uart_dev; };
@@ -44,9 +43,6 @@ struct AspeedCoprocessorClass {struct Aspeed27x0CoprocessorState {AspeedCoprocessorState parent;AspeedINTCState intc[2 ]; -UnimplementedDeviceState ipc[2 ]; -UnimplementedDeviceState pric[2 ]; -UnimplementedDeviceState otp;ARMv7MState armv7m;
Signature · 1 line
2.53.0
PATCH v2 11/12 hw/arm/aspeed_ast1700: Remove unused unimplemented device field
In reply to Jamin LinAST1700 now uses create_unimplemented_devices() for its unimplemented devices. Remove the old "i3c" field in AspeedAST1700SoCState, which is not used anymore.
No functional change.
--- include/hw/arm/aspeed_ast1700.h | 2 -- 1 file changed, 2 deletions(-)
include/hw/arm/aspeed_ast1700.h +0 -2
@@ -47,8 +47,6 @@ struct AspeedAST1700SoCState {AspeedI2CState i2c;AspeedPWMState pwm; AspeedWDTState wdt[AST1700_WDT_NUM]; - - UnimplementedDeviceState i3c; };#endif /* ASPEED_AST1700_H */
Signature · 1 line
2.53.0
Quoted 26 lines · Jamin Lin
v1:
1. Use unimp array and table for unimplemented devices
2. Sort device IDs alphabeticallyv2:
1. Add a commoncreate_unimplemented_devices()helper and UnimplementedDeviceConfig in hw/misc/unimp, as suggested by Philippe.
2. Define the unimplemented device table at the SoC class level
3. Drop the "unimp" array and the AspeedUnimpDevice table.
4. Removeaspeed_mmio_map_unimplemented(), which is not used anymore.Jamin Lin (12):
hw/misc/unimp: Addcreate_unimplemented_devices()helper hw/arm/aspeed_ast2400: Use a table for unimplemented devices hw/arm/aspeed_ast2600: Use a table for unimplemented devices hw/arm/aspeed_ast27x0: Use a table for unimplemented devices hw/arm/aspeed_ast10x0: Use a table for unimplemented devices hw/arm/aspeed_ast1040: Use a table for unimplemented devices hw/arm/aspeed: Remove unused unimplemented device fields hw/arm/aspeed_ast27x0: Use a table for unimplemented devices for
SSP/TSP
hw/arm/aspeed_coprocessor: Remove unused unimplemented device fields hw/arm/aspeed_ast1700: Use a table for unimplemented devices hw/arm/aspeed_ast1700: Remove unused unimplemented device field hw/arm/aspeed: Remove unusedaspeed_mmio_map_unimplemented()
Quoted 16 lines
include/hw/arm/aspeed_ast1700.h | 2 -- include/hw/arm/aspeed_coprocessor.h | 5 +-- include/hw/arm/aspeed_soc.h | 14 +------- include/hw/misc/unimp.h | 21 +++++++++++ hw/arm/aspeed_ast1040.c | 40 +++++++-------------- hw/arm/aspeed_ast10x0.c | 55 ++++++++--------------------- hw/arm/aspeed_ast1700.c | 21 +++++------ hw/arm/aspeed_ast2400.c | 25 ++++++------- hw/arm/aspeed_ast2600.c | 44 +++++++---------------- hw/arm/aspeed_ast27x0-ssp.c | 44 +++++++---------------- hw/arm/aspeed_ast27x0-tsp.c | 44 +++++++---------------- hw/arm/aspeed_ast27x0.c | 41 +++++++-------------- hw/arm/aspeed_soc_common.c | 11 ------ hw/misc/unimp.c | 20 +++++++++++ 14 files changed, 138 insertions(+), 249 deletions(-)
Thanks,
C.
Re: [PATCH v2 01/12] hw/misc/unimp: Add create_unimplemented_devices() helper
In reply to Jamin LinQuoted 9 lines · Jamin Lin
Several boards and SoCs create many unimplemented devices. Each of them uses its own structure and helper to describe and map these devices.
Add an UnimplementedDeviceConfig structure and a
create_unimplemented_devices()helper. The helper creates an unimplemented device for each entry of a table, adds it as a QOM child of the parent object, and maps it in a memory region container with the given priority. The table is terminated by an empty entry.
Quoted 6 lines
Suggested-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Jamin Lin <[email protected]>--- include/hw/misc/unimp.h | 21 +++++++++++++++++++++ hw/misc/unimp.c | 20 ++++++++++++++++++++ 2 files changed, 41 insertions(+)
Thanks!
Quoted 7 lines · Jamin Lin
include/hw/arm/aspeed_ast1700.h | 2 -- include/hw/arm/aspeed_coprocessor.h | 5 +-- include/hw/arm/aspeed_soc.h | 14 +------- include/hw/misc/unimp.h | 21 +++++++++++ hw/arm/aspeed_ast1040.c | 40 +++++++-------------- hw/arm/aspeed_ast10x0.c | 55 ++++++++--------------------- hw/arm/aspeed_ast1700.c | 21 +++++------
Quoted 8 lines
hw/arm/aspeed_ast2400.c | 25 ++++++------- hw/arm/aspeed_ast2600.c | 44 +++++++---------------- hw/arm/aspeed_ast27x0-ssp.c | 44 +++++++---------------- hw/arm/aspeed_ast27x0-tsp.c | 44 +++++++---------------- hw/arm/aspeed_ast27x0.c | 41 +++++++-------------- hw/arm/aspeed_soc_common.c | 11 ------ hw/misc/unimp.c | 20 +++++++++++ 14 files changed, 138 insertions(+), 249 deletions(-)
Per the diff-stat it was worth it IMHO :)
Quoted 26 lines · Jamin Lin
v1:
1. Use unimp array and table for unimplemented devices
2. Sort device IDs alphabeticallyv2:
1. Add a commoncreate_unimplemented_devices()helper and UnimplementedDeviceConfig in hw/misc/unimp, as suggested by Philippe.
2. Define the unimplemented device table at the SoC class level
3. Drop the "unimp" array and the AspeedUnimpDevice table.
4. Removeaspeed_mmio_map_unimplemented(), which is not used anymore.Jamin Lin (12):
hw/misc/unimp: Addcreate_unimplemented_devices()helper hw/arm/aspeed_ast2400: Use a table for unimplemented devices hw/arm/aspeed_ast2600: Use a table for unimplemented devices hw/arm/aspeed_ast27x0: Use a table for unimplemented devices hw/arm/aspeed_ast10x0: Use a table for unimplemented devices hw/arm/aspeed_ast1040: Use a table for unimplemented devices hw/arm/aspeed: Remove unused unimplemented device fields hw/arm/aspeed_ast27x0: Use a table for unimplemented devices for
SSP/TSP
hw/arm/aspeed_coprocessor: Remove unused unimplemented device fields hw/arm/aspeed_ast1700: Use a table for unimplemented devices hw/arm/aspeed_ast1700: Remove unused unimplemented device field hw/arm/aspeed: Remove unusedaspeed_mmio_map_unimplemented()
Quoted 16 lines
include/hw/arm/aspeed_ast1700.h | 2 -- include/hw/arm/aspeed_coprocessor.h | 5 +-- include/hw/arm/aspeed_soc.h | 14 +------- include/hw/misc/unimp.h | 21 +++++++++++ hw/arm/aspeed_ast1040.c | 40 +++++++-------------- hw/arm/aspeed_ast10x0.c | 55 ++++++++--------------------- hw/arm/aspeed_ast1700.c | 21 +++++------ hw/arm/aspeed_ast2400.c | 25 ++++++------- hw/arm/aspeed_ast2600.c | 44 +++++++---------------- hw/arm/aspeed_ast27x0-ssp.c | 44 +++++++---------------- hw/arm/aspeed_ast27x0-tsp.c | 44 +++++++---------------- hw/arm/aspeed_ast27x0.c | 41 +++++++-------------- hw/arm/aspeed_soc_common.c | 11 ------ hw/misc/unimp.c | 20 +++++++++++ 14 files changed, 138 insertions(+), 249 deletions(-)
Applied to
https://github.com/legoater/qemu aspeed-next
Thanks,
C.