Skip to content

Commit 28ffc3c

Browse files
committed
[ot] hw/opentitan: ot_spi_device: add trace events for Passthrough mode
Signed-off-by: Alice Ziuziakowska <[email protected]>
1 parent 6c95bee commit 28ffc3c

File tree

2 files changed

+44
-20
lines changed

2 files changed

+44
-20
lines changed

hw/opentitan/ot_spi_device.c

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ ot_spi_device_flash_match_command_slot(OtSPIDeviceState *s, uint8_t cmd)
998998
}
999999
}
10001000

1001-
trace_ot_spi_device_flash_ignored_command(s->ot_id, "unmatched", cmd);
1001+
trace_ot_spi_device_flash_unmatched_command(s->ot_id, cmd);
10021002
return false;
10031003
}
10041004

@@ -1532,46 +1532,55 @@ static bool ot_spi_device_flash_try_intercept_hw_command(OtSPIDeviceState *s)
15321532
SpiDeviceFlash *f = &s->flash;
15331533

15341534
uint32_t intercept_val32 = s->spi_regs[R_INTERCEPT_EN];
1535+
bool intercepted = false;
1536+
15351537
switch (f->slot) {
15361538
case SLOT_HW_READ_STATUS1:
15371539
case SLOT_HW_READ_STATUS2:
15381540
case SLOT_HW_READ_STATUS3:
15391541
if (FIELD_EX32(intercept_val32, INTERCEPT_EN, STATUS)) {
15401542
ot_spi_device_flash_decode_read_status(s);
1541-
return true;
1543+
intercepted = true;
15421544
}
1543-
return false;
1545+
break;
15441546
case SLOT_HW_READ_JEDEC:
15451547
if (FIELD_EX32(intercept_val32, INTERCEPT_EN, JEDEC)) {
15461548
ot_spi_device_flash_decode_read_jedec(s);
1547-
return true;
1549+
intercepted = true;
15481550
}
1549-
return false;
1551+
break;
15501552
case SLOT_HW_READ_SFDP:
15511553
if (FIELD_EX32(intercept_val32, INTERCEPT_EN, SFDP)) {
15521554
ot_spi_device_flash_decode_read_sfdp(s);
1553-
return true;
1555+
intercepted = true;
15541556
}
1555-
return false;
1557+
break;
15561558
case SLOT_HW_READ_NORMAL:
15571559
case SLOT_HW_READ_FAST:
15581560
case SLOT_HW_READ_DUAL:
15591561
case SLOT_HW_READ_QUAD:
15601562
case SLOT_HW_READ_DUAL_IO:
15611563
case SLOT_HW_READ_QUAD_IO:
15621564
/* We try to intercept at every read after an address is given */
1563-
return false;
1565+
break;
15641566
case SLOT_HW_EN4B:
15651567
case SLOT_HW_EX4B:
15661568
ot_spi_device_flash_decode_addr4_enable(s);
1567-
return true;
1569+
intercepted = true;
1570+
break;
15681571
case SLOT_HW_WREN:
15691572
case SLOT_HW_WRDI:
15701573
/* These HW commands cannot be intercepted */
1571-
return false;
1574+
break;
15721575
default:
1573-
return false;
1576+
break;
15741577
}
1578+
1579+
if (intercepted) {
1580+
trace_ot_spi_device_flash_intercepted_command(s->ot_id, f->slot);
1581+
}
1582+
1583+
return intercepted;
15751584
}
15761585

15771586
static void
@@ -1612,9 +1621,13 @@ ot_spi_device_flash_passthrough_addr(OtSPIDeviceState *s, uint8_t rx)
16121621
f->buffer[f->pos] = rx;
16131622
if (f->cmd_addr_swap_en) {
16141623
unsigned byte_sel = (f->len - f->pos - 1u);
1615-
rx = ot_spi_device_swap_byte_data(rx, byte_sel,
1616-
s->spi_regs[R_ADDR_SWAP_MASK],
1617-
s->spi_regs[R_ADDR_SWAP_DATA]);
1624+
uint8_t swapped_rx =
1625+
ot_spi_device_swap_byte_data(rx, byte_sel,
1626+
s->spi_regs[R_ADDR_SWAP_MASK],
1627+
s->spi_regs[R_ADDR_SWAP_DATA]);
1628+
trace_ot_spi_device_flash_swap_byte(s->ot_id, "address", byte_sel, rx,
1629+
swapped_rx);
1630+
rx = swapped_rx;
16181631
}
16191632

16201633
(void)ot_spi_device_flash_spi_transfer(s, rx);
@@ -1659,9 +1672,13 @@ ot_spi_device_flash_passthrough_payload(OtSPIDeviceState *s, uint8_t rx)
16591672

16601673
g_assert(f->cmd_payload_swap_en);
16611674

1662-
rx = ot_spi_device_swap_byte_data(rx, f->pos,
1663-
s->spi_regs[R_PAYLOAD_SWAP_MASK],
1664-
s->spi_regs[R_PAYLOAD_SWAP_DATA]);
1675+
uint8_t swapped_rx =
1676+
ot_spi_device_swap_byte_data(rx, f->pos,
1677+
s->spi_regs[R_PAYLOAD_SWAP_MASK],
1678+
s->spi_regs[R_PAYLOAD_SWAP_DATA]);
1679+
trace_ot_spi_device_flash_swap_byte(s->ot_id, "payload", f->pos, rx,
1680+
swapped_rx);
1681+
rx = swapped_rx;
16651682

