1
0

dmahost.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. /*++
  2. Copyright (c) 2016 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. dmahost.h
  5. Abstract:
  6. This header contains definitions for creating and managing Direct Memory
  7. Access controllers.
  8. Author:
  9. Evan Green 2-Feb-2016
  10. --*/
  11. //
  12. // ------------------------------------------------------------------- Includes
  13. //
  14. #include <minoca/dma/dma.h>
  15. //
  16. // ---------------------------------------------------------------- Definitions
  17. //
  18. #ifndef DMA_API
  19. #define DMA_API __DLLIMPORT
  20. #endif
  21. #define DMA_CONTROLLER_INFORMATION_VERSION 1
  22. //
  23. // ------------------------------------------------------ Data Type Definitions
  24. //
  25. typedef struct _DMA_CONTROLLER DMA_CONTROLLER, *PDMA_CONTROLLER;
  26. typedef
  27. KSTATUS
  28. (*PDMA_HOST_SUBMIT_TRANSFER) (
  29. PVOID Context,
  30. PDMA_TRANSFER Transfer
  31. );
  32. /*++
  33. Routine Description:
  34. This routine is called to execute a transfer on the DMA controller.
  35. Arguments:
  36. Context - Supplies the host controller context.
  37. Transfer - Supplies a pointer to the transfer to begin executing. The
  38. controller can return immediately, and should call
  39. DmaProcessCompletedTransfer when the transfer completes.
  40. Return Value:
  41. Status code indicating whether or not the transfer was successfully
  42. started.
  43. --*/
  44. typedef
  45. KSTATUS
  46. (*PDMA_HOST_CANCEL_TRANSFER) (
  47. PVOID Context,
  48. PDMA_TRANSFER Transfer
  49. );
  50. /*++
  51. Routine Description:
  52. This routine is called to cancel an in-progress transfer. Once this routine
  53. returns, the transfer should be all the way out of the DMA controller and
  54. the controller should no longer interrupt because of this transfer. This
  55. routine is called at dispatch level.
  56. Arguments:
  57. Context - Supplies the host controller context.
  58. Transfer - Supplies a pointer to the transfer to cancel.
  59. Return Value:
  60. STATUS_SUCCESS on success.
  61. STATUS_TOO_LATE if the transfer is already complete.
  62. Other errors on other failures.
  63. --*/
  64. typedef
  65. KSTATUS
  66. (*PDMA_HOST_CONTROL_REQUEST) (
  67. PVOID Context,
  68. PDMA_TRANSFER Transfer,
  69. PVOID Request,
  70. UINTN RequestSize
  71. );
  72. /*++
  73. Routine Description:
  74. This routine is called to perform a DMA controller-specific operation. It
  75. provides a direct link between DMA controllers and users, for controller-
  76. specific functionality.
  77. Arguments:
  78. Context - Supplies the host controller context.
  79. Transfer - Supplies an optional pointer to the transfer involved.
  80. Request - Supplies a pointer to the request/response data.
  81. RequestSize - Supplies the size of the request in bytes.
  82. Return Value:
  83. Status code.
  84. --*/
  85. /*++
  86. Structure Description:
  87. This structure stores the set of Direct Memory Access controller functions
  88. called by the DMA library.
  89. Members:
  90. SubmitTransfer - Stores a pointer to a function used to begin a new
  91. transfer.
  92. CancelTransfer - Stores a pointer to a function used to cancel a transfer.
  93. ControlRequest - Stores a pointer to a function used to implemented
  94. controller-specific functionality.
  95. --*/
  96. typedef struct _DMA_FUNCTION_TABLE {
  97. PDMA_HOST_SUBMIT_TRANSFER SubmitTransfer;
  98. PDMA_HOST_CANCEL_TRANSFER CancelTransfer;
  99. PDMA_HOST_CONTROL_REQUEST ControlRequest;
  100. } DMA_FUNCTION_TABLE, *PDMA_FUNCTION_TABLE;
  101. /*++
  102. Structure Description:
  103. This structure defines the information provided to the DMA library by a
  104. Direct Memory Access controller.
  105. Members:
  106. Version - Stores the value DMA_CONTROLLER_INFORMATION_VERSION, used to
  107. enable future expansion of this structure.
  108. Context - Stores an opaque context pointer that is passed to the DMA
  109. controller functions.
  110. Device - Stores a pointer to the OS device associated with this controller.
  111. Information - Stores the information to be returned to users via the
  112. interface.
  113. Features - Stores a bitfield of features about this controller. See
  114. DMA_FEATURE_* definitions.
  115. FunctionTable - Stores the table of functions the library uses to call back
  116. into the controller.
  117. --*/
  118. typedef struct _DMA_CONTROLLER_INFORMATION {
  119. ULONG Version;
  120. PVOID Context;
  121. PDEVICE Device;
  122. DMA_INFORMATION Information;
  123. ULONG Features;
  124. DMA_FUNCTION_TABLE FunctionTable;
  125. } DMA_CONTROLLER_INFORMATION, *PDMA_CONTROLLER_INFORMATION;
  126. //
  127. // -------------------------------------------------------------------- Globals
  128. //
  129. //
  130. // -------------------------------------------------------- Function Prototypes
  131. //
  132. DMA_API
  133. KSTATUS
  134. DmaCreateController (
  135. PDMA_CONTROLLER_INFORMATION Registration,
  136. PDMA_CONTROLLER *Controller
  137. );
  138. /*++
  139. Routine Description:
  140. This routine creates a new Direct Memory Access controller.
  141. Arguments:
  142. Registration - Supplies a pointer to the host registration information.
  143. Controller - Supplies a pointer where a pointer to the new controller will
  144. be returned on success.
  145. Return Value:
  146. Status code.
  147. --*/
  148. DMA_API
  149. VOID
  150. DmaDestroyController (
  151. PDMA_CONTROLLER Controller
  152. );
  153. /*++
  154. Routine Description:
  155. This routine destroys a Direct Memory Access controller.
  156. Arguments:
  157. Controller - Supplies a pointer to the controller to tear down.
  158. Return Value:
  159. None.
  160. --*/
  161. DMA_API
  162. KSTATUS
  163. DmaStartController (
  164. PDMA_CONTROLLER Controller
  165. );
  166. /*++
  167. Routine Description:
  168. This routine starts a Direct Memory Access controller. This function is
  169. not thread safe, as it is meant to be called during the start IRP, which is
  170. always serialized.
  171. Arguments:
  172. Controller - Supplies a pointer to the controller.
  173. Return Value:
  174. Status code.
  175. --*/
  176. DMA_API
  177. VOID
  178. DmaStopController (
  179. PDMA_CONTROLLER Controller
  180. );
  181. /*++
  182. Routine Description:
  183. This routine stops a Direct Memory Access controller. This function is not
  184. thread safe, as it is meant to be called during a state transition IRP,
  185. which is always serialized.
  186. Arguments:
  187. Controller - Supplies a pointer to the controller.
  188. Return Value:
  189. None.
  190. --*/
  191. DMA_API
  192. PDMA_TRANSFER
  193. DmaTransferCompletion (
  194. PDMA_CONTROLLER Controller,
  195. PDMA_TRANSFER Transfer
  196. );
  197. /*++
  198. Routine Description:
  199. This routine is called by a DMA host controller when a transfer has
  200. completed. This function must be called at or below dispatch level. The
  201. host should have already filled in the number of bytes completed and the
  202. status.
  203. Arguments:
  204. Controller - Supplies a pointer to the controller.
  205. Transfer - Supplies a pointer to the transfer that completed.
  206. Return Value:
  207. Returns a pointer to the next transfer to start.
  208. NULL if no more transfers are queued.
  209. --*/