Clean up ATA PIO driver.

This commit is contained in:
Jonas 'Sortie' Termansen 2013-06-02 17:27:29 +02:00
parent 7c3740a85d
commit 2ea7607f4e
1 changed files with 20 additions and 21 deletions

View File

@ -1,6 +1,6 @@
/******************************************************************************* /*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013.
This file is part of Sortix. This file is part of Sortix.
@ -223,7 +223,8 @@ ATABus::~ATABus()
ATADrive* ATABus::Instatiate(unsigned driveid) ATADrive* ATABus::Instatiate(unsigned driveid)
{ {
if ( 1 < driveid ) { errno = EINVAL; return NULL; } if ( 1 < driveid )
return errno = EINVAL, (ATADrive*) NULL;
curdriveid = 0; curdriveid = 0;
uint8_t drivemagic = 0xA0 | (driveid << 4); uint8_t drivemagic = 0xA0 | (driveid << 4);
@ -237,17 +238,16 @@ ATADrive* ATABus::Instatiate(unsigned driveid)
while ( true ) while ( true )
{ {
status = CPU::InPortB(iobase + STATUS); status = CPU::InPortB(iobase + STATUS);
if ( !status || status == 0xFF ) { errno = ENODEV; return NULL; } if ( !status || status == 0xFF )
if ( !(status & STATUS_BUSY) ) { break; } return errno = ENODEV, (ATADrive*) NULL;
if ( !(status & STATUS_BUSY) )
break;
} }
// Check for ATAPI device not following spec.
if ( CPU::InPortB(iobase + LBA_MID) || CPU::InPortB(iobase + LBA_MID) ) if ( CPU::InPortB(iobase + LBA_MID) || CPU::InPortB(iobase + LBA_MID) )
{ return errno = ENODEV, (ATADrive*) NULL;
errno = ENODEV; return NULL; // ATAPI device not following spec.
}
while ( !(status & STATUS_DATAREADY) && !(status & STATUS_ERROR) ) while ( !(status & STATUS_DATAREADY) && !(status & STATUS_ERROR) )
{
status = CPU::InPortB(iobase + STATUS); status = CPU::InPortB(iobase + STATUS);
}
if ( status & STATUS_ERROR ) if ( status & STATUS_ERROR )
{ {
unsigned mid = CPU::InPortB(iobase + LBA_MID); unsigned mid = CPU::InPortB(iobase + LBA_MID);
@ -268,8 +268,7 @@ ATADrive* ATABus::Instatiate(unsigned driveid)
{ {
//Log::PrintF("Error status during identify\n"); //Log::PrintF("Error status during identify\n");
} }
errno = EIO; return errno = EIO, (ATADrive*) NULL;
return NULL;
} }
ATADrive* drive = new ATADrive(this, driveid, iobase, altport); ATADrive* drive = new ATADrive(this, driveid, iobase, altport);
return drive; return drive;