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. */
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. */
84
85enum {
86 kDtCsrngAlertCount = 2, /**< Number of Alerts */
87};
88
89
90/**
91 * List of clock ports.
92 *
93 * Clock ports are guaranteed to be numbered consecutively from 0.
94 */
95typedef enum dt_csrng_clock {
96 kDtCsrngClockClk = 0, /**< Clock port clk_i */
98
99enum {
100 kDtCsrngClockCount = 1, /**< Number of clock ports */
101};
102
103
104/**
105 * List of reset ports.
106 *
107 * Reset ports are guaranteed to be numbered consecutively from 0.
108 */
109typedef enum dt_csrng_reset {
110 kDtCsrngResetRst = 0, /**< Reset port rst_ni */
112
113enum {
114 kDtCsrngResetCount = 1, /**< Number of reset ports */
115};
116
117
118/**
119 * List of supported hardware features.
120 */
121#define OPENTITAN_CSRNG_HAS_INTERFACE_SOFTWARE 1
122#define OPENTITAN_CSRNG_HAS_INTERFACE_HARDWARE0 1
123#define OPENTITAN_CSRNG_HAS_INTERFACE_HARDWARE1 1
124#define OPENTITAN_CSRNG_HAS_MODE_DETERMINISTIC 1
125#define OPENTITAN_CSRNG_HAS_MODE_NONDETERMINISTIC 1
126#define OPENTITAN_CSRNG_HAS_READ_INT_STATE 1
127#define OPENTITAN_CSRNG_HAS_LIFECYCLE_DEBUGENABLE 1
128
129
130
131/**
132 * Get the csrng instance from an instance ID
133 *
134 * For example, `dt_uart_from_instance_id(kDtInstanceIdUart3) == kDtUart3`.
135 *
136 * @param inst_id Instance ID.
137 * @return A csrng instance.
138 *
139 * **Note:** This function only makes sense if the instance ID has device type csrng,
140 * otherwise the returned value is unspecified.
141 */
143
144/**
145 * Get the instance ID of an instance.
146 *
147 * @param dt Instance of csrng.
148 * @return The instance ID of that instance.
149 */
151
152/**
153 * Get the register base address of an instance.
154 *
155 * @param dt Instance of csrng.
156 * @param reg_block The register block requested.
157 * @return The register base address of the requested block.
158 */
159uint32_t dt_csrng_reg_block(
160 dt_csrng_t dt,
161 dt_csrng_reg_block_t reg_block);
162
163/**
164 * Get the primary register base address of an instance.
165 *
166 * This is just a convenience function, equivalent to
167 * `dt_csrng_reg_block(dt, kDtCsrngRegBlockCore)`
168 *
169 * @param dt Instance of csrng.
170 * @return The register base address of the primary register block.
171 */
172static inline uint32_t dt_csrng_primary_reg_block(
173 dt_csrng_t dt) {
174 return dt_csrng_reg_block(dt, kDtCsrngRegBlockCore);
175}
176
177/**
178 * Get the PLIC ID of a csrng IRQ for a given instance.
179 *
180 * If the instance is not connected to the PLIC, this function
181 * will return `kDtPlicIrqIdNone`.
182 *
183 * @param dt Instance of csrng.
184 * @param irq A csrng IRQ.
185 * @return The PLIC ID of the IRQ of this instance.
186 */
188 dt_csrng_t dt,
189 dt_csrng_irq_t irq);
190
191/**
192 * Convert a global IRQ ID to a local csrng IRQ type.
193 *
194 * @param dt Instance of csrng.
195 * @param irq A PLIC ID that belongs to this instance.
196 * @return The csrng IRQ, or `kDtCsrngIrqCount`.
197 *
198 * **Note:** This function assumes that the PLIC ID belongs to the instance
199 * of csrng passed in parameter. In other words, it must be the case that
200 * `dt_csrng_instance_id(dt) == dt_plic_id_to_instance_id(irq)`. Otherwise, this function
201 * will return `kDtCsrngIrqCount`.
202 */
204 dt_csrng_t dt,
205 dt_plic_irq_id_t irq);
206
207
208/**
209 * Get the alert ID of a csrng alert for a given instance.
210 *
211 * **Note:** This function only makes sense if the instance is connected to the Alert Handler. For any
212 * instances where the instance is not connected, the return value is unspecified.
213 *
214 * @param dt Instance of csrng.
215 * @param alert A csrng alert.
216 * @return The Alert Handler alert ID of the alert of this instance.
217 */
219 dt_csrng_t dt,
220 dt_csrng_alert_t alert);
221
222/**
223 * Convert a global alert ID to a local csrng alert type.
224 *
225 * @param dt Instance of csrng.
226 * @param alert A global alert ID that belongs to this instance.
227 * @return The csrng alert, or `kDtCsrngAlertCount`.
228 *
229 * **Note:** This function assumes that the global alert ID belongs to the
230 * instance of csrng passed in parameter. In other words, it must be the case
231 * that `dt_csrng_instance_id(dt) == dt_alert_id_to_instance_id(alert)`. Otherwise,
232 * this function will return `kDtCsrngAlertCount`.
233 */
235 dt_csrng_t dt,
236 dt_alert_id_t alert);
237
238
239
240/**
241 * Get the clock signal connected to a clock port of an instance.
242 *
243 * @param dt Instance of csrng.
244 * @param clk Clock port.
245 * @return Clock signal.
246 */
248 dt_csrng_t dt,
249 dt_csrng_clock_t clk);
250
251/**
252 * Get the reset signal connected to a reset port of an instance.
253 *
254 * @param dt Instance of csrng.
255 * @param rst Reset port.
256 * @return Reset signal.
257 */
259 dt_csrng_t dt,
260 dt_csrng_reset_t rst);
261
262
263
264#ifdef __cplusplus
265} // extern "C"
266#endif // __cplusplus
267
268#endif // OPENTITAN_DT_CSRNG_H_