00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef IDELOW_H
00018 #define IDELOW_H
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #define HDC_BASEPRI 0x1F0 //Base port for primary channel register
00041 #define HDC_BASESEC 0x170 //Base port for secondary channel register
00042 #define HDC_CONTROLGAP 0x200 //Bas+Gap=Control register address (3F0 and 370)
00043
00044
00045 #define HDC_INTPRI 14 //Int num for primary channel's device
00046 #define HDC_INTSEC 15 //Int num for secondary channel's device
00047
00048
00049
00050
00051
00052
00053 #define HDC_DATA 0 // r/w Data Register
00054 #define HDC_ERR 1 // r Error Register w Feaure Register
00055 #define HDC_SECC 2 // r/w Sector Count, how many sectors to read/write
00056 #define HDC_SECN 3 // r/w Sector number, the actual sector wanted
00057 #define HDC_CYLL 4 // r/w Cylinder low, cylinders is 0-1024
00058 #define HDC_CYLH 5 // r/w Cylinder high, this makes up the rest of the 1024
00059 #define HDC_DEVH 6 // r/w Device/Head
00060 #define HDC_STATUS 7 // r Primary Status Register w Command Register
00061
00062
00063
00064 #define HDC_ASTAT 6 // r Alternate Status Register w Device control register
00065
00066
00067 #define HDC_ADD 7 // Device Address
00068
00069
00070
00071
00072
00073 #define HDC_DEVH_OBSOLETE 0xa0
00074
00075 #define HDC_DEVH_DEV0 HDC_DEVH_OBSOLETE | 0x00 // Device Head 10100000
00076 #define HDC_DEVH_DEV1 HDC_DEVH_OBSOLETE | 0x10 // Device Head 10110000
00077 #define HDC_DEVH_LBA 0x40 // Lba Mode 01000000
00078
00079
00080
00081
00082 #define HDC_DEVC_HD15 0x08 // Bit 4 = 1 This is needed only for older ATA standard
00083 #define HDC_DEVC_SRST 0x04 // Bit 2 : Soft Reset
00084 #define HDC_DEVC_NIEN 0x02 // Bit 1 : Enable=1 Disable=0 interrupts
00085
00086
00087
00088
00089
00090
00091 #define HDC_STAT_BSY 0x80 // busy
00092 #define HDC_STAT_RDY 0x40 // ready
00093 #define HDC_STAT_DF 0x20 // device fault
00094 #define HDC_STAT_WFT 0x20 // write fault (old name)
00095 #define HDC_STAT_SKC 0x10 // seek complete
00096 #define HDC_STAT_SERV 0x10 // service
00097 #define HDC_STAT_DRQ 0x08 // data request
00098 #define HDC_STAT_CORR 0x04 // corrected
00099 #define HDC_STAT_IDX 0x02 // index
00100 #define HDC_STAT_ERR 0x01 // error (ATA)
00101 #define HDC_STAT_CHK 0x01 // check (ATAPI)
00102
00103
00104
00105
00106
00107 #define HDC_CMD_CFA_ERASE_SECTORS 0xC0
00108 #define HDC_CMD_CFA_REQUEST_EXT_ERR_CODE 0x03
00109 #define HDC_CMD_CFA_TRANSLATE_SECTOR 0x87
00110 #define HDC_CMD_CFA_WRITE_MULTIPLE_WO_ERASE 0xCD
00111 #define HDC_CMD_CFA_WRITE_SECTORS_WO_ERASE 0x38
00112 #define HDC_CMD_CHECK_POWER_MODE1 0xE5
00113 #define HDC_CMD_CHECK_POWER_MODE2 0x98
00114 #define HDC_CMD_DEVICE_RESET 0x08
00115 #define HDC_CMD_EXECUTE_DEVICE_DIAGNOSTIC 0x90
00116 #define HDC_CMD_FLUSH_CACHE 0xE7
00117 #define HDC_CMD_FORMAT_TRACK 0x50
00118 #define HDC_CMD_IDENTIFY_DEVICE 0xEC
00119 #define HDC_CMD_IDENTIFY_PACKET_DEVICE 0xA1
00120 #define HDC_CMD_IDLE1 0xE3
00121 #define HDC_CMD_IDLE2 0x97
00122 #define HDC_CMD_IDLE_IMMEDIATE1 0xE1
00123 #define HDC_CMD_IDLE_IMMEDIATE2 0x95
00124 #define HDC_CMD_INITIALIZE_DRIVE_PARAMETERS 0x91
00125 #define HDC_CMD_INITIALIZE_DEVICE_PARAMETERS 0x91
00126 #define HDC_CMD_NOP 0x00
00127 #define HDC_CMD_PACKET 0xA0
00128 #define HDC_CMD_READ_BUFFER 0xE4
00129 #define HDC_CMD_READ_DMA 0xC8
00130 #define HDC_CMD_READ_DMA_QUEUED 0xC7
00131 #define HDC_CMD_READ_MULTIPLE 0xC4
00132 #define HDC_CMD_READ_SECTORS 0x20
00133 #define HDC_CMD_READ_VERIFY_SECTORS 0x40
00134 #define HDC_CMD_RECALIBRATE 0x10
00135 #define HDC_CMD_SEEK 0x70
00136 #define HDC_CMD_SET_FEATURES 0xEF
00137 #define HDC_CMD_SET_MULTIPLE_MODE 0xC6
00138 #define HDC_CMD_SLEEP1 0xE6
00139 #define HDC_CMD_SLEEP2 0x99
00140 #define HDC_CMD_STANDBY1 0xE2
00141 #define HDC_CMD_STANDBY2 0x96
00142 #define HDC_CMD_STANDBY_IMMEDIATE1 0xE0
00143 #define HDC_CMD_STANDBY_IMMEDIATE2 0x94
00144 #define HDC_CMD_WRITE_BUFFER 0xE8
00145 #define HDC_CMD_WRITE_DMA 0xCA
00146 #define HDC_CMD_WRITE_DMA_QUEUED 0xCC
00147 #define HDC_CMD_WRITE_MULTIPLE 0xC5
00148 #define HDC_CMD_WRITE_SECTORS 0x30
00149 #define HDC_CMD_WRITE_VERIFY 0x3C
00150
00151
00152
00153 typedef struct DeviceInfo_Struct
00154 {
00155 byte Ata;
00156 byte Removable;
00157 byte NotRemovable;
00158 word LogicalCylinders;
00159 word LogicalHeads;
00160 word LogicalSectorsPerTrack;
00161 char SerialNumber[21];
00162 char FirmwareRev[9];
00163 char ModelNumber[41];
00164 byte MaxMulitSectPerBlock;
00165 byte StandByTimerSupport;
00166 byte IORDYSupport;
00167 byte IORDYDisabled;
00168 byte PioMode;
00169 byte ValidUDMAMode;
00170 byte ValidCycleTime;
00171 byte ValidCurLogicalValue;
00172
00173 word CurLogicalCylinders;
00174 word CurLogicalHeads;
00175 word CurLogicalSectorsPerTrack;
00176 dword CapacityInSectors;
00177 byte ValidCurMultiSectPerInt;
00178 byte CurMultiSectPerInt;
00179 dword CapacityLba;
00180
00181
00182 byte MultiDMASelected;
00183 byte MultiDMASupported;
00184
00185 byte AdvPioModeSupported;
00186 word MinCycleTime;
00187 word RecCycleTime;
00188 word MinPioCycleTime;
00189 word MinPioCyleTimeFlow;
00190 byte QueueDepth;
00191
00192 word AtaSupported;
00193
00194 byte HighestAtaSupported;
00195
00196 word MinorVersion;
00197
00198 byte SFSNopSupported;
00199 byte SFSReadBufferSupported;
00200 byte SFSWriteBufferSupported;
00201 byte SFSProtectedAreaSupported;
00202 byte SFSDeviceResetSupported;
00203 byte SFSServiceIntSupported;
00204 byte SFSReleaseIntSupported;
00205 byte SFSLookAheadSupported;
00206 byte SFSWriteCacheSupported;
00207 byte SFSPacketSupported;
00208 byte SFSPowerManagSupported;
00209 byte SFSRemovableMediaSupported;
00210 byte SFSSecurityModeSupported;
00211 byte SFSSmartSupported;
00212
00213 byte SFSRemMediaNotifSupported;
00214 byte SFSAdvPowerManagSupported;
00215 byte SFSCFASupported;
00216 byte SFSRWDmaQueuedSupported;
00217 byte SFSDownMicrocodeSupported;
00218
00219 byte SFEServiceIntEnalbed;
00220 byte SFEReleaseIntEnabled;
00221 byte SFELookAheadEnabled;
00222 byte SFEWriteCacheEnabled;
00223 byte SFESecurityModeEnabled;
00224 byte SFESmartEnabled;
00225
00226 byte SFERemMediaNotifEnabled;
00227 byte SFEAdvPowerManagEnabled;
00228
00229
00230 byte UDMASelected;
00231 byte UDMASupported;
00232
00233 byte HighestUDMASupported;
00234
00235 word SecurityEraseTime;
00236 word SecurityEnEraseTime;
00237 word CurAPMValue;
00238
00239 byte SecurityLevel;
00240 byte SecurityEnErase;
00241 byte SecurityCountExpired;
00242 byte SecurityFrozen;
00243 byte SecurityLocked;
00244 byte SecurityEnabled;
00245 byte SecuritySupported;
00246
00247 word VendorSpecific[31];
00248
00249
00250 } DeviceInfo_Struct;
00251
00252
00253 typedef struct Device_Struct
00254 {
00255 byte RegBit;
00256 DeviceInfo_Struct Info;
00257 int Type;
00258 } Device_Struct;
00259
00260
00261 typedef struct IdeChannel_Struct
00262 {
00263 int IntDone;
00264 word CmdBasePort;
00265 word CntBasePort;
00266 word IoPort[10];
00267 Device_Struct Device[2];
00268 int IntNum;
00269 } IdeChannel_Struct;
00270
00271
00272
00273 void SetAtaRegisterIoPort(word CmdBase, word CntBase, int IntN) ;
00274 void SelectAtaChannel (int Channel);
00275 word AtaPort(word Port);
00276 void OutPortAta(word Port, byte Val);
00277 byte InPortAta(word Port);
00278 void InPortAtaMul(word Port, word * Buffer,word Count);
00279 void OutPortAtaMul(word Port, word * Buffer, word Count);
00280 void SetDevBit(int Dev);
00281 void SetFirstDevBit();
00282 void Ide_Handler(word Irq);
00283
00284
00285
00286 #endif