📄 atamain.cpp
字号:
DEBUGMSG(ZONE_INIT|ZONE_ERROR, (_T(
"Atapi!GetIDERegistryValueSet> Failed to read %s from IDE instance key\r\n"
), REG_VAL_IDE_STATUSPOLLCYCLEPAUSE));
return FALSE;
}
// fetch spawn function
fRet = AtaGetRegistryString(hIDEInstanceKey, REG_VAL_IDE_SPAWNFUNCTION, &pIdeReg->pszSpawnFunction);
if (!fRet) {
DEBUGMSG(ZONE_INIT|ZONE_ERROR, (_T(
"Atapi!GetIDERegistryValueSet> Failed to read %s from IDE instance key\r\n"
), REG_VAL_IDE_SPAWNFUNCTION));
return FALSE;
}
// fetch ISR dll; this is not mandatory; allocate pszIsrDll
fRet = AtaGetRegistryString(hIDEInstanceKey, REG_VAL_IDE_ISRDLL, &pIdeReg->pszIsrDll, 0);
if (!fRet) {
pIdeReg->pszIsrDll = NULL;
}
// fetch ISR handler; this is not mandatory; allocate pszIsrHandler
fRet = AtaGetRegistryString(hIDEInstanceKey, REG_VAL_IDE_ISRHANDLER, &pIdeReg->pszIsrHandler, 0);
if (!fRet) {
pIdeReg->pszIsrHandler = NULL;
}
// fetch device control offset; this is not mandatory
fRet = AtaGetRegistryValue(hIDEInstanceKey, REG_VAL_IDE_DEVICECONTROLOFFSET, &pIdeReg->dwDeviceControlOffset);
if (!fRet) {
// this value is only used by atapipcmcia
pIdeReg->dwDeviceControlOffset = ATA_REG_ALT_STATUS;
}
// fetch alternate status offset; this is not mandatory
fRet = AtaGetRegistryValue(hIDEInstanceKey, REG_VAL_IDE_ALTERNATESTATUSOFFSET, &pIdeReg->dwAlternateStatusOffset);
if (!fRet) {
// this value is only used by atapipcmcia
pIdeReg->dwAlternateStatusOffset = ATA_REG_DRV_CTRL;
}
// fetch register stride
fRet = AtaGetRegistryValue(hIDEInstanceKey, REG_VAL_IDE_REGISTERSTRIDE, &pIdeReg->dwRegisterStride);
if (!fRet) {
DEBUGMSG(ZONE_INIT|ZONE_ERROR, (_T(
"Atapi!GetIDERegistryValueSet> Failed to read %s from IDE instance key\r\n"
), REG_VAL_IDE_REGISTERSTRIDE));
return FALSE;
}
if (0 == pIdeReg->dwRegisterStride) {
DEBUGMSG(ZONE_INIT|ZONE_ERROR, (_T(
"Atapi!GetIDERegistryValueSet> Bad value(%d) for %s in IDE instance key; valid: > 0\r\n"
), pIdeReg->dwRegisterStride, REG_VAL_IDE_REGISTERSTRIDE));
return FALSE;
}
return TRUE;
}
// This function reads the DSK registry value set from the IDE/ATA controller's
// registry key
BOOL
GetDSKRegistryValueSet(
HKEY hDSKInstanceKey,
PDSKREG pDskReg
)
{
BOOL fRet;
// fetch device ID
fRet = AtaGetRegistryValue(hDSKInstanceKey, REG_VAL_DSK_DEVICEID, &pDskReg->dwDeviceId);
if (!fRet) {
DEBUGMSG(ZONE_INIT|ZONE_ERROR, (_T(
"Atapi!GetDSKRegistryValueSet> Failed to read %s from DSK instance key\r\n"
), REG_VAL_DSK_DEVICEID));
return FALSE;
}
if (!((0 <= pDskReg->dwDeviceId) && (pDskReg->dwDeviceId <= 3))) {
DEBUGMSG(ZONE_INIT|ZONE_ERROR, (_T(
"Atapi!GetDSKRegistryValueSet> Bad value(%d) for %s in DSK instance key; valid: {0, 1, 2, 3}\r\n"
), pDskReg->dwDeviceId, REG_VAL_DSK_DEVICEID));
return FALSE;
}
// fetch interrupt driven I/O boolean
fRet = AtaGetRegistryValue(hDSKInstanceKey, REG_VAL_DSK_INTERRUPTDRIVEN, &pDskReg->dwInterruptDriven);
if (!fRet) {
DEBUGMSG(ZONE_INIT|ZONE_ERROR, (_T(
"Atapi!GetDSKRegistryValueSet> Failed to read %s from DSK instance key\r\n"
), REG_VAL_DSK_INTERRUPTDRIVEN));
return FALSE;
}
if (pDskReg->dwInterruptDriven >= 2) {
DEBUGMSG(ZONE_INIT|ZONE_ERROR, (_T(
"Atapi!GetDSKRegistryValueSet> Bad value(%d) for %s in DSK instance key; valid: {0, 1}\r\n"
), pDskReg->dwInterruptDriven, REG_VAL_DSK_INTERRUPTDRIVEN));
return FALSE;
}
// fetch DMA triple
fRet = AtaGetRegistryValue(hDSKInstanceKey, REG_VAL_DSK_DMA, &pDskReg->dwDMA);
if (!fRet) {
DEBUGMSG(ZONE_INIT|ZONE_ERROR, (_T(
"Atapi!GetDSKRegistryValueSet> Failed to read %s from DSK instance key\r\n"
), REG_VAL_DSK_DMA));
pDskReg->dwDMA = 0;
}
if (pDskReg->dwDMA >= 3) {
DEBUGMSG(ZONE_INIT|ZONE_ERROR, (_T(
"Atapi!GetDSKRegistryValueSet> Bad value(%d) for %s in DSK instance key; valid: {0=no DMA, 1=DMA, 2=ATA DMA only}\r\n"
), pDskReg->dwDMA, REG_VAL_DSK_DMA));
return FALSE;
}
// fetch double buffer size
fRet = AtaGetRegistryValue(hDSKInstanceKey, REG_VAL_DSK_DOUBLEBUFFERSIZE, &pDskReg->dwDoubleBufferSize);
if (!fRet) {
DEBUGMSG(ZONE_INIT|ZONE_ERROR, (_T(
"Atapi!GetDSKRegistryValueSet> Failed to read %s from DSK instance key\r\n"
), REG_VAL_DSK_DOUBLEBUFFERSIZE));
return FALSE;
}
if (
(pDskReg->dwDoubleBufferSize < REG_VAL_DSK_DOUBLEBUFFERSIZE_MIN) ||
(pDskReg->dwDoubleBufferSize > REG_VAL_DSK_DOUBLEBUFFERSIZE_MAX)
) {
DEBUGMSG(ZONE_INIT|ZONE_ERROR, (_T(
"Atapi!GetDSKRegistryValueSet> Bad value(%d) for %s in DSK instance key; valid: {%d, ..., %d}\r\n"
), pDskReg->dwDoubleBufferSize, REG_VAL_DSK_DOUBLEBUFFERSIZE, REG_VAL_DSK_DOUBLEBUFFERSIZE_MIN, REG_VAL_DSK_DOUBLEBUFFERSIZE_MAX));
return FALSE;
}
// fetch DRQ data block size; this has to be validated by a sub-class
fRet = AtaGetRegistryValue(hDSKInstanceKey, REG_VAL_DSK_DRQDATABLOCKSIZE, &pDskReg->dwDrqDataBlockSize);
if (!fRet) {
DEBUGMSG(ZONE_INIT|ZONE_ERROR, (_T(
"Atapi!GetDSKRegistryValueSet> Failed to read %s from DSK instance key\r\n"
), REG_VAL_DSK_DRQDATABLOCKSIZE));
return FALSE;
}
// fetch write cache boolean
fRet = AtaGetRegistryValue(hDSKInstanceKey, REG_VAL_DSK_WRITECACHE, &pDskReg->dwWriteCache);
if (!fRet) {
DEBUGMSG(ZONE_INIT|ZONE_ERROR, (_T(
"Atapi!GetDSKRegistryValueSet> Failed to read %s from DSK instance key\r\n"
), REG_VAL_DSK_WRITECACHE));
return FALSE;
}
if (pDskReg->dwWriteCache >= 2) {
DEBUGMSG(ZONE_INIT|ZONE_ERROR, (_T(
"Atapi!GetDSKRegistryValueSet> Bad value(%d) for %s in DSK instance key; valid: {0, 1}\r\n"
), pDskReg->dwWriteCache, REG_VAL_DSK_WRITECACHE));
return FALSE;
}
// fetch look-ahead boolean
fRet = AtaGetRegistryValue(hDSKInstanceKey, REG_VAL_DSK_LOOKAHEAD, &pDskReg->dwLookAhead);
if (!fRet) {
DEBUGMSG(ZONE_INIT|ZONE_ERROR, (_T(
"Atapi!GetDSKRegistryValueSet> Failed to read %s from DSK instance key\r\n"
), REG_VAL_DSK_LOOKAHEAD));
return FALSE;
}
if (pDskReg->dwLookAhead >= 2) {
DEBUGMSG(ZONE_INIT|ZONE_ERROR, (_T(
"Atapi!GetDSKRegistryValueSet> Bad value(%d) for %s in DSK instance key; valid: {0, 1}\r\n"
), pDskReg->dwLookAhead, REG_VAL_DSK_LOOKAHEAD));
return FALSE;
}
// fetch transfer mode
fRet = AtaGetRegistryValue(hDSKInstanceKey, REG_VAL_DSK_TRANSFERMODE, &pDskReg->dwTransferMode);
if (!fRet) {
DEBUGMSG(ZONE_INIT|ZONE_ERROR, (_T(
"Atapi!GetDSKRegistryValueSet> Failed to read %s from DSK instance key\r\n"
), REG_VAL_DSK_TRANSFERMODE));
return FALSE;
}
fRet = AtaGetRegistryValue(hDSKInstanceKey, REG_VAL_DSK_ENABLE_PDMA, &pDskReg->dwEnablePDMA);
if (!fRet) {
DEBUGMSG(ZONE_INIT|ZONE_ERROR, (_T(
"Atapi!GetDSKRegistryValueSet> Failed to read %s from DSK instance key\r\n"
), REG_VAL_DSK_ENABLE_PDMA));
pDskReg->dwEnablePDMA= 0;
}
fRet = AtaGetRegistryValue(hDSKInstanceKey, REG_VAL_DSK_ENABLE_UDMA, &pDskReg->dwEnableUDMA);
if (!fRet) {
DEBUGMSG(ZONE_INIT|ZONE_ERROR, (_T(
"Atapi!GetDSKRegistryValueSet> Failed to read %s from DSK instance key\r\n"
), REG_VAL_DSK_ENABLE_UDMA));
pDskReg->dwEnableUDMA= 0;
}
return TRUE;
}
// This function reads the I/O window data from the IDE instance key and builds
// the I/O ports for the primary and secondary IDE controller channels
BOOL
GetIoPort(
HKEY hDevKey,
PTSTR szDevKey,
CIDEBUS *pBus
)
{
BOOL fRet = FALSE;
DEBUGCHK(pBus);
DEBUGCHK(pBus->m_pPrimaryPort);
DEBUGCHK(pBus->m_pSecondaryPort);
// TODO: What if the IDE/ATA controller only supports a single device on
// TODO: (con't) a single channel and bus mastering?
// fetch the IDE/ATA channel's I/O window; a channel can contain a single device
// or a master and a slave device; each device requires a device control I/O
// window and an alternate status I/O window; if the IDE/ATA controller supports
// bus mastering, then a bus master I/O window will be present
if (
(!AtaGetRegistryResources(hDevKey, &pBus->m_dwi)) ||
(pBus->m_dwi.dwNumIoWindows < 2)
) {
DEBUGMSG(ZONE_INIT|ZONE_ERROR, (_T(
"Atapi!BuildPortSet> Resource configuration missing or invalid in device key(%s)\r\n"
), szDevKey));
goto exit;
}
// save the base virtual addresss of the device control (RegBase)
// and alternate status (RegAlt) I/O windows
pBus->m_pPrimaryPort->m_dwRegBase = DoIoTranslation(&pBus->m_dwi, 0);
pBus->m_pPrimaryPort->m_dwRegAlt = DoIoTranslation(&pBus->m_dwi, 1);
pBus->m_pPrimaryPort->m_fInitialized = TRUE;
if (pBus->m_dwi.dwNumIoWindows >= 4) {
// this channel supports a primary and secondary IDE/ATA channels; save
// the base virtual addresses of the secondary channel's devoce control
// and alternate status I/O windows
pBus->m_pSecondaryPort->m_dwRegBase = DoIoTranslation(&pBus->m_dwi, 2);
pBus->m_pSecondaryPort->m_dwRegAlt = DoIoTranslation(&pBus->m_dwi, 3);
pBus->m_pSecondaryPort->m_fInitialized = TRUE;
}
if (pBus->m_dwi.dwNumIoWindows >= 5) {
// the IDE/ATA controller supports bus mastering; save the base virtual
// address of each channel's bus master I/O window
DEBUGCHK(pBus->m_dwi.ioWindows[4].dwLen >= 16);
pBus->m_pPrimaryPort->m_dwBMR = DoIoTranslation(&pBus->m_dwi, 4);
pBus->m_pPrimaryPort->m_dwBMRStatic= DoStaticTranslation(&pBus->m_dwi, 4);
pBus->m_pSecondaryPort->m_dwBMR = pBus->m_pPrimaryPort->m_dwBMR + 8;
pBus->m_pSecondaryPort->m_dwBMRStatic = pBus->m_pPrimaryPort->m_dwBMRStatic + 8;
}
fRet = TRUE;
exit:;
return fRet;
}
// IDE/ATA and ATA/ATAPI device stream interface
/*++
DSK_Init
This function is called as a result of IDE_Init calling ActivateDevice on
HKLM\Drivers\@BUS\@IDEAdapter\DeviceX, to initialize a master or slave
device on a particular IDE/ATA channel of a particular IDE/ATA controller.
That is, an "IDE" driver is a bus driver for devices to one its IDE/ATA
controller's channels.
This function is responsible for creating a CDisk instance to associate
with a device. This function reads the "Object" value from its instance
key to determine which CDisk (sub)type to instantiate and calls Init on the
CDisk instance to initialize the device. If the device is not present, then
Init will fail. The "Object" value maps to a function that creates an
instance of the target CDisk (sub)type.
Note that this driver model is convoluted. A CDisk (sub)type instance
corresponds to both an IDE/ATA controller and an ATA/ATAPI device.
Parameters:
dwContext - pointer to string containing the registry path to the active key
of the associated device; the active key contains a key to the device's instance
key, which stores all of the device's configuration information
Return:
On success, return handle to device (to identify device); this handle is
passed to all subsequent DSK_Xxx calls. Otherwise, return null.
--*/
#define DSKINIT_UNDO_CLS_KEY_ACTIVE 0x1
#define DSKINIT_UNDO_CLS_KEY_DEVICE 0x2
EXTERN_C
DWORD
DSK_Init(
DWORD dwContext
)
{
DWORD dwUndo = 0; // undo bitset
PTSTR szActiveKey = (PTSTR)dwContext; // name of device's active key
HKEY hActiveKey; // handle to device's active key
PTSTR szDevKey = NULL; // name of device's instance key
HKEY hDevKey; // handle to device's instance key
POBJECTFUNCTION pObject = NULL; // pointer to spawn function
CPort *pPort = NULL; // port
DWORD dwDeviceId = 0; // device ID; 0 => master, 1 => slave
CDisk *pDisk = NULL; // return
// guard global data; i.e., g_pDiskRoot
EnterCriticalSection(&g_csMain);
// open device's active key
if ((ERROR_SUCCESS != RegOpenKeyEx(HKEY_LOCAL_MACHINE, szActiveKey, 0, 0, &hActiveKey))) {
DEBUGMSG(ZONE_INIT|ZONE_ERROR, (_T(
"Atapi!DSK_Init> Failed to open device's active key(%s)\r\n"
), szActiveKey));
goto exit;
}
dwUndo |= DSKINIT_UNDO_CLS_KEY_ACTIVE;
DUMPREGKEY(ZONE_INIT, szActiveKey, hActiveKey);
// read name of and open device's instance key from device's active key
if (!(hDevKey = AtaLoadRegKey(hActiveKey, &szDevKey))) {
DEBUGMSG(ZONE_INIT|ZONE_ERROR, (_T(
"Atapi!DSK_Init> Failed to fetch/open device's instance key from device's active key(%s)\r\n"
), szActiveKey));
goto exit;
}
dwUndo |= DSKINIT_UNDO_CLS_KEY_DEVICE;
DUMPREGKEY(ZONE_INIT, szDevKey, hDevKey);
// fetch heap address of port instance from device's instance key
if (!AtaGetRegistryValue(hDevKey, REG_VALUE_PORT, (PDWORD)&pPort)) {
DEBUGMSG(ZONE_INIT|ZONE_ERROR, (_T(
"Atapi!DSK_Init> Failed to read address of port instance from device's instance key(%s)\r\n"
), szDevKey));
RETAILMSG(1, (_T(
"Atapi!DSK_Init> Failed to read address of port instance from device's instance key(%s)\r\n"
), szDevKey));
goto exit;
}
// fetch device ID from device's instance key; this informs the CDisk
// instance as to which device (i.e., master/slave) it is
if (!AtaGetRegistryValue(hDevKey, REG_VAL_DSK_DEVICEID, &dwDeviceId)) {
DEBUGMSG(ZONE_INIT|ZONE_ERROR, (_T(
"Atapi!DSK_Init> Failed to read device ID device's instance key(%s)\r\n"
), szDevKey));
goto exit;
}
// resolve address of spawn function
pObject = (POBJECTFUNCTION)GetProcAddress(g_hInstance, pPort->m_pController->m_pIdeReg->pszSpawnFunction);
if (!pObject) {
DEBUGMSG(ZONE_INIT|ZONE_ERROR, (_T(
"Atapi!DSK_Init> Failed to resolve address of device's spawn function(%s)\r\n"
), pPort->m_pController->m_pIdeReg->pszSpawnFunction));
goto exit;
}
// instantiate CDisk object
pDisk = pObject(hDevKey);
// if successful, write the name of the device's active and instance keys to
// its CDisk instance, and add the CDisk instance to the IDE/ATA bus driver's
// list of active disk devices
if (pDisk) {
// this information is used for ATA/ATAPI power management
pDisk->SetActiveKey(szActiveKey);
pDisk->SetDeviceKey(szDevKey);
// inform the CDisk instance as to which device it is
(pDisk)->m_pPort = pPort;
pDisk->m_dwDeviceId = dwDeviceId;
pDisk->m_dwDevice = dwDeviceId;
// configure register block
pDisk->ConfigureRegisterBlock(pPort->m_pController->m_pIdeReg->dwRegisterStride);
// initialize device
if (!(pDisk->Init(hActiveKey))) {
delete pDisk;
pDisk = NULL;
goto exit;
}
// add CDisk instance to IDE/ATA controller's list of active devices
pDisk->m_pNextDisk = g_pDiskRoot;
g_pDiskRoot = pDisk;
DEBUGMSG(ZONE_INIT, (_T(
"Atapi!DSK_Init> Initialized %s %s on %s\r\n"
), ((pPort == pPort->m_pController->m_pPrimaryPort) ? (_T("PRIMARY")) : (_T("SECONDARY"))),
((dwDeviceId == 0) ? (_T("MASTER")) : (_T("SLAVE"))),
szDevKey
));
}
exit:;
// clean up
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -