Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

IdeLow.h

Go to the documentation of this file.
00001 /*!     \file include/kernel/IdeLow.h
00002  *      \brief IDE driver::Low level routines header.
00003  *      \author Luca Giovacchini
00004  *      \date Last update: 2003-11-07
00005  *      \note Copyright (©) 2003 Luca Giovacchini
00006  *
00007  *      <b>IMPORTANT!!!</b>\n
00008  *      Here you can find the base sub for communicating with
00009  *      Ide Devices.
00010  *      First subs expose a simpler interface to the
00011  *      rest of the driver, creating a simpler logical view of
00012  *      registers and most important data.
00013  *      You must not issue commands to device only with these subs,
00014  *      but you must use IdeAta subs (Ata protocol).
00015  */
00016 
00017 #ifndef IDELOW_H
00018 #define IDELOW_H
00019 
00020 // primary host adapter at I/O address 1FX/3FX 
00021 // secondary host adapter at I/O adress 17X/37X
00022 // Each host adapter can have up to two hard drives MASTER/SLAVED off it.
00023 // 1FX  0001 1111 XXXX  Primary Command Registers
00024 // 3FX  0011 1111 XXXX  Primary Control Registers
00025 
00026 // 17X  0001 0111 XXXX  Alternate Command Registers
00027 // 37X  0011 0111 XXXX  Alternate Control Registers
00028 
00029 // I/O Ports //
00030 // 1FX and 17X use same command so we'll use they as a base port + command offset
00031 
00032 // For a very complete documentation of these ports and all commands you
00033 // must read T13 Documentation for ATA 1-2-3-4 etc. etc.,(for example you
00034 // can read (www.T13.org) d1153r18.pdf (330pag. all on ATA-4)
00035 
00036 //**********************************************
00037 // COMMAND REGISTER BASE IO PORT
00038 //**********************************************
00039 // Base port for controller registers
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 // IMPORTANT: HDC_ADDRESS PORT IN THE PRIMARY CHANNEL = 0x3F0+7=0x3F7 IS SHARED WITH FLOPPY (PAY ATTENTION)
00044 // Interrupt number
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 // REGISTERS OFFSET PORT
00050 //**********************************************
00051 
00052 // COMMAND REGISTER OFFSET PORT
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 // CONTROL REGISTER OFFSET PORT
00062 // alternate is like status but reading status register clear pending interrupts while 
00063 // reading alternate do not clear pending interrupt
00064 #define HDC_ASTAT      6     // r    Alternate Status Register     w  Device control register
00065 // i haven't found information about next register, the only thing is:
00066 // returns the drive select and head select addresses for the drive currently selected
00067 #define HDC_ADD        7     // Device Address 
00068 
00069 //**********************************************
00070 // DEVICE HEAD REGISTER BIT
00071 //**********************************************
00072 // Bit 7 and 5 = 1 This is needed only for ATA 1 standard
00073 #define HDC_DEVH_OBSOLETE 0xa0 
00074 // Bit 4 is for selecting the device
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 // DEVICE CONTROL REGISTER BIT  (WRITE) 
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 // STATUS AND ALTERNATE REGISTER SIGNAL (READ)
00089 //**********************************************
00090 // Primary And Alternate Register Bit and Command
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 // COMMAND CODE
00105 // Most mandtory and optional ATA commands (from ATA-3),
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 // We use it for store data returned by Identify Device command
00153 typedef struct DeviceInfo_Struct
00154 {
00155         byte Ata;                                               // Word  0 bit 15 bit coded bit 0 = ata 1 bit 1 = ata 2 ...
00156         byte Removable;                                 // Word  0 bit 7 bool
00157         byte NotRemovable;                              // Word  0 bit 6 bool
00158         word LogicalCylinders;                  // Word  1
00159         word LogicalHeads;                              // Word  3
00160         word LogicalSectorsPerTrack;    // Word  6
00161         char SerialNumber[21];                  // Word 10-19 ascii
00162         char FirmwareRev[9];                    // Word 23-26 ascii
00163         char ModelNumber[41];                   // Word 27-46 ascii
00164         byte MaxMulitSectPerBlock;              // Word 47 bit 7-0
00165         byte StandByTimerSupport;               // Word 49 bit 13
00166         byte IORDYSupport;                              // Word 49 bit 11
00167         byte IORDYDisabled;             // Word 49 bit 10
00168         byte PioMode;                                   // Word 51 bit 15-8  // only 0 1 2 value
00169         byte ValidUDMAMode;                             // Word 53 bit 2 bool if Udma info are valid
00170         byte ValidCycleTime;                    // Word 53 bit 1
00171         byte ValidCurLogicalValue;              // Word 53 bit 0
00172 
00173         word CurLogicalCylinders;               // Word 54
00174         word CurLogicalHeads;                   // Word 55
00175         word CurLogicalSectorsPerTrack; // Word 56
00176         dword CapacityInSectors;                // Word 57-58
00177         byte ValidCurMultiSectPerInt;   // Word 59 bit 8
00178         byte CurMultiSectPerInt;                // Word 59 bit 7-0
00179         dword CapacityLba;                              // Word 60-61
00180         // Word 63
00181         // Bit 10 9 8 and bit 2 1 0
00182         byte MultiDMASelected;                  // Word 63 bit coded bit 0 = udma 0 bit 1 = udma 1 ...
00183         byte MultiDMASupported;                 // Word 63 bit coded bit 0 = udma 0 bit 1 = udma 1 ...
00184 
00185         byte AdvPioModeSupported;       // Word 64 bit 7-0      // bit coded bit 0 = pio 3 bit 1 = pio 4 ....
00186         word MinCycleTime;                              // Word 65
00187         word RecCycleTime;                              // Word 66
00188         word MinPioCycleTime;                   // Word 67
00189         word MinPioCyleTimeFlow;                // Word 68
00190         byte QueueDepth;                // Word 75 bit:0-4
00191         // Word 80
00192         word AtaSupported;      // bit coded, bit 0 = reserved, bit 1 = ata1, bit 2 = ata2 ....
00193 
00194         byte HighestAtaSupported;  // This is not in DeviceInfo data but is calculated
00195         
00196         word MinorVersion;            // Word 81 only if != FFFF & != 0000
00197         // Word 82  Should not be 0000 or FFFF
00198         byte SFSNopSupported;                           // 14
00199         byte SFSReadBufferSupported;            // 13
00200         byte SFSWriteBufferSupported;           // 12
00201         byte SFSProtectedAreaSupported;         // 10
00202         byte SFSDeviceResetSupported;           //  9
00203         byte SFSServiceIntSupported;            //  8
00204         byte SFSReleaseIntSupported;            //  7
00205         byte SFSLookAheadSupported;                     //  6
00206         byte SFSWriteCacheSupported;            //  5
00207         byte SFSPacketSupported;                        //  4
00208         byte SFSPowerManagSupported;            //  3
00209         byte SFSRemovableMediaSupported;        //  2
00210         byte SFSSecurityModeSupported;          //  1
00211         byte SFSSmartSupported;                         //  0
00212         // Word 83
00213         byte SFSRemMediaNotifSupported;         //  4
00214         byte SFSAdvPowerManagSupported;         //  3
00215         byte SFSCFASupported;                           //  2
00216         byte SFSRWDmaQueuedSupported;           //  1
00217         byte SFSDownMicrocodeSupported;         //  0
00218         // Word 85
00219         byte SFEServiceIntEnalbed;                      //  8
00220         byte SFEReleaseIntEnabled;                      //  7
00221         byte SFELookAheadEnabled;                       //  6
00222         byte SFEWriteCacheEnabled;                      //  5
00223         byte SFESecurityModeEnabled;            //  1
00224         byte SFESmartEnabled;                           //  0
00225         // Word 86
00226         byte SFERemMediaNotifEnabled;           //  4
00227         byte SFEAdvPowerManagEnabled;           //  3
00228         // Word 88
00229         // bit 13 12 11 10 9 8 and 5 4 3 2 1 0
00230         byte UDMASelected;  // bit 13 -8
00231         byte UDMASupported; // bit 5 - 0
00232 
00233         byte HighestUDMASupported;  // This is not in DeviceInfo data but is calculated
00234 
00235         word SecurityEraseTime;         // Word 89
00236         word SecurityEnEraseTime;       // Word 90
00237         word CurAPMValue;                       // Word 91
00238         // Word 128
00239         byte SecurityLevel;                     // bit 8
00240         byte SecurityEnErase;           // bit 5
00241         byte SecurityCountExpired;  // bit 4
00242         byte SecurityFrozen;        // bit 3
00243         byte SecurityLocked;        // bit 2
00244         byte SecurityEnabled;           // bit 1
00245         byte SecuritySupported;     // bit 0;
00246 
00247         word VendorSpecific[31];        // Word 129-159
00248 
00249 
00250 } DeviceInfo_Struct;
00251 
00252 // Store global information about devices on the system
00253 typedef struct Device_Struct
00254 {
00255         byte RegBit;                    // Dev/Head register identifier for this device
00256         DeviceInfo_Struct Info; // A lot of info for this devices (filled by identifydevice command)
00257         int Type;                               // Type of device
00258 } Device_Struct;
00259 
00260 // Store global information about IdeChannels
00261 typedef struct IdeChannel_Struct
00262 {
00263         int IntDone;                    // interrupt flag for this channel
00264         word CmdBasePort;               // base address of commands registers
00265         word CntBasePort;               // base address of controls registers
00266         word IoPort[10];                // absolute address for all ide register
00267         Device_Struct Device[2];// two device for each channel
00268         int IntNum;                             // int number associeted with this channel
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

Generated on Fri Feb 20 15:32:15 2004 for Minirighi by doxygen1.2.18