|
4 | 4 |
|
5 | 5 | #include <string.h> |
6 | 6 |
|
| 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" |
7 | 15 | #include "sw/device/lib/base/memory.h" |
8 | 16 | #include "sw/device/lib/base/mmio.h" |
9 | 17 | #include "sw/device/lib/dif/dif_aes.h" |
|
25 | 33 | #include "sw/device/lib/testing/test_framework/ottf_main.h" |
26 | 34 | #include "sw/device/tests/otbn_randomness_impl.h" |
27 | 35 |
|
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. |
30 | 37 |
|
31 | 38 | OTTF_DEFINE_TEST_CONFIG(); |
32 | 39 |
|
@@ -91,6 +98,10 @@ enum { |
91 | 98 | * than other environments, and so is given a longer timeout. |
92 | 99 | */ |
93 | 100 | kVerilatorAesTestutilsTimeoutUsec = 48 * 1000 * 1000, |
| 101 | + /** |
| 102 | + * PLIC target for the Ibex core. |
| 103 | + */ |
| 104 | + kDtRvPlicTargetIbex0 = 0, |
94 | 105 | }; |
95 | 106 |
|
96 | 107 | static dif_aes_t aes; |
@@ -147,12 +158,14 @@ bool entropy_src_fifo_has_overflowed(void) { |
147 | 158 |
|
148 | 159 | void ottf_external_isr(uint32_t *exc_info) { |
149 | 160 | 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)); |
152 | 163 |
|
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); |
156 | 169 |
|
157 | 170 | // If the observe buffer overflows while we're still collecting samples |
158 | 171 | // 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) { |
220 | 233 | &entropy_src, kDifToggleDisabled)); |
221 | 234 | } |
222 | 235 |
|
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)); |
225 | 241 |
|
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)); |
228 | 244 | } |
229 | 245 |
|
230 | 246 | 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)); |
233 | 252 |
|
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)); |
236 | 254 |
|
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)); |
240 | 257 |
|
241 | 258 | TRY(dif_entropy_src_irq_set_enabled( |
242 | | - &entropy_src, kDifEntropySrcIrqEsObserveFifoReady, kDifToggleEnabled)); |
| 259 | + &entropy_src, kDtEntropySrcIrqEsObserveFifoReady, kDifToggleEnabled)); |
243 | 260 |
|
244 | 261 | return OK_STATUS(); |
245 | 262 | } |
@@ -466,26 +483,15 @@ status_t firmware_override_extract_insert( |
466 | 483 | } |
467 | 484 |
|
468 | 485 | 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)); |
489 | 495 |
|
490 | 496 | LOG_INFO("Configuring interrupts..."); |
491 | 497 | configure_interrupts(); |
|
0 commit comments