https://git.reactos.org/?p=reactos.git;a=commitdiff;h=8f44930f91fc843884a77…
commit 8f44930f91fc843884a778c018c8809ed34ad5d9
Author: Dmitry Borisov <di.sean(a)protonmail.com>
AuthorDate: Thu Mar 4 18:42:42 2021 +0600
Commit: Dmitry Borisov <di.sean(a)protonmail.com>
CommitDate: Sun Jun 20 19:22:31 2021 +0600
[ISAPNP] Code formatting
- Add SAL2 annotations.
- Use RTL_NUMBER_OF macro in kernel mode.
- Use better function/member names.
- Less hardcoded values.
- Add license information. See commit
d9face83c693cb5e3fad155df8609d9c13316061 for details.
No functional changes.
---
drivers/bus/isapnp/fdo.c | 26 ++---
drivers/bus/isapnp/hardware.c | 107 +++++++++----------
drivers/bus/isapnp/isapnp.c | 234 ++++++++++++++++++++++--------------------
drivers/bus/isapnp/isapnp.h | 76 ++++++++------
drivers/bus/isapnp/isapnphw.h | 32 ++++--
drivers/bus/isapnp/pdo.c | 98 ++++++++++--------
6 files changed, 311 insertions(+), 262 deletions(-)
diff --git a/drivers/bus/isapnp/fdo.c b/drivers/bus/isapnp/fdo.c
index be044407f20..b1d5781ea48 100644
--- a/drivers/bus/isapnp/fdo.c
+++ b/drivers/bus/isapnp/fdo.c
@@ -1,12 +1,12 @@
/*
* PROJECT: ReactOS ISA PnP Bus driver
- * FILE: fdo.c
+ * LICENSE: GPL-2.0-or-later (
https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: FDO-specific code
- * PROGRAMMERS: Cameron Gutman (cameron.gutman(a)reactos.org)
- * Hervé Poussineau
+ * COPYRIGHT: Copyright 2010 Cameron Gutman <cameron.gutman(a)reactos.org>
+ * Copyright 2020 Hervé Poussineau <hpoussin(a)reactos.org>
*/
-#include <isapnp.h>
+#include "isapnp.h"
#define NDEBUG
#include <debug.h>
@@ -14,9 +14,9 @@
NTSTATUS
NTAPI
IsaFdoStartDevice(
- IN PISAPNP_FDO_EXTENSION FdoExt,
- IN PIRP Irp,
- IN PIO_STACK_LOCATION IrpSp)
+ _In_ PISAPNP_FDO_EXTENSION FdoExt,
+ _Inout_ PIRP Irp,
+ _In_ PIO_STACK_LOCATION IrpSp)
{
UNREFERENCED_PARAMETER(Irp);
UNREFERENCED_PARAMETER(IrpSp);
@@ -29,9 +29,9 @@ IsaFdoStartDevice(
NTSTATUS
NTAPI
IsaFdoQueryDeviceRelations(
- IN PISAPNP_FDO_EXTENSION FdoExt,
- IN PIRP Irp,
- IN PIO_STACK_LOCATION IrpSp)
+ _In_ PISAPNP_FDO_EXTENSION FdoExt,
+ _Inout_ PIRP Irp,
+ _In_ PIO_STACK_LOCATION IrpSp)
{
if (IrpSp->Parameters.QueryDeviceRelations.Type != BusRelations)
return Irp->IoStatus.Status;
@@ -42,9 +42,9 @@ IsaFdoQueryDeviceRelations(
NTSTATUS
NTAPI
IsaFdoPnp(
- IN PISAPNP_FDO_EXTENSION FdoExt,
- IN PIRP Irp,
- IN PIO_STACK_LOCATION IrpSp)
+ _In_ PISAPNP_FDO_EXTENSION FdoExt,
+ _Inout_ PIRP Irp,
+ _In_ PIO_STACK_LOCATION IrpSp)
{
NTSTATUS Status = Irp->IoStatus.Status;
diff --git a/drivers/bus/isapnp/hardware.c b/drivers/bus/isapnp/hardware.c
index 8b84038ef8a..5c016902d5b 100644
--- a/drivers/bus/isapnp/hardware.c
+++ b/drivers/bus/isapnp/hardware.c
@@ -1,12 +1,12 @@
/*
* PROJECT: ReactOS ISA PnP Bus driver
- * FILE: hardware.c
+ * LICENSE: GPL-2.0-or-later (
https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Hardware support code
- * PROGRAMMERS: Cameron Gutman (cameron.gutman(a)reactos.org)
- * Hervé Poussineau
+ * COPYRIGHT: Copyright 2010 Cameron Gutman <cameron.gutman(a)reactos.org>
+ * Copyright 2020 Hervé Poussineau <hpoussin(a)reactos.org>
*/
-#include <isapnp.h>
+#include "isapnp.h"
#define NDEBUG
#include <debug.h>
@@ -15,7 +15,7 @@ static
inline
VOID
WriteAddress(
- IN USHORT Address)
+ _In_ USHORT Address)
{
WRITE_PORT_UCHAR((PUCHAR)ISAPNP_ADDRESS, Address);
}
@@ -24,7 +24,7 @@ static
inline
VOID
WriteData(
- IN USHORT Data)
+ _In_ USHORT Data)
{
WRITE_PORT_UCHAR((PUCHAR)ISAPNP_WRITE_DATA, Data);
}
@@ -33,7 +33,7 @@ static
inline
UCHAR
ReadData(
- IN PUCHAR ReadDataPort)
+ _In_ PUCHAR ReadDataPort)
{
return READ_PORT_UCHAR(ReadDataPort);
}
@@ -42,8 +42,8 @@ static
inline
VOID
WriteByte(
- IN USHORT Address,
- IN USHORT Value)
+ _In_ USHORT Address,
+ _In_ USHORT Value)
{
WriteAddress(Address);
WriteData(Value);
@@ -53,8 +53,8 @@ static
inline
UCHAR
ReadByte(
- IN PUCHAR ReadDataPort,
- IN USHORT Address)
+ _In_ PUCHAR ReadDataPort,
+ _In_ USHORT Address)
{
WriteAddress(Address);
return ReadData(ReadDataPort);
@@ -64,8 +64,8 @@ static
inline
USHORT
ReadWord(
- IN PUCHAR ReadDataPort,
- IN USHORT Address)
+ _In_ PUCHAR ReadDataPort,
+ _In_ USHORT Address)
{
return ((ReadByte(ReadDataPort, Address) << 8) |
(ReadByte(ReadDataPort, Address + 1)));
@@ -75,7 +75,7 @@ static
inline
VOID
SetReadDataPort(
- IN PUCHAR ReadDataPort)
+ _In_ PUCHAR ReadDataPort)
{
WriteByte(ISAPNP_READPORT, ((ULONG_PTR)ReadDataPort >> 2));
}
@@ -108,7 +108,7 @@ static
inline
VOID
Wake(
- IN USHORT Csn)
+ _In_ USHORT Csn)
{
WriteByte(ISAPNP_WAKE, Csn);
}
@@ -117,7 +117,7 @@ static
inline
USHORT
ReadResourceData(
- IN PUCHAR ReadDataPort)
+ _In_ PUCHAR ReadDataPort)
{
return ReadByte(ReadDataPort, ISAPNP_RESOURCEDATA);
}
@@ -126,7 +126,7 @@ static
inline
USHORT
ReadStatus(
- IN PUCHAR ReadDataPort)
+ _In_ PUCHAR ReadDataPort)
{
return ReadByte(ReadDataPort, ISAPNP_STATUS);
}
@@ -135,7 +135,7 @@ static
inline
VOID
WriteCsn(
- IN USHORT Csn)
+ _In_ USHORT Csn)
{
WriteByte(ISAPNP_CARDSELECTNUMBER, Csn);
}
@@ -144,7 +144,7 @@ static
inline
VOID
WriteLogicalDeviceNumber(
- IN USHORT LogDev)
+ _In_ USHORT LogDev)
{
WriteByte(ISAPNP_LOGICALDEVICENUMBER, LogDev);
}
@@ -153,7 +153,7 @@ static
inline
VOID
ActivateDevice(
- IN USHORT LogDev)
+ _In_ USHORT LogDev)
{
WriteLogicalDeviceNumber(LogDev);
WriteByte(ISAPNP_ACTIVATE, 1);
@@ -163,7 +163,7 @@ static
inline
VOID
DeactivateDevice(
- IN USHORT LogDev)
+ _In_ USHORT LogDev)
{
WriteLogicalDeviceNumber(LogDev);
WriteByte(ISAPNP_ACTIVATE, 0);
@@ -173,8 +173,8 @@ static
inline
USHORT
ReadIoBase(
- IN PUCHAR ReadDataPort,
- IN USHORT Index)
+ _In_ PUCHAR ReadDataPort,
+ _In_ USHORT Index)
{
return ReadWord(ReadDataPort, ISAPNP_IOBASE(Index));
}
@@ -183,8 +183,8 @@ static
inline
USHORT
ReadIrqNo(
- IN PUCHAR ReadDataPort,
- IN USHORT Index)
+ _In_ PUCHAR ReadDataPort,
+ _In_ USHORT Index)
{
return ReadByte(ReadDataPort, ISAPNP_IRQNO(Index));
}
@@ -193,8 +193,8 @@ static
inline
USHORT
ReadIrqType(
- IN PUCHAR ReadDataPort,
- IN USHORT Index)
+ _In_ PUCHAR ReadDataPort,
+ _In_ USHORT Index)
{
return ReadByte(ReadDataPort, ISAPNP_IRQTYPE(Index));
}
@@ -203,8 +203,8 @@ static
inline
USHORT
ReadDmaChannel(
- IN PUCHAR ReadDataPort,
- IN USHORT Index)
+ _In_ PUCHAR ReadDataPort,
+ _In_ USHORT Index)
{
return ReadByte(ReadDataPort, ISAPNP_DMACHANNEL(Index));
}
@@ -221,8 +221,8 @@ static
inline
UCHAR
NextLFSR(
- IN UCHAR Lfsr,
- IN UCHAR InputBit)
+ _In_ UCHAR Lfsr,
+ _In_ UCHAR InputBit)
{
UCHAR NextLfsr = Lfsr >> 1;
@@ -252,7 +252,7 @@ SendKey(VOID)
static
USHORT
PeekByte(
- IN PUCHAR ReadDataPort)
+ _In_ PUCHAR ReadDataPort)
{
USHORT i;
@@ -270,9 +270,9 @@ PeekByte(
static
VOID
Peek(
- IN PUCHAR ReadDataPort,
- IN OUT PVOID Buffer,
- IN ULONG Length)
+ _In_ PUCHAR ReadDataPort,
+ _Out_writes_bytes_all_opt_(Length) PVOID Buffer,
+ _In_ ULONG Length)
{
USHORT i, Byte;
@@ -280,22 +280,23 @@ Peek(
{
Byte = PeekByte(ReadDataPort);
if (Buffer)
- *((PUCHAR)Buffer + i) = Byte;
+ ((PUCHAR)Buffer)[i] = Byte;
}
}
static
USHORT
IsaPnpChecksum(
- IN PISAPNP_IDENTIFIER Identifier)
+ _In_ PISAPNP_IDENTIFIER Identifier)
{
- UCHAR i, j, Lfsr, Byte;
+ UCHAR i, j, Lfsr;
Lfsr = ISAPNP_LFSR_SEED;
- for (i = 0; i < 8; i++)
+ for (i = 0; i < FIELD_OFFSET(ISAPNP_IDENTIFIER, Checksum); i++)
{
- Byte = *(((PUCHAR)Identifier) + i);
- for (j = 0; j < 8; j++)
+ UCHAR Byte = ((PUCHAR)Identifier)[i];
+
+ for (j = 0; j < RTL_BITS_OF(Byte); j++)
{
Lfsr = NextLFSR(Lfsr, Byte);
Byte >>= 1;
@@ -308,9 +309,9 @@ IsaPnpChecksum(
static
BOOLEAN
ReadTags(
- IN PUCHAR ReadDataPort,
- IN USHORT LogDev,
- IN OUT PISAPNP_LOGICAL_DEVICE LogDevice)
+ _In_ PUCHAR ReadDataPort,
+ _In_ USHORT LogDev,
+ _Inout_ PISAPNP_LOGICAL_DEVICE LogDevice)
{
BOOLEAN res = FALSE;
PVOID Buffer;
@@ -392,7 +393,7 @@ ReadTags(
static
INT
TryIsolate(
- IN PUCHAR ReadDataPort)
+ _In_ PUCHAR ReadDataPort)
{
ISAPNP_IDENTIFIER Identifier;
USHORT i, j;
@@ -497,8 +498,8 @@ TryIsolate(
VOID
DeviceActivation(
- IN PISAPNP_LOGICAL_DEVICE IsaDevice,
- IN BOOLEAN Activate)
+ _In_ PISAPNP_LOGICAL_DEVICE IsaDevice,
+ _In_ BOOLEAN Activate)
{
WaitForKey();
SendKey();
@@ -516,7 +517,7 @@ DeviceActivation(
NTSTATUS
ProbeIsaPnpBus(
- IN PISAPNP_FDO_EXTENSION FdoExt)
+ _In_ PISAPNP_FDO_EXTENSION FdoExt)
{
PISAPNP_LOGICAL_DEVICE LogDevice;
ISAPNP_IDENTIFIER Identifier;
@@ -578,7 +579,7 @@ ProbeIsaPnpBus(
WaitForKey();
- InsertTailList(&FdoExt->DeviceListHead,
&LogDevice->ListEntry);
+ InsertTailList(&FdoExt->DeviceListHead,
&LogDevice->DeviceLink);
FdoExt->DeviceCount++;
}
}
@@ -589,7 +590,7 @@ ProbeIsaPnpBus(
NTSTATUS
NTAPI
IsaHwTryReadDataPort(
- IN PUCHAR ReadDataPort)
+ _In_ PUCHAR ReadDataPort)
{
return TryIsolate(ReadDataPort) > 0 ? STATUS_SUCCESS :
STATUS_INSUFFICIENT_RESOURCES;
}
@@ -597,7 +598,7 @@ IsaHwTryReadDataPort(
NTSTATUS
NTAPI
IsaHwActivateDevice(
- IN PISAPNP_LOGICAL_DEVICE LogicalDevice)
+ _In_ PISAPNP_LOGICAL_DEVICE LogicalDevice)
{
DeviceActivation(LogicalDevice,
TRUE);
@@ -608,7 +609,7 @@ IsaHwActivateDevice(
NTSTATUS
NTAPI
IsaHwDeactivateDevice(
- IN PISAPNP_LOGICAL_DEVICE LogicalDevice)
+ _In_ PISAPNP_LOGICAL_DEVICE LogicalDevice)
{
DeviceActivation(LogicalDevice,
FALSE);
@@ -619,7 +620,7 @@ IsaHwDeactivateDevice(
NTSTATUS
NTAPI
IsaHwFillDeviceList(
- IN PISAPNP_FDO_EXTENSION FdoExt)
+ _In_ PISAPNP_FDO_EXTENSION FdoExt)
{
return ProbeIsaPnpBus(FdoExt);
}
diff --git a/drivers/bus/isapnp/isapnp.c b/drivers/bus/isapnp/isapnp.c
index f14894de6c8..784119502de 100644
--- a/drivers/bus/isapnp/isapnp.c
+++ b/drivers/bus/isapnp/isapnp.c
@@ -1,12 +1,12 @@
/*
* PROJECT: ReactOS ISA PnP Bus driver
- * FILE: isapnp.c
+ * LICENSE: GPL-2.0-or-later (
https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Driver entry
- * PROGRAMMERS: Cameron Gutman (cameron.gutman(a)reactos.org)
- * Hervé Poussineau
+ * COPYRIGHT: Copyright 2010 Cameron Gutman <cameron.gutman(a)reactos.org>
+ * Copyright 2020 Hervé Poussineau <hpoussin(a)reactos.org>
*/
-#include <isapnp.h>
+#include "isapnp.h"
#define NDEBUG
#include <debug.h>
@@ -140,14 +140,14 @@ IsaFdoCreateDeviceIDs(
static
NTSTATUS
NTAPI
-IsaFdoCreateRequirements(
- IN PISAPNP_PDO_EXTENSION PdoExt)
+IsaPnpCreateLogicalDeviceRequirements(
+ _In_ PISAPNP_PDO_EXTENSION PdoExt)
{
PISAPNP_LOGICAL_DEVICE LogDev = PdoExt->IsaPnpDevice;
- RTL_BITMAP IrqBitmap[ARRAYSIZE(LogDev->Irq)];
- RTL_BITMAP DmaBitmap[ARRAYSIZE(LogDev->Dma)];
- ULONG IrqData[ARRAYSIZE(LogDev->Irq)];
- ULONG DmaData[ARRAYSIZE(LogDev->Dma)];
+ RTL_BITMAP IrqBitmap[RTL_NUMBER_OF(LogDev->Irq)];
+ RTL_BITMAP DmaBitmap[RTL_NUMBER_OF(LogDev->Dma)];
+ ULONG IrqData[RTL_NUMBER_OF(LogDev->Irq)];
+ ULONG DmaData[RTL_NUMBER_OF(LogDev->Dma)];
ULONG ResourceCount = 0;
ULONG ListSize, i, j;
BOOLEAN FirstIrq = TRUE, FirstDma = TRUE;
@@ -155,19 +155,22 @@ IsaFdoCreateRequirements(
PIO_RESOURCE_DESCRIPTOR Descriptor;
/* Count number of requirements */
- for (i = 0; i < ARRAYSIZE(LogDev->Io); i++)
+ for (i = 0; i < RTL_NUMBER_OF(LogDev->Io); i++)
{
if (!LogDev->Io[i].Description.Length)
break;
+
ResourceCount++;
}
- for (i = 0; i < ARRAYSIZE(LogDev->Irq); i++)
+ for (i = 0; i < RTL_NUMBER_OF(LogDev->Irq); i++)
{
if (!LogDev->Irq[i].Description.Mask)
break;
+
IrqData[i] = LogDev->Irq[i].Description.Mask;
RtlInitializeBitMap(&IrqBitmap[i], &IrqData[i], 16);
ResourceCount += RtlNumberOfSetBits(&IrqBitmap[i]);
+
if (LogDev->Irq[i].Description.Information & 0x4)
{
/* Add room for level sensitive */
@@ -176,10 +179,11 @@ IsaFdoCreateRequirements(
}
if (ResourceCount == 0)
return STATUS_SUCCESS;
- for (i = 0; i < ARRAYSIZE(LogDev->Irq); i++)
+ for (i = 0; i < RTL_NUMBER_OF(LogDev->Irq); i++)
{
if (!LogDev->Dma[i].Description.Mask)
break;
+
DmaData[i] = LogDev->Dma[i].Description.Mask;
RtlInitializeBitMap(&DmaBitmap[i], &DmaData[i], 8);
ResourceCount += RtlNumberOfSetBits(&DmaBitmap[i]);
@@ -187,7 +191,7 @@ IsaFdoCreateRequirements(
/* Allocate memory to store requirements */
ListSize = sizeof(IO_RESOURCE_REQUIREMENTS_LIST)
- + ResourceCount * sizeof(IO_RESOURCE_DESCRIPTOR);
+ + ResourceCount * sizeof(IO_RESOURCE_DESCRIPTOR);
RequirementsList = ExAllocatePool(PagedPool, ListSize);
if (!RequirementsList)
return STATUS_NO_MEMORY;
@@ -203,15 +207,17 @@ IsaFdoCreateRequirements(
/* Store requirements */
Descriptor = RequirementsList->List[0].Descriptors;
- for (i = 0; i < ARRAYSIZE(LogDev->Io); i++)
+ for (i = 0; i < RTL_NUMBER_OF(LogDev->Io); i++)
{
if (!LogDev->Io[i].Description.Length)
break;
+
DPRINT("Device.Io[%d].Information = 0x%02x\n", i,
LogDev->Io[i].Description.Information);
DPRINT("Device.Io[%d].Minimum = 0x%02x\n", i,
LogDev->Io[i].Description.Minimum);
DPRINT("Device.Io[%d].Maximum = 0x%02x\n", i,
LogDev->Io[i].Description.Maximum);
DPRINT("Device.Io[%d].Alignment = 0x%02x\n", i,
LogDev->Io[i].Description.Alignment);
DPRINT("Device.Io[%d].Length = 0x%02x\n", i,
LogDev->Io[i].Description.Length);
+
Descriptor->Type = CmResourceTypePort;
Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
if (LogDev->Io[i].Description.Information & 0x1)
@@ -221,19 +227,23 @@ IsaFdoCreateRequirements(
Descriptor->u.Port.Length = LogDev->Io[i].Description.Length;
Descriptor->u.Port.Alignment = LogDev->Io[i].Description.Alignment;
Descriptor->u.Port.MinimumAddress.LowPart =
LogDev->Io[i].Description.Minimum;
- Descriptor->u.Port.MaximumAddress.LowPart =
LogDev->Io[i].Description.Maximum + LogDev->Io[i].Description.Length - 1;
+ Descriptor->u.Port.MaximumAddress.LowPart =
+ LogDev->Io[i].Description.Maximum + LogDev->Io[i].Description.Length -
1;
Descriptor++;
}
- for (i = 0; i < ARRAYSIZE(LogDev->Irq); i++)
+ for (i = 0; i < RTL_NUMBER_OF(LogDev->Irq); i++)
{
if (!LogDev->Irq[i].Description.Mask)
break;
+
DPRINT("Device.Irq[%d].Mask = 0x%02x\n", i,
LogDev->Irq[i].Description.Mask);
DPRINT("Device.Irq[%d].Information = 0x%02x\n", i,
LogDev->Irq[i].Description.Information);
+
for (j = 0; j < 15; j++)
{
if (!RtlCheckBit(&IrqBitmap[i], j))
continue;
+
if (FirstIrq)
FirstIrq = FALSE;
else
@@ -242,6 +252,7 @@ IsaFdoCreateRequirements(
Descriptor->Flags = CM_RESOURCE_INTERRUPT_LATCHED;
Descriptor->u.Interrupt.MinimumVector =
Descriptor->u.Interrupt.MaximumVector = j;
Descriptor++;
+
if (LogDev->Irq[i].Description.Information & 0x4)
{
/* Level interrupt */
@@ -253,16 +264,19 @@ IsaFdoCreateRequirements(
}
}
}
- for (i = 0; i < ARRAYSIZE(LogDev->Dma); i++)
+ for (i = 0; i < RTL_NUMBER_OF(LogDev->Dma); i++)
{
if (!LogDev->Dma[i].Description.Mask)
break;
+
DPRINT("Device.Dma[%d].Mask = 0x%02x\n", i,
LogDev->Dma[i].Description.Mask);
DPRINT("Device.Dma[%d].Information = 0x%02x\n", i,
LogDev->Dma[i].Description.Information);
+
for (j = 0; j < 8; j++)
{
if (!RtlCheckBit(&DmaBitmap[i], j))
continue;
+
if (FirstDma)
FirstDma = FALSE;
else
@@ -296,8 +310,8 @@ IsaFdoCreateRequirements(
static
NTSTATUS
NTAPI
-IsaFdoCreateResources(
- IN PISAPNP_PDO_EXTENSION PdoExt)
+IsaPnpCreateLogicalDeviceResources(
+ _In_ PISAPNP_PDO_EXTENSION PdoExt)
{
PISAPNP_LOGICAL_DEVICE LogDev = PdoExt->IsaPnpDevice;
ULONG ResourceCount = 0;
@@ -306,21 +320,21 @@ IsaFdoCreateResources(
PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor;
/* Count number of required resources */
- for (i = 0; i < ARRAYSIZE(LogDev->Io); i++)
+ for (i = 0; i < RTL_NUMBER_OF(LogDev->Io); i++)
{
if (LogDev->Io[i].CurrentBase)
ResourceCount++;
else
break;
}
- for (i = 0; i < ARRAYSIZE(LogDev->Irq); i++)
+ for (i = 0; i < RTL_NUMBER_OF(LogDev->Irq); i++)
{
if (LogDev->Irq[i].CurrentNo)
ResourceCount++;
else
break;
}
- for (i = 0; i < ARRAYSIZE(LogDev->Dma); i++)
+ for (i = 0; i < RTL_NUMBER_OF(LogDev->Dma); i++)
{
if (LogDev->Dma[i].CurrentChannel != 4)
ResourceCount++;
@@ -332,7 +346,7 @@ IsaFdoCreateResources(
/* Allocate memory to store resources */
ListSize = sizeof(CM_RESOURCE_LIST)
- + (ResourceCount - 1) * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
+ + (ResourceCount - 1) * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
ResourceList = ExAllocatePool(PagedPool, ListSize);
if (!ResourceList)
return STATUS_NO_MEMORY;
@@ -346,10 +360,11 @@ IsaFdoCreateResources(
/* Store resources */
ResourceCount = 0;
- for (i = 0; i < ARRAYSIZE(LogDev->Io); i++)
+ for (i = 0; i < RTL_NUMBER_OF(LogDev->Io); i++)
{
if (!LogDev->Io[i].CurrentBase)
continue;
+
Descriptor =
&ResourceList->List[0].PartialResourceList.PartialDescriptors[ResourceCount++];
Descriptor->Type = CmResourceTypePort;
Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
@@ -360,10 +375,11 @@ IsaFdoCreateResources(
Descriptor->u.Port.Length = LogDev->Io[i].Description.Length;
Descriptor->u.Port.Start.LowPart = LogDev->Io[i].CurrentBase;
}
- for (i = 0; i < ARRAYSIZE(LogDev->Irq); i++)
+ for (i = 0; i < RTL_NUMBER_OF(LogDev->Irq); i++)
{
if (!LogDev->Irq[i].CurrentNo)
continue;
+
Descriptor =
&ResourceList->List[0].PartialResourceList.PartialDescriptors[ResourceCount++];
Descriptor->Type = CmResourceTypeInterrupt;
Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
@@ -375,10 +391,11 @@ IsaFdoCreateResources(
Descriptor->u.Interrupt.Vector = LogDev->Irq[i].CurrentNo;
Descriptor->u.Interrupt.Affinity = -1;
}
- for (i = 0; i < ARRAYSIZE(LogDev->Dma); i++)
+ for (i = 0; i < RTL_NUMBER_OF(LogDev->Dma); i++)
{
if (LogDev->Dma[i].CurrentChannel == 4)
continue;
+
Descriptor =
&ResourceList->List[0].PartialResourceList.PartialDescriptors[ResourceCount++];
Descriptor->Type = CmResourceTypeDma;
Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
@@ -409,9 +426,9 @@ IsaFdoCreateResources(
NTSTATUS
NTAPI
IsaPnpFillDeviceRelations(
- IN PISAPNP_FDO_EXTENSION FdoExt,
- IN PIRP Irp,
- IN BOOLEAN IncludeDataPort)
+ _In_ PISAPNP_FDO_EXTENSION FdoExt,
+ _Inout_ PIRP Irp,
+ _In_ BOOLEAN IncludeDataPort)
{
PISAPNP_PDO_EXTENSION PdoExt;
NTSTATUS Status = STATUS_SUCCESS;
@@ -429,63 +446,63 @@ IsaPnpFillDeviceRelations(
if (IncludeDataPort)
{
- DeviceRelations->Objects[i++] = FdoExt->DataPortPdo;
- ObReferenceObject(FdoExt->DataPortPdo);
+ DeviceRelations->Objects[i++] = FdoExt->ReadPortPdo;
+ ObReferenceObject(FdoExt->ReadPortPdo);
}
CurrentEntry = FdoExt->DeviceListHead.Flink;
while (CurrentEntry != &FdoExt->DeviceListHead)
{
- IsaDevice = CONTAINING_RECORD(CurrentEntry, ISAPNP_LOGICAL_DEVICE, ListEntry);
+ IsaDevice = CONTAINING_RECORD(CurrentEntry, ISAPNP_LOGICAL_DEVICE, DeviceLink);
- if (!IsaDevice->Pdo)
- {
- Status = IoCreateDevice(FdoExt->DriverObject,
- sizeof(ISAPNP_PDO_EXTENSION),
- NULL,
- FILE_DEVICE_CONTROLLER,
- FILE_DEVICE_SECURE_OPEN |
FILE_AUTOGENERATED_DEVICE_NAME,
- FALSE,
- &IsaDevice->Pdo);
- if (!NT_SUCCESS(Status))
- {
- break;
- }
+ if (!IsaDevice->Pdo)
+ {
+ Status = IoCreateDevice(FdoExt->DriverObject,
+ sizeof(ISAPNP_PDO_EXTENSION),
+ NULL,
+ FILE_DEVICE_CONTROLLER,
+ FILE_DEVICE_SECURE_OPEN |
FILE_AUTOGENERATED_DEVICE_NAME,
+ FALSE,
+ &IsaDevice->Pdo);
+ if (!NT_SUCCESS(Status))
+ {
+ break;
+ }
- IsaDevice->Pdo->Flags &= ~DO_DEVICE_INITIALIZING;
+ IsaDevice->Pdo->Flags &= ~DO_DEVICE_INITIALIZING;
- //Device->Pdo->Flags |= DO_POWER_PAGABLE;
+ //Device->Pdo->Flags |= DO_POWER_PAGABLE;
- PdoExt = (PISAPNP_PDO_EXTENSION)IsaDevice->Pdo->DeviceExtension;
+ PdoExt = IsaDevice->Pdo->DeviceExtension;
- RtlZeroMemory(PdoExt, sizeof(ISAPNP_PDO_EXTENSION));
+ RtlZeroMemory(PdoExt, sizeof(ISAPNP_PDO_EXTENSION));
- PdoExt->Common.IsFdo = FALSE;
- PdoExt->Common.Self = IsaDevice->Pdo;
- PdoExt->Common.State = dsStopped;
- PdoExt->IsaPnpDevice = IsaDevice;
- PdoExt->FdoExt = FdoExt;
+ PdoExt->Common.IsFdo = FALSE;
+ PdoExt->Common.Self = IsaDevice->Pdo;
+ PdoExt->Common.State = dsStopped;
+ PdoExt->IsaPnpDevice = IsaDevice;
+ PdoExt->FdoExt = FdoExt;
- Status = IsaFdoCreateDeviceIDs(PdoExt);
+ Status = IsaFdoCreateDeviceIDs(PdoExt);
- if (NT_SUCCESS(Status))
- Status = IsaFdoCreateRequirements(PdoExt);
+ if (NT_SUCCESS(Status))
+ Status = IsaPnpCreateLogicalDeviceRequirements(PdoExt);
- if (NT_SUCCESS(Status))
- Status = IsaFdoCreateResources(PdoExt);
+ if (NT_SUCCESS(Status))
+ Status = IsaPnpCreateLogicalDeviceResources(PdoExt);
- if (!NT_SUCCESS(Status))
- {
- IoDeleteDevice(IsaDevice->Pdo);
- IsaDevice->Pdo = NULL;
- break;
- }
- }
- DeviceRelations->Objects[i++] = IsaDevice->Pdo;
+ if (!NT_SUCCESS(Status))
+ {
+ IoDeleteDevice(IsaDevice->Pdo);
+ IsaDevice->Pdo = NULL;
+ break;
+ }
+ }
+ DeviceRelations->Objects[i++] = IsaDevice->Pdo;
- ObReferenceObject(IsaDevice->Pdo);
+ ObReferenceObject(IsaDevice->Pdo);
- CurrentEntry = CurrentEntry->Flink;
+ CurrentEntry = CurrentEntry->Flink;
}
DeviceRelations->Count = i;
@@ -495,7 +512,6 @@ IsaPnpFillDeviceRelations(
return Status;
}
-
static IO_COMPLETION_ROUTINE ForwardIrpCompletion;
static
@@ -539,14 +555,16 @@ IsaForwardIrpSynchronous(
return Status;
}
+_Dispatch_type_(IRP_MJ_CREATE)
+_Dispatch_type_(IRP_MJ_CLOSE)
static DRIVER_DISPATCH IsaCreateClose;
static
NTSTATUS
NTAPI
IsaCreateClose(
- IN PDEVICE_OBJECT DeviceObject,
- IN PIRP Irp)
+ _In_ PDEVICE_OBJECT DeviceObject,
+ _Inout_ PIRP Irp)
{
Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = FILE_OPENED;
@@ -609,15 +627,16 @@ static
NTSTATUS
NTAPI
IsaPnpCreateReadPortDORequirements(
- IN PISAPNP_PDO_EXTENSION PdoExt)
+ _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;
+ const ULONG Ports[] = { ISAPNP_WRITE_DATA, ISAPNP_ADDRESS,
+ 0x274, 0x3E4, 0x204, 0x2E4, 0x354, 0x2F4 };
ListSize = sizeof(IO_RESOURCE_REQUIREMENTS_LIST)
- + 2 * ARRAYSIZE(Ports) * sizeof(IO_RESOURCE_DESCRIPTOR);
+ + 2 * RTL_NUMBER_OF(Ports) * sizeof(IO_RESOURCE_DESCRIPTOR);
RequirementsList = ExAllocatePool(PagedPool, ListSize);
if (!RequirementsList)
return STATUS_NO_MEMORY;
@@ -628,9 +647,9 @@ IsaPnpCreateReadPortDORequirements(
RequirementsList->List[0].Version = 1;
RequirementsList->List[0].Revision = 1;
- RequirementsList->List[0].Count = 2 * ARRAYSIZE(Ports);
+ RequirementsList->List[0].Count = 2 * RTL_NUMBER_OF(Ports);
- for (i = 0; i < 2 * ARRAYSIZE(Ports); i += 2)
+ for (i = 0; i < 2 * RTL_NUMBER_OF(Ports); i += 2)
{
Descriptor = &RequirementsList->List[0].Descriptors[i];
@@ -659,15 +678,15 @@ static
NTSTATUS
NTAPI
IsaPnpCreateReadPortDOResources(
- IN PISAPNP_PDO_EXTENSION PdoExt)
+ _In_ PISAPNP_PDO_EXTENSION PdoExt)
{
- USHORT Ports[] = { ISAPNP_WRITE_DATA, ISAPNP_ADDRESS };
+ const 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);
+ ListSize = sizeof(CM_RESOURCE_LIST) +
+ sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * (RTL_NUMBER_OF(Ports) - 1);
ResourceList = ExAllocatePool(PagedPool, ListSize);
if (!ResourceList)
return STATUS_NO_MEMORY;
@@ -677,9 +696,9 @@ IsaPnpCreateReadPortDOResources(
ResourceList->List[0].InterfaceType = Internal;
ResourceList->List[0].PartialResourceList.Version = 1;
ResourceList->List[0].PartialResourceList.Revision = 1;
- ResourceList->List[0].PartialResourceList.Count = 2;
+ ResourceList->List[0].PartialResourceList.Count = RTL_NUMBER_OF(Ports);
- for (i = 0; i < ARRAYSIZE(Ports); i++)
+ for (i = 0; i < RTL_NUMBER_OF(Ports); i++)
{
Descriptor =
&ResourceList->List[0].PartialResourceList.PartialDescriptors[i];
Descriptor->Type = CmResourceTypePort;
@@ -697,28 +716,30 @@ IsaPnpCreateReadPortDOResources(
static
NTSTATUS
NTAPI
-IsaPnpCreateReadPortDO(PISAPNP_FDO_EXTENSION FdoExt)
+IsaPnpCreateReadPortDO(
+ _In_ PISAPNP_FDO_EXTENSION FdoExt)
{
UNICODE_STRING DeviceID = RTL_CONSTANT_STRING(L"ISAPNP\\ReadDataPort\0");
UNICODE_STRING HardwareIDs =
RTL_CONSTANT_STRING(L"ISAPNP\\ReadDataPort\0\0");
UNICODE_STRING CompatibleIDs = RTL_CONSTANT_STRING(L"\0\0");
UNICODE_STRING InstanceID = RTL_CONSTANT_STRING(L"0\0");
PISAPNP_PDO_EXTENSION PdoExt;
-
NTSTATUS Status;
+
Status = IoCreateDevice(FdoExt->DriverObject,
sizeof(ISAPNP_PDO_EXTENSION),
NULL,
FILE_DEVICE_CONTROLLER,
FILE_DEVICE_SECURE_OPEN,
FALSE,
- &FdoExt->DataPortPdo);
+ &FdoExt->ReadPortPdo);
if (!NT_SUCCESS(Status))
return Status;
- PdoExt = (PISAPNP_PDO_EXTENSION)FdoExt->DataPortPdo->DeviceExtension;
+
+ PdoExt = FdoExt->ReadPortPdo->DeviceExtension;
RtlZeroMemory(PdoExt, sizeof(ISAPNP_PDO_EXTENSION));
PdoExt->Common.IsFdo = FALSE;
- PdoExt->Common.Self = FdoExt->DataPortPdo;
+ PdoExt->Common.Self = FdoExt->ReadPortPdo;
PdoExt->Common.State = dsStopped;
PdoExt->FdoExt = FdoExt;
@@ -761,8 +782,8 @@ static
NTSTATUS
NTAPI
IsaAddDevice(
- IN PDRIVER_OBJECT DriverObject,
- IN PDEVICE_OBJECT PhysicalDeviceObject)
+ _In_ PDRIVER_OBJECT DriverObject,
+ _In_ PDEVICE_OBJECT PhysicalDeviceObject)
{
PDEVICE_OBJECT Fdo;
PISAPNP_FDO_EXTENSION FdoExt;
@@ -779,7 +800,7 @@ IsaAddDevice(
&Fdo);
if (!NT_SUCCESS(Status))
{
- DPRINT1("Failed to create FDO (0x%x)\n", Status);
+ DPRINT1("Failed to create FDO (0x%08lx)\n", Status);
return Status;
}
@@ -802,17 +823,19 @@ IsaAddDevice(
return Status;
Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
- FdoExt->DataPortPdo->Flags &= ~DO_DEVICE_INITIALIZING;
+ FdoExt->ReadPortPdo->Flags &= ~DO_DEVICE_INITIALIZING;
return STATUS_SUCCESS;
}
+_Dispatch_type_(IRP_MJ_POWER)
DRIVER_DISPATCH IsaPower;
+
NTSTATUS
NTAPI
IsaPower(
- IN PDEVICE_OBJECT DeviceObject,
- IN PIRP Irp)
+ _In_ PDEVICE_OBJECT DeviceObject,
+ _Inout_ PIRP Irp)
{
PISAPNP_COMMON_EXTENSION DevExt = DeviceObject->DeviceExtension;
NTSTATUS Status;
@@ -829,14 +852,15 @@ IsaPower(
return PoCallDriver(((PISAPNP_FDO_EXTENSION)DevExt)->Ldo, Irp);
}
+_Dispatch_type_(IRP_MJ_PNP)
static DRIVER_DISPATCH IsaPnp;
static
NTSTATUS
NTAPI
IsaPnp(
- IN PDEVICE_OBJECT DeviceObject,
- IN PIRP Irp)
+ _In_ PDEVICE_OBJECT DeviceObject,
+ _Inout_ PIRP Irp)
{
PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
PISAPNP_COMMON_EXTENSION DevExt = DeviceObject->DeviceExtension;
@@ -844,24 +868,16 @@ IsaPnp(
DPRINT("%s(%p, %p)\n", __FUNCTION__, DeviceObject, Irp);
if (DevExt->IsFdo)
- {
- return IsaFdoPnp((PISAPNP_FDO_EXTENSION)DevExt,
- Irp,
- IrpSp);
- }
+ return IsaFdoPnp((PISAPNP_FDO_EXTENSION)DevExt, Irp, IrpSp);
else
- {
- return IsaPdoPnp((PISAPNP_PDO_EXTENSION)DevExt,
- Irp,
- IrpSp);
- }
+ return IsaPdoPnp((PISAPNP_PDO_EXTENSION)DevExt, Irp, IrpSp);
}
NTSTATUS
NTAPI
DriverEntry(
- IN PDRIVER_OBJECT DriverObject,
- IN PUNICODE_STRING RegistryPath)
+ _In_ PDRIVER_OBJECT DriverObject,
+ _In_ PUNICODE_STRING RegistryPath)
{
DPRINT("%s(%p, %wZ)\n", __FUNCTION__, DriverObject, RegistryPath);
diff --git a/drivers/bus/isapnp/isapnp.h b/drivers/bus/isapnp/isapnp.h
index ed1d81b4bc9..9d339f2f0d4 100644
--- a/drivers/bus/isapnp/isapnp.h
+++ b/drivers/bus/isapnp/isapnp.h
@@ -1,9 +1,17 @@
+/*
+ * PROJECT: ReactOS ISA PnP Bus driver
+ * LICENSE: GPL-2.0-or-later (
https://spdx.org/licenses/GPL-2.0-or-later)
+ * PURPOSE: Common header file
+ * COPYRIGHT: Copyright 2010 Cameron Gutman <cameron.gutman(a)reactos.org>
+ * Copyright 2020 Hervé Poussineau <hpoussin(a)reactos.org>
+ */
+
#ifndef _ISAPNP_PCH_
#define _ISAPNP_PCH_
#include <wdm.h>
#include <ntstrsafe.h>
-#include <isapnphw.h>
+#include "isapnphw.h"
#ifdef __cplusplus
extern "C" {
@@ -11,28 +19,33 @@ extern "C" {
#define TAG_ISAPNP 'PNPI'
-typedef enum {
+typedef enum
+{
dsStopped,
dsStarted
} ISAPNP_DEVICE_STATE;
-typedef struct _ISAPNP_IO {
+typedef struct _ISAPNP_IO
+{
USHORT CurrentBase;
ISAPNP_IO_DESCRIPTION Description;
-} ISAPNP_IO, PISAPNP_IO;
+} ISAPNP_IO, *PISAPNP_IO;
-typedef struct _ISAPNP_IRQ {
+typedef struct _ISAPNP_IRQ
+{
UCHAR CurrentNo;
UCHAR CurrentType;
ISAPNP_IRQ_DESCRIPTION Description;
} ISAPNP_IRQ, *PISAPNP_IRQ;
-typedef struct _ISAPNP_DMA {
+typedef struct _ISAPNP_DMA
+{
UCHAR CurrentChannel;
ISAPNP_DMA_DESCRIPTION Description;
} ISAPNP_DMA, *PISAPNP_DMA;
-typedef struct _ISAPNP_LOGICAL_DEVICE {
+typedef struct _ISAPNP_LOGICAL_DEVICE
+{
PDEVICE_OBJECT Pdo;
ISAPNP_LOGDEVID LogDevId;
UCHAR VendorId[3];
@@ -43,20 +56,22 @@ typedef struct _ISAPNP_LOGICAL_DEVICE {
ISAPNP_DMA Dma[2];
UCHAR CSN;
UCHAR LDN;
- LIST_ENTRY ListEntry;
+ LIST_ENTRY DeviceLink;
} ISAPNP_LOGICAL_DEVICE, *PISAPNP_LOGICAL_DEVICE;
-typedef struct _ISAPNP_COMMON_EXTENSION {
+typedef struct _ISAPNP_COMMON_EXTENSION
+{
PDEVICE_OBJECT Self;
BOOLEAN IsFdo;
ISAPNP_DEVICE_STATE State;
} ISAPNP_COMMON_EXTENSION, *PISAPNP_COMMON_EXTENSION;
-typedef struct _ISAPNP_FDO_EXTENSION {
+typedef struct _ISAPNP_FDO_EXTENSION
+{
ISAPNP_COMMON_EXTENSION Common;
PDEVICE_OBJECT Ldo;
PDEVICE_OBJECT Pdo;
- PDEVICE_OBJECT DataPortPdo;
+ PDEVICE_OBJECT ReadPortPdo;
LIST_ENTRY DeviceListHead;
ULONG DeviceCount;
PDRIVER_OBJECT DriverObject;
@@ -64,7 +79,8 @@ typedef struct _ISAPNP_FDO_EXTENSION {
KSPIN_LOCK Lock;
} ISAPNP_FDO_EXTENSION, *PISAPNP_FDO_EXTENSION;
-typedef struct _ISAPNP_PDO_EXTENSION {
+typedef struct _ISAPNP_PDO_EXTENSION
+{
ISAPNP_COMMON_EXTENSION Common;
PISAPNP_LOGICAL_DEVICE IsaPnpDevice;
PISAPNP_FDO_EXTENSION FdoExt;
@@ -92,60 +108,54 @@ IsaPnpDuplicateUnicodeString(
NTSTATUS
NTAPI
IsaPnpFillDeviceRelations(
- IN PISAPNP_FDO_EXTENSION FdoExt,
- IN PIRP Irp,
- IN BOOLEAN IncludeDataPort);
+ _In_ PISAPNP_FDO_EXTENSION FdoExt,
+ _Inout_ PIRP Irp,
+ _In_ BOOLEAN IncludeDataPort);
DRIVER_INITIALIZE DriverEntry;
-NTSTATUS
-NTAPI
-DriverEntry(
- IN PDRIVER_OBJECT DriverObject,
- IN PUNICODE_STRING RegistryPath);
-
NTSTATUS
NTAPI
IsaForwardIrpSynchronous(
- IN PISAPNP_FDO_EXTENSION FdoExt,
- IN PIRP Irp);
+ _In_ PISAPNP_FDO_EXTENSION FdoExt,
+ _Inout_ PIRP Irp);
/* fdo.c */
NTSTATUS
NTAPI
IsaFdoPnp(
- IN PISAPNP_FDO_EXTENSION FdoExt,
- IN PIRP Irp,
- IN PIO_STACK_LOCATION IrpSp);
+ _In_ PISAPNP_FDO_EXTENSION FdoExt,
+ _Inout_ PIRP Irp,
+ _In_ PIO_STACK_LOCATION IrpSp);
/* pdo.c */
NTSTATUS
NTAPI
IsaPdoPnp(
- IN PISAPNP_PDO_EXTENSION PdoDeviceExtension,
- IN PIRP Irp,
- IN PIO_STACK_LOCATION IrpSp);
+ _In_ PISAPNP_PDO_EXTENSION PdoDeviceExtension,
+ _Inout_ PIRP Irp,
+ _In_ PIO_STACK_LOCATION IrpSp);
/* hardware.c */
NTSTATUS
NTAPI
IsaHwTryReadDataPort(
- IN PUCHAR ReadDataPort);
+ _In_ PUCHAR ReadDataPort);
NTSTATUS
NTAPI
IsaHwFillDeviceList(
- IN PISAPNP_FDO_EXTENSION FdoExt);
+ _In_ PISAPNP_FDO_EXTENSION FdoExt);
NTSTATUS
NTAPI
IsaHwDeactivateDevice(
- IN PISAPNP_LOGICAL_DEVICE LogicalDevice);
+ _In_ PISAPNP_LOGICAL_DEVICE LogicalDevice);
NTSTATUS
NTAPI
IsaHwActivateDevice(
- IN PISAPNP_LOGICAL_DEVICE LogicalDevice);
+ _In_ PISAPNP_LOGICAL_DEVICE LogicalDevice);
#ifdef __cplusplus
}
diff --git a/drivers/bus/isapnp/isapnphw.h b/drivers/bus/isapnp/isapnphw.h
index 9f1cc0c9cab..cc33c320683 100644
--- a/drivers/bus/isapnp/isapnphw.h
+++ b/drivers/bus/isapnp/isapnphw.h
@@ -1,3 +1,11 @@
+/*
+ * PROJECT: ReactOS ISA PnP Bus driver
+ * LICENSE: GPL-2.0-or-later (
https://spdx.org/licenses/GPL-2.0-or-later)
+ * PURPOSE: Hardware definitions
+ * COPYRIGHT: Copyright 2010 Cameron Gutman <cameron.gutman(a)reactos.org>
+ * Copyright 2020 Hervé Poussineau <hpoussin(a)reactos.org>
+ */
+
#pragma once
#ifdef __cplusplus
@@ -83,20 +91,23 @@ extern "C" {
#define ISAPNP_TAG_RSVDLONGF 0xFF
#define ISAPNP_TAG_PSEUDO_NEWBOARD 0x100
-typedef struct _ISAPNP_IDENTIFIER {
+typedef struct _ISAPNP_IDENTIFIER
+{
USHORT VendorId;
USHORT ProdId;
ULONG Serial;
UCHAR Checksum;
} ISAPNP_IDENTIFIER, *PISAPNP_IDENTIFIER;
-typedef struct _ISAPNP_LOGDEVID {
+typedef struct _ISAPNP_LOGDEVID
+{
USHORT VendorId;
USHORT ProdId;
USHORT Flags;
} ISAPNP_LOGDEVID, *PISAPNP_LOGDEVID;
-typedef struct _ISAPNP_DEVICEID {
+typedef struct _ISAPNP_DEVICEID
+{
CHAR* Name;
USHORT VendorId;
USHORT ProdId;
@@ -104,23 +115,26 @@ typedef struct _ISAPNP_DEVICEID {
#include <pshpack1.h>
-typedef struct _ISAPNP_IO_DESCRIPTION {
+typedef struct _ISAPNP_IO_DESCRIPTION
+{
UCHAR Information;
USHORT Minimum;
USHORT Maximum;
UCHAR Alignment;
UCHAR Length;
-} ISAPNP_IO_DESCRIPTION;
+} ISAPNP_IO_DESCRIPTION, *PISAPNP_IO_DESCRIPTION;
-typedef struct _ISAPNP_IRQ_DESCRIPTION {
+typedef struct _ISAPNP_IRQ_DESCRIPTION
+{
USHORT Mask;
UCHAR Information;
-} ISAPNP_IRQ_DESCRIPTION;
+} ISAPNP_IRQ_DESCRIPTION, *PISAPNP_IRQ_DESCRIPTION;
-typedef struct _ISAPNP_DMA_DESCRIPTION {
+typedef struct _ISAPNP_DMA_DESCRIPTION
+{
UCHAR Mask;
UCHAR Information;
-} ISAPNP_DMA_DESCRIPTION;
+} ISAPNP_DMA_DESCRIPTION, *PISAPNP_DMA_DESCRIPTION;
#include <poppack.h>
diff --git a/drivers/bus/isapnp/pdo.c b/drivers/bus/isapnp/pdo.c
index 36ba611e131..c8a86ed76f0 100644
--- a/drivers/bus/isapnp/pdo.c
+++ b/drivers/bus/isapnp/pdo.c
@@ -1,12 +1,12 @@
/*
* PROJECT: ReactOS ISA PnP Bus driver
- * FILE: pdo.c
+ * LICENSE: GPL-2.0-or-later (
https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: PDO-specific code
- * PROGRAMMERS: Cameron Gutman (cameron.gutman(a)reactos.org)
- * Hervé Poussineau
+ * COPYRIGHT: Copyright 2010 Cameron Gutman <cameron.gutman(a)reactos.org>
+ * Copyright 2020 Hervé Poussineau <hpoussin(a)reactos.org>
*/
-#include <isapnp.h>
+#include "isapnp.h"
#define NDEBUG
#include <debug.h>
@@ -14,14 +14,14 @@
NTSTATUS
NTAPI
IsaPdoQueryDeviceRelations(
- IN PISAPNP_PDO_EXTENSION PdoExt,
- IN PIRP Irp,
- IN PIO_STACK_LOCATION IrpSp)
+ _In_ PISAPNP_PDO_EXTENSION PdoExt,
+ _Inout_ PIRP Irp,
+ _In_ PIO_STACK_LOCATION IrpSp)
{
PDEVICE_RELATIONS DeviceRelations;
if (IrpSp->Parameters.QueryDeviceRelations.Type == RemovalRelations &&
- PdoExt->Common.Self == PdoExt->FdoExt->DataPortPdo)
+ PdoExt->Common.Self == PdoExt->FdoExt->ReadPortPdo)
{
return IsaPnpFillDeviceRelations(PdoExt->FdoExt, Irp, FALSE);
}
@@ -38,16 +38,15 @@ IsaPdoQueryDeviceRelations(
ObReferenceObject(PdoExt->Common.Self);
Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations;
-
return STATUS_SUCCESS;
}
NTSTATUS
NTAPI
IsaPdoQueryCapabilities(
- IN PISAPNP_PDO_EXTENSION PdoExt,
- IN PIRP Irp,
- IN PIO_STACK_LOCATION IrpSp)
+ _In_ PISAPNP_PDO_EXTENSION PdoExt,
+ _Inout_ PIRP Irp,
+ _In_ PIO_STACK_LOCATION IrpSp)
{
PDEVICE_CAPABILITIES DeviceCapabilities;
PISAPNP_LOGICAL_DEVICE LogDev = PdoExt->IsaPnpDevice;
@@ -79,9 +78,9 @@ IsaPdoQueryCapabilities(
NTSTATUS
NTAPI
IsaPdoQueryPnpDeviceState(
- IN PISAPNP_PDO_EXTENSION PdoExt,
- IN PIRP Irp,
- IN PIO_STACK_LOCATION IrpSp)
+ _In_ PISAPNP_PDO_EXTENSION PdoExt,
+ _Inout_ PIRP Irp,
+ _In_ PIO_STACK_LOCATION IrpSp)
{
Irp->IoStatus.Information |= PNP_DEVICE_NOT_DISABLEABLE;
return STATUS_SUCCESS;
@@ -90,9 +89,9 @@ IsaPdoQueryPnpDeviceState(
NTSTATUS
NTAPI
IsaPdoQueryId(
- IN PISAPNP_PDO_EXTENSION PdoExt,
- IN PIRP Irp,
- IN PIO_STACK_LOCATION IrpSp)
+ _In_ PISAPNP_PDO_EXTENSION PdoExt,
+ _Inout_ PIRP Irp,
+ _In_ PIO_STACK_LOCATION IrpSp)
{
PUNICODE_STRING Source;
PWCHAR Buffer;
@@ -140,9 +139,9 @@ IsaPdoQueryId(
NTSTATUS
NTAPI
IsaPdoQueryResources(
- IN PISAPNP_PDO_EXTENSION PdoExt,
- IN PIRP Irp,
- IN PIO_STACK_LOCATION IrpSp)
+ _In_ PISAPNP_PDO_EXTENSION PdoExt,
+ _Inout_ PIRP Irp,
+ _In_ PIO_STACK_LOCATION IrpSp)
{
ULONG ListSize;
PCM_RESOURCE_LIST ResourceList;
@@ -163,9 +162,9 @@ IsaPdoQueryResources(
NTSTATUS
NTAPI
IsaPdoQueryResourceRequirements(
- IN PISAPNP_PDO_EXTENSION PdoExt,
- IN PIRP Irp,
- IN PIO_STACK_LOCATION IrpSp)
+ _In_ PISAPNP_PDO_EXTENSION PdoExt,
+ _Inout_ PIRP Irp,
+ _In_ PIO_STACK_LOCATION IrpSp)
{
ULONG ListSize;
PIO_RESOURCE_REQUIREMENTS_LIST RequirementsList;
@@ -187,8 +186,8 @@ static
NTSTATUS
NTAPI
IsaPdoStartReadPort(
- IN PISAPNP_FDO_EXTENSION FdoExt,
- IN PIO_STACK_LOCATION IrpSp)
+ _In_ PISAPNP_FDO_EXTENSION FdoExt,
+ _In_ PIO_STACK_LOCATION IrpSp)
{
PCM_RESOURCE_LIST ResourceList =
IrpSp->Parameters.StartDevice.AllocatedResources;
NTSTATUS Status = STATUS_INSUFFICIENT_RESOURCES;
@@ -197,24 +196,32 @@ IsaPdoStartReadPort(
if (!ResourceList || ResourceList->Count != 1)
{
- DPRINT1("No resource list (%p) or bad count (%d)\n", ResourceList,
ResourceList ? ResourceList->Count : 0);
+ DPRINT1("No resource list (%p) or bad count (%d)\n",
+ ResourceList, ResourceList ? ResourceList->Count : 0);
return STATUS_INSUFFICIENT_RESOURCES;
}
- if (ResourceList->List[0].PartialResourceList.Version != 1
- || ResourceList->List[0].PartialResourceList.Revision != 1)
+
+ if (ResourceList->List[0].PartialResourceList.Version != 1 ||
+ ResourceList->List[0].PartialResourceList.Revision != 1)
{
- DPRINT1("Bad resource list version (%d.%d)\n",
ResourceList->List[0].PartialResourceList.Version,
ResourceList->List[0].PartialResourceList.Revision);
+ DPRINT1("Bad resource list version (%u.%u)\n",
+ ResourceList->List[0].PartialResourceList.Version,
+ ResourceList->List[0].PartialResourceList.Revision);
return STATUS_REVISION_MISMATCH;
}
+
for (i = 0; i < ResourceList->List[0].PartialResourceList.Count; i++)
{
- PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor =
&ResourceList->List[0].PartialResourceList.PartialDescriptors[i];
- if (PartialDescriptor->Type == CmResourceTypePort &&
PartialDescriptor->u.Port.Length > 1 && !FdoExt->ReadDataPort)
+ PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor =
+ &ResourceList->List[0].PartialResourceList.PartialDescriptors[i];
+
+ if (PartialDescriptor->Type == CmResourceTypePort &&
+ PartialDescriptor->u.Port.Length > 1 &&
!FdoExt->ReadDataPort)
{
PUCHAR ReadDataPort = ULongToPtr(PartialDescriptor->u.Port.Start.u.LowPart
+ 3);
if (NT_SUCCESS(IsaHwTryReadDataPort(ReadDataPort)))
{
- /* we detected some ISAPNP cards */
+ /* We detected some ISAPNP cards */
FdoExt->ReadDataPort = ReadDataPort;
KeAcquireSpinLock(&FdoExt->Lock, &OldIrql);
Status = IsaHwFillDeviceList(FdoExt);
@@ -222,16 +229,17 @@ IsaPdoStartReadPort(
if (FdoExt->DeviceCount > 0)
{
IoInvalidateDeviceRelations(FdoExt->Pdo, BusRelations);
- IoInvalidateDeviceRelations(FdoExt->DataPortPdo,
RemovalRelations);
+ IoInvalidateDeviceRelations(FdoExt->ReadPortPdo,
RemovalRelations);
}
}
else
{
- /* mark read data port as started, even if no card has been detected */
+ /* Mark read data port as started, even if no card has been detected */
Status = STATUS_SUCCESS;
}
}
}
+
return Status;
}
@@ -239,8 +247,8 @@ static
NTSTATUS
NTAPI
IsaPdoOnRepeaterComplete(
- IN PDEVICE_OBJECT Tdo,
- IN PIRP SubIrp,
+ PDEVICE_OBJECT Tdo,
+ PIRP SubIrp,
PVOID NeedsVote)
{
PIO_STACK_LOCATION SubStack = IoGetCurrentIrpStackLocation(SubIrp);
@@ -267,13 +275,12 @@ IsaPdoOnRepeaterComplete(
NTSTATUS
NTAPI
IsaPdoRepeatRequest(
- IN PISAPNP_PDO_EXTENSION PdoExt,
- IN PIRP Irp,
- IN BOOLEAN NeedsVote)
+ _In_ PISAPNP_PDO_EXTENSION PdoExt,
+ _In_ PIRP Irp,
+ _In_ BOOLEAN NeedsVote)
{
PDEVICE_OBJECT Fdo = PdoExt->FdoExt->Common.Self;
PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
-
PDEVICE_OBJECT Tdo = IoGetAttachedDeviceReference(Fdo);
PIRP SubIrp = IoAllocateIrp(Tdo->StackSize + 1, FALSE);
PIO_STACK_LOCATION SubStack = IoGetNextIrpStackLocation(SubIrp);
@@ -290,15 +297,16 @@ IsaPdoRepeatRequest(
SubIrp->IoStatus.Status = STATUS_NOT_SUPPORTED;
IoMarkIrpPending(Irp);
IoCallDriver(Tdo, SubIrp);
+
return STATUS_PENDING;
}
NTSTATUS
NTAPI
IsaPdoPnp(
- IN PISAPNP_PDO_EXTENSION PdoExt,
- IN PIRP Irp,
- IN PIO_STACK_LOCATION IrpSp)
+ _In_ PISAPNP_PDO_EXTENSION PdoExt,
+ _Inout_ PIRP Irp,
+ _In_ PIO_STACK_LOCATION IrpSp)
{
NTSTATUS Status = Irp->IoStatus.Status;
@@ -333,7 +341,7 @@ IsaPdoPnp(
break;
case IRP_MN_QUERY_PNP_DEVICE_STATE:
- if (PdoExt->Common.Self == PdoExt->FdoExt->DataPortPdo)
+ if (PdoExt->Common.Self == PdoExt->FdoExt->ReadPortPdo)
Status = IsaPdoQueryPnpDeviceState(PdoExt, Irp, IrpSp);
break;