Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

216 lines
8.5 KiB

  1. Video DMA Support Design Note
  2. The video port needs to expose the following apis:
  3. 1) PUBLIC
  4. BOOLEAN
  5. VideoPortDoDma(
  6. IN PVOID HwDeviceExtension,
  7. IN PVIDEO_REQUEST_PACKET pVrp
  8. );
  9. This function:
  10. a) allocates the MDL associated with the InputBuffer
  11. contained in the pVrp.
  12. b) maps the buffers if required by the hardware
  13. c) flushes the system buffers for cache coherency
  14. d)computes the number of map registers requested
  15. and checks that this number satisfies system requirements
  16. e) saves some parameters needed for subsequent
  17. Io calls such as the associated virtual MDL address, the
  18. number of map registers
  19. f) calls IoAllocateAdapterChannel, providiong a callback which
  20. builds the scatter gather list.
  21. Requirements: A mechanism to save the arguments to IoMapTransfer
  22. and a mechanism to indicate that a DPC is to be scheduled. The
  23. argments to IoMapTransfer are:
  24. PADAPTER_OBJECT pAO
  25. Returned from a call to HalGetAdapter and stored
  26. in the DEVICE_EXTENSION.
  27. If the actual transfer is desired, this is non NULL.
  28. If only the physical address is desired, this parameter
  29. can be NULL.
  30. PMDL pMdl
  31. Extracted from irp returned from
  32. IoBuildDeviceIoControlRequest. (also possible to get irp
  33. from IoBuildAsynchronousFsdRequest).
  34. PVOID pMapRegisterBase
  35. Allocated via ExAllocatePool from nonpaged pool of length
  36. dependent on bus type. Filled by Io subsystem via a call
  37. to HalGetBusData and held in the video ports
  38. DEVICE_EXTENSION.
  39. PVOID pCurrentVirtualAddress
  40. Constructed from LogicalAddress and
  41. MmGetMdlVirtualAddress(Irp->MdlAddress).
  42. PULONG pLength
  43. Pointer to amount to be transferred. Value saved in
  44. PUBLIC_VIDEO_REQUEST_BLOCK.
  45. BOOLEAN WriteToDevice
  46. Always set for video.
  47. 2) PVOID
  48. VideoPortGetCommonBuffer(
  49. IN PVOID HwDeviceExtension,
  50. IN PVIDEO_REQUEST_PACKET pVrp,
  51. IN ULONG Length,
  52. OUT PPHYSICAL_ADDRESS pLogicalAddress,
  53. IN BOOLEAN CacheEnabled
  54. );
  55. This routine allows the miniport to allocate a common buffer in
  56. which to store miniport specific data.
  57. 3) PVOID
  58. VideoPortGetCommonBuffer(
  59. IN PVOID HwDeviceExtension,
  60. IN PVIDEO_REQUEST_PACKET pVrp,
  61. IN ULONG Length,
  62. OUT PPHYSICAL_ADDRESS pLogicalAddress,
  63. IN BOOLEAN CacheEnabled
  64. );
  65. This routine allows the miniport to allocate a common buffer in
  66. which to store miniport specific data. This buffer is visible both to the
  67. system and the device and appears contiguous to the device.
  68. In support of each of these functions, the following can be added to the
  69. DEVICE_EXTENSION video port data structure:
  70. PVOID MapRegisterBase
  71. PADAPTER_OBJECT pDmaAdapterObject
  72. DMA_PARAMETERS FlushDmaParameters
  73. DMA_PARAMETERS MapTransferParameters
  74. PHW_DMA_STARTED HwDmaStarted
  75. BOOLEAN bMapBuffers
  76. where
  77. MapRegisterBase is as specified above.
  78. PADAPTER_OBJECT is defined by Io subsystem
  79. DMA_PARAMETERS, is of the form
  80. typedef struct __DMA_PARAMETERS {
  81. PPUBLIC_VIDEO_REQUEST_BLOCK pVideoRequestBlock;
  82. PIRP pIrp;
  83. ULONG DataOffset;
  84. ULONG VRBFlags;
  85. PVOID pMapRegisterBase;
  86. ULONG NumberOfMapRegisters;
  87. PVOID pLogicalAddress;
  88. ULONG Length;
  89. PVOID MdlAddress;
  90. PVRB_SG pScatterGather;
  91. VRB_SG SGList[17];
  92. } DMA_PARAMETERS, *PDMA_PARAMETERS;
  93. which needs to be a field of the Parameters field of the IrpStack as well
  94. as a field in the interrupt data owned by the miniport and where
  95. PPUBLIC_VIDEO_REQUEST_BLOCK may be defined by
  96. typedef struct __PUBLIC_VIDEO_REQUEST_BLOCK {
  97. // Private stuff.
  98. PIRP pIrp;
  99. ULONG VRBFlags;
  100. ULONG Qindex;
  101. // Public stuff.
  102. VIDEO_REQUEST_PACKET vrp;
  103. BOOLEAN bUnlock;
  104. } PUBLIC_VIDEO_REQUEST_BLOCK, *PPUBLIC_VIDEO_REQUEST_BLOCK;
  105. with VRB_SG defined by
  106. typedef struct __VRB_SG {
  107. int64 PhysicalAddress;
  108. ULONG Length;
  109. } VRB_SG, *PVRB_SG;
  110. Useful flags for VRBFlags in DMA_PARAMETERS:
  111. DMA_FLUSH_ADAPTER
  112. MAP_DMA_TRANSFER
  113. FREE_SG
  114. NOTIFY_REQUIRED.
  115. Also in PORT_CONFIG_INFO, the following are required:
  116. ULONG DmaChannel
  117. ULONG DmaPort
  118. DMA_WIDTH DmaWidth
  119. DMA_SPEED DmaSpeed
  120. BOOLEAN DMA32bitAddresses
  121. BOOLEAN DMADemandMode
  122. One of the dependencies that supporting DMA transfers has in NT is calling
  123. IoAllocateAdapterChannel.
  124. This routine is of the form:
  125. NTSTATUS
  126. IoAllocateAdapterChannel(
  127. PADAPTER_OBJECT pAO,
  128. PDEVICE_OBJECT pDO,
  129. ULONG NumberOfRegisters,
  130. PDRIVER_CONTROL pBuildScatterGather,
  131. PVOID pContext
  132. );
  133. where pAO is returned by HalGetAdapter,
  134. pDO is returned by IoCreateDevice
  135. NumberOfRegisters comes from a calculation involving the
  136. DataBuffer to be transferred and it's length.
  137. pBuildScatterGather builds the scatter/gather list and is a
  138. callback from the Io subsystem.
  139. pContext is the context pointer passed into pBuildScatterGather
  140. by Io subsystem (PDMA_PARAMETERS).
  141. If the miniport has indicated that DMA support is desired, then the
  142. following sequence of system calls are made:
  143. MmGetMdlVirtualAddress (to save IoMapTransfer params)
  144. MmGetSystemAddressForMdl (if MapBuffers set)
  145. KeFlushIoBuffers
  146. IoAllocateAdapterChannel (request a DPC if this fails)
  147. KeSynchronizeExecution
  148. IoMapTransfer (note PADAPTER_OBJECT)
  149. IoFlushAdapterBuffers
  150. IoFreeMapRegisters
  151. The Io subsystem calls back to a routine to build scatter gather lists
  152. of the form:
  153. IO_PRIVATE
  154. IO_ALLOCATION_ACTION
  155. pVideoPortBuildScatterGather(
  156. PDEVICE_OBJECT pDO,
  157. PIRP pIrp,
  158. PVOID pMapRegisterBase,
  159. PVOID pDmaParameters
  160. );
  161. As mentioned, it builds and saves the scatter gather lists, and calls
  162. KeSynchronizeExecution, passing in pVideoPortStartDmaSynchronized as
  163. the synchronizing function. pVideoPortStartDmaSynchronized in turn calls
  164. HwStartDma, which is not to return until the device has finished draining
  165. the current request data.
  166. IOCTL interface
  167. IOCTL_VIDEO_DMA_INIT - set by DispDrvr
  168. Causes VideoPortGetCommonBuffer() to be called by miniport.
  169. IOCTL_VIDEO_DMA_TRANSFER - set by DispDrvr
  170. Causes VideoPortDoDma() to be called by miniport.
  171. VideoPortGetScatterGatherList is called from miniport.
  172. IOCTL_VIDEO_DMA_UNLOCK_PAGES - set by DispDrvr
  173. Causes pVideoPortUnlock to be called from videoport. Note that
  174. this IOCTL is private to the videoport.