Software APIs
dif_usbdev_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_USBDEV_AUTOGEN_H_
8#define OPENTITAN_SW_DEVICE_LIB_DIF_AUTOGEN_DIF_USBDEV_AUTOGEN_H_
9
10// THIS FILE HAS BEEN GENERATED, DO NOT EDIT MANUALLY. COMMAND:
11// util/autogen_dif.py -i hw/ip/usbdev/data/usbdev.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/usbdev/">USBDEV</a> Device Interface Functions
18 */
19
20#include <stdbool.h>
21#include <stdint.h>
22
26#include "hw/top/dt/usbdev.h" // Generated.
27
28#ifdef __cplusplus
29extern "C" {
30#endif // __cplusplus
31
32/**
33 * A handle to usbdev.
34 *
35 * This type should be treated as opaque by users.
36 */
37typedef struct dif_usbdev {
38 /**
39 * The base address for the usbdev hardware registers.
40 */
42 /**
43 * The instance, set to `kDtUsbdevCount` if not initialized
44 * through `dif_usbdev_init_from_dt`.
45 */
48
49/**
50 * Creates a new handle for a(n) usbdev peripheral.
51 *
52 * This function does not actuate the hardware.
53 *
54 * @param base_addr The MMIO base address of the usbdev peripheral.
55 * @param[out] usbdev 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_usbdev_t *usbdev);
65
66/**
67 * Creates a new handle for a(n) usbdev peripheral.
68 *
69 * This function does not actuate the hardware.
70 *
71 * @param dt The devicetable description of the device.
72 * @param[out] usbdev Out param for the initialized handle.
73 * @return The result of the operation.
74 */
77 dt_usbdev_t dt,
78 dif_usbdev_t *usbdev);
79
80/**
81 * Get the DT handle from this DIF.
82 *
83 * If this DIF was initialized by `dif_usbdev_init_from_dt(dt, ..)`
84 * then this function will return `dt`. Otherwise it will return an error.
85 *
86 * @param usbdev A usbdev handle.
87 * @param[out] dt DT handle.
88 * @return `kDifBadArg` if the DIF has no DT information, `kDifOk` otherwise.
89 */
92 const dif_usbdev_t *usbdev,
93 dt_usbdev_t *dt);
94
95 /**
96 * A usbdev alert type.
97 */
98 typedef enum dif_usbdev_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 usbdev A usbdev handle.
110 * @param alert The alert to force.
111 * @return The result of the operation.
112 */
115 const dif_usbdev_t *usbdev,
116 dif_usbdev_alert_t alert);
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_usbdev_irq_t dif_usbdev_irq_t;
121
122 /**
123 * A usbdev interrupt request type.
124 *
125 * DEPRECATED Use `dt_usbdev_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 * Raised if a packet was received using an OUT or SETUP transaction. This interrupt is directly tied to whether the RX FIFO is empty, so it should be cleared only after handling the FIFO entry.
133 */
134#define kDifUsbdevIrqPktReceived kDtUsbdevIrqPktReceived
135 /**
136 * Raised if a packet was sent as part of an IN transaction. This interrupt is directly tied to whether a sent packet has not been acknowledged in the !!in_sent register. It should be cleared only after clearing all bits in the !!in_sent register.
137 */
138#define kDifUsbdevIrqPktSent kDtUsbdevIrqPktSent
139 /**
140 * Raised if VBUS is lost or the pullup is disabled, thus the link is disconnected.
141 */
142#define kDifUsbdevIrqDisconnected kDtUsbdevIrqDisconnected
143 /**
144 * Raised if link is active but SOF was not received from host for 4.096 ms. The SOF should be every 1 ms.
145 */
146#define kDifUsbdevIrqHostLost kDtUsbdevIrqHostLost
147 /**
148 * Raised if the link is at SE0 longer than 3 us indicating a link reset (host asserts for min 10 ms, device can react after 2.5 us).
149 */
150#define kDifUsbdevIrqLinkReset kDtUsbdevIrqLinkReset
151 /**
152 * Raised if the line has signaled J for longer than 3ms and is therefore in suspend state.
153 */
154#define kDifUsbdevIrqLinkSuspend kDtUsbdevIrqLinkSuspend
155 /**
156 * Raised when the link becomes active again after being suspended.
157 */
158#define kDifUsbdevIrqLinkResume kDtUsbdevIrqLinkResume
159 /**
160 * Raised when the Available OUT Buffer FIFO is empty and the device interface is enabled. This interrupt is directly tied to the FIFO status, so the Available OUT Buffer FIFO must be provided with a free buffer before the interrupt can be cleared.
161 */
162#define kDifUsbdevIrqAvOutEmpty kDtUsbdevIrqAvOutEmpty
163 /**
164 * Raised when the RX FIFO is full and the device interface is enabled. This interrupt is directly tied to the FIFO status, so the RX FIFO must have an entry removed before the interrupt is cleared. If the condition is not cleared, the interrupt can re-assert.
165 */
166#define kDifUsbdevIrqRxFull kDtUsbdevIrqRxFull
167 /**
168 * Raised if a write was done to either the Available OUT Buffer FIFO or the Available SETUP Buffer FIFO when the FIFO was full.
169 */
170#define kDifUsbdevIrqAvOverflow kDtUsbdevIrqAvOverflow
171 /**
172 * Raised if a packet to an IN endpoint started to be received but was then dropped due to an error. After transmitting the IN payload, the USB device expects a valid ACK handshake packet. This error is raised if either the packet or CRC is invalid, leading to a NAK instead, or if a different token was received.
173 */
174#define kDifUsbdevIrqLinkInErr kDtUsbdevIrqLinkInErr
175 /**
176 * Raised if a CRC error occurred on a received packet.
177 */
178#define kDifUsbdevIrqRxCrcErr kDtUsbdevIrqRxCrcErr
179 /**
180 * Raised if an invalid Packet IDentifier (PID) was received.
181 */
182#define kDifUsbdevIrqRxPidErr kDtUsbdevIrqRxPidErr
183 /**
184 * Raised if an invalid bitstuffing was received.
185 */
186#define kDifUsbdevIrqRxBitstuffErr kDtUsbdevIrqRxBitstuffErr
187 /**
188 * Raised when the USB frame number is updated with a valid SOF.
189 */
190#define kDifUsbdevIrqFrame kDtUsbdevIrqFrame
191 /**
192 * Raised if VBUS is applied.
193 */
194#define kDifUsbdevIrqPowered kDtUsbdevIrqPowered
195 /**
196 * Raised if a packet to an OUT endpoint started to be received but was then dropped due to an error. This error is raised if the data toggle, token, packet and/or CRC are invalid, or if the appropriate Available OUT Buffer FIFO is empty and/or the Received Buffer FIFO is full when a packet should have been received. Attempting to perform an OUT transaction to an endpoint that is stalled, i.e. its control bit in `out_stall` is set, will also cause this error to be raised.
197 */
198#define kDifUsbdevIrqLinkOutErr kDtUsbdevIrqLinkOutErr
199 /**
200 * Raised when the Available SETUP Buffer FIFO is empty and the device interface is enabled. This interrupt is directly tied to the FIFO status, so the Available SETUP Buffer FIFO must be provided with a free buffer before the interrupt can be cleared.
201 */
202#define kDifUsbdevIrqAvSetupEmpty kDtUsbdevIrqAvSetupEmpty
203
204 /**
205 * A snapshot of the state of the interrupts for this IP.
206 *
207 * This is an opaque type, to be used with the `dif_usbdev_irq_get_state()`
208 * and `dif_usbdev_irq_acknowledge_state()` functions.
209 */
211
212 /**
213 * Returns the type of a given interrupt (i.e., event or status) for this IP.
214 *
215 * @param usbdev A usbdev handle.
216 * @param irq An interrupt request.
217 * @param[out] type Out-param for the interrupt type.
218 * @return The result of the operation.
219 */
222 const dif_usbdev_t *usbdev,
223 dif_usbdev_irq_t,
224 dif_irq_type_t *type);
225
226 /**
227 * Returns the state of all interrupts (i.e., pending or not) for this IP.
228 *
229 * @param usbdev A usbdev handle.
230 * @param[out] snapshot Out-param for interrupt state snapshot.
231 * @return The result of the operation.
232 */
235 const dif_usbdev_t *usbdev,
237
238 /**
239 * Returns whether a particular interrupt is currently pending.
240 *
241 * @param usbdev A usbdev handle.
242 * @param irq An interrupt request.
243 * @param[out] is_pending Out-param for whether the interrupt is pending.
244 * @return The result of the operation.
245 */
248 const dif_usbdev_t *usbdev,
249 dif_usbdev_irq_t,
250 bool *is_pending);
251
252 /**
253 * Acknowledges all interrupts that were pending at the time of the state
254 * snapshot.
255 *
256 * @param usbdev A usbdev handle.
257 * @param snapshot Interrupt state snapshot.
258 * @return The result of the operation.
259 */
262 const dif_usbdev_t *usbdev,
264
265 /**
266 * Acknowledges all interrupts, indicating to the hardware that all
267 * interrupts have been successfully serviced.
268 *
269 * @param usbdev A usbdev handle.
270 * @return The result of the operation.
271 */
274 const dif_usbdev_t *usbdev
275 );
276
277 /**
278 * Acknowledges a particular interrupt, indicating to the hardware that it has
279 * been successfully serviced.
280 *
281 * @param usbdev A usbdev handle.
282 * @param irq An interrupt request.
283 * @return The result of the operation.
284 */
287 const dif_usbdev_t *usbdev,
288 dif_usbdev_irq_t);
289
290 /**
291 * Forces a particular interrupt, causing it to be serviced as if hardware had
292 * asserted it.
293 *
294 * @param usbdev A usbdev handle.
295 * @param irq An interrupt request.
296 * @param val Value to be set.
297 * @return The result of the operation.
298 */
301 const dif_usbdev_t *usbdev,
302 dif_usbdev_irq_t,
303 const bool val);
304
305 /**
306 * A snapshot of the enablement state of the interrupts for this IP.
307 *
308 * This is an opaque type, to be used with the
309 * `dif_usbdev_irq_disable_all()` and `dif_usbdev_irq_restore_all()`
310 * functions.
311 */
313
314 /**
315 * Checks whether a particular interrupt is currently enabled or disabled.
316 *
317 * @param usbdev A usbdev handle.
318 * @param irq An interrupt request.
319 * @param[out] state Out-param toggle state of the interrupt.
320 * @return The result of the operation.
321 */
324 const dif_usbdev_t *usbdev,
325 dif_usbdev_irq_t,
326 dif_toggle_t *state);
327
328 /**
329 * Sets whether a particular interrupt is currently enabled or disabled.
330 *
331 * @param usbdev A usbdev handle.
332 * @param irq An interrupt request.
333 * @param state The new toggle state for the interrupt.
334 * @return The result of the operation.
335 */
338 const dif_usbdev_t *usbdev,
339 dif_usbdev_irq_t,
340 dif_toggle_t state);
341
342 /**
343 * Disables all interrupts, optionally snapshotting all enable states for later
344 * restoration.
345 *
346 * @param usbdev A usbdev handle.
347 * @param[out] snapshot Out-param for the snapshot; may be `NULL`.
348 * @return The result of the operation.
349 */
352 const dif_usbdev_t *usbdev,
354
355 /**
356 * Restores interrupts from the given (enable) snapshot.
357 *
358 * @param usbdev A usbdev handle.
359 * @param snapshot A snapshot to restore from.
360 * @return The result of the operation.
361 */
364 const dif_usbdev_t *usbdev,
365 const dif_usbdev_irq_enable_snapshot_t *snapshot);
366
367
368#ifdef __cplusplus
369} // extern "C"
370#endif // __cplusplus
371
372#endif // OPENTITAN_SW_DEVICE_LIB_DIF_AUTOGEN_DIF_USBDEV_AUTOGEN_H_