From 2d902a8146b2d67cf7b153e94e3bc51f40f32c58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9=20van=20Geldorp?= Date: Thu, 17 Jun 2004 13:28:53 +0000 Subject: [PATCH] Remove obsolete ide and (old) floppy drivers svn path=/trunk/; revision=9698 --- reactos/drivers/dd/floppy/.cvsignore | 8 - reactos/drivers/dd/floppy/Makefile | 20 - reactos/drivers/dd/floppy/dpc.c | 279 ---- reactos/drivers/dd/floppy/floppy.c | 609 ------- reactos/drivers/dd/floppy/floppy.h | 258 --- reactos/drivers/dd/floppy/floppy.rc | 38 - reactos/drivers/dd/floppy/isr.c | 210 --- reactos/drivers/dd/ide/.cvsignore | 8 - reactos/drivers/dd/ide/ide.c | 2268 -------------------------- reactos/drivers/dd/ide/ide.h | 256 --- reactos/drivers/dd/ide/ide.rc | 39 - reactos/drivers/dd/ide/makefile | 19 - reactos/drivers/dd/ide/partitio.h | 41 - 13 files changed, 4053 deletions(-) delete mode 100644 reactos/drivers/dd/floppy/.cvsignore delete mode 100644 reactos/drivers/dd/floppy/Makefile delete mode 100644 reactos/drivers/dd/floppy/dpc.c delete mode 100644 reactos/drivers/dd/floppy/floppy.c delete mode 100644 reactos/drivers/dd/floppy/floppy.h delete mode 100644 reactos/drivers/dd/floppy/floppy.rc delete mode 100644 reactos/drivers/dd/floppy/isr.c delete mode 100644 reactos/drivers/dd/ide/.cvsignore delete mode 100644 reactos/drivers/dd/ide/ide.c delete mode 100644 reactos/drivers/dd/ide/ide.h delete mode 100644 reactos/drivers/dd/ide/ide.rc delete mode 100644 reactos/drivers/dd/ide/makefile delete mode 100644 reactos/drivers/dd/ide/partitio.h diff --git a/reactos/drivers/dd/floppy/.cvsignore b/reactos/drivers/dd/floppy/.cvsignore deleted file mode 100644 index 5f6c85b86cb..00000000000 --- a/reactos/drivers/dd/floppy/.cvsignore +++ /dev/null @@ -1,8 +0,0 @@ -*.tmp -*.exp -*.coff -*.d -*.o -*.sym -*.sys -*.map diff --git a/reactos/drivers/dd/floppy/Makefile b/reactos/drivers/dd/floppy/Makefile deleted file mode 100644 index 954a4ad0484..00000000000 --- a/reactos/drivers/dd/floppy/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -# $Id: Makefile,v 1.12 2003/11/13 14:22:03 ekohl Exp $ - -PATH_TO_TOP = ../../.. - -TARGET_BOOTSTRAP = yes - -TARGET_TYPE = driver - -TARGET_NAME = floppy - -TARGET_OBJECTS = \ - dpc.o \ - floppy.o \ - isr.o - -TARGET_CFLAGS = -Wall -Werror - -include $(PATH_TO_TOP)/rules.mak - -include $(TOOLS_PATH)/helper.mk diff --git a/reactos/drivers/dd/floppy/dpc.c b/reactos/drivers/dd/floppy/dpc.c deleted file mode 100644 index e0e58ab40cc..00000000000 --- a/reactos/drivers/dd/floppy/dpc.c +++ /dev/null @@ -1,279 +0,0 @@ -/**************************************************************************** - * Defered procedure calls for floppy disk driver, reactos project, created * - * by Phillip Susi on 2/25/2001. This software is published under the GNU * - * general public license, see the README file for more details * - ***************************************************************************/ - -#include -#define NDEBUG -#include -#include "floppy.h" - - -VOID STDCALL -FloppyDpc (PKDPC Dpc, - PDEVICE_OBJECT DeviceObject, - PIRP Irp, - PVOID Context) -{ - PCONTROLLER_OBJECT Controller; - PFLOPPY_CONTROLLER_EXTENSION ControllerExtension; - - Controller = (PCONTROLLER_OBJECT)Context; - ControllerExtension = (PFLOPPY_CONTROLLER_EXTENSION)Controller->ControllerExtension; - - ControllerExtension->DpcState (Dpc, - DeviceObject, - Irp, - Context); -} - - -VOID STDCALL -FloppyDpcDetect (PKDPC Dpc, - PDEVICE_OBJECT DeviceObject, - PIRP Irp, - PVOID Context) -{ - PCONTROLLER_OBJECT Controller; - PFLOPPY_CONTROLLER_EXTENSION ControllerExtension; - - Controller = (PCONTROLLER_OBJECT)Context; - ControllerExtension = (PFLOPPY_CONTROLLER_EXTENSION)Controller->ControllerExtension; - - KeSetEvent (&ControllerExtension->Event, - 0, - FALSE); -} - - -VOID STDCALL -FloppyDpcFailIrp (PKDPC Dpc, - PDEVICE_OBJECT DeviceObject, - PIRP Irp, - PVOID Context) -{ - Irp->IoStatus.Status = STATUS_DEVICE_NOT_READY; - Irp->IoStatus.Information = 0; - CHECKPOINT; - IoCompleteRequest (Irp, - IO_NO_INCREMENT); -} - - -VOID STDCALL -FloppyMotorSpindownDpc (PKDPC Dpc, - PVOID Context, - PVOID Arg1, - PVOID Arg2) -{ - PCONTROLLER_OBJECT Controller; - PFLOPPY_CONTROLLER_EXTENSION ControllerExtension; - - Controller = (PCONTROLLER_OBJECT)Context; - ControllerExtension = (PFLOPPY_CONTROLLER_EXTENSION)Controller->ControllerExtension; - - /* queue call to turn off motor */ - IoAllocateController (Controller, - ControllerExtension->Device, - FloppyExecuteSpindown, - ControllerExtension); -} - - -VOID STDCALL -FloppyMotorSpinupDpc (PKDPC Dpc, - PVOID Context, - PVOID Arg1, - PVOID Arg2) -{ - PCONTROLLER_OBJECT Controller; - PFLOPPY_CONTROLLER_EXTENSION ControllerExtension; - PFLOPPY_DEVICE_EXTENSION DeviceExtension; - LARGE_INTEGER Timeout; - - Controller = (PCONTROLLER_OBJECT)Context; - ControllerExtension = (PFLOPPY_CONTROLLER_EXTENSION)Controller->ControllerExtension; - DeviceExtension = (PFLOPPY_DEVICE_EXTENSION)ControllerExtension->Device->DeviceExtension; - Timeout.QuadPart = FLOPPY_MOTOR_SPINDOWN_TIME; - - // Motor has had time to spin up, mark motor as spun up and restart IRP - // don't forget to set the spindown timer - KeSetTimer (&ControllerExtension->SpinupTimer, - Timeout, - &ControllerExtension->MotorSpindownDpc); - DPRINT ("Motor spun up, retrying operation\n"); - - ControllerExtension->MotorOn = DeviceExtension->DriveSelect; - - IoFreeController (Controller); - IoAllocateController (Controller, - ControllerExtension->Device, - FloppyExecuteReadWrite, - ControllerExtension->Irp); -} - - -VOID STDCALL -FloppySeekDpc (PKDPC Dpc, - PDEVICE_OBJECT DeviceObject, - PIRP Irp, - PVOID Context) -{ - PFLOPPY_DEVICE_EXTENSION DeviceExtension; - PFLOPPY_CONTROLLER_EXTENSION ControllerExtension; - - DeviceExtension = (PFLOPPY_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - ControllerExtension = (PFLOPPY_CONTROLLER_EXTENSION)DeviceExtension->Controller->ControllerExtension; - - /* If the seek failed, fail the IRP */ - if (ControllerExtension->St0 & FLOPPY_ST0_GDMASK) - { - ControllerExtension->Irp->IoStatus.Status = STATUS_DISK_CORRUPT_ERROR; - ControllerExtension->Irp->IoStatus.Information = 0; - DPRINT ("Failing IRP: St0 = %2x, St1 = %2x, St2 = %2x\n", - ControllerExtension->St0, - ControllerExtension->St1, - ControllerExtension->St2); - for (;;); - IoCompleteRequest (ControllerExtension->Irp, - IO_NO_INCREMENT); - IoFreeController (DeviceExtension->Controller); - return; - } - - KeStallExecutionProcessor (10000); - - DPRINT ("Seek completed, now on cyl %2x\n", DeviceExtension->Cyl); - - /* Now that we are on the right cyl, restart the read */ - if (FloppyExecuteReadWrite (DeviceObject, - ControllerExtension->Irp, - ControllerExtension->MapRegisterBase, - ControllerExtension->Irp) == DeallocateObject) - { - IoFreeController (DeviceExtension->Controller); - } -} - - -VOID STDCALL -FloppyDpcReadWrite (PKDPC Dpc, - PDEVICE_OBJECT DeviceObject, - PIRP Irp, - PVOID Context) -{ - PCONTROLLER_OBJECT Controller; - PFLOPPY_CONTROLLER_EXTENSION ControllerExtension; - PFLOPPY_DEVICE_EXTENSION DeviceExtension; - ULONG SectorSize; - PIO_STACK_LOCATION Stack; - BOOLEAN WriteToDevice; - - - Controller = (PCONTROLLER_OBJECT)Context; - ControllerExtension = (PFLOPPY_CONTROLLER_EXTENSION)Controller->ControllerExtension; - DeviceExtension = (PFLOPPY_DEVICE_EXTENSION)ControllerExtension->Device->DeviceExtension; - - Irp = ControllerExtension->Irp; - - Stack = IoGetCurrentIrpStackLocation (Irp); - - SectorSize = 128 << ControllerExtension->SectorSizeCode; - - WriteToDevice = Stack->MajorFunction == IRP_MJ_WRITE ? TRUE : FALSE; - - /* If the IO failed, fail the IRP */ - if (ControllerExtension->St0 & FLOPPY_ST0_GDMASK) - { - Irp->IoStatus.Status = STATUS_DISK_CORRUPT_ERROR; - Irp->IoStatus.Information = 0; - DPRINT( "Failing IRP: St0 = %2x, St1 = %2x, St2 = %2x\n", - ControllerExtension->St0, - ControllerExtension->St1, - ControllerExtension->St2 ); - for(;;); - IoCompleteRequest (Irp, - IO_NO_INCREMENT); - IoFreeController (Controller); - return; - } - - /* Don't forget to flush the buffers */ - IoFlushAdapterBuffers( ControllerExtension->AdapterObject, - ControllerExtension->Irp->MdlAddress, - ControllerExtension->MapRegisterBase, - ControllerExtension->Irp->Tail.Overlay.DriverContext[0], - ControllerExtension->TransferLength, - WriteToDevice); - DPRINT ("St0 = %2x St1 = %2x St2 = %2x\n", - ControllerExtension->St0, - ControllerExtension->St1, - ControllerExtension->St2); - - /* Update buffer info */ - Stack->Parameters.Read.ByteOffset.u.LowPart += ControllerExtension->TransferLength; - Stack->Parameters.Read.Length -= ControllerExtension->TransferLength; - - /* drivercontext used for current va */ - ControllerExtension->Irp->Tail.Overlay.DriverContext[0] = (PVOID) ((ULONG) ControllerExtension->Irp->Tail.Overlay.DriverContext[0] - + ControllerExtension->TransferLength); - DPRINT ("First ulong: %x\n", *((PULONG)ControllerExtension->MapRegisterBase)) - - /* If there is more IO to be done, restart execute routine to issue next read */ - if (Stack->Parameters.Read.Length != 0) - { - if (FloppyExecuteReadWrite (DeviceObject, - Irp, - ControllerExtension->MapRegisterBase, - Irp ) == DeallocateObject) - { - IoFreeController (Controller); - } - } - else - { - /* Otherwise, complete the IRP */ - IoCompleteRequest (Irp, - IO_NO_INCREMENT); - IoFreeController (Controller); - } -} - - -VOID STDCALL -FloppyDpcDetectMedia (PKDPC Dpc, - PDEVICE_OBJECT DeviceObject, - PIRP Irp, - PVOID Context) -{ - PCONTROLLER_OBJECT Controller; - PFLOPPY_CONTROLLER_EXTENSION ControllerExtension; - - Controller = (PCONTROLLER_OBJECT)Context; - ControllerExtension = (PFLOPPY_CONTROLLER_EXTENSION)Controller->ControllerExtension; - - /* If the read ID failed, fail the IRP */ - if (ControllerExtension->St1 != 0) - { - DPRINT1 ("Read ID failed: ST1 = %2x\n", ControllerExtension->St1); - IoFreeController (Controller); - Irp->IoStatus.Information = 0; - Irp->IoStatus.Status = STATUS_DEVICE_NOT_READY; - IoCompleteRequest (Irp, - IO_NO_INCREMENT); - return; - } - - /* Set media type, and restart the IRP from the beginning */ - ((PFLOPPY_DEVICE_EXTENSION)ControllerExtension->Device->DeviceExtension)->MediaType = 0; - DPRINT ("Media detected, restarting IRP\n"); - - /* Don't forget to free the controller so that the now queued routine may execute */ - IoFreeController (Controller); - - IoAllocateController (Controller, - DeviceObject, - FloppyExecuteReadWrite, - Irp); -} diff --git a/reactos/drivers/dd/floppy/floppy.c b/reactos/drivers/dd/floppy/floppy.c deleted file mode 100644 index 17ca0f6b2be..00000000000 --- a/reactos/drivers/dd/floppy/floppy.c +++ /dev/null @@ -1,609 +0,0 @@ -/* - * FLOPPY.C - NEC-765/8272A floppy device driver - * written by Rex Jolliff - * with help from various other sources, including but not limited to: - * Art Baker's NT Device Driver Book, Linux Source, and the internet. - * - * Modification History: - * 08/19/98 RJJ Created. - * 01/31/01 PJS Heavy rewrite, most of code thrown out - * - * To do: - * FIXME: get it working - * FIXME: add support for DMA hardware - * FIXME: should add support for floppy tape/zip devices - */ - -#include - -#include "floppy.h" -#define NDEBUG -#include -#include - -FLOPPY_CONTROLLER_PARAMETERS ControllerParameters[FLOPPY_MAX_CONTROLLERS] = -{ - {0x03f0, 6, 2, Latched} - // {0x0370, 6, 6, Latched} -}; - -const FLOPPY_MEDIA_TYPE MediaTypes[] = { - { 0x02, 80, 2, 18, 512 }, - { 0, 0, 0, 0, 0 } }; - -static BOOLEAN -FloppyCreateController(PDRIVER_OBJECT DriverObject, - PFLOPPY_CONTROLLER_PARAMETERS ControllerParameters, - int Index) -{ - PCONTROLLER_OBJECT ControllerObject; - PFLOPPY_CONTROLLER_EXTENSION ControllerExtension; - PFLOPPY_DEVICE_EXTENSION DeviceExtension; - UNICODE_STRING DeviceName; - NTSTATUS Status; - PDEVICE_OBJECT DeviceObject; -// PCONFIGURATION_INFORMATION ConfigInfo; - LARGE_INTEGER Timeout; -// BYTE Byte; -// int c; - PCONFIGURATION_INFORMATION Config; - DEVICE_DESCRIPTION DeviceDescription; - ULONG MaxMapRegs; - ULONG MappedIrq; - KIRQL Dirql; - KAFFINITY Affinity; - KIRQL oldIrql; - - /* FIXME: Register port ranges with HAL */ - MappedIrq = HalGetInterruptVector(Isa, - 0, - ControllerParameters->Vector, - ControllerParameters->Vector, - &Dirql, - &Affinity); - - /* Create controller object for FDC */ - ControllerObject = IoCreateController(sizeof(FLOPPY_CONTROLLER_EXTENSION)); - if (ControllerObject == NULL) - { - DPRINT("Could not create controller object for controller %d\n", - Index); - return FALSE; - } - - /* FIXME: fill out controller data */ - ControllerExtension = (PFLOPPY_CONTROLLER_EXTENSION) - ControllerObject->ControllerExtension; - ControllerExtension->Number = Index; - ControllerExtension->PortBase = ControllerParameters->PortBase; - ControllerExtension->Vector = MappedIrq; - KeInitializeEvent( &ControllerExtension->Event, SynchronizationEvent, FALSE ); - ControllerExtension->Device = 0; // no active device - ControllerExtension->Irp = 0; // no active IRP - /* Initialize the spin lock in the controller extension */ - KeInitializeSpinLock(&ControllerExtension->SpinLock); - ControllerExtension->IsrState = FloppyIsrDetect; - ControllerExtension->DpcState = FloppyDpcDetect; - - /* Register an interrupt handler for this controller */ - Status = IoConnectInterrupt(&ControllerExtension->Interrupt, - FloppyIsr, - ControllerObject, - &ControllerExtension->SpinLock, - MappedIrq, - Dirql, - Dirql, - ControllerParameters->InterruptMode, - FALSE, - Affinity, - FALSE); - if (!NT_SUCCESS(Status)) - { - DPRINT("Could not Connect Interrupt %d\n", - ControllerExtension->Vector); - goto controllercleanup; - } - - - /* setup DMA stuff for controller */ - DeviceDescription.Version = DEVICE_DESCRIPTION_VERSION; - DeviceDescription.Master = FALSE; - DeviceDescription.ScatterGather = FALSE; - DeviceDescription.AutoInitialize = FALSE; - DeviceDescription.Dma32BitAddresses = FALSE; - DeviceDescription.DmaChannel = ControllerParameters->DmaChannel; - DeviceDescription.InterfaceType = Isa; - // DeviceDescription.DmaWidth = Width8Bits; - ControllerExtension->AdapterObject = HalGetAdapter( &DeviceDescription, &MaxMapRegs ); - if( ControllerExtension->AdapterObject == NULL ) - { - DPRINT1( "Could not get adapter object\n" ); - goto interruptcleanup; - } - -#if 0 - /* Check for each possible drive and create devices for them */ - for (DriveIdx = 0; DriveIdx < FLOPPY_MAX_DRIVES; DriveIdx++) - { - /* FIXME: try to identify the drive */ - /* FIXME: create a device if it's there */ - } -#endif - - /* FIXME: Let's assume one drive and one controller for the moment */ - RtlRosInitUnicodeStringFromLiteral(&DeviceName, L"\\Device\\Floppy0"); - Status = IoCreateDevice(DriverObject, - sizeof(FLOPPY_DEVICE_EXTENSION), - &DeviceName, - FILE_DEVICE_DISK, - FILE_REMOVABLE_MEDIA | FILE_FLOPPY_DISKETTE, - FALSE, - &DeviceObject); - if (!NT_SUCCESS(Status)) - { - goto interruptcleanup; - } - DeviceExtension = (PFLOPPY_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - DeviceExtension->DriveSelect = 0; - DeviceExtension->Controller = ControllerObject; - DeviceExtension->MediaType = ~0; - ControllerExtension->MotorOn = ~0; - // set up DPC - ControllerExtension->Device = DeviceObject; - KeInitializeDpc( &ControllerExtension->MotorSpinupDpc, - FloppyMotorSpinupDpc, - ControllerObject ); - KeInitializeDpc( &ControllerExtension->MotorSpindownDpc, - FloppyMotorSpindownDpc, - ControllerObject ); - KeInitializeTimer( &ControllerExtension->SpinupTimer ); - IoInitializeDpcRequest( DeviceObject, FloppyDpc ); - // reset controller and wait for interrupt - DPRINT( "Controller Off\n" ); - FloppyWriteDOR( ControllerExtension->PortBase, 0 ); - // let controller reset for at least FLOPPY_RESET_TIME - KeStallExecutionProcessor( FLOPPY_RESET_TIME ); - DPRINT( "Controller On\n" ); - FloppyWriteDOR( ControllerExtension->PortBase, FLOPPY_DOR_ENABLE | FLOPPY_DOR_DMA ); - // wait for interrupt now - Timeout.QuadPart = -10000000; - Status = KeWaitForSingleObject( &ControllerExtension->Event, - Executive, - KernelMode, - FALSE, - &Timeout ); - if( Status != STATUS_WAIT_0 ) - { - DPRINT1( "Error: KeWaitForSingleObject returned: %x\n", Status ); - goto devicecleanup; - } - // set for high speed mode - // FloppyWriteCCNTL( ControllerExtension->PortBase, FLOPPY_CCNTL_1MBIT ); - // ok, so we have an FDC, now check for drives - // aparently the sense drive status command does not work on any FDC I can find - // so instead we will just have to assume a 1.44 meg 3.5 inch floppy. At some - // point we should get the bios disk parameters passed in to the kernel at boot - // and stored in the HARDWARE registry key for us to pick up here. - - // Issue SPECIFY command - FloppyWriteDATA (ControllerExtension->PortBase, FLOPPY_CMD_SPEC_CHARS); - KeStallExecutionProcessor (100); - FloppyWriteDATA (ControllerExtension->PortBase, 0xD1); - KeStallExecutionProcessor (100); - FloppyWriteDATA (ControllerExtension->PortBase, 0x02); - KeStallExecutionProcessor (10000); - FloppyWriteMSTAT (ControllerExtension->PortBase, 0x00); - - - // turn on motor, wait for spinup time, and recalibrate the drive - FloppyWriteDOR( ControllerExtension->PortBase, FLOPPY_DRIVE0_ON ); - Timeout.QuadPart = FLOPPY_MOTOR_SPINUP_TIME; - KeDelayExecutionThread( KernelMode, FALSE, &Timeout ); - DPRINT( "MSTAT: %2x\n", FloppyReadMSTAT( ControllerExtension->PortBase ) ); - FloppyWriteDATA( ControllerExtension->PortBase, FLOPPY_CMD_RECAL ); - DPRINT( "MSTAT: %2x\n", FloppyReadMSTAT( ControllerExtension->PortBase ) ); - KeStallExecutionProcessor( 10000 ); - FloppyWriteDATA( ControllerExtension->PortBase, 0 ); // drive select - Timeout.QuadPart = FLOPPY_RECAL_TIMEOUT; - Status = KeWaitForSingleObject( &ControllerExtension->Event, - Executive, - KernelMode, - FALSE, - &Timeout ); - if( Status != STATUS_WAIT_0 ) - { - DPRINT1( "Error: KeWaitForSingleObject returned: %x\n", Status ); - goto devicecleanup; - } - if( ControllerExtension->St0 != FLOPPY_ST0_SEEKGD ) - { - DbgPrint( "Floppy: error recalibrating drive, ST0: %2x\n", (DWORD)ControllerExtension->St0 ); - goto devicecleanup; - } - DeviceExtension->Cyl = 0; - // drive is good, and it is now on track 0, turn off the motor - FloppyWriteDOR( ControllerExtension->PortBase, FLOPPY_DOR_ENABLE | FLOPPY_DOR_DMA ); - /* Initialize the device */ - DeviceObject->Flags = DeviceObject->Flags | DO_DIRECT_IO; - DeviceObject->AlignmentRequirement = FILE_512_BYTE_ALIGNMENT; - // change state machine, no interrupt expected - ControllerExtension->IsrState = FloppyIsrUnexpected; - Config = IoGetConfigurationInformation(); - Config->FloppyCount++; - // call IoAllocateAdapterChannel, and wait for execution routine to be given the channel - CHECKPOINT; - - /* DDK: IoAllocateAdapterChannel _must_ be called at DISPATCH_LEVEL */ - KeRaiseIrql(DISPATCH_LEVEL, &oldIrql); - Status = IoAllocateAdapterChannel( ControllerExtension->AdapterObject, - DeviceObject, - 0x3000/PAGE_SIZE, // max track size is 12k - FloppyAdapterControl, - ControllerExtension ); - KeLowerIrql(oldIrql); - - if( !NT_SUCCESS( Status ) ) - { - DPRINT1( "Error: IoAllocateAdapterChannel returned %x\n", Status ); - goto devicecleanup; - } - CHECKPOINT; - Status = KeWaitForSingleObject( &ControllerExtension->Event, - Executive, - KernelMode, - FALSE, - &Timeout ); - CHECKPOINT; - if( Status != STATUS_WAIT_0 ) - { - DPRINT1( "Error: KeWaitForSingleObject returned: %x\n", Status ); - goto devicecleanup; - } - // Ok, we own the adapter object, from now on we can just IoMapTransfer, and not - // bother releasing the adapter ever. - - DPRINT( "Floppy drive initialized\n" ); - return TRUE; - - devicecleanup: - IoDeleteDevice( DeviceObject ); - interruptcleanup: - IoDisconnectInterrupt(ControllerExtension->Interrupt); - controllercleanup: - // turn off controller - FloppyWriteDOR( ControllerExtension->PortBase, 0 ); - IoDeleteController(ControllerObject); - return FALSE; -} - -IO_ALLOCATION_ACTION STDCALL -FloppyExecuteSpindown(PDEVICE_OBJECT DeviceObject, - PIRP Irp, - PVOID MapRegisterbase, - PVOID Context) -{ - PFLOPPY_CONTROLLER_EXTENSION ControllerExtension= (PFLOPPY_CONTROLLER_EXTENSION)Context; - - // turn off motor, and return - DPRINT( "Spinning down motor\n" ); - ControllerExtension->MotorOn = ~0; - FloppyWriteDOR( ControllerExtension->PortBase, - FLOPPY_DOR_ENABLE | FLOPPY_DOR_DMA ); - return DeallocateObject; -} - -IO_ALLOCATION_ACTION STDCALL -FloppyExecuteReadWrite(PDEVICE_OBJECT DeviceObject, - PIRP Irp, - PVOID MapRegisterbase, - PVOID Context) -{ - PFLOPPY_DEVICE_EXTENSION DeviceExtension = (PFLOPPY_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - PFLOPPY_CONTROLLER_EXTENSION ControllerExtension = (PFLOPPY_CONTROLLER_EXTENSION)DeviceExtension->Controller->ControllerExtension; - LARGE_INTEGER Timeout; - BOOLEAN WriteToDevice; - ULONG Cyl, Sector, Head; - PIO_STACK_LOCATION Stk; - ULONG Length; - - DPRINT( "FloppyExecuteReadWrite()\n" ); - - ControllerExtension->Irp = Irp = (PIRP)Context; - Stk = IoGetCurrentIrpStackLocation( Irp ); - ControllerExtension->Device = DeviceObject; - Timeout.QuadPart = FLOPPY_MOTOR_SPINUP_TIME; - CHECKPOINT; - WriteToDevice = Stk->MajorFunction == IRP_MJ_WRITE ? TRUE : FALSE; - // verify drive is spun up and selected - if( ControllerExtension->MotorOn != DeviceExtension->DriveSelect ) - { - // turn on and select drive, and allow it to spin up - // FloppyMotorSpinupDpc will restart this operation once motor is spun up - DPRINT( "Motor not on, turning it on now\n" ); - FloppyWriteDOR( ControllerExtension->PortBase, - DeviceExtension->DriveSelect ? FLOPPY_DRIVE1_ON : FLOPPY_DRIVE0_ON ); - // cancel possible spindown timer first - KeCancelTimer( &ControllerExtension->SpinupTimer ); - KeSetTimerEx( &ControllerExtension->SpinupTimer, - Timeout, - 0, - &ControllerExtension->MotorSpinupDpc ); - return KeepObject; - } - else - { - Timeout.QuadPart = FLOPPY_MOTOR_SPINDOWN_TIME; - // motor is already spinning, so reset the spindown timer - KeCancelTimer( &ControllerExtension->SpinupTimer ); - KeSetTimer( &ControllerExtension->SpinupTimer, - Timeout, - &ControllerExtension->MotorSpindownDpc ); - } -#if 0 - /* Handle disk change, doesn't work correctly */ - if( FloppyReadDIR( ControllerExtension->PortBase ) & FLOPPY_DI_DSKCHNG ) - { - // No disk is in the drive - DPRINT( "No disk is in the drive\n" ); - Irp->IoStatus.Status = STATUS_MEDIA_CHANGED; - Irp->IoStatus.Information = 0; - IoCompleteRequest( Irp, 0 ); - return DeallocateObject; - } -#endif - if( DeviceExtension->MediaType == ~0 ) - { - // media is in disk, but we have not yet detected what kind it is, - // so detect it now - // First, we need to recalibrate the drive though - ControllerExtension->IsrState = FloppyIsrRecal; - DPRINT( "Recalibrating drive\n" ); - KeStallExecutionProcessor( 1000 ); - FloppyWriteDATA( ControllerExtension->PortBase, FLOPPY_CMD_RECAL ); - KeStallExecutionProcessor( 1000 ); - FloppyWriteDATA( ControllerExtension->PortBase, DeviceExtension->DriveSelect ); - return KeepObject; - } - // looks like we have media in the drive.... do the read - // first, calculate geometry for read - Sector = Stk->Parameters.Read.ByteOffset.u.LowPart / MediaTypes[DeviceExtension->MediaType].BytesPerSector; - // absolute sector right now - Cyl = Sector / MediaTypes[DeviceExtension->MediaType].SectorsPerTrack; - DPRINT( "Sector = %x, Offset = %x, Cyl = %x, Heads = %x MediaType = %x\n", Sector, Stk->Parameters.Read.ByteOffset.u.LowPart, (DWORD)Cyl, (DWORD)MediaTypes[DeviceExtension->MediaType].Heads, (DWORD)DeviceExtension->MediaType ); - Head = Cyl % MediaTypes[DeviceExtension->MediaType].Heads; - DPRINT( "Head = %2x\n", Head ); - // convert absolute cyl to relative - Cyl /= MediaTypes[DeviceExtension->MediaType].Heads; - // convert absolute sector to relative - Sector %= MediaTypes[DeviceExtension->MediaType].SectorsPerTrack; - Sector++; // track relative sector numbers are 1 based, not 0 based - DPRINT( "Cyl = %2x, Head = %2x, Sector = %2x\n", Cyl, Head, Sector ); - - // seek if we need to seek - if( DeviceExtension->Cyl != Cyl ) - { - DPRINT( "Seeking...\n" ); - ControllerExtension->IsrState = FloppyIsrDetect; - ControllerExtension->DpcState = FloppySeekDpc; - FloppyWriteDATA( ControllerExtension->PortBase, FLOPPY_CMD_SEEK ); - KeStallExecutionProcessor( 100 ); - FloppyWriteDATA( ControllerExtension->PortBase, DeviceExtension->DriveSelect ); - KeStallExecutionProcessor( 100 ); - FloppyWriteDATA( ControllerExtension->PortBase, Cyl ); - return KeepObject; - } - //set up DMA and issue read command - Length = MediaTypes[DeviceExtension->MediaType].SectorsPerTrack - Sector + 1; - // number of sectors untill end of track - Length *= 512; // convert to bytes - if( Length > Stk->Parameters.Read.Length ) - Length = Stk->Parameters.Read.Length; - DPRINT( "Sector: %d, Length: %d\n", Sector, Length ); - ControllerExtension->TransferLength = Length; - IoMapTransfer( ControllerExtension->AdapterObject, - Irp->MdlAddress, - ControllerExtension->MapRegisterBase, - Irp->Tail.Overlay.DriverContext[0], // current va - &Length, - WriteToDevice ); - ControllerExtension->IsrState = FloppyIsrReadWrite; - ControllerExtension->DpcState = FloppyDpcReadWrite; - CHECKPOINT; - FloppyWriteDATA( ControllerExtension->PortBase, WriteToDevice ? FLOPPY_CMD_WRITE : FLOPPY_CMD_READ ); - KeStallExecutionProcessor( 100 ); - FloppyWriteDATA( ControllerExtension->PortBase, ( Head << 2 ) | DeviceExtension->DriveSelect ); - KeStallExecutionProcessor( 100 ); - FloppyWriteDATA( ControllerExtension->PortBase, Cyl ); - KeStallExecutionProcessor( 100 ); - FloppyWriteDATA( ControllerExtension->PortBase, Head ); - KeStallExecutionProcessor( 100 ); - FloppyWriteDATA( ControllerExtension->PortBase, Sector ); - KeStallExecutionProcessor( 100 ); - FloppyWriteDATA( ControllerExtension->PortBase, MediaTypes[DeviceExtension->MediaType].SectorSizeCode ); - KeStallExecutionProcessor( 100 ); - FloppyWriteDATA( ControllerExtension->PortBase, MediaTypes[DeviceExtension->MediaType].SectorsPerTrack ); - KeStallExecutionProcessor( 100 ); - FloppyWriteDATA( ControllerExtension->PortBase, 0 ); - KeStallExecutionProcessor( 100 ); - FloppyWriteDATA( ControllerExtension->PortBase, 0xFF ); - CHECKPOINT; - // eventually, the FDC will interrupt and we will read results then - return KeepObject; -} - - -NTSTATUS STDCALL -FloppyDispatchOpenClose (PDEVICE_OBJECT DeviceObject, - PIRP Irp) -{ - DPRINT ("FloppyDispatchOpenClose\n"); - return STATUS_SUCCESS; -} - - -NTSTATUS STDCALL -FloppyDispatchReadWrite (PDEVICE_OBJECT DeviceObject, - PIRP Irp) -{ - PFLOPPY_DEVICE_EXTENSION DeviceExtension; - PIO_STACK_LOCATION Stack; - KIRQL oldlvl; - - DeviceExtension = (PFLOPPY_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - - Stack = IoGetCurrentIrpStackLocation (Irp); - - if (Stack->Parameters.Read.ByteOffset.u.HighPart) - { - Irp->IoStatus.Status = STATUS_INVALID_PARAMETER; - Irp->IoStatus.Information = 0; - IoCompleteRequest (Irp, 1); - return STATUS_INVALID_PARAMETER; - } - - /* Store currentva in drivercontext */ - Irp->Tail.Overlay.DriverContext[0] = MmGetMdlVirtualAddress (Irp->MdlAddress); - DPRINT ("FloppyDispatchReadWrite: offset = %x, length = %x, va = %x\n", - Stack->Parameters.Read.ByteOffset.u.LowPart, - Stack->Parameters.Read.Length, - Irp->Tail.Overlay.DriverContext[0]); - - /* Queue IRP */ - Irp->IoStatus.Status = STATUS_SUCCESS; - Irp->IoStatus.Information = Stack->Parameters.Read.Length; - IoMarkIrpPending (Irp); - - KeRaiseIrql (DISPATCH_LEVEL, - &oldlvl); - IoAllocateController (DeviceExtension->Controller, - DeviceObject, - FloppyExecuteReadWrite, - Irp); - KeLowerIrql (oldlvl); - - DPRINT( "oldlvl = %x\n", oldlvl ); - - return STATUS_PENDING; -} - - -IO_ALLOCATION_ACTION STDCALL -FloppyAdapterControl (PDEVICE_OBJECT DeviceObject, - PIRP Irp, - PVOID MapRegisterBase, - PVOID Context) -{ - PFLOPPY_CONTROLLER_EXTENSION ControllerExtension; - - ControllerExtension = (PFLOPPY_CONTROLLER_EXTENSION)Context; - CHECKPOINT; - - /* Just set the event, and return KeepObject */ - ControllerExtension->MapRegisterBase = MapRegisterBase; - KeSetEvent (&ControllerExtension->Event, - 0, - FALSE); - - return KeepObject; -} - - -NTSTATUS STDCALL -FloppyDispatchDeviceControl (PDEVICE_OBJECT DeviceObject, - PIRP Irp) -{ - PIO_STACK_LOCATION Stack; - ULONG ControlCode; - ULONG InputLength; - ULONG OutputLength; - NTSTATUS Status; - - DPRINT ("FloppyDispatchDeviceControl\n"); - - Stack = IoGetCurrentIrpStackLocation(Irp); - ControlCode = Stack->Parameters.DeviceIoControl.IoControlCode; - InputLength = Stack->Parameters.DeviceIoControl.InputBufferLength; - OutputLength = Stack->Parameters.DeviceIoControl.OutputBufferLength; - - switch (ControlCode) - { - case IOCTL_DISK_GET_DRIVE_GEOMETRY: - if (OutputLength < sizeof(DISK_GEOMETRY)) - { - Status = STATUS_INVALID_PARAMETER; - } - else - { - PDISK_GEOMETRY Geometry = Irp->AssociatedIrp.SystemBuffer; - - // FIXME: read the first sector of the diskette - Geometry->MediaType = F3_1Pt44_512; - Geometry->Cylinders.QuadPart = 80; - Geometry->TracksPerCylinder = 2 * 18; - Geometry->SectorsPerTrack = 18; - Geometry->BytesPerSector = 512; - Status = STATUS_SUCCESS; - Irp->IoStatus.Information = sizeof(DISK_GEOMETRY); - } - break; - - default: - Status = STATUS_INVALID_DEVICE_REQUEST; - Irp->IoStatus.Information = 0; - break; - } - - Irp->IoStatus.Status = Status; - IoCompleteRequest (Irp, - NT_SUCCESS(Status) ? IO_DISK_INCREMENT : IO_NO_INCREMENT); - - return Status; -} - - -/* - * DriverEntry - * - * DESCRIPTION: - * This function initializes the driver, locates and claims - * hardware resources, and creates various NT objects needed - * to process I/O requests. - * - * RUN LEVEL: - * PASSIVE_LEVEL - * - * ARGUMENTS: - * IN PDRIVER_OBJECT DriverObject System allocated Driver Object - * for this driver - * IN PUNICODE_STRING RegistryPath Name of registry driver service - * key - * - * RETURNS: - * NTSTATUS - */ -NTSTATUS STDCALL -DriverEntry (IN PDRIVER_OBJECT DriverObject, - IN PUNICODE_STRING RegistryPath) -{ - DPRINT ("Floppy driver\n"); - - /* Export other driver entry points... */ - DriverObject->MajorFunction[IRP_MJ_CREATE] = FloppyDispatchOpenClose; - DriverObject->MajorFunction[IRP_MJ_CLOSE] = FloppyDispatchOpenClose; - DriverObject->MajorFunction[IRP_MJ_READ] = FloppyDispatchReadWrite; - DriverObject->MajorFunction[IRP_MJ_WRITE] = FloppyDispatchReadWrite; - DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = FloppyDispatchDeviceControl; - - /* Try to detect controller and abort if it fails */ - if (!FloppyCreateController (DriverObject, - &ControllerParameters[0], - 0)) - { - DPRINT ("Could not find floppy controller\n"); - return STATUS_NO_SUCH_DEVICE; - } - - return STATUS_SUCCESS; -} - -/* EOF */ diff --git a/reactos/drivers/dd/floppy/floppy.h b/reactos/drivers/dd/floppy/floppy.h deleted file mode 100644 index 165e8b5d685..00000000000 --- a/reactos/drivers/dd/floppy/floppy.h +++ /dev/null @@ -1,258 +0,0 @@ -// -// Floppy register definitions -// - -#define FLOPPY_REG_DOR 0x0002 -#define FLOPPY_DOR_ENABLE 0x04 -#define FLOPPY_DOR_DMA 0x08 -#define FLOPPY_DOR_MOTOR0 0x10 -#define FLOPPY_DOR_MOTOR1 0x20 -#define FLOPPY_DRIVE0_ON ( FLOPPY_DOR_ENABLE | FLOPPY_DOR_DMA | FLOPPY_DOR_MOTOR0 ) -#define FLOPPY_DRIVE1_ON ( FLOPPY_DOR_ENABLE | FLOPPY_DOR_DMA | FLOPPY_DOR_MOTOR1 | 1 ) -#define FLOPPY_REG_MSTAT 0x0004 -#define FLOPPY_MS_DRV0BUSY 0x01 -#define FLOPPY_MS_DRV1BUSY 0x02 -#define FLOPPY_MS_DRV2BUSY 0x04 -#define FLOPPY_MS_DRV3BUSY 0x08 -#define FLOPPY_MS_FDCBUSY 0x10 -#define FLOPPY_MS_DMAMODE 0x20 -#define FLOPPY_MS_DATADIR 0x40 -#define FLOPPY_MS_RDYMASK 0xC0 -#define FLOPPY_MS_DATARDYW 0x80 -#define FLOPPY_MS_DATARDYR 0xC0 -#define FLOPPY_REG_DATA 0x0005 -#define FLOPPY_REG_DIR 0x0007 /* READ ONLY */ -#define FLOPPY_DI_DSKCHNG 0x80 -#define FLOPPY_REG_CCNTL 0x0007 /* WRITE ONLY */ -#define FLOPPY_CCNTL_1MBIT 0x03 - -#define FLOPPY_CMD_RD_TRK 0x02 -#define FLOPPY_CMD_SPEC_CHARS 0x03 -#define FLOPPY_CSC_SRT_SHIFT 4 -#define FLOPPY_CSC_HUT_MASK 0x0f -#define FLOPPY_CSC_HLT_SHIFT 1 -#define FLOPPY_CSC_NON_DMA 0x01 -#define FLOPPY_CMD_SNS_DRV 0x04 -#define FLOPPY_CMD_WRT_DATA 0x05 -#define FLOPPY_CMD_RD_DATA 0x06 -#define FLOPPY_CMD_RECAL 0x07 -#define FLOPPY_CMD_SNS_INTR 0x08 -#define FLOPPY_ST0_SEEKGD 0x20 -#define FLOPPY_ST0_GDMASK 0xd8 -#define FLOPPY_CMD_WRT_DEL 0x09 -#define FLOPPY_CMD_RD_ID 0x0a -#define FLOPPY_CMD_RD_DEL 0x0c -#define FLOPPY_CMD_FMT_TRK 0x0d -#define FLOPPY_CMD_DUMP_FDC 0x0e -#define FLOPPY_CMD_SEEK 0x0f -#define FLOPPY_CMD_VERSION 0x10 -#define FLOPPY_CMD_SCN_EQ 0x11 -#define FLOPPY_CMD_PPND_RW 0x12 -#define FLOPPY_CMD_CFG_FIFO 0x13 -#define FLOPPY_CMD_LCK_FIFO 0x14 -#define FLOPPY_CMD_PARTID 0x18 -#define FLOPPY_CMD_SCN_LE 0x19 -#define FLOPPY_CMD_SCN_GE 0x1d -#define FLOPPY_CMD_CFG_PWR 0x27 -#define FLOPPY_CMD_SAVE_FDC 0x2e -#define FLOPPY_CMD_FMT_ISO 0x33 -#define FLOPPY_CMD_DMA_READ 0x46 -#define FLOPPY_CMD_DMA_WRT 0x4a -#define FLOPPY_CMD_REST_FDC 0x4e -#define FLOPPY_CMD_DRV_SPEC 0x8e -#define FLOPPY_CMD_RSEEK_OUT 0x8f -#define FLOPPY_CMD_ULK_FIFO 0x94 -#define FLOPPY_CMD_RSEEK_IN 0xcf -#define FLOPPY_CMD_FMT_WRT 0xef - -// Command Code modifiers -#define FLOPPY_C0M_SK 0x20 -#define FLOPPY_C0M_MFM 0x40 -#define FLOPPY_C0M_MT 0x80 -#define FLOPPY_C1M_DRVMASK 0x03 -#define FLOPPY_C1M_HEAD1 0x04 - -// Status code values and masks -#define FLOPPY_ST0_INVALID 0x80 - -// useful command defines -#define FLOPPY_CMD_READ (FLOPPY_CMD_RD_DATA | FLOPPY_C0M_SK | FLOPPY_C0M_MFM | FLOPPY_C0M_MT) -#define FLOPPY_CMD_WRITE (FLOPPY_CMD_WRT_DATA | FLOPPY_C0M_MFM | FLOPPY_C0M_MT) -#define FLOPPY_CMD_FORMAT (FLOPPY_CMD_FMT_TRK | FLOPPY_C0M_MFM) - -// -// HAL floppy register access commands -// -#define FloppyWriteDOR(A, V) (WRITE_PORT_UCHAR((PVOID)(A) + FLOPPY_REG_DOR, (V))) -#define FloppyReadMSTAT(A) (READ_PORT_UCHAR((PVOID)(A) + FLOPPY_REG_MSTAT)) -#define FloppyWriteMSTAT(A, V) (WRITE_PORT_UCHAR((PVOID)(A) + FLOPPY_REG_MSTAT, (V))) -#define FloppyReadDATA(A) (READ_PORT_UCHAR((PVOID)(A) + FLOPPY_REG_DATA)) -#define FloppyWriteDATA(A, V) (WRITE_PORT_UCHAR((PVOID)(A) + FLOPPY_REG_DATA, (V))) -#define FloppyReadDIR(A) (READ_PORT_UCHAR((PVOID)(A) + FLOPPY_REG_DIR)) -#define FloppyWriteCCNTL(A, V) (WRITE_PORT_UCHAR((PVOID)(A) + FLOPPY_REG_CCNTL, (V))) - -typedef struct _FLOPPY_ERROR_THRESHOLDS -{ - /* number of errors to be reached before aborting */ - unsigned int Abort; - /* maximal number of errors permitted to read an entire track at once */ - unsigned int ReadTrack; - /* maximal number of errors before a reset is tried */ - unsigned int Reset; - /* maximal number of errors before a recalibrate is tried */ - unsigned int Recal; - /* - * Threshold for reporting FDC errors to the console. - * Setting this to zero may flood your screen when using - * ultra cheap floppies ;-) - */ - unsigned int Reporting; -} FLOPPY_ERROR_THRESHOLDS; - -typedef struct _FLOPPY_MEDIA_TYPE -{ - BYTE SectorSizeCode; - BYTE MaximumTrack; - BYTE Heads; - DWORD SectorsPerTrack; - ULONG BytesPerSector; -} FLOPPY_MEDIA_TYPE; - -extern const FLOPPY_MEDIA_TYPE MediaTypes[]; - -#define FDP_DEBUG 0x02 -#define FDP_SILENT_DCL_CLEAR 0x04 -#define FDP_MSG 0x10 -#define FDP_BROKEN_DCL 0x20 -#define FDP_INVERTED_DCL 0x80 - -// time to hold reset line low -#define FLOPPY_RESET_TIME 50000 -#define FLOPPY_MOTOR_SPINUP_TIME -15000000 -#define FLOPPY_MOTOR_SPINDOWN_TIME -50000000 -#define FLOPPY_RECAL_TIMEOUT -30000000 - -typedef BOOLEAN (*FloppyIsrStateRoutine)( PCONTROLLER_OBJECT Controller ); -typedef PIO_DPC_ROUTINE FloppyDpcStateRoutine; - -typedef struct _FLOPPY_DEVICE_EXTENSION -{ - PCONTROLLER_OBJECT Controller; - CHAR DriveSelect; - CHAR Cyl; // current cylinder - ULONG MediaType; // Media type index -} FLOPPY_DEVICE_EXTENSION, *PFLOPPY_DEVICE_EXTENSION; - -typedef struct _FLOPPY_CONTROLLER_EXTENSION -{ - PKINTERRUPT Interrupt; - KSPIN_LOCK SpinLock; - ULONG Number; - ULONG PortBase; - ULONG Vector; - KEVENT Event; // Event set by ISR/DPC to wake DeviceEntry - PDEVICE_OBJECT Device; // Pointer to the primary device on this controller - PIRP Irp; // Current IRP - CHAR St0; // Status registers - CHAR St1; - CHAR St2; - CHAR SectorSizeCode; - FloppyIsrStateRoutine IsrState; // pointer to state routine handler for ISR - FloppyDpcStateRoutine DpcState; // pointer to state routine handler for DPC - CHAR MotorOn; // drive select for drive with motor on - KDPC MotorSpinupDpc; // DPC for motor spin up time - KTIMER SpinupTimer; // Timer for motor spin up time - KDPC MotorSpindownDpc; // DPC for motor spin down - PADAPTER_OBJECT AdapterObject; // Adapter object for dma - PVOID MapRegisterBase; - DWORD TransferLength; // Length of the transfer -} FLOPPY_CONTROLLER_EXTENSION, *PFLOPPY_CONTROLLER_EXTENSION; - -typedef struct _FLOPPY_CONTROLLER_PARAMETERS -{ - ULONG PortBase; - ULONG Vector; - ULONG DmaChannel; - KINTERRUPT_MODE InterruptMode; -} FLOPPY_CONTROLLER_PARAMETERS, *PFLOPPY_CONTROLLER_PARAMETERS; - -#define FLOPPY_MAX_CONTROLLERS 1 - -VOID STDCALL -FloppyDpcDetectMedia(PKDPC Dpc, - PDEVICE_OBJECT DeviceObject, - PIRP Irp, - PVOID Context); -VOID STDCALL -FloppyDpcFailIrp(PKDPC Dpc, - PDEVICE_OBJECT DeviceObject, - PIRP Irp, - PVOID Context); - -IO_ALLOCATION_ACTION STDCALL -FloppyExecuteReadWrite(PDEVICE_OBJECT DeviceObject, - PIRP Irp, - PVOID MapRegisterbase, - PVOID Context); - -IO_ALLOCATION_ACTION STDCALL -FloppyExecuteSpindown(PDEVICE_OBJECT DeviceObject, - PIRP Irp, - PVOID MapRegisterbase, - PVOID Context); - -VOID STDCALL -FloppyMotorSpinupDpc(PKDPC Dpc, - PVOID Context, - PVOID Arg1, - PVOID Arg2); - -VOID STDCALL -FloppySeekDpc(PKDPC Dpc, - PDEVICE_OBJECT DeviceObject, - PIRP Irp, - PVOID Context); - -VOID STDCALL -FloppyMotorSpindownDpc(PKDPC Dpc, - PVOID Context, - PVOID Arg1, - PVOID Arg2); - -VOID STDCALL -FloppyDpcDetect(PKDPC Dpc, - PDEVICE_OBJECT DeviceObject, - PIRP Irp, - PVOID Context ); - -VOID STDCALL -FloppyDpcReadWrite(PKDPC Dpc, - PDEVICE_OBJECT DeviceObject, - PIRP Irp, - PVOID Context); - -VOID STDCALL -FloppyDpc(PKDPC Dpc, - PDEVICE_OBJECT DeviceObject, - PIRP Irp, - PVOID Context); - -BOOLEAN FloppyIsrDetect( PCONTROLLER_OBJECT Controller ); - -BOOLEAN FloppyIsrReadWrite( PCONTROLLER_OBJECT Controller ); - -BOOLEAN FloppyIsrUnexpected( PCONTROLLER_OBJECT Controller ); - -BOOLEAN FloppyIsrDetectMedia( PCONTROLLER_OBJECT Controller ); - -BOOLEAN FloppyIsrRecal( PCONTROLLER_OBJECT Controller ); - -BOOLEAN STDCALL -FloppyIsr(PKINTERRUPT Interrupt, - PVOID ServiceContext); - -IO_ALLOCATION_ACTION STDCALL -FloppyAdapterControl(PDEVICE_OBJECT DeviceObject, - PIRP Irp, - PVOID MapRegisterBase, - PVOID Context); diff --git a/reactos/drivers/dd/floppy/floppy.rc b/reactos/drivers/dd/floppy/floppy.rc deleted file mode 100644 index fd1d0e353a8..00000000000 --- a/reactos/drivers/dd/floppy/floppy.rc +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include - -LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US - -VS_VERSION_INFO VERSIONINFO - FILEVERSION RES_UINT_FV_MAJOR,RES_UINT_FV_MINOR,RES_UINT_FV_REVISION,RES_UINT_FV_BUILD - PRODUCTVERSION RES_UINT_PV_MAJOR,RES_UINT_PV_MINOR,RES_UINT_PV_REVISION,RES_UINT_PV_BUILD - FILEFLAGSMASK 0x3fL -#ifdef _DEBUG - FILEFLAGS 0x1L -#else - FILEFLAGS 0x0L -#endif - FILEOS 0x40004L - FILETYPE 0x2L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904b0" - BEGIN - VALUE "CompanyName", RES_STR_COMPANY_NAME - VALUE "FileDescription", "Floppy Device Driver\0" - VALUE "FileVersion", "0.1.4\0" - VALUE "InternalName", "floppy\0" - VALUE "LegalCopyright", RES_STR_LEGAL_COPYRIGHT - VALUE "OriginalFilename", "floppy.sys\0" - VALUE "ProductName", RES_STR_PRODUCT_NAME - VALUE "ProductVersion", RES_STR_PRODUCT_VERSION - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1200 - END -END - diff --git a/reactos/drivers/dd/floppy/isr.c b/reactos/drivers/dd/floppy/isr.c deleted file mode 100644 index ce2b8eec778..00000000000 --- a/reactos/drivers/dd/floppy/isr.c +++ /dev/null @@ -1,210 +0,0 @@ -/************************************************************************ - * Interrupt handlers for floppy disk driver, reactos project, created * - * by Phillip Susi on 2/25/2001. This software is publised under the * - * GNU General public license. See the README file for more details * - ***********************************************************************/ - -#include -#define NDEBUG -#include -#include "floppy.h" - - -// ISR state machine function called when expecting an interrupt due to reset -// During reset, there is nothing ready to read, just issue sense interrupt status - -BOOLEAN FloppyIsrDetect( PCONTROLLER_OBJECT Controller ) -{ - PFLOPPY_CONTROLLER_EXTENSION ControllerExtension = (PFLOPPY_CONTROLLER_EXTENSION)Controller->ControllerExtension; - PFLOPPY_DEVICE_EXTENSION DeviceExtension = (PFLOPPY_DEVICE_EXTENSION)ControllerExtension->Device->DeviceExtension; - // Issue read interrupt status, and store the results - FloppyWriteDATA( ControllerExtension->PortBase, FLOPPY_CMD_SNS_INTR ); - KeStallExecutionProcessor( 100 ); - ControllerExtension->St0 = FloppyReadDATA( ControllerExtension->PortBase ); - KeStallExecutionProcessor( 100 ); - DeviceExtension->Cyl = FloppyReadDATA( ControllerExtension->PortBase ); - KeStallExecutionProcessor( 100 ); - if (FLOPPY_MS_DATARDYR == - (FloppyReadMSTAT( ControllerExtension->PortBase ) & FLOPPY_MS_RDYMASK)) - { - /* There's something still to be read (what is it???? only happens on some - controllers). Ignore it. */ - (void) FloppyReadDATA( ControllerExtension->PortBase ); - } - // now queue DPC to set the event - IoRequestDpc( ControllerExtension->Device, - 0, - Controller ); - return TRUE; -} - -// ISR state machine handler for unexpected interrupt -BOOLEAN FloppyIsrUnexpected( PCONTROLLER_OBJECT Controller ) -{ - DPRINT( "Unexpected interrupt!\n" ); - return FALSE; -} - -BOOLEAN FloppyIsrDetectMedia( PCONTROLLER_OBJECT Controller ) -{ - PFLOPPY_CONTROLLER_EXTENSION ControllerExtension = (PFLOPPY_CONTROLLER_EXTENSION)Controller->ControllerExtension; - UCHAR SectorSize; - - DPRINT("FloppyIsrDetectMedia() called\n"); - - // media detect in progress, read ID command already issued - // first, read result registers - KeStallExecutionProcessor( 1000 ); - ControllerExtension->St0 = FloppyReadDATA( ControllerExtension->PortBase ); - KeStallExecutionProcessor( 1000 ); - ControllerExtension->St1 = FloppyReadDATA( ControllerExtension->PortBase ); - KeStallExecutionProcessor( 1000 ); - ControllerExtension->St2 = FloppyReadDATA( ControllerExtension->PortBase ); - KeStallExecutionProcessor( 1000 ); - FloppyReadDATA( ControllerExtension->PortBase ); // ignore cyl - KeStallExecutionProcessor( 1000 ); - FloppyReadDATA( ControllerExtension->PortBase ); // ignore head - KeStallExecutionProcessor( 1000 ); - FloppyReadDATA( ControllerExtension->PortBase ); // ignore sector - KeStallExecutionProcessor( 1000 ); - SectorSize = FloppyReadDATA( ControllerExtension->PortBase ); - DPRINT( "Sector Size Code: %2x\n", SectorSize ); - DPRINT( "St0 = %2x, St1 = %2x, St2 = %2x\n", ControllerExtension->St0, ControllerExtension->St1, ControllerExtension->St2 ); - DPRINT( "ControllerExtension->Device = %x, ControllerExtension->Irp = %x\n", ControllerExtension->Device, ControllerExtension->Irp ); - // queue DPC - ControllerExtension->DpcState = FloppyDpcDetectMedia; - IoRequestDpc( ControllerExtension->Device, - ControllerExtension->Irp, - Controller ); - return TRUE; -} - -BOOLEAN FloppyIsrRecal( PCONTROLLER_OBJECT Controller ) -{ - PFLOPPY_CONTROLLER_EXTENSION ControllerExtension = (PFLOPPY_CONTROLLER_EXTENSION)Controller->ControllerExtension; - // issue sense interrupt status, and read St0 and cyl - - DPRINT("FloppyIsrRecal() called\n"); - - FloppyWriteDATA( ControllerExtension->PortBase, FLOPPY_CMD_SNS_INTR ); - KeStallExecutionProcessor( 1000 ); - ControllerExtension->St0 = FloppyReadDATA( ControllerExtension->PortBase ); - KeStallExecutionProcessor( 1000 ); - FloppyReadDATA( ControllerExtension->PortBase ); // ignore cyl number - if (FLOPPY_MS_DATARDYR == - (FloppyReadMSTAT( ControllerExtension->PortBase ) & FLOPPY_MS_RDYMASK)) - { - /* There's something still to be read (what is it???? only happens on some - controllers). Ignore it. */ - (void) FloppyReadDATA( ControllerExtension->PortBase ); - } - DPRINT( "Recal St0: %2x\n", ControllerExtension->St0 ); - - // If recalibrate worked, issue read ID for each media type untill one works - if ( ControllerExtension->St0 != FLOPPY_ST0_SEEKGD ) - { - DPRINT( "Recalibrate failed, ST0 = %2x\n", ControllerExtension->St0 ); - // queue DPC to fail IRP - ControllerExtension->DpcState = FloppyDpcFailIrp; - IoRequestDpc( ControllerExtension->Device, - ControllerExtension->Irp, - Controller ); - } - else - { - // issue first read id, FloppyIsrDetectMedia will handle - DPRINT( "Recalibrate worked, issuing read ID mark command\n" ); - ControllerExtension->IsrState = FloppyIsrDetectMedia; - KeStallExecutionProcessor( 1000 ); - FloppyWriteDATA( ControllerExtension->PortBase, FLOPPY_CMD_RD_ID | FLOPPY_C0M_MFM ); - KeStallExecutionProcessor( 1000 ); - FloppyWriteDATA( ControllerExtension->PortBase, ((PFLOPPY_DEVICE_EXTENSION)ControllerExtension->Device->DeviceExtension)->DriveSelect ); - } - - return TRUE; -} - -BOOLEAN FloppyIsrReadWrite( PCONTROLLER_OBJECT Controller ) -{ - // read result registers from read or write command, and queue dpc to start next operation - PFLOPPY_CONTROLLER_EXTENSION ControllerExtension = (PFLOPPY_CONTROLLER_EXTENSION)Controller->ControllerExtension; - UCHAR Cyl; - UCHAR Head; - UCHAR Sector; -// PFLOPPY_DEVICE_EXTENSION DeviceExtension = (PFLOPPY_DEVICE_EXTENSION)ControllerExtension->Device->DeviceExtension; -// PIO_STACK_LOCATION Stk = IoGetCurrentIrpStackLocation( ControllerExtension->Irp ); -// BOOLEAN WriteToDevice = Stk->MajorFunction == IRP_MJ_WRITE ? TRUE : FALSE; - - - ControllerExtension->St0 = FloppyReadDATA( ControllerExtension->PortBase ); - KeStallExecutionProcessor( 100 ); - ControllerExtension->St1 = FloppyReadDATA( ControllerExtension->PortBase ); - KeStallExecutionProcessor( 100 ); - ControllerExtension->St2 = FloppyReadDATA( ControllerExtension->PortBase ); - KeStallExecutionProcessor( 100 ); - Cyl = FloppyReadDATA( ControllerExtension->PortBase ); // cyl - KeStallExecutionProcessor( 100 ); - Head = FloppyReadDATA( ControllerExtension->PortBase ); // head - KeStallExecutionProcessor( 100 ); - Sector = FloppyReadDATA( ControllerExtension->PortBase ); // sector - KeStallExecutionProcessor( 100 ); - ControllerExtension->SectorSizeCode = FloppyReadDATA( ControllerExtension->PortBase ); - - // reprogam for next sector if we are not done reading track - /* if( ( ControllerExtension->TransferLength -= ( 128 << ControllerExtension->SectorSizeCode ) ) ) - { - DPRINT1( "ISR reprogramming for next sector: %d\n", Sector ); - Sector++; - FloppyWriteDATA( ControllerExtension->PortBase, WriteToDevice ? FLOPPY_CMD_WRITE : FLOPPY_CMD_READ ); - KeStallExecutionProcessor( 100 ); - FloppyWriteDATA( ControllerExtension->PortBase, ( Head << 2 ) | DeviceExtension->DriveSelect ); - KeStallExecutionProcessor( 100 ); - FloppyWriteDATA( ControllerExtension->PortBase, Cyl ); - KeStallExecutionProcessor( 100 ); - FloppyWriteDATA( ControllerExtension->PortBase, Head ); - KeStallExecutionProcessor( 100 ); - FloppyWriteDATA( ControllerExtension->PortBase, Sector ); - KeStallExecutionProcessor( 100 ); - FloppyWriteDATA( ControllerExtension->PortBase, ControllerExtension->SectorSizeCode ); - KeStallExecutionProcessor( 100 ); - FloppyWriteDATA( ControllerExtension->PortBase, MediaTypes[DeviceExtension->MediaType].SectorsPerTrack ); - KeStallExecutionProcessor( 100 ); - FloppyWriteDATA( ControllerExtension->PortBase, 0 ); - KeStallExecutionProcessor( 100 ); - FloppyWriteDATA( ControllerExtension->PortBase, 0xFF ); - } - else */IoRequestDpc( ControllerExtension->Device, - ControllerExtension->Irp, - Controller ); - return TRUE; -} - - -// actual ISR, passes controll to handler for current state in state machine - -BOOLEAN STDCALL -FloppyIsr (PKINTERRUPT Interrupt, - PVOID ServiceContext) -{ - PCONTROLLER_OBJECT Controller; - PFLOPPY_CONTROLLER_EXTENSION ControllerExtension; - UCHAR Byte; - - Controller = (PCONTROLLER_OBJECT)ServiceContext; - ControllerExtension = (PFLOPPY_CONTROLLER_EXTENSION)Controller->ControllerExtension; - - // need to make sure interrupt is for us, and add some delay for the damn FDC - // without the delay, even though the thing has interrupted, it's still not ready - // for us to read the data register. - KeStallExecutionProcessor( 100 ); - Byte = FloppyReadMSTAT( ControllerExtension->PortBase ); - KeStallExecutionProcessor( 100 ); - if( Byte == 0 ) - { - DPRINT( "Ignoring interrupt, MSTAT = 0\n" ); - return TRUE; - } - return ControllerExtension->IsrState( Controller ); -} - -/* EOF */ diff --git a/reactos/drivers/dd/ide/.cvsignore b/reactos/drivers/dd/ide/.cvsignore deleted file mode 100644 index 5f6c85b86cb..00000000000 --- a/reactos/drivers/dd/ide/.cvsignore +++ /dev/null @@ -1,8 +0,0 @@ -*.tmp -*.exp -*.coff -*.d -*.o -*.sym -*.sys -*.map diff --git a/reactos/drivers/dd/ide/ide.c b/reactos/drivers/dd/ide/ide.c deleted file mode 100644 index f02e57f216e..00000000000 --- a/reactos/drivers/dd/ide/ide.c +++ /dev/null @@ -1,2268 +0,0 @@ -/* $Id: ide.c,v 1.61 2004/05/07 05:12:10 royce Exp $ - * - * IDE.C - IDE Disk driver - * written by Rex Jolliff - * with help from various documentation sources and a few peeks at - * linux and freebsd sources. - * - * This driver supports PCI controllers and up to 4 ISA controllers - * with up to 2 drives each. - * The device names are assigned as follows: - * \Devices\HarddiskX\Partition0 - * for the raw device, and - * \Devices\HarddiskX\PartitionY - * for partitions - * where: - * X is computed by counting the available drives from the following - * sequence: the controller number (0=0x1f0, 1=0x170, 2=0x1e8, - * 3=0x168) * 2 plus the drive number (0,1) - * Y is the partition number - * - * The driver exports the following function: - * - * DriverEntry() - NT device driver initialization routine - * - * And the following functions are exported implicitly: - * - * IDEStartIo() - called to start an I/O request packet - * IDEDispatchOpenClose() - Called to open/close the device. a NOOP - * IDEDispatchReadWrite() - Called to read/write the device. - * IDEDispatchQueryInformation() - Called to get device information - * IDEDispatchSetInformation() - Called to set device information - * IDEDispatchDeviceControl() - Called to execute device control requests - * - * Modification History: - * 05/25/98 RJJ Created. - * 05/30/98 RJJ Removed IRQ handler and inserted busy waits - * just to get something working... - * 07/18/98 RJJ Made drastic changes so that the driver - * resembles a WinNT driver. - * 08/05/98 RJJ Changed to .C extension - * 09/19/98 RJJ First release (run for cover!) - * - * Test List: - * 09/17/98 RJJ Pri/MST: 14.12X19 WDC AC31000H Test Passed - * Pri/SLV: None. - * - * - * To Do: - * FIXME: a timer should be used to watch for device timeouts and errors - * FIXME: errors should be retried - * FIXME: a drive reset/recalibrate should be attempted if errors occur - * FIXME: Use DMA for transfers if drives support it - * FIXME: should we support unloading of this driver??? - * FIXME: the device information should come from AUTODETECT (via registry) - * FIXME: really big devices need to be handled correctly - * FIXME: should get device info from the registry - * FIXME: should report hardware usage to iomgr - * FIXME: finish implementation of QueryInformation - * FIXME: finish implementation of SetInformation - * FIXME: finish implementation of DeviceControl - * FIXME: bring up to ATA-3 spec - * FIXME: add general support for ATAPI devices - * FIXME: add support for ATAPI CDROMs - * FIXME: add support for ATAPI ZIP drives/RHDs - * FIXME: add support for ATAPI tape drives - */ - -// ------------------------------------------------------------------------- - -#include - -#define NDEBUG -#include - -#include "ide.h" -#include "partitio.h" - -#define VERSION "V0.1.5" - -/* uncomment the following line to enable the secondary ide channel */ -//#define ENABLE_SECONDARY_IDE_CHANNEL - -// ------------------------------------------------------- File Static Data - - -typedef struct _IDE_CONTROLLER_PARAMETERS -{ - int CommandPortBase; - int CommandPortSpan; - int ControlPortBase; - int ControlPortSpan; - int Vector; - KINTERRUPT_MODE InterruptMode; -} IDE_CONTROLLER_PARAMETERS, *PIDE_CONTROLLER_PARAMETERS; - -// NOTE: Do not increase max drives above 2 - -#define IDE_MAX_DRIVES 2 - -#define IDE_MAX_CONTROLLERS 2 -IDE_CONTROLLER_PARAMETERS Controllers[IDE_MAX_CONTROLLERS] = -{ - {0x01f0, 8, 0x03f6, 1, 14, Latched}, - {0x0170, 8, 0x0376, 1, 15, Latched} -/* {0x01E8, 8, 0x03ee, 1, 11, LevelSensitive}, - {0x0168, 8, 0x036e, 1, 10, LevelSensitive}*/ -}; - -static BOOLEAN IDEInitialized = FALSE; - -// ----------------------------------------------- Discardable Declarations - -#ifdef ALLOC_PRAGMA - -// make the initialization routines discardable, so that they -// don't waste space - -#pragma alloc_text(init, DriverEntry) -#pragma alloc_text(init, IDECreateController) -#pragma alloc_text(init, IDECreateDevices) -#pragma alloc_text(init, IDECreateDevice) -#pragma alloc_text(init, IDEPolledRead) - -// make the PASSIVE_LEVEL routines pageable, so that they don't -// waste nonpaged memory - -#pragma alloc_text(page, IDEShutdown) -#pragma alloc_text(page, IDEDispatchOpenClose) -#pragma alloc_text(page, IDEDispatchRead) -#pragma alloc_text(page, IDEDispatchWrite) - -#endif /* ALLOC_PRAGMA */ - -// ---------------------------------------------------- Forward Declarations - -static NTSTATUS -IdeFindControllers(IN PDRIVER_OBJECT DriverObject); - -static NTSTATUS -IdeCreateController(IN PDRIVER_OBJECT DriverObject, - IN PIDE_CONTROLLER_PARAMETERS ControllerParams, - IN int ControllerIdx); - -static BOOLEAN IDEResetController(IN WORD CommandPort, IN WORD ControlPort); -static BOOLEAN IDECreateDevices(IN PDRIVER_OBJECT DriverObject, - IN PCONTROLLER_OBJECT ControllerObject, - IN PIDE_CONTROLLER_EXTENSION ControllerExtension, - IN int DriveIdx, - IN int HarddiskIdx); -static BOOLEAN IDEGetDriveIdentification(IN int CommandPort, - IN int DriveNum, - OUT PIDE_DRIVE_IDENTIFY DrvParms); -static NTSTATUS IDECreateDiskDevice(IN PDRIVER_OBJECT DriverObject, - OUT PDEVICE_OBJECT *DeviceObject, - IN PCONTROLLER_OBJECT ControllerObject, - IN int UnitNumber, - IN ULONG DiskNumber, - IN PIDE_DRIVE_IDENTIFY DrvParms, - IN ULONG SectorCount); -static NTSTATUS IDECreatePartitionDevice(IN PDRIVER_OBJECT DriverObject, - OUT PDEVICE_OBJECT *DeviceObject, - IN PCONTROLLER_OBJECT ControllerObject, - IN PVOID DiskDeviceExtension, - IN int UnitNumber, - IN ULONG DiskNumber, - IN PIDE_DRIVE_IDENTIFY DrvParms, - IN PPARTITION_INFORMATION PartitionInfo); -static int IDEPolledRead(IN WORD Address, - IN BYTE PreComp, - IN BYTE SectorCnt, - IN BYTE SectorNum, - IN BYTE CylinderLow, - IN BYTE CylinderHigh, - IN BYTE DrvHead, - IN BYTE Command, - OUT BYTE *Buffer); -static NTSTATUS STDCALL IDEDispatchOpenClose(IN PDEVICE_OBJECT pDO, IN PIRP Irp); -static NTSTATUS STDCALL IDEDispatchReadWrite(IN PDEVICE_OBJECT pDO, IN PIRP Irp); -static NTSTATUS STDCALL IDEDispatchDeviceControl(IN PDEVICE_OBJECT pDO, IN PIRP Irp); -static VOID STDCALL IDEStartIo(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp); -static IO_ALLOCATION_ACTION STDCALL -IDEAllocateController(IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp, - IN PVOID MapRegisterBase, - IN PVOID Ccontext); -static BOOLEAN STDCALL -IDEStartController(IN OUT PVOID Context); -VOID IDEBeginControllerReset(PIDE_CONTROLLER_EXTENSION ControllerExtension); -static BOOLEAN STDCALL IDEIsr(IN PKINTERRUPT Interrupt, IN PVOID ServiceContext); -static VOID IDEDpcForIsr(IN PKDPC Dpc, - IN PDEVICE_OBJECT DpcDeviceObject, - IN PIRP DpcIrp, - IN PVOID DpcContext); -static VOID IDEFinishOperation(PIDE_CONTROLLER_EXTENSION ControllerExtension); -static VOID STDCALL IDEIoTimer(PDEVICE_OBJECT DeviceObject, PVOID Context); - -// ---------------------------------------------------------------- Inlines - -void -IDESwapBytePairs(char *Buf, - int Cnt) -{ - char t; - int i; - - for (i = 0; i < Cnt; i += 2) - { - t = Buf[i]; - Buf[i] = Buf[i+1]; - Buf[i+1] = t; - } -} - -// ------------------------------------------------------- Public Interface - -// DriverEntry -// -// DESCRIPTION: -// This function initializes the driver, locates and claims -// hardware resources, and creates various NT objects needed -// to process I/O requests. -// -// RUN LEVEL: -// PASSIVE_LEVEL -// -// ARGUMENTS: -// IN PDRIVER_OBJECT DriverObject System allocated Driver Object -// for this driver -// IN PUNICODE_STRING RegistryPath Name of registry driver service -// key -// -// RETURNS: -// NTSTATUS - -STDCALL NTSTATUS -DriverEntry(IN PDRIVER_OBJECT DriverObject, - IN PUNICODE_STRING RegistryPath) -{ - NTSTATUS Status; - - DPRINT("IDE Driver %s\n", VERSION); - - /* Export other driver entry points... */ - DriverObject->DriverStartIo = IDEStartIo; - DriverObject->MajorFunction[IRP_MJ_CREATE] = (PDRIVER_DISPATCH)IDEDispatchOpenClose; - DriverObject->MajorFunction[IRP_MJ_CLOSE] = (PDRIVER_DISPATCH)IDEDispatchOpenClose; - DriverObject->MajorFunction[IRP_MJ_READ] = (PDRIVER_DISPATCH)IDEDispatchReadWrite; - DriverObject->MajorFunction[IRP_MJ_WRITE] = (PDRIVER_DISPATCH)IDEDispatchReadWrite; -// DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = (PDRIVER_DISPATCH)IDEDispatchQueryInformation; -// DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] = (PDRIVER_DISPATCH)IDEDispatchSetInformation; - DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = (PDRIVER_DISPATCH)IDEDispatchDeviceControl; - - Status = IdeFindControllers(DriverObject); - if (NT_SUCCESS(Status)) - { - IDEInitialized = TRUE; - } - - return(Status); -} - -// ---------------------------------------------------- Discardable statics - -static NTSTATUS -IdeFindControllers(IN PDRIVER_OBJECT DriverObject) -{ - PCI_COMMON_CONFIG PciConfig; - ULONG Bus; - ULONG Slot; - ULONG Size; - NTSTATUS ReturnedStatus = STATUS_NO_SUCH_DEVICE; - NTSTATUS Status; - INT ControllerIdx = 0; - PCONFIGURATION_INFORMATION ConfigInfo; - - DPRINT("IdeFindControllers() called!\n"); - - ConfigInfo = IoGetConfigurationInformation(); - - /* Search PCI busses for IDE controllers */ - for (Bus = 0; Bus < 8; Bus++) - { - for (Slot = 0; Slot < 256; Slot++) - { - Size = HalGetBusData(PCIConfiguration, - Bus, - Slot, - &PciConfig, - sizeof(PCI_COMMON_CONFIG)); - if (Size != 0) - { - if ((PciConfig.BaseClass == 0x01) && - (PciConfig.SubClass == 0x01)) - { - DPRINT("IDE controller found!\n"); - - DPRINT("Bus %1lu Device %2lu Func %1lu VenID 0x%04hx DevID 0x%04hx\n", - Bus, - Slot>>3, - Slot & 0x07, - PciConfig.VendorID, - PciConfig.DeviceID); - if ((PciConfig.HeaderType & 0x7FFFFFFF) == 0) - { - DPRINT(" IPR 0x%X ILR 0x%X\n", - PciConfig.u.type0.InterruptPin, - PciConfig.u.type0.InterruptLine); - } - - if (PciConfig.ProgIf & 0x01) - { - DPRINT("Primary channel: PCI native mode\n"); - } - else - { - DPRINT("Primary channel: Compatibility mode\n"); - if (ConfigInfo->AtDiskPrimaryAddressClaimed == FALSE) - { - Status = IdeCreateController(DriverObject, - &Controllers[0], - ControllerIdx); - if (NT_SUCCESS(Status)) - { - ControllerIdx++; - ConfigInfo->AtDiskPrimaryAddressClaimed = TRUE; - ConfigInfo->ScsiPortCount++; - ReturnedStatus = Status; - } - } - else - { - /* - * FIXME: Switch controller to native pci mode - * if it is programmable. - */ - } - } - if (PciConfig.ProgIf & 0x02) - { - DPRINT("Primary channel: programmable\n"); - } - else - { - DPRINT("Primary channel: not programmable\n"); - } - -#ifdef ENABLE_SECONDARY_IDE_CHANNEL - if (PciConfig.ProgIf & 0x04) - { - DPRINT("Secondary channel: PCI native mode\n"); - } - else - { - DPRINT("Secondary channel: Compatibility mode\n"); - if (ConfigInfo->AtDiskSecondaryAddressClaimed == FALSE) - { - Status = IdeCreateController(DriverObject, - &Controllers[1], - ControllerIdx); - if (NT_SUCCESS(Status)) - { - ControllerIdx++; - ConfigInfo->AtDiskSecondaryAddressClaimed = TRUE; - ConfigInfo->ScsiPortCount++; - ReturnedStatus = Status; - } - } - else - { - /* - * FIXME: Switch controller to native pci mode - * if it is programmable. - */ - } - } - if (PciConfig.ProgIf & 0x08) - { - DPRINT("Secondary channel: programmable\n"); - } - else - { - DPRINT("Secondary channel: not programmable\n"); - } - - if (PciConfig.ProgIf & 0x80) - { - DPRINT("Master IDE device: 1\n"); - } - else - { - DPRINT("Master IDE device: 0\n"); - } - - for (i = 0; i < PCI_TYPE0_ADDRESSES; i++) - { - DPRINT("BaseAddress: 0x%08X\n", PciConfig.u.type0.BaseAddresses[i]); - } -#endif - } - } - } - } - - /* Search for ISA IDE controller if no primary controller was found */ - if (ConfigInfo->AtDiskPrimaryAddressClaimed == FALSE) - { - DPRINT("Searching for primary ISA IDE controller!\n"); - - if (IDEResetController(Controllers[0].CommandPortBase, - Controllers[0].ControlPortBase)) - { - Status = IdeCreateController(DriverObject, - &Controllers[0], - 0); - if (NT_SUCCESS(Status)) - { - DPRINT(" Found primary ISA IDE controller!\n"); - ControllerIdx++; - ConfigInfo->AtDiskPrimaryAddressClaimed = TRUE; - ConfigInfo->ScsiPortCount++; - ReturnedStatus = Status; - } - } - } - - /* Search for ISA IDE controller if no secondary controller was found */ -#ifdef ENABLE_SECONDARY_IDE_CHANNEL - if (ConfigInfo->AtDiskSecondaryAddressClaimed == FALSE) - { - DPRINT("Searching for secondary ISA IDE controller!\n"); - - if (IDEResetController(Controllers[1].CommandPortBase, - Controllers[1].ControlPortBase)) - { - Status = IdeCreateController(DriverObject, - &Controllers[1], - 1); - if (NT_SUCCESS(Status)) - { - DPRINT(" Found secondary ISA IDE controller!\n"); - ControllerIdx++; - ConfigInfo->AtDiskSecondaryAddressClaimed = TRUE; - ConfigInfo->ScsiPortCount++; - ReturnedStatus = Status; - } - } - } -#endif - - DPRINT("IdeFindControllers() done!\n"); - - return(ReturnedStatus); -} - - -// IdeCreateController -// -// DESCRIPTION: -// Creates a controller object and a device object for each valid -// device on the controller -// -// RUN LEVEL: -// PASSIVE LEVEL -// -// ARGUMENTS: -// IN PDRIVER_OBJECT DriverObject The system created driver object -// IN PIDE_CONTROLLER_PARAMETERS The parameter block for this -// ControllerParams controller -// IN int ControllerIdx The index of this controller -// -// RETURNS: -// TRUE Devices where found on this controller -// FALSE The controller does not respond or there are no devices on it -// - -static NTSTATUS -IdeCreateController(IN PDRIVER_OBJECT DriverObject, - IN PIDE_CONTROLLER_PARAMETERS ControllerParams, - IN int ControllerIdx) -{ - BOOLEAN CreatedDevices, ThisDriveExists; - int DriveIdx; - NTSTATUS RC; - PCONTROLLER_OBJECT ControllerObject; - PIDE_CONTROLLER_EXTENSION ControllerExtension; - ULONG MappedIrq; - KIRQL Dirql; - KAFFINITY Affinity; - - ControllerObject = IoCreateController(sizeof(IDE_CONTROLLER_EXTENSION)); - if (ControllerObject == NULL) - { - DbgPrint ("Could not create controller object for controller %d\n", - ControllerIdx); - return STATUS_NO_SUCH_DEVICE; - } - - MappedIrq = HalGetInterruptVector(Isa, - 0, - ControllerParams->Vector, - ControllerParams->Vector, - &Dirql, - &Affinity); - - // Fill out Controller extension data - ControllerExtension = (PIDE_CONTROLLER_EXTENSION) - ControllerObject->ControllerExtension; - ControllerExtension->Number = ControllerIdx; - ControllerExtension->CommandPortBase = ControllerParams->CommandPortBase; - ControllerExtension->ControlPortBase = ControllerParams->ControlPortBase; - ControllerExtension->Vector = MappedIrq; - ControllerExtension->DMASupported = FALSE; - ControllerExtension->ControllerInterruptBug = FALSE; - ControllerExtension->OperationInProgress = FALSE; - - // Initialize the spin lock in the controller extension - KeInitializeSpinLock(&ControllerExtension->SpinLock); - - // Register an interrupt handler for this controller - RC = IoConnectInterrupt(&ControllerExtension->Interrupt, - IDEIsr, - ControllerExtension, - &ControllerExtension->SpinLock, - ControllerExtension->Vector, - Dirql, - Dirql, - ControllerParams->InterruptMode, - FALSE, - Affinity, - FALSE); - if (!NT_SUCCESS(RC)) - { - DbgPrint ("Could not Connect Interrupt %d\n", - ControllerExtension->Vector); - IoDeleteController (ControllerObject); - return RC; - } - -/* TEST */ - IDEInitialized = TRUE; - - // Create device objects for each raw device (and for partitions) - CreatedDevices = FALSE; - for (DriveIdx = 0; DriveIdx < IDE_MAX_DRIVES; DriveIdx++) - { - ThisDriveExists = IDECreateDevices(DriverObject, - ControllerObject, - ControllerExtension, - DriveIdx, - ControllerIdx * 2 + DriveIdx); - if (ThisDriveExists) - { - CreatedDevices = TRUE; - } - } - - if (!CreatedDevices) - { - DbgPrint ("Did not find any devices for controller %d\n", - ControllerIdx); - IoDisconnectInterrupt (ControllerExtension->Interrupt); - IoDeleteController (ControllerObject); - } - else - { - IDEResetController(ControllerParams->CommandPortBase, - ControllerParams->ControlPortBase); - IoStartTimer(ControllerExtension->TimerDevice); - } - - return((CreatedDevices == TRUE)?STATUS_SUCCESS:STATUS_NO_SUCH_DEVICE); -} - - -// IDEResetController -// -// DESCRIPTION: -// Reset the controller and report completion status -// -// RUN LEVEL: -// PASSIVE_LEVEL -// -// ARGUMENTS: -// IN WORD CommandPort The address of the command port -// IN WORD ControlPort The address of the control port -// -// RETURNS: -// - -BOOLEAN -IDEResetController(IN WORD CommandPort, - IN WORD ControlPort) -{ - int Retries; - - // Assert drive reset line - IDEWriteDriveControl(ControlPort, IDE_DC_SRST); - - // Wait for min. 25 microseconds - KeStallExecutionProcessor(IDE_RESET_PULSE_LENGTH); - - // Negate drive reset line - IDEWriteDriveControl(ControlPort, 0); - - // Wait for BUSY negation - for (Retries = 0; Retries < IDE_RESET_BUSY_TIMEOUT * 1000; Retries++) - { - if (!(IDEReadStatus(CommandPort) & IDE_SR_BUSY)) - { - break; - } - KeStallExecutionProcessor(10); - } - CHECKPOINT; - if (Retries >= IDE_RESET_BUSY_TIMEOUT * 1000) - { - return FALSE; - } - CHECKPOINT; - // return TRUE if controller came back to life. and - // the registers are initialized correctly - return IDEReadError(CommandPort) == 1; -} - - -// IDECreateDevices -// -// DESCRIPTION: -// Create the raw device and any partition devices on this drive -// -// RUN LEVEL: -// PASSIVE_LEVEL -// -// ARGUMENTS: -// IN PDRIVER_OBJECT DriverObject The system created driver object -// IN PCONTROLLER_OBJECT ControllerObject -// IN PIDE_CONTROLLER_EXTENSION ControllerExtension -// The IDE controller extension for -// this device -// IN int DriveIdx The index of the drive on this -// controller -// IN int HarddiskIdx The NT device number for this -// drive -// -// RETURNS: -// TRUE Drive exists and devices were created -// FALSE no devices were created for this device -// - -BOOLEAN -IDECreateDevices(IN PDRIVER_OBJECT DriverObject, - IN PCONTROLLER_OBJECT ControllerObject, - IN PIDE_CONTROLLER_EXTENSION ControllerExtension, - IN int DriveIdx, - IN int HarddiskIdx) -{ - WCHAR NameBuffer[IDE_MAX_NAME_LENGTH]; - int CommandPort; - NTSTATUS Status; - IDE_DRIVE_IDENTIFY DrvParms; - PDEVICE_OBJECT DiskDeviceObject; - PDEVICE_OBJECT PartitionDeviceObject; - UNICODE_STRING UnicodeDeviceDirName; - OBJECT_ATTRIBUTES DeviceDirAttributes; - HANDLE Handle; - ULONG SectorCount = 0; - PDRIVE_LAYOUT_INFORMATION PartitionList = NULL; - PPARTITION_INFORMATION PartitionEntry; - ULONG i; - - /* Copy I/O port offsets for convenience */ - CommandPort = ControllerExtension->CommandPortBase; -// ControlPort = ControllerExtension->ControlPortBase; - DPRINT("probing IDE controller %d Addr %04lx Drive %d\n", - ControllerExtension->Number, - CommandPort, - DriveIdx); - - /* Get the Drive Identification Data */ - if (!IDEGetDriveIdentification(CommandPort, DriveIdx, &DrvParms)) - { - DPRINT("No ATA drive %d found on controller %d...\n", - DriveIdx, - ControllerExtension->Number); - return(FALSE); - } - - DPRINT("Found ATA drive %d on controller %d...\n", - DriveIdx, - ControllerExtension->Number); - - /* Create the harddisk device directory */ - swprintf (NameBuffer, - L"\\Device\\Harddisk%d", - HarddiskIdx); - RtlInitUnicodeString(&UnicodeDeviceDirName, - NameBuffer); - InitializeObjectAttributes(&DeviceDirAttributes, - &UnicodeDeviceDirName, - 0, - NULL, - NULL); - Status = ZwCreateDirectoryObject(&Handle, 0, &DeviceDirAttributes); - if (!NT_SUCCESS(Status)) - { - DbgPrint("Could not create device dir object\n"); - return(FALSE); - } - - /* Create the disk device */ - if (DrvParms.Capabilities & IDE_DRID_LBA_SUPPORTED) - { - SectorCount = - (ULONG)((DrvParms.TMSectorCountHi << 16) + DrvParms.TMSectorCountLo); - } - else - { - SectorCount = - (ULONG)(DrvParms.LogicalCyls * DrvParms.LogicalHeads * DrvParms.SectorsPerTrack); - } - DPRINT("SectorCount %lu\n", SectorCount); - - Status = IDECreateDiskDevice(DriverObject, - &DiskDeviceObject, - ControllerObject, - DriveIdx, - HarddiskIdx, - &DrvParms, - SectorCount); - if (!NT_SUCCESS(Status)) - { - DbgPrint("IDECreateDevice call failed for raw device\n"); - return FALSE; - } - - /* Increase number of available physical disk drives */ - IoGetConfigurationInformation()->DiskCount++; - - /* - * Initialize the controller timer here - * (since it has to be tied to a device) - */ - if (DriveIdx == 0) - { - ControllerExtension->TimerState = IDETimerIdle; - ControllerExtension->TimerCount = 0; - ControllerExtension->TimerDevice = DiskDeviceObject; - IoInitializeTimer(DiskDeviceObject, - IDEIoTimer, - ControllerExtension); - } - - DPRINT("DrvParms.BytesPerSector %ld\n",DrvParms.BytesPerSector); - - /* Read partition table */ - Status = IoReadPartitionTable(DiskDeviceObject, - DrvParms.BytesPerSector, - TRUE, - &PartitionList); - if (!NT_SUCCESS(Status)) - { - DbgPrint("IoReadPartitionTable() failed\n"); - return FALSE; - } - - DPRINT(" Number of partitions: %u\n", PartitionList->PartitionCount); - for (i=0;i < PartitionList->PartitionCount; i++) - { - PartitionEntry = &PartitionList->PartitionEntry[i]; - - DPRINT("Partition %02ld: nr: %d boot: %1x type: %x offset: %I64d size: %I64d\n", - i, - PartitionEntry->PartitionNumber, - PartitionEntry->BootIndicator, - PartitionEntry->PartitionType, - PartitionEntry->StartingOffset.QuadPart / DrvParms.BytesPerSector, - PartitionEntry->PartitionLength.QuadPart / DrvParms.BytesPerSector); - - /* Create device for partition */ - Status = IDECreatePartitionDevice(DriverObject, - &PartitionDeviceObject, - ControllerObject, - DiskDeviceObject->DeviceExtension, - DriveIdx, - HarddiskIdx, - &DrvParms, - PartitionEntry); - if (!NT_SUCCESS(Status)) - { - DbgPrint("IDECreateDevice() failed\n"); - break; - } - } - - if (PartitionList != NULL) - ExFreePool(PartitionList); - - return TRUE; -} - -// IDEGetDriveIdentification -// -// DESCRIPTION: -// Get the identification block from the drive -// -// RUN LEVEL: -// PASSIVE_LEVEL -// -// ARGUMENTS: -// IN int CommandPort Address of the command port -// IN int DriveNum The drive index (0,1) -// OUT PIDE_DRIVE_IDENTIFY DrvParms Address to write drive ident block -// -// RETURNS: -// TRUE The drive identification block was retrieved successfully -// - -static BOOLEAN -IDEGetDriveIdentification(IN int CommandPort, - IN int DriveNum, - OUT PIDE_DRIVE_IDENTIFY DrvParms) -{ - - /* Get the Drive Identify block from drive or die */ - if (IDEPolledRead(CommandPort, 0, 1, 0, 0, 0, (DriveNum ? IDE_DH_DRV1 : 0), - IDE_CMD_IDENT_DRV, (BYTE *)DrvParms) != 0) - { - return(FALSE); - } - - /* Report on drive parameters if debug mode */ - IDESwapBytePairs(DrvParms->SerialNumber, 20); - IDESwapBytePairs(DrvParms->FirmwareRev, 8); - IDESwapBytePairs(DrvParms->ModelNumber, 40); - DPRINT("Config:%04x Cyls:%5d Heads:%2d Sectors/Track:%3d Gaps:%02d %02d\n", - DrvParms->ConfigBits, - DrvParms->LogicalCyls, - DrvParms->LogicalHeads, - DrvParms->SectorsPerTrack, - DrvParms->InterSectorGap, - DrvParms->InterSectorGapSize); - DPRINT("Bytes/PLO:%3d Vendor Cnt:%2d Serial number:[%.20s]\n", - DrvParms->BytesInPLO, - DrvParms->VendorUniqueCnt, - DrvParms->SerialNumber); - DPRINT("Cntlr type:%2d BufSiz:%5d ECC bytes:%3d Firmware Rev:[%.8s]\n", - DrvParms->ControllerType, - DrvParms->BufferSize * IDE_SECTOR_BUF_SZ, - DrvParms->ECCByteCnt, - DrvParms->FirmwareRev); - DPRINT("Model:[%.40s]\n", DrvParms->ModelNumber); - DPRINT("RWMult?:%02x LBA:%d DMA:%d MinPIO:%d ns MinDMA:%d ns\n", - (DrvParms->RWMultImplemented) & 0xff, - (DrvParms->Capabilities & IDE_DRID_LBA_SUPPORTED) ? 1 : 0, - (DrvParms->Capabilities & IDE_DRID_DMA_SUPPORTED) ? 1 : 0, - DrvParms->MinPIOTransTime, - DrvParms->MinDMATransTime); - DPRINT("TM:Cyls:%d Heads:%d Sectors/Trk:%d Capacity:%ld\n", - DrvParms->TMCylinders, - DrvParms->TMHeads, - DrvParms->TMSectorsPerTrk, - (ULONG)(DrvParms->TMCapacityLo + (DrvParms->TMCapacityHi << 16))); - DPRINT("TM:SectorCount: 0x%04x%04x = %lu\n", - DrvParms->TMSectorCountHi, - DrvParms->TMSectorCountLo, - (ULONG)((DrvParms->TMSectorCountHi << 16) + DrvParms->TMSectorCountLo)); - - /* - * Fix default ATA sector size. - * Attention: Default ATAPI sector size is 2048 bytes!! - */ - DPRINT("BytesPerSector %d\n", DrvParms->BytesPerSector); - DrvParms->BytesPerSector = 512; - DPRINT("BytesPerSector %d\n", DrvParms->BytesPerSector); - - return(TRUE); -} - - -// IDECreateDiskDevice -// -// DESCRIPTION: -// Creates the disk device object -// -// RUN LEVEL: -// PASSIVE_LEVEL -// -// ARGUMENTS: -// IN PDRIVER_OBJECT DriverObject The system supplied driver object -// OUT PDEVICE_OBJECT *DeviceObject The created device object -// IN PCONTROLLER_OBJECT ControllerObject The Controller for the device -// IN BOOLEAN LBASupported Does the drive support LBA addressing? -// IN BOOLEAN DMASupported Does the drive support DMA? -// IN int SectorsPerLogCyl Sectors per cylinder -// IN int SectorsPerLogTrk Sectors per track -// IN DWORD Offset First valid sector for this device -// IN DWORD Size Count of valid sectors for this device -// -// RETURNS: -// NTSTATUS -// - -NTSTATUS -IDECreateDiskDevice(IN PDRIVER_OBJECT DriverObject, - OUT PDEVICE_OBJECT *DeviceObject, - IN PCONTROLLER_OBJECT ControllerObject, - IN int UnitNumber, - IN ULONG DiskNumber, - IN PIDE_DRIVE_IDENTIFY DrvParms, - IN ULONG SectorCount) -{ - WCHAR NameBuffer[IDE_MAX_NAME_LENGTH]; - UNICODE_STRING DeviceName; - NTSTATUS RC; - PIDE_DEVICE_EXTENSION DeviceExtension; - - /* Create a unicode device name */ - swprintf(NameBuffer, - L"\\Device\\Harddisk%d\\Partition0", - DiskNumber); - RtlInitUnicodeString(&DeviceName, - NameBuffer); - - /* Create the device */ - RC = IoCreateDevice(DriverObject, - sizeof(IDE_DEVICE_EXTENSION), - &DeviceName, - FILE_DEVICE_DISK, - 0, - TRUE, - DeviceObject); - if (!NT_SUCCESS(RC)) - { - DbgPrint("IoCreateDevice call failed\n"); - return(RC); - } - - /* Set the buffering strategy here... */ - (*DeviceObject)->Flags |= DO_DIRECT_IO; - (*DeviceObject)->AlignmentRequirement = FILE_WORD_ALIGNMENT; - - /* Fill out Device extension data */ - DeviceExtension = (PIDE_DEVICE_EXTENSION) (*DeviceObject)->DeviceExtension; - DeviceExtension->DeviceObject = (*DeviceObject); - DeviceExtension->ControllerObject = ControllerObject; - DeviceExtension->DiskDeviceExtension = DeviceExtension; - DeviceExtension->UnitNumber = UnitNumber; - DeviceExtension->LBASupported = - (DrvParms->Capabilities & IDE_DRID_LBA_SUPPORTED) ? 1 : 0; - DeviceExtension->DMASupported = - (DrvParms->Capabilities & IDE_DRID_DMA_SUPPORTED) ? 1 : 0; - DeviceExtension->BytesPerSector = DrvParms->BytesPerSector; - DeviceExtension->SectorsPerLogCyl = - DrvParms->LogicalHeads * DrvParms->SectorsPerTrack; - DeviceExtension->SectorsPerLogTrk = DrvParms->SectorsPerTrack; - DeviceExtension->LogicalHeads = DrvParms->LogicalHeads; - DeviceExtension->LogicalCylinders = - (DrvParms->Capabilities & IDE_DRID_LBA_SUPPORTED) ? DrvParms->TMCylinders : DrvParms->LogicalCyls; - - DeviceExtension->StartingOffset.QuadPart = 0; - DeviceExtension->PartitionLength.QuadPart = (ULONGLONG)SectorCount * - (ULONGLONG)DrvParms->BytesPerSector; - DeviceExtension->HiddenSectors = 0; - DeviceExtension->PartitionNumber = 0; - DeviceExtension->PartitionType = 0; - DeviceExtension->BootIndicator = FALSE; - - DPRINT("%wZ: offset %I64d length %I64d\n", - &DeviceName, - DeviceExtension->StartingOffset.QuadPart, - DeviceExtension->PartitionLength.QuadPart); - - /* Initialize the DPC object here */ - IoInitializeDpcRequest(*DeviceObject, - IDEDpcForIsr); - - return RC; -} - - -// IDECreatePartitionDevice -// -// DESCRIPTION: -// Creates a partition device object -// -// RUN LEVEL: -// PASSIVE_LEVEL -// -// ARGUMENTS: -// IN PDRIVER_OBJECT DriverObject The system supplied driver object -// OUT PDEVICE_OBJECT *DeviceObject The created device object -// IN PCONTROLLER_OBJECT ControllerObject The Controller for the device -// IN BOOLEAN LBASupported Does the drive support LBA addressing? -// IN BOOLEAN DMASupported Does the drive support DMA? -// IN int SectorsPerLogCyl Sectors per cylinder -// IN int SectorsPerLogTrk Sectors per track -// IN DWORD Offset First valid sector for this device -// IN DWORD Size Count of valid sectors for this device -// -// RETURNS: -// NTSTATUS -// - -NTSTATUS -IDECreatePartitionDevice(IN PDRIVER_OBJECT DriverObject, - OUT PDEVICE_OBJECT *DeviceObject, - IN PCONTROLLER_OBJECT ControllerObject, - IN PVOID DiskDeviceExtension, - IN int UnitNumber, - IN ULONG DiskNumber, - IN PIDE_DRIVE_IDENTIFY DrvParms, - IN PPARTITION_INFORMATION PartitionInfo) -{ - WCHAR NameBuffer[IDE_MAX_NAME_LENGTH]; - UNICODE_STRING DeviceName; - NTSTATUS RC; - PIDE_DEVICE_EXTENSION DeviceExtension; - - /* Create a unicode device name */ - swprintf(NameBuffer, - L"\\Device\\Harddisk%d\\Partition%d", - DiskNumber, - PartitionInfo->PartitionNumber); - RtlInitUnicodeString(&DeviceName, - NameBuffer); - - /* Create the device */ - RC = IoCreateDevice(DriverObject, sizeof(IDE_DEVICE_EXTENSION), - &DeviceName, FILE_DEVICE_DISK, 0, TRUE, DeviceObject); - if (!NT_SUCCESS(RC)) - { - DbgPrint ("IoCreateDevice call failed\n"); - return RC; - } - - /* Set the buffering strategy here... */ - (*DeviceObject)->Flags |= DO_DIRECT_IO; - (*DeviceObject)->AlignmentRequirement = FILE_WORD_ALIGNMENT; - - /* Fill out Device extension data */ - DeviceExtension = (PIDE_DEVICE_EXTENSION)(*DeviceObject)->DeviceExtension; - DeviceExtension->DeviceObject = (*DeviceObject); - DeviceExtension->ControllerObject = ControllerObject; - DeviceExtension->DiskDeviceExtension = DiskDeviceExtension; - DeviceExtension->UnitNumber = UnitNumber; - DeviceExtension->LBASupported = - (DrvParms->Capabilities & IDE_DRID_LBA_SUPPORTED) ? 1 : 0; - DeviceExtension->DMASupported = - (DrvParms->Capabilities & IDE_DRID_DMA_SUPPORTED) ? 1 : 0; - DeviceExtension->BytesPerSector = DrvParms->BytesPerSector; - DeviceExtension->SectorsPerLogCyl = DrvParms->LogicalHeads * - DrvParms->SectorsPerTrack; - DeviceExtension->SectorsPerLogTrk = DrvParms->SectorsPerTrack; - DeviceExtension->LogicalHeads = DrvParms->LogicalHeads; - DeviceExtension->LogicalCylinders = - (DrvParms->Capabilities & IDE_DRID_LBA_SUPPORTED) ? DrvParms->TMCylinders : DrvParms->LogicalCyls; - - DeviceExtension->StartingOffset = PartitionInfo->StartingOffset; - DeviceExtension->PartitionLength = PartitionInfo->PartitionLength; - DeviceExtension->HiddenSectors = PartitionInfo->HiddenSectors; - DeviceExtension->PartitionNumber = PartitionInfo->PartitionNumber; - DeviceExtension->PartitionType = PartitionInfo->PartitionType; - DeviceExtension->BootIndicator = PartitionInfo->BootIndicator; - - DPRINT("%wZ: offset %I64d size %I64d\n", - &DeviceName, - DeviceExtension->StartingOffset.QuadPart, - DeviceExtension->PartitionLength.QuadPart); - - /* Initialize the DPC object here */ - IoInitializeDpcRequest(*DeviceObject, IDEDpcForIsr); - - DPRINT("%wZ %I64dMB\n", - &DeviceName, - DeviceExtension->PartitionLength.QuadPart >> 20); - - return RC; -} - - -// IDEPolledRead -// -// DESCRIPTION: -// Read a sector of data from the drive in a polled fashion. -// -// RUN LEVEL: -// PASSIVE_LEVEL -// -// ARGUMENTS: -// IN WORD Address Address of command port for drive -// IN BYTE PreComp Value to write to precomp register -// IN BYTE SectorCnt Value to write to sectorCnt register -// IN BYTE SectorNum Value to write to sectorNum register -// IN BYTE CylinderLow Value to write to CylinderLow register -// IN BYTE CylinderHigh Value to write to CylinderHigh register -// IN BYTE DrvHead Value to write to Drive/Head register -// IN BYTE Command Value to write to Command register -// OUT BYTE *Buffer Buffer for output data -// -// RETURNS: -// int 0 is success, non 0 is an error code -// - -static int -IDEPolledRead(IN WORD Address, - IN BYTE PreComp, - IN BYTE SectorCnt, - IN BYTE SectorNum, - IN BYTE CylinderLow, - IN BYTE CylinderHigh, - IN BYTE DrvHead, - IN BYTE Command, - OUT BYTE *Buffer) -{ - BYTE Status; - int RetryCount; - BOOLEAN ReadJunk = FALSE; - ULONG SectorCount = 0; - - /* Wait for STATUS.BUSY and STATUS.DRQ to clear */ - for (RetryCount = 0; RetryCount < IDE_MAX_BUSY_RETRIES; RetryCount++) - { - Status = IDEReadStatus(Address); - if (!(Status & IDE_SR_BUSY) && !(Status & IDE_SR_DRQ)) - { - break; - } - KeStallExecutionProcessor(10); - } - if (RetryCount == IDE_MAX_BUSY_RETRIES) - { - return IDE_ER_ABRT; - } - - /* Write Drive/Head to select drive */ - IDEWriteDriveHead(Address, IDE_DH_FIXED | DrvHead); - - /* Wait for STATUS.BUSY and STATUS.DRQ to clear */ - for (RetryCount = 0; RetryCount < IDE_MAX_BUSY_RETRIES; RetryCount++) - { - Status = IDEReadStatus(Address); - if (!(Status & IDE_SR_BUSY) && !(Status & IDE_SR_DRQ)) - { - break; - } - KeStallExecutionProcessor(10); - } - if (RetryCount == IDE_MAX_BUSY_RETRIES) - { - return IDE_ER_ABRT; - } - - /* Issue command to drive */ - if (DrvHead & IDE_DH_LBA) - { - DPRINT("READ:DRV=%d:LBA=1:BLK=%08d:SC=%02x:CM=%02x\n", - DrvHead & IDE_DH_DRV1 ? 1 : 0, - ((DrvHead & 0x0f) << 24) + (CylinderHigh << 16) + (CylinderLow << 8) + SectorNum, - SectorCnt, - Command); - } - else - { - DPRINT("READ:DRV=%d:LBA=0:CH=%02x:CL=%02x:HD=%01x:SN=%02x:SC=%02x:CM=%02x\n", - DrvHead & IDE_DH_DRV1 ? 1 : 0, - CylinderHigh, - CylinderLow, - DrvHead & 0x0f, - SectorNum, - SectorCnt, - Command); - } - - /* Setup command parameters */ - IDEWritePrecomp(Address, PreComp); - IDEWriteSectorCount(Address, SectorCnt); - IDEWriteSectorNum(Address, SectorNum); - IDEWriteCylinderHigh(Address, CylinderHigh); - IDEWriteCylinderLow(Address, CylinderLow); - IDEWriteDriveHead(Address, IDE_DH_FIXED | DrvHead); - - /* Issue the command */ - IDEWriteCommand(Address, Command); - KeStallExecutionProcessor(50); - - /* wait for DRQ or error */ - for (RetryCount = 0; RetryCount < IDE_MAX_POLL_RETRIES; RetryCount++) - { - Status = IDEReadStatus(Address); - if (!(Status & IDE_SR_BUSY)) - { - if (Status & IDE_SR_ERR) - { - DPRINT("IDE_SR_ERR asserted!\n"); - } - if ((Status & IDE_SR_DRQ) && !(Status & IDE_SR_ERR)) - { - break; - } - else - { - return IDE_ER_ABRT; - } - } - KeStallExecutionProcessor(10); - } - if (RetryCount >= IDE_MAX_POLL_RETRIES) - { - return IDE_ER_ABRT; - } - - while (1) - { - /* Read data into buffer */ - if (ReadJunk == TRUE) - { - UCHAR JunkBuffer[IDE_SECTOR_BUF_SZ]; - IDEReadBlock(Address, JunkBuffer, IDE_SECTOR_BUF_SZ); - } - else - { - IDEReadBlock(Address, Buffer, IDE_SECTOR_BUF_SZ); - Buffer += IDE_SECTOR_BUF_SZ; - } - SectorCount++; - - /* Check for more sectors to read */ - for (RetryCount = 0; RetryCount < IDE_MAX_BUSY_RETRIES; RetryCount++) - { - Status = IDEReadStatus(Address); - if (!(Status & IDE_SR_BUSY)) - { - if (Status & IDE_SR_ERR) - { - DPRINT("IDE_SR_ERR asserted!\n"); - } - if (Status & IDE_SR_DRQ) - { - if (SectorCount >= SectorCnt) - ReadJunk = TRUE; - break; - } - else - { - return 0; - } - } - } - } -} - -// ------------------------------------------- Nondiscardable statics - -// IDEDispatchOpenClose -// -// DESCRIPTION: -// Answer requests for Open/Close calls: a null operation -// -// RUN LEVEL: -// PASSIVE_LEVEL -// -// ARGUMENTS: -// Standard dispatch arguments -// -// RETURNS: -// NTSTATUS -// - -static NTSTATUS STDCALL -IDEDispatchOpenClose(IN PDEVICE_OBJECT pDO, - IN PIRP Irp) -{ - Irp->IoStatus.Status = STATUS_SUCCESS; - Irp->IoStatus.Information = FILE_OPENED; - IoCompleteRequest(Irp, IO_NO_INCREMENT); - - return STATUS_SUCCESS; -} - -// IDEDispatchReadWrite -// -// DESCRIPTION: -// Answer requests for reads and writes -// -// RUN LEVEL: -// PASSIVE_LEVEL -// -// ARGUMENTS: -// Standard dispatch arguments -// -// RETURNS: -// NTSTATUS -// - -static NTSTATUS STDCALL -IDEDispatchReadWrite(IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp) -{ - ULONG IrpInsertKey; - LARGE_INTEGER AdjustedOffset, AdjustedExtent, PartitionExtent, InsertKeyLI; - PIO_STACK_LOCATION IrpStack; - PIDE_DEVICE_EXTENSION DeviceExtension; - - IrpStack = IoGetCurrentIrpStackLocation(Irp); - DeviceExtension = (PIDE_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - - // Validate operation parameters - AdjustedOffset.QuadPart = DeviceExtension->StartingOffset.QuadPart + - IrpStack->Parameters.Read.ByteOffset.QuadPart; - DPRINT("AdjustedOffset: %I64x\n", AdjustedOffset.QuadPart); - - AdjustedExtent.QuadPart = AdjustedOffset.QuadPart + - (ULONGLONG)IrpStack->Parameters.Read.Length; - DPRINT("AdjustedExtent: %I64x\n", AdjustedExtent.QuadPart); - - PartitionExtent.QuadPart = DeviceExtension->StartingOffset.QuadPart + - DeviceExtension->PartitionLength.QuadPart; - DPRINT("PartitionExtent: %I64x\n", PartitionExtent.QuadPart); - - if ((AdjustedExtent.QuadPart > PartitionExtent.QuadPart) || - (IrpStack->Parameters.Read.Length & (DeviceExtension->BytesPerSector - 1))) - { - DPRINT("Request failed on bad parameters\n",0); - DPRINT("AdjustedExtent=%I64x PartitionExtent=%I64x ReadLength=%lx\n", - AdjustedExtent.QuadPart, - PartitionExtent.QuadPart, - IrpStack->Parameters.Read.Length); - Irp->IoStatus.Status = STATUS_INVALID_PARAMETER; - IoCompleteRequest(Irp, IO_NO_INCREMENT); - return STATUS_INVALID_PARAMETER; - } - - // Adjust operation to absolute sector offset - IrpStack->Parameters.Read.ByteOffset = AdjustedOffset; - - // Start the packet and insert the request in order of sector offset - assert(DeviceExtension->BytesPerSector == 512); - InsertKeyLI.QuadPart = IrpStack->Parameters.Read.ByteOffset.QuadPart >> 9; - IrpInsertKey = InsertKeyLI.u.LowPart; - IoStartPacket(DeviceObject, Irp, &IrpInsertKey, NULL); - - DPRINT("Returning STATUS_PENDING\n"); - return STATUS_PENDING; -} - -// IDEDispatchDeviceControl -// -// DESCRIPTION: -// Answer requests for device control calls -// -// RUN LEVEL: -// PASSIVE_LEVEL -// -// ARGUMENTS: -// Standard dispatch arguments -// -// RETURNS: -// NTSTATUS -// - -static NTSTATUS STDCALL -IDEDispatchDeviceControl(IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp) -{ - NTSTATUS RC; - ULONG ControlCode, InputLength, OutputLength; - PIO_STACK_LOCATION IrpStack; - PIDE_DEVICE_EXTENSION DeviceExtension; - PIDE_DEVICE_EXTENSION DiskDeviceExtension; - CCHAR Increment; - - RC = STATUS_SUCCESS; - IrpStack = IoGetCurrentIrpStackLocation(Irp); - ControlCode = IrpStack->Parameters.DeviceIoControl.IoControlCode; - InputLength = IrpStack->Parameters.DeviceIoControl.InputBufferLength; - OutputLength = IrpStack->Parameters.DeviceIoControl.OutputBufferLength; - DeviceExtension = (PIDE_DEVICE_EXTENSION) DeviceObject->DeviceExtension; - DiskDeviceExtension = (PIDE_DEVICE_EXTENSION)DeviceExtension->DiskDeviceExtension; - Increment = IO_NO_INCREMENT; - - // A huge switch statement in a Windows program?! who would have thought? - switch (ControlCode) - { - case IOCTL_DISK_GET_DRIVE_GEOMETRY: - if (IrpStack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(DISK_GEOMETRY)) - { - Irp->IoStatus.Status = STATUS_INVALID_PARAMETER; - } - else - { - PDISK_GEOMETRY Geometry; - - Geometry = (PDISK_GEOMETRY) Irp->AssociatedIrp.SystemBuffer; - - Geometry->MediaType = FixedMedia; - Geometry->Cylinders.QuadPart = DiskDeviceExtension->LogicalCylinders; - Geometry->TracksPerCylinder = DiskDeviceExtension->SectorsPerLogCyl / - DiskDeviceExtension->SectorsPerLogTrk; - Geometry->SectorsPerTrack = DiskDeviceExtension->SectorsPerLogTrk; - Geometry->BytesPerSector = DiskDeviceExtension->BytesPerSector; -DPRINT("DiskDeviceExtension->BytesPerSector %lu\n", DiskDeviceExtension->BytesPerSector); - Irp->IoStatus.Status = STATUS_SUCCESS; - Irp->IoStatus.Information = sizeof(DISK_GEOMETRY); - } - break; - - case IOCTL_DISK_GET_PARTITION_INFO: - DPRINT("IOCTL_DISK_GET_PARTITION_INFO\n"); - if (IrpStack->Parameters.DeviceIoControl.OutputBufferLength < - sizeof(PARTITION_INFORMATION)) - { - Irp->IoStatus.Status = STATUS_INFO_LENGTH_MISMATCH; - } - else if (DeviceExtension->PartitionNumber == 0) - { - Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST; - } - else - { - PPARTITION_INFORMATION PartitionInfo; - - PartitionInfo = (PPARTITION_INFORMATION)Irp->AssociatedIrp.SystemBuffer; - - PartitionInfo->PartitionType = DeviceExtension->PartitionType; - PartitionInfo->StartingOffset = DeviceExtension->StartingOffset; - PartitionInfo->PartitionLength = DeviceExtension->PartitionLength; - PartitionInfo->HiddenSectors = DeviceExtension->HiddenSectors; - PartitionInfo->PartitionNumber = DeviceExtension->PartitionNumber; - PartitionInfo->BootIndicator = DeviceExtension->BootIndicator; - PartitionInfo->RewritePartition = FALSE; - PartitionInfo->RecognizedPartition = - IsRecognizedPartition(DeviceExtension->PartitionType); - - Irp->IoStatus.Status = STATUS_SUCCESS; - Irp->IoStatus.Information = sizeof(PARTITION_INFORMATION); - } - break; - - case IOCTL_DISK_SET_PARTITION_INFO: - RC = STATUS_INVALID_DEVICE_REQUEST; - Irp->IoStatus.Status = RC; - Irp->IoStatus.Information = 0; - break; - - case IOCTL_DISK_GET_DRIVE_LAYOUT: - if (IrpStack->Parameters.DeviceIoControl.OutputBufferLength < - sizeof(DRIVE_LAYOUT_INFORMATION)) - { - Irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL; - } - else - { - PDRIVE_LAYOUT_INFORMATION PartitionList; - - RC = IoReadPartitionTable(DiskDeviceExtension->DeviceObject, - DiskDeviceExtension->BytesPerSector, - FALSE, - &PartitionList); - if (!NT_SUCCESS(RC)) - { - Irp->IoStatus.Status = RC; - } - else - { - ULONG BufferSize; - - BufferSize = FIELD_OFFSET(DRIVE_LAYOUT_INFORMATION, - PartitionEntry[0]); - BufferSize += PartitionList->PartitionCount * sizeof(PARTITION_INFORMATION); - - if (BufferSize > IrpStack->Parameters.DeviceIoControl.OutputBufferLength) - { - Irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL; - } - else - { - RtlMoveMemory(Irp->AssociatedIrp.SystemBuffer, - PartitionList, - BufferSize); - Irp->IoStatus.Status = STATUS_SUCCESS; - Irp->IoStatus.Information = BufferSize; - } - ExFreePool(PartitionList); - } - } - Increment = IO_DISK_INCREMENT; - break; - - case IOCTL_DISK_SET_DRIVE_LAYOUT: - case IOCTL_DISK_VERIFY: - case IOCTL_DISK_FORMAT_TRACKS: - case IOCTL_DISK_PERFORMANCE: - case IOCTL_DISK_IS_WRITABLE: - case IOCTL_DISK_LOGGING: - case IOCTL_DISK_FORMAT_TRACKS_EX: - case IOCTL_DISK_HISTOGRAM_STRUCTURE: - case IOCTL_DISK_HISTOGRAM_DATA: - case IOCTL_DISK_HISTOGRAM_RESET: - case IOCTL_DISK_REQUEST_STRUCTURE: - case IOCTL_DISK_REQUEST_DATA: - - // If we get here, something went wrong. inform the requestor - default: - RC = STATUS_INVALID_DEVICE_REQUEST; - Irp->IoStatus.Status = RC; - Irp->IoStatus.Information = 0; - break; - } - - IoCompleteRequest(Irp, Increment); - - return RC; -} - -// IDEStartIo -// -// DESCRIPTION: -// Get the next requested I/O packet started -// -// RUN LEVEL: -// DISPATCH_LEVEL -// -// ARGUMENTS: -// Dispatch routine standard arguments -// -// RETURNS: -// NTSTATUS -// - -static VOID -STDCALL IDEStartIo(IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp) -{ - LARGE_INTEGER SectorLI; - PIO_STACK_LOCATION IrpStack; - PIDE_DEVICE_EXTENSION DeviceExtension; - KIRQL OldIrql; - - DPRINT("IDEStartIo() called!\n"); - - IrpStack = IoGetCurrentIrpStackLocation(Irp); - DeviceExtension = (PIDE_DEVICE_EXTENSION) DeviceObject->DeviceExtension; - - // FIXME: implement the supported functions - - switch (IrpStack->MajorFunction) - { - case IRP_MJ_READ: - case IRP_MJ_WRITE: - DeviceExtension->Operation = IrpStack->MajorFunction; - DeviceExtension->BytesRequested = IrpStack->Parameters.Read.Length; - assert(DeviceExtension->BytesPerSector == 512); - SectorLI = RtlLargeIntegerShiftRight(IrpStack->Parameters.Read.ByteOffset, 9); - DeviceExtension->StartingSector = SectorLI.u.LowPart; - if (DeviceExtension->BytesRequested > DeviceExtension->BytesPerSector * - IDE_MAX_SECTORS_PER_XFER) - { - DeviceExtension->BytesToTransfer = DeviceExtension->BytesPerSector * - IDE_MAX_SECTORS_PER_XFER; - } - else - { - DeviceExtension->BytesToTransfer = DeviceExtension->BytesRequested; - } - DeviceExtension->BytesRequested -= DeviceExtension->BytesToTransfer; - DeviceExtension->SectorsTransferred = 0; - DeviceExtension->TargetAddress = (BYTE *)MmGetSystemAddressForMdl(Irp->MdlAddress); - KeRaiseIrql(DISPATCH_LEVEL, &OldIrql); - IoAllocateController(DeviceExtension->ControllerObject, - DeviceObject, - IDEAllocateController, - NULL); - KeLowerIrql(OldIrql); - break; - - default: - Irp->IoStatus.Status = STATUS_NOT_SUPPORTED; - Irp->IoStatus.Information = 0; - KEBUGCHECK((ULONG)Irp); - IoCompleteRequest(Irp, IO_NO_INCREMENT); - IoStartNextPacket(DeviceObject, FALSE); - break; - } - DPRINT("IDEStartIo() finished!\n"); -} - -// IDEAllocateController - -static IO_ALLOCATION_ACTION STDCALL -IDEAllocateController(IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp, - IN PVOID MapRegisterBase, - IN PVOID Ccontext) -{ - PIDE_DEVICE_EXTENSION DeviceExtension; - PIDE_CONTROLLER_EXTENSION ControllerExtension; - - DeviceExtension = (PIDE_DEVICE_EXTENSION) DeviceObject->DeviceExtension; - ControllerExtension = (PIDE_CONTROLLER_EXTENSION) - DeviceExtension->ControllerObject->ControllerExtension; - ControllerExtension->CurrentIrp = Irp; - ControllerExtension->Retries = 0; - return KeSynchronizeExecution(ControllerExtension->Interrupt, - IDEStartController, - DeviceExtension) ? KeepObject : - DeallocateObject; -} - -// IDEStartController - -BOOLEAN STDCALL -IDEStartController(IN OUT PVOID Context) -{ - BYTE SectorCnt, SectorNum, CylinderLow, CylinderHigh; - BYTE DrvHead, Command; - BYTE Status; - int Retries; - ULONG StartingSector; - PIDE_DEVICE_EXTENSION DeviceExtension; - PIDE_CONTROLLER_EXTENSION ControllerExtension; - PIRP Irp; - - DeviceExtension = (PIDE_DEVICE_EXTENSION) Context; - ControllerExtension = (PIDE_CONTROLLER_EXTENSION) - DeviceExtension->ControllerObject->ControllerExtension; - ControllerExtension->OperationInProgress = TRUE; - ControllerExtension->DeviceForOperation = DeviceExtension; - - // Write controller registers to start opteration - StartingSector = DeviceExtension->StartingSector; - SectorCnt = DeviceExtension->BytesToTransfer / - DeviceExtension->BytesPerSector; - if (DeviceExtension->LBASupported) - { - SectorNum = StartingSector & 0xff; - CylinderLow = (StartingSector >> 8) & 0xff; - CylinderHigh = (StartingSector >> 16) & 0xff; - DrvHead = ((StartingSector >> 24) & 0x0f) | - (DeviceExtension->UnitNumber ? IDE_DH_DRV1 : 0) | - IDE_DH_LBA; - } - else - { - SectorNum = (StartingSector % DeviceExtension->SectorsPerLogTrk) + 1; - StartingSector /= DeviceExtension->SectorsPerLogTrk; - DrvHead = (StartingSector % DeviceExtension->LogicalHeads) | - (DeviceExtension->UnitNumber ? IDE_DH_DRV1 : 0); - StartingSector /= DeviceExtension->LogicalHeads; - CylinderLow = StartingSector & 0xff; - CylinderHigh = StartingSector >> 8; - } - Command = DeviceExtension->Operation == IRP_MJ_READ ? - IDE_CMD_READ : IDE_CMD_WRITE; - if (DrvHead & IDE_DH_LBA) - { - DPRINT("%s:BUS=%04x:DRV=%d:LBA=1:BLK=%08d:SC=%02x:CM=%02x\n", - DeviceExtension->Operation == IRP_MJ_READ ? "READ" : "WRITE", - ControllerExtension->CommandPortBase, - DrvHead & IDE_DH_DRV1 ? 1 : 0, - ((DrvHead & 0x0f) << 24) + - (CylinderHigh << 16) + (CylinderLow << 8) + SectorNum, - SectorCnt, - Command); - } - else - { - DPRINT("%s:BUS=%04x:DRV=%d:LBA=0:CH=%02x:CL=%02x:HD=%01x:SN=%02x:SC=%02x:CM=%02x\n", - DeviceExtension->Operation == IRP_MJ_READ ? "READ" : "WRITE", - ControllerExtension->CommandPortBase, - DrvHead & IDE_DH_DRV1 ? 1 : 0, - CylinderHigh, - CylinderLow, - DrvHead & 0x0f, - SectorNum, - SectorCnt, - Command); - } - - /* wait for BUSY to clear */ - for (Retries = 0; Retries < IDE_MAX_BUSY_RETRIES; Retries++) - { - Status = IDEReadStatus(ControllerExtension->CommandPortBase); - if (!(Status & IDE_SR_BUSY)) - { - break; - } - KeStallExecutionProcessor(10); - } - DPRINT ("status=%02x\n", Status); - DPRINT ("waited %ld usecs for busy to clear\n", Retries * 10); - if (Retries >= IDE_MAX_BUSY_RETRIES) - { - DPRINT ("Drive is BUSY for too long\n"); - if (++ControllerExtension->Retries > IDE_MAX_CMD_RETRIES) - { - DbgPrint ("Max Retries on Drive reset reached, returning failure\n"); - Irp = ControllerExtension->CurrentIrp; - Irp->IoStatus.Status = STATUS_DISK_OPERATION_FAILED; - Irp->IoStatus.Information = 0; - - return FALSE; - } - else - { - DPRINT ("Beginning drive reset sequence\n"); - IDEBeginControllerReset(ControllerExtension); - - return TRUE; - } - } - - /* Select the desired drive */ - IDEWriteDriveHead(ControllerExtension->CommandPortBase, IDE_DH_FIXED | DrvHead); - - /* wait for BUSY to clear and DRDY to assert */ - for (Retries = 0; Retries < IDE_MAX_BUSY_RETRIES; Retries++) - { - Status = IDEReadStatus(ControllerExtension->CommandPortBase); -// if (!(Status & IDE_SR_BUSY) && (Status & IDE_SR_DRDY)) - if (!(Status & IDE_SR_BUSY) && !(Status & IDE_SR_DRQ)) - { - break; - } - KeStallExecutionProcessor(10); - } - DPRINT ("waited %ld usecs for busy to clear after drive select\n", Retries * 10); - if (Retries >= IDE_MAX_BUSY_RETRIES) - { - DPRINT ("Drive is BUSY for too long after drive select\n"); - if (ControllerExtension->Retries++ > IDE_MAX_CMD_RETRIES) - { - DbgPrint ("Max Retries on Drive reset reached, returning failure\n"); - Irp = ControllerExtension->CurrentIrp; - Irp->IoStatus.Status = STATUS_DISK_OPERATION_FAILED; - Irp->IoStatus.Information = 0; - - return FALSE; - } - else - { - DPRINT ("Beginning drive reset sequence\n"); - IDEBeginControllerReset(ControllerExtension); - - return TRUE; - } - } - - /* Setup command parameters */ - IDEWritePrecomp(ControllerExtension->CommandPortBase, 0); - IDEWriteSectorCount(ControllerExtension->CommandPortBase, SectorCnt); - IDEWriteSectorNum(ControllerExtension->CommandPortBase, SectorNum); - IDEWriteCylinderHigh(ControllerExtension->CommandPortBase, CylinderHigh); - IDEWriteCylinderLow(ControllerExtension->CommandPortBase, CylinderLow); - IDEWriteDriveHead(ControllerExtension->CommandPortBase, IDE_DH_FIXED | DrvHead); - - /* Issue command to drive */ - IDEWriteCommand(ControllerExtension->CommandPortBase, Command); - ControllerExtension->TimerState = IDETimerCmdWait; - ControllerExtension->TimerCount = IDE_CMD_TIMEOUT; - - if (DeviceExtension->Operation == IRP_MJ_WRITE) - { - - // Wait for controller ready - for (Retries = 0; Retries < IDE_MAX_WRITE_RETRIES; Retries++) - { - BYTE Status = IDEReadStatus(ControllerExtension->CommandPortBase); - if (!(Status & IDE_SR_BUSY) || (Status & IDE_SR_ERR)) - { - break; - } - KeStallExecutionProcessor(10); - } - if (Retries >= IDE_MAX_BUSY_RETRIES) - { - if (ControllerExtension->Retries++ > IDE_MAX_CMD_RETRIES) - { - Irp = ControllerExtension->CurrentIrp; - Irp->IoStatus.Status = STATUS_DISK_OPERATION_FAILED; - Irp->IoStatus.Information = 0; - - return FALSE; - } - else - { - IDEBeginControllerReset(ControllerExtension); - - return TRUE; - } - } - - // Load the first sector of data into the controller - IDEWriteBlock(ControllerExtension->CommandPortBase, - DeviceExtension->TargetAddress, - IDE_SECTOR_BUF_SZ); - DeviceExtension->TargetAddress += IDE_SECTOR_BUF_SZ; - DeviceExtension->BytesToTransfer -= DeviceExtension->BytesPerSector; - DeviceExtension->SectorsTransferred++; - } - DPRINT ("Command issued to drive, IDEStartController done\n"); - - return TRUE; -} - -// IDEBeginControllerReset - -VOID -IDEBeginControllerReset(PIDE_CONTROLLER_EXTENSION ControllerExtension) -{ - int Retries; - - DPRINT("Controller Reset initiated on %04x\n", - ControllerExtension->ControlPortBase); - - /* Assert drive reset line */ - DPRINT("Asserting reset line\n"); - IDEWriteDriveControl(ControllerExtension->ControlPortBase, IDE_DC_SRST); - - /* Wait for BSY assertion */ - DPRINT("Waiting for BSY assertion\n"); - for (Retries = 0; Retries < IDE_MAX_RESET_RETRIES; Retries++) - { - BYTE Status = IDEReadStatus(ControllerExtension->CommandPortBase); - if ((Status & IDE_SR_BUSY)) - { - break; - } - KeStallExecutionProcessor(10); - } - if (Retries == IDE_MAX_RESET_RETRIES) - { - DPRINT("Timeout on BSY assertion\n"); - } - - /* Negate drive reset line */ - DPRINT("Negating reset line\n"); - IDEWriteDriveControl(ControllerExtension->ControlPortBase, 0); - - // FIXME: handle case of no device 0 - - /* Set timer to check for end of reset */ - ControllerExtension->TimerState = IDETimerResetWaitForBusyNegate; - ControllerExtension->TimerCount = IDE_RESET_BUSY_TIMEOUT; -} - -// IDEIsr -// -// DESCIPTION: -// Handle interrupts for IDE devices -// -// RUN LEVEL: -// DIRQL -// -// ARGUMENTS: -// IN PKINTERRUPT Interrupt The interrupt level in effect -// IN PVOID ServiceContext The driver supplied context -// (the controller extension) -// RETURNS: -// TRUE This ISR handled the interrupt -// FALSE Another ISR must handle this interrupt - -static BOOLEAN STDCALL -IDEIsr(IN PKINTERRUPT Interrupt, - IN PVOID ServiceContext) -{ - BOOLEAN IsLastBlock, AnErrorOccured, RequestIsComplete; - BYTE *TargetAddress; - int Retries; - NTSTATUS ErrorStatus; - ULONG ErrorInformation; - PIRP Irp; - PIDE_DEVICE_EXTENSION DeviceExtension; - PIDE_CONTROLLER_EXTENSION ControllerExtension; - - if (IDEInitialized == FALSE) - { - return FALSE; - } - DPRINT ("IDEIsr called\n"); - - ControllerExtension = (PIDE_CONTROLLER_EXTENSION) ServiceContext; - - // Read the status port to clear the interrtupt (even if it's not ours). - ControllerExtension->DeviceStatus = IDEReadStatus(ControllerExtension->CommandPortBase); - - // If the interrupt is not ours, get the heck outta dodge. - if (!ControllerExtension->OperationInProgress) - { - return FALSE; - } - - DeviceExtension = ControllerExtension->DeviceForOperation; - IsLastBlock = FALSE; - AnErrorOccured = FALSE; - RequestIsComplete = FALSE; - ErrorStatus = STATUS_SUCCESS; - ErrorInformation = 0; - - // Handle error condition if it exists - if (ControllerExtension->DeviceStatus & IDE_SR_ERR) - { - BYTE ErrorReg, SectorCount, SectorNum, CylinderLow, CylinderHigh; - BYTE DriveHead; - - // Log the error - ErrorReg = IDEReadError(ControllerExtension->CommandPortBase); - CylinderLow = IDEReadCylinderLow(ControllerExtension->CommandPortBase); - CylinderHigh = IDEReadCylinderHigh(ControllerExtension->CommandPortBase); - DriveHead = IDEReadDriveHead(ControllerExtension->CommandPortBase); - SectorCount = IDEReadSectorCount(ControllerExtension->CommandPortBase); - SectorNum = IDEReadSectorNum(ControllerExtension->CommandPortBase); - // FIXME: should use the NT error logging facility - DbgPrint ("IDE Error: OP:%02x STAT:%02x ERR:%02x CYLLO:%02x CYLHI:%02x SCNT:%02x SNUM:%02x\n", - DeviceExtension->Operation, - ControllerExtension->DeviceStatus, - ErrorReg, - CylinderLow, - CylinderHigh, - SectorCount, - SectorNum); - - // FIXME: should retry the command and perhaps recalibrate the drive - - // Set error status information - AnErrorOccured = TRUE; - ErrorStatus = STATUS_DISK_OPERATION_FAILED; - ErrorInformation = - (((((((CylinderHigh << 8) + CylinderLow) * - DeviceExtension->LogicalHeads) + - (DriveHead % DeviceExtension->LogicalHeads)) * - DeviceExtension->SectorsPerLogTrk) + SectorNum - 1) - - DeviceExtension->StartingSector) * DeviceExtension->BytesPerSector; - } - else - { - - // Check controller and setup for next transfer - switch (DeviceExtension->Operation) - { - case IRP_MJ_READ: - - // Update controller/device state variables - TargetAddress = DeviceExtension->TargetAddress; - DeviceExtension->TargetAddress += DeviceExtension->BytesPerSector; - DeviceExtension->BytesToTransfer -= DeviceExtension->BytesPerSector; - DeviceExtension->SectorsTransferred++; - - // Remember whether DRQ should be low at end (last block read) - IsLastBlock = DeviceExtension->BytesToTransfer == 0; - - // Wait for DRQ assertion - for (Retries = 0; Retries < IDE_MAX_DRQ_RETRIES && - !(IDEReadStatus(ControllerExtension->CommandPortBase) & IDE_SR_DRQ); - Retries++) - { - KeStallExecutionProcessor(10); - } - - // Copy the block of data - IDEReadBlock(ControllerExtension->CommandPortBase, - TargetAddress, - IDE_SECTOR_BUF_SZ); - - // check DRQ - if (IsLastBlock) - { - for (Retries = 0; Retries < IDE_MAX_BUSY_RETRIES && - (IDEReadStatus(ControllerExtension->CommandPortBase) & IDE_SR_BUSY); - Retries++) - { - KeStallExecutionProcessor(10); - } - - // Check for data overrun - if (IDEReadStatus(ControllerExtension->CommandPortBase) & IDE_SR_DRQ) - { - AnErrorOccured = TRUE; - ErrorStatus = STATUS_DATA_OVERRUN; - ErrorInformation = 0; - } - else - { - - // Setup next transfer or set RequestIsComplete - if (DeviceExtension->BytesRequested > - DeviceExtension->BytesPerSector * IDE_MAX_SECTORS_PER_XFER) - { - DeviceExtension->StartingSector += DeviceExtension->SectorsTransferred; - DeviceExtension->SectorsTransferred = 0; - DeviceExtension->BytesToTransfer = - DeviceExtension->BytesPerSector * IDE_MAX_SECTORS_PER_XFER; - DeviceExtension->BytesRequested -= DeviceExtension->BytesToTransfer; - } - else if (DeviceExtension->BytesRequested > 0) - { - DeviceExtension->StartingSector += DeviceExtension->SectorsTransferred; - DeviceExtension->SectorsTransferred = 0; - DeviceExtension->BytesToTransfer = DeviceExtension->BytesRequested; - DeviceExtension->BytesRequested -= DeviceExtension->BytesToTransfer; - } - else - { - RequestIsComplete = TRUE; - } - } - } - break; - - case IRP_MJ_WRITE: - - // check DRQ - if (DeviceExtension->BytesToTransfer == 0) - { - for (Retries = 0; Retries < IDE_MAX_BUSY_RETRIES && - (IDEReadStatus(ControllerExtension->CommandPortBase) & IDE_SR_BUSY); - Retries++) - { - KeStallExecutionProcessor(10); - } - - // Check for data overrun - if (IDEReadStatus(ControllerExtension->CommandPortBase) & IDE_SR_DRQ) - { - AnErrorOccured = TRUE; - ErrorStatus = STATUS_DATA_OVERRUN; - ErrorInformation = 0; - } - else - { - - // Setup next transfer or set RequestIsComplete - IsLastBlock = TRUE; - if (DeviceExtension->BytesRequested > - DeviceExtension->BytesPerSector * IDE_MAX_SECTORS_PER_XFER) - { - DeviceExtension->StartingSector += DeviceExtension->SectorsTransferred; - DeviceExtension->SectorsTransferred = 0; - DeviceExtension->BytesToTransfer = - DeviceExtension->BytesPerSector * IDE_MAX_SECTORS_PER_XFER; - DeviceExtension->BytesRequested -= DeviceExtension->BytesToTransfer; - } - else if (DeviceExtension->BytesRequested > 0) - { - DeviceExtension->StartingSector += DeviceExtension->SectorsTransferred; - DeviceExtension->SectorsTransferred = 0; - DeviceExtension->BytesToTransfer = DeviceExtension->BytesRequested; - DeviceExtension->BytesRequested -= DeviceExtension->BytesToTransfer; - } - else - { - RequestIsComplete = TRUE; - } - } - } - else - { - - // Update controller/device state variables - TargetAddress = DeviceExtension->TargetAddress; - DeviceExtension->TargetAddress += DeviceExtension->BytesPerSector; - DeviceExtension->BytesToTransfer -= DeviceExtension->BytesPerSector; - DeviceExtension->SectorsTransferred++; - - // Write block to controller - IDEWriteBlock(ControllerExtension->CommandPortBase, - TargetAddress, - IDE_SECTOR_BUF_SZ); - } - break; - } - } - - // If there was an error or the request is done, complete the packet - if (AnErrorOccured || RequestIsComplete) - { - // Set the return status and info values - Irp = ControllerExtension->CurrentIrp; - Irp->IoStatus.Status = ErrorStatus; - Irp->IoStatus.Information = ErrorInformation; - - // Clear out controller fields - ControllerExtension->OperationInProgress = FALSE; - ControllerExtension->DeviceStatus = 0; - - // Queue the Dpc to finish up - IoRequestDpc(DeviceExtension->DeviceObject, - Irp, - ControllerExtension); - } - else if (IsLastBlock) - { - // Else more data is needed, setup next device I/O - IDEStartController((PVOID)DeviceExtension); - } - - return TRUE; -} - -// IDEDpcForIsr -// DESCRIPTION: -// -// RUN LEVEL: -// -// ARGUMENTS: -// IN PKDPC Dpc -// IN PDEVICE_OBJECT DpcDeviceObject -// IN PIRP DpcIrp -// IN PVOID DpcContext -// -static VOID -IDEDpcForIsr(IN PKDPC Dpc, - IN PDEVICE_OBJECT DpcDeviceObject, - IN PIRP DpcIrp, - IN PVOID DpcContext) -{ - DPRINT("IDEDpcForIsr()\n"); - IDEFinishOperation((PIDE_CONTROLLER_EXTENSION) DpcContext); -} - -// IDEFinishOperation - -static VOID -IDEFinishOperation(PIDE_CONTROLLER_EXTENSION ControllerExtension) -{ - PIDE_DEVICE_EXTENSION DeviceExtension; - PIRP Irp; - ULONG Operation; - - DeviceExtension = ControllerExtension->DeviceForOperation; - Irp = ControllerExtension->CurrentIrp; - Operation = DeviceExtension->Operation; - ControllerExtension->OperationInProgress = FALSE; - ControllerExtension->DeviceForOperation = 0; - ControllerExtension->CurrentIrp = 0; - - // Deallocate the controller - IoFreeController(DeviceExtension->ControllerObject); - - // Start the next packet - IoStartNextPacketByKey(DeviceExtension->DeviceObject, - FALSE, - DeviceExtension->StartingSector); - - // Flush cache if necessary - if (Operation == IRP_MJ_READ) - { - KeFlushIoBuffers(Irp->MdlAddress, TRUE, FALSE); - } - // Issue completion of the current packet - // return status information too - Irp->IoStatus.Status = STATUS_SUCCESS; - Irp->IoStatus.Information = DeviceExtension->SectorsTransferred * DeviceExtension->BytesPerSector; - IoCompleteRequest(Irp, IO_DISK_INCREMENT); -} - -// IDEIoTimer -// DESCRIPTION: -// This function handles timeouts and other time delayed processing -// -// RUN LEVEL: -// -// ARGUMENTS: -// IN PDEVICE_OBJECT DeviceObject Device object registered with timer -// IN PVOID Context the Controller extension for the -// controller the device is on -// -static VOID STDCALL -IDEIoTimer(PDEVICE_OBJECT DeviceObject, - PVOID Context) -{ - PIDE_CONTROLLER_EXTENSION ControllerExtension; - - // Setup Extension pointer - ControllerExtension = (PIDE_CONTROLLER_EXTENSION) Context; - DPRINT("Timer activated for %04lx\n", ControllerExtension->CommandPortBase); - - // Handle state change if necessary - switch (ControllerExtension->TimerState) - { - case IDETimerResetWaitForBusyNegate: - if (!(IDEReadStatus(ControllerExtension->CommandPortBase) & - IDE_SR_BUSY)) - { - DPRINT("Busy line has negated, waiting for DRDY assert\n"); - ControllerExtension->TimerState = IDETimerResetWaitForDrdyAssert; - ControllerExtension->TimerCount = IDE_RESET_DRDY_TIMEOUT; - return; - } - break; - - case IDETimerResetWaitForDrdyAssert: - if (IDEReadStatus(ControllerExtension->CommandPortBase) & - IDE_SR_DRQ) - { - DPRINT("DRDY has asserted, reset complete\n"); - ControllerExtension->TimerState = IDETimerIdle; - ControllerExtension->TimerCount = 0; - - // FIXME: get diagnostic code from drive 0 - - /* Start current packet command again */ - if (!KeSynchronizeExecution(ControllerExtension->Interrupt, - IDEStartController, - ControllerExtension->DeviceForOperation)) - { - IDEFinishOperation(ControllerExtension); - } - return; - } - break; - - default: - break; - } - - // If we're counting down, then count. - if (ControllerExtension->TimerCount > 0) - { - ControllerExtension->TimerCount--; - - // Else we'll check the state and process if necessary - } - else - { - switch (ControllerExtension->TimerState) - { - case IDETimerIdle: - break; - - case IDETimerCmdWait: - /* Command timed out, reset drive and try again or fail */ - DPRINT("Timeout waiting for command completion\n"); - if (++ControllerExtension->Retries > IDE_MAX_CMD_RETRIES) - { - if (ControllerExtension->CurrentIrp != NULL) - { - DbgPrint ("Max retries has been reached, IRP finished with error\n"); - ControllerExtension->CurrentIrp->IoStatus.Status = STATUS_IO_TIMEOUT; - ControllerExtension->CurrentIrp->IoStatus.Information = 0; - IDEFinishOperation(ControllerExtension); - } - ControllerExtension->TimerState = IDETimerIdle; - ControllerExtension->TimerCount = 0; - } - else - { - IDEBeginControllerReset(ControllerExtension); - } - break; - - case IDETimerResetWaitForBusyNegate: - case IDETimerResetWaitForDrdyAssert: - if (ControllerExtension->CurrentIrp != NULL) - { - DbgPrint ("Timeout waiting for drive reset, giving up on IRP\n"); - ControllerExtension->CurrentIrp->IoStatus.Status = - STATUS_IO_TIMEOUT; - ControllerExtension->CurrentIrp->IoStatus.Information = 0; - IDEFinishOperation(ControllerExtension); - } - ControllerExtension->TimerState = IDETimerIdle; - ControllerExtension->TimerCount = 0; - break; - } - } -} - - diff --git a/reactos/drivers/dd/ide/ide.h b/reactos/drivers/dd/ide/ide.h deleted file mode 100644 index 9ad89a2cc6a..00000000000 --- a/reactos/drivers/dd/ide/ide.h +++ /dev/null @@ -1,256 +0,0 @@ -// -// IDE.H - defines and typedefs for the IDE Driver module. -// - -#ifndef __IDE_H -#define __IDE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define IDE_MAXIMUM_DEVICES 8 - -#define IDE_MAX_NAME_LENGTH 50 - -#define IDE_SECTOR_BUF_SZ 512 -#define IDE_MAX_SECTORS_PER_XFER 256 -#define IDE_MAX_RESET_RETRIES 10000 -#define IDE_MAX_POLL_RETRIES 100000 -#define IDE_MAX_WRITE_RETRIES 1000 -#define IDE_MAX_BUSY_RETRIES 50000 -#define IDE_MAX_DRQ_RETRIES 10000 -//#define IDE_MAX_CMD_RETRIES 1 -#define IDE_MAX_CMD_RETRIES 0 -#define IDE_CMD_TIMEOUT 5 -#define IDE_RESET_PULSE_LENGTH 500 /* maybe a little too long */ -#define IDE_RESET_BUSY_TIMEOUT 120 -#define IDE_RESET_DRDY_TIMEOUT 120 - -// Control Block offsets and masks -#define IDE_REG_ALT_STATUS 0x0000 -#define IDE_REG_DEV_CNTRL 0x0000 /* device control register */ -#define IDE_DC_SRST 0x04 /* drive reset (both drives) */ -#define IDE_DC_nIEN 0x02 /* IRQ enable (active low) */ -#define IDE_REG_DRV_ADDR 0x0001 - -// Command Block offsets and masks -#define IDE_REG_DATA_PORT 0x0000 -#define IDE_REG_ERROR 0x0001 /* error register */ -#define IDE_ER_AMNF 0x01 /* addr mark not found */ -#define IDE_ER_TK0NF 0x02 /* track 0 not found */ -#define IDE_ER_ABRT 0x04 /* command aborted */ -#define IDE_ER_MCR 0x08 /* media change requested */ -#define IDE_ER_IDNF 0x10 /* ID not found */ -#define IDE_ER_MC 0x20 /* Media changed */ -#define IDE_ER_UNC 0x40 /* Uncorrectable data error */ -#define IDE_REG_PRECOMP 0x0001 -#define IDE_REG_SECTOR_CNT 0x0002 -#define IDE_REG_SECTOR_NUM 0x0003 -#define IDE_REG_CYL_LOW 0x0004 -#define IDE_REG_CYL_HIGH 0x0005 -#define IDE_REG_DRV_HEAD 0x0006 -#define IDE_DH_FIXED 0xA0 -#define IDE_DH_LBA 0x40 -#define IDE_DH_HDMASK 0x0F -#define IDE_DH_DRV0 0x00 -#define IDE_DH_DRV1 0x10 -#define IDE_REG_STATUS 0x0007 -#define IDE_SR_BUSY 0x80 -#define IDE_SR_DRDY 0x40 -#define IDE_SR_DRQ 0x08 -#define IDE_SR_ERR 0x01 -#define IDE_REG_COMMAND 0x0007 -#define IDE_CMD_READ 0x20 -#define IDE_CMD_READ_RETRY 0x21 -#define IDE_CMD_WRITE 0x30 -#define IDE_CMD_WRITE_RETRY 0x31 -#define IDE_CMD_IDENT_DRV 0xEC - -// -// Access macros for command registers -// Each macro takes an address of the command port block, and data -// -#define IDEReadError(Address) \ - (READ_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_ERROR))) -#define IDEWritePrecomp(Address, Data) \ - (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_PRECOMP), (Data))) -#define IDEReadSectorCount(Address) \ - (READ_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_SECTOR_CNT))) -#define IDEWriteSectorCount(Address, Data) \ - (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_SECTOR_CNT), (Data))) -#define IDEReadSectorNum(Address) \ - (READ_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_SECTOR_NUM))) -#define IDEWriteSectorNum(Address, Data) \ - (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_SECTOR_NUM), (Data))) -#define IDEReadCylinderLow(Address) \ - (READ_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_CYL_LOW))) -#define IDEWriteCylinderLow(Address, Data) \ - (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_CYL_LOW), (Data))) -#define IDEReadCylinderHigh(Address) \ - (READ_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_CYL_HIGH))) -#define IDEWriteCylinderHigh(Address, Data) \ - (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_CYL_HIGH), (Data))) -#define IDEReadDriveHead(Address) \ - (READ_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_DRV_HEAD))) -#define IDEWriteDriveHead(Address, Data) \ - (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_DRV_HEAD), (Data))) -#define IDEReadStatus(Address) \ - (READ_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_STATUS))) -#define IDEWriteCommand(Address, Data) \ - (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_COMMAND), (Data))) - - -// -// Data block read and write commands -// -#define IDEReadBlock(Address, Buffer, Count) \ - (READ_PORT_BUFFER_USHORT((PUSHORT)((Address) + IDE_REG_DATA_PORT), (PUSHORT)(Buffer), (Count) / 2)) -#define IDEWriteBlock(Address, Buffer, Count) \ - (WRITE_PORT_BUFFER_USHORT((PUSHORT)((Address) + IDE_REG_DATA_PORT), (PUSHORT)(Buffer), (Count) / 2)) - -// -// Access macros for control registers -// Each macro takes an address of the control port blank and data -// -#define IDEWriteDriveControl(Address, Data) \ - (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_DEV_CNTRL), (Data))) - -// IDE_DEVICE_EXTENSION -// -// DESCRIPTION: -// Extension to be placed in each device object -// -// ACCESS: -// Allocated from NON-PAGED POOL -// Available at any IRQL -// - -typedef struct _IDE_DEVICE_EXTENSION -{ - PDEVICE_OBJECT DeviceObject; - PCONTROLLER_OBJECT ControllerObject; - PVOID DiskDeviceExtension; - int UnitNumber; - BOOLEAN LBASupported; - BOOLEAN DMASupported; - int BytesPerSector; - int LogicalHeads; - int LogicalCylinders; - int SectorsPerLogCyl; - int SectorsPerLogTrk; - - LARGE_INTEGER StartingOffset; - LARGE_INTEGER PartitionLength; - ULONG HiddenSectors; - ULONG PartitionNumber; - UCHAR PartitionType; - BOOLEAN BootIndicator; - - int Operation; - ULONG BytesRequested; - ULONG BytesToTransfer; - ULONG BytesRemaining; - ULONG StartingSector; - int SectorsTransferred; - BYTE *TargetAddress; - -} IDE_DEVICE_EXTENSION, *PIDE_DEVICE_EXTENSION; - -// IDE_TIMER_STATES -// -// DESCRIPTION: -// An enumeration containing the states in the timer DFA -// - -typedef enum _IDE_TIMER_STATES { - IDETimerIdle, - IDETimerCmdWait, - IDETimerResetWaitForBusyNegate, - IDETimerResetWaitForDrdyAssert -} IDE_TIMER_STATES; - -// IDE_CONTROLLER_EXTENSION -// -// DESCRIPTION: -// Driver-defined structure used to hold miscellaneous controller information. -// -// ACCESS: -// Allocated from NON-PAGED POOL -// Available at any IRQL -// - -typedef struct _IDE_CONTROLLER_EXTENSION { - KSPIN_LOCK SpinLock; - int Number; - int Vector; - int CommandPortBase; - int ControlPortBase; - BOOLEAN DMASupported; - BOOLEAN ControllerInterruptBug; - PKINTERRUPT Interrupt; - - BOOLEAN OperationInProgress; - BYTE DeviceStatus; - PIDE_DEVICE_EXTENSION DeviceForOperation; - PIRP CurrentIrp; - int Retries; - - IDE_TIMER_STATES TimerState; - LONG TimerCount; - PDEVICE_OBJECT TimerDevice; - -} IDE_CONTROLLER_EXTENSION, *PIDE_CONTROLLER_EXTENSION; - -// IDE_DRIVE_IDENTIFY - -typedef struct _IDE_DRIVE_IDENTIFY { - WORD ConfigBits; /*00*/ - WORD LogicalCyls; /*01*/ - WORD Reserved02; /*02*/ - WORD LogicalHeads; /*03*/ - WORD BytesPerTrack; /*04*/ - WORD BytesPerSector; /*05*/ - WORD SectorsPerTrack; /*06*/ - BYTE InterSectorGap; /*07*/ - BYTE InterSectorGapSize; - BYTE Reserved08H; /*08*/ - BYTE BytesInPLO; - WORD VendorUniqueCnt; /*09*/ - char SerialNumber[20]; /*10*/ - WORD ControllerType; /*20*/ - WORD BufferSize; /*21*/ - WORD ECCByteCnt; /*22*/ - char FirmwareRev[8]; /*23*/ - char ModelNumber[40]; /*27*/ - WORD RWMultImplemented; /*47*/ - WORD Reserved48; /*48*/ - WORD Capabilities; /*49*/ -#define IDE_DRID_STBY_SUPPORTED 0x2000 -#define IDE_DRID_IORDY_SUPPORTED 0x0800 -#define IDE_DRID_IORDY_DISABLE 0x0400 -#define IDE_DRID_LBA_SUPPORTED 0x0200 -#define IDE_DRID_DMA_SUPPORTED 0x0100 - WORD Reserved50; /*50*/ - WORD MinPIOTransTime; /*51*/ - WORD MinDMATransTime; /*52*/ - WORD TMFieldsValid; /*53*/ - WORD TMCylinders; /*54*/ - WORD TMHeads; /*55*/ - WORD TMSectorsPerTrk; /*56*/ - WORD TMCapacityLo; /*57*/ - WORD TMCapacityHi; /*58*/ - WORD Reserved59; /*59*/ - WORD TMSectorCountLo; /*60*/ - WORD TMSectorCountHi; /*61*/ - WORD Reserved62[194]; /*62*/ -} IDE_DRIVE_IDENTIFY, *PIDE_DRIVE_IDENTIFY; - - -#ifdef __cplusplus -} -#endif - -#endif /* __IDE_H */ - - diff --git a/reactos/drivers/dd/ide/ide.rc b/reactos/drivers/dd/ide/ide.rc deleted file mode 100644 index 5981746c951..00000000000 --- a/reactos/drivers/dd/ide/ide.rc +++ /dev/null @@ -1,39 +0,0 @@ - -#include -#include - -LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US - -VS_VERSION_INFO VERSIONINFO - FILEVERSION RES_UINT_FV_MAJOR,RES_UINT_FV_MINOR,RES_UINT_FV_REVISION,RES_UINT_FV_BUILD - PRODUCTVERSION RES_UINT_PV_MAJOR,RES_UINT_PV_MINOR,RES_UINT_PV_REVISION,RES_UINT_PV_BUILD - FILEFLAGSMASK 0x3fL -#ifdef _DEBUG - FILEFLAGS 0x1L -#else - FILEFLAGS 0x0L -#endif - FILEOS 0x40004L - FILETYPE 0x2L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904b0" - BEGIN - VALUE "CompanyName", RES_STR_COMPANY_NAME - VALUE "FileDescription", "IDE Disk Device Driver\0" - VALUE "FileVersion", "0.1.4\0" - VALUE "InternalName", "ide\0" - VALUE "LegalCopyright", RES_STR_LEGAL_COPYRIGHT - VALUE "OriginalFilename", "ide.sys\0" - VALUE "ProductName", RES_STR_PRODUCT_NAME - VALUE "ProductVersion", RES_STR_PRODUCT_VERSION - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1200 - END -END - diff --git a/reactos/drivers/dd/ide/makefile b/reactos/drivers/dd/ide/makefile deleted file mode 100644 index ea15dd78c9f..00000000000 --- a/reactos/drivers/dd/ide/makefile +++ /dev/null @@ -1,19 +0,0 @@ -# $Id: makefile,v 1.27 2003/11/14 17:13:25 weiden Exp $ - -PATH_TO_TOP = ../../.. - -TARGET_TYPE = driver - -TARGET_NAME = ide - -TARGET_CFLAGS = -Wall -Werror - -TARGET_OBJECTS = ide.o - -TARGET_HEADERS = *.h - -TARGET_GCCLIBS = gcc - -include $(PATH_TO_TOP)/rules.mak - -include $(TOOLS_PATH)/helper.mk diff --git a/reactos/drivers/dd/ide/partitio.h b/reactos/drivers/dd/ide/partitio.h deleted file mode 100644 index 06841ee39fa..00000000000 --- a/reactos/drivers/dd/ide/partitio.h +++ /dev/null @@ -1,41 +0,0 @@ -/** -*** Partition.h - defines and structs for harddrive partition info -*** -*** 05/30/98 RJJ Created -**/ - -#ifndef __PARTITION_H -#define __PARTITION_H - -#define PARTITION_MAGIC 0xaa55 -#define PART_MAGIC_OFFSET 0x01fe -#define PARTITION_OFFSET 0x01be -#define PARTITION_TBL_SIZE 4 -#define PTCHSToLBA(c, h, s, scnt, hcnt) ((s) & 0x3f) + \ - (scnt) * ( (h) + (hcnt) * ((c) | (((s) & 0xc0) << 2))) -#define PTLBAToCHS(lba, c, h, s, scnt, hcnt) ( \ - (s) = (lba) % (scnt) + 1, \ - (lba) /= (scnt), \ - (h) = (lba) % (hcnt), \ - (lba) /= (heads), \ - (c) = (lba) & 0xff, \ - (s) |= ((lba) >> 2) & 0xc0) - - -typedef struct Partition { - unsigned char BootFlags; - unsigned char StartingHead; - unsigned char StartingSector; - unsigned char StartingCylinder; - unsigned char PartitionType; - unsigned char EndingHead; - unsigned char EndingSector; - unsigned char EndingCylinder; - unsigned int StartingBlock; - unsigned int SectorCount; - -} PARTITION; - -#endif // PARTITION_H - -