idedata.h

来自「EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是」· C头文件 代码 · 共 903 行 · 第 1/2 页

H
903
字号
/*++
Copyright (c) 2004 - 2006, Intel Corporation                                                         
All rights reserved. This program and the accompanying materials                          
are licensed and made available under the terms and conditions of the BSD License         
which accompanies this distribution.  The full text of the license may be found at        
http://opensource.org/licenses/bsd-license.php                                            
                                                                                          
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             

Module Name:

    idedata.h

Abstract:

    Header file for IDE Bus Driver's Data Structures

Revision History
++*/

// TODO: fix comment to end with --*/
#ifndef _IDE_DATA_H
#define _IDE_DATA_H

#include EFI_PROTOCOL_DEFINITION (IdeControllerInit)
//
// bit definition
//
#define bit0  (1 << 0)
#define bit1  (1 << 1)
#define bit2  (1 << 2)
#define bit3  (1 << 3)
#define bit4  (1 << 4)
#define bit5  (1 << 5)
#define bit6  (1 << 6)
#define bit7  (1 << 7)
#define bit8  (1 << 8)
#define bit9  (1 << 9)
#define bit10 (1 << 10)
#define bit11 (1 << 11)
#define bit12 (1 << 12)
#define bit13 (1 << 13)
#define bit14 (1 << 14)
#define bit15 (1 << 15)
#define bit16 (1 << 16)
#define bit17 (1 << 17)
#define bit18 (1 << 18)
#define bit19 (1 << 19)
#define bit20 (1 << 20)
#define bit21 (1 << 21)
#define bit22 (1 << 22)
#define bit23 (1 << 23)
#define bit24 (1 << 24)
#define bit25 (1 << 25)
#define bit26 (1 << 26)
#define bit27 (1 << 27)
#define bit28 (1 << 28)
#define bit29 (1 << 29)
#define bit30 (1 << 30)
#define bit31 (1 << 31)

//
// common constants
//
#define STALL_1_MILLI_SECOND  1000    // stall 1 ms
#define STALL_1_SECOND        1000000 // stall 1 second
typedef enum {
  IdePrimary    = 0,
  IdeSecondary  = 1,
  IdeMaxChannel = 2
} EFI_IDE_CHANNEL;

typedef enum {
  IdeMaster     = 0,
  IdeSlave      = 1,
  IdeMaxDevice  = 2
} EFI_IDE_DEVICE;

typedef enum {
  IdeMagnetic,                        /* ZIP Drive or LS120 Floppy Drive */
  IdeCdRom,                           /* ATAPI CDROM */
  IdeHardDisk,                        /* Hard Disk */
  Ide48bitAddressingHardDisk,         /* Hard Disk larger than 120GB */
  IdeUnknown
} IDE_DEVICE_TYPE;

typedef enum {
  SenseNoSenseKey,
  SenseDeviceNotReadyNoRetry,
  SenseDeviceNotReadyNeedRetry,
  SenseNoMedia,
  SenseMediaChange,
  SenseMediaError,
  SenseOtherSense
} SENSE_RESULT;

typedef enum {
  AtaUdmaReadOp,
  AtaUdmaReadExtOp,
  AtaUdmaWriteOp,
  AtaUdmaWriteExtOp
} ATA_UDMA_OPERATION;

//
// IDE Registers
//
typedef union {
  UINT16  Command;        /* when write */
  UINT16  Status;         /* when read */
} IDE_CMD_OR_STATUS;

typedef union {
  UINT16  Error;          /* when read */
  UINT16  Feature;        /* when write */
} IDE_ERROR_OR_FEATURE;

typedef union {
  UINT16  AltStatus;      /* when read */
  UINT16  DeviceControl;  /* when write */
} IDE_AltStatus_OR_DeviceControl;

//
// IDE registers set
//
typedef struct {
  UINT16                          Data;
  IDE_ERROR_OR_FEATURE            Reg1;
  UINT16                          SectorCount;
  UINT16                          SectorNumber;
  UINT16                          CylinderLsb;
  UINT16                          CylinderMsb;
  UINT16                          Head;
  IDE_CMD_OR_STATUS               Reg;

  IDE_AltStatus_OR_DeviceControl  Alt;
  UINT16                          DriveAddress;

  UINT16                          MasterSlave;
  UINT16                          BusMasterBaseAddr;
} IDE_BASE_REGISTERS;

