Software APIs
dt_kmac.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_KMAC_H_
8#define OPENTITAN_DT_KMAC_H_
9
10#ifdef __cplusplus
11extern "C" {
12#endif // __cplusplus
13
14/**
15 * @file
16 * @brief Device Tables (DT) for IP kmac and top earlgrey.
17 *
18 * This file contains the type definitions and global functions of the kmac.
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_kmac {
30 kDtKmac = 0, /**< kmac */
31 kDtKmacFirst = 0, /**< \internal First instance */
32 kDtKmacCount = 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_kmac_reg_block {
41 kDtKmacRegBlockCore = 0, /**< */
42 kDtKmacRegBlockCount = 1, /**< \internal Number of register blocks */
44
45/**
46 * List of memories.
47 *
48 * Memories are guaranteed to start at 0 and to be consecutively numbered.
49 */
50typedef enum dt_kmac_memory {
51 kDtKmacMemoryCount = 0, /**< \internal Number of memories */
53
54/** Primary register block (associated with the "primary" set of registers that control the IP). */
55static const dt_kmac_reg_block_t kDtKmacRegBlockPrimary = kDtKmacRegBlockCore;
56
57/**
58 * List of IRQs.
59 *
60 * IRQs are guaranteed to be numbered consecutively from 0.
61 */
62typedef enum dt_kmac_irq {
63 kDtKmacIrqKmacDone = 0, /**< KMAC/SHA3 absorbing has been completed */
64 kDtKmacIrqFifoEmpty = 1, /**< The message FIFO is empty.
65This interrupt is raised only if the message FIFO is actually writable by software, i.e., if all of the following conditions are met:
66i) The KMAC block is not exercised by a hardware application interface.
67ii) The SHA3 block is in the Absorb state.
68iii) Software has not yet written the Process command to finish the absorption process.
69For the interrupt to be raised, the message FIFO must also have been full previously.
70Otherwise, the hardware empties the FIFO faster than software can fill it and there is no point in interrupting the software to inform it about the message FIFO being empty. */
71 kDtKmacIrqKmacErr = 2, /**< KMAC/SHA3 error occurred. ERR_CODE register shows the details */
72 kDtKmacIrqCount = 3, /**< \internal Number of IRQs */
74
75/**
76 * List of Alerts.
77 *
78 * Alerts are guaranteed to be numbered consecutively from 0.
79 */
80typedef enum dt_kmac_alert {
81 kDtKmacAlertRecovOperationErr = 0, /**< Alert for KMAC operation error. It occurs when the shadow registers have update errors. */
82 kDtKmacAlertFatalFaultErr = 1, /**< This fatal alert is triggered when a fatal error is detected inside the KMAC unit.
83Examples for such faults include:
84i) TL-UL bus integrity fault.
85ii) Storage errors in the shadow registers.
86iii) Errors in the message, round, or key counter.
87iv) Any internal FSM entering an invalid state.
88v) An error in the redundant lfsr.
89The KMAC unit cannot recover from such an error and needs to be reset. */
90 kDtKmacAlertCount = 2, /**< \internal Number of Alerts */
92
93/**
94 * List of clock ports.
95 *
96 * Clock ports are guaranteed to be numbered consecutively from 0.
97 */
98typedef enum dt_kmac_clock {
99 kDtKmacClockClk = 0, /**< Clock port clk_i */
100 kDtKmacClockEdn = 1, /**< Clock port clk_edn_i */
101 kDtKmacClockCount = 2, /**< \internal Number of clock ports */
103
104/**
105 * List of reset ports.
106 *
107 * Reset ports are guaranteed to be numbered consecutively from 0.
108 */
109typedef enum dt_kmac_reset {
110 kDtKmacResetRst = 0, /**< Reset port rst_ni */
111 kDtKmacResetEdn = 1, /**< Reset port rst_edn_ni */
112 kDtKmacResetCount = 2, /**< \internal Number of reset ports */
114
115/**
116 * List of supported hardware features.
117 */
118#define OPENTITAN_KMAC_HAS_MODE_SHA3 1
119#define OPENTITAN_KMAC_HAS_MODE_SHAKE 1
120#define OPENTITAN_KMAC_HAS_MODE_CSHAKE 1
121#define OPENTITAN_KMAC_HAS_MODE_KMAC 1
122#define OPENTITAN_KMAC_HAS_MODE_XOF 1
123#define OPENTITAN_KMAC_HAS_ENDIANNESS_MESSAGE 1
124#define OPENTITAN_KMAC_HAS_ENDIANNESS_DIGEST 1
125#define OPENTITAN_KMAC_HAS_KEY_SIDELOAD 1
126#define OPENTITAN_KMAC_HAS_ENTROPY_MODES 1
127
128
129
130/**
131 * Get the kmac instance from an instance ID
132 *
133 * For example, `dt_uart_from_instance_id(kDtInstanceIdUart3) == kDtUart3`.
134 *
135 * @param inst_id Instance ID.
136 * @return A kmac instance.
137 *
138 * **Note:** This function only makes sense if the instance ID has device type kmac,
139 * otherwise the returned value is unspecified.
140 */
142
143/**
144 * Get the instance ID of an instance.
145 *
146 * @param dt Instance of kmac.
147 * @return The instance ID of that instance.
148 */
150
151/**
152 * Get the register base address of an instance.
153 *
154 * @param dt Instance of kmac.
155 * @param reg_block The register block requested.
156 * @return The register base address of the requested block.
157 */
158uint32_t dt_kmac_reg_block(
159 dt_kmac_t dt,
160 dt_kmac_reg_block_t reg_block);
161
162/**
163 * Get the primary register base address of an instance.
164 *
165 * This is just a convenience function, equivalent to
166 * `dt_kmac_reg_block(dt, kDtKmacRegBlockCore)`
167 *
168 * @param dt Instance of kmac.
169 * @return The register base address of the primary register block.
170 */
171static inline uint32_t dt_kmac_primary_reg_block(
172 dt_kmac_t dt) {
173 return dt_kmac_reg_block(dt, kDtKmacRegBlockCore);
174}
175
176/**
177 * Get the base address of a memory.
178 *
179 * @param dt Instance of kmac.
180 * @param mem The memory requested.
181 * @return The base address of the requested memory.
182 */
183uint32_t dt_kmac_memory_base(
184 dt_kmac_t dt,
185 dt_kmac_memory_t mem);
186
187/**
188 * Get the size of a memory.
189 *
190 * @param dt Instance of kmac.
191 * @param mem The memory requested.
192 * @return The size of the requested memory.
193 */
194uint32_t dt_kmac_memory_size(
195 dt_kmac_t dt,
196 dt_kmac_memory_t mem);
197
198/**
199 * Get the PLIC ID of a kmac IRQ for a given instance.
200 *
201 * If the instance is not connected to the PLIC, this function
202 * will return `kDtPlicIrqIdNone`.
203 *
204 * @param dt Instance of kmac.
205 * @param irq A kmac IRQ.
206 * @return The PLIC ID of the IRQ of this instance.
207 */
209 dt_kmac_t dt,
210 dt_kmac_irq_t irq);
211
212/**
213 * Convert a global IRQ ID to a local kmac IRQ type.
214 *
215 * @param dt Instance of kmac.
216 * @param irq A PLIC ID that belongs to this instance.
217 * @return The kmac IRQ, or `kDtKmacIrqCount`.
218 *
219 * **Note:** This function assumes that the PLIC ID belongs to the instance
220 * of kmac passed in parameter. In other words, it must be the case that
221 * `dt_kmac_instance_id(dt) == dt_plic_id_to_instance_id(irq)`. Otherwise, this function
222 * will return `kDtKmacIrqCount`.
223 */
225 dt_kmac_t dt,
226 dt_plic_irq_id_t irq);
227
228
229/**
230 * Get the alert ID of a kmac alert for a given instance.
231 *
232 * **Note:** This function only makes sense if the instance is connected to the Alert Handler. For any
233 * instances where the instance is not connected, the return value is unspecified.
234 *
235 * @param dt Instance of kmac.
236 * @param alert A kmac alert.
237 * @return The Alert Handler alert ID of the alert of this instance.
238 */
240 dt_kmac_t dt,
241 dt_kmac_alert_t alert);
242
243/**
244 * Convert a global alert ID to a local kmac alert type.
245 *
246 * @param dt Instance of kmac.
247 * @param alert A global alert ID that belongs to this instance.
248 * @return The kmac alert, or `kDtKmacAlertCount`.
249 *
250 * **Note:** This function assumes that the global alert ID belongs to the
251 * instance of kmac passed in parameter. In other words, it must be the case
252 * that `dt_kmac_instance_id(dt) == dt_alert_id_to_instance_id(alert)`. Otherwise,
253 * this function will return `kDtKmacAlertCount`.
254 */
256 dt_kmac_t dt,
257 dt_alert_id_t alert);
258
259
260
261/**
262 * Get the clock signal connected to a clock port of an instance.
263 *
264 * @param dt Instance of kmac.
265 * @param clk Clock port.
266 * @return Clock signal.
267 */
269 dt_kmac_t dt,
270 dt_kmac_clock_t clk);
271
272/**
273 * Get the reset signal connected to a reset port of an instance.
274 *
275 * @param dt Instance of kmac.
276 * @param rst Reset port.
277 * @return Reset signal.
278 */
280 dt_kmac_t dt,
281 dt_kmac_reset_t rst);
282
283
284
285#ifdef __cplusplus
286} // extern "C"
287#endif // __cplusplus
288
289#endif // OPENTITAN_DT_KMAC_H_