Skip to content

Commit 179dd0b

Browse files
committed
[ot] hw/opentitan: ot_sram_ctrl: add an option to disable SRAM backend switch
This is only useful for debugging purposes, as it enables tracing read/write access to the memory. The trade off is that this feature leads to terrible performances. Signed-off-by: Emmanuel Blot <eblot@rivosinc.com>
1 parent 3deb3d3 commit 179dd0b

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

hw/opentitan/ot_sram_ctrl.c

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ struct OtSramCtrlState {
133133
uint32_t init_chunk_words; /* init chunk size in words */
134134
bool ifetch; /* only used when no otp_ctrl is defined */
135135
bool noinit; /* discard initialization emulation feature */
136+
bool noswitch; /* do not switch to performance/host RAM after init */
136137
};
137138

138139
#ifdef OT_SRAM_CTRL_DEBUG
@@ -224,10 +225,14 @@ static bool ot_sram_ctrl_initialize(OtSramCtrlState *s, unsigned count,
224225

225226
s->init_slot_bm = g_new0(uint64_t, s->init_slot_count);
226227

227-
/* switch memory to SRAM */
228-
trace_ot_sram_ctrl_initialization_complete(s->ot_id, "ctrl");
229-
230-
qemu_bh_schedule(s->switch_mr_bh);
228+
if (!s->noswitch) {
229+
/* switch memory to SRAM */
230+
trace_ot_sram_ctrl_initialization_complete(s->ot_id, "ctrl");
231+
qemu_bh_schedule(s->switch_mr_bh);
232+
} else {
233+
trace_ot_sram_ctrl_initialization_complete(s->ot_id,
234+
"ctrl/noswitch");
235+
}
231236

232237
return true;
233238
}
@@ -592,14 +597,22 @@ static MemTxResult ot_sram_ctrl_mem_init_write_with_attrs(
592597

593598
if (!s->init_slot_bm[slot]) {
594599
if (ot_sram_ctrl_mem_is_fully_initialized(s)) {
600+
if (!s->noswitch) {
601+
/*
602+
* perform the memory switch in a BH so that the current mr
603+
* is not in use when switching
604+
*/
605+
trace_ot_sram_ctrl_initialization_complete(s->ot_id,
606+
"write");
607+
608+
qemu_bh_schedule(s->switch_mr_bh);
609+
} else {
610+
if (!s->initialized) {
611+
trace_ot_sram_ctrl_initialization_complete(
612+
s->ot_id, "write/noswitch");
613+
}
614+
}
595615
s->initialized = true;
596-
/*
597-
* perform the memory switch in a BH so that the current mr
598-
* is not in use when switching
599-
*/
600-
trace_ot_sram_ctrl_initialization_complete(s->ot_id, "write");
601-
602-
qemu_bh_schedule(s->switch_mr_bh);
603616
}
604617
}
605618
}
@@ -615,6 +628,7 @@ static Property ot_sram_ctrl_properties[] = {
615628
DEFINE_PROP_UINT32("wci_size", OtSramCtrlState, init_chunk_words, 0u),
616629
DEFINE_PROP_BOOL("ifetch", OtSramCtrlState, ifetch, false),
617630
DEFINE_PROP_BOOL("noinit", OtSramCtrlState, noinit, false),
631+
DEFINE_PROP_BOOL("noswitch", OtSramCtrlState, noswitch, false),
618632
DEFINE_PROP_END_OF_LIST(),
619633
};
620634

0 commit comments

Comments
 (0)