[ISAPNP] Reformat files. No code change.

This commit is contained in:
Hervé Poussineau 2020-03-20 19:19:30 +01:00
parent a8dbe6805a
commit 947b49aac3
6 changed files with 725 additions and 688 deletions

View file

@ -13,156 +13,156 @@
NTSTATUS
NTAPI
IsaFdoStartDevice(
IN PISAPNP_FDO_EXTENSION FdoExt,
IN PIRP Irp,
IN PIO_STACK_LOCATION IrpSp)
IN PISAPNP_FDO_EXTENSION FdoExt,
IN PIRP Irp,
IN PIO_STACK_LOCATION IrpSp)
{
NTSTATUS Status;
KIRQL OldIrql;
NTSTATUS Status;
KIRQL OldIrql;
UNREFERENCED_PARAMETER(Irp);
UNREFERENCED_PARAMETER(IrpSp);
UNREFERENCED_PARAMETER(Irp);
UNREFERENCED_PARAMETER(IrpSp);
KeAcquireSpinLock(&FdoExt->Lock, &OldIrql);
Status = IsaHwDetectReadDataPort(FdoExt);
KeReleaseSpinLock(&FdoExt->Lock, OldIrql);
KeAcquireSpinLock(&FdoExt->Lock, &OldIrql);
Status = IsaHwDetectReadDataPort(FdoExt);
KeReleaseSpinLock(&FdoExt->Lock, OldIrql);
if (!NT_SUCCESS(Status))
{
return Status;
}
if (!NT_SUCCESS(Status))
{
return Status;
}
FdoExt->Common.State = dsStarted;
FdoExt->Common.State = dsStarted;
return STATUS_SUCCESS;
return STATUS_SUCCESS;
}
NTSTATUS
NTAPI
IsaFdoQueryDeviceRelations(
IN PISAPNP_FDO_EXTENSION FdoExt,
IN PIRP Irp,
IN PIO_STACK_LOCATION IrpSp)
IN PISAPNP_FDO_EXTENSION FdoExt,
IN PIRP Irp,
IN PIO_STACK_LOCATION IrpSp)
{
PISAPNP_PDO_EXTENSION PdoExt;
NTSTATUS Status;
PLIST_ENTRY CurrentEntry;
PISAPNP_LOGICAL_DEVICE IsaDevice;
PDEVICE_RELATIONS DeviceRelations;
KIRQL OldIrql;
ULONG i = 0;
PISAPNP_PDO_EXTENSION PdoExt;
NTSTATUS Status;
PLIST_ENTRY CurrentEntry;
PISAPNP_LOGICAL_DEVICE IsaDevice;
PDEVICE_RELATIONS DeviceRelations;
KIRQL OldIrql;
ULONG i = 0;
if (IrpSp->Parameters.QueryDeviceRelations.Type != BusRelations)
return Irp->IoStatus.Status;
if (IrpSp->Parameters.QueryDeviceRelations.Type != BusRelations)
return Irp->IoStatus.Status;
KeAcquireSpinLock(&FdoExt->Lock, &OldIrql);
Status = IsaHwFillDeviceList(FdoExt);
KeReleaseSpinLock(&FdoExt->Lock, OldIrql);
KeAcquireSpinLock(&FdoExt->Lock, &OldIrql);
Status = IsaHwFillDeviceList(FdoExt);
KeReleaseSpinLock(&FdoExt->Lock, OldIrql);
if (!NT_SUCCESS(Status))
{
return Status;
}
if (!NT_SUCCESS(Status))
{
return Status;
}
DeviceRelations = ExAllocatePool(NonPagedPool,
sizeof(DEVICE_RELATIONS) + sizeof(DEVICE_OBJECT) * (FdoExt->DeviceCount - 1));
if (!DeviceRelations)
{
return STATUS_NO_MEMORY;
}
DeviceRelations = ExAllocatePool(NonPagedPool,
sizeof(DEVICE_RELATIONS) + sizeof(DEVICE_OBJECT) * (FdoExt->DeviceCount - 1));
if (!DeviceRelations)
{
return STATUS_NO_MEMORY;
}
CurrentEntry = FdoExt->DeviceListHead.Flink;
while (CurrentEntry != &FdoExt->DeviceListHead)
{
IsaDevice = CONTAINING_RECORD(CurrentEntry, ISAPNP_LOGICAL_DEVICE, ListEntry);
CurrentEntry = FdoExt->DeviceListHead.Flink;
while (CurrentEntry != &FdoExt->DeviceListHead)
{
IsaDevice = CONTAINING_RECORD(CurrentEntry, ISAPNP_LOGICAL_DEVICE, ListEntry);
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 = (PISAPNP_PDO_EXTENSION)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;
}
DeviceRelations->Objects[i++] = IsaDevice->Pdo;
PdoExt->Common.IsFdo = FALSE;
PdoExt->Common.Self = IsaDevice->Pdo;
PdoExt->Common.State = dsStopped;
PdoExt->IsaPnpDevice = IsaDevice;
}
DeviceRelations->Objects[i++] = IsaDevice->Pdo;
ObReferenceObject(IsaDevice->Pdo);
ObReferenceObject(IsaDevice->Pdo);
CurrentEntry = CurrentEntry->Flink;
}
CurrentEntry = CurrentEntry->Flink;
}
DeviceRelations->Count = FdoExt->DeviceCount;
DeviceRelations->Count = FdoExt->DeviceCount;
Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations;
Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations;
return STATUS_SUCCESS;
return STATUS_SUCCESS;
}
NTSTATUS
NTAPI
IsaFdoPnp(
IN PISAPNP_FDO_EXTENSION FdoExt,
IN PIRP Irp,
IN PIO_STACK_LOCATION IrpSp)
IN PISAPNP_FDO_EXTENSION FdoExt,
IN PIRP Irp,
IN PIO_STACK_LOCATION IrpSp)
{
NTSTATUS Status = Irp->IoStatus.Status;
NTSTATUS Status = Irp->IoStatus.Status;
switch (IrpSp->MinorFunction)
{
case IRP_MN_START_DEVICE:
Status = IsaForwardIrpSynchronous(FdoExt, Irp);
switch (IrpSp->MinorFunction)
{
case IRP_MN_START_DEVICE:
Status = IsaForwardIrpSynchronous(FdoExt, Irp);
if (NT_SUCCESS(Status))
Status = IsaFdoStartDevice(FdoExt, Irp, IrpSp);
if (NT_SUCCESS(Status))
Status = IsaFdoStartDevice(FdoExt, Irp, IrpSp);
Irp->IoStatus.Status = Status;
Irp->IoStatus.Status = Status;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return Status;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return Status;
case IRP_MN_STOP_DEVICE:
FdoExt->Common.State = dsStopped;
case IRP_MN_STOP_DEVICE:
FdoExt->Common.State = dsStopped;
Status = STATUS_SUCCESS;
break;
Status = STATUS_SUCCESS;
break;
case IRP_MN_QUERY_DEVICE_RELATIONS:
Status = IsaFdoQueryDeviceRelations(FdoExt, Irp, IrpSp);
case IRP_MN_QUERY_DEVICE_RELATIONS:
Status = IsaFdoQueryDeviceRelations(FdoExt, Irp, IrpSp);
Irp->IoStatus.Status = Status;
Irp->IoStatus.Status = Status;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return Status;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return Status;
case IRP_MN_FILTER_RESOURCE_REQUIREMENTS:
DPRINT("IRP_MN_FILTER_RESOURCE_REQUIREMENTS\n");
break;
case IRP_MN_FILTER_RESOURCE_REQUIREMENTS:
DPRINT("IRP_MN_FILTER_RESOURCE_REQUIREMENTS\n");
break;
default:
DPRINT1("Unknown PnP code: %x\n", IrpSp->MinorFunction);
break;
}
default:
DPRINT1("Unknown PnP code: %x\n", IrpSp->MinorFunction);
break;
}
IoSkipCurrentIrpStackLocation(Irp);
IoSkipCurrentIrpStackLocation(Irp);
return IoCallDriver(FdoExt->Ldo, Irp);
return IoCallDriver(FdoExt->Ldo, Irp);
}

