1 /******************************************************************************
3 * Copyright (C) 2014 Xilinx, Inc. All rights reserved.
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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.
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
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.
31 ******************************************************************************/
32 /*****************************************************************************/
35 * ZDMA is a general purpose DMA designed to support memory to memory and memory
36 * to IO buffer transfers. ALTO has two instance of general purpose ZDMA.
37 * One is located in FPD (full power domain) which is GDMA and other is located
38 * in LPD (low power domain) which is ADMA.
40 * GMDA & ADMA are configured each with 8 DMA channels and and each channel can
41 * be programmed secure or non-secure.
42 * Each channel is divided into two functional sides, Source (Read) and
43 * Destination (Write). Each DMA channel can be independently programmed
44 * in one of following DMA modes.
46 * - Normal data transfer from source to destination.
49 * - Scatter Gather DMA
50 * - Only Normal mode it can't support other two modes.
51 * In Scatter gather descriptor can be of 3 types
52 * - Linear descriptor.
53 * - Linked list descriptor
54 * - Hybrid descriptor (Combination of both Linear and Linked list)
55 * Our driver will not support Hybrid type of descriptor.
57 * <b>Initialization & Configuration</b>
59 * The device driver enables higher layer software (e.g., an application) to
60 * communicate to the ZDMA core.
62 * XZDma_CfgInitialize() API is used to initialize the ZDMA core.
63 * The user needs to first call the XZDma_LookupConfig() API which returns
64 * the Configuration structure pointer which is passed as a parameter to the
65 * XZDma_CfgInitialize() API.
68 * The driver provides an interrupt handler XZDma_IntrHandler for handling
69 * the interrupt from the ZDMA core. The users of this driver have to
70 * register this handler with the interrupt system and provide the callback
71 * functions by using XZDma_SetCallBack API. In this version Descriptor done
74 * <b> Virtual Memory </b>
76 * This driver supports Virtual Memory. The RTOS is responsible for calculating
77 * the correct device base address in Virtual Memory space.
81 * This driver is not thread safe. Any needs for threads or thread mutual
82 * exclusion must be satisfied by the layer above this driver.
86 * Asserts are used within all Xilinx drivers to enforce constraints on argument
87 * values. Asserts can be turned off on a system-wide basis by defining, at
88 * compile time, the NDEBUG identifier. By default, asserts are turned on and it
89 * is recommended that users leave asserts on during development.
91 * <b> Building the driver </b>
93 * The XZDma driver is composed of several source files. This allows the user
94 * to build and link only those parts of the driver that are necessary.
98 * This header file contains identifiers and register-level driver functions (or
99 * macros), range macros, structure typedefs that can be used to access the
100 * Xilinx ZDMA core instance.
103 * MODIFICATION HISTORY:
105 * Ver Who Date Changes
106 * ----- ------ -------- ------------------------------------------------------
107 * 1.0 vns 2/27/15 First release
110 ******************************************************************************/
118 /***************************** Include Files *********************************/
120 #include "xzdma_hw.h"
121 #include "xil_assert.h"
123 #include "xil_cache.h"
125 /************************** Constant Definitions *****************************/
128 /**************************** Type Definitions *******************************/
130 /** @name ZDMA Handler Types
134 XZDMA_HANDLER_DONE, /**< For Done Handler */
135 XZDMA_HANDLER_ERROR, /**< For Error Handler */
139 /** @name ZDMA Descriptors Types
143 XZDMA_LINEAR, /**< Linear descriptor */
144 XZDMA_LINKEDLIST, /**< Linked list descriptor */
148 /** @name ZDMA Operation modes
152 XZDMA_NORMAL_MODE, /**< Normal transfer from source to
154 XZDMA_WRONLY_MODE, /**< Write only mode */
155 XZDMA_RDONLY_MODE /**< Read only mode */
163 XZDMA_IDLE, /**< ZDMA is in Idle state */
164 XZDMA_PAUSE, /**< Paused state */
165 XZDMA_BUSY, /**< Busy state */
169 /** @name ZDMA AXI Burst type
173 XZDMA_FIXED_BURST = 0, /**< Fixed burst type */
174 XZDMA_INCR_BURST /**< Increment burst type */
178 /******************************************************************************/
180 * This typedef contains scatter gather descriptor fields for ZDMA core.
183 void *SrcDscrPtr; /**< Source Descriptor pointer */
184 void *DstDscrPtr; /**< Destination Descriptor pointer */
185 u32 DscrCount; /**< Count of descriptors available */
186 XZDma_DscrType DscrType;/**< Type of descriptor either Linear or
187 * Linked list type */
190 /******************************************************************************/
192 * This typedef contains scatter gather descriptor fields for ZDMA core.
195 u64 Address; /**< Address */
196 u32 Size; /**< Word2, Size of data */
197 u32 Cntl; /**< Word3 Control data */
198 u64 NextDscr; /**< Address of next descriptor */
199 u64 Reserved; /**< Reserved address */
200 } __attribute__ ((packed)) XZDma_LlDscr;
202 /******************************************************************************/
204 * This typedef contains Linear descriptor fields for ZDMA core.
207 u64 Address; /**< Address */
208 u32 Size; /**< Word3, Size of data */
209 u32 Cntl; /**< Word4, control data */
210 } __attribute__ ((packed)) XZDma_LiDscr;
212 /******************************************************************************/
215 * This typedef contains the data configurations of ZDMA core
218 u8 OverFetch; /**< Enable Over fetch */
219 u8 SrcIssue; /**< Outstanding transactions for Source */
220 XZDma_BurstType SrcBurstType;
221 /**< Burst type for SRC */
222 u8 SrcBurstLen; /**< AXI length for data read */
223 XZDma_BurstType DstBurstType;
224 /**< Burst type for DST */
225 u8 DstBurstLen; /**< AXI length for data write */
226 u8 SrcCache; /**< AXI cache bits for data read */
227 u8 SrcQos; /**< AXI QOS bits for data read */
228 u8 DstCache; /**< AXI cache bits for data write */
229 u8 DstQos; /**< AXI QOS bits for data write */
232 /******************************************************************************/
235 * This typedef contains the descriptor configurations of ZDMA core
238 u8 AxCoherent; /**< AXI transactions are coherent or non-coherent */
239 u8 AXCache; /**< AXI cache for DSCR fetch */
240 u8 AXQos; /**< Qos bit for DSCR fetch */
243 /******************************************************************************/
245 * Callback type for Completion of all data transfers.
247 * @param CallBackRef is a callback reference passed in by the upper layer
248 * when setting the callback functions, and passed back to the
249 * upper layer when the callback is invoked.
250 *******************************************************************************/
251 typedef void (*XZDma_DoneHandler) (void *CallBackRef);
253 /******************************************************************************/
255 * Callback type for all error interrupts.
257 * @param CallBackRef is a callback reference passed in by the upper layer
258 * when setting the callback functions, and passed back to the
259 * upper layer when the callback is invoked.
260 * @param ErrorMask is a bit mask indicating the cause of the error. Its
261 * value equals 'OR'ing one or more XZDMA_IXR_* values defined in
263 ****************************************************************************/
264 typedef void (*XZDma_ErrorHandler) (void *CallBackRef, u32 ErrorMask);
267 * This typedef contains configuration information for a ZDMA core
268 * Each ZDMA core should have a configuration structure associated.
271 u16 DeviceId; /**< Device Id of ZDMA */
272 u32 BaseAddress; /**< BaseAddress of ZDMA */
273 u8 DmaType; /**< Type of DMA */
276 /******************************************************************************/
279 * The XZDma driver instance data structure. A pointer to an instance data
280 * structure is passed around by functions to refer to a specific driver
284 XZDma_Config Config; /**< Hardware configuration */
285 u32 IsReady; /**< Device and the driver instance
287 u32 IntrMask; /**< Mask for enabling interrupts */
289 XZDma_Mode Mode; /**< Mode of ZDMA core to be operated */
290 u8 IsSgDma; /**< Is ZDMA core is in scatter gather or
291 * not will be specified */
292 XZDma_Descriptor Descriptor; /**< It contains information about
295 XZDma_DoneHandler DoneHandler; /**< Call back for transfer
297 void *DoneRef; /**< To be passed to the done
298 * interrupt callback */
300 XZDma_ErrorHandler ErrorHandler;/**< Call back for error
302 void *ErrorRef; /**< To be passed to the error
303 * interrupt callback */
304 XZDma_DataConfig DataConfig; /**< Current configurations */
305 XZDma_DscrConfig DscrConfig; /**< Current configurations */
306 XZDmaState ChannelState; /**< ZDMA channel is busy */
310 /******************************************************************************/
313 * This typedef contains the fields for transfer of data.
316 UINTPTR SrcAddr; /**< Source address */
317 UINTPTR DstAddr; /**< Destination Address */
318 u32 Size; /**< Size of the data to be transferred */
319 u8 SrcCoherent; /**< Source coherent */
320 u8 DstCoherent; /**< Destination coherent */
321 u8 Pause; /**< Will pause data transmission after
322 * this transfer only for SG mode */
325 /***************** Macros (Inline Functions) Definitions *********************/
327 /*****************************************************************************/
330 * This function returns interrupt status read from Interrupt Status Register.
331 * Use the XZDMA_IXR_DMA_*_MASK constants defined in xzdma_hw.h to interpret the
334 * @param InstancePtr is a pointer to the XZDma instance.
336 * @return The pending interrupts of the ZDMA core.
337 * Use the masks specified in xzdma_hw.h to interpret
338 * the returned value.
341 * void XZDma_IntrGetStatus(XZDma *InstancePtr)
343 ******************************************************************************/
344 #define XZDma_IntrGetStatus(InstancePtr) \
345 XZDma_ReadReg((InstancePtr)->Config.BaseAddress, XZDMA_CH_ISR_OFFSET)
347 /*****************************************************************************/
350 * This function clears interrupt(s). Every bit set in Interrupt Status
351 * Register indicates that a specific type of interrupt is occurring, and this
352 * function clears one or more interrupts by writing a bit mask to Interrupt
355 * @param InstancePtr is a pointer to the XZDma instance.
356 * @param Mask is the type of the interrupts to enable. Use OR'ing of
357 * XZDMA_IXR_DMA_*_MASK constants defined in xzdma_hw.h to create
358 * this parameter value.
364 * void XZDma_IntrClear(XZDma *InstancePtr)
366 ******************************************************************************/
367 #define XZDma_IntrClear(InstancePtr, Mask) \
368 XZDma_WriteReg( (InstancePtr)->Config.BaseAddress, \
369 XZDMA_CH_ISR_OFFSET, ((u32)(Mask) & (u32)XZDMA_IXR_ALL_INTR_MASK))
371 /*****************************************************************************/
374 * This function returns interrupt mask to know which interrupts are
375 * enabled and which of them were disabled.
377 * @param InstancePtr is a pointer to the XZDma instance.
379 * @return The current interrupt mask. The mask indicates which interrupts
380 * are enabled/disabled.
381 * 0 bit represents .....corresponding interrupt is enabled.
382 * 1 bit represents .....Corresponding interrupt is disabled.
386 * void XZDma_GetIntrMask(XZDma *InstancePtr)
388 ******************************************************************************/
389 #define XZDma_GetIntrMask(InstancePtr) \
390 XZDma_ReadReg((InstancePtr)->Config.BaseAddress, \
391 (u32)(XZDMA_CH_IMR_OFFSET))
393 /*****************************************************************************/
396 * This function enables individual interrupts of the ZDMA core by updating
397 * the Interrupt Enable register.
399 * @param InstancePtr is a pointer to the XZDma instance.
400 * @param Mask is the type of the interrupts to enable. Use OR'ing of
401 * XZDMA_IXR_DMA_*_MASK constants defined in xzdma_hw.h to create
402 * this parameter value.
406 * @note The existing enabled interrupt(s) will remain enabled.
408 * void XZDma_EnableIntr(XZDma *InstancePtr, u32 Mask)
410 ******************************************************************************/
411 #define XZDma_EnableIntr(InstancePtr, Mask) \
412 (InstancePtr)->IntrMask = ((InstancePtr)->IntrMask | (Mask))
414 /*****************************************************************************/
417 * This function disables individual interrupts of the ZDMA core by updating
418 * the Interrupt Disable register.
420 * @param InstancePtr is a pointer to the XZDma instance.
421 * @param Mask is the type of the interrupts to disable. Use OR'ing of
422 * XZDMA_IXR_DMA_*_MASK constants defined in xzdma_hw.h to create
423 * this parameter value.
427 * @note The existing disabled interrupt(s) will remain disabled.
429 * void XZDma_DisableIntr(XZDma *InstancePtr, u32 Mask)
431 ******************************************************************************/
432 #define XZDma_DisableIntr(InstancePtr, Mask) \
433 XZDma_WriteReg( (InstancePtr)->Config.BaseAddress, \
434 XZDMA_CH_IDS_OFFSET, \
435 ((u32)XZDma_ReadReg((InstancePtr)->Config.BaseAddress, \
436 XZDMA_CH_IDS_OFFSET) | ((u32)(Mask) & (u32)XZDMA_IXR_ALL_INTR_MASK)))
438 /*****************************************************************************/
441 * This function returns source current payload address under process
444 * @param InstancePtr is a pointer to the XZDma instance.
448 * @note This address may not be precise due to ZDMA pipeline structure
450 * u64 XZDma_SrcCurPyld(XZDma *InstancePtr)
452 ******************************************************************************/
453 #define XZDma_SrcCurPyld(InstancePtr) \
454 ((u64)(XZDma_ReadReg((InstancePtr)->Config.BaseAddress, \
455 XZDMA_CH_SRC_CUR_PYLD_LSB_OFFSET)) | \
456 ((u64)(XZDma_ReadReg((InstancePtr)->Config.BaseAddress, \
457 XZDMA_CH_SRC_CUR_PYLD_MSB_OFFSET)) << XZDMA_WORD1_MSB_SHIFT))
459 /*****************************************************************************/
462 * This function returns destination current payload address under process
465 * @param InstancePtr is a pointer to the XZDma instance.
469 * @note This address may not be precise due to ZDMA pipeline structure
471 * u64 XZDma_DstCurPyld(XZDma *InstancePtr)
473 ******************************************************************************/
474 #define XZDma_DstCurPyld(InstancePtr) \
475 ((u64)(XZDma_ReadReg((InstancePtr)->Config.BaseAddress, \
476 XZDMA_CH_DST_CUR_PYLD_LSB_OFFSET)) | \
477 ((u64)(XZDma_ReadReg((InstancePtr)->Config.BaseAddress, \
478 XZDMA_CH_DST_CUR_PYLD_MSB_OFFSET)) << XZDMA_WORD1_MSB_SHIFT))
480 /*****************************************************************************/
483 * This function returns source descriptor current payload address under
484 * process of ZDMA core.
486 * @param InstancePtr is a pointer to the XZDma instance.
490 * @note This address may not be precise due to ZDMA pipeline structure
492 * u64 XZDma_SrcDscrCurPyld(XZDma *InstancePtr)
494 ******************************************************************************/
495 #define XZDma_SrcDscrCurPyld(InstancePtr) \
496 ((u64)(XZDma_ReadReg((InstancePtr)->Config.BaseAddress, \
497 XZDMA_CH_SRC_CUR_DSCR_LSB_OFFSET)) | \
498 ((u64)(XZDma_ReadReg((InstancePtr)->Config.BaseAddress, \
499 XZDMA_CH_SRC_CUR_DSCR_MSB_OFFSET)) << XZDMA_WORD1_MSB_SHIFT))
502 /*****************************************************************************/
505 * This function returns destination descriptor current payload address under
506 * process of ZDMA core.
508 * @param InstancePtr is a pointer to the XZDma instance.
512 * @note This address may not be precise due to ZDMA pipeline structure
514 * u64 XZDma_DstDscrCurPyld(XZDma *InstancePtr)
516 ******************************************************************************/
517 #define XZDma_DstDscrCurPyld(InstancePtr) \
518 ((u64)(XZDma_ReadReg((InstancePtr)->Config.BaseAddress, \
519 XZDMA_CH_DST_CUR_DSCR_LSB_OFFSET)) | \
520 ((u64)(XZDma_ReadReg((InstancePtr)->Config.BaseAddress, \
521 XZDMA_CH_DST_CUR_DSCR_MSB_OFFSET)) << XZDMA_WORD1_MSB_SHIFT))
523 /*****************************************************************************/
526 * This function gets the count of total bytes transferred through core
527 * since last clear in ZDMA core.
529 * @param InstancePtr is a pointer to the XZDma instance.
535 * void XZDma_GetTotalByte(XZDma *InstancePtr)
537 ******************************************************************************/
538 #define XZDma_GetTotalByte(InstancePtr) \
539 XZDma_ReadReg((InstancePtr)->Config.BaseAddress, \
540 XZDMA_CH_TOTAL_BYTE_OFFSET)
542 /*****************************************************************************/
545 * This function clears the count of total bytes transferred in ZDMA core.
547 * @param InstancePtr is a pointer to the XZDma instance.
553 * void XZDma_TotalByteClear(XZDma *InstancePtr)
555 ******************************************************************************/
556 #define XZDma_TotalByteClear(InstancePtr) \
557 XZDma_WriteReg((InstancePtr)->Config.BaseAddress, \
558 XZDMA_CH_TOTAL_BYTE_OFFSET, \
559 XZDma_ReadReg((InstancePtr)->Config.BaseAddress, \
560 XZDMA_CH_TOTAL_BYTE_OFFSET))
562 /*****************************************************************************/
565 * This function gets the total number of Interrupt count for source after last
568 * @param InstancePtr is a pointer to the XZDma instance.
572 * @note Once this API is called then count will become zero.
574 * void XZDma_GetSrcIntrCnt(XZDma *InstancePtr)
576 ******************************************************************************/
577 #define XZDma_GetSrcIntrCnt(InstancePtr) \
578 XZDma_ReadReg((InstancePtr)->Config.BaseAddress, \
579 XZDMA_CH_IRQ_SRC_ACCT_OFFSET)
581 /*****************************************************************************/
584 * This function gets the total number of Interrupt count for destination
585 * after last call of this API.
587 * @param InstancePtr is a pointer to the XZDma instance.
591 * @note Once this API is called then count will become zero.
593 * void XZDma_GetDstIntrCnt(XZDma *InstancePtr)
595 ******************************************************************************/
596 #define XZDma_GetDstIntrCnt(InstancePtr) \
597 XZDma_ReadReg((InstancePtr)->Config.BaseAddress, \
598 XZDMA_CH_IRQ_DST_ACCT_OFFSET)
600 /*****************************************************************************/
603 * This function Enable's the ZDMA core for initiating the data transfer once the
604 * data transfer completes it will be automatically disabled.
606 * @param InstancePtr is a pointer to the XZDma instance.
612 * void XZDma_EnableCh(XZDma *InstancePtr)
614 ******************************************************************************/
615 #define XZDma_EnableCh(InstancePtr) \
616 XZDma_WriteReg((InstancePtr)->Config.BaseAddress, \
617 (XZDMA_CH_CTRL2_OFFSET), (XZDMA_CH_CTRL2_EN_MASK))
619 /*****************************************************************************/
622 * This function Disable's the ZDMA core.
624 * @param InstancePtr is a pointer to the XZDma instance.
630 * void XZDma_DisableCh(XZDma *InstancePtr)
632 ******************************************************************************/
633 #define XZDma_DisableCh(InstancePtr) \
634 XZDma_WriteReg((InstancePtr)->Config.BaseAddress,\
635 (XZDMA_CH_CTRL2_OFFSET), (XZDMA_CH_CTRL2_DIS_MASK))
637 /************************ Prototypes of functions **************************/
639 XZDma_Config *XZDma_LookupConfig(u16 DeviceId);
641 s32 XZDma_CfgInitialize(XZDma *InstancePtr, XZDma_Config *CfgPtr,
643 s32 XZDma_SetMode(XZDma *InstancePtr, u8 IsSgDma, XZDma_Mode Mode);
644 u32 XZDma_CreateBDList(XZDma *InstancePtr, XZDma_DscrType TypeOfDscr,
645 UINTPTR Dscr_MemPtr, u32 NoOfBytes);
646 s32 XZDma_SetChDataConfig(XZDma *InstancePtr, XZDma_DataConfig *Configure);
647 void XZDma_GetChDataConfig(XZDma *InstancePtr, XZDma_DataConfig *Configure);
648 s32 XZDma_SetChDscrConfig(XZDma *InstancePtr, XZDma_DscrConfig *Configure);
649 void XZDma_GetChDscrConfig(XZDma *InstancePtr, XZDma_DscrConfig *Configure);
650 s32 XZDma_Start(XZDma *InstancePtr, XZDma_Transfer *Data, u32 Num);
651 void XZDma_WOData(XZDma *InstancePtr, u32 *Buffer);
652 void XZDma_Resume(XZDma *InstancePtr);
653 void XZDma_Reset(XZDma *InstancePtr);
654 XZDmaState XZDma_ChannelState(XZDma *InstancePtr);
656 s32 XZDma_SelfTest(XZDma *InstancePtr);
658 void XZDma_IntrHandler(void *Instance);
659 s32 XZDma_SetCallBack(XZDma *InstancePtr, XZDma_Handler HandlerType,
660 void *CallBackFunc, void *CallBackRef);
669 #endif /* XZDMA_H_ */