ReactOS 0.4.15-dev-7788-g1ad9096
isapnp.c File Reference
#include "isapnp.h"
#include <search.h>
#include <debug.h>
Include dependency graph for isapnp.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

 _Guarded_by_ (BusSyncEvent)
 
static VOID IsaDetermineBestConfig (_Out_writes_all_(ISAPNP_MAX_ALTERNATIVES) PUCHAR BestConfig, _In_ PISAPNP_ALTERNATIVES Alternatives)
 
static VOID IsaConvertIoRequirement (_Out_ PIO_RESOURCE_DESCRIPTOR Descriptor, _In_ PISAPNP_IO_DESCRIPTION Description)
 
static VOID IsaConvertIrqRequirement (_Out_ PIO_RESOURCE_DESCRIPTOR Descriptor, _In_ PISAPNP_IRQ_DESCRIPTION Description, _In_ ULONG Vector, _In_ BOOLEAN FirstDescriptor)
 
static VOID IsaConvertDmaRequirement (_Out_ PIO_RESOURCE_DESCRIPTOR Descriptor, _In_ PISAPNP_DMA_DESCRIPTION Description, _In_ ULONG Channel, _In_ BOOLEAN FirstDescriptor)
 
static VOID IsaConvertMemRangeRequirement (_Out_ PIO_RESOURCE_DESCRIPTOR Descriptor, _In_ PISAPNP_MEMRANGE_DESCRIPTION Description)
 
static VOID IsaConvertMemRange32Requirement (_Out_ PIO_RESOURCE_DESCRIPTOR Descriptor, _In_ PISAPNP_MEMRANGE32_DESCRIPTION Description)
 
static NTSTATUS IsaPnpCreateLogicalDeviceRequirements (_In_ PISAPNP_PDO_EXTENSION PdoExt)
 
BOOLEAN FindIoDescriptor (_In_ PISAPNP_LOGICAL_DEVICE LogDevice, _In_opt_ ULONG Base, _In_ ULONG RangeStart, _In_ ULONG RangeEnd, _Out_opt_ PUCHAR Information, _Out_opt_ PULONG Length, _Out_opt_ PUCHAR WriteOrder)
 
BOOLEAN FindIrqDescriptor (_In_ PISAPNP_LOGICAL_DEVICE LogDevice, _In_ ULONG Vector, _Out_opt_ PUCHAR WriteOrder)
 
BOOLEAN FindDmaDescriptor (_In_ PISAPNP_LOGICAL_DEVICE LogDevice, _In_ ULONG Channel, _Out_opt_ PUCHAR WriteOrder)
 
BOOLEAN FindMemoryDescriptor (_In_ PISAPNP_LOGICAL_DEVICE LogDevice, _In_ ULONG RangeStart, _In_ ULONG RangeEnd, _Out_opt_ PBOOLEAN Memory32, _Out_opt_ PUCHAR Information, _Out_opt_ PUCHAR WriteOrder)
 
static NTSTATUS IsaPnpCreateLogicalDeviceResources (_In_ PISAPNP_PDO_EXTENSION PdoExt)
 
 _Dispatch_type_ (IRP_MJ_CREATE)
 
 _Dispatch_type_ (IRP_MJ_DEVICE_CONTROL)
 
NTSTATUS IsaPnpCreateReadPortDORequirements (_In_ PISAPNP_PDO_EXTENSION PdoExt, _In_opt_ ULONG SelectedReadPort)
 
static NTSTATUS IsaPnpCreateReadPortDOResources (_In_ PISAPNP_PDO_EXTENSION PdoExt)
 
static NTSTATUS IsaPnpCreateReadPortDO (_In_ PISAPNP_FDO_EXTENSION FdoExt)
 
VOID IsaPnpRemoveReadPortDO (_In_ PDEVICE_OBJECT Pdo)
 
NTSTATUS IsaPnpFillDeviceRelations (_In_ PISAPNP_FDO_EXTENSION FdoExt, _Inout_ PIRP Irp, _In_ BOOLEAN IncludeDataPort)
 
static CODE_SEG ("PAGE")
 
 _Dispatch_type_ (IRP_MJ_POWER)
 
 _Dispatch_type_ (IRP_MJ_PNP)
 
NTSTATUS NTAPI DriverEntry (_In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING RegistryPath)
 

Variables

KEVENT BusSyncEvent
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 16 of file isapnp.c.

Function Documentation

◆ _Dispatch_type_() [1/4]

_Dispatch_type_ ( IRP_MJ_CREATE  )

Definition at line 984 of file isapnp.c.

995{
996 PAGED_CODE();
997
998 Irp->IoStatus.Status = STATUS_SUCCESS;
999
1000 DPRINT("%s(%p, %p)\n", __FUNCTION__, DeviceObject, Irp);
1001
1003
1004 return STATUS_SUCCESS;
1005}
#define PAGED_CODE()
_In_ PIRP Irp
Definition: csq.h:116
#define __FUNCTION__
Definition: types.h:116
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define IO_NO_INCREMENT
Definition: iotypes.h:598

◆ _Dispatch_type_() [2/4]

_Dispatch_type_ ( IRP_MJ_DEVICE_CONTROL  )

Definition at line 1007 of file isapnp.c.

1018{
1019 PISAPNP_COMMON_EXTENSION CommonExt = DeviceObject->DeviceExtension;
1020
1021 PAGED_CODE();
1022
1023 DPRINT("%s(%p, %p) Minor - %X\n", __FUNCTION__, DeviceObject, Irp,
1025
1026 if (CommonExt->Signature == IsaPnpBus)
1027 {
1029 return IoCallDriver(((PISAPNP_FDO_EXTENSION)CommonExt)->Ldo, Irp);
1030 }
1031 else
1032 {
1033 NTSTATUS Status = Irp->IoStatus.Status;
1034
1036 return Status;
1037 }
1038}
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: gdiplustypes.h:25
@ IsaPnpBus
Definition: isapnp.h:143
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IoCallDriver
Definition: irp.c:1225
ISAPNP_SIGNATURE Signature
Definition: isapnp.h:150
_In_ UCHAR _In_ UCHAR MinorFunction
Definition: wdfdevice.h:1699
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793

◆ _Dispatch_type_() [3/4]

_Dispatch_type_ ( IRP_MJ_PNP  )

Definition at line 1581 of file isapnp.c.

1591{
1593 PISAPNP_COMMON_EXTENSION DevExt = DeviceObject->DeviceExtension;
1594
1595 PAGED_CODE();
1596
1597 if (DevExt->Signature == IsaPnpBus)
1598 return IsaFdoPnp((PISAPNP_FDO_EXTENSION)DevExt, Irp, IrpSp);
1599 else
1600 return IsaPdoPnp((PISAPNP_PDO_EXTENSION)DevExt, Irp, IrpSp);
1601}
NTSTATUS IsaFdoPnp(_In_ PISAPNP_FDO_EXTENSION FdoExt, _Inout_ PIRP Irp, _In_ PIO_STACK_LOCATION IrpSp)
Definition: fdo.c:123
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
NTSTATUS IsaPdoPnp(_In_ PISAPNP_PDO_EXTENSION PdoDeviceExtension, _Inout_ PIRP Irp, _In_ PIO_STACK_LOCATION IrpSp)
Definition: pdo.c:864

◆ _Dispatch_type_() [4/4]

_Dispatch_type_ ( IRP_MJ_POWER  )

Definition at line 1543 of file isapnp.c.

1552{
1553 PISAPNP_COMMON_EXTENSION DevExt = DeviceObject->DeviceExtension;
1555
1556 if (DevExt->Signature != IsaPnpBus)
1557 {
1559 {
1560 case IRP_MN_SET_POWER:
1561 case IRP_MN_QUERY_POWER:
1563 Irp->IoStatus.Status = Status;
1564 break;
1565
1566 default:
1567 Status = Irp->IoStatus.Status;
1568 break;
1569 }
1570
1573 return Status;
1574 }
1575
1578 return PoCallDriver(((PISAPNP_FDO_EXTENSION)DevExt)->Ldo, Irp);
1579}
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:758
#define IRP_MN_SET_POWER
#define IRP_MN_QUERY_POWER

◆ _Guarded_by_()

_Guarded_by_ ( BusSyncEvent  )

Definition at line 23 of file isapnp.c.

40{
41 PAGED_CODE();
42
43 return Priority[*(PUCHAR)A] - Priority[*(PUCHAR)B];
44}
Definition: ehthrow.cxx:93
#define B(row, col)
unsigned char * PUCHAR
Definition: typedefs.h:53
_In_ WDFINTERRUPT _In_ WDF_INTERRUPT_POLICY _In_ WDF_INTERRUPT_PRIORITY Priority
Definition: wdfinterrupt.h:655

◆ CODE_SEG()

static CODE_SEG ( "PAGE"  )
static

Definition at line 1482 of file isapnp.c.

1491{
1493 PISAPNP_FDO_EXTENSION FdoExt;
1495 static ULONG BusNumber = 0;
1496
1497 PAGED_CODE();
1498
1500
1502 sizeof(*FdoExt),
1503 NULL,
1506 FALSE,
1507 &Fdo);
1508 if (!NT_SUCCESS(Status))
1509 {
1510 DPRINT1("Failed to create FDO (0x%08lx)\n", Status);
1511 return Status;
1512 }
1513
1514 FdoExt = Fdo->DeviceExtension;
1515 RtlZeroMemory(FdoExt, sizeof(*FdoExt));
1516
1517 FdoExt->Common.Self = Fdo;
1518 FdoExt->Common.Signature = IsaPnpBus;
1519 FdoExt->Common.State = dsStopped;
1520 FdoExt->DriverObject = DriverObject;
1521 FdoExt->BusNumber = BusNumber++;
1522 FdoExt->Pdo = PhysicalDeviceObject;
1525 if (!FdoExt->Ldo)
1526 {
1528 return STATUS_DEVICE_REMOVED;
1529 }
1530
1531 InitializeListHead(&FdoExt->DeviceListHead);
1533
1534 IsaPnpAcquireBusDataLock();
1535 InsertTailList(&BusListHead, &FdoExt->BusLink);
1536 IsaPnpReleaseBusDataLock();
1537
1538 Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
1539
1540 return STATUS_SUCCESS;
1541}
#define DPRINT1
Definition: precomp.h:8
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1157
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define InsertTailList(ListHead, Entry)
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
@ dsStopped
Definition: isapnp.h:34
@ SynchronizationEvent
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define STATUS_DEVICE_REMOVED
Definition: ntstatus.h:809
#define FILE_DEVICE_BUS_EXTENDER
Definition: winioctl.h:148
PDEVICE_OBJECT Self
Definition: isapnp.h:151
ISAPNP_DEVICE_STATE State
Definition: isapnp.h:152
PDRIVER_OBJECT DriverObject
Definition: isapnp.h:170
PDEVICE_OBJECT Pdo
Definition: isapnp.h:159
LIST_ENTRY BusLink
Definition: isapnp.h:173
KEVENT DeviceSyncEvent
Definition: isapnp.h:162
ISAPNP_COMMON_EXTENSION Common
Definition: isapnp.h:157
PDEVICE_OBJECT Ldo
Definition: isapnp.h:158
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
_Must_inspect_result_ _In_ WDFDEVICE Fdo
Definition: wdffdo.h:461
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
Definition: halfuncs.h:160

