ReactOS  0.4.15-dev-4921-g25fcdc5
notpowerpolicyownerstatemachine.cpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft. All rights reserved.
4 
5 Module Name:
6 
7  NotPowerPolicyOwnerStateMachine.cpp
8 
9 Abstract:
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 
14 Author:
15 
16 
17 
18 
19 Environment:
20 
21  Both kernel and user mode
22 
23 Revision History:
24 
25 
26 
27 --*/
28 
29 #include "pnppriv.hpp"
30 
31 extern "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 
269 VOID
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 
299  m_PowerPolicyStateCallbacks->Invoke(currentState,
301  m_Device->GetHandle(),
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 
320  m_Device->GetHandle(),
321  &data);
322  }
323 
325  currentState = newState;
326 
327  entry = GetNotPowerPolicyOwnerTableEntry(currentState);
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 
348  m_PowerPolicyStateCallbacks->Invoke(currentState,
350  m_Device->GetHandle(),
351  &data);
352  }
353  }
354 }
355 
359  )
360 /*++
361 
362 Routine 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 
366 Arguments:
367  This - instance of the state machine
368 
369 Return Value:
370  WdfDevStatePwrPolNull
371 
372  --*/
373 {
374  This->PowerProcessEvent(PowerImplicitD0);
375  return WdfDevStatePwrPolNull;
376 }
377 
381  )
382 /*++
383 
384 Routine 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 
388 Arguments:
389  This - instance of the state machine
390 
391 Return Value:
392  WdfDevStatePwrPolNull
393 
394  --*/
395 {
396  This->PnpProcessEvent(PnpEventPwrPolStarted);
398 }
399 
403  )
404 {
405  This->PowerProcessEvent(PowerCompleteDx);
406  return WdfDevStatePwrPolNull;
407 }
408 
412  )
413 {
414  This->PowerProcessEvent(PowerCompleteDx);
415  return WdfDevStatePwrPolNull;
416 }
417 
421  )
422 {
423  This->PowerProcessEvent(PowerCompleteD0);
424  return WdfDevStatePwrPolNull;
425 }
426 
430  )
431 {
432  This->PowerProcessEvent(PowerCompleteD0);
433  return WdfDevStatePwrPolNull;
434 }
435 
439  )
440 /*++
441 
442 Routine 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 
446 Arguments:
447  This - instance of the state machine
448 
449 Return Value:
450  WdfDevStatePwrPolStoppingWaitingForImplicitPowerDown
451 
452  --*/
453 {
454  This->PowerProcessEvent(PowerImplicitD3);
456 }
457 
461  )
462 /*++
463 
464 Routine 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 
468 Arguments:
469  This - instance of the state machine
470 
471 Return Value:
472  WdfDevStatePwrPolStopped
473 
474  --*/
475 {
476  This->PnpProcessEvent(PnpEventPwrPolStopped);
478 }
479 
483  )
484 /*++
485 
486 Routine 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 
490 Arguments:
491  This - instance of the state machine
492 
493 Return Value:
494  WdfDevStatePwrPolNull
495 
496  --*/
497 {
498  This->PnpProcessEvent(PnpEventPwrPolStartFailed);
499  return WdfDevStatePwrPolNull;
500 }
501 
505  )
506 /*++
507 
508 Routine 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 
512 Arguments:
513  This - instance of the state machine
514 
515 Return Value:
516  WdfDevStatePwrPolStopped
517 
518  --*/
519 {
520  This->PnpProcessEvent(PnpEventPwrPolStopFailed);
522 }
523 
527  )
528 /*++
529 
530 Routine 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 
535 Arguments:
536  This - instance of the state machine
537 
538 Return Value:
539  WdfDevStatePwrPolNull
540 
541  --*/
542 {
543  This->PowerProcessEvent(PowerCompleteD0);
544  return WdfDevStatePwrPolNull;
545 }
546 
550  )
551 /*++
552 
553 Routine 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 
558 Arguments:
559  This - instance of the state machine
560 
561 Return Value:
562  WdfDevStatePwrPolNull
563 
564  --*/
565 {
566  This->PowerProcessEvent(PowerCompleteDx);
567  return WdfDevStatePwrPolNull;
568 }
569 
573  )
574 /*++
575 
576 Routine Description:
577  The device is being removed, so prepare for removal.
578 
579 Arguments:
580  This - instance of the state machine
581 
582 Return 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);
592  return WdfDevStatePwrPolNull;
593 }
#define TRAP_ON_EVENT
Definition: fxpkgpnp.hpp:60
CfxDevice * m_Device
Definition: fxobject.hpp:329
static const POWER_POLICY_EVENT_TARGET_STATE m_NotPowerPolOwnerObjectCreatedStates[]
Definition: fxpkgpnp.hpp:4493
MdDeviceObject __inline GetDeviceObject(VOID)
Definition: fxdevice.hpp:174
#define TRUE
Definition: types.h:120
WDFDEVICE __inline GetHandle(VOID)
Definition: fxdevice.hpp:237
FxPowerPolicyMachineStateHistory m_States
static WDF_DEVICE_POWER_POLICY_STATE NotPowerPolOwnerStoppingPoweringUp(__inout FxPkgPnp *This)
static WDF_DEVICE_POWER_POLICY_STATE NotPowerPolOwnerGotoD0(__inout FxPkgPnp *This)
static const POWER_POLICY_EVENT_TARGET_STATE m_NotPowerPolOwnerStoppingWaitForImplicitPowerDownStates[]
Definition: fxpkgpnp.hpp:4503
FxPowerPolicyMachine m_PowerPolicyMachine
Definition: fxpkgpnp.hpp:4153
static WDF_DEVICE_POWER_POLICY_STATE NotPowerPolOwnerStoppingPoweringDown(__inout FxPkgPnp *This)
UCHAR IncrementHistoryIndex(VOID)
#define TRACE_LEVEL_INFORMATION
Definition: storswtr.h:29
static const POWER_POLICY_EVENT_TARGET_STATE m_NotPowerPolOwnerRemovedStates[]
Definition: fxpkgpnp.hpp:4506
static const POWER_POLICY_EVENT_TARGET_STATE m_NotPowerPolOwnerStoppingPoweringUpStates[]
Definition: fxpkgpnp.hpp:4504
#define TRACINGPNPPOWERSTATES
Definition: dbgtrace.h:69
static const POWER_POLICY_EVENT_TARGET_STATE m_NotPowerPolOwnerGotoD0States[]
Definition: fxpkgpnp.hpp:4500
static _Must_inspect_result_ CPNOT_POWER_POLICY_OWNER_STATE_TABLE GetNotPowerPolicyOwnerTableEntry(__in WDF_DEVICE_POWER_POLICY_STATE State)
Definition: fxpkgpnp.hpp:2928
static const POWER_POLICY_EVENT_TARGET_STATE m_NotPowerPolOwnerGotoDxInDxStates[]
Definition: fxpkgpnp.hpp:4498
#define FALSE
Definition: types.h:117
static const POWER_POLICY_EVENT_TARGET_STATE m_NotPowerPolOwnerStoppingPoweringDownStates[]
Definition: fxpkgpnp.hpp:4505
static const POWER_POLICY_EVENT_TARGET_STATE m_NotPowerPolOwnerStoppedStates[]
Definition: fxpkgpnp.hpp:4502
static WDF_DEVICE_POWER_POLICY_STATE NotPowerPolOwnerStopping(__inout FxPkgPnp *This)
static WDF_DEVICE_POWER_POLICY_STATE NotPowerPolOwnerGotoDx(__inout FxPkgPnp *This)
VOID NotPowerPolicyOwnerEnterNewState(__in WDF_DEVICE_POWER_POLICY_STATE NewState)
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)
static const POWER_POLICY_EVENT_TARGET_STATE m_NotPowerPolOwnerStartingStates[]
Definition: fxpkgpnp.hpp:4494
__inline VOID SetDevicePowerPolicyState(__in WDF_DEVICE_POWER_POLICY_STATE DeviceState)
Definition: fxdevice.hpp:1191
FxPowerPolicyStateCallback * m_PowerPolicyStateCallbacks
Definition: fxpkgpnp.hpp:4378
static WDF_DEVICE_POWER_POLICY_STATE NotPowerPolOwnerStarted(__inout FxPkgPnp *This)
static WDF_DEVICE_POWER_POLICY_STATE NotPowerPolOwnerStoppingSendStatus(__inout FxPkgPnp *This)
static const POWER_POLICY_EVENT_TARGET_STATE m_NotPowerPolOwnerGotoDxStates[]
Definition: fxpkgpnp.hpp:4497
static WDF_DEVICE_POWER_POLICY_STATE NotPowerPolOwnerRemoved(__inout FxPkgPnp *This)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
static const POWER_POLICY_EVENT_TARGET_STATE m_NotPowerPolOwnerStartingFailedStates[]
Definition: fxpkgpnp.hpp:4496
uint32_t entry
Definition: isohybrid.c:63
static const NOT_POWER_POLICY_OWNER_STATE_TABLE m_WdfNotPowerPolicyOwnerStates[]
Definition: fxpkgpnp.hpp:4383
#define DEBUGGED_EVENT
Definition: fxpkgpnp.hpp:59
#define __inout
Definition: dbghelp.h:50
static WDF_DEVICE_POWER_POLICY_STATE NotPowerPolOwnerGotoDxInDx(__inout FxPkgPnp *This)
static const POWER_POLICY_EVENT_TARGET_STATE m_NotPowerPolOwnerDxStates[]
Definition: fxpkgpnp.hpp:4499
USHORT History[FxPowerPolicyEventQueueDepth]
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
unsigned short USHORT
Definition: pedump.c:61
#define ARRAY_SIZE(a)
Definition: main.h:24
static WDF_DEVICE_POWER_POLICY_STATE NotPowerPolOwnerStarting(__inout FxPkgPnp *This)
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define NULL
Definition: types.h:112
static WDF_DEVICE_POWER_POLICY_STATE NotPowerPolOwnerStoppingFailed(__inout FxPkgPnp *This)
static WDF_DEVICE_POWER_POLICY_STATE NotPowerPolOwnerGotoD0InD0(__inout FxPkgPnp *This)
__inline WDF_DEVICE_POWER_POLICY_STATE GetDevicePowerPolicyState()
Definition: fxdevice.hpp:1165
enum _WDF_DEVICE_POWER_POLICY_STATE WDF_DEVICE_POWER_POLICY_STATE
static WDF_DEVICE_POWER_POLICY_STATE NotPowerPolOwnerStartingFailed(__inout FxPkgPnp *This)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define __in
Definition: dbghelp.h:35
static const POWER_POLICY_EVENT_TARGET_STATE m_NotPowerPolOwnerStartingSucceededStates[]
Definition: fxpkgpnp.hpp:4495
static const POWER_POLICY_EVENT_TARGET_STATE m_NotPowerPolOwnerGotoD0InD0States[]
Definition: fxpkgpnp.hpp:4501