1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
|
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
Module Name:
pep.c
Abstract:
This module implements PEP registration.
Environment:
Kernel Mode
--*/
//
//-------------------------------------------------------------------- Includes
//
#include "pch.h"
#include <initguid.h>
#if defined(EVENT_TRACING)
#include "pep.tmh"
#endif
//
//------------------------------------------------------------------- Globals
//
PEP_KERNEL_INFORMATION PepKernelInformation;
LIST_ENTRY PepCompletedWorkList;
LIST_ENTRY PepDeviceList;
KSPIN_LOCK PepGlobalSpinLock;
LIST_ENTRY PepPendingWorkList;
BOOLEAN PepRegistered = FALSE;
WDFSPINLOCK PepWorkListLock;
//
// Define the default ACPI notification handlers.
//
PEP_GENERAL_NOTIFICATION_HANDLER PepAcpiNotificationHandlers[] = {
{0, NULL, "UNKNOWN"},
{PEP_NOTIFY_ACPI_PREPARE_DEVICE,
PepAcpiPrepareDevice,
"PEP_ACPI_PREPARE_DEVICE"},
{PEP_NOTIFY_ACPI_ABANDON_DEVICE,
PepAcpiAbandonDevice,
"PEP_ACPI_ABANDON_DEVICE"},
{PEP_NOTIFY_ACPI_REGISTER_DEVICE,
PepAcpiRegisterDevice,
"PEP_ACPI_REGISTER_DEVICE"},
{PEP_NOTIFY_ACPI_UNREGISTER_DEVICE,
PepAcpiUnregisterDevice,
"PEP_ACPI_UNREGISTER_DEVICE"},
{PEP_NOTIFY_ACPI_ENUMERATE_DEVICE_NAMESPACE,
PepAcpiEnumerateDeviceNamespace,
"PEP_ACPI_ENUMERATE_DEVICE_NAMESPACE"},
{PEP_NOTIFY_ACPI_QUERY_OBJECT_INFORMATION,
PepAcpiQueryObjectInformation,
"PEP_ACPI_QUERY_OBJECT_INFORMATION"},
{PEP_NOTIFY_ACPI_EVALUATE_CONTROL_METHOD,
PepAcpiEvaluateControlMethod,
"PEP_ACPI_EVALUATE_CONTROL_METHOD"},
{PEP_NOTIFY_ACPI_QUERY_DEVICE_CONTROL_RESOURCES,
PepAcpiQueryDeviceControlResources,
"PEP_ACPI_QUERY_DEVICE_CONTROL_RESOURCES"},
{PEP_NOTIFY_ACPI_TRANSLATED_DEVICE_CONTROL_RESOURCES,
PepAcpiTranslatedDeviceControlResources,
"PEP_ACPI_TRANSLATED_DEVICE_CONTROL_RESOURCES"},
{PEP_NOTIFY_ACPI_WORK,
PepAcpiWorkNotification,
"PEP_ACPI_WORK"}
};
PEP_GENERAL_NOTIFICATION_HANDLER PepDpmNotificationHandlers[] = {
{0, NULL, "UNKNOWN"},
};
//
//--------------------------------------------------------------------- Pragmas
//
#pragma alloc_text(INIT, PepRegister)
#pragma alloc_text(INIT, PepInitialize)
//
//------------------------------------------------------------------- Functions
//
NTSTATUS
PepRegister (
_In_ BOOLEAN AcpiHandlerOptIn,
_In_ BOOLEAN DpmHandlerOptIn,
_In_ BOOLEAN PpmHandlerOptIn
)
/*++
Routine Description:
This routine registers as a power engine plugin with the OS.
Arguments:
AcpiHandlerOptIn - Indicates whether the PEP handles ACPI notification.
DpmHandlerOptIn - Indicates whether the DPM handles ACPI notification.
PpmHandlerOptIn - Indicates whether the PPM handles ACPI notification.
Return Value:
NTSTATUS.
--*/
{
PEP_INFORMATION PepInformation;
NTSTATUS Status;
RtlZeroMemory(&PepInformation, sizeof(PepInformation));
PepInformation.Version = PEP_INFORMATION_VERSION;
PepInformation.Size = sizeof(PepInformation);
if (AcpiHandlerOptIn != FALSE) {
PepInformation.AcceptAcpiNotification = PepAcpiNotify;
}
if (DpmHandlerOptIn != FALSE) {
PepInformation.AcceptDeviceNotification = PepDpmNotify;
}
if (PpmHandlerOptIn != FALSE) {
PepInformation.AcceptProcessorNotification = PepPpmNotify;
}
RtlZeroMemory(&PepKernelInformation, sizeof(PepKernelInformation));
PepKernelInformation.Version = PEP_KERNEL_INFORMATION_V3;
PepKernelInformation.Size = sizeof(PepKernelInformation);
Status = PoFxRegisterPlugin(&PepInformation, &PepKernelInformation);
if (!NT_SUCCESS(Status)) {
TraceEvents(ERROR,
DBG_INIT,
"%s: PoFxRegisterPlugin() Failed! Status = %!STATUS!.\n",
__FUNCTION__,
Status);
goto RegisterEnd;
}
NT_ASSERT(PepKernelInformation.Plugin != NULL);
NT_ASSERT(PepKernelInformation.RequestWorker != NULL);
RegisterEnd:
return Status;
}
NTSTATUS
PepInitialize (
_In_ PDRIVER_OBJECT WdmDriverObject,
_In_ WDFDRIVER WdfDriver,
_In_ PUNICODE_STRING RegistryPath
)
/*++
Routine Description:
This routine performs initialization operations.
Arguments:
WdmDriverObject - Supplies a pointer to the WDM driver object.
WdfDriver - Supplies a handle to the WDF driver object.
RegistryPath - Supplies a pointer to the driver specific registry key.
Return Value:
NTSTATUS.
--*/
{
BOOLEAN AcpiOptin;
BOOLEAN DpmOptin;
WDF_OBJECT_ATTRIBUTES ObjectAttributes;
BOOLEAN PpmOptin;
NTSTATUS Status;
KeInitializeSpinLock(&PepGlobalSpinLock);
InitializeListHead(&PepDeviceList);
InitializeListHead(&PepPendingWorkList);
InitializeListHead(&PepCompletedWorkList);
//
// Create the spin-lock that is used to synchronize state during device
// powering down.
//
WDF_OBJECT_ATTRIBUTES_INIT(&ObjectAttributes);
Status = WdfSpinLockCreate(&ObjectAttributes, &PepWorkListLock);
if (!NT_SUCCESS(Status)) {
TraceEvents(ERROR,
DBG_INIT,
"%s: WdfSpinLockCreate() Failed! Status = %!STATUS!.\n",
__FUNCTION__,
Status);
goto InitializeEnd;
}
//
// Query the registry for flags. This registry flag may not be present
// and thus a failure is not treated as fatal.
//
AcpiOptin = FALSE;
DpmOptin = FALSE;
PpmOptin = FALSE;
PepQueryRegisterOptions(WdmDriverObject,
WdfDriver,
RegistryPath,
&AcpiOptin,
&DpmOptin,
&PpmOptin);
//
// The default behavior is to handle Acpi.
//
if ((AcpiOptin == FALSE) &&
(DpmOptin == FALSE) &&
(PpmOptin == FALSE)) {
AcpiOptin = TRUE;
}
Status = PepRegister(AcpiOptin, DpmOptin, PpmOptin);
if (!NT_SUCCESS(Status)) {
TraceEvents(ERROR,
DBG_INIT,
"%s: PepRegister() Failed! Status = %!STATUS!.\n",
__FUNCTION__,
Status);
} else {
PepRegistered = TRUE;
}
InitializeEnd:
return Status;
}
__drv_requiresIRQL(PASSIVE_LEVEL)
VOID
PepQueryRegisterOptions (
_In_ PDRIVER_OBJECT WdmDriverObject,
_In_ WDFDRIVER WdfDriver,
_In_ PUNICODE_STRING RegistryPath,
_Out_ PBOOLEAN PepAcpiOptin,
_Out_ PBOOLEAN PepDpmOptin,
_Out_ PBOOLEAN PepPpmOptin
)
/*++
Routine Description:
This routine queries options/flags set in the registry and intializes
respective variables.
Arguments:
WdmDriverObject - Supplies a pointer to the WDM driver object.
WdfDriver - Supplies a handle to the WDF driver object.
RegistryPath - Supplies a pointer to the driver specific registry key.
PepAcpiOptin - Supplies a pointer that receives whether ACPI opt-in
is enabled.
PepDpmOptin - Supplies a pointer that receives whether DPM opt-in
is enabled.
PepPpmOptin - Supplies a pointer that receives whether PPM opt-in
is enabled.
Return Value:
None.
--*/
{
DECLARE_CONST_UNICODE_STRING(Key, PEP_REGISTRY_OPTIN_KEY);
ULONG Flag;
NTSTATUS Status;
PAGED_CODE();
UNREFERENCED_PARAMETER(WdmDriverObject);
*PepAcpiOptin = FALSE;
*PepDpmOptin = FALSE;
*PepPpmOptin = FALSE;
//
// Check whether ACPI/DPM/PPM opt-in is enabled.
//
Flag = 0x0;
Status = PepQueryRegistry(NULL, WdfDriver, RegistryPath, &Key, &Flag);
if (NT_SUCCESS(Status)) {
if (CHECK_FLAG(Flag, PEP_REGISTRY_OPTIN_KEY_ACPI_MASK)) {
*PepAcpiOptin = TRUE;
}
if (CHECK_FLAG(Flag, PEP_REGISTRY_OPTIN_KEY_DPM_MASK)) {
*PepDpmOptin = TRUE;
}
if (CHECK_FLAG(Flag, PEP_REGISTRY_OPTIN_KEY_PPM_MASK)) {
*PepPpmOptin = TRUE;
}
}
return;
}
BOOLEAN
PepDpmNotify (
_In_ ULONG Notification,
_In_ PVOID Data
)
/*++
Routine Description:
Handles all incoming DPM notifications from the OS.
Arguments:
Notification - Supplies the notification type.
Data - Supplies a pointer to a data structure specific to the
notification type.
Return Value:
TRUE if the notification type was recognized;
FALSE otherwise.
--*/
{
BOOLEAN Recognized;
Recognized = FALSE;
if (Notification >= ARRAYSIZE(PepDpmNotificationHandlers)) {
goto DpmNotifyEnd;
}
if ((PepDpmNotificationHandlers[Notification].Notification == 0) ||
(PepDpmNotificationHandlers[Notification].Handler == NULL)) {
goto DpmNotifyEnd;
}
PepDpmNotificationHandlers[Notification].Handler(Data);
Recognized = TRUE;
DpmNotifyEnd:
return Recognized;
}
BOOLEAN
PepAcpiNotify (
_In_ ULONG Notification,
_In_ PVOID Data
)
/*++
Routine Description:
Handles all incoming ACPI notifications from the OS.
Arguments:
Notification - Supplies the notification type.
Data - Supplies a pointer to a data structure specific to the
notification type.
Return Value:
TRUE if the notification type was recognized;
FALSE otherwise.
--*/
{
BOOLEAN Recognized;
Recognized = FALSE;
if (Notification >= ARRAYSIZE(PepAcpiNotificationHandlers)) {
goto AcpiNotifyEnd;
}
if ((PepAcpiNotificationHandlers[Notification].Notification == 0) ||
(PepAcpiNotificationHandlers[Notification].Handler == NULL)) {
goto AcpiNotifyEnd;
}
PepAcpiNotificationHandlers[Notification].Handler(Data);
Recognized = TRUE;
AcpiNotifyEnd:
return Recognized;
}
BOOLEAN
PepPpmNotify (
_In_ PEPHANDLE Handle,
_In_ ULONG Notification,
_Inout_opt_ PVOID Data
)
/*++
Routine Description:
Handles all incoming PPM notifications from the OS. Will be implemented
in the future.
Arguments:
Notification - Supplies the notification type.
Data - Supplies a pointer to a data structure specific to the
notification type.
Return Value:
Returns TRUE if the notification type was recognized;
FALSE otherwise.
--*/
{
UNREFERENCED_PARAMETER(Handle);
UNREFERENCED_PARAMETER(Notification);
UNREFERENCED_PARAMETER(Data);
//
// Not implemented.
//
NT_ASSERT(FALSE);
return FALSE;
}
|