Referenced by KiSwitchToBootStack().

◆ DriverEntry()

NTSTATUS NTAPI DriverEntry ( _In_ PDRIVER_OBJECT  DriverObject,
_In_ PUNICODE_STRING  RegistryPath 
)

Definition at line 1606 of file isapnp.c.

1609{
1610 DPRINT("%s(%p, %wZ)\n", __FUNCTION__, DriverObject, RegistryPath);
1611
1612 DriverObject->MajorFunction[IRP_MJ_CREATE] = IsaCreateClose;
1613 DriverObject->MajorFunction[IRP_MJ_CLOSE] = IsaCreateClose;
1614 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = IsaForwardOrIgnore;
1615 DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = IsaForwardOrIgnore;
1616 DriverObject->MajorFunction[IRP_MJ_PNP] = IsaPnp;
1617 DriverObject->MajorFunction[IRP_MJ_POWER] = IsaPower;
1618 DriverObject->DriverExtension->AddDevice = IsaAddDevice;
1619
1620 /* FIXME: Fix SDK headers */
1621#if 0
1623#endif
1624
1626 InitializeListHead(&BusListHead);
1627
1628 /* FIXME: Fix SDK headers */
1629#if 0
1631#endif
1632
1633 return STATUS_SUCCESS;
1634}
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
#define _No_competing_thread_begin_
#define _No_competing_thread_end_
KEVENT BusSyncEvent
Definition: isapnp.c:21
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
#define IRP_MJ_SYSTEM_CONTROL
#define IRP_MJ_POWER

◆ FindDmaDescriptor()

BOOLEAN FindDmaDescriptor ( _In_ PISAPNP_LOGICAL_DEVICE  LogDevice,
_In_ ULONG  Channel,
_Out_opt_ PUCHAR  WriteOrder 
)

Definition at line 639 of file isapnp.c.

643{
644 ULONG i, j;
646
647 PAGED_CODE();
648
649 for (i = 0; i < RTL_NUMBER_OF(LogDevice->Dma); i++)
650 {
651 Description = &LogDevice->Dma[i].Description;
652
653 for (j = 0; j < RTL_BITS_OF(Description->Mask); j++)
654 {
655 if (Description->Mask & (1 << j))
656 {
657 if (j == Channel)
658 {
659 if (WriteOrder)
660 *WriteOrder = LogDevice->Dma[i].Index;
661
662 return TRUE;
663 }
664 }
665 }
666 }
667
668 if (!LogDevice->Alternatives)
669 return FALSE;
670
671 for (i = 0; i < LogDevice->Alternatives->Count; i++)
672 {
673 Description = &LogDevice->Alternatives->Dma[i];
674
675 for (j = 0; j < RTL_BITS_OF(Description->Mask); j++)
676 {
677 if (Description->Mask & (1 << j))
678 {
679 if (j == Channel)
680 {
681 if (WriteOrder)
682 *WriteOrder = LogDevice->Alternatives->DmaIndex;
683
684 return TRUE;
685 }
686 }
687 }
688 }
689
690 return FALSE;
691}
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
static const WCHAR Description[]
Definition: oid.c:1266
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define RTL_BITS_OF(sizeOfArg)
Definition: ntbasedef.h:668

Referenced by IsaHwConfigureDevice(), IsaPnpCreateLogicalDeviceResources(), and WriteResources().

◆ FindIoDescriptor()

BOOLEAN FindIoDescriptor ( _In_ PISAPNP_LOGICAL_DEVICE  LogDevice,
_In_opt_ ULONG  Base,
_In_ ULONG  RangeStart,
_In_ ULONG  RangeEnd,
_Out_opt_ PUCHAR  Information,
_Out_opt_ PULONG  Length,
_Out_opt_ PUCHAR  WriteOrder 
)

Definition at line 518 of file isapnp.c.

526{
527 ULONG i;
528 BOOLEAN Match;
530
531 PAGED_CODE();
532
533 for (i = 0; i < RTL_NUMBER_OF(LogDevice->Io); i++)
534 {
535 Description = &LogDevice->Io[i].Description;
536
537 Match = Base ? (Base >= Description->Minimum) && (Base <= Description->Maximum)
538 : (RangeStart >= Description->Minimum) &&
539 (RangeEnd <= (ULONG)(Description->Maximum + Description->Length - 1));
540
541 if (Match)
542 {
543 if (Information)
544 *Information = Description->Information;
545 if (Length)
546 *Length = Description->Length;
547 if (WriteOrder)
548 *WriteOrder = LogDevice->Io[i].Index;
549
550 return TRUE;
551 }
552 }
553
554 if (!LogDevice->Alternatives)
555 return FALSE;
556
557 for (i = 0; i < LogDevice->Alternatives->Count; i++)
558 {
559 Description = &LogDevice->Alternatives->Io[i];
560
561 Match = Base ? (Base >= Description->Minimum) && (Base <= Description->Maximum)
562 : (RangeStart >= Description->Minimum) &&
563 (RangeEnd <= (ULONG)(Description->Maximum + Description->Length - 1));
564
565 if (Match)
566 {
567 if (Information)
568 *Information = Description->Information;
569 if (Length)
570 *Length = Description->Length;
571 if (WriteOrder)
572 *WriteOrder = LogDevice->Alternatives->IoIndex;
573
574 return TRUE;
575 }
576 }
577
578 return FALSE;
579}
unsigned char BOOLEAN
_In_opt_ ULONG Base
Definition: rtlfuncs.h:2439
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
_In_ WDFREQUEST _In_ NTSTATUS _In_ ULONG_PTR Information
Definition: wdfrequest.h:1049

Referenced by IsaHwConfigureDevice(), IsaPnpCreateLogicalDeviceResources(), and WriteResources().

◆ FindIrqDescriptor()

BOOLEAN FindIrqDescriptor ( _In_ PISAPNP_LOGICAL_DEVICE  LogDevice,
_In_ ULONG  Vector,
_Out_opt_ PUCHAR  WriteOrder 
)

Definition at line 583 of file isapnp.c.

587{
588 ULONG i, j;
590
591 PAGED_CODE();
592
593 for (i = 0; i < RTL_NUMBER_OF(LogDevice->Irq); i++)
594 {
595 Description = &LogDevice->Irq[i].Description;
596
597 for (j = 0; j < RTL_BITS_OF(Description->Mask); j++)
598 {
599 if (Description->Mask & (1 << j))
600 {
601 if (j == Vector)
602 {
603 if (WriteOrder)
604 *WriteOrder = LogDevice->Irq[i].Index;
605
606 return TRUE;
607 }
608 }
609 }
610 }
611
612 if (!LogDevice->Alternatives)
613 return FALSE;
614
615 for (i = 0; i < LogDevice->Alternatives->Count; i++)
616 {
617 Description = &LogDevice->Alternatives->Irq[i];
618
619 for (j = 0; j < RTL_BITS_OF(Description->Mask); j++)
620 {
621 if (Description->Mask & (1 << j))
622 {
623 if (j == Vector)
624 {
625 if (WriteOrder)
626 *WriteOrder = LogDevice->Alternatives->IrqIndex;
627
628 return TRUE;
629 }
630 }
631 }
632 }
633
634 return FALSE;
635}

Referenced by IsaHwConfigureDevice(), IsaPnpCreateLogicalDeviceResources(), and WriteResources().

