Skip to content

Commit c08e867

Browse files
committed
[ot] hw/opentitan: ot_spi_device: Set WEL/BUSY bits in UPLOAD_CMD_FIFO
Change-Id: Ic52eed4009933cd4fc09da4a78fbd05e3de0822e Signed-off-by: Amit Kumar-Hermosillo <amitkh@google.com>
1 parent 8d8c0b0 commit c08e867

1 file changed

Lines changed: 21 additions & 11 deletions

File tree

hw/opentitan/ot_spi_device.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,8 @@ typedef struct {
428428
uint8_t *src; /* Selected read data source (alias) */
429429
uint8_t *payload; /* Selected write data sink (alias) */
430430
uint8_t *buffer; /* Temporary buffer to handle transfer */
431-
Fifo8 cmd_fifo; /* Command FIFO (HW uses 32-bit FIFO w/ 24-bit padding) */
431+
OtFifo32
432+
cmd_fifo; /* Command FIFO (HW uses 32-bit FIFO w/ 24-bit padding) */
432433
OtFifo32 address_fifo; /* Address FIFO */
433434
QEMUTimer *irq_timer; /* Timer to resume processing after a READBUF_* IRQ */
434435
bool loop; /* Keep reading the buffer if end is reached */
@@ -901,7 +902,7 @@ static void ot_spi_device_release(OtSPIDeviceState *s)
901902
case CTRL_MODE_FLASH:
902903
case CTRL_MODE_PASSTHROUGH:
903904
/* new uploaded command */
904-
if (!fifo8_is_empty(&f->cmd_fifo) && f->new_cmd) {
905+
if (!ot_fifo32_is_empty(&f->cmd_fifo) && f->new_cmd) {
905906
s->spi_regs[R_INTR_STATE] |= INTR_UPLOAD_CMDFIFO_NOT_EMPTY_MASK;
906907
update_irq = true;
907908
}
@@ -1045,11 +1046,20 @@ static void ot_spi_device_flash_try_upload(OtSPIDeviceState *s)
10451046
if (busy) {
10461047
s->spi_regs[R_FLASH_STATUS] |= R_FLASH_STATUS_BUSY_MASK;
10471048
}
1048-
if (fifo8_is_full(&f->cmd_fifo)) {
1049+
if (ot_fifo32_is_full(&f->cmd_fifo)) {
10491050
qemu_log_mask(LOG_GUEST_ERROR, "%s: %s: cmd fifo overflow",
10501051
__func__, s->ot_id);
10511052
} else {
1052-
fifo8_push(&f->cmd_fifo, COMMAND_OPCODE(f->cmd_info));
1053+
uint32_t data = COMMAND_OPCODE(f->cmd_info);
1054+
data = FIELD_DP32(data, UPLOAD_CMDFIFO, BUSY,
1055+
FIELD_EX32(s->spi_regs[R_FLASH_STATUS],
1056+
FLASH_STATUS, BUSY));
1057+
data = FIELD_DP32(data, UPLOAD_CMDFIFO, WEL,
1058+
FIELD_EX32(s->spi_regs[R_FLASH_STATUS],
1059+
FLASH_STATUS, WEL));
1060+
data = FIELD_DP32(data, UPLOAD_CMDFIFO, ADDR4B_MODE,
1061+
ot_spi_device_is_addr4b_en(s));
1062+
ot_fifo32_push(&f->cmd_fifo, data);
10531063
}
10541064
f->new_cmd = true;
10551065
trace_ot_spi_device_flash_upload(s->ot_id, f->slot, f->cmd_info, busy);
@@ -1972,17 +1982,17 @@ ot_spi_device_spi_regs_read(void *opaque, hwaddr addr, unsigned size)
19721982
case R_UPLOAD_STATUS:
19731983
val32 = 0;
19741984
val32 = FIELD_DP32(val32, UPLOAD_STATUS, CMDFIFO_DEPTH,
1975-
fifo8_num_used(&f->cmd_fifo));
1985+
ot_fifo32_num_used(&f->cmd_fifo));
19761986
val32 = FIELD_DP32(val32, UPLOAD_STATUS, CMDFIFO_NOTEMPTY,
1977-
!fifo8_is_empty(&f->cmd_fifo));
1987+
!ot_fifo32_is_empty(&f->cmd_fifo));
19781988
val32 = FIELD_DP32(val32, UPLOAD_STATUS, ADDRFIFO_DEPTH,
19791989
ot_fifo32_num_used(&f->address_fifo));
19801990
val32 = FIELD_DP32(val32, UPLOAD_STATUS, ADDRFIFO_NOTEMPTY,
19811991
!ot_fifo32_is_empty(&f->address_fifo));
19821992
break;
19831993
case R_UPLOAD_CMDFIFO:
1984-
if (!fifo8_is_empty(&f->cmd_fifo)) {
1985-
val32 = (uint32_t)fifo8_pop(&f->cmd_fifo);
1994+
if (!ot_fifo32_is_empty(&f->cmd_fifo)) {
1995+
val32 = ot_fifo32_pop(&f->cmd_fifo);
19861996
} else {
19871997
qemu_log_mask(LOG_UNIMP, "%s: %s: CMD_FIFO is empty\n", __func__,
19881998
s->ot_id);
@@ -2343,7 +2353,7 @@ static MemTxResult ot_spi_device_buf_read_with_attrs(
23432353
} else if (addr >= SPI_SRAM_CMD_OFFSET &&
23442354
last < (SPI_SRAM_CMD_OFFSET + SPI_SRAM_CMD_SIZE)) {
23452355
/* flash command FIFO */
2346-
val32 = ((const uint32_t *)s->flash.cmd_fifo.data)[addr >> 2u];
2356+
val32 = s->flash.cmd_fifo.data[addr >> 2u];
23472357
} else if (addr >= SPI_SRAM_ADDR_OFFSET &&
23482358
last < (SPI_SRAM_ADDR_OFFSET + SPI_SRAM_ADDR_SIZE)) {
23492359
/* flash address FIFO */
@@ -2885,7 +2895,7 @@ static void ot_spi_device_reset_enter(Object *obj, ResetType type)
28852895

28862896
fifo8_reset(&bus->chr_fifo);
28872897
/* not sure if the following FIFOs should be reset on clear_modes instead */
2888-
fifo8_reset(&f->cmd_fifo);
2898+
ot_fifo32_reset(&f->cmd_fifo);
28892899
ot_fifo32_reset(&f->address_fifo);
28902900

28912901
ot_spi_device_release(s);
@@ -2949,7 +2959,7 @@ static void ot_spi_device_init(Object *obj)
29492959
s->sram = g_new(uint32_t, SRAM_SIZE / sizeof(uint32_t));
29502960

29512961
fifo8_create(&bus->chr_fifo, SPI_BUS_HEADER_SIZE);
2952-
fifo8_create(&f->cmd_fifo, SPI_SRAM_CMD_SIZE / sizeof(uint32_t));
2962+
ot_fifo32_create(&f->cmd_fifo, SPI_SRAM_CMD_SIZE / sizeof(uint32_t));
29532963
fifo8_create(&s->tpm.rdfifo, SPI_TPM_READ_FIFO_SIZE_BYTES);
29542964
ot_fifo32_create(&f->address_fifo, SPI_SRAM_ADDR_SIZE / sizeof(uint32_t));
29552965
f->buffer =

0 commit comments

Comments
 (0)