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.

386 lines
9.2 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 _COMMON_H_
  8. #define _COMMON_H_
  9. #include "shared.h"
  10. /*****************************************************************************
  11. * Structs
  12. *****************************************************************************
  13. */
  14. //
  15. // Contains pin and node configuration of the AC97 codec.
  16. //
  17. typedef struct
  18. {
  19. // For nodes.
  20. struct
  21. {
  22. BOOL bNodeConfig;
  23. } Nodes[NODEC_TOP_ELEMENT];
  24. // For pins.
  25. struct
  26. {
  27. BOOL bPinConfig;
  28. PWCHAR sRegistryName;
  29. } Pins[PINC_TOP_ELEMENT];
  30. } tHardwareConfig;
  31. //
  32. // We cache the AC97 registers. Additionally, we want some default values
  33. // when the driver comes up first that are different from the HW default
  34. // values. The string in the structure is the name of the registry entry
  35. // that can be used instead of the hard coded default value.
  36. //
  37. typedef struct
  38. {
  39. WORD wCache;
  40. WORD wFlags;
  41. PWCHAR sRegistryName;
  42. WORD wWantedDefault;
  43. } tAC97Registers;
  44. /*****************************************************************************
  45. * Constants
  46. *****************************************************************************
  47. */
  48. //
  49. // This means shadow register are to be read at least once to initialize.
  50. //
  51. const WORD SHREG_INVALID = 0x0001;
  52. //
  53. // This means shadow register should be overwritten with default value at
  54. // driver init.
  55. //
  56. const WORD SHREG_INIT = 0x0002;
  57. //
  58. // This constant is used to prevent register caching.
  59. //
  60. const WORD SHREG_NOCACHE = 0x0004;
  61. /*****************************************************************************
  62. * Classes
  63. *****************************************************************************
  64. */
  65. /*****************************************************************************
  66. * CAdapterCommon
  67. *****************************************************************************
  68. * This is the common adapter object shared by all miniports to access the
  69. * hardware.
  70. */
  71. class CAdapterCommon : public IAdapterCommon,
  72. public IAdapterPowerManagement,
  73. public CUnknown
  74. {
  75. private:
  76. static tAC97Registers m_stAC97Registers[64]; // The shadow registers.
  77. static tHardwareConfig m_stHardwareConfig; // The hardware configuration.
  78. PDEVICE_OBJECT m_pDeviceObject; // Device object used for registry access.
  79. PWORD m_pCodecBase; // The AC97 I/O port address.
  80. PUCHAR m_pBusMasterBase; // The Bus Master base address.
  81. BOOL m_bDirectRead; // Used during init time.
  82. DEVICE_POWER_STATE m_PowerState; // Current power state of the device.
  83. PMINIPORTTOPOLOGYICH m_Topology; // Miniport Topology pointer.
  84. /*************************************************************************
  85. * CAdapterCommon methods
  86. *************************************************************************
  87. */
  88. //
  89. // Resets AC97 audio registers.
  90. //
  91. NTSTATUS InitAC97 (void);
  92. //
  93. // Checks for existance of registers.
  94. //
  95. NTSTATUS ProbeHWConfig (void);
  96. //
  97. // Checks for 6th bit support in the volume control.
  98. //
  99. NTSTATUS Check6thBitSupport (IN AC97Register, IN TopoNodeConfig);
  100. //
  101. // Returns true if you should disable the input or output pin.
  102. //
  103. BOOL DisableAC97Pin (IN TopoPinConfig);
  104. #if (DBG)
  105. //
  106. // Dumps the probed configuration.
  107. //
  108. void DumpConfig (void);
  109. #endif
  110. //
  111. // Sets AC97 registers to default.
  112. //
  113. NTSTATUS SetAC97Default (void);
  114. //
  115. // Aquires the semaphore for AC97 register access.
  116. //
  117. NTSTATUS AcquireCodecSemiphore (void);
  118. //
  119. // Checks if there is a AC97 link between ICH and codec.
  120. //
  121. NTSTATUS PrimaryCodecReady (void);
  122. //
  123. // Powers up the Codec.
  124. //
  125. NTSTATUS PowerUpCodec (void);
  126. //
  127. // Saves native audio bus master control registers values to be used
  128. // upon suspend.
  129. //
  130. NTSTATUS ReadNABMCtrlRegs (void);
  131. //
  132. // Writes back native audio bus master control resgister to be used upon
  133. // resume.
  134. //
  135. NTSTATUS RestoreNABMCtrlRegs (void);
  136. public:
  137. DECLARE_STD_UNKNOWN();
  138. DEFINE_STD_CONSTRUCTOR(CAdapterCommon);
  139. ~CAdapterCommon();
  140. /*************************************************************************
  141. * IAdapterPowerManagement methods
  142. *************************************************************************
  143. */
  144. IMP_IAdapterPowerManagement;
  145. /*************************************************************************
  146. * IAdapterCommon methods
  147. *************************************************************************
  148. */
  149. //
  150. // Initialize the adapter common object -> initialize and probe HW.
  151. //
  152. STDMETHODIMP_(NTSTATUS) Init
  153. (
  154. IN PRESOURCELIST ResourceList,
  155. IN PDEVICE_OBJECT DeviceObject
  156. );
  157. //
  158. // Returns if pin exists.
  159. //
  160. STDMETHODIMP_(BOOL) GetPinConfig
  161. (
  162. IN TopoPinConfig pin
  163. )
  164. {
  165. return m_stHardwareConfig.Pins[pin].bPinConfig;
  166. };
  167. //
  168. // Sets the pin configuration (exist/not exist).
  169. //
  170. STDMETHODIMP_(void) SetPinConfig
  171. (
  172. IN TopoPinConfig pin,
  173. IN BOOL config
  174. )
  175. {
  176. m_stHardwareConfig.Pins[pin].bPinConfig = config;
  177. };
  178. //
  179. // Return if node exists.
  180. //
  181. STDMETHODIMP_(BOOL) GetNodeConfig
  182. (
  183. IN TopoNodeConfig node
  184. )
  185. {
  186. return m_stHardwareConfig.Nodes[node].bNodeConfig;
  187. };
  188. //
  189. // Sets the node configuration (exist/not exist).
  190. //
  191. STDMETHODIMP_(void) SetNodeConfig
  192. (
  193. IN TopoNodeConfig node,
  194. IN BOOL config
  195. )
  196. {
  197. m_stHardwareConfig.Nodes[node].bNodeConfig = config;
  198. };
  199. //
  200. // Returns the AC97 register that is assosiated with the node.
  201. //
  202. STDMETHODIMP_(AC97Register) GetNodeReg
  203. ( IN TopoNodes node
  204. )
  205. {
  206. return stMapNodeToReg[node].reg;
  207. };
  208. //
  209. // Returns the AC97 register mask that is assosiated with the node.
  210. //
  211. STDMETHODIMP_(WORD) GetNodeMask
  212. (
  213. IN TopoNodes node
  214. )
  215. {
  216. return stMapNodeToReg[node].mask;
  217. };
  218. //
  219. // Reads a AC97 register.
  220. //
  221. STDMETHODIMP_(NTSTATUS) ReadCodecRegister
  222. (
  223. IN AC97Register Register,
  224. OUT PWORD wData
  225. );
  226. //
  227. // Writes a AC97 register.
  228. //
  229. STDMETHODIMP_(NTSTATUS) WriteCodecRegister
  230. (
  231. IN AC97Register Register,
  232. IN WORD wData,
  233. IN WORD wMask
  234. );
  235. //
  236. // Reads a 8 bit ICH bus master register.
  237. //
  238. STDMETHODIMP_(UCHAR) ReadBMControlRegister8
  239. (
  240. IN ULONG ulOffset
  241. );
  242. //
  243. // Reads a 16 bit ICH bus master register.
  244. //
  245. STDMETHODIMP_(USHORT) ReadBMControlRegister16
  246. (
  247. IN ULONG ulOffset
  248. );
  249. //
  250. // Reads a 32 bit ICH bus master register.
  251. //
  252. STDMETHODIMP_(ULONG) ReadBMControlRegister32
  253. (
  254. IN ULONG ulOffset
  255. );
  256. //
  257. // Writes a 8 bit ICH bus master register.
  258. //
  259. STDMETHODIMP_(void) WriteBMControlRegister
  260. (
  261. IN ULONG ulOffset,
  262. IN UCHAR Value
  263. );
  264. //
  265. // writes a 16 bit ICH bus master register.
  266. //
  267. STDMETHODIMP_(void) WriteBMControlRegister
  268. (
  269. IN ULONG ulOffset,
  270. IN USHORT Value
  271. );
  272. // writes a 32 bit ICH bus master register.
  273. STDMETHODIMP_(void) WriteBMControlRegister
  274. (
  275. IN ULONG ulOffset,
  276. IN ULONG Value
  277. );
  278. //
  279. // Write back cached mixer values to codec registers.
  280. //
  281. STDMETHODIMP_(NTSTATUS) RestoreCodecRegisters();
  282. //
  283. // Programs a sample rate.
  284. //
  285. STDMETHODIMP_(NTSTATUS) ProgramSampleRate
  286. (
  287. IN AC97Register Register,
  288. IN DWORD dwSampleRate
  289. );
  290. //
  291. // Stores the topology pointer. Used for DRM only.
  292. //
  293. STDMETHODIMP_(void) SetMiniportTopology (PMINIPORTTOPOLOGYICH topo)
  294. {
  295. m_Topology = topo;
  296. };
  297. //
  298. // Returns the topology pointer. Used for DRM only.
  299. //
  300. STDMETHODIMP_(PMINIPORTTOPOLOGYICH) GetMiniportTopology (void)
  301. {
  302. return m_Topology;
  303. };
  304. //
  305. // This function reads the default channel config and is called only by the
  306. // wave miniport.
  307. //
  308. STDMETHODIMP_(void) ReadChannelConfigDefault
  309. (
  310. PDWORD pdwChannelConfig,
  311. PWORD pwChannels
  312. );
  313. //
  314. // This function writes the default channel config and is called only by the
  315. // wave miniport.
  316. //
  317. STDMETHODIMP_(void) WriteChannelConfigDefault
  318. (
  319. DWORD dwChannelConfig
  320. );
  321. /*************************************************************************
  322. * Friends
  323. *************************************************************************
  324. */
  325. friend NTSTATUS NewAdapterCommon
  326. (
  327. OUT PADAPTERCOMMON *OutAdapterCommon,
  328. IN PRESOURCELIST ResourceList
  329. );
  330. };
  331. #endif //_COMMON_H_