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 
21 #include "sw/device/lib/dif/autogen/dif_rstmgr_autogen.h"
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 #if defined(OPENTITAN_IS_EARLGREY)
87  /**
88  * Device has reset due to the peripheral system reset control request.
89  */
90  kDifRstmgrResetInfoSysRstCtrl = (1 << 3),
91  /**
92  * Device has reset due to watchdog bite.
93  */
94  kDifRstmgrResetInfoWatchdog = (1 << 4),
95 #elif defined(OPENTITAN_IS_DARJEELING)
96  /**
97  * Device has reset due to watchdog bite.
98  */
99  kDifRstmgrResetInfoWatchdog = (1 << 3),
100  /**
101  * Device has reset due to an external reset request via soc_proxy.
102  */
103  kDifRstmgrResetInfoExternalRst = (1 << 4),
104 #else
105 #error "dif_rstmgr does not support this top"
106 #endif
107  /**
108  * Device has reset due to power unstable.
109  */
111  /**
112  * Device has reset due to alert escalation.
113  */
115  /**
116  * Device has reset due to non-debug-module request.
117  */
120 
121 /**
122  * Reset Manager software reset available peripherals.
123  */
124 typedef uint32_t dif_rstmgr_peripheral_t;
125 
127  /**
128  * A fatal error for regfile integrity.
129  */
131  /**
132  * A fatal error for reset consistency.
133  */
135 } dif_rstmgr_fatal_err_type_t;
136 
137 /**
138  * A set of fatal errors.
139  *
140  * This type is used to read the fatal error codes.
141  */
143 
144 /**
145  * Resets the Reset Manager registers to sane defaults.
146  *
147  * Note that software reset enable registers cannot be cleared once have been
148  * locked.
149  *
150  * @param handle A Reset Manager handle.
151  * @return The result of the operation.
152  */
154 dif_result_t dif_rstmgr_reset(const dif_rstmgr_t *handle);
155 
156 /**
157  * Locks out requested peripheral reset functionality.
158  *
159  * Calling this function when software reset is locked will have no effect
160  * and return `kDifOk`.
161  *
162  * @param handle A Reset Manager handle.
163  * @param peripheral Peripheral to lock the reset functionality for.
164  * @return The result of the operation.
165  */
167 dif_result_t dif_rstmgr_reset_lock(const dif_rstmgr_t *handle,
168  dif_rstmgr_peripheral_t peripheral);
169 
170 /**
171  * Checks whether requested peripheral reset functionality is locked.
172  *
173  * @param handle A Reset Manager handle.
174  * @param peripheral Peripheral to check the reset lock for.
175  * @param is_locked Out-param for the locked state.
176  * @return The result of the operation.
177  */
179 dif_result_t dif_rstmgr_reset_is_locked(const dif_rstmgr_t *handle,
180  dif_rstmgr_peripheral_t peripheral,
181  bool *is_locked);
182 
183 /**
184  * Obtains the complete Reset Manager reset information.
185  *
186  * The reset info are parsed and presented to the caller as an
187  * array of flags in 'info'.
188  *
189  * @param handle A Reset Manager handle.
190  * @param info Reset information.
191  * @return The result of the operation.
192  */
194 dif_result_t dif_rstmgr_reset_info_get(const dif_rstmgr_t *handle,
196 
197 /**
198  * Clears the reset information in Reset Manager.
199  *
200  * @param handle A Reset Manager handle.
201  * @return `dif_result_t`.
202  * @return The result of the operation.
203  */
205 dif_result_t dif_rstmgr_reset_info_clear(const dif_rstmgr_t *handle);
206 
207 /**
208  * Enables or disables the alert crash dump capture.
209  *
210  * When enabled, will capture the alert crash dump prior to a triggered reset.
211  *
212  * The alert info crash dump capture is automatically disabled upon system reset
213  * (even if the Reset Manager is not reset).
214  *
215  * @param handle A Reset Manager handle.
216  * @param state The new toggle state for the crash dump capture.
217  * @return The result of the operation.
218  */
220 dif_result_t dif_rstmgr_alert_info_set_enabled(const dif_rstmgr_t *handle,
221  dif_toggle_t state);
222 
223 /**
224  * Retrieves the alert info crash dump capture state.
225  *
226  * The alert info crash dump capture is automatically disabled upon system reset
227  * (even if the Reset Manager is not reset).
228  *
229  * @param handle A Reset Manager handle.
230  * @param[out] state The state of the crash dump capture.
231  * @return The result of the operation.
232  */
234 dif_result_t dif_rstmgr_alert_info_get_enabled(const dif_rstmgr_t *handle,
235  dif_toggle_t *state);
236 
237 /**
238  * Get alert info dump size.
239  *
240  *
241  * @param handle A Reset Manager handle.
242  * @param[out] size The size of the alert info dump in 32 bit words.
243  * @return The result of the operation.
244  */
246 dif_result_t dif_rstmgr_alert_info_get_size(const dif_rstmgr_t *handle,
247  size_t *size);
248 
249 /**
250  * Alert info crash dump segment.
251  *
252  * The alert info crash dump consists of 32-bit data segments
253  */
255 
256 /**
257  * Reads the entire alert info crash dump.
258  *
259  * The crash dump is always retained after any kind of reset, except on
260  * Power-On-Reset (POR).
261  *
262  * @param handle A Reset Manager handle.
263  * @param dump Address of buffer where the alert dump will be written.
264  * @param dump_size Size of the alert dump buffer. The entire crash dump will be
265  * read, and the actual size can be determined through the
266  * `segments_read` parameter. It is an error if dump_size is
267  * not large enough.
268  * @param[out] segments_read Number of segments read.
269  *
270  * @return The result of the operation.
271  */
274  const dif_rstmgr_t *handle, dif_rstmgr_alert_info_dump_segment_t *dump,
275  size_t dump_size, size_t *segments_read);
276 
277 /**
278  * Enables or disables the CPU crash dump capture.
279  *
280  * When enabled, will capture the CPU crash dump prior to a triggered reset.
281  *
282  * The CPU info crash dump capture is automatically disabled upon system reset
283  * (even if the Reset Manager is not reset).
284  *
285  * @param handle A Reset Manager handle.
286  * @param state The new toggle state for the CPU crash dump capture.
287  * @return The result of the operation.
288  */
290 dif_result_t dif_rstmgr_cpu_info_set_enabled(const dif_rstmgr_t *handle,
291  dif_toggle_t state);
292 
293 /**
294  * Retrieves the CPU info crash dump capture state.
295  *
296  * The CPU info crash dump capture is automatically disabled upon system reset
297  * (even if the Reset Manager is not reset).
298  *
299  * @param handle A Reset Manager handle.
300  * @param[out] state The state of the crash dump capture.
301  * @return The result of the operation.
302  */
304 dif_result_t dif_rstmgr_cpu_info_get_enabled(const dif_rstmgr_t *handle,
305  dif_toggle_t *state);
306 
307 /**
308  * Get cpu info dump size.
309  *
310  *
311  * @param handle A Reset Manager handle.
312  * @param[out] size The size of the cpu info dump in 32 bit words.
313  * @return The result of the operation.
314  */
316 dif_result_t dif_rstmgr_cpu_info_get_size(const dif_rstmgr_t *handle,
317  size_t *size);
318 
319 /**
320  * CPU info crash dump segment.
321  *
322  * The CPU info crash dump consists of 32-bit data segments
323  */
325 
326 /**
327  * Reads the entire CPU info crash dump.
328  *
329  * The crash dump is always retained after any kind of reset, except on
330  * Power-On-Reset (POR).
331  *
332  * @param handle A Reset Manager handle.
333  * @param dump Address of buffer where the crash dump will be written.
334  * @param dump_size Size of the crash dump buffer. The entire crash dump will
335  * be read, and the actual size can be determined through the
336  * `segments_read` parameter. It is an error if dump_size is
337  * not large enough.
338  * @param[out] segments_read Number of segments read.
339  *
340  * @return The result of the operation.
341  */
344  const dif_rstmgr_t *handle, dif_rstmgr_cpu_info_dump_segment_t *dump,
345  size_t dump_size, size_t *segments_read);
346 
347 /**
348  * Asserts or de-asserts software reset for the requested peripheral.
349  *
350  * @param handle A Reset Manager handle.
351  * @param peripheral Peripheral to assert/de-assert reset for.
352  * @param reset Reset control.
353  * @return The result of the operation.
354  */
356 dif_result_t dif_rstmgr_software_reset(const dif_rstmgr_t *handle,
357  dif_rstmgr_peripheral_t peripheral,
359 
360 /**
361  * Queries whether the requested peripheral is held in reset.
362  *
363  * @param handle A Reset Manager handle.
364  * @param peripheral Peripheral to query.
365  * @param asserted 'true' when held in reset, `false` otherwise.
366  * @return The result of the operation.
367  */
370  const dif_rstmgr_t *handle, dif_rstmgr_peripheral_t peripheral,
371  bool *asserted);
372 
373 /**
374  * Software request for system reset
375  *
376  * @param handle A Reset Manager handle.
377  * @return The result of the operation.
378  */
380 dif_result_t dif_rstmgr_software_device_reset(const dif_rstmgr_t *handle);
381 
382 /**
383  * Read the fatal error codes.
384  *
385  * @param rstmgr Reset Manager Handle.
386  * @param[out] codes The fatal error codes.
387  * @returns The result of the operation.
388  */
391  const dif_rstmgr_t *rstmgr, dif_rstmgr_fatal_err_codes_t *codes);
392 
393 #ifdef __cplusplus
394 } // extern "C"
395 #endif // __cplusplus
396 
397 #endif // OPENTITAN_SW_DEVICE_LIB_DIF_DIF_RSTMGR_H_