1 |
3 |
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_bd.c
|
36 |
|
|
* @addtogroup axidma_v9_0
|
37 |
|
|
* @{
|
38 |
|
|
*
|
39 |
|
|
* Buffer descriptor (BD) management API implementation.
|
40 |
|
|
*
|
41 |
|
|
* <pre>
|
42 |
|
|
* MODIFICATION HISTORY:
|
43 |
|
|
*
|
44 |
|
|
* Ver Who Date Changes
|
45 |
|
|
* ----- ---- -------- -------------------------------------------------------
|
46 |
|
|
* 1.00a jz 05/18/10 First release
|
47 |
|
|
* 2.00a jz 08/10/10 Second release, added in xaxidma_g.c, xaxidma_sinit.c,
|
48 |
|
|
* updated tcl file, added xaxidma_porting_guide.h
|
49 |
|
|
* 3.00a jz 11/22/10 Support IP core parameters change
|
50 |
|
|
* 6.00a srt 01/24/12 Added support for Multi-Channel DMA.
|
51 |
|
|
* - Changed APIs
|
52 |
|
|
* * XAxiDma_BdSetLength(XAxiDma_Bd *BdPtr,
|
53 |
|
|
* u32 LenBytes, u32 LengthMask)
|
54 |
|
|
* * XAxiDma_BdGetActualLength(BdPtr, LengthMask)
|
55 |
|
|
* * XAxiDma_BdGetLength(BdPtr, LengthMask)
|
56 |
|
|
* 8.0 srt 01/29/14 Added support for Micro DMA Mode:
|
57 |
|
|
* - New API
|
58 |
|
|
* XAxiDma_BdSetBufAddrMicroMode(XAxiDma_Bd*, u32)
|
59 |
|
|
*
|
60 |
|
|
* </pre>
|
61 |
|
|
*
|
62 |
|
|
*****************************************************************************/
|
63 |
|
|
|
64 |
|
|
#include "xaxidma_bd.h"
|
65 |
|
|
|
66 |
|
|
/************************** Function Prototypes ******************************/
|
67 |
|
|
|
68 |
|
|
/*****************************************************************************/
|
69 |
|
|
/**
|
70 |
|
|
* Set the length field for the given BD.
|
71 |
|
|
*
|
72 |
|
|
* Length has to be non-zero and less than LengthMask.
|
73 |
|
|
*
|
74 |
|
|
* For TX channels, the value passed in should be the number of bytes to
|
75 |
|
|
* transmit from the TX buffer associated with the given BD.
|
76 |
|
|
*
|
77 |
|
|
* For RX channels, the value passed in should be the size of the RX buffer
|
78 |
|
|
* associated with the given BD in bytes. This is to notify the RX channel
|
79 |
|
|
* the capability of the RX buffer to avoid buffer overflow.
|
80 |
|
|
*
|
81 |
|
|
* The actual receive length can be equal or smaller than the specified length.
|
82 |
|
|
* The actual transfer length will be updated by the hardware in the
|
83 |
|
|
* XAXIDMA_BD_STS_OFFSET word in the BD.
|
84 |
|
|
*
|
85 |
|
|
* @param BdPtr is the BD to operate on.
|
86 |
|
|
* @param LenBytes is the requested transfer length
|
87 |
|
|
* @param LengthMask is the maximum transfer length
|
88 |
|
|
*
|
89 |
|
|
* @returns
|
90 |
|
|
* - XST_SUCCESS for success
|
91 |
|
|
* - XST_INVALID_PARAM for invalid BD length
|
92 |
|
|
*
|
93 |
|
|
* @note This function can be used only when DMA is in SG mode
|
94 |
|
|
*
|
95 |
|
|
*****************************************************************************/
|
96 |
|
|
int XAxiDma_BdSetLength(XAxiDma_Bd *BdPtr, u32 LenBytes, u32 LengthMask)
|
97 |
|
|
{
|
98 |
|
|
if (LenBytes <= 0 || (LenBytes > LengthMask)) {
|
99 |
|
|
|
100 |
|
|
xdbg_printf(XDBG_DEBUG_ERROR, "invalid length %d\n",
|
101 |
|
|
(int)LenBytes);
|
102 |
|
|
|
103 |
|
|
return XST_INVALID_PARAM;
|
104 |
|
|
}
|
105 |
|
|
|
106 |
|
|
XAxiDma_BdWrite((BdPtr), XAXIDMA_BD_CTRL_LEN_OFFSET,
|
107 |
|
|
((XAxiDma_BdRead((BdPtr), XAXIDMA_BD_CTRL_LEN_OFFSET) & \
|
108 |
|
|
~LengthMask)) | LenBytes);
|
109 |
|
|
|
110 |
|
|
return XST_SUCCESS;
|
111 |
|
|
}
|
112 |
|
|
/*****************************************************************************/
|
113 |
|
|
/**
|
114 |
|
|
* Set the BD's buffer address.
|
115 |
|
|
*
|
116 |
|
|
* @param BdPtr is the BD to operate on
|
117 |
|
|
* @param Addr is the address to set
|
118 |
|
|
*
|
119 |
|
|
* @return
|
120 |
|
|
* - XST_SUCCESS if buffer address set successfully
|
121 |
|
|
* - XST_INVALID_PARAM if hardware has no DRE and address is not
|
122 |
|
|
* aligned
|
123 |
|
|
*
|
124 |
|
|
* @note This function can be used only when DMA is in SG mode
|
125 |
|
|
*
|
126 |
|
|
*****************************************************************************/
|
127 |
|
|
u32 XAxiDma_BdSetBufAddr(XAxiDma_Bd* BdPtr, UINTPTR Addr)
|
128 |
|
|
{
|
129 |
|
|
u32 HasDRE;
|
130 |
|
|
u8 WordLen;
|
131 |
|
|
u32 Addrlen;
|
132 |
|
|
|
133 |
|
|
HasDRE = XAxiDma_BdRead(BdPtr, XAXIDMA_BD_HAS_DRE_OFFSET);
|
134 |
|
|
WordLen = HasDRE & XAXIDMA_BD_WORDLEN_MASK;
|
135 |
|
|
Addrlen = XAxiDma_BdRead(BdPtr, XAXIDMA_BD_ADDRLEN_OFFSET);
|
136 |
|
|
|
137 |
|
|
|
138 |
|
|
if (Addr & (WordLen - 1)) {
|
139 |
|
|
if ((HasDRE & XAXIDMA_BD_HAS_DRE_MASK) == 0) {
|
140 |
|
|
xil_printf("Error set buf addr %x with %x and %x,"
|
141 |
|
|
" %x\r\n",Addr, HasDRE, (WordLen - 1),
|
142 |
|
|
Addr & (WordLen - 1));
|
143 |
|
|
|
144 |
|
|
return XST_INVALID_PARAM;
|
145 |
|
|
}
|
146 |
|
|
}
|
147 |
|
|
|
148 |
|
|
XAxiDma_BdWrite(BdPtr, XAXIDMA_BD_BUFA_OFFSET, LOWER_32_BITS(Addr));
|
149 |
|
|
if (Addrlen)
|
150 |
|
|
XAxiDma_BdWrite(BdPtr, XAXIDMA_BD_BUFA_MSB_OFFSET,
|
151 |
|
|
UPPER_32_BITS(Addr));
|
152 |
|
|
|
153 |
|
|
return XST_SUCCESS;
|
154 |
|
|
}
|
155 |
|
|
|
156 |
|
|
/*****************************************************************************/
|
157 |
|
|
/**
|
158 |
|
|
* Set the BD's buffer address when configured for Micro Mode. The buffer
|
159 |
|
|
* address should be 4K aligned.
|
160 |
|
|
*
|
161 |
|
|
* @param BdPtr is the BD to operate on
|
162 |
|
|
* @param Addr is the address to set
|
163 |
|
|
*
|
164 |
|
|
* @return
|
165 |
|
|
* - XST_SUCCESS if buffer address set successfully
|
166 |
|
|
* - XST_INVALID_PARAM if hardware has no DRE and address is not
|
167 |
|
|
* aligned
|
168 |
|
|
*
|
169 |
|
|
* @note This function can be used only when DMA is in SG mode
|
170 |
|
|
*
|
171 |
|
|
*****************************************************************************/
|
172 |
|
|
u32 XAxiDma_BdSetBufAddrMicroMode(XAxiDma_Bd* BdPtr, UINTPTR Addr)
|
173 |
|
|
{
|
174 |
|
|
u32 Addrlen;
|
175 |
|
|
Addrlen = XAxiDma_BdRead(BdPtr, XAXIDMA_BD_ADDRLEN_OFFSET);
|
176 |
|
|
|
177 |
|
|
if (Addr & XAXIDMA_MICROMODE_MIN_BUF_ALIGN) {
|
178 |
|
|
xil_printf("Error set buf addr %x and %x,"
|
179 |
|
|
" %x\r\n", Addr, XAXIDMA_MICROMODE_MIN_BUF_ALIGN,
|
180 |
|
|
Addr & XAXIDMA_MICROMODE_MIN_BUF_ALIGN);
|
181 |
|
|
|
182 |
|
|
return XST_INVALID_PARAM;
|
183 |
|
|
}
|
184 |
|
|
|
185 |
|
|
XAxiDma_BdWrite(BdPtr, XAXIDMA_BD_BUFA_OFFSET,
|
186 |
|
|
LOWER_32_BITS(Addr));
|
187 |
|
|
if (Addrlen)
|
188 |
|
|
XAxiDma_BdWrite(BdPtr, XAXIDMA_BD_BUFA_MSB_OFFSET,
|
189 |
|
|
UPPER_32_BITS(Addr));
|
190 |
|
|
|
191 |
|
|
return XST_SUCCESS;
|
192 |
|
|
}
|
193 |
|
|
|
194 |
|
|
/*****************************************************************************/
|
195 |
|
|
/**
|
196 |
|
|
* Set the APP word at the specified APP word offset for a BD.
|
197 |
|
|
*
|
198 |
|
|
* @param BdPtr is the BD to operate on.
|
199 |
|
|
* @param Offset is the offset inside the APP word, it is valid from
|
200 |
|
|
* 0 to 4
|
201 |
|
|
* @param Word is the value to set
|
202 |
|
|
*
|
203 |
|
|
* @returns
|
204 |
|
|
* - XST_SUCCESS for success
|
205 |
|
|
* - XST_INVALID_PARAM under following error conditions:
|
206 |
|
|
* 1) StsCntrlStrm is not built in hardware
|
207 |
|
|
* 2) Offset is not in valid range
|
208 |
|
|
*
|
209 |
|
|
* @note
|
210 |
|
|
* If the hardware build has C_SG_USE_STSAPP_LENGTH set to 1,
|
211 |
|
|
* then the last APP word, XAXIDMA_LAST_APPWORD, must have
|
212 |
|
|
* non-zero value when AND with 0x7FFFFF. Not doing so will cause
|
213 |
|
|
* the hardware to stall.
|
214 |
|
|
* This function can be used only when DMA is in SG mode
|
215 |
|
|
*
|
216 |
|
|
*****************************************************************************/
|
217 |
|
|
int XAxiDma_BdSetAppWord(XAxiDma_Bd* BdPtr, int Offset, u32 Word)
|
218 |
|
|
{
|
219 |
|
|
if (XAxiDma_BdRead(BdPtr, XAXIDMA_BD_HAS_STSCNTRL_OFFSET) == 0) {
|
220 |
|
|
|
221 |
|
|
xdbg_printf(XDBG_DEBUG_ERROR, "BdRingSetAppWord: no sts cntrl"
|
222 |
|
|
"stream in hardware build, cannot set app word\r\n");
|
223 |
|
|
|
224 |
|
|
return XST_INVALID_PARAM;
|
225 |
|
|
}
|
226 |
|
|
|
227 |
|
|
if ((Offset < 0) || (Offset > XAXIDMA_LAST_APPWORD)) {
|
228 |
|
|
|
229 |
|
|
xdbg_printf(XDBG_DEBUG_ERROR, "BdRingSetAppWord: invalid"
|
230 |
|
|
"offset %d",Offset);
|
231 |
|
|
|
232 |
|
|
return XST_INVALID_PARAM;
|
233 |
|
|
}
|
234 |
|
|
|
235 |
|
|
XAxiDma_BdWrite(BdPtr, XAXIDMA_BD_USR0_OFFSET + Offset * 4, Word);
|
236 |
|
|
|
237 |
|
|
return XST_SUCCESS;
|
238 |
|
|
}
|
239 |
|
|
/*****************************************************************************/
|
240 |
|
|
/**
|
241 |
|
|
* Get the APP word at the specified APP word offset for a BD.
|
242 |
|
|
*
|
243 |
|
|
* @param BdPtr is the BD to operate on.
|
244 |
|
|
* @param Offset is the offset inside the APP word, it is valid from
|
245 |
|
|
* 0 to 4
|
246 |
|
|
* @param Valid is to tell the caller whether parameters are valid
|
247 |
|
|
*
|
248 |
|
|
* @returns
|
249 |
|
|
* The APP word. Passed in parameter Valid holds 0 for failure,
|
250 |
|
|
* and 1 for success.
|
251 |
|
|
*
|
252 |
|
|
* @note This function can be used only when DMA is in SG mode
|
253 |
|
|
*
|
254 |
|
|
*****************************************************************************/
|
255 |
|
|
u32 XAxiDma_BdGetAppWord(XAxiDma_Bd* BdPtr, int Offset, int *Valid)
|
256 |
|
|
{
|
257 |
|
|
*Valid = 0;
|
258 |
|
|
|
259 |
|
|
if (XAxiDma_BdRead(BdPtr, XAXIDMA_BD_HAS_STSCNTRL_OFFSET) == 0) {
|
260 |
|
|
|
261 |
|
|
xdbg_printf(XDBG_DEBUG_ERROR, "BdRingGetAppWord: no sts cntrl "
|
262 |
|
|
"stream in hardware build, no app word available\r\n");
|
263 |
|
|
|
264 |
|
|
return (u32)0;
|
265 |
|
|
}
|
266 |
|
|
|
267 |
|
|
if((Offset < 0) || (Offset > XAXIDMA_LAST_APPWORD)) {
|
268 |
|
|
|
269 |
|
|
xdbg_printf(XDBG_DEBUG_ERROR, "BdRingGetAppWord: invalid"
|
270 |
|
|
" offset %d", Offset);
|
271 |
|
|
|
272 |
|
|
return (u32)0;
|
273 |
|
|
}
|
274 |
|
|
|
275 |
|
|
*Valid = 1;
|
276 |
|
|
|
277 |
|
|
return XAxiDma_BdRead(BdPtr, XAXIDMA_BD_USR0_OFFSET + Offset * 4);
|
278 |
|
|
}
|
279 |
|
|
|
280 |
|
|
/*****************************************************************************/
|
281 |
|
|
/**
|
282 |
|
|
* Set the control bits for a BD.
|
283 |
|
|
*
|
284 |
|
|
* @param BdPtr is the BD to operate on.
|
285 |
|
|
* @param Data is the bit value to set
|
286 |
|
|
*
|
287 |
|
|
* @return None
|
288 |
|
|
*
|
289 |
|
|
* @note This function can be used only when DMA is in SG mode
|
290 |
|
|
*
|
291 |
|
|
*****************************************************************************/
|
292 |
|
|
void XAxiDma_BdSetCtrl(XAxiDma_Bd* BdPtr, u32 Data)
|
293 |
|
|
{
|
294 |
|
|
u32 RegValue = XAxiDma_BdRead(BdPtr, XAXIDMA_BD_CTRL_LEN_OFFSET);
|
295 |
|
|
|
296 |
|
|
RegValue &= ~XAXIDMA_BD_CTRL_ALL_MASK;
|
297 |
|
|
|
298 |
|
|
RegValue |= (Data & XAXIDMA_BD_CTRL_ALL_MASK);
|
299 |
|
|
|
300 |
|
|
XAxiDma_BdWrite((BdPtr), XAXIDMA_BD_CTRL_LEN_OFFSET, RegValue);
|
301 |
|
|
|
302 |
|
|
return;
|
303 |
|
|
}
|
304 |
|
|
/*****************************************************************************/
|
305 |
|
|
/**
|
306 |
|
|
* Dump the fields of a BD.
|
307 |
|
|
*
|
308 |
|
|
* @param BdPtr is the BD to operate on.
|
309 |
|
|
*
|
310 |
|
|
* @return None
|
311 |
|
|
*
|
312 |
|
|
* @note This function can be used only when DMA is in SG mode
|
313 |
|
|
*
|
314 |
|
|
*****************************************************************************/
|
315 |
|
|
void XAxiDma_DumpBd(XAxiDma_Bd* BdPtr)
|
316 |
|
|
{
|
317 |
|
|
|
318 |
|
|
xil_printf("Dump BD %x:\r\n", (UINTPTR)BdPtr);
|
319 |
|
|
xil_printf("\tNext Bd Ptr: %x\r\n",
|
320 |
|
|
(unsigned int)XAxiDma_BdRead(BdPtr, XAXIDMA_BD_NDESC_OFFSET));
|
321 |
|
|
xil_printf("\tBuff addr: %x\r\n",
|
322 |
|
|
(unsigned int)XAxiDma_BdRead(BdPtr, XAXIDMA_BD_BUFA_OFFSET));
|
323 |
|
|
xil_printf("\tMCDMA Fields: %x\r\n",
|
324 |
|
|
(unsigned int)XAxiDma_BdRead(BdPtr, XAXIDMA_BD_MCCTL_OFFSET));
|
325 |
|
|
xil_printf("\tVSIZE_STRIDE: %x\r\n",
|
326 |
|
|
(unsigned int)XAxiDma_BdRead(BdPtr,
|
327 |
|
|
XAXIDMA_BD_STRIDE_VSIZE_OFFSET));
|
328 |
|
|
xil_printf("\tContrl len: %x\r\n",
|
329 |
|
|
(unsigned int)XAxiDma_BdRead(BdPtr, XAXIDMA_BD_CTRL_LEN_OFFSET));
|
330 |
|
|
xil_printf("\tStatus: %x\r\n",
|
331 |
|
|
(unsigned int)XAxiDma_BdRead(BdPtr, XAXIDMA_BD_STS_OFFSET));
|
332 |
|
|
|
333 |
|
|
xil_printf("\tAPP 0: %x\r\n",
|
334 |
|
|
(unsigned int)XAxiDma_BdRead(BdPtr, XAXIDMA_BD_USR0_OFFSET));
|
335 |
|
|
xil_printf("\tAPP 1: %x\r\n",
|
336 |
|
|
(unsigned int)XAxiDma_BdRead(BdPtr, XAXIDMA_BD_USR1_OFFSET));
|
337 |
|
|
xil_printf("\tAPP 2: %x\r\n",
|
338 |
|
|
(unsigned int)XAxiDma_BdRead(BdPtr, XAXIDMA_BD_USR2_OFFSET));
|
339 |
|
|
xil_printf("\tAPP 3: %x\r\n",
|
340 |
|
|
(unsigned int)XAxiDma_BdRead(BdPtr, XAXIDMA_BD_USR3_OFFSET));
|
341 |
|
|
xil_printf("\tAPP 4: %x\r\n",
|
342 |
|
|
(unsigned int)XAxiDma_BdRead(BdPtr, XAXIDMA_BD_USR4_OFFSET));
|
343 |
|
|
|
344 |
|
|
xil_printf("\tSW ID: %x\r\n",
|
345 |
|
|
(unsigned int)XAxiDma_BdRead(BdPtr, XAXIDMA_BD_ID_OFFSET));
|
346 |
|
|
xil_printf("\tStsCtrl: %x\r\n",
|
347 |
|
|
(unsigned int)XAxiDma_BdRead(BdPtr,
|
348 |
|
|
XAXIDMA_BD_HAS_STSCNTRL_OFFSET));
|
349 |
|
|
xil_printf("\tDRE: %x\r\n",
|
350 |
|
|
(unsigned int)XAxiDma_BdRead(BdPtr, XAXIDMA_BD_HAS_DRE_OFFSET));
|
351 |
|
|
|
352 |
|
|
xil_printf("\r\n");
|
353 |
|
|
}
|
354 |
|
|
/** @} */
|