dma.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. /*++
  2. Copyright (c) 2016 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. dma.h
  5. Abstract:
  6. This header contains definitions for interacting with generic Direct Memory
  7. Access controllers.
  8. Author:
  9. Evan Green 1-Feb-2016
  10. --*/
  11. //
  12. // ------------------------------------------------------------------- Includes
  13. //
  14. //
  15. // ---------------------------------------------------------------- Definitions
  16. //
  17. //
  18. // UUID for interfacing with Direct Memory Access controllers.
  19. //
  20. #define UUID_DMA_INTERFACE \
  21. {{0x33D10646, 0x595A4840, 0x9D42E2EA, 0x5C13FBA8}}
  22. //
  23. // Define DMA transfer flags.
  24. //
  25. //
  26. // Set this flag to advance the device address. If this flag is clear, the
  27. // device address will not change throughout the course of the transfer
  28. // (appropriate for writing to a register).
  29. //
  30. #define DMA_TRANSFER_ADVANCE_DEVICE 0x00000001
  31. //
  32. // Define the current version of the DMA information table.
  33. //
  34. #define DMA_INFORMATION_VERSION 1
  35. #define DMA_INFORMATION_MAX_VERSION 0x00001000
  36. //
  37. // ------------------------------------------------------ Data Type Definitions
  38. //
  39. typedef enum _DMA_TRANSFER_DIRECTION {
  40. DmaTransferDirectionInvalid,
  41. DmaTransferToDevice,
  42. DmaTransferFromDevice,
  43. DmaTransferMemoryToMemory
  44. } DMA_TRANSFER_DIRECTION, *PDMA_TRANSFER_DIRECTION;
  45. //
  46. // Define the type of an open DMA connection.
  47. //
  48. typedef struct _DMA_INTERFACE DMA_INTERFACE, *PDMA_INTERFACE;
  49. typedef struct _DMA_TRANSFER DMA_TRANSFER, *PDMA_TRANSFER;
  50. typedef
  51. VOID
  52. (*PDMA_TRANSFER_COMPLETION_CALLBACK) (
  53. PDMA_TRANSFER Transfer
  54. );
  55. /*++
  56. Routine Description:
  57. This routine is called when a transfer set has completed or errored out.
  58. Arguments:
  59. Transfer - Supplies a pointer to the transfer that completed.
  60. Return Value:
  61. None.
  62. --*/
  63. /*++
  64. Structure Description:
  65. This structure stores information about a DMA controller.
  66. Members:
  67. Version - Stores the version number of this table. This is set to
  68. DMA_INFORMATION_VERSION.
  69. ControllerUuid - Stores a universally unique identifier that identifies the
  70. manufacturer and model of the DMA controller. This specifies the format
  71. of the controller-specific configuration information.
  72. ControllerRevision - Stores the minor revision information for the DMA
  73. controller. Changes in these revisions are not significant enough to
  74. change the configuration and information structures.
  75. ExtendedInfo - Stores a pointer to controller-specific extended information,
  76. the format of which depends on the UUID.
  77. ExtendedInfoSize - Stores the size of the extended information in bytes.
  78. ChannelCount - Stores the number of channels in the controller.
  79. MinAddress - Stores the lowest physical address (inclusive) that the DMA
  80. controller can access.
  81. MaxAddress - Stores the highest physical address (inclusive) that the DMA
  82. controller can access.
  83. --*/
  84. typedef struct _DMA_INFORMATION {
  85. ULONG Version;
  86. UUID ControllerUuid;
  87. ULONG ControllerRevision;
  88. PVOID ExtendedInfo;
  89. UINTN ExtendedInfoSize;
  90. ULONG ChannelCount;
  91. PHYSICAL_ADDRESS MinAddress;
  92. PHYSICAL_ADDRESS MaxAddress;
  93. } DMA_INFORMATION, *PDMA_INFORMATION;
  94. /*++
  95. Structure Description:
  96. This structure stores information about a single DMA transfer request.
  97. Members:
  98. ListEntry - Stores a list entry used internally by the DMA library. Users
  99. should ignore this member.
  100. Allocation - Stores a pointer to the resource allocation describing the
  101. channel, request line, and a few other standardized DMA configuration
  102. details.
  103. Configuration - Stores a pointer to the controller-specific DMA channel
  104. configuration for this transfer. This memory should remain valid for
  105. the duration of the transfer.
  106. ConfigurationSize - Stores the size of configuration data in bytes.
  107. Direction - Stores the transfer direction. For memory to memory transfers,
  108. the transfer always goes from the "memory" member to the
  109. "device memory" member.
  110. Memory - Stores a pointer to the memory side of the transfer. This is the
  111. non-device side. This must be a non-paged I/O buffer.
  112. Device - Stores a pointer to the device side of the transfer, or the
  113. destination for memory to memory transfers.
  114. CompletionCallback - Stores a pointer to the routine to call when the
  115. transfer is complete. This callback will occur at dispatch level.
  116. UserContext - Stores a pointer's worth of context information that is
  117. unused by the DMA library or host controller. The user can store
  118. context here.
  119. Size - Stores the size of the transfer in bytes. It is an error if this
  120. size does not translate evenly to bus sized transactions. This size may
  121. be truncated after submission if there weren't enough internal DMA
  122. descriptors to accommodate the full size.
  123. Width - Stores the width of the transfer, in bytes. Supply 0 to use the
  124. width from the resource allocation.
  125. Flags - Stores a bitfield of flags governing the transfer. See
  126. DMA_TRANSFER_* definitions.
  127. Completed - Stores the number of bytes successfully transferred.
  128. Status - Stores the final status code of the transfer, as returned by the
  129. DMA controller.
  130. --*/
  131. struct _DMA_TRANSFER {
  132. LIST_ENTRY ListEntry;
  133. PRESOURCE_ALLOCATION Allocation;
  134. PVOID Configuration;
  135. UINTN ConfigurationSize;
  136. DMA_TRANSFER_DIRECTION Direction;
  137. PIO_BUFFER Memory;
  138. union {
  139. PHYSICAL_ADDRESS Address;
  140. PIO_BUFFER Memory;
  141. } Device;
  142. PDMA_TRANSFER_COMPLETION_CALLBACK CompletionCallback;
  143. PVOID UserContext;
  144. UINTN Size;
  145. ULONG Width;
  146. ULONG Flags;
  147. UINTN Completed;
  148. KSTATUS Status;
  149. };
  150. typedef
  151. KSTATUS
  152. (*PDMA_GET_INFORMATION) (
  153. PDMA_INTERFACE Interface,
  154. PDMA_INFORMATION Information
  155. );
  156. /*++
  157. Routine Description:
  158. This routine returns information about a given DMA controller.
  159. Arguments:
  160. Interface - Supplies a pointer to the interface instance, used to identify
  161. which specific controller is being queried.
  162. Information - Supplies a pointer where the DMA controller information is
  163. returned on success. The caller should initialize the version number of
  164. this structure.
  165. Return Value:
  166. Status code.
  167. --*/
  168. typedef
  169. KSTATUS
  170. (*PDMA_SUBMIT_TRANSFER) (
  171. PDMA_INTERFACE Interface,
  172. PDMA_TRANSFER Transfer
  173. );
  174. /*++
  175. Routine Description:
  176. This routine submits a transfer to the DMA controller for execution. This
  177. routine will ensure that other devices do not perform transfers on the
  178. given channel while this transfer is in progress. The submission is
  179. asynchronous, this routine will return immediately, and the callback
  180. function will be called when the transfer is complete.
  181. Arguments:
  182. Interface - Supplies a pointer to the DMA controller interface.
  183. Transfer - Supplies a pointer to the transfer to execute.
  184. Return Value:
  185. Status code. This routine will return immediately, the transfer will not
  186. have been complete. The caller should utilize the callback function to get
  187. notified when a transfer has completed.
  188. --*/
  189. typedef
  190. KSTATUS
  191. (*PDMA_CANCEL_TRANSFER) (
  192. PDMA_INTERFACE Interface,
  193. PDMA_TRANSFER Transfer
  194. );
  195. /*++
  196. Routine Description:
  197. This routine attempts to cancel a transfer that is currently in flight.
  198. Arguments:
  199. Interface - Supplies a pointer to the DMA controller interface.
  200. Transfer - Supplies a pointer to the transfer to cancel.
  201. Return Value:
  202. STATUS_SUCCESS if the transfer was successfully canceled.
  203. STATUS_TOO_LATE if the transfer is already complete.
  204. Other status codes on other failures.
  205. --*/
  206. typedef
  207. KSTATUS
  208. (*PDMA_CONTROL_REQUEST) (
  209. PDMA_INTERFACE Interface,
  210. PDMA_TRANSFER Transfer,
  211. PVOID Request,
  212. UINTN RequestSize
  213. );
  214. /*++
  215. Routine Description:
  216. This routine is called to perform a DMA controller-specific operation. It
  217. provides a direct link between DMA controllers and users, for controller-
  218. specific functionality.
  219. Arguments:
  220. Interface - Supplies a pointer to the DMA controller interface.
  221. Transfer - Supplies an optional pointer to the transfer involved.
  222. Request - Supplies a pointer to the request/response data.
  223. RequestSize - Supplies the size of the request in bytes.
  224. Return Value:
  225. Status code.
  226. --*/
  227. typedef
  228. KSTATUS
  229. (*PDMA_ALLOCATE_TRANSFER) (
  230. PDMA_INTERFACE Interface,
  231. PDMA_TRANSFER *Transfer
  232. );
  233. /*++
  234. Routine Description:
  235. This routine creates a new DMA transfer structure.
  236. Arguments:
  237. Interface - Supplies a pointer to the DMA controller interface.
  238. Transfer - Supplies a pointer where a pointer to the newly allocated
  239. transfer is returned on success.
  240. Return Value:
  241. Status code.
  242. --*/
  243. typedef
  244. VOID
  245. (*PDMA_FREE_TRANSFER) (
  246. PDMA_INTERFACE Interface,
  247. PDMA_TRANSFER Transfer
  248. );
  249. /*++
  250. Routine Description:
  251. This routine destroys a previously created DMA transfer. This transfer
  252. must not be actively submitted to any controller.
  253. Arguments:
  254. Interface - Supplies a pointer to the DMA controller interface.
  255. Transfer - Supplies a pointer to the transfer to destroy.
  256. Return Value:
  257. None.
  258. --*/
  259. /*++
  260. Structure Description:
  261. This structure defines the interface to a Simple Peripheral Bus device.
  262. Each handle given out by the open function of this interface is not thread
  263. safe.
  264. Members:
  265. Context - Stores an opaque pointer to additinal data that the interface
  266. producer uses to identify this interface instance.
  267. GetInformation - Stores a pointer to a function used to get information
  268. about the DMA controller.
  269. Submit - Stores a pointer to a function used to submit a new DMA transfer.
  270. Cancel - Stores a pointer to a function used to cancel a submitted but not
  271. yet complete DMA transfer.
  272. ControlRequest - Stores a pointer to a function used to implement
  273. controller-specific features.
  274. AllocateTransfer - Stores a pointer to a function used to allocate a DMA
  275. transfer.
  276. FreeTransfer - Stores a pointer to a function used to free a DMA transfer.
  277. --*/
  278. struct _DMA_INTERFACE {
  279. PVOID Context;
  280. PDMA_GET_INFORMATION GetInformation;
  281. PDMA_SUBMIT_TRANSFER Submit;
  282. PDMA_CANCEL_TRANSFER Cancel;
  283. PDMA_CONTROL_REQUEST ControlRequest;
  284. PDMA_ALLOCATE_TRANSFER AllocateTransfer;
  285. PDMA_FREE_TRANSFER FreeTransfer;
  286. };
  287. //
  288. // -------------------------------------------------------------------- Globals
  289. //
  290. //
  291. // -------------------------------------------------------- Function Prototypes
  292. //