View file

@ -14,60 +14,70 @@
static
inline
VOID
WriteAddress(USHORT Address)
WriteAddress(
IN USHORT Address)
{
WRITE_PORT_UCHAR((PUCHAR)ISAPNP_ADDRESS, Address);
WRITE_PORT_UCHAR((PUCHAR)ISAPNP_ADDRESS, Address);
}
static
inline
VOID
WriteData(USHORT Data)
WriteData(
IN USHORT Data)
{
WRITE_PORT_UCHAR((PUCHAR)ISAPNP_WRITE_DATA, Data);
WRITE_PORT_UCHAR((PUCHAR)ISAPNP_WRITE_DATA, Data);
}
static
inline
UCHAR
ReadData(PUCHAR ReadDataPort)
ReadData(
IN PUCHAR ReadDataPort)
{
return READ_PORT_UCHAR(ReadDataPort);
return READ_PORT_UCHAR(ReadDataPort);
}
static
inline
VOID
WriteByte(USHORT Address, USHORT Value)
WriteByte(
IN USHORT Address,
IN USHORT Value)
{
WriteAddress(Address);
WriteData(Value);
WriteAddress(Address);
WriteData(Value);
}
static
inline
UCHAR
ReadByte(PUCHAR ReadDataPort, USHORT Address)
ReadByte(
IN PUCHAR ReadDataPort,
IN USHORT Address)
{
WriteAddress(Address);
return ReadData(ReadDataPort);
WriteAddress(Address);
return ReadData(ReadDataPort);
}
static
inline
USHORT
ReadWord(PUCHAR ReadDataPort, USHORT Address)
ReadWord(
IN PUCHAR ReadDataPort,
IN USHORT Address)
{
return ((ReadByte(ReadDataPort, Address) << 8) |
(ReadByte(ReadDataPort, Address + 1)));
return ((ReadByte(ReadDataPort, Address) << 8) |
(ReadByte(ReadDataPort, Address + 1)));
}
static
inline
VOID
SetReadDataPort(PUCHAR ReadDataPort)
SetReadDataPort(
IN PUCHAR ReadDataPort)
{
WriteByte(ISAPNP_READPORT, ((ULONG_PTR)ReadDataPort >> 2));
WriteByte(ISAPNP_READPORT, ((ULONG_PTR)ReadDataPort >> 2));
}
static
@ -75,7 +85,7 @@ inline
VOID
EnterIsolationState(VOID)
{
WriteAddress(ISAPNP_SERIALISOLATION);
WriteAddress(ISAPNP_SERIALISOLATION);
}
static
@ -83,7 +93,7 @@ inline
VOID
WaitForKey(VOID)
{
WriteByte(ISAPNP_CONFIGCONTROL, ISAPNP_CONFIG_WAIT_FOR_KEY);
WriteByte(ISAPNP_CONFIGCONTROL, ISAPNP_CONFIG_WAIT_FOR_KEY);
}
static
@ -91,81 +101,92 @@ inline
VOID
ResetCsn(VOID)
{
WriteByte(ISAPNP_CONFIGCONTROL, ISAPNP_CONFIG_RESET_CSN);
WriteByte(ISAPNP_CONFIGCONTROL, ISAPNP_CONFIG_RESET_CSN);
}
static
inline
VOID
Wake(USHORT Csn)
Wake(
IN USHORT Csn)
{
WriteByte(ISAPNP_WAKE, Csn);
WriteByte(ISAPNP_WAKE, Csn);
}
static
inline
USHORT
ReadResourceData(PUCHAR ReadDataPort)
ReadResourceData(
IN PUCHAR ReadDataPort)
{
return ReadByte(ReadDataPort, ISAPNP_RESOURCEDATA);
return ReadByte(ReadDataPort, ISAPNP_RESOURCEDATA);
}
static
inline
USHORT
ReadStatus(PUCHAR ReadDataPort)
ReadStatus(
IN PUCHAR ReadDataPort)
{
return ReadByte(ReadDataPort, ISAPNP_STATUS);
return ReadByte(ReadDataPort, ISAPNP_STATUS);
}
static
inline
VOID
WriteCsn(USHORT Csn)
WriteCsn(
IN USHORT Csn)
{
WriteByte(ISAPNP_CARDSELECTNUMBER, Csn);
WriteByte(ISAPNP_CARDSELECTNUMBER, Csn);
}
static
inline
VOID
WriteLogicalDeviceNumber(USHORT LogDev)
WriteLogicalDeviceNumber(
IN USHORT LogDev)
{
WriteByte(ISAPNP_LOGICALDEVICENUMBER, LogDev);
WriteByte(ISAPNP_LOGICALDEVICENUMBER, LogDev);
}
static
inline
VOID
ActivateDevice(USHORT LogDev)
ActivateDevice(
IN USHORT LogDev)
{
WriteLogicalDeviceNumber(LogDev);
WriteByte(ISAPNP_ACTIVATE, 1);
WriteLogicalDeviceNumber(LogDev);
WriteByte(ISAPNP_ACTIVATE, 1);
}
static
inline
VOID
DeactivateDevice(USHORT LogDev)
DeactivateDevice(
IN USHORT LogDev)
{
WriteLogicalDeviceNumber(LogDev);
WriteByte(ISAPNP_ACTIVATE, 0);
WriteLogicalDeviceNumber(LogDev);
WriteByte(ISAPNP_ACTIVATE, 0);
}
static
inline
USHORT
ReadIoBase(PUCHAR ReadDataPort, USHORT Index)
ReadIoBase(
IN PUCHAR ReadDataPort,
IN USHORT Index)
{
return ReadWord(ReadDataPort, ISAPNP_IOBASE(Index));
return ReadWord(ReadDataPort, ISAPNP_IOBASE(Index));
}
static
inline
USHORT
ReadIrqNo(PUCHAR ReadDataPort, USHORT Index)
ReadIrqNo(
IN PUCHAR ReadDataPort,
IN USHORT Index)
{
return ReadByte(ReadDataPort, ISAPNP_IRQNO(Index));
return ReadByte(ReadDataPort, ISAPNP_IRQNO(Index));
}
static
@ -173,348 +194,365 @@ inline
VOID
HwDelay(VOID)
{
KeStallExecutionProcessor(1000);
KeStallExecutionProcessor(1000);
}
static
inline
UCHAR
NextLFSR(UCHAR Lfsr, UCHAR InputBit)
NextLFSR(
IN UCHAR Lfsr,
IN UCHAR InputBit)
{
UCHAR NextLfsr = Lfsr >> 1;
UCHAR NextLfsr = Lfsr >> 1;
NextLfsr |= (((Lfsr ^ NextLfsr) ^ InputBit)) << 7;
NextLfsr |= (((Lfsr ^ NextLfsr) ^ InputBit)) << 7;
return NextLfsr;
return NextLfsr;
}
static
VOID
SendKey(VOID)
{
UCHAR i, Lfsr;
UCHAR i, Lfsr;
HwDelay();
WriteAddress(0x00);
WriteAddress(0x00);
HwDelay();
WriteAddress(0x00);
WriteAddress(0x00);
Lfsr = ISAPNP_LFSR_SEED;
for (i = 0; i < 32; i++)
{
WriteAddress(Lfsr);
Lfsr = NextLFSR(Lfsr, 0);
}
Lfsr = ISAPNP_LFSR_SEED;
for (i = 0; i < 32; i++)
{
WriteAddress(Lfsr);
Lfsr = NextLFSR(Lfsr, 0);
}
}
static
USHORT
PeekByte(PUCHAR ReadDataPort)
PeekByte(
IN PUCHAR ReadDataPort)
{
USHORT i;
USHORT i;
for (i = 0; i < 20; i++)
{
if (ReadStatus(ReadDataPort) & 0x01)
return ReadResourceData(ReadDataPort);
for (i = 0; i < 20; i++)
{
if (ReadStatus(ReadDataPort) & 0x01)
return ReadResourceData(ReadDataPort);
HwDelay();
}
HwDelay();
}
return 0xFF;
return 0xFF;
}
static
VOID
Peek(PUCHAR ReadDataPort, PVOID Buffer, ULONG Length)
Peek(
IN PUCHAR ReadDataPort,
IN OUT PVOID Buffer,
IN ULONG Length)
{
USHORT i, byte;
USHORT i, Byte;
for (i = 0; i < Length; i++)
{
byte = PeekByte(ReadDataPort);
if (Buffer)
*((PUCHAR)Buffer + i) = byte;
}
for (i = 0; i < Length; i++)
{
Byte = PeekByte(ReadDataPort);
if (Buffer)
*((PUCHAR)Buffer + i) = Byte;
}
}
static
USHORT
IsaPnpChecksum(PISAPNP_IDENTIFIER Identifier)
IsaPnpChecksum(
IN PISAPNP_IDENTIFIER Identifier)
{
UCHAR i, j, Lfsr, Byte;
UCHAR i, j, Lfsr, Byte;
Lfsr = ISAPNP_LFSR_SEED;
for (i = 0; i < 8; i++)
{
Byte = *(((PUCHAR)Identifier) + i);
for (j = 0; j < 8; j++)
Lfsr = ISAPNP_LFSR_SEED;
for (i = 0; i < 8; i++)
{
Lfsr = NextLFSR(Lfsr, Byte);
Byte >>= 1;
Byte = *(((PUCHAR)Identifier) + i);
for (j = 0; j < 8; j++)
{
Lfsr = NextLFSR(Lfsr, Byte);
Byte >>= 1;
}
}
}
return Lfsr;
return Lfsr;
}
static
BOOLEAN
FindTag(PUCHAR ReadDataPort, USHORT WantedTag, PVOID Buffer, ULONG Length)
FindTag(
IN PUCHAR ReadDataPort,
IN USHORT WantedTag,
IN OUT PVOID Buffer,
IN ULONG Length)
{
USHORT Tag, TagLen;
USHORT Tag, TagLen;
do
{
Tag = PeekByte(ReadDataPort);
if (ISAPNP_IS_SMALL_TAG(Tag))
do
{
TagLen = ISAPNP_SMALL_TAG_LEN(Tag);
Tag = ISAPNP_SMALL_TAG_NAME(Tag);
}
else
{
TagLen = PeekByte(ReadDataPort) + (PeekByte(ReadDataPort) << 8);
Tag = ISAPNP_LARGE_TAG_NAME(Tag);
}
Tag = PeekByte(ReadDataPort);
if (ISAPNP_IS_SMALL_TAG(Tag))
{
TagLen = ISAPNP_SMALL_TAG_LEN(Tag);
Tag = ISAPNP_SMALL_TAG_NAME(Tag);
}
else
{
TagLen = PeekByte(ReadDataPort) + (PeekByte(ReadDataPort) << 8);
Tag = ISAPNP_LARGE_TAG_NAME(Tag);
}
if (Tag == WantedTag)
{
if (Length > TagLen)
Length = TagLen;
if (Tag == WantedTag)
{
if (Length > TagLen)
Length = TagLen;
Peek(ReadDataPort, Buffer, Length);
Peek(ReadDataPort, Buffer, Length);
return TRUE;
}
else
{
Peek(ReadDataPort, NULL, TagLen);
}
} while (Tag != ISAPNP_TAG_END);
return TRUE;
}
else
{
Peek(ReadDataPort, NULL, TagLen);
}
} while (Tag != ISAPNP_TAG_END);
return FALSE;
return FALSE;
}
static
BOOLEAN
FindLogDevId(PUCHAR ReadDataPort, USHORT LogDev, PISAPNP_LOGDEVID LogDeviceId)
FindLogDevId(
IN PUCHAR ReadDataPort,
IN USHORT LogDev,
IN OUT PISAPNP_LOGDEVID LogDeviceId)
{
USHORT i;
USHORT i;
for (i = 0; i <= LogDev; i++)
{
if (!FindTag(ReadDataPort, ISAPNP_TAG_LOGDEVID, LogDeviceId, sizeof(*LogDeviceId)))
return FALSE;
}
for (i = 0; i <= LogDev; i++)
{
if (!FindTag(ReadDataPort, ISAPNP_TAG_LOGDEVID, LogDeviceId, sizeof(*LogDeviceId)))
return FALSE;
}
return TRUE;
return TRUE;
}
static
INT
TryIsolate(PUCHAR ReadDataPort)
TryIsolate(
IN PUCHAR ReadDataPort)
{
ISAPNP_IDENTIFIER Identifier;
USHORT i, j;
BOOLEAN Seen55aa, SeenLife;
INT Csn = 0;
USHORT Byte, Data;
ISAPNP_IDENTIFIER Identifier;
USHORT i, j;
BOOLEAN Seen55aa, SeenLife;
INT Csn = 0;
USHORT Byte, Data;
DPRINT("Setting read data port: 0x%p\n", ReadDataPort);
DPRINT("Setting read data port: 0x%p\n", ReadDataPort);
WaitForKey();
SendKey();
WaitForKey();
SendKey();
ResetCsn();
HwDelay();
HwDelay();
WaitForKey();
SendKey();
Wake(0x00);
SetReadDataPort(ReadDataPort);
HwDelay();
while (TRUE)
{
EnterIsolationState();
HwDelay();
RtlZeroMemory(&Identifier, sizeof(Identifier));
Seen55aa = SeenLife = FALSE;
for (i = 0; i < 9; i++)
{
Byte = 0;
for (j = 0; j < 8; j++)
{
Data = ReadData(ReadDataPort);
HwDelay();
Data = ((Data << 8) | ReadData(ReadDataPort));
HwDelay();
Byte >>= 1;
if (Data != 0xFFFF)
{
SeenLife = TRUE;
if (Data == 0x55AA)
{
Byte |= 0x80;
Seen55aa = TRUE;
}
}
}
*(((PUCHAR)&Identifier) + i) = Byte;
}
if (!Seen55aa)
{
if (Csn)
{
DPRINT("Found no more cards\n");
}
else
{
if (SeenLife)
{
DPRINT("Saw life but no cards, trying new read port\n");
Csn = -1;
}
else
{
DPRINT("Saw no sign of life, abandoning isolation\n");
}
}
break;
}
if (Identifier.Checksum != IsaPnpChecksum(&Identifier))
{
DPRINT("Bad checksum, trying next read data port\n");
Csn = -1;
break;
}
Csn++;
WriteCsn(Csn);
ResetCsn();
HwDelay();
HwDelay();
WaitForKey();
SendKey();
Wake(0x00);
SetReadDataPort(ReadDataPort);
HwDelay();
}
WaitForKey();
while (TRUE)
{
EnterIsolationState();
HwDelay();
if (Csn > 0)
{
DPRINT("Found %d cards at read port 0x%p\n", Csn, ReadDataPort);
}
RtlZeroMemory(&Identifier, sizeof(Identifier));
return Csn;
Seen55aa = SeenLife = FALSE;
for (i = 0; i < 9; i++)
{
Byte = 0;
for (j = 0; j < 8; j++)
{
Data = ReadData(ReadDataPort);
HwDelay();
Data = ((Data << 8) | ReadData(ReadDataPort));
HwDelay();
Byte >>= 1;
if (Data != 0xFFFF)
{
SeenLife = TRUE;
if (Data == 0x55AA)
{
Byte |= 0x80;
Seen55aa = TRUE;
}
}
}
*(((PUCHAR)&Identifier) + i) = Byte;
}
if (!Seen55aa)
{
if (Csn)
{
DPRINT("Found no more cards\n");
}
else
{
if (SeenLife)
{
DPRINT("Saw life but no cards, trying new read port\n");
Csn = -1;
}
else
{
DPRINT("Saw no sign of life, abandoning isolation\n");
}
}
break;
}
if (Identifier.Checksum != IsaPnpChecksum(&Identifier))
{
DPRINT("Bad checksum, trying next read data port\n");
Csn = -1;
break;
}
Csn++;
WriteCsn(Csn);
HwDelay();
Wake(0x00);
HwDelay();
}
WaitForKey();
if (Csn > 0)
{
DPRINT("Found %d cards at read port 0x%p\n", Csn, ReadDataPort);
}
return Csn;
}
static
PUCHAR
Isolate(VOID)
{
PUCHAR ReadPort;
PUCHAR ReadPort;
for (ReadPort = (PUCHAR)ISAPNP_READ_PORT_START;
(ULONG_PTR)ReadPort <= ISAPNP_READ_PORT_MAX;
ReadPort += ISAPNP_READ_PORT_STEP)
{
/* Avoid the NE2000 probe space */
if ((ULONG_PTR)ReadPort >= 0x280 &&
(ULONG_PTR)ReadPort <= 0x380)
continue;
for (ReadPort = (PUCHAR)ISAPNP_READ_PORT_START;
(ULONG_PTR)ReadPort <= ISAPNP_READ_PORT_MAX;
ReadPort += ISAPNP_READ_PORT_STEP)
{
/* Avoid the NE2000 probe space */
if ((ULONG_PTR)ReadPort >= 0x280 &&
(ULONG_PTR)ReadPort <= 0x380)
continue;
if (TryIsolate(ReadPort) > 0)
return ReadPort;
}
if (TryIsolate(ReadPort) > 0)
return ReadPort;
}
return 0;
return 0;
}
VOID
DeviceActivation(PISAPNP_LOGICAL_DEVICE IsaDevice,
BOOLEAN Activate)
DeviceActivation(
IN PISAPNP_LOGICAL_DEVICE IsaDevice,
IN BOOLEAN Activate)
{
WaitForKey();
SendKey();
Wake(IsaDevice->CSN);
WaitForKey();
SendKey();
Wake(IsaDevice->CSN);
if (Activate)
ActivateDevice(IsaDevice->LDN);
else
DeactivateDevice(IsaDevice->LDN);
if (Activate)
ActivateDevice(IsaDevice->LDN);
else
DeactivateDevice(IsaDevice->LDN);
HwDelay();
HwDelay();
WaitForKey();
WaitForKey();
}
NTSTATUS
ProbeIsaPnpBus(PISAPNP_FDO_EXTENSION FdoExt)
ProbeIsaPnpBus(
IN PISAPNP_FDO_EXTENSION FdoExt)
{
PISAPNP_LOGICAL_DEVICE LogDevice;
ISAPNP_IDENTIFIER Identifier;
ISAPNP_LOGDEVID LogDevId;
USHORT Csn;
USHORT LogDev;
PISAPNP_LOGICAL_DEVICE LogDevice;
ISAPNP_IDENTIFIER Identifier;
ISAPNP_LOGDEVID LogDevId;
USHORT Csn;
USHORT LogDev;
ASSERT(FdoExt->ReadDataPort);
ASSERT(FdoExt->ReadDataPort);
for (Csn = 1; Csn <= 0xFF; Csn++)
{
for (LogDev = 0; LogDev <= 0xFF; LogDev++)
for (Csn = 1; Csn <= 0xFF; Csn++)
{
LogDevice = ExAllocatePool(NonPagedPool, sizeof(ISAPNP_LOGICAL_DEVICE));
if (!LogDevice)
return STATUS_NO_MEMORY;
for (LogDev = 0; LogDev <= 0xFF; LogDev++)
{
LogDevice = ExAllocatePool(NonPagedPool, sizeof(ISAPNP_LOGICAL_DEVICE));
if (!LogDevice)
return STATUS_NO_MEMORY;
RtlZeroMemory(LogDevice, sizeof(ISAPNP_LOGICAL_DEVICE));
RtlZeroMemory(LogDevice, sizeof(ISAPNP_LOGICAL_DEVICE));
LogDevice->CSN = Csn;
LogDevice->LDN = LogDev;
LogDevice->CSN = Csn;
LogDevice->LDN = LogDev;
WaitForKey();
SendKey();
Wake(Csn);
WaitForKey();
SendKey();
Wake(Csn);
Peek(FdoExt->ReadDataPort, &Identifier, sizeof(Identifier));
Peek(FdoExt->ReadDataPort, &Identifier, sizeof(Identifier));
if (Identifier.VendorId & 0x80)
{
ExFreePool(LogDevice);
return STATUS_SUCCESS;
}
if (Identifier.VendorId & 0x80)
{
ExFreePool(LogDevice);
return STATUS_SUCCESS;
}
if (!FindLogDevId(FdoExt->ReadDataPort, LogDev, &LogDevId))
break;
if (!FindLogDevId(FdoExt->ReadDataPort, LogDev, &LogDevId))
break;
WriteLogicalDeviceNumber(LogDev);
WriteLogicalDeviceNumber(LogDev);
LogDevice->VendorId[0] = ((LogDevId.VendorId >> 2) & 0x1f) + 'A' - 1,
LogDevice->VendorId[1] = (((LogDevId.VendorId & 0x3) << 3) | ((LogDevId.VendorId >> 13) & 0x7)) + 'A' - 1,
LogDevice->VendorId[2] = ((LogDevId.VendorId >> 8) & 0x1f) + 'A' - 1,
LogDevice->ProdId = RtlUshortByteSwap(LogDevId.ProdId);
LogDevice->SerialNumber = Identifier.Serial;
LogDevice->IoAddr = ReadIoBase(FdoExt->ReadDataPort, 0);
LogDevice->IrqNo = ReadIrqNo(FdoExt->ReadDataPort, 0);
LogDevice->VendorId[0] = ((LogDevId.VendorId >> 2) & 0x1f) + 'A' - 1,
LogDevice->VendorId[1] = (((LogDevId.VendorId & 0x3) << 3) | ((LogDevId.VendorId >> 13) & 0x7)) + 'A' - 1,
LogDevice->VendorId[2] = ((LogDevId.VendorId >> 8) & 0x1f) + 'A' - 1,
LogDevice->ProdId = RtlUshortByteSwap(LogDevId.ProdId);
LogDevice->SerialNumber = Identifier.Serial;
LogDevice->IoAddr = ReadIoBase(FdoExt->ReadDataPort, 0);
LogDevice->IrqNo = ReadIrqNo(FdoExt->ReadDataPort, 0);
DPRINT1("Detected ISA PnP device - VID: '%3s' PID: 0x%x SN: 0x%08x IoBase: 0x%x IRQ:0x%x\n",
LogDevice->VendorId, LogDevice->ProdId, LogDevice->SerialNumber, LogDevice->IoAddr, LogDevice->IrqNo);
DPRINT1("Detected ISA PnP device - VID: '%3s' PID: 0x%x SN: 0x%08x IoBase: 0x%x IRQ:0x%x\n",
LogDevice->VendorId, LogDevice->ProdId, LogDevice->SerialNumber, LogDevice->IoAddr, LogDevice->IrqNo);
WaitForKey();
WaitForKey();
InsertTailList(&FdoExt->DeviceListHead, &LogDevice->ListEntry);
FdoExt->DeviceCount++;
InsertTailList(&FdoExt->DeviceListHead, &LogDevice->ListEntry);
FdoExt->DeviceCount++;
}
}
}
return STATUS_SUCCESS;
return STATUS_SUCCESS;
}
NTSTATUS
@ -522,16 +560,16 @@ NTAPI
IsaHwDetectReadDataPort(
IN PISAPNP_FDO_EXTENSION FdoExt)
{
FdoExt->ReadDataPort = Isolate();
if (!FdoExt->ReadDataPort)
{
DPRINT1("No read data port found\n");
return STATUS_UNSUCCESSFUL;
}
FdoExt->ReadDataPort = Isolate();
if (!FdoExt->ReadDataPort)
{
DPRINT1("No read data port found\n");
return STATUS_UNSUCCESSFUL;
}
DPRINT1("Detected read data port at 0x%p\n", FdoExt->ReadDataPort);
DPRINT1("Detected read data port at 0x%p\n", FdoExt->ReadDataPort);
return STATUS_SUCCESS;
return STATUS_SUCCESS;
}
NTSTATUS
@ -548,18 +586,18 @@ IsaHwActivateDevice(
NTSTATUS
NTAPI
IsaHwDeactivateDevice(
IN PISAPNP_LOGICAL_DEVICE LogicalDevice)
IN PISAPNP_LOGICAL_DEVICE LogicalDevice)
{
DeviceActivation(LogicalDevice,
FALSE);
DeviceActivation(LogicalDevice,
FALSE);
return STATUS_SUCCESS;
return STATUS_SUCCESS;
}
NTSTATUS
NTAPI
IsaHwFillDeviceList(
IN PISAPNP_FDO_EXTENSION FdoExt)
IN PISAPNP_FDO_EXTENSION FdoExt)
{
return ProbeIsaPnpBus(FdoExt);
return ProbeIsaPnpBus(FdoExt);
}

