ReactOS 0.4.15-dev-7906-g1b85a5f
poxinterfacekm.cpp
Go to the documentation of this file.
1//
2// Copyright (C) Microsoft. All rights reserved.
3//
4#include "pnppriv.hpp"
5
6#include <initguid.h>
7#include <wdmguid.h>
8
9extern "C" {
10#if defined(EVENT_TRACING)
11#include "PoxInterfaceKm.tmh"
12#endif
13}
14
15VOID
20 )
21{
22 PPOX_SETTINGS poxSettings = NULL;
23 FxPoxInterface * pThis = NULL;
24
25 pThis = (FxPoxInterface*) Context;
26
28 pThis->m_PkgPnp->GetDriverGlobals(),
31 "WDFDEVICE 0x%p !devobj 0x%p PO_FX_COMPONENT_IDLE_STATE_CALLBACK "
32 "invoked.",
33 pThis->m_PkgPnp->GetDevice()->GetHandle(),
35 );
36
37 //
38 // If the client driver has specified power framework settings, retrieve
39 // them.
40 //
41 poxSettings = pThis->GetPowerFrameworkSettings();
42
43 //
44 // If the client driver has specified an F-state change callback, invoke it.
45 //
46 if ((NULL != poxSettings) &&
47 (NULL != poxSettings->ComponentIdleStateCallback)) {
48
50 pThis->m_PkgPnp->GetDriverGlobals(),
53 "WDFDEVICE 0x%p !devobj 0x%p Invoking client driver's "
54 "PO_FX_COMPONENT_IDLE_STATE_CALLBACK.",
55 pThis->m_PkgPnp->GetDevice()->GetHandle(),
57 );
58
59 poxSettings->ComponentIdleStateCallback(
60 poxSettings->PoFxDeviceContext,
62 State);
63 } else {
64 PoFxCompleteIdleState(pThis->m_PoHandle, Component);
65 }
66}
67
68VOID
72 )
73{
74 PPOX_SETTINGS poxSettings = NULL;
75 FxPoxInterface * pThis = NULL;
76
77 pThis = (FxPoxInterface*) Context;
78
80 pThis->m_PkgPnp->GetDriverGlobals(),
83 "WDFDEVICE 0x%p !devobj 0x%p PO_FX_COMPONENT_ACTIVE_CONDITION_CALLBACK "
84 "invoked.",
85 pThis->m_PkgPnp->GetDevice()->GetHandle(),
87 );
88
89 //
90 // If the client driver has specified power framework settings, retrieve
91 // them.
92 //
93 poxSettings = pThis->GetPowerFrameworkSettings();
94
95 //
96 // If the client driver has specified a component-active callback, invoke it
97 //
98 if ((NULL != poxSettings) &&
99 (NULL != poxSettings->ComponentActiveConditionCallback)) {
100
102 pThis->m_PkgPnp->GetDriverGlobals(),
105 "WDFDEVICE 0x%p !devobj 0x%p Invoking client driver's "
106 "PO_FX_COMPONENT_ACTIVE_CONDITION_CALLBACK.",
107 pThis->m_PkgPnp->GetDevice()->GetHandle(),
109 );
110
112 poxSettings->PoFxDeviceContext,
114 );
115 } else {
116 //
117 // Nothing to do.
118 //
119 DO_NOTHING();
120 }
121
122 return;
123}
124
125VOID
129 )
130{
131 PPOX_SETTINGS poxSettings = NULL;
132 FxPoxInterface * pThis = NULL;
133
134 pThis = (FxPoxInterface*) Context;
135
137 pThis->m_PkgPnp->GetDriverGlobals(),
140 "WDFDEVICE 0x%p !devobj 0x%p PO_FX_COMPONENT_IDLE_CONDITION_CALLBACK "
141 "invoked.",
142 pThis->m_PkgPnp->GetDevice()->GetHandle(),
144 );
145
146 //
147 // If the client driver has specified power framework settings, retrieve
148 // them.
149 //
150 poxSettings = pThis->GetPowerFrameworkSettings();
151
152 //
153 // If the client driver has specified a component-idle callback, invoke it
154 //
155 if ((NULL != poxSettings) &&
156 (NULL != poxSettings->ComponentIdleConditionCallback)) {
157
159 pThis->m_PkgPnp->GetDriverGlobals(),
162 "WDFDEVICE 0x%p !devobj 0x%p Invoking client driver's "
163 "PO_FX_COMPONENT_IDLE_CONDITION_CALLBACK.",
164 pThis->m_PkgPnp->GetDevice()->GetHandle(),
166 );
167
169 poxSettings->PoFxDeviceContext,
171 );
172 } else {
173 //
174 // We're being notified that we're idle, but there is no action that we
175 // need to take here. We power down the device only when we get the
176 // device-power-not-required event.
177 //
178 PoFxCompleteIdleCondition(pThis->m_PoHandle, Component);
179 }
180 return;
181}
182
183VOID
186 )
187{
188 FxPoxInterface * pThis = NULL;
189
190 pThis = (FxPoxInterface*) Context;
191 pThis->PowerRequiredCallbackWorker(TRUE /* InvokedFromPoxCallback */);
192 return;
193}
194
195VOID
198 )
199{
200 FxPoxInterface * pThis = NULL;
201
202 pThis = (FxPoxInterface*) Context;
203 pThis->PowerNotRequiredCallbackWorker(TRUE /* InvokedFromPoxCallback */);
204 PoFxCompleteDevicePowerNotRequired(pThis->m_PoHandle);
205 return;
206}
207
208_Function_class_(PO_FX_POWER_CONTROL_CALLBACK)
219 )
220{
222 PPOX_SETTINGS poxSettings = NULL;
223 FxPoxInterface * pThis = NULL;
224
225 pThis = (FxPoxInterface*) Context;
226
228 pThis->m_PkgPnp->GetDriverGlobals(),
231 "WDFDEVICE 0x%p !devobj 0x%p PO_FX_POWER_CONTROL_CALLBACK invoked.",
232 pThis->m_PkgPnp->GetDevice()->GetHandle(),
234 );
235
236 //
237 // If the client driver has specified power framework settings, retrieve
238 // them.
239 //
240 poxSettings = pThis->GetPowerFrameworkSettings();
241
242 //
243 // The client driver must have specified a power control callback
244 //
245 ASSERT((NULL != poxSettings) &&
246 (NULL != poxSettings->PowerControlCallback));
247
248 //
249 // Invoke the client driver's power control callback
250 //
251 status = poxSettings->PowerControlCallback(poxSettings->PoFxDeviceContext,
253 InBuffer,
255 OutBuffer,
258
260 pThis->m_PkgPnp->GetDriverGlobals(),
263 "WDFDEVICE 0x%p !devobj 0x%p Client driver's "
264 "PO_FX_POWER_CONTROL_CALLBACK returned %!STATUS!.",
265 pThis->m_PkgPnp->GetDevice()->GetHandle(),
267 status
268 );
269
270 return status;
271}
272
275 VOID
276 )
277{
278
280 PO_FX_DEVICE poxDevice;
282 PPOX_SETTINGS poxSettings = NULL;
283
284 RtlZeroMemory(&poxDevice, sizeof(poxDevice));
285 RtlZeroMemory(&idleState, sizeof(idleState));
286
287 poxDevice.Version = PO_FX_VERSION_V1;
288
289 //
290 // Specify callbacks and context
291 //
302 poxDevice.DeviceContext = this;
303
304 //
305 // We register as a single component device
306 //
307 poxDevice.ComponentCount = 1;
308
309 //
310 // If the client driver has specified power framework settings, retrieve
311 // them.
312 //
313 poxSettings = GetPowerFrameworkSettings();
314
315 //
316 // We specify a power control callback only if the client driver supplies us
317 // a power control callback
318 //
319 poxDevice.PowerControlCallback =
320 ((NULL == poxSettings) || (NULL == poxSettings->PowerControlCallback)) ?
321 NULL :
323
324 //
325 // If the client driver has specified any settings for component 0, use
326 // them. Otherwise use the default settings.
327 //
328 if ((NULL == poxSettings) || (NULL == poxSettings->Component)) {
329 //
330 // Default settings
331 //
332
333 //
334 // We only support F0
335 //
336 poxDevice.Components[0].IdleStateCount = 1;
337
338 //
339 // Transition latency should be 0 for F0
340 //
341 idleState.TransitionLatency = 0;
342
343 //
344 // Residency requirement should be 0 for F0
345 //
346 idleState.ResidencyRequirement = 0;
347
348 //
349 // The value doesn't matter because we do not support multiple F-states.
350 //
351 idleState.NominalPower = PO_FX_UNKNOWN_POWER;
352
353 //
354 // Specify the state information for F0
355 //
356 poxDevice.Components[0].IdleStates = &idleState;
357 }
358 else {
359 //
360 // Client driver's settings
361 //
362 RtlCopyMemory(&(poxDevice.Components[0]),
363 poxSettings->Component,
364 sizeof(poxDevice.Components[0]));
365 }
366
367 //
368 // Register with the power framework
369 //
370 status = PoFxRegisterDevice(
372 &poxDevice,
373 &(m_PoHandle)
374 );
375 if (FALSE == NT_SUCCESS(status)) {
379 "WDFDEVICE 0x%p !devobj 0x%p FxPox::PoxRegisterDevice failed. "
380 "%!STATUS!.",
383 status);
384 goto exit;
385 }
386
388
389exit:
390 return status;
391
392}
393
394VOID
396 VOID
397 )
398{
399 PoFxStartDevicePowerManagement(m_PoHandle);
400}
401
402
403VOID
405 VOID
406 )
407{
408 PoFxUnregisterDevice(m_PoHandle);
409}
410
411
412VOID
414 VOID
415 )
416{
417 //
418 // We only support single component and don't
419 // need to set any flags
420 //
421 PoFxActivateComponent(m_PoHandle,
422 0, //component
423 0 //flags
424 );
425}
426
427
428VOID
430 VOID
431 )
432{
433 //
434 // We only support single component and don't
435 // need to set any flags
436 //
437 PoFxIdleComponent(m_PoHandle,
438 0, //component
439 0 //flags
440 );
441}
442
443
444VOID
446 VOID
447 )
448{
449 PoFxReportDevicePoweredOn(m_PoHandle);
450}
451
452
453VOID
455 __in ULONGLONG IdleTimeout
456 )
457{
458 PoFxSetDeviceIdleTimeout(m_PoHandle, IdleTimeout);
459}
460
LONG NTSTATUS
Definition: precomp.h:26
MdDeviceObject __inline GetPhysicalDevice(VOID)
Definition: fxdevice.hpp:228
WDFDEVICE __inline GetHandle(VOID)
Definition: fxdevice.hpp:237
MdDeviceObject __inline GetDeviceObject(VOID)
Definition: fxdevice.hpp:174
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
__inline CfxDevice * GetDevice(VOID)
Definition: fxpackage.hpp:46
VOID PoxActivateComponent(VOID)
VOID PoxReportDevicePoweredOn(VOID)
struct _POX_SETTINGS * GetPowerFrameworkSettings(VOID)
VOID PowerRequiredCallbackWorker(__in BOOLEAN InvokedFromPoxCallback)
static PO_FX_COMPONENT_ACTIVE_CONDITION_CALLBACK ComponentActiveCallback
static PO_FX_COMPONENT_IDLE_CONDITION_CALLBACK ComponentIdleCallback
VOID PoxStartDevicePowerManagement(VOID)
VOID PoxIdleComponent(VOID)
static PO_FX_COMPONENT_IDLE_STATE_CALLBACK StateCallback
VOID PowerNotRequiredCallbackWorker(__in BOOLEAN InvokedFromPoxCallback)
static PO_FX_DEVICE_POWER_REQUIRED_CALLBACK PowerRequiredCallback
VOID PoxUnregisterDevice(VOID)
NTSTATUS PoxRegisterDevice(VOID)
static PO_FX_POWER_CONTROL_CALLBACK PowerControlCallback
VOID PoxSetDeviceIdleTimeout(__in ULONGLONG IdleTimeout)
FxPkgPnp * m_PkgPnp
static PO_FX_DEVICE_POWER_NOT_REQUIRED_CALLBACK PowerNotRequiredCallback
#define __in
Definition: dbghelp.h:35
#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
#define _IRQL_requires_max_(irql)
Definition: driverspecs.h:230
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define ASSERT(a)
Definition: mode.c:44
#define _Function_class_(x)
Definition: ms_sal.h:2946
#define _Out_opt_
Definition: ms_sal.h:346
#define _In_
Definition: ms_sal.h:308
#define _In_reads_bytes_opt_(size)
Definition: ms_sal.h:322
#define _Out_writes_bytes_opt_(size)
Definition: ms_sal.h:351
#define DO_NOTHING()
Definition: mxgeneral.h:32
_In_ UCHAR _In_ ULONG _Out_ PUCHAR _Outptr_result_bytebuffer_ OutBufferLength PVOID * OutBuffer
Definition: scsi.h:4071
#define exit(n)
Definition: config.h:202
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TRACE_LEVEL_VERBOSE
Definition: storswtr.h:30
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
PPO_FX_COMPONENT Component
PPO_FX_COMPONENT_ACTIVE_CONDITION_CALLBACK ComponentActiveConditionCallback
PPO_FX_COMPONENT_IDLE_STATE_CALLBACK ComponentIdleStateCallback
PPO_FX_POWER_CONTROL_CALLBACK PowerControlCallback
PPO_FX_COMPONENT_IDLE_CONDITION_CALLBACK ComponentIdleConditionCallback
ULONGLONG ResidencyRequirement
Definition: potypes.h:568
PPO_FX_COMPONENT_IDLE_CONDITION_CALLBACK ComponentIdleConditionCallback
Definition: potypes.h:585
PPO_FX_COMPONENT_IDLE_STATE_CALLBACK ComponentIdleStateCallback
Definition: potypes.h:586
PPO_FX_DEVICE_POWER_NOT_REQUIRED_CALLBACK DevicePowerNotRequiredCallback
Definition: potypes.h:588
ULONG ComponentCount
Definition: potypes.h:583
PPO_FX_COMPONENT_ACTIVE_CONDITION_CALLBACK ComponentActiveConditionCallback
Definition: potypes.h:584
PVOID DeviceContext
Definition: potypes.h:590
PPO_FX_DEVICE_POWER_REQUIRED_CALLBACK DevicePowerRequiredCallback
Definition: potypes.h:587
PPO_FX_POWER_CONTROL_CALLBACK PowerControlCallback
Definition: potypes.h:589
Definition: ps.c:97
ULONG_PTR * PSIZE_T
Definition: typedefs.h:80
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_ ULONG _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesReturned
Definition: wdfiotarget.h:1052
_In_ ULONG OutBufferSize
Definition: wdfwmi.h:87
_In_ ULONG InBufferSize
Definition: wdfwmi.h:106
_In_ ULONG Component
Definition: potypes.h:496
_In_ LPCGUID PowerControlCode
Definition: potypes.h:545
#define PO_FX_VERSION_V1
Definition: potypes.h:483