Skip to content

Commit a49e9bf

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

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
@@ -1000,7 +1000,7 @@ ot_spi_device_flash_match_command_slot(OtSPIDeviceState *s, uint8_t cmd)
10001000
}
10011001
}
10021002

1003-
trace_ot_spi_device_flash_ignored_command(s->ot_id, "unmatched", cmd);
1003+
trace_ot_spi_device_flash_unmatched_command(s->ot_id, cmd);
10041004
return false;
10051005
}
10061006

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

15351535
uint32_t intercept_val32 = s->spi_regs[R_INTERCEPT_EN];
1536+
bool intercepted = false;
1537+
15361538
switch (f->slot) {
15371539
case SLOT_HW_READ_STATUS1:
15381540
case SLOT_HW_READ_STATUS2:
15391541
case SLOT_HW_READ_STATUS3:
15401542
if (FIELD_EX32(intercept_val32, INTERCEPT_EN, STATUS)) {
15411543
ot_spi_device_flash_decode_read_status(s);
1542-
return true;
1544+
intercepted = true;
15431545
}
1544-
return false;
1546+
break;
15451547
case SLOT_HW_READ_JEDEC:
15461548
if (FIELD_EX32(intercept_val32, INTERCEPT_EN, JEDEC)) {
15471549
ot_spi_device_flash_decode_read_jedec(s);
1548-
return true;
1550+
intercepted = true;
15491551
}
1550-
return false;
1552+
break;
15511553
case SLOT_HW_READ_SFDP:
15521554
if (FIELD_EX32(intercept_val32, INTERCEPT_EN, SFDP)) {
15531555
ot_spi_device_flash_decode_read_sfdp(s);
1554-
return true;
1556+
intercepted = true;
15551557
}
1556-
return false;
1558+
break;
15571559
case SLOT_HW_READ_NORMAL:
15581560
case SLOT_HW_READ_FAST:
15591561
case SLOT_HW_READ_DUAL:
15601562
case SLOT_HW_READ_QUAD:
15611563
case SLOT_HW_READ_DUAL_IO:
15621564
case SLOT_HW_READ_QUAD_IO:
15631565
/* We try to intercept at every read after an address is given */
1564-
return false;
1566+
break;
15651567
case SLOT_HW_EN4B:
15661568
case SLOT_HW_EX4B:
15671569
ot_spi_device_flash_decode_addr4_enable(s);
1568-
return true;
1570+
intercepted = true;
1571+
break;
15691572
case SLOT_HW_WREN:
15701573
case SLOT_HW_WRDI:
15711574
/* These HW commands cannot be intercepted */
1572-
return false;
1575+
break;
15731576
default:
1574-
return false;
1577+
break;
15751578
}
1579+
1580+
if (intercepted) {
1581+
trace_ot_spi_device_flash_intercepted_command(s->ot_id, f->slot);
1582+
}
1583+
1584+
return intercepted;
15761585
}
15771586

15781587
static void
@@ -1613,9 +1622,13 @@ ot_spi_device_flash_passthrough_addr(OtSPIDeviceState *s, uint8_t rx)
16131622
f->buffer[f->pos] = rx;
16141623
if (f->cmd_addr_swap_en) {
16151624
unsigned byte_sel = (f->len - f->pos - 1u);
1616-
rx = ot_spi_device_swap_byte_data(rx, byte_sel,
1617-
s->spi_regs[R_ADDR_SWAP_MASK],
1618-
s->spi_regs[R_ADDR_SWAP_DATA]);
1625+
uint8_t swapped_rx =
1626+
ot_spi_device_swap_byte_data(rx, byte_sel,
1627+
s->spi_regs[R_ADDR_SWAP_MASK],
1628+
s->spi_regs[R_ADDR_SWAP_DATA]);
1629+
trace_ot_spi_device_flash_swap_byte(s->ot_id, "address", byte_sel, rx,
1630+
swapped_rx);
1631+
rx = swapped_rx;
16191632
}
16201633

16211634
(void)ot_spi_device_flash_spi_transfer(s, rx);
@@ -1660,9 +1673,13 @@ ot_spi_device_flash_passthrough_payload(OtSPIDeviceState *s, uint8_t rx)
16601673

16611674
g_assert(f->cmd_payload_swap_en);
16621675

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

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

@@ -1680,6 +1697,8 @@ static uint8_t ot_spi_device_flash_passthrough_read(OtSPIDeviceState *s)
16801697
if (f->slot >= SLOT_HW_READ_NORMAL && f->slot <= SLOT_HW_READ_QUAD_IO) {
16811698
if (ot_spi_device_get_command_address_size(s) != 0u) {
16821699
if (ot_spi_device_is_mailbox_match(s, f->address)) {
1700+
trace_ot_spi_device_flash_intercept_mailbox(s->ot_id,
1701+
f->address);
16831702
uint8_t *mbx = (uint8_t *)&s->sram[SPI_SRAM_MBX_OFFSET];
16841703
uint8_t tx = mbx[f->address & (SPI_SRAM_MBX_SIZE - 1u)];
16851704
f->address += 1u;
@@ -1739,6 +1758,7 @@ ot_spi_device_flash_transfer_passthrough(OtSPIDeviceState *s, uint8_t rx)
17391758

17401759
if (ot_spi_device_flash_passthrough_filter(s, rx)) {
17411760
/* command opcode is filtered, discard all bytes untl next CS */
1761+
trace_ot_spi_device_flash_filtered_command(s->ot_id, rx);
17421762
FLASH_CHANGE_STATE(s, IDLE);
17431763
BUS_CHANGE_STATE(s, DISCARD);
17441764
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)