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