9c1338963a35c1329874443004bc00b9df6863d7
[reactos.git] / reactos / drivers / wdm / audio / backpln / portcls / power.c
1 #include "private.h"
2
3 const GUID IID_IAdapterPowerManagement;
4
5 /*
6 * @implemented
7 */
8
9 NTSTATUS
10 NTAPI
11 PcRegisterAdapterPowerManagement(
12 IN PUNKNOWN pUnknown,
13 IN PVOID pvContext)
14 {
15 NTSTATUS Status;
16 PDEVICE_OBJECT pDeviceObject;
17 PCExtension* DeviceExt;
18 IAdapterPowerManagement * pPower;
19
20 if (!pUnknown || !pvContext)
21 return STATUS_INVALID_PARAMETER;
22
23 Status = pUnknown->lpVtbl->QueryInterface(pUnknown, &IID_IAdapterPowerManagement, (PVOID*)&pPower);
24 if (!NT_SUCCESS(Status))
25 return Status;
26
27 pDeviceObject = (PDEVICE_OBJECT)pvContext;
28 DeviceExt = (PCExtension*)pDeviceObject->DeviceExtension;
29
30 if (DeviceExt->AdapterPowerManagement)
31 {
32 pPower->lpVtbl->Release(pPower);
33 return STATUS_UNSUCCESSFUL;
34 }
35
36 DeviceExt->AdapterPowerManagement = pPower;
37 return STATUS_SUCCESS;
38 }
39
40
41 static
42 VOID
43 NTAPI
44 PwrCompletionCallback(
45 IN PDEVICE_OBJECT DeviceObject,
46 IN UCHAR MinorFunction,
47 IN POWER_STATE PowerState,
48 IN PVOID Context,
49 IN PIO_STATUS_BLOCK IoStatus)
50 {
51 KeSetEvent((PRKEVENT)Context, IO_NO_INCREMENT, FALSE);
52 }
53
54 /*
55 * @implemented
56 */
57 NTSTATUS NTAPI
58 PcRequestNewPowerState(
59 IN PDEVICE_OBJECT DeviceObject,
60 IN DEVICE_POWER_STATE RequestedNewState)
61 {
62 KEVENT Event;
63 NTSTATUS Status;
64 POWER_STATE PowerState;
65 PCExtension* DeviceExt;
66
67 if (!DeviceObject || !RequestedNewState)
68 return STATUS_INVALID_PARAMETER;
69
70 DeviceExt = (PCExtension*)DeviceObject->DeviceExtension;
71 KeInitializeEvent(&Event, SynchronizationEvent, FALSE);
72
73 PowerState.DeviceState = RequestedNewState;
74 PowerState.SystemState = PowerSystemUnspecified;
75
76 Status = PoRequestPowerIrp(DeviceExt->PhysicalDeviceObject, IRP_MN_SET_POWER, PowerState, PwrCompletionCallback, (PVOID)&Event, NULL);
77 if (NT_SUCCESS(Status))
78 {
79 KeWaitForSingleObject((PVOID)&Event, Executive, KernelMode, FALSE, NULL);
80 }
81
82
83 return Status;
84 }
85