Skip to content

Commit 61ee5a6

Browse files
committed
[sw,test] Port entropy_src_fw_override test to DT
Signed-off-by: Robert Schilling <[email protected]>
1 parent 128896c commit 61ee5a6

File tree

2 files changed

+47
-40
lines changed

2 files changed

+47
-40
lines changed

sw/device/tests/BUILD

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7427,14 +7427,15 @@ opentitan_test(
74277427
{
74287428
"//hw/top_earlgrey:silicon_creator": None,
74297429
},
7430+
DARJEELING_TEST_ENVS,
74307431
),
74317432
# This takes around 2 hours to run on Verilator, and so should only be
74327433
# run manually for debugging purposes.
74337434
verilator = verilator_params(tags = ["manual"]),
74347435
deps = [
74357436
":otbn_randomness_impl",
7437+
"//hw/top:dt",
74367438
"//hw/top:entropy_src_c_regs",
7437-
"//hw/top_earlgrey/sw/autogen:top_earlgrey",
74387439
"//sw/device/lib/base:memory",
74397440
"//sw/device/lib/base:mmio",
74407441
"//sw/device/lib/dif:aes",

sw/device/tests/entropy_src_fw_override_test.c

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44

55
#include <string.h>
66

7+
#include "hw/top/dt/dt_aes.h"
8+
#include "hw/top/dt/dt_csrng.h"
9+
#include "hw/top/dt/dt_edn.h"
10+
#include "hw/top/dt/dt_entropy_src.h"
11+
#include "hw/top/dt/dt_kmac.h"
12+
#include "hw/top/dt/dt_otbn.h"
13+
#include "hw/top/dt/dt_rv_core_ibex.h"
14+
#include "hw/top/dt/dt_rv_plic.h"
715
#include "sw/device/lib/base/memory.h"
816
#include "sw/device/lib/base/mmio.h"
917
#include "sw/device/lib/dif/dif_aes.h"
@@ -25,8 +33,7 @@
2533
#include "sw/device/lib/testing/test_framework/ottf_main.h"
2634
#include "sw/device/tests/otbn_randomness_impl.h"
2735

28-
#include "hw/top/entropy_src_regs.h" // Generated.
29-
#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h" // Generated.
36+
#include "hw/top/entropy_src_regs.h" // Generated.
3037

3138
OTTF_DEFINE_TEST_CONFIG();
3239

@@ -91,6 +98,10 @@ enum {
9198
* than other environments, and so is given a longer timeout.
9299
*/
93100
kVerilatorAesTestutilsTimeoutUsec = 48 * 1000 * 1000,
101+
/**
102+
* PLIC target for the Ibex core.
103+
*/
104+
kDtRvPlicTargetIbex0 = 0,
94105
};
95106

96107
static dif_aes_t aes;
@@ -147,12 +158,14 @@ bool entropy_src_fifo_has_overflowed(void) {
147158

148159
void ottf_external_isr(uint32_t *exc_info) {
149160
dif_rv_plic_irq_id_t plic_irq_id;
150-
CHECK_DIF_OK(dif_rv_plic_irq_claim(&rv_plic, kTopEarlgreyPlicTargetIbex0,
151-
&plic_irq_id));
161+
CHECK_DIF_OK(
162+
dif_rv_plic_irq_claim(&rv_plic, kDtRvPlicTargetIbex0, &plic_irq_id));
152163

153-
top_earlgrey_plic_peripheral_t peripheral =
154-
top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
155-
CHECK(peripheral == kTopEarlgreyPlicPeripheralEntropySrc);
164+
// Get the instance ID for the peripheral that generated the interrupt
165+
dt_instance_id_t inst_id = dt_plic_id_to_instance_id(plic_irq_id);
166+
CHECK(inst_id == dt_entropy_src_instance_id(kDtEntropySrc),
167+
"Interrupt from incorrect peripheral: (exp: %d, obs: %d)",
168+
dt_entropy_src_instance_id(kDtEntropySrc), inst_id);
156169

157170
// If the observe buffer overflows while we're still collecting samples
158171
// then we need to drain it and start again or our samples won't be
@@ -220,26 +233,30 @@ void ottf_external_isr(uint32_t *exc_info) {
220233
&entropy_src, kDifToggleDisabled));
221234
}
222235

223-
CHECK_DIF_OK(dif_entropy_src_irq_acknowledge(
224-
&entropy_src, kDifEntropySrcIrqEsObserveFifoReady));
236+
// Get the specific IRQ type from the PLIC IRQ ID
237+
dt_entropy_src_irq_t irq =
238+
dt_entropy_src_irq_from_plic_id(kDtEntropySrc, plic_irq_id);
239+
CHECK(irq == kDtEntropySrcIrqEsObserveFifoReady, "Unexpected irq: 0x%x", irq);
240+
CHECK_DIF_OK(dif_entropy_src_irq_acknowledge(&entropy_src, irq));
225241

226-
CHECK_DIF_OK(dif_rv_plic_irq_complete(&rv_plic, kTopEarlgreyPlicTargetIbex0,
227-
plic_irq_id));
242+
CHECK_DIF_OK(
243+
dif_rv_plic_irq_complete(&rv_plic, kDtRvPlicTargetIbex0, plic_irq_id));
228244
}
229245

