Software APIs
rram_ctrl_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_RRAM_CTRL_TESTUTILS_H_
6#define OPENTITAN_SW_DEVICE_LIB_TESTING_RRAM_CTRL_TESTUTILS_H_
7
8#include <stdint.h>
9
10#include "sw/device/lib/base/status.h"
12
13/**
14 * Wait for the rram_ctrl to initialize.
15 *
16 * @param rram_state A rram_ctrl state handle.
17 */
19status_t rram_ctrl_testutils_wait_for_init(dif_rram_ctrl_state_t *rram_state);
20
21/**
22 * Wait for a rram_ctrl operation to end.
23 *
24 * Calls dif_rram_ctrl_end in a loop and waits for a dif_result of Ok. If at
25 * any time the result is BadArg or Error this will fail.
26 * Clears any error codes and returns the value of operation_error.
27 *
28 * @param rram_state A rram_ctrl state handle.
29 * @return The result of the operation.
30 */
32status_t rram_ctrl_testutils_wait_transaction_end(
33 dif_rram_ctrl_state_t *rram_state);
34
35/**
36 * Setup and enable for a data region taking region properties as a parameter.
37 *
38 * @param rram_state A rram_ctrl state handle.
39 * @param base_page_index The region base page index.
40 * @param data_region The region index.
41 * @param region_size The region size (in number of pages).
42 * @param region_properties The properties for the data region.
43 * @param[out] offset The byte address offset of the region.
44 * @return The result of the operation.
45 */
47status_t rram_ctrl_testutils_data_region_setup_properties(
48 dif_rram_ctrl_state_t *rram_state, uint32_t base_page_index,
49 uint32_t data_region, uint32_t region_size,
50 dif_rram_ctrl_region_properties_t region_properties, uint32_t *offset);
51
52/**
53 * Setup and enable for a data region with scrambling disabled.
54 *
55 * @param rram_state A rram_ctrl state handle.
56 * @param base_page_index The region base page index.
57 * @param data_region The region index.
58 * @param region_size The region size (in number of pages).
59 * @param[out] offset The byte address offset of the region.
60 * @return The result of the operation.
61 */
63status_t rram_ctrl_testutils_data_region_setup(
64 dif_rram_ctrl_state_t *rram_state, uint32_t base_page_index,
65 uint32_t data_region, uint32_t region_size, uint32_t *offset);
66
67/**
68 * Setup and enable for a data region with scrambling enabled.
69 *
70 * @param rram_state A rram_ctrl state handle.
71 * @param base_page_index The region base page index.
72 * @param data_region The region index.
73 * @param region_size The region size (in number of pages).
74 * @param[out] offset The byte address offset of the region.
75 * @return The result of the operation.
76 */
78status_t rram_ctrl_testutils_data_region_scrambled_setup(
79 dif_rram_ctrl_state_t *rram_state, uint32_t base_page_index,
80 uint32_t data_region, uint32_t region_size, uint32_t *offset);
81
82/**
83 * Setup and enable for an info region taking region properties as a parameter.
84 *
85 * @param rram_state A rram_ctrl state handle.
86 * @param page_id Region page index.
87 * @param region_properties The properties for the info region.
88 * @param[out] offset The byte address offset of the region.
89 * @return The result of the operation.
90 */
92status_t rram_ctrl_testutils_info_region_setup_properties(
93 dif_rram_ctrl_state_t *rram_state, uint32_t page_id,
94 dif_rram_ctrl_region_properties_t region_properties, uint32_t *offset);
95
96/**
97 * Setup and enable for an info region with scrambling disabled.
98 *
99 * @param rram_state A rram_ctrl state handle.
100 * @param page_id Region page index.
101 * @param[out] offset The byte address offset of the region.
102 * @return The result of the operation.
103 */
105status_t rram_ctrl_testutils_info_region_setup(
106 dif_rram_ctrl_state_t *rram_state, uint32_t page_id, uint32_t *offset);
107
108/**
109 * Setup and enable for an info region with scrambling enabled.
110 *
111 * @param rram_state A rram_ctrl state handle.
112 * @param page_id Region page index.
113 * @param[out] offset The byte address offset of the region.
114 * @return The result of the operation.
115 */
117status_t rram_ctrl_testutils_info_region_scrambled_setup(
118 dif_rram_ctrl_state_t *rram_state, uint32_t page_id, uint32_t *offset);
119
120/**
121 * Write RRAM starting from byte_address.
122 * The write is broken into as many transactions as required for the supplied
123 * word_count exceeds the maximum supported size.
124 * Returns the result of transaction_end.
125 *
126 * @param rram_state A rram_ctrl state handle.
127 * @param byte_address The byte address of the page to program.
128 * @param data The data to program.
129 * @param partition_type The partition type, data or info.
130 * @param word_count The number of uint32_t words to program.
131 * @return The result of the operation.
132 */
134status_t rram_ctrl_testutils_write(
135 dif_rram_ctrl_state_t *rram_state, uint32_t byte_address,
136 const uint32_t *data, dif_rram_ctrl_partition_type_t partition_type,
137 uint32_t word_count);
138
139/**
140 * Write a single 32b word to RRAM.
141 * A full RRAM line is read, modified and written back to the RRAM
142 * Returns the result of transaction_end.
143 *
144 * @param rram_state A rram_ctrl state handle.
145 * @param byte_address The byte address of the page to program.
146 * @param data The data to program.
147 * @param partition_type The partition type, data or info.
148 * @return The result of the operation.
149 */
151status_t rram_ctrl_testutils_write_word(
152 dif_rram_ctrl_state_t *rram_state, uint32_t byte_address,
153 const uint32_t *data, dif_rram_ctrl_partition_type_t partition_type);
154
155/**
156 * Reads data starting from byte_address.
157 * Returns the result of transaction_end.
158 *
159 * @param rram_state A rram_ctrl state handle.
160 * @param byte_address The byte address of the page to erase and program.
161 * @param[out] data_out The data read from the page.
162 * @param partition_type The partition type, data or info.
163 * @param word_count The number of uint32_t words to read.
164 * @param delay_micros Optional delay (in us) for read FIFO fill testing.
165 * @return The result of the operation.
166 */
168status_t rram_ctrl_testutils_read(dif_rram_ctrl_state_t *rram_state,
169 uint32_t byte_address, uint32_t *data_out,
170 dif_rram_ctrl_partition_type_t partition_type,
171 uint32_t word_count, uint32_t delay);
172
173/**
174 * Sets the RRAM default configuration.
175 *
176 * @param rram_state A rram_ctrl state handle.
177 * @param rd_en Default read enable.
178 * @param wr_en Default program enable.
179 * @param scramble_en Default scramble enable.
180 * @param ecc_en Default ECC enable.
181 */
183status_t rram_ctrl_testutils_default_region_access(
184 dif_rram_ctrl_state_t *rram_state, bool rd_en, bool wr_en, bool scramble_en,
185 bool ecc_en);
186
187/**
188 * Write to log any faults set in the status register.
189 *
190 * @param rram_state A rram_ctrl state handle.
191 */
193status_t rram_ctrl_testutils_log_faults(
194 const dif_rram_ctrl_state_t *rram_state);
195
196/**
197 * Print the properties of a RRAM data region configuration.
198 *
199 * This prints:
200 *
201 * data region n=<index> st=<start> sz=<size> RD-WR-SC-EC LK
202 *
203 * The various properties are printed depending on their mubi bool value:
204 * - The property (e.g. `RD`, `WR`, etc) is printed if enabled by Mubi4True.
205 * - The string `xx` is printed if disabled by Mubi4False.
206 * - The string `uu` is printed if disabled by any other non-True value.
207 *
208 * @param index The index of the region.
209 * @param p The properties of the region.
210 * @param locked Whether or not the region is locked.
211 */
212void rram_ctrl_testutils_data_region_print(
213 size_t index, dif_rram_ctrl_data_region_properties_t *p, bool locked);
214
215/**
216 * Print the properties of a RRAM data region configuration.
217 *
218 * This prints:
219 *
220 * info region page=<page> RD-WR-SC-EC LK
221 *
222 * The various properties are printed depending on their mubi bool value:
223 * - The property (e.g. `RD`, `WR`, etc) is printed if enabled by Mubi4True.
224 * - The string `xx` is printed if disabled by Mubi4False.
225 * - The string `uu` is printed if disabled by any other non-True value.
226 *
227 * @param region The info region descriptor.
228 * @param p The properties of the region.
229 * @param locked Whether or not the region is locked.
230 */
231void rram_ctrl_testutils_info_region_print(dif_rram_ctrl_info_region_t region,
233 bool locked);
234#endif // OPENTITAN_SW_DEVICE_LIB_TESTING_RRAM_CTRL_TESTUTILS_H_