00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <string.h>
00018
00019 #include <arch/i386.h>
00020 #include <arch/interrupt.h>
00021 #include <arch/mem.h>
00022
00023 #include <kernel/clock.h>
00024 #include <kernel/Ide.h>
00025 #include <kernel/IdeAta.h>
00026 #include <kernel/IdeDebug.h>
00027 #include <kernel/IdeTimer.h>
00028 #include <kernel/keyboard.h>
00029 #include <kernel/video.h>
00030
00031 #include <kernel/IdeLow.h>
00032
00033
00034
00035 volatile IdeChannel_Struct * CurrentChannel;
00036
00037
00038 static IdeChannel_Struct IdePriReg;
00039
00040 static IdeChannel_Struct IdeSecReg;
00041
00042
00043
00044
00045
00046
00047 void SetAtaRegisterIoPort(word CmdBase, word CntBase, int IntN)
00048 {
00049 CurrentChannel->CmdBasePort=CmdBase;
00050 CurrentChannel->CntBasePort=CntBase;
00051
00052 CurrentChannel->IoPort[ CC_DATA ] = CmdBase + HDC_DATA;
00053 CurrentChannel->IoPort[ CC_ERR ] = CmdBase + HDC_ERR;
00054 CurrentChannel->IoPort[ CC_SECC ] = CmdBase + HDC_SECC;
00055 CurrentChannel->IoPort[ CC_SECN ] = CmdBase + HDC_SECN;
00056 CurrentChannel->IoPort[ CC_CYLL ] = CmdBase + HDC_CYLL;
00057 CurrentChannel->IoPort[ CC_CYLH ] = CmdBase + HDC_CYLH;
00058 CurrentChannel->IoPort[ CC_DEVH ] = CmdBase + HDC_DEVH;
00059 CurrentChannel->IoPort[ CC_STAT ] = CmdBase + HDC_STATUS;
00060 CurrentChannel->IoPort[ CC_ASTAT ] = CntBase + HDC_ASTAT;
00061 CurrentChannel->IoPort[ CC_ADDR ] = CntBase + HDC_ADD;
00062 CurrentChannel->Device[ CC_DEV0 ].RegBit = HDC_DEVH_DEV0;
00063 CurrentChannel->Device[ CC_DEV0 ].Type = CC_DEVTYPE_NONE;
00064 CurrentChannel->Device[ CC_DEV1 ].RegBit = HDC_DEVH_DEV1;
00065 CurrentChannel->Device[ CC_DEV1 ].Type = CC_DEVTYPE_NONE;
00066
00067 CurrentChannel->IntDone = FALSE;
00068 CurrentChannel->IntNum = IntN;
00069 }
00070
00071
00072
00073
00074
00075 void SelectAtaChannel (int Channel)
00076 {
00077
00078 if ( Channel == CC_SECONDARY )
00079 {
00080 CurrentChannel=&IdeSecReg;
00081 }
00082 else
00083 {
00084 CurrentChannel=&IdePriReg;
00085 }
00086 }
00087
00088
00089
00090
00091 word AtaPort(word Port)
00092 {
00093 return CurrentChannel->IoPort[Port];
00094 }
00095
00096
00097
00098
00099 void OutPortAta(word Port, byte Val)
00100 {
00101 outportb(AtaPort(Port),Val);
00102 }
00103
00104
00105
00106
00107 byte InPortAta(word Port)
00108 {
00109 return inportb(AtaPort(Port));
00110 }
00111
00112
00113
00114
00115 void InPortAtaMul(word Port, word * Buffer,word Count)
00116 {
00117
00118 inportwm(AtaPort(Port),Buffer,Count);
00119 }
00120
00121
00122
00123
00124 void OutPortAtaMul(word Port, word * Buffer, word Count)
00125 {
00126 outportwm(AtaPort(Port),Buffer,Count);
00127 }
00128
00129
00130
00131
00132
00133 void SetDevBit(int Dev)
00134 {
00135 OutPortAta( CC_DEVH, CurrentChannel->Device[Dev].RegBit);
00136 DELAY400NS;
00137 }
00138
00139
00140
00141
00142
00143 void SetFirstDevBit()
00144 {
00145 if ( CurrentChannel->Device[CC_DEV0].Type != CC_DEVTYPE_NONE )
00146 SetDevBit(CC_DEV0);
00147 else if( CurrentChannel->Device[CC_DEV1].Type != CC_DEVTYPE_NONE )
00148 SetDevBit(CC_DEV1);
00149 }
00150
00151
00152
00153
00154
00155
00156
00157 void Ide_Handler_Pri()
00158 {
00159 IdePriReg.IntDone = TRUE;
00160 }
00161
00162 void Ide_Handler_Sec()
00163 {
00164 IdeSecReg.IntDone = TRUE;
00165 }
00166