Software APIs
dma.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_DMA_H_
8#define OPENTITAN_DT_DMA_H_
9
10#ifdef __cplusplus
11extern "C" {
12#endif // __cplusplus
13
14/**
15 * @file
16 * @brief Device Tables (DT) for IP dma and top darjeeling.
17 *
18 * This file contains the type definitions and global functions of the dma.
19 */
20
21#include "hw/top/dt/api.h"
22#include <stdint.h>
23
24
25
26/**
27 * List of instances.
28 */
29typedef enum dt_dma {
30 kDtDmaFirst = 0, /**< First instance */
31 kDtDma = 0, /**< dma */
33
34enum {
35 kDtDmaCount = 1, /**< Number of instances */
36};
37
38
39/**
40 * List of register blocks.
41 *
42 * Register blocks are guaranteed to start at 0 and to be consecutively numbered.
43 */
44typedef enum dt_dma_reg_block {
45 kDtDmaRegBlockCore = 0, /**< */
47
48enum {
49 kDtDmaRegBlockCount = 1, /**< Number of register blocks */
50};
51
52
53/** Primary register block (associated with the "primary" set of registers that control the IP). */
54static const dt_dma_reg_block_t kDtDmaRegBlockPrimary = kDtDmaRegBlockCore;
55
56/**
57 * List of IRQs.
58 *
59 * IRQs are guaranteed to be numbered consecutively from 0.
60 */
61typedef enum dt_dma_irq {
62 kDtDmaIrqDmaDone = 0, /**< DMA operation has been completed. */
63 kDtDmaIrqDmaChunkDone = 1, /**< Indicates the transfer of a single chunk has been completed. */
64 kDtDmaIrqDmaError = 2, /**< DMA error has occurred. DMA_STATUS.error_code register shows the details. */
66
67enum {
68 kDtDmaIrqCount = 3, /**< Number of IRQs */
69};
70
71
72/**
73 * List of Alerts.
74 *
75 * Alerts are guaranteed to be numbered consecutively from 0.
76 */
77typedef enum dt_dma_alert {
78 kDtDmaAlertFatalFault = 0, /**< This fatal alert is triggered when a fatal TL-UL bus integrity fault is detected. */
80
81enum {
82 kDtDmaAlertCount = 1, /**< Number of Alerts */
83};
84
85
86/**
87 * List of clock ports.
88 *
89 * Clock ports are guaranteed to be numbered consecutively from 0.
90 */
91typedef enum dt_dma_clock {
92 kDtDmaClockClk = 0, /**< Clock port clk_i */
94
95enum {
96 kDtDmaClockCount = 1, /**< Number of clock ports */
97};
98
99
100/**
101 * List of reset ports.
102 *
103 * Reset ports are guaranteed to be numbered consecutively from 0.
104 */
105typedef enum dt_dma_reset {
106 kDtDmaResetRst = 0, /**< Reset port rst_ni */
108
109enum {
110 kDtDmaResetCount = 1, /**< Number of reset ports */
111};
112
113
114
115/**
116 * Get the dma instance from an instance ID
117 *
118 * For example, `dt_uart_from_instance_id(kDtInstanceIdUart3) == kDtUart3`.
119 *
120 * @param inst_id Instance ID.
121 * @return A dma instance.
122 *
123 * **Note:** This function only makes sense if the instance ID has device type dma,
124 * otherwise the returned value is unspecified.
125 */
127
128/**
129 * Get the instance ID of an instance.
130 *
131 * @param dt Instance of dma.
132 * @return The instance ID of that instance.
133 */
135
136/**
137 * Get the register base address of an instance.
138 *
139 * @param dt Instance of dma.
140 * @param reg_block The register block requested.
141 * @return The register base address of the requested block.
142 */
143uint32_t dt_dma_reg_block(
144 dt_dma_t dt,
145 dt_dma_reg_block_t reg_block);
146
147/**
148 * Get the primary register base address of an instance.
149 *
150 * This is just a convenience function, equivalent to
151 * `dt_dma_reg_block(dt, kDtDmaRegBlockCore)`
152 *
153 * @param dt Instance of dma.
154 * @return The register base address of the primary register block.
155 */
156static inline uint32_t dt_dma_primary_reg_block(
157 dt_dma_t dt) {
158 return dt_dma_reg_block(dt, kDtDmaRegBlockCore);
159}
160
161/**
162 * Get the PLIC ID of a dma IRQ for a given instance.
163 *
164 * If the instance is not connected to the PLIC, this function
165 * will return `kDtPlicIrqIdNone`.
166 *
167 * @param dt Instance of dma.
168 * @param irq A dma IRQ.
169 * @return The PLIC ID of the IRQ of this instance.
170 */
172 dt_dma_t dt,
173 dt_dma_irq_t irq);
174
175/**
176 * Convert a global IRQ ID to a local dma IRQ type.
177 *
178 * @param dt Instance of dma.
179 * @param irq A PLIC ID that belongs to this instance.
180 * @return The dma IRQ, or `kDtDmaIrqCount`.
181 *
182 * **Note:** This function assumes that the PLIC ID belongs to the instance
183 * of dma passed in parameter. In other words, it must be the case that
184 * `dt_dma_instance_id(dt) == dt_plic_id_to_instance_id(irq)`. Otherwise, this function
185 * will return `kDtDmaIrqCount`.
186 */
188 dt_dma_t dt,
189 dt_plic_irq_id_t irq);
190
191
192/**
193 * Get the alert ID of a dma alert for a given instance.
194 *
195 * **Note:** This function only makes sense if the instance is connected to the Alert Handler. For any
196 * instances where the instance is not connected, the return value is unspecified.
197 *
198 * @param dt Instance of dma.
199 * @param alert A dma alert.
200 * @return The Alert Handler alert ID of the alert of this instance.
201 */
203 dt_dma_t dt,
204 dt_dma_alert_t alert);
205
206/**
207 * Convert a global alert ID to a local dma alert type.
208 *
209 * @param dt Instance of dma.
210 * @param alert A global alert ID that belongs to this instance.
211 * @return The dma alert, or `kDtDmaAlertCount`.
212 *
213 * **Note:** This function assumes that the global alert ID belongs to the
214 * instance of dma passed in parameter. In other words, it must be the case
215 * that `dt_dma_instance_id(dt) == dt_alert_id_to_instance_id(alert)`. Otherwise,
216 * this function will return `kDtDmaAlertCount`.
217 */
219 dt_dma_t dt,
220 dt_alert_id_t alert);
221
222
223
224/**
225 * Get the clock signal connected to a clock port of an instance.
226 *
227 * @param dt Instance of dma.
228 * @param clk Clock port.
229 * @return Clock signal.
230 */
232 dt_dma_t dt,
233 dt_dma_clock_t clk);
234
235/**
236 * Get the reset signal connected to a reset port of an instance.
237 *
238 * @param dt Instance of dma.
239 * @param rst Reset port.
240 * @return Reset signal.
241 */
243 dt_dma_t dt,
244 dt_dma_reset_t rst);
245
246
247
248#ifdef __cplusplus
249} // extern "C"
250#endif // __cplusplus
251
252#endif // OPENTITAN_DT_DMA_H_