5 #include "dt/dt_otbn.h"      
    6 #include "dt/dt_rv_plic.h"   
   11 #include "sw/device/lib/runtime/irq.h" 
   13 #include "sw/device/lib/testing/clkmgr_testutils.h" 
   14 #include "sw/device/lib/testing/entropy_testutils.h" 
   16 #include "sw/device/lib/testing/rv_plic_testutils.h" 
   17 #include "sw/device/lib/testing/test_framework/check.h" 
   19 #include "sw/device/tests/otbn_randomness_impl.h" 
   21 OTTF_DEFINE_TEST_CONFIG();
 
   23 static const uint32_t kPlicTarget = 0;
 
   25 static dif_clkmgr_t clkmgr;
 
   27 #if defined(OPENTITAN_IS_EARLGREY) 
   29 #elif defined(OPENTITAN_IS_DARJEELING) 
   30     kTopDarjeelingHintableClocksMainOtbn
 
   32 #error Unsupported top 
   36 static dif_rv_plic_t plic;
 
   37 static dif_otbn_t otbn;
 
   41 static volatile dt_instance_id_t plic_peripheral;
 
   42 static volatile dt_otbn_irq_t irq;
 
   56 void ottf_external_isr(uint32_t *exc_info) {
 
   61   plic_peripheral = dt_plic_id_to_instance_id(irq_id);
 
   62   if (plic_peripheral == dt_otbn_instance_id(kDtOtbn)) {
 
   63     irq = dt_otbn_irq_from_plic_id(kDtOtbn, irq_id);
 
   68   irq_global_ctrl(
false);
 
   69   irq_external_ctrl(
false);
 
   75 static void otbn_wait_for_done_irq(dif_otbn_t *otbn) {
 
   79   plic_peripheral = kDtInstanceIdUnknown;
 
   85   ATOMIC_WAIT_FOR_INTERRUPT(plic_peripheral != kDtInstanceIdUnknown);
 
   86   CHECK(plic_peripheral == dt_otbn_instance_id(kDtOtbn),
 
   87         "Interrupt from incorrect peripheral: (exp: %d, obs: %s)",
 
   88         dt_otbn_instance_id(kDtOtbn), plic_peripheral);
 
   91   CHECK(irq == kDtOtbnIrqDone);
 
   94 static void otbn_init_irq(
void) {
 
   95   CHECK_DIF_OK(dif_rv_plic_init_from_dt(kDtRvPlic, &plic));
 
  106   irq_global_ctrl(
true);
 
  107   irq_external_ctrl(
true);
 
  111   CHECK_DIF_OK(dif_clkmgr_init_from_dt(kDtClkmgrAon, &clkmgr));
 
  118   return CLKMGR_TESTUTILS_CHECK_CLOCK_HINT(clkmgr, kOtbnClock,
 
  126   CLKMGR_TESTUTILS_SET_AND_CHECK_CLOCK_HINT(
 
  131   CLKMGR_TESTUTILS_SET_AND_CHECK_CLOCK_HINT(
 
  137   otbn_randomness_test_start(&otbn, 0);
 
  139   CLKMGR_TESTUTILS_SET_AND_CHECK_CLOCK_HINT(
 
  144   otbn_wait_for_done_irq(&otbn);
 
  149   CLKMGR_TESTUTILS_SET_AND_CHECK_CLOCK_HINT(
 
  152   otbn_randomness_test_log_results(&otbn);
 
  155   TRY_CHECK(otbn_randomness_test_end(&otbn, 
true));
 
  161   CHECK_STATUS_OK(entropy_testutils_auto_mode_init());
 
  162   CHECK_STATUS_OK(initialize_clkmgr());
 
  164   CHECK_DIF_OK(dif_otbn_init_from_dt(kDtOtbn, &otbn));
 
  167   return status_ok(execute_test());