Fixed floppy driver bug!

The floppy controler is now recognized properly!!

svn path=/trunk/; revision=1455
This commit is contained in:
Eric Kohl 2000-12-08 00:43:45 +00:00
parent 3d521d0a20
commit 07127c18af
2 changed files with 66 additions and 58 deletions

View file

@ -1,4 +1,4 @@
# $Id: Makefile,v 1.4 2000/10/07 13:41:54 dwelch Exp $ # $Id: Makefile,v 1.5 2000/12/08 00:43:45 ekohl Exp $
# #
# #
PATH_TO_TOP = ../../.. PATH_TO_TOP = ../../..
@ -20,6 +20,7 @@ clean:
- $(RM) base.tmp - $(RM) base.tmp
- $(RM) temp.exp - $(RM) temp.exp
- $(RM) $(TARGET).sys - $(RM) $(TARGET).sys
- $(RM) $(TARGET).sys.unstripped
.phony: clean .phony: clean

View file

@ -99,13 +99,13 @@ FloppyReadSTAT(ULONG PortBase)
} }
/* waits until the fdc becomes ready */ /* waits until the fdc becomes ready */
static int static int
FloppyWaitUntilReady(WORD PortBase) FloppyWaitUntilReady(ULONG PortBase)
{ {
int Retries; int Retries;
int Status; int Status;
for (Retries = 0; Retries < FLOPPY_MAX_STAT_RETRIES; Retries++) for (Retries = 0; Retries < FLOPPY_MAX_STAT_RETRIES; Retries++)
{ {
Status = FloppyReadSTAT(PortBase); Status = FloppyReadSTAT(PortBase);
if (Status & STATUS_READY) if (Status & STATUS_READY)
@ -114,10 +114,10 @@ FloppyWaitUntilReady(WORD PortBase)
} }
} }
if (FloppyInitialized) if (FloppyInitialized)
{ {
DPRINT("Getstatus times out (%x) on fdc %d\n", DPRINT("Getstatus times out (%x) on fdc %d\n",
Status, Status,
PortBase); PortBase);
} }
@ -125,14 +125,14 @@ FloppyWaitUntilReady(WORD PortBase)
} }
static VOID static VOID
FloppyWriteData(WORD PortBase, BYTE Byte) FloppyWriteData(ULONG PortBase, BYTE Byte)
{ {
WRITE_PORT_UCHAR((PUCHAR)(PortBase + FLOPPY_DATA), Byte); WRITE_PORT_UCHAR((PUCHAR)(PortBase + FLOPPY_DATA), Byte);
} }
/* sends a command byte to the fdc */ /* sends a command byte to the fdc */
static BOOLEAN static BOOLEAN
FloppyWriteCommandByte(WORD PortBase, BYTE Byte) FloppyWriteCommandByte(ULONG PortBase, BYTE Byte)
{ {
int Status; int Status;
@ -144,14 +144,14 @@ FloppyWriteCommandByte(WORD PortBase, BYTE Byte)
if ((Status & (STATUS_READY|STATUS_DIR|STATUS_DMA)) == STATUS_READY) if ((Status & (STATUS_READY|STATUS_DIR|STATUS_DMA)) == STATUS_READY)
{ {
FloppyWriteData(PortBase, Byte); FloppyWriteData(PortBase, Byte);
return 0; return TRUE;
} }
if (FloppyInitialized) if (FloppyInitialized)
{ {
DPRINT("Unable to send byte %x to FDC. Fdc=%x Status=%x\n", DPRINT("Unable to send byte %x to FDC. Fdc=%x Status=%x\n",
Byte, Byte,
PortBase, PortBase,
Status); Status);
} }
@ -159,13 +159,13 @@ FloppyWriteCommandByte(WORD PortBase, BYTE Byte)
} }
/* gets the response from the fdc */ /* gets the response from the fdc */
static int static int
FloppyReadResultCode(WORD PortBase, PUCHAR Result) FloppyReadResultCode(ULONG PortBase, PUCHAR Result)
{ {
int Replies; int Replies;
int Status; int Status;
for (Replies = 0; Replies < FLOPPY_MAX_REPLIES; Replies++) for (Replies = 0; Replies < FLOPPY_MAX_REPLIES; Replies++)
{ {
if ((Status = FloppyWaitUntilReady(PortBase)) < 0) if ((Status = FloppyWaitUntilReady(PortBase)) < 0)
{ {
@ -178,19 +178,20 @@ FloppyReadResultCode(WORD PortBase, PUCHAR Result)
} }
if (Status == (STATUS_DIR | STATUS_READY | STATUS_BUSY)) if (Status == (STATUS_DIR | STATUS_READY | STATUS_BUSY))
{ {
Result[Replies] = READ_PORT_UCHAR((PUCHAR)FLOPPY_DATA); Result[Replies] = READ_PORT_UCHAR((PUCHAR)(PortBase + FLOPPY_DATA));
} }
else else
{ {
DPRINT("FloppyReadResultCode: break\n");
break; break;
} }
} }
if (FloppyInitialized) if (FloppyInitialized)
{ {
DPRINT("get result error. Fdc=%d Last status=%x Read bytes=%d\n", DPRINT("get result error. Fdc=%d Last status=%x Read bytes=%d\n",
PortBase, PortBase,
Status, Status,
Replies); Replies);
} }
@ -199,8 +200,8 @@ FloppyReadResultCode(WORD PortBase, PUCHAR Result)
#define MORE_OUTPUT -2 #define MORE_OUTPUT -2
/* does the fdc need more output? */ /* does the fdc need more output? */
static int static int
FloppyNeedsMoreOutput(WORD PortBase, PUCHAR Result) FloppyNeedsMoreOutput(ULONG PortBase, PUCHAR Result)
{ {
int Status; int Status;
@ -215,7 +216,7 @@ FloppyNeedsMoreOutput(WORD PortBase, PUCHAR Result)
} }
static BOOLEAN static BOOLEAN
FloppyConfigure(WORD PortBase, BOOLEAN DisableFIFO, BYTE FIFODepth) FloppyConfigure(ULONG PortBase, BOOLEAN DisableFIFO, BYTE FIFODepth)
{ {
BYTE Result[FLOPPY_MAX_REPLIES]; BYTE Result[FLOPPY_MAX_REPLIES];
@ -226,12 +227,12 @@ FloppyConfigure(WORD PortBase, BOOLEAN DisableFIFO, BYTE FIFODepth)
return FALSE; return FALSE;
} }
FloppyWriteCommandByte(PortBase, 0); FloppyWriteCommandByte(PortBase, 0);
FloppyWriteCommandByte(PortBase, FloppyWriteCommandByte(PortBase,
0x10 | 0x10 |
(DisableFIFO ? 0x20 : 0x00) | (DisableFIFO ? 0x20 : 0x00) |
(FIFODepth & 0x0f)); (FIFODepth & 0x0f));
/* pre-compensation from track 0 upwards */ /* pre-compensation from track 0 upwards */
FloppyWriteCommandByte(PortBase, 0); FloppyWriteCommandByte(PortBase, 0);
return TRUE; return TRUE;
} }
@ -257,8 +258,8 @@ static BOOLEAN
FloppyGetControllerVersion(IN PFLOPPY_CONTROLLER_PARAMETERS ControllerParameters, FloppyGetControllerVersion(IN PFLOPPY_CONTROLLER_PARAMETERS ControllerParameters,
OUT PFLOPPY_CONTROLLER_TYPE ControllerType) OUT PFLOPPY_CONTROLLER_TYPE ControllerType)
{ {
ULONG ResultLength;
UCHAR Result[FLOPPY_MAX_REPLIES]; UCHAR Result[FLOPPY_MAX_REPLIES];
int ResultLength;
/* 82072 and better know DUMPREGS */ /* 82072 and better know DUMPREGS */
if (!FloppyWriteCommandByte(ControllerParameters->PortBase, if (!FloppyWriteCommandByte(ControllerParameters->PortBase,
@ -278,10 +279,10 @@ FloppyGetControllerVersion(IN PFLOPPY_CONTROLLER_PARAMETERS ControllerParameters
if ((ResultLength == 1) && (Result[0] == 0x80)) if ((ResultLength == 1) && (Result[0] == 0x80))
{ {
DPRINT("FDC %d is an 8272A\n", ControllerParameters->PortBase); DPRINT("FDC %d is an 8272A\n", ControllerParameters->PortBase);
*ControllerType = FDC_8272A; *ControllerType = FDC_8272A;
return TRUE; return TRUE;
} }
if (ResultLength != 10) if (ResultLength != 10)
{ {
DPRINT("FDC %d init: DUMP_FDC: unexpected return of %d bytes.\n", DPRINT("FDC %d init: DUMP_FDC: unexpected return of %d bytes.\n",
ControllerParameters->PortBase, ControllerParameters->PortBase,
@ -289,7 +290,7 @@ FloppyGetControllerVersion(IN PFLOPPY_CONTROLLER_PARAMETERS ControllerParameters
return FALSE; return FALSE;
} }
if (!FloppyConfigure(ControllerParameters->PortBase, FALSE, 0x0a)) if (!FloppyConfigure(ControllerParameters->PortBase, FALSE, 0x0a))
{ {
DPRINT("FDC %d is an 82072\n", ControllerParameters->PortBase); DPRINT("FDC %d is an 82072\n", ControllerParameters->PortBase);
*ControllerType = FDC_82072; *ControllerType = FDC_82072;
@ -297,11 +298,11 @@ FloppyGetControllerVersion(IN PFLOPPY_CONTROLLER_PARAMETERS ControllerParameters
} }
FloppyWriteCommandByte(ControllerParameters->PortBase, FLOPPY_CMD_PPND_RW); FloppyWriteCommandByte(ControllerParameters->PortBase, FLOPPY_CMD_PPND_RW);
if (FloppyNeedsMoreOutput(ControllerParameters->PortBase, Result) == if (FloppyNeedsMoreOutput(ControllerParameters->PortBase, Result) ==
FLOPPY_NEEDS_OUTPUT) FLOPPY_NEEDS_OUTPUT)
{ {
FloppyWriteCommandByte(ControllerParameters->PortBase, 0); FloppyWriteCommandByte(ControllerParameters->PortBase, 0);
} }
else else
{ {
DPRINT("FDC %d is an 82072A\n", ControllerParameters->PortBase); DPRINT("FDC %d is an 82072A\n", ControllerParameters->PortBase);
*ControllerType = FDC_82072A; *ControllerType = FDC_82072A;
@ -310,18 +311,18 @@ FloppyGetControllerVersion(IN PFLOPPY_CONTROLLER_PARAMETERS ControllerParameters
/* Pre-1991 82077, doesn't know LOCK/UNLOCK */ /* Pre-1991 82077, doesn't know LOCK/UNLOCK */
FloppyWriteCommandByte(ControllerParameters->PortBase, FLOPPY_CMD_UNLK_FIFO); FloppyWriteCommandByte(ControllerParameters->PortBase, FLOPPY_CMD_UNLK_FIFO);
ResultLength = FloppyReadResultCode(ControllerParameters->PortBase, ResultLength = FloppyReadResultCode(ControllerParameters->PortBase,
Result); Result);
if ((ResultLength == 1) && (Result[0] == 0x80)) if ((ResultLength == 1) && (Result[0] == 0x80))
{ {
DPRINT("FDC %d is a pre-1991 82077\n", ControllerParameters->PortBase); DPRINT("FDC %d is a pre-1991 82077\n", ControllerParameters->PortBase);
*ControllerType = FDC_82077_ORIG; *ControllerType = FDC_82077_ORIG;
return TRUE; return TRUE;
} }
if ((ResultLength != 1) || (Result[0] != 0x00)) if ((ResultLength != 1) || (Result[0] != 0x00))
{ {
DPRINT("FDC %d init: UNLOCK: unexpected return of %d bytes.\n", DPRINT("FDC %d init: UNLOCK: unexpected return of %d bytes.\n",
ControllerParameters->PortBase, ControllerParameters->PortBase,
ResultLength); ResultLength);
return FALSE; return FALSE;
} }
@ -330,20 +331,20 @@ FloppyGetControllerVersion(IN PFLOPPY_CONTROLLER_PARAMETERS ControllerParameters
FloppyWriteCommandByte(ControllerParameters->PortBase, FLOPPY_CMD_PARTID); FloppyWriteCommandByte(ControllerParameters->PortBase, FLOPPY_CMD_PARTID);
ResultLength = FloppyReadResultCode(ControllerParameters->PortBase, ResultLength = FloppyReadResultCode(ControllerParameters->PortBase,
Result); Result);
if (ResultLength != 1) if (ResultLength != 1)
{ {
DPRINT("FDC %d init: PARTID: unexpected return of %d bytes.\n", DPRINT("FDC %d init: PARTID: unexpected return of %d bytes.\n",
ControllerParameters->PortBase, ControllerParameters->PortBase,
ResultLength); ResultLength);
return FALSE; return FALSE;
} }
if (Result[0] == 0x80) if (Result[0] == 0x80)
{ {
DPRINT("FDC %d is a post-1991 82077\n", ControllerParameters->PortBase); DPRINT("FDC %d is a post-1991 82077\n", ControllerParameters->PortBase);
*ControllerType = FDC_82077; *ControllerType = FDC_82077;
return TRUE; return TRUE;
} }
switch (Result[0] >> 5) switch (Result[0] >> 5)
{ {
case 0x0: case 0x0:
/* Either a 82078-1 or a 82078SL running at 5Volt */ /* Either a 82078-1 or a 82078SL running at 5Volt */
@ -362,21 +363,21 @@ FloppyGetControllerVersion(IN PFLOPPY_CONTROLLER_PARAMETERS ControllerParameters
return TRUE; return TRUE;
case 0x3: case 0x3:
DPRINT("FDC %d is a National Semiconductor PC87306\n", DPRINT("FDC %d is a National Semiconductor PC87306\n",
ControllerParameters->PortBase); ControllerParameters->PortBase);
*ControllerType = FDC_87306; *ControllerType = FDC_87306;
return TRUE; return TRUE;
default: default:
DPRINT("FDC %d init: 82078 variant with unknown PARTID=%d.\n", DPRINT("FDC %d init: 82078 variant with unknown PARTID=%d.\n",
ControllerParameters->PortBase, ControllerParameters->PortBase,
Result[0] >> 5); Result[0] >> 5);
*ControllerType = FDC_82078_UNKN; *ControllerType = FDC_82078_UNKN;
return TRUE; return TRUE;
} }
} }
static BOOLEAN static BOOLEAN
FloppyIsr(PKINTERRUPT Interrupt, PVOID ServiceContext) FloppyIsr(PKINTERRUPT Interrupt, PVOID ServiceContext)
{ {
return(TRUE); return(TRUE);
@ -390,7 +391,7 @@ FloppyCreateController(PDRIVER_OBJECT DriverObject,
FLOPPY_CONTROLLER_TYPE ControllerType; FLOPPY_CONTROLLER_TYPE ControllerType;
PCONTROLLER_OBJECT ControllerObject; PCONTROLLER_OBJECT ControllerObject;
PFLOPPY_CONTROLLER_EXTENSION ControllerExtension; PFLOPPY_CONTROLLER_EXTENSION ControllerExtension;
UNICODE_STRING DeviceName; UNICODE_STRING DeviceName;
UNICODE_STRING SymlinkName; UNICODE_STRING SymlinkName;
NTSTATUS Status; NTSTATUS Status;
PDEVICE_OBJECT DeviceObject; PDEVICE_OBJECT DeviceObject;
@ -407,7 +408,7 @@ FloppyCreateController(PDRIVER_OBJECT DriverObject,
/* Create controller object for FDC */ /* Create controller object for FDC */
ControllerObject = IoCreateController(sizeof(FLOPPY_CONTROLLER_EXTENSION)); ControllerObject = IoCreateController(sizeof(FLOPPY_CONTROLLER_EXTENSION));
if (ControllerObject == NULL) if (ControllerObject == NULL)
{ {
DPRINT("Could not create controller object for controller %d\n", DPRINT("Could not create controller object for controller %d\n",
Index); Index);
@ -480,29 +481,33 @@ FloppyCreateController(PDRIVER_OBJECT DriverObject,
ConfigInfo = IoGetConfigurationInformation (); ConfigInfo = IoGetConfigurationInformation ();
ConfigInfo->FloppyCount++; ConfigInfo->FloppyCount++;
return STATUS_SUCCESS; return TRUE;
} }
VOID FloppyStartIo(PDEVICE_OBJECT DeviceObject, VOID STDCALL FloppyStartIo(PDEVICE_OBJECT DeviceObject,
PIRP Irp) PIRP Irp)
{ {
DPRINT("FloppyStartIo\n");
} }
NTSTATUS FloppyDispatchOpenClose(PDEVICE_OBJECT DeviceObject, NTSTATUS STDCALL FloppyDispatchOpenClose(PDEVICE_OBJECT DeviceObject,
PIRP Irp) PIRP Irp)
{ {
DPRINT("FloppyDispatchOpenClose\n");
return(STATUS_UNSUCCESSFUL); return(STATUS_UNSUCCESSFUL);
} }
NTSTATUS FloppyDispatchReadWrite(PDEVICE_OBJECT DeviceObject, NTSTATUS STDCALL FloppyDispatchReadWrite(PDEVICE_OBJECT DeviceObject,
PIRP Irp) PIRP Irp)
{ {
DPRINT("FloppyDispatchReadWrite\n");
return(STATUS_UNSUCCESSFUL); return(STATUS_UNSUCCESSFUL);
} }
NTSTATUS FloppyDispatchDeviceControl(PDEVICE_OBJECT DeviceObject, NTSTATUS STDCALL FloppyDispatchDeviceControl(PDEVICE_OBJECT DeviceObject,
PIRP Irp) PIRP Irp)
{ {
DPRINT("FloppyDispatchDeviceControl\n");
return(STATUS_UNSUCCESSFUL); return(STATUS_UNSUCCESSFUL);
} }
@ -525,8 +530,8 @@ NTSTATUS FloppyDispatchDeviceControl(PDEVICE_OBJECT DeviceObject,
* RETURNS: * RETURNS:
* NTSTATUS * NTSTATUS
*/ */
NTSTATUS STDCALL DriverEntry(IN PDRIVER_OBJECT DriverObject, NTSTATUS STDCALL DriverEntry(IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath) IN PUNICODE_STRING RegistryPath)
{ {
DbgPrint("Floppy driver\n"); DbgPrint("Floppy driver\n");
@ -536,11 +541,11 @@ NTSTATUS STDCALL DriverEntry(IN PDRIVER_OBJECT DriverObject,
DriverObject->MajorFunction[IRP_MJ_CLOSE] = FloppyDispatchOpenClose; DriverObject->MajorFunction[IRP_MJ_CLOSE] = FloppyDispatchOpenClose;
DriverObject->MajorFunction[IRP_MJ_READ] = FloppyDispatchReadWrite; DriverObject->MajorFunction[IRP_MJ_READ] = FloppyDispatchReadWrite;
DriverObject->MajorFunction[IRP_MJ_WRITE] = FloppyDispatchReadWrite; DriverObject->MajorFunction[IRP_MJ_WRITE] = FloppyDispatchReadWrite;
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] =
FloppyDispatchDeviceControl; FloppyDispatchDeviceControl;
/* Try to detect controller and abort if it fails */ /* Try to detect controller and abort if it fails */
if (!FloppyCreateController(DriverObject, if (!FloppyCreateController(DriverObject,
&ControllerParameters[0], &ControllerParameters[0],
0)) 0))
{ {
@ -550,3 +555,5 @@ NTSTATUS STDCALL DriverEntry(IN PDRIVER_OBJECT DriverObject,
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
/* EOF */