⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 diskmain.h

📁 WinCE5.0BSP for Renesas SH7770
💻 H
📖 第 1 页 / 共 2 页
字号:
//
//  Copyright(C) Renesas Technology Corp. 2005. All rights reserved.
//
// ATAPI(UDFS) driver for ITS-DS7
//
// FILE     : atamain.cpp
// CREATED  : 2005.02.10
// MODIFIED : 
// AUTHOR   : Renesas Technology Corp.
// HARDWARE : RENESAS ITS-DS7
// HISTORY  : 
//            2005.02.10
//            - Created release code.
//                (based on PUBLIC ATAPI driver for WCE5.0)

//
// 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:
    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>

// 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 CSHXDisk::ConfigPort and CSHXDisk::InitController; Tested in CSHXDisk::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

// Base ATA/ATAPI device abstraction
#define ATAPI_CTRL_OFFSET       0x0080
#define ATAPI_STAT_OFFSET       0x0084
#define ATAPI_IRRN_OFFSET       0x0088
#define ATAPI_PIOT_OFFSET       0x008c
#define ATAPI_MDMA_OFFSET       0x0090
#define ATAPI_UDMA_OFFSET       0x0094
#define ATAPI_DMAS_OFFSET       0x009c
#define ATAPI_DMAC_OFFSET       0x00a0
#define ATAPI_CTL2_OFFSET       0x00a4
#define ATAPI_SIST_OFFSET       0x00b0
#define ATAPI_BSWP_OFFSET       0x00bc

// 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 CSHXDisk::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

    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_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)

    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)

	BYTE m_dwBestPioMode;
	BYTE m_dwBestDmaMode;
	BYTE m_dwBestUdmaMode;

	BYTE m_dwPioMode;
	BYTE m_dwDmaMode;
	BYTE m_dwUdmaMode;

	BYTE  m_bTransferMode;
	BYTE  m_bDefaultTransferMode;
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);

    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));
    }
    inline void ReadByteBuffer(PBYTE pBuffer, DWORD dwCount) {
        READ_PORT_BUFFER_UCHAR(m_pATAReg + m_dwDataDrvCtrlOffset, pBuffer, dwCount);
    }
    inline void ReadWordBuffer(PWORD pBuffer, DWORD dwCount) {
        READ_PORT_BUFFER_USHORT((PWORD)(m_pATAReg + m_dwDataDrvCtrlOffset), pBuffer, dwCount);
    }
    inline void WriteByte(BYTE bData) {
        ATA_WRITE_BYTE(m_pATAReg + m_dwDataDrvCtrlOffset, bData);
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -