alt_dma.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #ifndef __ALT_DMA_H__
  2. #define __ALT_DMA_H__
  3. /******************************************************************************
  4. * *
  5. * License Agreement *
  6. * *
  7. * Copyright (c) 2004-2005 Altera Corporation, San Jose, California, USA. *
  8. * All rights reserved. *
  9. * *
  10. * Permission is hereby granted, free of charge, to any person obtaining a *
  11. * copy of this software and associated documentation files (the "Software"), *
  12. * to deal in the Software without restriction, including without limitation *
  13. * the rights to use, copy, modify, merge, publish, distribute, sublicense, *
  14. * and/or sell copies of the Software, and to permit persons to whom the *
  15. * Software is furnished to do so, subject to the following conditions: *
  16. * *
  17. * The above copyright notice and this permission notice shall be included in *
  18. * all copies or substantial portions of the Software. *
  19. * *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
  21. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
  22. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
  23. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
  24. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
  25. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
  26. * DEALINGS IN THE SOFTWARE. *
  27. * *
  28. * This agreement shall be governed in all respects by the laws of the State *
  29. * of California and by the laws of the United States of America. *
  30. * *
  31. * Altera does not recommend, suggest or require that this reference design *
  32. * file be used in conjunction or combination with any other product. *
  33. ******************************************************************************/
  34. /******************************************************************************
  35. * *
  36. * THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
  37. * *
  38. ******************************************************************************/
  39. #include "sys/alt_dma_dev.h"
  40. #include "alt_types.h"
  41. #include <errno.h>
  42. #ifdef __cplusplus
  43. extern "C"
  44. {
  45. #endif /* __cplusplus */
  46. /*
  47. * This header contains the application side interface for accessing DMA
  48. * resources. See alt_dma_dev.h for the dma device driver interface.
  49. *
  50. * The interface model treats a DMA transaction as being composed of two
  51. * halves (read and write).
  52. *
  53. * The application can supply data for transmit using an "alt_dma_txchan"
  54. * descriptor. Alternatively an "alt_dma_rxchan" descriptor can be used to
  55. * receive data.
  56. */
  57. /*
  58. * alt_dma_txchan_open() is used to obtain an "alt_dma_txchan" descriptor for
  59. * a DMA transmit device. The name is the name of the associated physical
  60. * device (e.g. "/dev/dma_0").
  61. *
  62. * The return value will be NULL on failure, and non-NULL otherwise.
  63. */
  64. extern alt_dma_txchan alt_dma_txchan_open (const char* name);
  65. /*
  66. * alt_dma_txchan_close() is provided so that an application can notify the
  67. * system that it has finished with a given DMA transmit channel. This is only
  68. * provided for completness.
  69. */
  70. static ALT_INLINE int alt_dma_txchan_close (alt_dma_txchan dma)
  71. {
  72. return 0;
  73. }
  74. /*
  75. * alt_dma_txchan_send() posts a transmit request to a DMA transmit channel.
  76. * The input arguments are:
  77. *
  78. * dma: the channel to use.
  79. * from: a pointer to the start of the data to send.
  80. * length: the length of the data to send in bytes.
  81. * done: callback function that will be called once the data has been sent.
  82. * handle: opaque value passed to "done".
  83. *
  84. * The return value will be negative if the request cannot be posted, and
  85. * zero otherwise.
  86. */
  87. static ALT_INLINE int alt_dma_txchan_send (alt_dma_txchan dma,
  88. const void* from,
  89. alt_u32 length,
  90. alt_txchan_done* done,
  91. void* handle)
  92. {
  93. return dma ? dma->dma_send (dma,
  94. from,
  95. length,
  96. done,
  97. handle) : -ENODEV;
  98. }
  99. /*
  100. * alt_dma_txchan_space() returns the number of tranmit requests that can be
  101. * posted to the specified DMA transmit channel.
  102. *
  103. * A negative value indicates that the value could not be determined.
  104. */
  105. static ALT_INLINE int alt_dma_txchan_space (alt_dma_txchan dma)
  106. {
  107. return dma ? dma->space (dma) : -ENODEV;
  108. }
  109. /*
  110. * alt_dma_txchan_ioctl() can be used to perform device specific I/O
  111. * operations on the indicated DMA transmit channel. For example some drivers
  112. * support options to control the width of the transfer operations. See
  113. * alt_dma_dev.h for the list of generic requests.
  114. *
  115. * A negative return value indicates failure, otherwise the interpretation
  116. * of the return value is request specific.
  117. */
  118. static ALT_INLINE int alt_dma_txchan_ioctl (alt_dma_txchan dma,
  119. int req,
  120. void* arg)
  121. {
  122. return dma ? dma->ioctl (dma, req, arg) : -ENODEV;
  123. }
  124. /*
  125. * alt_dma_rxchan_open() is used to obtain an "alt_dma_rxchan" descriptor for
  126. * a DMA receive channel. The name is the name of the associated physical
  127. * device (e.g. "/dev/dma_0").
  128. *
  129. * The return value will be NULL on failure, and non-NULL otherwise.
  130. */
  131. extern alt_dma_rxchan alt_dma_rxchan_open (const char* dev);
  132. /*
  133. * alt_dma_rxchan_close() is provided so that an application can notify the
  134. * system that it has finished with a given DMA receive channel. This is only
  135. * provided for completness.
  136. */
  137. static ALT_INLINE int alt_dma_rxchan_close (alt_dma_rxchan dma)
  138. {
  139. return 0;
  140. }
  141. /*
  142. *
  143. */
  144. /*
  145. * alt_dma_rxchan_prepare() posts a receive request to a DMA receive channel.
  146. *
  147. * The input arguments are:
  148. *
  149. * dma: the channel to use.
  150. * data: a pointer to the location that data is to be received to.
  151. * len: the maximum length of the data to receive.
  152. * done: callback function that will be called once the data has been
  153. * received.
  154. * handle: opaque value passed to "done".
  155. *
  156. * The return value will be negative if the request cannot be posted, and
  157. * zero otherwise.
  158. */
  159. static ALT_INLINE int alt_dma_rxchan_prepare (alt_dma_rxchan dma,
  160. void* data,
  161. alt_u32 len,
  162. alt_rxchan_done* done,
  163. void* handle)
  164. {
  165. return dma ? dma->prepare (dma, data, len, done, handle) : -ENODEV;
  166. }
  167. /*
  168. * alt_dma_rxchan_ioctl() can be used to perform device specific I/O
  169. * operations on the indicated DMA receive channel. For example some drivers
  170. * support options to control the width of the transfer operations. See
  171. * alt_dma_dev.h for the list of generic requests.
  172. *
  173. * A negative return value indicates failure, otherwise the interpretation
  174. * of the return value is request specific.
  175. */
  176. static ALT_INLINE int alt_dma_rxchan_ioctl (alt_dma_rxchan dma,
  177. int req,
  178. void* arg)
  179. {
  180. return dma ? dma->ioctl (dma, req, arg) : -ENODEV;
  181. }
  182. /*
  183. * alt_dma_rxchan_depth() returns the depth of the receive FIFO used to store
  184. * receive requests.
  185. */
  186. static ALT_INLINE alt_u32 alt_dma_rxchan_depth(alt_dma_rxchan dma)
  187. {
  188. return dma->depth;
  189. }
  190. /*
  191. *
  192. */
  193. #ifdef __cplusplus
  194. }
  195. #endif /* __cplusplus */
  196. #endif /* __ALT_DMA_H__ */