Software APIs
sw
device
lib
dif
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
17
#include "
sw/device/lib/base/macros.h
"
18
#include "
sw/device/lib/base/mmio.h
"
19
#include "
sw/device/lib/dif/dif_base.h
"
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
*/
44
typedef
enum
dif_rstmgr_software_reset
{
45
/**
46
* Simple reset (release straight away).
47
*/
48
kDifRstmgrSoftwareReset
= 0,
49
kDifRstmgrSoftwareResetHold
,
/**< Hold peripheral in reset. */
50
kDifRstmgrSoftwareResetRelease
,
/**< Release peripheral from reset. */
51
}
dif_rstmgr_software_reset_t
;
52
53
/**
54
* Reset Manager reset information bitfield.
55
*/
56
typedef
uint32_t
dif_rstmgr_reset_info_bitfield_t
;
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
*/
72
kDifRstmgrResetInfoPor
= 0x1,
73
/**
74
* Device has reset due to low power exit.
75
*/
76
kDifRstmgrResetInfoLowPowerExit
= (0x1 << 1),
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
*/
89
kDifRstmgrResetInfoSysRstCtrl
= (1 << 3),
90
/**
91
* Device has reset due to watchdog bite.
92
*/
93
kDifRstmgrResetInfoWatchdog
= (1 << 4),
94
/**
95
* Device has reset due to power unstable.
96
*/
97
kDifRstmgrResetInfoPowerUnstable
= (1 << 5),
98
/**
99
* Device has reset due to alert escalation.
100
*/
101
kDifRstmgrResetInfoEscalation
= (1 << 6),
102
/**
103
* Device has reset due to non-debug-module request.
104
*/
105
kDifRstmgrResetInfoNdm
= (1 << 7),
106
}
dif_rstmgr_reset_info_t
;
107
108
/**
109
* Reset Manager software reset available peripherals.
110
*/
111
typedef
uint32_t
dif_rstmgr_peripheral_t
;
112
113
typedef
enum
dif_rstmgr_fatal_err_type
{
114
/**
115
* A fatal error for regfile integrity.
116
*/
117
kDifRstmgrFatalErrTypeRegfileIntegrity
= 1u << 0,
118
/**
119
* A fatal error for reset consistency.
120
*/
121
kDifRstmgrFatalErrTypeResetConsistency
= 1u << 1,
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
*/
129
typedef
uint32_t
dif_rstmgr_fatal_err_codes_t
;
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
*/
140
OT_WARN_UNUSED_RESULT
141
dif_result_t
dif_rstmgr_reset
(
const
dif_rstmgr_t
*handle);
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
*/
153
OT_WARN_UNUSED_RESULT
154
dif_result_t
dif_rstmgr_reset_lock
(
const
dif_rstmgr_t
*handle,
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
*/
165
OT_WARN_UNUSED_RESULT
166
dif_result_t
dif_rstmgr_reset_is_locked
(
const
dif_rstmgr_t
*handle,
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
*/
180
OT_WARN_UNUSED_RESULT
181
dif_result_t
dif_rstmgr_reset_info_get
(
const
dif_rstmgr_t
*handle,
182
dif_rstmgr_reset_info_bitfield_t
*info);
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
*/
191
OT_WARN_UNUSED_RESULT
192
dif_result_t
dif_rstmgr_reset_info_clear
(
const
dif_rstmgr_t
*handle);
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
*/
206
OT_WARN_UNUSED_RESULT
207
dif_result_t
dif_rstmgr_alert_info_set_enabled
(
const
dif_rstmgr_t
*handle,
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
*/
220
OT_WARN_UNUSED_RESULT
221
dif_result_t
dif_rstmgr_alert_info_get_enabled
(
const
dif_rstmgr_t
*handle,
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
*/
232
OT_WARN_UNUSED_RESULT
233
dif_result_t
dif_rstmgr_alert_info_get_size
(
const
dif_rstmgr_t
*handle,
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
*/
241
typedef
uint32_t
dif_rstmgr_alert_info_dump_segment_t
;
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
*/
259
OT_WARN_UNUSED_RESULT
260
dif_result_t
dif_rstmgr_alert_info_dump_read
(
261
const
dif_rstmgr_t
*handle,
dif_rstmgr_alert_info_dump_segment_t
*dump,
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
*/
276
OT_WARN_UNUSED_RESULT
277
dif_result_t
dif_rstmgr_cpu_info_set_enabled
(
const
dif_rstmgr_t
*handle,
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
*/
290
OT_WARN_UNUSED_RESULT
291
dif_result_t
dif_rstmgr_cpu_info_get_enabled
(
const
dif_rstmgr_t
*handle,
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
*/
302
OT_WARN_UNUSED_RESULT
303
dif_result_t
dif_rstmgr_cpu_info_get_size
(
const
dif_rstmgr_t
*handle,
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
*/
311
typedef
uint32_t
dif_rstmgr_cpu_info_dump_segment_t
;
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
*/
329
OT_WARN_UNUSED_RESULT
330
dif_result_t
dif_rstmgr_cpu_info_dump_read
(
331
const
dif_rstmgr_t
*handle,
dif_rstmgr_cpu_info_dump_segment_t
*dump,
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
*/
342
OT_WARN_UNUSED_RESULT
343
dif_result_t
dif_rstmgr_software_reset
(
const
dif_rstmgr_t
*handle,
344
dif_rstmgr_peripheral_t
peripheral,
345
dif_rstmgr_software_reset_t
reset);
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
*/
355
OT_WARN_UNUSED_RESULT
356
dif_result_t
dif_rstmgr_software_reset_is_held
(
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
*/
366
OT_WARN_UNUSED_RESULT
367
dif_result_t
dif_rstmgr_software_device_reset
(
const
dif_rstmgr_t
*handle);
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
*/
376
OT_WARN_UNUSED_RESULT
377
dif_result_t
dif_rstmgr_fatal_err_code_get_codes
(
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_
Return to
OpenTitan Documentation