Software APIs
dt_hmac.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_HMAC_H_
8#define OPENTITAN_DT_HMAC_H_
9
10#ifdef __cplusplus
11extern "C" {
12#endif // __cplusplus
13
14/**
15 * @file
16 * @brief Device Tables (DT) for IP hmac and top darjeeling.
17 *
18 * This file contains the type definitions and global functions of the hmac.
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_hmac {
30 kDtHmac = 0, /**< hmac */
31 kDtHmacFirst = 0, /**< \internal First instance */
32 kDtHmacCount = 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_hmac_reg_block {
41 kDtHmacRegBlockCore = 0, /**< */
42 kDtHmacRegBlockCount = 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_hmac_reg_block_t kDtHmacRegBlockPrimary = kDtHmacRegBlockCore;
47
48/**
49 * List of memories.
50 *
51 * Memories are guaranteed to start at 0 and to be consecutively numbered.
52 */
53typedef enum dt_hmac_memory {
54 kDtHmacMemoryCount = 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_hmac_irq {
63 kDtHmacIrqHmacDone = 0, /**< HMAC/SHA-2 has completed. */
64 kDtHmacIrqFifoEmpty = 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 HMAC block is not running in HMAC mode and performing the second round of computing the final hash of the outer key as well as the result of the first round using the inner key.
67ii) Software has not yet written the Process or Stop command to finish the hashing operation.
68For the interrupt to be raised, the message FIFO must also have been full previously.
69Otherwise, 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 kDtHmacIrqHmacErr = 2, /**< HMAC error has occurred. ERR_CODE register shows which error occurred. */
71 kDtHmacIrqCount = 3, /**< \internal Number of IRQs */
73
74/**
75 * List of Alerts.
76 *
77 * Alerts are guaranteed to be numbered consecutively from 0.
78 */
79typedef enum dt_hmac_alert {
80 kDtHmacAlertFatalFault = 0, /**< This fatal alert is triggered when a fatal TL-UL bus integrity fault is detected. */
81 kDtHmacAlertCount = 1, /**< \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_hmac_clock {
90 kDtHmacClockClk = 0, /**< Clock port clk_i */
91 kDtHmacClockCount = 1, /**< \internal Number of clock ports */
93
94/**
95 * List of reset ports.
96 *
97 * Reset ports are guaranteed to be numbered consecutively from 0.
98 */
99typedef enum dt_hmac_reset {
100 kDtHmacResetRst = 0, /**< Reset port rst_ni */
101 kDtHmacResetCount = 1, /**< \internal Number of reset ports */
103
104/**
105 * List of supported hardware features.
106 */
107#define OPENTITAN_HMAC_HAS_MODE_SHA2 1
108#define OPENTITAN_HMAC_HAS_MODE_HMAC 1
109#define OPENTITAN_HMAC_HAS_DIGEST_SIZE_SHA2_256 1
110#define OPENTITAN_HMAC_HAS_DIGEST_SIZE_SHA2_384 1
111#define OPENTITAN_HMAC_HAS_DIGEST_SIZE_SHA2_512 1
112#define OPENTITAN_HMAC_HAS_KEY_LENGTH_KEY_128 1
113#define OPENTITAN_HMAC_HAS_KEY_LENGTH_KEY_256 1
114#define OPENTITAN_HMAC_HAS_KEY_LENGTH_KEY_384 1
115#define OPENTITAN_HMAC_HAS_KEY_LENGTH_KEY_512 1
116#define OPENTITAN_HMAC_HAS_KEY_LENGTH_KEY_1024 1
117#define OPENTITAN_HMAC_HAS_ENDIANNESS_MESSAGE 1
118#define OPENTITAN_HMAC_HAS_ENDIANNESS_DIGEST 1
119#define OPENTITAN_HMAC_HAS_SECURE_WIPE 1
120
121
122
123/**
124 * Get the hmac instance from an instance ID
125 *
126 * For example, `dt_uart_from_instance_id(kDtInstanceIdUart3) == kDtUart3`.
127 *
128 * @param inst_id Instance ID.
129 * @return A hmac instance.
130 *
131 * **Note:** This function only makes sense if the instance ID has device type hmac,
132 * otherwise the returned value is unspecified.
133 */
135
136/**
137 * Get the instance ID of an instance.
138 *
139 * @param dt Instance of hmac.
140 * @return The instance ID of that instance.
141 */
143
144/**
145 * Get the register base address of an instance.
146 *
147 * @param dt Instance of hmac.
148 * @param reg_block The register block requested.
149 * @return The register base address of the requested block.
150 */
151uint32_t dt_hmac_reg_block(
152 dt_hmac_t dt,
153 dt_hmac_reg_block_t reg_block);
154
155/**
156 * Get the primary register base address of an instance.
157 *
158 * This is just a convenience function, equivalent to
159 * `dt_hmac_reg_block(dt, kDtHmacRegBlockCore)`
160 *
161 * @param dt Instance of hmac.
162 * @return The register base address of the primary register block.
163 */
164static inline uint32_t dt_hmac_primary_reg_block(
165 dt_hmac_t dt) {
166 return dt_hmac_reg_block(dt, kDtHmacRegBlockCore);
167}
168
169/**
170 * Get the base address of a memory.
171 *
172 * @param dt Instance of hmac.
173 * @param mem The memory requested.
174 * @return The base address of the requested memory.
175 */
176uint32_t dt_hmac_memory_base(
177 dt_hmac_t dt,
178 dt_hmac_memory_t mem);
179
180/**
181 * Get the size of a memory.
182 *
183 * @param dt Instance of hmac.
184 * @param mem The memory requested.
185 * @return The size of the requested memory.
186 */
187uint32_t dt_hmac_memory_size(
188 dt_hmac_t dt,
189 dt_hmac_memory_t mem);
190
191/**
192 * Get the PLIC ID of a hmac 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 hmac.
198 * @param irq A hmac IRQ.
199 * @return The PLIC ID of the IRQ of this instance.
200 */
202 dt_hmac_t dt,
203 dt_hmac_irq_t irq);
204
205/**
206 * Convert a global IRQ ID to a local hmac IRQ type.
207 *
208 * @param dt Instance of hmac.
209 * @param irq A PLIC ID that belongs to this instance.
210 * @return The hmac IRQ, or `kDtHmacIrqCount`.
211 *
212 * **Note:** This function assumes that the PLIC ID belongs to the instance
213 * of hmac passed in parameter. In other words, it must be the case that
214 * `dt_hmac_instance_id(dt) == dt_plic_id_to_instance_id(irq)`. Otherwise, this function
215 * will return `kDtHmacIrqCount`.
216 */
218 dt_hmac_t dt,
219 dt_plic_irq_id_t irq);
220
221
222/**
223 * Get the alert ID of a hmac 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 hmac.
229 * @param alert A hmac alert.
230 * @return The Alert Handler alert ID of the alert of this instance.
231 */
233 dt_hmac_t dt,
234 dt_hmac_alert_t alert);
235
236/**
237 * Convert a global alert ID to a local hmac alert type.
238 *
239 * @param dt Instance of hmac.
240 * @param alert A global alert ID that belongs to this instance.
241 * @return The hmac alert, or `kDtHmacAlertCount`.
242 *
243 * **Note:** This function assumes that the global alert ID belongs to the
244 * instance of hmac passed in parameter. In other words, it must be the case
245 * that `dt_hmac_instance_id(dt) == dt_alert_id_to_instance_id(alert)`. Otherwise,
246 * this function will return `kDtHmacAlertCount`.
247 */
249 dt_hmac_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 hmac.
258 * @param clk Clock port.
259 * @return Clock signal.
260 */
262 dt_hmac_t dt,
263 dt_hmac_clock_t clk);
264
265/**
266 * Get the reset signal connected to a reset port of an instance.
267 *
268 * @param dt Instance of hmac.
269 * @param rst Reset port.
270 * @return Reset signal.
271 */
273 dt_hmac_t dt,
274 dt_hmac_reset_t rst);
275
276
277
278#ifdef __cplusplus
279} // extern "C"
280#endif // __cplusplus
281
282#endif // OPENTITAN_DT_HMAC_H_