//
// IDE registers' base addresses
//
typedef struct {
  UINT16  CommandBlockBaseAddr;
  UINT16  ControlBlockBaseAddr;
  UINT16  BusMasterBaseAddr;
} IDE_REGISTERS_BASE_ADDR;

//
// Bit definitions in Programming Interface byte of the Class Code field
// in PCI IDE controller's Configuration Space
//
#define IDE_PRIMARY_OPERATING_MODE            bit0
#define IDE_PRIMARY_PROGRAMMABLE_INDICATOR    bit1
#define IDE_SECONDARY_OPERATING_MODE          bit2
#define IDE_SECONDARY_PROGRAMMABLE_INDICATOR  bit3

//
// IDE registers bit definitions
//

//
// Err Reg
//
#define BBK_ERR   bit7  /* Bad block detected */
#define UNC_ERR   bit6  /* Uncorrectable Data */
#define MC_ERR    bit5  /* Media Change */
#define IDNF_ERR  bit4  /* ID Not Found */
#define MCR_ERR   bit3  /* Media Change Requested */
#define ABRT_ERR  bit2  /* Aborted Command */
#define TK0NF_ERR bit1  /* Track 0 Not Found */
#define AMNF_ERR  bit0  /* Address Mark Not Found */

//
// Device/Head Reg
//
#define LBA_MODE  bit6
#define DEV       bit4
#define HS3       bit3
#define HS2       bit2
#define HS1       bit1
#define HS0       bit0
#define CHS_MODE  (0)
#define DRV0      (0)
#define DRV1      (1)
#define MST_DRV   DRV0
#define SLV_DRV   DRV1

//
// Status Reg
//
#define BSY   bit7  /* Controller Busy */
#define DRDY  bit6  /* Drive Ready */
#define DWF   bit5  /* Drive Write Fault */
#define DSC   bit4  /* Disk Seek Complete */
#define DRQ   bit3  /* Data Request */
#define CORR  bit2  /* Corrected Data */
#define IDX   bit1  /* Index */
#define ERR   bit0  /* Error */

//
// Device Control Reg
//
#define SRST  bit2  /* Software Reset */
#define IEN_L bit1  /* Interrupt Enable #*/

//
// Bus Master Reg
//
#define BMIC_nREAD      bit3
#define BMIC_START      bit0
#define BMIS_INTERRUPT  bit2
#define BMIS_ERROR      bit1

#define BMICP_OFFSET    0x00
#define BMISP_OFFSET    0x02
#define BMIDP_OFFSET    0x04
#define BMICS_OFFSET    0x08
#define BMISS_OFFSET    0x0A
#define BMIDS_OFFSET    0x0C

//
// Time Out Value For IDE Device Polling
//

//
// ATATIMEOUT is used for waiting time out for ATA device
//

//
// 1 second
//
#define ATATIMEOUT  1000  

//
// ATAPITIMEOUT is used for waiting operation
// except read and write time out for ATAPI device
//

//
// 1 second
//
#define ATAPITIMEOUT  1000 

//
// ATAPILONGTIMEOUT is used for waiting read and
// write operation timeout for ATAPI device
//

//
// 2 seconds
//
#define CDROMLONGTIMEOUT  2000  

//
// 5 seconds
//
#define ATAPILONGTIMEOUT  5000  

//
// 10 seconds
//
#define ATASMARTTIMEOUT   10000

//
// ATA Commands Code
//
#define ATA_INITIALIZE_DEVICE 0x91

//
// Class 1
//
#define IDENTIFY_DRIVE_CMD          0xec
#define READ_BUFFER_CMD             0xe4
#define READ_SECTORS_CMD            0x20
#define READ_SECTORS_WITH_RETRY_CMD 0x21
#define READ_LONG_CMD               0x22
#define READ_LONG_WITH_RETRY_CMD    0x23
//
// Class 1 - Atapi6 enhanced commands
//
#define READ_SECTORS_EXT_CMD  0x24

