* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* PROJECT: ReactOS Floppy Driver
* FILE: floppy.c
*/
#include <ntddk.h>
-#define NDEBUG
#include <debug.h>
#include "floppy.h"
ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL);
ASSERT(ControllerInfo);
- DPRINT("floppy: MotorStopDpcFunc called\n");
+ TRACE_(FLOPPY, "MotorStopDpcFunc called\n");
HwTurnOffMotor(ControllerInfo);
ControllerInfo->StopDpcQueued = FALSE;
PAGED_CODE();
ASSERT(DriveInfo);
- DPRINT("floppy: StartMotor called\n");
+ TRACE_(FLOPPY, "StartMotor called\n");
if(DriveInfo->ControllerInfo->StopDpcQueued && !KeCancelTimer(&DriveInfo->ControllerInfo->MotorTimer))
{
/* Motor turner-offer is already running; wait for it to finish */
- DPRINT("floppy: StartMotor: motor turner-offer is already running; waiting for it\n");
+ INFO_(FLOPPY, "StartMotor: motor turner-offer is already running; waiting for it\n");
KeWaitForSingleObject(&DriveInfo->ControllerInfo->MotorStoppedEvent, Executive, KernelMode, FALSE, NULL);
- DPRINT("floppy: StartMotor: wait satisfied\n");
+ INFO_(FLOPPY, "StartMotor: wait satisfied\n");
}
DriveInfo->ControllerInfo->StopDpcQueued = FALSE;
if(HwTurnOnMotor(DriveInfo) != STATUS_SUCCESS)
{
- DPRINT("floppy: StartMotor(): warning: HwTurnOnMotor failed\n");
+ WARN_(FLOPPY, "StartMotor(): warning: HwTurnOnMotor failed\n");
}
}
ASSERT(ControllerInfo);
- DPRINT("floppy: StopMotor called\n");
+ TRACE_(FLOPPY, "StopMotor called\n");
/* one relative second, in 100-ns units */
StopTime.QuadPart = 10000000;
{
UNREFERENCED_PARAMETER(DeviceObject);
- DPRINT("floppy: CreateClose called\n");
+ TRACE_(FLOPPY, "CreateClose called\n");
Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = FILE_OPENED;
StartMotor(DriveInfo);
/* set the data rate */
- DPRINT("floppy: FIXME: UN-HARDCODE DATA RATE\n");
+ WARN_(FLOPPY, "FIXME: UN-HARDCODE DATA RATE\n");
if(HwSetDataRate(DriveInfo->ControllerInfo, 0) != STATUS_SUCCESS)
{
- DPRINT("floppy: Recalibrate: HwSetDataRate failed\n");
+ WARN_(FLOPPY, "Recalibrate: HwSetDataRate failed\n");
StopMotor(DriveInfo->ControllerInfo);
return STATUS_IO_DEVICE_ERROR;
}
Status = HwRecalibrate(DriveInfo);
if(Status != STATUS_SUCCESS)
{
- DPRINT("floppy: Recalibrate: HwRecalibrate returned error\n");
+ WARN_(FLOPPY, "Recalibrate: HwRecalibrate returned error\n");
continue;
}
Status = HwRecalibrateResult(DriveInfo->ControllerInfo);
if(Status != STATUS_SUCCESS)
{
- DPRINT("floppy: Recalibrate: HwRecalibrateResult returned error\n");
+ WARN_(FLOPPY, "Recalibrate: HwRecalibrateResult returned error\n");
break;
}
}
PAGED_CODE();
ASSERT(DriveInfo);
- DPRINT("floppy: ResetChangeFlag called\n");
+ TRACE_(FLOPPY, "ResetChangeFlag called\n");
/* Try to recalibrate. We don't care if it works. */
Recalibrate(DriveInfo);
/* Seek to 1 */
if(HwSeek(DriveInfo, 1) != STATUS_SUCCESS)
{
- DPRINT("floppy: ResetChangeFlag(): HwSeek failed; returning STATUS_IO_DEVICE_ERROR\n");
+ WARN_(FLOPPY, "ResetChangeFlag(): HwSeek failed; returning STATUS_IO_DEVICE_ERROR\n");
StopMotor(DriveInfo->ControllerInfo);
return STATUS_IO_DEVICE_ERROR;
}
if(HwSenseInterruptStatus(DriveInfo->ControllerInfo) != STATUS_SUCCESS)
{
- DPRINT("floppy: ResetChangeFlag(): HwSenseInterruptStatus failed; bailing out\n");
+ WARN_(FLOPPY, "ResetChangeFlag(): HwSenseInterruptStatus failed; bailing out\n");
StopMotor(DriveInfo->ControllerInfo);
return STATUS_IO_DEVICE_ERROR;
}
/* Seek back to 0 */
if(HwSeek(DriveInfo, 0) != STATUS_SUCCESS)
{
- DPRINT("floppy: ResetChangeFlag(): HwSeek failed; returning STATUS_IO_DEVICE_ERROR\n");
+ WARN_(FLOPPY, "ResetChangeFlag(): HwSeek failed; returning STATUS_IO_DEVICE_ERROR\n");
StopMotor(DriveInfo->ControllerInfo);
return STATUS_IO_DEVICE_ERROR;
}
if(HwSenseInterruptStatus(DriveInfo->ControllerInfo) != STATUS_SUCCESS)
{
- DPRINT("floppy: ResetChangeFlag(): HwSenseInterruptStatus #2 failed; bailing\n");
+ WARN_(FLOPPY, "ResetChangeFlag(): HwSenseInterruptStatus #2 failed; bailing\n");
StopMotor(DriveInfo->ControllerInfo);
return STATUS_IO_DEVICE_ERROR;
}
/* Check the change bit */
if(HwDiskChanged(DriveInfo, &DiskChanged) != STATUS_SUCCESS)
{
- DPRINT("floppy: ResetChangeFlag(): HwDiskChagned failed; returning STATUS_IO_DEVICE_ERROR\n");
+ WARN_(FLOPPY, "ResetChangeFlag(): HwDiskChanged failed; returning STATUS_IO_DEVICE_ERROR\n");
StopMotor(DriveInfo->ControllerInfo);
return STATUS_IO_DEVICE_ERROR;
}
PAGED_CODE();
UNREFERENCED_PARAMETER(DriverObject);
- DPRINT("floppy: unloading\n");
+ TRACE_(FLOPPY, "unloading\n");
KeSetEvent(&QueueThreadTerminate, 0, FALSE);
KeWaitForSingleObject(QueueThreadObject, Executive, KernelMode, FALSE, 0);
/* Power down the controller */
if(HwPowerOff(&gControllerInfo[i]) != STATUS_SUCCESS)
{
- DPRINT("floppy: unload: warning: HwPowerOff failed\n");
+ WARN_(FLOPPY, "unload: warning: HwPowerOff failed\n");
}
}
}
UNREFERENCED_PARAMETER(PathName);
- DPRINT("floppy: ConfigCallback called with ControllerNumber %d\n", ControllerNumber);
+ TRACE_(FLOPPY, "ConfigCallback called with ControllerNumber %d\n", ControllerNumber);
gControllerInfo[gNumberOfControllers].ControllerNumber = ControllerNumber;
gControllerInfo[gNumberOfControllers].InterfaceType = BusType;
if(!HalTranslateBusAddress(BusType, BusNumber, PartialDescriptor->u.Port.Start, &AddressSpace, &TranslatedAddress))
{
- DPRINT("floppy: HalTranslateBusAddress failed; returning\n");
+ WARN_(FLOPPY, "HalTranslateBusAddress failed; returning\n");
return STATUS_IO_DEVICE_ERROR;
}
ASSERT(ControllerInfo);
- DPRINT("floppy: ISR called\n");
+ TRACE_(FLOPPY, "ISR called\n");
/*
* Due to the stupidity of the drive/controller relationship on the floppy drive, only one device object
ASSERT(ControllerInfo);
- DPRINT("floppy: DpcForIsr called\n");
+ TRACE_(FLOPPY, "DpcForIsr called\n");
KeSetEvent(&ControllerInfo->SynchEvent, EVENT_INCREMENT, FALSE);
}
PAGED_CODE();
ASSERT(ControllerInfo);
- DPRINT("floppy: InitController called with Controller 0x%p\n", ControllerInfo);
+ TRACE_(FLOPPY, "InitController called with Controller 0x%p\n", ControllerInfo);
KeClearEvent(&ControllerInfo->SynchEvent);
- DPRINT("floppy: InitController: resetting the controller\n");
+ INFO_(FLOPPY, "InitController: resetting the controller\n");
/* Reset the controller */
if(HwReset(ControllerInfo) != STATUS_SUCCESS)
{
- DPRINT("floppy: InitController: unable to reset controller\n");
+ WARN_(FLOPPY, "InitController: unable to reset controller\n");
return STATUS_IO_DEVICE_ERROR;
}
-/* Check if floppy drive exists */
- if(HwSenseInterruptStatus(ControllerInfo) != STATUS_SUCCESS)
- {
- DPRINT("floppy: Floppy drive not detected! Returning STATUS_IO_DEVICE_ERROR\n");
- return STATUS_IO_DEVICE_ERROR;
- }
-
-DPRINT("floppy: InitController: resetting the controller after floppy detection\n");
+ /* All controllers should support this so
+ * if we get something strange back then we
+ * know that this isn't a floppy controller
+ */
+ if (HwGetVersion(ControllerInfo) <= 0)
+ {
+ WARN_(FLOPPY, "InitController: unable to contact controller\n");
+ return STATUS_NO_SUCH_DEVICE;
+ }
- /* Reset the controller */
+ /* Reset the controller to avoid interrupt garbage on certain controllers */
if(HwReset(ControllerInfo) != STATUS_SUCCESS)
{
- DPRINT("floppy: InitController: unable to reset controller\n");
+ WARN_(FLOPPY, "InitController: unable to reset controller #2\n");
return STATUS_IO_DEVICE_ERROR;
}
- DPRINT("floppy: InitController: setting data rate\n");
+ INFO_(FLOPPY, "InitController: setting data rate\n");
/* Set data rate */
if(HwSetDataRate(ControllerInfo, DRSR_DSEL_500KBPS) != STATUS_SUCCESS)
{
- DPRINT("floppy: InitController: unable to set data rate\n");
+ WARN_(FLOPPY, "InitController: unable to set data rate\n");
return STATUS_IO_DEVICE_ERROR;
}
- DPRINT("floppy: InitController: waiting for initial interrupt\n");
+ INFO_(FLOPPY, "InitController: waiting for initial interrupt\n");
/* Wait for an interrupt */
WaitForControllerInterrupt(ControllerInfo);
/* Reset means you have to clear each of the four interrupts (one per drive) */
for(i = 0; i < MAX_DRIVES_PER_CONTROLLER; i++)
{
- DPRINT("floppy: InitController: Sensing interrupt %d\n", i);
+ INFO_(FLOPPY, "InitController: Sensing interrupt %d\n", i);
if(HwSenseInterruptStatus(ControllerInfo) != STATUS_SUCCESS)
{
- DPRINT("floppy: InitController: Unable to clear interrupt 0x%x\n", i);
+ WARN_(FLOPPY, "InitController: Unable to clear interrupt 0x%x\n", i);
return STATUS_IO_DEVICE_ERROR;
}
}
- DPRINT("floppy: InitController: done sensing interrupts\n");
+ INFO_(FLOPPY, "InitController: done sensing interrupts\n");
/* Next, see if we have the right version to do implied seek */
if(HwGetVersion(ControllerInfo) == VERSION_ENHANCED)
/* If so, set that up -- all defaults below except first TRUE for EIS */
if(HwConfigure(ControllerInfo, TRUE, TRUE, FALSE, 0, 0) != STATUS_SUCCESS)
{
- DPRINT("floppy: InitController: unable to set up implied seek\n");
+ WARN_(FLOPPY, "InitController: unable to set up implied seek\n");
ControllerInfo->ImpliedSeeks = FALSE;
}
else
{
- DPRINT("floppy: InitController: implied seeks set!\n");
+ INFO_(FLOPPY, "InitController: implied seeks set!\n");
ControllerInfo->ImpliedSeeks = TRUE;
}
}
else
{
- DPRINT("floppy: InitController: enhanced version not supported; disabling implied seeks\n");
+ INFO_(FLOPPY, "InitController: enhanced version not supported; disabling implied seeks\n");
ControllerInfo->ImpliedSeeks = FALSE;
ControllerInfo->Model30 = FALSE;
}
/* Specify */
- DPRINT("FLOPPY: FIXME: Figure out speed\n");
+ WARN_(FLOPPY, "FIXME: Figure out speed\n");
HeadLoadTime = SPECIFY_HLT_500K;
HeadUnloadTime = SPECIFY_HUT_500K;
StepRateTime = SPECIFY_SRT_500K;
- DPRINT("floppy: InitController: issuing specify command to controller\n");
+ INFO_(FLOPPY, "InitController: issuing specify command to controller\n");
/* Don't disable DMA --> enable dma (dumb & confusing) */
if(HwSpecify(ControllerInfo, HeadLoadTime, HeadUnloadTime, StepRateTime, FALSE) != STATUS_SUCCESS)
{
- DPRINT("floppy: InitController: unable to specify options\n");
+ WARN_(FLOPPY, "InitController: unable to specify options\n");
return STATUS_IO_DEVICE_ERROR;
}
*/
for(i = 0; i < ControllerInfo->NumberOfDrives; i++)
{
- DPRINT("floppy: InitController: recalibrating drive 0x%x on controller 0x%p\n", i, ControllerInfo);
+ INFO_(FLOPPY, "InitController: recalibrating drive 0x%x on controller 0x%p\n", i, ControllerInfo);
Recalibrate(&ControllerInfo->DriveInfo[i]);
}
- DPRINT("floppy: InitController: done initializing; returning STATUS_SUCCESS\n");
+ INFO_(FLOPPY, "InitController: done initializing; returning STATUS_SUCCESS\n");
return STATUS_SUCCESS;
}
*/
if(!gControllerInfo[0].Populated)
{
- DPRINT("floppy: AddControllers: failed to get controller info from registry\n");
+ WARN_(FLOPPY, "AddControllers: failed to get controller info from registry\n");
return FALSE;
}
/* Must set up the DPC before we connect the interrupt */
KeInitializeDpc(&gControllerInfo[i].Dpc, DpcForIsr, &gControllerInfo[i]);
- DPRINT("floppy: Connecting interrupt %d to controller%d (object 0x%p)\n", gControllerInfo[i].MappedVector,
+ INFO_(FLOPPY, "Connecting interrupt %d to controller%d (object 0x%p)\n", gControllerInfo[i].MappedVector,
i, &gControllerInfo[i]);
/* NOTE: We cannot share our interrupt, even on level-triggered buses. See Isr() for details. */
gControllerInfo[i].MappedLevel, gControllerInfo[i].MappedLevel, gControllerInfo[i].InterruptMode,
FALSE, Affinity, 0) != STATUS_SUCCESS)
{
- DPRINT("floppy: AddControllers: unable to connect interrupt\n");
+ WARN_(FLOPPY, "AddControllers: unable to connect interrupt\n");
continue;
}
if(!gControllerInfo[i].AdapterObject)
{
- DPRINT("floppy: AddControllers: unable to allocate an adapter object\n");
+ WARN_(FLOPPY, "AddControllers: unable to allocate an adapter object\n");
IoDisconnectInterrupt(gControllerInfo[i].InterruptObject);
continue;
}
/* 2b: Initialize the new controller */
if(InitController(&gControllerInfo[i]) != STATUS_SUCCESS)
{
- DPRINT("floppy: AddControllers():Unable to set up controller %d - initialization failed\n", i);
+ WARN_(FLOPPY, "AddControllers(): Unable to set up controller %d - initialization failed\n", i);
IoDisconnectInterrupt(gControllerInfo[i].InterruptObject);
continue;
}
UNICODE_STRING ArcPath;
UCHAR DriveNumber;
- DPRINT("floppy: AddControllers(): Configuring drive %d on controller %d\n", i, j);
+ INFO_(FLOPPY, "AddControllers(): Configuring drive %d on controller %d\n", i, j);
/*
* 3a: create a device object for the drive
FILE_DEVICE_DISK, FILE_REMOVABLE_MEDIA | FILE_FLOPPY_DISKETTE, FALSE,
&gControllerInfo[i].DriveInfo[j].DeviceObject) != STATUS_SUCCESS)
{
- DPRINT("floppy: AddControllers: unable to register a Device object\n");
+ WARN_(FLOPPY, "AddControllers: unable to register a Device object\n");
IoDisconnectInterrupt(gControllerInfo[i].InterruptObject);
continue; /* continue on to next drive */
}
- DPRINT("floppy: AddControllers: New device: %S (0x%p)\n", DeviceNameBuf, gControllerInfo[i].DriveInfo[j].DeviceObject);
+ INFO_(FLOPPY, "AddControllers: New device: %S (0x%p)\n", DeviceNameBuf, gControllerInfo[i].DriveInfo[j].DeviceObject);
/* 3b.5: Create an ARC path in case we're booting from this drive */
swprintf(gControllerInfo[i].DriveInfo[j].ArcPathBuffer,
RtlInitUnicodeString(&LinkName, gControllerInfo[i].DriveInfo[j].SymLinkBuffer);
if(IoCreateSymbolicLink(&LinkName, &DeviceName) != STATUS_SUCCESS)
{
- DPRINT("floppy: AddControllers: Unable to create a symlink for drive %d\n", DriveNumber);
+ WARN_(FLOPPY, "AddControllers: Unable to create a symlink for drive %d\n", DriveNumber);
IoDisconnectInterrupt(gControllerInfo[i].InterruptObject);
IoDeassignArcName(&ArcPath);
continue; /* continue to next drive */
}
/* 3e: Set up the DPC */
- IoInitializeDpcRequest(gControllerInfo[i].DriveInfo[j].DeviceObject, DpcForIsr);
+ IoInitializeDpcRequest(gControllerInfo[i].DriveInfo[j].DeviceObject, (PIO_DPC_ROUTINE)DpcForIsr);
/* 3f: Point the device extension at our DriveInfo struct */
gControllerInfo[i].DriveInfo[j].DeviceObject->DeviceExtension = &gControllerInfo[i].DriveInfo[j];
/* 3i: Now that we're done, set the Initialized flag so we know to free this in Unload */
gControllerInfo[i].DriveInfo[j].Initialized = TRUE;
+
+ /* 3j: Clear the DO_DEVICE_INITIALIZING flag */
+ gControllerInfo[i].DriveInfo[j].DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
}
}
- DPRINT("floppy: AddControllers: --------------------------------------------> finished adding controllers\n");
+ INFO_(FLOPPY, "AddControllers: --------------------------------------------> finished adding controllers\n");
return TRUE;
}
{
PDRIVE_INFO DriveInfo = DeviceObject->DeviceExtension;
- DPRINT("floppy: SignalMediaChanged called\n");
+ TRACE_(FLOPPY, "SignalMediaChanged called\n");
DriveInfo->DiskChangeCount++;
if(KeReadStateEvent(&QueueThreadTerminate))
{
- DPRINT("floppy: QueueThread terminating\n");
+ INFO_(FLOPPY, "QueueThread terminating\n");
return;
}
- DPRINT("floppy: QueueThread: servicing an IRP\n");
+ INFO_(FLOPPY, "QueueThread: servicing an IRP\n");
Irp = IoCsqRemoveNextIrp(&Csq, 0);
/* we won't get an irp if it was canceled */
if(!Irp)
{
- DPRINT("floppy: QueueThread: IRP queue empty\n");
+ INFO_(FLOPPY, "QueueThread: IRP queue empty\n");
continue;
}
break;
default:
- DPRINT("floppy: QueueThread(): Unrecognized irp: mj: 0x%x\n", Stack->MajorFunction);
+ WARN_(FLOPPY, "QueueThread(): Unrecognized irp: mj: 0x%x\n", Stack->MajorFunction);
Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
*/
if(PsCreateSystemThread(&ThreadHandle, THREAD_ALL_ACCESS, 0, 0, 0, QueueThread, 0) != STATUS_SUCCESS)
{
- DPRINT("floppy: Unable to create system thread; failing init\n");
+ WARN_(FLOPPY, "Unable to create system thread; failing init\n");
return STATUS_INSUFFICIENT_RESOURCES;
}
if(ObReferenceObjectByHandle(ThreadHandle, STANDARD_RIGHTS_ALL, NULL, KernelMode, &QueueThreadObject, NULL) != STATUS_SUCCESS)
{
- DPRINT("floppy: Unable to reference returned thread handle; failing init\n");
+ WARN_(FLOPPY, "Unable to reference returned thread handle; failing init\n");
return STATUS_UNSUCCESSFUL;
}