minwave.cpp
来自「AC97 Sample Driver and Related Code Samp」· C++ 代码 · 共 1,667 行 · 第 1/5 页
CPP
1,667 行
else
{
DOUT (DBG_STREAM, ("[TestDataFormat] PCM - Frequency: %d, Channels: %d, bps: %d",
waveFormat->Format.nSamplesPerSec, waveFormat->Format.nChannels,
waveFormat->Format.wBitsPerSample));
}
return STATUS_SUCCESS;
}
/*****************************************************************************
* CMiniportWaveICH::PowerChangeNotify
*****************************************************************************
* This routine gets called as a result of hooking up the IPowerNotify
* interface. This interface indicates the driver's desire to receive explicit
* notification of power state changes. The interface provides a single method
* (or callback) that is called by the miniport's corresponding port driver in
* response to a power state change. Using wave audio as an example, when the
* device is requested to go to a sleep state the port driver pauses any
* active streams and then calls the power notify callback to inform the
* miniport of the impending power down. The miniport then has an opportunity
* to save any necessary context before the adapter's PowerChangeState method
* is called. The process is reversed when the device is powering up. PortCls
* first calls the adapter's PowerChangeState method to power up the adapter.
* The port driver then calls the miniport's callback to allow the miniport to
* restore its context. Finally, the port driver unpauses any previously paused
* active audio streams.
*/
STDMETHODIMP_(void) CMiniportWaveICH::PowerChangeNotify
(
IN POWER_STATE NewState
)
{
PAGED_CODE ();
NTSTATUS ntStatus = STATUS_SUCCESS;
DOUT (DBG_PRINT, ("[CMiniportWaveICH::PowerChangeNotify]"));
//
// Check to see if this is the current power state.
//
if (NewState.DeviceState == m_PowerState)
{
DOUT (DBG_POWER, ("New device state equals old state."));
return;
}
//
// Check the new device state.
//
if ((NewState.DeviceState < PowerDeviceD0) ||
(NewState.DeviceState > PowerDeviceD3))
{
DOUT (DBG_ERROR, ("Unknown device state: D%d.",
(ULONG)NewState.DeviceState - (ULONG)PowerDeviceD0));
return;
}
DOUT (DBG_POWER, ("Changing state to D%d.", (ULONG)NewState.DeviceState -
(ULONG)PowerDeviceD0));
//
// In case we return to D0 power state from a D3 state, restore the
// interrupt connection.
//
if (NewState.DeviceState == PowerDeviceD0)
{
ntStatus = InterruptSync->Connect ();
if (!NT_SUCCESS (ntStatus))
{
DOUT (DBG_ERROR, ("Failed to connect the ISR with InterruptSync!"));
// We can do nothing else than just continue ...
}
}
//
// Call the stream routine which takes care of the DMA engine.
// That's all we have to do.
//
for (int loop = PIN_WAVEOUT_OFFSET; loop < PIN_MICIN_OFFSET; loop++)
{
if (Streams[loop])
{
ntStatus = Streams[loop]->PowerChangeNotify (NewState);
if (!NT_SUCCESS (ntStatus))
{
DOUT (DBG_ERROR, ("PowerChangeNotify D%d for the stream failed",
(ULONG)NewState.DeviceState - (ULONG)PowerDeviceD0));
}
}
}
//
// In case we go to any sleep state we disconnect the interrupt service
// reoutine from the interrupt.
// Normally this is not required to do, but for some reason this fixes
// a problem where we won't have any interrupts on specific motherboards
// after resume.
//
if (NewState.DeviceState != PowerDeviceD0)
{
InterruptSync->Disconnect ();
}
//
// Save the new state. This local value is used to determine when to
// cache property accesses and when to permit the driver from accessing
// the hardware.
//
m_PowerState = NewState.DeviceState;
DOUT (DBG_POWER, ("Entering D%d",
(ULONG)m_PowerState - (ULONG)PowerDeviceD0));
}
/*****************************************************************************
* Non paged code begins here
*****************************************************************************
*/
#pragma code_seg()
/*****************************************************************************
* CMiniportWaveICH::Service
*****************************************************************************
* Processing routine for dealing with miniport interrupts. This routine is
* called at DISPATCH_LEVEL.
*/
STDMETHODIMP_(void) CMiniportWaveICH::Service (void)
{
// not needed
}
/*****************************************************************************
* InterruptServiceRoutine
*****************************************************************************
* The task of the ISR is to clear an interrupt from this device so we don't
* get an interrupt storm and schedule a DPC which actually does the
* real work.
*/
NTSTATUS CMiniportWaveICH::InterruptServiceRoutine
(
IN PINTERRUPTSYNC InterruptSync,
IN PVOID DynamicContext
)
{
ASSERT (InterruptSync);
ASSERT (DynamicContext);
ULONG GlobalStatus;
USHORT DMAStatusRegister;
//
// Get our context which is a pointer to class CMiniportWaveICH.
//
CMiniportWaveICH *that = (CMiniportWaveICH *)DynamicContext;
//
// Check for a valid AdapterCommon pointer.
//
if (!that->AdapterCommon)
{
//
// In case we didn't handle the interrupt, unsuccessful tells the system
// to call the next interrupt handler in the chain.
//
return STATUS_UNSUCCESSFUL;
}
//
// From this point down, basically in the complete ISR, we cannot use
// relative addresses (stream class base address + X_CR for example)
// cause we might get called when the stream class is destroyed or
// not existent. This doesn't make too much sense (that there is an
// interrupt for a non-existing stream) but could happen and we have
// to deal with the interrupt.
//
//
// Read the global register to check the interrupt bits
//
GlobalStatus = that->AdapterCommon->ReadBMControlRegister32 (GLOB_STA);
//
// Check for weird return values. Could happen if the PCI device is already
// disabled and another device that shares this interrupt generated an
// interrupt.
// The register should never have all bits cleared or set.
//
if (!GlobalStatus || (GlobalStatus == 0xFFFFFFFF))
{
return STATUS_UNSUCCESSFUL;
}
//
// Check for PCM out interrupt.
//
NTSTATUS ntStatus = STATUS_UNSUCCESSFUL;
if (GlobalStatus & GLOB_STA_POINT)
{
//
// Read PCM out DMA status registers.
//
DMAStatusRegister = (USHORT)that->AdapterCommon->
ReadBMControlRegister16 (PO_SR);
//
// We could now check for every possible error condition
// (like FIFO error) and monitor the different errors, but currently
// we have the same action for every INT and therefore we simplify
// this routine enormous with just clearing the bits.
//
if (that->Streams[PIN_WAVEOUT_OFFSET])
{
//
// ACK the interrupt.
//
that->AdapterCommon->WriteBMControlRegister (PO_SR, DMAStatusRegister);
ntStatus = STATUS_SUCCESS;
//
// Request DPC service for PCM out.
//
if ((that->Port) && (that->Streams[PIN_WAVEOUT_OFFSET]->ServiceGroup))
{
that->Port->Notify (that->Streams[PIN_WAVEOUT_OFFSET]->ServiceGroup);
}
else
{
//
// Bad, bad. Shouldn't print in an ISR!
//
DOUT (DBG_ERROR, ("WaveOut INT fired but no stream object there."));
}
}
}
//
// Check for PCM in interrupt.
//
if (GlobalStatus & GLOB_STA_PIINT)
{
//
// Read PCM in DMA status registers.
//
DMAStatusRegister = (USHORT)that->AdapterCommon->
ReadBMControlRegister16 (PI_SR);
//
// We could now check for every possible error condition
// (like FIFO error) and monitor the different errors, but currently
// we have the same action for every INT and therefore we simplify
// this routine enormous with just clearing the bits.
//
if (that->Streams[PIN_WAVEIN_OFFSET])
{
//
// ACK the interrupt.
//
that->AdapterCommon->WriteBMControlRegister (PI_SR, DMAStatusRegister);
ntStatus = STATUS_SUCCESS;
//
// Request DPC service for PCM in.
//
if ((that->Port) && (that->Streams[PIN_WAVEIN_OFFSET]->ServiceGroup))
{
that->Port->Notify (that->Streams[PIN_WAVEIN_OFFSET]->ServiceGroup);
}
else
{
//
// Bad, bad. Shouldn't print in an ISR!
//
DOUT (DBG_ERROR, ("WaveIn INT fired but no stream object there."));
}
}
}
//
// Check for MIC in interrupt.
//
if (GlobalStatus & GLOB_STA_MINT)
{
//
// Read MIC in DMA status registers.
//
DMAStatusRegister = (USHORT)that->AdapterCommon->
ReadBMControlRegister16 (MC_SR);
//
// We could now check for every possible error condition
// (like FIFO error) and monitor the different errors, but currently
// we have the same action for every INT and therefore we simplify
// this routine enormous with just clearing the bits.
//
if (that->Streams[PIN_MICIN_OFFSET])
{
//
// ACK the interrupt.
//
that->AdapterCommon->WriteBMControlRegister (MC_SR, DMAStatusRegister);
ntStatus = STATUS_SUCCESS;
//
// Request DPC service for PCM out.
//
if ((that->Port) && (that->Streams[PIN_MICIN_OFFSET]->ServiceGroup))
{
that->Port->Notify (that->Streams[PIN_MICIN_OFFSET]->ServiceGroup);
}
else
{
//
// Bad, bad. Shouldn't print in an ISR!
//
DOUT (DBG_ERROR, ("MicIn INT fired but no stream object there."));
}
}
}
return ntStatus;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?