Skip to content

Commit 26878e3

Browse files
committed
[ot] hw/opentitan: ot_ibex_wrapper: Add NMI support to Ibex Wrapper
Adds support for NMIs to Earlgrey's Ibex wrapper, allowing incoming NMI IRQ signals to be received by the device, which will then be propagated through an external IRQ signal to the Ibex itself (the hart) with the newly introduced IRQ_NMI value. This will allow support for hardware raising NMIs via GPIO signals between the QEMU devices, such that NMI support can be added to Earlgrey. Signed-off-by: Alex Jones <[email protected]>
1 parent a7079c0 commit 26878e3

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

hw/opentitan/ot_ibex_wrapper_eg.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ REG32(DBUS_ADDR_MATCHING_1, 0x40u)
8383
REG32(DBUS_REMAP_ADDR_0, 0x44u)
8484
REG32(DBUS_REMAP_ADDR_1, 0x48u)
8585
REG32(NMI_ENABLE, 0x4cu)
86-
SHARED_FIELD(NMI_ALERT_EN_BIT, 0u, 1u)
87-
SHARED_FIELD(NMI_WDOG_EN_BIT, 1u, 1u)
86+
SHARED_FIELD(NMI_ALERT_EN_BIT, OT_IBEX_NMI_ALERT, 1u)
87+
SHARED_FIELD(NMI_WDOG_EN_BIT, OT_IBEX_NMI_WDOG, 1u)
8888
REG32(NMI_STATE, 0x50u)
8989
REG32(ERR_STATUS, 0x54u)
9090
FIELD(ERR_STATUS, REG_INTG, 0u, 1u)
@@ -225,6 +225,7 @@ struct OtIbexWrapperEgState {
225225
MemoryRegion mmio;
226226
MemoryRegion remappers[PARAM_NUM_REGIONS];
227227
qemu_irq alerts[PARAM_NUM_ALERTS];
228+
IbexIRQ nmi_irq;
228229

229230
uint32_t *regs;
230231
OtIbexTestLogEngine *log_engine;
@@ -770,6 +771,24 @@ static void ot_ibex_wrapper_eg_cpu_enable_recv(void *opaque, int n, int level)
770771
ot_ibex_wrapper_eg_update_exec(s);
771772
}
772773

774+
static void ot_ibex_wrapper_eg_nmi_recv(void *opaque, int n, int level)
775+
{
776+
OtIbexWrapperEgState *s = opaque;
777+
778+
g_assert((unsigned)n < OT_IBEX_NMI_COUNT);
779+
780+
/* NMI_STATE is rw1c, so must be cleared with a register write. */
781+
if (level) {
782+
s->regs[R_NMI_STATE] |= 1u << (unsigned)n;
783+
}
784+
785+
trace_ot_ibex_wrapper_nmi_recv(s->ot_id ?: "", n ? "WDOG" : "ALERT",
786+
(bool)level);
787+
788+
uint32_t nmi_active = s->regs[R_NMI_ENABLE] & s->regs[R_NMI_STATE];
789+
ibex_irq_set(&s->nmi_irq, (bool)nmi_active);
790+
}
791+
773792
static void ot_ibex_wrapper_eg_escalate_rx(void *opaque, int n, int level)
774793
{
775794
OtIbexWrapperEgState *s = opaque;
@@ -1020,9 +1039,13 @@ static void ot_ibex_wrapper_eg_init(Object *obj)
10201039

10211040
qdev_init_gpio_in_named(DEVICE(obj), &ot_ibex_wrapper_eg_cpu_enable_recv,
10221041
OT_IBEX_WRAPPER_CPU_EN, OT_IBEX_CPU_EN_COUNT);
1042+
qdev_init_gpio_in_named(DEVICE(obj), &ot_ibex_wrapper_eg_nmi_recv,
1043+
OT_IBEX_WRAPPER_NMI, OT_IBEX_NMI_COUNT);
10231044
qdev_init_gpio_in_named(DEVICE(obj), &ot_ibex_wrapper_eg_escalate_rx,
10241045
OT_ALERT_ESCALATE, 1);
10251046

1047+
ibex_qdev_init_irq(obj, &s->nmi_irq, NULL);
1048+
10261049
s->regs = g_new0(uint32_t, REGS_COUNT);
10271050
s->log_engine = g_new0(OtIbexTestLogEngine, 1u);
10281051
}

hw/opentitan/trace-events

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ ot_i2c_update_irqs(const char *id, uint32_t active, uint32_t mask, uint32_t eff)
228228
# ot_ibex_wrapper.c
229229

230230
ot_ibex_wrapper_cpu_enable(const char *id, const char *ch, bool level) "%s: %s:%u"
231+
ot_ibex_wrapper_nmi_recv(const char *id, const char *ch, bool level) "%s: %s:%u"
231232
ot_ibex_wrapper_error(const char *id, const char *func, int line, const char *msg) "%s: %s:%d %s"
232233
ot_ibex_wrapper_escalate_rx(const char *id, bool level) "%s: %u"
233234
ot_ibex_wrapper_exit(const char *id, const char *msg, int val) "%s: %s (%d)"

hw/riscv/ot_earlgrey.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,7 @@ static const IbexDeviceDef ot_eg_soc_devices[] = {
10551055
{ .base = 0x411f0000u }
10561056
),
10571057
.gpio = IBEXGPIOCONNDEFS(
1058+
OT_EG_SOC_GPIO(0, HART, IRQ_NMI),
10581059
OT_EG_SOC_GPIO_ALERT(0, 61),
10591060
OT_EG_SOC_GPIO_ALERT(1, 62),
10601061
OT_EG_SOC_GPIO_ALERT(2, 63),

include/hw/opentitan/ot_ibex_wrapper.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,18 @@ struct OtIbexWrapperStateClass {
4545
};
4646

4747
#define OT_IBEX_WRAPPER_CPU_EN TYPE_OT_IBEX_WRAPPER "-cpu-en"
48+
#define OT_IBEX_WRAPPER_NMI TYPE_OT_IBEX_WRAPPER "-nmi"
4849

4950
typedef enum {
5051
OT_IBEX_LC_CTRL_CPU_EN,
5152
OT_IBEX_PWRMGR_CPU_EN,
5253
OT_IBEX_CPU_EN_COUNT
5354
} OtIbexWrapperCpuEnable;
5455

56+
typedef enum {
57+
OT_IBEX_NMI_ALERT,
58+
OT_IBEX_NMI_WDOG,
59+
OT_IBEX_NMI_COUNT
60+
} OtIbexWrapperNmi;
61+
5562
#endif /* HW_OPENTITAN_OT_IBEX_WRAPPER_H */

0 commit comments

Comments
 (0)