ReactOS  0.4.15-dev-2985-g54406bf
fxpkgpnpum.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 
9 extern "C" {
10 #if defined(EVENT_TRACING)
11 #include "FxPkgPnpUM.tmh"
12 #endif
13 }
14 
18  )
19 {
20  UNREFERENCED_PARAMETER(IoList);
21  ASSERTMSG("Not implemented for UMDF\n", FALSE);
22 
24 }
25 
29  VOID
30  )
31 {
32  ASSERTMSG("Not implemented for UMDF\n", FALSE);
33 
35 }
36 
37 VOID
39  __in FxDmaEnabler* Enabler
40  )
41 {
42  UNREFERENCED_PARAMETER(Enabler);
43  ASSERTMSG("Not implemented for UMDF\n", FALSE);
44 }
45 
46 VOID
48  __in FxDmaEnabler* Enabler
49  )
50 {
51  UNREFERENCED_PARAMETER(Enabler);
52  ASSERTMSG("Not implemented for UMDF\n", FALSE);
53 }
54 
58  _In_ BOOLEAN ForS0Idle
59  )
60 {
61  HRESULT hr;
63  IWudfDeviceStack* devStack;
64  WmiIdleWakeInstanceUpdate updateType;
65 
66  devStack = m_Device->GetDeviceStack();
67 
68  ASSERT(Action != InstanceActionInvalid);
69 
70  if (Action == AddInstance) {
71  updateType = ForS0Idle ? AddS0IdleInstance : AddSxWakeInstance;
72  } else {
73  updateType = ForS0Idle ? RemoveS0IdleInstance : RemoveSxWakeInstance;
74  }
75 
76  hr = devStack->UpdateIdleWakeWmiInstance(updateType);
77  if (S_OK == hr) {
79  }
80  else {
81  PUMDF_VERSION_DATA driverVersion = devStack->GetMinDriverVersion();
82  BOOL preserveCompat =
83  devStack->ShouldPreserveIrpCompletionStatusCompatibility();
84 
85  status = CHostFxUtil::NtStatusFromHr(hr,
86  driverVersion->MajorNumber,
87  driverVersion->MinorNumber,
88  preserveCompat);
89  }
90 
91  if (!NT_SUCCESS(status)) {
94  TRACINGPNP,
95  "failed to send ioctl to update %s WMI instance "
96  "%!STATUS!",
97  ForS0Idle ? "S0Idle" : "SxWake",
98  status);
99  }
100 
101  return status;
102 }
103 
104 NTSTATUS
108  )
109 {
110  DWORD err;
112  DWORD data;
113  DWORD dataSize;
114  HKEY pwrPolKey = NULL;
115  IWudfDeviceStack* devStack;
116 
117  ASSERT(NULL != Value);
118  ASSERT(ValueName != NULL &&
119  ValueName->Length != 0 &&
120  ValueName->Buffer != NULL);
121 
122  *Value = 0;
123  devStack = m_Device->GetDeviceStack();
124 
125  err = RegOpenKeyEx(devStack->GetDeviceRegistryKey(),
127  0,
128  KEY_READ,
129  &pwrPolKey);
130  if (ERROR_SUCCESS != err) {
133  TRACINGPNP,
134  "RegOpenKeyEx returned error %d",
135  err);
136  goto Clean;
137  }
138 
139  dataSize = sizeof(data);
140  err = RegQueryValueEx(pwrPolKey,
141  ValueName->Buffer,
142  NULL,
143  NULL,
144  (BYTE*) &data,
145  &dataSize);
146  if (ERROR_SUCCESS != err) {
149  TRACINGPNP,
150  "failed to read registry, "
151  "RegQueryValueEx returned error %d",
152  err);
153  goto Clean;
154  }
155 
156  *Value = data;
157  err = ERROR_SUCCESS;
158 
159 Clean:
160  if (NULL != pwrPolKey) {
161  RegCloseKey(pwrPolKey);
162  }
163 
164  if (ERROR_SUCCESS == err) {
166  }
167  else {
168  PUMDF_VERSION_DATA driverVersion = devStack->GetMinDriverVersion();
169  BOOL preserveCompat =
170  devStack->ShouldPreserveIrpCompletionStatusCompatibility();
171 
172  status = CHostFxUtil::NtStatusFromHr(HRESULT_FROM_WIN32(err),
173  driverVersion->MajorNumber,
174  driverVersion->MinorNumber,
175  preserveCompat);
176  }
177 
178  return status;
179 }
180 
181 VOID
183  __in HANDLE RegKey,
186  )
187 {
188  DWORD err;
189  HRESULT hr;
190  HKEY hKey = NULL;
191  IWudfDeviceStack* devStack;
192  UMINT::WDF_PROPERTY_STORE_ROOT propertyStore;
193 
194  UNREFERENCED_PARAMETER(RegKey);
195 
196  ASSERT(ValueName != NULL &&
197  ValueName->Length != 0 &&
198  ValueName->Buffer != NULL);
199 
200  devStack = m_Device->GetDeviceStack();
201 
202  propertyStore.LengthCb = sizeof(UMINT::WDF_PROPERTY_STORE_ROOT);
203  propertyStore.RootClass = UMINT::WdfPropertyStoreRootClassHardwareKey;
204  propertyStore.Qualifier.HardwareKey.ServiceName = WUDF_POWER_POLICY_SETTINGS;
205 
206  hr = devStack->CreateRegistryEntry(&propertyStore,
207  UMINT::WdfPropertyStoreCreateIfMissing,
209  NULL,
210  &hKey,
211  NULL);
212  if (FAILED(hr)) {
213  goto Clean;
214  }
215 
216  //
217  // Failure to save the user's idle/wake settings is not critical and we
218  // will continue on regardless. Hence we ignore the return value.
219  //
221  ValueName->Buffer,
222  0,
223  REG_DWORD,
224  (BYTE *) &Value,
225  sizeof(Value));
226  if (err != ERROR_SUCCESS) {
229  TRACINGPNP,
230  "Failed to set Registry value "
231  "for S0Idle/SxWake error %d",
232  err);
233  goto Clean;
234  }
235 
236 Clean:
237  if (NULL != hKey) {
238  RegCloseKey(hKey);
239  }
240 }
241 
242 NTSTATUS
245  )
246 {
248 
249  //
250  // Send an IOCTL to redirector
251  // to add/remove S0Idle WMI instance.
252  //
254 
255  return status;
256 }
257 
258 VOID
262  )
263 {
265  ULONG value;
266 
268 
269  //
270  // Modify value of Enabled only if success
271  //
272  if (NT_SUCCESS(status)) {
273  //
274  // Normalize the ULONG value into a BOOLEAN
275  //
276  *Enabled = (value == FALSE) ? FALSE : TRUE;
277  }
278 }
279 
280 NTSTATUS
283  )
284 {
286 
287  //
288  // Send an IOCTL to redirector
289  // to add/remove SxWake WMI instance.
290  //
292 
293  return status;
294 }
295 
296 VOID
300  )
301 {
303  ULONG value;
304 
306 
307  //
308  // Modify value of Enabled only if success
309  //
310  if (NT_SUCCESS(status)) {
311  //
312  // Normalize the ULONG value into a BOOLEAN
313  //
314  *Enabled = (value == FALSE) ? FALSE : TRUE;
315  }
316 }
317 
318 VOID
321  __inout FxIrp* Irp,
322  __inout FxIrp* ForwardIrp
323  )
324 {
327  UNREFERENCED_PARAMETER(ForwardIrp);
328  ASSERTMSG("Not implemented for UMDF\n", FALSE);
329 }
330 
331 
332 VOID
334  __in FxDmaEnabler * /* DmaEnabler */
335  )
336 {
337  // Do nothing
338 }
339 
#define RegQueryValueEx
Definition: winreg.h:524
CfxDevice * m_Device
Definition: fxobject.hpp:329
Definition: pdh_main.c:93
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
#define ERROR_SUCCESS
Definition: deptool.c:10
HRESULT hr
Definition: shlfolder.c:183
#define KEY_SET_VALUE
Definition: nt_native.h:1017
NTSTATUS FilterResourceRequirements(__in IO_RESOURCE_REQUIREMENTS_LIST **IoList)
Definition: fxpkgpnpkm.cpp:16
#define _Out_
Definition: ms_sal.h:345
#define KEY_READ
Definition: nt_native.h:1023
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
NTSTATUS UpdateWmiInstance(_In_ FxWmiInstanceAction Action, _In_ BOOLEAN ForS0Idle)
Definition: fxpkgpnpum.cpp:56
LONG NTSTATUS
Definition: precomp.h:26
VOID WriteStateToRegistry(__in HANDLE RegKey, __in PUNICODE_STRING ValueName, __in ULONG Value)
Definition: fxpkgpnpkm.cpp:301
Definition: fxirp.hpp:28
VOID RevokeDmaEnablerResources(__in FxDmaEnabler *Enabler)
Definition: fxpkgpnpkm.cpp:529
VOID AddDmaEnabler(__in FxDmaEnabler *Enabler)
Definition: fxpkgpnpkm.cpp:277
return STATUS_NOT_IMPLEMENTED
VOID PnpPassThroughQIWorker(__in MxDeviceObject *Device, __inout FxIrp *Irp, __inout FxIrp *ForwardIrp)
Definition: fxpkgpnpum.cpp:319
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ASSERTMSG(msg, exp)
Definition: nt_native.h:431
#define __out
Definition: dbghelp.h:62
unsigned char BOOLEAN
#define _In_
Definition: ms_sal.h:308
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:406
IWudfDeviceStack * GetDeviceStack(VOID)
Definition: fxdeviceum.hpp:435
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
LONG HRESULT
Definition: typedefs.h:79
VOID RemoveDmaEnabler(__in FxDmaEnabler *Enabler)
Definition: fxpkgpnpkm.cpp:289
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:240
NTSTATUS ReadStateFromRegistry(_In_ PCUNICODE_STRING ValueName, _Out_ PULONG Value)
Definition: fxpkgpnpum.cpp:105
NTSTATUS UpdateWmiInstanceForSxWake(__in FxWmiInstanceAction Action)
Definition: fxpkgpnpum.cpp:281
#define __inout
Definition: dbghelp.h:50
GLsizei const GLfloat * value
Definition: glext.h:6069
#define err(...)
#define _Must_inspect_result_
Definition: ms_sal.h:558
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474
unsigned char BYTE
Definition: xxhash.c:193
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
#define TRACINGPNP
Definition: dbgtrace.h:67
#define S_OK
Definition: intsafe.h:52
#define RegOpenKeyEx
Definition: winreg.h:520
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
_In_ WDFIOTARGET _In_ _Strict_type_match_ WDF_IO_TARGET_SENT_IO_ACTION Action
Definition: wdfiotarget.h:506
FxAutoRegKey hKey
FxWmiInstanceAction
Definition: fxpkgpnp.hpp:428
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
VOID ReadRegistryS0Idle(__in PCUNICODE_STRING ValueName, __out BOOLEAN *Enabled)
Definition: fxpkgpnpkm.cpp:376
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
unsigned int * PULONG
Definition: retypes.h:1
#define NULL
Definition: types.h:112
GLenum GLsizei dataSize
Definition: glext.h:11123
NTSTATUS UpdateWmiInstanceForS0Idle(__in FxWmiInstanceAction Action)
Definition: fxpkgpnpum.cpp:243
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
#define __in
Definition: dbghelp.h:35
#define REG_DWORD
Definition: sdbapi.c:596
static SERVICE_STATUS status
Definition: service.c:31
_Must_inspect_result_ NTSTATUS AllocateDmaEnablerList(VOID)
Definition: fxpkgpnpkm.cpp:241
#define RegSetValueEx
Definition: winreg.h:533
VOID ReadRegistrySxWake(__in PCUNICODE_STRING ValueName, __out BOOLEAN *Enabled)
Definition: fxpkgpnpkm.cpp:469
#define WUDF_POWER_POLICY_SETTINGS
Definition: device_common.h:45
Definition: ps.c:97