ReactOS  0.4.15-dev-3294-ge98684e
fxpoweridlestatemachine.hpp
Go to the documentation of this file.
1 //
2 // Copyright (C) Microsoft. All rights reserved.
3 //
4 #ifndef _FXPOWERIDLESTATEMACHINE_H_
5 #define _FXPOWERIDLESTATEMACHINE_H_
6 
7 //
8 // This is a magical number based on inspection. If the queue overflows,
9 // it is OK to increase these numbers without fear of either dependencies or
10 // weird side affects.
11 //
13 
15  // CAN BE REUSED = 0x0001,
27  PowerIdleNull = 0x0000,
28 };
29 
30 // begin_wpp config
31 // CUSTOM_TYPE(FxPowerIdleEvents, ItemEnum(FxPowerIdleEvents));
32 // end_wpp
33 
70 };
71 
72 //
73 // NOTE: if you change these flags (order, values, etc), you must also modify
74 // m_FlagsByName to match your changes.
75 //
85 };
86 
90 };
91 
92 typedef
96  );
97 
100 
102 
103 #if FX_SUPER_DBG
104  BOOLEAN EventDebugged;
105 #endif
106 };
107 
110 
112 
114 };
115 
116 class FxPowerIdleMachine : public FxStump {
117 
118 public:
120  VOID
121  );
122 
124  VOID
125  );
126 
128  NTSTATUS
129  Init(
130  VOID
131  );
132 
133  VOID
134  EnableTimer(
135  VOID
136  );
137 
138  BOOLEAN
139  DisableTimer(
140  VOID
141  );
142 
143  VOID
144  Start(
145  VOID
146  );
147 
148  VOID
149  Stop(
150  VOID
151  );
152 
153  VOID
154  Reset(
155  VOID
156  );
157 
159  NTSTATUS
160  IoIncrement(
161  VOID
162  );
163 
165  NTSTATUS
169  );
170 
171  VOID
172  IoDecrement(
174  __in_opt LONG Line = 0,
176  );
177 
178  BOOLEAN
180  VOID
181  );
182 
183  VOID
185  VOID
186  )
187  {
189  }
190 
192  NTSTATUS
196  __in_opt LONG Line = 0,
198  )
199  {
201  }
202 
204  NTSTATUS
207  )
208  {
209  return PowerReferenceWorker(FALSE, // WaitForD0
210  Flags);
211  }
212 
213  VOID
216  );
217 
218 protected:
219 
220  VOID
223  );
224 
225  BOOLEAN
227  VOID
228  )
229  {
231  }
232 
233  BOOLEAN
235  VOID
236  )
237  {
238  //
239  // If we are canceling the timer, be well sure it is started
240  //
242 
243  if (m_PowerTimeoutTimer.Stop()) {
245  return TRUE;
246  }
247  else {
248  return FALSE;
249  }
250  }
251 
252  BOOLEAN
254  VOID
255  )
256  {
258  }
259 
260  VOID
262  VOID
263  );
264 
266  NTSTATUS
271  __in_opt LONG Line = 0,
273  );
274 
275  static
278 
279  static
281  Stopped(
283  );
284 
285  static
287  Started(
289  );
290 
291  static
295  );
296 
297  static
301  );
302 
303  static
305  Disabled(
307  );
308 
309  static
311  CheckIoCount(
313  );
314 
315  static
317  DecrementIo(
319  );
320 
321  static
323  StartTimer(
325  );
326 
327  static
329  TimingOut(
331  );
332 
333  static
337  );
338 
339  static
343  );
344 
345  static
349  );
350 
351  static
353  GoingToDx(
355  );
356 
357  static
359  InDx(
361  );
362 
363  static
367  );
368 
369  static
373  );
374 
375  static
377  InDxStopped(
379  );
380 
381  static
383  InDxDisabled(
385  );
386 
387  static
389  InDxEnabled(
391  );
392 
393  static
395  PowerUp(
397  );
398 
399  static
403  );
404 
405  static
409  );
410 
411  static
415  );
416 
417  static
419  CancelTimer(
421  );
422 
423  static
425  TimerExpired(
427  );
428 
429  static
431  Disabling(
433  );
434 
435  static
439  );
440 
441  static
443  PowerFailed(
445  );
446 
447 private:
448  VOID
450  VOID
451  );
452 
453 public:
455 
456 protected:
457  //
458  // Lock which guards state
459  //
461 
462  //
463  // Number of pending requests which require being in D0
464  //
466 
467  //
468  // Tracks power references and releases.
469  //
471 
472  //
473  // Timer which will be set when the I/O count goes to zero
474  //
476 
477  //
478  // Event to wait on when transitioning from Dx to D0
479  //
481 
482  union {
483  //
484  // Combintaion of FxPowerIdleFlags enum values
485  //
487 
488  //
489  // Not used in the code. Here so that you can easily decode m_Flags in
490  // the debugger without needing the enum definition.
491  //
492  struct {
494  UCHAR InDx : 1;
501  } m_FlagsByName;
502  };
503 
504  //
505  // Index into m_EventHistory where to place the next value
506  //
508 
509  //
510  // Index into m_StateHistory where to place the next value
512 
513  //
514  // our current state
515  //
517 
518  //
519  // Circular history of events fed into this state machine
520  //
522 
523  //
524  // Circular history of states the state machine was in
525  //
527 
538 
540 
541  //
542  // We use a coalescable timer for idle timeout. The tolerable delay for the
543  // idle timer is defined below. The value below is an arbitrary choice and
544  // can be changed if necessary. MSDN documentation suggests 100 ms as being
545  // a reasonable choice.
546  //
547  static const ULONG m_IdleTimerTolerableDelayMS = 100;
548 };
549 
550 #endif // _FXPOWERIDLESTATEMACHINE_H_
static FxPowerIdleStates InDxPowerUpFailure(__inout FxPowerIdleMachine *This)
FxPowerIdleStates(* PFN_POWER_IDLE_STATE_ENTRY_FUNCTION)(FxPowerIdleMachine *)
static const FxPowerIdleTargetState m_BusyStates[]
_Must_inspect_result_ NTSTATUS PowerReference(__in BOOLEAN WaitForD0, __in_opt PVOID Tag=NULL, __in_opt LONG Line=0, __in_opt PSTR File=NULL)
static FxPowerIdleStates Stopped(__inout FxPowerIdleMachine *This)
#define __in_opt
Definition: dbghelp.h:38
#define TRUE
Definition: types.h:120
static FxPowerIdleStates InDxStopped(__inout FxPowerIdleMachine *This)
LONG NTSTATUS
Definition: precomp.h:26
static FxPowerIdleStates Disabling(__inout FxPowerIdleMachine *This)
static const FxPowerIdleTargetState m_TimerRunningStates[]
static FxPowerIdleStates TimedOutPowerDownFailed(__inout FxPowerIdleMachine *This)
static FxPowerIdleStates StartedPowerFailed(__inout FxPowerIdleMachine *This)
static FxPowerIdleStates StartedPowerUp(__inout FxPowerIdleMachine *This)
static const FxPowerIdleTargetState m_TimedOutStates[]
static FxPowerIdleStates CheckIoCount(__inout FxPowerIdleMachine *This)
FxPowerIdleEvents m_EventHistory[FxPowerIdleEventQueueDepth]
static FxPowerIdleStates Started(__inout FxPowerIdleMachine *This)
VOID IoDecrement(__in_opt PVOID Tag=NULL, __in_opt LONG Line=0, __in_opt PSTR File=NULL)
#define __out_opt
Definition: dbghelp.h:65
const UCHAR FxPowerIdleEventQueueDepth
static FxPowerIdleStates InDxDisabled(__inout FxPowerIdleMachine *This)
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
static const FxPowerIdleTargetState m_DisabledStates[]
static FxPowerIdleStates TimedOutDisabled(__inout FxPowerIdleMachine *This)
static const FxPowerIdleTargetState m_DisablingWaitForTimeoutStates[]
NTSTATUS EnterCRAndWaitAndLeave(VOID)
Definition: fxwaitlock.hpp:87
unsigned char BOOLEAN
VOID ProcessPowerEvent(__in FxPowerIdleEvents Event)
static FxPowerIdleStates TimedOutIoIncrement(__inout FxPowerIdleMachine *This)
static const FxPowerIdleTargetState m_WaitForTimeoutStates[]
int Count
Definition: noreturn.cpp:7
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define ASSERT(a)
Definition: mode.c:44
static FxPowerIdleStates InDxIoIncrement(__inout FxPowerIdleMachine *This)
_Must_inspect_result_ NTSTATUS PowerReferenceWorker(__in BOOLEAN WaitForD0, __in FxPowerReferenceFlags Flags, __in_opt PVOID Tag=NULL, __in_opt LONG Line=0, __in_opt PSTR File=NULL)
FxPowerIdleStates m_StateHistory[FxPowerIdleEventQueueDepth]
Definition: ncftp.h:79
static const FxPowerIdleTargetState m_InDxStates[]
unsigned char UCHAR
Definition: xmlstorage.h:181
_Must_inspect_result_ NTSTATUS IoIncrementWithFlags(__in FxPowerReferenceFlags Flags, __out_opt PULONG Count=NULL)
_Must_inspect_result_ NTSTATUS IoIncrement(VOID)
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN WaitForD0
Definition: wdfdevice.h:4003
static FxPowerIdleStates TimedOutEnabled(__inout FxPowerIdleMachine *This)
#define __inout
Definition: dbghelp.h:50
#define _Must_inspect_result_
Definition: ms_sal.h:558
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
Definition: wdfdevice.h:4061
static FxPowerIdleStates DecrementIo(__inout FxPowerIdleMachine *This)
Definition: mxlock.h:101
KDEFERRED_ROUTINE MdDeferredRoutineType
Definition: mxkm.h:35
FxPowerIdleStates m_CurrentIdleState
static FxPowerIdleStates TimingOut(__inout FxPowerIdleMachine *This)
static FxPowerIdleStates StartTimer(__inout FxPowerIdleMachine *This)
static const ULONG m_IdleTimerTolerableDelayMS
static const FxIdleStateTable m_StateTable[]
static FxPowerIdleStates TimedOutPowerDown(__inout FxPowerIdleMachine *This)
static FxPowerIdleStates DisablingTimerExpired(__inout FxPowerIdleMachine *This)
static MdDeferredRoutineType _PowerTimeoutDpcRoutine
signed char * PSTR
Definition: retypes.h:7
static FxPowerIdleStates Disabled(__inout FxPowerIdleMachine *This)
unsigned int * PULONG
Definition: retypes.h:1
#define NULL
Definition: types.h:112
static FxPowerIdleStates GoingToDx(__inout FxPowerIdleMachine *This)
_Must_inspect_result_ NTSTATUS PowerReferenceWithFlags(__in FxPowerReferenceFlags Flags)
static FxPowerIdleStates PowerUp(__inout FxPowerIdleMachine *This)
struct FxPowerIdleMachine::@4535::@4537 m_FlagsByName
static FxPowerIdleStates InDxEnabled(__inout FxPowerIdleMachine *This)
VOID ProcessEventLocked(__in FxPowerIdleEvents Event)
static const FxPowerIdleTargetState m_StartedStates[]
unsigned int ULONG
Definition: retypes.h:1
static FxPowerIdleStates PowerUpComplete(__inout FxPowerIdleMachine *This)
Definition: File.h:15
PFN_POWER_IDLE_STATE_ENTRY_FUNCTION StateFunc
_Must_inspect_result_ NTSTATUS Init(VOID)
#define __in
Definition: dbghelp.h:35
static FxPowerIdleStates PowerFailed(__inout FxPowerIdleMachine *This)
static FxPowerIdleStates CancelTimer(__inout FxPowerIdleMachine *This)
const FxPowerIdleTargetState * TargetStates
LONG ReadState(VOID)
Definition: fxwaitlock.hpp:160
static const FxPowerIdleTargetState m_PowerFailedWaitForTimeoutStates[]
_Must_inspect_result_ __inline BOOLEAN Stop(VOID)
Definition: mxtimerkm.h:273
static const FxPowerIdleTargetState m_StoppedStates[]
static FxPowerIdleStates TimerExpired(__inout FxPowerIdleMachine *This)