Software APIs
dt_otbn.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_OTBN_H_
8#define OPENTITAN_DT_OTBN_H_
9
10#ifdef __cplusplus
11extern "C" {
12#endif // __cplusplus
13
14/**
15 * @file
16 * @brief Device Tables (DT) for IP otbn and top earlgrey.
17 *
18 * This file contains the type definitions and global functions of the otbn.
19 */
20
21#include "hw/top/dt/dt_api.h"
22#include <stdint.h>
23
24
25
26/**
27 * List of instances.
28 */
29typedef enum dt_otbn {
30 kDtOtbn = 0, /**< otbn */
31 kDtOtbnFirst = 0, /**< \internal First instance */
32 kDtOtbnCount = 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_otbn_reg_block {
41 kDtOtbnRegBlockCore = 0, /**< */
42 kDtOtbnRegBlockCount = 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_otbn_reg_block_t kDtOtbnRegBlockPrimary = kDtOtbnRegBlockCore;
47
48/**
49 * List of memories.
50 *
51 * Memories are guaranteed to start at 0 and to be consecutively numbered.
52 */
53typedef enum dt_otbn_memory {
54 kDtOtbnMemoryCount = 0, /**< \internal Number of memories */
56
57/**
58 * List of IRQs.
59 *
60 * IRQs are guaranteed to be numbered consecutively from 0.
61 */
62typedef enum dt_otbn_irq {
63 kDtOtbnIrqDone = 0, /**< OTBN has completed the operation. */
64 kDtOtbnIrqCount = 1, /**< \internal Number of IRQs */
66
67/**
68 * List of Alerts.
69 *
70 * Alerts are guaranteed to be numbered consecutively from 0.
71 */
72typedef enum dt_otbn_alert {
73 kDtOtbnAlertFatal = 0, /**< A fatal error. Fatal alerts are non-recoverable and will be asserted until a hard reset. */
74 kDtOtbnAlertRecov = 1, /**< A recoverable error. Just sent once (as the processor stops). */
75 kDtOtbnAlertCount = 2, /**< \internal Number of Alerts */
77
78/**
79 * List of clock ports.
80 *
81 * Clock ports are guaranteed to be numbered consecutively from 0.
82 */
83typedef enum dt_otbn_clock {
84 kDtOtbnClockClk = 0, /**< Clock port clk_i */
85 kDtOtbnClockEdn = 1, /**< Clock port clk_edn_i */
86 kDtOtbnClockOtp = 2, /**< Clock port clk_otp_i */
87 kDtOtbnClockCount = 3, /**< \internal Number of clock ports */
89
90/**
91 * List of reset ports.
92 *
93 * Reset ports are guaranteed to be numbered consecutively from 0.
94 */
95typedef enum dt_otbn_reset {
96 kDtOtbnResetRst = 0, /**< Reset port rst_ni */
97 kDtOtbnResetEdn = 1, /**< Reset port rst_edn_ni */
98 kDtOtbnResetOtp = 2, /**< Reset port rst_otp_ni */
99 kDtOtbnResetCount = 3, /**< \internal Number of reset ports */
101
102/**
103 * List of supported hardware features.
104 */
105#define OPENTITAN_OTBN_HAS_MEM_SCRAMBLE 1
106
107
108
109/**
110 * Get the otbn instance from an instance ID
111 *
112 * For example, `dt_uart_from_instance_id(kDtInstanceIdUart3) == kDtUart3`.
113 *
114 * @param inst_id Instance ID.
115 * @return A otbn instance.
116 *
117 * **Note:** This function only makes sense if the instance ID has device type otbn,
118 * otherwise the returned value is unspecified.
119 */
121
122/**
123 * Get the instance ID of an instance.
124 *
125 * @param dt Instance of otbn.
126 * @return The instance ID of that instance.
127 */
129
130/**
131 * Get the register base address of an instance.
132 *
133 * @param dt Instance of otbn.
134 * @param reg_block The register block requested.
135 * @return The register base address of the requested block.
136 */
137uint32_t dt_otbn_reg_block(
138 dt_otbn_t dt,
139 dt_otbn_reg_block_t reg_block);
140
141/**
142 * Get the primary register base address of an instance.
143 *
144 * This is just a convenience function, equivalent to
145 * `dt_otbn_reg_block(dt, kDtOtbnRegBlockCore)`
146 *
147 * @param dt Instance of otbn.
148 * @return The register base address of the primary register block.
149 */
150static inline uint32_t dt_otbn_primary_reg_block(
151 dt_otbn_t dt) {
152 return dt_otbn_reg_block(dt, kDtOtbnRegBlockCore);
153}
154
155/**
156 * Get the base address of a memory.
157 *
158 * @param dt Instance of otbn.
159 * @param mem The memory requested.
160 * @return The base address of the requested memory.
161 */
162uint32_t dt_otbn_memory_base(
163 dt_otbn_t dt,
164 dt_otbn_memory_t mem);
165
166/**
167 * Get the size of a memory.
168 *
169 * @param dt Instance of otbn.
170 * @param mem The memory requested.
171 * @return The size of the requested memory.
172 */
173uint32_t dt_otbn_memory_size(
174 dt_otbn_t dt,
175 dt_otbn_memory_t mem);
176
177/**
178 * Get the PLIC ID of a otbn 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 otbn.
184 * @param irq A otbn IRQ.
185 * @return The PLIC ID of the IRQ of this instance.
186 */
188 dt_otbn_t dt,
189 dt_otbn_irq_t irq);
190
191/**
192 * Convert a global IRQ ID to a local otbn IRQ type.
193 *
194 * @param dt Instance of otbn.
195 * @param irq A PLIC ID that belongs to this instance.
196 * @return The otbn IRQ, or `kDtOtbnIrqCount`.
197 *
198 * **Note:** This function assumes that the PLIC ID belongs to the instance
199 * of otbn passed in parameter. In other words, it must be the case that
200 * `dt_otbn_instance_id(dt) == dt_plic_id_to_instance_id(irq)`. Otherwise, this function
201 * will return `kDtOtbnIrqCount`.
202 */
204 dt_otbn_t dt,
205 dt_plic_irq_id_t irq);
206
207
208/**
209 * Get the alert ID of a otbn 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 otbn.
215 * @param alert A otbn alert.
216 * @return The Alert Handler alert ID of the alert of this instance.
217 */
219 dt_otbn_t dt,
220 dt_otbn_alert_t alert);
221
222/**
223 * Convert a global alert ID to a local otbn alert type.
224 *
225 * @param dt Instance of otbn.
226 * @param alert A global alert ID that belongs to this instance.
227 * @return The otbn alert, or `kDtOtbnAlertCount`.
228 *
229 * **Note:** This function assumes that the global alert ID belongs to the
230 * instance of otbn passed in parameter. In other words, it must be the case
231 * that `dt_otbn_instance_id(dt) == dt_alert_id_to_instance_id(alert)`. Otherwise,
232 * this function will return `kDtOtbnAlertCount`.
233 */
235 dt_otbn_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 otbn.
244 * @param clk Clock port.
245 * @return Clock signal.
246 */
248 dt_otbn_t dt,
249 dt_otbn_clock_t clk);
250
251/**
252 * Get the reset signal connected to a reset port of an instance.
253 *
254 * @param dt Instance of otbn.
255 * @param rst Reset port.
256 * @return Reset signal.
257 */
259 dt_otbn_t dt,
260 dt_otbn_reset_t rst);
261
262
263
264#ifdef __cplusplus
265} // extern "C"
266#endif // __cplusplus
267
268#endif // OPENTITAN_DT_OTBN_H_