ReactOS 0.4.16-dev-1946-g52006dd
supportkm.cpp File Reference
#include "../pnppriv.hpp"
#include <wdmguid.h>
Include dependency graph for supportkm.cpp:

Go to the source code of this file.

Functions

VOID CopyQueryInterfaceToIrpStack (__in PPOWER_THREAD_INTERFACE PowerThreadInterface, __in FxIrp *Irp)
 
_Must_inspect_result_ NTSTATUS NTAPI GetStackCapabilities (__in PFX_DRIVER_GLOBALS DriverGlobals, __in MxDeviceObject *DeviceInStack, __in_opt PD3COLD_SUPPORT_INTERFACE D3ColdInterface, __out PSTACK_DEVICE_CAPABILITIES Capabilities)
 
VOID NTAPI SetD3ColdSupport (__in PFX_DRIVER_GLOBALS DriverGlobals, __in MxDeviceObject *DeviceInStack, __in PD3COLD_SUPPORT_INTERFACE D3ColdInterface, __in BOOLEAN UseD3Cold)
 
_Must_inspect_result_ PVOID GetIoMgrObjectForWorkItemAllocation (VOID)
 
_Must_inspect_result_ NTSTATUS NTAPI SendDeviceUsageNotification (__in MxDeviceObject *RelatedDevice, __inout FxIrp *RelatedIrp, __in MxWorkItem *Workitem, __in FxIrp *OriginalIrp, __in BOOLEAN Revert)
 
NTSTATUS SendDeviceUsageNotificationWorker (__in MxDeviceObject *RelatedDevice, __inout FxIrp *RelatedIrp, __in FxIrp *OriginalIrp, __in BOOLEAN Revert)
 
VOID NTAPI _DeviceUsageNotificationWorkItem (__in MdDeviceObject DeviceObject, __in PVOID Context)
 

Function Documentation

◆ _DeviceUsageNotificationWorkItem()

VOID NTAPI _DeviceUsageNotificationWorkItem ( __in MdDeviceObject  DeviceObject,
__in PVOID  Context 
)

Definition at line 298 of file supportkm.cpp.

302{
305
307
309
311 param->RelatedIrp,
312 param->OriginalIrp,
313 param->Revert);
314
315 //
316 // capture status in notification object
317 //
318 param->Status = status;
319
320 //
321 // set event to allow the origial notifcation thread to proceed
322 //
323 param->Event.Set();
324}
LONG NTSTATUS
Definition: precomp.h:26
GLfloat param
Definition: glext.h:5796
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:329
Definition: ps.c:97
NTSTATUS SendDeviceUsageNotificationWorker(__in MxDeviceObject *RelatedDevice, __inout FxIrp *RelatedIrp, __in FxIrp *OriginalIrp, __in BOOLEAN Revert)
Definition: supportkm.cpp:263
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2061

◆ CopyQueryInterfaceToIrpStack()

VOID CopyQueryInterfaceToIrpStack ( __in PPOWER_THREAD_INTERFACE  PowerThreadInterface,
__in FxIrp Irp 
)

Definition at line 32 of file supportkm.cpp.

36{
38
39 stack = Irp->GetCurrentIrpStackLocation();
40
41 RtlCopyMemory(stack->Parameters.QueryInterface.Interface,
42 PowerThreadInterface,
43 PowerThreadInterface->Interface.Size);
44}
_In_ PIRP Irp
Definition: csq.h:116
Definition: format.c:80
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263

Referenced by FxPkgPnp::HandleQueryInterfaceForPowerThread().

◆ GetIoMgrObjectForWorkItemAllocation()

_Must_inspect_result_ PVOID GetIoMgrObjectForWorkItemAllocation ( VOID  )

Definition at line 191 of file supportkm.cpp.

204{
206}
FxLibraryGlobalsType FxLibraryGlobals
Definition: globals.cpp:95
PDRIVER_OBJECT DriverObject
Definition: fxglobals.h:719

◆ GetStackCapabilities()

_Must_inspect_result_ NTSTATUS NTAPI GetStackCapabilities ( __in PFX_DRIVER_GLOBALS  DriverGlobals,
__in MxDeviceObject DeviceInStack,
__in_opt PD3COLD_SUPPORT_INTERFACE  D3ColdInterface,
__out PSTACK_DEVICE_CAPABILITIES  Capabilities 
)

Definition at line 49 of file supportkm.cpp.