◆ FindMemoryDescriptor()

BOOLEAN FindMemoryDescriptor ( _In_ PISAPNP_LOGICAL_DEVICE  LogDevice,
_In_ ULONG  RangeStart,
_In_ ULONG  RangeEnd,
_Out_opt_ PBOOLEAN  Memory32,
_Out_opt_ PUCHAR  Information,
_Out_opt_ PUCHAR  WriteOrder 
)

Definition at line 695 of file isapnp.c.

702{
703 ULONG i;
705 PISAPNP_MEMRANGE32_DESCRIPTION Description32;
706
707 PAGED_CODE();
708
709 for (i = 0; i < RTL_NUMBER_OF(LogDevice->MemRange); i++)
710 {
711 Description = &LogDevice->MemRange[i].Description;
712
713 if ((RangeStart >= (ULONG)(Description->Minimum << 8)) &&
714 (RangeEnd <= (ULONG)((Description->Maximum << 8) + (Description->Length << 8) - 1)))
715 {
716 if (Memory32)
717 *Memory32 = FALSE;
718 if (Information)
719 *Information = Description->Information;
720 if (WriteOrder)
721 *WriteOrder = LogDevice->MemRange[i].Index;
722
723 return TRUE;
724 }
725 }
726 for (i = 0; i < RTL_NUMBER_OF(LogDevice->MemRange32); i++)
727 {
728 Description32 = &LogDevice->MemRange32[i].Description;
729
730 if ((RangeStart >= Description32->Minimum) &&
731 (RangeEnd <= (Description32->Maximum + Description32->Length - 1)))
732 {
733 if (Memory32)
734 *Memory32 = TRUE;
735 if (Information)
736 *Information = Description32->Information;
737 if (WriteOrder)
738 *WriteOrder = LogDevice->MemRange32[i].Index;
739
740 return TRUE;
741 }
742 }
743
744 if (!LogDevice->Alternatives)
745 return FALSE;
746
747 for (i = 0; i < LogDevice->Alternatives->Count; i++)
748 {
749 Description = &LogDevice->Alternatives->MemRange[i];
750
751 if ((RangeStart >= (ULONG)(Description->Minimum << 8)) &&
752 (RangeEnd <= (ULONG)((Description->Maximum << 8) + (Description->Length << 8) - 1)))
753 {
754 if (Memory32)
755 *Memory32 = FALSE;
756 if (Information)
757 *Information = Description->Information;
758 if (WriteOrder)
759 *WriteOrder = LogDevice->Alternatives->MemRangeIndex;
760
761 return TRUE;
762 }
763 }
764 for (i = 0; i < LogDevice->Alternatives->Count; i++)
765 {
766 Description32 = &LogDevice->Alternatives->MemRange32[i];
767
768 if ((RangeStart >= Description32->Minimum) &&
769 (RangeEnd <= (Description32->Maximum + Description32->Length - 1)))
770 {
771 if (Memory32)
772 *Memory32 = TRUE;
773 if (Information)
774 *Information = Description32->Information;
775 if (WriteOrder)
776 *WriteOrder = LogDevice->Alternatives->MemRange32Index;
777
778 return TRUE;
779 }
780 }
781
782 return FALSE;
783}

Referenced by IsaHwConfigureDevice(), IsaPnpCreateLogicalDeviceResources(), and WriteResources().

◆ IsaConvertDmaRequirement()

static VOID IsaConvertDmaRequirement ( _Out_ PIO_RESOURCE_DESCRIPTOR  Descriptor,
_In_ PISAPNP_DMA_DESCRIPTION  Description,
_In_ ULONG  Channel,
_In_ BOOLEAN  FirstDescriptor 
)
static

Definition at line 123 of file isapnp.c.

128{
130
131 PAGED_CODE();
132
133 if (!FirstDescriptor)
136 Descriptor->ShareDisposition = CmResourceShareUndetermined;
137 Descriptor->Flags = CM_RESOURCE_DMA_8; /* Ignore information byte for compatibility */
138 Descriptor->u.Dma.MinimumChannel =
139 Descriptor->u.Dma.MaximumChannel = Channel;
140}
#define IO_RESOURCE_ALTERNATIVE
Definition: edit.c:119
#define CmResourceTypeDma
Definition: hwresource.cpp:126
#define CM_RESOURCE_DMA_8
Definition: cmtypes.h:131
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:342
@ CmResourceShareUndetermined
Definition: cmtypes.h:240

◆ IsaConvertIoRequirement()

static VOID IsaConvertIoRequirement ( _Out_ PIO_RESOURCE_DESCRIPTOR  Descriptor,
_In_ PISAPNP_IO_DESCRIPTION  Description 
)
static

Definition at line 72 of file isapnp.c.

75{
76 PAGED_CODE();
77
81 if (Description->Information & 0x1)
83 else
85 Descriptor->u.Port.Length = Description->Length;
86 Descriptor->u.Port.Alignment = Description->Alignment;
87 Descriptor->u.Port.MinimumAddress.LowPart = Description->Minimum;
88 Descriptor->u.Port.MaximumAddress.LowPart = Description->Maximum +
89 Description->Length - 1;
90}
#define CmResourceTypePort
Definition: hwresource.cpp:123
#define CM_RESOURCE_PORT_IO
Definition: cmtypes.h:109
#define CM_RESOURCE_PORT_16_BIT_DECODE
Definition: cmtypes.h:112
#define CM_RESOURCE_PORT_10_BIT_DECODE
Definition: cmtypes.h:110
@ CmResourceShareDeviceExclusive
Definition: cmtypes.h:241

◆ IsaConvertIrqRequirement()

static VOID IsaConvertIrqRequirement ( _Out_ PIO_RESOURCE_DESCRIPTOR  Descriptor,
_In_ PISAPNP_IRQ_DESCRIPTION  Description,
_In_ ULONG  Vector,
_In_ BOOLEAN  FirstDescriptor 
)
static

Definition at line 95 of file isapnp.c.

100{
101 PAGED_CODE();
102
103 if (!FirstDescriptor)
106 if (Description->Information & 0xC)
107 {
109 Descriptor->ShareDisposition = CmResourceShareShared;
110 }
111 else
112 {
114 Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
115 }
116 Descriptor->u.Interrupt.MinimumVector =
117 Descriptor->u.Interrupt.MaximumVector = Vector;
118}
#define CmResourceTypeInterrupt
Definition: hwresource.cpp:124
#define CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE
Definition: cmtypes.h:143
#define CM_RESOURCE_INTERRUPT_LATCHED
Definition: cmtypes.h:144
@ CmResourceShareShared
Definition: cmtypes.h:243

◆ IsaConvertMemRange32Requirement()

static VOID IsaConvertMemRange32Requirement ( _Out_ PIO_RESOURCE_DESCRIPTOR  Descriptor,
_In_ PISAPNP_MEMRANGE32_DESCRIPTION  Description 
)
static

Definition at line 171 of file isapnp.c.

174{
175 PAGED_CODE();
176
178 Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
180 if ((Description->Information & 0x40) || !(Description->Information & 0x01))
182 else
184 Descriptor->u.Memory.Length = Description->Length;
185 Descriptor->u.Memory.Alignment = Description->Alignment;
186 Descriptor->u.Memory.MinimumAddress.LowPart = Description->Minimum;
187 Descriptor->u.Memory.MaximumAddress.LowPart = Description->Maximum +
188 Description->Length - 1;
189}
#define CmResourceTypeMemory
Definition: hwresource.cpp:125
#define CM_RESOURCE_MEMORY_READ_ONLY
Definition: cmtypes.h:121
#define CM_RESOURCE_MEMORY_READ_WRITE
Definition: cmtypes.h:120
#define CM_RESOURCE_MEMORY_24
Definition: cmtypes.h:125

◆ IsaConvertMemRangeRequirement()

static VOID IsaConvertMemRangeRequirement ( _Out_ PIO_RESOURCE_DESCRIPTOR  Descriptor,
_In_ PISAPNP_MEMRANGE_DESCRIPTION  Description 
)
static

Definition at line 145 of file isapnp.c.

148{
149 PAGED_CODE();
150
152 Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
154 if ((Description->Information & 0x40) || !(Description->Information & 0x01))
156 else
158 Descriptor->u.Memory.Length = Description->Length << 8;
159 if (Description->Alignment == 0)
160 Descriptor->u.Memory.Alignment = 0x10000;
161 else
162 Descriptor->u.Memory.Alignment = Description->Alignment;
163 Descriptor->u.Memory.MinimumAddress.LowPart = Description->Minimum << 8;
164 Descriptor->u.Memory.MaximumAddress.LowPart = (Description->Maximum << 8) +
165 (Description->Length << 8) - 1;
166}

◆ IsaDetermineBestConfig()

static VOID IsaDetermineBestConfig ( _Out_writes_all_(ISAPNP_MAX_ALTERNATIVES) PUCHAR  BestConfig,
_In_ PISAPNP_ALTERNATIVES  Alternatives 
)
static

Definition at line 49 of file isapnp.c.

