ReactOS 0.4.15-dev-7788-g1ad9096
notpowerpolicyownerstatemachine.cpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft. All rights reserved.
4
5Module Name:
6
7 NotPowerPolicyOwnerStateMachine.cpp
8
9Abstract:
10
11 This module implements the Not Power Policy Owner state machine for the driver
12 framework. This code was split out from PowerPolicyStateMachine.cpp
13
14Author:
15
16
17
18
19Environment:
20
21 Both kernel and user mode
22
23Revision History:
24
25
26
27--*/
28
29#include "pnppriv.hpp"
30
31extern "C" {
32#if defined(EVENT_TRACING)
33#include "NotPowerPolicyOwnerStateMachine.tmh"
34#endif
35}
36
38{
41};
42
44{
47};
48
50{
55};
56
58{
60};
61
63{
66};
67
69{
72};
73
75{
80};
81
83{
86};
87
89{
92};
93
95{
98};
99
101{
106};
107
109{
112};
113
115{
118};
119
121{
124};
125
127{
128 // current state
129 // transition function,
130 // target states
131 // count of target states
132 // Queue state
133 //
135 NULL,
138 TRUE,
139 },
140
145 FALSE,
146 },
147
150 NULL,
151 0,
152 FALSE,
153 },
154
156 NULL,
159 TRUE,
160 },
161
166 FALSE,
167 },
168
173 FALSE,
174 },
175
177 NULL,
180 TRUE,
181 },
182
187 FALSE,
188 },
189
194 FALSE,
195 },
196
199 NULL,
200 0,
201 FALSE,
202 },
203
206 NULL,
207 0,
208 FALSE,
209 },
210
215 TRUE,
216 },
217
220 NULL,
221 0,
222 FALSE,
223 },
224
226 NULL,
229 TRUE,
230 },
231
233 NULL,
236 TRUE,
237 },
238
243 FALSE,
244 },
245
250 FALSE,
251 },
252
257 TRUE,
258 },
259
260 // the last entry must have WdfDevStatePwrPolNull as the current state
262 NULL,
263 NULL,
264 0,
265 FALSE,
266 },
267};
268
269VOID
272 )
273{
275 WDF_DEVICE_POWER_POLICY_STATE currentState, newState;
277
278 currentState = m_Device->GetDevicePowerPolicyState();
279 newState = NewState;
280
281 while (newState != WdfDevStatePwrPolNull) {
284 "WDFDEVICE 0x%p !devobj 0x%p entering not power policy owner state "
285 "%!WDF_DEVICE_POWER_POLICY_STATE! from "
286 "%!WDF_DEVICE_POWER_POLICY_STATE!", m_Device->GetHandle(),
287 m_Device->GetDeviceObject(), newState, currentState);
288
290 //
291 // Callback for leaving the old state
292 //
293 RtlZeroMemory(&data, sizeof(data));
294
296 data.Data.LeaveState.CurrentState = currentState;
297 data.Data.LeaveState.NewState = newState;
298
302 &data);
303 }
304
307
309 //
310 // Callback for entering the new state
311 //
312 RtlZeroMemory(&data, sizeof(data));
313
315 data.Data.EnterState.CurrentState = currentState;
316 data.Data.EnterState.NewState = newState;
317
321 &data);
322 }
323
325 currentState = newState;
326
328
329 //
330 // Call the state handler, if there is one.
331 //
332 if (entry->StateFunc != NULL) {
333 newState = entry->StateFunc(this);
334 }
335 else {
336 newState = WdfDevStatePwrPolNull;
337 }
338
340 //
341 // Callback for post processing the new state
342 //
343 RtlZeroMemory(&data, sizeof(data));
344
346 data.Data.PostProcessState.CurrentState = currentState;
347
351 &data);
352 }
353 }
354}
355
359 )
360/*++
361
362Routine Description:
363 Starting the power policy state machine for a device which is not the power
364 policy owner. Tell the power state machine to start up.
365
366Arguments:
367 This - instance of the state machine
368
369Return Value:
370 WdfDevStatePwrPolNull
371
372 --*/
373{
374 This->PowerProcessEvent(PowerImplicitD0);
376}
377
381 )
382/*++
383
384Routine Description:
385 Starting the power policy state machine for a device which is not the power
386 policy owner has succeeded. Indicate status to the pnp state machine.
387
388Arguments:
389 This - instance of the state machine
390
391Return Value:
392 WdfDevStatePwrPolNull
393
394 --*/
395{
396 This->PnpProcessEvent(PnpEventPwrPolStarted);
398}
399
403 )
404{
405 This->PowerProcessEvent(PowerCompleteDx);
407}
408
412 )
413{
414 This->PowerProcessEvent(PowerCompleteDx);
416}
417
421 )
422{
423 This->PowerProcessEvent(PowerCompleteD0);
425}
426
430 )
431{
432 This->PowerProcessEvent(PowerCompleteD0);
434}
435
439 )
440/*++
441
442Routine Description:
443 Stopping the power policy state machine for a device which is not the power
444 policy owner. Tell the power state machine to power down.
445
446Arguments:
447 This - instance of the state machine
448
449Return Value:
450 WdfDevStatePwrPolStoppingWaitingForImplicitPowerDown
451
452 --*/
453{
454 This->PowerProcessEvent(PowerImplicitD3);
456}
457
461 )
462/*++
463
464Routine Description:
465 Stopping the power policy state machine for a device which is not the power
466 policy owner has succeeded. Inidcate status to the pnp state machine.
467
468Arguments:
469 This - instance of the state machine
470
471Return Value:
472 WdfDevStatePwrPolStopped
473
474 --*/
475{
476 This->PnpProcessEvent(PnpEventPwrPolStopped);
478}
479
483 )
484/*++
485
486Routine Description:
487 Starting the power policy state machine for a device which is not the power
488 policy owner has failed. Inidcate status to the pnp state machine.
489
490Arguments:
491 This - instance of the state machine
492
493Return Value:
494 WdfDevStatePwrPolNull
495
496 --*/
497{
498 This->PnpProcessEvent(PnpEventPwrPolStartFailed);
500}
501
505 )
506/*++
507
508Routine Description:
509 Stopping the power policy state machine for a device which is not the power
510 policy owner has failed. Inidcate status to the pnp state machine.
511
512Arguments:
513 This - instance of the state machine
514
515Return Value:
516 WdfDevStatePwrPolStopped
517
518 --*/
519{
520 This->PnpProcessEvent(PnpEventPwrPolStopFailed);
522}
523
527 )
528/*++
529
530Routine Description:
531 Right as we attempted to implicitly power down, a real D0 irp came into the
532 stack. Complete the D0 irp in the power state machine so that the power
533 state machine can process the implicit power irp
534
535Arguments:
536 This - instance of the state machine
537
538Return Value:
539 WdfDevStatePwrPolNull
540
541 --*/
542{
543 This->PowerProcessEvent(PowerCompleteD0);
545}
546
550 )
551/*++
552
553Routine Description:
554 Right as we attempted to implicitly power down, a real Dx irp came into the
555 stack. Complete the Dx irp in the power state machine so that the power
556 state machine can process the implicit power irp
557
558Arguments:
559 This - instance of the state machine
560
561Return Value:
562 WdfDevStatePwrPolNull
563
564 --*/
565{
566 This->PowerProcessEvent(PowerCompleteDx);
568}
569
573 )
574/*++
575
576Routine Description:
577 The device is being removed, so prepare for removal.
578
579Arguments:
580 This - instance of the state machine
581
582Return Value:
583 WdfDevStatePwrPolNull
584
585 --*/
586{
587 //
588 // Since we are not the power policy owner, there is nothing to be done.
589 // Indicate to the PNP state machine that we are ready for removal.
590 //
591 This->PnpProcessEvent(PnpEventPwrPolRemoved);
593}
#define ARRAY_SIZE(A)
Definition: main.h:33
WDFDEVICE __inline GetHandle(VOID)
Definition: fxdevice.hpp:237
MdDeviceObject __inline GetDeviceObject(VOID)
Definition: fxdevice.hpp:174
__inline VOID SetDevicePowerPolicyState(__in WDF_DEVICE_POWER_POLICY_STATE DeviceState)
Definition: fxdevice.hpp:1191
__inline WDF_DEVICE_POWER_POLICY_STATE GetDevicePowerPolicyState()
Definition: fxdevice.hpp:1165
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
CfxDevice * m_Device
Definition: fxobject.hpp:329
static WDF_DEVICE_POWER_POLICY_STATE NotPowerPolOwnerStopping(__inout FxPkgPnp *This)
static WDF_DEVICE_POWER_POLICY_STATE NotPowerPolOwnerStoppingPoweringDown(__inout FxPkgPnp *This)
static WDF_DEVICE_POWER_POLICY_STATE NotPowerPolOwnerRemoved(__inout FxPkgPnp *This)
static const POWER_POLICY_EVENT_TARGET_STATE m_NotPowerPolOwnerGotoD0States[]
Definition: fxpkgpnp.hpp:4500
static const POWER_POLICY_EVENT_TARGET_STATE m_NotPowerPolOwnerRemovedStates[]
Definition: fxpkgpnp.hpp:4506
static const POWER_POLICY_EVENT_TARGET_STATE m_NotPowerPolOwnerStoppingPoweringDownStates[]
Definition: fxpkgpnp.hpp:4505
static WDF_DEVICE_POWER_POLICY_STATE NotPowerPolOwnerStarting(__inout FxPkgPnp *This)
static const POWER_POLICY_EVENT_TARGET_STATE m_NotPowerPolOwnerGotoDxStates[]
Definition: fxpkgpnp.hpp:4497
static const POWER_POLICY_EVENT_TARGET_STATE m_NotPowerPolOwnerObjectCreatedStates[]
Definition: fxpkgpnp.hpp:4493
static WDF_DEVICE_POWER_POLICY_STATE NotPowerPolOwnerStoppingPoweringUp(__inout FxPkgPnp *This)
static WDF_DEVICE_POWER_POLICY_STATE NotPowerPolOwnerStoppingSendStatus(__inout FxPkgPnp *This)
static WDF_DEVICE_POWER_POLICY_STATE NotPowerPolOwnerGotoDxInDx(__inout FxPkgPnp *This)
static const POWER_POLICY_EVENT_TARGET_STATE m_NotPowerPolOwnerGotoD0InD0States[]
Definition: fxpkgpnp.hpp:4501
static const POWER_POLICY_EVENT_TARGET_STATE m_NotPowerPolOwnerStartingSucceededStates[]
Definition: fxpkgpnp.hpp:4495
static const POWER_POLICY_EVENT_TARGET_STATE m_NotPowerPolOwnerStoppingWaitForImplicitPowerDownStates[]
Definition: fxpkgpnp.hpp:4503
static WDF_DEVICE_POWER_POLICY_STATE NotPowerPolOwnerGotoDx(__inout FxPkgPnp *This)
static WDF_DEVICE_POWER_POLICY_STATE NotPowerPolOwnerStoppingFailed(__inout FxPkgPnp *This)
static WDF_DEVICE_POWER_POLICY_STATE NotPowerPolOwnerStartingFailed(__inout FxPkgPnp *This)
FxPowerPolicyStateCallback * m_PowerPolicyStateCallbacks
Definition: fxpkgpnp.hpp:4378
static const POWER_POLICY_EVENT_TARGET_STATE m_NotPowerPolOwnerStoppedStates[]
Definition: fxpkgpnp.hpp:4502
static const POWER_POLICY_EVENT_TARGET_STATE m_NotPowerPolOwnerDxStates[]
Definition: fxpkgpnp.hpp:4499
static WDF_DEVICE_POWER_POLICY_STATE NotPowerPolOwnerGotoD0(__inout FxPkgPnp *This)
static const NOT_POWER_POLICY_OWNER_STATE_TABLE m_WdfNotPowerPolicyOwnerStates[]
Definition: fxpkgpnp.hpp:4383
static const POWER_POLICY_EVENT_TARGET_STATE m_NotPowerPolOwnerStoppingPoweringUpStates[]
Definition: fxpkgpnp.hpp:4504
VOID NotPowerPolicyOwnerEnterNewState(__in WDF_DEVICE_POWER_POLICY_STATE NewState)
static const POWER_POLICY_EVENT_TARGET_STATE m_NotPowerPolOwnerStartingFailedStates[]
Definition: fxpkgpnp.hpp:4496
static const POWER_POLICY_EVENT_TARGET_STATE m_NotPowerPolOwnerGotoDxInDxStates[]
Definition: fxpkgpnp.hpp:4498
static WDF_DEVICE_POWER_POLICY_STATE NotPowerPolOwnerStarted(__inout FxPkgPnp *This)
static const POWER_POLICY_EVENT_TARGET_STATE m_NotPowerPolOwnerStartingStates[]
Definition: fxpkgpnp.hpp:4494
static WDF_DEVICE_POWER_POLICY_STATE NotPowerPolOwnerGotoD0InD0(__inout FxPkgPnp *This)
FxPowerPolicyMachine m_PowerPolicyMachine
Definition: fxpkgpnp.hpp:4153
static _Must_inspect_result_ CPNOT_POWER_POLICY_OWNER_STATE_TABLE GetNotPowerPolicyOwnerTableEntry(__in WDF_DEVICE_POWER_POLICY_STATE State)
Definition: fxpkgpnp.hpp:2928
#define __in
Definition: dbghelp.h:35
#define __inout
Definition: dbghelp.h:50
#define TRACINGPNPPOWERSTATES
Definition: dbgtrace.h:69
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define DEBUGGED_EVENT
Definition: fxpkgpnp.hpp:59
#define TRAP_ON_EVENT
Definition: fxpkgpnp.hpp:60
@ PnpEventPwrPolStopFailed
@ PnpEventPwrPolStarted
@ PnpEventPwrPolRemoved
@ PnpEventPwrPolStartFailed
@ PnpEventPwrPolStopped
@ PwrPolPowerDownIoStopped
@ PwrPolPowerUpHwStarted
@ PwrPolImplicitPowerDown
@ PwrPolImplicitPowerDownFailed
@ PowerImplicitD3
@ PowerImplicitD0
@ PowerCompleteD0
@ PowerCompleteDx
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
uint32_t entry
Definition: isohybrid.c:63
unsigned short USHORT
Definition: pedump.c:61
#define TRACE_LEVEL_INFORMATION
Definition: storswtr.h:29
UCHAR IncrementHistoryIndex(VOID)
FxPowerPolicyMachineStateHistory m_States
VOID Invoke(__in WDF_DEVICE_POWER_POLICY_STATE State, __in WDF_STATE_NOTIFICATION_TYPE Type, __in WDFDEVICE Device, __in PCWDF_DEVICE_POWER_POLICY_NOTIFICATION_DATA NotificationData)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
USHORT History[FxPowerPolicyEventQueueDepth]
@ StateNotificationEnterState
Definition: wdfdevice.h:392
@ StateNotificationPostProcessState
Definition: wdfdevice.h:393
@ StateNotificationLeaveState
Definition: wdfdevice.h:394
enum _WDF_DEVICE_POWER_POLICY_STATE WDF_DEVICE_POWER_POLICY_STATE
@ WdfDevStatePwrPolGotoD0InD0
Definition: wdfdevice.h:347
@ WdfDevStatePwrPolStopping
Definition: wdfdevice.h:323
@ WdfDevStatePwrPolStartingFailed
Definition: wdfdevice.h:235
@ WdfDevStatePwrPolStoppingSendStatus
Definition: wdfdevice.h:325
@ WdfDevStatePwrPolStoppingPoweringDown
Definition: wdfdevice.h:355
@ WdfDevStatePwrPolGotoDx
Definition: wdfdevice.h:343
@ WdfDevStatePwrPolRemoved
Definition: wdfdevice.h:374
@ WdfDevStatePwrPolStoppingPoweringUp
Definition: wdfdevice.h:354
@ WdfDevStatePwrPolStarted
Definition: wdfdevice.h:333
@ WdfDevStatePwrPolStopped
Definition: wdfdevice.h:331
@ WdfDevStatePwrPolNull
Definition: wdfdevice.h:385
@ WdfDevStatePwrPolGotoD0
Definition: wdfdevice.h:346
@ WdfDevStatePwrPolGotoDxInDx
Definition: wdfdevice.h:344
@ WdfDevStatePwrPolStartingSucceeded
Definition: wdfdevice.h:234
@ WdfDevStatePwrPolStoppingFailed
Definition: wdfdevice.h:324
@ WdfDevStatePwrPolStarting
Definition: wdfdevice.h:233
@ WdfDevStatePwrPolObjectCreated
Definition: wdfdevice.h:232
@ WdfDevStatePwrPolStoppingWaitingForImplicitPowerDown
Definition: wdfdevice.h:353
@ WdfDevStatePwrPolDx
Definition: wdfdevice.h:345