55{
56 ULONG i;
59
61
63
64 //
65 // Normally this would be assigned to a local variable on the stack. Since
66 // query caps iteratively moves down the device's tree until it hits the
67 // root. As such, stack usage is consumed quickly. While this is only one
68 // pointer value we are saving, it does eventually add up on very deep stacks.
69 //
70 DeviceInStack->SetObject(DeviceInStack->GetAttachedDeviceReference());
71 if (DeviceInStack->GetObject() == NULL) {
72 goto Done;
73 }
74
75 irp.SetIrp(FxIrp::AllocateIrp(DeviceInStack->GetStackSize()));
76 if (irp.GetIrp() == NULL) {
77 goto Done;
78 }
79
80 //
81 // Initialize device capabilities.
82 //
84 Capabilities->DeviceCaps.Size = sizeof(DEVICE_CAPABILITIES);
85 Capabilities->DeviceCaps.Version = 1;
86 Capabilities->DeviceCaps.Address = (ULONG) -1;
87 Capabilities->DeviceCaps.UINumber = (ULONG) -1;
88
89 //
90 // Initialize the Irp.
91 //
93
98
99 status = irp.SendIrpSynchronously(DeviceInStack->GetObject());
100
101 if (!NT_SUCCESS(status)) {
103 DriverGlobals, TRACE_LEVEL_ERROR, TRACINGPNP,
104 "Failed to get DEVICE_CAPABILITIES from !devobj %p, %!STATUS!",
105 DeviceInStack->GetObject(), status);
106 goto Done;
107 }
108
109 //
110 // Invoke the D3cold support interface. If present, it will tell
111 // us specifically which D-states will work for generating wake signals
112 // from specific S-states.
113 //
114 // Earlier versions of WDF didn't make this query, so for compatibility,
115 // we only make it now if the driver was built against WDF 1.11 or
116 // later. In truth, this just shifts the failure from initialization
117 // time to run time, because the information that we're presumably
118 // getting from the BIOS with this interrogation is saying that the
119 // code in earlier verisions of WDF would have blindly enabled a device
120 // for wake which simply wasn't capable of generating its wake signal
121 // from the chosen D-state. Thus the device would have been put into
122 // a low power state and then failed to resume in response to its wake
123 // signal.
124 //
125
126 for (i = 0; i <= PowerSystemHibernate; i++) {
127 Capabilities->DeepestWakeableDstate[i] = DeviceWakeDepthMaximum;
128 }
129
130 if (ARGUMENT_PRESENT(D3ColdInterface) &&
131 (D3ColdInterface->GetIdleWakeInfo != NULL) &&
132 DriverGlobals->IsVersionGreaterThanOrEqualTo(1,11)) {
133
134 DEVICE_WAKE_DEPTH deepestWakeableDstate;
135
137
138 //
139 // Failure from D3ColdInterface->GetIdleWakeInfo just means that
140 // the bus drivers didn't have any information beyond what can
141 // gleaned from the older Query-Capabilities code path.
142 //
143 // In specific ACPI terms, ACPI will respond to this function with
144 // success whenever there is an _SxW object (where x is the sleep
145 // state, a value from 0 to 4.)
146 //
147 // PCI will respond to this interface if ACPI doesn't override its
148 // answer and if a parent bus is capable of leaving D0 in S0, and
149 // if the PCI device has
150 status = D3ColdInterface->GetIdleWakeInfo(
151 D3ColdInterface->Context,
153 &deepestWakeableDstate
154 );
155
156 if (NT_SUCCESS(status)) {
157 Capabilities->DeepestWakeableDstate[i] = deepestWakeableDstate;
158 }
159 }
160 }
161
163
164Done:
165 if (DeviceInStack->GetObject() != NULL) {
166 DeviceInStack->DereferenceObject();
167 }
168
169 return status;
170}
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
CHECK_RETURN_IF_USER_MODE NTSTATUS SendIrpSynchronously(__in MdDeviceObject DeviceObject)
Definition: fxirpum.cpp:151
VOID SetMinorFunction(__in UCHAR MinorFunction)
Definition: fxirpum.cpp:967
static _Must_inspect_result_ MdIrp AllocateIrp(_In_ CCHAR StackSize, _In_opt_ FxDevice *Device=NULL)
Definition: fxirpum.cpp:1089
VOID ClearNextStack(VOID)
Definition: fxirpum.cpp:1183
VOID SetMajorFunction(__in UCHAR MajorFunction)
Definition: fxirpum.cpp:905
VOID SetStatus(__in NTSTATUS Status)
Definition: fxirpum.cpp:457
MdIrp GetIrp(VOID)
Definition: fxirpum.cpp:15
MdIrp SetIrp(MdIrp irp)
Definition: fxirpkm.hpp:71
VOID SetParameterDeviceCapabilities(__in PDEVICE_CAPABILITIES DeviceCapabilities)
Definition: fxirpum.cpp:1145
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
#define TRACINGPNP
Definition: dbgtrace.h:67
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
FxIrp * irp
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Must_inspect_result_ typedef _Out_ PHIDP_CAPS Capabilities
Definition: hidclass.h:103
#define ASSERT(a)
Definition: mode.c:44
#define ARGUMENT_PRESENT(ArgumentPointer)
@ PowerSystemWorking
Definition: ntpoapi.h:36
@ PowerSystemHibernate
Definition: ntpoapi.h:40
enum _SYSTEM_POWER_STATE SYSTEM_POWER_STATE
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
enum _DEVICE_WAKE_DEPTH DEVICE_WAKE_DEPTH
DEVICE_CAPABILITIES
Definition: iotypes.h:965
#define IRP_MN_QUERY_CAPABILITIES
@ DeviceWakeDepthMaximum
Definition: iotypes.h:7488