52{
53 UCHAR i;
54
55 PAGED_CODE();
56
57 for (i = 0; i < ISAPNP_MAX_ALTERNATIVES; i++)
58 {
59 BestConfig[i] = i;
60 }
61
62 Priority = Alternatives->Priority;
63 qsort(BestConfig,
64 Alternatives->Count,
65 sizeof(*BestConfig),
66 IsaComparePriority);
67}
#define ISAPNP_MAX_ALTERNATIVES
Maximum number of Start DF tags supported by the driver.
Definition: isapnp.h:30
void __cdecl qsort(_Inout_updates_bytes_(_NumOfElements *_SizeOfElements) void *_Base, _In_ size_t _NumOfElements, _In_ size_t _SizeOfElements, _In_ int(__cdecl *_PtFuncCompare)(const void *, const void *))
unsigned char UCHAR
Definition: xmlstorage.h:181

◆ IsaPnpCreateLogicalDeviceRequirements()

static NTSTATUS IsaPnpCreateLogicalDeviceRequirements ( _In_ PISAPNP_PDO_EXTENSION  PdoExt)
static

Definition at line 194 of file isapnp.c.

196{
197 PISAPNP_LOGICAL_DEVICE LogDev = PdoExt->IsaPnpDevice;
198 RTL_BITMAP TempBitmap;
199 ULONG TempBuffer;
200 ULONG ResourceCount = 0, AltCount = 0, AltOptionalCount = 0;
201 ULONG ListSize, i, j;
202 BOOLEAN FirstDescriptor;
205 PISAPNP_ALTERNATIVES Alternatives = LogDev->Alternatives;
206
207 PAGED_CODE();
208
209 /* Count number of requirements */
210 for (i = 0; i < RTL_NUMBER_OF(LogDev->Io); i++)
211 {
212 /*
213 * Use the continue statement to count the number of requirements.
214 * We handle a possible gap because depedent function can appear at
215 * any position in the logical device's requirements list.
216 */
217 if (!LogDev->Io[i].Description.Length)
218 continue;
219
221 }
222 for (i = 0; i < RTL_NUMBER_OF(LogDev->Irq); i++)
223 {
224 if (!LogDev->Irq[i].Description.Mask)
225 continue;
226
227 TempBuffer = LogDev->Irq[i].Description.Mask;
228 RtlInitializeBitMap(&TempBitmap,
229 &TempBuffer,
230 RTL_BITS_OF(LogDev->Irq[i].Description.Mask));
231 ResourceCount += RtlNumberOfSetBits(&TempBitmap);
232 }
233 for (i = 0; i < RTL_NUMBER_OF(LogDev->Dma); i++)
234 {
235 if (!LogDev->Dma[i].Description.Mask)
236 continue;
237
238 TempBuffer = LogDev->Dma[i].Description.Mask;
239 RtlInitializeBitMap(&TempBitmap,
240 &TempBuffer,
241 RTL_BITS_OF(LogDev->Dma[i].Description.Mask));
242 ResourceCount += RtlNumberOfSetBits(&TempBitmap);
243 }
244 for (i = 0; i < RTL_NUMBER_OF(LogDev->MemRange); i++)
245 {
246 if (!LogDev->MemRange[i].Description.Length)
247 continue;
248
250 }
251 for (i = 0; i < RTL_NUMBER_OF(LogDev->MemRange32); i++)
252 {
253 if (!LogDev->MemRange32[i].Description.Length)
254 continue;
255
257 }
258 if (Alternatives)
259 {
260 ULONG BitCount;
261
262 if (HasIoAlternatives(Alternatives))
263 AltCount++;
264 if (HasIrqAlternatives(Alternatives))
265 AltCount++;
266 if (HasDmaAlternatives(Alternatives))
267 AltCount++;
268 if (HasMemoryAlternatives(Alternatives))
269 AltCount++;
270 if (HasMemory32Alternatives(Alternatives))
271 AltCount++;
272 ResourceCount += AltCount;
273
274 if (HasIrqAlternatives(Alternatives))
275 {
276 for (i = 0; i < Alternatives->Count; i++)
277 {
278 TempBuffer = Alternatives->Irq[i].Mask;
279 RtlInitializeBitMap(&TempBitmap,
280 &TempBuffer,
281 RTL_BITS_OF(Alternatives->Irq[i].Mask));
282 BitCount = RtlNumberOfSetBits(&TempBitmap);
283
284 if (BitCount > 1)
285 AltOptionalCount += BitCount - 1;
286 }
287 }
288 if (HasDmaAlternatives(Alternatives))
289 {
290 for (i = 0; i < Alternatives->Count; i++)
291 {
292 TempBuffer = Alternatives->Dma[i].Mask;
293 RtlInitializeBitMap(&TempBitmap,
294 &TempBuffer,
295 RTL_BITS_OF(Alternatives->Dma[i].Mask));
296 BitCount = RtlNumberOfSetBits(&TempBitmap);
297
298 if (BitCount > 1)
299 AltOptionalCount += BitCount - 1;
300 }
301 }
302 }
303 if (ResourceCount == 0)
304 return STATUS_SUCCESS;
305
306 /* Allocate memory to store requirements */
307 ListSize = sizeof(IO_RESOURCE_REQUIREMENTS_LIST);
308 if (Alternatives)
309 {
310 ListSize += sizeof(IO_RESOURCE_DESCRIPTOR) * (ResourceCount - 1) * Alternatives->Count
311 + sizeof(IO_RESOURCE_LIST) * (Alternatives->Count - 1)
312 + sizeof(IO_RESOURCE_DESCRIPTOR) * AltOptionalCount;
313 }
314 else
315 {
316 ListSize += sizeof(IO_RESOURCE_DESCRIPTOR) * (ResourceCount - 1);
317 }
318 RequirementsList = ExAllocatePoolZero(PagedPool, ListSize, TAG_ISAPNP);
319 if (!RequirementsList)
320 return STATUS_NO_MEMORY;
321
322 RequirementsList->ListSize = ListSize;
323 RequirementsList->InterfaceType = Isa;
324 RequirementsList->AlternativeLists = Alternatives ? Alternatives->Count : 1;
325
326 RequirementsList->List[0].Version = 1;
327 RequirementsList->List[0].Revision = 1;
328 RequirementsList->List[0].Count = ResourceCount;
329
330 /* Store requirements */
331 Descriptor = RequirementsList->List[0].Descriptors;
332 for (i = 0; i < RTL_NUMBER_OF(LogDev->Io); i++)
333 {
334 if (!LogDev->Io[i].Description.Length)
335 break;
336
338 }
339 for (i = 0; i < RTL_NUMBER_OF(LogDev->Irq); i++)
340 {
341 if (!LogDev->Irq[i].Description.Mask)
342 continue;
343
344 FirstDescriptor = TRUE;
345
346 for (j = 0; j < RTL_BITS_OF(LogDev->Irq[i].Description.Mask); j++)
347 {
348 if (!(LogDev->Irq[i].Description.Mask & (1 << j)))
349 continue;
350
352 &LogDev->Irq[i].Description,
353 j,
354 FirstDescriptor);
355
356 if (FirstDescriptor)
357 FirstDescriptor = FALSE;
358 }
359 }
360 for (i = 0; i < RTL_NUMBER_OF(LogDev->Dma); i++)
361 {
362 if (!LogDev->Dma[i].Description.Mask)
363 continue;
364
365 FirstDescriptor = TRUE;
366
367 for (j = 0; j < RTL_BITS_OF(LogDev->Dma[i].Description.Mask); j++)
368 {
369 if (!(LogDev->Dma[i].Description.Mask & (1 << j)))
370 continue;
371
373 &LogDev->Dma[i].Description,
374 j,
375 FirstDescriptor);
376
377 if (FirstDescriptor)
378 FirstDescriptor = FALSE;
379 }
380 }
381 for (i = 0; i < RTL_NUMBER_OF(LogDev->MemRange); i++)
382 {
383 if (!LogDev->MemRange[i].Description.Length)
384 continue;
385
387 &LogDev->MemRange[i].Description);
388 }
389 for (i = 0; i < RTL_NUMBER_OF(LogDev->MemRange32); i++)
390 {
391 if (!LogDev->MemRange32[i].Description.Length)
392 continue;
393
395 &LogDev->MemRange32[i].Description);
396 }
397 if (Alternatives)
398 {
399 UCHAR BestConfig[ISAPNP_MAX_ALTERNATIVES];
400 PIO_RESOURCE_LIST AltList = &RequirementsList->List[0];
401 PIO_RESOURCE_LIST NextList = AltList;
402
403 IsaDetermineBestConfig(BestConfig, Alternatives);
404
405 for (i = 0; i < RequirementsList->AlternativeLists; i++)
406 {
407 RtlMoveMemory(NextList, AltList, sizeof(IO_RESOURCE_LIST));
408
409 /* Just because the 'NextList->Count++' correction */
410 NextList->Count = ResourceCount;
411 /*
412 * For example, the ROM
413 * 0x15, ... // Logical device ID
414 * 0x30, // Start DF
415 * 0x22, 0x04, 0x00 // IRQ
416 * 0x30, // Start DF
417 * 0x22, 0xC0, 0x00 // IRQ
418 * 0x38, // End DF
419 * 0x2A, 0x20, 0x3A // DMA
420 * 0x22, 0x00, 0x08 // IRQ
421 * 0x79, 0x00 // END
422 *
423 * will be represented as the following resource requirements list:
424 * Interface 1 Bus 0 Slot 0 AlternativeLists 2
425 * AltList 1, AltList->Count 3
426 * [Option 0, ShareDisposition 1, Flags 1] INT: Min B Max B
427 * [Option 0, ShareDisposition 0, Flags 0] DMA: Min 5 Max 5
428 * [Option 0, ShareDisposition 1, Flags 1] INT: Min 2 Max 2
429 * End Descriptors
430 * AltList 2, AltList->Count 4
431 * [Option 0, ShareDisposition 1, Flags 1] INT: Min B Max B
432 * [Option 0, ShareDisposition 0, Flags 0] DMA: Min 5 Max 5
433 * [Option 0, ShareDisposition 1, Flags 1] INT: Min 6 Max 6
434 * [Option 8, ShareDisposition 1, Flags 1] INT: Min 7 Max 7
435 * End Descriptors
436 */
437
438 /* Propagate the fixed resources to our new list */
439 for (j = 0; j < AltList->Count - AltCount; j++)
440 {
441 RtlMoveMemory(&NextList->Descriptors[j],
442 &AltList->Descriptors[j],
443 sizeof(IO_RESOURCE_DESCRIPTOR));
444 }
445
446 Descriptor = &NextList->Descriptors[NextList->Count - AltCount];
447
448 /*
449 * Append alternatives.
450 * NOTE: To keep it simple, we append these to the end of the list.
451 */
452 if (HasIoAlternatives(Alternatives))
453 {
455 &Alternatives->Io[BestConfig[i]]);
456 }
457 if (HasIrqAlternatives(Alternatives))
458 {
459 FirstDescriptor = TRUE;
460
461 for (j = 0; j < RTL_BITS_OF(Alternatives->Irq[BestConfig[i]].Mask); j++)
462 {
463 if (!(Alternatives->Irq[BestConfig[i]].Mask & (1 << j)))
464 continue;
465
467 &Alternatives->Irq[BestConfig[i]],
468 j,
469 FirstDescriptor);
470
471 if (FirstDescriptor)
472 FirstDescriptor = FALSE;
473 else
474 NextList->Count++;
475 }
476 }
477 if (HasDmaAlternatives(Alternatives))
478 {
479 FirstDescriptor = TRUE;
480
481 for (j = 0; j < RTL_BITS_OF(Alternatives->Dma[BestConfig[i]].Mask); j++)
482 {
483 if (!(Alternatives->Dma[BestConfig[i]].Mask & (1 << j)))
484 continue;
485
487 &Alternatives->Dma[BestConfig[i]],
488 j,
489 FirstDescriptor);
490
491 if (FirstDescriptor)
492 FirstDescriptor = FALSE;
493 else
494 NextList->Count++;
495 }
496 }
497 if (HasMemoryAlternatives(Alternatives))
498 {
500 &Alternatives->MemRange[BestConfig[i]]);
501 }
502 if (HasMemory32Alternatives(Alternatives))
503 {
505 &Alternatives->MemRange32[BestConfig[i]]);
506 }
507
508 NextList = (PIO_RESOURCE_LIST)(NextList->Descriptors + NextList->Count);
509 }
510 }
511
512 PdoExt->RequirementsList = RequirementsList;
513 return STATUS_SUCCESS;
514}
struct _IO_RESOURCE_LIST * PIO_RESOURCE_LIST
struct _IO_RESOURCE_LIST IO_RESOURCE_LIST
struct _IO_RESOURCE_DESCRIPTOR IO_RESOURCE_DESCRIPTOR
struct _IO_RESOURCE_REQUIREMENTS_LIST IO_RESOURCE_REQUIREMENTS_LIST
#define PagedPool
Definition: env_spec_w32.h:308
@ Isa
Definition: hwresource.cpp:138
static ULONG ResourceCount
Definition: inbv.c:50
NTSYSAPI void WINAPI RtlInitializeBitMap(PRTL_BITMAP, PULONG, ULONG)
NTSYSAPI ULONG WINAPI RtlNumberOfSetBits(PCRTL_BITMAP)
static VOID IsaConvertIrqRequirement(_Out_ PIO_RESOURCE_DESCRIPTOR Descriptor, _In_ PISAPNP_IRQ_DESCRIPTION Description, _In_ ULONG Vector, _In_ BOOLEAN FirstDescriptor)
Definition: isapnp.c:95
static VOID IsaConvertIoRequirement(_Out_ PIO_RESOURCE_DESCRIPTOR Descriptor, _In_ PISAPNP_IO_DESCRIPTION Description)
Definition: isapnp.c:72
static VOID IsaConvertMemRange32Requirement(_Out_ PIO_RESOURCE_DESCRIPTOR Descriptor, _In_ PISAPNP_MEMRANGE32_DESCRIPTION Description)
Definition: isapnp.c:171
static VOID IsaConvertMemRangeRequirement(_Out_ PIO_RESOURCE_DESCRIPTOR Descriptor, _In_ PISAPNP_MEMRANGE_DESCRIPTION Description)
Definition: isapnp.c:145
static VOID IsaConvertDmaRequirement(_Out_ PIO_RESOURCE_DESCRIPTOR Descriptor, _In_ PISAPNP_DMA_DESCRIPTION Description, _In_ ULONG Channel, _In_ BOOLEAN FirstDescriptor)
Definition: isapnp.c:123
static VOID IsaDetermineBestConfig(_Out_writes_all_(ISAPNP_MAX_ALTERNATIVES) PUCHAR BestConfig, _In_ PISAPNP_ALTERNATIVES Alternatives)
Definition: isapnp.c:49
#define TAG_ISAPNP
Definition: isapnp.h:24
FORCEINLINE BOOLEAN HasDmaAlternatives(_In_ PISAPNP_ALTERNATIVES Alternatives)
Definition: isapnp.h:258
FORCEINLINE BOOLEAN HasMemory32Alternatives(_In_ PISAPNP_ALTERNATIVES Alternatives)
Definition: isapnp.h:274
FORCEINLINE BOOLEAN HasMemoryAlternatives(_In_ PISAPNP_ALTERNATIVES Alternatives)
Definition: isapnp.h:266
FORCEINLINE BOOLEAN HasIoAlternatives(_In_ PISAPNP_ALTERNATIVES Alternatives)
Definition: isapnp.h:242
FORCEINLINE BOOLEAN HasIrqAlternatives(_In_ PISAPNP_ALTERNATIVES Alternatives)
Definition: isapnp.h:250
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
ULONG Count
Definition: edit.c:124
IO_RESOURCE_DESCRIPTOR Descriptors[1]
Definition: edit.c:125
ISAPNP_IRQ_DESCRIPTION Irq[ISAPNP_MAX_ALTERNATIVES]
Definition: isapnp.h:86
ISAPNP_MEMRANGE32_DESCRIPTION MemRange32[ISAPNP_MAX_ALTERNATIVES]
Definition: isapnp.h:89
ISAPNP_MEMRANGE_DESCRIPTION MemRange[ISAPNP_MAX_ALTERNATIVES]
Definition: isapnp.h:88
ISAPNP_IO_DESCRIPTION Io[ISAPNP_MAX_ALTERNATIVES]
Definition: isapnp.h:85
ISAPNP_DMA_DESCRIPTION Dma[ISAPNP_MAX_ALTERNATIVES]
Definition: isapnp.h:87
ISAPNP_DMA_DESCRIPTION Description
Definition: isapnp.h:56
ISAPNP_IO_DESCRIPTION Description
Definition: isapnp.h:41
ISAPNP_IRQ_DESCRIPTION Description
Definition: isapnp.h:49
ISAPNP_IO Io[8]
Definition: isapnp.h:126
ISAPNP_DMA Dma[2]
Definition: isapnp.h:128
ISAPNP_MEMRANGE32 MemRange32[4]
Definition: isapnp.h:130
ISAPNP_MEMRANGE MemRange[4]
Definition: isapnp.h:129
ISAPNP_IRQ Irq[2]
Definition: isapnp.h:127
PISAPNP_ALTERNATIVES Alternatives
Definition: isapnp.h:124
ISAPNP_MEMRANGE32_DESCRIPTION Description
Definition: isapnp.h:72
ISAPNP_MEMRANGE_DESCRIPTION Description
Definition: isapnp.h:64
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
PUSBHUB_PORT_PDO_EXTENSION NTAPI PdoExt(IN PDEVICE_OBJECT DeviceObject)
Definition: usbhub.c:133
_In_ WDFIORESREQLIST RequirementsList
Definition: wdfresource.h:65

