2010-04-07 20:19:29 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS ISA PnP Bus driver
|
2021-03-04 12:42:42 +00:00
|
|
|
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
|
2010-04-07 20:19:29 +00:00
|
|
|
* PURPOSE: FDO-specific code
|
2021-03-04 12:42:42 +00:00
|
|
|
* COPYRIGHT: Copyright 2010 Cameron Gutman <cameron.gutman@reactos.org>
|
|
|
|
* Copyright 2020 Hervé Poussineau <hpoussin@reactos.org>
|
2021-03-04 12:48:43 +00:00
|
|
|
* Copyright 2021 Dmitry Borisov <di.sean@protonmail.com>
|
2010-04-07 20:19:29 +00:00
|
|
|
*/
|
2014-02-06 11:18:34 +00:00
|
|
|
|
2021-03-04 12:42:42 +00:00
|
|
|
#include "isapnp.h"
|
2010-04-07 20:19:29 +00:00
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2021-03-04 12:43:44 +00:00
|
|
|
static
|
|
|
|
CODE_SEG("PAGE")
|
2010-04-07 20:19:29 +00:00
|
|
|
NTSTATUS
|
|
|
|
IsaFdoStartDevice(
|
2021-03-04 12:42:42 +00:00
|
|
|
_In_ PISAPNP_FDO_EXTENSION FdoExt,
|
2021-03-04 12:48:43 +00:00
|
|
|
_Inout_ PIRP Irp)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2021-03-04 12:48:43 +00:00
|
|
|
NTSTATUS Status;
|
2013-05-09 14:06:21 +00:00
|
|
|
|
2021-03-04 12:43:44 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
2021-03-04 12:48:43 +00:00
|
|
|
if (!IoForwardIrpSynchronously(FdoExt->Ldo, Irp))
|
|
|
|
{
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
Status = Irp->IoStatus.Status;
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
FdoExt->Common.State = dsStarted;
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
return STATUS_SUCCESS;
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
2021-03-04 12:43:44 +00:00
|
|
|
static
|
|
|
|
CODE_SEG("PAGE")
|
2010-04-07 20:19:29 +00:00
|
|
|
NTSTATUS
|
2021-03-04 12:48:43 +00:00
|
|
|
IsaFdoQueryBusRelations(
|
2021-03-04 12:42:42 +00:00
|
|
|
_In_ PISAPNP_FDO_EXTENSION FdoExt,
|
2021-03-04 12:48:43 +00:00
|
|
|
_Inout_ PIRP Irp)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2021-03-04 12:43:44 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
2020-03-16 18:24:07 +00:00
|
|
|
return IsaPnpFillDeviceRelations(FdoExt, Irp, TRUE);
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
2021-03-04 12:48:43 +00:00
|
|
|
static
|
|
|
|
CODE_SEG("PAGE")
|
|
|
|
NTSTATUS
|
|
|
|
IsaFdoRemoveDevice(
|
|
|
|
_In_ PISAPNP_FDO_EXTENSION FdoExt,
|
|
|
|
_Inout_ PIRP Irp)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
PLIST_ENTRY Entry;
|
|
|
|
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
IsaPnpAcquireDeviceDataLock(FdoExt);
|
|
|
|
|
|
|
|
/* Remove our logical devices */
|
|
|
|
while (!IsListEmpty(&FdoExt->DeviceListHead))
|
|
|
|
{
|
|
|
|
PISAPNP_LOGICAL_DEVICE LogDevice = CONTAINING_RECORD(RemoveHeadList(&FdoExt->
|
|
|
|
DeviceListHead),
|
|
|
|
ISAPNP_LOGICAL_DEVICE,
|
|
|
|
DeviceLink);
|
|
|
|
|
|
|
|
--FdoExt->DeviceCount;
|
|
|
|
|
|
|
|
if (LogDevice->Pdo)
|
|
|
|
{
|
|
|
|
IsaPnpRemoveLogicalDeviceDO(LogDevice->Pdo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IsaPnpReleaseDeviceDataLock(FdoExt);
|
|
|
|
|
|
|
|
IsaPnpAcquireBusDataLock();
|
|
|
|
|
|
|
|
/* Remove the Read Port */
|
|
|
|
if (FdoExt->ReadPortPdo)
|
|
|
|
{
|
|
|
|
IsaPnpRemoveReadPortDO(FdoExt->ReadPortPdo);
|
|
|
|
ReadPortCreated = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the next ISA bus, if any */
|
|
|
|
Entry = BusListHead.Flink;
|
|
|
|
if (Entry != &BusListHead)
|
|
|
|
{
|
|
|
|
PISAPNP_FDO_EXTENSION NextIsaBus = CONTAINING_RECORD(Entry,
|
|
|
|
ISAPNP_FDO_EXTENSION,
|
|
|
|
BusLink);
|
|
|
|
|
|
|
|
/* Create a new Read Port for it */
|
|
|
|
if (!ReadPortCreated)
|
|
|
|
IoInvalidateDeviceRelations(NextIsaBus->Pdo, BusRelations);
|
|
|
|
}
|
|
|
|
|
|
|
|
RemoveEntryList(&FdoExt->BusLink);
|
|
|
|
|
|
|
|
IsaPnpReleaseBusDataLock();
|
|
|
|
|
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
IoSkipCurrentIrpStackLocation(Irp);
|
|
|
|
Status = IoCallDriver(FdoExt->Ldo, Irp);
|
|
|
|
|
|
|
|
IoDetachDevice(FdoExt->Ldo);
|
|
|
|
IoDeleteDevice(FdoExt->Common.Self);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2021-03-04 12:43:44 +00:00
|
|
|
CODE_SEG("PAGE")
|
2010-04-07 20:19:29 +00:00
|
|
|
NTSTATUS
|
|
|
|
IsaFdoPnp(
|
2021-03-04 12:42:42 +00:00
|
|
|
_In_ PISAPNP_FDO_EXTENSION FdoExt,
|
|
|
|
_Inout_ PIRP Irp,
|
|
|
|
_In_ PIO_STACK_LOCATION IrpSp)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2021-03-04 12:48:43 +00:00
|
|
|
NTSTATUS Status;
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2021-03-04 12:43:44 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
2021-03-04 12:48:43 +00:00
|
|
|
DPRINT("%s(%p, %p) FDO %lu, Minor - %X\n",
|
|
|
|
__FUNCTION__,
|
|
|
|
FdoExt,
|
|
|
|
Irp,
|
|
|
|
FdoExt->BusNumber,
|
|
|
|
IrpSp->MinorFunction);
|
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
switch (IrpSp->MinorFunction)
|
|
|
|
{
|
|
|
|
case IRP_MN_START_DEVICE:
|
2021-03-04 12:48:43 +00:00
|
|
|
Status = IsaFdoStartDevice(FdoExt, Irp);
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return Status;
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2021-03-04 12:48:43 +00:00
|
|
|
case IRP_MN_QUERY_DEVICE_RELATIONS:
|
|
|
|
{
|
|
|
|
if (IrpSp->Parameters.QueryDeviceRelations.Type != BusRelations)
|
|
|
|
break;
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2021-03-04 12:48:43 +00:00
|
|
|
Status = IsaFdoQueryBusRelations(FdoExt, Irp);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2021-03-04 12:48:43 +00:00
|
|
|
return Status;
|
|
|
|
}
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
Irp->IoStatus.Status = Status;
|
2021-03-04 12:48:43 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2021-03-04 12:48:43 +00:00
|
|
|
case IRP_MN_REMOVE_DEVICE:
|
|
|
|
return IsaFdoRemoveDevice(FdoExt, Irp);
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2021-03-04 12:48:43 +00:00
|
|
|
case IRP_MN_QUERY_PNP_DEVICE_STATE:
|
|
|
|
Irp->IoStatus.Information |= PNP_DEVICE_NOT_DISABLEABLE;
|
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_QUERY_INTERFACE:
|
|
|
|
{
|
|
|
|
Status = IsaFdoQueryInterface(FdoExt, IrpSp);
|
|
|
|
if (Status == STATUS_NOT_SUPPORTED)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IRP_MN_SURPRISE_REMOVAL:
|
|
|
|
case IRP_MN_QUERY_STOP_DEVICE:
|
|
|
|
case IRP_MN_QUERY_REMOVE_DEVICE:
|
|
|
|
case IRP_MN_CANCEL_STOP_DEVICE:
|
|
|
|
case IRP_MN_CANCEL_REMOVE_DEVICE:
|
|
|
|
case IRP_MN_STOP_DEVICE:
|
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
2020-03-20 18:19:30 +00:00
|
|
|
break;
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
default:
|
2021-03-04 12:48:43 +00:00
|
|
|
DPRINT("Unknown PnP code: %X\n", IrpSp->MinorFunction);
|
2020-03-20 18:19:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
IoSkipCurrentIrpStackLocation(Irp);
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
return IoCallDriver(FdoExt->Ldo, Irp);
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|