[ISAPNP] Create resource list ahead of IRP_MN_QUERY_RESOURCES

This commit is contained in:
Hervé Poussineau 2020-03-21 17:37:45 +01:00
parent debec8c96e
commit 61c1079a18
3 changed files with 53 additions and 28 deletions

View file

@ -379,6 +379,45 @@ IsaPnpCreateReadPortDORequirements(
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
static
NTSTATUS
NTAPI
IsaPnpCreateReadPortDOResources(
IN PISAPNP_PDO_EXTENSION PdoExt)
{
USHORT Ports[] = { ISAPNP_WRITE_DATA, ISAPNP_ADDRESS };
ULONG ListSize, i;
PCM_RESOURCE_LIST ResourceList;
PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor;
ListSize = sizeof(CM_RESOURCE_LIST)
+ (ARRAYSIZE(Ports) - 1) * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
ResourceList = ExAllocatePool(PagedPool, ListSize);
if (!ResourceList)
return STATUS_NO_MEMORY;
RtlZeroMemory(ResourceList, ListSize);
ResourceList->Count = 1;
ResourceList->List[0].InterfaceType = Internal;
ResourceList->List[0].PartialResourceList.Version = 1;
ResourceList->List[0].PartialResourceList.Revision = 1;
ResourceList->List[0].PartialResourceList.Count = 2;
for (i = 0; i < ARRAYSIZE(Ports); i++)
{
Descriptor = &ResourceList->List[0].PartialResourceList.PartialDescriptors[i];
Descriptor->Type = CmResourceTypePort;
Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
Descriptor->Flags = CM_RESOURCE_PORT_16_BIT_DECODE;
Descriptor->u.Port.Length = 0x01;
Descriptor->u.Port.Start.LowPart = Ports[i];
}
PdoExt->ResourceList = ResourceList;
PdoExt->ResourceListSize = ListSize;
return STATUS_SUCCESS;
}
static static
NTSTATUS NTSTATUS
NTAPI NTAPI
@ -435,6 +474,10 @@ IsaPnpCreateReadPortDO(PISAPNP_FDO_EXTENSION FdoExt)
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
return Status; return Status;
Status = IsaPnpCreateReadPortDOResources(PdoExt);
if (!NT_SUCCESS(Status))
return Status;
return Status; return Status;
} }

View file

@ -54,6 +54,8 @@ typedef struct _ISAPNP_PDO_EXTENSION {
UNICODE_STRING CompatibleIDs; UNICODE_STRING CompatibleIDs;
UNICODE_STRING InstanceID; UNICODE_STRING InstanceID;
PIO_RESOURCE_REQUIREMENTS_LIST RequirementsList; PIO_RESOURCE_REQUIREMENTS_LIST RequirementsList;
PCM_RESOURCE_LIST ResourceList;
ULONG ResourceListSize;
} ISAPNP_PDO_EXTENSION, *PISAPNP_PDO_EXTENSION; } ISAPNP_PDO_EXTENSION, *PISAPNP_PDO_EXTENSION;
/* isapnp.c */ /* isapnp.c */

View file

@ -6,7 +6,6 @@
*/ */
#include <isapnp.h> #include <isapnp.h>
#include <isapnphw.h>
#define NDEBUG #define NDEBUG
#include <debug.h> #include <debug.h>
@ -144,34 +143,18 @@ IsaPdoQueryResources(
IN PIRP Irp, IN PIRP Irp,
IN PIO_STACK_LOCATION IrpSp) IN PIO_STACK_LOCATION IrpSp)
{ {
USHORT Ports[] = { ISAPNP_WRITE_DATA, ISAPNP_ADDRESS }; ULONG ListSize;
ULONG ListSize, i;
PCM_RESOURCE_LIST ResourceList; PCM_RESOURCE_LIST ResourceList;
PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor;
ListSize = sizeof(CM_RESOURCE_LIST) if (!PdoExt->ResourceList)
+ (ARRAYSIZE(Ports) - 1) * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR); return Irp->IoStatus.Status;
ResourceList = ExAllocatePool(NonPagedPool, ListSize);
ListSize = PdoExt->ResourceListSize;
ResourceList = ExAllocatePool(PagedPool, ListSize);
if (!ResourceList) if (!ResourceList)
return STATUS_NO_MEMORY; return STATUS_NO_MEMORY;
RtlZeroMemory(ResourceList, ListSize); RtlCopyMemory(ResourceList, PdoExt->ResourceList, ListSize);
ResourceList->Count = 1;
ResourceList->List[0].InterfaceType = Internal;
ResourceList->List[0].PartialResourceList.Version = 1;
ResourceList->List[0].PartialResourceList.Revision = 1;
ResourceList->List[0].PartialResourceList.Count = 2;
for (i = 0; i < ARRAYSIZE(Ports); i++)
{
Descriptor = &ResourceList->List[0].PartialResourceList.PartialDescriptors[i];
Descriptor->Type = CmResourceTypePort;
Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
Descriptor->Flags = CM_RESOURCE_PORT_16_BIT_DECODE;
Descriptor->u.Port.Length = 0x01;
Descriptor->u.Port.Start.LowPart = Ports[i];
}
Irp->IoStatus.Information = (ULONG_PTR)ResourceList; Irp->IoStatus.Information = (ULONG_PTR)ResourceList;
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
@ -348,10 +331,7 @@ IsaPdoPnp(
break; break;
case IRP_MN_QUERY_RESOURCES: case IRP_MN_QUERY_RESOURCES:
if (PdoExt->Common.Self == PdoExt->FdoExt->DataPortPdo) Status = IsaPdoQueryResources(PdoExt, Irp, IrpSp);
Status = IsaPdoQueryResources(PdoExt, Irp, IrpSp);
else
DPRINT1("IRP_MN_QUERY_RESOURCES is UNIMPLEMENTED!\n");
break; break;
case IRP_MN_QUERY_RESOURCE_REQUIREMENTS: case IRP_MN_QUERY_RESOURCE_REQUIREMENTS: