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.

279 lines
11 KiB

  1. /*****************************************************************************
  2. * private.h - MPU-401 miniport private definitions
  3. *****************************************************************************
  4. * Copyright (c) 1997-2000 Microsoft Corporation. All Rights Reserved.
  5. */
  6. #ifndef _DMUSUART_PRIVATE_H_
  7. #define _DMUSUART_PRIVATE_H_
  8. #include "portcls.h"
  9. #include "stdunk.h"
  10. #include "dmusicks.h"
  11. // + for absolute / - for relative
  12. #define kOneMillisec (10 * 1000)
  13. //
  14. // MPU401 ports
  15. //
  16. #define MPU401_REG_STATUS 0x01 // Status register
  17. #define MPU401_DRR 0x40 // Output ready (for command or data)
  18. // if this bit is set, the output FIFO is FULL
  19. #define MPU401_DSR 0x80 // Input ready (for data)
  20. // if this bit is set, the input FIFO is empty
  21. #define MPU401_REG_DATA 0x00 // Data in
  22. #define MPU401_REG_COMMAND 0x01 // Commands
  23. #define MPU401_CMD_RESET 0xFF // Reset command
  24. #define MPU401_CMD_UART 0x3F // Switch to UART mod
  25. /*****************************************************************************
  26. * References forward
  27. */
  28. /*****************************************************************************
  29. * Prototypes
  30. */
  31. NTSTATUS InitMPU(IN PINTERRUPTSYNC InterruptSync,IN PVOID DynamicContext);
  32. NTSTATUS ResetHardware(PUCHAR portBase);
  33. NTSTATUS ValidatePropertyRequest(IN PPCPROPERTY_REQUEST pRequest, IN ULONG ulValueSize, IN BOOLEAN fValueRequired);
  34. /*****************************************************************************
  35. * Constants
  36. */
  37. const BOOLEAN COMMAND = TRUE;
  38. const BOOLEAN DATA = FALSE;
  39. const LONG kMPUInputBufferSize = 128;
  40. /*****************************************************************************
  41. * Globals
  42. */
  43. /*****************************************************************************
  44. * Classes
  45. */
  46. /*****************************************************************************
  47. * CMiniportDMusUART
  48. *****************************************************************************
  49. * MPU-401 miniport. This object is associated with the device and is
  50. * created when the device is started. The class inherits IMiniportDMus
  51. * so it can expose this interface and CUnknown so it automatically gets
  52. * reference counting and aggregation support.
  53. */
  54. class CMiniportDMusUART
  55. : public IMiniportDMus,
  56. public IMusicTechnology,
  57. public IPowerNotify,
  58. public CUnknown
  59. {
  60. private:
  61. KSSTATE m_KSStateInput; // Miniport state (RUN/PAUSE/ACQUIRE/STOP)
  62. PPORTDMUS m_pPort; // Callback interface.
  63. PUCHAR m_pPortBase; // Base port address.
  64. PINTERRUPTSYNC m_pInterruptSync; // Interrupt synchronization object.
  65. PSERVICEGROUP m_pServiceGroup; // Service group for capture.
  66. PMASTERCLOCK m_MasterClock; // for input data
  67. REFERENCE_TIME m_InputTimeStamp; // capture data timestamp
  68. USHORT m_NumRenderStreams; // Num active render streams.
  69. USHORT m_NumCaptureStreams; // Num active capture streams.
  70. LONG m_MPUInputBufferHead; // Index of the newest byte in the FIFO.
  71. LONG m_MPUInputBufferTail; // Index of the oldest empty space in the FIFO.
  72. GUID m_MusicFormatTechnology;
  73. POWER_STATE m_PowerState; // Saved power state (D0 = full power, D3 = off)
  74. BOOLEAN m_fMPUInitialized; // Is the MPU HW initialized.
  75. BOOLEAN m_UseIRQ; // FALSE if no IRQ is used for MIDI.
  76. UCHAR m_MPUInputBuffer[kMPUInputBufferSize]; // Internal SW FIFO.
  77. /*************************************************************************
  78. * CMiniportDMusUART methods
  79. *
  80. * These are private member functions used internally by the object.
  81. * See MINIPORT.CPP for specific descriptions.
  82. */
  83. NTSTATUS ProcessResources
  84. (
  85. IN PRESOURCELIST ResourceList
  86. );
  87. NTSTATUS InitializeHardware(PINTERRUPTSYNC interruptSync,PUCHAR portBase);
  88. public:
  89. /*************************************************************************
  90. * The following two macros are from STDUNK.H. DECLARE_STD_UNKNOWN()
  91. * defines inline IUnknown implementations that use CUnknown's aggregation
  92. * support. NonDelegatingQueryInterface() is declared, but it cannot be
  93. * implemented generically. Its definition appears in MINIPORT.CPP.
  94. * DEFINE_STD_CONSTRUCTOR() defines inline a constructor which accepts
  95. * only the outer unknown, which is used for aggregation. The standard
  96. * create macro (in MINIPORT.CPP) uses this constructor.
  97. */
  98. DECLARE_STD_UNKNOWN();
  99. DEFINE_STD_CONSTRUCTOR(CMiniportDMusUART);
  100. ~CMiniportDMusUART();
  101. /*************************************************************************
  102. * IMiniport methods
  103. */
  104. STDMETHODIMP_(NTSTATUS)
  105. GetDescription
  106. ( OUT PPCFILTER_DESCRIPTOR * OutFilterDescriptor
  107. );
  108. STDMETHODIMP_(NTSTATUS)
  109. DataRangeIntersection
  110. ( IN ULONG PinId
  111. , IN PKSDATARANGE DataRange
  112. , IN PKSDATARANGE MatchingDataRange
  113. , IN ULONG OutputBufferLength
  114. , OUT PVOID ResultantFormat
  115. , OUT PULONG ResultantFormatLength
  116. )
  117. {
  118. return STATUS_NOT_IMPLEMENTED;
  119. }
  120. /*************************************************************************
  121. * IMiniportDMus methods
  122. */
  123. STDMETHODIMP_(NTSTATUS) Init
  124. (
  125. IN PUNKNOWN UnknownAdapter,
  126. IN PRESOURCELIST ResourceList,
  127. IN PPORTDMUS Port,
  128. OUT PSERVICEGROUP * ServiceGroup
  129. );
  130. STDMETHODIMP_(NTSTATUS) NewStream
  131. (
  132. OUT PMXF * Stream,
  133. IN PUNKNOWN OuterUnknown OPTIONAL,
  134. IN POOL_TYPE PoolType,
  135. IN ULONG PinID,
  136. IN DMUS_STREAM_TYPE StreamType,
  137. IN PKSDATAFORMAT DataFormat,
  138. OUT PSERVICEGROUP * ServiceGroup,
  139. IN PAllocatorMXF AllocatorMXF,
  140. IN PMASTERCLOCK MasterClock,
  141. OUT PULONGLONG SchedulePreFetch
  142. );
  143. STDMETHODIMP_(void) Service
  144. ( void
  145. );
  146. /*************************************************************************
  147. * IMusicTechnology methods
  148. */
  149. IMP_IMusicTechnology;
  150. /*************************************************************************
  151. * IPowerNotify methods
  152. */
  153. IMP_IPowerNotify;
  154. /*************************************************************************
  155. * Friends
  156. */
  157. friend class CMiniportDMusUARTStream;
  158. friend NTSTATUS
  159. DMusMPUInterruptServiceRoutine(PINTERRUPTSYNC InterruptSync,PVOID DynamicContext);
  160. friend NTSTATUS
  161. SynchronizedDMusMPUWrite(PINTERRUPTSYNC InterruptSync,PVOID syncWriteContext);
  162. friend VOID NTAPI
  163. DMusUARTTimerDPC(PKDPC Dpc,PVOID DeferredContext,PVOID SystemArgument1,PVOID SystemArgument2);
  164. friend NTSTATUS PropertyHandler_Synth(IN PPCPROPERTY_REQUEST);
  165. friend STDMETHODIMP_(NTSTATUS) SnapTimeStamp(PINTERRUPTSYNC InterruptSync,PVOID pStream);
  166. };
  167. /*****************************************************************************
  168. * CMiniportDMusUARTStream
  169. *****************************************************************************
  170. * MPU-401 miniport stream. This object is associated with the pin and is
  171. * created when the pin is instantiated. It inherits IMXF
  172. * so it can expose this interface and CUnknown so it automatically gets
  173. * reference counting and aggregation support.
  174. */
  175. class CMiniportDMusUARTStream
  176. : public IMXF,
  177. public CUnknown
  178. {
  179. private:
  180. CMiniportDMusUART * m_pMiniport; // Parent.
  181. REFERENCE_TIME m_SnapshotTimeStamp; // Current snapshot of miniport's input timestamp.
  182. PUCHAR m_pPortBase; // Base port address.
  183. BOOLEAN m_fCapture; // Whether this is capture.
  184. long m_NumFailedMPUTries; // Deadman timeout for MPU hardware.
  185. PAllocatorMXF m_AllocatorMXF; // source/sink for DMus structs
  186. PMXF m_sinkMXF; // sink for DMus capture
  187. PDMUS_KERNEL_EVENT m_DMKEvtQueue; // queue of waiting events
  188. ULONG m_NumberOfRetries; // Number of consecutive times the h/w was busy/full
  189. ULONG m_DMKEvtOffset; // offset into the event
  190. KDPC m_Dpc; // DPC for timer
  191. KTIMER m_TimerEvent; // timer
  192. BOOL m_TimerQueued; // whether a timer has been set
  193. KSPIN_LOCK m_DpcSpinLock; // protects the ConsumeEvents DPC
  194. STDMETHODIMP_(NTSTATUS) SourceEvtsToPort();
  195. STDMETHODIMP_(NTSTATUS) ConsumeEvents();
  196. STDMETHODIMP_(NTSTATUS) PutMessageLocked(PDMUS_KERNEL_EVENT pDMKEvt);
  197. public:
  198. /*************************************************************************
  199. * The following two macros are from STDUNK.H. DECLARE_STD_UNKNOWN()
  200. * defines inline IUnknown implementations that use CUnknown's aggregation
  201. * support. NonDelegatingQueryInterface() is declared, but it cannot be
  202. * implemented generically. Its definition appears in MINIPORT.CPP.
  203. * DEFINE_STD_CONSTRUCTOR() defines inline a constructor which accepts
  204. * only the outer unknown, which is used for aggregation. The standard
  205. * create macro (in MINIPORT.CPP) uses this constructor.
  206. */
  207. DECLARE_STD_UNKNOWN();
  208. DEFINE_STD_CONSTRUCTOR(CMiniportDMusUARTStream);
  209. ~CMiniportDMusUARTStream();
  210. STDMETHODIMP_(NTSTATUS) Init
  211. (
  212. IN CMiniportDMusUART * pMiniport,
  213. IN PUCHAR pPortBase,
  214. IN BOOLEAN fCapture,
  215. IN PAllocatorMXF allocatorMXF,
  216. IN PMASTERCLOCK masterClock
  217. );
  218. NTSTATUS HandlePortParams
  219. (
  220. IN PPCPROPERTY_REQUEST Request
  221. );
  222. /*************************************************************************
  223. * IMiniportStreamDMusUART methods
  224. */
  225. IMP_IMXF;
  226. STDMETHODIMP_(NTSTATUS) Write
  227. (
  228. IN PVOID BufferAddress,
  229. IN ULONG BytesToWrite,
  230. OUT PULONG BytesWritten
  231. );
  232. friend VOID NTAPI
  233. DMusUARTTimerDPC
  234. (
  235. IN PKDPC Dpc,
  236. IN PVOID DeferredContext,
  237. IN PVOID SystemArgument1,
  238. IN PVOID SystemArgument2
  239. );
  240. friend NTSTATUS PropertyHandler_Synth(IN PPCPROPERTY_REQUEST);
  241. friend STDMETHODIMP_(NTSTATUS) SnapTimeStamp(PINTERRUPTSYNC InterruptSync,PVOID pStream);
  242. };
  243. #endif // _DMusUART_PRIVATE_H_