View file

@ -16,42 +16,41 @@ static
NTSTATUS
NTAPI
ForwardIrpCompletion(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN PVOID Context)
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN PVOID Context)
{
UNREFERENCED_PARAMETER(DeviceObject);
UNREFERENCED_PARAMETER(DeviceObject);
if (Irp->PendingReturned)
KeSetEvent((PKEVENT)Context, IO_NO_INCREMENT, FALSE);
if (Irp->PendingReturned)
KeSetEvent((PKEVENT)Context, IO_NO_INCREMENT, FALSE);
return STATUS_MORE_PROCESSING_REQUIRED;
return STATUS_MORE_PROCESSING_REQUIRED;
}
NTSTATUS
NTAPI
IsaForwardIrpSynchronous(
IN PISAPNP_FDO_EXTENSION FdoExt,
IN PIRP Irp)
IN PISAPNP_FDO_EXTENSION FdoExt,
IN PIRP Irp)
{
KEVENT Event;
NTSTATUS Status;
KEVENT Event;
NTSTATUS Status;
KeInitializeEvent(&Event, NotificationEvent, FALSE);
IoCopyCurrentIrpStackLocationToNext(Irp);
KeInitializeEvent(&Event, NotificationEvent, FALSE);
IoCopyCurrentIrpStackLocationToNext(Irp);
IoSetCompletionRoutine(Irp, ForwardIrpCompletion, &Event, TRUE, TRUE, TRUE);
IoSetCompletionRoutine(Irp, ForwardIrpCompletion, &Event, TRUE, TRUE, TRUE);
Status = IoCallDriver(FdoExt->Ldo, Irp);
if (Status == STATUS_PENDING)
{
Status = KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL);
if (NT_SUCCESS(Status))
Status = Irp->IoStatus.Status;
}
Status = IoCallDriver(FdoExt->Ldo, Irp);
if (Status == STATUS_PENDING)
{
Status = KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL);
if (NT_SUCCESS(Status))
Status = Irp->IoStatus.Status;
}
return Status;
return Status;
}
static DRIVER_DISPATCH IsaCreateClose;
@ -60,17 +59,17 @@ static
NTSTATUS
NTAPI
IsaCreateClose(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp)
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp)
{
Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = FILE_OPENED;
Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = FILE_OPENED;
DPRINT("%s(%p, %p)\n", __FUNCTION__, DeviceObject, Irp);
DPRINT("%s(%p, %p)\n", __FUNCTION__, DeviceObject, Irp);
IoCompleteRequest(Irp, IO_NO_INCREMENT);
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return STATUS_SUCCESS;
return STATUS_SUCCESS;
}
static DRIVER_DISPATCH IsaIoctl;
@ -79,26 +78,26 @@ static
NTSTATUS
NTAPI
IsaIoctl(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp)
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp)
{
PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
NTSTATUS Status;
PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
NTSTATUS Status;
DPRINT("%s(%p, %p)\n", __FUNCTION__, DeviceObject, Irp);
DPRINT("%s(%p, %p)\n", __FUNCTION__, DeviceObject, Irp);
switch (IrpSp->Parameters.DeviceIoControl.IoControlCode)
{
default:
DPRINT1("Unknown ioctl code: %x\n", IrpSp->Parameters.DeviceIoControl.IoControlCode);
Status = STATUS_NOT_SUPPORTED;
break;
}
switch (IrpSp->Parameters.DeviceIoControl.IoControlCode)
{
default:
DPRINT1("Unknown ioctl code: %x\n", IrpSp->Parameters.DeviceIoControl.IoControlCode);
Status = STATUS_NOT_SUPPORTED;
break;
}
Irp->IoStatus.Status = Status;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
Irp->IoStatus.Status = Status;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return Status;
return Status;
}
static DRIVER_DISPATCH IsaReadWrite;
@ -107,62 +106,62 @@ static
NTSTATUS
NTAPI
IsaReadWrite(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp)
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp)
{
DPRINT("%s(%p, %p)\n", __FUNCTION__, DeviceObject, Irp);
DPRINT("%s(%p, %p)\n", __FUNCTION__, DeviceObject, Irp);
Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
Irp->IoStatus.Information = 0;
Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return STATUS_NOT_SUPPORTED;
return STATUS_NOT_SUPPORTED;
}
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;
NTSTATUS Status;
PDEVICE_OBJECT Fdo;
PISAPNP_FDO_EXTENSION FdoExt;
NTSTATUS Status;
DPRINT("%s(%p, %p)\n", __FUNCTION__, DriverObject, PhysicalDeviceObject);
DPRINT("%s(%p, %p)\n", __FUNCTION__, DriverObject, PhysicalDeviceObject);
Status = IoCreateDevice(DriverObject,
sizeof(*FdoExt),
NULL,
FILE_DEVICE_BUS_EXTENDER,
FILE_DEVICE_SECURE_OPEN,
TRUE,
&Fdo);
if (!NT_SUCCESS(Status))
{
DPRINT1("Failed to create FDO (0x%x)\n", Status);
return Status;
}
Status = IoCreateDevice(DriverObject,
sizeof(*FdoExt),
NULL,
FILE_DEVICE_BUS_EXTENDER,
FILE_DEVICE_SECURE_OPEN,
TRUE,
&Fdo);
if (!NT_SUCCESS(Status))
{
DPRINT1("Failed to create FDO (0x%x)\n", Status);
return Status;
}
FdoExt = Fdo->DeviceExtension;
RtlZeroMemory(FdoExt, sizeof(*FdoExt));
FdoExt = Fdo->DeviceExtension;
RtlZeroMemory(FdoExt, sizeof(*FdoExt));
FdoExt->Common.Self = Fdo;
FdoExt->Common.IsFdo = TRUE;
FdoExt->Common.State = dsStopped;
FdoExt->DriverObject = DriverObject;
FdoExt->Pdo = PhysicalDeviceObject;
FdoExt->Ldo = IoAttachDeviceToDeviceStack(Fdo,
PhysicalDeviceObject);
FdoExt->Common.Self = Fdo;
FdoExt->Common.IsFdo = TRUE;
FdoExt->Common.State = dsStopped;
FdoExt->DriverObject = DriverObject;
FdoExt->Pdo = PhysicalDeviceObject;
FdoExt->Ldo = IoAttachDeviceToDeviceStack(Fdo,
PhysicalDeviceObject);
InitializeListHead(&FdoExt->DeviceListHead);
KeInitializeSpinLock(&FdoExt->Lock);
InitializeListHead(&FdoExt->DeviceListHead);
KeInitializeSpinLock(&FdoExt->Lock);
Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
return STATUS_SUCCESS;
return STATUS_SUCCESS;
}
static DRIVER_DISPATCH IsaPnp;
@ -171,45 +170,45 @@ static
NTSTATUS
NTAPI
IsaPnp(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp)
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp)
{
PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
PISAPNP_COMMON_EXTENSION DevExt = DeviceObject->DeviceExtension;
PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
PISAPNP_COMMON_EXTENSION DevExt = DeviceObject->DeviceExtension;
DPRINT("%s(%p, %p)\n", __FUNCTION__, DeviceObject, Irp);
DPRINT("%s(%p, %p)\n", __FUNCTION__, DeviceObject, Irp);
if (DevExt->IsFdo)
{
return IsaFdoPnp((PISAPNP_FDO_EXTENSION)DevExt,
Irp,
IrpSp);
}
else
{
return IsaPdoPnp((PISAPNP_PDO_EXTENSION)DevExt,
Irp,
IrpSp);
}
if (DevExt->IsFdo)
{
return IsaFdoPnp((PISAPNP_FDO_EXTENSION)DevExt,
Irp,
IrpSp);
}
else
{
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);
DPRINT("%s(%p, %wZ)\n", __FUNCTION__, DriverObject, RegistryPath);
DriverObject->MajorFunction[IRP_MJ_CREATE] = IsaCreateClose;
DriverObject->MajorFunction[IRP_MJ_CLOSE] = IsaCreateClose;
DriverObject->MajorFunction[IRP_MJ_READ] = IsaReadWrite;
DriverObject->MajorFunction[IRP_MJ_WRITE] = IsaReadWrite;
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = IsaIoctl;
DriverObject->MajorFunction[IRP_MJ_PNP] = IsaPnp;
DriverObject->DriverExtension->AddDevice = IsaAddDevice;
DriverObject->MajorFunction[IRP_MJ_CREATE] = IsaCreateClose;
DriverObject->MajorFunction[IRP_MJ_CLOSE] = IsaCreateClose;
DriverObject->MajorFunction[IRP_MJ_READ] = IsaReadWrite;
DriverObject->MajorFunction[IRP_MJ_WRITE] = IsaReadWrite;
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = IsaIoctl;
DriverObject->MajorFunction[IRP_MJ_PNP] = IsaPnp;
DriverObject->DriverExtension->AddDevice = IsaAddDevice;
return STATUS_SUCCESS;
return STATUS_SUCCESS;
}
/* EOF */

