ReactOS 0.4.15-dev-7711-g5627da4
pdopower.cpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation
4
5Module Name:
6
7 PdoPower.cpp
8
9Abstract:
10
11 This module implements the Pnp package for Pdo devices.
12
13Author:
14
15
16
17
18Environment:
19
20 Both kernel and user mode
21
22Revision History:
23
24
25
26--*/
27
28#include "pnppriv.hpp"
29
30// Tracing support
31#if defined(EVENT_TRACING)
32extern "C" {
33#include "PdoPower.tmh"
34}
35#endif
36
42 )
43/*++
44
45Routine Description:
46 report the power sequence for the child
47
48Arguments:
49 This - the package
50
51 Irp - the request
52
53Return Value:
54 STATUS_NOT_SUPPORTED
55
56 --*/
57{
58 return ((FxPkgPdo*) This)->CompletePowerRequest(Irp, STATUS_NOT_SUPPORTED);
59}
60
66 )
67/*++
68
69Routine Description:
70
71 This method is invoked when a SetPower IRP enters the driver.
72
73Arguemnts:
74
75 Device - a pointer to the FxDevice
76
77 Irp - a pointer to the FxIrp
78
79Returns:
80
81 NTSTATUS
82
83--*/
84{
85 if (Irp->GetParameterPowerType() == SystemPowerState) {
86 return ((FxPkgPdo*) This)->DispatchSystemSetPower(Irp);
87 }
88 else {
89 return ((FxPkgPdo*) This)->DispatchDeviceSetPower(Irp);
90 }
91}
92
97 )
98{
99 KIRQL irql;
101
102 m_SystemPowerState = (BYTE) Irp->GetParameterPowerStateSystemState();
104 Irp->GetParameterPowerState());
105
106 if (IsPowerPolicyOwner()) {
108 //
109 // Ideally we would like to complete the S0 irp before we start
110 // processing the event in the state machine so that the D0 irp
111 // comes after the S0 is moving up the stack...
112 //
113 // ... BUT ...
114 //
115 // ... by allowing the S0 irp to go up the stack first, we must then
116 // handle pnp requests from the current power policy state (because
117 // the S0 irp could be the last S irp in the system and when completed,
118 // the pnp lock is released). So, we process the event first so
119 // that we can move into a state where we can handle pnp events in
120 // the power policy state machine.
121 //
122 // We mitigate the situation a little bit by forcing the processing of the
123 // event to occur on the power policy thread rather then in the current
124 // context.
125 //
126 Mx::MxRaiseIrql(DISPATCH_LEVEL, &irql);
128 Mx::MxLowerIrql(irql);
129
131 }
132 else {
133 //
134 // Power policy state machine will complete the request later
135 //
138 return STATUS_PENDING;
139 }
140 }
141 else {
142 //
143 // Since we are not the power policy owner, we just complete all S irps
144 //
146 }
147}
148
152 __in FxIrp *Irp
153 )
154{
155 if (IsPowerPolicyOwner()) {
158 //
159 // A power irp arrived, but we did not request it. ASSERT and log
160 // an error.
161 //
164 "Received set device power irp 0x%p on WDFDEVICE 0x%p !devobj 0x%p, "
165 "but the irp was not requested by the device (the power policy owner)",
166 Irp->GetIrp(),
169
170 ASSERTMSG("Received set device power irp but the irp was not "
171 "requested by the device (the power policy owner)\n",
172 FALSE);
173 }
174
175 //
176 // We are no longer requesting a power irp because we received the one
177 // we requested.
178 //
181 }
182 else {
184 }
185 }
186
188
189 if (Irp->GetParameterPowerStateDeviceState() == PowerDeviceD0) {
191 }
192 else {
194 }
195
196 return STATUS_PENDING;
197}
198
203 __in FxIrp *Irp
204 )
205/*++
206
207Routine Description:
208 Dispatches query power for system and device requests
209
210Arguments:
211 This - the package
212
213 Irp - the query power request
214
215Return Value:
216 NTSTATUS
217
218 --*/
219{
220 FxPkgPdo* pThis;
222
223 pThis = ((FxPkgPdo*) This);
224
225 if (Irp->GetParameterPowerType() == SystemPowerState
226 &&
227 This->PowerPolicyIsWakeEnabled()) {
228
230 Irp->GetParameterPowerStateSystemState()
231 );
232 }
233 else {
235 }
236
237 return pThis->CompletePowerRequest(Irp, status);
238}
239
240VOID
242 __in BOOLEAN IrpMustBePresent
243 )
244{
245 MdIrp pIrp;
246
248
249 UNREFERENCED_PARAMETER(IrpMustBePresent);
250 ASSERT(IrpMustBePresent == FALSE || pIrp != NULL);
251
252 if (pIrp != NULL) {
253 FxIrp irp(pIrp);
254
256 }
257}
258
262 __in BOOLEAN* ParentOn
263 )
264/*++
265
266Routine Description:
267 This function implements the CheckParent state. Its
268 job is to determine which state we should go to next based on whether
269 the parent is in D0.
270
271Arguments:
272 none
273
274Return Value:
275
276 VOID
277
278--*/
279{
280
281
282
283
284 return (m_Device->m_ParentDevice->m_PkgPnp)->
286}
287
290 VOID
291 )
292/*++
293
294Routine Description:
295 This function implements the Check Type state. This is a PDO.
296
297Arguments:
298 none
299
300Return Value:
301
302 new power state
303
304--*/
305{
307}
308
311 VOID
312 )
313/*++
314
315Routine Description:
316 This function implements the Check Type state. This is a PDO.
317
318Arguments:
319 none
320
321Return Value:
322
323 new power state
324
325--*/
326{
328}
329
333 VOID
334 )
335/*++
336
337Routine Description:
338 Arms the device at the bus level for wake. This arming is generic since
339 the bus driver can only configure the device generically. The power policy
340 owner has already armed the device for wake in a device specific fashion
341 when it processed the wake irp (EvtDeviceArmDeviceForWakeFromS0/x if the ppo
342 is a WDF driver).
343
344Arguments:
345 None
346
347Return Value:
348 NTSTATUS, !NT_SUCCESS if the arm failed
349
350 --*/
351{
353
354 //
355 // The EnableWakeAtBus callback should not be called twice in a row without
356 // an intermediate call to the DisableWakeAtBus callback.
357 //
359
363 );
364
365 if (NT_SUCCESS(status)) {
368 }
369
370 return status;
371}
372
373VOID
375 VOID
376 )
377/*++
378
379Routine Description:
380 Disarms the device at the bus level for wake. This disarming is generic
381 since the bus driver can only configure the device generically. The power
382 policy owner may have already disarmed the device for wake in a device
383 specific fashion. For a WDF ppo EvtDeviceDisarmDeviceForWakeFromS0/x is
384 called after the bus has disarmed.
385
386Arguments:
387 None
388
389Return Value:
390 None
391
392 --*/
393{
397
399 }
400}
401
402VOID
404 VOID
405 )
406/*++
407
408Routine Description:
409 Releases the child power reference on the parent device. This allows the
410 parent to enter into an idle capable state. This power reference does not
411 prevent the parent from moving into Dx when the system power state changes.
412
413Arguments:
414 None
415
416Return Value:
417 None
418
419 --*/
420{
421
423}
424
425VOID
427 VOID
428 )
429/*++
430
431Routine Description:
432 Notifies the parent device that the child is armed for wake. This will
433 cause the parent to increment its count of children armed for wake.
434
435Arguments:
436 None
437
438Return Value:
439 None
440
441 --*/
442{
444
446
447
448
449
450
453 if (settings != NULL) {
454 settings->IncrementChildrenArmedForWakeCount();
455 }
456}
457
458VOID
460 VOID
461 )
462/*++
463
464Routine Description:
465 Notifies the parent device that the child is not armed for wake. This will
466 cause the parent to decrement its count of children armed for wake.
467
468Arguments:
469 None
470
471Return Value:
472 None
473
474 --*/
475{
477
479
480
481
482
483
486 if (settings != NULL) {
487 settings->DecrementChildrenArmedForWakeCount();
488 }
489}
struct mke2fs_defaults settings[]
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
WDFDEVICE __inline GetHandle(VOID)
Definition: fxdevice.hpp:237
MdDeviceObject __inline GetDeviceObject(VOID)
Definition: fxdevice.hpp:174
CfxDevice * m_ParentDevice
Definition: fxdevice.hpp:569
FxPkgPnp * m_PkgPnp
Definition: fxdevice.hpp:670
Definition: fxirp.hpp:28
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
CfxDevice * m_Device
Definition: fxobject.hpp:329
FxPowerDeviceEnableWakeAtBus m_DeviceEnableWakeAtBus
Definition: fxpkgpdo.hpp:53
_Must_inspect_result_ NTSTATUS DispatchDeviceSetPower(__in FxIrp *Irp)
Definition: pdopower.cpp:151
VOID PowerNotifyParentChildWakeDisarmed(VOID)
Definition: pdopower.cpp:459
virtual VOID PowerParentPowerDereference(VOID)
Definition: pdopower.cpp:403
virtual VOID PowerReleasePendingDeviceIrp(__in BOOLEAN IrpMustBePresent=TRUE)
Definition: pdopower.cpp:241
FxPowerDeviceDisableWakeAtBus m_DeviceDisableWakeAtBus
Definition: fxpkgpdo.hpp:54
virtual WDF_DEVICE_POWER_STATE PowerCheckDeviceTypeNPOverload(VOID)
Definition: pdopower.cpp:310
_Must_inspect_result_ NTSTATUS DispatchSystemSetPower(__in FxIrp *Irp)
Definition: pdopower.cpp:95
VOID PowerNotifyParentChildWakeArmed(VOID)
Definition: pdopower.cpp:426
virtual _Must_inspect_result_ NTSTATUS PowerEnableWakeAtBusOverload(VOID)
Definition: pdopower.cpp:332
virtual VOID PowerDisableWakeAtBusOverload(VOID)
Definition: pdopower.cpp:374
BOOLEAN m_EnableWakeAtBusInvoked
Definition: fxpkgpdo.hpp:141
static _Must_inspect_result_ NTSTATUS _DispatchSetPower(__inout FxPkgPnp *This, __in FxIrp *Irp)
Definition: pdopower.cpp:63
virtual _Must_inspect_result_ NTSTATUS PowerCheckParentOverload(__in BOOLEAN *ParentOn)
Definition: pdopower.cpp:261
static _Must_inspect_result_ NTSTATUS _DispatchQueryPower(__inout FxPkgPnp *This, __in FxIrp *Irp)
Definition: pdopower.cpp:201
virtual WDF_DEVICE_POWER_STATE PowerCheckDeviceTypeOverload(VOID)
Definition: pdopower.cpp:289
static _Must_inspect_result_ NTSTATUS _DispatchPowerSequence(__inout FxPkgPnp *This, __in FxIrp *Irp)
Definition: pdopower.cpp:39
VOID SetPendingDevicePowerIrp(__inout FxIrp *Irp)
Definition: fxpkgpnp.hpp:3050
VOID PowerProcessEvent(__in FxPowerEvent Event, __in BOOLEAN ProcessEventOnDifferentThread=FALSE)
VOID PowerPolicyChildPoweredDown(VOID)
Definition: fxpkgpnp.hpp:3746
MdIrp ClearPendingDevicePowerIrp(VOID)
Definition: fxpkgpnp.hpp:3069
_Must_inspect_result_ NTSTATUS PowerPolicyHandleSystemQueryPower(__in SYSTEM_POWER_STATE QueryState)
Definition: fxpkgpnp.cpp:3582
_Must_inspect_result_ NTSTATUS PowerPolicyCanChildPowerUp(__out PBOOLEAN PowerUp)
Definition: fxpkgpnp.hpp:3686
BYTE m_SystemPowerState
Definition: fxpkgpnp.hpp:4102
VOID SetPendingSystemPowerIrp(__inout FxIrp *Irp)
Definition: fxpkgpnp.hpp:3082
NTSTATUS CompletePowerRequest(__inout FxIrp *Irp, __in NTSTATUS Status)
Definition: fxpkgpnp.cpp:5404
FxPowerPolicyMachine m_PowerPolicyMachine
Definition: fxpkgpnp.hpp:4153
VOID PowerPolicyProcessEvent(__in FxPowerPolicyEvent Event, __in BOOLEAN ProcessEventOnDifferentThread=FALSE)
VOID Invoke(__in WDFDEVICE Device)
_Must_inspect_result_ NTSTATUS Invoke(__in WDFDEVICE Device, __in SYSTEM_POWER_STATE PowerState)
POWER_STATE SetPowerState(__in POWER_STATE_TYPE Type, __in POWER_STATE State)
_In_ PIRP Irp
Definition: csq.h:116
#define __in
Definition: dbghelp.h:35
#define __inout
Definition: dbghelp.h:50
#define TRACINGPNP
Definition: dbgtrace.h:67
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
KIRQL irql
Definition: wave.h:1
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
MxDeviceObject deviceObject
FxIrp * pIrp
FxIrp * irp
#define ASSERT(a)
Definition: mode.c:44
#define _Must_inspect_result_
Definition: ms_sal.h:558
IWudfIrp * MdIrp
Definition: mxum.h:103
#define ASSERTMSG(msg, exp)
Definition: nt_native.h:431
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
@ PowerSystemWorking
Definition: ntpoapi.h:36
@ PowerDeviceD0
Definition: ntpoapi.h:49
enum _SYSTEM_POWER_STATE SYSTEM_POWER_STATE
#define STATUS_PENDING
Definition: ntstatus.h:82
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
FxPowerPolicyOwnerSettings * m_Owner
Definition: ps.c:97
_In_ PWDFDEVICE_INIT _In_ BOOLEAN IsPowerPolicyOwner
Definition: wdfdevice.h:2966
enum _WDF_DEVICE_POWER_STATE WDF_DEVICE_POWER_STATE
@ WdfDevStatePowerCheckParentStateNP
Definition: wdfdevice.h:134
@ WdfDevStatePowerCheckParentState
Definition: wdfdevice.h:133
_In_ SYSTEM_POWER_STATE SystemPowerState
Definition: iotypes.h:7519
unsigned char BYTE
Definition: xxhash.c:193