Software APIs
dif_rstmgr.h
Go to the documentation of this file.
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_DIF_DIF_RSTMGR_H_
6 #define OPENTITAN_SW_DEVICE_LIB_DIF_DIF_RSTMGR_H_
7 
8 /**
9  * @file
10  * @brief <a href="/book/hw/top_earlgrey/ip_autogen/rstmgr/">Reset Manager</a>
11  * Device Interface Functions
12  */
13 
14 #include <stdbool.h>
15 #include <stdint.h>
16 
20 
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif // __cplusplus
26 
27 /**
28  * The maximal size of the alert crash info dump.
29  *
30  * Note: must match the autogenerated register definition.
31  */
32 #define DIF_RSTMGR_ALERT_INFO_MAX_SIZE 0xf
33 
34 /**
35  * The maximal size of the CPU crash info dump.
36  *
37  * Note: must match the autogenerated register definition.
38  */
39 #define DIF_RSTMGR_CPU_INFO_MAX_SIZE 0xf
40 
41 /**
42  * Reset Manager peripheral software reset control.
43  */
45  /**
46  * Simple reset (release straight away).
47  */
49  kDifRstmgrSoftwareResetHold, /**< Hold peripheral in reset. */
50  kDifRstmgrSoftwareResetRelease, /**< Release peripheral from reset. */
52 
53 /**
54  * Reset Manager reset information bitfield.
55  */
57 
58 /**
59  * Reset Manager possible reset information enumeration.
60  *
61  * Invariants are used to extract information encoded in
62  * `dif_rstmgr_reset_info_bitfield_t`, which means that the values must
63  * correspond
64  * to the individual bits (0x1, 0x2, 0x4, ..., 0x80000000).
65  *
66  * Note: these must match the autogenerated register definitions.
67  */
68 typedef enum dif_rstmgr_reset_info {
69  /**
70  * Device has reset due to power up.
71  */
73  /**
74  * Device has reset due to low power exit.
75  */
77  /**
78  * Device has reset due to software request.
79  */
80  kDifRstmgrResetInfoSw = (0x1 << 2),
81  /**
82  * Device has reset due to a peripheral request. This can be an alert
83  * escalation, watchdog or anything else.
84  */
85  kDifRstmgrResetInfoHwReq = (0x1f << 3),
86  /**
87  * Device has reset due to the peripheral system reset control request.
88  */
90  /**
91  * Device has reset due to watchdog bite.
92  */
94  /**
95  * Device has reset due to power unstable.
96  */
98  /**
99  * Device has reset due to alert escalation.
100  */
102  /**
103  * Device has reset due to non-debug-module request.
104  */
107 
108 /**
109  * Reset Manager software reset available peripherals.
110  */
111 typedef uint32_t dif_rstmgr_peripheral_t;
112 
114  /**
115  * A fatal error for regfile integrity.
116  */
118  /**
119  * A fatal error for reset consistency.
120  */
122 } dif_rstmgr_fatal_err_type_t;
123 
124 /**
125  * A set of fatal errors.
126  *
127  * This type is used to read the fatal error codes.
128  */
130 
131 /**
132  * Resets the Reset Manager registers to sane defaults.
133  *
134  * Note that software reset enable registers cannot be cleared once have been
135  * locked.
136  *
137  * @param handle A Reset Manager handle.
138  * @return The result of the operation.
139  */
142 
143 /**
144  * Locks out requested peripheral reset functionality.
145  *
146  * Calling this function when software reset is locked will have no effect
147  * and return `kDifOk`.
148  *
149  * @param handle A Reset Manager handle.
150  * @param peripheral Peripheral to lock the reset functionality for.
151  * @return The result of the operation.
152  */
155  dif_rstmgr_peripheral_t peripheral);
156 
157 /**
158  * Checks whether requested peripheral reset functionality is locked.
159  *
160  * @param handle A Reset Manager handle.
161  * @param peripheral Peripheral to check the reset lock for.
162  * @param is_locked Out-param for the locked state.
163  * @return The result of the operation.
164  */
167  dif_rstmgr_peripheral_t peripheral,
168  bool *is_locked);
169 
170 /**
171  * Obtains the complete Reset Manager reset information.
172  *
173  * The reset info are parsed and presented to the caller as an
174  * array of flags in 'info'.
175  *
176  * @param handle A Reset Manager handle.
177  * @param info Reset information.
178  * @return The result of the operation.
179  */
183 
184 /**
185  * Clears the reset information in Reset Manager.
186  *
187  * @param handle A Reset Manager handle.
188  * @return `dif_result_t`.
189  * @return The result of the operation.
190  */
193 
194 /**
195  * Enables or disables the alert crash dump capture.
196  *
197  * When enabled, will capture the alert crash dump prior to a triggered reset.
198  *
199  * The alert info crash dump capture is automatically disabled upon system reset
200  * (even if the Reset Manager is not reset).
201  *
202  * @param handle A Reset Manager handle.
203  * @param state The new toggle state for the crash dump capture.
204  * @return The result of the operation.
205  */
208  dif_toggle_t state);
209 
210 /**
211  * Retrieves the alert info crash dump capture state.
212  *
213  * The alert info crash dump capture is automatically disabled upon system reset
214  * (even if the Reset Manager is not reset).
215  *
216  * @param handle A Reset Manager handle.
217  * @param[out] state The state of the crash dump capture.
218  * @return The result of the operation.
219  */
222  dif_toggle_t *state);
223 
224 /**
225  * Get alert info dump size.
226  *
227  *
228  * @param handle A Reset Manager handle.
229  * @param[out] size The size of the alert info dump in 32 bit words.
230  * @return The result of the operation.
231  */
234  size_t *size);
235 
236 /**
237  * Alert info crash dump segment.
238  *
239  * The alert info crash dump consists of 32-bit data segments
240  */
242 
243 /**
244  * Reads the entire alert info crash dump.
245  *
246  * The crash dump is always retained after any kind of reset, except on
247  * Power-On-Reset (POR).
248  *
249  * @param handle A Reset Manager handle.
250  * @param dump Address of buffer where the alert dump will be written.
251  * @param dump_size Size of the alert dump buffer. The entire crash dump will be
252  * read, and the actual size can be determined through the
253  * `segments_read` parameter. It is an error if dump_size is
254  * not large enough.
255  * @param[out] segments_read Number of segments read.
256  *
257  * @return The result of the operation.
258  */
262  size_t dump_size, size_t *segments_read);
263 
264 /**
265  * Enables or disables the CPU crash dump capture.
266  *
267  * When enabled, will capture the CPU crash dump prior to a triggered reset.
268  *
269  * The CPU info crash dump capture is automatically disabled upon system reset
270  * (even if the Reset Manager is not reset).
271  *
272  * @param handle A Reset Manager handle.
273  * @param state The new toggle state for the CPU crash dump capture.
274  * @return The result of the operation.
275  */
278  dif_toggle_t state);
279 
280 /**
281  * Retrieves the CPU info crash dump capture state.
282  *
283  * The CPU info crash dump capture is automatically disabled upon system reset
284  * (even if the Reset Manager is not reset).
285  *
286  * @param handle A Reset Manager handle.
287  * @param[out] state The state of the crash dump capture.
288  * @return The result of the operation.
289  */
292  dif_toggle_t *state);
293 
294 /**
295  * Get cpu info dump size.
296  *
297  *
298  * @param handle A Reset Manager handle.
299  * @param[out] size The size of the cpu info dump in 32 bit words.
300  * @return The result of the operation.
301  */
304  size_t *size);
305 
306 /**
307  * CPU info crash dump segment.
308  *
309  * The CPU info crash dump consists of 32-bit data segments
310  */
312 
313 /**
314  * Reads the entire CPU info crash dump.
315  *
316  * The crash dump is always retained after any kind of reset, except on
317  * Power-On-Reset (POR).
318  *
319  * @param handle A Reset Manager handle.
320  * @param dump Address of buffer where the crash dump will be written.
321  * @param dump_size Size of the crash dump buffer. The entire crash dump will
322  * be read, and the actual size can be determined through the
323  * `segments_read` parameter. It is an error if dump_size is
324  * not large enough.
325  * @param[out] segments_read Number of segments read.
326  *
327  * @return The result of the operation.
328  */
332  size_t dump_size, size_t *segments_read);
333 
334 /**
335  * Asserts or de-asserts software reset for the requested peripheral.
336  *
337  * @param handle A Reset Manager handle.
338  * @param peripheral Peripheral to assert/de-assert reset for.
339  * @param reset Reset control.
340  * @return The result of the operation.
341  */
344  dif_rstmgr_peripheral_t peripheral,
346 
347 /**
348  * Queries whether the requested peripheral is held in reset.
349  *
350  * @param handle A Reset Manager handle.
351  * @param peripheral Peripheral to query.
352  * @param asserted 'true' when held in reset, `false` otherwise.
353  * @return The result of the operation.
354  */
357  const dif_rstmgr_t *handle, dif_rstmgr_peripheral_t peripheral,
358  bool *asserted);
359 
360 /**
361  * Software request for system reset
362  *
363  * @param handle A Reset Manager handle.
364  * @return The result of the operation.
365  */
368 
369 /**
370  * Read the fatal error codes.
371  *
372  * @param rstmgr Reset Manager Handle.
373  * @param[out] codes The fatal error codes.
374  * @returns The result of the operation.
375  */
378  const dif_rstmgr_t *rstmgr, dif_rstmgr_fatal_err_codes_t *codes);
379 
380 #ifdef __cplusplus
381 } // extern "C"
382 #endif // __cplusplus
383 
384 #endif // OPENTITAN_SW_DEVICE_LIB_DIF_DIF_RSTMGR_H_