Skip to content

Commit 6f5b2da

Browse files
amit-kumarhAlexJones0
authored andcommitted
[ot] hw/opentitan: ot_spi_device: Set WEL/BUSY bits in UPLOAD_CMD_FIFO
Change-Id: Ic52eed4009933cd4fc09da4a78fbd05e3de0822e Signed-off-by: Amit Kumar-Hermosillo <[email protected]>
1 parent 8d8c0b0 commit 6f5b2da

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

hw/opentitan/ot_spi_device.c

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ 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 cmd_fifo; /* Command FIFO */
432432
OtFifo32 address_fifo; /* Address FIFO */
433433
QEMUTimer *irq_timer; /* Timer to resume processing after a READBUF_* IRQ */
434434
bool loop; /* Keep reading the buffer if end is reached */
@@ -901,7 +901,7 @@ static void ot_spi_device_release(OtSPIDeviceState *s)
901901
case CTRL_MODE_FLASH:
902902
case CTRL_MODE_PASSTHROUGH:
903903
/* new uploaded command */
904-
if (!fifo8_is_empty(&f->cmd_fifo) && f->new_cmd) {
904+
if (!ot_fifo32_is_empty(&f->cmd_fifo) && f->new_cmd) {
905905
s->spi_regs[R_INTR_STATE] |= INTR_UPLOAD_CMDFIFO_NOT_EMPTY_MASK;
906906
update_irq = true;
907907
}
@@ -1045,11 +1045,20 @@ static void ot_spi_device_flash_try_upload(OtSPIDeviceState *s)
10451045
if (busy) {
10461046
s->spi_regs[R_FLASH_STATUS] |= R_FLASH_STATUS_BUSY_MASK;
10471047
}
1048-
if (fifo8_is_full(&f->cmd_fifo)) {
1048+
if (ot_fifo32_is_full(&f->cmd_fifo)) {
10491049
qemu_log_mask(LOG_GUEST_ERROR, "%s: %s: cmd fifo overflow",
10501050
__func__, s->ot_id);
10511051
} else {
1052-
fifo8_push(&f->cmd_fifo, COMMAND_OPCODE(f->cmd_info));
1052+
uint32_t data = COMMAND_OPCODE(f->cmd_info);
1053+
data = FIELD_DP32(data, UPLOAD_CMDFIFO, BUSY,
1054+
FIELD_EX32(s->spi_regs[R_FLASH_STATUS],
1055+
FLASH_STATUS, BUSY));
1056+
data = FIELD_DP32(data, UPLOAD_CMDFIFO, WEL,
1057+
FIELD_EX32(s->spi_regs[R_FLASH_STATUS],
1058+
FLASH_STATUS, WEL));
1059+
data = FIELD_DP32(data, UPLOAD_CMDFIFO, ADDR4B_MODE,
1060+
ot_spi_device_is_addr4b_en(s));
1061+
ot_fifo32_push(&f->cmd_fifo, data);
10531062
}
10541063
f->new_cmd = true;
10551064
trace_ot_spi_device_flash_upload(s->ot_id, f->slot, f->cmd_info, busy);
@@ -1803,7 +1812,6 @@ ot_spi_device_flash_passthrough_payload_phase(OtSPIDeviceState *s, uint8_t rx)
18031812
return SPI_DEFAULT_TX_RX_VALUE;
18041813
}
18051814

1806-
18071815
static uint8_t
18081816
ot_spi_device_flash_transfer_passthrough(OtSPIDeviceState *s, uint8_t rx)
18091817
{
@@ -1972,17 +1980,17 @@ ot_spi_device_spi_regs_read(void *opaque, hwaddr addr, unsigned size)
19721980
case R_UPLOAD_STATUS:
19731981
val32 = 0;
19741982
val32 = FIELD_DP32(val32, UPLOAD_STATUS, CMDFIFO_DEPTH,
1975-
fifo8_num_used(&f->cmd_fifo));
1983+
ot_fifo32_num_used(&f->cmd_fifo));
19761984
val32 = FIELD_DP32(val32, UPLOAD_STATUS, CMDFIFO_NOTEMPTY,
1977-
!fifo8_is_empty(&f->cmd_fifo));
1985+
!ot_fifo32_is_empty(&f->cmd_fifo));
19781986
val32 = FIELD_DP32(val32, UPLOAD_STATUS, ADDRFIFO_DEPTH,
19791987
ot_fifo32_num_used(&f->address_fifo));
19801988
val32 = FIELD_DP32(val32, UPLOAD_STATUS, ADDRFIFO_NOTEMPTY,
19811989
!ot_fifo32_is_empty(&f->address_fifo));
19821990
break;
19831991
case R_UPLOAD_CMDFIFO:
1984-
if (!fifo8_is_empty(&f->cmd_fifo)) {
1985-
val32 = (uint32_t)fifo8_pop(&f->cmd_fifo);
1992+
if (!ot_fifo32_is_empty(&f->cmd_fifo)) {
1993+
val32 = ot_fifo32_pop(&f->cmd_fifo);
19861994
} else {
19871995
qemu_log_mask(LOG_UNIMP, "%s: %s: CMD_FIFO is empty\n", __func__,
19881996
s->ot_id);
@@ -2261,7 +2269,6 @@ ot_spi_device_tpm_regs_read(void *opaque, hwaddr addr, unsigned size)
22612269
break;
22622270
}
22632271

2264-
22652272
uint32_t pc = ibex_get_current_pc();
22662273
trace_ot_spi_device_io_tpm_read_out(s->ot_id, (uint32_t)addr,
22672274
TPM_REG_NAME(reg), val32, pc);
@@ -2343,7 +2350,7 @@ static MemTxResult ot_spi_device_buf_read_with_attrs(
23432350
} else if (addr >= SPI_SRAM_CMD_OFFSET &&
23442351
last < (SPI_SRAM_CMD_OFFSET + SPI_SRAM_CMD_SIZE)) {
23452352
/* flash command FIFO */
2346-
val32 = ((const uint32_t *)s->flash.cmd_fifo.data)[addr >> 2u];
2353+
val32 = s->flash.cmd_fifo.data[addr >> 2u];
23472354
} else if (addr >= SPI_SRAM_ADDR_OFFSET &&
23482355
last < (SPI_SRAM_ADDR_OFFSET + SPI_SRAM_ADDR_SIZE)) {
23492356
/* flash address FIFO */
@@ -2819,7 +2826,6 @@ static int ot_spi_device_chr_be_change(void *opaque)
28192826
&ot_spi_device_chr_event_hander,
28202827
&ot_spi_device_chr_be_change, s, NULL, true);
28212828

2822-
28232829
fifo8_reset(&bus->chr_fifo);
28242830

28252831
ot_spi_device_release(s);
@@ -2885,7 +2891,7 @@ static void ot_spi_device_reset_enter(Object *obj, ResetType type)
28852891

28862892
fifo8_reset(&bus->chr_fifo);
28872893
/* not sure if the following FIFOs should be reset on clear_modes instead */
2888-
fifo8_reset(&f->cmd_fifo);
2894+
ot_fifo32_reset(&f->cmd_fifo);
28892895
ot_fifo32_reset(&f->address_fifo);
28902896

28912897
ot_spi_device_release(s);
@@ -2949,7 +2955,7 @@ static void ot_spi_device_init(Object *obj)
29492955
s->sram = g_new(uint32_t, SRAM_SIZE / sizeof(uint32_t));
29502956

29512957
fifo8_create(&bus->chr_fifo, SPI_BUS_HEADER_SIZE);
2952-
fifo8_create(&f->cmd_fifo, SPI_SRAM_CMD_SIZE / sizeof(uint32_t));
2958+
ot_fifo32_create(&f->cmd_fifo, SPI_SRAM_CMD_SIZE / sizeof(uint32_t));
29532959
fifo8_create(&s->tpm.rdfifo, SPI_TPM_READ_FIFO_SIZE_BYTES);
29542960
ot_fifo32_create(&f->address_fifo, SPI_SRAM_ADDR_SIZE / sizeof(uint32_t));
29552961
f->buffer =

0 commit comments

Comments
 (0)