Software APIs
dif_spi_device_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_SPI_DEVICE_AUTOGEN_H_
8#define OPENTITAN_SW_DEVICE_LIB_DIF_AUTOGEN_DIF_SPI_DEVICE_AUTOGEN_H_
9
10// THIS FILE HAS BEEN GENERATED, DO NOT EDIT MANUALLY. COMMAND:
11// util/autogen_dif.py -i hw/ip/spi_device/data/spi_device.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/spi_device/">SPI_DEVICE</a> Device Interface Functions
18 */
19
20#include <stdbool.h>
21#include <stdint.h>
22
26#include "hw/top/dt/spi_device.h" // Generated.
27
28#ifdef __cplusplus
29extern "C" {
30#endif // __cplusplus
31
32/**
33 * A handle to spi_device.
34 *
35 * This type should be treated as opaque by users.
36 */
37typedef struct dif_spi_device {
38 /**
39 * The base address for the spi_device hardware registers.
40 */
42 /**
43 * The instance, set to `kDtSpiDeviceCount` if not initialized
44 * through `dif_spi_device_init_from_dt`.
45 */
48
49/**
50 * Creates a new handle for a(n) spi_device peripheral.
51 *
52 * This function does not actuate the hardware.
53 *
54 * @param base_addr The MMIO base address of the spi_device peripheral.
55 * @param[out] spi_device 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_spi_device_t *spi_device);
65
66/**
67 * Creates a new handle for a(n) spi_device peripheral.
68 *
69 * This function does not actuate the hardware.
70 *
71 * @param dt The devicetable description of the device.
72 * @param[out] spi_device Out param for the initialized handle.
73 * @return The result of the operation.
74 */
78 dif_spi_device_t *spi_device);
79
80/**
81 * Get the DT handle from this DIF.
82 *
83 * If this DIF was initialized by `dif_spi_device_init_from_dt(dt, ..)`
84 * then this function will return `dt`. Otherwise it will return an error.
85 *
86 * @param spi_device A spi_device handle.
87 * @param[out] dt DT handle.
88 * @return `kDifBadArg` if the DIF has no DT information, `kDifOk` otherwise.
89 */
92 const dif_spi_device_t *spi_device,
93 dt_spi_device_t *dt);
94
95 /**
96 * A spi_device alert type.
97 */
98 typedef enum dif_spi_device_alert {
99 /**
100 * This fatal alert is triggered when a fatal TL-UL bus integrity fault is detected.
101 */
104
105 /**
106 * Forces a particular alert, causing it to be escalated as if the hardware
107 * had raised it.
108 *
109 * @param spi_device A spi_device handle.
110 * @param alert The alert to force.
111 * @return The result of the operation.
112 */
115 const dif_spi_device_t *spi_device,
117
118 // DEPRECATED This typedef exists solely for the transition to
119 // dt-based interrupt numbers and will be removed in the future.
120 typedef dt_spi_device_irq_t dif_spi_device_irq_t;
121
122 /**
123 * A spi_device interrupt request type.
124 *
125 * DEPRECATED Use `dt_spi_device_irq_t` instead.
126 * This enumeration exists solely for the transition to
127 * dt-based interrupt numbers and will be removed in the future.
128 *
129 * The following are defines to keep the types consistent with DT.
130 */
131 /**
132 * Upload Command FIFO is not empty.
133 */
134#define kDifSpiDeviceIrqUploadCmdfifoNotEmpty kDtSpiDeviceIrqUploadCmdfifoNotEmpty
135 /**
136 * Upload payload is not empty. The event occurs after a SPI transaction is completed.
137 */
138#define kDifSpiDeviceIrqUploadPayloadNotEmpty kDtSpiDeviceIrqUploadPayloadNotEmpty
139 /**
140 * Upload payload overflow event. When a SPI Host system issues a command with payload more than 256B, this event is reported. When it happens, SW should read the last written payload index CSR to figure out the starting address of the last 256B.
141 */
142#define kDifSpiDeviceIrqUploadPayloadOverflow kDtSpiDeviceIrqUploadPayloadOverflow
143 /**
144 * Read Buffer Threshold event. The host system accesses greater than or equal to the threshold of a buffer.
145 */
146#define kDifSpiDeviceIrqReadbufWatermark kDtSpiDeviceIrqReadbufWatermark
147 /**
148 * Read buffer flipped event. The host system accesses other side of buffer.
149 */
150#define kDifSpiDeviceIrqReadbufFlip kDtSpiDeviceIrqReadbufFlip
151 /**
152 * TPM Header(Command/Address) buffer available
153 */
154#define kDifSpiDeviceIrqTpmHeaderNotEmpty kDtSpiDeviceIrqTpmHeaderNotEmpty
155 /**
156 * TPM RdFIFO command ended. The TPM Read command targeting the RdFIFO ended. Check TPM_STATUS.rdfifo_aborted to see if the transaction completed.
157 */
158#define kDifSpiDeviceIrqTpmRdfifoCmdEnd kDtSpiDeviceIrqTpmRdfifoCmdEnd
159 /**
160 * TPM RdFIFO data dropped. Data was dropped from the RdFIFO. Data was written while a read command was not active, and it was not accepted. This can occur when the host aborts a read command.
161 */
162#define kDifSpiDeviceIrqTpmRdfifoDrop kDtSpiDeviceIrqTpmRdfifoDrop
163
164 /**
165 * A snapshot of the state of the interrupts for this IP.
166 *
167 * This is an opaque type, to be used with the `dif_spi_device_irq_get_state()`
168 * and `dif_spi_device_irq_acknowledge_state()` functions.
169 */
171
172 /**
173 * Returns the type of a given interrupt (i.e., event or status) for this IP.
174 *
175 * @param spi_device A spi_device handle.
176 * @param irq An interrupt request.
177 * @param[out] type Out-param for the interrupt type.
178 * @return The result of the operation.
179 */
182 const dif_spi_device_t *spi_device,
183 dif_spi_device_irq_t,
184 dif_irq_type_t *type);
185
186 /**
187 * Returns the state of all interrupts (i.e., pending or not) for this IP.
188 *
189 * @param spi_device A spi_device handle.
190 * @param[out] snapshot Out-param for interrupt state snapshot.
191 * @return The result of the operation.
192 */
195 const dif_spi_device_t *spi_device,
197
198 /**
199 * Returns whether a particular interrupt is currently pending.
200 *
201 * @param spi_device A spi_device handle.
202 * @param irq An interrupt request.
203 * @param[out] is_pending Out-param for whether the interrupt is pending.
204 * @return The result of the operation.
205 */
208 const dif_spi_device_t *spi_device,
209 dif_spi_device_irq_t,
210 bool *is_pending);
211
212 /**
213 * Acknowledges all interrupts that were pending at the time of the state
214 * snapshot.
215 *
216 * @param spi_device A spi_device handle.
217 * @param snapshot Interrupt state snapshot.
218 * @return The result of the operation.
219 */
222 const dif_spi_device_t *spi_device,
224
225 /**
226 * Acknowledges all interrupts, indicating to the hardware that all
227 * interrupts have been successfully serviced.
228 *
229 * @param spi_device A spi_device handle.
230 * @return The result of the operation.
231 */
234 const dif_spi_device_t *spi_device
235 );
236
237 /**
238 * Acknowledges a particular interrupt, indicating to the hardware that it has
239 * been successfully serviced.
240 *
241 * @param spi_device A spi_device handle.
242 * @param irq An interrupt request.
243 * @return The result of the operation.
244 */
247 const dif_spi_device_t *spi_device,
248 dif_spi_device_irq_t);
249
250 /**
251 * Forces a particular interrupt, causing it to be serviced as if hardware had
252 * asserted it.
253 *
254 * @param spi_device A spi_device handle.
255 * @param irq An interrupt request.
256 * @param val Value to be set.
257 * @return The result of the operation.
258 */
261 const dif_spi_device_t *spi_device,
262 dif_spi_device_irq_t,
263 const bool val);
264
265 /**
266 * A snapshot of the enablement state of the interrupts for this IP.
267 *
268 * This is an opaque type, to be used with the
269 * `dif_spi_device_irq_disable_all()` and `dif_spi_device_irq_restore_all()`
270 * functions.
271 */
273
274 /**
275 * Checks whether a particular interrupt is currently enabled or disabled.
276 *
277 * @param spi_device A spi_device handle.
278 * @param irq An interrupt request.
279 * @param[out] state Out-param toggle state of the interrupt.
280 * @return The result of the operation.
281 */
284 const dif_spi_device_t *spi_device,
285 dif_spi_device_irq_t,
286 dif_toggle_t *state);
287
288 /**
289 * Sets whether a particular interrupt is currently enabled or disabled.
290 *
291 * @param spi_device A spi_device handle.
292 * @param irq An interrupt request.
293 * @param state The new toggle state for the interrupt.
294 * @return The result of the operation.
295 */
298 const dif_spi_device_t *spi_device,
299 dif_spi_device_irq_t,
300 dif_toggle_t state);
301
302 /**
303 * Disables all interrupts, optionally snapshotting all enable states for later
304 * restoration.
305 *
306 * @param spi_device A spi_device handle.
307 * @param[out] snapshot Out-param for the snapshot; may be `NULL`.
308 * @return The result of the operation.
309 */
312 const dif_spi_device_t *spi_device,
314
315 /**
316 * Restores interrupts from the given (enable) snapshot.
317 *
318 * @param spi_device A spi_device handle.
319 * @param snapshot A snapshot to restore from.
320 * @return The result of the operation.
321 */
324 const dif_spi_device_t *spi_device,
326
327
328#ifdef __cplusplus
329} // extern "C"
330#endif // __cplusplus
331
332#endif // OPENTITAN_SW_DEVICE_LIB_DIF_AUTOGEN_DIF_SPI_DEVICE_AUTOGEN_H_