◆ IsaPnpCreateLogicalDeviceResources()

static NTSTATUS IsaPnpCreateLogicalDeviceResources ( _In_ PISAPNP_PDO_EXTENSION  PdoExt)
static

Definition at line 788 of file isapnp.c.

790{
791 PISAPNP_LOGICAL_DEVICE LogDev = PdoExt->IsaPnpDevice;
794 ULONG ListSize, i;
797
798 PAGED_CODE();
799
800 if (!(LogDev->Flags & ISAPNP_HAS_RESOURCES))
801 return STATUS_SUCCESS;
802
803 /* Count number of required resources */
804 for (i = 0; i < RTL_NUMBER_OF(LogDev->Io); i++)
805 {
806 if (LogDev->Io[i].CurrentBase)
808 else
809 break;
810 }
811 for (i = 0; i < RTL_NUMBER_OF(LogDev->Irq); i++)
812 {
813 if (LogDev->Irq[i].CurrentNo)
815 else
816 break;
817 }
818 for (i = 0; i < RTL_NUMBER_OF(LogDev->Dma); i++)
819 {
820 if (LogDev->Dma[i].CurrentChannel != 4)
822 else
823 break;
824 }
825 for (i = 0; i < RTL_NUMBER_OF(LogDev->MemRange); i++)
826 {
827 if (LogDev->MemRange[i].CurrentBase)
829 else
830 break;
831 }
832 for (i = 0; i < RTL_NUMBER_OF(LogDev->MemRange32); i++)
833 {
834 if (LogDev->MemRange32[i].CurrentBase)
836 else
837 break;
838 }
839 if (ResourceCount == 0)
840 return STATUS_SUCCESS;
841
842 /* Allocate memory to store resources */
843 ListSize = sizeof(CM_RESOURCE_LIST)
845 ResourceList = ExAllocatePoolZero(PagedPool, ListSize, TAG_ISAPNP);
846 if (!ResourceList)
847 return STATUS_NO_MEMORY;
848
849 ResourceList->Count = 1;
850 ResourceList->List[0].InterfaceType = Isa;
851 ResourceList->List[0].PartialResourceList.Version = 1;
852 ResourceList->List[0].PartialResourceList.Revision = 1;
853 ResourceList->List[0].PartialResourceList.Count = ResourceCount;
854
855 /* Store resources */
856 ResourceCount = 0;
857 for (i = 0; i < RTL_NUMBER_OF(LogDev->Io); i++)
858 {
859 ULONG CurrentLength;
860
861 if (!LogDev->Io[i].CurrentBase)
862 break;
863
864 if (!FindIoDescriptor(LogDev,
865 LogDev->Io[i].CurrentBase,
866 0,
867 0,
869 &CurrentLength,
870 NULL))
871 {
872 goto InvalidBiosResources;
873 }
874
875 Descriptor = &ResourceList->List[0].PartialResourceList.PartialDescriptors[ResourceCount++];
877 Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
879 if (Information & 0x1)
881 else
883 Descriptor->u.Port.Length = CurrentLength;
884 Descriptor->u.Port.Start.LowPart = LogDev->Io[i].CurrentBase;
885 }
886 for (i = 0; i < RTL_NUMBER_OF(LogDev->Irq); i++)
887 {
888 if (!LogDev->Irq[i].CurrentNo)
889 break;
890
891 if (!FindIrqDescriptor(LogDev, LogDev->Irq[i].CurrentNo, NULL))
892 goto InvalidBiosResources;
893
894 Descriptor = &ResourceList->List[0].PartialResourceList.PartialDescriptors[ResourceCount++];
896 Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
897 if (LogDev->Irq[i].CurrentType & 0x01)
899 else
901 Descriptor->u.Interrupt.Level = LogDev->Irq[i].CurrentNo;
902 Descriptor->u.Interrupt.Vector = LogDev->Irq[i].CurrentNo;
903 Descriptor->u.Interrupt.Affinity = 0xFFFFFFFF;
904 }
905 for (i = 0; i < RTL_NUMBER_OF(LogDev->Dma); i++)
906 {
907 if (LogDev->Dma[i].CurrentChannel == 4)
908 break;
909
910 if (!FindDmaDescriptor(LogDev, LogDev->Dma[i].CurrentChannel, NULL))
911 goto InvalidBiosResources;
912
913 Descriptor = &ResourceList->List[0].PartialResourceList.PartialDescriptors[ResourceCount++];
915 Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
916 Descriptor->Flags = CM_RESOURCE_DMA_8; /* Ignore information byte for compatibility */
917 Descriptor->u.Dma.Channel = LogDev->Dma[i].CurrentChannel;
918 }
919 for (i = 0; i < RTL_NUMBER_OF(LogDev->MemRange); i++)
920 {
921 if (!LogDev->MemRange[i].CurrentBase)
922 break;
923
924 if (!FindMemoryDescriptor(LogDev,
925 LogDev->MemRange[i].CurrentBase,
926 LogDev->MemRange[i].CurrentLength,
927 NULL,
929 NULL))
930 {
931 goto InvalidBiosResources;
932 }
933
934 Descriptor = &ResourceList->List[0].PartialResourceList.PartialDescriptors[ResourceCount++];
936 Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
938 if ((Information & 0x40) || !(Information & 0x01))
940 else
942 Descriptor->u.Memory.Length = LogDev->MemRange[i].Description.Length;
943 Descriptor->u.Memory.Start.QuadPart = LogDev->MemRange[i].CurrentBase;
944 }
945 for (i = 0; i < RTL_NUMBER_OF(LogDev->MemRange32); i++)
946 {
947 if (!LogDev->MemRange32[i].CurrentBase)
948 break;
949
950 if (!FindMemoryDescriptor(LogDev,
951 LogDev->MemRange32[i].CurrentBase,
952 LogDev->MemRange32[i].CurrentLength,
953 NULL,
955 NULL))
956 {
957 goto InvalidBiosResources;
958 }
959
960 Descriptor = &ResourceList->List[0].PartialResourceList.PartialDescriptors[ResourceCount++];
962 Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
964 if ((Information & 0x40) || !(Information & 0x01))
966 else
968 Descriptor->u.Memory.Length = LogDev->MemRange32[i].Description.Length;
969 Descriptor->u.Memory.Start.QuadPart = LogDev->MemRange32[i].CurrentBase;
970 }
971
972 PdoExt->ResourceList = ResourceList;
973 PdoExt->ResourceListSize = ListSize;
974 return STATUS_SUCCESS;
975
976InvalidBiosResources:
977 DPRINT("Invalid boot resources! (CSN %u, LDN %u)\n", LogDev->CSN, LogDev->LDN);
978
979 LogDev->Flags &= ~ISAPNP_HAS_RESOURCES;
981 return STATUS_SUCCESS;
982}
struct _CM_RESOURCE_LIST CM_RESOURCE_LIST
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR CM_PARTIAL_RESOURCE_DESCRIPTOR
BOOLEAN FindMemoryDescriptor(_In_ PISAPNP_LOGICAL_DEVICE LogDevice, _In_ ULONG RangeStart, _In_ ULONG RangeEnd, _Out_opt_ PBOOLEAN Memory32, _Out_opt_ PUCHAR Information, _Out_opt_ PUCHAR WriteOrder)
Definition: isapnp.c:695
BOOLEAN FindIrqDescriptor(_In_ PISAPNP_LOGICAL_DEVICE LogDevice, _In_ ULONG Vector, _Out_opt_ PUCHAR WriteOrder)
Definition: isapnp.c:583
BOOLEAN FindIoDescriptor(_In_ PISAPNP_LOGICAL_DEVICE LogDevice, _In_opt_ ULONG Base, _In_ ULONG RangeStart, _In_ ULONG RangeEnd, _Out_opt_ PUCHAR Information, _Out_opt_ PULONG Length, _Out_opt_ PUCHAR WriteOrder)
Definition: isapnp.c:518
BOOLEAN FindDmaDescriptor(_In_ PISAPNP_LOGICAL_DEVICE LogDevice, _In_ ULONG Channel, _Out_opt_ PUCHAR WriteOrder)
Definition: isapnp.c:639
#define ISAPNP_HAS_RESOURCES
Cleared when the device has no boot resources.
Definition: isapnp.h:136
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
UCHAR CurrentChannel
Definition: isapnp.h:55
USHORT CurrentBase
Definition: isapnp.h:40
UCHAR CurrentType
Definition: isapnp.h:48
UCHAR CurrentNo
Definition: isapnp.h:47
ULONG CurrentBase
Definition: isapnp.h:70
ULONG CurrentLength
Definition: isapnp.h:71
ULONG CurrentLength
Definition: isapnp.h:63
ULONG CurrentBase
Definition: isapnp.h:62
_Must_inspect_result_ _In_ WDFIORESREQLIST _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFIORESLIST * ResourceList
Definition: wdfresource.h:309

