Software APIs
dif_gpio_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_GPIO_AUTOGEN_H_
8#define OPENTITAN_SW_DEVICE_LIB_DIF_AUTOGEN_DIF_GPIO_AUTOGEN_H_
9
10// THIS FILE HAS BEEN GENERATED, DO NOT EDIT MANUALLY. COMMAND:
11// util/autogen_dif.py -i hw/top_earlgrey/ip_autogen/gpio/data/gpio.hjson
12// -o bazel-out/k8-fastbuild/bin/sw/device/lib/dif/autogen
13
14
15/**
16 * @file
17 * @brief <a href="/book/hw/ip/gpio/">GPIO</a> Device Interface Functions
18 */
19
20#include <stdbool.h>
21#include <stdint.h>
22
26#include "hw/top/dt/gpio.h" // Generated.
27
28#ifdef __cplusplus
29extern "C" {
30#endif // __cplusplus
31
32/**
33 * A handle to gpio.
34 *
35 * This type should be treated as opaque by users.
36 */
37typedef struct dif_gpio {
38 /**
39 * The base address for the gpio hardware registers.
40 */
42 /**
43 * The instance, set to `kDtGpioCount` if not initialized
44 * through `dif_gpio_init_from_dt`.
45 */
48
49/**
50 * Creates a new handle for a(n) gpio peripheral.
51 *
52 * This function does not actuate the hardware.
53 *
54 * @param base_addr The MMIO base address of the gpio peripheral.
55 * @param[out] gpio 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_gpio_t *gpio);
65
66/**
67 * Creates a new handle for a(n) gpio peripheral.
68 *
69 * This function does not actuate the hardware.
70 *
71 * @param dt The devicetable description of the device.
72 * @param[out] gpio Out param for the initialized handle.
73 * @return The result of the operation.
74 */
77 dt_gpio_t dt,
78 dif_gpio_t *gpio);
79
80/**
81 * Get the DT handle from this DIF.
82 *
83 * If this DIF was initialized by `dif_gpio_init_from_dt(dt, ..)`
84 * then this function will return `dt`. Otherwise it will return an error.
85 *
86 * @param gpio A gpio handle.
87 * @param[out] dt DT handle.
88 * @return `kDifBadArg` if the DIF has no DT information, `kDifOk` otherwise.
89 */
92 const dif_gpio_t *gpio,
93 dt_gpio_t *dt);
94
95 /**
96 * A gpio alert type.
97 */
98 typedef enum dif_gpio_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 gpio A gpio handle.
110 * @param alert The alert to force.
111 * @return The result of the operation.
112 */
115 const dif_gpio_t *gpio,
116 dif_gpio_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_gpio_irq_t dif_gpio_irq_t;
121
122 /**
123 * A gpio interrupt request type.
124 *
125 * DEPRECATED Use `dt_gpio_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 any of GPIO pin detects configured interrupt mode
133 */
134#define kDifGpioIrqGpio0 kDtGpioIrqGpio0
135#define kDifGpioIrqGpio1 kDtGpioIrqGpio1
136#define kDifGpioIrqGpio2 kDtGpioIrqGpio2
137#define kDifGpioIrqGpio3 kDtGpioIrqGpio3
138#define kDifGpioIrqGpio4 kDtGpioIrqGpio4
139#define kDifGpioIrqGpio5 kDtGpioIrqGpio5
140#define kDifGpioIrqGpio6 kDtGpioIrqGpio6
141#define kDifGpioIrqGpio7 kDtGpioIrqGpio7
142#define kDifGpioIrqGpio8 kDtGpioIrqGpio8
143#define kDifGpioIrqGpio9 kDtGpioIrqGpio9
144#define kDifGpioIrqGpio10 kDtGpioIrqGpio10
145#define kDifGpioIrqGpio11 kDtGpioIrqGpio11
146#define kDifGpioIrqGpio12 kDtGpioIrqGpio12
147#define kDifGpioIrqGpio13 kDtGpioIrqGpio13
148#define kDifGpioIrqGpio14 kDtGpioIrqGpio14
149#define kDifGpioIrqGpio15 kDtGpioIrqGpio15
150#define kDifGpioIrqGpio16 kDtGpioIrqGpio16
151#define kDifGpioIrqGpio17 kDtGpioIrqGpio17
152#define kDifGpioIrqGpio18 kDtGpioIrqGpio18
153#define kDifGpioIrqGpio19 kDtGpioIrqGpio19
154#define kDifGpioIrqGpio20 kDtGpioIrqGpio20
155#define kDifGpioIrqGpio21 kDtGpioIrqGpio21
156#define kDifGpioIrqGpio22 kDtGpioIrqGpio22
157#define kDifGpioIrqGpio23 kDtGpioIrqGpio23
158#define kDifGpioIrqGpio24 kDtGpioIrqGpio24
159#define kDifGpioIrqGpio25 kDtGpioIrqGpio25
160#define kDifGpioIrqGpio26 kDtGpioIrqGpio26
161#define kDifGpioIrqGpio27 kDtGpioIrqGpio27
162#define kDifGpioIrqGpio28 kDtGpioIrqGpio28
163#define kDifGpioIrqGpio29 kDtGpioIrqGpio29
164#define kDifGpioIrqGpio30 kDtGpioIrqGpio30
165#define kDifGpioIrqGpio31 kDtGpioIrqGpio31
166
167 /**
168 * A snapshot of the state of the interrupts for this IP.
169 *
170 * This is an opaque type, to be used with the `dif_gpio_irq_get_state()`
171 * and `dif_gpio_irq_acknowledge_state()` functions.
172 */
174
175 /**
176 * Returns the type of a given interrupt (i.e., event or status) for this IP.
177 *
178 * @param gpio A gpio handle.
179 * @param irq An interrupt request.
180 * @param[out] type Out-param for the interrupt type.
181 * @return The result of the operation.
182 */
185 const dif_gpio_t *gpio,
186 dif_gpio_irq_t,
187 dif_irq_type_t *type);
188
189 /**
190 * Returns the state of all interrupts (i.e., pending or not) for this IP.
191 *
192 * @param gpio A gpio handle.
193 * @param[out] snapshot Out-param for interrupt state snapshot.
194 * @return The result of the operation.
195 */
198 const dif_gpio_t *gpio,
200
201 /**
202 * Returns whether a particular interrupt is currently pending.
203 *
204 * @param gpio A gpio handle.
205 * @param irq An interrupt request.
206 * @param[out] is_pending Out-param for whether the interrupt is pending.
207 * @return The result of the operation.
208 */
211 const dif_gpio_t *gpio,
212 dif_gpio_irq_t,
213 bool *is_pending);
214
215 /**
216 * Acknowledges all interrupts that were pending at the time of the state
217 * snapshot.
218 *
219 * @param gpio A gpio handle.
220 * @param snapshot Interrupt state snapshot.
221 * @return The result of the operation.
222 */
225 const dif_gpio_t *gpio,
227
228 /**
229 * Acknowledges all interrupts, indicating to the hardware that all
230 * interrupts have been successfully serviced.
231 *
232 * @param gpio A gpio handle.
233 * @return The result of the operation.
234 */
237 const dif_gpio_t *gpio
238 );
239
240 /**
241 * Acknowledges a particular interrupt, indicating to the hardware that it has
242 * been successfully serviced.
243 *
244 * @param gpio A gpio handle.
245 * @param irq An interrupt request.
246 * @return The result of the operation.
247 */
250 const dif_gpio_t *gpio,
251 dif_gpio_irq_t);
252
253 /**
254 * Forces a particular interrupt, causing it to be serviced as if hardware had
255 * asserted it.
256 *
257 * @param gpio A gpio handle.
258 * @param irq An interrupt request.
259 * @param val Value to be set.
260 * @return The result of the operation.
261 */
264 const dif_gpio_t *gpio,
265 dif_gpio_irq_t,
266 const bool val);
267
268 /**
269 * A snapshot of the enablement state of the interrupts for this IP.
270 *
271 * This is an opaque type, to be used with the
272 * `dif_gpio_irq_disable_all()` and `dif_gpio_irq_restore_all()`
273 * functions.
274 */
276
277 /**
278 * Checks whether a particular interrupt is currently enabled or disabled.
279 *
280 * @param gpio A gpio handle.
281 * @param irq An interrupt request.
282 * @param[out] state Out-param toggle state of the interrupt.
283 * @return The result of the operation.
284 */
287 const dif_gpio_t *gpio,
288 dif_gpio_irq_t,
289 dif_toggle_t *state);
290
291 /**
292 * Sets whether a particular interrupt is currently enabled or disabled.
293 *
294 * @param gpio A gpio handle.
295 * @param irq An interrupt request.
296 * @param state The new toggle state for the interrupt.
297 * @return The result of the operation.
298 */
301 const dif_gpio_t *gpio,
302 dif_gpio_irq_t,
303 dif_toggle_t state);
304
305 /**
306 * Disables all interrupts, optionally snapshotting all enable states for later
307 * restoration.
308 *
309 * @param gpio A gpio handle.
310 * @param[out] snapshot Out-param for the snapshot; may be `NULL`.
311 * @return The result of the operation.
312 */
315 const dif_gpio_t *gpio,
317
318 /**
319 * Restores interrupts from the given (enable) snapshot.
320 *
321 * @param gpio A gpio handle.
322 * @param snapshot A snapshot to restore from.
323 * @return The result of the operation.
324 */
327 const dif_gpio_t *gpio,
328 const dif_gpio_irq_enable_snapshot_t *snapshot);
329
330
331#ifdef __cplusplus
332} // extern "C"
333#endif // __cplusplus
334
335#endif // OPENTITAN_SW_DEVICE_LIB_DIF_AUTOGEN_DIF_GPIO_AUTOGEN_H_