ReactOS 0.4.15-dev-8096-ga0eec98
power.c
Go to the documentation of this file.
1#include "precomp.h"
2
3#define NDEBUG
4#include <debug.h>
5
10 PIRP Irp
11 )
12{
13 PIO_STACK_LOCATION irpStack;
15 PCOMMON_DEVICE_DATA commonData;
16
19 ASSERT (IRP_MJ_POWER == irpStack->MajorFunction);
20
21 commonData = (PCOMMON_DEVICE_DATA) DeviceObject->DeviceExtension;
22
23 if (commonData->IsFDO) {
24
25 DPRINT("FDO %s IRP:0x%p %s %s\n",
29
30
32 Irp);
33 } else {
34
35 DPRINT("PDO %s IRP:0x%p %s %s\n",
39
41 Irp);
42 }
43
44 return status;
45}
46
47
51 PIRP Irp
52 )
53{
55 POWER_STATE powerState;
56 POWER_STATE_TYPE powerType;
58 ULONG AcpiState;
59 ACPI_STATUS AcpiStatus;
60 SYSTEM_POWER_STATE oldPowerState;
61
63 powerType = stack->Parameters.Power.Type;
64 powerState = stack->Parameters.Power.State;
65
66
67 if (stack->MinorFunction == IRP_MN_SET_POWER) {
68 DPRINT("\tRequest to set %s state to %s\n",
69 ((powerType == SystemPowerState) ? "System" : "Device"),
70 ((powerType == SystemPowerState) ? \
73
74 if (powerType == SystemPowerState)
75 {
76 switch (powerState.SystemState) {
78 AcpiState = ACPI_STATE_S1;
79 break;
81 AcpiState = ACPI_STATE_S2;
82 break;
84 AcpiState = ACPI_STATE_S3;
85 break;
87 AcpiState = ACPI_STATE_S4;
88 break;
90 AcpiState = ACPI_STATE_S5;
91 break;
92 default:
93 AcpiState = ACPI_STATE_UNKNOWN;
95 break;
96 }
97 oldPowerState = Data->Common.SystemPowerState;
98 Data->Common.SystemPowerState = powerState.SystemState;
99 AcpiStatus = acpi_suspend(AcpiState);
100 if (!ACPI_SUCCESS(AcpiStatus)) {
101 DPRINT1("Failed to enter sleep state %d (Status 0x%X)\n",
102 AcpiState, AcpiStatus);
103 Data->Common.SystemPowerState = oldPowerState;
105 }
106 }
107 }
110 status = PoCallDriver (Data->NextLowerDriver, Irp);
111 return status;
112}
113
114
117 PPDO_DEVICE_DATA PdoData,
118 PIRP Irp
119 )
120{
123 POWER_STATE powerState;
124 POWER_STATE_TYPE powerType;
125 ULONG error;
126
128 powerType = stack->Parameters.Power.Type;
129 powerState = stack->Parameters.Power.State;
130
131 switch (stack->MinorFunction) {
132 case IRP_MN_SET_POWER:
133
134 DPRINT("\tSetting %s power state to %s\n",
135 ((powerType == SystemPowerState) ? "System" : "Device"),
136 ((powerType == SystemPowerState) ? \
137 DbgSystemPowerString(powerState.SystemState) : \
138 DbgDevicePowerString(powerState.DeviceState)));
139
140 switch (powerType) {
141 case DevicePowerState:
142 if (!PdoData->AcpiHandle || !acpi_bus_power_manageable(PdoData->AcpiHandle))
143 {
144 PoSetPowerState(PdoData->Common.Self, DevicePowerState, powerState);
145 PdoData->Common.DevicePowerState = powerState.DeviceState;
147 break;
148 }
149
150 switch (powerState.DeviceState)
151 {
152 case PowerDeviceD0:
154 break;
155
156 case PowerDeviceD1:
158 break;
159
160 case PowerDeviceD2:
162 break;
163
164 case PowerDeviceD3:
166 break;
167
168 default:
169 error = 0;
170 break;
171 }
172
173 if (ACPI_SUCCESS(error))
174 {
175 PoSetPowerState(PdoData->Common.Self, DevicePowerState, powerState);
176 PdoData->Common.DevicePowerState = powerState.DeviceState;
178 }
179 else
181 break;
182
183 case SystemPowerState:
184 PdoData->Common.SystemPowerState = powerState.SystemState;
186 break;
187
188 default:
190 break;
191 }
192 break;
193
196 break;
197
198 case IRP_MN_WAIT_WAKE:
199 //
200 // We cannot support wait-wake because we are root-enumerated
201 // driver, and our parent, the PnP manager, doesn't support wait-wake.
202 //
204 default:
206 break;
207 }
208
210
211 Irp->IoStatus.Status = status;
212 }
213
215 status = Irp->IoStatus.Status;
217
218 return status;
219}
220
221#if !defined(NDEBUG) || defined(_MSC_VER)
222
223PCHAR
226)
227{
228 switch (MinorFunction)
229 {
230 case IRP_MN_SET_POWER:
231 return "IRP_MN_SET_POWER";
233 return "IRP_MN_QUERY_POWER";
235 return "IRP_MN_POWER_SEQUENCE";
236 case IRP_MN_WAIT_WAKE:
237 return "IRP_MN_WAIT_WAKE";
238
239 default:
240 return "unknown_power_irp";
241 }
242}
243
244PCHAR
247 )
248{
249 switch (Type)
250 {
252 return "PowerSystemUnspecified";
254 return "PowerSystemWorking";
256 return "PowerSystemSleeping1";
258 return "PowerSystemSleeping2";
260 return "PowerSystemSleeping3";
262 return "PowerSystemHibernate";
264 return "PowerSystemShutdown";
266 return "PowerSystemMaximum";
267 default:
268 return "UnKnown System Power State";
269 }
270 }
271
272PCHAR
275 )
276{
277 switch (Type)
278 {
280 return "PowerDeviceUnspecified";
281 case PowerDeviceD0:
282 return "PowerDeviceD0";
283 case PowerDeviceD1:
284 return "PowerDeviceD1";
285 case PowerDeviceD2:
286 return "PowerDeviceD2";
287 case PowerDeviceD3:
288 return "PowerDeviceD3";
290 return "PowerDeviceMaximum";
291 default:
292 return "UnKnown Device Power State";
293 }
294}
295
296#endif
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
Type
Definition: Type.h:7
#define ACPI_SUCCESS(a)
Definition: acexcep.h:94
struct _COMMON_DEVICE_DATA * PCOMMON_DEVICE_DATA
PCHAR DbgSystemPowerString(SYSTEM_POWER_STATE Type)
PCHAR DbgDevicePowerString(DEVICE_POWER_STATE Type)
#define ACPI_STATE_S5
Definition: actypes.h:629
#define ACPI_STATE_S2
Definition: actypes.h:626
#define ACPI_STATE_D2
Definition: actypes.h:635
#define ACPI_STATE_S1
Definition: actypes.h:625
#define ACPI_STATE_D0
Definition: actypes.h:633
#define ACPI_STATE_D3
Definition: actypes.h:636
UINT32 ACPI_STATUS
Definition: actypes.h:460
#define ACPI_STATE_S4
Definition: actypes.h:628
#define ACPI_STATE_D1
Definition: actypes.h:634
#define ACPI_STATE_UNKNOWN
Definition: actypes.h:622
#define ACPI_STATE_S3
Definition: actypes.h:627
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
Definition: _stack.h:55
_In_ PIRP Irp
Definition: csq.h:116
#define FALSE
Definition: types.h:117
BOOLEAN acpi_bus_power_manageable(ACPI_HANDLE handle)
Definition: bus.c:351
int acpi_bus_set_power(ACPI_HANDLE handle, int state)
Definition: bus.c:249
ACPI_STATUS acpi_suspend(UINT32 state)
Definition: system.c:347
NTSTATUS Bus_PDO_Power(PPDO_DEVICE_DATA PdoData, PIRP Irp)
Definition: power.c:116
NTSTATUS Bus_FDO_Power(PFDO_DEVICE_DATA Data, PIRP Irp)
Definition: power.c:49
NTSTATUS NTAPI Bus_Power(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: power.c:8
PCHAR NTAPI PowerMinorFunctionString(IN UCHAR MinorFunction)
Definition: fbtpwr.c:1042
if(dx< 0)
Definition: linetemp.h:194
#define error(str)
Definition: mkdosfs.c:1605
#define ASSERT(a)
Definition: mode.c:44
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IoCompleteRequest
Definition: irp.c:1240
POWER_STATE NTAPI PoSetPowerState(IN PDEVICE_OBJECT DeviceObject, IN POWER_STATE_TYPE Type, IN POWER_STATE State)
Definition: power.c:729
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:758
@ PowerSystemMaximum
Definition: ntpoapi.h:42
@ PowerSystemUnspecified
Definition: ntpoapi.h:35
@ PowerSystemSleeping1
Definition: ntpoapi.h:37
@ PowerSystemSleeping2
Definition: ntpoapi.h:38
@ PowerSystemSleeping3
Definition: ntpoapi.h:39
@ PowerSystemShutdown
Definition: ntpoapi.h:41
@ PowerSystemWorking
Definition: ntpoapi.h:36
@ PowerSystemHibernate
Definition: ntpoapi.h:40
enum _POWER_STATE_TYPE POWER_STATE_TYPE
@ DevicePowerState
Definition: ntpoapi.h:63
@ PowerDeviceD1
Definition: ntpoapi.h:50
@ PowerDeviceUnspecified
Definition: ntpoapi.h:48
@ PowerDeviceD0
Definition: ntpoapi.h:49
@ PowerDeviceD2
Definition: ntpoapi.h:51
@ PowerDeviceD3
Definition: ntpoapi.h:52
@ PowerDeviceMaximum
Definition: ntpoapi.h:53
enum _DEVICE_POWER_STATE DEVICE_POWER_STATE
enum _SYSTEM_POWER_STATE SYSTEM_POWER_STATE
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
SYSTEM_POWER_STATE SystemPowerState
Definition: acpisys.h:32
DEVICE_POWER_STATE DevicePowerState
Definition: acpisys.h:33
PDEVICE_OBJECT Self
Definition: acpisys.h:28
ACPI_HANDLE AcpiHandle
Definition: acpisys.h:39
COMMON_DEVICE_DATA Common
Definition: acpisys.h:38
Definition: ps.c:97
#define NTAPI
Definition: typedefs.h:36
uint32_t ULONG
Definition: typedefs.h:59
char * PCHAR
Definition: typedefs.h:51
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
DEVICE_POWER_STATE DeviceState
Definition: ntpoapi.h:58
SYSTEM_POWER_STATE SystemState
Definition: ntpoapi.h:57
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ UCHAR _In_ UCHAR MinorFunction
Definition: wdfdevice.h:1699
#define IRP_MN_WAIT_WAKE
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define IRP_MN_POWER_SEQUENCE
#define IRP_MN_SET_POWER
#define IRP_MJ_POWER
_In_ SYSTEM_POWER_STATE SystemPowerState
Definition: iotypes.h:7519
#define IRP_MN_QUERY_POWER
unsigned char UCHAR
Definition: xmlstorage.h:181