View file

@ -11,42 +11,42 @@ extern "C" {
#define TAG_ISAPNP 'PNPI'
typedef enum {
dsStopped,
dsStarted
dsStopped,
dsStarted
} ISAPNP_DEVICE_STATE;
typedef struct _ISAPNP_LOGICAL_DEVICE {
PDEVICE_OBJECT Pdo;
UCHAR VendorId[3];
USHORT ProdId;
ULONG SerialNumber;
USHORT IoAddr;
UCHAR IrqNo;
UCHAR CSN;
UCHAR LDN;
LIST_ENTRY ListEntry;
PDEVICE_OBJECT Pdo;
UCHAR VendorId[3];
USHORT ProdId;
ULONG SerialNumber;
USHORT IoAddr;
UCHAR IrqNo;
UCHAR CSN;
UCHAR LDN;
LIST_ENTRY ListEntry;
} ISAPNP_LOGICAL_DEVICE, *PISAPNP_LOGICAL_DEVICE;
typedef struct _ISAPNP_COMMON_EXTENSION {
PDEVICE_OBJECT Self;
BOOLEAN IsFdo;
ISAPNP_DEVICE_STATE State;
PDEVICE_OBJECT Self;
BOOLEAN IsFdo;
ISAPNP_DEVICE_STATE State;
} ISAPNP_COMMON_EXTENSION, *PISAPNP_COMMON_EXTENSION;
typedef struct _ISAPNP_FDO_EXTENSION {
ISAPNP_COMMON_EXTENSION Common;
PDEVICE_OBJECT Ldo;
PDEVICE_OBJECT Pdo;
LIST_ENTRY DeviceListHead;
ULONG DeviceCount;
PDRIVER_OBJECT DriverObject;
PUCHAR ReadDataPort;
KSPIN_LOCK Lock;
ISAPNP_COMMON_EXTENSION Common;
PDEVICE_OBJECT Ldo;
PDEVICE_OBJECT Pdo;
LIST_ENTRY DeviceListHead;
ULONG DeviceCount;
PDRIVER_OBJECT DriverObject;
PUCHAR ReadDataPort;
KSPIN_LOCK Lock;
} ISAPNP_FDO_EXTENSION, *PISAPNP_FDO_EXTENSION;
typedef struct _ISAPNP_PDO_EXTENSION {
ISAPNP_COMMON_EXTENSION Common;
PISAPNP_LOGICAL_DEVICE IsaPnpDevice;
ISAPNP_COMMON_EXTENSION Common;
PISAPNP_LOGICAL_DEVICE IsaPnpDevice;
} ISAPNP_PDO_EXTENSION, *PISAPNP_PDO_EXTENSION;
/* isapnp.c */
@ -56,51 +56,51 @@ DRIVER_INITIALIZE DriverEntry;
NTSTATUS
NTAPI
DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath);
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath);
NTSTATUS
NTAPI
IsaForwardIrpSynchronous(
IN PISAPNP_FDO_EXTENSION FdoExt,
IN PIRP Irp);
IN PISAPNP_FDO_EXTENSION FdoExt,
IN 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,
IN 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,
IN PIRP Irp,
IN PIO_STACK_LOCATION IrpSp);
/* hardware.c */
NTSTATUS
NTAPI
IsaHwDetectReadDataPort(
IN PISAPNP_FDO_EXTENSION FdoExt);
IN PISAPNP_FDO_EXTENSION FdoExt);
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
}

