5 #include "sw/device/tests/clkmgr_off_trans_impl.h"
17 #include "sw/device/lib/dif/dif_rv_core_ibex.h"
19 #include "sw/device/lib/testing/aon_timer_testutils.h"
20 #include "sw/device/lib/testing/rstmgr_testutils.h"
21 #include "sw/device/lib/testing/test_framework/check.h"
25 #include "hmac_regs.h"
27 #include "kmac_regs.h"
28 #include "otbn_regs.h"
35 OTTF_DEFINE_TEST_CONFIG();
37 static dif_aon_timer_t aon_timer;
40 static dif_hmac_t hmac;
41 static dif_kmac_t kmac;
42 static dif_otbn_t otbn;
66 enum { kPcSpread = 8 * 4 };
68 inline uint32_t addr_as_offset(
mmio_region_t base, uint32_t offset) {
69 return (uint32_t)base.base + offset;
76 CHECK_DIF_OK(dif_aes_alert_force(&aes, kDifAesAlertRecovCtrlUpdateErr));
80 dif_hmac_irq_state_snapshot_t snapshot;
81 CHECK_DIF_OK(dif_hmac_irq_get_state(&hmac, &snapshot));
109 LOG_ERROR(
"Invalid hintable clock (%d)", trans);
119 static void test_hintable_clocks_off(
const dif_clkmgr_t *clkmgr,
133 other <= kTopEarlgreyHintableClocksLast; ++other) {
134 if (other != clock) {
135 trans_csr_access(other);
141 uint32_t bite_us = 20;
142 uint32_t bite_cycles = 0;
144 aon_timer_testutils_get_aon_cycles_32_from_us(bite_us, &bite_cycles));
145 LOG_INFO(
"Setting bite reset for %u us (%u cycles)", bite_us, bite_cycles);
146 CHECK_STATUS_OK(aon_timer_testutils_watchdog_config(&aon_timer, UINT32_MAX,
147 bite_cycles,
false));
149 trans_csr_access(clock);
150 LOG_ERROR(
"Access to disabled unit should freeze and cause a reset");
158 CHECK_DIF_OK(dif_rstmgr_init(
161 CHECK_DIF_OK(dif_clkmgr_init(
164 CHECK_DIF_OK(dif_pwrmgr_init(
168 CHECK_DIF_OK(dif_aon_timer_init(
189 {
"aes", addr_as_offset(aes.base_addr, AES_ALERT_TEST_REG_OFFSET),
190 (uint32_t)&aes_csr_access},
191 {
"hmac", addr_as_offset(hmac.base_addr, HMAC_INTR_STATE_REG_OFFSET),
192 (uint32_t)&hmac_csr_access},
193 {
"kmac", addr_as_offset(kmac.base_addr, KMAC_STATUS_REG_OFFSET),
194 (uint32_t)&kmac_csr_access},
195 {
"otbn", addr_as_offset(otbn.base_addr, OTBN_ERR_BITS_REG_OFFSET),
196 (uint32_t)&otbn_csr_access}};
204 kDifPwrmgrResetRequestSourceTwo,
206 CHECK_STATUS_OK(rstmgr_testutils_pre_reset(&rstmgr));
208 test_hintable_clocks_off(&clkmgr, clock);
211 LOG_ERROR(
"This is unreachable since a reset should have been triggered");
213 }
else if (UNWRAP(rstmgr_testutils_is_reset_info(
214 &rstmgr, kDifRstmgrResetInfoWatchdog))) {
216 LOG_INFO(
"Got an expected watchdog reset when reading for clock %d", clock);
231 CHECK(crash_dump.fault_state.mcpc >=
233 crash_dump.fault_state.mcpc <=
239 reset_info = rstmgr_testutils_reason_get();
240 LOG_ERROR(
"Unexpected reset_info 0x%x", reset_info);