Software APIs
dif_kmac_autogen.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
6
7#ifndef OPENTITAN_SW_DEVICE_LIB_DIF_AUTOGEN_DIF_KMAC_AUTOGEN_H_
8#define OPENTITAN_SW_DEVICE_LIB_DIF_AUTOGEN_DIF_KMAC_AUTOGEN_H_
9
10// THIS FILE HAS BEEN GENERATED, DO NOT EDIT MANUALLY. COMMAND:
11// util/autogen_dif.py -i hw/ip/kmac/data/kmac.hjson -o
12// bazel-out/k8-fastbuild/bin/sw/device/lib/dif/autogen
13
14
15/**
16 * @file
17 * @brief <a href="/book/hw/ip/kmac/">KMAC</a> Device Interface Functions
18 */
19
20#include <stdbool.h>
21#include <stdint.h>
22
26#include "hw/top/dt/kmac.h" // Generated.
27
28#ifdef __cplusplus
29extern "C" {
30#endif // __cplusplus
31
32/**
33 * A handle to kmac.
34 *
35 * This type should be treated as opaque by users.
36 */
37typedef struct dif_kmac {
38 /**
39 * The base address for the kmac hardware registers.
40 */
42 /**
43 * The instance, set to `kDtKmacCount` if not initialized
44 * through `dif_kmac_init_from_dt`.
45 */
48
49/**
50 * Creates a new handle for a(n) kmac peripheral.
51 *
52 * This function does not actuate the hardware.
53 *
54 * @param base_addr The MMIO base address of the kmac peripheral.
55 * @param[out] kmac Out param for the initialized handle.
56 * @return The result of the operation.
57 *
58 * DEPRECATED This function exists solely for the transition to
59 * dt-based DIFs and will be removed in the future.
60 */
63 mmio_region_t base_addr,
64 dif_kmac_t *kmac);
65
66/**
67 * Creates a new handle for a(n) kmac peripheral.
68 *
69 * This function does not actuate the hardware.
70 *
71 * @param dt The devicetable description of the device.
72 * @param[out] kmac Out param for the initialized handle.
73 * @return The result of the operation.
74 */
77 dt_kmac_t dt,
78 dif_kmac_t *kmac);
79
80/**
81 * Get the DT handle from this DIF.
82 *
83 * If this DIF was initialized by `dif_kmac_init_from_dt(dt, ..)`
84 * then this function will return `dt`. Otherwise it will return an error.
85 *
86 * @param kmac A kmac handle.
87 * @param[out] dt DT handle.
88 * @return `kDifBadArg` if the DIF has no DT information, `kDifOk` otherwise.
89 */
92 const dif_kmac_t *kmac,
93 dt_kmac_t *dt);
94
95 /**
96 * A kmac alert type.
97 */
98 typedef enum dif_kmac_alert {
99 /**
100 * Alert for KMAC operation error. It occurs when the shadow registers have update errors.
101 */
103 /**
104 * This fatal alert is triggered when a fatal error is detected inside the KMAC unit. Examples for such faults include: i) TL-UL bus integrity fault. ii) Storage errors in the shadow registers. iii) Errors in the message, round, or key counter. iv) Any internal FSM entering an invalid state. v) An error in the redundant lfsr. The KMAC unit cannot recover from such an error and needs to be reset.
105 */
108
109 /**
110 * Forces a particular alert, causing it to be escalated as if the hardware
111 * had raised it.
112 *
113 * @param kmac A kmac handle.
114 * @param alert The alert to force.
115 * @return The result of the operation.
116 */
119 const dif_kmac_t *kmac,
120 dif_kmac_alert_t alert);
121
122 // DEPRECATED This typedef exists solely for the transition to
123 // dt-based interrupt numbers and will be removed in the future.
124 typedef dt_kmac_irq_t dif_kmac_irq_t;
125
126 /**
127 * A kmac interrupt request type.
128 *
129 * DEPRECATED Use `dt_kmac_irq_t` instead.
130 * This enumeration exists solely for the transition to
131 * dt-based interrupt numbers and will be removed in the future.
132 *
133 * The following are defines to keep the types consistent with DT.
134 */
135 /**
136 * KMAC/SHA3 absorbing has been completed
137 */
138#define kDifKmacIrqKmacDone kDtKmacIrqKmacDone
139 /**
140 * The message FIFO is empty. This interrupt is raised only if the message FIFO is actually writable by software, i.e., if all of the following conditions are met: i) The KMAC block is not exercised by a hardware application interface. ii) The SHA3 block is in the Absorb state. iii) Software has not yet written the Process command to finish the absorption process. For the interrupt to be raised, the message FIFO must also have been full previously. 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.
141 */
142#define kDifKmacIrqFifoEmpty kDtKmacIrqFifoEmpty
143 /**
144 * KMAC/SHA3 error occurred. ERR_CODE register shows the details
145 */
146#define kDifKmacIrqKmacErr kDtKmacIrqKmacErr
147
148 /**
149 * A snapshot of the state of the interrupts for this IP.
150 *
151 * This is an opaque type, to be used with the `dif_kmac_irq_get_state()`
152 * and `dif_kmac_irq_acknowledge_state()` functions.
153 */
155
156 /**
157 * Returns the type of a given interrupt (i.e., event or status) for this IP.
158 *
159 * @param kmac A kmac handle.
160 * @param irq An interrupt request.
161 * @param[out] type Out-param for the interrupt type.
162 * @return The result of the operation.
163 */
166 const dif_kmac_t *kmac,
167 dif_kmac_irq_t,
168 dif_irq_type_t *type);
169
170 /**
171 * Returns the state of all interrupts (i.e., pending or not) for this IP.
172 *
173 * @param kmac A kmac handle.
174 * @param[out] snapshot Out-param for interrupt state snapshot.
175 * @return The result of the operation.
176 */
179 const dif_kmac_t *kmac,
181
182 /**
183 * Returns whether a particular interrupt is currently pending.
184 *
185 * @param kmac A kmac handle.
186 * @param irq An interrupt request.
187 * @param[out] is_pending Out-param for whether the interrupt is pending.
188 * @return The result of the operation.
189 */
192 const dif_kmac_t *kmac,
193 dif_kmac_irq_t,
194 bool *is_pending);
195
196 /**
197 * Acknowledges all interrupts that were pending at the time of the state
198 * snapshot.
199 *
200 * @param kmac A kmac handle.
201 * @param snapshot Interrupt state snapshot.
202 * @return The result of the operation.
203 */
206 const dif_kmac_t *kmac,
208
209 /**
210 * Acknowledges all interrupts, indicating to the hardware that all
211 * interrupts have been successfully serviced.
212 *
213 * @param kmac A kmac handle.
214 * @return The result of the operation.
215 */
218 const dif_kmac_t *kmac
219 );
220
221 /**
222 * Acknowledges a particular interrupt, indicating to the hardware that it has
223 * been successfully serviced.
224 *
225 * @param kmac A kmac handle.
226 * @param irq An interrupt request.
227 * @return The result of the operation.
228 */
231 const dif_kmac_t *kmac,
232 dif_kmac_irq_t);
233
234 /**
235 * Forces a particular interrupt, causing it to be serviced as if hardware had
236 * asserted it.
237 *
238 * @param kmac A kmac handle.
239 * @param irq An interrupt request.
240 * @param val Value to be set.
241 * @return The result of the operation.
242 */
245 const dif_kmac_t *kmac,
246 dif_kmac_irq_t,
247 const bool val);
248
249 /**
250 * A snapshot of the enablement state of the interrupts for this IP.
251 *
252 * This is an opaque type, to be used with the
253 * `dif_kmac_irq_disable_all()` and `dif_kmac_irq_restore_all()`
254 * functions.
255 */
257
258 /**
259 * Checks whether a particular interrupt is currently enabled or disabled.
260 *
261 * @param kmac A kmac handle.
262 * @param irq An interrupt request.
263 * @param[out] state Out-param toggle state of the interrupt.
264 * @return The result of the operation.
265 */
268 const dif_kmac_t *kmac,
269 dif_kmac_irq_t,
270 dif_toggle_t *state);
271
272 /**
273 * Sets whether a particular interrupt is currently enabled or disabled.
274 *
275 * @param kmac A kmac handle.
276 * @param irq An interrupt request.
277 * @param state The new toggle state for the interrupt.
278 * @return The result of the operation.
279 */
282 const dif_kmac_t *kmac,
283 dif_kmac_irq_t,
284 dif_toggle_t state);
285
286 /**
287 * Disables all interrupts, optionally snapshotting all enable states for later
288 * restoration.
289 *
290 * @param kmac A kmac handle.
291 * @param[out] snapshot Out-param for the snapshot; may be `NULL`.
292 * @return The result of the operation.
293 */
296 const dif_kmac_t *kmac,
298
299 /**
300 * Restores interrupts from the given (enable) snapshot.
301 *
302 * @param kmac A kmac handle.
303 * @param snapshot A snapshot to restore from.
304 * @return The result of the operation.
305 */
308 const dif_kmac_t *kmac,
309 const dif_kmac_irq_enable_snapshot_t *snapshot);
310
311
312#ifdef __cplusplus
313} // extern "C"
314#endif // __cplusplus
315
316#endif // OPENTITAN_SW_DEVICE_LIB_DIF_AUTOGEN_DIF_KMAC_AUTOGEN_H_