📄 common.cpp
字号:
/********************************************************************************
** Copyright (c) 1998-2000 Microsoft Corporation. All Rights Reserved.
**
** Portions Copyright (c) 1998-1999 Intel Corporation
**
********************************************************************************/
// Every debug output has "Modulname text"
static char STR_MODULENAME[] = "ICH Common: ";
#include "common.h"
/*****************************************************************************
* Static Members
*****************************************************************************
*/
//
// This is the register cache including registry names and default values. The
// first WORD contains the register value and the second WORD contains a flag.
// Currently, we only set SHREG_INVALID if we have to read the register at
// startup (that's true when there is no constant default value for the
// register). Note that we cache the registers only to prevent read access to
// the AC97 CoDec during runtime, because this is slow (40us).
// We only set SHREG_INIT if we want to set the register to default at driver
// startup. If needed, the third field contains the registry name and the
// forth field contains a default value that is used when there is no registry
// entry.
// The flag SHREG_NOCACHE is used when we don't want to cache the register
// at all. This is neccessary for status registers and sample rate registers.
//
tAC97Registers CAdapterCommon::m_stAC97Registers[] =
{
{0x0000, SHREG_INVALID, NULL, 0}, // AC97REG_RESET
{0x8000, SHREG_INIT, L"MasterVolume", 0x0000}, // AC97REG_MASTER_VOLUME
{0x8000, SHREG_INIT, L"HeadphoneVolume", 0x0000}, // AC97REG_HPHONE_VOLUME
{0x8000, SHREG_INIT, L"MonooutVolume", 0x0000}, // AC97REG_MMONO_VOLUME
{0x0F0F, SHREG_INIT, L"ToneControls", 0x0F0F}, // AC97REG_MASTER_TONE
{0x0000, SHREG_INVALID |
SHREG_INIT, L"BeepVolume", 0x0000}, // AC97REG_BEEP_VOLUME
{0x8008, SHREG_INIT, L"PhoneVolume", 0x8008}, // AC97REG_PHONE_VOLUME
{0x8008, SHREG_INIT, L"MicVolume", 0x8008}, // AC97REG_MIC_VOLUME
{0x8808, SHREG_INIT, L"LineInVolume", 0x0808}, // AC97REG_LINE_IN_VOLUME
{0x8808, SHREG_INIT, L"CDVolume", 0x0808}, // AC97REG_CD_VOLUME
{0x8808, SHREG_INIT, L"VideoVolume", 0x0808}, // AC97REG_VIDEO_VOLUME
{0x8808, SHREG_INIT, L"AUXVolume", 0x0808}, // AC97REG_AUX_VOLUME
{0x8808, SHREG_INIT, L"WaveOutVolume", 0x0808}, // AC97REG_PCM_OUT_VOLUME
{0x0000, SHREG_INIT, L"RecordSelect", 0x0404}, // AC97REG_RECORD_SELECT
{0x8000, SHREG_INIT, L"RecordGain", 0x0000}, // AC97REG_RECORD_GAIN
{0x8000, SHREG_INIT, L"RecordGainMic", 0x0000}, // AC97REG_RECORD_GAIN_MIC
{0x0000, SHREG_INIT, L"GeneralPurpose", 0x0000}, // AC97REG_GENERAL
{0x0000, SHREG_INIT, L"3DControl", 0x0000}, // AC97REG_3D_CONTROL
{0x0000, SHREG_NOCACHE, NULL, 0}, // AC97REG_RESERVED
{0x0000, SHREG_NOCACHE |
SHREG_INIT, L"PowerDown", 0}, // AC97REG_POWERDOWN
// AC97-2.0 registers
{0x0000, SHREG_INVALID, NULL, 0}, // AC97REG_EXT_AUDIO_ID
{0x0000, SHREG_NOCACHE |
SHREG_INIT, L"ExtAudioCtrl", 0x4001}, // AC97REG_EXT_AUDIO_CTRL
{0xBB80, SHREG_NOCACHE, NULL, 0}, // AC97REG_FRONT_SAMPLERATE
{0xBB80, SHREG_NOCACHE, NULL, 0}, // AC97REG_SURROUND_SAMPLERATE
{0xBB80, SHREG_NOCACHE, NULL, 0}, // AC97REG_LFE_SAMPLERATE
{0xBB80, SHREG_NOCACHE, NULL, 0}, // AC97REG_RECORD_SAMPLERATE
{0xBB80, SHREG_NOCACHE, NULL, 0}, // AC97REG_MIC_SAMPLERATE
{0x8080, SHREG_INIT, L"CenterLFEVolume", 0x0000}, // AC97REG_CENTER_LFE_VOLUME
{0x8080, SHREG_INIT, L"SurroundVolume", 0x0000}, // AC97REG_SURROUND_VOLUME
{0x0000, SHREG_NOCACHE, NULL, 0} // AC97REG_RESERVED2
// We leave the other values blank. There would be a huge gap with 31
// elements that are currently unused, and then there would be 2 other
// (used) values, the vendor IDs. We just force a read from the vendor
// IDs in the end of ProbeHWConfig to fill the cache.
};
//
// This is the hardware configuration information. The first struct is for
// nodes, which we default to FALSE. The second struct is for Pins, which
// contains the configuration (FALSE) and the registry string which is the
// reason for making a static struct so we can just fill in the name.
//
tHardwareConfig CAdapterCommon::m_stHardwareConfig =
{
// Nodes
{{FALSE}, {FALSE}, {FALSE}, {FALSE}, {FALSE}, {FALSE}, {FALSE}, {FALSE},
{FALSE}, {FALSE}, {FALSE}, {FALSE}, {FALSE}, {FALSE}, {FALSE}, {FALSE},
{FALSE}},
// Pins
{{FALSE, L"DisablePCBeep"}, // PINC_PCBEEP_PRESENT
{FALSE, L"DisablePhone"}, // PINC_PHONE_PRESENT
{FALSE, L"DisableMic2"}, // PINC_MIC2_PRESENT
{FALSE, L"DisableVideo"}, // PINC_VIDEO_PRESENT
{FALSE, L"DisableAUX"}, // PINC_AUX_PRESENT
{FALSE, L"DisableHeadphone"}, // PINC_HPOUT_PRESENT
{FALSE, L"DisableMonoOut"}, // PINC_MONOOUT_PRESENT
{FALSE, L"DisableMicIn"}, // PINC_MICIN_PRESENT
{FALSE, L"DisableMic"}, // PINC_MIC_PRESENT
{FALSE, L"DisableLineIn"}, // PINC_LINEIN_PRESENT
{FALSE, L"DisableCD"}, // PINC_CD_PRESENT
{FALSE, L"DisableSurround"}, // PINC_SURROUND_PRESENT
{FALSE, L"DisableCenterLFE"}} // PINC_CENTER_LFE_PRESENT
};
#pragma code_seg("PAGE")
/*****************************************************************************
* NewAdapterCommon
*****************************************************************************
* Create a new adapter common object.
*/
NTSTATUS NewAdapterCommon
(
OUT PUNKNOWN *Unknown,
IN REFCLSID,
IN PUNKNOWN UnknownOuter OPTIONAL,
IN POOL_TYPE PoolType
)
{
PAGED_CODE ();
ASSERT (Unknown);
DOUT (DBG_PRINT, ("[NewAdapterCommon]"));
STD_CREATE_BODY_
(
CAdapterCommon,
Unknown,
UnknownOuter,
PoolType,
PADAPTERCOMMON
);
}
/*****************************************************************************
* CAdapterCommon::Init
*****************************************************************************
* Initialize the adapter common object -> initialize and probe HW.
* Pass only checked resources.
*/
STDMETHODIMP_(NTSTATUS) CAdapterCommon::Init
(
IN PRESOURCELIST ResourceList,
IN PDEVICE_OBJECT DeviceObject
)
{
PAGED_CODE ();
ASSERT (ResourceList);
ASSERT (DeviceObject);
NTSTATUS ntStatus = STATUS_SUCCESS;
DOUT (DBG_PRINT, ("[CAdapterCommon::Init]"));
//
// Set the topology pointer to NULL.
//
m_Topology = NULL;
//
// Save the device object
//
m_pDeviceObject = DeviceObject;
//
// Get the base address for the AC97 codec and bus master.
//
ASSERT (ResourceList->FindTranslatedPort (0));
m_pCodecBase = (PUSHORT)ResourceList->FindTranslatedPort (0)->
u.Port.Start.QuadPart;
ASSERT (ResourceList->FindTranslatedPort (1));
m_pBusMasterBase = (PUCHAR)ResourceList->FindTranslatedPort (1)->
u.Port.Start.QuadPart;
DOUT (DBG_SYSINFO, ("Configuration:\n"
" Bus Master = 0x%X\n"
" Codec = 0x%X",
m_pBusMasterBase, m_pCodecBase));
//
// Set m_bDirectRead to TRUE so that all AC97 register read and
// writes are going directly to the HW
//
m_bDirectRead = TRUE;
//
// Initialize the hardware.
//
ntStatus = InitAC97 ();
if (!NT_SUCCESS (ntStatus))
return ntStatus;
//
// Probe hardware configuration
//
ntStatus = ProbeHWConfig ();
if (!NT_SUCCESS (ntStatus))
{
DOUT (DBG_ERROR, ("Probing of hardware configuration failed!"));
return ntStatus;
}
//
// Now, every AC97 read access goes to the cache.
//
m_bDirectRead = FALSE;
//
// Restore the AC97 registers now.
//
#if (DBG)
DumpConfig ();
#endif
ntStatus = SetAC97Default ();
//
// Initialize the device state.
//
m_PowerState = PowerDeviceD0;
return ntStatus;
}
/*****************************************************************************
* CAdapterCommon::~CAdapterCommon
*****************************************************************************
* Destructor.
*/
CAdapterCommon::~CAdapterCommon ()
{
PAGED_CODE ();
DOUT (DBG_PRINT, ("[CAdapterCommon::~CAdapterCommon]"));
}
#if (DBG)
/*****************************************************************************
* CAdapterCommon::DumpConfig
*****************************************************************************
* Dumps the HW configuration for the AC97 codec.
*/
void CAdapterCommon::DumpConfig (void)
{
PAGED_CODE ();
DOUT (DBG_PRINT, ("[CAdapterCommon::DumpConfig]"));
//
// Print debug output for MICIN.
//
if (GetPinConfig (PINC_MICIN_PRESENT))
{
DOUT (DBG_PROBE, ("MICIN found"));
}
else
{
DOUT (DBG_PROBE, ("No MICIN found"));
}
//
// Print debug output for tone controls.
//
if (GetNodeConfig (NODEC_TONE_PRESENT))
{
DOUT (DBG_PROBE, ("Tone controls found"));
}
else
{
DOUT (DBG_PROBE, ("No tone controls found"));
}
//
// Print debug output for mono out.
//
if (!GetPinConfig (PINC_MONOOUT_PRESENT))
{
DOUT (DBG_PROBE, ("No mono out found"));
}
//
// Print debug output for headphones.
//
if (!GetPinConfig (PINC_HPOUT_PRESENT))
{
DOUT (DBG_PROBE, ("No headphone out found"));
}
//
// Print debug output for loudness.
//
if (GetNodeConfig (NODEC_LOUDNESS_PRESENT))
{
DOUT (DBG_PROBE, ("Loudness found"));
}
else
{
DOUT (DBG_PROBE, ("No Loudness found"));
}
//
// Print debug output for 3D.
//
if (GetNodeConfig (NODEC_3D_PRESENT))
{
DOUT (DBG_PROBE, ("3D controls found"));
}
else
{
DOUT (DBG_PROBE, ("No 3D controls found"));
}
//
// Print debug output for pc beep.
//
if (GetPinConfig (PINC_PCBEEP_PRESENT))
{
DOUT (DBG_PROBE, ("PC beep found"));
}
else
{
DOUT (DBG_PROBE, ("No PC beep found"));
}
//
// Print debug output for phone line (or mono line input).
//
if (GetPinConfig (PINC_PHONE_PRESENT))
{
DOUT (DBG_PROBE, ("Phone found"));
}
else
{
DOUT (DBG_PROBE, ("No Phone found"));
}
//
// Print debug output for video.
//
if (GetPinConfig (PINC_VIDEO_PRESENT))
{
DOUT (DBG_PROBE, ("Video in found"));
}
else
{
DOUT (DBG_PROBE, ("No Video in found"));
}
//
// Print debug output for AUX.
//
if (GetPinConfig (PINC_AUX_PRESENT))
{
DOUT (DBG_PROBE, ("AUX in found"));
}
else
{
DOUT (DBG_PROBE, ("No AUX in found"));
}
//
// Print debug output for second miorophone.
//
if (GetPinConfig (PINC_MIC2_PRESENT))
{
DOUT (DBG_PROBE, ("MIC2 found"));
}
else
{
DOUT (DBG_PROBE, ("No MIC2 found"));
}
//
// Print debug output for 3D stuff.
//
if (GetNodeConfig (NODEC_3D_PRESENT))
{
if (GetNodeConfig (NODEC_3D_CENTER_ADJUSTABLE))
{
DOUT (DBG_PROBE, ("Adjustable 3D center control found"));
}
if (GetNodeConfig (NODEC_3D_DEPTH_ADJUSTABLE))
{
DOUT (DBG_PROBE, ("Nonadjustable 3D depth control found"));
}
}
//
// Print debug output for quality of master volume.
//
if (GetNodeConfig (NODEC_6BIT_MASTER_VOLUME))
{
DOUT (DBG_PROBE, ("6bit master out found"));
}
else
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -