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