Skip to content

Commit daa50e9

Browse files
committed
[ot] hw/opentitan: ibex_wrapper: make dv-sim-status shutdown configurable
Signed-off-by: James Wainwright <[email protected]>
1 parent 338ecc9 commit daa50e9

File tree

3 files changed

+46
-22
lines changed

3 files changed

+46
-22
lines changed

docs/opentitan/darjeeling.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@ virtual machine. It contains three ASCII chars `QMU` followed with a configurabl
209209
the MSB, whose meaning is not defined. It can be any 8-byte value, and defaults to 0x0. To configure
210210
this version field, use the `qemu_version` property of the Ibex Wrapper device.
211211

212+
The `DV_SIM_STATUS` register (address 0 of the `DV_SIM_WINDOW`) can be used to exit QEMU with a
213+
passing or failing status code. The lower half of the word is written either `900d` (good) or `baad`
214+
(bad). If an error code is written to the upper half of the word, QEMU will exit with that status
215+
code for failures. The `-global ot-ibex_wrapper.dv-sim-status-exit=[on|off]` can be used to control
216+
whether QEMU shuts down when this register is written.
217+
212218
There are two modes to handle address remapping, with different limitations:
213219

214220
- default mode: use an MMU-like implementation (via ot_vmapper) to remap addresses. This mode

docs/opentitan/earlgrey.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ virtual machine. It contains three ASCII chars `QMU` followed with a configurabl
181181
the MSB, whose meaning is not defined. It can be any 8-byte value, and defaults to 0x0. To configure
182182
this version field, use the `qemu_version` property of the Ibex Wrapper device.
183183

184+
The `DV_SIM_STATUS` register (address 0 of the `DV_SIM_WINDOW`) can be used to exit QEMU with a
185+
passing or failing status code. The lower half of the word is written either `900d` (good) or `baad`
186+
(bad). If an error code is written to the upper half of the word, QEMU will exit with that status
187+
code for failures. The `-global ot-ibex_wrapper.dv-sim-status-exit=[on|off]` can be used to control
188+
whether QEMU shuts down when this register is written.
189+
184190
There are two modes to handle address remapping, with different limitations:
185191

186192
- default mode: use an MMU-like implementation (via ot_vmapper) to remap addresses. This mode

hw/opentitan/ot_ibex_wrapper.c

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ struct OtIbexWrapperState {
238238
uint8_t qemu_version;
239239
bool lc_ignore;
240240
bool alias_mode;
241+
bool dv_sim_status_exit;
241242
CharBackend chr;
242243
};
243244

@@ -1136,30 +1137,39 @@ static void ot_ibex_wrapper_write_dv_sim_status(OtIbexWrapperState *s,
11361137
(void)reg;
11371138

11381139
ot_ibex_wrapper_status_report(s, value);
1139-
switch (value & DV_SIM_STATUS_CODE_MASK) {
1140-
case TEST_STATUS_PASSED:
1141-
trace_ot_ibex_wrapper_exit(s->ot_id, "DV SIM success, exiting", 0);
1142-
qemu_system_shutdown_request_with_code(SHUTDOWN_CAUSE_GUEST_SHUTDOWN,
1143-
0);
1144-
break;
1145-
case TEST_STATUS_FAILED: {
1146-
uint32_t info = SHARED_FIELD_EX32(value, DV_SIM_STATUS_INFO);
1147-
int ret;
1148-
if (info == 0) {
1149-
/* no extra info */
1150-
ret = 1;
1151-
} else {
1152-
ret = (int)(info & 0x7fu);
1140+
1141+
if (s->dv_sim_status_exit) {
1142+
switch (value & DV_SIM_STATUS_CODE_MASK) {
1143+
case TEST_STATUS_PASSED:
1144+
trace_ot_ibex_wrapper_exit(s->ot_id, "DV SIM success, exiting", 0);
1145+
qemu_system_shutdown_request_with_code(
1146+
SHUTDOWN_CAUSE_GUEST_SHUTDOWN, 0);
1147+
break;
1148+
case TEST_STATUS_FAILED: {
1149+
uint32_t info = SHARED_FIELD_EX32(value, DV_SIM_STATUS_INFO);
1150+
int ret;
1151+
if (info == 0) {
1152+
/* no extra info */
1153+
ret = 1;
1154+
} else {
1155+
ret = (int)(info & 0x7fu);
1156+
}
1157+
trace_ot_ibex_wrapper_exit(s->ot_id, "DV SIM failure, exiting",
1158+
ret);
1159+
qemu_system_shutdown_request_with_code(
1160+
SHUTDOWN_CAUSE_GUEST_SHUTDOWN, ret);
1161+
break;
11531162
}
1154-
trace_ot_ibex_wrapper_exit(s->ot_id, "DV SIM failure, exiting", ret);
1155-
qemu_system_shutdown_request_with_code(SHUTDOWN_CAUSE_GUEST_SHUTDOWN,
1156-
ret);
1157-
break;
1158-
}
1159-
default:
1160-
s->regs.dv_sim_win[DV_SIM_STATUS] = value;
1161-
break;
1163+
default:
1164+
break;
1165+
}
1166+
} else {
1167+
trace_ot_ibex_wrapper_exit(s->ot_id,
1168+
"dv-sim-status-exit disabled, not exiting",
1169+
0);
11621170
}
1171+
1172+
s->regs.dv_sim_win[DV_SIM_STATUS] = value;
11631173
}
11641174

11651175
static void ot_ibex_wrapper_write_dv_sim_log(OtIbexWrapperState *s,
@@ -1381,6 +1391,8 @@ static Property ot_ibex_wrapper_properties[] = {
13811391
DEFINE_PROP_UINT8("edn-ep", OtIbexWrapperState, edn_ep, UINT8_MAX),
13821392
DEFINE_PROP_BOOL("lc-ignore", OtIbexWrapperState, lc_ignore, false),
13831393
DEFINE_PROP_BOOL("alias-mode", OtIbexWrapperState, alias_mode, false),
1394+
DEFINE_PROP_BOOL("dv-sim-status-exit", OtIbexWrapperState,
1395+
dv_sim_status_exit, true),
13841396
DEFINE_PROP_UINT8("qemu_version", OtIbexWrapperState, qemu_version, 0),
13851397
DEFINE_PROP_STRING("lc-ignore-ids", OtIbexWrapperState, lc_ignore_ids),
13861398
DEFINE_PROP_CHR("logdev", OtIbexWrapperState, chr),

0 commit comments

Comments
 (0)