Software APIs
rstmgr_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_RSTMGR_TESTUTILS_H_
6 #define OPENTITAN_SW_DEVICE_LIB_TESTING_RSTMGR_TESTUTILS_H_
7 
8 #include <stdint.h>
9 
10 #include "sw/device/lib/base/status.h"
12 
13 /**
14  * Determines if the reset_info matches info.
15  *
16  * @param rstmgr A reset manager handle.
17  * @param info A bit mask of reset reasons.
18  * @return `kOk(res)` Where `res` is true if the reset_info CSR matches info or
19  * `kInternal` in case of error.
20  */
22 status_t rstmgr_testutils_is_reset_info(const dif_rstmgr_t *rstmgr,
24 
25 /**
26  * Determines if the reset info contains any of the reasons in `info`.
27  *
28  * @param rstmgr A reset manager handle.
29  * @param info A bit mask of reset reasons.
30  * @return `kOk(res)` Where `res` is true if the reset info contains any of the
31  * reasons in `info` or `kInternal` in case of error.
32  */
34 status_t rstmgr_testutils_reset_info_any(const dif_rstmgr_t *rstmgr,
36 
37 /**
38  * Compares the given alert dump against the device's.
39  *
40  * If the dump array is null or its size is zero this check succeeds. It is
41  * possible to compare less words than the device captures, but it is an error
42  * to try to compare more.
43  *
44  * @param rstmgr A reset manager handle.
45  * @param expected_alert_dump An array holding the expected alert dump.
46  * @param dump_size The size of the expected_alert_dump array.
47  * @return The result of the operation.
48  */
50 status_t rstmgr_testutils_compare_alert_info(
51  const dif_rstmgr_t *rstmgr,
52  dif_rstmgr_alert_info_dump_segment_t *expected_alert_dump,
53  size_t dump_size);
54 
55 /**
56  * Compares the given cpu dump against the device's.
57  *
58  * If the dump array is null or its size is zero this check succeeds. It is
59  * possible to compare less words than the device captures, but it is an error
60  * to try to compare more.
61  *
62  * @param rstmgr A reset manager handle.
63  * @param expected_cpu_dump An array holding the expected cpu dump.
64  * @param dump_size The size of the expected_cpu_dump array.
65  * @return The result of the operation.
66  */
68 status_t rstmgr_testutils_compare_cpu_info(
69  const dif_rstmgr_t *rstmgr,
70  dif_rstmgr_cpu_info_dump_segment_t *expected_cpu_dump, size_t dump_size);
71 
72 /**
73  * Prepares the rstmgr for a reset scenario.
74  *
75  * @param rstmgr A reset manager handle.
76  * @return The result of the operation.
77  */
79 status_t rstmgr_testutils_pre_reset(const dif_rstmgr_t *rstmgr);
80 
81 /**
82  * Checks state after a reset.
83  *
84  * This will cause a failure if any of the checks fail. If either of the dump
85  * arrays is null or its size is zero the corresponding comparison will be
86  * skipped.
87  *
88  * @param rstmgr A reset manager handle.
89  * @param expected_reset_info The expected contents of the reset_info CSR.
90  * @param expected_alert_dump An array with the expected contents of the
91  * alert_info CSR.
92  * @param alert_dump_size The size of the expected_alert_dump array.
93  * @param expected_cpu_dump An array with the expected contents of the cpu_info
94  * CSR.
95  * @param cpu_dump_size The size of the expected_cpu_dump array.
96  * @return The result of the operation.
97  */
99 status_t rstmgr_testutils_post_reset(
100  const dif_rstmgr_t *rstmgr,
101  dif_rstmgr_reset_info_bitfield_t expected_reset_info,
102  dif_rstmgr_alert_info_dump_segment_t *expected_alert_dump,
103  size_t alert_dump_size,
104  dif_rstmgr_cpu_info_dump_segment_t *expected_cpu_dump,
105  size_t cpu_dump_size);
106 
107 /**
108  * Gets the reason for a reset in retention SRAM.
109  *
110  * @returns reset reason
111  */
112 dif_rstmgr_reset_info_bitfield_t rstmgr_testutils_reason_get(void);
113 
114 /**
115  * Clears the reset information in Retention SRAM
116  */
117 void rstmgr_testutils_reason_clear(void);
118 
119 #endif // OPENTITAN_SW_DEVICE_LIB_TESTING_RSTMGR_TESTUTILS_H_