1717
1818#define IDE_EXI_V1 0
1919#define IDE_EXI_V2 1
20+ #define IDE_EXI_V3 2
2021
2122u16 buffer [256 ] ATTRIBUTE_ALIGN (32 );
2223static int __ata_init [3 ] = {0 ,0 ,0 };
@@ -153,7 +154,7 @@ static inline void ata_read_buffer(int chn, u32 *dst)
153154 }
154155 else {
155156 // IDE_EXI_V2, no need to select / deselect all the time
156- EXI_ImmEx (chn ,dst ,512 ,EXI_READ );
157+ EXI_DmaEx (chn ,dst ,512 ,EXI_READ );
157158 EXI_Deselect (chn );
158159 EXI_Unlock (chn );
159160 }
@@ -172,7 +173,7 @@ static inline void ata_write_buffer(int chn, u32 *src)
172173 EXI_Lock (chn , dev , NULL );
173174 EXI_Select (chn ,dev ,EXI_SPEED32MHZ );
174175 EXI_ImmEx (chn ,& dat ,3 ,EXI_WRITE );
175- EXI_ImmEx (chn , src ,512 ,EXI_WRITE );
176+ EXI_DmaEx (chn , src ,512 ,EXI_WRITE );
176177 dat = 0 ;
177178 EXI_ImmEx (chn ,& dat ,1 ,EXI_WRITE ); // Burn an extra cycle for the IDE-EXI to know to stop serving data
178179 EXI_Deselect (chn );
@@ -187,8 +188,8 @@ int _ideExiVersion(int chn) {
187188 }
188189 u32 cid = 0 ;
189190 EXI_GetID (chn ,dev ,& cid );
190- if (cid == 0x49444532 ) {
191- return IDE_EXI_V2 ;
191+ if (( cid & ~ 0xff ) == 0x49444500 ) {
192+ return ( cid & 0xff ) - '1' ;
192193 }
193194 else {
194195 return IDE_EXI_V1 ;
@@ -204,7 +205,7 @@ u32 _ataDriveIdentify(int chn) {
204205
205206 memset (& ataDriveInfo , 0 , sizeof (typeDriveInfo ));
206207
207- // Get the ID to see if it's a V2
208+ // Get the ID to see if it's a V2+
208209 _ideexi_version = _ideExiVersion (chn );
209210 if (_ideexi_version == IDE_EXI_V1 && chn == EXI_CHANNEL_2 ) {
210211 return -1 ;
@@ -433,9 +434,14 @@ int _ataWriteSector(int chn, u64 lba, u32 *Buffer)
433434 while (!(ataReadStatusReg (chn ) & ATA_SR_DRQ ));
434435
435436 // Write data to the drive
436- u16 * ptr = (u16 * )Buffer ;
437- for (i = 0 ; i < 256 ; i ++ ) {
438- ataWriteu16 (chn , ptr [i ]);
437+ if (_ideexi_version < IDE_EXI_V3 ) {
438+ u16 * ptr = (u16 * )Buffer ;
439+ for (i = 0 ; i < 256 ; i ++ ) {
440+ ataWriteu16 (chn , ptr [i ]);
441+ }
442+ }
443+ else {
444+ ata_write_buffer (chn , Buffer );
439445 }
440446
441447 // Wait for the write to finish
0 commit comments