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: Hardware support 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-20 14:50:34 +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
|
|
|
|
2024-05-03 13:09:23 +00:00
|
|
|
#ifndef UNIT_TEST
|
|
|
|
|
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-20 14:50:34 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(disable:28138) /* ISA bus always uses hardcoded port addresses */
|
|
|
|
#endif
|
|
|
|
|
2024-05-03 13:09:23 +00:00
|
|
|
#endif /* UNIT_TEST */
|
|
|
|
|
2024-10-07 14:10:08 +00:00
|
|
|
ULONG IsaConfigPorts[2] =
|
|
|
|
{
|
|
|
|
ISAPNP_WRITE_DATA_PCAT,
|
|
|
|
ISAPNP_ADDRESS_PCAT
|
|
|
|
};
|
|
|
|
|
2010-04-07 20:19:29 +00:00
|
|
|
static
|
|
|
|
inline
|
|
|
|
VOID
|
2020-03-20 18:19:30 +00:00
|
|
|
WriteAddress(
|
2021-03-20 14:49:57 +00:00
|
|
|
_In_ UCHAR Address)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2024-10-07 14:10:08 +00:00
|
|
|
WRITE_PORT_UCHAR(UlongToPtr(IsaConfigPorts[1]), Address);
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
inline
|
|
|
|
VOID
|
2020-03-20 18:19:30 +00:00
|
|
|
WriteData(
|
2021-03-20 14:49:57 +00:00
|
|
|
_In_ UCHAR Data)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2024-10-07 14:10:08 +00:00
|
|
|
WRITE_PORT_UCHAR(UlongToPtr(IsaConfigPorts[0]), Data);
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
inline
|
|
|
|
UCHAR
|
2020-03-20 18:19:30 +00:00
|
|
|
ReadData(
|
2021-03-04 12:42:42 +00:00
|
|
|
_In_ PUCHAR ReadDataPort)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2020-03-20 18:19:30 +00:00
|
|
|
return READ_PORT_UCHAR(ReadDataPort);
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2024-05-03 14:43:40 +00:00
|
|
|
CODE_SEG("PAGE")
|
2010-04-07 20:19:29 +00:00
|
|
|
VOID
|
2020-03-20 18:19:30 +00:00
|
|
|
WriteByte(
|
2021-03-20 14:49:57 +00:00
|
|
|
_In_ UCHAR Address,
|
|
|
|
_In_ UCHAR Value)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2024-05-03 14:43:40 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
WriteAddress(Address);
|
|
|
|
WriteData(Value);
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
2021-03-20 14:53:54 +00:00
|
|
|
static
|
|
|
|
inline
|
|
|
|
VOID
|
|
|
|
WriteWord(
|
|
|
|
_In_ UCHAR Address,
|
|
|
|
_In_ USHORT Value)
|
|
|
|
{
|
2024-05-03 14:43:40 +00:00
|
|
|
WriteByte(Address + 1, (UCHAR)Value);
|
|
|
|
WriteByte(Address, Value >> 8);
|
2021-03-20 14:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
inline
|
|
|
|
VOID
|
|
|
|
WriteDoubleWord(
|
|
|
|
_In_ UCHAR Address,
|
|
|
|
_In_ ULONG Value)
|
|
|
|
{
|
|
|
|
WriteWord(Address + 2, (USHORT)Value);
|
|
|
|
WriteWord(Address, Value >> 16);
|
|
|
|
}
|
|
|
|
|
2010-04-07 20:19:29 +00:00
|
|
|
static
|
2024-05-03 14:43:40 +00:00
|
|
|
CODE_SEG("PAGE")
|
2010-04-07 20:19:29 +00:00
|
|
|
UCHAR
|
2020-03-20 18:19:30 +00:00
|
|
|
ReadByte(
|
2021-03-04 12:42:42 +00:00
|
|
|
_In_ PUCHAR ReadDataPort,
|
2021-03-20 14:49:57 +00:00
|
|
|
_In_ UCHAR Address)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2024-05-03 14:43:40 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
WriteAddress(Address);
|
|
|
|
return ReadData(ReadDataPort);
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
inline
|
|
|
|
USHORT
|
2020-03-20 18:19:30 +00:00
|
|
|
ReadWord(
|
2021-03-04 12:42:42 +00:00
|
|
|
_In_ PUCHAR ReadDataPort,
|
2021-03-20 14:49:57 +00:00
|
|
|
_In_ UCHAR Address)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2020-03-20 18:19:30 +00:00
|
|
|
return ((ReadByte(ReadDataPort, Address) << 8) |
|
|
|
|
(ReadByte(ReadDataPort, Address + 1)));
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
2021-03-20 14:51:05 +00:00
|
|
|
static
|
|
|
|
inline
|
|
|
|
ULONG
|
|
|
|
ReadDoubleWord(
|
|
|
|
_In_ PUCHAR ReadDataPort,
|
|
|
|
_In_ UCHAR Address)
|
|
|
|
{
|
2024-05-03 14:03:51 +00:00
|
|
|
return ((ReadWord(ReadDataPort, Address) << 16) |
|
2021-03-20 14:51:05 +00:00
|
|
|
(ReadWord(ReadDataPort, Address + 2)));
|
|
|
|
}
|
|
|
|
|
2010-04-07 20:19:29 +00:00
|
|
|
static
|
|
|
|
inline
|
|
|
|
VOID
|
2020-03-20 18:19:30 +00:00
|
|
|
SetReadDataPort(
|
2021-03-04 12:42:42 +00:00
|
|
|
_In_ PUCHAR ReadDataPort)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2021-03-20 14:49:57 +00:00
|
|
|
WriteByte(ISAPNP_READPORT, (UCHAR)((ULONG_PTR)ReadDataPort >> 2));
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
inline
|
|
|
|
VOID
|
|
|
|
EnterIsolationState(VOID)
|
|
|
|
{
|
2020-03-20 18:19:30 +00:00
|
|
|
WriteAddress(ISAPNP_SERIALISOLATION);
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
inline
|
|
|
|
VOID
|
|
|
|
WaitForKey(VOID)
|
|
|
|
{
|
2020-03-20 18:19:30 +00:00
|
|
|
WriteByte(ISAPNP_CONFIGCONTROL, ISAPNP_CONFIG_WAIT_FOR_KEY);
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
inline
|
|
|
|
VOID
|
2020-03-20 18:19:30 +00:00
|
|
|
Wake(
|
2021-03-20 14:49:57 +00:00
|
|
|
_In_ UCHAR Csn)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2020-03-20 18:19:30 +00:00
|
|
|
WriteByte(ISAPNP_WAKE, Csn);
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
inline
|
2021-03-20 14:49:57 +00:00
|
|
|
UCHAR
|
2020-03-20 18:19:30 +00:00
|
|
|
ReadResourceData(
|
2021-03-04 12:42:42 +00:00
|
|
|
_In_ PUCHAR ReadDataPort)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2020-03-20 18:19:30 +00:00
|
|
|
return ReadByte(ReadDataPort, ISAPNP_RESOURCEDATA);
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
inline
|
2021-03-20 14:49:57 +00:00
|
|
|
UCHAR
|
2020-03-20 18:19:30 +00:00
|
|
|
ReadStatus(
|
2021-03-04 12:42:42 +00:00
|
|
|
_In_ PUCHAR ReadDataPort)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2020-03-20 18:19:30 +00:00
|
|
|
return ReadByte(ReadDataPort, ISAPNP_STATUS);
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
inline
|
|
|
|
VOID
|
2020-03-20 18:19:30 +00:00
|
|
|
WriteCsn(
|
2021-03-20 14:49:57 +00:00
|
|
|
_In_ UCHAR Csn)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2020-03-20 18:19:30 +00:00
|
|
|
WriteByte(ISAPNP_CARDSELECTNUMBER, Csn);
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
inline
|
|
|
|
VOID
|
2020-03-20 18:19:30 +00:00
|
|
|
WriteLogicalDeviceNumber(
|
2021-03-20 14:49:57 +00:00
|
|
|
_In_ UCHAR LogDev)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2020-03-20 18:19:30 +00:00
|
|
|
WriteByte(ISAPNP_LOGICALDEVICENUMBER, LogDev);
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
inline
|
|
|
|
VOID
|
2020-03-20 18:19:30 +00:00
|
|
|
ActivateDevice(
|
2021-03-20 14:53:06 +00:00
|
|
|
_In_ PUCHAR ReadDataPort,
|
2021-03-20 14:49:57 +00:00
|
|
|
_In_ UCHAR LogDev)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2020-03-20 18:19:30 +00:00
|
|
|
WriteLogicalDeviceNumber(LogDev);
|
2021-03-20 14:53:06 +00:00
|
|
|
|
|
|
|
WriteByte(ISAPNP_IORANGECHECK,
|
|
|
|
ReadByte(ReadDataPort, ISAPNP_IORANGECHECK) & ~2);
|
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
WriteByte(ISAPNP_ACTIVATE, 1);
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
inline
|
|
|
|
VOID
|
2020-03-20 18:19:30 +00:00
|
|
|
DeactivateDevice(
|
2021-03-20 14:49:57 +00:00
|
|
|
_In_ UCHAR LogDev)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2020-03-20 18:19:30 +00:00
|
|
|
WriteLogicalDeviceNumber(LogDev);
|
|
|
|
WriteByte(ISAPNP_ACTIVATE, 0);
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
inline
|
|
|
|
USHORT
|
2020-03-20 18:19:30 +00:00
|
|
|
ReadIoBase(
|
2021-03-04 12:42:42 +00:00
|
|
|
_In_ PUCHAR ReadDataPort,
|
2021-03-20 14:49:57 +00:00
|
|
|
_In_ UCHAR Index)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2020-03-20 18:19:30 +00:00
|
|
|
return ReadWord(ReadDataPort, ISAPNP_IOBASE(Index));
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
inline
|
2021-03-20 14:49:57 +00:00
|
|
|
UCHAR
|
2020-03-20 18:19:30 +00:00
|
|
|
ReadIrqNo(
|
2021-03-04 12:42:42 +00:00
|
|
|
_In_ PUCHAR ReadDataPort,
|
2021-03-20 14:49:57 +00:00
|
|
|
_In_ UCHAR Index)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2021-03-20 14:51:05 +00:00
|
|
|
return ReadByte(ReadDataPort, ISAPNP_IRQNO(Index)) & 0x0F;
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
2020-03-21 22:08:00 +00:00
|
|
|
static
|
|
|
|
inline
|
2021-03-20 14:49:57 +00:00
|
|
|
UCHAR
|
2020-03-21 22:08:00 +00:00
|
|
|
ReadIrqType(
|
2021-03-04 12:42:42 +00:00
|
|
|
_In_ PUCHAR ReadDataPort,
|
2021-03-20 14:49:57 +00:00
|
|
|
_In_ UCHAR Index)
|
2020-03-21 22:08:00 +00:00
|
|
|
{
|
|
|
|
return ReadByte(ReadDataPort, ISAPNP_IRQTYPE(Index));
|
|
|
|
}
|
|
|
|
|
2020-03-22 22:23:04 +00:00
|
|
|
static
|
|
|
|
inline
|
2021-03-20 14:49:57 +00:00
|
|
|
UCHAR
|
2020-03-22 22:23:04 +00:00
|
|
|
ReadDmaChannel(
|
2021-03-04 12:42:42 +00:00
|
|
|
_In_ PUCHAR ReadDataPort,
|
2021-03-20 14:49:57 +00:00
|
|
|
_In_ UCHAR Index)
|
2020-03-22 22:23:04 +00:00
|
|
|
{
|
2021-03-20 14:51:05 +00:00
|
|
|
return ReadByte(ReadDataPort, ISAPNP_DMACHANNEL(Index)) & 0x07;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
inline
|
|
|
|
USHORT
|
|
|
|
ReadMemoryBase(
|
|
|
|
_In_ PUCHAR ReadDataPort,
|
|
|
|
_In_ UCHAR Index)
|
|
|
|
{
|
|
|
|
return ReadWord(ReadDataPort, ISAPNP_MEMBASE(Index));
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
inline
|
|
|
|
UCHAR
|
|
|
|
ReadMemoryControl(
|
|
|
|
_In_ PUCHAR ReadDataPort,
|
|
|
|
_In_ UCHAR Index)
|
|
|
|
{
|
|
|
|
return ReadByte(ReadDataPort, ISAPNP_MEMCONTROL(Index));
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
inline
|
|
|
|
USHORT
|
|
|
|
ReadMemoryLimit(
|
|
|
|
_In_ PUCHAR ReadDataPort,
|
|
|
|
_In_ UCHAR Index)
|
|
|
|
{
|
|
|
|
return ReadWord(ReadDataPort, ISAPNP_MEMLIMIT(Index));
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
inline
|
|
|
|
ULONG
|
|
|
|
ReadMemoryBase32(
|
|
|
|
_In_ PUCHAR ReadDataPort,
|
|
|
|
_In_ UCHAR Index)
|
|
|
|
{
|
|
|
|
return ReadDoubleWord(ReadDataPort, ISAPNP_MEMBASE32(Index));
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
inline
|
|
|
|
UCHAR
|
|
|
|
ReadMemoryControl32(
|
|
|
|
_In_ PUCHAR ReadDataPort,
|
|
|
|
_In_ UCHAR Index)
|
|
|
|
{
|
|
|
|
return ReadByte(ReadDataPort, ISAPNP_MEMCONTROL32(Index));
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
inline
|
|
|
|
ULONG
|
|
|
|
ReadMemoryLimit32(
|
|
|
|
_In_ PUCHAR ReadDataPort,
|
|
|
|
_In_ UCHAR Index)
|
|
|
|
{
|
|
|
|
return ReadDoubleWord(ReadDataPort, ISAPNP_MEMLIMIT32(Index));
|
2020-03-22 22:23:04 +00:00
|
|
|
}
|
|
|
|
|
2010-04-07 20:19:29 +00:00
|
|
|
static
|
|
|
|
inline
|
2020-02-07 22:48:22 +00:00
|
|
|
UCHAR
|
2020-03-20 18:19:30 +00:00
|
|
|
NextLFSR(
|
2021-03-04 12:42:42 +00:00
|
|
|
_In_ UCHAR Lfsr,
|
|
|
|
_In_ UCHAR InputBit)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2020-03-20 18:19:30 +00:00
|
|
|
UCHAR NextLfsr = Lfsr >> 1;
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
NextLfsr |= (((Lfsr ^ NextLfsr) ^ InputBit)) << 7;
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
return NextLfsr;
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2024-05-03 14:43:40 +00:00
|
|
|
CODE_SEG("PAGE")
|
2010-04-07 20:19:29 +00:00
|
|
|
VOID
|
|
|
|
SendKey(VOID)
|
|
|
|
{
|
2020-03-20 18:19:30 +00:00
|
|
|
UCHAR i, Lfsr;
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2024-05-03 14:43:40 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
WriteAddress(0x00);
|
|
|
|
WriteAddress(0x00);
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
Lfsr = ISAPNP_LFSR_SEED;
|
|
|
|
for (i = 0; i < 32; i++)
|
|
|
|
{
|
|
|
|
WriteAddress(Lfsr);
|
|
|
|
Lfsr = NextLFSR(Lfsr, 0);
|
|
|
|
}
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2021-03-04 12:43:44 +00:00
|
|
|
CODE_SEG("PAGE")
|
2021-03-20 14:49:57 +00:00
|
|
|
UCHAR
|
2020-03-20 18:19:30 +00:00
|
|
|
PeekByte(
|
2021-03-04 12:42:42 +00:00
|
|
|
_In_ PUCHAR ReadDataPort)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2021-03-20 14:49:57 +00:00
|
|
|
UCHAR i;
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2021-03-04 12:43:44 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
for (i = 0; i < 20; i++)
|
|
|
|
{
|
|
|
|
if (ReadStatus(ReadDataPort) & 0x01)
|
|
|
|
return ReadResourceData(ReadDataPort);
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2021-03-20 14:52:04 +00:00
|
|
|
KeStallExecutionProcessor(1000);
|
2020-03-20 18:19:30 +00:00
|
|
|
}
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
return 0xFF;
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2021-03-04 12:43:44 +00:00
|
|
|
CODE_SEG("PAGE")
|
2010-04-07 20:19:29 +00:00
|
|
|
VOID
|
2020-03-20 18:19:30 +00:00
|
|
|
Peek(
|
2021-03-04 12:42:42 +00:00
|
|
|
_In_ PUCHAR ReadDataPort,
|
|
|
|
_Out_writes_bytes_all_opt_(Length) PVOID Buffer,
|
2021-03-20 14:49:57 +00:00
|
|
|
_In_ USHORT Length)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2021-03-20 14:49:57 +00:00
|
|
|
USHORT i;
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2021-03-04 12:43:44 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
for (i = 0; i < Length; i++)
|
|
|
|
{
|
2021-03-20 14:49:57 +00:00
|
|
|
UCHAR Byte = PeekByte(ReadDataPort);
|
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
if (Buffer)
|
2021-03-04 12:42:42 +00:00
|
|
|
((PUCHAR)Buffer)[i] = Byte;
|
2020-03-20 18:19:30 +00:00
|
|
|
}
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2021-03-04 12:43:44 +00:00
|
|
|
CODE_SEG("PAGE")
|
2021-03-20 14:49:57 +00:00
|
|
|
UCHAR
|
2020-03-20 18:19:30 +00:00
|
|
|
IsaPnpChecksum(
|
2021-03-04 12:42:42 +00:00
|
|
|
_In_ PISAPNP_IDENTIFIER Identifier)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2021-03-04 12:42:42 +00:00
|
|
|
UCHAR i, j, Lfsr;
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2021-03-04 12:43:44 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
Lfsr = ISAPNP_LFSR_SEED;
|
2021-03-04 12:42:42 +00:00
|
|
|
for (i = 0; i < FIELD_OFFSET(ISAPNP_IDENTIFIER, Checksum); i++)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2021-03-04 12:42:42 +00:00
|
|
|
UCHAR Byte = ((PUCHAR)Identifier)[i];
|
|
|
|
|
|
|
|
for (j = 0; j < RTL_BITS_OF(Byte); j++)
|
2020-03-20 18:19:30 +00:00
|
|
|
{
|
|
|
|
Lfsr = NextLFSR(Lfsr, Byte);
|
|
|
|
Byte >>= 1;
|
|
|
|
}
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
return Lfsr;
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2021-03-04 12:43:44 +00:00
|
|
|
CODE_SEG("PAGE")
|
2021-03-20 14:50:34 +00:00
|
|
|
VOID
|
|
|
|
IsaPnpExtractAscii(
|
|
|
|
_Out_writes_all_(3) PUCHAR Buffer,
|
|
|
|
_In_ USHORT CompressedData)
|
|
|
|
{
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
Buffer[0] = ((CompressedData >> 2) & 0x1F) + 'A' - 1;
|
|
|
|
Buffer[1] = (((CompressedData & 0x3) << 3) | ((CompressedData >> 13) & 0x7)) + 'A' - 1;
|
|
|
|
Buffer[2] = ((CompressedData >> 8) & 0x1F) + 'A' - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
CODE_SEG("PAGE")
|
|
|
|
NTSTATUS
|
2020-03-21 22:08:00 +00:00
|
|
|
ReadTags(
|
2021-03-04 12:42:42 +00:00
|
|
|
_In_ PUCHAR ReadDataPort,
|
2021-03-20 14:50:34 +00:00
|
|
|
_Out_writes_(ISAPNP_MAX_RESOURCEDATA) PUCHAR Buffer,
|
|
|
|
_In_ ULONG MaxLength,
|
2024-05-03 14:39:26 +00:00
|
|
|
_Out_ PUSHORT MaxLogDev,
|
|
|
|
_Out_ PULONG MaxTagsPerDevice)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2024-05-03 14:39:26 +00:00
|
|
|
ULONG TagCount = 0;
|
|
|
|
|
2021-03-04 12:43:44 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
2021-03-20 14:50:34 +00:00
|
|
|
*MaxLogDev = 0;
|
2024-05-03 14:39:26 +00:00
|
|
|
*MaxTagsPerDevice = 0;
|
2020-03-21 22:08:00 +00:00
|
|
|
|
|
|
|
while (TRUE)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2021-03-20 14:50:34 +00:00
|
|
|
UCHAR Tag;
|
|
|
|
USHORT TagLen;
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
++TagCount;
|
|
|
|
|
2021-03-20 14:50:34 +00:00
|
|
|
if (MaxLength < 1)
|
2024-05-03 14:39:26 +00:00
|
|
|
{
|
|
|
|
DPRINT("Too small tag\n");
|
2021-03-20 14:50:34 +00:00
|
|
|
return STATUS_BUFFER_OVERFLOW;
|
2024-05-03 14:39:26 +00:00
|
|
|
}
|
2021-03-20 14:50:34 +00:00
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
Tag = PeekByte(ReadDataPort);
|
2021-03-20 14:50:34 +00:00
|
|
|
if (Tag == 0)
|
|
|
|
{
|
|
|
|
DPRINT("Invalid tag\n");
|
|
|
|
return STATUS_INVALID_PARAMETER_1;
|
|
|
|
}
|
|
|
|
*Buffer++ = Tag;
|
|
|
|
--MaxLength;
|
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
if (ISAPNP_IS_SMALL_TAG(Tag))
|
|
|
|
{
|
|
|
|
TagLen = ISAPNP_SMALL_TAG_LEN(Tag);
|
|
|
|
Tag = ISAPNP_SMALL_TAG_NAME(Tag);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-20 14:50:34 +00:00
|
|
|
UCHAR Temp[2];
|
|
|
|
|
|
|
|
if (MaxLength < sizeof(Temp))
|
2024-05-03 14:39:26 +00:00
|
|
|
{
|
|
|
|
DPRINT("Too small tag\n");
|
2021-03-20 14:50:34 +00:00
|
|
|
return STATUS_BUFFER_OVERFLOW;
|
2024-05-03 14:39:26 +00:00
|
|
|
}
|
2021-03-20 14:50:34 +00:00
|
|
|
|
|
|
|
Peek(ReadDataPort, &Temp, sizeof(Temp));
|
|
|
|
*Buffer++ = Temp[0];
|
|
|
|
*Buffer++ = Temp[1];
|
|
|
|
MaxLength -= sizeof(Temp);
|
|
|
|
|
|
|
|
TagLen = Temp[0] + (Temp[1] << 8);
|
2020-03-20 18:19:30 +00:00
|
|
|
Tag = ISAPNP_LARGE_TAG_NAME(Tag);
|
|
|
|
}
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2021-03-20 14:50:34 +00:00
|
|
|
if (Tag == 0xFF && TagLen == 0xFFFF)
|
2020-03-21 22:08:00 +00:00
|
|
|
{
|
2021-03-20 14:50:34 +00:00
|
|
|
DPRINT("Invalid tag\n");
|
|
|
|
return STATUS_INVALID_PARAMETER_2;
|
2020-03-21 22:08:00 +00:00
|
|
|
}
|
2021-03-20 14:50:34 +00:00
|
|
|
|
|
|
|
if (TagLen > MaxLength)
|
2024-05-03 14:39:26 +00:00
|
|
|
{
|
|
|
|
DPRINT("Too large resource data structure\n");
|
2021-03-20 14:50:34 +00:00
|
|
|
return STATUS_BUFFER_OVERFLOW;
|
2024-05-03 14:39:26 +00:00
|
|
|
}
|
2021-03-20 14:50:34 +00:00
|
|
|
|
|
|
|
Peek(ReadDataPort, Buffer, TagLen);
|
|
|
|
MaxLength -= TagLen;
|
|
|
|
Buffer += TagLen;
|
|
|
|
|
|
|
|
if (Tag == ISAPNP_TAG_LOGDEVID)
|
2024-05-03 14:39:26 +00:00
|
|
|
{
|
|
|
|
/* Attempt to guess the allocation size based on the tags available */
|
|
|
|
*MaxTagsPerDevice = max(*MaxTagsPerDevice, TagCount);
|
|
|
|
TagCount = 0;
|
2021-03-20 14:50:34 +00:00
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
(*MaxLogDev)++;
|
|
|
|
}
|
|
|
|
else if (Tag == ISAPNP_TAG_END)
|
|
|
|
{
|
|
|
|
*MaxTagsPerDevice = max(*MaxTagsPerDevice, TagCount);
|
2021-03-20 14:50:34 +00:00
|
|
|
break;
|
2024-05-03 14:39:26 +00:00
|
|
|
}
|
2021-03-20 14:50:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
CODE_SEG("PAGE")
|
|
|
|
VOID
|
|
|
|
FreeLogicalDevice(
|
|
|
|
_In_ __drv_freesMem(Mem) PISAPNP_LOGICAL_DEVICE LogDevice)
|
|
|
|
{
|
|
|
|
PLIST_ENTRY Entry;
|
|
|
|
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
if (LogDevice->FriendlyName)
|
|
|
|
ExFreePoolWithTag(LogDevice->FriendlyName, TAG_ISAPNP);
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
if (LogDevice->Resources)
|
|
|
|
ExFreePoolWithTag(LogDevice->Resources, TAG_ISAPNP);
|
2021-03-20 14:50:34 +00:00
|
|
|
|
|
|
|
Entry = LogDevice->CompatibleIdList.Flink;
|
|
|
|
while (Entry != &LogDevice->CompatibleIdList)
|
|
|
|
{
|
|
|
|
PISAPNP_COMPATIBLE_ID_ENTRY CompatibleId =
|
|
|
|
CONTAINING_RECORD(Entry, ISAPNP_COMPATIBLE_ID_ENTRY, IdLink);
|
|
|
|
|
|
|
|
RemoveEntryList(&CompatibleId->IdLink);
|
|
|
|
|
|
|
|
Entry = Entry->Flink;
|
|
|
|
|
|
|
|
ExFreePoolWithTag(CompatibleId, TAG_ISAPNP);
|
|
|
|
}
|
|
|
|
|
|
|
|
ExFreePoolWithTag(LogDevice, TAG_ISAPNP);
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
CODE_SEG("PAGE")
|
|
|
|
NTSTATUS
|
|
|
|
ParseTags(
|
|
|
|
_In_ PUCHAR ResourceData,
|
|
|
|
_In_ USHORT LogDevToParse,
|
|
|
|
_Inout_ PISAPNP_LOGICAL_DEVICE LogDevice)
|
|
|
|
{
|
|
|
|
USHORT LogDev;
|
2024-05-03 14:39:26 +00:00
|
|
|
ISAPNP_DEPENDENT_FUNCTION_STATE DfState = dfNotStarted;
|
|
|
|
PISAPNP_RESOURCE Resource = LogDevice->Resources;
|
2021-03-20 14:50:34 +00:00
|
|
|
PUCHAR IdStrPos = NULL;
|
|
|
|
USHORT IdStrLen = 0;
|
|
|
|
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
DPRINT("%s for CSN %u, LDN %u\n", __FUNCTION__, LogDevice->CSN, LogDevice->LDN);
|
|
|
|
|
|
|
|
LogDev = LogDevToParse + 1;
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
UCHAR Tag;
|
|
|
|
USHORT TagLen;
|
|
|
|
|
|
|
|
Tag = *ResourceData++;
|
|
|
|
|
|
|
|
if (ISAPNP_IS_SMALL_TAG(Tag))
|
2020-03-22 22:23:04 +00:00
|
|
|
{
|
2021-03-20 14:50:34 +00:00
|
|
|
TagLen = ISAPNP_SMALL_TAG_LEN(Tag);
|
|
|
|
Tag = ISAPNP_SMALL_TAG_NAME(Tag);
|
2020-03-22 22:23:04 +00:00
|
|
|
}
|
2021-03-20 14:50:34 +00:00
|
|
|
else
|
2020-03-21 22:08:00 +00:00
|
|
|
{
|
2021-03-20 14:50:34 +00:00
|
|
|
TagLen = *ResourceData++;
|
|
|
|
TagLen += *ResourceData++ << 8;
|
|
|
|
|
|
|
|
Tag = ISAPNP_LARGE_TAG_NAME(Tag);
|
2020-03-21 22:08:00 +00:00
|
|
|
}
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2021-03-20 14:50:34 +00:00
|
|
|
switch (Tag)
|
2020-03-21 22:08:00 +00:00
|
|
|
{
|
2021-03-20 14:50:34 +00:00
|
|
|
case ISAPNP_TAG_LOGDEVID:
|
2020-03-21 22:08:00 +00:00
|
|
|
{
|
2021-03-20 14:50:34 +00:00
|
|
|
ISAPNP_LOGDEVID Temp;
|
|
|
|
|
|
|
|
--LogDev;
|
|
|
|
|
|
|
|
if (LogDev != 0 ||
|
|
|
|
(TagLen > sizeof(ISAPNP_LOGDEVID) ||
|
|
|
|
TagLen < (sizeof(ISAPNP_LOGDEVID) - 1)))
|
|
|
|
{
|
|
|
|
goto SkipTag;
|
|
|
|
}
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
RtlCopyMemory(&Temp, ResourceData, TagLen);
|
2021-03-20 14:50:34 +00:00
|
|
|
ResourceData += TagLen;
|
|
|
|
|
|
|
|
DPRINT("Found tag 0x%X (len %u)\n"
|
|
|
|
" VendorId 0x%04X\n"
|
|
|
|
" ProdId 0x%04X\n",
|
|
|
|
Tag, TagLen,
|
|
|
|
Temp.VendorId,
|
|
|
|
Temp.ProdId);
|
|
|
|
|
|
|
|
IsaPnpExtractAscii(LogDevice->LogVendorId, Temp.VendorId);
|
|
|
|
LogDevice->LogProdId = RtlUshortByteSwap(Temp.ProdId);
|
|
|
|
|
|
|
|
break;
|
2020-03-21 22:08:00 +00:00
|
|
|
}
|
2021-03-20 14:50:34 +00:00
|
|
|
|
|
|
|
case ISAPNP_TAG_COMPATDEVID:
|
2020-03-21 22:08:00 +00:00
|
|
|
{
|
2021-03-20 14:50:34 +00:00
|
|
|
ISAPNP_COMPATID Temp;
|
|
|
|
PISAPNP_COMPATIBLE_ID_ENTRY CompatibleId;
|
|
|
|
|
|
|
|
if (LogDev != 0 || TagLen != sizeof(ISAPNP_COMPATID))
|
|
|
|
goto SkipTag;
|
|
|
|
|
|
|
|
CompatibleId = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
sizeof(ISAPNP_COMPATIBLE_ID_ENTRY),
|
|
|
|
TAG_ISAPNP);
|
|
|
|
if (!CompatibleId)
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
RtlCopyMemory(&Temp, ResourceData, TagLen);
|
2021-03-20 14:50:34 +00:00
|
|
|
ResourceData += TagLen;
|
|
|
|
|
|
|
|
DPRINT("Found tag 0x%X (len %u)\n"
|
|
|
|
" VendorId 0x%04X\n"
|
|
|
|
" ProdId 0x%04X\n",
|
|
|
|
Tag, TagLen,
|
|
|
|
Temp.VendorId,
|
|
|
|
Temp.ProdId);
|
|
|
|
|
|
|
|
IsaPnpExtractAscii(CompatibleId->VendorId, Temp.VendorId);
|
|
|
|
CompatibleId->ProdId = RtlUshortByteSwap(Temp.ProdId);
|
|
|
|
|
|
|
|
InsertTailList(&LogDevice->CompatibleIdList, &CompatibleId->IdLink);
|
|
|
|
|
|
|
|
break;
|
2020-03-21 22:08:00 +00:00
|
|
|
}
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2021-03-20 14:50:34 +00:00
|
|
|
case ISAPNP_TAG_IRQ:
|
|
|
|
{
|
|
|
|
PISAPNP_IRQ_DESCRIPTION Description;
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
if (LogDev != 0)
|
2021-03-20 14:50:34 +00:00
|
|
|
goto SkipTag;
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
if (TagLen > sizeof(ISAPNP_IRQ_DESCRIPTION) ||
|
|
|
|
TagLen < (sizeof(ISAPNP_IRQ_DESCRIPTION) - 1))
|
2021-03-20 14:50:34 +00:00
|
|
|
{
|
2024-05-03 14:39:26 +00:00
|
|
|
DPRINT1("Invalid tag %x\n", ISAPNP_TAG_IRQ);
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
2021-03-20 14:50:34 +00:00
|
|
|
}
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
Resource->Type = ISAPNP_RESOURCE_TYPE_IRQ;
|
|
|
|
Description = &Resource->IrqDescription;
|
|
|
|
++Resource;
|
2021-03-20 14:50:34 +00:00
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
RtlCopyMemory(Description, ResourceData, TagLen);
|
2021-03-20 14:50:34 +00:00
|
|
|
ResourceData += TagLen;
|
|
|
|
|
|
|
|
if (TagLen == (sizeof(ISAPNP_IRQ_DESCRIPTION) - 1))
|
|
|
|
Description->Information = 0x01;
|
|
|
|
|
|
|
|
DPRINT("Found tag 0x%X (len %u)\n"
|
|
|
|
" Mask 0x%X\n"
|
|
|
|
" Information 0x%X\n",
|
|
|
|
Tag, TagLen,
|
|
|
|
Description->Mask,
|
|
|
|
Description->Information);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ISAPNP_TAG_DMA:
|
|
|
|
{
|
|
|
|
PISAPNP_DMA_DESCRIPTION Description;
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
if (LogDev != 0)
|
2021-03-20 14:50:34 +00:00
|
|
|
goto SkipTag;
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
if (TagLen != sizeof(ISAPNP_DMA_DESCRIPTION))
|
2021-03-20 14:50:34 +00:00
|
|
|
{
|
2024-05-03 14:39:26 +00:00
|
|
|
DPRINT1("Invalid tag %x\n", ISAPNP_TAG_DMA);
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
2021-03-20 14:50:34 +00:00
|
|
|
}
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
Resource->Type = ISAPNP_RESOURCE_TYPE_DMA;
|
|
|
|
Description = &Resource->DmaDescription;
|
|
|
|
++Resource;
|
2021-03-20 14:50:34 +00:00
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
RtlCopyMemory(Description, ResourceData, TagLen);
|
2021-03-20 14:50:34 +00:00
|
|
|
ResourceData += TagLen;
|
|
|
|
|
|
|
|
DPRINT("Found tag 0x%X (len %u)\n"
|
|
|
|
" Mask 0x%X\n"
|
|
|
|
" Information 0x%X\n",
|
|
|
|
Tag, TagLen,
|
|
|
|
Description->Mask,
|
|
|
|
Description->Information);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ISAPNP_TAG_STARTDEP:
|
|
|
|
{
|
2024-05-03 14:39:26 +00:00
|
|
|
if (LogDev != 0)
|
2021-03-20 14:50:34 +00:00
|
|
|
goto SkipTag;
|
2024-05-03 14:39:26 +00:00
|
|
|
|
|
|
|
if (TagLen > 1)
|
|
|
|
{
|
|
|
|
DPRINT1("Invalid tag %x\n", ISAPNP_TAG_STARTDEP);
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
2021-03-20 14:50:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (DfState == dfNotStarted)
|
|
|
|
{
|
|
|
|
DfState = dfStarted;
|
|
|
|
}
|
2024-05-03 14:39:26 +00:00
|
|
|
else if (DfState != dfStarted)
|
2021-03-20 14:50:34 +00:00
|
|
|
{
|
|
|
|
goto SkipTag;
|
|
|
|
}
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
Resource->Type = ISAPNP_RESOURCE_TYPE_START_DEPENDENT;
|
|
|
|
++Resource;
|
2021-03-20 14:50:34 +00:00
|
|
|
|
|
|
|
if (TagLen != 1)
|
|
|
|
{
|
2024-05-03 14:39:26 +00:00
|
|
|
Resource->Priority = 1;
|
2021-03-20 14:50:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-05-03 14:39:26 +00:00
|
|
|
RtlCopyMemory(&Resource->Priority, ResourceData, TagLen);
|
2021-03-20 14:50:34 +00:00
|
|
|
ResourceData += TagLen;
|
|
|
|
}
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
DPRINT("*** Start dependent set, priority %u ***\n",
|
|
|
|
Resource->Priority);
|
2021-03-20 14:50:34 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ISAPNP_TAG_ENDDEP:
|
|
|
|
{
|
|
|
|
if (LogDev != 0 || DfState != dfStarted)
|
|
|
|
goto SkipTag;
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
Resource->Type = ISAPNP_RESOURCE_TYPE_END_DEPENDENT;
|
|
|
|
++Resource;
|
|
|
|
|
2021-03-20 14:50:34 +00:00
|
|
|
DfState = dfDone;
|
|
|
|
|
|
|
|
ResourceData += TagLen;
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
DPRINT("*** End of dependent set ***\n");
|
2021-03-20 14:50:34 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ISAPNP_TAG_IOPORT:
|
|
|
|
{
|
|
|
|
PISAPNP_IO_DESCRIPTION Description;
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
if (LogDev != 0)
|
2021-03-20 14:50:34 +00:00
|
|
|
goto SkipTag;
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
if (TagLen != sizeof(ISAPNP_IO_DESCRIPTION))
|
2021-03-20 14:50:34 +00:00
|
|
|
{
|
2024-05-03 14:39:26 +00:00
|
|
|
DPRINT1("Invalid tag %x\n", ISAPNP_TAG_IOPORT);
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
2021-03-20 14:50:34 +00:00
|
|
|
}
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
Resource->Type = ISAPNP_RESOURCE_TYPE_IO;
|
|
|
|
Description = &Resource->IoDescription;
|
|
|
|
++Resource;
|
2021-03-20 14:50:34 +00:00
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
RtlCopyMemory(Description, ResourceData, TagLen);
|
2021-03-20 14:50:34 +00:00
|
|
|
ResourceData += TagLen;
|
|
|
|
|
|
|
|
DPRINT("Found tag 0x%X (len %u)\n"
|
|
|
|
" Information 0x%X\n"
|
|
|
|
" Minimum 0x%X\n"
|
|
|
|
" Maximum 0x%X\n"
|
|
|
|
" Alignment 0x%X\n"
|
|
|
|
" Length 0x%X\n",
|
|
|
|
Tag, TagLen,
|
|
|
|
Description->Information,
|
|
|
|
Description->Minimum,
|
|
|
|
Description->Maximum,
|
|
|
|
Description->Alignment,
|
|
|
|
Description->Length);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ISAPNP_TAG_FIXEDIO:
|
|
|
|
{
|
|
|
|
ISAPNP_FIXED_IO_DESCRIPTION Temp;
|
|
|
|
PISAPNP_IO_DESCRIPTION Description;
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
if (LogDev != 0)
|
2021-03-20 14:50:34 +00:00
|
|
|
goto SkipTag;
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
if (TagLen != sizeof(ISAPNP_FIXED_IO_DESCRIPTION))
|
2021-03-20 14:50:34 +00:00
|
|
|
{
|
2024-05-03 14:39:26 +00:00
|
|
|
DPRINT1("Invalid tag %x\n", ISAPNP_TAG_FIXEDIO);
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
2021-03-20 14:50:34 +00:00
|
|
|
}
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
Resource->Type = ISAPNP_RESOURCE_TYPE_IO;
|
|
|
|
Description = &Resource->IoDescription;
|
|
|
|
++Resource;
|
2021-03-20 14:50:34 +00:00
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
RtlCopyMemory(&Temp, ResourceData, TagLen);
|
2021-03-20 14:50:34 +00:00
|
|
|
ResourceData += TagLen;
|
|
|
|
|
2024-05-03 14:01:47 +00:00
|
|
|
/* Save the address bits [0:9] */
|
|
|
|
Temp.IoBase &= ((1 << 10) - 1);
|
|
|
|
|
2021-03-20 14:50:34 +00:00
|
|
|
Description->Information = 0;
|
|
|
|
Description->Minimum =
|
|
|
|
Description->Maximum = Temp.IoBase;
|
|
|
|
Description->Alignment = 1;
|
|
|
|
Description->Length = Temp.Length;
|
|
|
|
|
|
|
|
DPRINT("Found tag 0x%X (len %u)\n"
|
|
|
|
" IoBase 0x%X\n"
|
|
|
|
" Length 0x%X\n",
|
|
|
|
Tag, TagLen,
|
|
|
|
Temp.IoBase,
|
|
|
|
Temp.Length);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ISAPNP_TAG_END:
|
|
|
|
{
|
|
|
|
if (IdStrPos)
|
|
|
|
{
|
|
|
|
PSTR End;
|
|
|
|
|
|
|
|
LogDevice->FriendlyName = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
IdStrLen + sizeof(ANSI_NULL),
|
|
|
|
TAG_ISAPNP);
|
|
|
|
if (!LogDevice->FriendlyName)
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
RtlCopyMemory(LogDevice->FriendlyName, IdStrPos, IdStrLen);
|
2021-03-20 14:50:34 +00:00
|
|
|
|
|
|
|
End = LogDevice->FriendlyName + IdStrLen - 1;
|
|
|
|
while (End > LogDevice->FriendlyName && *End == ' ')
|
|
|
|
{
|
|
|
|
--End;
|
|
|
|
}
|
|
|
|
*++End = ANSI_NULL;
|
|
|
|
}
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
Resource->Type = ISAPNP_RESOURCE_TYPE_END;
|
|
|
|
|
2021-03-20 14:50:34 +00:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ISAPNP_TAG_MEMRANGE:
|
|
|
|
{
|
|
|
|
PISAPNP_MEMRANGE_DESCRIPTION Description;
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
if (LogDev != 0)
|
2021-03-20 14:50:34 +00:00
|
|
|
goto SkipTag;
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
if (TagLen != sizeof(ISAPNP_MEMRANGE_DESCRIPTION))
|
2021-03-20 14:50:34 +00:00
|
|
|
{
|
2024-05-03 14:39:26 +00:00
|
|
|
DPRINT1("Invalid tag %x\n", ISAPNP_TAG_MEMRANGE);
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
2021-03-20 14:50:34 +00:00
|
|
|
}
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
LogDevice->Flags |= ISAPNP_HAS_MEM24_DECODER;
|
|
|
|
ASSERT(!(LogDevice->Flags & ISAPNP_HAS_MEM32_DECODER));
|
2021-03-20 14:50:34 +00:00
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
Resource->Type = ISAPNP_RESOURCE_TYPE_MEMRANGE;
|
|
|
|
Description = &Resource->MemRangeDescription;
|
|
|
|
++Resource;
|
|
|
|
|
|
|
|
RtlCopyMemory(Description, ResourceData, TagLen);
|
2021-03-20 14:50:34 +00:00
|
|
|
ResourceData += TagLen;
|
|
|
|
|
|
|
|
DPRINT("Found tag 0x%X (len %u)\n"
|
|
|
|
" Information 0x%X\n"
|
|
|
|
" Minimum 0x%X\n"
|
|
|
|
" Maximum 0x%X\n"
|
|
|
|
" Alignment 0x%X\n"
|
|
|
|
" Length 0x%X\n",
|
|
|
|
Tag, TagLen,
|
|
|
|
Description->Information,
|
|
|
|
Description->Minimum,
|
|
|
|
Description->Maximum,
|
|
|
|
Description->Alignment,
|
|
|
|
Description->Length);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ISAPNP_TAG_ANSISTR:
|
|
|
|
{
|
|
|
|
/* If logical device identifier is not supplied, use card identifier */
|
|
|
|
if (LogDev == LogDevToParse + 1 || LogDev == 0)
|
|
|
|
{
|
|
|
|
IdStrPos = ResourceData;
|
|
|
|
IdStrLen = TagLen;
|
|
|
|
|
|
|
|
ResourceData += TagLen;
|
|
|
|
|
|
|
|
DPRINT("Found tag 0x%X (len %u)\n"
|
|
|
|
" '%.*s'\n",
|
|
|
|
Tag, TagLen,
|
|
|
|
IdStrLen,
|
|
|
|
IdStrPos);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
goto SkipTag;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ISAPNP_TAG_MEM32RANGE:
|
|
|
|
{
|
|
|
|
PISAPNP_MEMRANGE32_DESCRIPTION Description;
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
if (LogDev != 0)
|
2021-03-20 14:50:34 +00:00
|
|
|
goto SkipTag;
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
if (TagLen != sizeof(ISAPNP_MEMRANGE32_DESCRIPTION))
|
2021-03-20 14:50:34 +00:00
|
|
|
{
|
2024-05-03 14:39:26 +00:00
|
|
|
DPRINT1("Invalid tag %x\n", ISAPNP_TAG_MEM32RANGE);
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
2021-03-20 14:50:34 +00:00
|
|
|
}
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
LogDevice->Flags |= ISAPNP_HAS_MEM32_DECODER;
|
|
|
|
ASSERT(!(LogDevice->Flags & ISAPNP_HAS_MEM24_DECODER));
|
|
|
|
|
|
|
|
Resource->Type = ISAPNP_RESOURCE_TYPE_MEMRANGE32;
|
|
|
|
Description = &Resource->MemRange32Description;
|
|
|
|
++Resource;
|
2021-03-20 14:50:34 +00:00
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
RtlCopyMemory(Description, ResourceData, TagLen);
|
2021-03-20 14:50:34 +00:00
|
|
|
ResourceData += TagLen;
|
|
|
|
|
|
|
|
DPRINT("Found tag 0x%X (len %u)\n"
|
|
|
|
" Information 0x%X\n"
|
|
|
|
" Minimum 0x%08lX\n"
|
|
|
|
" Maximum 0x%08lX\n"
|
|
|
|
" Alignment 0x%08lX\n"
|
|
|
|
" Length 0x%08lX\n",
|
|
|
|
Tag, TagLen,
|
|
|
|
Description->Information,
|
|
|
|
Description->Minimum,
|
|
|
|
Description->Maximum,
|
|
|
|
Description->Alignment,
|
|
|
|
Description->Length);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ISAPNP_TAG_FIXEDMEM32RANGE:
|
|
|
|
{
|
|
|
|
ISAPNP_FIXEDMEMRANGE_DESCRIPTION Temp;
|
|
|
|
PISAPNP_MEMRANGE32_DESCRIPTION Description;
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
if (LogDev != 0)
|
2021-03-20 14:50:34 +00:00
|
|
|
goto SkipTag;
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
if (TagLen != sizeof(ISAPNP_FIXEDMEMRANGE_DESCRIPTION))
|
2021-03-20 14:50:34 +00:00
|
|
|
{
|
2024-05-03 14:39:26 +00:00
|
|
|
DPRINT1("Invalid tag %x\n", ISAPNP_TAG_FIXEDMEM32RANGE);
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
2021-03-20 14:50:34 +00:00
|
|
|
}
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
LogDevice->Flags |= ISAPNP_HAS_MEM32_DECODER;
|
|
|
|
ASSERT(!(LogDevice->Flags & ISAPNP_HAS_MEM24_DECODER));
|
|
|
|
|
|
|
|
Resource->Type = ISAPNP_RESOURCE_TYPE_MEMRANGE32;
|
|
|
|
Description = &Resource->MemRange32Description;
|
|
|
|
++Resource;
|
2021-03-20 14:50:34 +00:00
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
RtlCopyMemory(&Temp, ResourceData, TagLen);
|
2021-03-20 14:50:34 +00:00
|
|
|
ResourceData += TagLen;
|
|
|
|
|
|
|
|
Description->Information = Temp.Information;
|
|
|
|
Description->Minimum =
|
|
|
|
Description->Maximum = Temp.MemoryBase;
|
|
|
|
Description->Alignment = 1;
|
|
|
|
Description->Length = Temp.Length;
|
|
|
|
|
|
|
|
DPRINT("Found tag 0x%X (len %u)\n"
|
|
|
|
" Information 0x%X\n"
|
|
|
|
" MemoryBase 0x%08lX\n"
|
|
|
|
" Length 0x%08lX\n",
|
|
|
|
Tag, TagLen,
|
|
|
|
Temp.Information,
|
|
|
|
Temp.MemoryBase,
|
|
|
|
Temp.Length);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkipTag:
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
if (LogDev == 0)
|
|
|
|
DPRINT("Found unknown tag 0x%X (len %u)\n", Tag, TagLen);
|
|
|
|
|
|
|
|
/* We don't want to read informations on this
|
|
|
|
* logical device, or we don't know the tag. */
|
|
|
|
ResourceData += TagLen;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
2021-03-20 14:51:05 +00:00
|
|
|
static
|
|
|
|
CODE_SEG("PAGE")
|
|
|
|
BOOLEAN
|
|
|
|
ReadCurrentResources(
|
|
|
|
_In_ PUCHAR ReadDataPort,
|
|
|
|
_Inout_ PISAPNP_LOGICAL_DEVICE LogDevice)
|
|
|
|
{
|
|
|
|
UCHAR i;
|
|
|
|
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
DPRINT("%s for CSN %u, LDN %u\n", __FUNCTION__, LogDevice->CSN, LogDevice->LDN);
|
|
|
|
|
|
|
|
WriteLogicalDeviceNumber(LogDevice->LDN);
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
/* If the device is not activated by BIOS then the device has no boot resources */
|
2021-03-20 14:51:05 +00:00
|
|
|
if (!(ReadByte(ReadDataPort, ISAPNP_ACTIVATE) & 1))
|
|
|
|
{
|
|
|
|
LogDevice->Flags &= ~ISAPNP_HAS_RESOURCES;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < RTL_NUMBER_OF(LogDevice->Io); i++)
|
|
|
|
{
|
|
|
|
LogDevice->Io[i].CurrentBase = ReadIoBase(ReadDataPort, i);
|
|
|
|
|
|
|
|
/* Skip empty descriptors */
|
|
|
|
if (!LogDevice->Io[i].CurrentBase)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (i = 0; i < RTL_NUMBER_OF(LogDevice->Irq); i++)
|
|
|
|
{
|
|
|
|
LogDevice->Irq[i].CurrentNo = ReadIrqNo(ReadDataPort, i);
|
|
|
|
|
|
|
|
if (!LogDevice->Irq[i].CurrentNo)
|
|
|
|
break;
|
|
|
|
|
|
|
|
LogDevice->Irq[i].CurrentType = ReadIrqType(ReadDataPort, i);
|
|
|
|
}
|
|
|
|
for (i = 0; i < RTL_NUMBER_OF(LogDevice->Dma); i++)
|
|
|
|
{
|
|
|
|
LogDevice->Dma[i].CurrentChannel = ReadDmaChannel(ReadDataPort, i);
|
|
|
|
|
2024-05-03 14:42:21 +00:00
|
|
|
if (LogDevice->Dma[i].CurrentChannel == DMACHANNEL_NONE)
|
2021-03-20 14:51:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (i = 0; i < RTL_NUMBER_OF(LogDevice->MemRange); i++)
|
|
|
|
{
|
|
|
|
LogDevice->MemRange[i].CurrentBase = ReadMemoryBase(ReadDataPort, i) << 8;
|
|
|
|
|
|
|
|
if (!LogDevice->MemRange[i].CurrentBase)
|
|
|
|
break;
|
|
|
|
|
|
|
|
LogDevice->MemRange[i].CurrentLength = ReadMemoryLimit(ReadDataPort, i) << 8;
|
|
|
|
|
|
|
|
if (ReadMemoryControl(ReadDataPort, i) & MEMORY_UPPER_LIMIT)
|
|
|
|
{
|
|
|
|
LogDevice->MemRange[i].CurrentLength -= LogDevice->MemRange[i].CurrentBase;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LogDevice->MemRange[i].CurrentLength =
|
|
|
|
RANGE_LENGTH_TO_LENGTH(LogDevice->MemRange[i].CurrentLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0; i < RTL_NUMBER_OF(LogDevice->MemRange32); i++)
|
|
|
|
{
|
|
|
|
LogDevice->MemRange32[i].CurrentBase = ReadMemoryBase32(ReadDataPort, i);
|
|
|
|
|
|
|
|
if (!LogDevice->MemRange32[i].CurrentBase)
|
|
|
|
break;
|
|
|
|
|
|
|
|
LogDevice->MemRange32[i].CurrentLength = ReadMemoryLimit32(ReadDataPort, i);
|
|
|
|
|
|
|
|
if (ReadMemoryControl32(ReadDataPort, i) & MEMORY_UPPER_LIMIT)
|
|
|
|
{
|
|
|
|
LogDevice->MemRange32[i].CurrentLength -= LogDevice->MemRange32[i].CurrentBase;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LogDevice->MemRange32[i].CurrentLength =
|
|
|
|
RANGE_LENGTH_TO_LENGTH(LogDevice->MemRange32[i].CurrentLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LogDevice->Flags |= ISAPNP_HAS_RESOURCES;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-03-20 14:53:54 +00:00
|
|
|
static
|
|
|
|
CODE_SEG("PAGE")
|
|
|
|
VOID
|
2024-05-03 14:42:21 +00:00
|
|
|
IsaProgramIoDecoder(
|
|
|
|
_In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor,
|
|
|
|
_In_ UCHAR Index)
|
2021-03-20 14:53:54 +00:00
|
|
|
{
|
|
|
|
PAGED_CODE();
|
|
|
|
|
2024-05-03 14:42:21 +00:00
|
|
|
ASSERT(Descriptor->u.Port.Start.QuadPart <= 0xFFFF);
|
2021-03-20 14:53:54 +00:00
|
|
|
|
2024-05-03 14:42:21 +00:00
|
|
|
WriteWord(ISAPNP_IOBASE(Index), Descriptor->u.Port.Start.LowPart);
|
|
|
|
}
|
2021-03-20 14:53:54 +00:00
|
|
|
|
2024-05-03 14:42:21 +00:00
|
|
|
static
|
|
|
|
CODE_SEG("PAGE")
|
|
|
|
VOID
|
|
|
|
IsaProgramIrqSelect(
|
|
|
|
_In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor,
|
|
|
|
_In_ UCHAR Index)
|
|
|
|
{
|
|
|
|
UCHAR TypeSelect;
|
2021-03-20 14:53:54 +00:00
|
|
|
|
2024-05-03 14:42:21 +00:00
|
|
|
PAGED_CODE();
|
2021-03-20 14:53:54 +00:00
|
|
|
|
2024-05-03 14:42:21 +00:00
|
|
|
ASSERT(Descriptor->u.Interrupt.Level <= 15);
|
2021-03-20 14:53:54 +00:00
|
|
|
|
2024-05-03 14:42:21 +00:00
|
|
|
if (Descriptor->Flags & CM_RESOURCE_INTERRUPT_LATCHED)
|
|
|
|
TypeSelect = IRQTYPE_HIGH_EDGE;
|
|
|
|
else
|
|
|
|
TypeSelect = IRQTYPE_LOW_LEVEL;
|
2021-03-20 14:53:54 +00:00
|
|
|
|
2024-05-03 14:42:21 +00:00
|
|
|
WriteByte(ISAPNP_IRQNO(Index), Descriptor->u.Interrupt.Level);
|
|
|
|
WriteByte(ISAPNP_IRQTYPE(Index), TypeSelect);
|
|
|
|
}
|
2021-03-20 14:53:54 +00:00
|
|
|
|
2024-05-03 14:42:21 +00:00
|
|
|
static
|
|
|
|
CODE_SEG("PAGE")
|
|
|
|
VOID
|
|
|
|
IsaProgramDmaSelect(
|
|
|
|
_In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor,
|
|
|
|
_In_ UCHAR Index)
|
|
|
|
{
|
|
|
|
PAGED_CODE();
|
2021-03-20 14:53:54 +00:00
|
|
|
|
2024-05-03 14:42:21 +00:00
|
|
|
ASSERT(Descriptor->u.Dma.Channel <= 7);
|
2021-03-20 14:53:54 +00:00
|
|
|
|
2024-05-03 14:42:21 +00:00
|
|
|
WriteByte(ISAPNP_DMACHANNEL(Index), Descriptor->u.Dma.Channel);
|
|
|
|
}
|
2021-03-20 14:53:54 +00:00
|
|
|
|
2024-05-03 14:42:21 +00:00
|
|
|
static
|
|
|
|
CODE_SEG("PAGE")
|
|
|
|
NTSTATUS
|
|
|
|
IsaProgramMemoryDecoder(
|
|
|
|
_In_ PUCHAR ReadDataPort,
|
|
|
|
_In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor,
|
|
|
|
_In_ BOOLEAN IsMemory32,
|
|
|
|
_In_ UCHAR Information,
|
|
|
|
_In_ UCHAR Index)
|
|
|
|
{
|
|
|
|
UCHAR MemoryControl;
|
|
|
|
ULONG LengthLimit;
|
2021-03-20 14:53:54 +00:00
|
|
|
|
2024-05-03 14:42:21 +00:00
|
|
|
PAGED_CODE();
|
2021-03-20 14:53:54 +00:00
|
|
|
|
2024-05-03 14:42:21 +00:00
|
|
|
if (!IsMemory32)
|
|
|
|
{
|
|
|
|
/* The 24-bit memory address decoder always considers bits 0:7 to be zeros */
|
|
|
|
if (Descriptor->u.Memory.Start.LowPart & 0xFF)
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
2021-03-20 14:53:54 +00:00
|
|
|
|
2024-05-03 14:42:21 +00:00
|
|
|
if (Information & MEMRANGE_16_BIT_MEMORY_MASK)
|
|
|
|
MemoryControl = MEMORY_USE_16_BIT_DECODER;
|
|
|
|
else
|
|
|
|
MemoryControl = MEMORY_USE_8_BIT_DECODER;
|
2021-03-20 14:53:54 +00:00
|
|
|
|
2024-05-03 14:42:21 +00:00
|
|
|
if (ReadMemoryControl(ReadDataPort, Index) & MEMORY_UPPER_LIMIT)
|
|
|
|
{
|
|
|
|
MemoryControl |= MEMORY_UPPER_LIMIT;
|
|
|
|
LengthLimit = Descriptor->u.Memory.Start.LowPart + Descriptor->u.Memory.Length;
|
2021-03-20 14:53:54 +00:00
|
|
|
}
|
2024-05-03 14:42:21 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
LengthLimit = LENGTH_TO_RANGE_LENGTH(Descriptor->u.Memory.Length);
|
|
|
|
}
|
|
|
|
LengthLimit >>= 8;
|
2021-03-20 14:53:54 +00:00
|
|
|
|
2024-05-03 14:42:21 +00:00
|
|
|
WriteWord(ISAPNP_MEMBASE(Index), Descriptor->u.Memory.Start.LowPart >> 8);
|
|
|
|
WriteByte(ISAPNP_MEMCONTROL(Index), MemoryControl);
|
|
|
|
WriteWord(ISAPNP_MEMLIMIT(Index), LengthLimit);
|
2021-03-20 14:53:54 +00:00
|
|
|
}
|
2024-05-03 14:42:21 +00:00
|
|
|
else
|
2021-03-20 14:53:54 +00:00
|
|
|
{
|
2024-05-03 14:42:21 +00:00
|
|
|
if ((Information & MEMRANGE_16_BIT_MEMORY_MASK) == MEMRANGE_32_BIT_MEMORY_ONLY)
|
|
|
|
MemoryControl = MEMORY_USE_32_BIT_DECODER;
|
|
|
|
else if (Information & MEMRANGE_16_BIT_MEMORY_MASK)
|
|
|
|
MemoryControl = MEMORY_USE_16_BIT_DECODER;
|
|
|
|
else
|
|
|
|
MemoryControl = MEMORY_USE_8_BIT_DECODER;
|
|
|
|
|
|
|
|
if (ReadMemoryControl32(ReadDataPort, Index) & MEMORY_UPPER_LIMIT)
|
|
|
|
{
|
|
|
|
MemoryControl |= MEMORY_UPPER_LIMIT;
|
|
|
|
LengthLimit = Descriptor->u.Memory.Start.LowPart + Descriptor->u.Memory.Length;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LengthLimit = LENGTH_TO_RANGE_LENGTH(Descriptor->u.Memory.Length);
|
|
|
|
}
|
|
|
|
|
|
|
|
WriteDoubleWord(ISAPNP_MEMBASE32(Index), Descriptor->u.Memory.Start.LowPart);
|
|
|
|
WriteByte(ISAPNP_MEMCONTROL32(Index), MemoryControl);
|
|
|
|
WriteDoubleWord(ISAPNP_MEMLIMIT32(Index), LengthLimit);
|
2021-03-20 14:53:54 +00:00
|
|
|
}
|
2024-05-03 14:42:21 +00:00
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2021-03-20 14:53:54 +00:00
|
|
|
}
|
|
|
|
|
2021-03-04 12:43:44 +00:00
|
|
|
CODE_SEG("PAGE")
|
2021-03-20 14:52:40 +00:00
|
|
|
UCHAR
|
|
|
|
IsaHwTryReadDataPort(
|
2021-03-04 12:42:42 +00:00
|
|
|
_In_ PUCHAR ReadDataPort)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2021-03-20 14:52:40 +00:00
|
|
|
ULONG NumberOfRead = 0;
|
|
|
|
UCHAR Csn = 0;
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2021-03-04 12:43:44 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
DPRINT("Setting read data port: 0x%p\n", ReadDataPort);
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
SendKey();
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2021-03-20 14:52:40 +00:00
|
|
|
WriteByte(ISAPNP_CONFIGCONTROL,
|
|
|
|
ISAPNP_CONFIG_RESET_CSN | ISAPNP_CONFIG_WAIT_FOR_KEY);
|
2021-03-20 14:52:04 +00:00
|
|
|
KeStallExecutionProcessor(2000);
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
SendKey();
|
2021-03-20 14:52:40 +00:00
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
Wake(0x00);
|
2021-03-20 14:52:04 +00:00
|
|
|
KeStallExecutionProcessor(1000);
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
SetReadDataPort(ReadDataPort);
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2021-03-20 14:52:40 +00:00
|
|
|
Wake(0x00);
|
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
while (TRUE)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2021-03-20 14:52:40 +00:00
|
|
|
ISAPNP_IDENTIFIER Identifier;
|
|
|
|
UCHAR i, j;
|
|
|
|
BOOLEAN Seen55aa = FALSE;
|
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
EnterIsolationState();
|
2021-03-20 14:52:04 +00:00
|
|
|
KeStallExecutionProcessor(1000);
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
RtlZeroMemory(&Identifier, sizeof(Identifier));
|
|
|
|
|
2021-03-20 14:52:40 +00:00
|
|
|
for (i = 0; i < sizeof(Identifier); i++)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2021-03-20 14:52:40 +00:00
|
|
|
UCHAR Byte = 0;
|
|
|
|
|
|
|
|
for (j = 0; j < RTL_BITS_OF(Byte); j++)
|
2020-03-20 18:19:30 +00:00
|
|
|
{
|
2021-03-20 14:52:40 +00:00
|
|
|
USHORT Data;
|
|
|
|
|
|
|
|
Data = ReadData(ReadDataPort) << 8;
|
2021-03-20 14:52:04 +00:00
|
|
|
KeStallExecutionProcessor(250);
|
2021-03-20 14:52:40 +00:00
|
|
|
Data |= ReadData(ReadDataPort);
|
2021-03-20 14:52:04 +00:00
|
|
|
KeStallExecutionProcessor(250);
|
2021-03-20 14:52:40 +00:00
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
Byte >>= 1;
|
|
|
|
|
2021-03-20 14:52:40 +00:00
|
|
|
if (Data == 0x55AA)
|
2020-03-20 18:19:30 +00:00
|
|
|
{
|
2021-03-20 14:52:40 +00:00
|
|
|
Byte |= 0x80;
|
|
|
|
Seen55aa = TRUE;
|
2020-03-20 18:19:30 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-20 14:52:40 +00:00
|
|
|
|
|
|
|
((PUCHAR)&Identifier)[i] = Byte;
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
2021-03-20 14:52:40 +00:00
|
|
|
++NumberOfRead;
|
|
|
|
|
|
|
|
if (Identifier.Checksum != 0x00 &&
|
|
|
|
Identifier.Checksum != IsaPnpChecksum(&Identifier))
|
2020-03-20 18:19:30 +00:00
|
|
|
{
|
2021-03-20 14:52:40 +00:00
|
|
|
DPRINT("Bad checksum\n");
|
2020-03-20 18:19:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2021-03-20 14:52:40 +00:00
|
|
|
if (!Seen55aa)
|
2020-03-20 18:19:30 +00:00
|
|
|
{
|
2021-03-20 14:52:40 +00:00
|
|
|
DPRINT("Saw no sign of life\n");
|
2020-03-20 18:19:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
Csn++;
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
WriteCsn(Csn);
|
2021-03-20 14:52:04 +00:00
|
|
|
KeStallExecutionProcessor(1000);
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
Wake(0x00);
|
|
|
|
}
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2021-03-20 14:52:40 +00:00
|
|
|
Wake(0x00);
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2021-03-20 14:52:40 +00:00
|
|
|
if (NumberOfRead == 1)
|
2020-03-20 18:19:30 +00:00
|
|
|
{
|
2021-03-20 14:52:40 +00:00
|
|
|
DPRINT("Trying next read data port\n");
|
|
|
|
return 0;
|
2020-03-20 18:19:30 +00:00
|
|
|
}
|
|
|
|
else
|
2021-03-20 14:52:40 +00:00
|
|
|
{
|
|
|
|
DPRINT("Found %u cards at read port 0x%p\n", Csn, ReadDataPort);
|
|
|
|
return Csn;
|
|
|
|
}
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
2021-03-20 14:50:34 +00:00
|
|
|
_Requires_lock_held_(FdoExt->DeviceSyncEvent)
|
2021-03-04 12:43:44 +00:00
|
|
|
CODE_SEG("PAGE")
|
2010-04-07 20:19:29 +00:00
|
|
|
NTSTATUS
|
2021-03-20 14:50:34 +00:00
|
|
|
IsaHwFillDeviceList(
|
2021-03-04 12:42:42 +00:00
|
|
|
_In_ PISAPNP_FDO_EXTENSION FdoExt)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2020-03-20 18:19:30 +00:00
|
|
|
PISAPNP_LOGICAL_DEVICE LogDevice;
|
2021-03-20 14:50:34 +00:00
|
|
|
UCHAR Csn;
|
|
|
|
PLIST_ENTRY Entry;
|
|
|
|
PUCHAR ResourceData;
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2021-03-04 12:43:44 +00:00
|
|
|
PAGED_CODE();
|
2020-03-20 18:19:30 +00:00
|
|
|
ASSERT(FdoExt->ReadDataPort);
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2021-03-20 14:50:34 +00:00
|
|
|
DPRINT("%s for read port 0x%p\n", __FUNCTION__, FdoExt->ReadDataPort);
|
|
|
|
|
|
|
|
ResourceData = ExAllocatePoolWithTag(PagedPool, ISAPNP_MAX_RESOURCEDATA, TAG_ISAPNP);
|
|
|
|
if (!ResourceData)
|
|
|
|
{
|
|
|
|
DPRINT1("Failed to allocate memory for cache data\n");
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Entry = FdoExt->DeviceListHead.Flink;
|
|
|
|
Entry != &FdoExt->DeviceListHead;
|
|
|
|
Entry = Entry->Flink)
|
|
|
|
{
|
|
|
|
LogDevice = CONTAINING_RECORD(Entry, ISAPNP_LOGICAL_DEVICE, DeviceLink);
|
|
|
|
|
|
|
|
LogDevice->Flags &= ~ISAPNP_PRESENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Csn = 1; Csn <= FdoExt->Cards; Csn++)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2021-03-20 14:50:34 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
UCHAR TempId[3], LogDev;
|
|
|
|
ISAPNP_IDENTIFIER Identifier;
|
2024-05-03 14:39:26 +00:00
|
|
|
ULONG MaxTagsPerDevice;
|
2021-03-20 14:50:34 +00:00
|
|
|
USHORT MaxLogDev;
|
|
|
|
|
|
|
|
Wake(Csn);
|
|
|
|
|
|
|
|
Peek(FdoExt->ReadDataPort, &Identifier, sizeof(Identifier));
|
|
|
|
|
|
|
|
IsaPnpExtractAscii(TempId, Identifier.VendorId);
|
|
|
|
Identifier.ProdId = RtlUshortByteSwap(Identifier.ProdId);
|
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
Status = ReadTags(FdoExt->ReadDataPort,
|
|
|
|
ResourceData,
|
|
|
|
ISAPNP_MAX_RESOURCEDATA,
|
|
|
|
&MaxLogDev,
|
|
|
|
&MaxTagsPerDevice);
|
2021-03-20 14:50:34 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("Failed to read tags with status 0x%08lx, CSN %u\n", Status, Csn);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT("Detected ISA PnP device - VID: '%.3s' PID: 0x%04x SN: 0x%08lX\n",
|
|
|
|
TempId, Identifier.ProdId, Identifier.Serial);
|
|
|
|
|
|
|
|
for (LogDev = 0; LogDev < MaxLogDev; LogDev++)
|
2020-03-20 18:19:30 +00:00
|
|
|
{
|
2021-03-20 14:50:34 +00:00
|
|
|
BOOLEAN IsAlreadyEnumerated = FALSE;
|
|
|
|
|
2024-05-03 13:09:23 +00:00
|
|
|
#ifndef UNIT_TEST
|
2021-03-20 14:50:34 +00:00
|
|
|
for (Entry = FdoExt->DeviceListHead.Flink;
|
|
|
|
Entry != &FdoExt->DeviceListHead;
|
|
|
|
Entry = Entry->Flink)
|
|
|
|
{
|
|
|
|
LogDevice = CONTAINING_RECORD(Entry, ISAPNP_LOGICAL_DEVICE, DeviceLink);
|
|
|
|
|
|
|
|
/* This logical device has already been enumerated */
|
|
|
|
if ((LogDevice->SerialNumber == Identifier.Serial) &&
|
|
|
|
(RtlCompareMemory(LogDevice->VendorId, TempId, 3) == 3) &&
|
|
|
|
(LogDevice->ProdId == Identifier.ProdId) &&
|
|
|
|
(LogDevice->LDN == LogDev))
|
|
|
|
{
|
|
|
|
LogDevice->Flags |= ISAPNP_PRESENT;
|
|
|
|
|
|
|
|
/* Assign a new CSN */
|
|
|
|
LogDevice->CSN = Csn;
|
|
|
|
|
|
|
|
if (LogDevice->Pdo)
|
|
|
|
{
|
|
|
|
PISAPNP_PDO_EXTENSION PdoExt = LogDevice->Pdo->DeviceExtension;
|
|
|
|
|
|
|
|
if (PdoExt->Common.State == dsStarted)
|
2021-03-20 14:53:06 +00:00
|
|
|
ActivateDevice(FdoExt->ReadDataPort, LogDev);
|
2021-03-20 14:50:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT("Skip CSN %u, LDN %u\n", LogDevice->CSN, LogDevice->LDN);
|
|
|
|
IsAlreadyEnumerated = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2024-05-03 13:09:23 +00:00
|
|
|
#endif /* UNIT_TEST */
|
2021-03-20 14:50:34 +00:00
|
|
|
|
|
|
|
if (IsAlreadyEnumerated)
|
|
|
|
continue;
|
|
|
|
|
2021-03-04 12:43:19 +00:00
|
|
|
LogDevice = ExAllocatePoolZero(NonPagedPool, sizeof(ISAPNP_LOGICAL_DEVICE), TAG_ISAPNP);
|
2020-03-20 18:19:30 +00:00
|
|
|
if (!LogDevice)
|
2021-03-20 14:50:34 +00:00
|
|
|
{
|
|
|
|
DPRINT1("Failed to allocate logical device!\n");
|
|
|
|
goto Deactivate;
|
|
|
|
}
|
|
|
|
|
|
|
|
InitializeListHead(&LogDevice->CompatibleIdList);
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
LogDevice->CSN = Csn;
|
|
|
|
LogDevice->LDN = LogDev;
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2024-05-03 14:39:26 +00:00
|
|
|
LogDevice->Resources = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
MaxTagsPerDevice * sizeof(ISAPNP_RESOURCE),
|
|
|
|
TAG_ISAPNP);
|
|
|
|
if (!LogDevice->Resources)
|
|
|
|
{
|
|
|
|
DPRINT1("Failed to allocate the resources array\n");
|
|
|
|
FreeLogicalDevice(LogDevice);
|
|
|
|
goto Deactivate;
|
|
|
|
}
|
|
|
|
|
2021-03-20 14:50:34 +00:00
|
|
|
Status = ParseTags(ResourceData, LogDev, LogDevice);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2020-03-20 18:19:30 +00:00
|
|
|
{
|
2021-03-20 14:50:34 +00:00
|
|
|
DPRINT1("Failed to parse tags with status 0x%08lx, CSN %u, LDN %u\n",
|
|
|
|
Status, LogDevice->CSN, LogDevice->LDN);
|
|
|
|
FreeLogicalDevice(LogDevice);
|
|
|
|
goto Deactivate;
|
2020-03-20 18:19:30 +00:00
|
|
|
}
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2021-03-20 14:51:05 +00:00
|
|
|
if (!ReadCurrentResources(FdoExt->ReadDataPort, LogDevice))
|
|
|
|
DPRINT("Unable to read boot resources\n");
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2021-03-20 14:50:34 +00:00
|
|
|
IsaPnpExtractAscii(LogDevice->VendorId, Identifier.VendorId);
|
|
|
|
LogDevice->ProdId = Identifier.ProdId;
|
|
|
|
LogDevice->SerialNumber = Identifier.Serial;
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2021-03-20 14:50:34 +00:00
|
|
|
if (MaxLogDev > 1)
|
|
|
|
LogDevice->Flags |= ISAPNP_HAS_MULTIPLE_LOGDEVS;
|
|
|
|
|
|
|
|
LogDevice->Flags |= ISAPNP_PRESENT;
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2021-03-04 12:42:42 +00:00
|
|
|
InsertTailList(&FdoExt->DeviceListHead, &LogDevice->DeviceLink);
|
2020-03-20 18:19:30 +00:00
|
|
|
FdoExt->DeviceCount++;
|
2021-03-20 14:50:34 +00:00
|
|
|
|
|
|
|
/* Now we wait for the start device IRP */
|
|
|
|
Deactivate:
|
|
|
|
DeactivateDevice(LogDev);
|
2020-03-20 18:19:30 +00:00
|
|
|
}
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
2021-03-20 14:50:34 +00:00
|
|
|
ExFreePoolWithTag(ResourceData, TAG_ISAPNP);
|
|
|
|
|
2020-03-20 18:19:30 +00:00
|
|
|
return STATUS_SUCCESS;
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
2021-03-20 14:53:54 +00:00
|
|
|
CODE_SEG("PAGE")
|
|
|
|
NTSTATUS
|
|
|
|
IsaHwConfigureDevice(
|
|
|
|
_In_ PISAPNP_FDO_EXTENSION FdoExt,
|
|
|
|
_In_ PISAPNP_LOGICAL_DEVICE LogicalDevice,
|
|
|
|
_In_ PCM_RESOURCE_LIST Resources)
|
|
|
|
{
|
2024-05-03 14:42:21 +00:00
|
|
|
ULONG i;
|
|
|
|
UCHAR NumberOfIo = 0,
|
2021-03-20 14:53:54 +00:00
|
|
|
NumberOfIrq = 0,
|
|
|
|
NumberOfDma = 0,
|
2024-05-03 14:42:21 +00:00
|
|
|
NumberOfMemory = 0,
|
|
|
|
NumberOfMemory32 = 0;
|
2021-03-20 14:53:54 +00:00
|
|
|
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
if (!Resources)
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
2024-05-03 14:42:21 +00:00
|
|
|
WriteLogicalDeviceNumber(LogicalDevice->LDN);
|
|
|
|
|
2021-03-20 14:53:54 +00:00
|
|
|
for (i = 0; i < Resources->List[0].PartialResourceList.Count; i++)
|
|
|
|
{
|
|
|
|
PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor =
|
|
|
|
&Resources->List[0].PartialResourceList.PartialDescriptors[i];
|
|
|
|
|
|
|
|
switch (Descriptor->Type)
|
|
|
|
{
|
|
|
|
case CmResourceTypePort:
|
|
|
|
{
|
2024-05-03 14:42:21 +00:00
|
|
|
if (NumberOfIo >= RTL_NUMBER_OF(LogicalDevice->Io))
|
2021-03-20 14:53:54 +00:00
|
|
|
return STATUS_INVALID_PARAMETER_1;
|
|
|
|
|
2024-05-03 14:42:21 +00:00
|
|
|
IsaProgramIoDecoder(Descriptor, NumberOfIo++);
|
2021-03-20 14:53:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CmResourceTypeInterrupt:
|
|
|
|
{
|
2024-05-03 14:42:21 +00:00
|
|
|
if (NumberOfIrq >= RTL_NUMBER_OF(LogicalDevice->Irq))
|
2021-03-20 14:53:54 +00:00
|
|
|
return STATUS_INVALID_PARAMETER_2;
|
|
|
|
|
2024-05-03 14:42:21 +00:00
|
|
|
IsaProgramIrqSelect(Descriptor, NumberOfIrq++);
|
2021-03-20 14:53:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CmResourceTypeDma:
|
|
|
|
{
|
2024-05-03 14:42:21 +00:00
|
|
|
if (NumberOfDma >= RTL_NUMBER_OF(LogicalDevice->Dma))
|
2021-03-20 14:53:54 +00:00
|
|
|
return STATUS_INVALID_PARAMETER_3;
|
|
|
|
|
2024-05-03 14:42:21 +00:00
|
|
|
IsaProgramDmaSelect(Descriptor, NumberOfDma++);
|
2021-03-20 14:53:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CmResourceTypeMemory:
|
|
|
|
{
|
2024-05-03 14:42:21 +00:00
|
|
|
BOOLEAN IsMemory32;
|
|
|
|
UCHAR Index, Information;
|
|
|
|
NTSTATUS Status;
|
2021-03-20 14:53:54 +00:00
|
|
|
|
2024-05-03 14:42:21 +00:00
|
|
|
if ((NumberOfMemory + NumberOfMemory32) >= RTL_NUMBER_OF(LogicalDevice->MemRange))
|
2021-03-20 14:53:54 +00:00
|
|
|
return STATUS_INVALID_PARAMETER_4;
|
|
|
|
|
2024-05-03 14:42:21 +00:00
|
|
|
/*
|
|
|
|
* The PNP ROM provides an information byte for each memory descriptor
|
|
|
|
* which is then used to program the memory control register.
|
|
|
|
*/
|
2021-03-20 14:53:54 +00:00
|
|
|
if (!FindMemoryDescriptor(LogicalDevice,
|
|
|
|
Descriptor->u.Memory.Start.LowPart,
|
|
|
|
Descriptor->u.Memory.Start.LowPart +
|
|
|
|
Descriptor->u.Memory.Length - 1,
|
2024-05-03 14:42:21 +00:00
|
|
|
&Information))
|
2021-03-20 14:53:54 +00:00
|
|
|
{
|
|
|
|
return STATUS_RESOURCE_DATA_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2024-05-03 14:42:21 +00:00
|
|
|
/* We can have a 24- or 32-bit memory decoder, but not both */
|
|
|
|
IsMemory32 = !!(LogicalDevice->Flags & ISAPNP_HAS_MEM32_DECODER);
|
|
|
|
|
|
|
|
if (IsMemory32)
|
|
|
|
Index = NumberOfMemory32++;
|
|
|
|
else
|
|
|
|
Index = NumberOfMemory++;
|
|
|
|
|
|
|
|
Status = IsaProgramMemoryDecoder(FdoExt->ReadDataPort,
|
|
|
|
Descriptor,
|
|
|
|
IsMemory32,
|
|
|
|
Information,
|
|
|
|
Index);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
return Status;
|
2021-03-20 14:53:54 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-03 14:42:21 +00:00
|
|
|
/* Disable the unclaimed device resources */
|
|
|
|
for (i = NumberOfIo; i < RTL_NUMBER_OF(LogicalDevice->Io); i++)
|
|
|
|
{
|
|
|
|
WriteWord(ISAPNP_IOBASE(i), 0);
|
|
|
|
}
|
|
|
|
for (i = NumberOfIrq; i < RTL_NUMBER_OF(LogicalDevice->Irq); i++)
|
|
|
|
{
|
|
|
|
WriteByte(ISAPNP_IRQNO(i), 0);
|
|
|
|
WriteByte(ISAPNP_IRQTYPE(i), 0);
|
|
|
|
}
|
|
|
|
for (i = NumberOfDma; i < RTL_NUMBER_OF(LogicalDevice->Dma); i++)
|
|
|
|
{
|
|
|
|
WriteByte(ISAPNP_DMACHANNEL(i), DMACHANNEL_NONE);
|
|
|
|
}
|
|
|
|
for (i = NumberOfMemory; i < RTL_NUMBER_OF(LogicalDevice->MemRange); i++)
|
|
|
|
{
|
|
|
|
WriteWord(ISAPNP_MEMBASE(i), 0);
|
|
|
|
WriteByte(ISAPNP_MEMCONTROL(i), 0);
|
|
|
|
WriteWord(ISAPNP_MEMLIMIT(i), 0);
|
|
|
|
}
|
|
|
|
for (i = NumberOfMemory32; i < RTL_NUMBER_OF(LogicalDevice->MemRange32); i++)
|
|
|
|
{
|
|
|
|
WriteDoubleWord(ISAPNP_MEMBASE32(i), 0);
|
|
|
|
WriteByte(ISAPNP_MEMCONTROL32(i), 0);
|
|
|
|
WriteDoubleWord(ISAPNP_MEMLIMIT32(i), 0);
|
|
|
|
}
|
2021-03-20 14:53:54 +00:00
|
|
|
|
|
|
|
KeStallExecutionProcessor(10000);
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2024-05-03 14:43:40 +00:00
|
|
|
CODE_SEG("PAGE")
|
2021-03-20 14:52:40 +00:00
|
|
|
VOID
|
|
|
|
IsaHwWakeDevice(
|
|
|
|
_In_ PISAPNP_LOGICAL_DEVICE LogicalDevice)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2024-05-03 14:43:40 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
2021-03-20 14:52:40 +00:00
|
|
|
SendKey();
|
|
|
|
Wake(LogicalDevice->CSN);
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
2024-05-03 14:43:40 +00:00
|
|
|
CODE_SEG("PAGE")
|
2021-03-20 14:52:40 +00:00
|
|
|
VOID
|
2010-04-07 20:19:29 +00:00
|
|
|
IsaHwActivateDevice(
|
2021-03-20 14:53:06 +00:00
|
|
|
_In_ PISAPNP_FDO_EXTENSION FdoExt,
|
2021-03-04 12:42:42 +00:00
|
|
|
_In_ PISAPNP_LOGICAL_DEVICE LogicalDevice)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2024-05-03 14:43:40 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
2021-03-20 14:53:06 +00:00
|
|
|
ActivateDevice(FdoExt->ReadDataPort, LogicalDevice->LDN);
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
2024-05-03 13:09:23 +00:00
|
|
|
#ifndef UNIT_TEST
|
2024-05-03 14:43:40 +00:00
|
|
|
CODE_SEG("PAGE")
|
2021-03-20 14:52:40 +00:00
|
|
|
VOID
|
2010-04-07 20:19:29 +00:00
|
|
|
IsaHwDeactivateDevice(
|
2021-03-04 12:42:42 +00:00
|
|
|
_In_ PISAPNP_LOGICAL_DEVICE LogicalDevice)
|
2010-04-07 20:19:29 +00:00
|
|
|
{
|
2024-05-03 14:43:40 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
2021-03-20 14:52:40 +00:00
|
|
|
DeactivateDevice(LogicalDevice->LDN);
|
|
|
|
}
|
2024-05-03 13:09:23 +00:00
|
|
|
#endif /* UNIT_TEST */
|
2010-04-07 20:19:29 +00:00
|
|
|
|
2024-05-03 14:43:40 +00:00
|
|
|
CODE_SEG("PAGE")
|
2021-03-20 14:52:40 +00:00
|
|
|
VOID
|
|
|
|
IsaHwWaitForKey(VOID)
|
|
|
|
{
|
2024-05-03 14:43:40 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
2021-03-20 14:52:40 +00:00
|
|
|
WaitForKey();
|
2010-04-07 20:19:29 +00:00
|
|
|
}
|