dma.h 12 KB

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