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: PDO-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
|
|
|
|
IsaPdoQueryDeviceRelations(
|
2021-03-04 12:42:42 +00:00
|
|
|
_In_ PISAPNP_PDO_EXTENSION PdoExt,
|
|
|
|
_Inout_ PIRP Irp,
|
|
|
|
_In_ PIO_STACK_LOCATION IrpSp)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2020-03-20 18:19:30 +00:00
|
|
|
PDEVICE_RELATIONS DeviceRelations;
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2021-03-04 12:43:44 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
2020-03-16 18:43:37 +00:00
|
|
|
if (IrpSp->Parameters.QueryDeviceRelations.Type == RemovalRelations &&
|
2021-03-04 12:48:43 +00:00
|
|
|
PdoExt->Common.Signature == IsaPnpReadDataPort)
|
2020-03-16 18:43:37 +00:00
|
|
|
{
|
|
|
|
return IsaPnpFillDeviceRelations(PdoExt->FdoExt, Irp, FALSE);
|
|
|
|
}
|
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
if (IrpSp->Parameters.QueryDeviceRelations.Type != TargetDeviceRelation)
|
|
|
|
return Irp->IoStatus.Status;
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2021-03-04 12:43:19 +00:00
|
|
|
DeviceRelations = ExAllocatePoolWithTag(PagedPool, sizeof(*DeviceRelations), TAG_ISAPNP);
|
2020-03-20 18:19:30 +00:00
|
|
|
if (!DeviceRelations)
|
2020-03-20 18:41:55 +00:00
|
|
|
return STATUS_NO_MEMORY;
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
DeviceRelations->Count = 1;
|
|
|
|
DeviceRelations->Objects[0] = PdoExt->Common.Self;
|
|
|
|
ObReferenceObject(PdoExt->Common.Self);
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations;
|
|
|
|
return STATUS_SUCCESS;
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
2021-03-04 12:43:44 +00:00
|
|
|
static
|
|
|
|
CODE_SEG("PAGE")
|
2020-02-10 20:31:28 +00:00
|
|
|
NTSTATUS
|
|
|
|
IsaPdoQueryCapabilities(
|
2021-03-04 12:42:42 +00:00
|
|
|
_In_ PISAPNP_PDO_EXTENSION PdoExt,
|
|
|
|
_Inout_ PIRP Irp,
|
|
|
|
_In_ PIO_STACK_LOCATION IrpSp)
|
2020-02-10 20:31:28 +00:00
|
|
|
{
|
2020-03-20 18:19:30 +00:00
|
|
|
PDEVICE_CAPABILITIES DeviceCapabilities;
|
2020-03-16 18:24:07 +00:00
|
|
|
ULONG i;
|
2020-02-10 20:31:28 +00:00
|
|
|
|
2021-03-04 12:46:50 +00:00
|
|
|
UNREFERENCED_PARAMETER(Irp);
|
|
|
|
|
2021-03-04 12:43:44 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
DeviceCapabilities = IrpSp->Parameters.DeviceCapabilities.Capabilities;
|
|
|
|
if (DeviceCapabilities->Version != 1)
|
2020-03-20 18:41:55 +00:00
|
|
|
return STATUS_REVISION_MISMATCH;
|
2020-02-10 20:31:28 +00:00
|
|
|
|
2021-03-04 12:46:50 +00:00
|
|
|
DeviceCapabilities->LockSupported =
|
|
|
|
DeviceCapabilities->EjectSupported =
|
|
|
|
DeviceCapabilities->Removable =
|
|
|
|
DeviceCapabilities->DockDevice = FALSE;
|
|
|
|
|
|
|
|
DeviceCapabilities->UniqueID = TRUE;
|
|
|
|
|
2021-03-04 12:48:43 +00:00
|
|
|
if (PdoExt->Common.Signature == IsaPnpReadDataPort)
|
2020-03-16 18:24:07 +00:00
|
|
|
{
|
|
|
|
DeviceCapabilities->RawDeviceOK = TRUE;
|
2020-03-21 13:59:02 +00:00
|
|
|
DeviceCapabilities->SilentInstall = TRUE;
|
2020-03-16 18:24:07 +00:00
|
|
|
}
|
2020-02-10 20:31:28 +00:00
|
|
|
|
2020-03-21 13:59:02 +00:00
|
|
|
for (i = 0; i < POWER_SYSTEM_MAXIMUM; i++)
|
|
|
|
DeviceCapabilities->DeviceState[i] = PowerDeviceD3;
|
|
|
|
DeviceCapabilities->DeviceState[PowerSystemWorking] = PowerDeviceD0;
|
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
return STATUS_SUCCESS;
|
2020-02-10 20:31:28 +00:00
|
|
|
}
|
|
|
|
|
2021-03-04 12:43:44 +00:00
|
|
|
static
|
|
|
|
CODE_SEG("PAGE")
|
2020-03-17 22:50:39 +00:00
|
|
|
NTSTATUS
|
|
|
|
IsaPdoQueryPnpDeviceState(
|
2021-03-04 12:42:42 +00:00
|
|
|
_In_ PISAPNP_PDO_EXTENSION PdoExt,
|
2021-03-04 12:48:43 +00:00
|
|
|
_Inout_ PIRP Irp)
|
2020-03-17 22:50:39 +00:00
|
|
|
{
|
2021-03-04 12:43:44 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
2021-03-28 17:29:02 +00:00
|
|
|
if (PdoExt->Flags & ISAPNP_READ_PORT_NEED_REBALANCE)
|
|
|
|
{
|
|
|
|
Irp->IoStatus.Information |= PNP_DEVICE_NOT_DISABLEABLE |
|
|
|
|
PNP_DEVICE_RESOURCE_REQUIREMENTS_CHANGED |
|
|
|
|
PNP_DEVICE_FAILED;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
else if (PdoExt->SpecialFiles > 0)
|
2021-03-04 12:48:43 +00:00
|
|
|
{
|
|
|
|
Irp->IoStatus.Information |= PNP_DEVICE_NOT_DISABLEABLE;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Irp->IoStatus.Status;
|
2020-03-17 22:50:39 +00:00
|
|
|
}
|
|
|
|
|
2021-03-04 12:43:44 +00:00
|
|
|
static
|
|
|
|
CODE_SEG("PAGE")
|
2020-02-10 20:31:28 +00:00
|
|
|
NTSTATUS
|
|
|
|
IsaPdoQueryId(
|
2021-03-04 12:42:42 +00:00
|
|
|
_In_ PISAPNP_PDO_EXTENSION PdoExt,
|
|
|
|
_Inout_ PIRP Irp,
|
|
|
|
_In_ PIO_STACK_LOCATION IrpSp)
|
2020-02-10 20:31:28 +00:00
|
|
|
{
|
2021-03-04 12:44:20 +00:00
|
|
|
PISAPNP_LOGICAL_DEVICE LogDev = PdoExt->IsaPnpDevice;
|
|
|
|
NTSTATUS Status;
|
|
|
|
PWCHAR Buffer, End, IdStart;
|
|
|
|
size_t CharCount, Remaining;
|
2020-03-20 18:19:30 +00:00
|
|
|
|
2021-03-04 12:43:44 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
switch (IrpSp->Parameters.QueryId.IdType)
|
2020-02-10 20:31:28 +00:00
|
|
|
{
|
2020-03-20 18:19:30 +00:00
|
|
|
case BusQueryDeviceID:
|
2021-03-04 12:44:20 +00:00
|
|
|
{
|
|
|
|
CharCount = sizeof("ISAPNP\\XXXFFFF");
|
|
|
|
|
2021-03-20 14:50:34 +00:00
|
|
|
if (LogDev->Flags & ISAPNP_HAS_MULTIPLE_LOGDEVS)
|
|
|
|
{
|
|
|
|
CharCount += sizeof("_DEV1234") - sizeof(ANSI_NULL);
|
|
|
|
}
|
|
|
|
|
2021-03-04 12:44:20 +00:00
|
|
|
Buffer = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
CharCount * sizeof(WCHAR),
|
|
|
|
TAG_ISAPNP);
|
|
|
|
if (!Buffer)
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
|
|
|
Status = RtlStringCchPrintfExW(Buffer,
|
|
|
|
CharCount,
|
|
|
|
&End,
|
|
|
|
&Remaining,
|
|
|
|
0,
|
2022-09-23 21:06:34 +00:00
|
|
|
L"ISAPNP\\%.3S%04X",
|
2021-03-04 12:44:20 +00:00
|
|
|
LogDev->VendorId,
|
|
|
|
LogDev->ProdId);
|
|
|
|
if (!NT_VERIFY(NT_SUCCESS(Status)))
|
|
|
|
goto Failure;
|
|
|
|
|
2021-03-20 14:50:34 +00:00
|
|
|
if (LogDev->Flags & ISAPNP_HAS_MULTIPLE_LOGDEVS)
|
|
|
|
{
|
|
|
|
Status = RtlStringCchPrintfExW(End,
|
|
|
|
Remaining,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
L"_DEV%04X",
|
|
|
|
LogDev->LDN);
|
|
|
|
if (!NT_VERIFY(NT_SUCCESS(Status)))
|
|
|
|
goto Failure;
|
|
|
|
}
|
|
|
|
|
2021-03-04 12:44:20 +00:00
|
|
|
DPRINT("Device ID: '%S'\n", Buffer);
|
2020-03-20 18:19:30 +00:00
|
|
|
break;
|
2021-03-04 12:44:20 +00:00
|
|
|
}
|
2020-03-20 18:19:30 +00:00
|
|
|
|
|
|
|
case BusQueryHardwareIDs:
|
2021-03-04 12:44:20 +00:00
|
|
|
{
|
|
|
|
CharCount = sizeof("ISAPNP\\XXXFFFF") +
|
|
|
|
sizeof("*PNPxxxx") +
|
|
|
|
sizeof(ANSI_NULL); /* multi-string */
|
|
|
|
|
2021-03-20 14:50:34 +00:00
|
|
|
if (LogDev->Flags & ISAPNP_HAS_MULTIPLE_LOGDEVS)
|
|
|
|
{
|
|
|
|
CharCount += sizeof("_DEV1234") - sizeof(ANSI_NULL);
|
|
|
|
}
|
|
|
|
|
2021-03-04 12:44:20 +00:00
|
|
|
Buffer = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
CharCount * sizeof(WCHAR),
|
|
|
|
TAG_ISAPNP);
|
|
|
|
if (!Buffer)
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
|
|
|
DPRINT("Hardware IDs:\n");
|
|
|
|
|
|
|
|
/* 1 */
|
|
|
|
Status = RtlStringCchPrintfExW(Buffer,
|
|
|
|
CharCount,
|
|
|
|
&End,
|
|
|
|
&Remaining,
|
|
|
|
0,
|
2022-09-23 21:06:34 +00:00
|
|
|
L"ISAPNP\\%.3S%04X",
|
2021-03-04 12:44:20 +00:00
|
|
|
LogDev->VendorId,
|
|
|
|
LogDev->ProdId);
|
|
|
|
if (!NT_VERIFY(NT_SUCCESS(Status)))
|
|
|
|
goto Failure;
|
|
|
|
|
2021-03-20 14:50:34 +00:00
|
|
|
if (LogDev->Flags & ISAPNP_HAS_MULTIPLE_LOGDEVS)
|
|
|
|
{
|
|
|
|
Status = RtlStringCchPrintfExW(End,
|
|
|
|
Remaining,
|
|
|
|
&End,
|
|
|
|
&Remaining,
|
|
|
|
0,
|
|
|
|
L"_DEV%04X",
|
|
|
|
LogDev->LDN);
|
|
|
|
if (!NT_VERIFY(NT_SUCCESS(Status)))
|
|
|
|
goto Failure;
|
|
|
|
}
|
|
|
|
|
2021-03-04 12:44:20 +00:00
|
|
|
DPRINT(" '%S'\n", Buffer);
|
|
|
|
|
|
|
|
++End;
|
|
|
|
--Remaining;
|
|
|
|
|
|
|
|
/* 2 */
|
|
|
|
IdStart = End;
|
|
|
|
Status = RtlStringCchPrintfExW(End,
|
|
|
|
Remaining,
|
|
|
|
&End,
|
|
|
|
&Remaining,
|
|
|
|
0,
|
2022-09-23 21:06:34 +00:00
|
|
|
L"*%.3S%04X",
|
2021-03-20 14:50:34 +00:00
|
|
|
LogDev->LogVendorId,
|
|
|
|
LogDev->LogProdId);
|
2021-03-04 12:44:20 +00:00
|
|
|
if (!NT_VERIFY(NT_SUCCESS(Status)))
|
|
|
|
goto Failure;
|
|
|
|
|
|
|
|
DPRINT(" '%S'\n", IdStart);
|
|
|
|
|
|
|
|
*++End = UNICODE_NULL;
|
|
|
|
--Remaining;
|
|
|
|
|
2020-03-16 18:00:00 +00:00
|
|
|
break;
|
2021-03-04 12:44:20 +00:00
|
|
|
}
|
2020-03-16 18:00:00 +00:00
|
|
|
|
|
|
|
case BusQueryCompatibleIDs:
|
2021-03-20 14:50:34 +00:00
|
|
|
{
|
|
|
|
PLIST_ENTRY Entry;
|
|
|
|
|
|
|
|
for (Entry = LogDev->CompatibleIdList.Flink, CharCount = 0;
|
|
|
|
Entry != &LogDev->CompatibleIdList;
|
|
|
|
Entry = Entry->Flink)
|
|
|
|
{
|
|
|
|
CharCount += sizeof("*PNPxxxx");
|
|
|
|
}
|
|
|
|
CharCount += sizeof(ANSI_NULL); /* multi-string */
|
|
|
|
|
|
|
|
if (CharCount == sizeof(ANSI_NULL))
|
|
|
|
return Irp->IoStatus.Status;
|
|
|
|
|
|
|
|
Buffer = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
CharCount * sizeof(WCHAR),
|
|
|
|
TAG_ISAPNP);
|
|
|
|
if (!Buffer)
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
|
|
|
DPRINT("Compatible IDs:\n");
|
|
|
|
|
|
|
|
for (Entry = LogDev->CompatibleIdList.Flink, End = Buffer, Remaining = CharCount;
|
|
|
|
Entry != &LogDev->CompatibleIdList;
|
|
|
|
Entry = Entry->Flink)
|
|
|
|
{
|
|
|
|
PISAPNP_COMPATIBLE_ID_ENTRY CompatibleId =
|
|
|
|
CONTAINING_RECORD(Entry, ISAPNP_COMPATIBLE_ID_ENTRY, IdLink);
|
|
|
|
|
|
|
|
IdStart = End;
|
|
|
|
Status = RtlStringCchPrintfExW(End,
|
|
|
|
Remaining,
|
|
|
|
&End,
|
|
|
|
&Remaining,
|
|
|
|
0,
|
2022-09-23 21:06:34 +00:00
|
|
|
L"*%.3S%04X",
|
2021-03-20 14:50:34 +00:00
|
|
|
CompatibleId->VendorId,
|
|
|
|
CompatibleId->ProdId);
|
|
|
|
if (!NT_VERIFY(NT_SUCCESS(Status)))
|
|
|
|
goto Failure;
|
|
|
|
|
|
|
|
DPRINT(" '%S'\n", IdStart);
|
|
|
|
|
|
|
|
++End;
|
|
|
|
--Remaining;
|
|
|
|
}
|
|
|
|
|
|
|
|
*End = UNICODE_NULL;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2020-03-20 18:19:30 +00:00
|
|
|
|
|
|
|
case BusQueryInstanceID:
|
2021-03-04 12:44:20 +00:00
|
|
|
{
|
|
|
|
CharCount = sizeof(LogDev->SerialNumber) * 2 + sizeof(ANSI_NULL);
|
|
|
|
|
|
|
|
Buffer = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
CharCount * sizeof(WCHAR),
|
|
|
|
TAG_ISAPNP);
|
|
|
|
if (!Buffer)
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
|
|
|
Status = RtlStringCchPrintfExW(Buffer,
|
|
|
|
CharCount,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
L"%X",
|
|
|
|
LogDev->SerialNumber);
|
|
|
|
if (!NT_VERIFY(NT_SUCCESS(Status)))
|
|
|
|
goto Failure;
|
|
|
|
|
|
|
|
DPRINT("Instance ID: '%S'\n", Buffer);
|
2020-03-20 18:19:30 +00:00
|
|
|
break;
|
2021-03-04 12:44:20 +00:00
|
|
|
}
|
2020-03-20 18:19:30 +00:00
|
|
|
|
|
|
|
default:
|
2021-03-04 12:44:20 +00:00
|
|
|
return Irp->IoStatus.Status;
|
2020-02-10 20:31:28 +00:00
|
|
|
}
|
|
|
|
|
2021-03-04 12:44:20 +00:00
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)Buffer;
|
|
|
|
return STATUS_SUCCESS;
|
2020-03-21 13:58:36 +00:00
|
|
|
|
2021-03-04 12:44:20 +00:00
|
|
|
Failure:
|
|
|
|
ExFreePoolWithTag(Buffer, TAG_ISAPNP);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
CODE_SEG("PAGE")
|
|
|
|
NTSTATUS
|
|
|
|
IsaReadPortQueryId(
|
|
|
|
_Inout_ PIRP Irp,
|
|
|
|
_In_ PIO_STACK_LOCATION IrpSp)
|
|
|
|
{
|
|
|
|
PWCHAR Buffer;
|
|
|
|
static const WCHAR ReadPortId[] = L"ISAPNP\\ReadDataPort";
|
|
|
|
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
switch (IrpSp->Parameters.QueryId.IdType)
|
|
|
|
{
|
|
|
|
case BusQueryDeviceID:
|
|
|
|
{
|
|
|
|
Buffer = ExAllocatePoolWithTag(PagedPool, sizeof(ReadPortId), TAG_ISAPNP);
|
|
|
|
if (!Buffer)
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
|
|
|
RtlCopyMemory(Buffer, ReadPortId, sizeof(ReadPortId));
|
|
|
|
|
|
|
|
DPRINT("Device ID: '%S'\n", Buffer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BusQueryHardwareIDs:
|
|
|
|
{
|
|
|
|
Buffer = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
sizeof(ReadPortId) + sizeof(UNICODE_NULL),
|
|
|
|
TAG_ISAPNP);
|
|
|
|
if (!Buffer)
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
|
|
|
RtlCopyMemory(Buffer, ReadPortId, sizeof(ReadPortId));
|
|
|
|
|
|
|
|
Buffer[sizeof(ReadPortId) / sizeof(WCHAR)] = UNICODE_NULL; /* multi-string */
|
|
|
|
|
|
|
|
DPRINT("Hardware ID: '%S'\n", Buffer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BusQueryCompatibleIDs:
|
|
|
|
{
|
|
|
|
/* Empty multi-string */
|
|
|
|
Buffer = ExAllocatePoolZero(PagedPool, sizeof(UNICODE_NULL) * 2, TAG_ISAPNP);
|
|
|
|
if (!Buffer)
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
|
|
|
DPRINT("Compatible ID: '%S'\n", Buffer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BusQueryInstanceID:
|
|
|
|
{
|
|
|
|
/* Even if there are multiple ISA buses, the driver has only one Read Port */
|
|
|
|
static const WCHAR InstanceId[] = L"0";
|
|
|
|
|
|
|
|
Buffer = ExAllocatePoolWithTag(PagedPool, sizeof(InstanceId), TAG_ISAPNP);
|
|
|
|
if (!Buffer)
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
|
|
|
RtlCopyMemory(Buffer, InstanceId, sizeof(InstanceId));
|
|
|
|
|
|
|
|
DPRINT("Instance ID: '%S'\n", Buffer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return Irp->IoStatus.Status;
|
|
|
|
}
|
2020-03-20 18:19:30 +00:00
|
|
|
|
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)Buffer;
|
|
|
|
return STATUS_SUCCESS;
|
2020-02-10 20:31:28 +00:00
|
|
|
}
|
|
|
|
|
2021-03-20 14:50:34 +00:00
|
|
|
static
|
|
|
|
CODE_SEG("PAGE")
|
|
|
|
NTSTATUS
|
|
|
|
IsaPdoQueryDeviceText(
|
|
|
|
_In_ PISAPNP_PDO_EXTENSION PdoExt,
|
|
|
|
_Inout_ PIRP Irp,
|
|
|
|
_In_ PIO_STACK_LOCATION IrpSp)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
PWCHAR Buffer;
|
|
|
|
size_t CharCount;
|
|
|
|
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
switch (IrpSp->Parameters.QueryDeviceText.DeviceTextType)
|
|
|
|
{
|
|
|
|
case DeviceTextDescription:
|
|
|
|
{
|
|
|
|
if (!PdoExt->IsaPnpDevice->FriendlyName)
|
|
|
|
return Irp->IoStatus.Status;
|
|
|
|
|
|
|
|
CharCount = strlen(PdoExt->IsaPnpDevice->FriendlyName) +
|
|
|
|
sizeof(ANSI_NULL);
|
|
|
|
|
|
|
|
if (CharCount == sizeof(ANSI_NULL))
|
|
|
|
return Irp->IoStatus.Status;
|
|
|
|
|
|
|
|
Buffer = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
CharCount * sizeof(WCHAR),
|
|
|
|
TAG_ISAPNP);
|
|
|
|
if (!Buffer)
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
|
|
|
Status = RtlStringCchPrintfExW(Buffer,
|
|
|
|
CharCount,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
L"%hs",
|
|
|
|
PdoExt->IsaPnpDevice->FriendlyName);
|
|
|
|
if (!NT_VERIFY(NT_SUCCESS(Status)))
|
|
|
|
{
|
|
|
|
ExFreePoolWithTag(Buffer, TAG_ISAPNP);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT("TextDescription: '%S'\n", Buffer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return Irp->IoStatus.Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)Buffer;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-03-04 12:43:44 +00:00
|
|
|
static
|
|
|
|
CODE_SEG("PAGE")
|
2020-03-16 19:50:29 +00:00
|
|
|
NTSTATUS
|
|
|
|
IsaPdoQueryResources(
|
2021-03-04 12:42:42 +00:00
|
|
|
_In_ PISAPNP_PDO_EXTENSION PdoExt,
|
|
|
|
_Inout_ PIRP Irp,
|
|
|
|
_In_ PIO_STACK_LOCATION IrpSp)
|
2020-03-16 19:50:29 +00:00
|
|
|
{
|
2020-03-21 16:37:45 +00:00
|
|
|
ULONG ListSize;
|
2020-03-16 19:50:29 +00:00
|
|
|
PCM_RESOURCE_LIST ResourceList;
|
|
|
|
|
2021-03-04 12:48:43 +00:00
|
|
|
UNREFERENCED_PARAMETER(IrpSp);
|
|
|
|
|
2021-03-04 12:43:44 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
2021-03-20 14:51:05 +00:00
|
|
|
if (PdoExt->Common.Signature == IsaPnpLogicalDevice &&
|
|
|
|
!(PdoExt->IsaPnpDevice->Flags & ISAPNP_HAS_RESOURCES))
|
|
|
|
{
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-03-21 16:37:45 +00:00
|
|
|
if (!PdoExt->ResourceList)
|
|
|
|
return Irp->IoStatus.Status;
|
|
|
|
|
|
|
|
ListSize = PdoExt->ResourceListSize;
|
2021-03-04 12:43:19 +00:00
|
|
|
ResourceList = ExAllocatePoolWithTag(PagedPool, ListSize, TAG_ISAPNP);
|
2020-03-16 19:50:29 +00:00
|
|
|
if (!ResourceList)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
2020-03-21 16:37:45 +00:00
|
|
|
RtlCopyMemory(ResourceList, PdoExt->ResourceList, ListSize);
|
2020-03-16 19:50:29 +00:00
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)ResourceList;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-03-04 12:43:44 +00:00
|
|
|
static
|
|
|
|
CODE_SEG("PAGE")
|
2020-03-16 19:50:29 +00:00
|
|
|
NTSTATUS
|
|
|
|
IsaPdoQueryResourceRequirements(
|
2021-03-04 12:42:42 +00:00
|
|
|
_In_ PISAPNP_PDO_EXTENSION PdoExt,
|
|
|
|
_Inout_ PIRP Irp,
|
|
|
|
_In_ PIO_STACK_LOCATION IrpSp)
|
2020-03-16 19:50:29 +00:00
|
|
|
{
|
2020-03-21 15:58:21 +00:00
|
|
|
ULONG ListSize;
|
2020-03-16 19:50:29 +00:00
|
|
|
PIO_RESOURCE_REQUIREMENTS_LIST RequirementsList;
|
|
|
|
|
2021-03-04 12:48:43 +00:00
|
|
|
UNREFERENCED_PARAMETER(IrpSp);
|
|
|
|
|
2021-03-04 12:43:44 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
2020-03-21 15:58:21 +00:00
|
|
|
if (!PdoExt->RequirementsList)
|
|
|
|
return Irp->IoStatus.Status;
|
|
|
|
|
|
|
|
ListSize = PdoExt->RequirementsList->ListSize;
|
2021-03-04 12:43:19 +00:00
|
|
|
RequirementsList = ExAllocatePoolWithTag(PagedPool, ListSize, TAG_ISAPNP);
|
2020-03-16 19:50:29 +00:00
|
|
|
if (!RequirementsList)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
2020-03-21 15:58:21 +00:00
|
|
|
RtlCopyMemory(RequirementsList, PdoExt->RequirementsList, ListSize);
|
2020-03-16 19:50:29 +00:00
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)RequirementsList;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-03-28 17:29:02 +00:00
|
|
|
#define IS_READ_PORT(_d) ((_d)->Type == CmResourceTypePort && (_d)->u.Port.Length > 1)
|
|
|
|
|
2020-03-16 19:58:53 +00:00
|
|
|
static
|
2021-03-04 12:43:44 +00:00
|
|
|
CODE_SEG("PAGE")
|
2020-03-16 19:58:53 +00:00
|
|
|
NTSTATUS
|
|
|
|
IsaPdoStartReadPort(
|
2021-03-28 17:29:02 +00:00
|
|
|
_In_ PISAPNP_PDO_EXTENSION PdoExt,
|
|
|
|
_In_ PCM_RESOURCE_LIST ResourceList)
|
2020-03-16 19:58:53 +00:00
|
|
|
{
|
2021-03-28 17:29:02 +00:00
|
|
|
PISAPNP_FDO_EXTENSION FdoExt = PdoExt->FdoExt;
|
|
|
|
NTSTATUS Status;
|
2020-03-16 19:58:53 +00:00
|
|
|
ULONG i;
|
|
|
|
|
2021-03-04 12:43:44 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
2021-03-28 17:29:02 +00:00
|
|
|
if (!ResourceList)
|
2020-03-16 19:58:53 +00:00
|
|
|
{
|
2021-03-28 17:29:02 +00:00
|
|
|
DPRINT1("No resource list\n");
|
2020-03-16 19:58:53 +00:00
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
2021-03-04 12:42:42 +00:00
|
|
|
|
|
|
|
if (ResourceList->List[0].PartialResourceList.Version != 1 ||
|
|
|
|
ResourceList->List[0].PartialResourceList.Revision != 1)
|
2020-03-16 19:58:53 +00:00
|
|
|
{
|
2021-03-04 12:42:42 +00:00
|
|
|
DPRINT1("Bad resource list version (%u.%u)\n",
|
|
|
|
ResourceList->List[0].PartialResourceList.Version,
|
|
|
|
ResourceList->List[0].PartialResourceList.Revision);
|
2020-03-16 19:58:53 +00:00
|
|
|
return STATUS_REVISION_MISMATCH;
|
|
|
|
}
|
2021-03-04 12:42:42 +00:00
|
|
|
|
2021-03-28 17:29:02 +00:00
|
|
|
#if 0
|
|
|
|
/* Try various Read Ports from the list */
|
|
|
|
if (ResourceList->List[0].PartialResourceList.Count > 3)
|
2020-03-16 19:58:53 +00:00
|
|
|
{
|
2021-03-28 17:29:02 +00:00
|
|
|
ULONG SelectedPort = 0;
|
2021-03-04 12:42:42 +00:00
|
|
|
|
2021-03-28 17:29:02 +00:00
|
|
|
for (i = 0; i < ResourceList->List[0].PartialResourceList.Count; i++)
|
2020-03-16 19:58:53 +00:00
|
|
|
{
|
2021-03-28 17:29:02 +00:00
|
|
|
PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor =
|
|
|
|
&ResourceList->List[0].PartialResourceList.PartialDescriptors[i];
|
|
|
|
|
|
|
|
if (IS_READ_PORT(PartialDescriptor))
|
2020-03-16 19:58:53 +00:00
|
|
|
{
|
2021-03-28 17:29:02 +00:00
|
|
|
PUCHAR ReadDataPort = ULongToPtr(PartialDescriptor->u.Port.Start.u.LowPart + 3);
|
2021-03-20 14:52:40 +00:00
|
|
|
ULONG Cards;
|
2021-03-28 17:29:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Remember the first Read Port in the resource list.
|
|
|
|
* It will be selected by default even if no card has been detected.
|
|
|
|
*/
|
|
|
|
if (!SelectedPort)
|
|
|
|
SelectedPort = PartialDescriptor->u.Port.Start.u.LowPart;
|
|
|
|
|
2021-03-20 14:52:40 +00:00
|
|
|
Cards = IsaHwTryReadDataPort(ReadDataPort);
|
|
|
|
IsaHwWaitForKey();
|
|
|
|
|
2021-03-04 12:42:42 +00:00
|
|
|
/* We detected some ISAPNP cards */
|
2021-03-20 14:52:40 +00:00
|
|
|
if (Cards > 0)
|
2021-03-28 17:29:02 +00:00
|
|
|
{
|
|
|
|
SelectedPort = PartialDescriptor->u.Port.Start.u.LowPart;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT(SelectedPort != 0);
|
|
|
|
|
|
|
|
if (PdoExt->RequirementsList)
|
|
|
|
{
|
|
|
|
ExFreePoolWithTag(PdoExt->RequirementsList, TAG_ISAPNP);
|
|
|
|
PdoExt->RequirementsList = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Discard the Read Ports at conflicting locations */
|
|
|
|
Status = IsaPnpCreateReadPortDORequirements(PdoExt, SelectedPort);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
return Status;
|
|
|
|
|
|
|
|
PdoExt->Flags |= ISAPNP_READ_PORT_NEED_REBALANCE;
|
|
|
|
|
|
|
|
IoInvalidateDeviceState(PdoExt->Common.Self);
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
/* Set the Read Port */
|
|
|
|
else if (ResourceList->List[0].PartialResourceList.Count == 3)
|
|
|
|
#else
|
|
|
|
if (ResourceList->List[0].PartialResourceList.Count > 3) /* Temporary HACK */
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
PdoExt->Flags &= ~ISAPNP_READ_PORT_NEED_REBALANCE;
|
2021-03-04 12:43:44 +00:00
|
|
|
|
2021-03-28 17:29:02 +00:00
|
|
|
for (i = 0; i < ResourceList->List[0].PartialResourceList.Count; i++)
|
|
|
|
{
|
|
|
|
PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor =
|
|
|
|
&ResourceList->List[0].PartialResourceList.PartialDescriptors[i];
|
2021-03-04 12:43:44 +00:00
|
|
|
|
2021-03-28 17:29:02 +00:00
|
|
|
if (IS_READ_PORT(PartialDescriptor))
|
|
|
|
{
|
|
|
|
PUCHAR ReadDataPort = ULongToPtr(PartialDescriptor->u.Port.Start.u.LowPart + 3);
|
2021-03-04 12:43:44 +00:00
|
|
|
|
2021-03-28 17:29:02 +00:00
|
|
|
/* Run the isolation protocol */
|
2021-03-20 14:50:34 +00:00
|
|
|
FdoExt->Cards = IsaHwTryReadDataPort(ReadDataPort);
|
|
|
|
|
|
|
|
if (FdoExt->Cards > 0)
|
2020-03-16 19:58:53 +00:00
|
|
|
{
|
2021-03-28 17:29:02 +00:00
|
|
|
FdoExt->ReadDataPort = ReadDataPort;
|
|
|
|
|
|
|
|
IsaPnpAcquireDeviceDataLock(FdoExt);
|
2021-03-04 12:48:43 +00:00
|
|
|
|
2021-03-28 17:29:02 +00:00
|
|
|
/* Card identification */
|
|
|
|
Status = IsaHwFillDeviceList(FdoExt);
|
2021-03-20 14:52:40 +00:00
|
|
|
IsaHwWaitForKey();
|
2021-03-28 17:29:02 +00:00
|
|
|
|
2021-03-20 14:50:34 +00:00
|
|
|
IsaPnpReleaseDeviceDataLock(FdoExt);
|
2021-03-28 17:29:02 +00:00
|
|
|
|
2021-03-20 14:50:34 +00:00
|
|
|
PdoExt->Flags |= ISAPNP_READ_PORT_ALLOW_FDO_SCAN |
|
|
|
|
ISAPNP_SCANNED_BY_READ_PORT;
|
2021-03-28 17:29:02 +00:00
|
|
|
|
2021-03-20 14:50:34 +00:00
|
|
|
IoInvalidateDeviceRelations(FdoExt->Pdo, BusRelations);
|
|
|
|
IoInvalidateDeviceRelations(FdoExt->ReadPortPdo, RemovalRelations);
|
2021-03-28 17:29:02 +00:00
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-20 14:52:40 +00:00
|
|
|
IsaHwWaitForKey();
|
|
|
|
#if 0 /* See the 'if 0' above */
|
2021-03-28 17:29:02 +00:00
|
|
|
break;
|
2021-03-20 14:52:40 +00:00
|
|
|
#endif
|
2020-03-16 19:58:53 +00:00
|
|
|
}
|
2020-05-16 21:17:19 +00:00
|
|
|
}
|
2020-03-16 19:58:53 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-28 17:29:02 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return STATUS_DEVICE_CONFIGURATION_ERROR;
|
|
|
|
}
|
2021-03-04 12:42:42 +00:00
|
|
|
|
2021-03-28 17:29:02 +00:00
|
|
|
/* Mark Read Port as started, even if no card has been detected */
|
|
|
|
return STATUS_SUCCESS;
|
2020-03-16 19:58:53 +00:00
|
|
|
}
|
|
|
|
|
2020-03-17 22:51:53 +00:00
|
|
|
static
|
2021-03-04 12:48:43 +00:00
|
|
|
CODE_SEG("PAGE")
|
2020-03-17 22:51:53 +00:00
|
|
|
NTSTATUS
|
2021-03-04 12:48:43 +00:00
|
|
|
IsaPdoFilterResourceRequirements(
|
2021-03-04 12:42:42 +00:00
|
|
|
_In_ PISAPNP_PDO_EXTENSION PdoExt,
|
2021-03-04 12:48:43 +00:00
|
|
|
_Inout_ PIRP Irp,
|
|
|
|
_In_ PIO_STACK_LOCATION IrpSp)
|
2020-03-17 22:51:53 +00:00
|
|
|
{
|
2021-03-04 12:48:43 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
/* TODO: Handle */
|
|
|
|
UNREFERENCED_PARAMETER(PdoExt);
|
|
|
|
UNREFERENCED_PARAMETER(IrpSp);
|
|
|
|
return Irp->IoStatus.Status;
|
2020-03-17 22:51:53 +00:00
|
|
|
}
|
|
|
|
|
2021-03-04 12:47:34 +00:00
|
|
|
static
|
|
|
|
CODE_SEG("PAGE")
|
|
|
|
NTSTATUS
|
|
|
|
IsaPdoQueryBusInformation(
|
|
|
|
_In_ PISAPNP_PDO_EXTENSION PdoExt,
|
|
|
|
_Inout_ PIRP Irp)
|
|
|
|
{
|
|
|
|
PPNP_BUS_INFORMATION BusInformation;
|
|
|
|
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
BusInformation = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
sizeof(PNP_BUS_INFORMATION),
|
|
|
|
TAG_ISAPNP);
|
|
|
|
if (!BusInformation)
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
|
|
|
BusInformation->BusTypeGuid = GUID_BUS_TYPE_ISAPNP;
|
|
|
|
BusInformation->LegacyBusType = Isa;
|
|
|
|
BusInformation->BusNumber = PdoExt->FdoExt->BusNumber;
|
|
|
|
|
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)BusInformation;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-03-04 12:48:43 +00:00
|
|
|
static
|
|
|
|
CODE_SEG("PAGE")
|
|
|
|
NTSTATUS
|
|
|
|
IsaPdoQueryDeviceUsageNotification(
|
|
|
|
_In_ PISAPNP_PDO_EXTENSION PdoExt,
|
|
|
|
_Inout_ PIRP Irp,
|
|
|
|
_In_ PIO_STACK_LOCATION IrpSp)
|
|
|
|
{
|
|
|
|
BOOLEAN InPath = IrpSp->Parameters.UsageNotification.InPath;
|
|
|
|
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
switch (IrpSp->Parameters.UsageNotification.Type)
|
|
|
|
{
|
|
|
|
case DeviceUsageTypePaging:
|
|
|
|
case DeviceUsageTypeHibernation:
|
|
|
|
case DeviceUsageTypeDumpFile:
|
|
|
|
IoAdjustPagingPathCount(&PdoExt->SpecialFiles, InPath);
|
|
|
|
IoInvalidateDeviceState(PdoExt->Common.Self);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return Irp->IoStatus.Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do not send it to FDO for compatibility */
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
CODE_SEG("PAGE")
|
|
|
|
NTSTATUS
|
|
|
|
IsaPdoRemoveDevice(
|
|
|
|
_In_ PISAPNP_PDO_EXTENSION PdoExt,
|
|
|
|
_In_ BOOLEAN FinalRemove)
|
|
|
|
{
|
|
|
|
PISAPNP_FDO_EXTENSION FdoExt = PdoExt->FdoExt;
|
|
|
|
|
|
|
|
PAGED_CODE();
|
|
|
|
|
2021-03-20 14:52:40 +00:00
|
|
|
/* Deactivate the device if previously activated */
|
|
|
|
if (PdoExt->Common.State == dsStarted)
|
|
|
|
{
|
|
|
|
IsaHwWakeDevice(PdoExt->IsaPnpDevice);
|
|
|
|
IsaHwDeactivateDevice(PdoExt->IsaPnpDevice);
|
|
|
|
|
|
|
|
IsaHwWaitForKey();
|
|
|
|
|
|
|
|
PdoExt->Common.State = dsStopped;
|
|
|
|
}
|
|
|
|
|
2021-03-04 12:48:43 +00:00
|
|
|
if (FinalRemove && !(PdoExt->Flags & ISAPNP_ENUMERATED))
|
|
|
|
{
|
|
|
|
IsaPnpAcquireDeviceDataLock(FdoExt);
|
|
|
|
|
|
|
|
RemoveEntryList(&PdoExt->IsaPnpDevice->DeviceLink);
|
|
|
|
--FdoExt->DeviceCount;
|
|
|
|
|
|
|
|
IsaPnpReleaseDeviceDataLock(FdoExt);
|
|
|
|
|
|
|
|
IsaPnpRemoveLogicalDeviceDO(PdoExt->Common.Self);
|
|
|
|
}
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
CODE_SEG("PAGE")
|
|
|
|
NTSTATUS
|
|
|
|
IsaReadPortRemoveDevice(
|
|
|
|
_In_ PISAPNP_PDO_EXTENSION PdoExt,
|
|
|
|
_In_ BOOLEAN FinalRemove)
|
|
|
|
{
|
|
|
|
PISAPNP_FDO_EXTENSION FdoExt = PdoExt->FdoExt;
|
|
|
|
PLIST_ENTRY Entry;
|
|
|
|
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
IsaPnpAcquireDeviceDataLock(FdoExt);
|
|
|
|
|
|
|
|
/* Logical devices will receive a remove request afterwards */
|
|
|
|
for (Entry = FdoExt->DeviceListHead.Flink;
|
|
|
|
Entry != &FdoExt->DeviceListHead;
|
|
|
|
Entry = Entry->Flink)
|
|
|
|
{
|
|
|
|
PISAPNP_LOGICAL_DEVICE LogDevice = CONTAINING_RECORD(Entry,
|
|
|
|
ISAPNP_LOGICAL_DEVICE,
|
|
|
|
DeviceLink);
|
|
|
|
|
|
|
|
LogDevice->Flags &= ~ISAPNP_PRESENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
IsaPnpReleaseDeviceDataLock(FdoExt);
|
|
|
|
|
|
|
|
PdoExt->Flags &= ~ISAPNP_READ_PORT_ALLOW_FDO_SCAN;
|
|
|
|
IoInvalidateDeviceRelations(FdoExt->Pdo, BusRelations);
|
|
|
|
|
|
|
|
if (FinalRemove && !(PdoExt->Flags & ISAPNP_ENUMERATED))
|
|
|
|
{
|
|
|
|
IsaPnpRemoveReadPortDO(PdoExt->Common.Self);
|
|
|
|
}
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
CODE_SEG("PAGE")
|
|
|
|
VOID
|
|
|
|
IsaPnpRemoveLogicalDeviceDO(
|
|
|
|
_In_ PDEVICE_OBJECT Pdo)
|
|
|
|
{
|
|
|
|
PISAPNP_PDO_EXTENSION PdoExt = Pdo->DeviceExtension;
|
|
|
|
PISAPNP_LOGICAL_DEVICE LogDev = PdoExt->IsaPnpDevice;
|
2021-03-20 14:50:34 +00:00
|
|
|
PLIST_ENTRY Entry;
|
2021-03-04 12:48:43 +00:00
|
|
|
|
|
|
|
PAGED_CODE();
|
|
|
|
ASSERT(LogDev);
|
|
|
|
|
|
|
|
DPRINT("Removing CSN %u, LDN %u\n", LogDev->CSN, LogDev->LDN);
|
|
|
|
|
|
|
|
if (PdoExt->RequirementsList)
|
|
|
|
ExFreePoolWithTag(PdoExt->RequirementsList, TAG_ISAPNP);
|
|
|
|
|
|
|
|
if (PdoExt->ResourceList)
|
|
|
|
ExFreePoolWithTag(PdoExt->ResourceList, TAG_ISAPNP);
|
|
|
|
|
2021-03-20 14:50:34 +00:00
|
|
|
if (LogDev->FriendlyName)
|
|
|
|
ExFreePoolWithTag(LogDev->FriendlyName, TAG_ISAPNP);
|
|
|
|
|
|
|
|
if (LogDev->Alternatives)
|
|
|
|
ExFreePoolWithTag(LogDev->Alternatives, TAG_ISAPNP);
|
|
|
|
|
|
|
|
Entry = LogDev->CompatibleIdList.Flink;
|
|
|
|
while (Entry != &LogDev->CompatibleIdList)
|
|
|
|
{
|
|
|
|
PISAPNP_COMPATIBLE_ID_ENTRY CompatibleId =
|
|
|
|
CONTAINING_RECORD(Entry, ISAPNP_COMPATIBLE_ID_ENTRY, IdLink);
|
|
|
|
|
|
|
|
RemoveEntryList(&CompatibleId->IdLink);
|
|
|
|
|
|
|
|
Entry = Entry->Flink;
|
|
|
|
|
|
|
|
ExFreePoolWithTag(CompatibleId, TAG_ISAPNP);
|
|
|
|
}
|
|
|
|
|
2021-03-04 12:48:43 +00:00
|
|
|
ExFreePoolWithTag(LogDev, TAG_ISAPNP);
|
|
|
|
|
|
|
|
IoDeleteDevice(PdoExt->Common.Self);
|
|
|
|
}
|
|
|
|
|
2021-03-04 12:43:44 +00:00
|
|
|
CODE_SEG("PAGE")
|
2010-04-07 20:19:29 +00:00
|
|
|
NTSTATUS
|
|
|
|
IsaPdoPnp(
|
2021-03-04 12:42:42 +00:00
|
|
|
_In_ PISAPNP_PDO_EXTENSION PdoExt,
|
|
|
|
_Inout_ PIRP Irp,
|
|
|
|
_In_ PIO_STACK_LOCATION IrpSp)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2020-03-20 18:19:30 +00:00
|
|
|
NTSTATUS Status = Irp->IoStatus.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
|
|
|
if (PdoExt->Common.Signature == IsaPnpLogicalDevice)
|
|
|
|
{
|
|
|
|
DPRINT("%s(%p, %p) CSN %u, LDN %u, Minor - %X\n",
|
|
|
|
__FUNCTION__,
|
|
|
|
PdoExt,
|
|
|
|
Irp,
|
|
|
|
PdoExt->IsaPnpDevice->CSN,
|
|
|
|
PdoExt->IsaPnpDevice->LDN,
|
|
|
|
IrpSp->MinorFunction);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DPRINT("%s(%p, %p) ReadPort, Minor - %X\n",
|
|
|
|
__FUNCTION__,
|
|
|
|
PdoExt,
|
|
|
|
Irp,
|
|
|
|
IrpSp->MinorFunction);
|
|
|
|
}
|
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
switch (IrpSp->MinorFunction)
|
|
|
|
{
|
2020-03-16 19:50:29 +00:00
|
|
|
case IRP_MN_START_DEVICE:
|
2021-03-20 14:52:40 +00:00
|
|
|
{
|
2021-03-04 12:48:43 +00:00
|
|
|
if (PdoExt->Common.Signature == IsaPnpLogicalDevice)
|
2021-03-20 14:52:40 +00:00
|
|
|
{
|
|
|
|
IsaHwWakeDevice(PdoExt->IsaPnpDevice);
|
|
|
|
|
2021-03-20 14:53:54 +00:00
|
|
|
Status = IsaHwConfigureDevice(PdoExt->FdoExt,
|
|
|
|
PdoExt->IsaPnpDevice,
|
|
|
|
IrpSp->Parameters.StartDevice.AllocatedResources);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
IsaHwActivateDevice(PdoExt->FdoExt, PdoExt->IsaPnpDevice);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DPRINT1("Failed to configure CSN %u, LDN %u with status 0x%08lx\n",
|
|
|
|
PdoExt->IsaPnpDevice->CSN, PdoExt->IsaPnpDevice->LDN, Status);
|
|
|
|
}
|
2021-03-20 14:52:40 +00:00
|
|
|
|
|
|
|
IsaHwWaitForKey();
|
|
|
|
}
|
2020-03-16 19:50:29 +00:00
|
|
|
else
|
2021-03-28 17:29:02 +00:00
|
|
|
{
|
|
|
|
Status = IsaPdoStartReadPort(PdoExt,
|
|
|
|
IrpSp->Parameters.StartDevice.AllocatedResources);
|
|
|
|
}
|
2020-03-16 19:50:29 +00:00
|
|
|
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
PdoExt->Common.State = dsStarted;
|
|
|
|
break;
|
2021-03-20 14:52:40 +00:00
|
|
|
}
|
2020-03-16 19:50:29 +00:00
|
|
|
|
|
|
|
case IRP_MN_STOP_DEVICE:
|
2021-03-20 14:52:40 +00:00
|
|
|
{
|
2021-03-04 12:48:43 +00:00
|
|
|
if (PdoExt->Common.Signature == IsaPnpLogicalDevice)
|
2021-03-20 14:52:40 +00:00
|
|
|
{
|
|
|
|
IsaHwWakeDevice(PdoExt->IsaPnpDevice);
|
|
|
|
IsaHwDeactivateDevice(PdoExt->IsaPnpDevice);
|
|
|
|
|
|
|
|
IsaHwWaitForKey();
|
|
|
|
}
|
2020-03-16 19:50:29 +00:00
|
|
|
else
|
2021-03-04 12:48:43 +00:00
|
|
|
{
|
|
|
|
PdoExt->Flags &= ~ISAPNP_READ_PORT_ALLOW_FDO_SCAN;
|
|
|
|
}
|
2020-03-16 19:50:29 +00:00
|
|
|
|
2021-03-20 14:52:40 +00:00
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
|
2020-03-16 19:50:29 +00:00
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
PdoExt->Common.State = dsStopped;
|
|
|
|
break;
|
2021-03-20 14:52:40 +00:00
|
|
|
}
|
2020-03-16 19:50:29 +00:00
|
|
|
|
2021-03-04 12:48:43 +00:00
|
|
|
case IRP_MN_QUERY_STOP_DEVICE:
|
|
|
|
{
|
|
|
|
if (PdoExt->SpecialFiles > 0)
|
|
|
|
Status = STATUS_DEVICE_BUSY;
|
2021-03-28 17:29:02 +00:00
|
|
|
else if (PdoExt->Flags & ISAPNP_READ_PORT_NEED_REBALANCE)
|
|
|
|
Status = STATUS_RESOURCE_REQUIREMENTS_CHANGED;
|
2021-03-04 12:48:43 +00:00
|
|
|
else
|
|
|
|
Status = STATUS_SUCCESS;
|
2021-03-28 17:29:02 +00:00
|
|
|
|
2021-03-04 12:48:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IRP_MN_QUERY_REMOVE_DEVICE:
|
|
|
|
{
|
|
|
|
if (PdoExt->SpecialFiles > 0)
|
|
|
|
Status = STATUS_DEVICE_BUSY;
|
|
|
|
else
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-03-16 19:50:29 +00:00
|
|
|
case IRP_MN_QUERY_DEVICE_RELATIONS:
|
|
|
|
Status = IsaPdoQueryDeviceRelations(PdoExt, Irp, IrpSp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_QUERY_CAPABILITIES:
|
|
|
|
Status = IsaPdoQueryCapabilities(PdoExt, Irp, IrpSp);
|
|
|
|
break;
|
|
|
|
|
2021-03-04 12:48:43 +00:00
|
|
|
case IRP_MN_SURPRISE_REMOVAL:
|
|
|
|
if (PdoExt->Common.Signature == IsaPnpLogicalDevice)
|
|
|
|
Status = IsaPdoRemoveDevice(PdoExt, FALSE);
|
|
|
|
else
|
|
|
|
Status = IsaReadPortRemoveDevice(PdoExt, FALSE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_REMOVE_DEVICE:
|
|
|
|
if (PdoExt->Common.Signature == IsaPnpLogicalDevice)
|
|
|
|
Status = IsaPdoRemoveDevice(PdoExt, TRUE);
|
|
|
|
else
|
|
|
|
Status = IsaReadPortRemoveDevice(PdoExt, TRUE);
|
|
|
|
break;
|
|
|
|
|
2020-03-17 22:50:39 +00:00
|
|
|
case IRP_MN_QUERY_PNP_DEVICE_STATE:
|
2021-03-04 12:48:43 +00:00
|
|
|
Status = IsaPdoQueryPnpDeviceState(PdoExt, Irp);
|
2020-03-17 22:50:39 +00:00
|
|
|
break;
|
|
|
|
|
2020-03-16 19:50:29 +00:00
|
|
|
case IRP_MN_QUERY_RESOURCES:
|
2020-03-21 16:37:45 +00:00
|
|
|
Status = IsaPdoQueryResources(PdoExt, Irp, IrpSp);
|
2020-03-16 19:50:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_QUERY_RESOURCE_REQUIREMENTS:
|
2020-03-21 15:58:21 +00:00
|
|
|
Status = IsaPdoQueryResourceRequirements(PdoExt, Irp, IrpSp);
|
2020-03-16 19:50:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_QUERY_ID:
|
2021-03-04 12:48:43 +00:00
|
|
|
if (PdoExt->Common.Signature == IsaPnpLogicalDevice)
|
2021-03-04 12:44:20 +00:00
|
|
|
Status = IsaPdoQueryId(PdoExt, Irp, IrpSp);
|
|
|
|
else
|
|
|
|
Status = IsaReadPortQueryId(Irp, IrpSp);
|
2020-03-16 19:50:29 +00:00
|
|
|
break;
|
|
|
|
|
2021-03-20 14:50:34 +00:00
|
|
|
case IRP_MN_QUERY_DEVICE_TEXT:
|
|
|
|
if (PdoExt->Common.Signature == IsaPnpLogicalDevice)
|
|
|
|
Status = IsaPdoQueryDeviceText(PdoExt, Irp, IrpSp);
|
|
|
|
break;
|
|
|
|
|
2021-03-04 12:48:43 +00:00
|
|
|
case IRP_MN_FILTER_RESOURCE_REQUIREMENTS:
|
|
|
|
Status = IsaPdoFilterResourceRequirements(PdoExt, Irp, IrpSp);
|
|
|
|
break;
|
|
|
|
|
2021-03-04 12:47:34 +00:00
|
|
|
case IRP_MN_QUERY_BUS_INFORMATION:
|
|
|
|
Status = IsaPdoQueryBusInformation(PdoExt, Irp);
|
|
|
|
break;
|
|
|
|
|
2021-03-04 12:48:43 +00:00
|
|
|
case IRP_MN_DEVICE_USAGE_NOTIFICATION:
|
|
|
|
Status = IsaPdoQueryDeviceUsageNotification(PdoExt, Irp, IrpSp);
|
|
|
|
break;
|
|
|
|
|
2020-03-17 22:51:53 +00:00
|
|
|
case IRP_MN_CANCEL_REMOVE_DEVICE:
|
|
|
|
case IRP_MN_CANCEL_STOP_DEVICE:
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
break;
|
|
|
|
|
2020-03-16 19:50:29 +00:00
|
|
|
default:
|
2021-03-04 12:48:43 +00:00
|
|
|
DPRINT("Unknown PnP code: %X\n", IrpSp->MinorFunction);
|
2020-03-16 19:50:29 +00:00
|
|
|
break;
|
2020-03-20 18:19:30 +00:00
|
|
|
}
|
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);
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
return Status;
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|