Software APIs
dif_rv_core_ibex.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_RV_CORE_IBEX_H_
6#define OPENTITAN_SW_DEVICE_LIB_DIF_DIF_RV_CORE_IBEX_H_
7
8#include <stdint.h>
9
13
14#include "sw/device/lib/dif/autogen/dif_rv_core_ibex_autogen.h"
15
16#ifdef __cplusplus
17extern "C" {
18#endif // __cplusplus
19
20/**
21 * @file
22 * Access to Ibex state (e.g. addresses, crashdumps, alerts)
23 */
24
25/**
26 * Address translation slot selection.
27 */
29 kDifRvCoreIbexAddrTranslationSlot_0,
30 kDifRvCoreIbexAddrTranslationSlot_1,
31 kDifRvCoreIbexAddrTranslationSlotCount,
33
34/**
35 * Address translation bus selection.
36 */
38 kDifRvCoreIbexAddrTranslationDBus,
39 kDifRvCoreIbexAddrTranslationIBus,
40 kDifRvCoreIbexAddrTranslationBusCount,
42
43/**
44 * Address translation matching region.
45 *
46 * The value programmed is done at power-of-2 alignment. For example, if the
47 * intended matching region is 0x8000_0000 to 0x8000_FFFF, the value
48 * programmed is 0x8000_7FFF.
49 *
50 * The value programmed can be determined from the translation granule. Assume
51 * the user wishes to translate a specific 64KB block to a different address:
52 * 64KB has a hex value of 0x10000. Subtract 1 from this value and then right
53 * shift by one to obtain 0x7FFF. This value is then logically OR'd with the
54 * upper address bits that would select which 64KB to translate.
55 */
57 /**
58 * Matching address (Virtual address).
59 * When an incoming transaction matches the matching
60 * region, it is redirected to the new address. If a transaction does not
61 * match, then it is directly passed through.
62 */
63 uintptr_t matching_addr;
64
65 /**
66 * Remap address (Physical address).
67 * The region where the matched transtaction will be
68 * redirected to.
69 */
70 uintptr_t remap_addr;
71
72 /**
73 * Address region size.
74 */
75 size_t size;
77
78/**
79 * Ibex error status detected by `rv_core_ibex` peripheral.
80 */
82 /**
83 * Register transmission integrity error.
84 */
86
87 /**
88 * Response integrity error.
89 */
91
92 /**
93 * Fatal internal error (`alert_major_internal_o` from Ibex seen).
94 */
96
97 /**
98 * recoverable internal error (`alert_minor` from Ibex seen).
99 */
101
102 /**
103 * All errors combined.
104 */
105 kDifRvCoreIbexErrorStatusAll = (1 << 0 | 1 << 8 | 1 << 9 | 1 << 10),
107
109 /**
110 * The current rnd word is valid.
111 */
113 /**
114 * The current rnd word is fips compliant.
115 */
117} dif_rv_core_ibex_rnd_status_code_t;
118
119/**
120 * Bitmask with the `dif_rv_core_ibex_rnd_status_code_t` values.
121 */
123
124/**
125 * NMI enabled status and current state.
126 */
128 /**
129 * NMI alert is currently enabled.
130 */
132 /**
133 * Alert has been raised.
134 */
136 /**
137 * NMI watchdog is currently enabled.
138 */
140 /**
141 * Watchdog has barked.
142 */
145
147 /**
148 * NMI alert handler.
149 */
151 /**
152 * NMI watchdog bark.
153 */
155 /**
156 * All ibex NMIs.
157 */
159} dif_rv_core_ibex_nmi_source_t;
160
162 /**
163 * The last exception address.
164 */
165 uint32_t mtval;
166
167 /**
168 * The last exception PC.
169 */
170 uint32_t mpec;
171
172 /**
173 * The last data access address.
174 */
175 uint32_t mdaa;
176
177 /**
178 * The next PC.
179 */
180 uint32_t mnpc;
181
182 /**
183 * The current PC.
184 */
185 uint32_t mcpc;
186} dif_rv_core_ibex_crash_dump_state_t;
187
189 /**
190 * The exception address for the previous crash.
191 */
192 uint32_t mtval;
193
194 /**
195 * The last exception PC for the previous crash.
196 */
197 uint32_t mpec;
198} dif_rv_core_ibex_previous_crash_dump_state_t;
199
200/**
201 * Under normal circumstances, only the current crash dump state is valid. When
202 * the CPU encounters a double fault, the current crash dump is moved to
203 * previous, and the new crash dump is shown in current.
204 */
206 /**
207 * The crash dump state for the current execution.
208 */
209 dif_rv_core_ibex_crash_dump_state_t fault_state;
210
211 /**
212 * The crash dump state for the previous execution. It will only contain valid
213 * data in case of a double fault, which will be indicated by the
214 * `double_fault` member.
215 */
216 dif_rv_core_ibex_previous_crash_dump_state_t previous_fault_state;
217
218 /**
219 * `kDifToggleEnabled` if a double fault happened, otherwise
220 * `kDifToggleDisabled`
221 */
224
225/**
226 * Configure address translation for
227 * the given `bus` (either instruction or data) in the `slot`.
228 *
229 * @param rv_core_ibex Handle.
230 * @param slot Slot to be used.
231 * @param bus Bus to be translated.
232 * @param addr_map Address mapping description.
233 * @return The result of the operation.
234 */
237 const dif_rv_core_ibex_t *rv_core_ibex,
241
242/**
243 * Enable address translation for
244 * the given `bus` (either instruction or data) in the `slot`.
245 *
246 * @param rv_core_ibex Handle.
247 * @param slot Slot to be used.
248 * @param bus Bus to be translated.
249 * @return The result of the operation.
250 */
253 const dif_rv_core_ibex_t *rv_core_ibex,
256
257/**
258 * Disable address translation for
259 * the given `bus` (either instruction or data) in the `slot`.
260 *
261 * @param rv_core_ibex Handle.
262 * @param slot Slot to be used.
263 * @param bus Bus to be translated.
264 * @return The result of the operation.
265 */
268 const dif_rv_core_ibex_t *rv_core_ibex,
271
272/**
273 * Read a discription of the address mapping configured on a given `slot`
274 * for a given `bus`.
275 *
276 * @param rv_core_ibex Handle.
277 * @param slot Slot of interest.
278 * @param bus Bus of interest.
279 * @param[out] addr_map Description of address mapping.
280 * @return The result of the operation.
281 */
284 const dif_rv_core_ibex_t *rv_core_ibex,
288
289/**
290 * Lock the address translation settings for a given `slot` and `bus` registers.
291 * Once locked it can no longer be unlocked until the next system reset. This
292 * function will quietly do nothing if the settings are already locked.
293 *
294 * @param rv_core_ibex Handle.
295 * @param slot Slot to be locked.
296 * @param bus Translated bus to be locked.
297 * @return The result of the operation.
298 */
301 const dif_rv_core_ibex_t *rv_core_ibex,
304
305/**
306 * Read the ibex error status.
307 *
308 * @param rv_core_ibex Handle.
309 * @param error_status Pointer to receive the error status value.
310 * @return The result of the operation.
311 */
314 const dif_rv_core_ibex_t *rv_core_ibex,
315 dif_rv_core_ibex_error_status_t *error_status);
316
317/**
318 * Clear the ibex error status, after the software has handled it.
319 *
320 * @param rv_core_ibex Handle.
321 * @param error_status The error to be cleared.
322 * @return The result of the operation.
323 */
326 const dif_rv_core_ibex_t *rv_core_ibex,
328
329/**
330 * Enables NMI support for security alert events and watchdog bark.
331 *
332 * @param rv_core_ibex Handle.
333 * @param nmi A bitmask with nmi sources to be enabled.
334 * @return The result of the operation.
335 */
338 dif_rv_core_ibex_nmi_source_t nmi);
339
340/**
341 * Read the NMI enable status and current event state.
342 *
343 * @param rv_core_ibex Handle.
344 * @param[out] nmi_state The nmi state.
345 * @return The result of the operation.
346 */
349 const dif_rv_core_ibex_t *rv_core_ibex,
351
352/**
353 * Clear the NMI current event state.
354 *
355 * @param rv_core_ibex Handle
356 * @param nmi A bitmask with nmi sources to be cleared.
357 * @return The result of the operation.
358 */
361 const dif_rv_core_ibex_t *rv_core_ibex, dif_rv_core_ibex_nmi_source_t nmi);
362
363/**
364 * Gets whether the rnd data is either valid or is FIPS compliant.
365 *
366 * @param rv_core_ibex Handle.
367 * @param[out] status Pointer to be filled with the current rnd status.
368 * @return The result of the operation.
369 */
372 const dif_rv_core_ibex_t *rv_core_ibex,
374
375/**
376 * Reads a random word from the RISC-V Ibex core wrapper.
377 *
378 * @param rv_core_ibex Handle.
379 * @param[out] data Pointer to be filled with the random word.
380 * @return The result of the operation.
381 */
384 const dif_rv_core_ibex_t *rv_core_ibex, uint32_t *data);
385
386typedef uint32_t dif_rv_core_ibex_fpga_info_t;
387
388/**
389 * Read the FPGA build timestamp info. This function only returns valid data for
390 * fpga environments, for all other environments it is simply 0.
391 *
392 * @param rv_core_ibex Handle.
393 * @param[out] info A pointer to receive the FPGA timestamp info.
394 * @return The result of the operation.
395 */
398 const dif_rv_core_ibex_t *rv_core_ibex, dif_rv_core_ibex_fpga_info_t *info);
399
400/**
401 * Software fatal alert. When triggered,
402 * a fatal alert is sent. Note, this alert once cleared cannot be set and
403 * will continuously cause alert events.
404 */
405
406/**
407 * Get the software recoverable alert sate.
408 *
409 * @param rv_core_ibex Handle.
410 * @param[out] enabled Returns `true` if enabled.
411 * @return The result of the operation.
412 */
414 const dif_rv_core_ibex_t *rv_core_ibex, bool *enabled);
415
416/**
417 * Software recoverable alert. When triggered, a recoverable alert is sent. Once
418 * the alert is sent, the register is then reset to disabled.
419 *
420 * @param rv_core_ibex Handle.
421 * @return The result of the operation.
422 */
425 const dif_rv_core_ibex_t *rv_core_ibex);
426
427/**
428 * Get the software fatal alert trigger status.
429 *
430 * @param rv_core_ibex Handle.
431 * @param[out] enabled Returns `true` if enabled.
432 * @return The result of the operation.
433 */
436 const dif_rv_core_ibex_t *rv_core_ibex, bool *enabled);
437
438/**
439 * Software fatal alert. When triggered, a fatal alert is sent. Note, once this
440 * alert is triggered it cannot be reset and will continuously cause alert
441 * events.
442 *
443 * @param rv_core_ibex Handle.
444 * @return The result of the operation.
445 */
448 const dif_rv_core_ibex_t *rv_core_ibex);
449
450/**
451 * Parse the cpu info read from the rstmgr.
452 *
453 * @param rv_core_ibex Handle.
454 * @param cpu_info Buffer with the cpu info read from the rstmgr.
455 * @param cpu_info_len The amount of words in the `cpu_info` buffer.
456 * @param[out] crash_dump_info Parsed dump.
457 * @return The result of the operation.
458 */
461 const dif_rv_core_ibex_t *rv_core_ibex, uint32_t *cpu_info,
462 uint32_t cpu_info_len, dif_rv_core_ibex_crash_dump_info_t *crash_dump_info);
463
464#ifdef __cplusplus
465} // extern "C"
466#endif // __cplusplus
467#endif // OPENTITAN_SW_DEVICE_LIB_DIF_DIF_RV_CORE_IBEX_H_