Fix the reset sequence in AtapiFindDevices to work correctly in VMware.

svn path=/trunk/; revision=10813
This commit is contained in:
Filip Navara 2004-09-10 23:17:45 +00:00
parent fb16e656c4
commit 9a4721af9c

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: atapi.c,v 1.51 2004/09/03 04:44:45 navaraf Exp $ /* $Id: atapi.c,v 1.52 2004/09/10 23:17:45 navaraf Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS ATAPI miniport driver * PROJECT: ReactOS ATAPI miniport driver
@ -56,7 +56,7 @@
#include "atapi.h" #include "atapi.h"
#define NDEBUG //#define NDEBUG
#include <debug.h> #include <debug.h>
#define VERSION "0.0.1" #define VERSION "0.0.1"
@ -294,7 +294,10 @@ AtapiErrorToScsi(PVOID DeviceExtension,
PSCSI_REQUEST_BLOCK Srb); PSCSI_REQUEST_BLOCK Srb);
static VOID static VOID
AtapiScsiSrbToAtapi (PSCSI_REQUEST_BLOCK Srb); AtapiScsiSrbToAtapi(PSCSI_REQUEST_BLOCK Srb);
static BOOLEAN
AtapiWaitForStatus(ULONG CommandPort, ULONG Mask, ULONG Value, ULONG Timeout);
// ---------------------------------------------------------------- Inlines // ---------------------------------------------------------------- Inlines
@ -1094,9 +1097,10 @@ AtapiFindDevices(PATAPI_MINIPORT_EXTENSION DeviceExtension,
ULONG CommandPortBase; ULONG CommandPortBase;
ULONG ControlPortBase; ULONG ControlPortBase;
ULONG UnitNumber; ULONG UnitNumber;
ULONG Retries; ULONG Status;
UCHAR High; UCHAR High;
UCHAR Low; UCHAR Low;
BOOL UnitPresent[2];
DPRINT("AtapiFindDevices() called\n"); DPRINT("AtapiFindDevices() called\n");
@ -1109,51 +1113,65 @@ AtapiFindDevices(PATAPI_MINIPORT_EXTENSION DeviceExtension,
for (UnitNumber = 0; UnitNumber < 2; UnitNumber++) for (UnitNumber = 0; UnitNumber < 2; UnitNumber++)
{ {
/* Select drive */ /* Select drive */
IDEWriteDriveHead(CommandPortBase, IDEWriteDriveControl(ControlPortBase, 0);
IDE_DH_FIXED | (UnitNumber ? IDE_DH_DRV1 : 0)); IDEWriteDriveHead(CommandPortBase, IDE_DH_FIXED |
(UnitNumber ? IDE_DH_DRV1 : IDE_DH_DRV0));
ScsiPortStallExecution(500); ScsiPortStallExecution(500);
/* Disable interrupts */
IDEWriteDriveControl(ControlPortBase,
IDE_DC_nIEN);
ScsiPortStallExecution(500);
/* Check if a device is attached to the interface */ /* Check if a device is attached to the interface */
IDEWriteCylinderHigh(CommandPortBase, 0xaa); IDEWriteCylinderHigh(CommandPortBase, 0xaa);
IDEWriteCylinderLow(CommandPortBase, 0x55); IDEWriteCylinderLow(CommandPortBase, 0x55);
High = IDEReadCylinderHigh(CommandPortBase); High = IDEReadCylinderHigh(CommandPortBase);
Low = IDEReadCylinderLow(CommandPortBase); Low = IDEReadCylinderLow(CommandPortBase);
UnitPresent[UnitNumber] = (Low == 0x55 || High == 0xaa);
IDEWriteCylinderHigh(CommandPortBase, 0); #ifndef NDEBUG
IDEWriteCylinderLow(CommandPortBase, 0);
if (Low != 0x55 || High != 0xaa) if (Low != 0x55 || High != 0xaa)
{ {
DPRINT("No Drive found. UnitNumber %d CommandPortBase %x\n", UnitNumber, CommandPortBase); DPRINT("No Drive found. UnitNumber %d CommandPortBase %x\n", UnitNumber, CommandPortBase);
continue; }
} #endif
}
/* Soft reset */ /* Check if any unit was found. */
IDEWriteDriveControl(ControlPortBase, IDE_DC_nIEN | IDE_DC_SRST); if (UnitPresent[0] == FALSE && UnitPresent[1] == FALSE)
ScsiPortStallExecution(500); {
IDEWriteDriveControl(ControlPortBase, IDE_DC_nIEN); DPRINT("No device found\n");
ScsiPortStallExecution(500); return FALSE;
}
for (Retries = 0; Retries < 20000; Retries++) /* Soft reset */
{ IDEWriteDriveHead(CommandPortBase, IDE_DH_FIXED);
if (!(IDEReadStatus(CommandPortBase) & IDE_SR_BUSY)) IDEWriteDriveControl(ControlPortBase, IDE_DC_SRST);
{ ScsiPortStallExecution(500);
break; IDEWriteDriveControl(ControlPortBase, IDE_DC_nIEN);
} ScsiPortStallExecution(200);
ScsiPortStallExecution(150);
} /* Wait for busy to clear */
if (Retries >= 20000) if (!AtapiWaitForStatus(CommandPortBase, IDE_SR_BUSY, 0, 20000))
{ {
DPRINT("Timeout on drive %lu\n", UnitNumber); DPRINT("Timeout on drive %lu\n", UnitNumber);
DeviceExtension->DeviceFlags[UnitNumber] &= ~DEVICE_PRESENT; return FALSE;
continue; }
} else
{
Status = IDEReadStatus(DeviceExtension->CommandPortBase);
if (Status & IDE_SR_ERR)
{
DPRINT("Error while doing software reset\n");
return FALSE;
}
}
for (UnitNumber = 0; UnitNumber < 2; UnitNumber++)
{
/* Skip initilization of non-existent units */
if (!UnitPresent[UnitNumber])
{
continue;
}
/* Select drive */
IDEWriteDriveHead(CommandPortBase, IDE_DH_FIXED |
(UnitNumber ? IDE_DH_DRV1 : IDE_DH_DRV0));
High = IDEReadCylinderHigh(CommandPortBase); High = IDEReadCylinderHigh(CommandPortBase);
Low = IDEReadCylinderLow(CommandPortBase); Low = IDEReadCylinderLow(CommandPortBase);
@ -1239,9 +1257,6 @@ AtapiFindDevices(PATAPI_MINIPORT_EXTENSION DeviceExtension,
/* Reenable interrupts */ /* Reenable interrupts */
IDEWriteDriveControl(ControlPortBase, 0); IDEWriteDriveControl(ControlPortBase, 0);
ScsiPortStallExecution(500); ScsiPortStallExecution(500);
/* Return with drive 0 selected */
IDEWriteDriveHead(CommandPortBase, IDE_DH_FIXED);
ScsiPortStallExecution(500);
DPRINT("AtapiFindDrives() done (DeviceFound %s)\n", (DeviceFound) ? "TRUE" : "FALSE"); DPRINT("AtapiFindDrives() done (DeviceFound %s)\n", (DeviceFound) ? "TRUE" : "FALSE");
@ -3046,4 +3061,23 @@ AtapiInitDma(PATAPI_MINIPORT_EXTENSION DevExt,
} }
#endif #endif
static BOOLEAN
AtapiWaitForStatus( ULONG CommandPort, ULONG Mask, ULONG Value, ULONG Timeout )
{
ULONG RetryCount, Status;
for (RetryCount = 0; RetryCount < Timeout; RetryCount++)
{
Status = IDEReadStatus(CommandPort);
if ((Status & Mask) == Value)
{
return TRUE;
}
ScsiPortStallExecution(10);
}
DPRINT("status=%02x\n", Status);
DPRINT("waited %ld usecs\n", RetryCount * 10);
return FALSE;
}
/* EOF */ /* EOF */