1 /******************************************************************************
3 * Copyright (C) 2010 - 2015 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 * @file xemacps_bdring.h
36 * @addtogroup emacps_v3_1
39 * The Xiline EmacPs Buffer Descriptor ring driver. This is part of EmacPs
40 * DMA functionalities.
43 * MODIFICATION HISTORY:
45 * Ver Who Date Changes
46 * ----- ---- -------- -------------------------------------------------------
47 * 1.00a wsy 01/10/10 First release
48 * 2.1 srt 07/15/14 Add support for Zynq Ultrascale Mp architecture.
49 * 3.0 kvn 02/13/15 Modified code for MISRA-C:2012 compliance.
53 ******************************************************************************/
55 #ifndef XEMACPS_BDRING_H /* prevent curcular inclusions */
56 #define XEMACPS_BDRING_H /* by using protection macros */
63 /**************************** Type Definitions *******************************/
65 /** This is an internal structure used to maintain the DMA list */
67 UINTPTR PhysBaseAddr;/**< Physical address of 1st BD in list */
68 UINTPTR BaseBdAddr; /**< Virtual address of 1st BD in list */
69 UINTPTR HighBdAddr; /**< Virtual address of last BD in the list */
70 u32 Length; /**< Total size of ring in bytes */
71 u32 RunState; /**< Flag to indicate DMA is started */
72 u32 Separation; /**< Number of bytes between the starting address
75 /**< First BD in the free group */
76 XEmacPs_Bd *PreHead;/**< First BD in the pre-work group */
77 XEmacPs_Bd *HwHead; /**< First BD in the work group */
78 XEmacPs_Bd *HwTail; /**< Last BD in the work group */
80 /**< First BD in the post-work group */
81 XEmacPs_Bd *BdaRestart;
82 /**< BDA to load when channel is started */
84 u32 HwCnt; /**< Number of BDs in work group */
85 u32 PreCnt; /**< Number of BDs in pre-work group */
86 u32 FreeCnt; /**< Number of allocatable BDs in the free group */
87 u32 PostCnt; /**< Number of BDs in post-work group */
88 u32 AllCnt; /**< Total Number of BDs for channel */
92 /***************** Macros (Inline Functions) Definitions *********************/
94 /*****************************************************************************/
96 * Use this macro at initialization time to determine how many BDs will fit
97 * in a BD list within the given memory constraints.
99 * The results of this macro can be provided to XEmacPs_BdRingCreate().
101 * @param Alignment specifies what byte alignment the BDs must fall on and
102 * must be a power of 2 to get an accurate calculation (32, 64, 128,...)
103 * @param Bytes is the number of bytes to be used to store BDs.
105 * @return Number of BDs that can fit in the given memory area
109 * u32 XEmacPs_BdRingCntCalc(u32 Alignment, u32 Bytes)
111 ******************************************************************************/
112 #define XEmacPs_BdRingCntCalc(Alignment, Bytes) \
113 (u32)((Bytes) / (sizeof(XEmacPs_Bd)))
115 /*****************************************************************************/
117 * Use this macro at initialization time to determine how many bytes of memory
118 * is required to contain a given number of BDs at a given alignment.
120 * @param Alignment specifies what byte alignment the BDs must fall on. This
121 * parameter must be a power of 2 to get an accurate calculation (32, 64,
123 * @param NumBd is the number of BDs to calculate memory size requirements for
125 * @return The number of bytes of memory required to create a BD list with the
126 * given memory constraints.
130 * u32 XEmacPs_BdRingMemCalc(u32 Alignment, u32 NumBd)
132 ******************************************************************************/
133 #define XEmacPs_BdRingMemCalc(Alignment, NumBd) \
134 (u32)(sizeof(XEmacPs_Bd) * (NumBd))
136 /****************************************************************************/
138 * Return the total number of BDs allocated by this channel with
139 * XEmacPs_BdRingCreate().
141 * @param RingPtr is the DMA channel to operate on.
143 * @return The total number of BDs allocated for this channel.
147 * u32 XEmacPs_BdRingGetCnt(XEmacPs_BdRing* RingPtr)
149 *****************************************************************************/
150 #define XEmacPs_BdRingGetCnt(RingPtr) ((RingPtr)->AllCnt)
152 /****************************************************************************/
154 * Return the number of BDs allocatable with XEmacPs_BdRingAlloc() for pre-
157 * @param RingPtr is the DMA channel to operate on.
159 * @return The number of BDs currently allocatable.
163 * u32 XEmacPs_BdRingGetFreeCnt(XEmacPs_BdRing* RingPtr)
165 *****************************************************************************/
166 #define XEmacPs_BdRingGetFreeCnt(RingPtr) ((RingPtr)->FreeCnt)
168 /****************************************************************************/
170 * Return the next BD from BdPtr in a list.
172 * @param RingPtr is the DMA channel to operate on.
173 * @param BdPtr is the BD to operate on.
175 * @return The next BD in the list relative to the BdPtr parameter.
179 * XEmacPs_Bd *XEmacPs_BdRingNext(XEmacPs_BdRing* RingPtr,
182 *****************************************************************************/
183 #define XEmacPs_BdRingNext(RingPtr, BdPtr) \
184 (((UINTPTR)((void *)(BdPtr)) >= (RingPtr)->HighBdAddr) ? \
185 (XEmacPs_Bd*)((void*)(RingPtr)->BaseBdAddr) : \
186 (XEmacPs_Bd*)((UINTPTR)((void *)(BdPtr)) + (RingPtr)->Separation))
188 /****************************************************************************/
190 * Return the previous BD from BdPtr in the list.
192 * @param RingPtr is the DMA channel to operate on.
193 * @param BdPtr is the BD to operate on
195 * @return The previous BD in the list relative to the BdPtr parameter.
199 * XEmacPs_Bd *XEmacPs_BdRingPrev(XEmacPs_BdRing* RingPtr,
202 *****************************************************************************/
203 #define XEmacPs_BdRingPrev(RingPtr, BdPtr) \
204 (((UINTPTR)(BdPtr) <= (RingPtr)->BaseBdAddr) ? \
205 (XEmacPs_Bd*)(RingPtr)->HighBdAddr : \
206 (XEmacPs_Bd*)((UINTPTR)(BdPtr) - (RingPtr)->Separation))
208 /************************** Function Prototypes ******************************/
211 * Scatter gather DMA related functions in xemacps_bdring.c
213 LONG XEmacPs_BdRingCreate(XEmacPs_BdRing * RingPtr, UINTPTR PhysAddr,
214 UINTPTR VirtAddr, u32 Alignment, u32 BdCount);
215 LONG XEmacPs_BdRingClone(XEmacPs_BdRing * RingPtr, XEmacPs_Bd * SrcBdPtr,
217 LONG XEmacPs_BdRingAlloc(XEmacPs_BdRing * RingPtr, u32 NumBd,
218 XEmacPs_Bd ** BdSetPtr);
219 LONG XEmacPs_BdRingUnAlloc(XEmacPs_BdRing * RingPtr, u32 NumBd,
220 XEmacPs_Bd * BdSetPtr);
221 LONG XEmacPs_BdRingToHw(XEmacPs_BdRing * RingPtr, u32 NumBd,
222 XEmacPs_Bd * BdSetPtr);
223 LONG XEmacPs_BdRingFree(XEmacPs_BdRing * RingPtr, u32 NumBd,
224 XEmacPs_Bd * BdSetPtr);
225 u32 XEmacPs_BdRingFromHwTx(XEmacPs_BdRing * RingPtr, u32 BdLimit,
226 XEmacPs_Bd ** BdSetPtr);
227 u32 XEmacPs_BdRingFromHwRx(XEmacPs_BdRing * RingPtr, u32 BdLimit,
228 XEmacPs_Bd ** BdSetPtr);
229 LONG XEmacPs_BdRingCheck(XEmacPs_BdRing * RingPtr, u8 Direction);
237 #endif /* end of protection macros */