ReactOS 0.4.15-dev-7953-g1f49173
common.cpp File Reference
#include "common.h"
Include dependency graph for common.cpp:

Go to the source code of this file.

Macros

#define STR_MODULENAME   "AC97 Common: "
 

Functions

NTSTATUS NewAdapterCommon (OUT PUNKNOWN *Unknown, IN REFCLSID, IN PUNKNOWN UnknownOuter OPTIONAL, _When_((PoolType &NonPagedPoolMustSucceed) !=0, __drv_reportError("Must succeed pool allocations are forbidden. " "Allocation failures cause a system crash")) IN POOL_TYPE PoolType)
 
 STDMETHODIMP_ (NTSTATUS) CAC97AdapterCommon
 
 STDMETHODIMP_ (void) CAC97AdapterCommon
 
 STDMETHODIMP_ (UCHAR) CAC97AdapterCommon
 
 STDMETHODIMP_ (USHORT) CAC97AdapterCommon
 
 STDMETHODIMP_ (ULONG) CAC97AdapterCommon
 

Macro Definition Documentation

◆ STR_MODULENAME

#define STR_MODULENAME   "AC97 Common: "

Definition at line 11 of file common.cpp.

Function Documentation

◆ NewAdapterCommon()

NTSTATUS NewAdapterCommon ( OUT PUNKNOWN Unknown,
IN  REFCLSID,
IN PUNKNOWN UnknownOuter  OPTIONAL,
_When_((PoolType &NonPagedPoolMustSucceed) !=0, __drv_reportError("Must succeed pool allocations are forbidden. " "Allocation failures cause a system crash")) IN POOL_TYPE  PoolType 
)

Definition at line 116 of file common.cpp.