//
// Class 2
//
#define FORMAT_TRACK_CMD              0x50
#define WRITE_BUFFER_CMD              0xe8
#define WRITE_SECTORS_CMD             0x30
#define WRITE_SECTORS_WITH_RETRY_CMD  0x31
#define WRITE_LONG_CMD                0x32
#define WRITE_LONG_WITH_RETRY_CMD     0x33
#define WRITE_VERIFY_CMD              0x3c
//
// Class 2 - Atapi6 enhanced commands
//
#define WRITE_SECTORS_EXT_CMD 0x34

//
// Class 3
//
#define ACK_MEDIA_CHANGE_CMD        0xdb
#define BOOT_POST_BOOT_CMD          0xdc
#define BOOT_PRE_BOOT_CMD           0xdd
#define CHECK_POWER_MODE_CMD        0x98
#define CHECK_POWER_MODE_CMD_ALIAS  0xe5
#define DOOR_LOCK_CMD               0xde
#define DOOR_UNLOCK_CMD             0xdf
#define EXEC_DRIVE_DIAG_CMD         0x90
#define IDLE_CMD_ALIAS              0x97
#define IDLE_CMD                    0xe3
#define IDLE_IMMEDIATE_CMD          0x95
#define IDLE_IMMEDIATE_CMD_ALIAS    0xe1
#define INIT_DRIVE_PARAM_CMD        0x91
#define RECALIBRATE_CMD             0x10  /* aliased to 1x */
#define READ_DRIVE_STATE_CMD        0xe9
#define SET_MULTIPLE_MODE_CMD       0xC6
#define READ_DRIVE_STATE_CMD        0xe9
#define READ_VERIFY_CMD             0x40
#define READ_VERIFY_WITH_RETRY_CMD  0x41
#define SEEK_CMD                    0x70  /* aliased to 7x */
#define SET_FEATURES_CMD            0xef
#define STANDBY_CMD                 0x96
#define STANDBY_CMD_ALIAS           0xe2
#define STANDBY_IMMEDIATE_CMD       0x94
#define STANDBY_IMMEDIATE_CMD_ALIAS 0xe0

//
// Class 4
//
#define READ_DMA_CMD              0xc8
#define READ_DMA_WITH_RETRY_CMD   0xc9
#define READ_DMA_EXT_CMD          0x25
#define WRITE_DMA_CMD             0xca
#define WRITE_DMA_WITH_RETRY_CMD  0xcb
#define WRITE_DMA_EXT_CMD         0x35

//
// Class 5
//
#define READ_MULTIPLE_CMD         0xc4
#define REST_CMD                  0xe7
#define RESTORE_DRIVE_STATE_CMD   0xea
#define SET_SLEEP_MODE_CMD        0x99
#define SET_SLEEP_MODE_CMD_ALIAS  0xe6
#define WRITE_MULTIPLE_CMD        0xc5
#define WRITE_SAME_CMD            0xe9

//
// Class 6 - Host protected area access feature set
//
#define READ_NATIVE_MAX_ADDRESS_CMD 0xf8
#define SET_MAX_ADDRESS_CMD         0xf9

//
// Class 6 - ATA/ATAPI-6 enhanced commands
//
#define READ_NATIVE_MAX_ADDRESS_EXT_CMD 0x27
#define SET_MAX_ADDRESS_CMD_EXT         0x37

//
// Class 6 - SET_MAX related sub command (in feature register)
//
#define PARTIES_SET_MAX_ADDRESS_SUB_CMD 0x00
#define PARTIES_SET_PASSWORD_SUB_CMD    0x01
#define PARTIES_LOCK_SUB_CMD            0x02
#define PARTIES_UNLOCK_SUB_CMD          0x03
#define PARTIES_FREEZE_SUB_CMD          0x04

//
// S.M.A.R.T
//
#define ATA_SMART_CMD               0xb0
#define ATA_CONSTANT_C2             0xc2
#define ATA_CONSTANT_4F             0x4f
#define ATA_SMART_ENABLE_OPERATION  0xd8
#define ATA_SMART_RETURN_STATUS     0xda

