ReactOS 0.4.16-dev-297-gc569aee
common.h
Go to the documentation of this file.
1/********************************************************************************
2** Copyright (c) 1998-2000 Microsoft Corporation. All Rights Reserved.
3**
4** Portions Copyright (c) 1998-1999 Intel Corporation
5**
6********************************************************************************/
7
8/* The file common.h was reviewed by LCA in June 2011 and is acceptable for use by Microsoft. */
9
10#ifndef _COMMON_H_
11#define _COMMON_H_
12
13#include "shared.h"
14
15/*****************************************************************************
16 * Structs
17 *****************************************************************************
18 */
19
20//
21// Contains pin and node configuration of the AC97 codec.
22//
23typedef struct
24{
25 // For nodes.
26 struct
27 {
30
31 // For pins.
32 struct
33 {
38
39//
40// We cache the AC97 registers. Additionally, we want some default values
41// when the driver comes up first that are different from the HW default
42// values. The string in the structure is the name of the registry entry
43// that can be used instead of the hard coded default value.
44//
45typedef struct
46{
52
53
54/*****************************************************************************
55 * Constants
56 *****************************************************************************
57 */
58
59//
60// This means shadow register are to be read at least once to initialize.
61//
62const WORD SHREG_INVALID = 0x0001;
63
64//
65// This means shadow register should be overwritten with default value at
66// driver init.
67//
68const WORD SHREG_INIT = 0x0002;
69
70//
71// This constant is used to prevent register caching.
72//
73const WORD SHREG_NOCACHE = 0x0004;
74
75
76/*****************************************************************************
77 * Classes
78 *****************************************************************************
79 */
80
81/*****************************************************************************
82 * CAC97AdapterCommon
83 *****************************************************************************
84 * This is the common adapter object shared by all miniports to access the
85 * hardware.
86 */
87class CAC97AdapterCommon : public IAC97AdapterCommon,
88 public IAdapterPowerManagement,
89 public CUnknown
90{
91private:
92 static tAC97Registers m_stAC97Registers[64]; // The shadow registers.
93 static tHardwareConfig m_stHardwareConfig; // The hardware configuration.
94 PDEVICE_OBJECT m_pDeviceObject; // Device object used for registry access.
95 PWORD m_pCodecBase; // The AC97 I/O port address.
96 PUCHAR m_pBusMasterBase; // The Bus Master base address.
97 BOOL m_bDirectRead; // Used during init time.
98 DEVICE_POWER_STATE m_PowerState; // Current power state of the device.
99 PAC97MINIPORTTOPOLOGY m_Topology; // Miniport Topology pointer.
100
101
102 /*************************************************************************
103 * CAC97AdapterCommon methods
104 *************************************************************************
105 */
106
107 //
108 // Resets AC97 audio registers.
109 //
110 NTSTATUS InitAC97 (void);
111
112 //
113 // Checks for existance of registers.
114 //
115 NTSTATUS ProbeHWConfig (void);
116
117 //
118 // Checks for 6th bit support in the volume control.
119 //
121
122 //
123 // Returns true if you should disable the input or output pin.
124 //
126
127#if (DBG)
128 //
129 // Dumps the probed configuration.
130 //
131 void DumpConfig (void);
132#endif
133
134 //
135 // Sets AC97 registers to default.
136 //
138
139 //
140 // Aquires the semaphore for AC97 register access.
141 //
143
144 //
145 // Checks if there is a AC97 link between AC97 and codec.
146 //
148
149 //
150 // Powers up the Codec.
151 //
152 NTSTATUS PowerUpCodec (void);
153
154 //
155 // Saves native audio bus master control registers values to be used
156 // upon suspend.
157 //
159
160 //
161 // Writes back native audio bus master control resgister to be used upon
162 // resume.
163 //
165
166public:
170
171 /*************************************************************************
172 * IAdapterPowerManagement methods
173 *************************************************************************
174 */
176
177 /*************************************************************************
178 * IAC97AdapterCommon methods
179 *************************************************************************
180 */
181
182 //
183 // Initialize the adapter common object -> initialize and probe HW.
184 //
186 (
189 );
190
191 //
192 // Returns if pin exists.
193 //
194 STDMETHODIMP_(BOOL) GetPinConfig
195 (
197 )
198 {
199 return m_stHardwareConfig.Pins[pin].bPinConfig;
200 };
201
202 //
203 // Sets the pin configuration (exist/not exist).
204 //
205 STDMETHODIMP_(void) SetPinConfig
206 (
209 )
210 {
211 m_stHardwareConfig.Pins[pin].bPinConfig = config;
212 };
213
214 //
215 // Return if node exists.
216 //
217 STDMETHODIMP_(BOOL) GetNodeConfig
218 (
220 )
221 {
222 return m_stHardwareConfig.Nodes[node].bNodeConfig;
223 };
224
225 //
226 // Sets the node configuration (exist/not exist).
227 //
228 STDMETHODIMP_(void) SetNodeConfig
229 (
232 )
233 {
234 m_stHardwareConfig.Nodes[node].bNodeConfig = config;
235 };
236
237 //
238 // Returns the AC97 register that is assosiated with the node.
239 //
242 )
243 {
244 return stMapNodeToReg[node].reg;
245 };
246
247 //
248 // Returns the AC97 register mask that is assosiated with the node.
249 //
250 STDMETHODIMP_(WORD) GetNodeMask
251 (
253 )
254 {
255 return stMapNodeToReg[node].mask;
256 };
257
258 //
259 // Reads a AC97 register.
260 //
261 STDMETHODIMP_(NTSTATUS) ReadCodecRegister
262 (
265 );
266
267 //
268 // Writes a AC97 register.
269 //
270 STDMETHODIMP_(NTSTATUS) WriteCodecRegister
271 (
275 );
276
277 //
278 // Reads a 8 bit AC97 bus master register.
279 //
280 STDMETHODIMP_(UCHAR) ReadBMControlRegister8
281 (
282 IN ULONG ulOffset
283 );
284
285 //
286 // Reads a 16 bit AC97 bus master register.
287 //
288 STDMETHODIMP_(USHORT) ReadBMControlRegister16
289 (
290 IN ULONG ulOffset
291 );
292
293 //
294 // Reads a 32 bit AC97 bus master register.
295 //
296 STDMETHODIMP_(ULONG) ReadBMControlRegister32
297 (
298 IN ULONG ulOffset
299 );
300
301 //
302 // Writes a 8 bit AC97 bus master register.
303 //
304 STDMETHODIMP_(void) WriteBMControlRegister
305 (
306 IN ULONG ulOffset,
308 );
309
310 //
311 // writes a 16 bit AC97 bus master register.
312 //
313 STDMETHODIMP_(void) WriteBMControlRegister
314 (
315 IN ULONG ulOffset,
317 );
318
319 // writes a 32 bit AC97 bus master register.
320 STDMETHODIMP_(void) WriteBMControlRegister
321 (
322 IN ULONG ulOffset,
324 );
325
326 //
327 // Write back cached mixer values to codec registers.
328 //
329 STDMETHODIMP_(NTSTATUS) RestoreCodecRegisters();
330
331 //
332 // Programs a sample rate.
333 //
334 STDMETHODIMP_(NTSTATUS) ProgramSampleRate
335 (
338 );
339
340 //
341 // Stores the topology pointer. Used for DRM only.
342 //
343 STDMETHODIMP_(void) SetMiniportTopology (PAC97MINIPORTTOPOLOGY topo)
344 {
345 m_Topology = topo;
346 };
347
348 //
349 // Returns the topology pointer. Used for DRM only.
350 //
351 STDMETHODIMP_(PAC97MINIPORTTOPOLOGY) GetMiniportTopology (void)
352 {
353 return m_Topology;
354 };
355
356 //
357 // This function reads the default channel config and is called only by the
358 // wave miniport.
359 //
360 STDMETHODIMP_(void) ReadChannelConfigDefault
361 (
362 PDWORD pdwChannelConfig,
364 );
365
366 //
367 // This function writes the default channel config and is called only by the
368 // wave miniport.
369 //
370 STDMETHODIMP_(void) WriteChannelConfigDefault
371 (
372 DWORD dwChannelConfig
373 );
374
375 /*************************************************************************
376 * Friends
377 *************************************************************************
378 */
379
381 (
382 OUT PADAPTERCOMMON *OutAdapterCommon,
384 );
385};
386
387#endif //_COMMON_H_
AC97Register
Definition: ac97reg.h:17
@ AC97REG_INVALID
Definition: ac97reg.h:60
const tMapNodeToReg stMapNodeToReg[]
Definition: ac97reg.h:109
LONG NTSTATUS
Definition: precomp.h:26
STDMETHODIMP_(BOOL) GetPinConfig(IN TopoPinConfig pin)
Definition: common.h:194
AC97REG_INVALID AC97Register _Out_ PWORD wData
Definition: common.h:265
NTSTATUS SetAC97Default(void)
Definition: common.cpp:1742
STDMETHODIMP_(AC97Register) GetNodeReg(IN TopoNodes node)
Definition: common.h:240
STDMETHODIMP_(NTSTATUS) RestoreCodecRegisters()
STDMETHODIMP_(void) SetPinConfig(IN TopoPinConfig pin
PWORD pwChannels
Definition: common.h:364
STDMETHODIMP_(BOOL) GetNodeConfig(IN TopoNodeConfig node)
Definition: common.h:217
NTSTATUS PrimaryCodecReady(void)
Definition: common.cpp:1284
NTSTATUS InitAC97(void)
Definition: common.cpp:540
DEVICE_POWER_STATE m_PowerState
Definition: common.h:98
STDMETHODIMP_(UCHAR) ReadBMControlRegister8(IN ULONG ulOffset)
STDMETHODIMP_(WORD) GetNodeMask(IN TopoNodes node)
Definition: common.h:250
IN BOOL config
Definition: common.h:210
BOOL m_bDirectRead
Definition: common.h:97
STDMETHODIMP_(void) WriteBMControlRegister(IN ULONG ulOffset
static tHardwareConfig m_stHardwareConfig
Definition: common.h:93
STDMETHODIMP_(NTSTATUS) Init(IN PRESOURCELIST ResourceList
STDMETHODIMP_(USHORT) ReadBMControlRegister16(IN ULONG ulOffset)
STDMETHODIMP_(NTSTATUS) ReadCodecRegister(_In_range_(0
STDMETHODIMP_(NTSTATUS) WriteCodecRegister(_In_range_(0
NTSTATUS PowerUpCodec(void)
Definition: common.cpp:1331
static tAC97Registers m_stAC97Registers[64]
Definition: common.h:92
STDMETHODIMP_(NTSTATUS) ProgramSampleRate(IN AC97Register Register
PUCHAR m_pBusMasterBase
Definition: common.h:96
STDMETHODIMP_(void) ReadChannelConfigDefault(PDWORD pdwChannelConfig
PAC97MINIPORTTOPOLOGY m_Topology
Definition: common.h:99
PDEVICE_OBJECT m_pDeviceObject
Definition: common.h:94
STDMETHODIMP_(void) SetNodeConfig(IN TopoNodeConfig node
friend NTSTATUS NewAdapterCommon(OUT PADAPTERCOMMON *OutAdapterCommon, IN PRESOURCELIST ResourceList)
DEFINE_STD_CONSTRUCTOR(CAC97AdapterCommon)
NTSTATUS AcquireCodecSemiphore(void)
Definition: common.cpp:1062
STDMETHODIMP_(PAC97MINIPORTTOPOLOGY) GetMiniportTopology(void)
Definition: common.h:351
STDMETHODIMP_(ULONG) ReadBMControlRegister32(IN ULONG ulOffset)
AC97REG_INVALID AC97Register Register
Definition: common.h:263
STDMETHODIMP_(void) WriteChannelConfigDefault(DWORD dwChannelConfig)
AC97REG_INVALID AC97Register _In_ WORD _In_ WORD wMask
Definition: common.h:275
PWORD m_pCodecBase
Definition: common.h:95
IN DWORD dwSampleRate
Definition: common.h:338
NTSTATUS Check6thBitSupport(IN AC97Register, IN TopoNodeConfig)
Definition: common.cpp:577
NTSTATUS RestoreNABMCtrlRegs(void)
STDMETHODIMP_(void) SetMiniportTopology(PAC97MINIPORTTOPOLOGY topo)
Definition: common.h:343
NTSTATUS ReadNABMCtrlRegs(void)
NTSTATUS ProbeHWConfig(void)
Definition: common.cpp:636
BOOL DisableAC97Pin(IN TopoPinConfig)
Definition: common.cpp:1880
const WORD SHREG_NOCACHE
Definition: common.h:73
const WORD SHREG_INIT
Definition: common.h:68
const WORD SHREG_INVALID
Definition: common.h:62
TopoPinConfig
Definition: shared.h:62
@ PINC_TOP_ELEMENT
Definition: shared.h:76
IAC97MiniportTopology * PAC97MINIPORTTOPOLOGY
Definition: shared.h:380
TopoNodes
Definition: shared.h:186
TopoNodeConfig
Definition: shared.h:84
@ NODEC_TOP_ELEMENT
Definition: shared.h:103
IAC97AdapterCommon * PADAPTERCOMMON
Definition: shared.h:488
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
#define _In_range_(l, h)
Definition: no_sal2.h:368
enum _DEVICE_POWER_STATE DEVICE_POWER_STATE
WORD * PWORD
Definition: pedump.c:67
DWORD * PDWORD
Definition: pedump.c:68
unsigned short USHORT
Definition: pedump.c:61
IResourceList * PRESOURCELIST
Definition: portcls.h:442
Definition: regsvr.c:104
WORD wFlags
Definition: common.h:48
WORD wWantedDefault
Definition: common.h:50
PWCHAR sRegistryName
Definition: common.h:49
WORD wCache
Definition: common.h:47
BOOL bPinConfig
Definition: common.h:34
PWCHAR sRegistryName
Definition: common.h:35
BOOL bNodeConfig
Definition: common.h:28
struct tHardwareConfig::@1460 Nodes[NODEC_TOP_ELEMENT]
struct tHardwareConfig::@1461 Pins[PINC_TOP_ELEMENT]
AC97Register reg
Definition: ac97reg.h:105
#define IN
Definition: typedefs.h:39
uint16_t * PWCHAR
Definition: typedefs.h:56
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
Definition: dlist.c:348
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
_Must_inspect_result_ _In_ WDFIORESREQLIST _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFIORESLIST * ResourceList
Definition: wdfresource.h:309
unsigned char UCHAR
Definition: xmlstorage.h:181