Skip to contentSkip to conversation

aspeed/smc: add fast read support under User command mode.

PATCH Applied Cédric Le Goater 4 participants 10 messages Jan 24, 2019 – Jan 28, 2019 Arm/Aspeed machine support

lore
Share & tools
lore
#0 lore raw

cover aspeed/smc: add fast read support under User command mode.

Hello,

When in the User command mode, the Aspeed SMC controller driver performs the dummy cycles of a fast read command using byte transfers, that is ony byte for eight cycles. But, the QEMU m25p80 models one dummy cycle with one byte transfer.

To restore the correct number of cycles, this series adds a function snooping the SPI transfers to catch commands requiring dummy cycles and replaces them with byte transfers compatible with the m25p80 model.

Thanks,

C.

Cédric Le Goater (4):
aspeed/smc: fix default read value aspeed/smc: define registers for all possible CS aspeed/smc: Add dummy data register aspeed/smc: snoop transfers to fake dummy cycles

 include/hw/ssi/aspeed_smc.h |   3 +
 hw/ssi/aspeed_smc.c         | 128 +++++++++++++++++++++++++++++++++---
 2 files changed, 123 insertions(+), 8 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/4 aspeed/smc: fix default read value

0xFFFFFFFF should be returned for non implemented registers.

---
 hw/ssi/aspeed_smc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ssi/aspeed_smc.c +1 -1
index 1270842dcf0c..7af808c33c50 100644
@@ -670,7 +670,7 @@ static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size)
     } else {
         qemu_log_mask(LOG_UNIMP, "%s: not implemented: 0x%" HWADDR_PRIx "\n",
                       __func__, addr);
-        return 0;
+        return -1;
     }
 }
 
Signature · 1 line
2.20.1
#3 lore raw

PATCH 2/4 aspeed/smc: define registers for all possible CS

In reply to Cédric Le Goater

The model should expose one control register per possible CS. When testing the validity of the register number in the read operation, replace 's->num_cs' by 'ctrl->max_slaves' which represents the maximum number of flash devices a controller can handle.

---
 hw/ssi/aspeed_smc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ssi/aspeed_smc.c +1 -1
index 7af808c33c50..6045ca11b969 100644
@@ -665,7 +665,7 @@ static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size)
         addr == s->r_ce_ctrl ||
         addr == R_INTR_CTRL ||
         (addr >= R_SEG_ADDR0 && addr < R_SEG_ADDR0 + s->ctrl->max_slaves) ||
-        (addr >= s->r_ctrl0 && addr < s->r_ctrl0 + s->num_cs)) {
+        (addr >= s->r_ctrl0 && addr < s->r_ctrl0 + s->ctrl->max_slaves)) {
         return s->regs[addr];
     } else {
         qemu_log_mask(LOG_UNIMP, "%s: not implemented: 0x%" HWADDR_PRIx "\n",
Signature · 1 line
2.20.1
maintainer Reviewed-by on v1 2/4
#4 lore raw

Re: [Qemu-arm] [PATCH 2/4] aspeed/smc: define registers for all possible CS

Quoted 7 lines · Cédric Le Goater

The model should expose one control register per possible CS. When testing the validity of the register number in the read operation, replace 's->num_cs' by 'ctrl->max_slaves' which represents the maximum number of flash devices a controller can handle.

#5 lore raw

PATCH 3/4 aspeed/smc: Add dummy data register

In reply to Cédric Le Goater

The SMC controllers have a register containing the byte that will be used as dummy output. It can be modified by software.

---
 hw/ssi/aspeed_smc.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
hw/ssi/aspeed_smc.c +6 -3
index 6045ca11b969..9f3b6f4b4501 100644
@@ -98,8 +98,8 @@
 /* Misc Control Register #1 */
 #define R_MISC_CTRL1      (0x50 / 4)
 
-/* Misc Control Register #2 */
-#define R_MISC_CTRL2      (0x54 / 4)
+/* SPI dummy cycle data */
+#define R_DUMMY_DATA      (0x54 / 4)
 
 /* DMA Control/Status Register */
 #define R_DMA_CTRL        (0x80 / 4)
@@ -529,7 +529,7 @@ static void aspeed_smc_flash_setup(AspeedSMCFlash *fl, uint32_t addr)
      */
     if (aspeed_smc_flash_mode(fl) == CTRL_FREADMODE) {
         for (i = 0; i < aspeed_smc_flash_dummies(fl); i++) {
-            ssi_transfer(fl->controller->spi, 0xFF);
+            ssi_transfer(fl->controller->spi, s->regs[R_DUMMY_DATA] & 0xff);
         }
     }
 }
@@ -664,6 +664,7 @@ static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size)
         addr == s->r_timings ||
         addr == s->r_ce_ctrl ||
         addr == R_INTR_CTRL ||