126{
127 PAGED_CODE ();
128
129 ASSERT (Unknown);
130
131 DOUT (DBG_PRINT, ("[NewAdapterCommon]"));
132
133 STD_CREATE_BODY_WITH_TAG_(CAC97AdapterCommon,Unknown,UnknownOuter,PoolType,
135}
#define PAGED_CODE()
#define DOUT(lvl, strings)
Definition: debug.h:82
IAC97AdapterCommon * PADAPTERCOMMON
Definition: shared.h:488
@ Unknown
Definition: i8042prt.h:114
#define ASSERT(a)
Definition: mode.c:44
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ _Strict_type_match_ POOL_TYPE PoolType
Definition: wdfdevice.h:3815
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ _Strict_type_match_ POOL_TYPE _In_opt_ ULONG PoolTag
Definition: wdfmemory.h:164
#define DBG_PRINT(ppi, ch, level)
Definition: win32kdebug.h:168

Referenced by StartDevice().

◆ STDMETHODIMP_() [1/5]

STDMETHODIMP_ ( NTSTATUS  )

Definition at line 144 of file common.cpp.

149{
150 PAGED_CODE ();
151
154
155 NTSTATUS ntStatus = STATUS_SUCCESS;
156
157 DOUT (DBG_PRINT, ("[CAC97AdapterCommon::Init]"));
158
159 //
160 // Set the topology pointer to NULL.
161 //
162 m_Topology = NULL;
163
164 //
165 // Save the device object
166 //
167 m_pDeviceObject = DeviceObject;
168
169 //
170 // Get the base address for the AC97 codec and bus master.
171 //
172 ASSERT (ResourceList->FindTranslatedPort (0));
173 m_pCodecBase = (PUSHORT)ResourceList->FindTranslatedPort (0)->
174 u.Port.Start.QuadPart;
175
176 ASSERT (ResourceList->FindTranslatedPort (1));
177 m_pBusMasterBase = (PUCHAR)ResourceList->FindTranslatedPort (1)->
178 u.Port.Start.QuadPart;
179
180 DOUT (DBG_SYSINFO, ("Configuration:\n"
181 " Bus Master = 0x%p\n"
182 " Codec = 0x%p",
183 m_pBusMasterBase, m_pCodecBase));
184
185 //
186 // Set m_bDirectRead to TRUE so that all AC97 register read and
187 // writes are going directly to the HW
188 //
189 m_bDirectRead = TRUE;
190
191 //
192 // Initialize the hardware.
193 //
194 ntStatus = InitAC97 ();
195 if (!NT_SUCCESS (ntStatus))
196 return ntStatus;
197
198 //
199 // Probe hardware configuration
200 //
201 ntStatus = ProbeHWConfig ();
202 if (!NT_SUCCESS (ntStatus))
203 {
204 DOUT (DBG_ERROR, ("Probing of hardware configuration failed!"));
205 return ntStatus;
206 }
207
208 //
209 // Now, every AC97 read access goes to the cache.
210 //
211 m_bDirectRead = FALSE;
212
213 //
214 // Restore the AC97 registers now.
215 //
216#if (DBG)
217 DumpConfig ();
218#endif
219 ntStatus = SetAC97Default ();
220
221 //
222 // Initialize the device state.
223 //
224 m_PowerState = PowerDeviceD0;
225
226 return ntStatus;
227}
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
const int DBG_SYSINFO
Definition: debug.h:27
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
#define DBG_ERROR
Definition: nfs41_debug.h:78
@ PowerDeviceD0
Definition: ntpoapi.h:49
#define STATUS_SUCCESS
Definition: shellext.h:65
uint16_t * PUSHORT
Definition: typedefs.h:56
unsigned char * PUCHAR
Definition: typedefs.h:53
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ WDFIORESREQLIST _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFIORESLIST * ResourceList
Definition: wdfresource.h:309

◆ STDMETHODIMP_() [2/5]

STDMETHODIMP_ ( UCHAR  )

Definition at line 2249 of file common.cpp.

2253{
2254 UCHAR ucValue = UCHAR(-1);
2255
2256 DOUT (DBG_PRINT, ("[CAC97AdapterCommon::ReadBMControlRegister8]"));
2257
2258 ucValue = READ_PORT_UCHAR ((PUCHAR)(m_pBusMasterBase + ulOffset));
2259
2260 DOUT (DBG_REGS, ("ReadBMControlRegister read 0x%2x from 0x%4p.", ucValue,
2261 m_pBusMasterBase + ulOffset));
2262
2263 return ucValue;
2264}
const int DBG_REGS
Definition: debug.h:25
#define READ_PORT_UCHAR(p)
Definition: pc98vid.h:22
unsigned char UCHAR
Definition: xmlstorage.h:181

◆ STDMETHODIMP_() [3/5]

STDMETHODIMP_ ( ULONG  )

Definition at line 2293 of file common.cpp.

2297{
2298 ULONG ulValue = ULONG(-1);
2299
2300 DOUT (DBG_PRINT, ("[CAC97AdapterCommon::ReadBMControlRegister32]"));
2301
2302 ulValue = READ_PORT_ULONG ((PULONG)(m_pBusMasterBase + ulOffset));
2303
2304 DOUT (DBG_REGS, ("ReadBMControlRegister read 0x%8x = 0x%4p", ulValue,
2305 m_pBusMasterBase + ulOffset));
2306
2307 return ulValue;
2308}
ULONG NTAPI READ_PORT_ULONG(IN PULONG Port)
Definition: portio.c:70
uint32_t * PULONG
Definition: typedefs.h:59
uint32_t ULONG
Definition: typedefs.h:59

◆ STDMETHODIMP_() [4/5]

STDMETHODIMP_ ( USHORT  )

Definition at line 2271 of file common.cpp.

2275{
2276 USHORT usValue = USHORT(-1);
2277
2278 DOUT (DBG_PRINT, ("[CAC97AdapterCommon::ReadBMControlRegister16]"));
2279
2280 usValue = READ_PORT_USHORT ((PUSHORT)(m_pBusMasterBase + ulOffset));
2281
2282 DOUT (DBG_REGS, ("ReadBMControlRegister read 0x%4x = 0x%4p", usValue,
2283 m_pBusMasterBase + ulOffset));
2284
2285 return usValue;
2286}
USHORT NTAPI READ_PORT_USHORT(IN PUSHORT Port)
Definition: portio.c:63
unsigned short USHORT
Definition: pedump.c:61

◆ STDMETHODIMP_() [5/5]

STDMETHODIMP_ ( void  )

Definition at line 1532 of file common.cpp.

1536{
1537 PAGED_CODE ();
1538
1539 NTSTATUS ntStatus = STATUS_SUCCESS;
1540
1541 DOUT (DBG_PRINT, ("[CAC97AdapterCommon::PowerChangeNotify]"));
1542
1543 //
1544 // Check to see if this is the current power state.
1545 //
1546 if (NewState.DeviceState == m_PowerState)
1547 {
1548 DOUT (DBG_POWER, ("New device state equals old state."));
1549 return;
1550 }
1551
1552 //
1553 // Check the new device state.
1554 //
1555 if ((NewState.DeviceState < PowerDeviceD0) ||
1556 (NewState.DeviceState > PowerDeviceD3))
1557 {
1558 DOUT (DBG_ERROR, ("Unknown device state: D%d.",
1559 (ULONG)NewState.DeviceState - (ULONG)PowerDeviceD0));
1560 return;
1561 }
1562
1563 DOUT (DBG_POWER, ("Changing state to D%d.", (ULONG)NewState.DeviceState -
1565
1566 //
1567 // Switch on new state.
1568 //
1569 switch (NewState.DeviceState)
1570 {
1571 case PowerDeviceD0:
1572 //
1573 // If we are coming from D2 or D3 we have to restore the registers cause
1574 // there might have been a power loss.
1575 //
1576 if ((m_PowerState == PowerDeviceD3) || (m_PowerState == PowerDeviceD2))
1577 {
1578 //
1579 // Reset AD3 to indicate that we are now awake.
1580 // Because the system has only one power irp at a time, we are sure
1581 // that the modem driver doesn't get called while we are restoring
1582 // power.
1583 //
1584 WriteBMControlRegister (GLOB_STA,
1585 ReadBMControlRegister32 (GLOB_STA) & ~GLOB_STA_AD3);
1586
1587 //
1588 // Restore codec registers.
1589 //
1590 ntStatus = RestoreCodecRegisters ();
1591 }
1592 else // We are coming from power state D1
1593 {
1594 ntStatus = PowerUpCodec ();
1595 }
1596
1597 // Print error code.
1598 if (!NT_SUCCESS (ntStatus))
1599 {
1600 DOUT (DBG_ERROR, ("PowerChangeState failed to restore the codec."));
1601 }
1602 break;
1603
1604 case PowerDeviceD1:
1605 //
1606 // This sleep state is the lowest latency sleep state with respect
1607 // to the latency time required to return to D0. If the
1608 // driver is not being used an inactivity timer in portcls will
1609 // place the driver in this state after a timeout period
1610 // controllable via the registry.
1611 //
1612
1613 // Let's power down the DAC/ADC's and analog mixer.
1614 WriteCodecRegister (AC97REG_POWERDOWN, 0x0700, 0xFFFF);
1615 break;
1616
1617 case PowerDeviceD2:
1618 case PowerDeviceD3:
1619 //
1620 // This is a full hibernation state and is the longest latency sleep
1621 // state. In this modes the power could be removed or reduced that
1622 // much that the AC97 controller looses information, so we save
1623 // whatever we have to save.
1624 //
1625
1626 //
1627 // Powerdown ADC, DAC, Mixer, Vref, HP amp, and Exernal Amp but not
1628 // AC-link and Clk
1629 //
1630 WriteCodecRegister (AC97REG_POWERDOWN, 0xCF00, 0xFFFF);
1631
1632 //
1633 // Only in D3 mode we set the AD3 bit and evtl. shut off the AC link.
1634 //
1635 if (NewState.DeviceState == PowerDeviceD3)
1636 {
1637 //
1638 // Set the AD3 bit.
1639 //
1640 ULONG ulReg = ReadBMControlRegister32 (GLOB_STA);
1641 WriteBMControlRegister (GLOB_STA, ulReg | GLOB_STA_AD3);
1642
1643 //
1644 // We check if the modem is sleeping. If it is, we can shut off the
1645 // AC link also. We shut off the AC link also if the modem is not
1646 // there.
1647 //
1648 if ((ulReg & GLOB_STA_MD3) || !(ulReg & GLOB_STA_SCR))
1649 {
1650 // Set Codec to super sleep
1651 WriteCodecRegister (AC97REG_POWERDOWN, 0xFF00, 0xFFFF);
1652
1653 // Disable the AC-link signals
1654 ulReg = ReadBMControlRegister32 (GLOB_CNT);
1655 WriteBMControlRegister (GLOB_CNT, (ulReg | GLOB_CNT_ACLOFF) & ~GLOB_CNT_COLD);
1656 }
1657 }
1658 break;
1659 }
1660
1661 //
1662 // Save the new state. This local value is used to determine when to
1663 // cache property accesses and when to permit the driver from accessing
1664 // the hardware.
1665 //
1666 m_PowerState = NewState.DeviceState;
1667 DOUT (DBG_POWER, ("Entering D%d", (ULONG)m_PowerState -
1669}
@ AC97REG_POWERDOWN
Definition: ac97reg.h:37
const int DBG_POWER
Definition: debug.h:23
const ULONG GLOB_STA_SCR
Definition: ichreg.h:85
const ULONG GLOB_CNT
Definition: ichreg.h:42
const ULONG GLOB_CNT_ACLOFF
Definition: ichreg.h:69
const ULONG GLOB_CNT_COLD
Definition: ichreg.h:71
const ULONG GLOB_STA_MD3
Definition: ichreg.h:77
const ULONG GLOB_STA_AD3
Definition: ichreg.h:78
const ULONG GLOB_STA
Definition: ichreg.h:43
@ PowerDeviceD1
Definition: ntpoapi.h:50
@ PowerDeviceD2
Definition: ntpoapi.h:51
@ PowerDeviceD3
Definition: ntpoapi.h:52