Skip to content

Commit ba4a94b

Browse files
rivos-eblotjwnrt
authored andcommitted
[ot] hw/opentitan: ot_spi_device: fix upload command FIFO status.
Interrupt state for upload command FIFO should not be set if no new command has been pushed, even if the CMD FIFO is not empty. Signed-off-by: Emmanuel Blot <eblot@rivosinc.com> (cherry picked from commit dd781da)
1 parent 38e8fb4 commit ba4a94b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

hw/opentitan/ot_spi_device.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ typedef struct {
418418
QEMUTimer *irq_timer; /* Timer to resume processing after a READBUF_* IRQ */
419419
bool loop; /* Keep reading the buffer if end is reached */
420420
bool watermark; /* Read watermark hit, used as flip-flop */
421+
bool new_cmd; /* New command has been pushed in current SPI transaction */
421422
} SpiDeviceFlash;
422423

423424
typedef struct {
@@ -811,7 +812,7 @@ static void ot_spi_device_release_cs(OtSPIDeviceState *s)
811812
bool update_irq = false;
812813
switch (ot_spi_device_get_mode(s)) {
813814
case CTRL_MODE_FLASH:
814-
if (!fifo8_is_empty(&f->cmd_fifo)) {
815+
if (!fifo8_is_empty(&f->cmd_fifo) && f->new_cmd) {
815816
s->spi_regs[R_INTR_STATE] |= INTR_UPLOAD_CMDFIFO_NOT_EMPTY_MASK;
816817
update_irq = true;
817818
}
@@ -858,6 +859,8 @@ static void ot_spi_device_release_cs(OtSPIDeviceState *s)
858859
break;
859860
}
860861

862+
f->new_cmd = false;
863+
861864
if (update_irq) {
862865
ot_spi_device_update_irqs(s);
863866
}
@@ -930,6 +933,7 @@ static void ot_spi_device_flash_decode_command(OtSPIDeviceState *s, uint8_t cmd)
930933
}
931934
trace_ot_spi_device_flash_upload(f->slot, f->cmd_info, set_busy);
932935
fifo8_push(&f->cmd_fifo, COMMAND_OPCODE(f->cmd_info));
936+
f->new_cmd = true;
933937
}
934938
}
935939

@@ -2120,6 +2124,7 @@ static void ot_spi_device_reset(DeviceState *dev)
21202124

21212125
ot_spi_device_release_cs(s);
21222126
f->watermark = false;
2127+
f->new_cmd = false;
21232128
s->spi_regs[R_CONTROL] = 0x10u;
21242129
s->spi_regs[R_STATUS] = 0x60u;
21252130
s->spi_regs[R_JEDEC_CC] = 0x7fu;

0 commit comments

Comments
 (0)