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