31#if defined(EVENT_TRACING)
32#include "PowerStateMachine.tmh"
36#if FX_STATE_MACHINE_VERIFY
37 #define VALIDATE_POWER_STATE(_CurrentState, _NewState) \
38 ValidatePowerStateEntryFunctionReturnValue((_CurrentState), (_NewState))
40 #define VALIDATE_POWER_STATE(_CurrentState, _NewState) (0)
1197 "WDFDEVICE 0x%p !devobj 0x%p current pwr pol state "
1198 "%!WDF_DEVICE_POWER_STATE! dropping event %!FxPowerEvent! because "
1215 ASSERT(!
"The Power queue is full. This shouldn't be able to happen.");
1222 "WDFDEVICE 0x%p !devobj 0x%p current pwr pol state "
1223 "%!WDF_DEVICE_POWER_STATE! dropping event %!FxPowerEvent! because "
1266 FALSE == ProcessOnDifferentThread) {
1272 if (FxWaitLockInternal::IsLockAcquired(
status)) {
1288 info.Evaluate(
this);
1321 This->m_PowerMachine.m_StateMachineLock.AcquireLock(
1322 This->GetDriverGlobals()
1328 This->PowerProcessEventInner(
Info);
1339 This->m_PowerMachine.m_StateMachineLock.ReleaseLock(
1340 This->GetDriverGlobals()
1401 if (
entry->StateInfo.Bits.QueueOpen ==
FALSE) {
1425 if (
entry->FirstTargetState.PowerEvent ==
event) {
1426 newState =
entry->FirstTargetState.TargetState;
1430 else if (
entry->OtherTargetStates !=
NULL) {
1436 if (
entry->OtherTargetStates[
i].PowerEvent ==
event) {
1437 newState =
entry->OtherTargetStates[
i].TargetState;
1447 "WDFDEVICE 0x%p !devobj 0x%p current power state "
1448 "%!WDF_DEVICE_POWER_STATE! dropping event %!FxPowerEvent!",
1457 if ((
entry->StateInfo.Bits.KnownDroppedEvents &
event) == 0) {
1462 "WDFDEVICE %p !devobj 0x%p current state "
1463 "%!WDF_DEVICE_POWER_STATE! event %!FxPowerEvent! is not a "
1464 "known dropped event, known dropped events are "
1468 event,
entry->StateInfo.Bits.KnownDroppedEvents);
1540 "WDFDEVICE 0x%p !devobj 0x%p entering Power State "
1541 "%!WDF_DEVICE_POWER_STATE! from %!WDF_DEVICE_POWER_STATE!",
1544 newState, currentState);
1553 data.Data.LeaveState.CurrentState = currentState;
1554 data.Data.LeaveState.NewState = newState;
1572 data.Data.EnterState.CurrentState = currentState;
1573 data.Data.EnterState.NewState = newState;
1582 currentState = newState;
1591 newState =
entry->StateFunc(
this);
1611 data.Data.PostProcessState.CurrentState = currentState;
1643 status =
This->PowerCheckParentOverload(&parentOn);
1648 else if (parentOn) {
1678 status =
This->PowerCheckParentOverload(&parentOn);
1683 else if (parentOn) {
1710 return This->PowerCheckDeviceTypeOverload();
1732 return This->PowerCheckDeviceTypeNPOverload();
1760 status =
This->PowerEnableWakeAtBusOverload();
1773 This->PowerCompleteWakeRequestFromWithinMachine(
status);
1805 status =
This->PowerEnableWakeAtBusOverload();
1823 This->PowerCompleteWakeRequestFromWithinMachine(
status);
1915 else if (
This->PowerIsWakeRequestPresent()) {
1951 else if (
This->PowerIsWakeRequestPresent()) {
2051 This->PowerDisableWakeAtBusOverload();
2084 This->PowerDisableWakeAtBusOverload();
2085 This->PowerCompletePendedWakeIrp();
2120 This->PowerDisableWakeAtBusOverload();
2121 This->PowerCompletePendedWakeIrp();
2157 This->m_Device->GetHandle(),
2163 "EvtDeviceD0Entry WDFDEVICE 0x%p !devobj 0x%p, old state "
2164 "%!WDF_POWER_DEVICE_STATE! failed, %!STATUS!",
2165 This->m_Device->GetHandle(),
2166 This->m_Device->GetDeviceObject(),
2208 status =
This->m_DeviceD0EntryPostInterruptsEnabled.Invoke(
2209 This->m_Device->GetHandle(),
2216 "EvtDeviceD0EntryPostInterruptsEnabed WDFDEVICE 0x%p !devobj 0x%p, "
2217 "old state %!WDF_POWER_DEVICE_STATE! failed, %!STATUS!",
2218 This->m_Device->GetHandle(),
2219 This->m_Device->GetDeviceObject(),
2278 This->m_Device->m_PkgIo->ResumeProcessingForPower();
2280 if (
This->m_SelfManagedIoMachine !=
NULL) {
2283 status =
This->m_SelfManagedIoMachine->Start();
2295 This->PowerSendPowerUpEvents();
2322 if (
This->m_SharedPower.m_WaitWakeOwner) {
2333 if (
This->m_SharedPower.m_WaitWakeOwner) {
2386 if (
This->m_SelfManagedIoMachine !=
NULL) {
2387 status =
This->m_SelfManagedIoMachine->Suspend();
2392 "EvtDeviceSelfManagedIoStop failed %!STATUS!",
status);
2404 if (
This->PowerDmaPowerDown() ==
FALSE) {
2408 status =
This->m_DeviceD0ExitPreInterruptsDisabled.Invoke(
2409 This->m_Device->GetHandle(),
2418 "EvtDeviceD0ExitPreInterruptsDisabled WDFDEVICE 0x%p !devobj 0x%p, "
2419 "new state %!WDF_POWER_DEVICE_STATE! failed, %!STATUS!",
2420 This->m_Device->GetHandle(),
2421 This->m_Device->GetDeviceObject(),
2440 status =
This->m_DeviceD0Exit.Invoke(
This->m_Device->GetHandle(),
2447 "EvtDeviceD0Exit WDFDEVICE 0x%p !devobj 0x%p, new state "
2448 "%!WDF_POWER_DEVICE_STATE! failed, %!STATUS!",
2449 This->m_Device->GetHandle(),
2450 This->m_Device->GetDeviceObject(),
2459 This->PowerParentPowerDereference();
2496 if (
This->m_Device->IsPdo()) {
2524 status =
This->PowerCheckParentOverload(&parentOn);
2529 "PowerReference on parent WDFDEVICE %p for child WDFDEVICE %p "
2530 "failed, %!STATUS!",
This->m_Device->m_ParentDevice->m_Device->GetHandle(),
2531 This->m_Device->GetHandle(),
2536 else if (parentOn) {
2574 This->PowerDisableWakeAtBusOverload();
2602 This->PowerDisableWakeAtBusOverload();
2624 This->PowerGotoDx();
2646 This->PowerGotoDx();
2656 if (
This->PowerGotoDxIoStopped() ==
FALSE) {
2668 if (
This->PowerGotoDxIoStoppedNP() ==
FALSE) {
2692 This->DisconnectInterruptNP();
2725 "EvtDeviceSelfManagedIoStop failed %!STATUS!",
status);
2813 "EvtDeviceD0ExitPreInterruptsDisabled WDFDEVICE 0x%p !devobj 0x%p, "
2814 "new state %!WDF_POWER_DEVICE_STATE! failed, %!STATUS!",
2871 "EvtDeviceD0Exit WDFEVICE 0x%p !devobj 0x%p, new state "
2872 "%!WDF_POWER_DEVICE_STATE! failed, %!STATUS!",
2982 "EvtDeviceD0ExitPreInterruptsDisabled WDFDEVICE 0x%p !devobj 0x%p, "
2983 "new state %!WDF_POWER_DEVICE_STATE! failed, %!STATUS!",
3010 "EvtDeviceD0Exit WDFDEVICE 0x%p !devobj 0x%p, new state "
3011 "%!WDF_POWER_DEVICE_STATE! failed, %!STATUS!",
3075 This->PowerGotoDx();
3099 This->PowerGotoDx();
3109 if (
This->PowerGotoDxIoStopped() ==
FALSE) {
3121 if (
This->PowerGotoDxIoStoppedNP() ==
FALSE) {
3152 status =
This->PowerCheckParentOverload(&parentOn);
3157 else if (parentOn) {
3185 status =
This->PowerCheckParentOverload(&parentOn);
3190 else if (parentOn) {
3224 This->m_Device->m_PkgIo->ResumeProcessingForPower();
3226 if (
This->m_SelfManagedIoMachine !=
NULL) {
3229 status =
This->m_SelfManagedIoMachine->Start();
3234 "EvtDeviceSelfManagedIoRestart failed - %!STATUS!",
status);
3246 This->PowerSendPowerUpEvents();
3248 This->PowerReleasePendingDeviceIrp();
3250 if (
This->m_SharedPower.m_WaitWakeOwner) {
3284 This->m_Device->m_PkgIo->ResumeProcessingForPower();
3286 if (
This->m_SelfManagedIoMachine !=
NULL) {
3289 status =
This->m_SelfManagedIoMachine->Start();
3294 "EvtDeviceSelfManagedIoRestart failed - %!STATUS!",
status);
3305 This->PowerSendPowerUpEvents();
3307 This->PowerReleasePendingDeviceIrp();
3309 if (
This->m_SharedPower.m_WaitWakeOwner) {
3392 This->PowerCompletePendedWakeIrp();
3416 This->PowerCompletePendedWakeIrp();
3447 This->m_Device->GetHandle(),
3453 "EvtDeviceD0Entry WDFDEVICE 0x%p !devobj 0x%p, old state "
3454 "%!WDF_POWER_DEVICE_STATE! failed, %!STATUS!",
3455 This->m_Device->GetHandle(),
3456 This->m_Device->GetDeviceObject(),
3492 This->m_Device->GetHandle(),
3498 "EvtDeviceD0Entry WDFDEVICE 0x%p !devobj 0x%p, old state "
3499 "%!WDF_POWER_DEVICE_STATE! failed, %!STATUS!",
3500 This->m_Device->GetHandle(),
3501 This->m_Device->GetDeviceObject(),
3540 status =
This->m_DeviceD0EntryPostInterruptsEnabled.Invoke(
3541 This->m_Device->GetHandle(),
3547 "EvtDeviceD0EntryPostInterruptsEnabed WDFDEVICE 0x%p !devobj 0x%p, "
3548 "old state %!WDF_POWER_DEVICE_STATE! failed, %!STATUS!",
3549 This->m_Device->GetHandle(),
3550 This->m_Device->GetDeviceObject(),
3589 status =
This->m_DeviceD0EntryPostInterruptsEnabled.Invoke(
3590 This->m_Device->GetHandle(),
3596 "EvtDeviceD0EntryPostInterruptsEnabed WDFDEVICE 0x%p !devobj 0x%p, "
3597 "old state %!WDF_POWER_DEVICE_STATE! failed, %!STATUS!",
3598 This->m_Device->GetHandle(),
3599 This->m_Device->GetDeviceObject(),
3625 This->PowerConnectInterruptFailed();
3656 "Force disconnecting interupts on !devobj %p, WDFDEVICE %p",
3657 This->m_Device->GetDeviceObject(),
3658 This->m_Device->GetHandle());
3660 This->PowerConnectInterruptFailed();
3684 ((
FxChildList*)
ple->GetTransactionedObject())->ScanForChildren();
3690 if (ImplicitPowerUp ==
FALSE) {
3775 status =
This->m_DeviceD0ExitPreInterruptsDisabled.Invoke(
3776 This->m_Device->GetHandle(),
3786 "EvtDeviceD0ExitPreInterruptsDisabled WDFDEVICE 0x%p !devobj 0x%p "
3787 "new state %!WDF_POWER_DEVICE_STATE! failed, %!STATUS!",
3788 This->m_Device->GetHandle(),
3789 This->m_Device->GetDeviceObject(),
3820 status =
This->m_DeviceD0ExitPreInterruptsDisabled.Invoke(
3821 This->m_Device->GetHandle(),
3831 "EvtDeviceD0ExitPreInterruptsDisabled WDFDEVICE 0x%p !devobj 0x%p "
3832 "new state %!WDF_POWER_DEVICE_STATE! failed, %!STATUS!",
3833 This->m_Device->GetHandle(),
3834 This->m_Device->GetDeviceObject(),
3862 This->PowerParentPowerDereference();
3887 This->PowerReleasePendingDeviceIrp();
3888 This->PowerSendPowerUpFailureEvent();
3946 This->PowerReleasePendingDeviceIrp();
3971 This->PowerConnectInterruptFailed();
3999 status =
This->m_DeviceD0ExitPreInterruptsDisabled.Invoke(
4000 This->m_Device->GetHandle(),
4010 "EvtDeviceD0ExitPreInterruptsDisabled WDFDEVICE 0x%p !devobj 0x%p "
4011 "new state %!WDF_POWER_DEVICE_STATE! failed, %!STATUS!",
4012 This->m_Device->GetHandle(),
4013 This->m_Device->GetDeviceObject(),
4069 This->PowerParentPowerDereference();
4091 This->PowerSendPowerUpFailureEvent();
4120 This->PowerDisableWakeAtBusOverload();
4149 This->PowerDisableWakeAtBusOverload();
4225 This->PowerReleasePendingDeviceIrp();
4254 This->PowerReleasePendingDeviceIrp();
4290 This->PowerSendPowerUpEvents();
4293 if (
This->PowerIsWakeRequestPresent()) {
4302 if (
This->PowerIsWakeRequestPresent()) {
4343 status =
This->PowerEnableWakeAtBusOverload();
4356 This->PowerCompleteWakeRequestFromWithinMachine(
status);
4391 status =
This->PowerEnableWakeAtBusOverload();
4404 This->PowerCompleteWakeRequestFromWithinMachine(
status);
4572 This->DisconnectInterruptNP();
4598 This->DisconnectInterruptNP();
4622 if (
This->m_WakeInterruptCount == 0) {
4650 if (
This->m_WakeInterruptCount == 0) {
4659 if (
This->m_WakeInterruptsKeepConnected ==
TRUE ||
4660 This->m_SharedPower.m_WaitWakeIrp !=
NULL) {
4699 if (
This->m_WakeInterruptCount == 0) {
4727 if (
This->m_WakeInterruptCount == 0) {
4736 if (
This->m_WakeInterruptsKeepConnected ==
TRUE ||
4737 This->m_SharedPower.m_WaitWakeIrp !=
NULL) {
4770 "Force disconnecting interrupts on !devobj 0x%p, WDFDEVICE %p",
4944 if (pOldCancelRoutine !=
NULL) {
4979 "WDFDEVICE 0x%p !devobj 0x%p WW !irp 0x%p is a source "
5313 "Interrupt(s) disconnect on WDFDEVICE %p failed, %!STATUS!",
5326 "EvtDeviceD0Exit WDFDEVICE 0x%p !devobj 0x%p failed, %!STATUS!",
WDFDEVICE __inline GetHandle(VOID)
MdDeviceObject __inline GetDeviceObject(VOID)
CfxDevice * m_ParentDevice
static FxDevice * GetFxDevice(__in MdDeviceObject DeviceObject)
__inline WDF_DEVICE_POWER_STATE GetDevicePowerState()
__inline VOID SetDevicePowerState(__in WDF_DEVICE_POWER_STATE DeviceState)
__inline FxPkgPdo * GetPdoPkg(VOID)
POWER_ACTION GetParameterPowerShutdownType()
MdCancelRoutine SetCancelRoutine(__in_opt MdCancelRoutine CancelRoutine)
VOID SetStatus(__in NTSTATUS Status)
DEVICE_POWER_STATE GetParameterPowerStateDeviceState()
static MdIrp GetIrpFromListEntry(__in PLIST_ENTRY Ple)
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
_Must_inspect_result_ NTSTATUS StopProcessingForPower(__in FxIoStopProcessingForPowerAction Action)
static WDF_DEVICE_POWER_STATE PowerStartingChild(__inout FxPkgPnp *This)
VOID SetInternalFailure(VOID)
static WDF_DEVICE_POWER_STATE PowerReportPowerDownFailed(__inout FxPkgPnp *This)
static WDF_DEVICE_POWER_STATE PowerWakingDmaEnable(__inout FxPkgPnp *This)
BOOLEAN PowerDmaEnableAndScan(__in BOOLEAN ImplicitPowerUp)
static MdCancelRoutineType _PowerWaitWakeCancelRoutine
static WDF_DEVICE_POWER_STATE PowerD0DisarmingWakeAtBusNP(__inout FxPkgPnp *This)
static WDF_DEVICE_POWER_STATE PowerD0ArmedForWake(__inout FxPkgPnp *This)
static WDF_DEVICE_POWER_STATE PowerNotifyingD0ExitToWakeInterruptsNP(__inout FxPkgPnp *This)
static const POWER_EVENT_TARGET_STATE m_PowerD0BusWakeOwnerNPOtherStates[]
static WDF_DEVICE_POWER_STATE PowerWakePendingNP(__inout FxPkgPnp *This)
BOOLEAN PowerGotoDxIoStoppedNP(VOID)
static WDF_DEVICE_POWER_STATE PowerStartSelfManagedIoFailed(__inout FxPkgPnp *This)
VOID PowerCompleteWakeRequestFromWithinMachine(__in NTSTATUS Status)