Software APIs
csrng.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// Device table API auto-generated by `dtgen`
6
7#ifndef OPENTITAN_DT_CSRNG_H_
8#define OPENTITAN_DT_CSRNG_H_
9
10#ifdef __cplusplus
11extern "C" {
12#endif // __cplusplus
13
14/**
15 * @file
16 * @brief Device Tables (DT) for IP csrng and top darjeeling.
17 *
18 * This file contains the type definitions and global functions of the csrng.
19 */
20
21#include "hw/top/dt/api.h"
22#include <stdint.h>
23
24
25
26/**
27 * List of instances.
28 */
29typedef enum dt_csrng {
30 kDtCsrngFirst = 0, /**< First instance */
31 kDtCsrng = 0, /**< csrng */
33
34enum {
35 kDtCsrngCount = 1, /**< Number of instances */
36};
37
38
39/**
40 * List of register blocks.
41 *
42 * Register blocks are guaranteed to start at 0 and to be consecutively numbered.
43 */
44typedef enum dt_csrng_reg_block {
45 kDtCsrngRegBlockCore = 0, /**< */
47
48enum {
49 kDtCsrngRegBlockCount = 1, /**< Number of register blocks */
50};
51
52
53/** Primary register block (associated with the "primary" set of registers that control the IP). */
54static const dt_csrng_reg_block_t kDtCsrngRegBlockPrimary = kDtCsrngRegBlockCore;
55
56/**
57 * List of IRQs.
58 *
59 * IRQs are guaranteed to be numbered consecutively from 0.
60 */
61typedef enum dt_csrng_irq {
62 kDtCsrngIrqCsCmdReqDone = 0, /**< Asserted when a command request is completed, or when a CSRNG instance halted via INT_STATE_HALT has quiesced. */
63 kDtCsrngIrqCsEntropyReq = 1, /**< Asserted when a request for entropy has been made. */
64 kDtCsrngIrqCsHwInstExc = 2, /**< Asserted when a hardware-attached CSRNG instance encounters a command exception */
65 kDtCsrngIrqCsFatalErr = 3, /**< Asserted when a FIFO error or a fatal alert occurs. Check the !!ERR_CODE register to get more information. */
67
68enum {
69 kDtCsrngIrqCount = 4, /**< Number of IRQs */
70};
71
72
73/**
74 * List of Alerts.
75 *
76 * Alerts are guaranteed to be numbered consecutively from 0.
77 */
78typedef enum dt_csrng_alert {
79 kDtCsrngAlertRecovAlert = 0, /**< This alert is triggered when a recoverable alert occurs. Check the !!RECOV_ALERT_STS register to get more information. */
80 kDtCsrngAlertFatalAlert = 1, /**< This alert triggers (i) if an illegal state machine state is reached, or
81 (ii) if an AES fatal alert condition occurs, or (iii) if a fatal integrity
82 failure is detected on the TL-UL bus, or (iv) if a FIFO error is detected while
83 CSRNG is enabled. */
85
86enum {
87 kDtCsrngAlertCount = 2, /**< Number of Alerts */
88};
89
90
91/**
92 * List of clock ports.
93 *
94 * Clock ports are guaranteed to be numbered consecutively from 0.
95 */
96typedef enum dt_csrng_clock {
97 kDtCsrngClockClk = 0, /**< Clock port clk_i */
99
100enum {
101 kDtCsrngClockCount = 1, /**< Number of clock ports */
102};
103
104
105/**
106 * List of reset ports.
107 *
108 * Reset ports are guaranteed to be numbered consecutively from 0.
109 */
110typedef enum dt_csrng_reset {
111 kDtCsrngResetRst = 0, /**< Reset port rst_ni */
113
114enum {
115 kDtCsrngResetCount = 1, /**< Number of reset ports */
116};
117
118
119/**
120 * List of supported hardware features.
121 */
122#define OPENTITAN_CSRNG_HAS_INTERFACE_SOFTWARE 1
123#define OPENTITAN_CSRNG_HAS_INTERFACE_HARDWARE0 1
124#define OPENTITAN_CSRNG_HAS_INTERFACE_HARDWARE1 1
125#define OPENTITAN_CSRNG_HAS_MODE_DETERMINISTIC 1
126#define OPENTITAN_CSRNG_HAS_MODE_NONDETERMINISTIC 1
127#define OPENTITAN_CSRNG_HAS_HALT 1
128#define OPENTITAN_CSRNG_HAS_GENERATE_ABORT 1
129#define OPENTITAN_CSRNG_HAS_SAVE_AND_RESTORE 1
130#define OPENTITAN_CSRNG_HAS_LIFECYCLE_DEBUGENABLE 1
131
132
133
134/**
135 * Get the csrng instance from an instance ID
136 *
137 * For example, `dt_uart_from_instance_id(kDtInstanceIdUart3) == kDtUart3`.
138 *
139 * @param inst_id Instance ID.
140 * @return A csrng instance.
141 *
142 * **Note:** This function only makes sense if the instance ID has device type csrng,
143 * otherwise the returned value is unspecified.
144 */
146
147/**
148 * Get the instance ID of an instance.
149 *
150 * @param dt Instance of csrng.
151 * @return The instance ID of that instance.
152 */
154
155/**
156 * Get the register base address of an instance.
157 *
158 * @param dt Instance of csrng.
159 * @param reg_block The register block requested.
160 * @return The register base address of the requested block.
161 */
162uint32_t dt_csrng_reg_block(
163 dt_csrng_t dt,
164 dt_csrng_reg_block_t reg_block);
165
166/**
167 * Get the primary register base address of an instance.
168 *
169 * This is just a convenience function, equivalent to
170 * `dt_csrng_reg_block(dt, kDtCsrngRegBlockCore)`
171 *
172 * @param dt Instance of csrng.
173 * @return The register base address of the primary register block.
174 */
175static inline uint32_t dt_csrng_primary_reg_block(
176 dt_csrng_t dt) {
177 return dt_csrng_reg_block(dt, kDtCsrngRegBlockCore);
178}
179
180/**
181 * Get the PLIC ID of a csrng IRQ for a given instance.
182 *
183 * If the instance is not connected to the PLIC, this function
184 * will return `kDtPlicIrqIdNone`.
185 *
186 * @param dt Instance of csrng.
187 * @param irq A csrng IRQ.
188 * @return The PLIC ID of the IRQ of this instance.
189 */
191 dt_csrng_t dt,
192 dt_csrng_irq_t irq);
193
194/**
195 * Convert a global IRQ ID to a local csrng IRQ type.
196 *
197 * @param dt Instance of csrng.
198 * @param irq A PLIC ID that belongs to this instance.
199 * @return The csrng IRQ, or `kDtCsrngIrqCount`.
200 *
201 * **Note:** This function assumes that the PLIC ID belongs to the instance
202 * of csrng passed in parameter. In other words, it must be the case that
203 * `dt_csrng_instance_id(dt) == dt_plic_id_to_instance_id(irq)`. Otherwise, this function
204 * will return `kDtCsrngIrqCount`.
205 */
207 dt_csrng_t dt,
208 dt_plic_irq_id_t irq);
209
210
211/**
212 * Get the alert ID of a csrng alert for a given instance.
213 *
214 * **Note:** This function only makes sense if the instance is connected to the Alert Handler. For any
215 * instances where the instance is not connected, the return value is unspecified.
216 *
217 * @param dt Instance of csrng.
218 * @param alert A csrng alert.
219 * @return The Alert Handler alert ID of the alert of this instance.
220 */
222 dt_csrng_t dt,
223 dt_csrng_alert_t alert);
224
225/**
226 * Convert a global alert ID to a local csrng alert type.
227 *
228 * @param dt Instance of csrng.
229 * @param alert A global alert ID that belongs to this instance.
230 * @return The csrng alert, or `kDtCsrngAlertCount`.
231 *
232 * **Note:** This function assumes that the global alert ID belongs to the
233 * instance of csrng passed in parameter. In other words, it must be the case
234 * that `dt_csrng_instance_id(dt) == dt_alert_id_to_instance_id(alert)`. Otherwise,
235 * this function will return `kDtCsrngAlertCount`.
236 */
238 dt_csrng_t dt,
239 dt_alert_id_t alert);
240
241
242
243/**
244 * Get the clock signal connected to a clock port of an instance.
245 *
246 * @param dt Instance of csrng.
247 * @param clk Clock port.
248 * @return Clock signal.
249 */
251 dt_csrng_t dt,
252 dt_csrng_clock_t clk);
253
254/**
255 * Get the reset signal connected to a reset port of an instance.
256 *
257 * @param dt Instance of csrng.
258 * @param rst Reset port.
259 * @return Reset signal.
260 */
262 dt_csrng_t dt,
263 dt_csrng_reset_t rst);
264
265
266
267#ifdef __cplusplus
268} // extern "C"
269#endif // __cplusplus
270
271#endif // OPENTITAN_DT_CSRNG_H_