◆ IsaPnpCreateReadPortDO()

static NTSTATUS IsaPnpCreateReadPortDO ( _In_ PISAPNP_FDO_EXTENSION  FdoExt)
static

Definition at line 1234 of file isapnp.c.

1236{
1239
1240 PAGED_CODE();
1241 ASSERT(ReadPortCreated == FALSE);
1242
1243 DPRINT("Creating Read Port\n");
1244
1245 Status = IoCreateDevice(FdoExt->DriverObject,
1246 sizeof(ISAPNP_PDO_EXTENSION),
1247 NULL,
1250 FALSE,
1251 &FdoExt->ReadPortPdo);
1252 if (!NT_SUCCESS(Status))
1253 return Status;
1254
1255 PdoExt = FdoExt->ReadPortPdo->DeviceExtension;
1257 PdoExt->Common.Signature = IsaPnpReadDataPort;
1258 PdoExt->Common.Self = FdoExt->ReadPortPdo;
1259 PdoExt->Common.State = dsStopped;
1260 PdoExt->FdoExt = FdoExt;
1261
1263 if (!NT_SUCCESS(Status))
1264 goto Failure;
1265
1267 if (!NT_SUCCESS(Status))
1268 goto Failure;
1269
1270 FdoExt->ReadPortPdo->Flags &= ~DO_DEVICE_INITIALIZING;
1271
1272 return Status;
1273
1274Failure:
1275 IsaPnpRemoveReadPortDO(FdoExt->ReadPortPdo);
1276
1277 FdoExt->ReadPortPdo = NULL;
1278
1279 return Status;
1280}
NTSTATUS IsaPnpCreateReadPortDORequirements(_In_ PISAPNP_PDO_EXTENSION PdoExt, _In_opt_ ULONG SelectedReadPort)
Definition: isapnp.c:1042
VOID IsaPnpRemoveReadPortDO(_In_ PDEVICE_OBJECT Pdo)
Definition: isapnp.c:1284
static NTSTATUS IsaPnpCreateReadPortDOResources(_In_ PISAPNP_PDO_EXTENSION PdoExt)
Definition: isapnp.c:1192
@ IsaPnpReadDataPort
Definition: isapnp.h:145
#define ASSERT(a)
Definition: mode.c:44
#define FILE_AUTOGENERATED_DEVICE_NAME
Definition: iotypes.h:138
#define FILE_DEVICE_CONTROLLER
Definition: winioctl.h:110
PDEVICE_OBJECT Self
Definition: pciidex.h:60
COMMON_DEVICE_EXTENSION Common
Definition: usbhub.h:204

