https://git.reactos.org/?p=reactos.git;a=commitdiff;h=10b08aa2bbc831faf5c15…
commit 10b08aa2bbc831faf5c15afced425c442618c325
Author: Dmitry Borisov <di.sean(a)protonmail.com>
AuthorDate: Mon Oct 7 20:10:08 2024 +0600
Commit: GitHub <noreply(a)github.com>
CommitDate: Mon Oct 7 16:10:08 2024 +0200
[ISAPNP] Detect I/O ports at runtime (#7411)
Improve the driver's portability.
CORE-17977
---
drivers/bus/isapnp/hardware.c | 10 ++++++++--
drivers/bus/isapnp/isapnp.c | 26 ++++++++++++++++----------
drivers/bus/isapnp/isapnphw.h | 12 +++++-------
3 files changed, 29 insertions(+), 19 deletions(-)
diff --git a/drivers/bus/isapnp/hardware.c b/drivers/bus/isapnp/hardware.c
index 443fb787bbd..7a50c2740bd 100644
--- a/drivers/bus/isapnp/hardware.c
+++ b/drivers/bus/isapnp/hardware.c
@@ -20,13 +20,19 @@
#endif /* UNIT_TEST */
+ULONG IsaConfigPorts[2] =
+{
+ ISAPNP_WRITE_DATA_PCAT,
+ ISAPNP_ADDRESS_PCAT
+};
+
static
inline
VOID
WriteAddress(
_In_ UCHAR Address)
{
- WRITE_PORT_UCHAR((PUCHAR)ISAPNP_ADDRESS, Address);
+ WRITE_PORT_UCHAR(UlongToPtr(IsaConfigPorts[1]), Address);
}
static
@@ -35,7 +41,7 @@ VOID
WriteData(
_In_ UCHAR Data)
{
- WRITE_PORT_UCHAR((PUCHAR)ISAPNP_WRITE_DATA, Data);
+ WRITE_PORT_UCHAR(UlongToPtr(IsaConfigPorts[0]), Data);
}
static
diff --git a/drivers/bus/isapnp/isapnp.c b/drivers/bus/isapnp/isapnp.c
index 2450d367413..6b498812773 100644
--- a/drivers/bus/isapnp/isapnp.c
+++ b/drivers/bus/isapnp/isapnp.c
@@ -28,6 +28,8 @@ LIST_ENTRY BusListHead;
#endif /* UNIT_TEST */
+extern ULONG IsaConfigPorts[2];
+
/* FUNCTIONS ******************************************************************/
static
@@ -822,7 +824,6 @@ IsaPnpCreateReadPortDORequirements(
ULONG ResourceCount, ListSize, i;
PIO_RESOURCE_REQUIREMENTS_LIST RequirementsList;
PIO_RESOURCE_DESCRIPTOR Descriptor;
- const ULONG Ports[] = { ISAPNP_WRITE_DATA, ISAPNP_ADDRESS };
const ULONG ReadPorts[] = { 0x274, 0x3E4, 0x204, 0x2E4, 0x354, 0x2F4 };
PAGED_CODE();
@@ -840,7 +841,7 @@ IsaPnpCreateReadPortDORequirements(
* [...]
* [IO descriptor: Read Port X - 1, optional]
*/
- ResourceCount = RTL_NUMBER_OF(Ports) * 2 + RTL_NUMBER_OF(ReadPorts);
+ ResourceCount = RTL_NUMBER_OF(IsaConfigPorts) * 2 + RTL_NUMBER_OF(ReadPorts);
}
else
{
@@ -857,7 +858,7 @@ IsaPnpCreateReadPortDORequirements(
* [IO descriptor: Read Port X, required]
* [IO descriptor: Read Port X, optional]
*/
- ResourceCount = (RTL_NUMBER_OF(Ports) + RTL_NUMBER_OF(ReadPorts)) * 2;
+ ResourceCount = (RTL_NUMBER_OF(IsaConfigPorts) + RTL_NUMBER_OF(ReadPorts)) * 2;
}
ListSize = sizeof(IO_RESOURCE_REQUIREMENTS_LIST) +
sizeof(IO_RESOURCE_DESCRIPTOR) * (ResourceCount - 1);
@@ -875,7 +876,7 @@ IsaPnpCreateReadPortDORequirements(
Descriptor = &RequirementsList->List[0].Descriptors[0];
/* Store the Data port and the Address port */
- for (i = 0; i < RTL_NUMBER_OF(Ports) * 2; i++)
+ for (i = 0; i < RTL_NUMBER_OF(IsaConfigPorts) * 2; i++)
{
if ((i % 2) == 0)
{
@@ -886,7 +887,7 @@ IsaPnpCreateReadPortDORequirements(
Descriptor->u.Port.Length = 0x01;
Descriptor->u.Port.Alignment = 0x01;
Descriptor->u.Port.MinimumAddress.LowPart =
- Descriptor->u.Port.MaximumAddress.LowPart = Ports[i / 2];
+ Descriptor->u.Port.MaximumAddress.LowPart = IsaConfigPorts[i / 2];
}
else
{
@@ -965,7 +966,6 @@ CODE_SEG("PAGE")
PCM_RESOURCE_LIST
IsaPnpCreateReadPortDOResources(VOID)
{
- const USHORT Ports[] = { ISAPNP_WRITE_DATA, ISAPNP_ADDRESS };
ULONG ListSize, i;
PCM_RESOURCE_LIST ResourceList;
PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor;
@@ -973,7 +973,7 @@ IsaPnpCreateReadPortDOResources(VOID)
PAGED_CODE();
ListSize = sizeof(CM_RESOURCE_LIST) +
- sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * (RTL_NUMBER_OF(Ports) - 1);
+ sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * (RTL_NUMBER_OF(IsaConfigPorts) -
1);
ResourceList = ExAllocatePoolZero(PagedPool, ListSize, TAG_ISAPNP);
if (!ResourceList)
return NULL;
@@ -982,16 +982,16 @@ IsaPnpCreateReadPortDOResources(VOID)
ResourceList->List[0].InterfaceType = Internal;
ResourceList->List[0].PartialResourceList.Version = 1;
ResourceList->List[0].PartialResourceList.Revision = 1;
- ResourceList->List[0].PartialResourceList.Count = RTL_NUMBER_OF(Ports);
+ ResourceList->List[0].PartialResourceList.Count = RTL_NUMBER_OF(IsaConfigPorts);
Descriptor =
&ResourceList->List[0].PartialResourceList.PartialDescriptors[0];
- for (i = 0; i < RTL_NUMBER_OF(Ports); i++)
+ for (i = 0; i < RTL_NUMBER_OF(IsaConfigPorts); i++)
{
Descriptor->Type = CmResourceTypePort;
Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
Descriptor->Flags = CM_RESOURCE_PORT_16_BIT_DECODE;
Descriptor->u.Port.Length = 0x01;
- Descriptor->u.Port.Start.LowPart = Ports[i];
+ Descriptor->u.Port.Start.LowPart = IsaConfigPorts[i];
Descriptor++;
}
@@ -1415,6 +1415,12 @@ DriverEntry(
{
DPRINT("%s(%p, %wZ)\n", __FUNCTION__, DriverObject, RegistryPath);
+ if (IsNEC_98)
+ {
+ IsaConfigPorts[0] = ISAPNP_WRITE_DATA_PC98;
+ IsaConfigPorts[1] = ISAPNP_ADDRESS_PC98;
+ }
+
DriverObject->MajorFunction[IRP_MJ_CREATE] = IsaCreateClose;
DriverObject->MajorFunction[IRP_MJ_CLOSE] = IsaCreateClose;
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = IsaForwardOrIgnore;
diff --git a/drivers/bus/isapnp/isapnphw.h b/drivers/bus/isapnp/isapnphw.h
index 5eb62746450..a5cb7a7d98c 100644
--- a/drivers/bus/isapnp/isapnphw.h
+++ b/drivers/bus/isapnp/isapnphw.h
@@ -13,13 +13,11 @@
extern "C" {
#endif
-#if defined(SARCH_PC98)
-#define ISAPNP_ADDRESS 0x259
-#define ISAPNP_WRITE_DATA 0xA59
-#else
-#define ISAPNP_ADDRESS 0x279
-#define ISAPNP_WRITE_DATA 0xA79
-#endif
+#define ISAPNP_ADDRESS_PCAT 0x279
+#define ISAPNP_WRITE_DATA_PCAT 0xA79
+
+#define ISAPNP_ADDRESS_PC98 0x259
+#define ISAPNP_WRITE_DATA_PC98 0xA59
#define ISAPNP_READPORT 0x00
#define ISAPNP_SERIALISOLATION 0x01