Add pciidex (controller driver) and pciide (miniport driver). They enumerate channels 0 and 1 on IDE controllers. Modified: trunk/reactos/bootdata/packages/reactos.dff Modified: trunk/reactos/drivers/storage/directory.xml Added: trunk/reactos/drivers/storage/pciide/ Added: trunk/reactos/drivers/storage/pciide/pciide.c Added: trunk/reactos/drivers/storage/pciide/pciide.h Added: trunk/reactos/drivers/storage/pciide/pciide.rc Added: trunk/reactos/drivers/storage/pciide/pciide.xml Added: trunk/reactos/drivers/storage/pciidex/ Added: trunk/reactos/drivers/storage/pciidex/fdo.c Added: trunk/reactos/drivers/storage/pciidex/miniport.c Added: trunk/reactos/drivers/storage/pciidex/misc.c Added: trunk/reactos/drivers/storage/pciidex/pciidex.c Added: trunk/reactos/drivers/storage/pciidex/pciidex.def Added: trunk/reactos/drivers/storage/pciidex/pciidex.h Added: trunk/reactos/drivers/storage/pciidex/pciidex.rc Added: trunk/reactos/drivers/storage/pciidex/pciidex.xml Added: trunk/reactos/drivers/storage/pciidex/pdo.c Added: trunk/reactos/media/inf/hdc.inf Modified: trunk/reactos/media/inf/syssetup.inf Added: trunk/reactos/w32api/include/ddk/ide.h _____
Modified: trunk/reactos/bootdata/packages/reactos.dff --- trunk/reactos/bootdata/packages/reactos.dff 2005-10-20 18:55:45 UTC (rev 18643) +++ trunk/reactos/bootdata/packages/reactos.dff 2005-10-20 19:33:16 UTC (rev 18644) @@ -293,7 +293,7 @@
media\drivers\etc\services 5 media\inf\acpi.inf 6 media\inf\cdrom.inf 6 -media\inf\NET_NIC.inf 6 +media\inf\hdc.inf 6 media\inf\layout.inf 6 media\inf\machine.inf 6 media\inf\mouse.inf 6 _____
Modified: trunk/reactos/drivers/storage/directory.xml --- trunk/reactos/drivers/storage/directory.xml 2005-10-20 18:55:45 UTC (rev 18643) +++ trunk/reactos/drivers/storage/directory.xml 2005-10-20 19:33:16 UTC (rev 18644) @@ -16,6 +16,12 @@
<directory name="floppy"> <xi:include href="floppy/floppy.xml" /> </directory> +<directory name="pciide"> + <xi:include href="pciide/pciide.xml" /> +</directory> +<directory name="pciidex"> + <xi:include href="pciidex/pciidex.xml" /> +</directory> <directory name="scsiport"> <xi:include href="scsiport/scsiport.xml" /> </directory> Property changes on: trunk/reactos/drivers/storage/pciide ___________________________________________________________________ Name: svn:ignore + GNUmakefile *.bak _____
Added: trunk/reactos/drivers/storage/pciide/pciide.c --- trunk/reactos/drivers/storage/pciide/pciide.c 2005-10-20 18:55:45 UTC (rev 18643) +++ trunk/reactos/drivers/storage/pciide/pciide.c 2005-10-20 19:33:16 UTC (rev 18644) @@ -0,0 +1,132 @@
+/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: PCI IDE bus driver + * FILE: drivers/storage/pciide/pciide.c + * PURPOSE: Main file + * PROGRAMMERS: HervÚ Poussineau (hpoussin@reactos.org) + */ + +#define NDEBUG +#include <debug.h> + +#include "pciide.h" + +IDE_CHANNEL_STATE NTAPI +PciIdeChannelEnabled( + IN PVOID DeviceExtension, + IN ULONG Channel) +{ + PCI_COMMON_CONFIG PciConfig; + NTSTATUS Status; + + DPRINT("PciIdeChannelEnabled(%p, %lu)\n", DeviceExtension, Channel); + + Status = PciIdeXGetBusData( + DeviceExtension, + &PciConfig, + 0, + PCI_COMMON_HDR_LENGTH); + if (!NT_SUCCESS(Status)) + { + DPRINT("PciIdeXGetBusData() failed with status 0x%08lx\n", Status); + return ChannelStateUnknown; + } + + if (PCI_CONFIGURATION_TYPE(&PciConfig) != PCI_DEVICE_TYPE) + { + DPRINT("Wrong PCI card type. Disabling IDE channel #%lu\n", Channel); + return ChannelDisabled; + } + + if (PciConfig.BaseClass != PCI_CLASS_MASS_STORAGE_CTLR || PciConfig.SubClass != PCI_SUBCLASS_MSC_IDE_CTLR) + { + DPRINT("Wrong PCI card base class/sub class. Disabling IDE channel #%lu\n", Channel); + return ChannelDisabled; + } + + /* FIXME: I don't know where to find the enabled/disabled + * bits for channels, so assume they are always enabled + */ + return ChannelEnabled; +} + +BOOLEAN NTAPI +PciIdeSyncAccessRequired( + IN PVOID DeviceExtension) +{ + DPRINT1("PciIdeSyncAccessRequired %p\n", DeviceExtension); + + return FALSE; /* FIXME */ +} + +NTSTATUS NTAPI +PciIdeTransferModeSelect( + IN PVOID DeviceExtension, + IN PPCIIDE_TRANSFER_MODE_SELECT XferMode) +{ + ULONG i; + + DPRINT1("PciIdeTransferModeSelect(%p %p)\n", DeviceExtension, XferMode); + + for (i = 0; i < MAX_IDE_DEVICE; i++) + XferMode->DevicePresent[i] = FALSE; /* FIXME */ + + return STATUS_SUCCESS; +} + +BOOLEAN NTAPI +PciIdeUseDma( + IN PVOID DeviceExtension, + IN PUCHAR CdbCommand, + IN PUCHAR Slave) +{ + DPRINT1("PciIdeUseDma(%p %p %p)\n", DeviceExtension, CdbCommand, Slave); + + return FALSE; +} + +NTSTATUS NTAPI +PciIdeGetControllerProperties( + IN PVOID DeviceExtension, + OUT PIDE_CONTROLLER_PROPERTIES ControllerProperties) +{ + if (ControllerProperties->Size != sizeof(IDE_CONTROLLER_PROPERTIES)) + return STATUS_REVISION_MISMATCH; + + ControllerProperties->PciIdeChannelEnabled = PciIdeChannelEnabled; + ControllerProperties->PciIdeSyncAccessRequired = PciIdeSyncAccessRequired; + ControllerProperties->PciIdeTransferModeSelect = PciIdeTransferModeSelect; + ControllerProperties->IgnoreActiveBitForAtaDevice = FALSE; + ControllerProperties->AlwaysClearBusMasterInterrupt = TRUE; + ControllerProperties->PciIdeUseDma = PciIdeUseDma; + ControllerProperties->AlignmentRequirement = 1; /* FIXME */ + ControllerProperties->DefaultPIO = 0; /* FIXME */ + ControllerProperties->PciIdeUdmaModesSupported = NULL; /* optional */ + + ControllerProperties->SupportedTransferMode[0][0] = + ControllerProperties->SupportedTransferMode[0][1] = + ControllerProperties->SupportedTransferMode[1][0] = + ControllerProperties->SupportedTransferMode[1][0] = + PIO_MODE0 | PIO_MODE1 | PIO_MODE2 | PIO_MODE3 | PIO_MODE4 | + SWDMA_MODE0 | SWDMA_MODE1 | SWDMA_MODE2 | + MWDMA_MODE0 | MWDMA_MODE1 | MWDMA_MODE2 | + UDMA_MODE0 | UDMA_MODE1 | UDMA_MODE2 | UDMA_MODE3 | UDMA_MODE4; + + return STATUS_SUCCESS; +} + +NTSTATUS NTAPI +DriverEntry( + IN PDRIVER_OBJECT DriverObject, + IN PUNICODE_STRING RegistryPath) +{ + NTSTATUS Status; + + Status = PciIdeXInitialize( + DriverObject, + RegistryPath, + PciIdeGetControllerProperties, + 0); + + return Status; +} Property changes on: trunk/reactos/drivers/storage/pciide/pciide.c ___________________________________________________________________ Name: svn:eol-style + native _____
Added: trunk/reactos/drivers/storage/pciide/pciide.h --- trunk/reactos/drivers/storage/pciide/pciide.h 2005-10-20 18:55:45 UTC (rev 18643) +++ trunk/reactos/drivers/storage/pciide/pciide.h 2005-10-20 19:33:16 UTC (rev 18644) @@ -0,0 +1,2 @@
+#include <ntddk.h> +#include <ide.h> Property changes on: trunk/reactos/drivers/storage/pciide/pciide.h ___________________________________________________________________ Name: svn:eol-style + native _____
Added: trunk/reactos/drivers/storage/pciide/pciide.rc --- trunk/reactos/drivers/storage/pciide/pciide.rc 2005-10-20 18:55:45 UTC (rev 18643) +++ trunk/reactos/drivers/storage/pciide/pciide.rc 2005-10-20 19:33:16 UTC (rev 18644) @@ -0,0 +1,5 @@
+#define REACTOS_VERSION_DLL +#define REACTOS_STR_FILE_DESCRIPTION "PCI IDE bus driver\0" +#define REACTOS_STR_INTERNAL_NAME "pciide\0" +#define REACTOS_STR_ORIGINAL_FILENAME "pciide.sys\0" +#include <reactos/version.rc> Property changes on: trunk/reactos/drivers/storage/pciide/pciide.rc ___________________________________________________________________ Name: svn:eol-style + native _____
Added: trunk/reactos/drivers/storage/pciide/pciide.xml --- trunk/reactos/drivers/storage/pciide/pciide.xml 2005-10-20 18:55:45 UTC (rev 18643) +++ trunk/reactos/drivers/storage/pciide/pciide.xml 2005-10-20 19:33:16 UTC (rev 18644) @@ -0,0 +1,7 @@
+<module name="pciide" type="kernelmodedriver" installbase="system32/drivers" installname="pciide.sys"> + <define name="__USE_W32API" /> + <library>pciidex</library> + <library>ntoskrnl</library> + <file>pciide.c</file> + <file>pciide.rc</file> +</module> Property changes on: trunk/reactos/drivers/storage/pciide/pciide.xml ___________________________________________________________________ Name: svn:eol-style + native Property changes on: trunk/reactos/drivers/storage/pciidex ___________________________________________________________________ Name: svn:ignore + GNUmakefile *.bak _____
Added: trunk/reactos/drivers/storage/pciidex/fdo.c --- trunk/reactos/drivers/storage/pciidex/fdo.c 2005-10-20 18:55:45 UTC (rev 18643) +++ trunk/reactos/drivers/storage/pciidex/fdo.c 2005-10-20 19:33:16 UTC (rev 18644) @@ -0,0 +1,437 @@
+/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: PCI IDE bus driver extension + * FILE: drivers/storage/pciidex/fdo.c + * PURPOSE: IRP_MJ_PNP operations for FDOs + * PROGRAMMERS: HervÚ Poussineau (hpoussin@reactos.org) + */ + +#define NDEBUG +#include <debug.h> + +#include "pciidex.h" + +static NTSTATUS +GetBusInterface( + IN PFDO_DEVICE_EXTENSION DeviceExtension) +{ + PBUS_INTERFACE_STANDARD BusInterface = NULL; + KEVENT Event; + IO_STATUS_BLOCK IoStatus; + PIRP Irp; + PIO_STACK_LOCATION Stack; + NTSTATUS Status = STATUS_UNSUCCESSFUL; + + if (DeviceExtension->BusInterface) + { + DPRINT("We already have the bus interface\n"); + goto cleanup; + } + + BusInterface = ExAllocatePool(PagedPool, sizeof(BUS_INTERFACE_STANDARD)); + if (!BusInterface) + { + DPRINT("ExAllocatePool() failed\n"); + Status = STATUS_INSUFFICIENT_RESOURCES; + goto cleanup; + } + + KeInitializeEvent(&Event, SynchronizationEvent, FALSE); + Irp = IoBuildSynchronousFsdRequest( + IRP_MJ_PNP, + DeviceExtension->LowerDevice, + NULL, + 0, + NULL, + &Event, + &IoStatus); + if (!Irp) + { + DPRINT("IoBuildSynchronousFsdRequest() failed\n"); + Status = STATUS_INSUFFICIENT_RESOURCES; + goto cleanup; + } + + Irp->IoStatus.Status = STATUS_NOT_SUPPORTED; + Irp->IoStatus.Information = 0; + + Stack = IoGetNextIrpStackLocation(Irp); + Stack->MajorFunction = IRP_MJ_PNP; + Stack->MinorFunction = IRP_MN_QUERY_INTERFACE; + Stack->Parameters.QueryInterface.InterfaceType = (LPGUID)&GUID_BUS_INTERFACE_STANDARD; + Stack->Parameters.QueryInterface.Version = 1; + Stack->Parameters.QueryInterface.Size = sizeof(BUS_INTERFACE_STANDARD); + Stack->Parameters.QueryInterface.Interface = (PINTERFACE)BusInterface; + Stack->Parameters.QueryInterface.InterfaceSpecificData = NULL; + + Status = IoCallDriver(DeviceExtension->LowerDevice, Irp); + if (Status == STATUS_PENDING) + { + KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL); + Status = IoStatus.Status; + } + if (!NT_SUCCESS(Status)) + goto cleanup; + + DeviceExtension->BusInterface = BusInterface; + BusInterface = NULL; + Status = STATUS_SUCCESS; + +cleanup: + ExFreePool(BusInterface); + return Status; +} + +/* +static NTSTATUS +ReleaseBusInterface( + IN PFDO_DEVICE_EXTENSION DeviceExtension) +{ + NTSTATUS Status = STATUS_UNSUCCESSFUL; + + if (DeviceExtension->BusInterface) + { + (*DeviceExtension->BusInterface->InterfaceDereference)( + DeviceExtension->BusInterface->Context); + DeviceExtension->BusInterface = NULL; + Status = STATUS_SUCCESS; + } + + return Status; +} +*/ + +NTSTATUS NTAPI +PciIdeXAddDevice( + IN PDRIVER_OBJECT DriverObject, + IN PDEVICE_OBJECT Pdo) +{ + PPCIIDEX_DRIVER_EXTENSION DriverExtension; + PFDO_DEVICE_EXTENSION DeviceExtension; + PDEVICE_OBJECT Fdo; + NTSTATUS Status; + + DPRINT("PciIdeXAddDevice(%p %p)\n", DriverObject, Pdo); + + DriverExtension = IoGetDriverObjectExtension(DriverObject, DriverObject); + ASSERT(DriverExtension); + + Status = IoCreateDevice( + DriverObject, + sizeof(FDO_DEVICE_EXTENSION) + DriverExtension->MiniControllerExtensionSize, + NULL, + FILE_DEVICE_BUS_EXTENDER, + FILE_DEVICE_SECURE_OPEN, + TRUE, + &Fdo); + if (!NT_SUCCESS(Status)) + { + DPRINT("IoCreateDevice() failed with status 0x%08lx\n", Status); + return Status; + } + + DeviceExtension = (PFDO_DEVICE_EXTENSION)Fdo->DeviceExtension; + RtlZeroMemory(DeviceExtension, sizeof(FDO_DEVICE_EXTENSION)); + + DeviceExtension->Common.IsFDO = TRUE; + + Status = IoAttachDeviceToDeviceStackSafe(Fdo, Pdo, &DeviceExtension->LowerDevice); + if (!NT_SUCCESS(Status)) + { + DPRINT("IoAttachDeviceToDeviceStackSafe() failed with status 0x%08lx\n", Status); + return Status; + } + + Status = GetBusInterface(DeviceExtension); + if (!NT_SUCCESS(Status)) + { + DPRINT("GetBusInterface() failed() failed with status 0x%08lx\n", Status); + return Status; + } + + Fdo->Flags &= ~DO_DEVICE_INITIALIZING; + + return STATUS_SUCCESS; +} + +static NTSTATUS NTAPI +PciIdeXUdmaModesSupported( + IN IDE_DRIVE_IDENTIFY IdentifyData, + OUT PULONG BestXferMode, + OUT PULONG CurrentXferMode) +{ + ULONG Best = PIO_MODE0; + ULONG Current = PIO_MODE0; + + DPRINT("PciIdeXUdmaModesSupported(%lu, %p %p)\n", + IdentifyData, BestXferMode, CurrentXferMode); + + /* FIXME: if current mode is a PIO mode, how to get it? + * At the moment, PIO_MODE0 is always returned... + */ + + if (IdentifyData.TranslationFieldsValid & 0x2) + { + /* PIO modes and some DMA modes are supported */ + if (IdentifyData.AdvancedPIOModes & 0x10) + Best = PIO_MODE4; + else if (IdentifyData.AdvancedPIOModes & 0x8) + Best = PIO_MODE3; + else if (IdentifyData.AdvancedPIOModes & 0x4) + Best = PIO_MODE2; + else if (IdentifyData.AdvancedPIOModes & 0x2) + Best = PIO_MODE1; + else if (IdentifyData.AdvancedPIOModes & 0x1) + Best = PIO_MODE0; + + if (IdentifyData.SingleWordDMASupport & 0x4) + Best = SWDMA_MODE2; + else if (IdentifyData.SingleWordDMASupport & 0x2) + Best = SWDMA_MODE1; + else if (IdentifyData.SingleWordDMASupport & 0x1) + Best = SWDMA_MODE0; + + if (IdentifyData.SingleWordDMAActive & 0x4) + Current = SWDMA_MODE2; + else if (IdentifyData.SingleWordDMAActive & 0x2) + Current = SWDMA_MODE1; + else if (IdentifyData.SingleWordDMAActive & 0x1) + Current = SWDMA_MODE0; + + if (IdentifyData.MultiWordDMASupport & 0x4) + Best = MWDMA_MODE2; + else if (IdentifyData.MultiWordDMASupport & 0x2) + Best = MWDMA_MODE1; + else if (IdentifyData.MultiWordDMASupport & 0x1) + Best = MWDMA_MODE0; + + if (IdentifyData.MultiWordDMAActive & 0x4) + Current = MWDMA_MODE2; + else if (IdentifyData.MultiWordDMAActive & 0x2) + Current = MWDMA_MODE1; + else if (IdentifyData.MultiWordDMAActive & 0x1) + Current = MWDMA_MODE0; + } + + if (IdentifyData.TranslationFieldsValid & 0x4) + { + /* UDMA modes are supported */ + if (IdentifyData.UltraDMAActive & 0x10) + Current = UDMA_MODE4; + else if (IdentifyData.UltraDMAActive & 0x8) + Current = UDMA_MODE3; + else if (IdentifyData.UltraDMAActive & 0x4) + Current = UDMA_MODE2; + else if (IdentifyData.UltraDMAActive & 0x2) + Current = UDMA_MODE1; + else if (IdentifyData.UltraDMAActive & 0x1) + Current = UDMA_MODE0; + + if (IdentifyData.UltraDMASupport & 0x10) + Best = UDMA_MODE4; + else if (IdentifyData.UltraDMASupport & 0x8) + Best = UDMA_MODE3; + else if (IdentifyData.UltraDMASupport & 0x4) + Best = UDMA_MODE2; + else if (IdentifyData.UltraDMASupport & 0x2) + Best = UDMA_MODE1; + else if (IdentifyData.UltraDMASupport & 0x1) + Best = UDMA_MODE0; + } + + *BestXferMode = Best; + *CurrentXferMode = Current; + return TRUE; +} + +static NTSTATUS +PciIdeXFdoStartDevice( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp) +{ + PPCIIDEX_DRIVER_EXTENSION DriverExtension; + PFDO_DEVICE_EXTENSION DeviceExtension; + PCM_RESOURCE_LIST ResourceList; + NTSTATUS Status; + + DPRINT("PciIdeXStartDevice(%p %p)\n", DeviceObject, Irp); + + DriverExtension = IoGetDriverObjectExtension(DeviceObject->DriverObject, DeviceObject->DriverObject); + ASSERT(DriverExtension); + DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; + ASSERT(DeviceExtension); + ASSERT(DeviceExtension->Common.IsFDO); + + DeviceExtension->Properties.Size = sizeof(IDE_CONTROLLER_PROPERTIES); + DeviceExtension->Properties.ExtensionSize = DriverExtension->MiniControllerExtensionSize; + Status = DriverExtension->HwGetControllerProperties( + DeviceExtension->MiniControllerExtension, + &DeviceExtension->Properties); + if (!NT_SUCCESS(Status)) + return Status; + + DriverExtension->HwUdmaModesSupported = DeviceExtension->Properties.PciIdeUdmaModesSupported; + if (!DriverExtension->HwUdmaModesSupported) + /* This method is optional, so provide our own one */ + DriverExtension->HwUdmaModesSupported = PciIdeXUdmaModesSupported; + + /* Get bus master port base, if any */ + ResourceList = IoGetCurrentIrpStackLocation(Irp)->Parameters.StartDevice.AllocatedResou rces; + if (ResourceList + && ResourceList->Count == 1 + && ResourceList->List[0].PartialResourceList.Count == 1 + && ResourceList->List[0].PartialResourceList.Version == 1 + && ResourceList->List[0].PartialResourceList.Revision == 1 + && ResourceList->List[0].PartialResourceList.PartialDescriptors[0].Type == CmResourceTypePort + && ResourceList->List[0].PartialResourceList.PartialDescriptors[0].u.Port.L ength == 16) + { + DeviceExtension->BusMasterPortBase = ResourceList->List[0].PartialResourceList.PartialDescriptors[0].u.Port.S tart; + } + return STATUS_SUCCESS; +} + +static NTSTATUS +PciIdeXFdoQueryBusRelations( + IN PDEVICE_OBJECT DeviceObject, + OUT PDEVICE_RELATIONS* pDeviceRelations) +{ + PFDO_DEVICE_EXTENSION DeviceExtension; + PDEVICE_RELATIONS DeviceRelations = NULL; + PDEVICE_OBJECT Pdo; + PPDO_DEVICE_EXTENSION PdoDeviceExtension; + ULONG i, j; + ULONG PDOs = 0; + IDE_CHANNEL_STATE ChannelState; + NTSTATUS Status; + + DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; + ASSERT(DeviceExtension); + ASSERT(DeviceExtension->Common.IsFDO); + + for (i = 0; i < MAX_IDE_CHANNEL; i++) + { + if (DeviceExtension->Pdo[i]) + { + PDOs++; + continue; + } + ChannelState = DeviceExtension->Properties.PciIdeChannelEnabled( + DeviceExtension->MiniControllerExtension, i); + if (ChannelState != ChannelEnabled) + { + DPRINT("Channel %lu is disabled\n", i); + continue; + } + + /* Need to create a PDO */ + Status = IoCreateDevice( + DeviceObject->DriverObject, + sizeof(PDO_DEVICE_EXTENSION), + NULL, + FILE_DEVICE_CONTROLLER, + FILE_AUTOGENERATED_DEVICE_NAME, + FALSE, + &Pdo); + if (!NT_SUCCESS(Status)) + /* FIXME: handle error */ + continue; + + PdoDeviceExtension = (PPDO_DEVICE_EXTENSION)Pdo->DeviceExtension; + RtlZeroMemory(PdoDeviceExtension, sizeof(PDO_DEVICE_EXTENSION)); + PdoDeviceExtension->Common.IsFDO = FALSE; + PdoDeviceExtension->Channel = i; + PdoDeviceExtension->ControllerFdo = DeviceObject; + Pdo->Flags |= DO_BUS_ENUMERATED_DEVICE; + Pdo->Flags &= ~DO_DEVICE_INITIALIZING; + + DeviceExtension->Pdo[i] = Pdo; + PDOs++; + } + + if (PDOs == 0) + { + DeviceRelations = (PDEVICE_RELATIONS)ExAllocatePool( + PagedPool, + sizeof(DEVICE_RELATIONS)); + } + else + { + DeviceRelations = (PDEVICE_RELATIONS)ExAllocatePool( + PagedPool, + sizeof(DEVICE_RELATIONS) + sizeof(PDEVICE_OBJECT) * (PDOs - 1)); + } + if (!DeviceRelations) + return STATUS_INSUFFICIENT_RESOURCES; + + DeviceRelations->Count = PDOs; + for (i = 0, j = 0; i < MAX_IDE_CHANNEL; i++) + { + if (DeviceExtension->Pdo[i]) + { + ObReferenceObject(DeviceExtension->Pdo[i]); + DeviceRelations->Objects[j++] = DeviceExtension->Pdo[i]; + } + } + + *pDeviceRelations = DeviceRelations; + return STATUS_SUCCESS; +} + +NTSTATUS NTAPI +PciIdeXFdoPnpDispatch( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp) +{ + ULONG MinorFunction; + PIO_STACK_LOCATION Stack; + ULONG_PTR Information = 0; + NTSTATUS Status; + + Stack = IoGetCurrentIrpStackLocation(Irp); + MinorFunction = Stack->MinorFunction; + + switch (MinorFunction) + { + case IRP_MN_START_DEVICE: /* 0x00 */ + { + DPRINT("IRP_MJ_PNP / IRP_MN_START_DEVICE\n"); + /* Call lower driver */ + Status = ForwardIrpAndWait(DeviceObject, Irp); + if (NT_SUCCESS(Status)) + Status = PciIdeXFdoStartDevice(DeviceObject, Irp); + break; + } + case IRP_MN_QUERY_DEVICE_RELATIONS: /* 0x07 */ + { + switch (Stack->Parameters.QueryDeviceRelations.Type) + { + case BusRelations: + { + PDEVICE_RELATIONS DeviceRelations = NULL; + DPRINT("IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / BusRelations\n"); + Status = PciIdeXFdoQueryBusRelations(DeviceObject, &DeviceRelations); + Information = (ULONG_PTR)DeviceRelations; + break; + } + default: + { + DPRINT1("IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / Unknown type 0x%lx\n", + Stack->Parameters.QueryDeviceRelations.Type); + Status = STATUS_NOT_IMPLEMENTED; + break; + } + } + break; + } + default: + { + DPRINT1("IRP_MJ_PNP / Unknown minor function 0x%lx\n", MinorFunction); + return ForwardIrpAndForget(DeviceObject, Irp); + } + } + + Irp->IoStatus.Information = Information; + Irp->IoStatus.Status = Status; + IoCompleteRequest(Irp, IO_NO_INCREMENT); + return Status; +} Property changes on: trunk/reactos/drivers/storage/pciidex/fdo.c ___________________________________________________________________ Name: svn:eol-style + native _____
Added: trunk/reactos/drivers/storage/pciidex/miniport.c --- trunk/reactos/drivers/storage/pciidex/miniport.c 2005-10-20 18:55:45 UTC (rev 18643) +++ trunk/reactos/drivers/storage/pciidex/miniport.c 2005-10-20 19:33:16 UTC (rev 18644) @@ -0,0 +1,104 @@
+/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: PCI IDE bus driver extension + * FILE: drivers/storage/pciidex/miniport.c + * PURPOSE: Miniport functions + * PROGRAMMERS: HervÚ Poussineau (hpoussin@reactos.org) + */ + +#define NDEBUG +#include <debug.h> + +#define INITGUID +#include "pciidex.h" + +static NTSTATUS NTAPI +PciIdeXPnpDispatch( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp) +{ + if (((PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsFDO) + return PciIdeXFdoPnpDispatch(DeviceObject, Irp); + else + return PciIdeXPdoPnpDispatch(DeviceObject, Irp); +} + +NTSTATUS NTAPI +PciIdeXInitialize( + IN PDRIVER_OBJECT DriverObject, + IN PUNICODE_STRING RegistryPath, + IN PCONTROLLER_PROPERTIES HwGetControllerProperties, + IN ULONG ExtensionSize) +{ + ULONG i; + PPCIIDEX_DRIVER_EXTENSION DriverExtension; + NTSTATUS Status; + + DPRINT("PciIdeXInitialize(%p '%wZ' %p 0x%lx)\n", + DriverObject, RegistryPath, HwGetControllerProperties, ExtensionSize); + + Status = IoAllocateDriverObjectExtension( + DriverObject, + DriverObject, + sizeof(PCIIDEX_DRIVER_EXTENSION), + (PVOID*)&DriverExtension); + if (!NT_SUCCESS(Status)) + return Status; + RtlZeroMemory(DriverExtension, sizeof(PCIIDEX_DRIVER_EXTENSION)); + DriverExtension->MiniControllerExtensionSize = ExtensionSize; + DriverExtension->HwGetControllerProperties = HwGetControllerProperties; + + DriverObject->DriverExtension->AddDevice = PciIdeXAddDevice; + + for (i = 0; i < IRP_MJ_MAXIMUM_FUNCTION; i++) + DriverObject->MajorFunction[i] = ForwardIrpAndForget; + DriverObject->MajorFunction[IRP_MJ_PNP] = PciIdeXPnpDispatch; + + return STATUS_SUCCESS; +} + +/* May be called at IRQL <= DISPATCH_LEVEL */ +NTSTATUS NTAPI +PciIdeXGetBusData( + IN PVOID DeviceExtension, + IN PVOID Buffer, + IN ULONG ConfigDataOffset, + IN ULONG BufferLength) +{ + PFDO_DEVICE_EXTENSION FdoDeviceExtension; + ULONG BytesRead = 0; + NTSTATUS Status = STATUS_UNSUCCESSFUL; + + DPRINT("PciIdeXGetBusData(%p %p 0x%lx 0x%lx)\n", + DeviceExtension, Buffer, ConfigDataOffset, BufferLength); + + FdoDeviceExtension = CONTAINING_RECORD(DeviceExtension, FDO_DEVICE_EXTENSION, MiniControllerExtension); + if (FdoDeviceExtension->BusInterface) + { + BytesRead = (*FdoDeviceExtension->BusInterface->GetBusData)( + FdoDeviceExtension->BusInterface->Context, + PCI_WHICHSPACE_CONFIG, + Buffer, + ConfigDataOffset, + BufferLength); + if (BytesRead == BufferLength) + Status = STATUS_SUCCESS; + } + + return Status; +} + +/* May be called at IRQL <= DISPATCH_LEVEL */ +NTSTATUS NTAPI +PciIdeXSetBusData( + IN PVOID DeviceExtension, + IN PVOID Buffer, + IN PVOID DataMask, + IN ULONG ConfigDataOffset, + IN ULONG BufferLength) +{ + DPRINT1("PciIdeXSetBusData(%p %p %p 0x%lx 0x%lx)\n", + DeviceExtension, Buffer, DataMask, ConfigDataOffset, BufferLength); + + return STATUS_NOT_IMPLEMENTED; +} Property changes on: trunk/reactos/drivers/storage/pciidex/miniport.c ___________________________________________________________________ Name: svn:eol-style + native _____
Added: trunk/reactos/drivers/storage/pciidex/misc.c --- trunk/reactos/drivers/storage/pciidex/misc.c 2005-10-20 18:55:45 UTC (rev 18643) +++ trunk/reactos/drivers/storage/pciidex/misc.c 2005-10-20 19:33:16 UTC (rev 18644) @@ -0,0 +1,68 @@
+/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: PCI IDE bus driver extension + * FILE: drivers/storage/pciidex/misc.c + * PURPOSE: Misceallenous operations + * PROGRAMMERS: HervÚ Poussineau (hpoussin@reactos.org) + */ + +#define NDEBUG +#include <debug.h> + +#include "pciidex.h" + +NTSTATUS NTAPI +PciIdeXGenericCompletion( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp, + IN PVOID Context) +{ + if (Irp->PendingReturned) + KeSetEvent((PKEVENT)Context, IO_NO_INCREMENT, FALSE); + return STATUS_MORE_PROCESSING_REQUIRED; +} + +NTSTATUS +ForwardIrpAndWait( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp) +{ + PDEVICE_OBJECT LowerDevice; + KEVENT Event; + NTSTATUS Status; + + ASSERT(((PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsFDO) ; + LowerDevice = ((PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice; + ASSERT(LowerDevice); + + KeInitializeEvent(&Event, NotificationEvent, FALSE); + IoCopyCurrentIrpStackLocationToNext(Irp); + + DPRINT("Calling lower device %p [%wZ]\n", LowerDevice, &LowerDevice->DriverObject->DriverName); + IoSetCompletionRoutine(Irp, PciIdeXGenericCompletion, &Event, TRUE, TRUE, TRUE); + + Status = IoCallDriver(LowerDevice, Irp); + if (Status == STATUS_PENDING) + { + Status = KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL); + if (NT_SUCCESS(Status)) + Status = Irp->IoStatus.Status; + } + + return Status; +} + +NTSTATUS NTAPI +ForwardIrpAndForget( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp) +{ + PDEVICE_OBJECT LowerDevice; + + ASSERT(((PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsFDO) ; + LowerDevice = ((PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice; + ASSERT(LowerDevice); + + IoSkipCurrentIrpStackLocation(Irp); + return IoCallDriver(LowerDevice, Irp); +} Property changes on: trunk/reactos/drivers/storage/pciidex/misc.c ___________________________________________________________________ Name: svn:eol-style + native _____
Added: trunk/reactos/drivers/storage/pciidex/pciidex.c --- trunk/reactos/drivers/storage/pciidex/pciidex.c 2005-10-20 18:55:45 UTC (rev 18643) +++ trunk/reactos/drivers/storage/pciidex/pciidex.c 2005-10-20 19:33:16 UTC (rev 18644) @@ -0,0 +1,20 @@
+/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: PCI IDE bus driver extension + * FILE: drivers/storage/pciidex/pciidex.c + * PURPOSE: Main file + * PROGRAMMERS: HervÚ Poussineau (hpoussin@reactos.org) + */ + +#define NDEBUG +#include <debug.h> + +#include "pciidex.h" + +NTSTATUS NTAPI +DriverEntry( + IN PDRIVER_OBJECT DriverObject, + IN PUNICODE_STRING RegistryPath) +{ + return STATUS_SUCCESS; +} Property changes on: trunk/reactos/drivers/storage/pciidex/pciidex.c ___________________________________________________________________ Name: svn:eol-style + native _____
Added: trunk/reactos/drivers/storage/pciidex/pciidex.def --- trunk/reactos/drivers/storage/pciidex/pciidex.def 2005-10-20 18:55:45 UTC (rev 18643) +++ trunk/reactos/drivers/storage/pciidex/pciidex.def 2005-10-20 19:33:16 UTC (rev 18644) @@ -0,0 +1,8 @@
+LIBRARY pciidex.sys + +EXPORTS +PciIdeXGetBusData@16 +PciIdeXInitialize@16 +PciIdeXSetBusData@20 + +;EOF \ No newline at end of file Property changes on: trunk/reactos/drivers/storage/pciidex/pciidex.def ___________________________________________________________________ Name: svn:eol-style + native _____
Added: trunk/reactos/drivers/storage/pciidex/pciidex.h --- trunk/reactos/drivers/storage/pciidex/pciidex.h 2005-10-20 18:55:45 UTC (rev 18643) +++ trunk/reactos/drivers/storage/pciidex/pciidex.h 2005-10-20 19:33:16 UTC (rev 18644) @@ -0,0 +1,81 @@
+#include <ntddk.h> +#include <ntifs.h> +#include <ide.h> +#include <wdmguid.h> +#include <stdio.h> + +/* FIXME: I don't know why it is not defined anywhere... */ +NTSTATUS STDCALL +IoAttachDeviceToDeviceStackSafe( + IN PDEVICE_OBJECT SourceDevice, + IN PDEVICE_OBJECT TargetDevice, + OUT PDEVICE_OBJECT *AttachedToDeviceObject); + +typedef struct _PCIIDEX_DRIVER_EXTENSION +{ + PCONTROLLER_PROPERTIES HwGetControllerProperties; + ULONG MiniControllerExtensionSize; + PCIIDE_UDMA_MODES_SUPPORTED HwUdmaModesSupported; +} PCIIDEX_DRIVER_EXTENSION, *PPCIIDEX_DRIVER_EXTENSION; + +typedef struct _COMMON_DEVICE_EXTENSION +{ + BOOLEAN IsFDO; +} COMMON_DEVICE_EXTENSION, *PCOMMON_DEVICE_EXTENSION; + +typedef struct _FDO_DEVICE_EXTENSION +{ + COMMON_DEVICE_EXTENSION Common; + + PBUS_INTERFACE_STANDARD BusInterface; + IDE_CONTROLLER_PROPERTIES Properties; + PHYSICAL_ADDRESS BusMasterPortBase; + PDEVICE_OBJECT LowerDevice; + PDEVICE_OBJECT Pdo[MAX_IDE_CHANNEL]; + PBYTE MiniControllerExtension[0]; +} FDO_DEVICE_EXTENSION, *PFDO_DEVICE_EXTENSION; + +typedef struct _PDO_DEVICE_EXTENSION +{ + COMMON_DEVICE_EXTENSION Common; + + ULONG Channel; + PDEVICE_OBJECT ControllerFdo; +} PDO_DEVICE_EXTENSION, *PPDO_DEVICE_EXTENSION; + +/* fdo.c */ + +NTSTATUS NTAPI +PciIdeXAddDevice( + IN PDRIVER_OBJECT DriverObject, + IN PDEVICE_OBJECT Pdo); + +NTSTATUS NTAPI +PciIdeXFdoPnpDispatch( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp); + +/* misc.c */ + +NTSTATUS NTAPI +PciIdeXGenericCompletion( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp, + IN PVOID Context); + +NTSTATUS +ForwardIrpAndWait( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp); + +NTSTATUS NTAPI +ForwardIrpAndForget( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp); + +/* pdo.c */ + +NTSTATUS NTAPI +PciIdeXPdoPnpDispatch( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp); Property changes on: trunk/reactos/drivers/storage/pciidex/pciidex.h ___________________________________________________________________ Name: svn:eol-style + native _____
Added: trunk/reactos/drivers/storage/pciidex/pciidex.rc --- trunk/reactos/drivers/storage/pciidex/pciidex.rc 2005-10-20 18:55:45 UTC (rev 18643) +++ trunk/reactos/drivers/storage/pciidex/pciidex.rc 2005-10-20 19:33:16 UTC (rev 18644) @@ -0,0 +1,5 @@
[truncated at 1000 lines; 830 more skipped]