230246
static status_t configure_interrupts(void) {
231-
TRY(dif_rv_plic_irq_set_priority(
232-
&rv_plic, kTopEarlgreyPlicIrqIdEntropySrcEsObserveFifoReady, 0x1));
247+
// Get PLIC IRQ ID using DT API
248+
dt_plic_irq_id_t entropy_src_irq_id = dt_entropy_src_irq_to_plic_id(
249+
kDtEntropySrc, kDtEntropySrcIrqEsObserveFifoReady);
250+
251+
TRY(dif_rv_plic_irq_set_priority(&rv_plic, entropy_src_irq_id, 0x1));
233252

234-
TRY(dif_rv_plic_target_set_threshold(&rv_plic, kTopEarlgreyPlicTargetIbex0,
235-
0x0));
253+
TRY(dif_rv_plic_target_set_threshold(&rv_plic, kDtRvPlicTargetIbex0, 0x0));
236254

237-
TRY(dif_rv_plic_irq_set_enabled(
238-
&rv_plic, kTopEarlgreyPlicIrqIdEntropySrcEsObserveFifoReady,
239-
kTopEarlgreyPlicTargetIbex0, kDifToggleEnabled));
255+
TRY(dif_rv_plic_irq_set_enabled(&rv_plic, entropy_src_irq_id,
256+
kDtRvPlicTargetIbex0, kDifToggleEnabled));
240257

241258
TRY(dif_entropy_src_irq_set_enabled(
242-
&entropy_src, kDifEntropySrcIrqEsObserveFifoReady, kDifToggleEnabled));
259+
&entropy_src, kDtEntropySrcIrqEsObserveFifoReady, kDifToggleEnabled));
243260

244261
return OK_STATUS();
245262
}
@@ -466,26 +483,15 @@ status_t firmware_override_extract_insert(
466483
}
467484

468485
bool test_main(void) {
469-
mmio_region_t base_addr;
470-
471-
base_addr = mmio_region_from_addr(TOP_EARLGREY_AES_BASE_ADDR);
472-
CHECK_DIF_OK(dif_aes_init(base_addr, &aes));
473-
base_addr = mmio_region_from_addr(TOP_EARLGREY_CSRNG_BASE_ADDR);
474-
CHECK_DIF_OK(dif_csrng_init(base_addr, &csrng));
475-
base_addr = mmio_region_from_addr(TOP_EARLGREY_EDN0_BASE_ADDR);
476-
CHECK_DIF_OK(dif_edn_init(base_addr, &edn0));
477-
base_addr = mmio_region_from_addr(TOP_EARLGREY_EDN1_BASE_ADDR);
478-
CHECK_DIF_OK(dif_edn_init(base_addr, &edn1));
479-
base_addr = mmio_region_from_addr(TOP_EARLGREY_ENTROPY_SRC_BASE_ADDR);
480-
CHECK_DIF_OK(dif_entropy_src_init(base_addr, &entropy_src));
481-
base_addr = mmio_region_from_addr(TOP_EARLGREY_KMAC_BASE_ADDR);
482-
CHECK_DIF_OK(dif_kmac_init(base_addr, &kmac));
483-
base_addr = mmio_region_from_addr(TOP_EARLGREY_OTBN_BASE_ADDR);
484-
CHECK_DIF_OK(dif_otbn_init(base_addr, &otbn));
485-
base_addr = mmio_region_from_addr(TOP_EARLGREY_RV_CORE_IBEX_CFG_BASE_ADDR);
486-
CHECK_DIF_OK(dif_rv_core_ibex_init(base_addr, &rv_core_ibex));
487-
base_addr = mmio_region_from_addr(TOP_EARLGREY_RV_PLIC_BASE_ADDR);
488-
CHECK_DIF_OK(dif_rv_plic_init(base_addr, &rv_plic));
486+
CHECK_DIF_OK(dif_aes_init_from_dt(kDtAes, &aes));
487+
CHECK_DIF_OK(dif_csrng_init_from_dt(kDtCsrng, &csrng));
488+
CHECK_DIF_OK(dif_edn_init_from_dt(kDtEdn0, &edn0));
489+
CHECK_DIF_OK(dif_edn_init_from_dt(kDtEdn1, &edn1));
490+
CHECK_DIF_OK(dif_entropy_src_init_from_dt(kDtEntropySrc, &entropy_src));
491+
CHECK_DIF_OK(dif_kmac_init_from_dt(kDtKmac, &kmac));
492+
CHECK_DIF_OK(dif_otbn_init_from_dt(kDtOtbn, &otbn));
493+
CHECK_DIF_OK(dif_rv_core_ibex_init_from_dt(kDtRvCoreIbex, &rv_core_ibex));
494+
CHECK_DIF_OK(dif_rv_plic_init_from_dt(kDtRvPlic, &rv_plic));
489495

490496
LOG_INFO("Configuring interrupts...");
491497
configure_interrupts();

0 commit comments

Comments
 (0)