https://git.reactos.org/?p=reactos.git;a=commitdiff;h=debec8c96ee50336ff5b22ed24821e2c075b5729

commit debec8c96ee50336ff5b22ed24821e2c075b5729
Author:     Hervé Poussineau <[email protected]>
AuthorDate: Sat Mar 21 16:58:21 2020 +0100
Commit:     Hervé Poussineau <[email protected]>
CommitDate: Sun Mar 22 14:29:38 2020 +0100

    [ISAPNP] Create resource requirements ahead of 
IRP_MN_QUERY_RESOURCE_REQUIREMENTS
---
 drivers/bus/isapnp/isapnp.c | 55 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/bus/isapnp/isapnp.h |  1 +
 drivers/bus/isapnp/pdo.c    | 47 +++++++-------------------------------
 3 files changed, 64 insertions(+), 39 deletions(-)

diff --git a/drivers/bus/isapnp/isapnp.c b/drivers/bus/isapnp/isapnp.c
index 16fd14c489d..c9025875ddc 100644
--- a/drivers/bus/isapnp/isapnp.c
+++ b/drivers/bus/isapnp/isapnp.c
@@ -6,6 +6,7 @@
  */
 
 #include <isapnp.h>
+#include <isapnphw.h>
 
 #define NDEBUG
 #include <debug.h>
@@ -328,6 +329,56 @@ IsaReadWrite(
     return STATUS_NOT_SUPPORTED;
 }
 
+static
+NTSTATUS
+NTAPI
+IsaPnpCreateReadPortDORequirements(
+    IN PISAPNP_PDO_EXTENSION PdoExt)
+{
+    USHORT Ports[] = { ISAPNP_WRITE_DATA, ISAPNP_ADDRESS, 0x274, 0x3e4, 0x204, 
0x2e4, 0x354, 0x2f4 };
+    ULONG ListSize, i;
+    PIO_RESOURCE_REQUIREMENTS_LIST RequirementsList;
+    PIO_RESOURCE_DESCRIPTOR Descriptor;
+
+    ListSize = sizeof(IO_RESOURCE_REQUIREMENTS_LIST)
+             + 2 * ARRAYSIZE(Ports) * sizeof(IO_RESOURCE_DESCRIPTOR);
+    RequirementsList = ExAllocatePool(PagedPool, ListSize);
+    if (!RequirementsList)
+        return STATUS_NO_MEMORY;
+
+    RtlZeroMemory(RequirementsList, ListSize);
+    RequirementsList->ListSize = ListSize;
+    RequirementsList->AlternativeLists = 1;
+
+    RequirementsList->List[0].Version = 1;
+    RequirementsList->List[0].Revision = 1;
+    RequirementsList->List[0].Count = 2 * ARRAYSIZE(Ports);
+
+    for (i = 0; i < 2 * ARRAYSIZE(Ports); i += 2)
+    {
+        Descriptor = &RequirementsList->List[0].Descriptors[i];
+
+        /* Expected port */
+        Descriptor[0].Type = CmResourceTypePort;
+        Descriptor[0].ShareDisposition = CmResourceShareDeviceExclusive;
+        Descriptor[0].Flags = CM_RESOURCE_PORT_16_BIT_DECODE;
+        Descriptor[0].u.Port.Length = Ports[i / 2] & 1 ? 0x01 : 0x04;
+        Descriptor[0].u.Port.Alignment = 0x01;
+        Descriptor[0].u.Port.MinimumAddress.LowPart = Ports[i / 2];
+        Descriptor[0].u.Port.MaximumAddress.LowPart = Ports[i / 2] + 
Descriptor[0].u.Port.Length - 1;
+
+        /* ... but mark it as optional */
+        Descriptor[1].Option = IO_RESOURCE_ALTERNATIVE;
+        Descriptor[1].Type = CmResourceTypePort;
+        Descriptor[1].ShareDisposition = CmResourceShareDeviceExclusive;
+        Descriptor[1].Flags = CM_RESOURCE_PORT_16_BIT_DECODE;
+        Descriptor[1].u.Port.Alignment = 0x01;
+    }
+
+    PdoExt->RequirementsList = RequirementsList;
+    return STATUS_SUCCESS;
+}
+
 static
 NTSTATUS
 NTAPI
@@ -380,6 +431,10 @@ IsaPnpCreateReadPortDO(PISAPNP_FDO_EXTENSION FdoExt)
     if (!NT_SUCCESS(Status))
         return Status;
 
+    Status = IsaPnpCreateReadPortDORequirements(PdoExt);
+    if (!NT_SUCCESS(Status))
+        return Status;
+
     return Status;
 }
 