Referenced by IsaPnpFillDeviceRelations().

◆ IsaPnpCreateReadPortDORequirements()

NTSTATUS IsaPnpCreateReadPortDORequirements ( _In_ PISAPNP_PDO_EXTENSION  PdoExt,
_In_opt_ ULONG  SelectedReadPort 
)

Definition at line 1042 of file isapnp.c.

1045{
1046 ULONG ResourceCount, ListSize, i;
1050 const ULONG ReadPorts[] = { 0x274, 0x3E4, 0x204, 0x2E4, 0x354, 0x2F4 };
1051
1052 PAGED_CODE();
1053
1054 if (SelectedReadPort)
1055 {
1056 /*
1057 * [IO descriptor: ISAPNP_WRITE_DATA, required]
1058 * [IO descriptor: ISAPNP_WRITE_DATA, optional]
1059 * [IO descriptor: ISAPNP_ADDRESS, required]
1060 * [IO descriptor: ISAPNP_ADDRESS, optional]
1061 * [IO descriptor: Selected Read Port, required]
1062 * [IO descriptor: Read Port 1, optional]
1063 * [IO descriptor: Read Port 2, optional]
1064 * [...]
1065 * [IO descriptor: Read Port X - 1, optional]
1066 */
1067 ResourceCount = RTL_NUMBER_OF(Ports) * 2 + RTL_NUMBER_OF(ReadPorts);
1068 }
1069 else
1070 {
1071 /*
1072 * [IO descriptor: ISAPNP_WRITE_DATA, required]
1073 * [IO descriptor: ISAPNP_WRITE_DATA, optional]
1074 * [IO descriptor: ISAPNP_ADDRESS, required]
1075 * [IO descriptor: ISAPNP_ADDRESS, optional]
1076 * [IO descriptor: Read Port 1, required]
1077 * [IO descriptor: Read Port 1, optional]
1078 * [IO descriptor: Read Port 2, required]
1079 * [IO descriptor: Read Port 2, optional]
1080 * [...]
1081 * [IO descriptor: Read Port X, required]
1082 * [IO descriptor: Read Port X, optional]
1083 */
1084 ResourceCount = (RTL_NUMBER_OF(Ports) + RTL_NUMBER_OF(ReadPorts)) * 2;
1085 }
1086 ListSize = sizeof(IO_RESOURCE_REQUIREMENTS_LIST) +
1087 sizeof(IO_RESOURCE_DESCRIPTOR) * (ResourceCount - 1);
1088 RequirementsList = ExAllocatePoolZero(PagedPool, ListSize, TAG_ISAPNP);
1089 if (!RequirementsList)
1090 return STATUS_NO_MEMORY;
1091
1092 RequirementsList->ListSize = ListSize;
1093 RequirementsList->AlternativeLists = 1;
1094
1095 RequirementsList->List[0].Version = 1;
1096 RequirementsList->List[0].Revision = 1;
1097 RequirementsList->List[0].Count = ResourceCount;
1098
1099 Descriptor = &RequirementsList->List[0].Descriptors[0];
1100
1101 /* Store the Data port and the Address port */
1102 for (i = 0; i < RTL_NUMBER_OF(Ports) * 2; i++)
1103 {
1104 if ((i % 2) == 0)
1105 {
1106 /* Expected port */
1108 Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
1110 Descriptor->u.Port.Length = 0x01;
1111 Descriptor->u.Port.Alignment = 0x01;
1112 Descriptor->u.Port.MinimumAddress.LowPart =
1113 Descriptor->u.Port.MaximumAddress.LowPart = Ports[i / 2];
1114 }
1115 else
1116 {
1117 /* ... but mark it as optional */
1120 Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
1122 Descriptor->u.Port.Alignment = 0x01;
1123 }
1124
1125 Descriptor++;
1126 }
1127
1128 /* Store the Read Ports */
1129 if (SelectedReadPort)
1130 {
1131 BOOLEAN Selected = FALSE;
1132
1134
1135 for (i = 0; i < RTL_NUMBER_OF(ReadPorts); i++)
1136 {
1137 if (ReadPorts[i] != SelectedReadPort)
1139 else
1140 Selected = TRUE;
1142 Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
1144 Descriptor->u.Port.Length = 0x04;
1145 Descriptor->u.Port.Alignment = 0x01;
1146 Descriptor->u.Port.MinimumAddress.LowPart = ReadPorts[i];
1147 Descriptor->u.Port.MaximumAddress.LowPart = ReadPorts[i] +
1148 Descriptor->u.Port.Length - 1;
1149
1150 Descriptor++;
1151 }
1152
1153 ASSERT(Selected == TRUE);
1154 }
1155 else
1156 {
1157 for (i = 0; i < RTL_NUMBER_OF(ReadPorts) * 2; i++)
1158 {
1159 if ((i % 2) == 0)
1160 {
1161 /* Expected port */
1163 Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
1165 Descriptor->u.Port.Length = 0x04;
1166 Descriptor->u.Port.Alignment = 0x01;
1167 Descriptor->u.Port.MinimumAddress.LowPart = ReadPorts[i / 2];
1168 Descriptor->u.Port.MaximumAddress.LowPart = ReadPorts[i / 2] +
1169 Descriptor->u.Port.Length - 1;
1170 }
1171 else
1172 {
1173 /* ... but mark it as optional */
1176 Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
1178 Descriptor->u.Port.Alignment = 0x01;
1179 }
1180
1181 Descriptor++;
1182 }
1183 }
1184
1185 PdoExt->RequirementsList = RequirementsList;
1186 return STATUS_SUCCESS;
1187}
#define ISAPNP_ADDRESS
Definition: isapnphw.h:20
#define ISAPNP_WRITE_DATA
Definition: isapnphw.h:21
#define DBG_UNREFERENCED_LOCAL_VARIABLE(L)
Definition: ntbasedef.h:319
static PS2_PORT Ports[PS2_PORTS]
Definition: ps2.c:52

Referenced by IsaPdoStartReadPort(), and IsaPnpCreateReadPortDO().

◆ IsaPnpCreateReadPortDOResources()

static NTSTATUS IsaPnpCreateReadPortDOResources ( _In_ PISAPNP_PDO_EXTENSION  PdoExt)
static

Definition at line 1192 of file isapnp.c.

1194{
1196 ULONG ListSize, i;
1199
1200 PAGED_CODE();
1201
1202 ListSize = sizeof(CM_RESOURCE_LIST) +
1204 ResourceList = ExAllocatePoolZero(PagedPool, ListSize, TAG_ISAPNP);
1205 if (!ResourceList)
1206 return STATUS_NO_MEMORY;
1207
1208 ResourceList->Count = 1;
1209 ResourceList->List[0].InterfaceType = Internal;
1210 ResourceList->List[0].PartialResourceList.Version = 1;
1211 ResourceList->List[0].PartialResourceList.Revision = 1;
1212 ResourceList->List[0].PartialResourceList.Count = RTL_NUMBER_OF(Ports);
1213
1214 Descriptor = &ResourceList->List[0].PartialResourceList.PartialDescriptors[0];
1215 for (i = 0; i < RTL_NUMBER_OF(Ports); i++)
1216 {
1218 Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
1220 Descriptor->u.Port.Length = 0x01;
1221 Descriptor->u.Port.Start.LowPart = Ports[i];
1222
1223 Descriptor++;
1224 }
1225
1226 PdoExt->ResourceList = ResourceList;
1227 PdoExt->ResourceListSize = ListSize;
1228 return STATUS_SUCCESS;
1229}
@ Internal
Definition: hwresource.cpp:137
unsigned short USHORT
Definition: pedump.c:61

Referenced by IsaPnpCreateReadPortDO().

◆ IsaPnpFillDeviceRelations()

NTSTATUS IsaPnpFillDeviceRelations ( _In_ PISAPNP_FDO_EXTENSION  FdoExt,
_Inout_ PIRP  Irp,
_In_ BOOLEAN  IncludeDataPort 
)

Definition at line 1304 of file isapnp.c.

