ReactOS 0.4.17-dev-1190-g4c812f4
pdo.c File Reference
#include <pci.h>
#include <debug.h>
Include dependency graph for pdo.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

 C_ASSERT (FIELD_OFFSET(PCI_FDO_EXTENSION, DeviceState)==FIELD_OFFSET(PCI_PDO_EXTENSION, DeviceState))
 
 C_ASSERT (FIELD_OFFSET(PCI_FDO_EXTENSION, TentativeNextState)==FIELD_OFFSET(PCI_PDO_EXTENSION, TentativeNextState))
 
 C_ASSERT (FIELD_OFFSET(PCI_FDO_EXTENSION, List)==FIELD_OFFSET(PCI_PDO_EXTENSION, Next))
 
static NTSTATUS NTAPI PciPdoEnterDevicePowerState (_Inout_ PPCI_PDO_EXTENSION DeviceExtension, _In_ DEVICE_POWER_STATE DeviceState)
 Moves a function to a device power state and reports it to the power manager.
 
NTSTATUS NTAPI PciPdoWaitWake (IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI PciPdoSetPowerState (IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI PciPdoIrpQueryPower (IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI PciPdoIrpStartDevice (IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
 
static NTSTATUS NTAPI PciPdoValidateRelease (_In_ PPCI_PDO_EXTENSION DeviceExtension)
 Checks the uses of a function that keep it from being stopped or removed.
 
static BOOLEAN NTAPI PciPdoCanTurnOff (_In_ PPCI_PDO_EXTENSION DeviceExtension)
 Checks whether a function may stop decoding for as long as it is stopped or removed.
 
static BOOLEAN NTAPI PciPdoIsPresent (_Inout_ PPCI_PDO_EXTENSION DeviceExtension)
 Reads the identity back from the slot to learn whether the function is still there.
 
static VOID NTAPI PciPdoTurnOff (_Inout_ PPCI_PDO_EXTENSION DeviceExtension, _In_ BOOLEAN PowerDown)
 Stops a function from decoding, mastering and raising interrupts, and optionally moves it to D3.
 
static BOOLEAN NTAPI PciPdoCanPowerDown (_In_ PPCI_PDO_EXTENSION DeviceExtension, _In_ DEVICE_POWER_STATE DeviceState)
 Checks whether a request for a low power device state may take power from a function.
 
static VOID NTAPI PciPdoDevicePowerWorker (_In_ PDEVICE_OBJECT DeviceObject, _In_opt_ PVOID Context)
 Completes a device set power request that arrived at raised IRQL.
 
NTSTATUS NTAPI PciPdoIrpQueryRemoveDevice (IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI PciPdoIrpRemoveDevice (IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI PciPdoIrpCancelRemoveDevice (IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI PciPdoIrpStopDevice (IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI PciPdoIrpQueryStopDevice (IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI PciPdoIrpCancelStopDevice (IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI PciPdoIrpQueryInterface (IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI PciPdoIrpQueryDeviceRelations (IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI PciPdoIrpQueryCapabilities (IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI PciPdoIrpQueryResources (IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI PciPdoIrpQueryResourceRequirements (IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI PciPdoIrpQueryDeviceText (IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI PciPdoIrpQueryId (IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI PciPdoIrpQueryBusInformation (IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
 
static NTSTATUS NTAPI PciPdoReadWriteConfig (_Inout_ PIRP Irp, _In_ PIO_STACK_LOCATION IoStackLocation, _In_ PPCI_PDO_EXTENSION DeviceExtension, _In_ BOOLEAN Read)
 Serves a driver's read or write of its own function's configuration space.
 
NTSTATUS NTAPI PciPdoIrpReadConfig (IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI PciPdoIrpWriteConfig (IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI PciPdoIrpQueryDeviceState (IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI PciPdoIrpDeviceUsageNotification (IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI PciPdoIrpSurpriseRemoval (IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI PciPdoIrpQueryLegacyBusInformation (IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI PciPdoCreate (IN PPCI_FDO_EXTENSION DeviceExtension, IN PCI_SLOT_NUMBER Slot, OUT PDEVICE_OBJECT *PdoDeviceObject)
 

Variables

LONG PciPdoSequenceNumber
 
PCI_MN_DISPATCH_TABLE PciPdoDispatchPowerTable []
 
PCI_MN_DISPATCH_TABLE PciPdoDispatchPnpTable []
 
PCI_MJ_DISPATCH_TABLE PciPdoDispatchTable
 
static IO_WORKITEM_ROUTINE PciPdoDevicePowerWorker
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file pdo.c.

Function Documentation

◆ C_ASSERT() [1/3]

◆ C_ASSERT() [2/3]

◆ C_ASSERT() [3/3]

C_ASSERT ( FIELD_OFFSET(PCI_FDO_EXTENSION, TentativeNextState)  = =FIELD_OFFSET(PCI_PDO_EXTENSION, TentativeNextState))

◆ PciPdoCanPowerDown()

static BOOLEAN NTAPI PciPdoCanPowerDown ( _In_ PPCI_PDO_EXTENSION  DeviceExtension,
_In_ DEVICE_POWER_STATE  DeviceState 
)
static

Checks whether a request for a low power device state may take power from a function.

Parameters
[in]DeviceExtensionThe PDO extension of the function.
[in]DeviceStateThe low power state being entered.
Returns
FALSE if the function has to stay in D0 and keep decoding.

Definition at line 402 of file pdo.c.

405{
406 SYSTEM_POWER_STATE SystemState = DeviceExtension->PowerState.CurrentSystemState;
407
408 /* Critical functions, VGA and the debug path keep decoding, so they keep power too */
409 if (!PciPdoCanTurnOff(DeviceExtension))
410 return FALSE;
411
412 /* IDE controllers and legacy bridges stay in D0 */
413 if (!PciCanDisableDecodes(DeviceExtension, NULL, 0, TRUE))
414 return FALSE;
415
416 /* The hibernation file and crash dump are written through this function */
417 if ((SystemState == PowerSystemHibernate) &&
418 (DeviceExtension->PowerState.Hibernate || DeviceExtension->PowerState.CrashDump))
419 {
420 return FALSE;
421 }
422
423 /* On a warm reboot firmware may not power a bridge up again before booting from behind it */
424 if ((SystemState == PowerSystemShutdown) &&
426 (DeviceExtension->BaseClass == PCI_CLASS_BRIDGE_DEV) &&
427 (DeviceExtension->SubClass == PCI_SUBCLASS_BR_PCI_TO_PCI))
428 {
429 return FALSE;
430 }
431
432 return TRUE;
433}
static BOOLEAN NTAPI PciPdoCanTurnOff(_In_ PPCI_PDO_EXTENSION DeviceExtension)
Checks whether a function may stop decoding for as long as it is stopped or removed.
Definition: pdo.c:300
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOLEAN NTAPI PciCanDisableDecodes(IN PPCI_PDO_EXTENSION DeviceExtension, IN PPCI_COMMON_HEADER Config, IN ULONGLONG HackFlags, IN BOOLEAN ForPowerDown)
Definition: utils.c:1027
@ PowerSystemShutdown
Definition: ntpoapi.h:41
@ PowerSystemHibernate
Definition: ntpoapi.h:40
@ PowerDeviceD3
Definition: ntpoapi.h:52
enum _SYSTEM_POWER_STATE SYSTEM_POWER_STATE
_In_ WDFDEVICE _Out_ PWDF_DEVICE_STATE DeviceState
Definition: wdfdevice.h:2005
#define PCI_SUBCLASS_BR_PCI_TO_PCI
Definition: iotypes.h:4181
#define PCI_CLASS_BRIDGE_DEV
Definition: iotypes.h:4124

Referenced by PciPdoEnterDevicePowerState().

◆ PciPdoCanTurnOff()

static BOOLEAN NTAPI PciPdoCanTurnOff ( _In_ PPCI_PDO_EXTENSION  DeviceExtension)
static

Checks whether a function may stop decoding for as long as it is stopped or removed.

Parameters
[in]DeviceExtensionThe PDO extension of the function.
Returns
TRUE if the decodes and interrupts of the function can be turned off.

Definition at line 300 of file pdo.c.

302{
303 /* Critical functions, VGA, legacy bridges and the debug path keep decoding */
304 return PciCanDisableDecodes(DeviceExtension, NULL, 0, FALSE);
305}

Referenced by PciPdoCanPowerDown(), PciPdoIrpQueryStopDevice(), and PciPdoTurnOff().

◆ PciPdoCreate()

NTSTATUS NTAPI PciPdoCreate ( IN PPCI_FDO_EXTENSION  DeviceExtension,
IN PCI_SLOT_NUMBER  Slot,
OUT PDEVICE_OBJECT *  PdoDeviceObject 
)

Definition at line 1022 of file pdo.c.

1025{
1026 WCHAR DeviceName[32];
1027 UNICODE_STRING DeviceString;
1031 ULONG SequenceNumber;
1032 PAGED_CODE();
1033
1034 /* Pick an atomically unique sequence number for this device */
1035 SequenceNumber = InterlockedIncrement(&PciPdoSequenceNumber);
1036
1037 /* Create the standard PCI device name for a PDO */
1038 _swprintf(DeviceName, L"\\Device\\NTPNP_PCI%04d", SequenceNumber);
1039 RtlInitUnicodeString(&DeviceString, DeviceName);
1040
1041 /* Create the actual device now */
1042 Status = IoCreateDevice(DeviceExtension->FunctionalDeviceObject->DriverObject,
1043 sizeof(PCI_PDO_EXTENSION),
1044 &DeviceString,
1046 0,
1047 0,
1048 &DeviceObject);
1050
1051 /* Get the extension for it */
1052 PdoExtension = (PPCI_PDO_EXTENSION)DeviceObject->DeviceExtension;
1053 DPRINT1("PCIX - New PDO (b=0x%x, d=0x%x, f=0x%x) @ %p, ext @ %p\n",
1054 DeviceExtension->BaseBus,
1055 Slot.u.bits.DeviceNumber,
1056 Slot.u.bits.FunctionNumber,
1058 DeviceObject->DeviceExtension);
1059
1060 /* Configure the extension */
1061 PdoExtension->ExtensionType = PciPdoExtensionType;
1062 PdoExtension->IrpDispatchTable = &PciPdoDispatchTable;
1063 PdoExtension->PhysicalDeviceObject = DeviceObject;
1064 PdoExtension->Slot = Slot;
1065 PdoExtension->PowerState.CurrentSystemState = PowerSystemWorking;
1066 PdoExtension->PowerState.CurrentDeviceState = PowerDeviceD0;
1067 PdoExtension->ParentFdoExtension = DeviceExtension;
1068
1069 /* Initialize the lock for arbiters and other interfaces */
1071
1072 /* Initialize the state machine */
1074
1075 /* Add the PDO to the parent's list */
1076 PdoExtension->Next = NULL;
1077 PciInsertEntryAtTail((PSINGLE_LIST_ENTRY)&DeviceExtension->ChildPdoList,
1079 &DeviceExtension->ChildListLock);
1080
1081 /* And finally return it to the caller */
1083 return STATUS_SUCCESS;
1084}
#define PAGED_CODE()
#define InterlockedIncrement
Definition: armddk.h:53
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
PCI_MJ_DISPATCH_TABLE PciPdoDispatchTable
Definition: pdo.c:63
LONG PciPdoSequenceNumber
Definition: pdo.c:18
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define L(x)
Definition: resources.c:13
VOID NTAPI PciInsertEntryAtTail(IN PSINGLE_LIST_ENTRY ListHead, IN PPCI_FDO_EXTENSION DeviceExtension, IN PKEVENT Lock)
Definition: utils.c:400
struct _PCI_PDO_EXTENSION * PPCI_PDO_EXTENSION
VOID NTAPI PciInitializeState(IN PPCI_FDO_EXTENSION DeviceExtension)
Definition: state.c:88
@ PciPdoExtensionType
Definition: pci.h:133
@ PdoExtension
Definition: precomp.h:61
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
Status
Definition: gdiplustypes.h:24
_Outptr_ PUSB_DEVICE_HANDLE _In_ PUSB_DEVICE_HANDLE _In_ USHORT _In_ PUSB_PORT_PATH _Out_ PUSB_CD_ERROR_INFORMATION _In_ USHORT _In_ PDEVICE_OBJECT PdoDeviceObject
Definition: hubbusif.h:95
#define ASSERT(a)
Definition: mode.c:44
#define _swprintf(buf, format,...)
Definition: sprintf.c:56
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
@ SynchronizationEvent
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:1038
@ PowerSystemWorking
Definition: ntpoapi.h:36
@ PowerDeviceD0
Definition: ntpoapi.h:49
short WCHAR
Definition: pedump.c:58
#define FILE_DEVICE_BUS_EXTENDER
Definition: winioctl.h:87
#define STATUS_SUCCESS
Definition: shellext.h:65
Definition: ntbasedef.h:640
uint32_t ULONG
Definition: typedefs.h:59
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2061
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3281

Referenced by PciScanBus().

◆ PciPdoDevicePowerWorker()

static VOID NTAPI PciPdoDevicePowerWorker ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_opt_ PVOID  Context 
)
static

Completes a device set power request that arrived at raised IRQL.

Parameters
[in]ContextThe pending device power IRP.

Definition at line 511 of file pdo.c.

514{
515 PIRP Irp = Context;
518
519 ASSERT(Irp != NULL);
520
521 IoFreeWorkItem(Irp->Tail.Overlay.DriverContext[0]);
522
524 DeviceState = IoStackLocation->Parameters.Power.State.DeviceState;
525
526 Irp->IoStatus.Status = PciPdoEnterDevicePowerState(DeviceObject->DeviceExtension,
530}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
static NTSTATUS NTAPI PciPdoEnterDevicePowerState(_Inout_ PPCI_PDO_EXTENSION DeviceExtension, _In_ DEVICE_POWER_STATE DeviceState)
Moves a function to a device power state and reports it to the power manager.
Definition: pdo.c:451
VOID NTAPI IoFreeWorkItem(IN PIO_WORKITEM IoWorkItem)
Definition: iowork.c:64
_In_ PIRP Irp
Definition: kse.h:79
_In_ PIRP _In_ PIO_COMPLETION_ROUTINE _In_ PVOID Context
Definition: kse.h:81
#define IoCompleteRequest
Definition: irp.c:1272
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:758
enum _DEVICE_POWER_STATE DEVICE_POWER_STATE
union _IO_STACK_LOCATION::@1814 Parameters
struct _IO_STACK_LOCATION::@5020::@5056 Power
_In_ PIO_STACK_LOCATION IoStackLocation
Definition: usbdlib.h:292
#define IO_NO_INCREMENT
Definition: iotypes.h:598

◆ PciPdoEnterDevicePowerState()

static NTSTATUS NTAPI PciPdoEnterDevicePowerState ( _Inout_ PPCI_PDO_EXTENSION  DeviceExtension,
_In_ DEVICE_POWER_STATE  DeviceState 
)
static

Moves a function to a device power state and reports it to the power manager.

Parameters
[in,out]DeviceExtensionThe PDO extension of the function.
[in]DeviceStateThe state to enter, D0 through D3.
Returns
STATUS_SUCCESS, or the error that kept the function from returning to D0.

Definition at line 451 of file pdo.c.

454{
457 PAGED_CODE();
458
459 if (DeviceState == DeviceExtension->PowerState.CurrentDeviceState)
460 return STATUS_SUCCESS;
461
462 PowerState.DeviceState = DeviceState;
463
465 {
466 /* After the settle delay this also writes the configuration and interrupt back */
468 if (!NT_SUCCESS(Status))
469 {
470 DPRINT1("PCIX - pdox %p failed to return to D0 (0x%08lx)\n", DeviceExtension, Status);
471 return Status;
472 }
473
474 DeviceExtension->PowerState.CurrentDeviceState = PowerDeviceD0;
475 PoSetPowerState(DeviceExtension->PhysicalDeviceObject, DevicePowerState, PowerState);
476 return STATUS_SUCCESS;
477 }
478
479 /* The power manager learns of a power down before the function loses power */
480 PoSetPowerState(DeviceExtension->PhysicalDeviceObject, DevicePowerState, PowerState);
481
482 if (PciPdoCanPowerDown(DeviceExtension, DeviceState))
483 {
484 PciPdoTurnOff(DeviceExtension, FALSE);
485
487 if (!NT_SUCCESS(Status))
488 {
489 DPRINT1("PCIX - pdox %p did not settle in device state %lu (0x%08lx)\n",
490 DeviceExtension,
492 Status);
493 }
494 }
495
496 /* A function kept running is still reprogrammed by the next D0 */
497 DeviceExtension->PowerState.CurrentDeviceState = DeviceState;
498 return STATUS_SUCCESS;
499}
static VOID NTAPI PciPdoTurnOff(_Inout_ PPCI_PDO_EXTENSION DeviceExtension, _In_ BOOLEAN PowerDown)
Stops a function from decoding, mastering and raising interrupts, and optionally moves it to D3.
Definition: pdo.c:353
static BOOLEAN NTAPI PciPdoCanPowerDown(_In_ PPCI_PDO_EXTENSION DeviceExtension, _In_ DEVICE_POWER_STATE DeviceState)
Checks whether a request for a low power device state may take power from a function.
Definition: pdo.c:402
_Check_return_ _In_ ULONG _In_ DEVICE_POWER_STATE DevicePowerState
Definition: dispmprt.h:1274
NTSTATUS NTAPI PciSetPowerManagedDevicePowerState(IN PPCI_PDO_EXTENSION DeviceExtension, IN DEVICE_POWER_STATE DeviceState, IN BOOLEAN IrpSet)
Definition: power.c:123
POWER_STATE NTAPI PoSetPowerState(IN PDEVICE_OBJECT DeviceObject, IN POWER_STATE_TYPE Type, IN POWER_STATE State)
Definition: power.c:729
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ WDF_DEVICE_POWER_STATE PowerState
Definition: wdfdevice.h:3040

Referenced by PciPdoDevicePowerWorker(), and PciPdoSetPowerState().

◆ PciPdoIrpCancelRemoveDevice()

NTSTATUS NTAPI PciPdoIrpCancelRemoveDevice ( IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation,
IN PPCI_PDO_EXTENSION  DeviceExtension 
)

Definition at line 597 of file pdo.c.

600{
601 PAGED_CODE();
602
605
606 /* The remove is off, so the device stays where it was */
608 return STATUS_SUCCESS;
609}
@ PciNotStarted
Definition: pci.h:168
NTSTATUS NTAPI PciCancelStateTransition(IN PPCI_FDO_EXTENSION DeviceExtension, IN PCI_STATE NewState)
Definition: state.c:145
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:329

◆ PciPdoIrpCancelStopDevice()

NTSTATUS NTAPI PciPdoIrpCancelStopDevice ( IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation,
IN PPCI_PDO_EXTENSION  DeviceExtension 
)

Definition at line 655 of file pdo.c.

658{
659 PAGED_CODE();
660
663
664 /* The stop is off, so the device keeps what it has */
665 PciCancelStateTransition((PVOID)DeviceExtension, PciStopped);
666 return STATUS_SUCCESS;
667}
@ PciStopped
Definition: pci.h:171

◆ PciPdoIrpDeviceUsageNotification()

NTSTATUS NTAPI PciPdoIrpDeviceUsageNotification ( IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation,
IN PPCI_PDO_EXTENSION  DeviceExtension 
)

Definition at line 956 of file pdo.c.

959{
961 PAGED_CODE();
962
964
965 /* Every bus up to the root has to hold on to the path, so it goes up first */
966 Status = PciSendDeviceUsageToParent(DeviceExtension->ParentFdoExtension,
968 if (!NT_SUCCESS(Status))
969 return Status;
970
971 return PciUpdateDeviceUsage(&DeviceExtension->PowerState, IoStackLocation);
972}
NTSTATUS NTAPI PciSendDeviceUsageToParent(_In_ PPCI_FDO_EXTENSION ParentFdoExtension, _In_ PIO_STACK_LOCATION IoStackLocation)
Sends a device usage notification to the top of the stack of a parent bus.
Definition: usage.c:94
NTSTATUS NTAPI PciUpdateDeviceUsage(_Inout_ PPCI_POWER_STATE PowerState, _In_ PIO_STACK_LOCATION IoStackLocation)
Counts a paging, hibernation or dump file arriving on or leaving a device.
Definition: usage.c:35

◆ PciPdoIrpQueryBusInformation()

NTSTATUS NTAPI PciPdoIrpQueryBusInformation ( IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation,
IN PPCI_PDO_EXTENSION  DeviceExtension 
)

Definition at line 809 of file pdo.c.

812{
813 PAGED_CODE();
814
816
817 /* Call the worker function */
818 return PciQueryBusInformation(DeviceExtension,
820 IoStatus.Information);
821}
NTSTATUS NTAPI PciQueryBusInformation(IN PPCI_PDO_EXTENSION PdoExtension, OUT PPNP_BUS_INFORMATION *Buffer)
Definition: utils.c:1408
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:159

◆ PciPdoIrpQueryCapabilities()

NTSTATUS NTAPI PciPdoIrpQueryCapabilities ( IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation,
IN PPCI_PDO_EXTENSION  DeviceExtension 
)

Definition at line 731 of file pdo.c.

734{
735 PAGED_CODE();
736
738
739 /* Call the worker function */
740 return PciQueryCapabilities(DeviceExtension,
742 Parameters.DeviceCapabilities.Capabilities);
743}
_In_ HANDLE _In_ CONST PDXGKMDT_OPM_GET_INFO_PARAMETERS Parameters
Definition: dispmprt.h:321
NTSTATUS NTAPI PciQueryCapabilities(IN PPCI_PDO_EXTENSION PdoExtension, IN OUT PDEVICE_CAPABILITIES DeviceCapability)
Definition: utils.c:1820
struct _IO_STACK_LOCATION::@5020::@5047 DeviceCapabilities

◆ PciPdoIrpQueryDeviceRelations()

NTSTATUS NTAPI PciPdoIrpQueryDeviceRelations ( IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation,
IN PPCI_PDO_EXTENSION  DeviceExtension 
)

Definition at line 697 of file pdo.c.

700{
702 PAGED_CODE();
703
704 /* Are ejection relations being queried? */
706 {
707 /* Call the worker function */
708 Status = PciQueryEjectionRelations(DeviceExtension,
710 IoStatus.Information);
711 }
713 {
714 /* The only other relation supported is the target device relation */
715 Status = PciQueryTargetDeviceRelations(DeviceExtension,
717 IoStatus.Information);
718 }
719 else
720 {
721 /* All other relations are unsupported */
723 }
724
725 /* Return either the result of the worker function, or unsupported status */
726 return Status;
727}
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
NTSTATUS NTAPI PciQueryEjectionRelations(IN PPCI_PDO_EXTENSION PdoExtension, IN OUT PDEVICE_RELATIONS *pDeviceRelations)
Definition: enum.c:614
NTSTATUS NTAPI PciQueryTargetDeviceRelations(IN PPCI_PDO_EXTENSION PdoExtension, IN OUT PDEVICE_RELATIONS *pDeviceRelations)
Definition: enum.c:552
struct _IO_STACK_LOCATION::@5020::@5045 QueryDeviceRelations
@ EjectionRelations
Definition: iotypes.h:2155
@ TargetDeviceRelation
Definition: iotypes.h:2158

◆ PciPdoIrpQueryDeviceState()

NTSTATUS NTAPI PciPdoIrpQueryDeviceState ( IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation,
IN PPCI_PDO_EXTENSION  DeviceExtension 
)

Definition at line 930 of file pdo.c.

933{
935 PAGED_CODE();
936
938
939 /* Whatever the rest of the stack decided about this device still holds */
940 State = (PNP_DEVICE_STATE)Irp->IoStatus.Information;
941
942 /* Host bridges, and anything a query remove would refuse, must not be offered for disabling */
943 if (((DeviceExtension->BaseClass == PCI_CLASS_BRIDGE_DEV) &&
944 (DeviceExtension->SubClass == PCI_SUBCLASS_BR_HOST)) ||
945 (!NT_SUCCESS(PciPdoValidateRelease(DeviceExtension))))
946 {
948 }
949
950 Irp->IoStatus.Information = State;
951 return STATUS_SUCCESS;
952}
static NTSTATUS NTAPI PciPdoValidateRelease(_In_ PPCI_PDO_EXTENSION DeviceExtension)
Checks the uses of a function that keep it from being stopped or removed.
Definition: pdo.c:268
if(dx< 0)
Definition: linetemp.h:194
#define PNP_DEVICE_NOT_DISABLEABLE
Definition: iotypes.h:1006
#define PCI_SUBCLASS_BR_HOST
Definition: iotypes.h:4177
ULONG PNP_DEVICE_STATE
Definition: iotypes.h:997

◆ PciPdoIrpQueryDeviceText()

NTSTATUS NTAPI PciPdoIrpQueryDeviceText ( IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation,
IN PPCI_PDO_EXTENSION  DeviceExtension 
)

Definition at line 778 of file pdo.c.

781{
782 PAGED_CODE();
783
784 /* Call the worker function */
785 return PciQueryDeviceText(DeviceExtension,
787 Parameters.QueryDeviceText.DeviceTextType,
790 (PWCHAR*)&Irp->IoStatus.Information);
791}
NTSTATUS NTAPI PciQueryDeviceText(IN PPCI_PDO_EXTENSION PdoExtension, IN DEVICE_TEXT_TYPE QueryType, IN ULONG Locale, OUT PWCHAR *Buffer)
Definition: id.c:422
struct _IO_STACK_LOCATION::@5020::@5052 QueryDeviceText
uint16_t * PWCHAR
Definition: typedefs.h:56

◆ PciPdoIrpQueryId()

NTSTATUS NTAPI PciPdoIrpQueryId ( IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation,
IN PPCI_PDO_EXTENSION  DeviceExtension 
)

Definition at line 795 of file pdo.c.

798{
799 PAGED_CODE();
800
801 /* Call the worker function */
802 return PciQueryId(DeviceExtension,
804 (PWCHAR*)&Irp->IoStatus.Information);
805}
NTSTATUS NTAPI PciQueryId(IN PPCI_PDO_EXTENSION DeviceExtension, IN BUS_QUERY_ID_TYPE QueryType, OUT PWCHAR *Buffer)
Definition: id.c:217
struct _IO_STACK_LOCATION::@5020::@5051 QueryId

◆ PciPdoIrpQueryInterface()

NTSTATUS NTAPI PciPdoIrpQueryInterface ( IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation,
IN PPCI_PDO_EXTENSION  DeviceExtension 
)

Definition at line 671 of file pdo.c.

674{
676 PAGED_CODE();
677
679
680 /* Query the interface from the PCI driver */
682 (PPCI_FDO_EXTENSION)DeviceExtension,
686 IoStackLocation->Parameters.QueryInterface.InterfaceSpecificData,
688 FALSE);
689
690 /* TODO: There's more to this story, but NOT TODAY! */
691
692 return Status;
693}
NTSTATUS NTAPI PciQueryInterface(IN PPCI_FDO_EXTENSION DeviceExtension, IN CONST GUID *InterfaceType, IN ULONG Size, IN ULONG Version, IN PVOID InterfaceData, IN PINTERFACE Interface, IN BOOLEAN LastChance)
Definition: intrface.c:45
struct _IO_STACK_LOCATION::@5020::@5046 QueryInterface

◆ PciPdoIrpQueryLegacyBusInformation()

NTSTATUS NTAPI PciPdoIrpQueryLegacyBusInformation ( IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation,
IN PPCI_PDO_EXTENSION  DeviceExtension 
)

Definition at line 1006 of file pdo.c.

1009{
1010 PAGED_CODE();
1011
1014 UNREFERENCED_PARAMETER(DeviceExtension);
1015
1016 /* A bridge's FDO answers above this, so keep its bus number and buffer intact */
1017 return STATUS_NOT_SUPPORTED;
1018}

◆ PciPdoIrpQueryPower()

NTSTATUS NTAPI PciPdoIrpQueryPower ( IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation,
IN PPCI_PDO_EXTENSION  DeviceExtension 
)

Definition at line 144 of file pdo.c.

147{
150 UNREFERENCED_PARAMETER(DeviceExtension);
151
152 /* Every device state is accepted when set, so none is refused here */
153 return STATUS_SUCCESS;
154}

◆ PciPdoIrpQueryRemoveDevice()

NTSTATUS NTAPI PciPdoIrpQueryRemoveDevice ( IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation,
IN PPCI_PDO_EXTENSION  DeviceExtension 
)

Definition at line 534 of file pdo.c.

537{
539 PAGED_CODE();
540
543
544 if (DeviceExtension->HackFlags & PCI_HACK_FAIL_QUERY_REMOVE)
545 return STATUS_DEVICE_BUSY;
546
547 Status = PciPdoValidateRelease(DeviceExtension);
548 if (!NT_SUCCESS(Status))
549 return Status;
550
551 /* A function that was never started has no state to leave */
552 if (DeviceExtension->DeviceState == PciNotStarted)
553 return STATUS_SUCCESS;
554
555 return PciBeginStateTransition((PVOID)DeviceExtension, PciNotStarted);
556}
NTSTATUS NTAPI PciBeginStateTransition(IN PPCI_FDO_EXTENSION DeviceExtension, IN PCI_STATE NewState)
Definition: state.c:97
#define PCI_HACK_FAIL_QUERY_REMOVE
Definition: pci.h:47
#define STATUS_DEVICE_BUSY
Definition: udferr_usr.h:129

◆ PciPdoIrpQueryResourceRequirements()

NTSTATUS NTAPI PciPdoIrpQueryResourceRequirements ( IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation,
IN PPCI_PDO_EXTENSION  DeviceExtension 
)

Definition at line 762 of file pdo.c.

765{
766 PAGED_CODE();
767
769
770 /* Call the worker function */
771 return PciQueryRequirements(DeviceExtension,
773 IoStatus.Information);
774}
NTSTATUS NTAPI PciQueryRequirements(IN PPCI_PDO_EXTENSION PdoExtension, IN OUT PIO_RESOURCE_REQUIREMENTS_LIST *RequirementsList)
Definition: enum.c:882

◆ PciPdoIrpQueryResources()

NTSTATUS NTAPI PciPdoIrpQueryResources ( IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation,
IN PPCI_PDO_EXTENSION  DeviceExtension 
)

Definition at line 747 of file pdo.c.

750{
751 PAGED_CODE();
752
754
755 /* Call the worker function */
756 return PciQueryResources(DeviceExtension,
757 (PCM_RESOURCE_LIST*)&Irp->IoStatus.Information);
758}
NTSTATUS NTAPI PciQueryResources(IN PPCI_PDO_EXTENSION PdoExtension, OUT PCM_RESOURCE_LIST *Buffer)
Definition: enum.c:389

◆ PciPdoIrpQueryStopDevice()

NTSTATUS NTAPI PciPdoIrpQueryStopDevice ( IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation,
IN PPCI_PDO_EXTENSION  DeviceExtension 
)

Definition at line 632 of file pdo.c.

635{
637 PAGED_CODE();
638
641
642 Status = PciPdoValidateRelease(DeviceExtension);
643 if (!NT_SUCCESS(Status))
644 return Status;
645
646 /* New resources are useless if the old ranges keep decoding */
647 if (!PciPdoCanTurnOff(DeviceExtension))
649
650 return PciBeginStateTransition((PVOID)DeviceExtension, PciStopped);
651}
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138

◆ PciPdoIrpReadConfig()

NTSTATUS NTAPI PciPdoIrpReadConfig ( IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation,
IN PPCI_PDO_EXTENSION  DeviceExtension 
)

Definition at line 908 of file pdo.c.

911{
912 PAGED_CODE();
913
914 return PciPdoReadWriteConfig(Irp, IoStackLocation, DeviceExtension, TRUE);
915}
static NTSTATUS NTAPI PciPdoReadWriteConfig(_Inout_ PIRP Irp, _In_ PIO_STACK_LOCATION IoStackLocation, _In_ PPCI_PDO_EXTENSION DeviceExtension, _In_ BOOLEAN Read)
Serves a driver's read or write of its own function's configuration space.
Definition: pdo.c:836

◆ PciPdoIrpRemoveDevice()

NTSTATUS NTAPI PciPdoIrpRemoveDevice ( IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation,
IN PPCI_PDO_EXTENSION  DeviceExtension 
)

Definition at line 560 of file pdo.c.

563{
564 PAGED_CODE();
565
568
569 if (PciPdoIsPresent(DeviceExtension))
570 PciPdoTurnOff(DeviceExtension, TRUE);
571
572 /* A remove without a query still has to take a started function out of that state */
573 if ((DeviceExtension->DeviceState == PciStarted) &&
574 (DeviceExtension->TentativeNextState == PciStarted))
575 {
577 }
578
579 if ((DeviceExtension->DeviceState != PciNotStarted) &&
580 (DeviceExtension->TentativeNextState == PciNotStarted))
581 {
583 }
584
585 /* A function that left the bus will not come back through this PDO */
586 if ((DeviceExtension->ReportedMissing) &&
588 {
589 PciCommitStateTransition((PVOID)DeviceExtension, PciDeleted);
590 }
591
592 return STATUS_SUCCESS;
593}
static BOOLEAN NTAPI PciPdoIsPresent(_Inout_ PPCI_PDO_EXTENSION DeviceExtension)
Reads the identity back from the slot to learn whether the function is still there.
Definition: pdo.c:320
@ PciDeleted
Definition: pci.h:170
@ PciStarted
Definition: pci.h:169
VOID NTAPI PciCommitStateTransition(IN PPCI_FDO_EXTENSION DeviceExtension, IN PCI_STATE NewState)
Definition: state.c:181

◆ PciPdoIrpStartDevice()

NTSTATUS NTAPI PciPdoIrpStartDevice ( IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation,
IN PPCI_PDO_EXTENSION  DeviceExtension 
)

Definition at line 158 of file pdo.c.

161{
163 BOOLEAN Changed, DoReset;
165 PAGED_CODE();
166
168
169 DoReset = FALSE;
170
171 /* Begin entering the start phase */
172 Status = PciBeginStateTransition((PVOID)DeviceExtension, PciStarted);
173 if (!NT_SUCCESS(Status)) return Status;
174
175 /* Check if this is a VGA device */
176 if (((DeviceExtension->BaseClass == PCI_CLASS_PRE_20) &&
177 (DeviceExtension->SubClass == PCI_SUBCLASS_PRE_20_VGA)) ||
178 ((DeviceExtension->BaseClass == PCI_CLASS_DISPLAY_CTLR) &&
179 (DeviceExtension->SubClass == PCI_SUBCLASS_VID_VGA_CTLR)))
180 {
181 /* Always force it on */
182 DeviceExtension->CommandEnables |= (PCI_ENABLE_IO_SPACE |
184 }
185
186 /* Check if native IDE is enabled and it owns the I/O ports */
187 if (DeviceExtension->IoSpaceUnderNativeIdeControl)
188 {
189 /* Then don't allow I/O access */
190 DeviceExtension->CommandEnables &= ~PCI_ENABLE_IO_SPACE;
191 }
192
193 /* Always enable bus mastering */
194 DeviceExtension->CommandEnables |= PCI_ENABLE_BUS_MASTER;
195
196 /* Check if the OS assigned resources differ from the PCI configuration */
197 Changed = PciComputeNewCurrentSettings(DeviceExtension,
199 StartDevice.AllocatedResources);
200 if (Changed)
201 {
202 /* Remember this for later */
203 DeviceExtension->MovedDevice = TRUE;
204 }
205 else
206 {
207 /* All good */
208 DPRINT1("PCIX - START not changing resource settings.\n");
209 }
210
211 /* Check if the device was sleeping */
212 if (DeviceExtension->PowerState.CurrentDeviceState != PowerDeviceD0)
213 {
214 /* Power it up */
217 FALSE);
218 if (!NT_SUCCESS(Status))
219 {
220 /* Powerup fail, fail the request */
221 PciCancelStateTransition((PVOID)DeviceExtension, PciStarted);
223 }
224
225 /* Tell the power manager that the device is powered up */
226 PowerState.DeviceState = PowerDeviceD0;
227 PoSetPowerState(DeviceExtension->PhysicalDeviceObject,
229 PowerState);
230
231 /* Update internal state */
232 DeviceExtension->PowerState.CurrentDeviceState = PowerDeviceD0;
233
234 /* This device's resources and decodes will need to be reset */
235 DoReset = TRUE;
236 }
237
238 /* Update resource information now that the device is powered up and active */
239 Status = PciSetResources(DeviceExtension, DoReset, TRUE);
240 if (!NT_SUCCESS(Status))
241 {
242 /* That failed, so cancel the transition */
243 PciCancelStateTransition((PVOID)DeviceExtension, PciStarted);
244 }
245 else
246 {
247 /* Fully commit, as the device is now started up and ready to go */
248 PciCommitStateTransition((PVOID)DeviceExtension, PciStarted);
249 }
250
251 /* Return the result of the start request */
252 return Status;
253}
unsigned char BOOLEAN
Definition: actypes.h:127
NTSTATUS NTAPI PciSetResources(IN PPCI_PDO_EXTENSION PdoExtension, IN BOOLEAN DoReset, IN BOOLEAN SomethingSomethingDarkSide)
Definition: enum.c:2490
BOOLEAN NTAPI PciComputeNewCurrentSettings(IN PPCI_PDO_EXTENSION PdoExtension, IN PCM_RESOURCE_LIST ResourceList)
Definition: enum.c:55
static BOOL StartDevice(IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DevInfoData OPTIONAL, IN BOOL bEnable, IN DWORD HardwareProfile OPTIONAL, OUT BOOL *bNeedReboot OPTIONAL)
Definition: wizard.c:173
#define STATUS_DEVICE_POWER_FAILURE
Definition: ntstatus.h:488
#define PCI_ENABLE_BUS_MASTER
Definition: iotypes.h:3633
#define PCI_ENABLE_IO_SPACE
Definition: iotypes.h:3631
#define PCI_ENABLE_MEMORY_SPACE
Definition: iotypes.h:3632
#define PCI_CLASS_PRE_20
Definition: iotypes.h:4118
#define PCI_SUBCLASS_VID_VGA_CTLR
Definition: iotypes.h:4160
#define PCI_SUBCLASS_PRE_20_VGA
Definition: iotypes.h:4140
#define PCI_CLASS_DISPLAY_CTLR
Definition: iotypes.h:4121

◆ PciPdoIrpStopDevice()

NTSTATUS NTAPI PciPdoIrpStopDevice ( IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation,
IN PPCI_PDO_EXTENSION  DeviceExtension 
)

Definition at line 613 of file pdo.c.

616{
617 PAGED_CODE();
618
621
622 /* The device is losing its resources, so it must stop using them first */
623 PciPdoTurnOff(DeviceExtension, FALSE);
624
625 /* The query stop that has to come first already began the transition */
626 PciCommitStateTransition((PVOID)DeviceExtension, PciStopped);
627 return STATUS_SUCCESS;
628}

◆ PciPdoIrpSurpriseRemoval()

NTSTATUS NTAPI PciPdoIrpSurpriseRemoval ( IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation,
IN PPCI_PDO_EXTENSION  DeviceExtension 
)

Definition at line 976 of file pdo.c.

979{
980 PAGED_CODE();
981
984
985 /* This also comes after a failed start, with the function still in its slot */
986 if (PciPdoIsPresent(DeviceExtension))
987 PciPdoTurnOff(DeviceExtension, TRUE);
988
989 if (DeviceExtension->ReportedMissing)
990 {
991 /* The slot is empty, so only the remove is left to come */
994 }
995 else if (DeviceExtension->DeviceState != PciNotStarted)
996 {
997 /* The remove that follows commits this */
999 }
1000
1001 return STATUS_SUCCESS;
1002}
@ PciSurpriseRemoved
Definition: pci.h:172

◆ PciPdoIrpWriteConfig()

NTSTATUS NTAPI PciPdoIrpWriteConfig ( IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation,
IN PPCI_PDO_EXTENSION  DeviceExtension 
)

Definition at line 919 of file pdo.c.

922{
923 PAGED_CODE();
924
925 return PciPdoReadWriteConfig(Irp, IoStackLocation, DeviceExtension, FALSE);
926}

◆ PciPdoIsPresent()

static BOOLEAN NTAPI PciPdoIsPresent ( _Inout_ PPCI_PDO_EXTENSION  DeviceExtension)
static

Reads the identity back from the slot to learn whether the function is still there.

Parameters
[in,out]DeviceExtensionThe PDO extension of the function. Marked not present if the identity differs.
Returns
TRUE if the same function still answers in the slot.

Definition at line 320 of file pdo.c.

322{
323 PCI_COMMON_HEADER PciData;
324
325 if (DeviceExtension->NotPresent)
326 return FALSE;
327
328 PciReadDeviceConfig(DeviceExtension, &PciData, 0, PCI_COMMON_HDR_LENGTH);
329 if (!PcipIsSameDevice(DeviceExtension, &PciData))
330 {
331 DPRINT1("PCIX - pdox %p no longer answers in its slot\n", DeviceExtension);
332 DeviceExtension->NotPresent = TRUE;
333 return FALSE;
334 }
335
336 return TRUE;
337}
BOOLEAN NTAPI PcipIsSameDevice(IN PPCI_PDO_EXTENSION DeviceExtension, IN PPCI_COMMON_HEADER PciData)
Definition: enum.c:1333
VOID NTAPI PciReadDeviceConfig(IN PPCI_PDO_EXTENSION DeviceExtension, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
Definition: config.c:149
#define PCI_COMMON_HDR_LENGTH
Definition: iotypes.h:3609

Referenced by PciPdoIrpRemoveDevice(), and PciPdoIrpSurpriseRemoval().

◆ PciPdoReadWriteConfig()

static NTSTATUS NTAPI PciPdoReadWriteConfig ( _Inout_ PIRP  Irp,
_In_ PIO_STACK_LOCATION  IoStackLocation,
_In_ PPCI_PDO_EXTENSION  DeviceExtension,
_In_ BOOLEAN  Read 
)
static

Serves a driver's read or write of its own function's configuration space.

Parameters
[in]ReadTRUE to read configuration space, FALSE to write it.
Returns
STATUS_SUCCESS, or the error that kept the access from being made.

Definition at line 836 of file pdo.c.

841{
842 PUCHAR Bounce;
843 ULONG Offset, Length, End, Limit, LineOffset;
844 BOOLEAN CoversLine;
845 PAGED_CODE();
846
847 Irp->IoStatus.Information = 0;
848
849 /* No ROM image is kept, and a ROM can never be written */
852
853 /* Any other space value is taken as configuration space */
856
857 End = Offset + Length;
858 if (End < Offset)
860
861 Limit = DeviceExtension->IsExtendedConfigReachable ? PCI_EXTENDED_CONFIG_LENGTH :
863 if (End > Limit)
865
866 if (!Length)
867 return STATUS_SUCCESS;
868
869 /* The caller's buffer may be pageable, and config cycles run at raised IRQL */
871 if (!Bounce)
873
874 LineOffset = FIELD_OFFSET(PCI_COMMON_HEADER, u.type0.InterruptLine);
875 CoversLine = (DeviceExtension->InterruptPin != 0) &&
876 (LineOffset >= Offset) &&
877 (LineOffset < End);
878
879 if (Read)
880 {
881 PciReadDeviceConfig(DeviceExtension, Bounce, Offset, Length);
882
883 /* Drivers see the line they were assigned */
884 if (CoversLine)
885 Bounce[LineOffset - Offset] = DeviceExtension->AdjustedInterruptLine;
886
888 }
889 else
890 {
892
893 /* The register keeps its firmware value */
894 if (CoversLine)
895 Bounce[LineOffset - Offset] = DeviceExtension->RawInterruptLine;
896
897 PciWriteDeviceConfig(DeviceExtension, Bounce, Offset, Length);
898 }
899
901
902 Irp->IoStatus.Information = Length;
903 return STATUS_SUCCESS;
904}
#define STATUS_INTEGER_OVERFLOW
Definition: log.c:20
VOID NTAPI PciWriteDeviceConfig(IN PPCI_PDO_EXTENSION DeviceExtension, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
Definition: config.c:133
#define PCI_LEGACY_CONFIG_LENGTH
Definition: pci.h:87
#define PCI_POOL_TAG
Definition: pci.h:27
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define NonPagedPool
Definition: env_spec_w32.h:307
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 * u
Definition: glfuncs.h:240
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
_In_ BOOLEAN Read
Definition: strmini.h:479
struct _IO_STACK_LOCATION::@5020::@5049 ReadWriteConfig
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
unsigned char * PUCHAR
Definition: typedefs.h:53
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define PCI_WHICHSPACE_ROM
Definition: iotypes.h:3660
#define PCI_EXTENDED_CONFIG_LENGTH
Definition: iotypes.h:3611
_In_ LONG _In_ LONG Limit
Definition: kefuncs.h:304

Referenced by PciPdoIrpReadConfig(), and PciPdoIrpWriteConfig().

◆ PciPdoSetPowerState()

NTSTATUS NTAPI PciPdoSetPowerState ( IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation,
IN PPCI_PDO_EXTENSION  DeviceExtension 
)

Definition at line 104 of file pdo.c.

107{
110
111 /* The function driver follows a system state with a device state request of its own */
113 {
114 DeviceExtension->PowerState.CurrentSystemState = State.SystemState;
115 return STATUS_SUCCESS;
116 }
117
118 if ((State.DeviceState < PowerDeviceD0) || (State.DeviceState > PowerDeviceD3))
120
121 if (State.DeviceState == DeviceExtension->PowerState.CurrentDeviceState)
122 return STATUS_SUCCESS;
123
124 /* Configuration cycles cannot reach a function on a bus that is not running */
125 if (DeviceExtension->ParentFdoExtension->DeviceState != PciStarted)
127
129 return PciPdoEnterDevicePowerState(DeviceExtension, State.DeviceState);
130
131 /* D0 may be sent at DISPATCH_LEVEL, and reprogramming the function needs PASSIVE_LEVEL */
132 WorkItem = IoAllocateWorkItem(DeviceExtension->PhysicalDeviceObject);
133 if (!WorkItem)
135
136 Irp->Tail.Overlay.DriverContext[0] = WorkItem;
139 return STATUS_PENDING;
140}
static IO_WORKITEM_ROUTINE PciPdoDevicePowerWorker
Definition: pdo.c:84
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
_In_opt_ PVOID _In_ PUCXHUB_WORKITEM WorkItem
Definition: hubucx.h:227
VOID NTAPI IoQueueWorkItem(IN PIO_WORKITEM IoWorkItem, IN PIO_WORKITEM_ROUTINE WorkerRoutine, IN WORK_QUEUE_TYPE QueueType, IN PVOID Context)
Definition: iowork.c:40
PIO_WORKITEM NTAPI IoAllocateWorkItem(IN PDEVICE_OBJECT DeviceObject)
Definition: iowork.c:75
IoMarkIrpPending(Irp)
#define STATUS_PENDING
Definition: telnetd.h:14
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136
@ DelayedWorkQueue
Definition: extypes.h:190
_In_ SYSTEM_POWER_STATE SystemPowerState
Definition: iotypes.h:7535

◆ PciPdoTurnOff()

static VOID NTAPI PciPdoTurnOff ( _Inout_ PPCI_PDO_EXTENSION  DeviceExtension,
_In_ BOOLEAN  PowerDown 
)
static

Stops a function from decoding, mastering and raising interrupts, and optionally moves it to D3.

Parameters
[in,out]DeviceExtensionThe PDO extension of the function.
[in]PowerDownTRUE to also power the function down.

Definition at line 353 of file pdo.c.

356{
359
360 if (!PciPdoCanTurnOff(DeviceExtension))
361 return;
362
363 /* The wired line is masked in the same write that clears the decodes */
364 PciReadDeviceConfig(DeviceExtension,
365 &Command,
367 sizeof(Command));
369 PciDecodeEnable(DeviceExtension, FALSE, &Command);
370
371 if (!PowerDown ||
372 (DeviceExtension->PowerState.CurrentDeviceState == PowerDeviceD3) ||
373 !PciCanDisableDecodes(DeviceExtension, NULL, 0, TRUE))
374 {
375 return;
376 }
377
378 /* Start sees D3, powers the function back up and reprograms it */
380 DeviceExtension->PowerState.CurrentDeviceState = PowerDeviceD3;
381
382 PowerState.DeviceState = PowerDeviceD3;
383 PoSetPowerState(DeviceExtension->PhysicalDeviceObject, DevicePowerState, PowerState);
384}
VOID NTAPI PciDecodeEnable(IN PPCI_PDO_EXTENSION PdoExtension, IN BOOLEAN Enable, OUT PUSHORT Command)
Definition: utils.c:1359
unsigned short USHORT
Definition: pedump.c:61
Definition: shell.h:41
#define PCI_DISABLE_LEVEL_INTERRUPT
Definition: iotypes.h:3641

Referenced by PciPdoEnterDevicePowerState(), PciPdoIrpRemoveDevice(), PciPdoIrpStopDevice(), and PciPdoIrpSurpriseRemoval().

◆ PciPdoValidateRelease()

static NTSTATUS NTAPI PciPdoValidateRelease ( _In_ PPCI_PDO_EXTENSION  DeviceExtension)
static

Checks the uses of a function that keep it from being stopped or removed.

Parameters
[in]DeviceExtensionThe PDO extension of the function.
Returns
STATUS_SUCCESS if the function may be given up.

Definition at line 268 of file pdo.c.

270{
271 /* Paging, hibernation and dump files, and the debugger, cannot lose their hardware */
272 if ((DeviceExtension->PowerState.Paging) ||
273 (DeviceExtension->PowerState.Hibernate) ||
274 (DeviceExtension->PowerState.CrashDump) ||
275 (DeviceExtension->OnDebugPath))
276 {
277 return STATUS_DEVICE_BUSY;
278 }
279
280 /* A driver that claimed the function outside of PnP will not let go of it */
281 if (DeviceExtension->LegacyDriver)
283
284 return STATUS_SUCCESS;
285}

Referenced by PciPdoIrpQueryDeviceState(), PciPdoIrpQueryRemoveDevice(), and PciPdoIrpQueryStopDevice().

◆ PciPdoWaitWake()

NTSTATUS NTAPI PciPdoWaitWake ( IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation,
IN PPCI_PDO_EXTENSION  DeviceExtension 
)

Definition at line 88 of file pdo.c.

91{
93 UNREFERENCED_PARAMETER(DeviceExtension);
94
95 /* PME is never armed, so the function cannot wake the system */
96 Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
100}

Variable Documentation

◆ PciPdoDevicePowerWorker

IO_WORKITEM_ROUTINE PciPdoDevicePowerWorker
static

Definition at line 84 of file pdo.c.

Referenced by PciPdoSetPowerState().

◆ PciPdoDispatchPnpTable

PCI_MN_DISPATCH_TABLE PciPdoDispatchPnpTable[]
Initial value:
=
{
}
NTSTATUS NTAPI PciPdoIrpStopDevice(IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
Definition: pdo.c:613
NTSTATUS NTAPI PciPdoIrpCancelStopDevice(IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
Definition: pdo.c:655
NTSTATUS NTAPI PciPdoIrpSurpriseRemoval(IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
Definition: pdo.c:976
NTSTATUS NTAPI PciPdoIrpQueryInterface(IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
Definition: pdo.c:671
NTSTATUS NTAPI PciPdoIrpQueryResourceRequirements(IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
Definition: pdo.c:762
NTSTATUS NTAPI PciPdoIrpQueryDeviceText(IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
Definition: pdo.c:778
NTSTATUS NTAPI PciPdoIrpCancelRemoveDevice(IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
Definition: pdo.c:597
NTSTATUS NTAPI PciPdoIrpQueryDeviceState(IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
Definition: pdo.c:930
NTSTATUS NTAPI PciPdoIrpReadConfig(IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
Definition: pdo.c:908
NTSTATUS NTAPI PciPdoIrpQueryLegacyBusInformation(IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
Definition: pdo.c:1006
NTSTATUS NTAPI PciPdoIrpRemoveDevice(IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
Definition: pdo.c:560
NTSTATUS NTAPI PciPdoIrpQueryId(IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
Definition: pdo.c:795
NTSTATUS NTAPI PciPdoIrpQueryDeviceRelations(IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
Definition: pdo.c:697
NTSTATUS NTAPI PciPdoIrpWriteConfig(IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
Definition: pdo.c:919
NTSTATUS NTAPI PciPdoIrpQueryCapabilities(IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
Definition: pdo.c:731
NTSTATUS NTAPI PciPdoIrpStartDevice(IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
Definition: pdo.c:158
NTSTATUS NTAPI PciPdoIrpQueryRemoveDevice(IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
Definition: pdo.c:534
NTSTATUS NTAPI PciPdoIrpDeviceUsageNotification(IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
Definition: pdo.c:956
NTSTATUS NTAPI PciPdoIrpQueryStopDevice(IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
Definition: pdo.c:632
NTSTATUS NTAPI PciPdoIrpQueryResources(IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
Definition: pdo.c:747
NTSTATUS NTAPI PciPdoIrpQueryBusInformation(IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
Definition: pdo.c:809
NTSTATUS NTAPI PciIrpNotSupported(IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_FDO_EXTENSION DeviceExtension)
Definition: dispatch.c:261
@ IRP_COMPLETE
Definition: pci.h:182
NTSTATUS(NTAPI * PCI_DISPATCH_FUNCTION)(IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PVOID DeviceExtension)
Definition: pci.h:390

Definition at line 33 of file pdo.c.

◆ PciPdoDispatchPowerTable

PCI_MN_DISPATCH_TABLE PciPdoDispatchPowerTable[]
Initial value:
=
{
}
NTSTATUS NTAPI PciPdoSetPowerState(IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
Definition: pdo.c:104
NTSTATUS NTAPI PciPdoIrpQueryPower(IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
Definition: pdo.c:144
NTSTATUS NTAPI PciPdoWaitWake(IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_PDO_EXTENSION DeviceExtension)
Definition: pdo.c:88
@ IRP_DISPATCH
Definition: pci.h:185

Definition at line 24 of file pdo.c.

◆ PciPdoDispatchTable

PCI_MJ_DISPATCH_TABLE PciPdoDispatchTable
Initial value:
=
{
}
PCI_MN_DISPATCH_TABLE PciPdoDispatchPowerTable[]
Definition: pdo.c:24
PCI_MN_DISPATCH_TABLE PciPdoDispatchPnpTable[]
Definition: pdo.c:33
NTSTATUS NTAPI PciIrpInvalidDeviceRequest(IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation, IN PPCI_FDO_EXTENSION DeviceExtension)
Definition: dispatch.c:277
#define IRP_MN_QUERY_POWER
#define IRP_MN_QUERY_LEGACY_BUS_INFORMATION
Definition: iotypes.h:4443

Definition at line 63 of file pdo.c.

Referenced by PciPdoCreate().

◆ PciPdoSequenceNumber

LONG PciPdoSequenceNumber

Definition at line 18 of file pdo.c.

Referenced by PciPdoCreate().