//
// Error codes for Exec Drive Diag
//
#define DRIV_DIAG_NO_ERROR          (0x01)
#define DRIV_DIAG_FORMATTER_ERROR   (0x02)
#define DRIV_DIAG_DATA_BUFFER_ERROR (0x03)
#define DRIV_DIAG_ECC_CKT_ERRROR    (0x04)
#define DRIV_DIAG_UP_ERROR          (0x05)
#define DRIV_DIAG_SLAVE_DRV_ERROR   (0x80)  /* aliased to 0x8x */

//
// Codes for Format Track
//
#define FORMAT_GOOD_SECTOR            (0x00)
#define FORMAT_SUSPEND_ALLOC          (0x01)
#define FORMAT_REALLOC_SECTOR         (0x02)
#define FORMAT_MARK_SECTOR_DEFECTIVE  (0x03)

//
// IDE_IDENTIFY bits
// config bits :
//
#define ID_CONFIG_RESERVED0                             bit0
#define ID_CONFIG_HARD_SECTORED_DRIVE                   bit1
#define ID_CONFIG_SOFT_SECTORED_DRIVE                   bit2
#define ID_CONFIG_NON_MFM                               bit3
#define ID_CONFIG_15uS_HEAD_SWITCHING                   bit4
#define ID_CONFIG_SPINDLE_MOTOR_CONTROL                 bit5
#define ID_CONFIG_HARD_DRIVE                            bit6
#define ID_CONFIG_CHANGEABLE_MEDIUM                     bit7
#define ID_CONFIG_DATA_RATE_TO_5MHZ                     bit8
#define ID_CONFIG_DATA_RATE_5_TO_10MHZ                  bit9
#define ID_CONFIG_DATA_RATE_ABOVE_10MHZ                 bit10
#define ID_CONFIG_MOTOR_SPEED_TOLERANCE_ABOVE_0_5_PERC  bit11
#define ID_CONFIG_DATA_CLK_OFFSET_AVAIL                 bit12
#define ID_CONFIG_TRACK_OFFSET_AVAIL                    bit13
#define ID_CONFIG_SPEED_TOLERANCE_GAP_NECESSARY         bit14
#define ID_CONFIG_RESERVED1                             bit15

#define ID_DOUBLE_WORD_IO_POSSIBLE                      bit01
#define ID_LBA_SUPPORTED                                bit9
#define ID_DMA_SUPPORTED                                bit8

#define SET_FEATURE_ENABLE_8BIT_TRANSFER                (0x01)
#define SET_FEATURE_ENABLE_WRITE_CACHE                  (0x02)
#define SET_FEATURE_TRANSFER_MODE                       (0x03)
#define SET_FEATURE_WRITE_SAME_WRITE_SPECIFIC_AREA      (0x22)
#define SET_FEATURE_DISABLE_RETRIES                     (0x33)
//
// for Read & Write Longs
//
#define SET_FEATURE_VENDOR_SPEC_ECC_LENGTH                          (0x44)
#define SET_FEATURE_PLACE_NO_OF_CACHE_SEGMENTS_IN_SECTOR_NO_REG     (0x54)
#define SET_FEATURE_DISABLE_READ_AHEAD                              (0x55)
#define SET_FEATURE_MAINTAIN_PARAM_AFTER_RESET                      (0x66)
#define SET_FEATURE_DISABLE_ECC                                     (0x77)
#define SET_FEATURE_DISABLE_8BIT_TRANSFER                           (0x81)
#define SET_FEATURE_DISABLE_WRITE_CACHE                             (0x82)
#define SET_FEATURE_ENABLE_ECC                                      (0x88)
#define SET_FEATURE_ENABLE_RETRIES                                  (0x99)
#define SET_FEATURE_ENABLE_READ_AHEAD                               (0xaa)
#define SET_FEATURE_SET_SECTOR_CNT_REG_AS_NO_OF_READ_AHEAD_SECTORS  (0xab)
#define SET_FEATURE_ALLOW_REST_MODE                                 (0xac)
//
// for Read & Write Longs
//
#define SET_FEATURE_4BYTE_ECC                           (0xbb)
#define SET_FEATURE_DEFALUT_FEATURES_ON_SOFTWARE_RESET  (0xcc)
#define SET_FEATURE_WRITE_SAME_TO_WRITE_ENTIRE_MEDIUM   (0xdd)

#define BLOCK_TRANSFER_MODE                             (0x00)

⌨️ 快捷键说明

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