|
27 | 27 | * THE SOFTWARE. |
28 | 28 | */ |
29 | 29 |
|
| 30 | +#include "hw/opentitan/ot_spi_device.h" |
30 | 31 | #include "qemu/osdep.h" |
31 | 32 | #include "qemu/bswap.h" |
32 | 33 | #include "qemu/fifo8.h" |
|
37 | 38 | #include "hw/opentitan/ot_alert.h" |
38 | 39 | #include "hw/opentitan/ot_common.h" |
39 | 40 | #include "hw/opentitan/ot_fifo32.h" |
40 | | -#include "hw/opentitan/ot_spi_device.h" |
41 | 41 | #include "hw/opentitan/ot_spi_host.h" |
42 | 42 | #include "hw/qdev-properties-system.h" |
43 | 43 | #include "hw/qdev-properties.h" |
@@ -428,7 +428,7 @@ typedef struct { |
428 | 428 | uint8_t *src; /* Selected read data source (alias) */ |
429 | 429 | uint8_t *payload; /* Selected write data sink (alias) */ |
430 | 430 | 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 */ |
432 | 432 | OtFifo32 address_fifo; /* Address FIFO */ |
433 | 433 | QEMUTimer *irq_timer; /* Timer to resume processing after a READBUF_* IRQ */ |
434 | 434 | bool loop; /* Keep reading the buffer if end is reached */ |
@@ -901,7 +901,7 @@ static void ot_spi_device_release(OtSPIDeviceState *s) |
901 | 901 | case CTRL_MODE_FLASH: |
902 | 902 | case CTRL_MODE_PASSTHROUGH: |
903 | 903 | /* 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) { |
905 | 905 | s->spi_regs[R_INTR_STATE] |= INTR_UPLOAD_CMDFIFO_NOT_EMPTY_MASK; |
906 | 906 | update_irq = true; |
907 | 907 | } |
@@ -1045,11 +1045,20 @@ static void ot_spi_device_flash_try_upload(OtSPIDeviceState *s) |
1045 | 1045 | if (busy) { |
1046 | 1046 | s->spi_regs[R_FLASH_STATUS] |= R_FLASH_STATUS_BUSY_MASK; |
1047 | 1047 | } |
1048 | | - if (fifo8_is_full(&f->cmd_fifo)) { |
| 1048 | + if (ot_fifo32_is_full(&f->cmd_fifo)) { |
1049 | 1049 | qemu_log_mask(LOG_GUEST_ERROR, "%s: %s: cmd fifo overflow", |
1050 | 1050 | __func__, s->ot_id); |
1051 | 1051 | } 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); |
1053 | 1062 | } |
1054 | 1063 | f->new_cmd = true; |
1055 | 1064 | 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) |
1803 | 1812 | return SPI_DEFAULT_TX_RX_VALUE; |
1804 | 1813 | } |
1805 | 1814 |
|
1806 | | - |
1807 | 1815 | static uint8_t |
1808 | 1816 | ot_spi_device_flash_transfer_passthrough(OtSPIDeviceState *s, uint8_t rx) |
1809 | 1817 | { |
@@ -1972,17 +1980,17 @@ ot_spi_device_spi_regs_read(void *opaque, hwaddr addr, unsigned size) |
1972 | 1980 | case R_UPLOAD_STATUS: |
1973 | 1981 | val32 = 0; |
1974 | 1982 | val32 = FIELD_DP32(val32, UPLOAD_STATUS, CMDFIFO_DEPTH, |
1975 | | - fifo8_num_used(&f->cmd_fifo)); |
| 1983 | + ot_fifo32_num_used(&f->cmd_fifo)); |
1976 | 1984 | val32 = FIELD_DP32(val32, UPLOAD_STATUS, CMDFIFO_NOTEMPTY, |
1977 | | - !fifo8_is_empty(&f->cmd_fifo)); |
| 1985 | + !ot_fifo32_is_empty(&f->cmd_fifo)); |
1978 | 1986 | val32 = FIELD_DP32(val32, UPLOAD_STATUS, ADDRFIFO_DEPTH, |
1979 | 1987 | ot_fifo32_num_used(&f->address_fifo)); |
1980 | 1988 | val32 = FIELD_DP32(val32, UPLOAD_STATUS, ADDRFIFO_NOTEMPTY, |
1981 | 1989 | !ot_fifo32_is_empty(&f->address_fifo)); |
1982 | 1990 | break; |
1983 | 1991 | 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); |
1986 | 1994 | } else { |
1987 | 1995 | qemu_log_mask(LOG_UNIMP, "%s: %s: CMD_FIFO is empty\n", __func__, |
1988 | 1996 | s->ot_id); |
@@ -2261,7 +2269,6 @@ ot_spi_device_tpm_regs_read(void *opaque, hwaddr addr, unsigned size) |
2261 | 2269 | break; |
2262 | 2270 | } |
2263 | 2271 |
|
2264 | | - |
2265 | 2272 | uint32_t pc = ibex_get_current_pc(); |
2266 | 2273 | trace_ot_spi_device_io_tpm_read_out(s->ot_id, (uint32_t)addr, |
2267 | 2274 | TPM_REG_NAME(reg), val32, pc); |
@@ -2343,7 +2350,7 @@ static MemTxResult ot_spi_device_buf_read_with_attrs( |
2343 | 2350 | } else if (addr >= SPI_SRAM_CMD_OFFSET && |
2344 | 2351 | last < (SPI_SRAM_CMD_OFFSET + SPI_SRAM_CMD_SIZE)) { |
2345 | 2352 | /* flash command FIFO */ |
2346 | | - val32 = ((const uint32_t *)s->flash.cmd_fifo.data)[addr >> 2u]; |
| 2353 | + val32 = s->flash.cmd_fifo.data[addr >> 2u]; |
2347 | 2354 | } else if (addr >= SPI_SRAM_ADDR_OFFSET && |
2348 | 2355 | last < (SPI_SRAM_ADDR_OFFSET + SPI_SRAM_ADDR_SIZE)) { |
2349 | 2356 | /* flash address FIFO */ |
@@ -2819,7 +2826,6 @@ static int ot_spi_device_chr_be_change(void *opaque) |
2819 | 2826 | &ot_spi_device_chr_event_hander, |
2820 | 2827 | &ot_spi_device_chr_be_change, s, NULL, true); |
2821 | 2828 |
|
2822 | | - |
2823 | 2829 | fifo8_reset(&bus->chr_fifo); |
2824 | 2830 |
|
2825 | 2831 | ot_spi_device_release(s); |
@@ -2885,7 +2891,7 @@ static void ot_spi_device_reset_enter(Object *obj, ResetType type) |
2885 | 2891 |
|
2886 | 2892 | fifo8_reset(&bus->chr_fifo); |
2887 | 2893 | /* 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); |
2889 | 2895 | ot_fifo32_reset(&f->address_fifo); |
2890 | 2896 |
|
2891 | 2897 | ot_spi_device_release(s); |
@@ -2949,7 +2955,7 @@ static void ot_spi_device_init(Object *obj) |
2949 | 2955 | s->sram = g_new(uint32_t, SRAM_SIZE / sizeof(uint32_t)); |
2950 | 2956 |
|
2951 | 2957 | 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)); |
2953 | 2959 | fifo8_create(&s->tpm.rdfifo, SPI_TPM_READ_FIFO_SIZE_BYTES); |
2954 | 2960 | ot_fifo32_create(&f->address_fifo, SPI_SRAM_ADDR_SIZE / sizeof(uint32_t)); |
2955 | 2961 | f->buffer = |
|
0 commit comments