Skip to content

Commit 4801c53

Browse files
committed
[ot] hw/opentitan: ot_socdbg_ctrl: improve state machine debug traces.
Signed-off-by: Emmanuel Blot <eblot@rivosinc.com>
1 parent 179dd0b commit 4801c53

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

hw/opentitan/ot_socdbg_ctrl.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "hw/riscv/ibex_common.h"
3939
#include "hw/riscv/ibex_irq.h"
4040
#include "trace.h"
41+
#include "trace/trace-hw_opentitan.h"
4142

4243

4344
/* clang-format off */
@@ -275,6 +276,11 @@ static void ot_socdbg_ctrl_tick_fsm(OtSoCDbgCtrlState *s)
275276
{
276277
bool cpu_boot_done = false;
277278

279+
trace_ot_socdbg_ctrl_tick_fsm(s->ot_id, STATE_NAME(s->fsm_state),
280+
s->boot_status_bm, s->lc_broadcast_bm,
281+
s->socdbg_bm, s->dft_ignore,
282+
s->boot_continue);
283+
278284
switch (s->fsm_state) {
279285
case ST_IDLE:
280286
if (s->boot_status_bm & R_BOOT_STATUS_LC_DONE_MASK) {
@@ -319,7 +325,11 @@ static void ot_socdbg_ctrl_tick_fsm(OtSoCDbgCtrlState *s)
319325
}
320326

321327
/* as with PwrMgr, use simple boolean value, not MuBi4 */
322-
ibex_irq_set(&s->cpu_boot[CPU_BOOT_DONE], (int)cpu_boot_done);
328+
int cpu_boot_done_i = (int)cpu_boot_done;
329+
if (ibex_irq_get_level(&s->cpu_boot[CPU_BOOT_DONE]) != cpu_boot_done_i) {
330+
trace_ot_socdbg_ctrl_cpu_boot_done(s->ot_id, cpu_boot_done_i);
331+
}
332+
ibex_irq_set(&s->cpu_boot[CPU_BOOT_DONE], cpu_boot_done_i);
323333
}
324334

325335
static void ot_socdbg_ctrl_update(OtSoCDbgCtrlState *s)
@@ -658,9 +668,8 @@ ot_socdbg_ctrl_dmi_read(void *opaque, hwaddr addr, unsigned size)
658668
break;
659669
}
660670

661-
uint32_t pc = ibex_get_current_pc();
662671
trace_ot_socdbg_ctrl_dmi_io_read_out(s->ot_id, (uint32_t)addr,
663-
REG_NAME(DMI, reg), val32, pc);
672+
REG_NAME(DMI, reg), val32);
664673

665674
return (uint32_t)val32;
666675
}
@@ -674,9 +683,8 @@ static void ot_socdbg_ctrl_dmi_write(void *opaque, hwaddr addr, uint64_t value,
674683

675684
hwaddr reg = R32_OFF(addr);
676685

677-
uint32_t pc = ibex_get_current_pc();
678686
trace_ot_socdbg_ctrl_dmi_io_write(s->ot_id, (uint32_t)addr,
679-
REG_NAME(DMI, reg), val32, pc);
687+
REG_NAME(DMI, reg), val32);
680688

681689
switch (reg) {
682690
case R_DMI_CONTROL:
@@ -733,6 +741,7 @@ static void ot_socdbg_ctrl_reset_enter(Object *dev, ResetType type)
733741
ot_socdbg_ctrl_core_update_irq(s);
734742
ibex_irq_set(&s->alert, 0);
735743
ibex_irq_set(&s->cpu_boot[CPU_BOOT_GOOD], (int)false);
744+
ibex_irq_set(&s->cpu_boot[CPU_BOOT_DONE], (int)false);
736745

737746
CHANGE_STATE(s, IDLE);
738747
s->fsm_tick_count = 0u;
@@ -742,6 +751,7 @@ static void ot_socdbg_ctrl_reset_enter(Object *dev, ResetType type)
742751
s->socdbg_state = OT_SOCDBG_ST_PROD;
743752
s->debug_policy = s->dbg_locked;
744753
s->debug_valid = false;
754+
s->boot_continue = false;
745755
}
746756

747757
static void ot_socdbg_ctrl_reset_exit(Object *obj, ResetType type)
@@ -761,7 +771,6 @@ static void ot_socdbg_ctrl_reset_exit(Object *obj, ResetType type)
761771
SCHEDULE_FSM(s);
762772
}
763773

764-
765774
static void ot_socdbg_ctrl_realize(DeviceState *dev, Error **errp)
766775
{
767776
OtSoCDbgCtrlState *s = OT_SOCDBG_CTRL(dev);

hw/opentitan/trace-events

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,14 +415,16 @@ ot_soc_proxy_update_irq(const char * id, unsigned n, int prev, int next) "%s: #%
415415

416416
ot_socdbg_ctrl_boot_status(const char *id, bool mclk, bool ioclk, bool otp, bool lc, bool cpu, unsigned rdone, unsigned rgood) "%s: mclk:%u ioclk:%u otp:%u lc:%u cpu_en:%u rom_done:0x%x rom_good:0x%x"
417417
ot_socdbg_ctrl_change_state(const char *id, int line, const char *old, int nold, const char *new, int nnew) "%s: @ %d [%s:%d] -> [%s:%d]"
418+
ot_socdbg_ctrl_cpu_boot_done(const char *id, int level) "%s: %d"
418419
ot_socdbg_ctrl_core_io_read_out(const char *id, uint32_t addr, const char * regname, uint32_t val, uint32_t pc) "%s: addr=0x%02x (%s), val=0x%x, pc=0x%x"
419420
ot_socdbg_ctrl_core_io_write(const char *id, uint32_t addr, const char * regname, uint32_t val, uint32_t pc) "%s: addr=0x%02x (%s), val=0x%x, pc=0x%x"
420421
ot_socdbg_ctrl_core_update_irq(const char *id, int new) "%s: %u"
421-
ot_socdbg_ctrl_dmi_io_read_out(const char *id, uint32_t addr, const char * regname, uint32_t val, uint32_t pc) "%s: addr=0x%02x (%s), val=0x%x, pc=0x%x"
422-
ot_socdbg_ctrl_dmi_io_write(const char *id, uint32_t addr, const char * regname, uint32_t val, uint32_t pc) "%s: addr=0x%02x (%s), val=0x%x, pc=0x%x"
422+
ot_socdbg_ctrl_dmi_io_read_out(const char *id, uint32_t addr, const char * regname, uint32_t val) "%s: addr=0x%02x (%s), val=0x%x"
423+
ot_socdbg_ctrl_dmi_io_write(const char *id, uint32_t addr, const char * regname, uint32_t val) "%s: addr=0x%02x (%s), val=0x%x"
423424
ot_socdbg_ctrl_rcv(const char *id, const char *src, unsigned n, int level) "%s: %s #%d: lvl 0x%x"
424425
ot_socdbg_ctrl_schedule_fsm(const char *id, const char *func, int line, unsigned tc) "%s: @ %s:%d (%u)"
425426
ot_socdbg_ctrl_socdbg_state(const char *id, const char *st) "%s: %s"
427+
ot_socdbg_ctrl_tick_fsm(const char *id, const char *st, uint32_t bs, uint32_t lc, uint32_t dbg, bool dfti, bool bc) "%s: %s bs:0x%03x lc:0x%02x dbg:0x%01x dfti:%u bc:%u"
426428
ot_socdbg_ctrl_update(const char *id, unsigned policy, bool valid) "%s: debug policy:0x%1x valid:%u"
427429

428430

0 commit comments

Comments
 (0)