Leaked source code of windows server 2003
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.

357 lines
12 KiB

  1. //==========================================================================;
  2. //
  3. // WDMTVSnd.CPP
  4. // WDM TVAudio MiniDriver.
  5. // AllInWonder / AIWPro Hardware platform.
  6. // CWDMTVAudio class implementation.
  7. // Copyright (c) 1996 - 1997 ATI Technologies Inc. All Rights Reserved.
  8. //
  9. // $Date: 23 Nov 1998 13:22:00 $
  10. // $Revision: 1.4 $
  11. // $Author: minyailo $
  12. //
  13. //==========================================================================;
  14. extern "C"
  15. {
  16. #include "strmini.h"
  17. #include "ksmedia.h"
  18. #include "wdmdebug.h"
  19. }
  20. #include "atitvsnd.h"
  21. #include "wdmdrv.h"
  22. #include "aticonfg.h"
  23. /*^^*
  24. * AdapterCompleteInitialization()
  25. * Purpose : Called when SRB_COMPLETE_UNINITIALIZATION SRB is received.
  26. *
  27. * Inputs : PHW_STREAM_REQUEST_BLOCK pSrb : pointer to the current Srb
  28. *
  29. * Outputs : BOOL : returns TRUE
  30. * Author : IKLEBANOV
  31. *^^*/
  32. NTSTATUS CWDMTVAudio::AdapterCompleteInitialization( PHW_STREAM_REQUEST_BLOCK pSrb)
  33. {
  34. PADAPTER_DATA_EXTENSION pPrivateData = ( PADAPTER_DATA_EXTENSION)( pSrb->HwDeviceExtension);
  35. PDEVICE_OBJECT pDeviceObject = pPrivateData->PhysicalDeviceObject;
  36. KSPIN_MEDIUM mediumKSPin;
  37. NTSTATUS ntStatus;
  38. UINT nIndex;
  39. HANDLE hFolder;
  40. ULONG ulInstance;
  41. ENSURE
  42. {
  43. nIndex = 0;
  44. ulInstance = ::GetDriverInstanceNumber( pDeviceObject);
  45. hFolder = ::OpenRegistryFolder( pDeviceObject, UNICODE_WDM_REG_PIN_MEDIUMS);
  46. // put the hardcoded Medium values first
  47. ::RtlCopyMemory( &m_wdmTVAudioPinsMediumInfo[0], &ATITVAudioInMedium, sizeof( KSPIN_MEDIUM));
  48. ::RtlCopyMemory( &m_wdmTVAudioPinsMediumInfo[1], &ATITVAudioOutMedium, sizeof( KSPIN_MEDIUM));
  49. for( nIndex = 0; nIndex < WDMTVAUDIO_PINS_NUMBER; nIndex ++)
  50. {
  51. if( ::ReadPinMediumFromRegistryFolder( hFolder, nIndex, &mediumKSPin))
  52. ::RtlCopyMemory( &m_wdmTVAudioPinsMediumInfo[nIndex], &mediumKSPin, sizeof( KSPIN_MEDIUM));
  53. m_wdmTVAudioPinsMediumInfo[nIndex].Id = ulInstance;
  54. }
  55. m_wdmTVAudioPinsDirectionInfo[0] = FALSE;
  56. m_wdmTVAudioPinsDirectionInfo[1] = TRUE;
  57. if( hFolder != NULL)
  58. ::ZwClose( hFolder);
  59. ntStatus = StreamClassRegisterFilterWithNoKSPins( \
  60. pDeviceObject, // IN PDEVICE_OBJECT DeviceObject,
  61. &KSCATEGORY_TVAUDIO, // IN GUID * InterfaceClassGUID
  62. WDMTVAUDIO_PINS_NUMBER, // IN ULONG PinCount,
  63. m_wdmTVAudioPinsDirectionInfo, // IN ULONG * Flags,
  64. m_wdmTVAudioPinsMediumInfo, // IN KSPIN_MEDIUM * MediumList,
  65. NULL); // IN GUID * CategoryList
  66. if( !NT_SUCCESS( ntStatus))
  67. FAIL;
  68. OutputDebugTrace(( "CATIWDMTVAudio:AdapterCompleteInitialization() exit\n"));
  69. } END_ENSURE;
  70. if( !NT_SUCCESS( ntStatus))
  71. OutputDebugError(( "CATIWDMTVAudio:AdapterCompleteInitialization() ntStatus=%x\n",
  72. ntStatus));
  73. return( ntStatus);
  74. }
  75. /*^^*
  76. * AdapterUnInitialize()
  77. * Purpose : Called when SRB_UNINITIALIZE_DEVICE SRB is received.
  78. *
  79. * Inputs : PHW_STREAM_REQUEST_BLOCK pSrb : pointer to the current Srb
  80. *
  81. * Outputs : BOOL : returns TRUE
  82. * Author : IKLEBANOV
  83. *^^*/
  84. BOOL CWDMTVAudio::AdapterUnInitialize( PHW_STREAM_REQUEST_BLOCK pSrb)
  85. {
  86. OutputDebugTrace(( "CWDMTVAudio:AdapterUnInitialize()\n"));
  87. pSrb->Status = STATUS_SUCCESS;
  88. return( TRUE);
  89. }
  90. /*^^*
  91. * AdapterGetStreamInfo()
  92. * Purpose :
  93. *
  94. * Inputs : PHW_STREAM_REQUEST_BLOCK pSrb : pointer to the current Srb
  95. *
  96. * Outputs : BOOL : returns TRUE
  97. * Author : IKLEBANOV
  98. *^^*/
  99. BOOL CWDMTVAudio::AdapterGetStreamInfo( PHW_STREAM_REQUEST_BLOCK pSrb)
  100. {
  101. // pick up the pointer to the stream header data structure
  102. PHW_STREAM_HEADER pStreamHeader = ( PHW_STREAM_HEADER) \
  103. &( pSrb->CommandData.StreamBuffer->StreamHeader);
  104. // pick up the pointer to the stream information data structure
  105. PHW_STREAM_INFORMATION pStreamInfo = ( PHW_STREAM_INFORMATION) \
  106. &( pSrb->CommandData.StreamBuffer->StreamInfo);
  107. // no streams are supported
  108. DEBUG_ASSERT( pSrb->NumberOfBytesToTransfer >= sizeof( HW_STREAM_HEADER));
  109. OutputDebugTrace(( "CWDMTVAudio:AdapterGetStreamInfo()\n"));
  110. m_wdmTVAudioStreamHeader.NumberOfStreams = 0;
  111. m_wdmTVAudioStreamHeader.SizeOfHwStreamInformation = sizeof( HW_STREAM_INFORMATION);
  112. m_wdmTVAudioStreamHeader.NumDevPropArrayEntries = KSPROPERTIES_TVAUDIO_NUMBER_SET;
  113. m_wdmTVAudioStreamHeader.DevicePropertiesArray = m_wdmTVAudioPropertySet;
  114. m_wdmTVAudioStreamHeader.NumDevEventArrayEntries = KSEVENTS_TVAUDIO_NUMBER_SET;
  115. m_wdmTVAudioStreamHeader.DeviceEventsArray = m_wdmTVAudioEventsSet;
  116. m_wdmTVAudioStreamHeader.Topology = &m_wdmTVAudioTopology;
  117. * pStreamHeader = m_wdmTVAudioStreamHeader;
  118. pSrb->Status = STATUS_SUCCESS;
  119. return( TRUE);
  120. }
  121. /*^^*
  122. * AdapterQueryUnload()
  123. * Purpose : Called when the class driver is about to unload the MiniDriver
  124. * The MiniDriver checks if any open stream left.
  125. *
  126. * Inputs : PHW_STREAM_REQUEST_BLOCK pSrb : pointer to the current Srb
  127. *
  128. * Outputs : BOOL : returns TRUE
  129. * Author : IKLEBANOV
  130. *^^*/
  131. BOOL CWDMTVAudio::AdapterQueryUnload( PHW_STREAM_REQUEST_BLOCK pSrb)
  132. {
  133. OutputDebugTrace(( "CWDMTVAudio:AdapterQueryUnload()\n"));
  134. pSrb->Status = STATUS_SUCCESS;
  135. return( TRUE);
  136. }
  137. /*^^*
  138. * operator new
  139. * Purpose : CWDMTVAudio class overloaded operator new.
  140. * Provides placement for a CWDMTVAudio class object from the PADAPTER_DEVICE_EXTENSION
  141. * allocated by the StreamClassDriver for the MiniDriver.
  142. *
  143. * Inputs : UINT size_t : size of the object to be placed
  144. * PVOID pAllocation : casted pointer to the CWDMTVAudio allocated data
  145. *
  146. * Outputs : PVOID : pointer of the CWDMTVAudio class object
  147. * Author : IKLEBANOV
  148. *^^*/
  149. PVOID CWDMTVAudio::operator new( size_t stSize, PVOID pAllocation)
  150. {
  151. if( stSize != sizeof( CWDMTVAudio))
  152. {
  153. OutputDebugError(( "CWDMTVAudio: operator new() fails\n"));
  154. return( NULL);
  155. }
  156. else
  157. return( pAllocation);
  158. }
  159. /*^^*
  160. * CWDMTVAudio()
  161. * Purpose : CWDMTVAudio class constructor.
  162. * Performs checking of the hardware presence. Sets the hardware in an initial state.
  163. *
  164. * Inputs : CI2CScript * pCScript : pointer to the I2CScript class object
  165. * PUINT puiError : pointer to return a completion error code
  166. *
  167. * Outputs : none
  168. * Author : IKLEBANOV
  169. *^^*/
  170. CWDMTVAudio::CWDMTVAudio( PPORT_CONFIGURATION_INFORMATION pConfigInfo, CI2CScript * pCScript, PUINT puiErrorCode)
  171. :m_CATIConfiguration( pConfigInfo, pCScript, puiErrorCode)
  172. {
  173. UINT uiError;
  174. OutputDebugTrace(( "CWDMTVAudio:CWDMTVAudio() enter\n"));
  175. m_ulModesSupported = KS_TVAUDIO_MODE_MONO;
  176. // error code was carried over from ATIConfiguration class constructor
  177. uiError = * puiErrorCode;
  178. ENSURE
  179. {
  180. UINT uiAudioConfigurationId;
  181. UCHAR uchAudioChipAddress;
  182. if( uiError != WDMMINI_NOERROR)
  183. FAIL;
  184. if( pCScript == NULL)
  185. {
  186. uiError = WDMMINI_INVALIDPARAM;
  187. FAIL;
  188. }
  189. if( !m_CATIConfiguration.GetAudioConfiguration( &uiAudioConfigurationId, &uchAudioChipAddress))
  190. {
  191. uiError = WDMMINI_UNKNOWNHARDWARE;
  192. FAIL;
  193. }
  194. m_uiAudioConfiguration = uiAudioConfigurationId;
  195. m_uchAudioChipAddress = uchAudioChipAddress;
  196. if( !m_CATIConfiguration.InitializeAudioConfiguration( pCScript,
  197. uiAudioConfigurationId,
  198. uchAudioChipAddress))
  199. {
  200. uiError = WDMMINI_HARDWAREFAILURE;
  201. FAIL;
  202. }
  203. switch( uiAudioConfigurationId)
  204. {
  205. case ATI_AUDIO_CONFIG_1:
  206. m_ulModesSupported |= KS_TVAUDIO_MODE_STEREO;
  207. break;
  208. case ATI_AUDIO_CONFIG_2:
  209. case ATI_AUDIO_CONFIG_7:
  210. m_ulModesSupported |= KS_TVAUDIO_MODE_STEREO |
  211. KS_TVAUDIO_MODE_LANG_A | KS_TVAUDIO_MODE_LANG_B;
  212. break;
  213. case ATI_AUDIO_CONFIG_5:
  214. case ATI_AUDIO_CONFIG_6:
  215. m_ulModesSupported |= KS_TVAUDIO_MODE_STEREO;
  216. break;
  217. case ATI_AUDIO_CONFIG_8:
  218. m_ulModesSupported |= KS_TVAUDIO_MODE_STEREO |
  219. KS_TVAUDIO_MODE_LANG_A | KS_TVAUDIO_MODE_LANG_B;
  220. break;
  221. case ATI_AUDIO_CONFIG_3:
  222. case ATI_AUDIO_CONFIG_4:
  223. default:
  224. break;
  225. }
  226. // set stereo mode as the power up default, if supported
  227. m_ulTVAudioMode = ( m_ulModesSupported & KS_TVAUDIO_MODE_STEREO) ?
  228. KS_TVAUDIO_MODE_STEREO : KS_TVAUDIO_MODE_MONO;
  229. if( m_ulModesSupported & KS_TVAUDIO_MODE_LANG_A)
  230. m_ulTVAudioMode |= KS_TVAUDIO_MODE_LANG_A;
  231. // these two functions has to be called after the CWDMTVAudio class object was build on
  232. // on the stack and copied over into the DeviceExtension
  233. // This comment was true for the case, where the class object was build on the stack first.
  234. // There is an overloaded operator new provided for this class, and we can call it from here
  235. SetWDMTVAudioKSProperties();
  236. SetWDMTVAudioKSTopology();
  237. m_pI2CScript = pCScript;
  238. * puiErrorCode = WDMMINI_NOERROR;
  239. OutputDebugTrace(( "CWDMTVAudio:CWDMTVAudio() exit\n"));
  240. return;
  241. } END_ENSURE;
  242. * puiErrorCode = uiError;
  243. OutputDebugError(( "CWDMTVAudio:CWDMTVAudio() Error = %x\n", uiError));
  244. }
  245. /*^^*
  246. * AdapterSetPowerState()
  247. * Purpose : Sets Power Management state for deviec
  248. *
  249. * Inputs : PHW_STREAM_REQUEST_BLOCK pSrb : pointer to the current Srb
  250. * PBOOL pbSynchronous : pointer to return Synchronous/Asynchronous flag
  251. *
  252. * Outputs : NTSTATUS as the operation result
  253. * Author : IKLEBANOV
  254. *^^*/
  255. NTSTATUS CWDMTVAudio::AdapterSetPowerState( PHW_STREAM_REQUEST_BLOCK pSrb)
  256. {
  257. DEVICE_POWER_STATE nDeviceState = pSrb->CommandData.DeviceState;
  258. NTSTATUS ntStatus;
  259. switch( nDeviceState)
  260. {
  261. case PowerDeviceD0:
  262. case PowerDeviceD3:
  263. // if transition form D3 to D0 we have to restore audio connections
  264. if(( nDeviceState == PowerDeviceD0) && ( m_ulPowerState == PowerDeviceD3))
  265. {
  266. if( SetAudioOperationMode( m_ulTVAudioMode))
  267. ntStatus = STATUS_SUCCESS;
  268. else
  269. ntStatus = STATUS_ADAPTER_HARDWARE_ERROR;
  270. }
  271. else
  272. ntStatus = STATUS_SUCCESS;
  273. m_ulPowerState = nDeviceState;
  274. break;
  275. case PowerDeviceD1:
  276. case PowerDeviceD2:
  277. ntStatus = STATUS_SUCCESS;
  278. break;
  279. default:
  280. ntStatus = STATUS_INVALID_PARAMETER;
  281. break;
  282. }
  283. return( ntStatus);
  284. }