arm: aspeed: Extend SDRAM controller
Joel Stanley
maintainercover arm: aspeed: Extend SDRAM controller
This series allow us to run upstream u-boot on the ast2500-evb model. They have been tested with upstream u-boot, as well as openbmc's ast2500 and ast2500 images.
Cédric Le Goater (1):
aspeed: add a max_ram_size property to the memory controller
Joel Stanley (6):
aspeed_sdmc: Extend number of valid registers
aspeed_sdmc: Fix saved values
aspeed_sdmc: Set 'cache initial sequence' always true
aspeed_sdmc: Init status alwlays idle
aspeed_sdmc: Handle ECC training
aspeed: Link SCU to the watchdog
hw/arm/aspeed.c | 31 ++++++++++++++++++ hw/arm/aspeed_soc.c | 4 +++ hw/misc/aspeed_sdmc.c | 55 +++++++++++++++++++++----------- hw/watchdog/wdt_aspeed.c | 20 ++++++++++++ include/hw/misc/aspeed_sdmc.h | 4 ++- include/hw/watchdog/wdt_aspeed.h | 1 + 6 files changed, 95 insertions(+), 20 deletions(-)
Signature · 1 line
2.17.1
Joel Stanley
maintainerPATCH 1/7 aspeed_sdmc: Extend number of valid registers
The SDMC on the ast2500 has 170 registers.
--- include/hw/misc/aspeed_sdmc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/hw/misc/aspeed_sdmc.h +1 -1
@@ -14,7 +14,7 @@#define TYPE_ASPEED_SDMC "aspeed.sdmc"#define ASPEED_SDMC (obj) OBJECT_CHECK(AspeedSDMCState, (obj), TYPE_ASPEED_SDMC) -#define ASPEED_SDMC_NR_REGS (0x8 >> 2) +#define ASPEED_SDMC_NR_REGS (0x174 >> 2) typedef struct AspeedSDMCState { /*< private >*/
Signature · 1 line
2.17.1
Re: [Qemu-arm] [PATCH 1/7] aspeed_sdmc: Extend number of valid registers
Quoted 1 line · Joel Stanley
The SDMC on the ast2500 has 170 registers.
Thanks,
C.
Quoted 19 lines
Signed-off-by Joel Stanley <[email protected]>--- include/hw/misc/aspeed_sdmc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/hw/misc/aspeed_sdmc.h +1
-1@@ -14,7 +14,7 @@#define TYPE_ASPEED_SDMC "aspeed.sdmc"#define ASPEED_SDMC (obj) OBJECT_CHECK(AspeedSDMCState, (obj), TYPE_ASPEED_SDMC) -#define ASPEED_SDMC_NR_REGS (0x8 >> 2) +#define ASPEED_SDMC_NR_REGS (0x174 >> 2) typedef struct AspeedSDMCState { /*< private >*/
Joel Stanley
maintainerPATCH 2/7 aspeed_sdmc: Fix saved values
In reply to Joel StanleyThis fixes the intended protection of read-only values in the configuration register. They were being always set to zero by mistake.
The read-only fields depend on the configured memory size of the system, so they cannot be fixed at compile time. The most straight forward option was to store them in the state structure.
--- hw/misc/aspeed_sdmc.c | 27 ++++++++------------------- include/hw/misc/aspeed_sdmc.h | 1 + 2 files changed, 9 insertions(+), 19 deletions(-)
hw/misc/aspeed_sdmc.c +8 -19
@@ -126,10 +126,12 @@ static void aspeed_sdmc_write(void *opaque, hwaddr addr, uint64_t data,case AST2400_A0_SILICON_REV :case AST2400_A1_SILICON_REV : data &= ~ASPEED_SDMC_READONLY_MASK ; + data |= s->fixed_conf;break ;case AST2500_A0_SILICON_REV :case AST2500_A1_SILICON_REV : data &= ~ASPEED_SDMC_AST2500_READONLY_MASK ; + data |= s->fixed_conf;break ;default :g_assert_not_reached ();
@@ -198,25 +200,7 @@ static void aspeed_sdmc_reset(DeviceState *dev)memset (s->regs,0 ,sizeof (s->regs));/* Set ram size bit and defaults values */ -switch (s->silicon_rev) { -case AST2400_A0_SILICON_REV : -case AST2400_A1_SILICON_REV : - s->regs[R_CONF ] |= -ASPEED_SDMC_VGA_COMPAT | -ASPEED_SDMC_DRAM_SIZE (s->ram_bits); -break ; - -case AST2500_A0_SILICON_REV : -case AST2500_A1_SILICON_REV : - s->regs[R_CONF ] |= -ASPEED_SDMC_HW_VERSION (1 ) | -ASPEED_SDMC_VGA_APERTURE (ASPEED_SDMC_VGA_64MB ) | -ASPEED_SDMC_DRAM_SIZE (s->ram_bits); -break ; - -default : -g_assert_not_reached (); - } + s->regs[R_CONF ] = s->fixed_conf; }static void aspeed_sdmc_realize (DeviceState *dev,Error **errp)
@@ -234,10 +218,15 @@ static void aspeed_sdmc_realize(DeviceState *dev, Error **errp)case AST2400_A0_SILICON_REV :case AST2400_A1_SILICON_REV : s->ram_bits =ast2400_rambits (s); + s->fixed_conf =ASPEED_SDMC_VGA_COMPAT | +ASPEED_SDMC_DRAM_SIZE (s->ram_bits);break ;case AST2500_A0_SILICON_REV :case AST2500_A1_SILICON_REV : s->ram_bits =ast2500_rambits (s); + s->fixed_conf =ASPEED_SDMC_HW_VERSION (1 ) | +ASPEED_SDMC_VGA_APERTURE (ASPEED_SDMC_VGA_64MB ) | +ASPEED_SDMC_DRAM_SIZE (s->ram_bits);break ;default :g_assert_not_reached ();
include/hw/misc/aspeed_sdmc.h +1 -0
@@ -27,6 +27,7 @@ typedef struct AspeedSDMCState {uint32_t silicon_rev;uint32_t ram_bits;uint64_t ram_size; +uint32_t fixed_conf; } AspeedSDMCState;
Signature · 1 line
2.17.1
Re: [Qemu-arm] [PATCH 2/7] aspeed_sdmc: Fix saved values
Quoted 2 lines · Joel Stanley
This fixes the intended protection of read-only values in the configuration register. They were being always set to zero by mistake.
yes :/
Quoted 3 lines
The read-only fields depend on the configured memory size of the system, so they cannot be fixed at compile time. The most straight forward option was to store them in the state structure.
We could also use an array of init values for registers, like SCU does, but this is fine for now.
Quoted 1 line
Signed-off-by Joel Stanley <[email protected]>
Thanks,
C.
Quoted 78 lines
--- hw/misc/aspeed_sdmc.c | 27 ++++++++------------------- include/hw/misc/aspeed_sdmc.h | 1 + 2 files changed, 9 insertions(+), 19 deletions(-)hw/misc/aspeed_sdmc.c +8
-19@@ -126,10 +126,12 @@ static void aspeed_sdmc_write(void *opaque, hwaddr addr, uint64_t data,case AST2400_A0_SILICON_REV :case AST2400_A1_SILICON_REV : data &= ~ASPEED_SDMC_READONLY_MASK ; + data |= s->fixed_conf;break ;case AST2500_A0_SILICON_REV :case AST2500_A1_SILICON_REV : data &= ~ASPEED_SDMC_AST2500_READONLY_MASK ; + data |= s->fixed_conf;break ;default :g_assert_not_reached ();@@ -198,25 +200,7 @@ static void aspeed_sdmc_reset(DeviceState *dev)memset (s->regs,0 ,sizeof (s->regs));/* Set ram size bit and defaults values */ -switch (s->silicon_rev) { -case AST2400_A0_SILICON_REV : -case AST2400_A1_SILICON_REV : - s->regs[R_CONF ] |= -ASPEED_SDMC_VGA_COMPAT | -ASPEED_SDMC_DRAM_SIZE (s->ram_bits); -break ; - -case AST2500_A0_SILICON_REV : -case AST2500_A1_SILICON_REV : - s->regs[R_CONF ] |= -ASPEED_SDMC_HW_VERSION (1 ) | -ASPEED_SDMC_VGA_APERTURE (ASPEED_SDMC_VGA_64MB ) | -ASPEED_SDMC_DRAM_SIZE (s->ram_bits); -break ; - -default : -g_assert_not_reached (); - } + s->regs[R_CONF ] = s->fixed_conf; }static void aspeed_sdmc_realize (DeviceState *dev,Error **errp)@@ -234,10 +218,15 @@ static void aspeed_sdmc_realize(DeviceState *dev, Error **errp)case AST2400_A0_SILICON_REV :case AST2400_A1_SILICON_REV : s->ram_bits =ast2400_rambits (s); + s->fixed_conf =ASPEED_SDMC_VGA_COMPAT | +ASPEED_SDMC_DRAM_SIZE (s->ram_bits);break ;case AST2500_A0_SILICON_REV :case AST2500_A1_SILICON_REV : s->ram_bits =ast2500_rambits (s); + s->fixed_conf =ASPEED_SDMC_HW_VERSION (1 ) | +ASPEED_SDMC_VGA_APERTURE (ASPEED_SDMC_VGA_64MB ) | +ASPEED_SDMC_DRAM_SIZE (s->ram_bits);break ;default :g_assert_not_reached ();include/hw/misc/aspeed_sdmc.h +1
-0@@ -27,6 +27,7 @@ typedef struct AspeedSDMCState {uint32_t silicon_rev;uint32_t ram_bits;uint64_t ram_size; +uint32_t fixed_conf; } AspeedSDMCState;
Joel Stanley
maintainerPATCH 3/7 aspeed_sdmc: Set 'cache initial sequence' always true
In reply to Joel StanleyThe SDRAM training routine sets the 'Enable cache initial' bit, and then waits for the 'cache initial sequence' to be done.
Have it always return done, as there is no other side effects that the model needs to implement. This allows the upstream u-boot training to proceed on the ast2500-evb board.
--- hw/misc/aspeed_sdmc.c | 1 + 1 file changed, 1 insertion(+)
hw/misc/aspeed_sdmc.c +1 -0
@@ -226,6 +226,7 @@ static void aspeed_sdmc_realize(DeviceState *dev, Error **errp) s->ram_bits =ast2500_rambits (s); s->fixed_conf =ASPEED_SDMC_HW_VERSION (1 ) |ASPEED_SDMC_VGA_APERTURE (ASPEED_SDMC_VGA_64MB ) | +ASPEED_SDMC_CACHE_INITIAL_DONE |ASPEED_SDMC_DRAM_SIZE (s->ram_bits);break ;default :
Signature · 1 line
2.17.1
Re: [Qemu-arm] [PATCH 3/7] aspeed_sdmc: Set 'cache initial sequence' always true
Quoted 8 lines · Joel Stanley
The SDRAM training routine sets the 'Enable cache initial' bit, and then waits for the 'cache initial sequence' to be done.
Have it always return done, as there is no other side effects that the model needs to implement. This allows the upstream u-boot training to proceed on the ast2500-evb board.
Signed-off-by Joel Stanley <[email protected]>
Thanks,
C.
Quoted 17 lines
--- hw/misc/aspeed_sdmc.c | 1 + 1 file changed, 1 insertion(+)hw/misc/aspeed_sdmc.c +1
-0@@ -226,6 +226,7 @@ static void aspeed_sdmc_realize(DeviceState *dev, Error **errp) s->ram_bits =ast2500_rambits (s); s->fixed_conf =ASPEED_SDMC_HW_VERSION (1 ) |ASPEED_SDMC_VGA_APERTURE (ASPEED_SDMC_VGA_64MB ) | +ASPEED_SDMC_CACHE_INITIAL_DONE |ASPEED_SDMC_DRAM_SIZE (s->ram_bits);break ;default :
Joel Stanley
maintainerPATCH 4/7 aspeed_sdmc: Init status alwlays idle
In reply to Joel StanleyThe ast2500 SDRAM training routine busy waits on the 'init cycle busy state' bit in DDR PHY Control/Status register #1 (MCR60).
This ensures the bit always reads zero, and allows training to complete with upstream u-boot on the ast2500-evb.
--- hw/misc/aspeed_sdmc.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
hw/misc/aspeed_sdmc.c +15 -0
@@ -23,6 +23,10 @@/* Configuration Register */ #define R_CONF (0x04 / 4) +/* Control/Status Register #1 (ast2500) */ +#define R_STATUS1 (0x60 / 4) +#define PHY_BUSY_STATE BIT(0) +/* * Configuration register Ox4 (for Aspeed AST2400 SOC) *
@@ -137,6 +141,17 @@ static void aspeed_sdmc_write(void *opaque, hwaddr addr, uint64_t data,g_assert_not_reached (); } } +if (s->silicon_rev ==AST2500_A0_SILICON_REV || + s->silicon_rev ==AST2500_A1_SILICON_REV ) { +switch (addr) { +case R_STATUS1 : +/* Will never return 'busy' */ + data &= ~PHY_BUSY_STATE ; +break ; +default : +break ; + } + } s->regs[addr] = data; }
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 4/7] aspeed_sdmc: Init status alwlays idle
Quoted 7 lines · Joel Stanley
The ast2500 SDRAM training routine busy waits on the 'init cycle busy state' bit in DDR PHY Control/Status register #1 (MCR60).
This ensures the bit always reads zero, and allows training to complete with upstream u-boot on the ast2500-evb.
Signed-off-by Joel Stanley <[email protected]>
One comment below, no need to resend for that.
Quoted 20 lines
--- hw/misc/aspeed_sdmc.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)hw/misc/aspeed_sdmc.c +4
-0@@ -23,6 +23,10 @@/* Configuration Register */ #define R_CONF (0x04 / 4) +/* Control/Status Register #1 (ast2500) */ +#define R_STATUS1 (0x60 / 4) +#define PHY_BUSY_STATE BIT(0) +/* * Configuration register Ox4 (for Aspeed AST2400 SOC) *
hw/misc/aspeed_sdmc.c static void aspeed_sdmc_write(void *opaque, hwaddr addr, uint64_t data, · line 145
Quoted 5 lines
hw/misc/aspeed_sdmc.c +2
-0@@ -137,6 +141,17 @@ static void aspeed_sdmc_write(void *opaque, hwaddr addr, uint64_t data,g_assert_not_reached (); } } +if (s->silicon_rev ==AST2500_A0_SILICON_REV || + s->silicon_rev ==AST2500_A1_SILICON_REV ) {
Maybe use the ASPEED_IS_AST2500() ?
It would be nice to have a set of macros we could use in the different models testing the SoC silicon revision. How about :
#define ASPEED_AST2400 0x2
#define ASPEED_AST2500 0x4
#define ASPEED_AST2600 0x6
#define ASPEED_REVISION_MAJOR(si_rev) (((si_rev) >> 24) & 0xff)
#define ASPEED_IS_AST2400(si_rev) (ASPEED_REVISION_MAJOR(si_rev) == ASPEED_AST2400) #define ASPEED_IS_AST2500(si_rev) (ASPEED_REVISION_MAJOR(si_rev) == ASPEED_AST2500) #define ASPEED_IS_AST2600(si_rev) (ASPEED_REVISION_MAJOR(si_rev) == ASPEED_AST2600)
Thanks,
C.
Quoted 13 lines
hw/misc/aspeed_sdmc.c +9
-0+switch (addr) { +case R_STATUS1 : +/* Will never return 'busy' */ + data &= ~PHY_BUSY_STATE ; +break ; +default : +break ; + } + } s->regs[addr] = data; }
Joel Stanley
maintainerPATCH 5/7 aspeed_sdmc: Handle ECC training
In reply to Joel StanleyThis is required to ensure u-boot SDRAM training completes.
--- hw/misc/aspeed_sdmc.c | 9 +++++++++ 1 file changed, 9 insertions(+)
hw/misc/aspeed_sdmc.c +9 -0
@@ -27,6 +27,10 @@#define R_STATUS1 (0x60 / 4)#define PHY_BUSY_STATE BIT(0) +#define R_ECC_TEST_CTRL (0x70 / 4) +#define ECC_TEST_FINISHED BIT(12) +#define ECC_TEST_FAIL BIT(13) +/* * Configuration register Ox4 (for Aspeed AST2400 SOC) *
@@ -148,6 +152,11 @@ static void aspeed_sdmc_write(void *opaque, hwaddr addr, uint64_t data,/* Will never return 'busy' */ data &= ~PHY_BUSY_STATE ;break ; +case R_ECC_TEST_CTRL : +/* Always done, always happy */ + data |=ECC_TEST_FINISHED ; + data &= ~ECC_TEST_FAIL ; +break ;default :break ; }
Signature · 1 line
2.17.1
Re: [Qemu-arm] [PATCH 5/7] aspeed_sdmc: Handle ECC training
Quoted 3 lines · Joel Stanley
This is required to ensure u-boot SDRAM training completes.
Signed-off-by Joel Stanley <[email protected]>
Thanks,
C.
Quoted 32 lines
--- hw/misc/aspeed_sdmc.c | 9 +++++++++ 1 file changed, 9 insertions(+)hw/misc/aspeed_sdmc.c +9
-0@@ -27,6 +27,10 @@#define R_STATUS1 (0x60 / 4)#define PHY_BUSY_STATE BIT(0) +#define R_ECC_TEST_CTRL (0x70 / 4) +#define ECC_TEST_FINISHED BIT(12) +#define ECC_TEST_FAIL BIT(13) +/* * Configuration register Ox4 (for Aspeed AST2400 SOC) * @@ -148,6 +152,11 @@ static void aspeed_sdmc_write(void *opaque, hwaddr addr, uint64_t data,/* Will never return 'busy' */ data &= ~PHY_BUSY_STATE ;break ; +case R_ECC_TEST_CTRL : +/* Always done, always happy */ + data |=ECC_TEST_FINISHED ; + data &= ~ECC_TEST_FAIL ; +break ;default :break ; }
Joel Stanley
maintainerPATCH 6/7 aspeed: add a max_ram_size property to the memory controller
In reply to Joel StanleyFrom: Cédric Le Goater <[email protected]>
This will be used to construct a memory region beyond the RAM region to let firmwares scan the address space with load/store to guess how much RAM the SoC has.
--- hw/arm/aspeed.c | 31 +++++++++++++++++++++++++++++++ hw/arm/aspeed_soc.c | 2 ++ hw/misc/aspeed_sdmc.c | 3 +++ include/hw/misc/aspeed_sdmc.h | 1 + 4 files changed, 37 insertions(+)
hw/arm/aspeed.c +31 -0
@@ -31,6 +31,7 @@ static struct arm_boot_info aspeed_board_binfo = {typedef struct AspeedBoardState {AspeedSoCState soc;MemoryRegion ram; +MemoryRegion max_ram; }AspeedBoardState ; typedef struct AspeedBoardConfig {
@@ -127,6 +128,27 @@ static const AspeedBoardConfig aspeed_boards[] = { }, }; +/* +* The max ram region is for firmwares that scan the address space +* with load/store to guess how much RAM the SoC has. +*/ +static uint64_t max_ram_read (void *opaque,hwaddr offset,unsigned size) +{ +return 0 ; +} + +static void max_ram_write (void *opaque,hwaddr offset,uint64_t value, +unsigned size) +{ +/* Disacard writes */ +} + +static const MemoryRegionOps max_ram_ops = { + .read = max_ram_read, + .write = max_ram_write, + .endianness =DEVICE_NATIVE_ENDIAN , +}; +#define FIRMWARE_ADDR 0x0 static void write_boot_rom(DriveInfo *dinfo, hwaddr addr, size_t rom_size,
@@ -187,6 +209,7 @@ static void aspeed_board_init(MachineState *machine,AspeedBoardState *bmc;AspeedSoCClass *sc;DriveInfo *drive0 =drive_get (IF_MTD ,0 ,0 ); +ram_addr_t max_ram_size; bmc =g_new0 (AspeedBoardState,1 );object_initialize (&bmc->soc, (sizeof (bmc->soc)), cfg->soc_name);
@@ -226,6 +249,14 @@ static void aspeed_board_init(MachineState *machine,object_property_add_const_link (OBJECT (&bmc->soc),"ram" ,OBJECT (&bmc->ram), &error_abort); + max_ram_size =object_property_get_uint (OBJECT (&bmc->soc),"max-ram-size" , + &error_abort); +memory_region_init_io (&bmc->max_ram,NULL , &max_ram_ops,NULL , +"max_ram" , max_ram_size - ram_size); +memory_region_add_subregion (get_system_memory (), + sc->info->sdram_base + ram_size, + &bmc->max_ram); +aspeed_board_init_flashes (&bmc->soc.fmc, cfg->fmc_model, &error_abort);aspeed_board_init_flashes (&bmc->soc.spi[0 ], cfg->spi_model, &error_abort);
hw/arm/aspeed_soc.c +2 -0
@@ -155,6 +155,8 @@ static void aspeed_soc_init(Object *obj) sc->info->silicon_rev);object_property_add_alias (obj,"ram-size" ,OBJECT (&s->sdmc),"ram-size" , &error_abort); +object_property_add_alias (obj,"max-ram-size" ,OBJECT (&s->sdmc), +"max-ram-size" , &error_abort);for (i =0 ; i < sc->info->wdts_num; i++) {object_initialize (&s->wdt[i],sizeof (s->wdt[i]),TYPE_ASPEED_WDT );
hw/misc/aspeed_sdmc.c +3 -0
@@ -242,12 +242,14 @@ static void aspeed_sdmc_realize(DeviceState *dev, Error **errp)case AST2400_A0_SILICON_REV :case AST2400_A1_SILICON_REV : s->ram_bits =ast2400_rambits (s); + s->max_ram_size =512 <<20 ; s->fixed_conf =ASPEED_SDMC_VGA_COMPAT |ASPEED_SDMC_DRAM_SIZE (s->ram_bits);break ;case AST2500_A0_SILICON_REV :case AST2500_A1_SILICON_REV : s->ram_bits =ast2500_rambits (s); + s->max_ram_size =1024 <<20 ; s->fixed_conf =ASPEED_SDMC_HW_VERSION (1 ) |ASPEED_SDMC_VGA_APERTURE (ASPEED_SDMC_VGA_64MB ) | ASPEED_SDMC_CACHE_INITIAL_DONE |
@@ -275,6 +277,7 @@ static const VMStateDescription vmstate_aspeed_sdmc = {static Property aspeed_sdmc_properties[] = {DEFINE_PROP_UINT32 ("silicon-rev" , AspeedSDMCState, silicon_rev,0 ),DEFINE_PROP_UINT64 ("ram-size" , AspeedSDMCState, ram_size,0 ), +DEFINE_PROP_UINT64 ("max-ram-size" , AspeedSDMCState, max_ram_size,0 ),DEFINE_PROP_END_OF_LIST (), };
include/hw/misc/aspeed_sdmc.h +1 -0
@@ -27,6 +27,7 @@ typedef struct AspeedSDMCState {uint32_t silicon_rev;uint32_t ram_bits;uint64_t ram_size; +uint64_t max_ram_size;uint32_t fixed_conf; } AspeedSDMCState;
Signature · 1 line
2.17.1
Re: [Qemu-arm] [PATCH 6/7] aspeed: add a max_ram_size property to the memory controller
Quoted 5 lines · Joel Stanley
From: Cédric Le Goater <[email protected]>
This will be used to construct a memory region beyond the RAM region to let firmwares scan the address space with load/store to guess how much RAM the SoC has.
This is in another patch I can send later on.
Thanks,
C.
Quoted 125 lines
Signed-off-by Cédric Le Goater <[email protected]>Signed-off-by Joel Stanley <[email protected]>--- hw/arm/aspeed.c | 31 +++++++++++++++++++++++++++++++ hw/arm/aspeed_soc.c | 2 ++ hw/misc/aspeed_sdmc.c | 3 +++ include/hw/misc/aspeed_sdmc.h | 1 + 4 files changed, 37 insertions(+)hw/arm/aspeed.c +31
-0@@ -31,6 +31,7 @@ static struct arm_boot_info aspeed_board_binfo = {typedef struct AspeedBoardState {AspeedSoCState soc;MemoryRegion ram; +MemoryRegion max_ram; }AspeedBoardState ; typedef struct AspeedBoardConfig {@@ -127,6 +128,27 @@ static const AspeedBoardConfig aspeed_boards[] = { }, }; +/* +* The max ram region is for firmwares that scan the address space +* with load/store to guess how much RAM the SoC has. +*/ +static uint64_t max_ram_read (void *opaque,hwaddr offset,unsigned size) +{ +return 0 ; +} + +static void max_ram_write (void *opaque,hwaddr offset,uint64_t value, +unsigned size) +{ +/* Disacard writes */ +} + +static const MemoryRegionOps max_ram_ops = { + .read = max_ram_read, + .write = max_ram_write, + .endianness =DEVICE_NATIVE_ENDIAN , +}; +#define FIRMWARE_ADDR 0x0 static void write_boot_rom(DriveInfo *dinfo, hwaddr addr, size_t rom_size,@@ -187,6 +209,7 @@ static void aspeed_board_init(MachineState *machine,AspeedBoardState *bmc;AspeedSoCClass *sc;DriveInfo *drive0 =drive_get (IF_MTD ,0 ,0 ); +ram_addr_t max_ram_size; bmc =g_new0 (AspeedBoardState,1 );object_initialize (&bmc->soc, (sizeof (bmc->soc)), cfg->soc_name);@@ -226,6 +249,14 @@ static void aspeed_board_init(MachineState *machine,object_property_add_const_link (OBJECT (&bmc->soc),"ram" ,OBJECT (&bmc->ram), &error_abort); + max_ram_size =object_property_get_uint (OBJECT (&bmc->soc),"max-ram-size" , + &error_abort); +memory_region_init_io (&bmc->max_ram,NULL , &max_ram_ops,NULL , +"max_ram" , max_ram_size - ram_size); +memory_region_add_subregion (get_system_memory (), + sc->info->sdram_base + ram_size, + &bmc->max_ram); +aspeed_board_init_flashes (&bmc->soc.fmc, cfg->fmc_model, &error_abort);aspeed_board_init_flashes (&bmc->soc.spi[0 ], cfg->spi_model, &error_abort);hw/arm/aspeed_soc.c +2
-0@@ -155,6 +155,8 @@ static void aspeed_soc_init(Object *obj) sc->info->silicon_rev);object_property_add_alias (obj,"ram-size" ,OBJECT (&s->sdmc),"ram-size" , &error_abort); +object_property_add_alias (obj,"max-ram-size" ,OBJECT (&s->sdmc), +"max-ram-size" , &error_abort);for (i =0 ; i < sc->info->wdts_num; i++) {object_initialize (&s->wdt[i],sizeof (s->wdt[i]),TYPE_ASPEED_WDT );hw/misc/aspeed_sdmc.c +3
-0@@ -242,12 +242,14 @@ static void aspeed_sdmc_realize(DeviceState *dev, Error **errp)case AST2400_A0_SILICON_REV :case AST2400_A1_SILICON_REV : s->ram_bits =ast2400_rambits (s); + s->max_ram_size =512 <<20 ; s->fixed_conf =ASPEED_SDMC_VGA_COMPAT |ASPEED_SDMC_DRAM_SIZE (s->ram_bits);break ;case AST2500_A0_SILICON_REV :case AST2500_A1_SILICON_REV : s->ram_bits =ast2500_rambits (s); + s->max_ram_size =1024 <<20 ; s->fixed_conf =ASPEED_SDMC_HW_VERSION (1 ) |ASPEED_SDMC_VGA_APERTURE (ASPEED_SDMC_VGA_64MB ) | ASPEED_SDMC_CACHE_INITIAL_DONE |@@ -275,6 +277,7 @@ static const VMStateDescription vmstate_aspeed_sdmc = {static Property aspeed_sdmc_properties[] = {DEFINE_PROP_UINT32 ("silicon-rev" , AspeedSDMCState, silicon_rev,0 ),DEFINE_PROP_UINT64 ("ram-size" , AspeedSDMCState, ram_size,0 ), +DEFINE_PROP_UINT64 ("max-ram-size" , AspeedSDMCState, max_ram_size,0 ),DEFINE_PROP_END_OF_LIST (), };include/hw/misc/aspeed_sdmc.h +1
-0@@ -27,6 +27,7 @@ typedef struct AspeedSDMCState {uint32_t silicon_rev;uint32_t ram_bits;uint64_t ram_size; +uint64_t max_ram_size;uint32_t fixed_conf; } AspeedSDMCState;
Re: [Qemu-devel] [Qemu-arm] [PATCH 6/7] aspeed: add a max_ram_size property to the memory controller
Quoted 8 lines · Cédric Le Goater
Quoted 5 lines · Joel Stanley
From: Cédric Le Goater <[email protected]>
This will be used to construct a memory region beyond the RAM region to let firmwares scan the address space with load/store to guess how much RAM the SoC has.
This is in another patch I can send later on.
I now see that you have merged two patches. This is fine then.
Thanks,
C.
Re: [Qemu-arm] [PATCH 6/7] aspeed: add a max_ram_size property to the memory controller
In reply to Joel StanleyQuoted 64 lines · Joel Stanley
From: Cédric Le Goater <[email protected]>
This will be used to construct a memory region beyond the RAM region to let firmwares scan the address space with load/store to guess how much RAM the SoC has.
Signed-off-by Cédric Le Goater <[email protected]>Signed-off-by Joel Stanley <[email protected]>--- hw/arm/aspeed.c | 31 +++++++++++++++++++++++++++++++ hw/arm/aspeed_soc.c | 2 ++ hw/misc/aspeed_sdmc.c | 3 +++ include/hw/misc/aspeed_sdmc.h | 1 + 4 files changed, 37 insertions(+)hw/arm/aspeed.c +23
-0@@ -31,6 +31,7 @@ static struct arm_boot_info aspeed_board_binfo = {typedef struct AspeedBoardState {AspeedSoCState soc;MemoryRegion ram; +MemoryRegion max_ram; }AspeedBoardState ; typedef struct AspeedBoardConfig {@@ -127,6 +128,27 @@ static const AspeedBoardConfig aspeed_boards[] = { }, }; +/* +* The max ram region is for firmwares that scan the address space +* with load/store to guess how much RAM the SoC has. +*/ +static uint64_t max_ram_read (void *opaque,hwaddr offset,unsigned size) +{ +return 0 ; +} + +static void max_ram_write (void *opaque,hwaddr offset,uint64_t value, +unsigned size) +{ +/* Disacard writes */ +} + +static const MemoryRegionOps max_ram_ops = { + .read = max_ram_read, + .write = max_ram_write, + .endianness =DEVICE_NATIVE_ENDIAN , +}; +#define FIRMWARE_ADDR 0x0 static void write_boot_rom(DriveInfo *dinfo, hwaddr addr, size_t rom_size,@@ -187,6 +209,7 @@ static void aspeed_board_init(MachineState *machine,AspeedBoardState *bmc;AspeedSoCClass *sc;DriveInfo *drive0 =drive_get (IF_MTD ,0 ,0 ); +ram_addr_t max_ram_size; bmc =g_new0 (AspeedBoardState,1 );object_initialize (&bmc->soc, (sizeof (bmc->soc)), cfg->soc_name);
hw/arm/aspeed.c static void aspeed_board_init(MachineState *machine, · line 258
Quoted 10 lines
hw/arm/aspeed.c +7
-0@@ -226,6 +249,14 @@ static void aspeed_board_init(MachineState *machine,object_property_add_const_link (OBJECT (&bmc->soc),"ram" ,OBJECT (&bmc->ram), &error_abort); + max_ram_size =object_property_get_uint (OBJECT (&bmc->soc),"max-ram-size" , + &error_abort); +memory_region_init_io (&bmc->max_ram,NULL , &max_ram_ops,NULL , +"max_ram" , max_ram_size - ram_size); +memory_region_add_subregion (get_system_memory (), + sc->info->sdram_base + ram_size, + &bmc->max_ram);
I'm surprised that you need the IO ops, ie that it doesn't work just to define an empty container region with memory_region_init().
thanks
-- PMM
Re: [Qemu-devel] [PATCH 6/7] aspeed: add a max_ram_size property to the memory controller
Quoted 68 lines · Peter Maydell
Quoted 67 lines · Joel Stanley
From: Cédric Le Goater <[email protected]>
This will be used to construct a memory region beyond the RAM region to let firmwares scan the address space with load/store to guess how much RAM the SoC has.
Signed-off-by Cédric Le Goater <[email protected]>Signed-off-by Joel Stanley <[email protected]>--- hw/arm/aspeed.c | 31 +++++++++++++++++++++++++++++++ hw/arm/aspeed_soc.c | 2 ++ hw/misc/aspeed_sdmc.c | 3 +++ include/hw/misc/aspeed_sdmc.h | 1 + 4 files changed, 37 insertions(+)hw/arm/aspeed.c +23
-0@@ -31,6 +31,7 @@ static struct arm_boot_info aspeed_board_binfo = {typedef struct AspeedBoardState {AspeedSoCState soc;MemoryRegion ram; +MemoryRegion max_ram; }AspeedBoardState ; typedef struct AspeedBoardConfig {@@ -127,6 +128,27 @@ static const AspeedBoardConfig aspeed_boards[] = { }, }; +/* +* The max ram region is for firmwares that scan the address space +* with load/store to guess how much RAM the SoC has. +*/ +static uint64_t max_ram_read (void *opaque,hwaddr offset,unsigned size) +{ +return 0 ; +} + +static void max_ram_write (void *opaque,hwaddr offset,uint64_t value, +unsigned size) +{ +/* Disacard writes */ +} + +static const MemoryRegionOps max_ram_ops = { + .read = max_ram_read, + .write = max_ram_write, + .endianness =DEVICE_NATIVE_ENDIAN , +}; +#define FIRMWARE_ADDR 0x0 static void write_boot_rom(DriveInfo *dinfo, hwaddr addr, size_t rom_size,@@ -187,6 +209,7 @@ static void aspeed_board_init(MachineState *machine,AspeedBoardState *bmc;AspeedSoCClass *sc;DriveInfo *drive0 =drive_get (IF_MTD ,0 ,0 ); +ram_addr_t max_ram_size; bmc =g_new0 (AspeedBoardState,1 );object_initialize (&bmc->soc, (sizeof (bmc->soc)), cfg->soc_name);@@ -226,6 +249,14 @@ static void aspeed_board_init(MachineState *machine,object_property_add_const_link (OBJECT (&bmc->soc),"ram" ,OBJECT (&bmc->ram), &error_abort);
Quoted 10 lines
hw/arm/aspeed.c static void aspeed_board_init(MachineState *machine, · line 258
Quoted 7 lines
hw/arm/aspeed.c +7
-0+ max_ram_size =object_property_get_uint (OBJECT (&bmc->soc),"max-ram-size" , + &error_abort); +memory_region_init_io (&bmc->max_ram,NULL , &max_ram_ops,NULL , +"max_ram" , max_ram_size - ram_size); +memory_region_add_subregion (get_system_memory (), + sc->info->sdram_base + ram_size, + &bmc->max_ram);I'm surprised that you need the IO ops, ie that it doesn't work just to define an empty container region with
memory_region_init().
Initially, there was some logging in the IO ops, which was a nice to have. But that was dropped in this patch. No a big issue I think.
Thanks,
C.
Joel Stanley
maintainerPATCH 7/7 aspeed: Link SCU to the watchdog
In reply to Joel StanleyThe ast2500 uses the watchdog to reset the SDRAM controller. This operation is usually performed by u-boot's memory training procedure, and it is enabled by setting a bit in the SCU and then causing the watchdog to expire. Therefore, we need the watchdog to be able to acess the SCU's register space.
This does not cause a system reset, but only resets the SDRAM controller.
--- hw/arm/aspeed_soc.c | 2 ++ hw/watchdog/wdt_aspeed.c | 20 ++++++++++++++++++++ include/hw/watchdog/wdt_aspeed.h | 1 + 3 files changed, 23 insertions(+)
hw/arm/aspeed_soc.c +2 -0
@@ -164,6 +164,8 @@ static void aspeed_soc_init(Object *obj)qdev_set_parent_bus (DEVICE (&s->wdt[i]),sysbus_get_default ());qdev_prop_set_uint32 (DEVICE (&s->wdt[i]),"silicon-rev" , sc->info->silicon_rev); +object_property_add_const_link (OBJECT (&s->wdt[i]),"scu" , +OBJECT (&s->scu), &error_abort); }object_initialize (&s->ftgmac100,sizeof (s->ftgmac100),TYPE_FTGMAC100 );
hw/watchdog/wdt_aspeed.c +20 -0
@@ -43,6 +43,9 @@#define WDT_RESTART_MAGIC 0x4755 +#define SCU_RESET_CONTROL1 (0x04 / 4) +#define SCU_RESET_SDRAM BIT(0) +static bool aspeed_wdt_is_enabled (const AspeedWDTState *s) {return s->regs[WDT_CTRL ] &WDT_CTRL_ENABLE ;
@@ -221,6 +224,13 @@ static void aspeed_wdt_timer_expired(void *dev) {AspeedWDTState *s =ASPEED_WDT (dev); +/* Do not reset on SDRAM controller reset */ +if (s->scu->regs[SCU_RESET_CONTROL1 ] &SCU_RESET_SDRAM ) { +timer_del (s->timer); + s->regs[WDT_CTRL ] =0 ; +return ; + } +qemu_log_mask (CPU_LOG_RESET ,"Watchdog timer expired.\n" );watchdog_perform_action ();timer_del (s->timer);
@@ -232,6 +242,16 @@ static void aspeed_wdt_realize(DeviceState *dev, Error **errp) {SysBusDevice *sbd =SYS_BUS_DEVICE (dev);AspeedWDTState *s =ASPEED_WDT (dev); +Error *err =NULL ; +Object *obj; + + obj =object_property_get_link (OBJECT (dev),"scu" , &err); +if (!obj) { +error_propagate (errp, err); +error_prepend (errp,"required link 'scu' not found: " ); +return ; + } + s->scu =ASPEED_SCU (obj);if (!is_supported_silicon_rev (s->silicon_rev)) { error_setg(errp, "Unknown silicon revision: 0x%" PRIx32,
include/hw/watchdog/wdt_aspeed.h +1 -0
@@ -26,6 +26,7 @@ typedef struct AspeedWDTState {MemoryRegion iomem;uint32_t regs[ASPEED_WDT_REGS_MAX ]; +AspeedSCUState *scu;uint32_t pclk_freq;uint32_t silicon_rev;uint32_t ext_pulse_width_mask;
Signature · 1 line
2.17.1
Re: [Qemu-arm] [PATCH 7/7] aspeed: Link SCU to the watchdog
Quoted 5 lines · Joel Stanley
The ast2500 uses the watchdog to reset the SDRAM controller. This operation is usually performed by u-boot's memory training procedure, and it is enabled by setting a bit in the SCU and then causing the watchdog to expire. Therefore, we need the watchdog to be able to acess the SCU's register space.
... access ...
Quoted 2 lines
This does not cause a system reset, but only resets the SDRAM controller.
Well, it does nothing below :)
I think we should call device_reset() on all the devices that have their reset bit enabled in the SCU System Reset Control Register and in the Reset Mask Register of the watchdog being used.
Watchdog Reset Mask Register bits :
31:26 Reserved
25 Enable reset Misc. SOC controller (WDT, RTC, Timer, UART, SRAM) 24 Enable reset SPI controller
23 Enable reset X-DMA controller
22 Enable reset MCTP controller
21 Enable reset GPIO controller
20 Enable reset ADC controller
19 Enable reset JTAG master controller
18 Enable reset PECI controller
17 Enable reset PWM controller
16 Enable reset CRT mode 2D engine
15 Enable reset MIC controller
14 Enable reset SD/SDIO controller
13 Enable reset LPC controller
12 Enable reset HAC engine
11 Enable reset Video engine
10 Enable reset USB1.1 HID/USB2.0 Host EHCI2 controller
9 Enable reset USB1.1 Host controller
8 Enable reset USB2.0 Host/Hub controller
7 Enable reset Graphics CRT controller
6 Enable reset MAC#2 controller
5 Enable reset MAC#1 controller
4 Enable reset I2C controller
3 Enable reset AHB bridges
2 Enable reset SDRAM controller
1 Enable reset Coprocessor
0 Enable reset ARM
Default value is 0x23FFFF3 which means reset all devices a part from :
SPI controller
X-DMA controller
MCTP controller
AHB bridges
SDRAM controller
SCU System Reset Control Register ( has a different layout :/)
25 Reset X-DMA controller
24 Reset MCTP controller
23 Reset ADC controller
22 Reset JTAG Master controller
21 Reserved
20 PEWAKE# pin output enable control
19 PEWAKE# pin output value
18 Reset MIC controller
17 Reserved, must keep at value ”1”
16 Reset SD/SDIO card controller
15 Reset USB1.1 Host controller
14 Reset USB2.0 Hub/Host controller
13 Reset CRT controller
12 Reset MAC#2 controller
11 Reset MAC#1 controller
10 Reset PECI controller
9 Reset PWM controller
8 Disable PCI bus controller and VGA controller
7 Reset 2D engine
6 Reset Video engine
5 Reset LPC controller
4 Reset HAC engine
3 Reset USB1.1 HID controller
2 Reset I2C/SMBus controller
1 Reset AHB bridges
0 Enable reset SDRAM controller when full chip Watchdog reset occur
Default value is 0xFFCFFEDC which means reset all devices a part from :
5 Reset LPC controller
1 Reset AHB bridges
0 Enable reset SDRAM controller
Quoted 25 lines
Signed-off-by Joel Stanley <[email protected]>--- hw/arm/aspeed_soc.c | 2 ++ hw/watchdog/wdt_aspeed.c | 20 ++++++++++++++++++++ include/hw/watchdog/wdt_aspeed.h | 1 + 3 files changed, 23 insertions(+)hw/arm/aspeed_soc.c +2
-0@@ -164,6 +164,8 @@ static void aspeed_soc_init(Object *obj)qdev_set_parent_bus (DEVICE (&s->wdt[i]),sysbus_get_default ());qdev_prop_set_uint32 (DEVICE (&s->wdt[i]),"silicon-rev" , sc->info->silicon_rev); +object_property_add_const_link (OBJECT (&s->wdt[i]),"scu" , +OBJECT (&s->scu), &error_abort); }object_initialize (&s->ftgmac100,sizeof (s->ftgmac100),TYPE_FTGMAC100 );hw/watchdog/wdt_aspeed.c +0
-0
hw/watchdog/wdt_aspeed.c line 46
Quoted 4 lines
hw/watchdog/wdt_aspeed.c +1
-0@@ -43,6 +43,9 @@#define WDT_RESTART_MAGIC 0x4755 +#define SCU_RESET_CONTROL1 (0x04 / 4)
Too bad that the Aspeed SCU registers are already defined in the .c file.
Quoted 49 lines
hw/watchdog/wdt_aspeed.c +19
-0+#define SCU_RESET_SDRAM BIT(0) +static bool aspeed_wdt_is_enabled (const AspeedWDTState *s) {return s->regs[WDT_CTRL ] &WDT_CTRL_ENABLE ;@@ -221,6 +224,13 @@ static void aspeed_wdt_timer_expired(void *dev) {AspeedWDTState *s =ASPEED_WDT (dev); +/* Do not reset on SDRAM controller reset */ +if (s->scu->regs[SCU_RESET_CONTROL1 ] &SCU_RESET_SDRAM ) { +timer_del (s->timer); + s->regs[WDT_CTRL ] =0 ; +return ; + } +qemu_log_mask (CPU_LOG_RESET ,"Watchdog timer expired.\n" );watchdog_perform_action ();timer_del (s->timer);@@ -232,6 +242,16 @@ static void aspeed_wdt_realize(DeviceState *dev, Error **errp) {SysBusDevice *sbd =SYS_BUS_DEVICE (dev);AspeedWDTState *s =ASPEED_WDT (dev); +Error *err =NULL ; +Object *obj; + + obj =object_property_get_link (OBJECT (dev),"scu" , &err); +if (!obj) { +error_propagate (errp, err); +error_prepend (errp,"required link 'scu' not found: " ); +return ; + } + s->scu =ASPEED_SCU (obj);if (!is_supported_silicon_rev (s->silicon_rev)) { error_setg(errp, "Unknown silicon revision: 0x%" PRIx32,include/hw/watchdog/wdt_aspeed.h +1
-0@@ -26,6 +26,7 @@ typedef struct AspeedWDTState {MemoryRegion iomem;uint32_t regs[ASPEED_WDT_REGS_MAX ]; +AspeedSCUState *scu;uint32_t pclk_freq;uint32_t silicon_rev;uint32_t ext_pulse_width_mask;
Quoted 3 lines · Joel Stanley
This series allow us to run upstream u-boot on the ast2500-evb model. They have been tested with upstream u-boot, as well as openbmc's ast2500 and ast2500 images.
For all patches,
Patch [1-6] are good to merge.
I think patch 7 is a good start. It enables support for mainline U-Boot that we can use to develop more U-Boot drivers (flash). But the device reset model needs a little more work to take into account the Reset Mask Register of the watchdog.
We don't have to support all of them, only the SoC and SDRAM to start with.
Thanks,
C.
Quoted 20 lines
Cédric Le Goater (1):
aspeed: add amax_ram_sizeproperty to the memory controllerJoel Stanley (6):
aspeed_sdmc: Extend number of valid registers
aspeed_sdmc: Fix saved values
aspeed_sdmc: Set 'cache initial sequence' always true
aspeed_sdmc: Init status alwlays idle
aspeed_sdmc: Handle ECC training
aspeed: Link SCU to the watchdoghw/arm/aspeed.c | 31 ++++++++++++++++++ hw/arm/aspeed_soc.c | 4 +++ hw/misc/aspeed_sdmc.c | 55 +++++++++++++++++++++----------- hw/watchdog/wdt_aspeed.c | 20 ++++++++++++ include/hw/misc/aspeed_sdmc.h | 4 ++- include/hw/watchdog/wdt_aspeed.h | 1 + 6 files changed, 95 insertions(+), 20 deletions(-)
Peter Maydell
AppliedQuoted 10 lines · Cédric Le Goater
Quoted 3 lines · Joel Stanley
This series allow us to run upstream u-boot on the ast2500-evb model. They have been tested with upstream u-boot, as well as openbmc's ast2500 and ast2500 images.
For all patches,
Tested-by Cédric Le Goater <[email protected]>Patch [1-6] are good to merge.
I've applied 1-6 to target-arm.next.
thanks
-- PMM