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.

239 lines
8.3 KiB

  1. /********************************************************************************
  2. ** Copyright (c) 1998-2000 Microsoft Corporation. All Rights Reserved.
  3. **
  4. ** Portions Copyright (c) 1998-1999 Intel Corporation
  5. **
  6. ********************************************************************************/
  7. #ifndef _ICHWAVE_H_
  8. #define _ICHWAVE_H_
  9. #include "shared.h"
  10. //*****************************************************************************
  11. // Defines
  12. //*****************************************************************************
  13. //
  14. // The scatter gather can (only) handle 32 entries
  15. //
  16. const int MAX_BDL_ENTRIES = 32;
  17. //
  18. // Mask for accessing the scatter gather entries with a counter.
  19. //
  20. const int BDL_MASK = 31;
  21. //
  22. // These are the differnet DMA engine states. The HW can only be in two states
  23. // (on or off) but there are also 2 transition states.
  24. // From DMA_ENGINE_RESET a failed start transitions to DMA_ENGINE_NEED_START, a
  25. // successful start transitions to DMA_ENGINE_ON. From DMA_ENGINE_NEED_START a
  26. // successful restart transitions to DMA_ENGINE_ON, a pause or stop transitions
  27. // to DMA_ENGINE_RESET. From DMA_ENGINE_ON a pause or stop transitions to
  28. // DMA_ENGINE_OFF. From DMA_ENGINE_OFF a start transitions to DMA_ENGINE_ON,
  29. // a reset would transitions to DMA_ENGINE_RESET.
  30. //
  31. const int DMA_ENGINE_OFF = 0;
  32. const int DMA_ENGINE_ON = 1;
  33. const int DMA_ENGINE_RESET = 2;
  34. const int DMA_ENGINE_NEED_START = 3; // DMA_ENGINE_RESET | DMA_ENGINE_ON
  35. //*****************************************************************************
  36. // Data Structures and Typedefs
  37. //*****************************************************************************
  38. //
  39. // This is a description of one mapping entry. It contains information
  40. // about the buffer and a tag which is used for "cancel mappings".
  41. // For one mapping that is described here, there is an entry in the
  42. // scatter gather engine.
  43. //
  44. typedef struct tagMapData
  45. {
  46. ULONG ulTag; //tag, a simple counter.
  47. PHYSICAL_ADDRESS PhysAddr; //phys. addr. of buffer
  48. PVOID pVirtAddr; //virt. addr. of buffer
  49. ULONG ulBufferLength; //buffer length
  50. } tMapData;
  51. //
  52. // Structure to describe the ICH Buffer Descriptor List (BDL).
  53. // The ICH can handle 32 entries, they are allocated at once in common
  54. // memory (non-cached memory). To avoid slow-down of CPU, the additional
  55. // information for handling this structure is stored in tBDList.
  56. //
  57. typedef struct tagBDEntry
  58. {
  59. DWORD dwPtrToPhyAddress;
  60. WORD wLength;
  61. WORD wPolicyBits;
  62. } tBDEntry;
  63. //
  64. // Structure needed to keep track of the BDL tables.
  65. // This structure is seperated from tBDEntry because we want to
  66. // have it in cached memory (and not along with tBDEntry in non-
  67. // cached memory).
  68. //
  69. typedef struct tagBDList
  70. {
  71. PHYSICAL_ADDRESS PhysAddr; // Physical address of BDList
  72. volatile tBDEntry *pBDEntry; // Virtual Address of BDList
  73. tBDEntry *pBDEntryBackup;// needed for rearranging the BDList
  74. tMapData *pMapData; // mapping list
  75. tMapData *pMapDataBackup;// needed for rearranging the BDList
  76. int nHead; // index for the BDL Head
  77. int nTail; // index for the BDL Tail
  78. ULONG ulTagCounter; // the tag is a simple counter.
  79. int nBDEntries; // number of entries.
  80. } tBDList;
  81. //*****************************************************************************
  82. // Classes
  83. //*****************************************************************************
  84. /*****************************************************************************
  85. * CMiniportWaveICHStream
  86. *****************************************************************************
  87. * ICH wave miniport stream.
  88. */
  89. class CMiniportWaveICHStream : public IMiniportWavePciStream,
  90. public IDrmAudioStream,
  91. public CUnknown
  92. {
  93. private:
  94. //
  95. // CMiniportWaveICHStream private variables
  96. //
  97. CMiniportWaveICH * Wave; // Miniport Object
  98. ULONG Channel; // channel this stream handles.
  99. BOOL Capture; // TRUE=Capture,FALSE=Render
  100. ULONG CurrentRate; // Current Sample Rate
  101. WORD NumberOfChannels; // Number of channels
  102. PSERVICEGROUP ServiceGroup; // service group helps with DPCs
  103. tBDList stBDList; // needed for scatter gather org.
  104. PPORTWAVEPCISTREAM PortStream; // Port Stream Interface
  105. PKSDATAFORMAT_WAVEFORMATEX DataFormat; // Data Format
  106. KSPIN_LOCK MapLock; // for processing mappings.
  107. ULONG m_ulBDAddr; // Offset of the stream's DMA registers.
  108. ULONG DMAEngineState; // DMA engine state (STOP, PAUSE, RUN)
  109. ULONGLONG TotalBytesMapped; // factor in position calculation
  110. ULONGLONG TotalBytesReleased; // factor in position calculation
  111. DEVICE_POWER_STATE m_PowerState; // Current power state of the device.
  112. /*************************************************************************
  113. * CMiniportWaveICHStream methods
  114. *************************************************************************
  115. *
  116. * These are private member functions used internally by the object. See
  117. * ICHWAVE.CPP for specific descriptions.
  118. */
  119. //
  120. // Moves the BDL and associated mappings list around.
  121. //
  122. void MoveBDList
  123. (
  124. IN int nFirst,
  125. IN int nLast,
  126. IN int nNewPos
  127. );
  128. //
  129. // Called when new mappings have to be processed.
  130. //
  131. NTSTATUS GetNewMappings (void);
  132. //
  133. // Called when we want to release some mappings.
  134. //
  135. NTSTATUS ReleaseUsedMappings (void);
  136. //
  137. // DMA start/stop/pause/reset routines.
  138. //
  139. NTSTATUS ResetDMA (void);
  140. NTSTATUS PauseDMA (void);
  141. NTSTATUS ResumeDMA (void);
  142. public:
  143. /*************************************************************************
  144. * The following two macros are from STDUNK.H. DECLARE_STD_UNKNOWN()
  145. * defines inline IUnknown implementations that use CUnknown's aggregation
  146. * support. NonDelegatingQueryInterface() is declared, but it cannot be
  147. * implemented generically. Its definition appears in ICHWAVE.CPP.
  148. * DEFINE_STD_CONSTRUCTOR() defines inline a constructor which accepts
  149. * only the outer unknown, which is used for aggregation. The standard
  150. * create macro (in ICHWAVE.CPP) uses this constructor.
  151. */
  152. DECLARE_STD_UNKNOWN ();
  153. DEFINE_STD_CONSTRUCTOR (CMiniportWaveICHStream);
  154. ~CMiniportWaveICHStream ();
  155. /*************************************************************************
  156. * Include IMiniportWavePciStream (public/exported) methods.
  157. *************************************************************************
  158. */
  159. IMP_IMiniportWavePciStream;
  160. /*************************************************************************
  161. * Include IDrmAudioStream (public/exported) methods.
  162. *************************************************************************
  163. */
  164. IMP_IDrmAudioStream;
  165. /*************************************************************************
  166. * CMiniportWaveICHStream methods
  167. *************************************************************************
  168. */
  169. //
  170. // Initializes the Stream object.
  171. //
  172. NTSTATUS Init
  173. (
  174. IN CMiniportWaveICH *Miniport_,
  175. IN PPORTWAVEPCISTREAM PortStream,
  176. IN ULONG Channel,
  177. IN BOOLEAN Capture,
  178. IN PKSDATAFORMAT DataFormat,
  179. OUT PSERVICEGROUP * ServiceGroup
  180. );
  181. //
  182. // This method is called when the device changes power states.
  183. //
  184. NTSTATUS PowerChangeNotify
  185. (
  186. IN POWER_STATE NewState
  187. );
  188. //
  189. // Return the current sample rate.
  190. //
  191. ULONG GetCurrentSampleRate (void)
  192. {
  193. return CurrentRate;
  194. }
  195. //
  196. // Friends
  197. //
  198. friend
  199. NTSTATUS CMiniportWaveICH::InterruptServiceRoutine
  200. (
  201. IN PINTERRUPTSYNC InterruptSync,
  202. IN PVOID StaticContext
  203. );
  204. };
  205. #endif