+        addr == R_DUMMY_DATA ||
         (addr >= R_SEG_ADDR0 && addr < R_SEG_ADDR0 + s->ctrl->max_slaves) ||
         (addr >= s->r_ctrl0 && addr < s->r_ctrl0 + s->ctrl->max_slaves)) {
         return s->regs[addr];
@@ -697,6 +698,8 @@ static void aspeed_smc_write(void *opaque, hwaddr addr, uint64_t data,
         if (value != s->regs[R_SEG_ADDR0 + cs]) {
             aspeed_smc_flash_set_segment(s, cs, value);
         }
+    } else if (addr == R_DUMMY_DATA) {
+        s->regs[addr] = value & 0xff;
     } else {
         qemu_log_mask(LOG_UNIMP, "%s: not implemented: 0x%" HWADDR_PRIx "\n",
                       __func__, addr);
Signature · 1 line
2.20.1
Reviewed-by on v1 3/4
#7 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH 3/4] aspeed/smc: Add dummy data register

In reply to Cédric Le Goater
Quoted 6 lines · Cédric Le Goater

The SMC controllers have a register containing the byte that will be used as dummy output. It can be modified by software.

Alistair

Quoted 49 lines
---
 hw/ssi/aspeed_smc.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
hw/ssi/aspeed_smc.c +6 -4
index 6045ca11b969..9f3b6f4b4501 100644
@@ -98,8 +98,8 @@
 /* Misc Control Register #1 */
 #define R_MISC_CTRL1      (0x50 / 4)
 
-/* Misc Control Register #2 */
-#define R_MISC_CTRL2      (0x54 / 4)
+/* SPI dummy cycle data */
+#define R_DUMMY_DATA      (0x54 / 4)
 
 /* DMA Control/Status Register */
 #define R_DMA_CTRL        (0x80 / 4)
@@ -529,7 +529,7 @@ static void aspeed_smc_flash_setup(AspeedSMCFlash *fl, uint32_t addr)
      */
     if (aspeed_smc_flash_mode(fl) == CTRL_FREADMODE) {
         for (i = 0; i < aspeed_smc_flash_dummies(fl); i++) {
-            ssi_transfer(fl->controller->spi, 0xFF);
+            ssi_transfer(fl->controller->spi, s->regs[R_DUMMY_DATA] & 0xff);
         }
     }
 }
@@ -664,6 +664,7 @@ static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size)
         addr == s->r_timings ||
         addr == s->r_ce_ctrl ||
         addr == R_INTR_CTRL ||
+        addr == R_DUMMY_DATA ||
         (addr >= R_SEG_ADDR0 && addr < R_SEG_ADDR0 + s->ctrl->max_slaves) ||
         (addr >= s->r_ctrl0 && addr < s->r_ctrl0 + s->ctrl->max_slaves)) {
         return s->regs[addr];
@@ -697,6 +698,8 @@ static void aspeed_smc_write(void *opaque, hwaddr addr, uint64_t data,
         if (value != s->regs[R_SEG_ADDR0 + cs]) {
             aspeed_smc_flash_set_segment(s, cs, value);
         }
+    } else if (addr == R_DUMMY_DATA) {
+        s->regs[addr] = value & 0xff;
     } else {
         qemu_log_mask(LOG_UNIMP, "%s: not implemented: 0x%" HWADDR_PRIx "\n",
                       __func__, addr);
--

2.20.1

#8 lore raw

PATCH 4/4 aspeed/smc: snoop SPI transfers to fake dummy cycles

In reply to Cédric Le Goater

The m25p80 models dummy cycles using byte transfers. This works well when the transfers are initiated by the QEMU model of a SPI controller but when these are initiated by the OS, it breaks emulation.

Snoop the SPI transfer to catch commands requiring dummy cycles and replace them with byte transfers compatible with the m25p80 model.

---
 include/hw/ssi/aspeed_smc.h |   3 +
 hw/ssi/aspeed_smc.c         | 115 +++++++++++++++++++++++++++++++++++-
 2 files changed, 115 insertions(+), 3 deletions(-)
include/hw/ssi/aspeed_smc.h +3 -0
index 1f557313fa93..3b1e7fce6c86 100644
@@ -98,6 +98,9 @@ typedef struct AspeedSMCState {
     uint8_t conf_enable_w0;
 
     AspeedSMCFlash *flashes;
+
+    uint8_t snoop_index;
+    uint8_t snoop_dummies;
 } AspeedSMCState;
 
 #endif /* ASPEED_SMC_H */
hw/ssi/aspeed_smc.c +112 -3

153 lines not on this page · raw message

Signature · 1 line
2.20.1
#9 lore raw
In reply to Cédric Le Goater
Quoted 14 lines · Cédric Le Goater

Hello,

When in the User command mode, the Aspeed SMC controller driver performs the dummy cycles of a fast read command using byte transfers, that is ony byte for eight cycles. But, the QEMU m25p80 models one dummy cycle with one byte transfer.

To restore the correct number of cycles, this series adds a function snooping the SPI transfers to catch commands requiring dummy cycles and replaces them with byte transfers compatible with the m25p80 model.

Thanks,

Quoted 7 lines

C.

Cédric Le Goater (4):
aspeed/smc: fix default read value aspeed/smc: define registers for all possible CS aspeed/smc: Add dummy data register aspeed/smc: snoop transfers to fake dummy cycles

Applied to target-arm.next, thanks.

-- PMM