1308{
1310 PLIST_ENTRY CurrentEntry;
1311 PISAPNP_LOGICAL_DEVICE IsaDevice;
1312 PDEVICE_RELATIONS DeviceRelations;
1313 ULONG PdoCount, i = 0;
1314
1315 PAGED_CODE();
1316
1317 IsaPnpAcquireBusDataLock();
1318
1319 /* Try to claim the Read Port for our FDO */
1320 if (!ReadPortCreated)
1321 {
1323 if (!NT_SUCCESS(Status))
1324 return Status;
1325
1326 ReadPortCreated = TRUE;
1327 }
1328
1329 IsaPnpReleaseBusDataLock();
1330
1331 /* Inactive ISA bus */
1332 if (!FdoExt->ReadPortPdo)
1333 IncludeDataPort = FALSE;
1334
1335 IsaPnpAcquireDeviceDataLock(FdoExt);
1336
1337 /* If called from the FDO dispatch routine && Active bus */
1338 if (IncludeDataPort && FdoExt->ReadPortPdo)
1339 {
1340 PISAPNP_PDO_EXTENSION ReadPortExt = FdoExt->ReadPortPdo->DeviceExtension;
1341
1342 if ((ReadPortExt->Flags & ISAPNP_READ_PORT_ALLOW_FDO_SCAN) &&
1343 !(ReadPortExt->Flags & ISAPNP_SCANNED_BY_READ_PORT))
1344 {
1345 DPRINT("Rescan ISA PnP bus\n");
1346
1347 /* Run the isolation protocol */
1348 FdoExt->Cards = IsaHwTryReadDataPort(FdoExt->ReadDataPort);
1349
1350 /* Card identification */
1351 if (FdoExt->Cards > 0)
1352 (VOID)IsaHwFillDeviceList(FdoExt);
1353
1354 IsaHwWaitForKey();
1355 }
1356
1357 ReadPortExt->Flags &= ~ISAPNP_SCANNED_BY_READ_PORT;
1358 }
1359
1360 PdoCount = FdoExt->DeviceCount;
1361 if (IncludeDataPort)
1362 ++PdoCount;
1363
1364 CurrentEntry = FdoExt->DeviceListHead.Flink;
1365 while (CurrentEntry != &FdoExt->DeviceListHead)
1366 {
1367 IsaDevice = CONTAINING_RECORD(CurrentEntry, ISAPNP_LOGICAL_DEVICE, DeviceLink);
1368
1369 if (!(IsaDevice->Flags & ISAPNP_PRESENT))
1370 --PdoCount;
1371
1372 CurrentEntry = CurrentEntry->Flink;
1373 }
1374
1375 DeviceRelations = ExAllocatePoolWithTag(PagedPool,
1376 FIELD_OFFSET(DEVICE_RELATIONS, Objects[PdoCount]),
1377 TAG_ISAPNP);
1378 if (!DeviceRelations)
1379 {
1380 IsaPnpReleaseDeviceDataLock(FdoExt);
1381 return STATUS_NO_MEMORY;
1382 }
1383
1384 if (IncludeDataPort)
1385 {
1386 PISAPNP_PDO_EXTENSION ReadPortExt = FdoExt->ReadPortPdo->DeviceExtension;
1387
1388 DeviceRelations->Objects[i++] = FdoExt->ReadPortPdo;
1389 ObReferenceObject(FdoExt->ReadPortPdo);
1390
1391 /* The Read Port PDO can only be removed by FDO */
1392 ReadPortExt->Flags |= ISAPNP_ENUMERATED;
1393 }
1394
1395 CurrentEntry = FdoExt->DeviceListHead.Flink;
1396 while (CurrentEntry != &FdoExt->DeviceListHead)
1397 {
1399
1400 IsaDevice = CONTAINING_RECORD(CurrentEntry, ISAPNP_LOGICAL_DEVICE, DeviceLink);
1401
1402 if (!(IsaDevice->Flags & ISAPNP_PRESENT))
1403 goto SkipPdo;
1404
1405 if (!IsaDevice->Pdo)
1406 {
1407 Status = IoCreateDevice(FdoExt->DriverObject,
1408 sizeof(ISAPNP_PDO_EXTENSION),
1409 NULL,
1412 FALSE,
1413 &IsaDevice->Pdo);
1414 if (!NT_SUCCESS(Status))
1415 goto SkipPdo;
1416
1417 IsaDevice->Pdo->Flags &= ~DO_DEVICE_INITIALIZING;
1418 /* The power pagable flag is always unset */
1419
1420 PdoExt = IsaDevice->Pdo->DeviceExtension;
1421
1423 PdoExt->Common.Signature = IsaPnpLogicalDevice;
1424 PdoExt->Common.Self = IsaDevice->Pdo;
1425 PdoExt->Common.State = dsStopped;
1426 PdoExt->IsaPnpDevice = IsaDevice;
1427 PdoExt->FdoExt = FdoExt;
1428
1431 {
1432 if (PdoExt->RequirementsList)
1433 {
1434 ExFreePoolWithTag(PdoExt->RequirementsList, TAG_ISAPNP);
1435 PdoExt->RequirementsList = NULL;
1436 }
1437
1438 if (PdoExt->ResourceList)
1439 {
1440 ExFreePoolWithTag(PdoExt->ResourceList, TAG_ISAPNP);
1441 PdoExt->ResourceList = NULL;
1442 }
1443
1444 IoDeleteDevice(IsaDevice->Pdo);
1445 IsaDevice->Pdo = NULL;
1446 goto SkipPdo;
1447 }
1448 }
1449 else
1450 {
1451 PdoExt = IsaDevice->Pdo->DeviceExtension;
1452 }
1453 DeviceRelations->Objects[i++] = IsaDevice->Pdo;
1454 ObReferenceObject(IsaDevice->Pdo);
1455
1456 PdoExt->Flags |= ISAPNP_ENUMERATED;
1457
1458 CurrentEntry = CurrentEntry->Flink;
1459 continue;
1460
1461SkipPdo:
1462 if (IsaDevice->Pdo)
1463 {
1464 PdoExt = IsaDevice->Pdo->DeviceExtension;
1465
1466 if (PdoExt)
1467 PdoExt->Flags &= ~ISAPNP_ENUMERATED;
1468 }
1469
1470 CurrentEntry = CurrentEntry->Flink;
1471 }
1472
1473 IsaPnpReleaseDeviceDataLock(FdoExt);
1474
1475 DeviceRelations->Count = i;
1476
1477 Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations;
1478
1479 return Status;
1480}
#define VOID
Definition: acefi.h:82
UCHAR IsaHwTryReadDataPort(_In_ PUCHAR ReadDataPort)
Definition: hardware.c:1362
#define ULONG_PTR
Definition: config.h:101
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
static NTSTATUS IsaPnpCreateLogicalDeviceRequirements(_In_ PISAPNP_PDO_EXTENSION PdoExt)
Definition: isapnp.c:194
static NTSTATUS IsaPnpCreateLogicalDeviceResources(_In_ PISAPNP_PDO_EXTENSION PdoExt)
Definition: isapnp.c:788
static NTSTATUS IsaPnpCreateReadPortDO(_In_ PISAPNP_FDO_EXTENSION FdoExt)
Definition: isapnp.c:1234
#define ISAPNP_READ_PORT_ALLOW_FDO_SCAN
Allows the active FDO to scan the bus.
Definition: isapnp.h:189
@ IsaPnpLogicalDevice
Definition: isapnp.h:144
#define ISAPNP_PRESENT
Cleared when the device is physically removed.
Definition: isapnp.h:134
#define ISAPNP_SCANNED_BY_READ_PORT
The bus has been scanned by Read Port PDO.
Definition: isapnp.h:188
#define ISAPNP_ENUMERATED
Whether the device has been reported to the PnP manager.
Definition: isapnp.h:187
PVOID DeviceExtension
Definition: env_spec_w32.h:418
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2163
PDEVICE_OBJECT Pdo
Definition: isapnp.h:103
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
#define ObReferenceObject
Definition: obfuncs.h:204

Referenced by IsaFdoQueryBusRelations(), and IsaPdoQueryDeviceRelations().

◆ IsaPnpRemoveReadPortDO()

VOID IsaPnpRemoveReadPortDO ( _In_ PDEVICE_OBJECT  Pdo)

Definition at line 1284 of file isapnp.c.

1286{
1287 PISAPNP_PDO_EXTENSION ReadPortExt = Pdo->DeviceExtension;
1288
1289 PAGED_CODE();
1290
1291 DPRINT("Removing Read Port\n");
1292
1293 if (ReadPortExt->RequirementsList)
1295
1296 if (ReadPortExt->ResourceList)
1298
1300}
PCM_RESOURCE_LIST ResourceList
Definition: isapnp.h:183
PIO_RESOURCE_REQUIREMENTS_LIST RequirementsList
Definition: isapnp.h:181
WDF_EXTERN_C_START typedef _Must_inspect_result_ _In_ WDFDRIVER _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ PDEVICE_OBJECT _In_opt_ PDEVICE_OBJECT _In_opt_ PDEVICE_OBJECT Pdo
Definition: wdfminiport.h:72

Referenced by IsaFdoRemoveDevice(), IsaPnpCreateReadPortDO(), and IsaReadPortRemoveDevice().

Variable Documentation

◆ BusSyncEvent

KEVENT BusSyncEvent

Definition at line 21 of file isapnp.c.

Referenced by _Releases_lock_(), _Requires_lock_not_held_(), and DriverEntry().