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

Ide.h

Go to the documentation of this file.
00001 /*!     \file include/kernel/Ide.h
00002  *      \brief IDE driver header.
00003  *      \author Luca Giovacchini
00004  *      \date Last update: 2003-11-07
00005  *      \note Copyright (©) 2003 Luca Giovacchini
00006  *
00007  *      This driver is based on Atadrv by Hale Landis
00008  *      but it is completely rearranged for the minirighi32.
00009  *      \n
00010  *      <b>IMPORTANT!!!</b>\n
00011  *      Here you can find what the driver should expose to the rest
00012  *      of the world.
00013  *
00014  *      Read IdeAta, IdeLow, IdeDebug and IdeTimer comments for better
00015  *      understand how this driver works.
00016  *      Implementing new ide commands is very very simple.
00017  *      All the major part of the Ata protocol is in "IdeAta.c".
00018  *      You only need to look for Ata-4 references, search for a
00019  *      command and see what protocol and what parameter you have
00020  *      to use.
00021  *      I have written specific subroutines to read, write and identify
00022  *      identifying devices, but they only simplify the interface for
00023  *      the more generic ata protocol.
00024  *
00025  *      I have already set inizialization of Ide Driver in main.c so
00026  *      you only need to:
00027  *      \li select the channel you want to use (with SelectAtaChannel);
00028  *      \li check CurrentChannel to find a specific device (directly
00029  *      with CurrentChannel var);
00030  *      \li use one of the specific command sub (i.e. ReadSectorLba,
00031  *      WriteSectorLba, ...)
00032  */
00033 
00034 #ifndef IDE_H
00035 #define IDE_H
00036 
00037 #include <const.h>
00038 
00039 #define IDE_DEBUG      1 // 1=compila codice di debug  0=non compila codice di debug
00040 
00041 
00042 //**********************************************
00043 // LOGICAL REGISTERS, INDEX, TYPE
00044 // used with CurrentChannel
00045 //**********************************************
00046 #define CC_PRIMARY         0     
00047 #define CC_SECONDARY       1     
00048 
00049 // Index of IdeChannel_Struct.IOPort (see above)
00050 #define CC_DATA      0     // Data Register
00051 #define CC_ERR       1     // Error Register
00052 #define CC_FEAT      1     // Features Register
00053 #define CC_SECC      2     // Sector Count Register
00054 #define CC_SECN      3     // Sector Number Register
00055 #define CC_CYLL      4     // Cylinder Low Register
00056 #define CC_CYLH      5     // Cylinder High Register
00057 #define CC_DEVH      6     // Device/Head Register
00058 #define CC_STAT      7     // Status Register
00059 #define CC_CMD       7     // Command Register
00060 #define CC_ASTAT     8     // Alternate Status Register
00061 #define CC_DEVC      8     // Device Command Register
00062 #define CC_ADDR      9     // Address Register
00063 
00064 #define CC_DEV0          0
00065 #define CC_DEV1          1
00066 #define CC_DEVTYPE_NONE  0
00067 #define CC_DEVTYPE_UNKN  1
00068 #define CC_DEVTYPE_ATA   2
00069 #define CC_DEVTYPE_ATAPI 3
00070 
00071 //**********************************************
00072 // SUB AND STRUCTURE
00073 //**********************************************
00074 
00075 #define GETBITB(Data,nBit) ( ((byte) Data >> nBit) & 0x01 )
00076 #define GETBITW(Data,nBit) ( ((word) Data >> nBit) & 0x0001 )
00077 #define GETBITD(Data,nBit) ( ((dword) Data >> nBit) & 0x00000001 )
00078 #define GETNIBBLEB(Data,nNibble) ( ((byte) Data >> (nNibble<<2)) & 0x0F)
00079 #define GETNIBBLEW(Data,nNibble) ( ((word) Data >> (nNibble<<2)) & 0x000F)
00080 #define GETNIBBLED(Data,nNibble) ( ((dword) Data >> (nNibble<<2)) & 0x0000000F)
00081 #define GETBYTEW(Data,nByte) ( ((word) Data >> (nByte<<3)) & 0x00FF )
00082 #define GETBYTED(Data,nByte) ( ((dword) Data >> (nByte<<3)) & 0x000000FF)
00083 #define GETWORDD(Data,nWord) ( ((dword) Data >> (nWord<<4)) & 0x0000FFFF )
00084 #define MAKEDWORDW(Word1,Word0) ( (((dword) Word1 << 16) | (word) Word0) )
00085 #define SWAPBYTEW(Data) ( (GETBYTEW(Data,0) << 8) | (GETBYTEW(Data,1)) )
00086 
00087 // the "NO " with the space is to let they be 3 char len
00088 #define Bit2YesNo(Exp) ( (char *) (Exp ? "YES" : "NO ") )
00089 
00090 
00091 typedef struct BusMaster_Struct
00092 {
00093         int Config;
00094         dword BaseAddress;
00095         unsigned long * PrdBufPtr;  // PRD address (seg:off, off is 0)
00096         dword DmaPciPrdAddr;
00097         byte PrdBuf[64];        // Physical region descriptor table (for Dma 32)
00098         dword PrdBufPtrLow;     // 32-bit prd ptr upper 16 bits
00099         dword PrdBufPtrHigh;    // 32-bit prd ptr lower 16 bits
00100         byte StatReg;          // save BM status reg bits
00101         byte RWControl;        // read/write control bit setting
00102 } BusMaster_Struct;
00103 
00104 
00105 void ShowDeviceSubData(int Dev);
00106 void ShowIdeSubData();
00107 int ScanDevice(int UseInterrupt) ;
00108 int IdentifyDevice (int Dev) ;
00109 void ShowDeviceDataRowName(char * Name,int Col);
00110 void ShowDeviceDataRowValue(char * Name, int Col, char * Format, dword Value);
00111 void ShowDeviceDataRowString(char * Name, int Col, char * Value);
00112 void ShowDeviceDataRowSup(char * Name,int Col, byte Supported);
00113 void ShowDeviceDataRowSupEn(char * Name,int Col,byte Supported,byte Enabled);
00114 void ShowDeviceDataRowBitNum(word BitCode,byte StartFrom, byte EndTo, byte StartPrintNum);
00115 void ShowDeviceData(int Dev,int Col);
00116 void InitIde();
00117 int ReadSectorsLba(int Dev, uint64 Lba, int NumSect, word * Buffer,int UseInterrupt);
00118 int WriteSectorsLba(int Dev, uint64 Lba, int NumSect, word * Buffer,int UseInterrupt);
00119 
00120 
00121 /*
00122 byte InPortPci(word Port);
00123 void SetUpXfer( int dir, long count, unsigned seg, unsigned off );
00124 int DmaPciAta( int Dev, int Cmd,
00125                  int Feat, int SecC,
00126                  dword Cyl, int Head, int Sect,
00127                  unsigned Seg, unsigned Off );
00128 int DmaPciAtaLba( int Dev, int Cmd,
00129                             int Feat, int SecC,
00130                             uint64 Lba,
00131                             unsigned Seg, unsigned Off );
00132 void EnableChanPci() ;
00133 void DisableChanPci();
00134 void OutPortPci(word Port, byte Val);
00135 */
00136 //**********************************************
00137 // BUS MASTER REGISTER BASE IO PORT
00138 //**********************************************
00139 #define BMCR_IO_ADDR 0xFF00   // YOU MUST SUPPLY THIS VALUE
00140 #define BM_COMMAND_REG     0              // offset to command reg
00141 #define BM_CR_MASK_READ    0x00           // read from memory
00142 #define BM_CR_MASK_WRITE   0x08           // write to memory
00143 #define BM_CR_MASK_START   0x01           // start transfer
00144 #define BM_CR_MASK_STOP    0x00           // stop transfer
00145 
00146 #define BM_STATUS_REG     2            // offset to status reg
00147 #define BM_SR_MASK_SIMPLEX 0x80           // simplex only
00148 #define BM_SR_MASK_DRV1    0x40           // drive 1 can do dma
00149 #define BM_SR_MASK_DRV0    0x20           // drive 0 can do dma
00150 #define BM_SR_MASK_INT     0x04           // INTRQ signal asserted
00151 #define BM_SR_MASK_ERR     0x02           // error
00152 #define BM_SR_MASK_ACT     0x01           // active
00153 
00154 #define BM_PRD_ADDR_LOW   4            // offset to prd addr reg low 16 bits
00155 #define BM_PRD_ADDR_HIGH  6            // offset to prd addr reg high 16 bits
00156 
00157 
00158 #endif

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