Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions hw/opentitan/ot_rstmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "qemu/timer.h"
#include "qemu/typedefs.h"
#include "qapi/error.h"
#include "hw/core/cpu.h"
#include "hw/opentitan/ot_alert.h"
#include "hw/opentitan/ot_common.h"
#include "hw/opentitan/ot_i2c.h"
Expand Down Expand Up @@ -173,6 +174,7 @@ struct OtRstMgrState {
QEMUBH *bus_reset_bh;
QEMUTimer *sw_reset_timer;
CPUState *cpu;
bool reset_bus_queued;

uint32_t *regs;
uint32_t cpu_info_dump[8];
Expand Down Expand Up @@ -330,13 +332,41 @@ static void ot_rstmgr_sw_reset_timer_cb(void *opaque)

extern void riscv_cpu_get_crash_dump(CPUState *cs, uint32_t dump[8]);

static void ot_rstmgr_reset_bus(void *opaque);

static void ot_rstmgr_reset_bus_on_cpu(CPUState *cpu, run_on_cpu_data data)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: probably you can move this function down so we don't define the dummy ot_rstmgr_reset_bus

{
OtRstMgrState *s = data.host_ptr;

(void)cpu;
if (!s->reset_bus_queued) {
return;
}
s->reset_bus_queued = false;
ot_rstmgr_reset_bus(s);
}

static void ot_rstmgr_reset_bus(void *opaque)
{
OtRstMgrState *s = opaque;

g_assert(s->cpu);

if (!s->cpu->stopped) {
if (s->cpu->running) {
if (!s->reset_bus_queued) {
s->reset_bus_queued = true;
cpu_exit(s->cpu);
async_run_on_cpu(s->cpu, &ot_rstmgr_reset_bus_on_cpu,
RUN_ON_CPU_HOST_PTR(s));
}
return;
}

if (s->reset_bus_queued) {
return;
}

if (!qemu_cpu_is_self(s->cpu) && !s->cpu->stopped) {
/* request the vCPU to stop */
s->cpu->stop = true;

Expand All @@ -355,9 +385,8 @@ static void ot_rstmgr_reset_bus(void *opaque)
replay_mutex_lock();
bql_lock();
qemu_notify_event();
} else {
s->cpu->stop = false;
}
s->cpu->stop = false;

if (s->regs[R_CPU_INFO_CTRL] & R_CPU_INFO_CTRL_EN_MASK) {
riscv_cpu_get_crash_dump(s->cpu, s->cpu_info_dump);
Expand Down Expand Up @@ -477,7 +506,11 @@ static void ot_rstmgr_reset_req(void *opaque, int irq, int level)
trace_ot_rstmgr_reset_req(s->ot_id, REQ_NAME(level), req, fastclk);

if (s->cpu) {
cpu_pause(s->cpu);
if (qemu_cpu_is_self(s->cpu)) {
cpu_exit(s->cpu);
} else {
cpu_pause(s->cpu);
}
}

if (level == OT_RSTMGR_RESET_RV_DM) {
Expand Down Expand Up @@ -748,6 +781,7 @@ static void ot_rstmgr_reset_enter(Object *obj, ResetType type)

qemu_bh_cancel(s->bus_reset_bh);
timer_del(s->sw_reset_timer);
s->reset_bus_queued = false;

uint32_t reset_info = s->regs[R_RESET_INFO];
uint32_t alert_info_ctrl = s->regs[R_ALERT_INFO_CTRL];
Expand Down
14 changes: 5 additions & 9 deletions hw/opentitan/ot_sysrst_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ static void ot_sysrst_ctrl_check_events(OtSysrstCtrlState *s)
} else if (prev_trig && !curr_trig) {
if (out_ctl & R_COM_OUT_CTL_0_RST_REQ_MASK) {
timer_del(s->combo_rst_timer);
ibex_irq_set(&s->rst_req, 0);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In sysrst_ctrl_comboact.sv, rst_req_q is actually latched (assign rst_req_d = rst_req_q | combo_ot_pulse) and only cleared on reset (!rst_ni, which ot_sysrst_ctrl_reset_enter already handles), hence releasing the combo keys shouldn't lower rst_req here (only timer_del(s->combo_rst_timer) should happen if the detection timer hasn't expired yet)

}
if (out_ctl &
(R_COM_OUT_CTL_0_EC_RST_MASK | R_COM_OUT_CTL_0_RST_REQ_MASK)) {
Expand All @@ -414,8 +415,8 @@ static void ot_sysrst_ctrl_check_events(OtSysrstCtrlState *s)

if (trigger_rst) {
timer_mod_ns(s->combo_rst_timer,
qemu_clock_get_ns(QEMU_CLOCK_REALTIME) +
(rst_det_cyc > 0u ? 3000000LL : 0LL));
qemu_clock_get_ns(OT_VIRTUAL_CLOCK) +
(int64_t)(rst_det_cyc + 1u) * 5000LL);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: ((int64_t)rst_det_cyc + 1) * 5000LL to avoid 32-bit unsigned overflow if rst_det_cyc == UINT32_MAX (also IIUC u_sysrst_ctrl_detect in sysrst_ctrl_combo.sv counts key_intr_debounce_ctl + 1 cycles in DebounceSt before DetectSt, in case we want to include that too)

}

ot_sysrst_ctrl_update_outputs(s);
Expand All @@ -437,11 +438,6 @@ static void ot_sysrst_ctrl_input_change(void *opaque, int irq, int level)
}
s->poll_count = 0;

if (timer_pending(s->combo_rst_timer)) {
timer_mod_ns(s->combo_rst_timer,
qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + 3000000LL);
}

/*
* Per sysrst_ctrl_comboact.sv: ec_rst_l_i High -> Low transition
* (ec_rst_l_det_pulse) asserts ec_rst_l_q = 0 and stretches it for
Expand Down Expand Up @@ -689,8 +685,8 @@ static void ot_sysrst_ctrl_init(Object *obj)
s->ec_rst_l_hw = true;
s->ec_rst_timer =
timer_new_ns(QEMU_CLOCK_REALTIME, &ot_sysrst_ctrl_ec_rst_timer_cb, s);
s->combo_rst_timer = timer_new_ns(QEMU_CLOCK_REALTIME,
&ot_sysrst_ctrl_combo_rst_timer_cb, s);
s->combo_rst_timer =
timer_new_ns(OT_VIRTUAL_CLOCK, &ot_sysrst_ctrl_combo_rst_timer_cb, s);
s->ulp_timer =
timer_new_ns(OT_VIRTUAL_CLOCK, &ot_sysrst_ctrl_ulp_timer_cb, s);

Expand Down
Loading