16661683
(void)ot_spi_device_flash_spi_transfer(s, rx);
16671684

@@ -1679,6 +1696,8 @@ static uint8_t ot_spi_device_flash_passthrough_read(OtSPIDeviceState *s)
16791696
if (f->slot >= SLOT_HW_READ_NORMAL && f->slot <= SLOT_HW_READ_QUAD_IO) {
16801697
if (ot_spi_device_get_command_address_size(s) != 0u) {
16811698
if (ot_spi_device_is_mailbox_match(s, f->address)) {
1699+
trace_ot_spi_device_flash_intercept_mailbox(s->ot_id,
1700+
f->address);
16821701
uint8_t *mbx = (uint8_t *)&s->sram[SPI_SRAM_MBX_OFFSET];
16831702
uint8_t tx = mbx[f->address & (SPI_SRAM_MBX_SIZE - 1u)];
16841703
f->address += 1u;
@@ -1738,6 +1757,7 @@ ot_spi_device_flash_transfer_passthrough(OtSPIDeviceState *s, uint8_t rx)
17381757

17391758
if (ot_spi_device_flash_passthrough_filter(s, rx)) {
17401759
/* command opcode is filtered, discard all bytes untl next CS */
1760+
trace_ot_spi_device_flash_filtered_command(s->ot_id, rx);
17411761
FLASH_CHANGE_STATE(s, IDLE);
17421762
BUS_CHANGE_STATE(s, DISCARD);
17431763
break;

hw/opentitan/trace-events

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -548,18 +548,22 @@ ot_spi_device_flash_transfer(const char *id, const char *dir, uint8_t byte) "%s:
548548
ot_spi_device_flash_byte_unexpected(const char *id, uint8_t rx) "%s: unexpected byte 0x%02x after completed command"
549549
ot_spi_device_flash_change_state(const char *id, int line, const char *prev, int preval, const char *next, int nextval) "%s: @%d: %s[%d] -> %s[%d]"
550550
ot_spi_device_flash_cross_buffer(const char *id, const char *msg, uint32_t addr) "%s: %s 0x%08x"
551-
ot_spi_device_flash_disabled_slot(const char *id, uint8_t cmd, unsigned slot) "%s: cmd 0x%02x matched, disabled slot %u"
551+
ot_spi_device_flash_disabled_slot(const char *id, uint8_t cmd, unsigned slot) "%s: cmd 0x%02x matched disabled slot %u"
552552
ot_spi_device_flash_exec(const char *id, const char *cmd) "%s: %s"
553-
ot_spi_device_flash_ignored_command(const char *id, const char* msg, uint8_t cmd) "%s: %s cmd 0x%02x"
554-
ot_spi_device_flash_new_command(const char *id, const char* type, uint8_t cmd, unsigned slot) "%s: %s CMD 0x%02X slot %u"
553+
ot_spi_device_flash_filtered_command(const char *id, uint8_t cmd) "%s: filtered cmd %02x"
554+
ot_spi_device_flash_intercepted_command(const char *id, unsigned slot) "%s: intercepted HW cmd slot %u"
555+
ot_spi_device_flash_intercept_mailbox(const char *id, uint32_t addr) "%s: intercepted read addr:0x%08x to mailbox region"
556+
ot_spi_device_flash_new_command(const char *id, const char* type, uint8_t cmd, unsigned slot) "%s: %s CMD 0x%02x slot %u"
555557
ot_spi_device_flash_overflow(const char *id, const char *msg) "%s: %s"
556558
ot_spi_device_flash_pace(const char *id, const char *msg, bool pending) "%s: %s: %u"
557559
ot_spi_device_flash_payload(const char *id, unsigned fpos, unsigned idx, unsigned len) "%s: pos:%u idx:%u len:%u"
558560
ot_spi_device_flash_push_address(const char *id, uint32_t address) "%s: 0x%08x"
559561
ot_spi_device_flash_set_read_addr(const char *id, uint32_t addr) "%s: 0x%08x"
562+
ot_spi_device_flash_swap_byte(const char *id, const char *type, unsigned byte_num, uint8_t prev, uint8_t cur) "%s: swapped %s byte %u 0x%02x -> 0x%02x"
560563
ot_spi_device_flash_read_status(const char *id, unsigned slot, uint8_t status) "%s: sr[%u] 0x%02x"
561564
ot_spi_device_flash_read_threshold(const char *id, uint32_t addr, uint32_t threshold) "%s: 0x%08x @ 0x%08x"
562565
ot_spi_device_flash_unknown_command(const char *id, uint8_t opcode) "%s: 0x%02x"
566+
ot_spi_device_flash_unmatched_command(const char *id, uint8_t cmd) "%s: unmatched cmd 0x%02x"
563567
ot_spi_device_flash_upload(const char *id, unsigned slot, uint32_t cmd_info, bool busy) "%s: slot:%d info:0x%08x busy:%u"
564568
ot_spi_device_gen_fifo_error(const char *id, const char *msg) "%s: %s"
565569
ot_spi_device_gen_phase(const char *id, const char *func, unsigned off, unsigned lim, bool phase) "%s: %s off:0x%03x lim:0x%03x ph:%u"

0 commit comments

Comments
 (0)