Software APIs
rv_core_ibex_testutils.h
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
5 #ifndef OPENTITAN_SW_DEVICE_LIB_TESTING_RV_CORE_IBEX_TESTUTILS_H_
6 #define OPENTITAN_SW_DEVICE_LIB_TESTING_RV_CORE_IBEX_TESTUTILS_H_
7 
8 #include <stdbool.h>
9 #include <stdint.h>
10 
11 #include "sw/device/lib/base/status.h"
12 #include "sw/device/lib/dif/dif_rv_core_ibex.h"
13 
14 /**
15  * Returns the validity of random data read from the entropy source as bool.
16  *
17  * Returns true if the random data read from the entropy source is valid, else
18  * false. Whether the random data is FIPS compliant or not is not indicated.
19  * @param rv_core_ibex An rv_core_ibex handle.
20  * @return The validity of random data read from the entropy source.
21  */
22 bool rv_core_ibex_testutils_is_rnd_data_valid(
23  const dif_rv_core_ibex_t *rv_core_ibex);
24 
25 /**
26  * Returns a random data read from the entropy source.
27  *
28  * A spinwait loop is invoked to wait for the random data fetched from the
29  * entropy source to be valid. The spinwait times out after the timeout_usec
30  * microseconds. Once valid, the random data is read and checked before it is
31  * returned.
32  * @param rv_core_ibex An rv_core_ibex handle.
33  * @param timeout_usec Timeout in microseconds.
34  * @param[out] rnd The random data read from the entropy source.
35  * @return The result of the operation
36  */
38 status_t rv_core_ibex_testutils_get_rnd_data(
39  const dif_rv_core_ibex_t *rv_core_ibex, uint32_t timeout_usec,
40  uint32_t *rnd);
41 
42 #define RV_CORE_IBEX_TESTUTILS_PRINT_CRASH_DUMP(dump) \
43  LOG_INFO( \
44  "\n%s = {" \
45  "\n\tmtval=%08x" \
46  "\n\tmpec=%08x," \
47  "\n\tmdaa=%08x," \
48  "\n\tmnpc=%08x," \
49  "\n\tmcpc=%08x," \
50  "\n}\n", \
51  #dump, dump.mtval, dump.mpec, dump.mdaa, dump.mnpc, dump.mcpc)
52 
53 #define RV_CORE_IBEX_TESTUTILS_PRINT_CRASH_PREVIOUS_DUMP(dump) \
54  LOG_INFO( \
55  "\n%s = {" \
56  "\n\tmtval=%08x" \
57  "\n\tmpec=%08x," \
58  "\n}\n", \
59  #dump, dump.mtval, dump.mpec)
60 
61 #endif // OPENTITAN_SW_DEVICE_LIB_TESTING_RV_CORE_IBEX_TESTUTILS_H_