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