xdma_channel.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. /******************************************************************************
  2. *
  3. * Author: Xilinx, Inc.
  4. *
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. *
  11. *
  12. * XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A
  13. * COURTESY TO YOU. BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS
  14. * ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION OR STANDARD,
  15. * XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION IS FREE
  16. * FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE FOR OBTAINING
  17. * ANY THIRD PARTY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION.
  18. * XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO
  19. * THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY
  20. * WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM
  21. * CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND
  22. * FITNESS FOR A PARTICULAR PURPOSE.
  23. *
  24. *
  25. * Xilinx hardware products are not intended for use in life support
  26. * appliances, devices, or systems. Use in such applications is
  27. * expressly prohibited.
  28. *
  29. *
  30. * (c) Copyright 2002-2004 Xilinx Inc.
  31. * All rights reserved.
  32. *
  33. *
  34. * You should have received a copy of the GNU General Public License along
  35. * with this program; if not, write to the Free Software Foundation, Inc.,
  36. * 675 Mass Ave, Cambridge, MA 02139, USA.
  37. *
  38. * FILENAME:
  39. *
  40. * xdma_channel.c
  41. *
  42. * DESCRIPTION:
  43. *
  44. * This file contains the DMA channel component. This component supports
  45. * a distributed DMA design in which each device can have it's own dedicated
  46. * DMA channel, as opposed to a centralized DMA design. This component
  47. * performs processing for DMA on all devices.
  48. *
  49. * See xdma_channel.h for more information about this component.
  50. *
  51. * NOTES:
  52. *
  53. * None.
  54. *
  55. ******************************************************************************/
  56. /***************************** Include Files *********************************/
  57. #include "xdma_channel.h"
  58. #include "xbasic_types.h"
  59. #include "xio.h"
  60. /************************** Constant Definitions *****************************/
  61. /**************************** Type Definitions *******************************/
  62. /***************** Macros (Inline Functions) Definitions *********************/
  63. /************************** Function Prototypes ******************************/
  64. /******************************************************************************
  65. *
  66. * FUNCTION:
  67. *
  68. * XDmaChannel_Initialize
  69. *
  70. * DESCRIPTION:
  71. *
  72. * This function initializes a DMA channel. This function must be called
  73. * prior to using a DMA channel. Initialization of a channel includes setting
  74. * up the registers base address, and resetting the channel such that it's in a
  75. * known state. Interrupts for the channel are disabled when the channel is
  76. * reset.
  77. *
  78. * ARGUMENTS:
  79. *
  80. * InstancePtr contains a pointer to the DMA channel to operate on.
  81. *
  82. * BaseAddress contains the base address of the registers for the DMA channel.
  83. *
  84. * RETURN VALUE:
  85. *
  86. * XST_SUCCESS indicating initialization was successful.
  87. *
  88. * NOTES:
  89. *
  90. * None.
  91. *
  92. ******************************************************************************/
  93. XStatus
  94. XDmaChannel_Initialize(XDmaChannel * InstancePtr, u32 BaseAddress)
  95. {
  96. /* assert to verify input arguments, don't assert base address */
  97. XASSERT_NONVOID(InstancePtr != NULL);
  98. /* setup the base address of the registers for the DMA channel such
  99. * that register accesses can be done
  100. */
  101. InstancePtr->RegBaseAddress = BaseAddress;
  102. /* initialize the scatter gather list such that it indicates it has not
  103. * been created yet and the DMA channel is ready to use (initialized)
  104. */
  105. InstancePtr->GetPtr = NULL;
  106. InstancePtr->PutPtr = NULL;
  107. InstancePtr->CommitPtr = NULL;
  108. InstancePtr->LastPtr = NULL;
  109. InstancePtr->TotalDescriptorCount = 0;
  110. InstancePtr->ActiveDescriptorCount = 0;
  111. InstancePtr->IsReady = XCOMPONENT_IS_READY;
  112. /* initialize the version of the component
  113. */
  114. XVersion_FromString(&InstancePtr->Version, "1.00a");
  115. /* reset the DMA channel such that it's in a known state and ready
  116. * and indicate the initialization occured with no errors, note that
  117. * the is ready variable must be set before this call or reset will assert
  118. */
  119. XDmaChannel_Reset(InstancePtr);
  120. return XST_SUCCESS;
  121. }
  122. /******************************************************************************
  123. *
  124. * FUNCTION:
  125. *
  126. * XDmaChannel_IsReady
  127. *
  128. * DESCRIPTION:
  129. *
  130. * This function determines if a DMA channel component has been successfully
  131. * initialized such that it's ready to use.
  132. *
  133. * ARGUMENTS:
  134. *
  135. * InstancePtr contains a pointer to the DMA channel to operate on.
  136. *
  137. * RETURN VALUE:
  138. *
  139. * TRUE if the DMA channel component is ready, FALSE otherwise.
  140. *
  141. * NOTES:
  142. *
  143. * None.
  144. *
  145. ******************************************************************************/
  146. u32
  147. XDmaChannel_IsReady(XDmaChannel * InstancePtr)
  148. {
  149. /* assert to verify input arguments used by the base component */
  150. XASSERT_NONVOID(InstancePtr != NULL);
  151. return InstancePtr->IsReady == XCOMPONENT_IS_READY;
  152. }
  153. /******************************************************************************
  154. *
  155. * FUNCTION:
  156. *
  157. * XDmaChannel_GetVersion
  158. *
  159. * DESCRIPTION:
  160. *
  161. * This function gets the software version for the specified DMA channel
  162. * component.
  163. *
  164. * ARGUMENTS:
  165. *
  166. * InstancePtr contains a pointer to the DMA channel to operate on.
  167. *
  168. * RETURN VALUE:
  169. *
  170. * A pointer to the software version of the specified DMA channel.
  171. *
  172. * NOTES:
  173. *
  174. * None.
  175. *
  176. ******************************************************************************/
  177. XVersion *
  178. XDmaChannel_GetVersion(XDmaChannel * InstancePtr)
  179. {
  180. /* assert to verify input arguments */
  181. XASSERT_NONVOID(InstancePtr != NULL);
  182. XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);
  183. /* return a pointer to the version of the DMA channel */
  184. return &InstancePtr->Version;
  185. }
  186. /******************************************************************************
  187. *
  188. * FUNCTION:
  189. *
  190. * XDmaChannel_SelfTest
  191. *
  192. * DESCRIPTION:
  193. *
  194. * This function performs a self test on the specified DMA channel. This self
  195. * test is destructive as the DMA channel is reset and a register default is
  196. * verified.
  197. *
  198. * ARGUMENTS:
  199. *
  200. * InstancePtr is a pointer to the DMA channel to be operated on.
  201. *
  202. * RETURN VALUE:
  203. *
  204. * XST_SUCCESS is returned if the self test is successful, or one of the
  205. * following errors.
  206. *
  207. * XST_DMA_RESET_REGISTER_ERROR Indicates the control register value
  208. * after a reset was not correct
  209. *
  210. * NOTES:
  211. *
  212. * This test does not performs a DMA transfer to test the channel because the
  213. * DMA hardware will not currently allow a non-local memory transfer to non-local
  214. * memory (memory copy), but only allows a non-local memory to or from the device
  215. * memory (typically a FIFO).
  216. *
  217. ******************************************************************************/
  218. #define XDC_CONTROL_REG_RESET_MASK 0x98000000UL /* control reg reset value */
  219. XStatus
  220. XDmaChannel_SelfTest(XDmaChannel * InstancePtr)
  221. {
  222. u32 ControlReg;
  223. /* assert to verify input arguments */
  224. XASSERT_NONVOID(InstancePtr != NULL);
  225. XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);
  226. /* reset the DMA channel such that it's in a known state before the test
  227. * it resets to no interrupts enabled, the desired state for the test
  228. */
  229. XDmaChannel_Reset(InstancePtr);
  230. /* this should be the first test to help prevent a lock up with the polling
  231. * loop that occurs later in the test, check the reset value of the DMA
  232. * control register to make sure it's correct, return with an error if not
  233. */
  234. ControlReg = XDmaChannel_GetControl(InstancePtr);
  235. if (ControlReg != XDC_CONTROL_REG_RESET_MASK) {
  236. return XST_DMA_RESET_REGISTER_ERROR;
  237. }
  238. return XST_SUCCESS;
  239. }
  240. /******************************************************************************
  241. *
  242. * FUNCTION:
  243. *
  244. * XDmaChannel_Reset
  245. *
  246. * DESCRIPTION:
  247. *
  248. * This function resets the DMA channel. This is a destructive operation such
  249. * that it should not be done while a channel is being used. If the DMA channel
  250. * is transferring data into other blocks, such as a FIFO, it may be necessary
  251. * to reset other blocks. This function does not modify the contents of a
  252. * scatter gather list for a DMA channel such that the user is responsible for
  253. * getting buffer descriptors from the list if necessary.
  254. *
  255. * ARGUMENTS:
  256. *
  257. * InstancePtr contains a pointer to the DMA channel to operate on.
  258. *
  259. * RETURN VALUE:
  260. *
  261. * None.
  262. *
  263. * NOTES:
  264. *
  265. * None.
  266. *
  267. ******************************************************************************/
  268. void
  269. XDmaChannel_Reset(XDmaChannel * InstancePtr)
  270. {
  271. /* assert to verify input arguments */
  272. XASSERT_VOID(InstancePtr != NULL);
  273. XASSERT_VOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);
  274. /* reset the DMA channel such that it's in a known state, the reset
  275. * register is self clearing such that it only has to be set
  276. */
  277. XIo_Out32(InstancePtr->RegBaseAddress + XDC_RST_REG_OFFSET,
  278. XDC_RESET_MASK);
  279. }
  280. /******************************************************************************
  281. *
  282. * FUNCTION:
  283. *
  284. * XDmaChannel_GetControl
  285. *
  286. * DESCRIPTION:
  287. *
  288. * This function gets the control register contents of the DMA channel.
  289. *
  290. * ARGUMENTS:
  291. *
  292. * InstancePtr contains a pointer to the DMA channel to operate on.
  293. *
  294. * RETURN VALUE:
  295. *
  296. * The control register contents of the DMA channel. One or more of the
  297. * following values may be contained the register. Each of the values are
  298. * unique bit masks.
  299. *
  300. * XDC_DMACR_SOURCE_INCR_MASK Increment the source address
  301. * XDC_DMACR_DEST_INCR_MASK Increment the destination address
  302. * XDC_DMACR_SOURCE_LOCAL_MASK Local source address
  303. * XDC_DMACR_DEST_LOCAL_MASK Local destination address
  304. * XDC_DMACR_SG_ENABLE_MASK Scatter gather enable
  305. * XDC_DMACR_GEN_BD_INTR_MASK Individual buffer descriptor interrupt
  306. * XDC_DMACR_LAST_BD_MASK Last buffer descriptor in a packet
  307. *
  308. * NOTES:
  309. *
  310. * None.
  311. *
  312. ******************************************************************************/
  313. u32
  314. XDmaChannel_GetControl(XDmaChannel * InstancePtr)
  315. {
  316. /* assert to verify input arguments */
  317. XASSERT_NONVOID(InstancePtr != NULL);
  318. XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);
  319. /* return the contents of the DMA control register */
  320. return XIo_In32(InstancePtr->RegBaseAddress + XDC_DMAC_REG_OFFSET);
  321. }
  322. /******************************************************************************
  323. *
  324. * FUNCTION:
  325. *
  326. * XDmaChannel_SetControl
  327. *
  328. * DESCRIPTION:
  329. *
  330. * This function sets the control register of the specified DMA channel.
  331. *
  332. * ARGUMENTS:
  333. *
  334. * InstancePtr contains a pointer to the DMA channel to operate on.
  335. *
  336. * Control contains the value to be written to the control register of the DMA
  337. * channel. One or more of the following values may be contained the register.
  338. * Each of the values are unique bit masks such that they may be ORed together
  339. * to enable multiple bits or inverted and ANDed to disable multiple bits.
  340. *
  341. * XDC_DMACR_SOURCE_INCR_MASK Increment the source address
  342. * XDC_DMACR_DEST_INCR_MASK Increment the destination address
  343. * XDC_DMACR_SOURCE_LOCAL_MASK Local source address
  344. * XDC_DMACR_DEST_LOCAL_MASK Local destination address
  345. * XDC_DMACR_SG_ENABLE_MASK Scatter gather enable
  346. * XDC_DMACR_GEN_BD_INTR_MASK Individual buffer descriptor interrupt
  347. * XDC_DMACR_LAST_BD_MASK Last buffer descriptor in a packet
  348. *
  349. * RETURN VALUE:
  350. *
  351. * None.
  352. *
  353. * NOTES:
  354. *
  355. * None.
  356. *
  357. ******************************************************************************/
  358. void
  359. XDmaChannel_SetControl(XDmaChannel * InstancePtr, u32 Control)
  360. {
  361. /* assert to verify input arguments except the control which can't be
  362. * asserted since all values are valid
  363. */
  364. XASSERT_VOID(InstancePtr != NULL);
  365. XASSERT_VOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);
  366. /* set the DMA control register to the specified value */
  367. XIo_Out32(InstancePtr->RegBaseAddress + XDC_DMAC_REG_OFFSET, Control);
  368. }
  369. /******************************************************************************
  370. *
  371. * FUNCTION:
  372. *
  373. * XDmaChannel_GetStatus
  374. *
  375. * DESCRIPTION:
  376. *
  377. * This function gets the status register contents of the DMA channel.
  378. *
  379. * ARGUMENTS:
  380. *
  381. * InstancePtr contains a pointer to the DMA channel to operate on.
  382. *
  383. * RETURN VALUE:
  384. *
  385. * The status register contents of the DMA channel. One or more of the
  386. * following values may be contained the register. Each of the values are
  387. * unique bit masks.
  388. *
  389. * XDC_DMASR_BUSY_MASK The DMA channel is busy
  390. * XDC_DMASR_BUS_ERROR_MASK A bus error occurred
  391. * XDC_DMASR_BUS_TIMEOUT_MASK A bus timeout occurred
  392. * XDC_DMASR_LAST_BD_MASK The last buffer descriptor of a packet
  393. *
  394. * NOTES:
  395. *
  396. * None.
  397. *
  398. ******************************************************************************/
  399. u32
  400. XDmaChannel_GetStatus(XDmaChannel * InstancePtr)
  401. {
  402. /* assert to verify input arguments */
  403. XASSERT_NONVOID(InstancePtr != NULL);
  404. XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);
  405. /* return the contents of the DMA status register */
  406. return XIo_In32(InstancePtr->RegBaseAddress + XDC_DMAS_REG_OFFSET);
  407. }
  408. /******************************************************************************
  409. *
  410. * FUNCTION:
  411. *
  412. * XDmaChannel_SetIntrStatus
  413. *
  414. * DESCRIPTION:
  415. *
  416. * This function sets the interrupt status register of the specified DMA channel.
  417. * Setting any bit of the interrupt status register will clear the bit to
  418. * indicate the interrupt processing has been completed. The definitions of each
  419. * bit in the register match the definition of the bits in the interrupt enable
  420. * register.
  421. *
  422. * ARGUMENTS:
  423. *
  424. * InstancePtr contains a pointer to the DMA channel to operate on.
  425. *
  426. * Status contains the value to be written to the status register of the DMA
  427. * channel. One or more of the following values may be contained the register.
  428. * Each of the values are unique bit masks such that they may be ORed together
  429. * to enable multiple bits or inverted and ANDed to disable multiple bits.
  430. *
  431. * XDC_IXR_DMA_DONE_MASK The dma operation is done
  432. * XDC_IXR_DMA_ERROR_MASK The dma operation had an error
  433. * XDC_IXR_PKT_DONE_MASK A packet is complete
  434. * XDC_IXR_PKT_THRESHOLD_MASK The packet count threshold reached
  435. * XDC_IXR_PKT_WAIT_BOUND_MASK The packet wait bound reached
  436. * XDC_IXR_SG_DISABLE_ACK_MASK The scatter gather disable completed
  437. * XDC_IXR_BD_MASK A buffer descriptor is done
  438. *
  439. * RETURN VALUE:
  440. *
  441. * None.
  442. *
  443. * NOTES:
  444. *
  445. * None.
  446. *
  447. ******************************************************************************/
  448. void
  449. XDmaChannel_SetIntrStatus(XDmaChannel * InstancePtr, u32 Status)
  450. {
  451. /* assert to verify input arguments except the status which can't be
  452. * asserted since all values are valid
  453. */
  454. XASSERT_VOID(InstancePtr != NULL);
  455. XASSERT_VOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);
  456. /* set the interrupt status register with the specified value such that
  457. * all bits which are set in the register are cleared effectively clearing
  458. * any active interrupts
  459. */
  460. XIo_Out32(InstancePtr->RegBaseAddress + XDC_IS_REG_OFFSET, Status);
  461. }
  462. /******************************************************************************
  463. *
  464. * FUNCTION:
  465. *
  466. * XDmaChannel_GetIntrStatus
  467. *
  468. * DESCRIPTION:
  469. *
  470. * This function gets the interrupt status register of the specified DMA channel.
  471. * The interrupt status register indicates which interrupts are active
  472. * for the DMA channel. If an interrupt is active, the status register must be
  473. * set (written) with the bit set for each interrupt which has been processed
  474. * in order to clear the interrupts. The definitions of each bit in the register
  475. * match the definition of the bits in the interrupt enable register.
  476. *
  477. * ARGUMENTS:
  478. *
  479. * InstancePtr contains a pointer to the DMA channel to operate on.
  480. *
  481. * RETURN VALUE:
  482. *
  483. * The interrupt status register contents of the specified DMA channel.
  484. * One or more of the following values may be contained the register.
  485. * Each of the values are unique bit masks.
  486. *
  487. * XDC_IXR_DMA_DONE_MASK The dma operation is done
  488. * XDC_IXR_DMA_ERROR_MASK The dma operation had an error
  489. * XDC_IXR_PKT_DONE_MASK A packet is complete
  490. * XDC_IXR_PKT_THRESHOLD_MASK The packet count threshold reached
  491. * XDC_IXR_PKT_WAIT_BOUND_MASK The packet wait bound reached
  492. * XDC_IXR_SG_DISABLE_ACK_MASK The scatter gather disable completed
  493. * XDC_IXR_SG_END_MASK Current descriptor was the end of the list
  494. * XDC_IXR_BD_MASK A buffer descriptor is done
  495. *
  496. * NOTES:
  497. *
  498. * None.
  499. *
  500. ******************************************************************************/
  501. u32
  502. XDmaChannel_GetIntrStatus(XDmaChannel * InstancePtr)
  503. {
  504. /* assert to verify input arguments */
  505. XASSERT_NONVOID(InstancePtr != NULL);
  506. XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);
  507. /* return the contents of the interrupt status register */
  508. return XIo_In32(InstancePtr->RegBaseAddress + XDC_IS_REG_OFFSET);
  509. }
  510. /******************************************************************************
  511. *
  512. * FUNCTION:
  513. *
  514. * XDmaChannel_SetIntrEnable
  515. *
  516. * DESCRIPTION:
  517. *
  518. * This function sets the interrupt enable register of the specified DMA
  519. * channel. The interrupt enable register contains bits which enable
  520. * individual interrupts for the DMA channel. The definitions of each bit
  521. * in the register match the definition of the bits in the interrupt status
  522. * register.
  523. *
  524. * ARGUMENTS:
  525. *
  526. * InstancePtr contains a pointer to the DMA channel to operate on.
  527. *
  528. * Enable contains the interrupt enable register contents to be written
  529. * in the DMA channel. One or more of the following values may be contained
  530. * the register. Each of the values are unique bit masks such that they may be
  531. * ORed together to enable multiple bits or inverted and ANDed to disable
  532. * multiple bits.
  533. *
  534. * XDC_IXR_DMA_DONE_MASK The dma operation is done
  535. * XDC_IXR_DMA_ERROR_MASK The dma operation had an error
  536. * XDC_IXR_PKT_DONE_MASK A packet is complete
  537. * XDC_IXR_PKT_THRESHOLD_MASK The packet count threshold reached
  538. * XDC_IXR_PKT_WAIT_BOUND_MASK The packet wait bound reached
  539. * XDC_IXR_SG_DISABLE_ACK_MASK The scatter gather disable completed
  540. * XDC_IXR_SG_END_MASK Current descriptor was the end of the list
  541. * XDC_IXR_BD_MASK A buffer descriptor is done
  542. *
  543. * RETURN VALUE:
  544. *
  545. * None.
  546. *
  547. * NOTES:
  548. *
  549. * None.
  550. *
  551. ******************************************************************************/
  552. void
  553. XDmaChannel_SetIntrEnable(XDmaChannel * InstancePtr, u32 Enable)
  554. {
  555. /* assert to verify input arguments except the enable which can't be
  556. * asserted since all values are valid
  557. */
  558. XASSERT_VOID(InstancePtr != NULL);
  559. XASSERT_VOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);
  560. /* set the interrupt enable register to the specified value */
  561. XIo_Out32(InstancePtr->RegBaseAddress + XDC_IE_REG_OFFSET, Enable);
  562. }
  563. /******************************************************************************
  564. *
  565. * FUNCTION:
  566. *
  567. * XDmaChannel_GetIntrEnable
  568. *
  569. * DESCRIPTION:
  570. *
  571. * This function gets the interrupt enable of the DMA channel. The
  572. * interrupt enable contains flags which enable individual interrupts for the
  573. * DMA channel. The definitions of each bit in the register match the definition
  574. * of the bits in the interrupt status register.
  575. *
  576. * ARGUMENTS:
  577. *
  578. * InstancePtr contains a pointer to the DMA channel to operate on.
  579. *
  580. * RETURN VALUE:
  581. *
  582. * The interrupt enable of the DMA channel. One or more of the following values
  583. * may be contained the register. Each of the values are unique bit masks.
  584. *
  585. * XDC_IXR_DMA_DONE_MASK The dma operation is done
  586. * XDC_IXR_DMA_ERROR_MASK The dma operation had an error
  587. * XDC_IXR_PKT_DONE_MASK A packet is complete
  588. * XDC_IXR_PKT_THRESHOLD_MASK The packet count threshold reached
  589. * XDC_IXR_PKT_WAIT_BOUND_MASK The packet wait bound reached
  590. * XDC_IXR_SG_DISABLE_ACK_MASK The scatter gather disable completed
  591. * XDC_IXR_BD_MASK A buffer descriptor is done
  592. *
  593. * NOTES:
  594. *
  595. * None.
  596. *
  597. ******************************************************************************/
  598. u32
  599. XDmaChannel_GetIntrEnable(XDmaChannel * InstancePtr)
  600. {
  601. /* assert to verify input arguments */
  602. XASSERT_NONVOID(InstancePtr != NULL);
  603. XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);
  604. /* return the contents of the interrupt enable register */
  605. return XIo_In32(InstancePtr->RegBaseAddress + XDC_IE_REG_OFFSET);
  606. }
  607. /******************************************************************************
  608. *
  609. * FUNCTION:
  610. *
  611. * XDmaChannel_Transfer
  612. *
  613. * DESCRIPTION:
  614. *
  615. * This function starts the DMA channel transferring data from a memory source
  616. * to a memory destination. This function only starts the operation and returns
  617. * before the operation may be complete. If the interrupt is enabled, an
  618. * interrupt will be generated when the operation is complete, otherwise it is
  619. * necessary to poll the channel status to determine when it's complete. It is
  620. * the responsibility of the caller to determine when the operation is complete
  621. * by handling the generated interrupt or polling the status. It is also the
  622. * responsibility of the caller to ensure that the DMA channel is not busy with
  623. * another transfer before calling this function.
  624. *
  625. * ARGUMENTS:
  626. *
  627. * InstancePtr contains a pointer to the DMA channel to operate on.
  628. *
  629. * SourcePtr contains a pointer to the source memory where the data is to
  630. * be tranferred from and must be 32 bit aligned.
  631. *
  632. * DestinationPtr contains a pointer to the destination memory where the data
  633. * is to be transferred and must be 32 bit aligned.
  634. *
  635. * ByteCount contains the number of bytes to transfer during the DMA operation.
  636. *
  637. * RETURN VALUE:
  638. *
  639. * None.
  640. *
  641. * NOTES:
  642. *
  643. * The DMA h/w will not currently allow a non-local memory transfer to non-local
  644. * memory (memory copy), but only allows a non-local memory to or from the device
  645. * memory (typically a FIFO).
  646. *
  647. * It is the responsibility of the caller to ensure that the cache is
  648. * flushed and invalidated both before and after the DMA operation completes
  649. * if the memory pointed to is cached. The caller must also ensure that the
  650. * pointers contain a physical address rather than a virtual address
  651. * if address translation is being used.
  652. *
  653. ******************************************************************************/
  654. void
  655. XDmaChannel_Transfer(XDmaChannel * InstancePtr,
  656. u32 * SourcePtr, u32 * DestinationPtr, u32 ByteCount)
  657. {
  658. /* assert to verify input arguments and the alignment of any arguments
  659. * which have expected alignments
  660. */
  661. XASSERT_VOID(InstancePtr != NULL);
  662. XASSERT_VOID(SourcePtr != NULL);
  663. XASSERT_VOID(((u32) SourcePtr & 3) == 0);
  664. XASSERT_VOID(DestinationPtr != NULL);
  665. XASSERT_VOID(((u32) DestinationPtr & 3) == 0);
  666. XASSERT_VOID(ByteCount != 0);
  667. XASSERT_VOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);
  668. /* setup the source and destination address registers for the transfer */
  669. XIo_Out32(InstancePtr->RegBaseAddress + XDC_SA_REG_OFFSET,
  670. (u32) SourcePtr);
  671. XIo_Out32(InstancePtr->RegBaseAddress + XDC_DA_REG_OFFSET,
  672. (u32) DestinationPtr);
  673. /* start the DMA transfer to copy from the source buffer to the
  674. * destination buffer by writing the length to the length register
  675. */
  676. XIo_Out32(InstancePtr->RegBaseAddress + XDC_LEN_REG_OFFSET, ByteCount);
  677. }