Skip to content

Commit

Permalink
[ot] hw/opentitan: ot_spi_device: fix upload command FIFO status.
Browse files Browse the repository at this point in the history
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 <[email protected]>
(cherry picked from commit dd781da)
  • Loading branch information
rivos-eblot authored and AlexJones0 committed Dec 18, 2024
1 parent ec86037 commit 43e917b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion hw/opentitan/ot_spi_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ typedef struct {
QEMUTimer *irq_timer; /* Timer to resume processing after a READBUF_* IRQ */
bool loop; /* Keep reading the buffer if end is reached */
bool watermark; /* Read watermark hit, used as flip-flop */
bool new_cmd; /* New command has been pushed in current SPI transaction */
} SpiDeviceFlash;

typedef struct {
Expand Down Expand Up @@ -811,7 +812,7 @@ static void ot_spi_device_release_cs(OtSPIDeviceState *s)
bool update_irq = false;
switch (ot_spi_device_get_mode(s)) {
case CTRL_MODE_FLASH:
if (!fifo8_is_empty(&f->cmd_fifo)) {
if (!fifo8_is_empty(&f->cmd_fifo) && f->new_cmd) {
s->spi_regs[R_INTR_STATE] |= INTR_UPLOAD_CMDFIFO_NOT_EMPTY_MASK;
update_irq = true;
}
Expand Down Expand Up @@ -858,6 +859,8 @@ static void ot_spi_device_release_cs(OtSPIDeviceState *s)
break;
}

f->new_cmd = false;

if (update_irq) {
ot_spi_device_update_irqs(s);
}
Expand Down Expand Up @@ -930,6 +933,7 @@ static void ot_spi_device_flash_decode_command(OtSPIDeviceState *s, uint8_t cmd)
}
trace_ot_spi_device_flash_upload(f->slot, f->cmd_info, set_busy);
fifo8_push(&f->cmd_fifo, COMMAND_OPCODE(f->cmd_info));
f->new_cmd = true;
}
}

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

ot_spi_device_release_cs(s);
f->watermark = false;
f->new_cmd = false;
s->spi_regs[R_CONTROL] = 0x10u;
s->spi_regs[R_STATUS] = 0x60u;
s->spi_regs[R_JEDEC_CC] = 0x7fu;
Expand Down

0 comments on commit 43e917b

Please sign in to comment.