ReactOS  0.4.15-dev-499-g1f31905
power.c
Go to the documentation of this file.
1 #include "precomp.h"
2 
3 #define NDEBUG
4 #include <debug.h>
5 
7 NTAPI
10  PIRP Irp
11  )
12 {
13  PIO_STACK_LOCATION irpStack;
15  PCOMMON_DEVICE_DATA commonData;
16 
18  irpStack = IoGetCurrentIrpStackLocation (Irp);
19  ASSERT (IRP_MJ_POWER == irpStack->MajorFunction);
20 
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) ? \
71  DbgSystemPowerString(powerState.SystemState) :\
72  DbgDevicePowerString(powerState.DeviceState)));
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;
94  ASSERT(FALSE);
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 
115 NTSTATUS
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 
194  case IRP_MN_QUERY_POWER:
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 
209  if (status != STATUS_NOT_SUPPORTED) {
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 
223 PCHAR
226 )
227 {
228  switch (MinorFunction)
229  {
230  case IRP_MN_SET_POWER:
231  return "IRP_MN_SET_POWER";
232  case IRP_MN_QUERY_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 
244 PCHAR
247  )
248 {
249  switch (Type)
250  {
252  return "PowerSystemUnspecified";
253  case PowerSystemWorking:
254  return "PowerSystemWorking";
256  return "PowerSystemSleeping1";
258  return "PowerSystemSleeping2";
260  return "PowerSystemSleeping3";
262  return "PowerSystemHibernate";
263  case PowerSystemShutdown:
264  return "PowerSystemShutdown";
265  case PowerSystemMaximum:
266  return "PowerSystemMaximum";
267  default:
268  return "UnKnown System Power State";
269  }
270  }
271 
272 PCHAR
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";
289  case PowerDeviceMaximum:
290  return "PowerDeviceMaximum";
291  default:
292  return "UnKnown Device Power State";
293  }
294 }
295 
296 #endif
signed char * PCHAR
Definition: retypes.h:7
enum _POWER_STATE_TYPE POWER_STATE_TYPE
DEVICE_POWER_STATE DevicePowerState
Definition: acpisys.h:33
#define ACPI_SUCCESS(a)
Definition: acexcep.h:94
Type
Definition: Type.h:6
#define error(str)
Definition: mkdosfs.c:1605
#define IRP_MN_POWER_SEQUENCE
#define IRP_MN_QUERY_POWER
_In_ PIRP Irp
Definition: csq.h:116
NTSTATUS Bus_FDO_Power(PFDO_DEVICE_DATA Data, PIRP Irp)
Definition: power.c:49
NTSTATUS Bus_PDO_Power(PPDO_DEVICE_DATA PdoData, PIRP Irp)
Definition: power.c:116
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN acpi_bus_power_manageable(ACPI_HANDLE handle)
Definition: bus.c:351
static stack_node_t * stack
Definition: rpn_ieee.c:37
UINT32 ACPI_STATUS
Definition: actypes.h:460
enum _SYSTEM_POWER_STATE SYSTEM_POWER_STATE
PDEVICE_OBJECT Self
Definition: acpisys.h:28
SYSTEM_POWER_STATE SystemState
Definition: ntpoapi.h:57
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
struct _COMMON_DEVICE_DATA * PCOMMON_DEVICE_DATA
SYSTEM_POWER_STATE SystemPowerState
Definition: acpisys.h:32
#define ACPI_STATE_S5
Definition: actypes.h:621
PVOID DeviceExtension
Definition: env_spec_w32.h:418
PCHAR NTAPI PowerMinorFunctionString(IN UCHAR MinorFunction)
Definition: fbtpwr.c:1042
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
#define ACPI_STATE_S4
Definition: actypes.h:620
Definition: _stack.h:47
enum _DEVICE_POWER_STATE DEVICE_POWER_STATE
if(!(yy_init))
Definition: macro.lex.yy.c:714
DEVICE_POWER_STATE DeviceState
Definition: ntpoapi.h:58
#define ACPI_STATE_D3
Definition: actypes.h:628
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
unsigned char UCHAR
Definition: xmlstorage.h:181
#define IRP_MJ_POWER
ACPI_STATUS acpi_suspend(UINT32 state)
Definition: system.c:347
#define IRP_MN_SET_POWER
_In_ UCHAR MinorFunction
Definition: pofuncs.h:42
PCHAR DbgSystemPowerString(SYSTEM_POWER_STATE Type)
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
int acpi_bus_set_power(ACPI_HANDLE handle, int state)
Definition: bus.c:249
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:737
ACPI_HANDLE AcpiHandle
Definition: acpisys.h:39
#define ACPI_STATE_S1
Definition: actypes.h:617
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define ACPI_STATE_S2
Definition: actypes.h:618
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI Bus_Power(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: power.c:8
#define ACPI_STATE_D0
Definition: actypes.h:625
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:568
POWER_STATE NTAPI PoSetPowerState(IN PDEVICE_OBJECT DeviceObject, IN POWER_STATE_TYPE Type, IN POWER_STATE State)
Definition: power.c:708
#define IRP_MN_WAIT_WAKE
#define ACPI_STATE_D1
Definition: actypes.h:626
#define ACPI_STATE_S3
Definition: actypes.h:619
return STATUS_SUCCESS
Definition: btrfs.c:3014
static SERVICE_STATUS status
Definition: service.c:31
#define ACPI_STATE_D2
Definition: actypes.h:627
COMMON_DEVICE_DATA Common
Definition: acpisys.h:38
PCHAR DbgDevicePowerString(DEVICE_POWER_STATE Type)
#define ACPI_STATE_UNKNOWN
Definition: actypes.h:614
Definition: ps.c:97