?? diskmain.h
字號:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
/*++
Module Name:
diskmain.h
Abstract:
Base ATA/ATAPI device abstraction.
Revision History:
--*/
#ifndef _DISKMAIN_H_
#define _DISKMAIN_H_
#include <atapi2.h>
#include <atamain.h>
#include <atapiio.h>
#include <atapipm.h>
#include <csgreq.h>
#include <storemgr.h>
#define MAXIMUM_DMA_TRANSFER_SIZE (512 * 256)
#define MUX_REG 0x1800
#define ATA_CONTROL 0x1900
#define ATA_STATUS 0x1904
#define ATA_COMMAND 0x1908
#define ATA_SWRST 0x190c
#define ATA_IRQ 0x1910
#define ATA_IRQ_MASK 0x1914
#define ATA_CFG 0x1918
#define ATA_PIO_TIME 0x192c
#define ATA_UDMA_TIME 0x1930
#define ATA_XFR_NUM 0x1934
#define ATA_XFR_CNT 0x1938
#define ATA_TBUF_START 0x193c
#define ATA_TBUF_SIZE 0x1940
#define ATA_SBUF_START 0x1944
#define ATA_SBUF_SIZE 0x1948
#define ATA_CADDR_TBUR 0x194c
#define ATA_CADDR_SBUF 0x1950
#define ATA_PIO_DTR 0x1954
#define ATA_PIO_FED 0x1958
#define ATA_PIO_SCR 0x195c
#define ATA_PIO_LLR 0x1960
#define ATA_PIO_LMR 0x1964
#define ATA_PIO_LHR 0x1968
#define ATA_PIO_DVR 0x196c
#define ATA_PIO_CSD 0x1970
#define ATA_PIO_DAD 0x1974
#define ATA_PIO_READY 0x1978
#define ATA_PIO_RDATA 0x197c
#define BUS_FIFO_STATUS 0x1990
#define ATA_FIFO_STATUS 0x1994
// These flags are used by CDisk m_dwDeviceFlags member
#define DFLAGS_DEVICE_PRESENT (1 << 0) // Device is present (Set in Identify; Tested in ADC)
#define DFLAGS_ATAPI_DEVICE (1 << 1) // Device is ATAPI (Set in Identify; Not tested--redundant, same as m_fAtapiDevice)
#define DFLAGS_INT_DRQ (1 << 3) // Device interrupts as DRQ is set after receiving ATAPI packet command
#define DFLAGS_REMOVABLE_DRIVE (1 << 4) // Removable media device bit set in Identify Data (General Configuration) (Set in Identify; Not tested)
#define DFLAGS_DEVICE_ISDVD (1 << 6) // Device is DVD (use different read command) (Set in ReadSettings, based on registry; Tested in SetupCdRomRead)
#define DFLAGS_MEDIA_ISDVD (1 << 7) // Media is DVD (Not set; Unset in DVDGetCopySystem; Tested in DVDGetRegion)
#define DFLAGS_USE_WRITE_CACHE (1 << 8) // Use write cache (Set in ReadSettings based on Identify Data and in ReadSettings based on registry; Unset in ReadSettings based on registry; Tested in FlushCache)
#define DFLAGS_DEVICE_PWRDN (1 << 24) // Device has been powered down (Set in PowerDown; Unset in PowerUp; Tested in MainIoctl)
#define DFLAGS_DEVICE_CDROM (1 << 26) // Device is CD-ROM (Set in Identify; Tested in StallExecution)
#define DFLAGS_DEVICE_INITIALIZED (1 << 30) // File system is loaded and Storage Manager has requested device information (Set in CPCIDisk::ConfigPort and CPCIDisk::InitController; Tested in CPCIDisk::InitController)
// These flags are not set and not tested
#define DFLAGS_TAPE_DEVICE (1 << 2) // Device is tape (Not set; Not tested)
#define DFLAGS_MEDIA_STATUS_ENABLED (1 << 5) // Device supports removable media status notification feature set? (Not set; Not tested)
#define DFLAGS_USE_DMA (1 << 9) // Device supports DMA (Not set; Not tested)
#define DFLAGS_LBA (1 << 10) // Device supports LBA (Not set; Not tested)
#define DFLAGS_MULTI_LUN_INITED (1 << 11) // Multi-LUN support intialized (Not set; Not tested)
#define DFLAGS_MSN_SUPPORT (1 << 12) // Device supports media status notifications (Not set; Not tested)
#define DFLAGS_AUTO_EJECT_ZIP (1 << 13) // "Boot-up default enables auto eject" (Not set; Not tested)
#define DFLAGS_WD_MODE (1 << 14) // Device is WD, not SFF (Not set; Not tested)
#define DFLAGS_USE_UDMA (1 << 16) // Device supports UDMA (Not set; Not tested)
#define DFLAGS_IDENTIFY_VALID (1 << 17) // Identify Data is valid (Not set; Not tested)
#define DFLAGS_DEVICE_BUSY (1 << 25) // Device is busy (Not set; Not tested)
#define DFLAGS_MEDIA_CHANGED (1 << 27) // Media has changed (Not set; Not tested)
#define DFLAGS_DEVICE_READY (1 << 28) // Device supports removable media and is ready (Not set; Not tested)
#define DFLAGS_DEVICE_ACTIVATED (1 << 29) // Device supports removable media and has volume(s) mounted (Not set; Not tested)
#ifdef FAKE_CRC_ERROR
#define DFLAGS_FAKING_CRC_ERROR (1 << 31) // Fake CRC error (Not set; Not tested)
#endif // FAKE_CRC_ERROR
// These flags are not set and not tested
#define ATA_VERSION_MASK (0xfffe)
#define ATA1_COMPLIANCE (1 << 1)
#define ATA2_COMPLIANCE (1 << 2)
#define ATA3_COMPLIANCE (1 << 3)
#define ATA4_COMPLIANCE (1 << 4)
// WaitForDisc wait condition codes; for more information on WaitForDisc
// (bStatusType), see atapiio.cpp.
// For more information on ATA/ATAPI device conditions, see ATA/ATAPI-6 R3B
// 7.14 (Status register).
#define WAIT_TYPE_BUSY 1
#define WAIT_TYPE_NOT_BUSY 2
#define WAIT_TYPE_READY 3
#define WAIT_TYPE_DRQ 4
#define WAIT_TYPE_NOT_DRQ 5
#define WAIT_TYPE_ERROR 6
// By default, this will use the CEDDK functions. To use macros instead,
// turn on CEDDK_USEDDKMACRO flag in the sources file.
// Base ATA/ATAPI device abstraction
// forward declaration
class CPort;
class CDisk {
public:
// Number of bytes between each ATA register; this is to facilitate PMC
// platforms (i.e., Intel PXA)
DWORD m_dwStride;
// ATA register offsets from start of device control I/O port
// Name | Ref | Notes
// -----------------|------|------
DWORD m_dwDataDrvCtrlOffset; // Data | 7.8 | 8 or 16 bits; PIO out <=> read, PIO in <=> write
DWORD m_dwFeatureErrorOffset; // Error | 7.11 | RO; ABRT bit, i.e., Command code/parameter is invalid
// Features | 7.12 | WO; Command parameter
DWORD m_dwSectCntReasonOffset; // Sector Count | 7.13 | Command parameter
DWORD m_dwSectNumOffset; // Sector Number | 7.14 | Command parameter
DWORD m_dwByteCountLowOffset; // Cylinder Low | 7.6 | Command parameter
DWORD m_dwByteCountHighOffset; // Cylinder High | 7.5 | Command parameter
DWORD m_dwDrvHeadOffset; // Device/Head | 7.10 | DEV bit selects device; 0 <=> master/device 0, 1 <=> slave/device 1
DWORD m_dwCommandStatusOffset; // Status | 7.15 | RO; Read clears pending interrupt; contains BSY, DRDY, and ERR bits
// Command | 7.4 | WO; Command code; execution begins immediately after write
// ATA register offsets from start of alternate status I/O port
DWORD m_dwAltStatusOffset; // Alternate Status | 7.3 | RO; Same as Status; Read does not clear pending interrupt
// Device Control | 7.9 | WO; SRST and nIEN bits; Both devices respond to write
DWORD m_dwAltDrvCtrl; // Same as m_dwAltStatusOffset
volatile PBYTE m_pATAReg; // Base address of device control register set (MmMapped)
volatile PBYTE m_pATARegAlt; // Base address of alternate status register set (MmMapped)
BOOL m_f16Bit; // Data register width; set to TRUE in CPCIDisk::Init, tested in Identify and ReadWritedisk
CPort *m_pPort; // I/O resources; including registry settings
BOOL m_fInterruptSupported; // Set based on registry
BOOL m_fDMAActive; // Set based on registry
DWORD m_dwDMAAlign; // Set based on registry
PBYTE m_rgbDoubleBuffer; // PIO mode double buffer; set based on registry
WORD m_wNextByte; // Store extra byte when reading/writing unaligned buffer
PSG_REQ m_pSterileIoRequest; // Sterile I/O request for safe I/O
CRITICAL_SECTION m_csDisk; // CDisk critical section
DWORD m_dwOpenCount; // DSK_Open count; number of system-wide references to this device
CDisk *m_pNextDisk; // Next CDisk in global (ATAPI.DLL) disk list
TCHAR m_szActiveKey[MAX_PATH]; // Name of DeviceX's active key
TCHAR m_szDeviceKey[MAX_PATH]; // Name of DeviceX's instance key
HKEY m_hDevKey; // Handle to DeviceX subkey
DWORD m_dwDevice; // Master <=> 0; Slave <=> 1
DWORD m_dwDeviceId; // Master <=> 0; Slave <=> 1
DWORD m_dwPort; // Not used; if device is on primary channel, 0; If device is on secondary channel, 1
IDENTIFY_DATA m_Id; // IDENTIFY DEVICE data
DWORD m_dwDeviceFlags; // Device attributes, see above
BOOL m_fLBAMode; // Device supports LBA or C/H/S
BOOL m_fUseLBA48; // Device supports extended 48 bit LBA from the revised ATA6 spec (disks > 128 GB)
BOOL m_fAtapiDevice; // Device is ATA or ATAPI
BYTE m_bReadCommand; // Read command to use (single-sector or multi-sector)
BYTE m_bWriteCommand; // Write command to use (single-sector or multi-sector)
BYTE m_bDMAReadCommand; // DMA Read command to use
BYTE m_bDMAWriteCommand;// DMA Write command to use
DISK_INFO m_DiskInfo; // DISK_INFO (disk geometry) Storage Manager structure
PTSTR m_szDiskName;
DWORD m_dwWaitCheckIter; // Timeout
DWORD m_dwWaitSampleTimes; // Timeout
DWORD m_dwWaitStallTime; // Timeout
DWORD m_dwDiskIoTimeOut; // Timeout
DWORD m_dwUnitReadyTime; // Time between TEST_UNIT_READY commands
DWORD m_dwLastCheckTime; // Not used; time of last TEST_UNIT_READY command
CDiskPower *m_pDiskPower;
HANDLE m_hDevice; // Handle to this store
DWORD dwPktSize; // Not used; command packet size (12 or 16 bytes)
DWORD m_dwStateFlag; // Not used
INQUIRY_DATA m_InqData; // Not used
BYTE m_bSectorsPerBlock; // This was used at some point in time, but is no longer used (Set in Identify)
STORAGEDEVICEINFO m_storagedeviceinfo; // This structure holds information to be returned for IOCTL_DISK_DEVICE_INFO
PHYSICAL_ADDRESS m_DMAPhyaddress;
PBYTE m_pDMAVirtualAddress;
DWORD m_dwCurrentUDMAMode;
public:
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
CDisk(); // Not used
CDisk(HKEY hKey); // Handle to device's DeviceX instance key
virtual ~CDisk();
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// Read/write Data register
void ReadBuffer(PBYTE pBuffer, DWORD dwCount);
void WriteBuffer(PBYTE pBuffer, DWORD dwCount);
BOOL WaitForDeviceAccessReady(void);
inline void WriteDriveController(BYTE bData) {
ATA_WRITE_BYTE(m_pATAReg + m_dwDataDrvCtrlOffset, bData);
}
inline WORD ReadByte() {
return ATA_READ_BYTE(m_pATAReg+m_dwDataDrvCtrlOffset);
}
inline WORD ReadWord() {
return ATA_READ_WORD((PWORD)(m_pATAReg+m_dwDataDrvCtrlOffset));
}
/* // These macro has to change to our CF controller style.
inline void ReadByteBuffer(PBYTE pBuffer, DWORD dwCount) {
volatile BYTE * const Port = (volatile BYTE * const)(m_pATAReg+m_dwDataDrvCtrlOffset);
if (m_pPort->m_pController->m_bisIOMapped)
READ_PORT_BUFFER_UCHAR((PBYTE)Port, pBuffer, dwCount);
else {
while( dwCount-- )
*pBuffer++ = *Port;
}
}
inline void ReadWordBuffer(PWORD pBuffer, DWORD dwCount) {
volatile USHORT * const Port = (volatile USHORT * const)(m_pATAReg+m_dwDataDrvCtrlOffset);
if (m_pPort->m_pController->m_bisIOMapped)
READ_PORT_BUFFER_USHORT((PUSHORT)Port, pBuffer, dwCount);
else {
while( dwCount-- )
*pBuffer++ = *Port;
}
}
*/
inline void WriteByte(BYTE bData) {
ATA_WRITE_BYTE(m_pATAReg + m_dwDataDrvCtrlOffset, bData);
}
inline void WriteWord(WORD wData) {
ATA_WRITE_WORD((PWORD)(m_pATAReg + m_dwDataDrvCtrlOffset), wData);
}
inline UINT32 ReadReg(UINT32 dwOffset)
{
volatile UINT32 uRegister = *(volatile UINT32 *)(m_pATAReg + dwOffset);
return uRegister;
}
inline VOID WriteReg(UINT32 dwOffset, UINT32 uValue)
{
volatile UINT32 *puRegister = (volatile UINT32 *)(m_pATAReg + dwOffset);
*puRegister = uValue;
}
/* // These macro has to change to our CF controller style.
inline void WriteByteBuffer(PBYTE pBuffer, DWORD dwCount) {
volatile BYTE * const Port = (volatile BYTE * const)(m_pATAReg+m_dwDataDrvCtrlOffset);
if (m_pPort->m_pController->m_bisIOMapped)
WRITE_PORT_BUFFER_UCHAR((PBYTE)Port, pBuffer, dwCount);
else {
while( dwCount-- )
*Port = *pBuffer++;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -