📄 atapiromi.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*++
Module Name:
atapiRomi.cpp
based on atapipci.cpp
Abstract:
ATA/ATAPI for 2440 Ref Board.
Revision History:
--*/
#include "atapiRomi.h"
#include "atapiRomipm.h"
#include "bsp_cfg.h"
#define RTL_MSG 1
LONG CRomiDisk::m_lDeviceCount = 0;
static TCHAR *g_szPCICDRomDisk = TEXT("CD-ROM");
static TCHAR *g_szPCIHardDisk = TEXT("Hard Disk");
// ----------------------------------------------------------------------------
// Function: CreatePCIHD
// Spawn function called by IDE/ATA controller enumerator
//
// Parameters:
// hDevKey -
// ----------------------------------------------------------------------------
EXTERN_C
CDisk *
CreateRomi(
HKEY hDevKey
)
{
return new CRomiDisk(hDevKey);
}
// ----------------------------------------------------------------------------
// Function: CRomiDisk
// Constructor
//
// Parameters:
// hKey -
// ----------------------------------------------------------------------------
CRomiDisk::CRomiDisk(
HKEY hKey
) : CDisk(hKey)
{
m_pStartMemory = NULL;
m_pPort = NULL;
m_pPhysList = NULL;
m_pSGCopy = NULL;
m_pPFNs = NULL;
m_pPRDPhys = 0;
m_pPRD = NULL;
m_dwPhysCount = 0;
m_dwSGCount = 0;
m_dwPRDSize = 0;
m_pBMCommand = NULL;
InterlockedIncrement(&m_lDeviceCount);
DEBUGMSG(ZONE_INIT|ZONE_PCI, (_T(
"Atapi!CRomiDisk::CRomiDisk> device count(%d)\r\n"
), m_lDeviceCount));
}
// ----------------------------------------------------------------------------
// Function: ~CRomiDisk
// Destructor
//
// Parameters:
// None
// ----------------------------------------------------------------------------
CRomiDisk::~CRomiDisk(
)
{
FreeDMABuffers();
/*
if ( m_vpATAPIRegs )
{
VirtualFree((PVOID)m_vpATAPIRegs, 0, MEM_RELEASE);
m_vpATAPIRegs = NULL;
}
*/
if ( m_vpEBIRegs )
{
VirtualFree((PVOID)m_vpEBIRegs, 0, MEM_RELEASE);
m_vpEBIRegs= NULL;
}
if ( m_vpIOPORTRegs )
{
VirtualFree((PVOID)m_vpIOPORTRegs, 0, MEM_RELEASE);
m_vpIOPORTRegs = NULL;
}
InterlockedDecrement(&m_lDeviceCount);
DEBUGMSG(ZONE_INIT|ZONE_PCI, (_T(
"Atapi!CRomiDisk::~CRomiDisk> device count(%d)\r\n"
), m_lDeviceCount));
}
// ----------------------------------------------------------------------------
// Function: FreeDMABuffers
// Deallocate DMA buffers
//
// Parameters:
// None
// ----------------------------------------------------------------------------
void
CRomiDisk::FreeDMABuffers(
)
{
if (m_pPRD) {
FreePhysMem(m_pPRD);
m_pPRDPhys = NULL;
m_pPRD = NULL;
}
if (m_pPhysList) {
// free the fixed pages; the variable pages should already be free
for (DWORD i = 0; i < MIN_PHYS_PAGES; i++) {
FreePhysMem(m_pPhysList[i].pVirtualAddress);
}
VirtualFree(m_pPhysList, UserKInfo[KINX_PAGESIZE], MEM_DECOMMIT);
m_pPhysList = NULL;
}
if (m_pSGCopy) {
VirtualFree(m_pSGCopy, UserKInfo[KINX_PAGESIZE], MEM_DECOMMIT);
m_pSGCopy = NULL;
}
if (m_pPFNs) {
VirtualFree(m_pPFNs, UserKInfo[KINX_PAGESIZE], MEM_DECOMMIT);
m_pSGCopy = NULL;
}
VirtualFree(m_pStartMemory, 0, MEM_RELEASE);
m_pStartMemory = NULL;
m_dwPhysCount = 0;
m_dwSGCount = 0;
}
// ----------------------------------------------------------------------------
// Function: CopyDiskInfoFromPort
// This function is not used
//
// Parameters:
// None
// ----------------------------------------------------------------------------
void
CRomiDisk::CopyDiskInfoFromPort(
)
{
ASSERT(m_pPort->m_dwRegBase != 0);
m_pATAReg = (PBYTE)m_pPort->m_dwRegBase;
m_pATARegAlt = (PBYTE)m_pPort->m_dwRegAlt;
ASSERT(m_pPort->m_dwBMR != 0);
m_pBMCommand = (LPBYTE)m_pPort->m_dwBMR;
}
// ----------------------------------------------------------------------------
// Function: WaitForInterrupt
// Wait for interrupt
//
// Parameters:
// dwTimeOut -
// ----------------------------------------------------------------------------
BOOL
CRomiDisk::WaitForInterrupt(
DWORD dwTimeOut
)
{
BYTE bStatus;
BOOL fRet = TRUE;
DWORD dwRet;
// wait for interrupt
dwRet = WaitForSingleObject(m_pPort->m_hIRQEvent, dwTimeOut);
if (dwRet == WAIT_TIMEOUT) {
fRet = FALSE;
}
else {
if (dwRet != WAIT_OBJECT_0) {
if (!WaitForDisc(WAIT_TYPE_DRQ, dwTimeOut, 10)) {
fRet = FALSE;
}
}
}
// read status; acknowledge interrupt
bStatus = GetBaseStatus();
if (bStatus & ATA_STATUS_ERROR) {
bStatus = GetError();
fRet = FALSE;
}
// signal interrupt done
InterruptDone(m_pPort->m_dwSysIntr);
return fRet;
}
// ----------------------------------------------------------------------------
// Function: EnableInterrupt
// Enable channel interrupt
//
// Parameters:
// None
// ----------------------------------------------------------------------------
void
CRomiDisk::EnableInterrupt(
)
{
GetBaseStatus(); // acknowledge interrupt, if pending
// signal interrupt done
InterruptDone(m_pPort->m_dwSysIntr);
}
// ----------------------------------------------------------------------------
// Function: ConfigureRegisterBlock
// This function is called by DSK_Init before any other CDisk function to
// set up the register block.
//
// Parameters:
// dwStride -
// ----------------------------------------------------------------------------
VOID
CRomiDisk::ConfigureRegisterBlock(
DWORD dwStride
)
{
m_dwStride = dwStride;
m_dwDataDrvCtrlOffset = ATA_PIO_DTR;//ATA_REG_DATA * dwStride;
m_dwFeatureErrorOffset = ATA_PIO_FED;//ATA_REG_FEATURE * dwStride;
m_dwSectCntReasonOffset = ATA_PIO_SCR;//ATA_REG_SECT_CNT * dwStride;
m_dwSectNumOffset = ATA_PIO_LLR;//ATA_REG_SECT_NUM * dwStride;
m_dwByteCountLowOffset = ATA_PIO_LMR;//ATA_REG_BYTECOUNTLOW * dwStride;
m_dwByteCountHighOffset = ATA_PIO_LHR;//ATA_REG_BYTECOUNTHIGH * dwStride;
m_dwDrvHeadOffset = ATA_PIO_DVR;//ATA_REG_DRV_HEAD * dwStride;
m_dwCommandStatusOffset =ATA_PIO_CSD;// ATA_REG_COMMAND * dwStride;
// PCI ATA implementations don't assign I/O resources for the first four
// bytes, as they are unused
m_dwAltStatusOffset = ATA_PIO_DAD;//8 * dwStride;//ATA_REG_ALT_STATUS * dwStride;
m_dwAltDrvCtrl = ATA_PIO_DAD;//8 * dwStride;//ATA_REG_DRV_CTRL * dwStride;
}
// ----------------------------------------------------------------------------
// Function: Init
// Initialize channel
//
// Parameters:
// hActiveKey -
// ----------------------------------------------------------------------------
BOOL
CRomiDisk::Init(
HKEY hActiveKey
)
{
BOOL bRet = FALSE;
m_f16Bit = TRUE; // PCI is 16-bit
// configure port
if (!ConfigPort()) {
DEBUGMSG(ZONE_INIT, (_T(
"Atapi!CRomiDisk::Init> Failed to configure port; device(%u)\r\n"
), m_dwDeviceId));
goto exit;
}
// assign the appropriate folder name
//m_szDiskName = (IsCDRomDevice() ? g_szPCICDRomDisk : g_szPCIHardDisk);
// reserve memory for DMA buffers
m_pStartMemory = (LPBYTE)VirtualAlloc(NULL, 0x10000, MEM_RESERVE, PAGE_READWRITE);
if (!m_pStartMemory) {
bRet = FALSE;
}
*(UINT32 *)(m_pATAReg + ATA_CONTROL) |= 1;
//*(UINT32 *)(m_pATAReg + ATA_CFG ) |= 0x40; // set big endian hsjang
// finish intialization; i.e., initialize device
bRet = CDisk::Init(hActiveKey);
//*(UINT32 *)(m_pATAReg + ATA_CFG) &= ~(0x40); // set little endian hsjang
if (!bRet) {
goto exit;
}
exit:;
return bRet;
}
// ----------------------------------------------------------------------------
// Function: MainIoctl
// This is redundant
//
// Parameters:
// pIOReq -
// ----------------------------------------------------------------------------
DWORD
CRomiDisk::MainIoctl(
PIOREQ pIOReq
)
{
DEBUGMSG(ZONE_IOCTL, (_T(
"Atapi!CRomiDisk::MainIoctl> IOCTL(%d), device(%d) \r\n"
), pIOReq->dwCode, m_dwDeviceId));
return CDisk::MainIoctl(pIOReq);
}
// ----------------------------------------------------------------------------
// Function: ConfigPort
// Initialize IST/ISR
//
// Parameters:
// None
// ----------------------------------------------------------------------------
BOOL
CRomiDisk::ConfigPort(
)
{
// int i;
int RetValue=TRUE;
DWORD dwCleanUp = 0; // track progress for undo on clean up
m_pATAReg = (PBYTE)m_pPort->m_dwRegBase;
m_pATARegAlt = (PBYTE)m_pPort->m_dwRegAlt;
m_pBMCommand = (PBYTE)m_pPort->m_dwBMR;
m_vpIOPORTRegs= (volatile S3C2450_IOPORT_REG *)VirtualAlloc(0, sizeof(S3C2450_IOPORT_REG), MEM_RESERVE, PAGE_NOACCESS);
if (m_vpIOPORTRegs == NULL)
{
RETAILMSG(1,(TEXT("For m_vpATAPIRegs : VirtualAlloc failed! error code %d\r\n"),GetLastError()));
RetValue = FALSE;
}
else
{
if (!VirtualCopy((PVOID)m_vpIOPORTRegs, (PVOID)(S3C2450_BASE_REG_PA_IOPORT>>8),
sizeof(S3C2450_IOPORT_REG), PAGE_PHYSICAL | PAGE_READWRITE | PAGE_NOCACHE))
{
RETAILMSG(1,(TEXT("For INTRregs: VirtualCopy failed IOPORT!\r\n")));
RetValue = FALSE;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -