1 /*****************************************************************************
3 * (c) Copyright 2009-2013 Xilinx, Inc. All rights reserved.
5 * This file contains confidential and proprietary information of Xilinx, Inc.
6 * and is protected under U.S. and international copyright and other
7 * intellectual property laws.
10 * This disclaimer is not a license and does not grant any rights to the
11 * materials distributed herewith. Except as otherwise provided in a valid
12 * license issued to you by Xilinx, and to the maximum extent permitted by
13 * applicable law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND WITH ALL
14 * FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS,
15 * IMPLIED, OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
16 * MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE;
17 * and (2) Xilinx shall not be liable (whether in contract or tort, including
18 * negligence, or under any other theory of liability) for any loss or damage
19 * of any kind or nature related to, arising under or in connection with these
20 * materials, including for any direct, or any indirect, special, incidental,
21 * or consequential loss or damage (including loss of data, profits, goodwill,
22 * or any type of loss or damage suffered as a result of any action brought by
23 * a third party) even if such damage or loss was reasonably foreseeable or
24 * Xilinx had been advised of the possibility of the same.
26 * CRITICAL APPLICATIONS
27 * Xilinx products are not designed or intended to be fail-safe, or for use in
28 * any application requiring fail-safe performance, such as life-support or
29 * safety devices or systems, Class III medical devices, nuclear facilities,
30 * applications related to the deployment of airbags, or any other applications
31 * that could lead to death, personal injury, or severe property or
32 * environmental damage (individually and collectively, "Critical
33 * Applications"). Customer assumes the sole risk and liability of any use of
34 * Xilinx products in Critical Applications, subject only to applicable laws
35 * and regulations governing limitations on product liability.
37 * THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS PART OF THIS FILE
40 *****************************************************************************/
41 /****************************************************************************/
48 * MODIFICATION HISTORY:
50 * Ver Who Date Changes
51 * ----- ------ -------- ----------------------------------------------
52 * 1.00 hbm 08/19/10 First Release
53 * 1.01a nm 12/20/12 Added definition XDMAPS_CHANNELS_PER_DEV which specifies
54 * the maximum number of channels.
55 * Replaced the usage of XPAR_XDMAPS_CHANNELS_PER_DEV
56 * with XDMAPS_CHANNELS_PER_DEV defined in xdmaps_hw.h.
57 * Added the tcl file to automatically generate the
59 * 1.02a sg 05/16/12 Made changes for doxygen and moved some function
60 * header from the xdmaps.h file to xdmaps.c file
61 * Other cleanup for coding guidelines and CR 657109
63 * The xdmaps_example_no_intr.c example is removed
64 * as it is using interrupts and is similar to
65 * the interrupt example - CR 652477
66 * 1.03a sg 07/16/2012 changed inline to __inline for CR665681
67 * 1.04a nm 10/22/2012 Fixed CR# 681671.
68 * 1.05a nm 04/15/2013 Fixed CR# 704396. Removed warnings when compiled
69 * with -Wall and -Wextra option in bsp.
70 * 05/01/2013 Fixed CR# 700189. Changed XDmaPs_BuildDmaProg()
71 * function description.
72 * Fixed CR# 704396. Removed unused variables
73 * UseM2MByte & MemBurstLen from XDmaPs_BuildDmaProg()
75 * 1.07a asa 11/02/13. Made changes to fix compilation issues for iarcc.
76 * Removed the PDBG prints. By default they were always
77 * defined out and never used. The PDBG is non-standard for
78 * Xilinx drivers and no other driver does something similar.
79 * Since there is no easy way to fix compilation issues with
80 * the IARCC compiler around PDBG, it is better to remove it.
81 * Users can always use xil_printfs if they want to debug.
82 * 2.0 adk 10/12/13 Updated as per the New Tcl API's
85 *****************************************************************************/
87 #ifndef XDMAPS_H /* prevent circular inclusions */
88 #define XDMAPS_H /* by using protection macros */
94 /***************************** Include Files ********************************/
96 #include "xparameters.h"
97 #include "xil_types.h"
98 #include "xil_assert.h"
101 #include "xdmaps_hw.h"
103 /************************** Constant Definitions ****************************/
105 /**************************** Type Definitions ******************************/
108 * This typedef contains configuration information for the device.
111 u16 DeviceId; /**< Unique ID of device */
112 u32 BaseAddress; /**< Base address of device (IPIF) */
116 /** DMA channle control structure. It's for AXI bus transaction.
117 * This struct will be translated into a 32-bit channel control register value.
120 unsigned int EndianSwapSize; /**< Endian swap size. */
121 unsigned int DstCacheCtrl; /**< Destination cache control */
122 unsigned int DstProtCtrl; /**< Destination protection control */
123 unsigned int DstBurstLen; /**< Destination burst length */
124 unsigned int DstBurstSize; /**< Destination burst size */
125 unsigned int DstInc; /**< Destination incrementing or fixed
127 unsigned int SrcCacheCtrl; /**< Source cache control */
128 unsigned int SrcProtCtrl; /**< Source protection control */
129 unsigned int SrcBurstLen; /**< Source burst length */
130 unsigned int SrcBurstSize; /**< Source burst size */
131 unsigned int SrcInc; /**< Source incrementing or fixed
135 /** DMA block descriptor stucture.
138 u32 SrcAddr; /**< Source starting address */
139 u32 DstAddr; /**< Destination starting address */
140 unsigned int Length; /**< Number of bytes for the block */
144 * A DMA command consisits of a channel control struct, a block descriptor,
145 * a user defined program, a pointer pointing to generated DMA program, and
150 XDmaPs_ChanCtrl ChanCtrl; /**< Channel Control Struct */
151 XDmaPs_BD BD; /**< Together with SgLength field,
152 * it's a scatter-gather list.
154 void *UserDmaProg; /**< If user wants the driver to
155 * execute their own DMA program,
156 * this field points to the DMA
159 int UserDmaProgLength; /**< The length of user defined
163 void *GeneratedDmaProg; /**< The DMA program genreated
164 * by the driver. This field will be
165 * set if a user invokes the DMA
166 * program generation function. Or
167 * the DMA command is finished and
168 * a user informs the driver not to
169 * release the program buffer.
170 * This field has two purposes, one
171 * is to ask the driver to generate
172 * a DMA program while the DMAC is
173 * performaning DMA transactions. The
174 * other purpose is to debug the
177 int GeneratedDmaProgLength; /**< The length of the DMA program
178 * generated by the driver
180 int DmaStatus; /**< 0 on success, otherwise error code
182 u32 ChanFaultType; /**< Channel fault type in case of fault
184 u32 ChanFaultPCAddr; /**< Channel fault PC address
189 * It's the done handler a user can set for a channel
191 typedef void (*XDmaPsDoneHandler) (unsigned int Channel,
196 * It's the fault handler a user can set for a channel
198 typedef void (*XDmaPsFaultHandler) (unsigned int Channel,
202 #define XDMAPS_MAX_CHAN_BUFS 2
203 #define XDMAPS_CHAN_BUF_LEN 128
206 * The XDmaPs_ProgBuf is the struct for a DMA program buffer.
209 char Buf[XDMAPS_CHAN_BUF_LEN]; /**< The actual buffer the holds the
211 unsigned Len; /**< The actual length of the DMA
212 * program in bytes. */
213 int Allocated; /**< A tag indicating whether the
214 * buffer is allocated or not */
218 * The XDmaPs_ChannelData is a struct to book keep individual channel of
222 unsigned DevId; /**< Device id indicating which DMAC */
223 unsigned ChanId; /**< Channel number of the DMAC */
224 XDmaPs_ProgBuf ProgBufPool[XDMAPS_MAX_CHAN_BUFS]; /**< A pool of
226 XDmaPsDoneHandler DoneHandler; /**< Done interrupt handler */
227 void *DoneRef; /**< Done interrupt callback data */
228 XDmaPs_Cmd *DmaCmdToHw; /**< DMA command being executed */
229 XDmaPs_Cmd *DmaCmdFromHw; /**< DMA command that is finished.
230 * This field is for debugging purpose
232 int HoldDmaProg; /**< A tag indicating whether to hold the
233 * DMA program after the DMA is done.
236 } XDmaPs_ChannelData;
239 * The XDmaPs driver instance data structure. A pointer to an instance data
240 * structure is passed around by functions to refer to a specific driver
244 XDmaPs_Config Config; /**< Configuration data structure */
245 int IsReady; /**< Device is Ready */
246 int CacheLength; /**< icache length */
247 XDmaPsFaultHandler FaultHandler; /**< fault interrupt handler */
248 void *FaultRef; /**< fault call back data */
249 XDmaPs_ChannelData Chans[XDMAPS_CHANNELS_PER_DEV];
256 * Functions implemented in xdmaps.c
258 int XDmaPs_CfgInitialize(XDmaPs *InstPtr,
259 XDmaPs_Config *Config,
262 int XDmaPs_Start(XDmaPs *InstPtr, unsigned int Channel,
266 int XDmaPs_IsActive(XDmaPs *InstPtr, unsigned int Channel);
267 int XDmaPs_GenDmaProg(XDmaPs *InstPtr, unsigned int Channel,
269 int XDmaPs_FreeDmaProg(XDmaPs *InstPtr, unsigned int Channel,
271 void XDmaPs_Print_DmaProg(XDmaPs_Cmd *Cmd);
274 int XDmaPs_ResetManager(XDmaPs *InstPtr);
275 int XDmaPs_ResetChannel(XDmaPs *InstPtr, unsigned int Channel);
278 int XDmaPs_SetDoneHandler(XDmaPs *InstPtr,
280 XDmaPsDoneHandler DoneHandler,
283 int XDmaPs_SetFaultHandler(XDmaPs *InstPtr,
284 XDmaPsFaultHandler FaultHandler,
287 void XDmaPs_Print_DmaProg(XDmaPs_Cmd *Cmd);
290 * Driver done interrupt service routines for the channels.
291 * We need this done ISR mainly because the driver needs to release the
292 * DMA program buffer. This is the one that connects the GIC
294 void XDmaPs_DoneISR_0(XDmaPs *InstPtr);
295 void XDmaPs_DoneISR_1(XDmaPs *InstPtr);
296 void XDmaPs_DoneISR_2(XDmaPs *InstPtr);
297 void XDmaPs_DoneISR_3(XDmaPs *InstPtr);
298 void XDmaPs_DoneISR_4(XDmaPs *InstPtr);
299 void XDmaPs_DoneISR_5(XDmaPs *InstPtr);
300 void XDmaPs_DoneISR_6(XDmaPs *InstPtr);
301 void XDmaPs_DoneISR_7(XDmaPs *InstPtr);
304 * Driver fault interrupt service routine
306 void XDmaPs_FaultISR(XDmaPs *InstPtr);
310 * Static loopup function implemented in xdmaps_sinit.c
312 XDmaPs_Config *XDmaPs_LookupConfig(u16 DeviceId);
316 * self-test functions in xdmaps_selftest.c
318 int XDmaPs_SelfTest(XDmaPs *InstPtr);
325 #endif /* end of protection macro */