View file

@ -83,22 +83,22 @@ extern "C" {
#define ISAPNP_TAG_PSEUDO_NEWBOARD 0x100
typedef struct _ISAPNP_IDENTIFIER {
USHORT VendorId;
USHORT ProdId;
ULONG Serial;
UCHAR Checksum;
USHORT VendorId;
USHORT ProdId;
ULONG Serial;
UCHAR Checksum;
} ISAPNP_IDENTIFIER, *PISAPNP_IDENTIFIER;
typedef struct _ISAPNP_LOGDEVID {
USHORT VendorId;
USHORT ProdId;
USHORT Flags;
USHORT VendorId;
USHORT ProdId;
USHORT Flags;
} ISAPNP_LOGDEVID, *PISAPNP_LOGDEVID;
typedef struct _ISAPNP_DEVICEID {
CHAR* Name;
USHORT VendorId;
USHORT ProdId;
CHAR* Name;
USHORT VendorId;
USHORT ProdId;
} ISAPNP_DEVICEID, *PISAPNP_DEVICEID;
#ifdef __cplusplus

View file

@ -13,184 +13,184 @@
NTSTATUS
NTAPI
IsaPdoQueryDeviceRelations(
IN PISAPNP_PDO_EXTENSION PdoExt,
IN PIRP Irp,
IN PIO_STACK_LOCATION IrpSp)
IN PISAPNP_PDO_EXTENSION PdoExt,
IN PIRP Irp,
IN PIO_STACK_LOCATION IrpSp)
{
PDEVICE_RELATIONS DeviceRelations;
PDEVICE_RELATIONS DeviceRelations;
if (IrpSp->Parameters.QueryDeviceRelations.Type != TargetDeviceRelation)
return Irp->IoStatus.Status;
if (IrpSp->Parameters.QueryDeviceRelations.Type != TargetDeviceRelation)
return Irp->IoStatus.Status;
DeviceRelations = ExAllocatePool(PagedPool, sizeof(*DeviceRelations));
if (!DeviceRelations)
return STATUS_INSUFFICIENT_RESOURCES;
DeviceRelations = ExAllocatePool(PagedPool, sizeof(*DeviceRelations));
if (!DeviceRelations)
return STATUS_INSUFFICIENT_RESOURCES;
DeviceRelations->Count = 1;
DeviceRelations->Objects[0] = PdoExt->Common.Self;
ObReferenceObject(PdoExt->Common.Self);
DeviceRelations->Count = 1;
DeviceRelations->Objects[0] = PdoExt->Common.Self;
ObReferenceObject(PdoExt->Common.Self);
Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations;
Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations;
return STATUS_SUCCESS;
return STATUS_SUCCESS;
}
NTSTATUS
NTAPI
IsaPdoQueryCapabilities(
IN PISAPNP_PDO_EXTENSION PdoExt,
IN PIRP Irp,
IN PIO_STACK_LOCATION IrpSp)
IN PISAPNP_PDO_EXTENSION PdoExt,
IN PIRP Irp,
IN PIO_STACK_LOCATION IrpSp)
{
PDEVICE_CAPABILITIES DeviceCapabilities;
PISAPNP_LOGICAL_DEVICE LogDev = PdoExt->IsaPnpDevice;
PDEVICE_CAPABILITIES DeviceCapabilities;
PISAPNP_LOGICAL_DEVICE LogDev = PdoExt->IsaPnpDevice;
DeviceCapabilities = IrpSp->Parameters.DeviceCapabilities.Capabilities;
if (DeviceCapabilities->Version != 1)
return STATUS_UNSUCCESSFUL;
DeviceCapabilities = IrpSp->Parameters.DeviceCapabilities.Capabilities;
if (DeviceCapabilities->Version != 1)
return STATUS_UNSUCCESSFUL;
DeviceCapabilities->UniqueID = LogDev->SerialNumber != 0xffffffff;
DeviceCapabilities->Address = LogDev->CSN;
DeviceCapabilities->UniqueID = LogDev->SerialNumber != 0xffffffff;
DeviceCapabilities->Address = LogDev->CSN;
return STATUS_SUCCESS;
return STATUS_SUCCESS;
}
NTSTATUS
NTAPI
IsaPdoQueryId(
IN PISAPNP_PDO_EXTENSION PdoExt,
IN PIRP Irp,
IN PIO_STACK_LOCATION IrpSp)
IN PISAPNP_PDO_EXTENSION PdoExt,
IN PIRP Irp,
IN PIO_STACK_LOCATION IrpSp)
{
PISAPNP_LOGICAL_DEVICE LogDev = PdoExt->IsaPnpDevice;
WCHAR Temp[256];
PWCHAR Buffer, End;
ULONG Length;
NTSTATUS Status;
PISAPNP_LOGICAL_DEVICE LogDev = PdoExt->IsaPnpDevice;
WCHAR Temp[256];
PWCHAR Buffer, End;
ULONG Length;
NTSTATUS Status;
switch (IrpSp->Parameters.QueryId.IdType)
{
case BusQueryDeviceID:
switch (IrpSp->Parameters.QueryId.IdType)
{
DPRINT("IRP_MJ_PNP / IRP_MN_QUERY_ID / BusQueryDeviceID\n");
Status = RtlStringCbPrintfExW(Temp, sizeof(Temp),
&End,
NULL, 0,
L"ISAPNP\\%3S%04X",
LogDev->VendorId,
LogDev->ProdId);
if (!NT_SUCCESS(Status))
return Status;
Length = End - Temp;
Temp[Length++] = UNICODE_NULL;
break;
case BusQueryDeviceID:
{
DPRINT("IRP_MJ_PNP / IRP_MN_QUERY_ID / BusQueryDeviceID\n");
Status = RtlStringCbPrintfExW(Temp, sizeof(Temp),
&End,
NULL, 0,
L"ISAPNP\\%3S%04X",
LogDev->VendorId,
LogDev->ProdId);
if (!NT_SUCCESS(Status))
return Status;
Length = End - Temp;
Temp[Length++] = UNICODE_NULL;
break;
}
case BusQueryHardwareIDs:
DPRINT("IRP_MJ_PNP / IRP_MN_QUERY_ID / BusQueryHardwareIDs\n");
Status = RtlStringCbPrintfExW(Temp, sizeof(Temp),
&End,
NULL, 0,
L"ISAPNP\\%3S%04X",
LogDev->VendorId,
LogDev->ProdId);
if (!NT_SUCCESS(Status))
return Status;
Length = End - Temp;
Temp[Length++] = UNICODE_NULL;
Status = RtlStringCbPrintfExW(Temp + Length, sizeof(Temp) - Length,
&End,
NULL, 0,
L"*%3S%04X",
LogDev->VendorId,
LogDev->ProdId);
if (!NT_SUCCESS(Status))
return Status;
Length = End - Temp;
Temp[Length++] = UNICODE_NULL;
Temp[Length++] = UNICODE_NULL;
break;
case BusQueryInstanceID:
DPRINT("IRP_MJ_PNP / IRP_MN_QUERY_ID / BusQueryInstanceID\n");
Status = RtlStringCbPrintfExW(Temp, sizeof(Temp),
&End,
NULL, 0,
L"%X",
LogDev->SerialNumber);
if (!NT_SUCCESS(Status))
return Status;
Length = End - Temp;
Temp[Length++] = UNICODE_NULL;
break;
default:
DPRINT1("IRP_MJ_PNP / IRP_MN_QUERY_ID / unknown query id type 0x%lx\n",
IrpSp->Parameters.QueryId.IdType);
return Irp->IoStatus.Status;
}
case BusQueryHardwareIDs:
DPRINT("IRP_MJ_PNP / IRP_MN_QUERY_ID / BusQueryHardwareIDs\n");
Status = RtlStringCbPrintfExW(Temp, sizeof(Temp),
&End,
NULL, 0,
L"ISAPNP\\%3S%04X",
LogDev->VendorId,
LogDev->ProdId);
if (!NT_SUCCESS(Status))
return Status;
Length = End - Temp;
Temp[Length++] = UNICODE_NULL;
Status = RtlStringCbPrintfExW(Temp + Length, sizeof(Temp) - Length,
&End,
NULL, 0,
L"*%3S%04X",
LogDev->VendorId,
LogDev->ProdId);
if (!NT_SUCCESS(Status))
return Status;
Length = End - Temp;
Temp[Length++] = UNICODE_NULL;
Temp[Length++] = UNICODE_NULL;
break;
Buffer = ExAllocatePool(PagedPool, Length * sizeof(WCHAR));
if (!Buffer)
return STATUS_NO_MEMORY;
case BusQueryInstanceID:
DPRINT("IRP_MJ_PNP / IRP_MN_QUERY_ID / BusQueryInstanceID\n");
Status = RtlStringCbPrintfExW(Temp, sizeof(Temp),
&End,
NULL, 0,
L"%X",
LogDev->SerialNumber);
if (!NT_SUCCESS(Status))
return Status;
Length = End - Temp;
Temp[Length++] = UNICODE_NULL;
break;
default:
DPRINT1("IRP_MJ_PNP / IRP_MN_QUERY_ID / unknown query id type 0x%lx\n",
IrpSp->Parameters.QueryId.IdType);
return Irp->IoStatus.Status;
}
Buffer = ExAllocatePool(PagedPool, Length * sizeof(WCHAR));
if (!Buffer)
return STATUS_NO_MEMORY;
RtlCopyMemory(Buffer, Temp, Length * sizeof(WCHAR));
Irp->IoStatus.Information = (ULONG_PTR)Buffer;
return STATUS_SUCCESS;
RtlCopyMemory(Buffer, Temp, Length * sizeof(WCHAR));
Irp->IoStatus.Information = (ULONG_PTR)Buffer;
return STATUS_SUCCESS;
}
NTSTATUS
NTAPI
IsaPdoPnp(
IN PISAPNP_PDO_EXTENSION PdoExt,
IN PIRP Irp,
IN PIO_STACK_LOCATION IrpSp)
IN PISAPNP_PDO_EXTENSION PdoExt,
IN PIRP Irp,
IN PIO_STACK_LOCATION IrpSp)
{
NTSTATUS Status = Irp->IoStatus.Status;
NTSTATUS Status = Irp->IoStatus.Status;
switch (IrpSp->MinorFunction)
{
case IRP_MN_START_DEVICE:
Status = IsaHwActivateDevice(PdoExt->IsaPnpDevice);
switch (IrpSp->MinorFunction)
{
case IRP_MN_START_DEVICE:
Status = IsaHwActivateDevice(PdoExt->IsaPnpDevice);
if (NT_SUCCESS(Status))
PdoExt->Common.State = dsStarted;
break;
if (NT_SUCCESS(Status))
PdoExt->Common.State = dsStarted;
break;
case IRP_MN_STOP_DEVICE:
Status = IsaHwDeactivateDevice(PdoExt->IsaPnpDevice);
case IRP_MN_STOP_DEVICE:
Status = IsaHwDeactivateDevice(PdoExt->IsaPnpDevice);
if (NT_SUCCESS(Status))
PdoExt->Common.State = dsStopped;
break;
if (NT_SUCCESS(Status))
PdoExt->Common.State = dsStopped;
break;
case IRP_MN_QUERY_DEVICE_RELATIONS:
Status = IsaPdoQueryDeviceRelations(PdoExt, Irp, IrpSp);
break;
case IRP_MN_QUERY_DEVICE_RELATIONS:
Status = IsaPdoQueryDeviceRelations(PdoExt, Irp, IrpSp);
break;
case IRP_MN_QUERY_CAPABILITIES:
Status = IsaPdoQueryCapabilities(PdoExt, Irp, IrpSp);
break;
case IRP_MN_QUERY_CAPABILITIES:
Status = IsaPdoQueryCapabilities(PdoExt, Irp, IrpSp);
break;
case IRP_MN_QUERY_RESOURCES:
DPRINT1("IRP_MN_QUERY_RESOURCES is UNIMPLEMENTED!\n");
break;
case IRP_MN_QUERY_RESOURCES:
DPRINT1("IRP_MN_QUERY_RESOURCES is UNIMPLEMENTED!\n");
break;
case IRP_MN_QUERY_RESOURCE_REQUIREMENTS:
DPRINT1("IRP_MN_QUERY_RESOURCE_REQUIREMENTS is UNIMPLEMENTED!\n");
break;
case IRP_MN_QUERY_RESOURCE_REQUIREMENTS:
DPRINT1("IRP_MN_QUERY_RESOURCE_REQUIREMENTS is UNIMPLEMENTED!\n");
break;
case IRP_MN_QUERY_ID:
Status = IsaPdoQueryId(PdoExt, Irp, IrpSp);
break;
case IRP_MN_QUERY_ID:
Status = IsaPdoQueryId(PdoExt, Irp, IrpSp);
break;
default:
DPRINT1("Unknown PnP code: %x\n", IrpSp->MinorFunction);
break;
}
default:
DPRINT1("Unknown PnP code: %x\n", IrpSp->MinorFunction);
break;
}
Irp->IoStatus.Status = Status;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
Irp->IoStatus.Status = Status;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return Status;
return Status;
}