]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A53_64-bit_UltraScale_MPSoC/RTOSDemo_A53_bsp/psu_cortexa53_0/libsrc/emacps_v3_0/src/xemacps_bdring.h
Completely re-generate the Zynq 7000 demo using the 2016.1 SDK tools.
[freertos] / FreeRTOS / Demo / CORTEX_A53_64-bit_UltraScale_MPSoC / RTOSDemo_A53_bsp / psu_cortexa53_0 / libsrc / emacps_v3_0 / src / xemacps_bdring.h
1 /******************************************************************************
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 xemacps_bdring.h
36 *
37 * The Xiline EmacPs Buffer Descriptor ring driver. This is part of EmacPs
38 * DMA functionalities.
39 *
40 * <pre>
41 * MODIFICATION HISTORY:
42 *
43 * Ver   Who  Date     Changes
44 * ----- ---- -------- -------------------------------------------------------
45 * 1.00a wsy  01/10/10 First release
46 * 2.1   srt  07/15/14 Add support for Zynq Ultrascale Mp architecture.
47 * 3.0   kvn  02/13/15 Modified code for MISRA-C:2012 compliance.
48 *
49 * </pre>
50 *
51 ******************************************************************************/
52
53 #ifndef XEMACPS_BDRING_H        /* prevent curcular inclusions */
54 #define XEMACPS_BDRING_H        /* by using protection macros */
55
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59
60
61 /**************************** Type Definitions *******************************/
62
63 /** This is an internal structure used to maintain the DMA list */
64 typedef struct {
65         UINTPTR PhysBaseAddr;/**< Physical address of 1st BD in list */
66         UINTPTR BaseBdAddr;      /**< Virtual address of 1st BD in list */
67         UINTPTR HighBdAddr;      /**< Virtual address of last BD in the list */
68         u32 Length;      /**< Total size of ring in bytes */
69         u32 RunState;    /**< Flag to indicate DMA is started */
70         u32 Separation;  /**< Number of bytes between the starting address
71                                   of adjacent BDs */
72         XEmacPs_Bd *FreeHead;
73                              /**< First BD in the free group */
74         XEmacPs_Bd *PreHead;/**< First BD in the pre-work group */
75         XEmacPs_Bd *HwHead; /**< First BD in the work group */
76         XEmacPs_Bd *HwTail; /**< Last BD in the work group */
77         XEmacPs_Bd *PostHead;
78                              /**< First BD in the post-work group */
79         XEmacPs_Bd *BdaRestart;
80                              /**< BDA to load when channel is started */
81
82         u32 HwCnt;           /**< Number of BDs in work group */
83         u32 PreCnt;     /**< Number of BDs in pre-work group */
84         u32 FreeCnt;    /**< Number of allocatable BDs in the free group */
85         u32 PostCnt;    /**< Number of BDs in post-work group */
86         u32 AllCnt;     /**< Total Number of BDs for channel */
87 } XEmacPs_BdRing;
88
89
90 /***************** Macros (Inline Functions) Definitions *********************/
91
92 /*****************************************************************************/
93 /**
94 * Use this macro at initialization time to determine how many BDs will fit
95 * in a BD list within the given memory constraints.
96 *
97 * The results of this macro can be provided to XEmacPs_BdRingCreate().
98 *
99 * @param Alignment specifies what byte alignment the BDs must fall on and
100 *        must be a power of 2 to get an accurate calculation (32, 64, 128,...)
101 * @param Bytes is the number of bytes to be used to store BDs.
102 *
103 * @return Number of BDs that can fit in the given memory area
104 *
105 * @note
106 * C-style signature:
107 *    u32 XEmacPs_BdRingCntCalc(u32 Alignment, u32 Bytes)
108 *
109 ******************************************************************************/
110 #define XEmacPs_BdRingCntCalc(Alignment, Bytes)                    \
111     (u32)((Bytes) / (sizeof(XEmacPs_Bd)))
112
113 /*****************************************************************************/
114 /**
115 * Use this macro at initialization time to determine how many bytes of memory
116 * is required to contain a given number of BDs at a given alignment.
117 *
118 * @param Alignment specifies what byte alignment the BDs must fall on. This
119 *        parameter must be a power of 2 to get an accurate calculation (32, 64,
120 *        128,...)
121 * @param NumBd is the number of BDs to calculate memory size requirements for
122 *
123 * @return The number of bytes of memory required to create a BD list with the
124 *         given memory constraints.
125 *
126 * @note
127 * C-style signature:
128 *    u32 XEmacPs_BdRingMemCalc(u32 Alignment, u32 NumBd)
129 *
130 ******************************************************************************/
131 #define XEmacPs_BdRingMemCalc(Alignment, NumBd)                    \
132     (u32)(sizeof(XEmacPs_Bd) * (NumBd))
133
134 /****************************************************************************/
135 /**
136 * Return the total number of BDs allocated by this channel with
137 * XEmacPs_BdRingCreate().
138 *
139 * @param  RingPtr is the DMA channel to operate on.
140 *
141 * @return The total number of BDs allocated for this channel.
142 *
143 * @note
144 * C-style signature:
145 *    u32 XEmacPs_BdRingGetCnt(XEmacPs_BdRing* RingPtr)
146 *
147 *****************************************************************************/
148 #define XEmacPs_BdRingGetCnt(RingPtr) ((RingPtr)->AllCnt)
149
150 /****************************************************************************/
151 /**
152 * Return the number of BDs allocatable with XEmacPs_BdRingAlloc() for pre-
153 * processing.
154 *
155 * @param  RingPtr is the DMA channel to operate on.
156 *
157 * @return The number of BDs currently allocatable.
158 *
159 * @note
160 * C-style signature:
161 *    u32 XEmacPs_BdRingGetFreeCnt(XEmacPs_BdRing* RingPtr)
162 *
163 *****************************************************************************/
164 #define XEmacPs_BdRingGetFreeCnt(RingPtr)   ((RingPtr)->FreeCnt)
165
166 /****************************************************************************/
167 /**
168 * Return the next BD from BdPtr in a list.
169 *
170 * @param  RingPtr is the DMA channel to operate on.
171 * @param  BdPtr is the BD to operate on.
172 *
173 * @return The next BD in the list relative to the BdPtr parameter.
174 *
175 * @note
176 * C-style signature:
177 *    XEmacPs_Bd *XEmacPs_BdRingNext(XEmacPs_BdRing* RingPtr,
178 *                                      XEmacPs_Bd *BdPtr)
179 *
180 *****************************************************************************/
181 #define XEmacPs_BdRingNext(RingPtr, BdPtr)                           \
182     (((UINTPTR)((void *)(BdPtr)) >= (RingPtr)->HighBdAddr) ?                     \
183     (XEmacPs_Bd*)((void*)(RingPtr)->BaseBdAddr) :                              \
184     (XEmacPs_Bd*)((UINTPTR)((void *)(BdPtr)) + (RingPtr)->Separation))
185
186 /****************************************************************************/
187 /**
188 * Return the previous BD from BdPtr in the list.
189 *
190 * @param  RingPtr is the DMA channel to operate on.
191 * @param  BdPtr is the BD to operate on
192 *
193 * @return The previous BD in the list relative to the BdPtr parameter.
194 *
195 * @note
196 * C-style signature:
197 *    XEmacPs_Bd *XEmacPs_BdRingPrev(XEmacPs_BdRing* RingPtr,
198 *                                      XEmacPs_Bd *BdPtr)
199 *
200 *****************************************************************************/
201 #define XEmacPs_BdRingPrev(RingPtr, BdPtr)                           \
202     (((UINTPTR)(BdPtr) <= (RingPtr)->BaseBdAddr) ?                     \
203     (XEmacPs_Bd*)(RingPtr)->HighBdAddr :                              \
204     (XEmacPs_Bd*)((UINTPTR)(BdPtr) - (RingPtr)->Separation))
205
206 /************************** Function Prototypes ******************************/
207
208 /*
209  * Scatter gather DMA related functions in xemacps_bdring.c
210  */
211 LONG XEmacPs_BdRingCreate(XEmacPs_BdRing * RingPtr, UINTPTR PhysAddr,
212                           UINTPTR VirtAddr, u32 Alignment, u32 BdCount);
213 LONG XEmacPs_BdRingClone(XEmacPs_BdRing * RingPtr, XEmacPs_Bd * SrcBdPtr,
214                          u8 Direction);
215 LONG XEmacPs_BdRingAlloc(XEmacPs_BdRing * RingPtr, u32 NumBd,
216                          XEmacPs_Bd ** BdSetPtr);
217 LONG XEmacPs_BdRingUnAlloc(XEmacPs_BdRing * RingPtr, u32 NumBd,
218                            XEmacPs_Bd * BdSetPtr);
219 LONG XEmacPs_BdRingToHw(XEmacPs_BdRing * RingPtr, u32 NumBd,
220                         XEmacPs_Bd * BdSetPtr);
221 LONG XEmacPs_BdRingFree(XEmacPs_BdRing * RingPtr, u32 NumBd,
222                         XEmacPs_Bd * BdSetPtr);
223 u32 XEmacPs_BdRingFromHwTx(XEmacPs_BdRing * RingPtr, u32 BdLimit,
224                                  XEmacPs_Bd ** BdSetPtr);
225 u32 XEmacPs_BdRingFromHwRx(XEmacPs_BdRing * RingPtr, u32 BdLimit,
226                                  XEmacPs_Bd ** BdSetPtr);
227 LONG XEmacPs_BdRingCheck(XEmacPs_BdRing * RingPtr, u8 Direction);
228
229
230 #ifdef __cplusplus
231 }
232 #endif
233
234
235 #endif /* end of protection macros */