Skip to content

Commit ca61a08

Browse files
committed
[ot] hw/opentitan: ot_spi_device: add trace events for passthrough mode
Signed-off-by: Alice Ziuziakowska <[email protected]>
1 parent ad5c39c commit ca61a08

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
@@ -997,7 +997,7 @@ ot_spi_device_flash_match_command_slot(OtSPIDeviceState *s, uint8_t cmd)
997997
}
998998
}
999999

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

@@ -1521,46 +1521,55 @@ static bool ot_spi_device_flash_try_intercept_hw_command(OtSPIDeviceState *s)
15211521
SpiDeviceFlash *f = &s->flash;
15221522

15231523
uint32_t intercept_val32 = s->spi_regs[R_INTERCEPT_EN];
1524+
bool intercepted = false;
1525+
15241526
switch (f->slot) {
15251527
case SLOT_HW_READ_STATUS1:
15261528
case SLOT_HW_READ_STATUS2:
15271529
case SLOT_HW_READ_STATUS3:
15281530
if (FIELD_EX32(intercept_val32, INTERCEPT_EN, STATUS)) {
15291531
ot_spi_device_flash_decode_read_status(s);
1530-
return true;
1532+
intercepted = true;
15311533
}
1532-
return false;
1534+
break;
15331535
case SLOT_HW_READ_JEDEC:
15341536
if (FIELD_EX32(intercept_val32, INTERCEPT_EN, JEDEC)) {
15351537
ot_spi_device_flash_decode_read_jedec(s);
1536-
return true;
1538+
intercepted = true;
15371539
}
1538-
return false;
1540+
break;
15391541
case SLOT_HW_READ_SFDP:
15401542
if (FIELD_EX32(intercept_val32, INTERCEPT_EN, SFDP)) {
15411543
ot_spi_device_flash_decode_read_sfdp(s);
1542-
return true;
1544+
intercepted = true;
15431545
}
1544-
return false;
1546+
break;
15451547
case SLOT_HW_READ_NORMAL:
15461548
case SLOT_HW_READ_FAST:
15471549
case SLOT_HW_READ_DUAL:
15481550
case SLOT_HW_READ_QUAD:
15491551
case SLOT_HW_READ_DUAL_IO:
15501552
case SLOT_HW_READ_QUAD_IO:
15511553
/* We try to intercept at every read after an address is given */
1552-
return false;
1554+
break;
15531555
case SLOT_HW_EN4B:
15541556
case SLOT_HW_EX4B:
15551557
ot_spi_device_flash_decode_addr4_enable(s);
1556-
return true;
1558+
intercepted = true;
1559+
break;
15571560
case SLOT_HW_WREN:
15581561
case SLOT_HW_WRDI:
15591562
/* These HW commands cannot be intercepted */
1560-
return false;
1563+
break;
15611564
default:
1562-
return false;
1565+
break;
15631566
}
1567+
1568+
if (intercepted) {
1569+
trace_ot_spi_device_flash_intercepted_command(s->ot_id, f->slot);
1570+
}
1571+
1572+
return intercepted;
15641573
}
15651574

15661575
static void
@@ -1601,9 +1610,13 @@ ot_spi_device_flash_passthrough_addr(OtSPIDeviceState *s, uint8_t rx)
16011610
f->buffer[f->pos] = rx;
16021611
if (f->cmd_addr_swap_en) {
16031612
unsigned byte_sel = (f->len - f->pos - 1u);
1604-
rx = ot_spi_device_swap_byte_data(rx, byte_sel,
1605-
s->spi_regs[R_ADDR_SWAP_MASK],
1606-
s->spi_regs[R_ADDR_SWAP_DATA]);
1613+
uint8_t swapped_rx =
1614+
ot_spi_device_swap_byte_data(rx, byte_sel,
1615+
s->spi_regs[R_ADDR_SWAP_MASK],
1616+
s->spi_regs[R_ADDR_SWAP_DATA]);
1617+
trace_ot_spi_device_flash_swap_byte(s->ot_id, "address", byte_sel, rx,
1618+
swapped_rx);
1619+
rx = swapped_rx;
16071620
}
16081621

16091622
(void)ssi_transfer(s->spi, (uint32_t)rx);
@@ -1648,9 +1661,13 @@ ot_spi_device_flash_passthrough_payload(OtSPIDeviceState *s, uint8_t rx)
16481661

16491662
g_assert(f->cmd_payload_swap_en);
16501663

1651-
rx = ot_spi_device_swap_byte_data(rx, f->pos,
1652-
s->spi_regs[R_PAYLOAD_SWAP_MASK],
1653-
s->spi_regs[R_PAYLOAD_SWAP_DATA]);
1664+
uint8_t swapped_rx =
1665+
ot_spi_device_swap_byte_data(rx, f->pos,
1666+
s->spi_regs[R_PAYLOAD_SWAP_MASK],
1667+
s->spi_regs[R_PAYLOAD_SWAP_DATA]);
1668+
trace_ot_spi_device_flash_swap_byte(s->ot_id, "payload", f->pos, rx,
1669+
swapped_rx);
1670+
rx = swapped_rx;
16541671

16551672
(void)ssi_transfer(s->spi, (uint32_t)rx);
16561673

@@ -1668,6 +1685,8 @@ static uint8_t ot_spi_device_flash_passthrough_read(OtSPIDeviceState *s)
16681685
if (f->slot >= SLOT_HW_READ_NORMAL && f->slot <= SLOT_HW_READ_QUAD_IO) {
16691686
if (ot_spi_device_get_command_address_size(s) != 0u) {
16701687
if (ot_spi_device_is_mailbox_match(s, f->address)) {
1688+
trace_ot_spi_device_flash_intercept_mailbox(s->ot_id,
1689+
f->address);
16711690
uint8_t *mbx = (uint8_t *)&s->sram[SPI_SRAM_MBX_OFFSET];
16721691
uint8_t tx = mbx[f->address & (SPI_SRAM_MBX_SIZE - 1u)];
16731692
f->address += 1u;
@@ -1727,6 +1746,7 @@ ot_spi_device_flash_transfer_passthrough(OtSPIDeviceState *s, uint8_t rx)
17271746

17281747
if (ot_spi_device_flash_passthrough_filter(s, rx)) {
17291748
/* command opcode is filtered, discard all bytes untl next CS */
1749+
trace_ot_spi_device_flash_filtered_command(s->ot_id, rx);
17301750
FLASH_CHANGE_STATE(s, IDLE);
17311751
BUS_CHANGE_STATE(s, DISCARD);
17321752
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)