Skip to content

Commit 650257a

Browse files
committed
[ot] hw/opentitan: ot_alert: Connect alert phase 0 NMI
In escalation phase 0, the alert handler sends an NMI to the CPU, which will interrupt execution so long as the NMI is enabled in Ibex itself. As such, we connect this functionality in the alert handler. See: https://opentitan.org/book/sw/device/silicon_creator/rom/doc/shutdown.html#alert-escalation-phase-actions Signed-off-by: Alex Jones <[email protected]>
1 parent 3daef7b commit 650257a

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

hw/opentitan/ot_alert.c

+7
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ struct OtAlertState {
220220
MemoryRegion mmio;
221221
IbexIRQ *irqs;
222222
IbexIRQ *esc_txs;
223+
IbexIRQ nmi_alert;
223224
OtAlertScheduler *schedulers;
224225

225226
OtAlertRegs regs; /* not ordered by register index */
@@ -571,6 +572,7 @@ static void ot_alert_clear_alert(OtAlertState *s, unsigned nclass)
571572
trace_ot_alert_escalation(s->ot_id, ACLASS(nclass), ix, "release");
572573
}
573574
ibex_irq_set(esc_tx, 0);
575+
ibex_irq_set(&s->nmi_alert, 0u);
574576
}
575577
/*
576578
* "Software can clear CLASSn_ACCUM_CNT with a write to CLASSA_CLR_SHADOWED"
@@ -741,6 +743,10 @@ static void ot_alert_signal_tx(void *opaque, int n, int level)
741743

742744
trace_ot_alert_signal_tx(s->ot_id, alert, (bool)level, alert_en);
743745

746+
if (alert_en && level) {
747+
ibex_irq_set(&s->nmi_alert, 1u);
748+
}
749+
744750
if (!alert_en || !level) {
745751
/* releasing the alert does not clear it */
746752
return;
@@ -1034,6 +1040,7 @@ static void ot_alert_realize(DeviceState *dev, Error **errp)
10341040
s->esc_txs = g_new0(IbexIRQ, PARAM_N_ESC_SEV);
10351041
ibex_qdev_init_irqs(OBJECT(dev), s->esc_txs, OT_ALERT_ESCALATE,
10361042
PARAM_N_ESC_SEV);
1043+
ibex_qdev_init_irq(OBJECT(dev), &s->nmi_alert, OT_ALERT_NMI);
10371044

10381045
qdev_init_gpio_in_named(dev, &ot_alert_signal_tx, OT_DEVICE_ALERT,
10391046
s->n_alerts);

hw/riscv/ot_earlgrey.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,9 @@ static const IbexDeviceDef ot_eg_soc_devices[] = {
640640
OT_EG_SOC_GPIO_ESCALATE(0, IBEX_WRAPPER, 0),
641641
OT_EG_SOC_GPIO_ESCALATE(1, LC_CTRL, 0),
642642
OT_EG_SOC_GPIO_ESCALATE(1, LC_CTRL, 1),
643-
OT_EG_SOC_GPIO_ESCALATE(3, PWRMGR, 0)
643+
OT_EG_SOC_GPIO_ESCALATE(3, PWRMGR, 0),
644+
OT_EG_SOC_SIGNAL(OT_ALERT_NMI, 0, IBEX_WRAPPER, \
645+
OT_IBEX_WRAPPER_NMI, OT_IBEX_NMI_ALERT)
644646
),
645647
.link = IBEXDEVICELINKDEFS(
646648
OT_EG_SOC_DEVLINK("edn", EDN0)

include/hw/opentitan/ot_alert.h

+1
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@ OBJECT_DECLARE_TYPE(OtAlertState, OtAlertStateClass, OT_ALERT)
3737

3838
#define OT_DEVICE_ALERT TYPE_OT_ALERT "-sig"
3939
#define OT_ALERT_ESCALATE TYPE_OT_ALERT "-esc"
40+
#define OT_ALERT_NMI TYPE_OT_ALERT "-nmi"
4041

4142
#endif /* HW_OPENTITAN_OT_ALERT_H */

0 commit comments

Comments
 (0)