Skip to contentSkip to conversation

aspeed: miscellaneous small fixes

PATCH Applied Cédric Le Goater 3 participants 8 messages Feb 9, 2017 – Feb 10, 2017 Arm/Aspeed machine support

lore
Share & tools
lore
#0 lore raw

cover aspeed: miscellaneous small fixes

Hello,

Here is a short series fixing small issues in the SMC controller model of the Aspeed SoC.

Thanks,

C.

Cédric Le Goater (4):
aspeed: check for negative values returned by blk_getlength()
aspeed: remove useless comment on controller segment size aspeed/smc: handle dummies only in fast read mode aspeed/smc: use a modulo to check segment limits

 hw/arm/aspeed.c     | 22 +++++++++++++++-------
 hw/ssi/aspeed_smc.c | 13 ++++++++-----
 2 files changed, 23 insertions(+), 12 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/4 aspeed: check for negative values returned by blk_getlength()

write_boot_rom() does not check for negative values. This is more a problem for coverity than the actual code as the size of the flash device is checked when the m25p80 object is created. If there is anything wrong with the backing file, we should not even reach that path.

---
 hw/arm/aspeed.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
hw/arm/aspeed.c +12 -2
index a92c2f1c362b..ac9cbd66b72a 100644
@@ -113,9 +113,19 @@ static void write_boot_rom(DriveInfo *dinfo, hwaddr addr, size_t rom_size,
 {
     BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
     uint8_t *storage;
+    int64_t size;
 
-    if (rom_size > blk_getlength(blk)) {
-        rom_size = blk_getlength(blk);
+    /* The block backend size should have already been 'validated' by
+     * the creation of the m25p80 object.
+     */
+    size = blk_getlength(blk);
+    if (size <= 0) {
+        error_setg(errp, "failed to get flash size");
+        return;
+    }
+
+    if (rom_size > size) {
+        rom_size = size;
     }
 
     storage = g_new0(uint8_t, rom_size);
Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/4 aspeed: remove useless comment on controller segment size

In reply to Cédric Le Goater

The flash devices used for the FMC controller (BMC firmware) are well defined for each Aspeed machine and are all smaller than the default mapping window size, at least for CE0 which is the chip the SoC boots from.

---
 hw/arm/aspeed.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
hw/arm/aspeed.c +3 -5
index ac9cbd66b72a..283c03881493 100644
@@ -148,10 +148,6 @@ static void aspeed_board_init_flashes(AspeedSMCState *s, const char *flashtype,
         DriveInfo *dinfo = drive_get_next(IF_MTD);
         qemu_irq cs_line;
 
-        /*
-         * FIXME: check that we are not using a flash module exceeding
-         * the controller segment size
-         */
         fl->flash = ssi_create_slave_no_init(s->spi, flashtype);
         if (dinfo) {
             qdev_prop_set_drive(fl->flash, "drive", blk_by_legacy_dinfo(dinfo),
@@ -210,7 +206,9 @@ static void aspeed_board_init(MachineState *machine,
 
         /*
          * create a ROM region using the default mapping window size of
-         * the flash module.
+         * the flash module. The window size is 64MB for the AST2400
+         * SoC and 128MB for the AST2500 SoC, which is twice as big as
+         * needed by the flash modules of the Aspeed machines.
          */
         memory_region_init_rom(boot_rom, OBJECT(bmc), "aspeed.boot_rom",
                                fl->size, &error_abort);
Signature · 1 line
2.7.4
Reviewed-by on v1 2/4
#3 lore raw

Re: [Qemu-devel] [PATCH 2/4] aspeed: remove useless comment on controller segment size

Quoted 6 lines · Cédric Le Goater

The flash devices used for the FMC controller (BMC firmware) are well defined for each Aspeed machine and are all smaller than the default mapping window size, at least for CE0 which is the chip the SoC boots from.

Quoted 31 lines
---
 hw/arm/aspeed.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
hw/arm/aspeed.c +3 -5
index ac9cbd66b72a..283c03881493 100644
@@ -148,10 +148,6 @@ static void aspeed_board_init_flashes(AspeedSMCState *s, const char *flashtype,
         DriveInfo *dinfo = drive_get_next(IF_MTD);
         qemu_irq cs_line;
 
-        /*
-         * FIXME: check that we are not using a flash module exceeding
-         * the controller segment size
-         */
         fl->flash = ssi_create_slave_no_init(s->spi, flashtype);
         if (dinfo) {
             qdev_prop_set_drive(fl->flash, "drive", blk_by_legacy_dinfo(dinfo),
@@ -210,7 +206,9 @@ static void aspeed_board_init(MachineState *machine,
 
         /*
          * create a ROM region using the default mapping window size of
-         * the flash module.
+         * the flash module. The window size is 64MB for the AST2400
+         * SoC and 128MB for the AST2500 SoC, which is twice as big as
+         * needed by the flash modules of the Aspeed machines.
          */
         memory_region_init_rom(boot_rom, OBJECT(bmc), "aspeed.boot_rom",
                                fl->size, &error_abort);
#4 lore raw

PATCH 3/4 aspeed/smc: handle dummies only in fast read mode

In reply to Cédric Le Goater

HW works fine in normal read mode with dummy bytes being set. So let's check this case to not transfer bytes.

---
 hw/ssi/aspeed_smc.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
hw/ssi/aspeed_smc.c +6 -3
index 087b29e8da10..70177078a8f2 100644
@@ -536,10 +536,13 @@ static uint64_t aspeed_smc_flash_read(void *opaque, hwaddr addr, unsigned size)
         /*
          * Use fake transfers to model dummy bytes. The value should
          * be configured to some non-zero value in fast read mode and
-         * zero in read mode.
+         * zero in read mode. But, as the HW allows inconsistent
+         * settings, let's check for fast read mode.
          */
-        for (i = 0; i < aspeed_smc_flash_dummies(fl); i++) {
-            ssi_transfer(fl->controller->spi, 0xFF);
+        if (aspeed_smc_flash_mode(fl) == CTRL_FREADMODE) {
+            for (i = 0; i < aspeed_smc_flash_dummies(fl); i++) {
+                ssi_transfer(fl->controller->spi, 0xFF);
+            }
         }
 
         for (i = 0; i < size; i++) {
Signature · 1 line
2.7.4
#5 lore raw

PATCH 4/4 aspeed/smc: use a modulo to check segment limits

In reply to Cédric Le Goater

The size of a segment is not necessarily a power of 2.

---
 hw/ssi/aspeed_smc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/ssi/aspeed_smc.c +2 -2
index 70177078a8f2..cb515730c5ad 100644
@@ -475,15 +475,15 @@ static uint32_t aspeed_smc_check_segment_addr(const AspeedSMCFlash *fl,
     AspeedSegments seg;
 
     aspeed_smc_reg_to_segment(s->regs[R_SEG_ADDR0 + fl->id], &seg);
-    if ((addr & (seg.size - 1)) != addr) {
+    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);
+        addr %= seg.size;
     }
 
-    addr &= seg.size - 1;
     return addr;
 }
 
Signature · 1 line
2.7.4
Reviewed-by on v1 4/4
#6 lore raw

Re: [Qemu-devel] [Qemu-arm] [PATCH 4/4] aspeed/smc: use a modulo to check segment limits

Quoted 3 lines · Cédric Le Goater

The size of a segment is not necessarily a power of 2.

Quoted 27 lines
---
 hw/ssi/aspeed_smc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/ssi/aspeed_smc.c +2 -2
index 70177078a8f2..cb515730c5ad 100644
@@ -475,15 +475,15 @@ static uint32_t aspeed_smc_check_segment_addr(const AspeedSMCFlash *fl,
     AspeedSegments seg;
 
     aspeed_smc_reg_to_segment(s->regs[R_SEG_ADDR0 + fl->id], &seg);
-    if ((addr & (seg.size - 1)) != addr) {
+    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);
+        addr %= seg.size;
     }
 
-    addr &= seg.size - 1;
     return addr;
 }
 
#7 lore raw
In reply to Cédric Le Goater
Quoted 7 lines · Cédric Le Goater

Hello,

Here is a short series fixing small issues in the SMC controller model of the Aspeed SoC.

Thanks,

Quoted 7 lines

C.

Cédric Le Goater (4):
aspeed: check for negative values returned by blk_getlength()
aspeed: remove useless comment on controller segment size aspeed/smc: handle dummies only in fast read mode aspeed/smc: use a modulo to check segment limits

Applied to target-arm.next, thanks.

-- PMM