aspeed/smc: Cleanups and QOMification
cover aspeed/smc: Cleanups and QOMification
Hello,
It looks big but there are no major changes.
This series adds a simple support for the 2nd watchdog registers which were moved under the AST2600 FMC controller to deactivate the alternate boot function. Then come cleanups of the AspeedSMC model mostly removing a useless AspeedSMCController structure (that's the noisy part) and QOMifying the AspeedSMCFlash structure.
Thanks,
C.
Cédric Le Goater (10):
aspeed/smc: Add watchdog Control/Status Registers aspeed/smc: Introduce aspeed_smc_error() helper aspeed/smc: Stop using the model name for the memory regions aspeed/smc: Drop AspeedSMCController structure aspeed/smc: Remove the 'flash' attribute from AspeedSMCFlash aspeed/smc: Remove the 'size' attribute from AspeedSMCFlash aspeed/smc: Rename AspeedSMCFlash 'id' to 'cs' aspeed/smc: QOMify AspeedSMCFlash
aspeed/smc: Add default reset values
aspeed/smc: Introduce an addr_width() class handler
include/hw/ssi/aspeed_smc.h | 81 ++- hw/arm/aspeed.c | 18 +- hw/arm/aspeed_ast2600.c | 4 +- hw/arm/aspeed_soc.c | 4 +- hw/ssi/aspeed_smc.c | 1129 ++++++++++++++++++++--------------- 5 files changed, 701 insertions(+), 535 deletions(-)
Signature · 1 line
2.31.1
PATCH 1/10 aspeed/smc: Add watchdog Control/Status Registers
The Aspeed SoCs have a dual boot function for firmware fail-over recovery. The system auto-reboots from the second flash if the main flash does not boot sucessfully within a certain amount of time. This function is called alternate boot (ABR) in the FMC controllers.
On AST2400/AST2500, ABR is enabled by hardware strapping in SCU70 to enable the 2nd watchdog timer, on AST2600, through register SCU510. If the boot on the the main flash succeeds, the firmware should disable the 2nd watchdog timer. If not, the BMC is reset and the CE0 and CE1 mappings are swapped to restart the BMC from the 2nd flash.
On the AST2600, the registers controlling the 2nd watchdog timer were moved from the watchdog register to the FMC controller. Add simple read/write handlers for these to let the FW disable the 2nd watchdog without error.
--- hw/ssi/aspeed_smc.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
hw/ssi/aspeed_smc.c +16 -0
@@ -124,6 +124,13 @@/* SPI dummy cycle data */ #define R_DUMMY_DATA (0x54 / 4) +/* FMC_WDT2 Control/Status Register for Alternate Boot (AST2600) */ +#define R_FMC_WDT2_CTRL (0x64 / 4) +#define FMC_WDT2_CTRL_ALT_BOOT_MODE BIT(6)/* O: 2 chips 1: 1 chip */ +#define FMC_WDT2_CTRL_SINGLE_BOOT_MODE BIT(5) +#define FMC_WDT2_CTRL_BOOT_SOURCE BIT(4)/* O: primary 1: alternate */ +#define FMC_WDT2_CTRL_EN BIT(0) +/* DMA Control/Status Register */ #define R_DMA_CTRL (0x80 / 4)#define DMA_CTRL_REQUEST (1 << 31)
@@ -263,12 +270,18 @@ static void aspeed_2600_smc_dma_ctrl(AspeedSMCState *s, uint32_t value);#define ASPEED_SMC_FEATURE_DMA 0x1#define ASPEED_SMC_FEATURE_DMA_GRANT 0x2 +#define ASPEED_SMC_FEATURE_WDT_CONTROL 0x4static inline bool aspeed_smc_has_dma (const AspeedSMCState *s) {return !!(s->ctrl->features &ASPEED_SMC_FEATURE_DMA ); } +static inline bool aspeed_smc_has_wdt_control (const AspeedSMCState *s) +{ +return !!(s->ctrl->features &ASPEED_SMC_FEATURE_WDT_CONTROL ); +} +static const AspeedSMCController controllers[] = { { .name ="aspeed.smc-ast2400" ,
@@ -1019,6 +1032,7 @@ static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size) addr ==R_CE_CMD_CTRL || addr ==R_INTR_CTRL || addr ==R_DUMMY_DATA || + (aspeed_smc_has_wdt_control (s) && addr ==R_FMC_WDT2_CTRL ) || (aspeed_smc_has_dma (s) && addr ==R_DMA_CTRL ) || (aspeed_smc_has_dma (s) && addr ==R_DMA_FLASH_ADDR ) || (aspeed_smc_has_dma(s) && addr == R_DMA_DRAM_ADDR) ||
@@ -1350,6 +1364,8 @@ static void aspeed_smc_write(void *opaque, hwaddr addr, uint64_t data, s->regs[addr] = value &0xff ; }else if (addr ==R_DUMMY_DATA ) { s->regs[addr] = value &0xff ; + }else if (aspeed_smc_has_wdt_control (s) && addr ==R_FMC_WDT2_CTRL ) { + s->regs[addr] = value &0xb ; }else if (addr ==R_INTR_CTRL ) { s->regs[addr] = value; }else if (aspeed_smc_has_dma (s) && addr ==R_DMA_CTRL ) {
Signature · 1 line
2.31.1
Re: [PATCH 01/10] aspeed/smc: Add watchdog Control/Status Registers
Quoted 83 lines · Cédric Le Goater
The Aspeed SoCs have a dual boot function for firmware fail-over recovery. The system auto-reboots from the second flash if the main flash does not boot sucessfully within a certain amount of time. This function is called alternate boot (ABR) in the FMC controllers.
On AST2400/AST2500, ABR is enabled by hardware strapping in SCU70 to enable the 2nd watchdog timer, on AST2600, through register SCU510. If the boot on the the main flash succeeds, the firmware should disable the 2nd watchdog timer. If not, the BMC is reset and the CE0 and CE1 mappings are swapped to restart the BMC from the 2nd flash.
On the AST2600, the registers controlling the 2nd watchdog timer were moved from the watchdog register to the FMC controller. Add simple read/write handlers for these to let the FW disable the 2nd watchdog without error.
Reported-by Peter Delevoryas <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>---
hw/ssi/aspeed_smc.c| 16 ++++++++++++++++1 file changed, 16 insertions(+)hw/ssi/aspeed_smc.c +16
-0@@ -124,6 +124,13 @@/* SPI dummy cycle data */ #define R_DUMMY_DATA (0x54 / 4) +/* FMC_WDT2 Control/Status Register for Alternate Boot (AST2600) */ +#define R_FMC_WDT2_CTRL (0x64 / 4) +#define FMC_WDT2_CTRL_ALT_BOOT_MODE BIT(6)/* O: 2 chips 1: 1 chip */ +#define FMC_WDT2_CTRL_SINGLE_BOOT_MODE BIT(5) +#define FMC_WDT2_CTRL_BOOT_SOURCE BIT(4)/* O: primary 1: alternate */ +#define FMC_WDT2_CTRL_EN BIT(0) +/* DMA Control/Status Register */ #define R_DMA_CTRL (0x80 / 4)#define DMA_CTRL_REQUEST (1 << 31)@@ -263,12 +270,18 @@ static void aspeed_2600_smc_dma_ctrl(AspeedSMCState *s, uint32_t value);#define ASPEED_SMC_FEATURE_DMA 0x1#define ASPEED_SMC_FEATURE_DMA_GRANT 0x2 +#define ASPEED_SMC_FEATURE_WDT_CONTROL 0x4static inline bool aspeed_smc_has_dma (const AspeedSMCState *s) {return !!(s->ctrl->features &ASPEED_SMC_FEATURE_DMA ); } +static inline bool aspeed_smc_has_wdt_control (const AspeedSMCState *s) +{ +return !!(s->ctrl->features &ASPEED_SMC_FEATURE_WDT_CONTROL ); +} +static const AspeedSMCController controllers[] = { { .name ="aspeed.smc-ast2400" ,@@ -1019,6 +1032,7 @@ static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size) addr ==R_CE_CMD_CTRL || addr ==R_INTR_CTRL || addr ==R_DUMMY_DATA || + (aspeed_smc_has_wdt_control (s) && addr ==R_FMC_WDT2_CTRL ) || (aspeed_smc_has_dma (s) && addr ==R_DMA_CTRL ) || (aspeed_smc_has_dma (s) && addr ==R_DMA_FLASH_ADDR ) || (aspeed_smc_has_dma(s) && addr == R_DMA_DRAM_ADDR) ||@@ -1350,6 +1364,8 @@ static void aspeed_smc_write(void *opaque, hwaddr addr, uint64_t data, s->regs[addr] = value &0xff ; }else if (addr ==R_DUMMY_DATA ) { s->regs[addr] = value &0xff ; + }else if (aspeed_smc_has_wdt_control (s) && addr ==R_FMC_WDT2_CTRL ) { + s->regs[addr] = value &0xb ; }else if (addr ==R_INTR_CTRL ) { s->regs[addr] = value; }else if (aspeed_smc_has_dma (s) && addr ==R_DMA_CTRL ) {Signature · 1 line
2.31.1
Looks good to me!
One thing: should we enable this feature (ASPEED_SMC_FEATURE_WDT_CONTROL) on any of the SMC controller models? I wanted to test this with the Fuji image and machine type I added, and I needed the following diff to enable this:
hw/ssi/aspeed_smc.c +1 -1
@@ -388,7 +388,7 @@ static const AspeedSMCController controllers[] = { .segments = aspeed_segments_ast2600_fmc, .flash_window_base = ASPEED26_SOC_FMC_FLASH_BASE, .flash_window_size = 0x10000000, - .features = ASPEED_SMC_FEATURE_DMA, + .features = ASPEED_SMC_FEATURE_DMA | ASPEED_SMC_FEATURE_WDT_CONTROL, .dma_flash_mask = 0x0FFFFFFC, .dma_dram_mask = 0x3FFFFFFC, .nregs = ASPEED_SMC_R_MAX,
Without this, Fuji would try to clear BIT(0) of R_FMC_WDT2_CTRL, but then the default aspeed_smc_read() value would return 0xFFFFFFF.
Error: unable to disable the 2nd watchdog: FMC_WDT2=0xFFFFFFFF
And then with these changes added, the writes and reads work so that BIT(0) appears to have been cleared:
Disabled the 2nd watchdog (FMC_WDT2) successfully.
root@bmc-oob:~# devmem 0x1e620064 0x00000000 root@bmc-oob:~# devmem 0x1e620064 32 0xffffffff root@bmc-oob:~# devmem 0x1e620064 0x0000000B
I don’t totally understand why the mask for the register is 0xb though?
Quoted 1 line
Quoted 1 line
Quoted 1 line
bin(0xb)
‘0b1011'
This doesn’t seem to match the macro BIT(...) #define’s included. Those #define’s are correct (I cross-referenced with the datasheet to double check), wouldn’t it be something like this? (zero’s for the reserved bits?)
Quoted 1 line
Quoted 1 line
Quoted 1 line
hex(0b1111111101110001)
'0xff71'
Thanks,
Peter
Re: [PATCH 01/10] aspeed/smc: Add watchdog Control/Status Registers
Quoted 86 lines · Peter Delevoryas
Quoted 83 lines · Cédric Le Goater
The Aspeed SoCs have a dual boot function for firmware fail-over recovery. The system auto-reboots from the second flash if the main flash does not boot sucessfully within a certain amount of time. This function is called alternate boot (ABR) in the FMC controllers.
On AST2400/AST2500, ABR is enabled by hardware strapping in SCU70 to enable the 2nd watchdog timer, on AST2600, through register SCU510. If the boot on the the main flash succeeds, the firmware should disable the 2nd watchdog timer. If not, the BMC is reset and the CE0 and CE1 mappings are swapped to restart the BMC from the 2nd flash.
On the AST2600, the registers controlling the 2nd watchdog timer were moved from the watchdog register to the FMC controller. Add simple read/write handlers for these to let the FW disable the 2nd watchdog without error.
Reported-by Peter Delevoryas <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>---
hw/ssi/aspeed_smc.c| 16 ++++++++++++++++1 file changed, 16 insertions(+)hw/ssi/aspeed_smc.c +16
-0@@ -124,6 +124,13 @@/* SPI dummy cycle data */ #define R_DUMMY_DATA (0x54 / 4) +/* FMC_WDT2 Control/Status Register for Alternate Boot (AST2600) */ +#define R_FMC_WDT2_CTRL (0x64 / 4) +#define FMC_WDT2_CTRL_ALT_BOOT_MODE BIT(6)/* O: 2 chips 1: 1 chip */ +#define FMC_WDT2_CTRL_SINGLE_BOOT_MODE BIT(5) +#define FMC_WDT2_CTRL_BOOT_SOURCE BIT(4)/* O: primary 1: alternate */ +#define FMC_WDT2_CTRL_EN BIT(0) +/* DMA Control/Status Register */ #define R_DMA_CTRL (0x80 / 4)#define DMA_CTRL_REQUEST (1 << 31)@@ -263,12 +270,18 @@ static void aspeed_2600_smc_dma_ctrl(AspeedSMCState *s, uint32_t value);#define ASPEED_SMC_FEATURE_DMA 0x1#define ASPEED_SMC_FEATURE_DMA_GRANT 0x2 +#define ASPEED_SMC_FEATURE_WDT_CONTROL 0x4static inline bool aspeed_smc_has_dma (const AspeedSMCState *s) {return !!(s->ctrl->features &ASPEED_SMC_FEATURE_DMA ); } +static inline bool aspeed_smc_has_wdt_control (const AspeedSMCState *s) +{ +return !!(s->ctrl->features &ASPEED_SMC_FEATURE_WDT_CONTROL ); +} +static const AspeedSMCController controllers[] = { { .name ="aspeed.smc-ast2400" ,@@ -1019,6 +1032,7 @@ static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size) addr ==R_CE_CMD_CTRL || addr ==R_INTR_CTRL || addr ==R_DUMMY_DATA || + (aspeed_smc_has_wdt_control (s) && addr ==R_FMC_WDT2_CTRL ) || (aspeed_smc_has_dma (s) && addr ==R_DMA_CTRL ) || (aspeed_smc_has_dma (s) && addr ==R_DMA_FLASH_ADDR ) || (aspeed_smc_has_dma(s) && addr == R_DMA_DRAM_ADDR) ||@@ -1350,6 +1364,8 @@ static void aspeed_smc_write(void *opaque, hwaddr addr, uint64_t data, s->regs[addr] = value &0xff ; }else if (addr ==R_DUMMY_DATA ) { s->regs[addr] = value &0xff ; + }else if (aspeed_smc_has_wdt_control (s) && addr ==R_FMC_WDT2_CTRL ) { + s->regs[addr] = value &0xb ; }else if (addr ==R_INTR_CTRL ) { s->regs[addr] = value; }else if (aspeed_smc_has_dma (s) && addr ==R_DMA_CTRL ) {Signature · 1 line
2.31.1Looks good to me!
Quoted 6 lines
Reviewed-by Peter Delevoryas <[email protected]>One thing: should we enable this feature (
ASPEED_SMC_FEATURE_WDT_CONTROL) on any of the SMC controller models? I wanted to test this with the Fuji image and machine type I added, and I needed the following diff to enable this:
Ah yes. It fell through the cracks with PATCH 04 "aspeed/smc: Drop AspeedSMCController structure" which moves a lot of code around. I will add it back in the next spin.
Quoted 24 lines
hw/ssi/aspeed_smc.c +1
-1@@ -388,7 +388,7 @@ static const AspeedSMCController controllers[] = { .segments = aspeed_segments_ast2600_fmc, .flash_window_base = ASPEED26_SOC_FMC_FLASH_BASE, .flash_window_size = 0x10000000, - .features = ASPEED_SMC_FEATURE_DMA, + .features = ASPEED_SMC_FEATURE_DMA | ASPEED_SMC_FEATURE_WDT_CONTROL, .dma_flash_mask = 0x0FFFFFFC, .dma_dram_mask = 0x3FFFFFFC, .nregs = ASPEED_SMC_R_MAX,Without this, Fuji would try to clear BIT(0) of
R_FMC_WDT2_CTRL, but then the defaultaspeed_smc_read()value would return0xFFFFFFF.Error: unable to disable the 2nd watchdog: FMC_WDT2=0xFFFFFFFF
And then with these changes added, the writes and reads work so that BIT(0) appears to have been cleared:
Disabled the 2nd watchdog (
FMC_WDT2) successfully.
Quoted 7 lines
root@bmc-oob:~# devmem 0x1e620064 0x00000000 root@bmc-oob:~# devmem 0x1e620064 32 0xffffffff root@bmc-oob:~# devmem 0x1e620064 0x0000000BI don’t totally understand why the mask for the register is
0xbthough?
It is bogus. I changed it to :
s->regs[addr] = value & FMC_WDT2_CTRL_EN;
since we only care about the watchdog enablement status bit. So now :
root@bmc-oob:~# devmem 0x1e620064 0x00000000 root@bmc-oob:~# devmem 0x1e620064 32 0xffffffff root@bmc-oob:~# devmem 0x1e620064 0x00000001
It would be interesting also to implement the WDT2 reset. We can link the WDT2 register memory region in the AST2600 FMC model to have the controls. We need to boot much faster else WDT2 will fire.
When merged, we can ask Peter for some help on understanding why it is so slow compared to the other AST2600 machines.
The others FMC_WDT2 bits will need more work.
Thanks for the review and tests,
C.
PATCH 2/10 aspeed/smc: Introduce aspeed_smc_error() helper
In reply to Cédric Le GoaterIt unifies the errors reported by the Aspeed SMC model and also removes some use of ctrl->name which will help us for the next patches.
--- hw/ssi/aspeed_smc.c | 97 +++++++++++++++++++++------------------------ 1 file changed, 45 insertions(+), 52 deletions(-)
hw/ssi/aspeed_smc.c +45 -52
@@ -512,6 +512,9 @@ static void aspeed_2600_smc_reg_to_segment(const AspeedSMCState *s, } } +#define aspeed_smc_error (fmt, ...) \ + qemu_log_mask(LOG_GUEST_ERROR, "%s: " fmt "\n", __func__, ## __VA_ARGS__) +static bool aspeed_smc_flash_overlap (const AspeedSMCState *s,const AspeedSegments *new,int cs)
@@ -528,11 +531,11 @@ static bool aspeed_smc_flash_overlap(const AspeedSMCState *s,if (new->addr + new->size > seg.addr && new->addr < seg.addr + seg.size) { -qemu_log_mask (LOG_GUEST_ERROR ,"%s: new segment CS%d [ 0x%" - HWADDR_PRIx" - 0x%" HWADDR_PRIx" ] overlaps with " -"CS%d [ 0x%" HWADDR_PRIx" - 0x%" HWADDR_PRIx" ]\n" , - s->ctrl->name, cs, new->addr, new->addr + new->size, - i, seg.addr, seg.addr + seg.size); +aspeed_smc_error ("new segment CS%d [ 0x%" + HWADDR_PRIx" - 0x%" HWADDR_PRIx" ] overlaps with " +"CS%d [ 0x%" HWADDR_PRIx" - 0x%" HWADDR_PRIx" ]" , + cs, new->addr, new->addr + new->size, + i, seg.addr, seg.addr + seg.size);return true; } }
@@ -567,9 +570,8 @@ static void aspeed_smc_flash_set_segment(AspeedSMCState *s, int cs,/* The start address of CS0 is read-only */ if (cs ==0 && seg.addr != s->ctrl->flash_window_base) { -qemu_log_mask (LOG_GUEST_ERROR , -"%s: Tried to change CS0 start address to 0x%" - HWADDR_PRIx"\n" , s->ctrl->name, seg.addr); +aspeed_smc_error ("Tried to change CS0 start address to 0x%" + HWADDR_PRIx, seg.addr); seg.addr = s->ctrl->flash_window_base; new = s->ctrl->segment_to_reg (s, &seg); }
@@ -583,9 +585,8 @@ static void aspeed_smc_flash_set_segment(AspeedSMCState *s, int cs, cs == s->ctrl->max_peripherals && seg.addr + seg.size != s->ctrl->segments[cs].addr + s->ctrl->segments[cs].size) { -qemu_log_mask (LOG_GUEST_ERROR , -"%s: Tried to change CS%d end address to 0x%" - HWADDR_PRIx"\n" , s->ctrl->name, cs, seg.addr + seg.size); +aspeed_smc_error ("Tried to change CS%d end address to 0x%" + HWADDR_PRIx, cs, seg.addr + seg.size); seg.size = s->ctrl->segments[cs].addr + s->ctrl->segments[cs].size - seg.addr; new = s->ctrl->segment_to_reg (s, &seg);
@@ -595,17 +596,17 @@ static void aspeed_smc_flash_set_segment(AspeedSMCState *s, int cs,if (seg.size && (seg.addr + seg.size <= s->ctrl->flash_window_base || seg.addr > s->ctrl->flash_window_base + s->ctrl->flash_window_size)) { -qemu_log_mask (LOG_GUEST_ERROR ,"%s: new segment for CS%d is invalid : " -"[ 0x%" HWADDR_PRIx" - 0x%" HWADDR_PRIx" ]\n" , - s->ctrl->name, cs, seg.addr, seg.addr + seg.size); +aspeed_smc_error ("new segment for CS%d is invalid : " +"[ 0x%" HWADDR_PRIx" - 0x%" HWADDR_PRIx" ]" , + cs, seg.addr, seg.addr + seg.size);return ; }/* Check start address vs. alignment */ if (seg.size && !QEMU_IS_ALIGNED (seg.addr, seg.size)) { -qemu_log_mask (LOG_GUEST_ERROR ,"%s: new segment for CS%d is not " -"aligned : [ 0x%" HWADDR_PRIx" - 0x%" HWADDR_PRIx" ]\n" , - s->ctrl->name, cs, seg.addr, seg.addr + seg.size); +aspeed_smc_error ("new segment for CS%d is not " +"aligned : [ 0x%" HWADDR_PRIx" - 0x%" HWADDR_PRIx" ]" , + cs, seg.addr, seg.addr + seg.size); }/* And segments should not overlap (in the specs) */
@@ -618,16 +619,15 @@ static void aspeed_smc_flash_set_segment(AspeedSMCState *s, int cs,static uint64_t aspeed_smc_flash_default_read (void *opaque,hwaddr addr,unsigned size) { -qemu_log_mask (LOG_GUEST_ERROR ,"%s: To 0x%" HWADDR_PRIx" of size %u" - PRIx64"\n" , __func__, addr, size); +aspeed_smc_error ("To 0x%" HWADDR_PRIx" of size %u" PRIx64, addr, size);return 0 ; }static void aspeed_smc_flash_default_write (void *opaque,hwaddr addr,uint64_t data,unsigned size) { -qemu_log_mask (LOG_GUEST_ERROR ,"%s: To 0x%" HWADDR_PRIx" of size %u: 0x%" - PRIx64"\n" , __func__, addr, size, data); +aspeed_smc_error ("To 0x%" HWADDR_PRIx" of size %u: 0x%" PRIx64, + addr, size, data); }static const MemoryRegionOps aspeed_smc_flash_default_ops = {
@@ -670,8 +670,8 @@ static inline int aspeed_smc_flash_cmd(const AspeedSMCFlash *fl) }if (!cmd) { -qemu_log_mask (LOG_GUEST_ERROR ,"%s: no command defined for mode %d\n" , - __func__,aspeed_smc_flash_mode (fl)); +aspeed_smc_error ("no command defined for mode %d" , +aspeed_smc_flash_mode (fl)); }return cmd;
@@ -715,11 +715,9 @@ static uint32_t aspeed_smc_check_segment_addr(const AspeedSMCFlash *fl, s->ctrl->reg_to_segment (s, s->regs[R_SEG_ADDR0 + fl->id], &seg);if ((addr % seg.size) != addr) { -qemu_log_mask (LOG_GUEST_ERROR , -"%s: invalid address 0x%08x for CS%d segment : " -"[ 0x%" HWADDR_PRIx" - 0x%" HWADDR_PRIx" ]\n" , - s->ctrl->name, addr, fl->id, seg.addr, - seg.addr + seg.size); +aspeed_smc_error ("invalid address 0x%08x for CS%d segment : " +"[ 0x%" HWADDR_PRIx" - 0x%" HWADDR_PRIx" ]" , + addr, fl->id, seg.addr, seg.addr + seg.size); addr %= seg.size; }
@@ -795,8 +793,7 @@ static uint64_t aspeed_smc_flash_read(void *opaque, hwaddr addr, unsigned size)aspeed_smc_flash_unselect (fl);break ;default : -qemu_log_mask (LOG_GUEST_ERROR ,"%s: invalid flash mode %d\n" , - __func__,aspeed_smc_flash_mode (fl)); +aspeed_smc_error ("invalid flash mode %d" ,aspeed_smc_flash_mode (fl)); } trace_aspeed_smc_flash_read(fl->id, addr, size, ret,
@@ -913,8 +910,7 @@ static void aspeed_smc_flash_write(void *opaque, hwaddr addr, uint64_t data, aspeed_smc_flash_mode(fl));if (!aspeed_smc_is_writable (fl)) { -qemu_log_mask (LOG_GUEST_ERROR ,"%s: flash is not writable at 0x%" - HWADDR_PRIx"\n" , __func__, addr); +aspeed_smc_error ("flash is not writable at 0x%" HWADDR_PRIx, addr);return ; }
@@ -939,8 +935,7 @@ static void aspeed_smc_flash_write(void *opaque, hwaddr addr, uint64_t data,aspeed_smc_flash_unselect (fl);break ;default : -qemu_log_mask (LOG_GUEST_ERROR ,"%s: invalid flash mode %d\n" , - __func__,aspeed_smc_flash_mode (fl)); +aspeed_smc_error ("invalid flash mode %d" ,aspeed_smc_flash_mode (fl)); } }
@@ -1066,7 +1061,7 @@ static uint8_t aspeed_smc_hclk_divisor(uint8_t hclk_mask) } } -qemu_log_mask (LOG_GUEST_ERROR ,"invalid HCLK mask %x" , hclk_mask); +aspeed_smc_error ("invalid HCLK mask %x" , hclk_mask);return 0 ; }
@@ -1146,8 +1141,7 @@ static void aspeed_smc_dma_checksum(AspeedSMCState *s)uint32_t data;if (s->regs[R_DMA_CTRL ] &DMA_CTRL_WRITE ) { -qemu_log_mask (LOG_GUEST_ERROR , -"%s: invalid direction for DMA checksum\n" , __func__); +aspeed_smc_error ("invalid direction for DMA checksum" );return ; }
@@ -1159,8 +1153,8 @@ static void aspeed_smc_dma_checksum(AspeedSMCState *s) data =address_space_ldl_le (&s->flash_as, s->regs[R_DMA_FLASH_ADDR ],MEMTXATTRS_UNSPECIFIED , &result);if (result !=MEMTX_OK ) { -qemu_log_mask (LOG_GUEST_ERROR ,"%s: Flash read failed @%08x\n" , - __func__, s->regs[R_DMA_FLASH_ADDR ]); +aspeed_smc_error ("Flash read failed @%08x" , + s->regs[R_DMA_FLASH_ADDR ]);return ; }trace_aspeed_smc_dma_checksum (s->regs[R_DMA_FLASH_ADDR ], data);
@@ -1195,32 +1189,32 @@ static void aspeed_smc_dma_rw(AspeedSMCState *s) data =address_space_ldl_le (&s->dram_as, s->regs[R_DMA_DRAM_ADDR ],MEMTXATTRS_UNSPECIFIED , &result);if (result !=MEMTX_OK ) { -qemu_log_mask (LOG_GUEST_ERROR ,"%s: DRAM read failed @%08x\n" , - __func__, s->regs[R_DMA_DRAM_ADDR ]); +aspeed_smc_error ("DRAM read failed @%08x" , + s->regs[R_DMA_DRAM_ADDR ]);return ; }address_space_stl_le (&s->flash_as, s->regs[R_DMA_FLASH_ADDR ], data,MEMTXATTRS_UNSPECIFIED , &result);if (result !=MEMTX_OK ) { -qemu_log_mask (LOG_GUEST_ERROR ,"%s: Flash write failed @%08x\n" , - __func__, s->regs[R_DMA_FLASH_ADDR ]); +aspeed_smc_error ("Flash write failed @%08x" , + s->regs[R_DMA_FLASH_ADDR ]);return ; } }else { data =address_space_ldl_le (&s->flash_as, s->regs[R_DMA_FLASH_ADDR ],MEMTXATTRS_UNSPECIFIED , &result);if (result !=MEMTX_OK ) { -qemu_log_mask (LOG_GUEST_ERROR ,"%s: Flash read failed @%08x\n" , - __func__, s->regs[R_DMA_FLASH_ADDR ]); +aspeed_smc_error ("Flash read failed @%08x" , + s->regs[R_DMA_FLASH_ADDR ]);return ; }address_space_stl_le (&s->dram_as, s->regs[R_DMA_DRAM_ADDR ], data,MEMTXATTRS_UNSPECIFIED , &result);if (result !=MEMTX_OK ) { -qemu_log_mask (LOG_GUEST_ERROR ,"%s: DRAM write failed @%08x\n" , - __func__, s->regs[R_DMA_DRAM_ADDR ]); +aspeed_smc_error ("DRAM write failed @%08x" , + s->regs[R_DMA_DRAM_ADDR ]);return ; } }
@@ -1280,7 +1274,7 @@ static void aspeed_smc_dma_ctrl(AspeedSMCState *s, uint32_t dma_ctrl) }if (aspeed_smc_dma_in_progress (s)) { -qemu_log_mask (LOG_GUEST_ERROR ,"%s: DMA in progress\n" , __func__); +aspeed_smc_error ("DMA in progress !" );return ; }
@@ -1302,7 +1296,7 @@ static inline bool aspeed_smc_dma_granted(AspeedSMCState *s) }if (!(s->regs[R_DMA_CTRL ] &DMA_CTRL_GRANT )) { -qemu_log_mask (LOG_GUEST_ERROR ,"%s: DMA not granted\n" , __func__); +aspeed_smc_error ("DMA not granted" );return false; }
@@ -1327,7 +1321,7 @@ static void aspeed_2600_smc_dma_ctrl(AspeedSMCState *s, uint32_t dma_ctrl) }if (!aspeed_smc_dma_granted (s)) { -qemu_log_mask (LOG_GUEST_ERROR ,"%s: DMA not granted\n" , __func__); +aspeed_smc_error ("DMA not granted" );return ; }
@@ -1433,8 +1427,7 @@ static void aspeed_smc_realize(DeviceState *dev, Error **errp)/* Enforce some real HW limits */ if (s->num_cs > s->ctrl->max_peripherals) { -qemu_log_mask (LOG_GUEST_ERROR ,"%s: num_cs cannot exceed: %d\n" , - __func__, s->ctrl->max_peripherals); +aspeed_smc_error ("num_cs cannot exceed: %d" , s->ctrl->max_peripherals); s->num_cs = s->ctrl->max_peripherals; }
Signature · 1 line
2.31.1
PATCH 3/10 aspeed/smc: Stop using the model name for the memory regions
In reply to Cédric Le GoaterThere is no real reason to use this name. It's simply nice to have in the monitor output but it's a burden for the following patch which removes the AspeedSMCController structure describing the controller.
--- hw/ssi/aspeed_smc.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-)
hw/ssi/aspeed_smc.c +10 -15
@@ -1391,20 +1391,15 @@ static const MemoryRegionOps aspeed_smc_ops = {*/ static void aspeed_smc_dma_setup (AspeedSMCState *s,Error **errp) { -char *name; -if (!s->dram_mr) {error_setg (errp,TYPE_ASPEED_SMC ": 'dram' link not set" );return ; } - name =g_strdup_printf ("%s-dma-flash" , s->ctrl->name); -address_space_init (&s->flash_as, &s->mmio_flash, name); -g_free (name); - - name =g_strdup_printf ("%s-dma-dram" , s->ctrl->name); -address_space_init (&s->dram_as, s->dram_mr, name); -g_free (name); +address_space_init (&s->flash_as, &s->mmio_flash, +TYPE_ASPEED_SMC ".dma-flash" ); +address_space_init (&s->dram_as, s->dram_mr, +TYPE_ASPEED_SMC ".dma-dram" ); }static void aspeed_smc_realize (DeviceState *dev,Error **errp)
@@ -1445,7 +1440,7 @@ static void aspeed_smc_realize(DeviceState *dev, Error **errp)/* The memory region for the controller registers */ memory_region_init_io (&s->mmio,OBJECT (s), &aspeed_smc_ops, s, - s->ctrl->name, s->ctrl->nregs *4 ); +TYPE_ASPEED_SMC , s->ctrl->nregs *4 );sysbus_init_mmio (sbd, &s->mmio);/*
@@ -1453,12 +1448,12 @@ static void aspeed_smc_realize(DeviceState *dev, Error **errp)* window in which the flash modules are mapped. The size and * address depends on the SoC model and controller type. */ -snprintf (name,sizeof (name),"%s.flash" , s->ctrl->name); -memory_region_init_io (&s->mmio_flash,OBJECT (s), - &aspeed_smc_flash_default_ops, s, name, + &aspeed_smc_flash_default_ops, s, +TYPE_ASPEED_SMC ".flash" , s->ctrl->flash_window_size); -memory_region_init_alias (&s->mmio_flash_alias,OBJECT (s), name, +memory_region_init_alias (&s->mmio_flash_alias,OBJECT (s), +TYPE_ASPEED_SMC ".flash" , &s->mmio_flash,0 , s->ctrl->flash_window_size);sysbus_init_mmio (sbd, &s->mmio_flash_alias);
@@ -1474,7 +1469,7 @@ static void aspeed_smc_realize(DeviceState *dev, Error **errp)for (i =0 ; i < s->ctrl->max_peripherals; ++i) {AspeedSMCFlash *fl = &s->flashes[i]; -snprintf (name,sizeof (name),"%s.%d" , s->ctrl->name, i); +snprintf (name,sizeof (name),TYPE_ASPEED_SMC ".flash.%d" , i); fl->id = i; fl->controller = s;
Signature · 1 line
2.31.1
PATCH 4/10 aspeed/smc: Drop AspeedSMCController structure
In reply to Cédric Le GoaterThe characteristics of the Aspeed controllers are described in a AspeedSMCController structure which is redundant with the AspeedSMCClass. Move all attributes under the class and adapt the code to use class attributes instead.
This is a large change but it is functionally equivalent.
--- include/hw/ssi/aspeed_smc.h | 64 ++- hw/arm/aspeed_ast2600.c | 4 +- hw/arm/aspeed_soc.c | 4 +- hw/ssi/aspeed_smc.c | 859 ++++++++++++++++++++---------------- 4 files changed, 510 insertions(+), 421 deletions(-)
include/hw/ssi/aspeed_smc.h +29 -35
@@ -29,35 +29,7 @@#include "hw/sysbus.h" #include "qom/object.h" -typedef struct AspeedSegments { -hwaddr addr; -uint32_t size; -}AspeedSegments ; -struct AspeedSMCState ; -typedef struct AspeedSMCController { -const char *name; -uint8_t r_conf; -uint8_t r_ce_ctrl; -uint8_t r_ctrl0; -uint8_t r_timings; -uint8_t nregs_timings; -uint8_t conf_enable_w0; -uint8_t max_peripherals; -const AspeedSegments *segments; -hwaddr flash_window_base; -uint32_t flash_window_size; -uint32_t features; -hwaddr dma_flash_mask; -hwaddr dma_dram_mask; -uint32_t nregs; -uint32_t (*segment_to_reg)(const struct AspeedSMCState *s, -const AspeedSegments *seg); -void (*reg_to_segment)(const struct AspeedSMCState *s,uint32_t reg, -AspeedSegments *seg); -void (*dma_ctrl)(struct AspeedSMCState *s,uint32_t value); -}AspeedSMCController ; - typedef struct AspeedSMCFlash { struct AspeedSMCState *controller;
@@ -71,18 +43,11 @@ typedef struct AspeedSMCFlash {#define TYPE_ASPEED_SMC "aspeed.smc" OBJECT_DECLARE_TYPE(AspeedSMCState, AspeedSMCClass, ASPEED_SMC) -struct AspeedSMCClass { -SysBusDevice parent_obj; -const AspeedSMCController *ctrl; -}; -#define ASPEED_SMC_R_MAX (0x100 / 4)struct AspeedSMCState {SysBusDevice parent_obj; -const AspeedSMCController *ctrl; -MemoryRegion mmio;MemoryRegion mmio_flash;MemoryRegion mmio_flash_alias;
@@ -115,4 +80,33 @@ struct AspeedSMCState { uint8_t snoop_dummies; }; +typedef struct AspeedSegments { +hwaddr addr; +uint32_t size; +}AspeedSegments ; + +struct AspeedSMCClass { +SysBusDeviceClass parent_obj; + +uint8_t r_conf; +uint8_t r_ce_ctrl; +uint8_t r_ctrl0; +uint8_t r_timings; +uint8_t nregs_timings; +uint8_t conf_enable_w0; +uint8_t max_peripherals; +const AspeedSegments *segments; +hwaddr flash_window_base; +uint32_t flash_window_size; +uint32_t features; +hwaddr dma_flash_mask; +hwaddr dma_dram_mask; +uint32_t nregs; +uint32_t (*segment_to_reg)(const AspeedSMCState *s, +const AspeedSegments *seg); +void (*reg_to_segment)(const AspeedSMCState *s,uint32_t reg, +AspeedSegments *seg); +void (*dma_ctrl)(AspeedSMCState *s,uint32_t value); +}; +#endif /* ASPEED_SMC_H */
hw/arm/aspeed_ast2600.c +2 -2
@@ -352,7 +352,7 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp) }sysbus_mmio_map (SYS_BUS_DEVICE (&s->fmc),0 , sc->memmap[ASPEED_DEV_FMC ]);sysbus_mmio_map (SYS_BUS_DEVICE (&s->fmc),1 , - s->fmc.ctrl->flash_window_base); +ASPEED_SMC_GET_CLASS (&s->fmc)->flash_window_base);sysbus_connect_irq (SYS_BUS_DEVICE (&s->fmc),0 ,aspeed_soc_get_irq (s,ASPEED_DEV_FMC ));
@@ -367,7 +367,7 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)sysbus_mmio_map (SYS_BUS_DEVICE (&s->spi[i]),0 , sc->memmap[ASPEED_DEV_SPI1 + i]);sysbus_mmio_map (SYS_BUS_DEVICE (&s->spi[i]),1 , - s->spi[i].ctrl->flash_window_base); +ASPEED_SMC_GET_CLASS (&s->spi[i])->flash_window_base); }/* EHCI */
hw/arm/aspeed_soc.c +2 -2
@@ -310,7 +310,7 @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp) }sysbus_mmio_map (SYS_BUS_DEVICE (&s->fmc),0 , sc->memmap[ASPEED_DEV_FMC ]);sysbus_mmio_map (SYS_BUS_DEVICE (&s->fmc),1 , - s->fmc.ctrl->flash_window_base); +ASPEED_SMC_GET_CLASS (&s->fmc)->flash_window_base);sysbus_connect_irq (SYS_BUS_DEVICE (&s->fmc),0 ,aspeed_soc_get_irq (s,ASPEED_DEV_FMC ));
@@ -323,7 +323,7 @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)sysbus_mmio_map (SYS_BUS_DEVICE (&s->spi[i]),0 , sc->memmap[ASPEED_DEV_SPI1 + i]);sysbus_mmio_map (SYS_BUS_DEVICE (&s->spi[i]),1 , - s->spi[i].ctrl->flash_window_base); +ASPEED_SMC_GET_CLASS (&s->spi[i])->flash_window_base); }/* EHCI */
hw/ssi/aspeed_smc.c +477 -382
1,102 lines not on this page · raw message
Signature · 1 line
2.31.1
Re: [PATCH 04/10] aspeed/smc: Drop AspeedSMCController structure
Quoted 7 lines · Cédric Le Goater
The characteristics of the Aspeed controllers are described in a AspeedSMCController structure which is redundant with the AspeedSMCClass. Move all attributes under the class and adapt the code to use class attributes instead.
This is a large change but it is functionally equivalent.
Quoted 7 lines
Signed-off-by Cédric Le Goater <[email protected]>--- include/hw/ssi/aspeed_smc.h | 64 ++- hw/arm/aspeed_ast2600.c | 4 +- hw/arm/aspeed_soc.c | 4 +- hw/ssi/aspeed_smc.c | 859 ++++++++++++++++++++---------------- 4 files changed, 510 insertions(+), 421 deletions(-)
Overall LGTM, I might do a more detailed pass later.
PATCH 5/10 aspeed/smc: Remove the 'flash' attribute from AspeedSMCFlash
In reply to Cédric Le GoaterThere is no use for it.
--- include/hw/ssi/aspeed_smc.h | 1 - hw/arm/aspeed.c | 11 +++++------ 2 files changed, 5 insertions(+), 7 deletions(-)
include/hw/ssi/aspeed_smc.h +0 -1
@@ -37,7 +37,6 @@ typedef struct AspeedSMCFlash {uint32_t size;MemoryRegion mmio; -DeviceState *flash; } AspeedSMCFlash;#define TYPE_ASPEED_SMC "aspeed.smc"
hw/arm/aspeed.c +5 -6
@@ -274,18 +274,17 @@ static void aspeed_board_init_flashes(AspeedSMCState *s,int i ;for (i =0 ; i < s->num_cs; ++i) { -AspeedSMCFlash *fl = &s->flashes[i];DriveInfo *dinfo =drive_get_next (IF_MTD );qemu_irq cs_line; +DeviceState *dev; - fl->flash =qdev_new (flashtype); + dev =qdev_new (flashtype);if (dinfo) { -qdev_prop_set_drive (fl->flash,"drive" , -blk_by_legacy_dinfo (dinfo)); +qdev_prop_set_drive (dev,"drive" ,blk_by_legacy_dinfo (dinfo)); } -qdev_realize_and_unref (fl->flash,BUS (s->spi), &error_fatal); +qdev_realize_and_unref (dev,BUS (s->spi), &error_fatal); - cs_line =qdev_get_gpio_in_named (fl->flash,SSI_GPIO_CS ,0 ); + cs_line =qdev_get_gpio_in_named (dev,SSI_GPIO_CS ,0 );sysbus_connect_irq (SYS_BUS_DEVICE (s), i +1 , cs_line); } }
Signature · 1 line
2.31.1
Re: [PATCH 05/10] aspeed/smc: Remove the 'flash' attribute from AspeedSMCFlash
Quoted 1 line · Cédric Le Goater
There is no use for it.
Hmmm this is not the correct justification.
This devices sits on a bus, so its state will be released when the bus is released. There is no need to release it manually, so we can remove the reference.
Quoted 47 lines
Signed-off-by Cédric Le Goater <[email protected]>--- include/hw/ssi/aspeed_smc.h | 1 - hw/arm/aspeed.c | 11 +++++------ 2 files changed, 5 insertions(+), 7 deletions(-)include/hw/ssi/aspeed_smc.h +0
-1@@ -37,7 +37,6 @@ typedef struct AspeedSMCFlash {uint32_t size;MemoryRegion mmio; -DeviceState *flash; } AspeedSMCFlash;#define TYPE_ASPEED_SMC "aspeed.smc"hw/arm/aspeed.c +5
-6@@ -274,18 +274,17 @@ static void aspeed_board_init_flashes(AspeedSMCState *s,int i ;for (i =0 ; i < s->num_cs; ++i) { -AspeedSMCFlash *fl = &s->flashes[i];DriveInfo *dinfo =drive_get_next (IF_MTD );qemu_irq cs_line; +DeviceState *dev; - fl->flash =qdev_new (flashtype); + dev =qdev_new (flashtype);if (dinfo) { -qdev_prop_set_drive (fl->flash,"drive" , -blk_by_legacy_dinfo (dinfo)); +qdev_prop_set_drive (dev,"drive" ,blk_by_legacy_dinfo (dinfo)); } -qdev_realize_and_unref (fl->flash,BUS (s->spi), &error_fatal); +qdev_realize_and_unref (dev,BUS (s->spi), &error_fatal); - cs_line =qdev_get_gpio_in_named (fl->flash,SSI_GPIO_CS ,0 ); + cs_line =qdev_get_gpio_in_named (dev,SSI_GPIO_CS ,0 );sysbus_connect_irq (SYS_BUS_DEVICE (s), i +1 , cs_line); } }
Re: [PATCH 05/10] aspeed/smc: Remove the 'flash' attribute from AspeedSMCFlash
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 1 line · Cédric Le Goater
There is no use for it.
Hmmm this is not the correct justification.
This devices sits on a bus, so its state will be released when the bus is released. There is no need to release it manually, so we can remove the reference.
That's what the code is doing AFAIUI.
This is just removing the AspeedSMCFlash attribute because it is not used anywhere else than under aspeed_board_init_flashes().
Is there anything else ? I am bit lost by your comment.
Thanks,
C.
Quoted 49 lines
Quoted 48 lines
Signed-off-by Cédric Le Goater <[email protected]>--- include/hw/ssi/aspeed_smc.h | 1 - hw/arm/aspeed.c | 11 +++++------ 2 files changed, 5 insertions(+), 7 deletions(-)include/hw/ssi/aspeed_smc.h +0
-1@@ -37,7 +37,6 @@ typedef struct AspeedSMCFlash {uint32_t size;MemoryRegion mmio; -DeviceState *flash; } AspeedSMCFlash;#define TYPE_ASPEED_SMC "aspeed.smc"hw/arm/aspeed.c +5
-6@@ -274,18 +274,17 @@ static void aspeed_board_init_flashes(AspeedSMCState *s,int i ;for (i =0 ; i < s->num_cs; ++i) { -AspeedSMCFlash *fl = &s->flashes[i];DriveInfo *dinfo =drive_get_next (IF_MTD );qemu_irq cs_line; +DeviceState *dev; - fl->flash =qdev_new (flashtype); + dev =qdev_new (flashtype);if (dinfo) { -qdev_prop_set_drive (fl->flash,"drive" , -blk_by_legacy_dinfo (dinfo)); +qdev_prop_set_drive (dev,"drive" ,blk_by_legacy_dinfo (dinfo)); } -qdev_realize_and_unref (fl->flash,BUS (s->spi), &error_fatal); +qdev_realize_and_unref (dev,BUS (s->spi), &error_fatal); - cs_line =qdev_get_gpio_in_named (fl->flash,SSI_GPIO_CS ,0 ); + cs_line =qdev_get_gpio_in_named (dev,SSI_GPIO_CS ,0 );sysbus_connect_irq (SYS_BUS_DEVICE (s), i +1 , cs_line); } }
Philippe Mathieu-Daudé
Reviewed-byRe: [PATCH 05/10] aspeed/smc: Remove the 'flash' attribute from AspeedSMCFlash
Quoted 10 lines · Cédric Le Goater
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 1 line · Cédric Le Goater
There is no use for it.
Hmmm this is not the correct justification.
This devices sits on a bus, so its state will be released when the bus is released. There is no need to release it manually, so we can remove the reference.
Quoted 6 lines
That's what the code is doing AFAIUI.
This is just removing the AspeedSMCFlash attribute because it is not used anywhere else than under
aspeed_board_init_flashes().Is there anything else ? I am bit lost by your comment.
I was thinking of d4e1d8f57eb ("hw/arm/tosa: Encapsulate misc GPIO handling in a device"), if the device were not created on a bus, the we'd need to keep this reference, otherwise we'd leak it.
Anyhow this is board code where we are not releasing anything.
Maybe "There is no need to keep a reference of the flash qdev in the AspeedSMCFlash state: the SPI bus takes ownership and will release its resources. Remove AspeedSMCFlash::flash."?
Anyway no big deal with the comment,
PATCH 6/10 aspeed/smc: Remove the 'size' attribute from AspeedSMCFlash
In reply to Cédric Le GoaterIt's only useful to compute the initial size of the boot_rom region. Use memory_region_size() instead.
--- include/hw/ssi/aspeed_smc.h | 1 - hw/arm/aspeed.c | 7 ++++--- hw/ssi/aspeed_smc.c | 5 ++--- 3 files changed, 6 insertions(+), 7 deletions(-)
include/hw/ssi/aspeed_smc.h +0 -1
@@ -34,7 +34,6 @@ typedef struct AspeedSMCFlash {struct AspeedSMCState *controller;uint8_t id; -uint32_t size;MemoryRegion mmio; } AspeedSMCFlash;
hw/arm/aspeed.c +4 -3
@@ -376,6 +376,7 @@ static void aspeed_machine_init(MachineState *machine)if (drive0) {AspeedSMCFlash *fl = &bmc->soc.fmc.flashes[0 ];MemoryRegion *boot_rom =g_new (MemoryRegion,1 ); +uint64_t size =memory_region_size (&fl->mmio);/* * create a ROM region using the default mapping window size of
@@ -385,15 +386,15 @@ static void aspeed_machine_init(MachineState *machine)*/ if (ASPEED_MACHINE (machine)->mmio_exec) {memory_region_init_alias (boot_rom,NULL ,"aspeed.boot_rom" , - &fl->mmio,0 , fl->size); + &fl->mmio,0 , size);memory_region_add_subregion (get_system_memory (),FIRMWARE_ADDR , boot_rom); }else {memory_region_init_rom (boot_rom,NULL ,"aspeed.boot_rom" , - fl->size, &error_abort); + size, &error_abort);memory_region_add_subregion (get_system_memory (),FIRMWARE_ADDR , boot_rom); -write_boot_rom (drive0,FIRMWARE_ADDR , fl->size, &error_abort); +write_boot_rom (drive0,FIRMWARE_ADDR , size, &error_abort); } }
hw/ssi/aspeed_smc.c +2 -3
@@ -1186,11 +1186,10 @@ static void aspeed_smc_realize(DeviceState *dev, Error **errp) fl->id = i; fl->controller = s; - fl->size = asc->segments[i].size;memory_region_init_io (&fl->mmio,OBJECT (s), &aspeed_smc_flash_ops, - fl, name, fl->size); + fl, name, asc->segments[i].size);memory_region_add_subregion (&s->mmio_flash, offset, &fl->mmio); - offset += fl->size; + offset += asc->segments[i].size; }/* DMA support */
Signature · 1 line
2.31.1
Re: [PATCH 06/10] aspeed/smc: Remove the 'size' attribute from AspeedSMCFlash
Quoted 1 line · Cédric Le Goater
It's only useful to compute the initial size of the
boot_romregion.
"AspeedSMCFlash::size is only used to compute the initial size
of the boot_rom region. Not very useful, so directly call memory_region_size() instead."?
Quoted 8 lines
Use
memory_region_size()instead.Signed-off-by Cédric Le Goater <[email protected]>--- include/hw/ssi/aspeed_smc.h | 1 - hw/arm/aspeed.c | 7 ++++--- hw/ssi/aspeed_smc.c | 5 ++--- 3 files changed, 6 insertions(+), 7 deletions(-)
Re: [PATCH 06/10] aspeed/smc: Remove the 'size' attribute from AspeedSMCFlash
Quoted 6 lines · Philippe Mathieu-Daudé
Quoted 1 line · Cédric Le Goater
It's only useful to compute the initial size of the
boot_romregion."
AspeedSMCFlash::sizeis only used to compute the initial size
of theboot_romregion. Not very useful, so directly callmemory_region_size()instead."?
Sure. I will rephrase.
Thanks,
C.
Quoted 12 lines
Quoted 9 lines
Use
memory_region_size()instead.Signed-off-by Cédric Le Goater <[email protected]>--- include/hw/ssi/aspeed_smc.h | 1 - hw/arm/aspeed.c | 7 ++++--- hw/ssi/aspeed_smc.c | 5 ++--- 3 files changed, 6 insertions(+), 7 deletions(-)Reviewed-by Philippe Mathieu-Daudé <[email protected]>
PATCH 7/10 aspeed/smc: Rename AspeedSMCFlash 'id' to 'cs'
In reply to Cédric Le Goater'cs' is a more appropriate name to index SPI flash devices.
--- include/hw/ssi/aspeed_smc.h | 2 +- hw/ssi/aspeed_smc.c | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-)
include/hw/ssi/aspeed_smc.h +1 -1
@@ -33,7 +33,7 @@ struct AspeedSMCState;typedef struct AspeedSMCFlash {struct AspeedSMCState *controller; -uint8_t id; +uint8_t cs;MemoryRegion mmio; }AspeedSMCFlash ;
hw/ssi/aspeed_smc.c +15 -15
@@ -352,20 +352,20 @@ static inline int aspeed_smc_flash_mode(const AspeedSMCFlash *fl) {const AspeedSMCState *s = fl->controller; -return s->regs[s->r_ctrl0 + fl->id] &CTRL_CMD_MODE_MASK ; +return s->regs[s->r_ctrl0 + fl->cs] &CTRL_CMD_MODE_MASK ; }static inline bool aspeed_smc_is_writable (const AspeedSMCFlash *fl) {const AspeedSMCState *s = fl->controller; -return s->regs[s->r_conf] & (1 << (s->conf_enable_w0 + fl->id)); +return s->regs[s->r_conf] & (1 << (s->conf_enable_w0 + fl->cs)); }static inline int aspeed_smc_flash_cmd (const AspeedSMCFlash *fl) {const AspeedSMCState *s = fl->controller; -int cmd = (s->regs[s->r_ctrl0 + fl->id] >>CTRL_CMD_SHIFT ) &CTRL_CMD_MASK ; +int cmd = (s->regs[s->r_ctrl0 + fl->cs] >>CTRL_CMD_SHIFT ) &CTRL_CMD_MASK ;/* * In read mode, the default SPI command is READ (0x3). In other
@@ -393,7 +393,7 @@ static inline int aspeed_smc_flash_is_4byte(const AspeedSMCFlash *fl)if (asc->segments == aspeed_2400_spi1_segments) {return s->regs[s->r_ctrl0] &CTRL_AST2400_SPI_4BYTE ; }else { -return s->regs[s->r_ce_ctrl] & (1 << (CTRL_EXTENDED0 + fl->id)); +return s->regs[s->r_ce_ctrl] & (1 << (CTRL_EXTENDED0 + fl->cs)); } }
@@ -401,9 +401,9 @@ static void aspeed_smc_flash_do_select(AspeedSMCFlash *fl, bool unselect) {AspeedSMCState *s = fl->controller; -trace_aspeed_smc_flash_select (fl->id, unselect ?"un" :"" ); +trace_aspeed_smc_flash_select (fl->cs, unselect ?"un" :"" ); -qemu_set_irq (s->cs_lines[fl->id], unselect); +qemu_set_irq (s->cs_lines[fl->cs], unselect); }static void aspeed_smc_flash_select (AspeedSMCFlash *fl)
@@ -423,11 +423,11 @@ static uint32_t aspeed_smc_check_segment_addr(const AspeedSMCFlash *fl,AspeedSMCClass *asc =ASPEED_SMC_GET_CLASS (s);AspeedSegments seg; - asc->reg_to_segment (s, s->regs[R_SEG_ADDR0 + fl->id], &seg); + asc->reg_to_segment (s, s->regs[R_SEG_ADDR0 + fl->cs], &seg);if ((addr % seg.size) != addr) {aspeed_smc_error ("invalid address 0x%08x for CS%d segment : " "[ 0x%" HWADDR_PRIx" - 0x%" HWADDR_PRIx" ]" , - addr, fl->id, seg.addr, seg.addr + seg.size); + addr, fl->cs, seg.addr, seg.addr + seg.size); addr %= seg.size; }
@@ -437,7 +437,7 @@ static uint32_t aspeed_smc_check_segment_addr(const AspeedSMCFlash *fl,static int aspeed_smc_flash_dummies (const AspeedSMCFlash *fl) {const AspeedSMCState *s = fl->controller; -uint32_t r_ctrl0 = s->regs[s->r_ctrl0 + fl->id]; +uint32_t r_ctrl0 = s->regs[s->r_ctrl0 + fl->cs];uint32_t dummy_high = (r_ctrl0 >>CTRL_DUMMY_HIGH_SHIFT ) &0x1 ;uint32_t dummy_low = (r_ctrl0 >>CTRL_DUMMY_LOW_SHIFT ) &0x3 ;uint32_t dummies = ((dummy_high <<2 ) | dummy_low) *8 ;
@@ -506,7 +506,7 @@ static uint64_t aspeed_smc_flash_read(void *opaque, hwaddr addr, unsigned size)aspeed_smc_error ("invalid flash mode %d" ,aspeed_smc_flash_mode (fl)); } -trace_aspeed_smc_flash_read (fl->id, addr, size, ret, +trace_aspeed_smc_flash_read (fl->cs, addr, size, ret,aspeed_smc_flash_mode (fl));return ret; }
@@ -563,7 +563,7 @@ static bool aspeed_smc_do_snoop(AspeedSMCFlash *fl, uint64_t data,AspeedSMCState *s = fl->controller;uint8_t addr_width =aspeed_smc_flash_is_4byte (fl) ?4 :3 ; -trace_aspeed_smc_do_snoop (fl->id, s->snoop_index, s->snoop_dummies, +trace_aspeed_smc_do_snoop (fl->cs, s->snoop_index, s->snoop_dummies, (uint8_t ) data &0xff );if (s->snoop_index ==SNOOP_OFF ) {
@@ -616,7 +616,7 @@ static void aspeed_smc_flash_write(void *opaque, hwaddr addr, uint64_t data,AspeedSMCState *s = fl->controller;int i; -trace_aspeed_smc_flash_write (fl->id, addr, size, data, +trace_aspeed_smc_flash_write (fl->cs, addr, size, data,aspeed_smc_flash_mode (fl));if (!aspeed_smc_is_writable (fl)) {
@@ -668,12 +668,12 @@ static void aspeed_smc_flash_update_ctrl(AspeedSMCFlash *fl, uint32_t value) unselect = (value &CTRL_CMD_MODE_MASK ) !=CTRL_USERMODE ;/* A change of CTRL_CE_STOP_ACTIVE from 0 to 1, unselects the CS */ -if (!(s->regs[s->r_ctrl0 + fl->id] &CTRL_CE_STOP_ACTIVE ) && +if (!(s->regs[s->r_ctrl0 + fl->cs] &CTRL_CE_STOP_ACTIVE ) && value &CTRL_CE_STOP_ACTIVE ) { unselect = true; } - s->regs[s->r_ctrl0 + fl->id] = value; + s->regs[s->r_ctrl0 + fl->cs] = value; s->snoop_index = unselect ?SNOOP_OFF :SNOOP_START ;
@@ -1184,7 +1184,7 @@ static void aspeed_smc_realize(DeviceState *dev, Error **errp)snprintf (name,sizeof (name),TYPE_ASPEED_SMC ".flash.%d" , i); - fl->id = i; + fl->cs = i; fl->controller = s;memory_region_init_io (&fl->mmio,OBJECT (s), &aspeed_smc_flash_ops, fl, name, asc->segments[i].size);
Signature · 1 line
2.31.1
Re: [PATCH 07/10] aspeed/smc: Rename AspeedSMCFlash 'id' to 'cs'
Quoted 7 lines · Cédric Le Goater
'cs' is a more appropriate name to index SPI flash devices.
Signed-off-by Cédric Le Goater <[email protected]>--- include/hw/ssi/aspeed_smc.h | 2 +- hw/ssi/aspeed_smc.c | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-)
PATCH 8/10 aspeed/smc: QOMify AspeedSMCFlash
In reply to Cédric Le GoaterAspeedSMCFlash is a little object representing the AHB memory window through which the contents of a flash device can be accessed with MMIOs.
--- include/hw/ssi/aspeed_smc.h | 13 +++++-- hw/ssi/aspeed_smc.c | 78 +++++++++++++++++++++++++++++++++---- 2 files changed, 79 insertions(+), 12 deletions(-)
include/hw/ssi/aspeed_smc.h +9 -4
@@ -30,18 +30,23 @@#include "qom/object.h" struct AspeedSMCState ; -typedef struct AspeedSMCFlash { -struct AspeedSMCState *controller; +#define TYPE_ASPEED_SMC_FLASH "aspeed.smc.flash" +OBJECT_DECLARE_SIMPLE_TYPE(AspeedSMCFlash, ASPEED_SMC_FLASH) +struct AspeedSMCFlash { +SysBusDevice parent_obj; + +struct AspeedSMCState *controller;uint8_t cs;MemoryRegion mmio; -}AspeedSMCFlash ; +};#define TYPE_ASPEED_SMC "aspeed.smc" OBJECT_DECLARE_TYPE(AspeedSMCState, AspeedSMCClass, ASPEED_SMC)#define ASPEED_SMC_R_MAX (0x100 / 4) +#define ASPEED_SMC_CS_MAX 5struct AspeedSMCState {SysBusDevice parent_obj;
@@ -72,7 +77,7 @@ struct AspeedSMCState {MemoryRegion *dram_mr;AddressSpace dram_as; -AspeedSMCFlash *flashes; +AspeedSMCFlash flashes[ASPEED_SMC_CS_MAX ];uint8_t snoop_index;uint8_t snoop_dummies;
hw/ssi/aspeed_smc.c +70 -8
121 lines not on this page · raw message
Signature · 1 line
2.31.1
Re: [PATCH 08/10] aspeed/smc: QOMify AspeedSMCFlash
Quoted 9 lines · Cédric Le Goater
AspeedSMCFlash is a little object representing the AHB memory window through which the contents of a flash device can be accessed with MMIOs.
Signed-off-by Cédric Le Goater <[email protected]>--- include/hw/ssi/aspeed_smc.h | 13 +++++-- hw/ssi/aspeed_smc.c | 78 +++++++++++++++++++++++++++++++++---- 2 files changed, 79 insertions(+), 12 deletions(-)
PATCH 9/10 aspeed/smc: Add default reset values
In reply to Cédric Le GoaterThis simplifies the reset handler and has the benefit to remove some bad use of the segments array as an identifier of the controller model.
--- include/hw/ssi/aspeed_smc.h | 1 + hw/ssi/aspeed_smc.c | 52 +++++++++++++++++++------------------ 2 files changed, 28 insertions(+), 25 deletions(-)
include/hw/ssi/aspeed_smc.h +1 -0
@@ -98,6 +98,7 @@ struct AspeedSMCClass {uint8_t nregs_timings;uint8_t conf_enable_w0;uint8_t max_peripherals; +const uint32_t *resets;const AspeedSegments *segments;hwaddr flash_window_base;uint32_t flash_window_size;
hw/ssi/aspeed_smc.c +27 -25
109 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH 10/10 aspeed/smc: Introduce an addr_width() class handler
In reply to Cédric Le GoaterThe AST2400 SPI controller has a transitional HW interface and it stores the address width currently in use in a different register than all the other SMC controllers. It needs special handling when working in 4B mode.
Make it clear through a class handler. This also removes another use of the segments array.
--- include/hw/ssi/aspeed_smc.h | 1 + hw/ssi/aspeed_smc.c | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-)
include/hw/ssi/aspeed_smc.h +1 -0
@@ -111,6 +111,7 @@ struct AspeedSMCClass {void (*reg_to_segment)(const AspeedSMCState *s,uint32_t reg,AspeedSegments *seg);void (*dma_ctrl)(AspeedSMCState *s,uint32_t value); + int (*addr_width)(const AspeedSMCState *s); };#endif /* ASPEED_SMC_H */
hw/ssi/aspeed_smc.c +12 -7
@@ -196,7 +196,6 @@* controller. These can be changed when board is initialized with the * Segment Address Registers. */ -static const AspeedSegments aspeed_2400_spi1_segments[];static const AspeedSegments aspeed_2500_spi1_segments[];static const AspeedSegments aspeed_2500_spi2_segments[];
@@ -382,15 +381,15 @@ static inline int aspeed_smc_flash_cmd(const AspeedSMCFlash *fl)return cmd; } -static inline int aspeed_smc_flash_is_4byte (const AspeedSMCFlash *fl) +static inline int aspeed_smc_flash_addr_width (const AspeedSMCFlash *fl) {const AspeedSMCState *s = fl->controller;AspeedSMCClass *asc =ASPEED_SMC_GET_CLASS (s); -if (asc->segments == aspeed_2400_spi1_segments) { -return s->regs[s->r_ctrl0] &CTRL_AST2400_SPI_4BYTE ; +if (asc->addr_width) { +return asc->addr_width (s); }else { -return s->regs[s->r_ce_ctrl] & (1 << (CTRL_EXTENDED0 + fl->cs)); +return s->regs[s->r_ce_ctrl] & (1 << (CTRL_EXTENDED0 + fl->cs)) ?4 :3 ; } }
@@ -450,7 +449,7 @@ static void aspeed_smc_flash_setup(AspeedSMCFlash *fl, uint32_t addr) {const AspeedSMCState *s = fl->controller;uint8_t cmd =aspeed_smc_flash_cmd (fl); -int i =aspeed_smc_flash_is_4byte (fl) ?4 :3 ; +int i =aspeed_smc_flash_addr_width (fl);/* Flash access can not exceed CS segment */ addr =aspeed_smc_check_segment_addr (fl, addr);
@@ -558,7 +557,7 @@ static bool aspeed_smc_do_snoop(AspeedSMCFlash *fl, uint64_t data, unsigned size) {AspeedSMCState *s = fl->controller; -uint8_t addr_width =aspeed_smc_flash_is_4byte (fl) ?4 :3 ; +uint8_t addr_width =aspeed_smc_flash_addr_width (fl);trace_aspeed_smc_do_snoop (fl->cs, s->snoop_index, s->snoop_dummies, (uint8_t ) data &0xff );
@@ -1386,6 +1385,11 @@ static const AspeedSegments aspeed_2400_spi1_segments[] = { { 0x30000000, 64 * MiB }, }; +static int aspeed_2400_spi1_addr_width (const AspeedSMCState *s) +{ +return s->regs[R_SPI_CTRL0 ] &CTRL_AST2400_SPI_4BYTE ?4 :3 ; +} +static void aspeed_2400_spi1_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
@@ -1407,6 +1411,7 @@ static void aspeed_2400_spi1_class_init(ObjectClass *klass, void *data) asc->segment_to_reg = aspeed_smc_segment_to_reg; asc->reg_to_segment = aspeed_smc_reg_to_segment; asc->dma_ctrl = aspeed_smc_dma_ctrl; + asc->addr_width = aspeed_2400_spi1_addr_width; }static const TypeInfo aspeed_2400_spi1_info = {
Signature · 1 line
2.31.1
Hi Cédric,
Quoted 5 lines · Cédric Le Goater
This series adds a simple support for the 2nd watchdog registers which were moved under the AST2600 FMC controller to deactivate the alternate boot function. Then come cleanups of the AspeedSMC model mostly removing a useless AspeedSMCController structure (that's the noisy part) and QOMifying the AspeedSMCFlash structure.
I had a read through and it makes sense to me.
Cheers,
Joel