X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Modules%2FStorage%2FFDD%2Ffdd.c;h=cbd7844feb668900e042aca7801af14bb59b46e3;hb=9d85201216cb35e1b1e051b1d7cdc38eaa5befa4;hp=149465e3dbdabd36236c45b60c429da112a0929f;hpb=6a945643557084578509e149c84cf5dde3c59c3c;p=tpg%2Facess2.git diff --git a/Modules/Storage/FDD/fdd.c b/Modules/Storage/FDD/fdd.c index 149465e3..cbd7844f 100644 --- a/Modules/Storage/FDD/fdd.c +++ b/Modules/Storage/FDD/fdd.c @@ -69,7 +69,7 @@ enum FloppyPorts { enum FloppyCommands { FIX_DRIVE_DATA = 0x03, - HECK_DRIVE_STATUS = 0x04, + CHECK_DRIVE_STATUS = 0x04, CALIBRATE_DRIVE = 0x07, CHECK_INTERRUPT_STATUS = 0x08, SEEK_TRACK = 0x0F, @@ -113,7 +113,7 @@ void FDD_int_StartMotor(int Disk); // === GLOBALS === MODULE_DEFINE(0, FDD_VERSION, FDD, FDD_Install, NULL, "ISADMA", NULL); t_floppyDevice gFDD_Devices[2]; -tSpinlock glFDD; +tMutex glFDD; volatile int gbFDD_IrqFired = 0; tDevFS_Driver gFDD_DriverInfo = { NULL, "fdd", @@ -213,13 +213,13 @@ int FDD_Install(char **Arguments) void FDD_UnloadModule() { int i; - //DevFS_DelDevice( &gFDD_DriverInfo ); - LOCK(&glFDD); + DevFS_DelDevice( &gFDD_DriverInfo ); + Mutex_Acquire(&glFDD); for(i=0;i<4;i++) { Time_RemoveTimer(gFDD_Devices[i].timer); FDD_int_StopMotor((void *)(Uint)i); } - RELEASE(&glFDD); + Mutex_Release(&glFDD); //IRQ_Clear(6); } @@ -370,11 +370,11 @@ int FDD_int_ReadWriteSector(Uint32 Disk, Uint64 SectorAddr, int Write, void *Buf } LOG("Cyl=%i, Head=%i, Sector=%i", cyl, head, sec); - LOCK(&glFDD); // Lock to stop the motor stopping on us + Mutex_Acquire(&glFDD); // Lock to stop the motor stopping on us Time_RemoveTimer(gFDD_Devices[Disk].timer); // Remove Old Timer // Start motor if needed if(gFDD_Devices[Disk].motorState != 2) FDD_int_StartMotor(Disk); - RELEASE(&glFDD); + Mutex_Release(&glFDD); LOG("Wait for the motor to spin up"); @@ -382,7 +382,7 @@ int FDD_int_ReadWriteSector(Uint32 Disk, Uint64 SectorAddr, int Write, void *Buf while(gFDD_Devices[Disk].motorState == 1) Threads_Yield(); LOG("Acquire Spinlock"); - LOCK(&glFDD); + Mutex_Acquire(&glFDD); // Seek to track outb(base + CALIBRATE_DRIVE, 0); @@ -390,7 +390,7 @@ int FDD_int_ReadWriteSector(Uint32 Disk, Uint64 SectorAddr, int Write, void *Buf while(FDD_int_SeekTrack(Disk, head, (Uint8)cyl) == 0 && i++ < FDD_SEEK_TIMEOUT ) Threads_Yield(); if( i > FDD_SEEK_TIMEOUT ) { - RELEASE(&glFDD); + Mutex_Release(&glFDD); LEAVE('i', 0); return 0; } @@ -398,7 +398,7 @@ int FDD_int_ReadWriteSector(Uint32 Disk, Uint64 SectorAddr, int Write, void *Buf // Read Data from DMA LOG("Setting DMA for read"); - DMA_SetChannel(2, 512, !Write); // Read 512 Bytes from channel 2 + DMA_SetChannel(2, 512, !Write); // Read/Write 512 Bytes from channel 2 LOG("Sending command"); @@ -441,7 +441,7 @@ int FDD_int_ReadWriteSector(Uint32 Disk, Uint64 SectorAddr, int Write, void *Buf st1 = FDD_int_GetByte(base); st2 = FDD_int_GetByte(base); - // Cylinder, Head and Sector (mutilated in some way + // Cylinder, Head and Sector (mutilated in some way) rcy = FDD_int_GetByte(base); rhe = FDD_int_GetByte(base); rse = FDD_int_GetByte(base); @@ -487,7 +487,7 @@ int FDD_int_ReadWriteSector(Uint32 Disk, Uint64 SectorAddr, int Write, void *Buf // Release Spinlock LOG("Realeasing Spinlock and setting motor to stop"); - RELEASE(&glFDD); + Mutex_Release(&glFDD); if(i == FDD_MAX_READWRITE_ATTEMPTS) { Log_Warning("FDD", "Exceeded %i attempts in %s the disk", @@ -499,6 +499,7 @@ int FDD_int_ReadWriteSector(Uint32 Disk, Uint64 SectorAddr, int Write, void *Buf // Don't turn the motor off now, wait for a while gFDD_Devices[Disk].timer = Time_CreateTimer(MOTOR_OFF_DELAY, FDD_int_StopMotor, (void*)(tVAddr)Disk); + // Error check if( i < FDD_MAX_READWRITE_ATTEMPTS ) { LEAVE('i', 0); return 0; @@ -675,22 +676,19 @@ void FDD_SensInt(int base, Uint8 *sr0, Uint8 *cyl) */ void FDD_int_SendByte(int base, char byte) { - volatile int state; - int timeout = 128; - for( ; timeout--; ) + int timeout = 128; + + while( (inb(base + PORT_MAINSTATUS) & 0xC0) != 0x80 && timeout-- ) + inb(0x80); //Delay + + if( timeout >= 0 ) { - state = inb(base + PORT_MAINSTATUS); - if ((state & 0xC0) == 0x80) - { - outb(base + PORT_DATA, byte); - return; - } - inb(0x80); //Delay + outb(base + PORT_DATA, byte); + } + else + { + Log_Warning("FDD", "FDD_int_SendByte: Timeout sending byte 0x%x to base 0x%x\n", byte, base); } - - #if WARN - Warning("FDD_int_SendByte - Timeout sending byte 0x%x to base 0x%x\n", byte, base); - #endif } /** @@ -699,16 +697,20 @@ void FDD_int_SendByte(int base, char byte) */ int FDD_int_GetByte(int base) { - volatile int state; - int timeout; - for( timeout = 128; timeout--; ) + int timeout = 128; + + while( (inb(base + PORT_MAINSTATUS) & 0xd0) != 0xd0 && timeout-- ) + inb(0x80); //Delay + + if( timeout >= 0 ) { - state = inb((base + PORT_MAINSTATUS)); - if ((state & 0xd0) == 0xd0) - return inb(base + PORT_DATA); - inb(0x80); + return inb(base + PORT_DATA); + } + else + { + Log_Warning("FDD", "FDD_int_GetByte: Timeout reading byte from base 0x%x\n", base); + return -1; } - return -1; } /** @@ -804,7 +806,7 @@ void FDD_int_StartMotor(int disk) void FDD_int_StopMotor(void *Arg) { Uint8 state, disk = (Uint)Arg; - if( IS_LOCKED(&glFDD) ) return ; + if( Mutex_IsLocked(&glFDD) ) return ; ENTER("iDisk", disk); state = inb( cPORTBASE[ disk>>1 ] + PORT_DIGOUTPUT );