alt_dma_dev.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #ifndef __ALT_DMA_DEV_H__
  2. #define __ALT_DMA_DEV_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 "priv/alt_dev_llist.h"
  40. #include "alt_types.h"
  41. #ifdef __cplusplus
  42. extern "C"
  43. {
  44. #endif /* __cplusplus */
  45. /*
  46. * This header contains the device driver interface for accessing DMA
  47. * resources. See alt_dma.h for the DMA application side interface.
  48. *
  49. * The interface model treats a DMA transaction as being composed of two
  50. * halves (read and write).
  51. *
  52. * An "alt_dma_txchan_dev" is used to describe the device associated with a
  53. * DMA transmit channel. An "alt_dma_rxchan_dev" is used to describe the
  54. * device associated with a DMA receive channel.
  55. */
  56. /*
  57. * List of generic ioctl requests that may be supported by a DMA device.
  58. *
  59. * ALT_DMA_RX_ONLY_ON: This causes a DMA channel to operate in a mode
  60. * where only the receiver is under software control.
  61. * The other side reads continously from a single
  62. * location. The address to read is the argument to
  63. * this request.
  64. * ALT_DMA_RX_ONLY_OFF: Return to the default mode where both the receive
  65. * and transmit sides of the DMA can be under software
  66. * control.
  67. * ALT_DMA_TX_ONLY_ON: This causes a DMA channel to operate in a mode
  68. * where only the transmitter is under software control.
  69. * The other side writes continously to a single
  70. * location. The address to write to is the argument to
  71. * this request.
  72. * ALT_DMA_TX_ONLY_OFF: Return to the default mode where both the receive
  73. * and transmit sides of the DMA can be under software
  74. * control.
  75. * ALT_DMA_SET_MODE_8: Transfer data in units of 8 bits.
  76. * ALT_DMA_SET_MODE_16: Transfer data in units of 16 bits.
  77. * ALT_DMA_SET_MODE_32: Transfer data in units of 32 bits.
  78. * ALT_DMA_SET_MODE_64: Transfer data in units of 64 bits.
  79. * ALT_DMA_SET_MODE_128: Transfer data in units of 128 bits.
  80. * ALT_DMA_GET_MODE: Get the current transfer mode.
  81. *
  82. * The use of the macros: ALT_DMA_TX_STREAM_ON, ALT_DMA_TX_STREAM_OFF
  83. * ALT_DMA_RX_STREAM_OFF and ALT_DMA_RX_STREAM_ON are depreciated. You should
  84. * instead use the macros: ALT_DMA_RX_ONLY_ON, ALT_DMA_RX_ONLY_OFF,
  85. * ALT_DMA_TX_ONLY_ON and ALT_DMA_TX_ONLY_OFF.
  86. */
  87. #define ALT_DMA_TX_STREAM_ON (0x1)
  88. #define ALT_DMA_TX_STREAM_OFF (0x2)
  89. #define ALT_DMA_RX_STREAM_ON (0x3)
  90. #define ALT_DMA_RX_STREAM_OFF (0x4)
  91. #define ALT_DMA_SET_MODE_8 (0x5)
  92. #define ALT_DMA_SET_MODE_16 (0x6)
  93. #define ALT_DMA_SET_MODE_32 (0x7)
  94. #define ALT_DMA_SET_MODE_64 (0x8)
  95. #define ALT_DMA_SET_MODE_128 (0x9)
  96. #define ALT_DMA_GET_MODE (0xa)
  97. #define ALT_DMA_RX_ONLY_ON ALT_DMA_TX_STREAM_ON
  98. #define ALT_DMA_RX_ONLY_OFF ALT_DMA_TX_STREAM_OFF
  99. #define ALT_DMA_TX_ONLY_ON ALT_DMA_RX_STREAM_ON
  100. #define ALT_DMA_TX_ONLY_OFF ALT_DMA_RX_STREAM_OFF
  101. /*
  102. *
  103. */
  104. typedef struct alt_dma_txchan_dev_s alt_dma_txchan_dev;
  105. typedef struct alt_dma_rxchan_dev_s alt_dma_rxchan_dev;
  106. typedef alt_dma_txchan_dev* alt_dma_txchan;
  107. typedef alt_dma_rxchan_dev* alt_dma_rxchan;
  108. typedef void (alt_txchan_done)(void* handle);
  109. typedef void (alt_rxchan_done)(void* handle, void* data);
  110. /*
  111. * devices that provide a DMA transmit channel are required to provide an
  112. * instance of the "alt_dma_txchan_dev" structure.
  113. */
  114. struct alt_dma_txchan_dev_s {
  115. alt_llist llist; /* for internal use */
  116. const char* name; /* name of the device instance
  117. * (e.g. "/dev/dma_0").
  118. */
  119. int (*space) (alt_dma_txchan dma); /* returns the maximum number of
  120. * transmit requests that can be posted
  121. */
  122. int (*dma_send) (alt_dma_txchan dma,
  123. const void* from,
  124. alt_u32 len,
  125. alt_txchan_done* done,
  126. void* handle); /* post a transmit request */
  127. int (*ioctl) (alt_dma_txchan dma, int req, void* arg); /* perform device
  128. * specific I/O control.
  129. */
  130. };
  131. /*
  132. * devices that provide a DMA receive channel are required to provide an
  133. * instance of the "alt_dma_rxchan_dev" structure.
  134. */
  135. struct alt_dma_rxchan_dev_s {
  136. alt_llist list; /* for internal use */
  137. const char* name; /* name of the device instance
  138. * (e.g. "/dev/dma_0").
  139. */
  140. alt_u32 depth; /* maximum number of receive requests that
  141. * can be posted.
  142. */
  143. int (*prepare) (alt_dma_rxchan dma,
  144. void* data,
  145. alt_u32 len,
  146. alt_rxchan_done* done,
  147. void* handle); /* post a receive request */
  148. int (*ioctl) (alt_dma_rxchan dma, int req, void* arg); /* perform device
  149. * specific I/O control.
  150. */
  151. };
  152. /*
  153. * Register a DMA transmit channel with the system.
  154. */
  155. static ALT_INLINE int alt_dma_txchan_reg (alt_dma_txchan_dev* dev)
  156. {
  157. extern alt_llist alt_dma_txchan_list;
  158. return alt_dev_llist_insert((alt_dev_llist*) dev, &alt_dma_txchan_list);
  159. }
  160. /*
  161. * Register a DMA receive channel with the system.
  162. */
  163. static ALT_INLINE int alt_dma_rxchan_reg (alt_dma_rxchan_dev* dev)
  164. {
  165. extern alt_llist alt_dma_rxchan_list;
  166. return alt_dev_llist_insert((alt_dev_llist*) dev, &alt_dma_rxchan_list);
  167. }
  168. /*
  169. *
  170. */
  171. #ifdef __cplusplus
  172. }
  173. #endif /* __cplusplus */
  174. #endif /* __ALT_DMA_DEV_H__ */