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.

729 lines
13 KiB

  1. /*++
  2. Copyright (c) 1997-2000 Microsoft Corporation All Rights Reserved
  3. Module Name:
  4. common.cpp
  5. Abstract:
  6. Implementation of the AdapterCommon class.
  7. --*/
  8. #include <msvad.h>
  9. #include "common.h"
  10. #include "hw.h"
  11. #include "savedata.h"
  12. //-----------------------------------------------------------------------------
  13. // Externals
  14. //-----------------------------------------------------------------------------
  15. PSAVEWORKER_PARAM CSaveData::m_pWorkItems = NULL;
  16. PDEVICE_OBJECT CSaveData::m_pDeviceObject = NULL;
  17. //=============================================================================
  18. // Classes
  19. //=============================================================================
  20. ///////////////////////////////////////////////////////////////////////////////
  21. // CAdapterCommon
  22. //
  23. class CAdapterCommon :
  24. public IAdapterCommon,
  25. public IAdapterPowerManagement,
  26. public CUnknown
  27. {
  28. private:
  29. PPORTWAVECYCLIC m_pPortWave; // Port interface
  30. PSERVICEGROUP m_pServiceGroupWave;
  31. PDEVICE_OBJECT m_pDeviceObject;
  32. DEVICE_POWER_STATE m_PowerState;
  33. PCMSVADHW m_pHW; // Virtual MSVAD HW object
  34. public:
  35. //=====================================================================
  36. // Default CUnknown
  37. DECLARE_STD_UNKNOWN();
  38. DEFINE_STD_CONSTRUCTOR(CAdapterCommon);
  39. ~CAdapterCommon();
  40. //=====================================================================
  41. // Default IAdapterPowerManagement
  42. IMP_IAdapterPowerManagement;
  43. //=====================================================================
  44. // IAdapterCommon methods
  45. STDMETHODIMP_(NTSTATUS) Init
  46. (
  47. IN PDEVICE_OBJECT DeviceObject
  48. );
  49. STDMETHODIMP_(PDEVICE_OBJECT) GetDeviceObject(void);
  50. STDMETHODIMP_(PUNKNOWN *) WavePortDriverDest(void);
  51. STDMETHODIMP_(void) SetWaveServiceGroup
  52. (
  53. IN PSERVICEGROUP ServiceGroup
  54. );
  55. STDMETHODIMP_(BOOL) MixerMuteRead
  56. (
  57. IN ULONG Index
  58. );
  59. STDMETHODIMP_(void) MixerMuteWrite
  60. (
  61. IN ULONG Index,
  62. IN BOOL Value
  63. );
  64. STDMETHODIMP_(ULONG) MixerMuxRead(void);
  65. STDMETHODIMP_(void) MixerMuxWrite
  66. (
  67. IN ULONG Index
  68. );
  69. STDMETHODIMP_(void) MixerReset(void);
  70. STDMETHODIMP_(LONG) MixerVolumeRead
  71. (
  72. IN ULONG Index,
  73. IN LONG Channel
  74. );
  75. STDMETHODIMP_(void) MixerVolumeWrite
  76. (
  77. IN ULONG Index,
  78. IN LONG Channel,
  79. IN LONG Value
  80. );
  81. //=====================================================================
  82. // friends
  83. friend NTSTATUS NewAdapterCommon
  84. (
  85. OUT PADAPTERCOMMON * OutAdapterCommon,
  86. IN PRESOURCELIST ResourceList
  87. );
  88. };
  89. //-----------------------------------------------------------------------------
  90. // Functions
  91. //-----------------------------------------------------------------------------
  92. //=============================================================================
  93. #pragma code_seg("PAGE")
  94. NTSTATUS
  95. NewAdapterCommon
  96. (
  97. OUT PUNKNOWN * Unknown,
  98. IN REFCLSID,
  99. IN PUNKNOWN UnknownOuter OPTIONAL,
  100. IN POOL_TYPE PoolType
  101. )
  102. /*++
  103. Routine Description:
  104. Creates a new CAdapterCommon
  105. Arguments:
  106. Unknown -
  107. UnknownOuter -
  108. PoolType
  109. Return Value:
  110. NT status code.
  111. --*/
  112. {
  113. PAGED_CODE();
  114. ASSERT(Unknown);
  115. STD_CREATE_BODY_
  116. (
  117. CAdapterCommon,
  118. Unknown,
  119. UnknownOuter,
  120. PoolType,
  121. PADAPTERCOMMON
  122. );
  123. } // NewAdapterCommon
  124. //=============================================================================
  125. CAdapterCommon::~CAdapterCommon
  126. (
  127. void
  128. )
  129. /*++
  130. Routine Description:
  131. Destructor for CAdapterCommon.
  132. Arguments:
  133. Return Value:
  134. void
  135. --*/
  136. {
  137. PAGED_CODE();
  138. DPF_ENTER(("[CAdapterCommon::~CAdapterCommon]"));
  139. if (m_pHW)
  140. {
  141. delete m_pHW;
  142. }
  143. CSaveData::DestroyWorkItems();
  144. if (m_pPortWave)
  145. {
  146. m_pPortWave->Release();
  147. }
  148. if (m_pServiceGroupWave)
  149. {
  150. m_pServiceGroupWave->Release();
  151. }
  152. } // ~CAdapterCommon
  153. //=============================================================================
  154. STDMETHODIMP_(PDEVICE_OBJECT)
  155. CAdapterCommon::GetDeviceObject
  156. (
  157. void
  158. )
  159. /*++
  160. Routine Description:
  161. Returns the deviceobject
  162. Arguments:
  163. Return Value:
  164. PDEVICE_OBJECT
  165. --*/
  166. {
  167. PAGED_CODE();
  168. return m_pDeviceObject;
  169. } // GetDeviceObject
  170. //=============================================================================
  171. NTSTATUS
  172. CAdapterCommon::Init
  173. (
  174. IN PDEVICE_OBJECT DeviceObject
  175. )
  176. /*++
  177. Routine Description:
  178. Initialize adapter common object.
  179. Arguments:
  180. DeviceObject - pointer to the device object
  181. Return Value:
  182. NT status code.
  183. --*/
  184. {
  185. PAGED_CODE();
  186. ASSERT(DeviceObject);
  187. NTSTATUS ntStatus = STATUS_SUCCESS;
  188. DPF_ENTER(("[CAdapterCommon::Init]"));
  189. m_pDeviceObject = DeviceObject;
  190. m_PowerState = PowerDeviceD0;
  191. // Initialize HW.
  192. //
  193. m_pHW = new (NonPagedPool, MSVAD_POOLTAG) CMSVADHW;
  194. if (!m_pHW)
  195. {
  196. DPF(D_TERSE, ("Insufficient memory for MSVAD HW"));
  197. ntStatus = STATUS_INSUFFICIENT_RESOURCES;
  198. }
  199. else
  200. {
  201. m_pHW->MixerReset();
  202. }
  203. // Initialize the work items for saving data to disk.
  204. //
  205. if (NT_SUCCESS(ntStatus))
  206. {
  207. ntStatus = CSaveData::InitializeWorkItems(DeviceObject);
  208. }
  209. return ntStatus;
  210. } // Init
  211. //=============================================================================
  212. STDMETHODIMP_(void)
  213. CAdapterCommon::MixerReset
  214. (
  215. void
  216. )
  217. /*++
  218. Routine Description:
  219. Reset mixer registers from registry.
  220. Arguments:
  221. Return Value:
  222. void
  223. --*/
  224. {
  225. PAGED_CODE();
  226. if (m_pHW)
  227. {
  228. m_pHW->MixerReset();
  229. }
  230. } // MixerReset
  231. //=============================================================================
  232. STDMETHODIMP
  233. CAdapterCommon::NonDelegatingQueryInterface
  234. (
  235. REFIID Interface,
  236. PVOID * Object
  237. )
  238. /*++
  239. Routine Description:
  240. QueryInterface routine for AdapterCommon
  241. Arguments:
  242. Interface -
  243. Object -
  244. Return Value:
  245. NT status code.
  246. --*/
  247. {
  248. PAGED_CODE();
  249. ASSERT(Object);
  250. if (IsEqualGUIDAligned(Interface, IID_IUnknown))
  251. {
  252. *Object = PVOID(PUNKNOWN(PADAPTERCOMMON(this)));
  253. }
  254. else if (IsEqualGUIDAligned(Interface, IID_IAdapterCommon))
  255. {
  256. *Object = PVOID(PADAPTERCOMMON(this));
  257. }
  258. else if (IsEqualGUIDAligned(Interface, IID_IAdapterPowerManagement))
  259. {
  260. *Object = PVOID(PADAPTERPOWERMANAGEMENT(this));
  261. }
  262. else
  263. {
  264. *Object = NULL;
  265. }
  266. if (*Object)
  267. {
  268. PUNKNOWN(*Object)->AddRef();
  269. return STATUS_SUCCESS;
  270. }
  271. return STATUS_INVALID_PARAMETER;
  272. } // NonDelegatingQueryInterface
  273. //=============================================================================
  274. STDMETHODIMP_(void)
  275. CAdapterCommon::SetWaveServiceGroup
  276. (
  277. IN PSERVICEGROUP ServiceGroup
  278. )
  279. /*++
  280. Routine Description:
  281. Arguments:
  282. Return Value:
  283. NT status code.
  284. --*/
  285. {
  286. PAGED_CODE();
  287. DPF_ENTER(("[CAdapterCommon::SetWaveServiceGroup]"));
  288. if (m_pServiceGroupWave)
  289. {
  290. m_pServiceGroupWave->Release();
  291. }
  292. m_pServiceGroupWave = ServiceGroup;
  293. if (m_pServiceGroupWave)
  294. {
  295. m_pServiceGroupWave->AddRef();
  296. }
  297. } // SetWaveServiceGroup
  298. //=============================================================================
  299. STDMETHODIMP_(PUNKNOWN *)
  300. CAdapterCommon::WavePortDriverDest
  301. (
  302. void
  303. )
  304. /*++
  305. Routine Description:
  306. Returns the wave port.
  307. Arguments:
  308. Return Value:
  309. PUNKNOWN : pointer to waveport
  310. --*/
  311. {
  312. PAGED_CODE();
  313. return (PUNKNOWN *)&m_pPortWave;
  314. } // WavePortDriverDest
  315. #pragma code_seg()
  316. //=============================================================================
  317. STDMETHODIMP_(BOOL)
  318. CAdapterCommon::MixerMuteRead
  319. (
  320. IN ULONG Index
  321. )
  322. /*++
  323. Routine Description:
  324. Store the new value in mixer register array.
  325. Arguments:
  326. Index - node id
  327. Return Value:
  328. BOOL - mixer mute setting for this node
  329. --*/
  330. {
  331. if (m_pHW)
  332. {
  333. return m_pHW->GetMixerMute(Index);
  334. }
  335. return 0;
  336. } // MixerMuteRead
  337. //=============================================================================
  338. STDMETHODIMP_(void)
  339. CAdapterCommon::MixerMuteWrite
  340. (
  341. IN ULONG Index,
  342. IN BOOL Value
  343. )
  344. /*++
  345. Routine Description:
  346. Store the new value in mixer register array.
  347. Arguments:
  348. Index - node id
  349. Value - new mute settings
  350. Return Value:
  351. NT status code.
  352. --*/
  353. {
  354. if (m_pHW)
  355. {
  356. m_pHW->SetMixerMute(Index, Value);
  357. }
  358. } // MixerMuteWrite
  359. //=============================================================================
  360. STDMETHODIMP_(ULONG)
  361. CAdapterCommon::MixerMuxRead()
  362. /*++
  363. Routine Description:
  364. Return the mux selection
  365. Arguments:
  366. Index - node id
  367. Value - new mute settings
  368. Return Value:
  369. NT status code.
  370. --*/
  371. {
  372. if (m_pHW)
  373. {
  374. return m_pHW->GetMixerMux();
  375. }
  376. return 0;
  377. } // MixerMuxRead
  378. //=============================================================================
  379. STDMETHODIMP_(void)
  380. CAdapterCommon::MixerMuxWrite
  381. (
  382. IN ULONG Index
  383. )
  384. /*++
  385. Routine Description:
  386. Store the new mux selection
  387. Arguments:
  388. Index - node id
  389. Value - new mute settings
  390. Return Value:
  391. NT status code.
  392. --*/
  393. {
  394. if (m_pHW)
  395. {
  396. m_pHW->SetMixerMux(Index);
  397. }
  398. } // MixerMuxWrite
  399. //=============================================================================
  400. STDMETHODIMP_(LONG)
  401. CAdapterCommon::MixerVolumeRead
  402. (
  403. IN ULONG Index,
  404. IN LONG Channel
  405. )
  406. /*++
  407. Routine Description:
  408. Return the value in mixer register array.
  409. Arguments:
  410. Index - node id
  411. Channel = which channel
  412. Return Value:
  413. Byte - mixer volume settings for this line
  414. --*/
  415. {
  416. if (m_pHW)
  417. {
  418. return m_pHW->GetMixerVolume(Index, Channel);
  419. }
  420. return 0;
  421. } // MixerVolumeRead
  422. //=============================================================================
  423. STDMETHODIMP_(void)
  424. CAdapterCommon::MixerVolumeWrite
  425. (
  426. IN ULONG Index,
  427. IN LONG Channel,
  428. IN LONG Value
  429. )
  430. /*++
  431. Routine Description:
  432. Store the new value in mixer register array.
  433. Arguments:
  434. Index - node id
  435. Channel - which channel
  436. Value - new volume level
  437. Return Value:
  438. void
  439. --*/
  440. {
  441. if (m_pHW)
  442. {
  443. m_pHW->SetMixerVolume(Index, Channel, Value);
  444. }
  445. } // MixerVolumeWrite
  446. //=============================================================================
  447. STDMETHODIMP_(void)
  448. CAdapterCommon::PowerChangeState
  449. (
  450. IN POWER_STATE NewState
  451. )
  452. /*++
  453. Routine Description:
  454. Arguments:
  455. NewState - The requested, new power state for the device.
  456. Return Value:
  457. void
  458. --*/
  459. {
  460. UINT i;
  461. DPF_ENTER(("[CAdapterCommon::PowerChangeState]"));
  462. // is this actually a state change??
  463. //
  464. if (NewState.DeviceState != m_PowerState)
  465. {
  466. // switch on new state
  467. //
  468. switch (NewState.DeviceState)
  469. {
  470. case PowerDeviceD0:
  471. case PowerDeviceD1:
  472. case PowerDeviceD2:
  473. case PowerDeviceD3:
  474. m_PowerState = NewState.DeviceState;
  475. DPF
  476. (
  477. D_VERBOSE,
  478. ("Entering D%d", ULONG(m_PowerState) - ULONG(PowerDeviceD0))
  479. );
  480. break;
  481. default:
  482. DPF(D_VERBOSE, ("Unknown Device Power State"));
  483. break;
  484. }
  485. }
  486. } // PowerStateChange
  487. //=============================================================================
  488. STDMETHODIMP_(NTSTATUS)
  489. CAdapterCommon::QueryDeviceCapabilities
  490. (
  491. IN PDEVICE_CAPABILITIES PowerDeviceCaps
  492. )
  493. /*++
  494. Routine Description:
  495. Called at startup to get the caps for the device. This structure provides
  496. the system with the mappings between system power state and device power
  497. state. This typically will not need modification by the driver.
  498. Arguments:
  499. PowerDeviceCaps - The device's capabilities.
  500. Return Value:
  501. NT status code.
  502. --*/
  503. {
  504. DPF_ENTER(("[CAdapterCommon::QueryDeviceCapabilities]"));
  505. return (STATUS_SUCCESS);
  506. } // QueryDeviceCapabilities
  507. //=============================================================================
  508. STDMETHODIMP_(NTSTATUS)
  509. CAdapterCommon::QueryPowerChangeState
  510. (
  511. IN POWER_STATE NewStateQuery
  512. )
  513. /*++
  514. Routine Description:
  515. Query to see if the device can change to this power state
  516. Arguments:
  517. NewStateQuery - The requested, new power state for the device
  518. Return Value:
  519. NT status code.
  520. --*/
  521. {
  522. DPF_ENTER(("[CAdapterCommon::QueryPowerChangeState]"));
  523. return STATUS_SUCCESS;
  524. } // QueryPowerChangeState