blob: 08a446644552290e2bbf1431d61dd2267e5e2f6d [file] [log] [blame]
Guillermo Maturana037bfc22021-10-05 10:13:58 -07001// Copyright lowRISC contributors.
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/dif/dif_rstmgr.h"
11
12/**
13 * Determines if the reset_info matches info.
14 *
15 * @param rstmgr A reset manager handle.
16 * @param info A bit mask of reset reasons.
Guillermo Maturana475a6e12021-10-27 12:31:39 -070017 *
18 * @return True if the reset_info CSR matches info.
Guillermo Maturana037bfc22021-10-05 10:13:58 -070019 */
Guillermo Maturana475a6e12021-10-27 12:31:39 -070020bool rstmgr_testutils_is_reset_info(const dif_rstmgr_t *rstmgr,
Guillermo Maturana037bfc22021-10-05 10:13:58 -070021 dif_rstmgr_reset_info_bitfield_t info);
22
Guillermo Maturana475a6e12021-10-27 12:31:39 -070023/**
Silvestrs Timofejevsd53bbba2021-11-30 17:13:04 +000024 * Determines if the reset info contains any of the reasons in `info`.
25 *
26 * @param rstmgr A reset manager handle.
27 * @param info A bit mask of reset reasons.
28 *
29 * @return True if the reset info contains any of the reasons in `info`.
30 */
31bool rstmgr_testutils_reset_info_any(const dif_rstmgr_t *rstmgr,
32 dif_rstmgr_reset_info_bitfield_t info);
33
34/**
Guillermo Maturana475a6e12021-10-27 12:31:39 -070035 * Compares the given alert dump against the device's.
36 *
37 * If the dump array is null or its size is zero this check succeeds. It is
38 * possible to compare less words than the device captures, but it is an error
39 * to try to compare more.
40 *
41 * @param rstmgr A reset manager handle.
42 * @param expected_alert_dump An array holding the expected alert dump.
43 * @param dump_size The size of the expected_alert_dump array.
Guillermo Maturana475a6e12021-10-27 12:31:39 -070044 */
Timothy Trippel1b73f802021-11-01 23:16:50 +000045void rstmgr_testutils_compare_alert_info(
Guillermo Maturana475a6e12021-10-27 12:31:39 -070046 const dif_rstmgr_t *rstmgr,
47 dif_rstmgr_alert_info_dump_segment_t *expected_alert_dump,
48 size_t dump_size);
49
50/**
51 * Compares the given cpu dump against the device's.
52 *
53 * If the dump array is null or its size is zero this check succeeds. It is
54 * possible to compare less words than the device captures, but it is an error
55 * to try to compare more.
56 *
57 * @param rstmgr A reset manager handle.
58 * @param expected_cpu_dump An array holding the expected cpu dump.
59 * @param dump_size The size of the expected_cpu_dump array.
Guillermo Maturana475a6e12021-10-27 12:31:39 -070060 */
Timothy Trippel1b73f802021-11-01 23:16:50 +000061void rstmgr_testutils_compare_cpu_info(
Guillermo Maturana475a6e12021-10-27 12:31:39 -070062 const dif_rstmgr_t *rstmgr,
63 dif_rstmgr_cpu_info_dump_segment_t *expected_cpu_dump, size_t dump_size);
64
65/**
66 * Prepares the rstmgr for a reset scenario.
67 *
68 * @param rstmgr A reset manager handle.
69 */
70void rstmgr_testutils_pre_reset(const dif_rstmgr_t *rstmgr);
71
72/**
73 * Checks state after a reset.
74 *
75 * This will cause a failure if any of the checks fail. If either of the dump
76 * arrays is null or its size is zero the corresponding comparison will be
77 * skipped.
78 *
79 * @param rstmgr A reset manager handle.
80 * @param expected_reset_info The expected contents of the reset_info CSR.
81 * @param expected_alert_dump An array with the expected contents of the
82 * alert_info CSR.
83 * @param alert_dump_size The size of the expected_alert_dump array.
84 * @param expected_cpu_dump An array with the expected contents of the cpu_info
85 * CSR.
86 * @param cpu_dump_size The size of the expected_cpu_dump array.
87 */
88void rstmgr_testutils_post_reset(
89 const dif_rstmgr_t *rstmgr,
90 dif_rstmgr_reset_info_bitfield_t expected_reset_info,
91 dif_rstmgr_alert_info_dump_segment_t *expected_alert_dump,
92 size_t alert_dump_size,
93 dif_rstmgr_cpu_info_dump_segment_t *expected_cpu_dump,
94 size_t cpu_dump_size);
95
Guillermo Maturana037bfc22021-10-05 10:13:58 -070096#endif // OPENTITAN_SW_DEVICE_LIB_TESTING_RSTMGR_TESTUTILS_H_