Referenced by FxPkgPdo::_QueryCapsWorkItem(), FxPkgPdo::PnpQueryCapabilities(), and FxPkgPnp::QueryForCapabilities().

◆ SendDeviceUsageNotification()

_Must_inspect_result_ NTSTATUS NTAPI SendDeviceUsageNotification ( __in MxDeviceObject RelatedDevice,
__inout FxIrp RelatedIrp,
__in MxWorkItem Workitem,
__in FxIrp OriginalIrp,
__in BOOLEAN  Revert 
)

Definition at line 219 of file supportkm.cpp.

226{
228
229 //
230 // use workitem if available
231 //
232 if (Workitem->GetWorkItem() != NULL) {
234
235 param.RelatedDevice = RelatedDevice;
236 param.RelatedIrp = RelatedIrp;
237 param.OriginalIrp = OriginalIrp;
238 param.Revert = Revert;
239
240 //
241 // Kick off to another thread
242 //
243 Workitem->Enqueue(_DeviceUsageNotificationWorkItem, &param);
244
245 //
246 // wait for the workitem to finish
247 //
248 param.Event.EnterCRAndWaitAndLeave();
249
250 status = param.Status;
251 }
252 else {
254 RelatedIrp,
256 Revert);
257 }
258
259 return status;
260}
_In_ PTRANSFER_PACKET _In_ ULONG _In_ PIRP OriginalIrp
Definition: classp.h:1757
IO_WORKITEM_ROUTINE _DeviceUsageNotificationWorkItem
Definition: pnpprivkm.hpp:75

Referenced by FxPkgPnp::PnpDeviceUsageNotification().

◆ SendDeviceUsageNotificationWorker()

NTSTATUS SendDeviceUsageNotificationWorker ( __in MxDeviceObject RelatedDevice,
__inout FxIrp RelatedIrp,
__in FxIrp OriginalIrp,
__in BOOLEAN  Revert 
)

Definition at line 263 of file supportkm.cpp.

269{
270 MxDeviceObject relatedTopOfStack;
272
273 relatedTopOfStack.SetObject(RelatedDevice->GetAttachedDeviceReference());
274 ASSERT(relatedTopOfStack.GetObject() != NULL);
275
276 //
277 // Initialize the new IRP with the stack data from the current IRP and
278 // and send it to the parent stack.
279 //
280 RelatedIrp->InitNextStackUsingStack(OriginalIrp);
281
282 if (Revert) {
283 RelatedIrp->SetParameterUsageNotificationInPath(
284 !RelatedIrp->GetNextStackParameterUsageNotificationInPath());
285 }
286
287 RelatedIrp->SetStatus(STATUS_NOT_SUPPORTED);
288
289 status = RelatedIrp->SendIrpSynchronously(relatedTopOfStack.GetObject());
290
291 relatedTopOfStack.DereferenceObject();
292
293 return status;
294}
__inline VOID SetObject(__in_opt MdDeviceObject DeviceObject)
VOID DereferenceObject()
__inline MdDeviceObject GetObject(VOID)

Referenced by _DeviceUsageNotificationWorkItem(), and SendDeviceUsageNotification().

◆ SetD3ColdSupport()

VOID NTAPI SetD3ColdSupport ( __in PFX_DRIVER_GLOBALS  DriverGlobals,
__in MxDeviceObject DeviceInStack,
__in PD3COLD_SUPPORT_INTERFACE  D3ColdInterface,
__in BOOLEAN  UseD3Cold 
)

Definition at line 174 of file supportkm.cpp.

180{
181 UNREFERENCED_PARAMETER(DriverGlobals);
182 UNREFERENCED_PARAMETER(DeviceInStack);
183
184 if (D3ColdInterface->SetD3ColdSupport != NULL) {
185 D3ColdInterface->SetD3ColdSupport(D3ColdInterface->Context, UseD3Cold);
186 }
187}

Referenced by FxPkgPnp::PowerPolicySetS0IdleSettings().