ReactOS  0.4.14-dev-293-g2b39b42
power.c File Reference
#include "precomp.h"
#include <debug.h>
Include dependency graph for power.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS NTAPI Bus_Power (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS Bus_FDO_Power (PFDO_DEVICE_DATA Data, PIRP Irp)
 
NTSTATUS Bus_PDO_Power (PPDO_DEVICE_DATA PdoData, PIRP Irp)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 3 of file power.c.

Function Documentation

◆ Bus_FDO_Power()

NTSTATUS Bus_FDO_Power ( PFDO_DEVICE_DATA  Data,
PIRP  Irp 
)

Definition at line 49 of file power.c.

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 }
enum _POWER_STATE_TYPE POWER_STATE_TYPE
#define ACPI_SUCCESS(a)
Definition: acexcep.h:94
NTSTATUS NTAPI PoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: power.c:485
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
static stack_node_t * stack
Definition: rpn_ieee.c:37
UINT32 ACPI_STATUS
Definition: actypes.h:460
enum _SYSTEM_POWER_STATE SYSTEM_POWER_STATE
SYSTEM_POWER_STATE SystemState
Definition: ntpoapi.h:57
#define ACPI_STATE_S5
Definition: actypes.h:620
void DPRINT(...)
Definition: polytest.cpp:61
#define ACPI_STATE_S4
Definition: actypes.h:619
Definition: _stack.h:47
DEVICE_POWER_STATE DeviceState
Definition: ntpoapi.h:58
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
ACPI_STATUS acpi_suspend(UINT32 state)
Definition: system.c:347
#define IRP_MN_SET_POWER
PCHAR DbgSystemPowerString(SYSTEM_POWER_STATE Type)
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:626
#define ACPI_STATE_S1
Definition: actypes.h:616
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define ACPI_STATE_S2
Definition: actypes.h:617
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define ACPI_STATE_S3
Definition: actypes.h:618
return STATUS_SUCCESS
Definition: btrfs.c:2966
static SERVICE_STATUS status
Definition: service.c:31
PCHAR DbgDevicePowerString(DEVICE_POWER_STATE Type)
#define ACPI_STATE_UNKNOWN
Definition: actypes.h:613
Definition: ps.c:97

Referenced by Bus_Power().

◆ Bus_PDO_Power()

NTSTATUS Bus_PDO_Power ( PPDO_DEVICE_DATA  PdoData,
PIRP  Irp 
)

Definition at line 116 of file power.c.

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 }
enum _POWER_STATE_TYPE POWER_STATE_TYPE
DEVICE_POWER_STATE DevicePowerState
Definition: acpisys.h:33
#define ACPI_SUCCESS(a)
Definition: acexcep.h:94
#define error(str)
Definition: mkdosfs.c:1605
#define IRP_MN_POWER_SEQUENCE
#define IRP_MN_QUERY_POWER
_In_ PIRP Irp
Definition: csq.h: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
PDEVICE_OBJECT Self
Definition: acpisys.h:28
SYSTEM_POWER_STATE SystemState
Definition: ntpoapi.h:57
SYSTEM_POWER_STATE SystemPowerState
Definition: acpisys.h:32
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
Definition: _stack.h:47
DEVICE_POWER_STATE DeviceState
Definition: ntpoapi.h:58
#define ACPI_STATE_D3
Definition: actypes.h:627
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define IRP_MN_SET_POWER
PCHAR DbgSystemPowerString(SYSTEM_POWER_STATE Type)
__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:626
ACPI_HANDLE AcpiHandle
Definition: acpisys.h:39
#define ACPI_STATE_D0
Definition: actypes.h:624
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566
POWER_STATE NTAPI PoSetPowerState(IN PDEVICE_OBJECT DeviceObject, IN POWER_STATE_TYPE Type, IN POWER_STATE State)
Definition: power.c:597
#define IRP_MN_WAIT_WAKE
#define ACPI_STATE_D1
Definition: actypes.h:625
return STATUS_SUCCESS
Definition: btrfs.c:2966
static SERVICE_STATUS status
Definition: service.c:31
#define ACPI_STATE_D2
Definition: actypes.h:626
COMMON_DEVICE_DATA Common
Definition: acpisys.h:38
PCHAR DbgDevicePowerString(DEVICE_POWER_STATE Type)
Definition: ps.c:97

Referenced by Bus_Power().

◆ Bus_Power()

NTSTATUS NTAPI Bus_Power ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 8 of file power.c.

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 }
DEVICE_POWER_STATE DevicePowerState
Definition: acpisys.h:33
_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
struct _COMMON_DEVICE_DATA * PCOMMON_DEVICE_DATA
SYSTEM_POWER_STATE SystemPowerState
Definition: acpisys.h:32
PVOID DeviceExtension
Definition: env_spec_w32.h:418
PCHAR NTAPI PowerMinorFunctionString(IN UCHAR MinorFunction)
Definition: fbtpwr.c:1042
void DPRINT(...)
Definition: polytest.cpp:61
if(!(yy_init))
Definition: macro.lex.yy.c:714
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define IRP_MJ_POWER
PCHAR DbgSystemPowerString(SYSTEM_POWER_STATE Type)
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
return STATUS_SUCCESS
Definition: btrfs.c:2966
static SERVICE_STATUS status
Definition: service.c:31
PCHAR DbgDevicePowerString(DEVICE_POWER_STATE Type)
Definition: ps.c:97

Referenced by DriverEntry().