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