diff --git a/drivers/bus/isapnp/isapnp.h b/drivers/bus/isapnp/isapnp.h
index 8417687867b..2d45ce6cac7 100644
--- a/drivers/bus/isapnp/isapnp.h
+++ b/drivers/bus/isapnp/isapnp.h
@@ -53,6 +53,7 @@ typedef struct _ISAPNP_PDO_EXTENSION {
     UNICODE_STRING HardwareIDs;
     UNICODE_STRING CompatibleIDs;
     UNICODE_STRING InstanceID;
+    PIO_RESOURCE_REQUIREMENTS_LIST RequirementsList;
 } ISAPNP_PDO_EXTENSION, *PISAPNP_PDO_EXTENSION;
 
 /* isapnp.c */
diff --git a/drivers/bus/isapnp/pdo.c b/drivers/bus/isapnp/pdo.c
index 2add8d4a2b3..cecb3d2000f 100644
--- a/drivers/bus/isapnp/pdo.c
+++ b/drivers/bus/isapnp/pdo.c
@@ -183,46 +183,18 @@ IsaPdoQueryResourceRequirements(
     IN PIRP Irp,
     IN PIO_STACK_LOCATION IrpSp)
 {
-    USHORT Ports[] = { ISAPNP_WRITE_DATA, ISAPNP_ADDRESS, 0x274, 0x3e4, 0x204, 
0x2e4, 0x354, 0x2f4 };
-    ULONG ListSize, i;
+    ULONG ListSize;
     PIO_RESOURCE_REQUIREMENTS_LIST RequirementsList;
-    PIO_RESOURCE_DESCRIPTOR Descriptor;
 
-    ListSize = sizeof(IO_RESOURCE_REQUIREMENTS_LIST)
-             + 2 * ARRAYSIZE(Ports) * sizeof(IO_RESOURCE_DESCRIPTOR);
-    RequirementsList = ExAllocatePool(NonPagedPool, ListSize);
+    if (!PdoExt->RequirementsList)
+        return Irp->IoStatus.Status;
+
+    ListSize = PdoExt->RequirementsList->ListSize;
+    RequirementsList = ExAllocatePool(PagedPool, ListSize);
     if (!RequirementsList)
         return STATUS_NO_MEMORY;
 
-    RtlZeroMemory(RequirementsList, ListSize);
-    RequirementsList->ListSize = ListSize;
-    RequirementsList->AlternativeLists = 1;
-
-    RequirementsList->List[0].Version = 1;
-    RequirementsList->List[0].Revision = 1;
-    RequirementsList->List[0].Count = 2 * ARRAYSIZE(Ports);
-
-    for (i = 0; i < 2 * ARRAYSIZE(Ports); i += 2)
-    {
-        Descriptor = &RequirementsList->List[0].Descriptors[i];
-
-        /* Expected port */
-        Descriptor[0].Type = CmResourceTypePort;
-        Descriptor[0].ShareDisposition = CmResourceShareDeviceExclusive;
-        Descriptor[0].Flags = CM_RESOURCE_PORT_16_BIT_DECODE;
-        Descriptor[0].u.Port.Length = Ports[i / 2] & 1 ? 0x01 : 0x04;
-        Descriptor[0].u.Port.Alignment = 0x01;
-        Descriptor[0].u.Port.MinimumAddress.LowPart = Ports[i / 2];
-        Descriptor[0].u.Port.MaximumAddress.LowPart = Ports[i / 2] + 
Descriptor[0].u.Port.Length - 1;
-
-        /* ... but mark it as optional */
-        Descriptor[1].Option = IO_RESOURCE_ALTERNATIVE;
-        Descriptor[1].Type = CmResourceTypePort;
-        Descriptor[1].ShareDisposition = CmResourceShareDeviceExclusive;
-        Descriptor[1].Flags = CM_RESOURCE_PORT_16_BIT_DECODE;
-        Descriptor[1].u.Port.Alignment = 0x01;
-    }
-
+    RtlCopyMemory(RequirementsList, PdoExt->RequirementsList, ListSize);
     Irp->IoStatus.Information = (ULONG_PTR)RequirementsList;
     return STATUS_SUCCESS;
 }
@@ -383,10 +355,7 @@ IsaPdoPnp(
             break;
 
         case IRP_MN_QUERY_RESOURCE_REQUIREMENTS:
-            if (PdoExt->Common.Self == PdoExt->FdoExt->DataPortPdo)
-                Status = IsaPdoQueryResourceRequirements(PdoExt, Irp, IrpSp);
-            else
-                DPRINT1("IRP_MN_QUERY_RESOURCE_REQUIREMENTS is 
UNIMPLEMENTED!\n");
+            Status = IsaPdoQueryResourceRequirements(PdoExt, Irp, IrpSp);
             break;
 
         case IRP_MN_QUERY_ID:

Reply via email to