1 |
4 |
kuzmi4 |
/******************************************************************************
|
2 |
|
|
*
|
3 |
|
|
* Copyright (C) 2010 - 2015 Xilinx, Inc. All rights reserved.
|
4 |
|
|
*
|
5 |
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
6 |
|
|
* of this software and associated documentation files (the "Software"), to deal
|
7 |
|
|
* in the Software without restriction, including without limitation the rights
|
8 |
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9 |
|
|
* copies of the Software, and to permit persons to whom the Software is
|
10 |
|
|
* furnished to do so, subject to the following conditions:
|
11 |
|
|
*
|
12 |
|
|
* The above copyright notice and this permission notice shall be included in
|
13 |
|
|
* all copies or substantial portions of the Software.
|
14 |
|
|
*
|
15 |
|
|
* Use of the Software is limited solely to applications:
|
16 |
|
|
* (a) running on a Xilinx device, or
|
17 |
|
|
* (b) that interact with a Xilinx device through a bus or interconnect.
|
18 |
|
|
*
|
19 |
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
20 |
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
21 |
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
22 |
|
|
* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
|
24 |
|
|
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
25 |
|
|
* SOFTWARE.
|
26 |
|
|
*
|
27 |
|
|
* Except as contained in this notice, the name of the Xilinx shall not be used
|
28 |
|
|
* in advertising or otherwise to promote the sale, use or other dealings in
|
29 |
|
|
* this Software without prior written authorization from Xilinx.
|
30 |
|
|
*
|
31 |
|
|
******************************************************************************/
|
32 |
|
|
/*****************************************************************************/
|
33 |
|
|
/**
|
34 |
|
|
*
|
35 |
|
|
* @file xaxidma.h
|
36 |
|
|
* @addtogroup axidma_v9_0
|
37 |
|
|
* @{
|
38 |
|
|
* @details
|
39 |
|
|
*
|
40 |
|
|
* This is the driver API for the AXI DMA engine.
|
41 |
|
|
*
|
42 |
|
|
* For a full description of DMA features, please see the hardware spec. This
|
43 |
|
|
* driver supports the following features:
|
44 |
|
|
*
|
45 |
|
|
* - Scatter-Gather DMA (SGDMA)
|
46 |
|
|
* - Simple DMA
|
47 |
|
|
* - Interrupts
|
48 |
|
|
* - Programmable interrupt coalescing for SGDMA
|
49 |
|
|
* - APIs to manage Buffer Descriptors (BD) movement to and from the SGDMA
|
50 |
|
|
* engine
|
51 |
|
|
*
|
52 |
|
|
* <b>Simple DMA</b>
|
53 |
|
|
*
|
54 |
|
|
* Simple DMA allows the application to define a single transaction between DMA
|
55 |
|
|
* and Device. It has two channels: one from the DMA to Device and the other
|
56 |
|
|
* from Device to DMA. Application has to set the buffer address and
|
57 |
|
|
* length fields to initiate the transfer in respective channel.
|
58 |
|
|
*
|
59 |
|
|
* <b>Transactions</b>
|
60 |
|
|
*
|
61 |
|
|
* The object used to describe a transaction is referred to as a Buffer
|
62 |
|
|
* Descriptor (BD). Buffer descriptors are allocated in the user application.
|
63 |
|
|
* The user application needs to set buffer address, transfer length, and
|
64 |
|
|
* control information for this transfer. The control information includes
|
65 |
|
|
* SOF and EOF. Definition of those masks are in xaxidma_hw.h
|
66 |
|
|
*
|
67 |
|
|
* <b>Scatter-Gather DMA</b>
|
68 |
|
|
*
|
69 |
|
|
* SGDMA allows the application to define a list of transactions in memory which
|
70 |
|
|
* the hardware will process without further application intervention. During
|
71 |
|
|
* this time, the application is free to continue adding more work to keep the
|
72 |
|
|
* Hardware busy.
|
73 |
|
|
*
|
74 |
|
|
* User can check for the completion of transactions through polling the
|
75 |
|
|
* hardware, or interrupts.
|
76 |
|
|
*
|
77 |
|
|
* SGDMA processes whole packets. A packet is defined as a series of
|
78 |
|
|
* data bytes that represent a message. SGDMA allows a packet of data to be
|
79 |
|
|
* broken up into one or more transactions. For example, take an Ethernet IP
|
80 |
|
|
* packet which consists of a 14 byte header followed by a 1 or more bytes of
|
81 |
|
|
* payload. With SGDMA, the application may point a BD to the header and another
|
82 |
|
|
* BD to the payload, then transfer them as a single message. This strategy can
|
83 |
|
|
* make a TCP/IP stack more efficient by allowing it to keep packet header and
|
84 |
|
|
* data in different memory regions instead of assembling packets into
|
85 |
|
|
* contiguous blocks of memory.
|
86 |
|
|
*
|
87 |
|
|
* <b>BD Ring Management</b>
|
88 |
|
|
*
|
89 |
|
|
* BD rings are shared by the software and the hardware.
|
90 |
|
|
*
|
91 |
|
|
* The hardware expects BDs to be setup as a linked list. The DMA hardware walks
|
92 |
|
|
* through the list by following the next pointer field of a completed BD.
|
93 |
|
|
* The hardware stops processing when the just completed BD is the same as the
|
94 |
|
|
* BD specified in the Tail Ptr register in the hardware.
|
95 |
|
|
*
|
96 |
|
|
* The last BD in the ring is linked to the first BD in the ring.
|
97 |
|
|
*
|
98 |
|
|
* All BD management are done inside the driver. The user application should not
|
99 |
|
|
* directly modify the BD fields. Modifications to the BD fields should always
|
100 |
|
|
* go through the specific API functions.
|
101 |
|
|
*
|
102 |
|
|
* Within the ring, the driver maintains four groups of BDs. Each group consists
|
103 |
|
|
* of 0 or more adjacent BDs:
|
104 |
|
|
*
|
105 |
|
|
* - Free: The BDs that can be allocated by the application with
|
106 |
|
|
* XAxiDma_BdRingAlloc().
|
107 |
|
|
*
|
108 |
|
|
* - Pre-process: The BDs that have been allocated with
|
109 |
|
|
* XAxiDma_BdRingAlloc(). These BDs are under application control. The
|
110 |
|
|
* application modifies these BDs through driver API to prepare them
|
111 |
|
|
* for DMA transactions.
|
112 |
|
|
*
|
113 |
|
|
* - Hardware: The BDs that have been enqueued to hardware with
|
114 |
|
|
* XAxiDma_BdRingToHw(). These BDs are under hardware control and may be in a
|
115 |
|
|
* state of awaiting hardware processing, in process, or processed by
|
116 |
|
|
* hardware. It is considered an error for the application to change BDs
|
117 |
|
|
* while they are in this group. Doing so can cause data corruption and lead
|
118 |
|
|
* to system instability.
|
119 |
|
|
*
|
120 |
|
|
* - Post-process: The BDs that have been processed by hardware and have
|
121 |
|
|
* been extracted from the Hardware group with XAxiDma_BdRingFromHw().
|
122 |
|
|
* These BDs are under application control. The application can check the
|
123 |
|
|
* transfer status of these BDs. The application use XAxiDma_BdRingFree()
|
124 |
|
|
* to put them into the Free group.
|
125 |
|
|
*
|
126 |
|
|
* BDs are expected to transition in the following way for continuous
|
127 |
|
|
* DMA transfers:
|
128 |
|
|
* <pre>
|
129 |
|
|
*
|
130 |
|
|
* XAxiDma_BdRingAlloc() XAxiDma_BdRingToHw()
|
131 |
|
|
* Free ------------------------> Pre-process ----------------------> Hardware
|
132 |
|
|
* |
|
133 |
|
|
* /|\ |
|
134 |
|
|
* | XAxiDma_BdRingFree() XAxiDma_BdRingFromHw() |
|
135 |
|
|
* +--------------------------- Post-process <----------------------+
|
136 |
|
|
*
|
137 |
|
|
* </pre>
|
138 |
|
|
*
|
139 |
|
|
* When a DMA transfer is to be cancelled before enqueuing to hardware,
|
140 |
|
|
* application can return the requested BDs to the Free group using
|
141 |
|
|
* XAxiDma_BdRingUnAlloc(), as shown below:
|
142 |
|
|
* <pre>
|
143 |
|
|
*
|
144 |
|
|
* XAxiDma_BdRingUnAlloc()
|
145 |
|
|
* Free <----------------------- Pre-process
|
146 |
|
|
*
|
147 |
|
|
* </pre>
|
148 |
|
|
*
|
149 |
|
|
* The API provides functions for BD list traversal:
|
150 |
|
|
* - XAxiDma_BdRingNext()
|
151 |
|
|
* - XAxiDma_BdRingPrev()
|
152 |
|
|
*
|
153 |
|
|
* These functions should be used with care as they do not understand where
|
154 |
|
|
* one group ends and another begins.
|
155 |
|
|
*
|
156 |
|
|
* <b>SGDMA Descriptor Ring Creation</b>
|
157 |
|
|
*
|
158 |
|
|
* BD ring is created using XAxiDma_BdRingCreate(). The memory for the BD ring
|
159 |
|
|
* is allocated by the application, and it has to be contiguous. Physical
|
160 |
|
|
* address is required to setup the BD ring.
|
161 |
|
|
*
|
162 |
|
|
* The applicaiton can use XAxiDma_BdRingMemCalc() to find out the amount of
|
163 |
|
|
* memory needed for a certain number of BDs. XAxiDma_BdRingCntCalc() can be
|
164 |
|
|
* used to find out how many BDs can be allocated for certain amount of memory.
|
165 |
|
|
*
|
166 |
|
|
* A helper function, XAxiDma_BdRingClone(), can speed up the BD ring setup if
|
167 |
|
|
* the BDs have same types of controls, for example, SOF and EOF. After
|
168 |
|
|
* using the XAxiDma_BdRingClone(), the application only needs to setup the
|
169 |
|
|
* buffer address and transfer length. Note that certain BDs in one packet,
|
170 |
|
|
* for example, the first BD and the last BD, may need to setup special
|
171 |
|
|
* control information.
|
172 |
|
|
*
|
173 |
|
|
* <b>Descriptor Ring State Machine</b>
|
174 |
|
|
*
|
175 |
|
|
* There are two states of the BD ring:
|
176 |
|
|
*
|
177 |
|
|
* - HALTED (H), where hardware is not running
|
178 |
|
|
*
|
179 |
|
|
* - NOT HALTED (NH), where hardware is running
|
180 |
|
|
*
|
181 |
|
|
* The following diagram shows the state transition for the DMA engine:
|
182 |
|
|
*
|
183 |
|
|
* <pre>
|
184 |
|
|
* _____ XAxiDma_StartBdRingHw(), or XAxiDma_BdRingStart(), ______
|
185 |
|
|
* | | or XAxiDma_Resume() | |
|
186 |
|
|
* | H |----------------------------------------------------->| NH |
|
187 |
|
|
* | |<-----------------------------------------------------| |
|
188 |
|
|
* ----- XAxiDma_Pause() or XAxiDma_Reset() ------
|
189 |
|
|
* </pre>
|
190 |
|
|
*
|
191 |
|
|
* <b>Interrupt Coalescing</b>
|
192 |
|
|
*
|
193 |
|
|
* SGDMA provides control over the frequency of interrupts through interrupt
|
194 |
|
|
* coalescing. The DMA engine provides two ways to tune the interrupt
|
195 |
|
|
* coalescing:
|
196 |
|
|
*
|
197 |
|
|
* - The packet threshold counter. Interrupt will fire once the
|
198 |
|
|
* programmable number of packets have been processed by the engine.
|
199 |
|
|
*
|
200 |
|
|
* - The packet delay timer counter. Interrupt will fire once the
|
201 |
|
|
* programmable amount of time has passed after processing the last packet,
|
202 |
|
|
* and no new packets to process. Note that the interrupt will only fire if
|
203 |
|
|
* at least one packet has been processed.
|
204 |
|
|
*
|
205 |
|
|
* <b> Interrupt </b>
|
206 |
|
|
*
|
207 |
|
|
* Interrupts are handled by the user application. Each DMA channel has its own
|
208 |
|
|
* interrupt ID. The driver provides APIs to enable/disable interrupt,
|
209 |
|
|
* and tune the interrupt frequency regarding to packet processing frequency.
|
210 |
|
|
*
|
211 |
|
|
* <b> Software Initialization </b>
|
212 |
|
|
*
|
213 |
|
|
*
|
214 |
|
|
* To use the Simple mode DMA engine for transfers, the following setup is
|
215 |
|
|
* required:
|
216 |
|
|
*
|
217 |
|
|
* - DMA Initialization using XAxiDma_CfgInitialize() function. This step
|
218 |
|
|
* initializes a driver instance for the given DMA engine and resets the
|
219 |
|
|
* engine.
|
220 |
|
|
*
|
221 |
|
|
* - Enable interrupts if chosen to use interrupt mode. The application is
|
222 |
|
|
* responsible for setting up the interrupt system, which includes providing
|
223 |
|
|
* and connecting interrupt handlers and call back functions, before
|
224 |
|
|
* enabling the interrupts.
|
225 |
|
|
*
|
226 |
|
|
* - Set the buffer address and length field in respective channels to start
|
227 |
|
|
* the DMA transfer
|
228 |
|
|
*
|
229 |
|
|
* To use the SG mode DMA engine for transfers, the following setup are
|
230 |
|
|
* required:
|
231 |
|
|
*
|
232 |
|
|
* - DMA Initialization using XAxiDma_CfgInitialize() function. This step
|
233 |
|
|
* initializes a driver instance for the given DMA engine and resets the
|
234 |
|
|
* engine.
|
235 |
|
|
*
|
236 |
|
|
* - BD Ring creation. A BD ring is needed per DMA channel and can be built by
|
237 |
|
|
* calling XAxiDma_BdRingCreate().
|
238 |
|
|
*
|
239 |
|
|
* - Enable interrupts if chose to use interrupt mode. The application is
|
240 |
|
|
* responsible for setting up the interrupt system, which includes providing
|
241 |
|
|
* and connecting interrupt handlers and call back functions, before
|
242 |
|
|
* enabling the interrupts.
|
243 |
|
|
*
|
244 |
|
|
* - Start a DMA transfer: Call XAxiDma_BdRingStart() to start a transfer for
|
245 |
|
|
* the first time or after a reset, and XAxiDma_BdRingToHw() if the channel
|
246 |
|
|
* is already started. Calling XAxiDma_BdRingToHw() when a DMA channel is not
|
247 |
|
|
* running will not put the BDs to the hardware, and the BDs will be processed
|
248 |
|
|
* later when the DMA channel is started through XAxiDma_BdRingStart().
|
249 |
|
|
*
|
250 |
|
|
* <b> How to start DMA transactions </b>
|
251 |
|
|
*
|
252 |
|
|
* The user application uses XAxiDma_BdRingToHw() to submit BDs to the hardware
|
253 |
|
|
* to start DMA transfers.
|
254 |
|
|
*
|
255 |
|
|
* For both channels, if the DMA engine is currently stopped (using
|
256 |
|
|
* XAxiDma_Pause()), the newly added BDs will be accepted but not processed
|
257 |
|
|
* until the DMA engine is started, using XAxiDma_BdRingStart(), or resumed,
|
258 |
|
|
* using XAxiDma_Resume().
|
259 |
|
|
*
|
260 |
|
|
* <b> Software Post-Processing on completed DMA transactions </b>
|
261 |
|
|
*
|
262 |
|
|
* If the interrupt system has been set up and the interrupts are enabled,
|
263 |
|
|
* a DMA channels notifies the software about the completion of a transfer
|
264 |
|
|
* through interrupts. Otherwise, the user application can poll for
|
265 |
|
|
* completions of the BDs, using XAxiDma_BdRingFromHw() or
|
266 |
|
|
* XAxiDma_BdHwCompleted().
|
267 |
|
|
*
|
268 |
|
|
* - Once BDs are finished by a channel, the application first needs to fetch
|
269 |
|
|
* them from the channel using XAxiDma_BdRingFromHw().
|
270 |
|
|
*
|
271 |
|
|
* - On the TX side, the application now could free the data buffers attached to
|
272 |
|
|
* those BDs as the data in the buffers has been transmitted.
|
273 |
|
|
*
|
274 |
|
|
* - On the RX side, the application now could use the received data in the
|
275 |
|
|
* buffers attached to those BDs.
|
276 |
|
|
*
|
277 |
|
|
* - For both channels, completed BDs need to be put back to the Free group
|
278 |
|
|
* using XAxiDma_BdRingFree(), so they can be used for future transactions.
|
279 |
|
|
*
|
280 |
|
|
* - On the RX side, it is the application's responsibility to have BDs ready
|
281 |
|
|
* to receive data at any time. Otherwise, the RX channel refuses to
|
282 |
|
|
* accept any data if it has no RX BDs.
|
283 |
|
|
*
|
284 |
|
|
* <b> Examples </b>
|
285 |
|
|
*
|
286 |
|
|
* We provide five examples to show how to use the driver API:
|
287 |
|
|
* - One for SG interrupt mode (xaxidma_example_sg_intr.c), multiple BD/packets transfer
|
288 |
|
|
* - One for SG polling mode (xaxidma_example_sg_poll.c), single BD transfer.
|
289 |
|
|
* - One for SG polling mode (xaxidma_poll_multi_pkts.c), multiple BD/packets transfer
|
290 |
|
|
* - One for simple polling mode (xaxidma_example_simple_poll.c)
|
291 |
|
|
* - One for simple Interrupt mode (xaxidma_example_simple_intr.c)
|
292 |
|
|
*
|
293 |
|
|
* <b> Address Translation </b>
|
294 |
|
|
*
|
295 |
|
|
* All buffer addresses and BD addresses for the hardware are physical
|
296 |
|
|
* addresses. The user application is responsible to provide physical buffer
|
297 |
|
|
* address for the BD upon BD ring creation. The user application accesses BD
|
298 |
|
|
* through its virtual addess. The driver maintains the address translation
|
299 |
|
|
* between the physical and virtual address for BDs.
|
300 |
|
|
*
|
301 |
|
|
* <b> Cache Coherency </b>
|
302 |
|
|
*
|
303 |
|
|
* This driver expects all application buffers attached to BDs to be in cache
|
304 |
|
|
* coherent memory. If cache is used in the system, buffers for transmit MUST
|
305 |
|
|
* be flushed from the cache before passing the associated BD to this driver.
|
306 |
|
|
* Buffers for receive MUST be invalidated before accessing the data.
|
307 |
|
|
*
|
308 |
|
|
* <b> Alignment </b>
|
309 |
|
|
*
|
310 |
|
|
* For BDs:
|
311 |
|
|
*
|
312 |
|
|
* Minimum alignment is defined by the constant XAXIDMA_BD_MINIMUM_ALIGNMENT.
|
313 |
|
|
* This is the smallest alignment allowed by both hardware and software for them
|
314 |
|
|
* to properly work.
|
315 |
|
|
*
|
316 |
|
|
* If the descriptor ring is to be placed in cached memory, alignment also MUST
|
317 |
|
|
* be at least the processor's cache-line size. Otherwise, system instability
|
318 |
|
|
* occurs. For alignment larger than the cache line size, multiple cache line
|
319 |
|
|
* size alignment is required.
|
320 |
|
|
*
|
321 |
|
|
* Aside from the initial creation of the descriptor ring (see
|
322 |
|
|
* XAxiDma_BdRingCreate()), there are no other run-time checks for proper
|
323 |
|
|
* alignment of BDs.
|
324 |
|
|
*
|
325 |
|
|
* For application data buffers:
|
326 |
|
|
*
|
327 |
|
|
* Application data buffers may reside on any alignment if DRE is built into the
|
328 |
|
|
* hardware. Otherwise, application data buffer must be word-aligned. The word
|
329 |
|
|
* is defined by XPAR_AXIDMA_0_M_AXIS_MM2S_TDATA_WIDTH for transmit and
|
330 |
|
|
* XPAR_AXIDMA_0_S_AXIS_S2MM_TDATA_WIDTH for receive.
|
331 |
|
|
*
|
332 |
|
|
* For scatter gather transfers that have more than one BDs in the chain of BDs,
|
333 |
|
|
* Each BD transfer length must be multiple of word too. Otherwise, internal
|
334 |
|
|
* error happens in the hardware.
|
335 |
|
|
*
|
336 |
|
|
* <b> Error Handling </b>
|
337 |
|
|
*
|
338 |
|
|
* The DMA engine will halt on all error conditions. It requires the software
|
339 |
|
|
* to do a reset before it can start process new transfer requests.
|
340 |
|
|
*
|
341 |
|
|
* <b> Restart After Stopping </b>
|
342 |
|
|
*
|
343 |
|
|
* After the DMA engine has been stopped (through reset or reset after an error)
|
344 |
|
|
* the software keeps track of the current BD pointer when reset happens, and
|
345 |
|
|
* processing of BDs can be resumed through XAxiDma_BdRingStart().
|
346 |
|
|
*
|
347 |
|
|
* <b> Limitations </b>
|
348 |
|
|
*
|
349 |
|
|
* This driver does not have any mechanisms for mutual exclusion. It is up to
|
350 |
|
|
* the application to provide this protection.
|
351 |
|
|
*
|
352 |
|
|
* <b> Hardware Defaults & Exclusive Use </b>
|
353 |
|
|
*
|
354 |
|
|
* After the initialization or reset, the DMA engine is in the following
|
355 |
|
|
* default mode:
|
356 |
|
|
* - All interrupts are disabled.
|
357 |
|
|
*
|
358 |
|
|
* - Interrupt coalescing counter is 1.
|
359 |
|
|
*
|
360 |
|
|
* - The DMA engine is not running (halted). Each DMA channel is started
|
361 |
|
|
* separately, using XAxiDma_StartBdRingHw() if no BDs are setup for transfer
|
362 |
|
|
* yet, or XAxiDma_BdRingStart() otherwise.
|
363 |
|
|
*
|
364 |
|
|
* The driver has exclusive use of the registers and BDs. All accesses to the
|
365 |
|
|
* registers and BDs should go through the driver interface.
|
366 |
|
|
*
|
367 |
|
|
* <b> Debug Print </b>
|
368 |
|
|
*
|
369 |
|
|
* To see the debug print for the driver, please put "-DDEBUG" as the extra
|
370 |
|
|
* compiler flags in software platform settings. Also comment out the line in
|
371 |
|
|
* xdebug.h: "#undef DEBUG".
|
372 |
|
|
*
|
373 |
|
|
* <b>Changes From v1.00a</b>
|
374 |
|
|
*
|
375 |
|
|
* . We have changes return type for XAxiDma_BdSetBufAddr() from void to int
|
376 |
|
|
* . We added XAxiDma_LookupConfig() so that user does not need to look for the
|
377 |
|
|
* hardware settings anymore.
|
378 |
|
|
*
|
379 |
|
|
* <pre>
|
380 |
|
|
* MODIFICATION HISTORY:
|
381 |
|
|
*
|
382 |
|
|
* Ver Who Date Changes
|
383 |
|
|
* ----- ---- -------- -------------------------------------------------------
|
384 |
|
|
* 1.00a jz 05/18/10 First release
|
385 |
|
|
* 2.00a jz 08/10/10 Second release, added in xaxidma_g.c, xaxidma_sinit.c,
|
386 |
|
|
* updated tcl file, added xaxidma_porting_guide.h
|
387 |
|
|
* 3.00a jz 11/22/10 Support IP core parameters change
|
388 |
|
|
* 4.00a rkv 02/22/11 Added support for simple DMA mode
|
389 |
|
|
* New API added for simple DMA mode are
|
390 |
|
|
* - XAxiDma_Busy
|
391 |
|
|
* - XAxiDma_SimpleTransfer
|
392 |
|
|
* New Macros added for simple DMA mode are
|
393 |
|
|
* - XAxiDma_HasSg
|
394 |
|
|
* - XAxiDma_IntrEnable
|
395 |
|
|
* - XAxiDma_IntrGetEnabled
|
396 |
|
|
* - XAxiDma_IntrDisable
|
397 |
|
|
* - XAxiDma_IntrGetIrq
|
398 |
|
|
* - XAxiDma_IntrAckIrq
|
399 |
|
|
* 5.00a srt 08/25/11 Added support for memory barrier and modified
|
400 |
|
|
* Cache Macros to have a common API for Microblaze
|
401 |
|
|
* and Zynq.
|
402 |
|
|
* 6.00a srt 01/24/12 Added support for Multi-Channel DMA mode.
|
403 |
|
|
* - Changed APIs:
|
404 |
|
|
* * XAxiDma_GetRxRing(InstancePtr, RingIndex)
|
405 |
|
|
* * XAxiDma_Start(XAxiDma * InstancePtr, int RingIndex)
|
406 |
|
|
* * XAxiDma_Started(XAxiDma * InstancePtr, int RingIndex)
|
407 |
|
|
* * XAxiDma_Pause(XAxiDma * InstancePtr, int RingIndex)
|
408 |
|
|
* * XAxiDma_Resume(XAxiDma * InstancePtr, int RingIndex)
|
409 |
|
|
* * XAxiDma_SimpleTransfer(XAxiDma *InstancePtr,
|
410 |
|
|
* u32 BuffAddr, u32 Length,
|
411 |
|
|
* int Direction, int RingIndex)
|
412 |
|
|
* * XAxiDma_StartBdRingHw(XAxiDma_BdRing * RingPtr,
|
413 |
|
|
* int RingIndex)
|
414 |
|
|
* * XAxiDma_BdRingStart(XAxiDma_BdRing * RingPtr,
|
415 |
|
|
* int RingIndex)
|
416 |
|
|
* * XAxiDma_BdRingToHw(XAxiDma_BdRing * RingPtr,
|
417 |
|
|
* int NumBd, XAxiDma_Bd * BdSetPtr, int RingIndex)
|
418 |
|
|
* * XAxiDma_BdRingDumpRegs(XAxiDma_BdRing * RingPtr,
|
419 |
|
|
* int RingIndex)
|
420 |
|
|
* * XAxiDma_BdRingSnapShotCurrBd(XAxiDma_BdRing * RingPtr,
|
421 |
|
|
* int RingIndex)
|
422 |
|
|
* * XAxiDma_BdSetLength(XAxiDma_Bd *BdPtr,
|
423 |
|
|
* u32 LenBytes, u32 LengthMask)
|
424 |
|
|
* * XAxiDma_BdGetActualLength(BdPtr, LengthMask)
|
425 |
|
|
* * XAxiDma_BdGetLength(BdPtr, LengthMask)
|
426 |
|
|
* - New APIs
|
427 |
|
|
* * XAxiDma_SelectKeyHole(XAxiDma *InstancePtr,
|
428 |
|
|
* int Direction, int Select)
|
429 |
|
|
* * XAxiDma_UpdateBdRingCDesc(XAxiDma_BdRing * RingPtr,
|
430 |
|
|
* int RingIndex)
|
431 |
|
|
* 7.00a srt 06/18/12 All the APIs changed in v6_00_a are reverted back for
|
432 |
|
|
* backward compatibility.
|
433 |
|
|
* - New API:
|
434 |
|
|
* XAxiDma_GetRxIndexRing(InstancePtr, RingIndex)
|
435 |
|
|
* 7.01a srt 10/26/12 - Fixed issue with driver as it fails with IP version
|
436 |
|
|
* < 6.00a as the parameter C_NUM_*_CHANNELS is not
|
437 |
|
|
* applicable.
|
438 |
|
|
* - Changed the logic of MCDMA BD fields Set APIs, to
|
439 |
|
|
* clear the field first and then set it.
|
440 |
|
|
* 7.02a srt 01/23/13 Replaced *_TDATA_WIDTH parameters to *_DATA_WIDTH
|
441 |
|
|
* (CR 691867)
|
442 |
|
|
* Updated DDR base address for IPI designs (CR 703656).
|
443 |
|
|
* 8.0 adk 19/12/13 Updated as per the New Tcl API's
|
444 |
|
|
* srt 01/29/14 Added support for Micro DMA Mode and cyclic mode of
|
445 |
|
|
* operations.
|
446 |
|
|
* - New APIs:
|
447 |
|
|
* * XAxiDma_SelectCyclicMode(XAxiDma *InstancePtr,
|
448 |
|
|
* int Direction, int Select)
|
449 |
|
|
* * XAxiDma_BdSetBufAddrMicroMode(XAxiDma_Bd*, u32)
|
450 |
|
|
* 8.1 adk 20/01/15 Added support for peripheral test. Created the self
|
451 |
|
|
* test example to include it on peripheral test's(CR#823144).
|
452 |
|
|
* 8.1 adk 29/01/15 Added the sefltest api (XAxiDma_Selftest) to the driver source files
|
453 |
|
|
* (xaxidma_selftest.c) and called this from the selftest example
|
454 |
|
|
* 9.0 adk 27/07/15 Added support for 64-bit Addressing.
|
455 |
|
|
* 9.0 adk 19/08/15 Fixed CR#873125 DMA SG Mode example tests are failing on
|
456 |
|
|
* HW in 2015.3.
|
457 |
|
|
*
|
458 |
|
|
* </pre>
|
459 |
|
|
*
|
460 |
|
|
******************************************************************************/
|
461 |
|
|
|
462 |
|
|
#ifndef XAXIDMA_H_ /* prevent circular inclusions */
|
463 |
|
|
#define XAXIDMA_H_
|
464 |
|
|
|
465 |
|
|
#ifdef __cplusplus
|
466 |
|
|
extern "C" {
|
467 |
|
|
#endif
|
468 |
|
|
|
469 |
|
|
/***************************** Include Files *********************************/
|
470 |
|
|
#include "xaxidma_bdring.h"
|
471 |
|
|
#ifdef __MICROBLAZE__
|
472 |
|
|
#include "xenv.h"
|
473 |
|
|
#else
|
474 |
|
|
#include <string.h>
|
475 |
|
|
#include "xil_cache.h"
|
476 |
|
|
#endif
|
477 |
|
|
|
478 |
|
|
/************************** Constant Definitions *****************************/
|
479 |
|
|
|
480 |
|
|
|
481 |
|
|
/**************************** Type Definitions *******************************/
|
482 |
|
|
|
483 |
|
|
/**
|
484 |
|
|
* The XAxiDma driver instance data. An instance must be allocated for each DMA
|
485 |
|
|
* engine in use.
|
486 |
|
|
*/
|
487 |
|
|
typedef struct XAxiDma {
|
488 |
|
|
u32 RegBase; /* Virtual base address of DMA engine */
|
489 |
|
|
|
490 |
|
|
int HasMm2S; /* Has transmit channel */
|
491 |
|
|
int HasS2Mm; /* Has receive channel */
|
492 |
|
|
int Initialized; /* Driver has been initialized */
|
493 |
|
|
int HasSg;
|
494 |
|
|
|
495 |
|
|
XAxiDma_BdRing TxBdRing; /* BD container management for TX channel */
|
496 |
|
|
XAxiDma_BdRing RxBdRing[16]; /* BD container management for RX channel */
|
497 |
|
|
int TxNumChannels;
|
498 |
|
|
int RxNumChannels;
|
499 |
|
|
int MicroDmaMode;
|
500 |
|
|
int AddrWidth; /**< Address Width */
|
501 |
|
|
} XAxiDma;
|
502 |
|
|
|
503 |
|
|
/**
|
504 |
|
|
* The configuration structure for AXI DMA engine
|
505 |
|
|
*
|
506 |
|
|
* This structure passes the hardware building information to the driver
|
507 |
|
|
*/
|
508 |
|
|
typedef struct {
|
509 |
|
|
u32 DeviceId;
|
510 |
|
|
u32 BaseAddr;
|
511 |
|
|
|
512 |
|
|
int HasStsCntrlStrm;
|
513 |
|
|
int HasMm2S;
|
514 |
|
|
int HasMm2SDRE;
|
515 |
|
|
int Mm2SDataWidth;
|
516 |
|
|
int HasS2Mm;
|
517 |
|
|
int HasS2MmDRE;
|
518 |
|
|
int S2MmDataWidth;
|
519 |
|
|
int HasSg;
|
520 |
|
|
int Mm2sNumChannels;
|
521 |
|
|
int S2MmNumChannels;
|
522 |
|
|
int Mm2SBurstSize;
|
523 |
|
|
int S2MmBurstSize;
|
524 |
|
|
int MicroDmaMode;
|
525 |
|
|
int AddrWidth; /**< Address Width */
|
526 |
|
|
} XAxiDma_Config;
|
527 |
|
|
|
528 |
|
|
|
529 |
|
|
/***************** Macros (Inline Functions) Definitions *********************/
|
530 |
|
|
/*****************************************************************************/
|
531 |
|
|
/**
|
532 |
|
|
* Get Transmit (Tx) Ring ptr
|
533 |
|
|
*
|
534 |
|
|
* Warning: This has a different API than the LLDMA driver. It now returns
|
535 |
|
|
* the pointer to the BD ring.
|
536 |
|
|
*
|
537 |
|
|
* @param InstancePtr is a pointer to the DMA engine instance to be
|
538 |
|
|
* worked on.
|
539 |
|
|
*
|
540 |
|
|
* @return Pointer to the Tx Ring
|
541 |
|
|
*
|
542 |
|
|
* @note C-style signature:
|
543 |
|
|
* XAxiDma_BdRing * XAxiDma_GetTxRing(XAxiDma * InstancePtr)
|
544 |
|
|
* This function is used only when system is configured as SG mode
|
545 |
|
|
*
|
546 |
|
|
*****************************************************************************/
|
547 |
|
|
#define XAxiDma_GetTxRing(InstancePtr) \
|
548 |
|
|
(&((InstancePtr)->TxBdRing))
|
549 |
|
|
|
550 |
|
|
/*****************************************************************************/
|
551 |
|
|
/**
|
552 |
|
|
* Get Receive (Rx) Ring ptr
|
553 |
|
|
*
|
554 |
|
|
* Warning: This has a different API than the LLDMA driver. It now returns
|
555 |
|
|
* the pointer to the BD ring.
|
556 |
|
|
*
|
557 |
|
|
* @param InstancePtr is a pointer to the DMA engine instance to be
|
558 |
|
|
* worked on.
|
559 |
|
|
*
|
560 |
|
|
* @return Pointer to the Rx Ring
|
561 |
|
|
*
|
562 |
|
|
* @note
|
563 |
|
|
* C-style signature:
|
564 |
|
|
* XAxiDma_BdRing * XAxiDma_GetRxRing(XAxiDma * InstancePtr)
|
565 |
|
|
* This function is used only when system is configured as SG mode
|
566 |
|
|
*
|
567 |
|
|
*****************************************************************************/
|
568 |
|
|
#define XAxiDma_GetRxRing(InstancePtr) \
|
569 |
|
|
(&((InstancePtr)->RxBdRing[0]))
|
570 |
|
|
|
571 |
|
|
/*****************************************************************************/
|
572 |
|
|
/**
|
573 |
|
|
* Get Receive (Rx) Ring ptr of a Index
|
574 |
|
|
*
|
575 |
|
|
* Warning: This has a different API than the LLDMA driver. It now returns
|
576 |
|
|
* the pointer to the BD ring.
|
577 |
|
|
*
|
578 |
|
|
* @param InstancePtr is a pointer to the DMA engine instance to be
|
579 |
|
|
* worked on.
|
580 |
|
|
* @param RingIndex is the channel Index.
|
581 |
|
|
*
|
582 |
|
|
* @return Pointer to the Rx Ring
|
583 |
|
|
*
|
584 |
|
|
* @note
|
585 |
|
|
* C-style signature:
|
586 |
|
|
* XAxiDma_BdRing * XAxiDma_GetRxIndexRing(XAxiDma * InstancePtr,
|
587 |
|
|
int RingIndex)
|
588 |
|
|
* This function is used only when system is configured as SG mode
|
589 |
|
|
*
|
590 |
|
|
*****************************************************************************/
|
591 |
|
|
#define XAxiDma_GetRxIndexRing(InstancePtr, RingIndex) \
|
592 |
|
|
(&((InstancePtr)->RxBdRing[RingIndex]))
|
593 |
|
|
|
594 |
|
|
/*****************************************************************************/
|
595 |
|
|
/**
|
596 |
|
|
* This function checks whether system is configured as Simple or
|
597 |
|
|
* Scatter Gather mode
|
598 |
|
|
*
|
599 |
|
|
* @param InstancePtr is a pointer to the DMA engine instance to be
|
600 |
|
|
* worked on.
|
601 |
|
|
*
|
602 |
|
|
* @return
|
603 |
|
|
* - TRUE if configured as SG mode
|
604 |
|
|
* - FALSE if configured as simple mode
|
605 |
|
|
*
|
606 |
|
|
* @note None
|
607 |
|
|
*
|
608 |
|
|
*****************************************************************************/
|
609 |
|
|
#define XAxiDma_HasSg(InstancePtr) ((InstancePtr)->HasSg) ? TRUE : FALSE
|
610 |
|
|
|
611 |
|
|
/*****************************************************************************/
|
612 |
|
|
/**
|
613 |
|
|
* This function enables interrupts specified by the Mask in specified
|
614 |
|
|
* direction, Interrupts that are not in the mask are not affected.
|
615 |
|
|
*
|
616 |
|
|
* @param InstancePtr is the driver instance we are working on
|
617 |
|
|
* @param Mask is the mask for the interrupts to be enabled
|
618 |
|
|
* @param Direction is DMA transfer direction, valid values are
|
619 |
|
|
* - XAXIDMA_DMA_TO_DEVICE.
|
620 |
|
|
* - XAXIDMA_DEVICE_TO_DMA.
|
621 |
|
|
* @return None
|
622 |
|
|
*
|
623 |
|
|
* @note None
|
624 |
|
|
*
|
625 |
|
|
*****************************************************************************/
|
626 |
|
|
#define XAxiDma_IntrEnable(InstancePtr, Mask, Direction) \
|
627 |
|
|
XAxiDma_WriteReg((InstancePtr)->RegBase + \
|
628 |
|
|
(XAXIDMA_RX_OFFSET * Direction), XAXIDMA_CR_OFFSET, \
|
629 |
|
|
(XAxiDma_ReadReg((InstancePtr)->RegBase + \
|
630 |
|
|
(XAXIDMA_RX_OFFSET * Direction), XAXIDMA_CR_OFFSET)) \
|
631 |
|
|
| (Mask & XAXIDMA_IRQ_ALL_MASK))
|
632 |
|
|
|
633 |
|
|
|
634 |
|
|
/*****************************************************************************/
|
635 |
|
|
/**
|
636 |
|
|
* This function gets the mask for the interrupts that are currently enabled
|
637 |
|
|
*
|
638 |
|
|
* @param InstancePtr is the driver instance we are working on
|
639 |
|
|
* @param Direction is DMA transfer direction, valid values are
|
640 |
|
|
* - XAXIDMA_DMA_TO_DEVICE.
|
641 |
|
|
* - XAXIDMA_DEVICE_TO_DMA.
|
642 |
|
|
*
|
643 |
|
|
* @return The bit mask for the interrupts that are currently enabled
|
644 |
|
|
*
|
645 |
|
|
* @note None
|
646 |
|
|
*
|
647 |
|
|
*****************************************************************************/
|
648 |
|
|
#define XAxiDma_IntrGetEnabled(InstancePtr, Direction) \
|
649 |
|
|
XAxiDma_ReadReg((InstancePtr)->RegBase + \
|
650 |
|
|
(XAXIDMA_RX_OFFSET * Direction), XAXIDMA_CR_OFFSET) &\
|
651 |
|
|
XAXIDMA_IRQ_ALL_MASK)
|
652 |
|
|
|
653 |
|
|
|
654 |
|
|
|
655 |
|
|
/*****************************************************************************/
|
656 |
|
|
/**
|
657 |
|
|
* This function disables interrupts specified by the Mask. Interrupts that
|
658 |
|
|
* are not in the mask are not affected.
|
659 |
|
|
*
|
660 |
|
|
* @param InstancePtr is the driver instance we are working on
|
661 |
|
|
* @param Mask is the mask for the interrupts to be disabled
|
662 |
|
|
* @param Direction is DMA transfer direction, valid values are
|
663 |
|
|
* - XAXIDMA_DMA_TO_DEVICE.
|
664 |
|
|
* - XAXIDMA_DEVICE_TO_DMA.
|
665 |
|
|
* @return None
|
666 |
|
|
*
|
667 |
|
|
* @note None
|
668 |
|
|
*
|
669 |
|
|
*****************************************************************************/
|
670 |
|
|
#define XAxiDma_IntrDisable(InstancePtr, Mask, Direction) \
|
671 |
|
|
XAxiDma_WriteReg((InstancePtr)->RegBase + \
|
672 |
|
|
(XAXIDMA_RX_OFFSET * Direction), XAXIDMA_CR_OFFSET, \
|
673 |
|
|
(XAxiDma_ReadReg((InstancePtr)->RegBase + \
|
674 |
|
|
(XAXIDMA_RX_OFFSET * Direction), XAXIDMA_CR_OFFSET)) \
|
675 |
|
|
& ~(Mask & XAXIDMA_IRQ_ALL_MASK))
|
676 |
|
|
|
677 |
|
|
|
678 |
|
|
/*****************************************************************************/
|
679 |
|
|
/**
|
680 |
|
|
* This function gets the interrupts that are asserted.
|
681 |
|
|
*
|
682 |
|
|
* @param InstancePtr is the driver instance we are working on
|
683 |
|
|
* @param Direction is DMA transfer direction, valid values are
|
684 |
|
|
* - XAXIDMA_DMA_TO_DEVICE.
|
685 |
|
|
* - XAXIDMA_DEVICE_TO_DMA.
|
686 |
|
|
*
|
687 |
|
|
* @return The bit mask for the interrupts asserted.
|
688 |
|
|
*
|
689 |
|
|
* @note None
|
690 |
|
|
*
|
691 |
|
|
*****************************************************************************/
|
692 |
|
|
#define XAxiDma_IntrGetIrq(InstancePtr, Direction) \
|
693 |
|
|
(XAxiDma_ReadReg((InstancePtr)->RegBase + \
|
694 |
|
|
(XAXIDMA_RX_OFFSET * Direction), XAXIDMA_SR_OFFSET) &\
|
695 |
|
|
XAXIDMA_IRQ_ALL_MASK)
|
696 |
|
|
|
697 |
|
|
/*****************************************************************************/
|
698 |
|
|
/**
|
699 |
|
|
* This function acknowledges the interrupts that are specified in Mask
|
700 |
|
|
*
|
701 |
|
|
* @param InstancePtr is the driver instance we are working on
|
702 |
|
|
* @param Mask is the mask for the interrupts to be acknowledge
|
703 |
|
|
* @param Direction is DMA transfer direction, valid values are
|
704 |
|
|
* - XAXIDMA_DMA_TO_DEVICE.
|
705 |
|
|
* - XAXIDMA_DEVICE_TO_DMA.
|
706 |
|
|
*
|
707 |
|
|
* @return None
|
708 |
|
|
*
|
709 |
|
|
* @note None.
|
710 |
|
|
*
|
711 |
|
|
*****************************************************************************/
|
712 |
|
|
#define XAxiDma_IntrAckIrq(InstancePtr, Mask, Direction) \
|
713 |
|
|
XAxiDma_WriteReg((InstancePtr)->RegBase + \
|
714 |
|
|
(XAXIDMA_RX_OFFSET * Direction), XAXIDMA_SR_OFFSET, \
|
715 |
|
|
(Mask) & XAXIDMA_IRQ_ALL_MASK)
|
716 |
|
|
|
717 |
|
|
|
718 |
|
|
|
719 |
|
|
/************************** Function Prototypes ******************************/
|
720 |
|
|
|
721 |
|
|
/*
|
722 |
|
|
* Initialization and control functions in xaxidma.c
|
723 |
|
|
*/
|
724 |
|
|
XAxiDma_Config *XAxiDma_LookupConfig(u32 DeviceId);
|
725 |
|
|
int XAxiDma_CfgInitialize(XAxiDma * InstancePtr, XAxiDma_Config *Config);
|
726 |
|
|
void XAxiDma_Reset(XAxiDma * InstancePtr);
|
727 |
|
|
int XAxiDma_ResetIsDone(XAxiDma * InstancePtr);
|
728 |
|
|
int XAxiDma_Pause(XAxiDma * InstancePtr);
|
729 |
|
|
int XAxiDma_Resume(XAxiDma * InstancePtr);
|
730 |
|
|
u32 XAxiDma_Busy(XAxiDma *InstancePtr,int Direction);
|
731 |
|
|
u32 XAxiDma_SimpleTransfer(XAxiDma *InstancePtr, UINTPTR BuffAddr, u32 Length,
|
732 |
|
|
int Direction);
|
733 |
|
|
int XAxiDma_SelectKeyHole(XAxiDma *InstancePtr, int Direction, int Select);
|
734 |
|
|
int XAxiDma_SelectCyclicMode(XAxiDma *InstancePtr, int Direction, int Select);
|
735 |
|
|
int XAxiDma_Selftest(XAxiDma * InstancePtr);
|
736 |
|
|
#ifdef __cplusplus
|
737 |
|
|
}
|
738 |
|
|
#endif
|
739 |
|
|
|
740 |
|
|
#endif /* end of protection macro */
|
741 |
|
|
/** @} */
|