[ISAPNP] Extract resource definitions

Prepare the driver for upcoming API tests
CORE-18562
This commit is contained in:
Dmitry Borisov 2024-05-03 19:08:09 +06:00
parent 4ba8a8b59b
commit 016d01e5d1
3 changed files with 220 additions and 205 deletions

View file

@ -981,62 +981,6 @@ InvalidBiosResources:
return STATUS_SUCCESS;
}
_Dispatch_type_(IRP_MJ_CREATE)
_Dispatch_type_(IRP_MJ_CLOSE)
static CODE_SEG("PAGE") DRIVER_DISPATCH_PAGED IsaCreateClose;
static
CODE_SEG("PAGE")
NTSTATUS
NTAPI
IsaCreateClose(
_In_ PDEVICE_OBJECT DeviceObject,
_Inout_ PIRP Irp)
{
PAGED_CODE();
Irp->IoStatus.Status = STATUS_SUCCESS;
DPRINT("%s(%p, %p)\n", __FUNCTION__, DeviceObject, Irp);
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return STATUS_SUCCESS;
}
_Dispatch_type_(IRP_MJ_DEVICE_CONTROL)
_Dispatch_type_(IRP_MJ_SYSTEM_CONTROL)
static CODE_SEG("PAGE") DRIVER_DISPATCH_PAGED IsaForwardOrIgnore;
static
CODE_SEG("PAGE")
NTSTATUS
NTAPI
IsaForwardOrIgnore(
_In_ PDEVICE_OBJECT DeviceObject,
_Inout_ PIRP Irp)
{
PISAPNP_COMMON_EXTENSION CommonExt = DeviceObject->DeviceExtension;
PAGED_CODE();
DPRINT("%s(%p, %p) Minor - %X\n", __FUNCTION__, DeviceObject, Irp,
IoGetCurrentIrpStackLocation(Irp)->MinorFunction);
if (CommonExt->Signature == IsaPnpBus)
{
IoSkipCurrentIrpStackLocation(Irp);
return IoCallDriver(((PISAPNP_FDO_EXTENSION)CommonExt)->Ldo, Irp);
}
else
{
NTSTATUS Status = Irp->IoStatus.Status;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return Status;
}
}
CODE_SEG("PAGE")
PIO_RESOURCE_REQUIREMENTS_LIST
IsaPnpCreateReadPortDORequirements(
@ -1571,6 +1515,62 @@ IsaPnp(
return IsaPdoPnp((PISAPNP_PDO_EXTENSION)DevExt, Irp, IrpSp);
}
_Dispatch_type_(IRP_MJ_CREATE)
_Dispatch_type_(IRP_MJ_CLOSE)
static CODE_SEG("PAGE") DRIVER_DISPATCH_PAGED IsaCreateClose;
static
CODE_SEG("PAGE")
NTSTATUS
NTAPI
IsaCreateClose(
_In_ PDEVICE_OBJECT DeviceObject,
_Inout_ PIRP Irp)
{
PAGED_CODE();
Irp->IoStatus.Status = STATUS_SUCCESS;
DPRINT("%s(%p, %p)\n", __FUNCTION__, DeviceObject, Irp);
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return STATUS_SUCCESS;
}
_Dispatch_type_(IRP_MJ_DEVICE_CONTROL)
_Dispatch_type_(IRP_MJ_SYSTEM_CONTROL)
static CODE_SEG("PAGE") DRIVER_DISPATCH_PAGED IsaForwardOrIgnore;
static
CODE_SEG("PAGE")
NTSTATUS
NTAPI
IsaForwardOrIgnore(
_In_ PDEVICE_OBJECT DeviceObject,
_Inout_ PIRP Irp)
{
PISAPNP_COMMON_EXTENSION CommonExt = DeviceObject->DeviceExtension;
PAGED_CODE();
DPRINT("%s(%p, %p) Minor - %X\n", __FUNCTION__, DeviceObject, Irp,
IoGetCurrentIrpStackLocation(Irp)->MinorFunction);
if (CommonExt->Signature == IsaPnpBus)
{
IoSkipCurrentIrpStackLocation(Irp);
return IoCallDriver(((PISAPNP_FDO_EXTENSION)CommonExt)->Ldo, Irp);
}
else
{
NTSTATUS Status = Irp->IoStatus.Status;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return Status;
}
}
CODE_SEG("INIT")
NTSTATUS
NTAPI

View file

@ -12,7 +12,9 @@
#include <ntddk.h>
#include <ntstrsafe.h>
#include <section_attribs.h>
#include "isapnphw.h"
#include "isapnpres.h"
#include <initguid.h>
#include <wdmguid.h>
@ -23,121 +25,12 @@ extern "C" {
#define TAG_ISAPNP 'pasI'
/** @brief Maximum size of resource data structure supported by the driver. */
#define ISAPNP_MAX_RESOURCEDATA 0x1000
/** @brief Maximum number of Start DF tags supported by the driver. */
#define ISAPNP_MAX_ALTERNATIVES 8
typedef enum
{
dsStopped,
dsStarted
} ISAPNP_DEVICE_STATE;
typedef struct _ISAPNP_IO
{
USHORT CurrentBase;
ISAPNP_IO_DESCRIPTION Description;
UCHAR Index;
} ISAPNP_IO, *PISAPNP_IO;
typedef struct _ISAPNP_IRQ
{
UCHAR CurrentNo;
UCHAR CurrentType;
ISAPNP_IRQ_DESCRIPTION Description;
UCHAR Index;
} ISAPNP_IRQ, *PISAPNP_IRQ;
typedef struct _ISAPNP_DMA
{
UCHAR CurrentChannel;
ISAPNP_DMA_DESCRIPTION Description;
UCHAR Index;
} ISAPNP_DMA, *PISAPNP_DMA;
typedef struct _ISAPNP_MEMRANGE
{
ULONG CurrentBase;
ULONG CurrentLength;
ISAPNP_MEMRANGE_DESCRIPTION Description;
UCHAR Index;
} ISAPNP_MEMRANGE, *PISAPNP_MEMRANGE;
typedef struct _ISAPNP_MEMRANGE32
{
ULONG CurrentBase;
ULONG CurrentLength;
ISAPNP_MEMRANGE32_DESCRIPTION Description;
UCHAR Index;
} ISAPNP_MEMRANGE32, *PISAPNP_MEMRANGE32;
typedef struct _ISAPNP_COMPATIBLE_ID_ENTRY
{
UCHAR VendorId[3];
USHORT ProdId;
LIST_ENTRY IdLink;
} ISAPNP_COMPATIBLE_ID_ENTRY, *PISAPNP_COMPATIBLE_ID_ENTRY;
typedef struct _ISAPNP_ALTERNATIVES
{
ISAPNP_IO_DESCRIPTION Io[ISAPNP_MAX_ALTERNATIVES];
ISAPNP_IRQ_DESCRIPTION Irq[ISAPNP_MAX_ALTERNATIVES];
ISAPNP_DMA_DESCRIPTION Dma[ISAPNP_MAX_ALTERNATIVES];
ISAPNP_MEMRANGE_DESCRIPTION MemRange[ISAPNP_MAX_ALTERNATIVES];
ISAPNP_MEMRANGE32_DESCRIPTION MemRange32[ISAPNP_MAX_ALTERNATIVES];
UCHAR Priority[ISAPNP_MAX_ALTERNATIVES];
UCHAR IoIndex;
UCHAR IrqIndex;
UCHAR DmaIndex;
UCHAR MemRangeIndex;
UCHAR MemRange32Index;
_Field_range_(0, ISAPNP_MAX_ALTERNATIVES)
UCHAR Count;
} ISAPNP_ALTERNATIVES, *PISAPNP_ALTERNATIVES;
typedef struct _ISAPNP_LOGICAL_DEVICE
{
PDEVICE_OBJECT Pdo;
/**
* @name The card data.
* @{
*/
UCHAR CSN;
UCHAR VendorId[3];
USHORT ProdId;
ULONG SerialNumber;
/**@}*/
/**
* @name The logical device data.
* @{
*/
UCHAR LDN;
UCHAR LogVendorId[3];
USHORT LogProdId;
LIST_ENTRY CompatibleIdList;
PSTR FriendlyName;
PISAPNP_ALTERNATIVES Alternatives;
ISAPNP_IO Io[8];
ISAPNP_IRQ Irq[2];
ISAPNP_DMA Dma[2];
ISAPNP_MEMRANGE MemRange[4];
ISAPNP_MEMRANGE32 MemRange32[4];
/**@}*/
ULONG Flags;
#define ISAPNP_PRESENT 0x00000001 /**< @brief Cleared when the device is physically removed. */
#define ISAPNP_HAS_MULTIPLE_LOGDEVS 0x00000002 /**< @brief Indicates if the parent card has multiple logical devices. */
#define ISAPNP_HAS_RESOURCES 0x00000004 /**< @brief Cleared when the device has no boot resources. */
LIST_ENTRY DeviceLink;
} ISAPNP_LOGICAL_DEVICE, *PISAPNP_LOGICAL_DEVICE;
typedef enum _ISAPNP_SIGNATURE
{
IsaPnpBus = 'odFI',
@ -248,46 +141,6 @@ IsaPnpReleaseDeviceDataLock(
KeSetEvent(&FdoExt->DeviceSyncEvent, IO_NO_INCREMENT, FALSE);
}
FORCEINLINE
BOOLEAN
HasIoAlternatives(
_In_ PISAPNP_ALTERNATIVES Alternatives)
{
return (Alternatives->Io[0].Length != 0);
}
FORCEINLINE
BOOLEAN
HasIrqAlternatives(
_In_ PISAPNP_ALTERNATIVES Alternatives)
{
return (Alternatives->Irq[0].Mask != 0);
}
FORCEINLINE
BOOLEAN
HasDmaAlternatives(
_In_ PISAPNP_ALTERNATIVES Alternatives)
{
return (Alternatives->Dma[0].Mask != 0);
}
FORCEINLINE
BOOLEAN
HasMemoryAlternatives(
_In_ PISAPNP_ALTERNATIVES Alternatives)
{
return (Alternatives->MemRange[0].Length != 0);
}
FORCEINLINE
BOOLEAN
HasMemory32Alternatives(
_In_ PISAPNP_ALTERNATIVES Alternatives)
{
return (Alternatives->MemRange32[0].Length != 0);
}
/* isapnp.c */
CODE_SEG("PAGE")

View file

@ -0,0 +1,162 @@
/*
* PROJECT: ReactOS ISA PnP Bus driver
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Resource management header file
* COPYRIGHT: Copyright 2010 Cameron Gutman <cameron.gutman@reactos.org>
* Copyright 2020 Hervé Poussineau <hpoussin@reactos.org>
*/
#pragma once
/** @brief Maximum size of resource data structure supported by the driver. */
#define ISAPNP_MAX_RESOURCEDATA 0x1000
/** @brief Maximum number of Start DF tags supported by the driver. */
#define ISAPNP_MAX_ALTERNATIVES 8
typedef struct _ISAPNP_IO
{
USHORT CurrentBase;
ISAPNP_IO_DESCRIPTION Description;
UCHAR Index;
} ISAPNP_IO, *PISAPNP_IO;
typedef struct _ISAPNP_IRQ
{
UCHAR CurrentNo;
UCHAR CurrentType;
ISAPNP_IRQ_DESCRIPTION Description;
UCHAR Index;
} ISAPNP_IRQ, *PISAPNP_IRQ;
typedef struct _ISAPNP_DMA
{
UCHAR CurrentChannel;
ISAPNP_DMA_DESCRIPTION Description;
UCHAR Index;
} ISAPNP_DMA, *PISAPNP_DMA;
typedef struct _ISAPNP_MEMRANGE
{
ULONG CurrentBase;
ULONG CurrentLength;
ISAPNP_MEMRANGE_DESCRIPTION Description;
UCHAR Index;
} ISAPNP_MEMRANGE, *PISAPNP_MEMRANGE;
typedef struct _ISAPNP_MEMRANGE32
{
ULONG CurrentBase;
ULONG CurrentLength;
ISAPNP_MEMRANGE32_DESCRIPTION Description;
UCHAR Index;
} ISAPNP_MEMRANGE32, *PISAPNP_MEMRANGE32;
typedef struct _ISAPNP_COMPATIBLE_ID_ENTRY
{
UCHAR VendorId[3];
USHORT ProdId;
LIST_ENTRY IdLink;
} ISAPNP_COMPATIBLE_ID_ENTRY, *PISAPNP_COMPATIBLE_ID_ENTRY;
typedef struct _ISAPNP_ALTERNATIVES
{
ISAPNP_IO_DESCRIPTION Io[ISAPNP_MAX_ALTERNATIVES];
ISAPNP_IRQ_DESCRIPTION Irq[ISAPNP_MAX_ALTERNATIVES];
ISAPNP_DMA_DESCRIPTION Dma[ISAPNP_MAX_ALTERNATIVES];
ISAPNP_MEMRANGE_DESCRIPTION MemRange[ISAPNP_MAX_ALTERNATIVES];
ISAPNP_MEMRANGE32_DESCRIPTION MemRange32[ISAPNP_MAX_ALTERNATIVES];
UCHAR Priority[ISAPNP_MAX_ALTERNATIVES];
UCHAR IoIndex;
UCHAR IrqIndex;
UCHAR DmaIndex;
UCHAR MemRangeIndex;
UCHAR MemRange32Index;
_Field_range_(0, ISAPNP_MAX_ALTERNATIVES)
UCHAR Count;
} ISAPNP_ALTERNATIVES, *PISAPNP_ALTERNATIVES;
typedef struct _ISAPNP_LOGICAL_DEVICE
{
LIST_ENTRY DeviceLink;
PDEVICE_OBJECT Pdo;
ULONG Flags;
/** Cleared when the device is physically removed */
#define ISAPNP_PRESENT 0x00000001
/** Indicates if the parent card has multiple logical devices */
#define ISAPNP_HAS_MULTIPLE_LOGDEVS 0x00000002
/** Cleared when the device has no boot resources */
#define ISAPNP_HAS_RESOURCES 0x00000004
/**
* @name The card data.
* @{
*/
UCHAR CSN;
UCHAR VendorId[3];
USHORT ProdId;
ULONG SerialNumber;
/**@}*/
/**
* @name The logical device data.
* @{
*/
UCHAR LDN;
UCHAR LogVendorId[3];
USHORT LogProdId;
PISAPNP_ALTERNATIVES Alternatives;
PSTR FriendlyName;
LIST_ENTRY CompatibleIdList;
ISAPNP_IO Io[8];
ISAPNP_IRQ Irq[2];
ISAPNP_DMA Dma[2];
ISAPNP_MEMRANGE MemRange[4];
ISAPNP_MEMRANGE32 MemRange32[4];
/**@}*/
} ISAPNP_LOGICAL_DEVICE, *PISAPNP_LOGICAL_DEVICE;
FORCEINLINE
BOOLEAN
HasIoAlternatives(
_In_ PISAPNP_ALTERNATIVES Alternatives)
{
return (Alternatives->Io[0].Length != 0);
}
FORCEINLINE
BOOLEAN
HasIrqAlternatives(
_In_ PISAPNP_ALTERNATIVES Alternatives)
{
return (Alternatives->Irq[0].Mask != 0);
}
FORCEINLINE
BOOLEAN
HasDmaAlternatives(
_In_ PISAPNP_ALTERNATIVES Alternatives)
{
return (Alternatives->Dma[0].Mask != 0);
}
FORCEINLINE
BOOLEAN
HasMemoryAlternatives(
_In_ PISAPNP_ALTERNATIVES Alternatives)
{
return (Alternatives->MemRange[0].Length != 0);
}
FORCEINLINE
BOOLEAN
HasMemory32Alternatives(
_In_ PISAPNP_ALTERNATIVES Alternatives)
{
return (Alternatives->MemRange32[0].Length != 0);
}