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/**
11 * @file
12 * @brief Device Tables (DT) for IP hmac and top earlgrey.
13 *
14 * This file contains the type definitions and global functions of the hmac.
15 */
16
17#include "dt_api.h"
18#include <stdint.h>
19
20/**
21 * List of instances.
22 */
23typedef enum dt_hmac {
24 kDtHmac = 0, /**< hmac */
25 kDtHmacFirst = 0, /**< \internal First instance */
26 kDtHmacCount = 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_hmac_reg_block {
35 kDtHmacRegBlockCore = 0, /**< */
36 kDtHmacRegBlockCount = 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_hmac_reg_block_t kDtHmacRegBlockPrimary = kDtHmacRegBlockCore;
41
42/**
43 * List of IRQs.
44 *
45 * IRQs are guaranteed to be numbered consecutively from 0.
46 */
47typedef enum dt_hmac_irq {
48 kDtHmacIrqHmacDone = 0, /**< HMAC/SHA-2 has completed. */
49 kDtHmacIrqFifoEmpty = 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 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.
52ii) Software has not yet written the Process or Stop command to finish the hashing operation.
53For the interrupt to be raised, the message FIFO must also have been full previously.
54Otherwise, 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. */
55 kDtHmacIrqHmacErr = 2, /**< HMAC error has occurred. ERR_CODE register shows which error occurred. */
56 kDtHmacIrqCount = 3, /**< \internal Number of IRQs */
58
59/**
60 * List of Alerts.
61 *
62 * Alerts are guaranteed to be numbered consecutively from 0.
63 */
64typedef enum dt_hmac_alert {
65 kDtHmacAlertFatalFault = 0, /**< This fatal alert is triggered when a fatal TL-UL bus integrity fault is detected. */
66 kDtHmacAlertCount = 1, /**< \internal Number of Alerts */
68
69/**
70 * List of clock ports.
71 *
72 * Clock ports are guaranteed to be numbered consecutively from 0.
73 */
74typedef enum dt_hmac_clock {
75 kDtHmacClockClk = 0, /**< Clock port clk_i */
76 kDtHmacClockCount = 1, /**< \internal Number of clock ports */
78
79/**
80 * List of reset ports.
81 *
82 * Reset ports are guaranteed to be numbered consecutively from 0.
83 */
84typedef enum dt_hmac_reset {
85 kDtHmacResetRst = 0, /**< Reset port rst_ni */
86 kDtHmacResetCount = 1, /**< \internal Number of reset ports */
88
89/**
90 * List of supported hardware features.
91 */
92#define OPENTITAN_HMAC_HAS_MODE_SHA2 1
93#define OPENTITAN_HMAC_HAS_MODE_HMAC 1
94#define OPENTITAN_HMAC_HAS_DIGEST_SIZE_SHA2_256 1
95#define OPENTITAN_HMAC_HAS_DIGEST_SIZE_SHA2_384 1
96#define OPENTITAN_HMAC_HAS_DIGEST_SIZE_SHA2_512 1
97#define OPENTITAN_HMAC_HAS_KEY_LENGTH_KEY_128 1
98#define OPENTITAN_HMAC_HAS_KEY_LENGTH_KEY_256 1
99#define OPENTITAN_HMAC_HAS_KEY_LENGTH_KEY_384 1
100#define OPENTITAN_HMAC_HAS_KEY_LENGTH_KEY_512 1
101#define OPENTITAN_HMAC_HAS_KEY_LENGTH_KEY_1024 1
102#define OPENTITAN_HMAC_HAS_ENDIANNESS_MESSAGE 1
103#define OPENTITAN_HMAC_HAS_ENDIANNESS_DIGEST 1
104#define OPENTITAN_HMAC_HAS_SECURE_WIPE 1
105
106
107
108/**
109 * Get the hmac instance from an instance ID
110 *
111 * For example, `dt_uart_from_instance_id(kDtInstanceIdUart3) == kDtUart3`.
112 *
113 * @param inst_id Instance ID.
114 * @return A hmac instance.
115 *
116 * **Note:** This function only makes sense if the instance ID has device type hmac,
117 * otherwise the returned value is unspecified.
118 */
120
121/**
122 * Get the instance ID of an instance.
123 *
124 * @param dt Instance of hmac.
125 * @return The instance ID of that instance.
126 */
128
129/**
130 * Get the register base address of an instance.
131 *
132 * @param dt Instance of hmac.
133 * @param reg_block The register block requested.
134 * @return The register base address of the requested block.
135 */
136uint32_t dt_hmac_reg_block(
137 dt_hmac_t dt,
138 dt_hmac_reg_block_t reg_block);
139
140/**
141 * Get the primary register base address of an instance.
142 *
143 * This is just a convenience function, equivalent to
144 * `dt_hmac_reg_block(dt, kDtHmacRegBlockCore)`
145 *
146 * @param dt Instance of hmac.
147 * @return The register base address of the primary register block.
148 */
149static inline uint32_t dt_hmac_primary_reg_block(
150 dt_hmac_t dt) {
151 return dt_hmac_reg_block(dt, kDtHmacRegBlockCore);
152}
153
154/**
155 * Get the PLIC ID of a hmac IRQ for a given instance.
156 *
157 * If the instance is not connected to the PLIC, this function
158 * will return `kDtPlicIrqIdNone`.
159 *
160 * @param dt Instance of hmac.
161 * @param irq A hmac IRQ.
162 * @return The PLIC ID of the IRQ of this instance.
163 */
165 dt_hmac_t dt,
166 dt_hmac_irq_t irq);
167
168/**
169 * Convert a global IRQ ID to a local hmac IRQ type.
170 *
171 * @param dt Instance of hmac.
172 * @param irq A PLIC ID that belongs to this instance.
173 * @return The hmac IRQ, or `kDtHmacIrqCount`.
174 *
175 * **Note:** This function assumes that the PLIC ID belongs to the instance
176 * of hmac passed in parameter. In other words, it must be the case that
177 * `dt_hmac_instance_id(dt) == dt_plic_id_to_instance_id(irq)`. Otherwise, this function
178 * will return `kDtHmacIrqCount`.
179 */
181 dt_hmac_t dt,
182 dt_plic_irq_id_t irq);
183
184
185/**
186 * Get the alert ID of a hmac alert for a given instance.
187 *
188 * **Note:** This function only makes sense if the instance is connected to the Alert Handler. For any
189 * instances where the instance is not connected, the return value is unspecified.
190 *
191 * @param dt Instance of hmac.
192 * @param alert A hmac alert.
193 * @return The Alert Handler alert ID of the alert of this instance.
194 */
196 dt_hmac_t dt,
197 dt_hmac_alert_t alert);
198
199/**
200 * Convert a global alert ID to a local hmac alert type.
201 *
202 * @param dt Instance of hmac.
203 * @param alert A global alert ID that belongs to this instance.
204 * @return The hmac alert, or `kDtHmacAlertCount`.
205 *
206 * **Note:** This function assumes that the global alert ID belongs to the
207 * instance of hmac passed in parameter. In other words, it must be the case
208 * that `dt_hmac_instance_id(dt) == dt_alert_id_to_instance_id(alert)`. Otherwise,
209 * this function will return `kDtHmacAlertCount`.
210 */
212 dt_hmac_t dt,
213 dt_alert_id_t alert);
214
215
216
217/**
218 * Get the clock signal connected to a clock port of an instance.
219 *
220 * @param dt Instance of hmac.
221 * @param clk Clock port.
222 * @return Clock signal.
223 */
225 dt_hmac_t dt,
226 dt_hmac_clock_t clk);
227
228/**
229 * Get the reset signal connected to a reset port of an instance.
230 *
231 * @param dt Instance of hmac.
232 * @param rst Reset port.
233 * @return Reset signal.
234 */
236 dt_hmac_t dt,
237 dt_hmac_reset_t rst);
238
239
240
241#endif // OPENTITAN_DT_HMAC_H_