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