Skip to content

Commit a6cc7db

Browse files
committed
[tests] Port aon_timer_wdog_lc_escalate_test to multitop
Signed-off-by: Robert Schilling <[email protected]>
1 parent 4faebab commit a6cc7db

File tree

2 files changed

+75
-49
lines changed

2 files changed

+75
-49
lines changed

sw/device/tests/BUILD

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,10 +696,11 @@ opentitan_test(
696696
exec_env = dicts.add(
697697
EARLGREY_TEST_ENVS,
698698
EARLGREY_SILICON_OWNER_ROM_EXT_ENVS,
699+
DARJEELING_TEST_ENVS,
699700
),
700701
verilator = verilator_params(timeout = "long"),
701702
deps = [
702-
"//hw/top_earlgrey/sw/autogen:top_earlgrey",
703+
"//hw/top:dt",
703704
"//sw/device/lib/base:math",
704705
"//sw/device/lib/base:mmio",
705706
"//sw/device/lib/dif:alert_handler",

sw/device/tests/aon_timer_wdog_lc_escalate_test.c

Lines changed: 73 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
#include <stdbool.h>
88
#include <stdint.h>
99

10+
#include "hw/top/dt/dt_alert_handler.h"
11+
#include "hw/top/dt/dt_aon_timer.h"
12+
#include "hw/top/dt/dt_pwrmgr.h"
13+
#include "hw/top/dt/dt_rstmgr.h"
14+
#include "hw/top/dt/dt_rv_plic.h"
15+
#include "sw/device/lib/base/macros.h"
1016
#include "sw/device/lib/base/math.h"
1117
#include "sw/device/lib/base/mmio.h"
1218
#include "sw/device/lib/dif/dif_alert_handler.h"
@@ -20,13 +26,10 @@
2026
#include "sw/device/lib/testing/alert_handler_testutils.h"
2127
#include "sw/device/lib/testing/aon_timer_testutils.h"
2228
#include "sw/device/lib/testing/rstmgr_testutils.h"
23-
#include "sw/device/lib/testing/rv_plic_testutils.h"
2429
#include "sw/device/lib/testing/test_framework/FreeRTOSConfig.h"
2530
#include "sw/device/lib/testing/test_framework/check.h"
2631
#include "sw/device/lib/testing/test_framework/ottf_main.h"
2732

28-
#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h"
29-
3033
OTTF_DEFINE_TEST_CONFIG();
3134

3235
/**
@@ -56,7 +59,13 @@ static_assert(
5659
/**
5760
* Objects to access the peripherals used in this test via dif API.
5861
*/
59-
static const uint32_t kPlicTarget = kTopEarlgreyPlicTargetIbex0;
62+
enum {
63+
/**
64+
* PLIC target for the Ibex core.
65+
*/
66+
kDtRvPlicTargetIbex0 = 0,
67+
};
68+
6069
static dif_aon_timer_t aon_timer;
6170
static dif_rv_plic_t plic;
6271
static dif_pwrmgr_t pwrmgr;
@@ -70,33 +79,32 @@ static dif_alert_handler_t alert_handler;
7079
* line to the CPU, which results in a call to this OTTF ISR. This ISR
7180
* overrides the default OTTF implementation.
7281
*/
73-
void ottf_external_isr(uint32_t *exc_info) {
74-
dif_rv_plic_irq_id_t irq_id;
75-
CHECK_DIF_OK(dif_rv_plic_irq_claim(&plic, kPlicTarget, &irq_id));
76-
77-
top_earlgrey_plic_peripheral_t peripheral = (top_earlgrey_plic_peripheral_t)
78-
top_earlgrey_plic_interrupt_for_peripheral[irq_id];
79-
80-
if (peripheral == kTopEarlgreyPlicPeripheralAonTimerAon) {
81-
uint32_t irq =
82-
(irq_id - (dif_rv_plic_irq_id_t)
83-
kTopEarlgreyPlicIrqIdAonTimerAonWkupTimerExpired);
84-
82+
bool ottf_handle_irq(uint32_t *exc_info, dt_instance_id_t inst_id,
83+
dif_rv_plic_irq_id_t plic_irq_id) {
84+
// Check if this is the AON timer peripheral
85+
if (inst_id == dt_aon_timer_instance_id(kDtAonTimerAon)) {
8586
// We should not get aon timer interrupts since escalation suppresses them.
87+
dt_aon_timer_irq_t irq =
88+
dt_aon_timer_irq_from_plic_id(kDtAonTimerAon, plic_irq_id);
8689
LOG_ERROR("Unexpected aon timer interrupt %d", irq);
87-
} else if (peripheral == kTopEarlgreyPlicPeripheralAlertHandler) {
90+
return true;
91+
}
92+
93+
// Check if this is the alert handler peripheral
94+
if (inst_id == dt_alert_handler_instance_id(kDtAlertHandler)) {
95+
// Convert PLIC IRQ ID to alert handler IRQ
96+
dt_alert_handler_irq_t irq =
97+
dt_alert_handler_irq_from_plic_id(kDtAlertHandler, plic_irq_id);
98+
8899
// Check the class.
89100
dif_alert_handler_class_state_t state;
90101
CHECK_DIF_OK(dif_alert_handler_get_class_state(
91102
&alert_handler, kDifAlertHandlerClassA, &state));
92103
CHECK(state == kDifAlertHandlerClassStatePhase0, "Wrong phase %d", state);
93104

94-
uint32_t irq =
95-
(irq_id -
96-
(dif_rv_plic_irq_id_t)kTopEarlgreyPlicIrqIdAlertHandlerClassa);
97-
98105
// Deals with the alert cause: we expect it to be from the pwrmgr.
99-
dif_alert_handler_alert_t alert = kTopEarlgreyAlertIdPwrmgrAonFatalFault;
106+
dif_alert_handler_alert_t alert =
107+
dt_pwrmgr_alert_to_alert_id(kDtPwrmgrAon, kDtPwrmgrAlertFatalFault);
100108
bool is_cause = false;
101109
CHECK_DIF_OK(
102110
dif_alert_handler_alert_is_cause(&alert_handler, alert, &is_cause));
@@ -109,36 +117,38 @@ void ottf_external_isr(uint32_t *exc_info) {
109117
CHECK(!is_cause);
110118

111119
CHECK_DIF_OK(dif_alert_handler_irq_acknowledge(&alert_handler, irq));
120+
return true;
112121
}
113122

114-
// Complete the IRQ by writing the IRQ source to the Ibex specific CC
115-
// register.
116-
CHECK_DIF_OK(dif_rv_plic_irq_complete(&plic, kPlicTarget, irq_id));
123+
return false;
117124
}
118125

119126
/**
120127
* Initialize the peripherals used in this test.
121128
*/
122129
void init_peripherals(void) {
123-
mmio_region_t base_addr =
124-
mmio_region_from_addr(TOP_EARLGREY_PWRMGR_AON_BASE_ADDR);
125-
CHECK_DIF_OK(dif_pwrmgr_init(base_addr, &pwrmgr));
126-
127-
base_addr = mmio_region_from_addr(TOP_EARLGREY_RSTMGR_AON_BASE_ADDR);
128-
CHECK_DIF_OK(dif_rstmgr_init(base_addr, &rstmgr));
129-
130-
base_addr = mmio_region_from_addr(TOP_EARLGREY_AON_TIMER_AON_BASE_ADDR);
131-
CHECK_DIF_OK(dif_aon_timer_init(base_addr, &aon_timer));
132-
133-
base_addr = mmio_region_from_addr(TOP_EARLGREY_RV_PLIC_BASE_ADDR);
134-
CHECK_DIF_OK(dif_rv_plic_init(base_addr, &plic));
135-
136-
rv_plic_testutils_irq_range_enable(
137-
&plic, kPlicTarget, kTopEarlgreyPlicIrqIdAonTimerAonWkupTimerExpired,
138-
kTopEarlgreyPlicIrqIdAonTimerAonWdogTimerBark);
130+
CHECK_DIF_OK(dif_pwrmgr_init_from_dt(kDtPwrmgrAon, &pwrmgr));
131+
CHECK_DIF_OK(dif_rstmgr_init_from_dt(kDtRstmgrAon, &rstmgr));
132+
CHECK_DIF_OK(dif_aon_timer_init_from_dt(kDtAonTimerAon, &aon_timer));
133+
CHECK_DIF_OK(dif_rv_plic_init_from_dt(kDtRvPlic, &plic));
134+
CHECK_DIF_OK(dif_alert_handler_init_from_dt(kDtAlertHandler, &alert_handler));
135+
136+
// Enable AON timer interrupts in PLIC
137+
dt_plic_irq_id_t wkup_irq = dt_aon_timer_irq_to_plic_id(
138+
kDtAonTimerAon, kDtAonTimerIrqWkupTimerExpired);
139+
dt_plic_irq_id_t bark_irq =
140+
dt_aon_timer_irq_to_plic_id(kDtAonTimerAon, kDtAonTimerIrqWdogTimerBark);
141+
142+
dt_plic_irq_id_t aon_irq_ids[] = {wkup_irq, bark_irq};
143+
for (size_t i = 0; i < ARRAYSIZE(aon_irq_ids); ++i) {
144+
CHECK_DIF_OK(dif_rv_plic_irq_set_priority(&plic, aon_irq_ids[i],
145+
/*priority=*/1u));
146+
CHECK_DIF_OK(dif_rv_plic_irq_set_enabled(
147+
&plic, aon_irq_ids[i], kDtRvPlicTargetIbex0, kDifToggleEnabled));
148+
}
139149

140-
base_addr = mmio_region_from_addr(TOP_EARLGREY_ALERT_HANDLER_BASE_ADDR);
141-
CHECK_DIF_OK(dif_alert_handler_init(base_addr, &alert_handler));
150+
CHECK_DIF_OK(dif_rv_plic_target_set_threshold(&plic, kDtRvPlicTargetIbex0,
151+
/*threshold=*/0u));
142152
}
143153

144154
static uint32_t udiv64_slow_into_u32(uint64_t a, uint64_t b,
@@ -154,7 +164,8 @@ static uint32_t udiv64_slow_into_u32(uint64_t a, uint64_t b,
154164
* wdog is programed to bark.
155165
*/
156166
static void alert_handler_config(void) {
157-
dif_alert_handler_alert_t alerts[] = {kTopEarlgreyAlertIdPwrmgrAonFatalFault};
167+
dif_alert_handler_alert_t alerts[] = {
168+
dt_pwrmgr_alert_to_alert_id(kDtPwrmgrAon, kDtPwrmgrAlertFatalFault)};
158169
dif_alert_handler_class_t alert_classes[] = {kDifAlertHandlerClassA};
159170

160171
dif_alert_handler_escalation_phase_t esc_phases[] = {
@@ -236,10 +247,24 @@ bool test_main(void) {
236247

237248
init_peripherals();
238249

239-
// Enable all the AON interrupts used in this test.
240-
rv_plic_testutils_irq_range_enable(&plic, kPlicTarget,
241-
kTopEarlgreyPlicIrqIdAlertHandlerClassa,
242-
kTopEarlgreyPlicIrqIdAlertHandlerClassd);
250+
// Enable all the alert handler interrupts used in this test.
251+
dt_plic_irq_id_t classa_irq = dt_alert_handler_irq_to_plic_id(
252+
kDtAlertHandler, kDtAlertHandlerIrqClassa);
253+
dt_plic_irq_id_t classb_irq = dt_alert_handler_irq_to_plic_id(
254+
kDtAlertHandler, kDtAlertHandlerIrqClassb);
255+
dt_plic_irq_id_t classc_irq = dt_alert_handler_irq_to_plic_id(
256+
kDtAlertHandler, kDtAlertHandlerIrqClassc);
257+
dt_plic_irq_id_t classd_irq = dt_alert_handler_irq_to_plic_id(
258+
kDtAlertHandler, kDtAlertHandlerIrqClassd);
259+
260+
dt_plic_irq_id_t alert_irq_ids[] = {classa_irq, classb_irq, classc_irq,
261+
classd_irq};
262+
for (size_t i = 0; i < ARRAYSIZE(alert_irq_ids); ++i) {
263+
CHECK_DIF_OK(dif_rv_plic_irq_set_priority(&plic, alert_irq_ids[i],
264+
/*priority=*/1u));
265+
CHECK_DIF_OK(dif_rv_plic_irq_set_enabled(
266+
&plic, alert_irq_ids[i], kDtRvPlicTargetIbex0, kDifToggleEnabled));
267+
}
243268

244269
alert_handler_config();
245270

0 commit comments

Comments
 (0)