3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/po/power.c
6 * PURPOSE: Power Manager
8 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
13 #include <internal/debug.h>
16 PDEVICE_NODE PopSystemPowerDeviceNode
= NULL
;
24 IN PDEVICE_OBJECT DeviceObject
,
29 Status
= IoCallDriver(DeviceObject
, Irp
);
39 PoRegisterDeviceForIdleDetection(
40 IN PDEVICE_OBJECT DeviceObject
,
41 IN ULONG ConservationIdleTime
,
42 IN ULONG PerformanceIdleTime
,
43 IN DEVICE_POWER_STATE State
)
53 PoRegisterSystemState(
55 IN EXECUTION_STATE Flags
)
66 IN PDEVICE_OBJECT DeviceObject
,
67 IN UCHAR MinorFunction
,
68 IN POWER_STATE PowerState
,
69 IN PREQUEST_POWER_COMPLETE CompletionFunction
,
71 OUT PIRP
*Irp OPTIONAL
)
73 return STATUS_NOT_IMPLEMENTED
;
89 IN PDEVICE_OBJECT DeviceObject
,
90 IN POWER_STATE_TYPE Type
,
95 ps
.SystemState
= PowerSystemWorking
; // Fully on
96 ps
.DeviceState
= PowerDeviceD0
; // Fully on
107 IN EXECUTION_STATE Flags
)
126 PoUnregisterSystemState(
127 IN PVOID StateHandle
)
132 PopSetSystemPowerState(
133 SYSTEM_POWER_STATE PowerState
)
138 IO_STATUS_BLOCK IoStatusBlock
;
139 PDEVICE_OBJECT DeviceObject
;
140 PIO_STACK_LOCATION IrpSp
;
146 Status
= IopGetSystemPowerDeviceObject(&DeviceObject
);
147 if (!NT_SUCCESS(Status
)) {
148 CPRINT("No system power driver available\n");
149 return STATUS_UNSUCCESSFUL
;
152 Fdo
= IoGetAttachedDeviceReference(DeviceObject
);
154 if (Fdo
== DeviceObject
)
156 DPRINT("An FDO was not attached\n");
157 return STATUS_UNSUCCESSFUL
;
160 KeInitializeEvent(&Event
,
164 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_POWER
,
172 IrpSp
= IoGetNextIrpStackLocation(Irp
);
173 IrpSp
->MinorFunction
= IRP_MN_SET_POWER
;
174 IrpSp
->Parameters
.Power
.Type
= SystemPowerState
;
175 IrpSp
->Parameters
.Power
.State
.SystemState
= PowerState
;
177 Status
= PoCallDriver(Fdo
, Irp
);
178 if (Status
== STATUS_PENDING
)
180 KeWaitForSingleObject(&Event
,
185 Status
= IoStatusBlock
.Status
;
188 ObDereferenceObject(Fdo
);
194 return STATUS_NOT_IMPLEMENTED
;
207 NtInitiatePowerAction (
208 IN POWER_ACTION SystemAction
,
209 IN SYSTEM_POWER_STATE MinSystemState
,
211 IN BOOLEAN Asynchronous
)
214 return STATUS_NOT_IMPLEMENTED
;
223 IN POWER_INFORMATION_LEVEL PowerInformationLevel
,
224 IN PVOID InputBuffer OPTIONAL
,
225 IN ULONG InputBufferLength
,
226 OUT PVOID OutputBuffer OPTIONAL
,
227 IN ULONG OutputBufferLength
232 DPRINT("NtPowerInformation(PowerInformationLevel 0x%x, InputBuffer 0x%x, "
233 "InputBufferLength 0x%x, OutputBuffer 0x%x, OutputBufferLength 0x%x)\n",
234 PowerInformationLevel
,
235 InputBuffer
, InputBufferLength
,
236 OutputBuffer
, OutputBufferLength
);
237 switch (PowerInformationLevel
)
239 case SystemBatteryState
:
241 PSYSTEM_BATTERY_STATE BatteryState
= (PSYSTEM_BATTERY_STATE
)OutputBuffer
;
243 if (InputBuffer
!= NULL
)
244 return STATUS_INVALID_PARAMETER
;
245 if (OutputBufferLength
< sizeof(SYSTEM_BATTERY_STATE
))
246 return STATUS_BUFFER_TOO_SMALL
;
248 /* Just zero the struct (and thus set BatteryState->BatteryPresent = FALSE) */
249 RtlZeroMemory(BatteryState
, sizeof(SYSTEM_BATTERY_STATE
));
250 BatteryState
->EstimatedTime
= (ULONG
)-1;
252 Status
= STATUS_SUCCESS
;
257 Status
= STATUS_NOT_IMPLEMENTED
;
258 DPRINT1("PowerInformationLevel 0x%x is UNIMPLEMENTED! Have a nice day.\n",
259 PowerInformationLevel
);