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.

405 lines
8.8 KiB

  1. /*++
  2. Copyright (c) 1997-2000 Microsoft Corporation All Rights Reserved
  3. Module Name:
  4. basedma.cpp
  5. Abstract:
  6. IDmaChannel implementation. Does nothing HW related.
  7. --*/
  8. #include <msvad.h>
  9. #include "common.h"
  10. #include "basewave.h"
  11. #pragma code_seg("PAGE")
  12. //=============================================================================
  13. STDMETHODIMP_(NTSTATUS)
  14. CMiniportWaveCyclicStreamMSVAD::AllocateBuffer
  15. (
  16. IN ULONG BufferSize,
  17. IN PPHYSICAL_ADDRESS PhysicalAddressConstraint OPTIONAL
  18. )
  19. /*++
  20. Routine Description:
  21. The AllocateBuffer function allocates a buffer associated with the DMA object.
  22. The buffer is nonPaged.
  23. Callers of AllocateBuffer should run at a passive IRQL.
  24. Arguments:
  25. BufferSize - Size in bytes of the buffer to be allocated.
  26. PhysicalAddressConstraint - Optional constraint to place on the physical
  27. address of the buffer. If supplied, only the bits
  28. that are set in the constraint address may vary
  29. from the beginning to the end of the buffer.
  30. For example, if the desired buffer should not
  31. cross a 64k boundary, the physical address
  32. constraint 0x000000000000ffff should be specified
  33. Return Value:
  34. NT status code.
  35. --*/
  36. {
  37. DPF_ENTER(("[CMiniportWaveCyclicStreamMSVAD::AllocateBuffer]"));
  38. NTSTATUS ntStatus = STATUS_SUCCESS;
  39. //
  40. // Adjust this cap as needed...
  41. ASSERT (BufferSize <= DMA_BUFFER_SIZE);
  42. m_pvDmaBuffer = (PVOID)
  43. ExAllocatePoolWithTag
  44. (
  45. NonPagedPool,
  46. BufferSize,
  47. MSVAD_POOLTAG
  48. );
  49. if (!m_pvDmaBuffer)
  50. {
  51. ntStatus = STATUS_INSUFFICIENT_RESOURCES;
  52. }
  53. else
  54. {
  55. m_ulDmaBufferSize = BufferSize;
  56. }
  57. return ntStatus;
  58. } // AllocateBuffer
  59. #pragma code_seg()
  60. //=============================================================================
  61. STDMETHODIMP_(ULONG)
  62. CMiniportWaveCyclicStreamMSVAD::AllocatedBufferSize
  63. (
  64. void
  65. )
  66. /*++
  67. Routine Description:
  68. AllocatedBufferSize returns the size of the allocated buffer.
  69. Callers of AllocatedBufferSize can run at any IRQL.
  70. Arguments:
  71. Return Value:
  72. ULONG
  73. --*/
  74. {
  75. DPF_ENTER(("[CMiniportWaveCyclicStreamMSVAD::AllocatedBufferSize]"));
  76. return m_ulDmaBufferSize;
  77. } // AllocatedBufferSize
  78. //=============================================================================
  79. STDMETHODIMP_(ULONG)
  80. CMiniportWaveCyclicStreamMSVAD::BufferSize
  81. (
  82. void
  83. )
  84. /*++
  85. Routine Description:
  86. BufferSize returns the size set by SetBufferSize or the allocated buffer size
  87. if the buffer size has not been set. The DMA object does not actually use
  88. this value internally. This value is maintained by the object to allow its
  89. various clients to communicate the intended size of the buffer. This call
  90. is often used to obtain the map size parameter to the Start member
  91. function. Callers of BufferSize can run at any IRQL
  92. Arguments:
  93. Return Value:
  94. ULONG
  95. --*/
  96. {
  97. return m_ulDmaBufferSize;
  98. } // BufferSize
  99. //=============================================================================
  100. STDMETHODIMP_(void)
  101. CMiniportWaveCyclicStreamMSVAD::CopyFrom
  102. (
  103. IN PVOID Destination,
  104. IN PVOID Source,
  105. IN ULONG ByteCount
  106. )
  107. /*++
  108. Routine Description:
  109. The CopyFrom function copies sample data from the DMA buffer.
  110. Callers of CopyFrom can run at any IRQL
  111. Arguments:
  112. Destination - Points to the destination buffer.
  113. Source - Points to the source buffer.
  114. ByteCount - Points to the source buffer.
  115. Return Value:
  116. void
  117. --*/
  118. {
  119. } // CopyFrom
  120. //=============================================================================
  121. STDMETHODIMP_(void)
  122. CMiniportWaveCyclicStreamMSVAD::CopyTo
  123. (
  124. IN PVOID Destination,
  125. IN PVOID Source,
  126. IN ULONG ByteCount
  127. /*++
  128. Routine Description:
  129. The CopyTo function copies sample data to the DMA buffer.
  130. Callers of CopyTo can run at any IRQL.
  131. Arguments:
  132. Destination - Points to the destination buffer.
  133. Source - Points to the source buffer
  134. ByteCount - Number of bytes to be copied
  135. Return Value:
  136. void
  137. --*/
  138. )
  139. {
  140. m_SaveData.WriteData((PBYTE) Source, ByteCount);
  141. } // CopyTo
  142. //=============================================================================
  143. #pragma code_seg("PAGE")
  144. STDMETHODIMP_(void)
  145. CMiniportWaveCyclicStreamMSVAD::FreeBuffer
  146. (
  147. void
  148. )
  149. /*++
  150. Routine Description:
  151. The FreeBuffer function frees the buffer allocated by AllocateBuffer. Because
  152. the buffer is automatically freed when the DMA object is deleted, this
  153. function is not normally used. Callers of FreeBuffer should run at
  154. IRQL PASSIVE_LEVEL.
  155. Arguments:
  156. Return Value:
  157. void
  158. --*/
  159. {
  160. DPF_ENTER(("[CMiniportWaveCyclicStreamMSVAD::FreeBuffer]"));
  161. if ( m_pvDmaBuffer )
  162. {
  163. ExFreePool( m_pvDmaBuffer );
  164. m_ulDmaBufferSize = 0;
  165. }
  166. } // FreeBuffer
  167. #pragma code_seg()
  168. //=============================================================================
  169. STDMETHODIMP_(PADAPTER_OBJECT)
  170. CMiniportWaveCyclicStreamMSVAD::GetAdapterObject
  171. (
  172. void
  173. )
  174. /*++
  175. Routine Description:
  176. The GetAdapterObject function returns the DMA object's internal adapter
  177. object. Callers of GetAdapterObject can run at any IRQL.
  178. Arguments:
  179. Return Value:
  180. PADAPTER_OBJECT - The return value is the object's internal adapter object.
  181. --*/
  182. {
  183. DPF_ENTER(("[CMiniportWaveCyclicStreamMSVAD::GetAdapterObject]"));
  184. // MSVAD does not have need a physical DMA channel. Therefore it
  185. // does not have physical DMA structure.
  186. return NULL;
  187. } // GetAdapterObject
  188. //=============================================================================
  189. STDMETHODIMP_(ULONG)
  190. CMiniportWaveCyclicStreamMSVAD::MaximumBufferSize
  191. (
  192. void
  193. )
  194. /*++
  195. Routine Description:
  196. Arguments:
  197. Return Value:
  198. NT status code.
  199. --*/
  200. {
  201. DPF_ENTER(("[CMiniportWaveCyclicStreamMSVAD::MaximumBufferSize]"));
  202. return m_pMiniport->m_MaxDmaBufferSize;
  203. } // MaximumBufferSize
  204. //=============================================================================
  205. STDMETHODIMP_(PHYSICAL_ADDRESS)
  206. CMiniportWaveCyclicStreamMSVAD::PhysicalAddress
  207. (
  208. void
  209. )
  210. /*++
  211. Routine Description:
  212. MaximumBufferSize returns the size in bytes of the largest buffer this DMA
  213. object is configured to support. Callers of MaximumBufferSize can run
  214. at any IRQL
  215. Arguments:
  216. Return Value:
  217. PHYSICAL_ADDRESS - The return value is the size in bytes of the largest
  218. buffer this DMA object is configured to support.
  219. --*/
  220. {
  221. DPF_ENTER(("[CMiniportWaveCyclicStreamMSVAD::PhysicalAddress]"));
  222. PHYSICAL_ADDRESS pAddress;
  223. pAddress.QuadPart = (LONGLONG) m_pvDmaBuffer;
  224. return pAddress;
  225. } // PhysicalAddress
  226. //=============================================================================
  227. STDMETHODIMP_(void)
  228. CMiniportWaveCyclicStreamMSVAD::SetBufferSize
  229. (
  230. IN ULONG BufferSize
  231. )
  232. /*++
  233. Routine Description:
  234. The SetBufferSize function sets the current buffer size. This value is set to
  235. the allocated buffer size when AllocateBuffer is called. The DMA object does
  236. not actually use this value internally. This value is maintained by the object
  237. to allow its various clients to communicate the intended size of the buffer.
  238. Callers of SetBufferSize can run at any IRQL.
  239. Arguments:
  240. BufferSize - Current size in bytes.
  241. Return Value:
  242. void
  243. --*/
  244. {
  245. DPF_ENTER(("[CMiniportWaveCyclicStreamMSVAD::SetBufferSize]"));
  246. if ( BufferSize <= m_ulDmaBufferSize )
  247. {
  248. m_ulDmaBufferSize = BufferSize;
  249. }
  250. else
  251. {
  252. DPF(D_ERROR, ("Tried to enlarge dma buffer size"));
  253. }
  254. } // SetBufferSize
  255. //=============================================================================
  256. STDMETHODIMP_(PVOID)
  257. CMiniportWaveCyclicStreamMSVAD::SystemAddress
  258. (
  259. void
  260. )
  261. /*++
  262. Routine Description:
  263. The SystemAddress function returns the virtual system address of the
  264. allocated buffer. Callers of SystemAddress can run at any IRQL.
  265. Arguments:
  266. Return Value:
  267. PVOID - The return value is the virtual system address of the
  268. allocated buffer.
  269. --*/
  270. {
  271. return m_pvDmaBuffer;
  272. } // SystemAddress
  273. //=============================================================================
  274. STDMETHODIMP_(ULONG)
  275. CMiniportWaveCyclicStreamMSVAD::TransferCount
  276. (
  277. void
  278. )
  279. /*++
  280. Routine Description:
  281. The TransferCount function returns the size in bytes of the buffer currently
  282. being transferred by a slave DMA object. Callers of TransferCount can run
  283. at any IRQL.
  284. Arguments:
  285. Return Value:
  286. ULONG - The return value is the size in bytes of the buffer currently
  287. being transferred.
  288. --*/
  289. {
  290. DPF_ENTER(("[CMiniportWaveCyclicStreamMSVAD::TransferCount]"));
  291. return m_ulDmaBufferSize;
  292. }