outb(base+0x03, 0xFF);
if(inb(base+0x02) != 0x66 || inb(base+0x03) != 0xFF) {
Log_Error("ATA", "Unable to write to 0x%x/0x%x", base+2, base+3);
- LEAVE('i', 0);
- return 0;
+ LEAVE('i', MODULE_ERR_MISC);
+ return MODULE_ERR_MISC;
}
}
LOG("gATA_PRDTs = {PBufAddr: 0x%x, PBufAddr: 0x%x}", gATA_PRDTs[0].PBufAddr, gATA_PRDTs[1].PBufAddr);
- // TODO: Ensure that this is within 32-bits
gaATA_PRDT_PAddrs[0] = MM_GetPhysAddr( &gATA_PRDTs[0] );
gaATA_PRDT_PAddrs[1] = MM_GetPhysAddr( &gATA_PRDTs[1] );
LOG("gaATA_PRDT_PAddrs = {0x%P, 0x%P}", gaATA_PRDT_PAddrs[0], gaATA_PRDT_PAddrs[1]);
#if PHYS_BITS > 32
+ // Ensure that this is within 32-bits
if( gaATA_PRDT_PAddrs[0] >> 32 || gaATA_PRDT_PAddrs[1] >> 32 ) {
Log_Error("ATA", "Physical addresses of PRDTs are not in 32-bits (%P and %P)",
gaATA_PRDT_PAddrs[0], gaATA_PRDT_PAddrs[1]);
}
// Poll until BSY clears or ERR is set
+ tTime endtime = now() + 2*1000; // 2 second timeout
// TODO: Timeout?
- while( (val & 0x80) && !(val & 1) )
+ while( (val & 0x80) && !(val & 1) && now() < endtime )
val = inb(base+7);
LOG("BSY unset (0x%x)", val);
// and, wait for DRQ to set
- while( !(val & 0x08) && !(val & 1))
+ while( !(val & 0x08) && !(val & 1) && now() < endtime )
val = inb(base+7);
LOG("DRQ set (0x%x)", val);
+ if(now() >= endtime) {
+ Log_Warning("ATA", "Timeout on ATA IDENTIFY (Disk %i)", Disk);
+ LEAVE('i', 0);
+ return 0;
+ }
+
// Check for an error
if(val & 1) {
LEAVE('i', 0);
int cont = (Disk>>1)&1; // Controller ID
int disk = Disk & 1;
Uint16 base;
- int bUseBounceBuffer;
+ int bUseBounceBuffer = 0;
ENTER("iDisk XAddress iCount bbWrite pBuffer", Disk, Address, Count, bWrite, Buffer);