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>
15 PDEVICE_NODE PopSystemPowerDeviceNode
= NULL
;
16 BOOLEAN PopAcpiPresent
= FALSE
;
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 ASSERT_IRQL(DISPATCH_LEVEL
);
97 ps
.SystemState
= PowerSystemWorking
; // Fully on
98 ps
.DeviceState
= PowerDeviceD0
; // Fully on
109 IN EXECUTION_STATE Flags
)
128 PoUnregisterSystemState(
129 IN PVOID StateHandle
)
134 PopSetSystemPowerState(
135 SYSTEM_POWER_STATE PowerState
)
137 IO_STATUS_BLOCK IoStatusBlock
;
138 PDEVICE_OBJECT DeviceObject
;
139 PIO_STACK_LOCATION IrpSp
;
145 if (!PopAcpiPresent
) return STATUS_NOT_IMPLEMENTED
;
147 Status
= IopGetSystemPowerDeviceObject(&DeviceObject
);
148 if (!NT_SUCCESS(Status
)) {
149 CPRINT("No system power driver available\n");
150 return STATUS_UNSUCCESSFUL
;
153 Fdo
= IoGetAttachedDeviceReference(DeviceObject
);
155 if (Fdo
== DeviceObject
)
157 DPRINT("An FDO was not attached\n");
158 return STATUS_UNSUCCESSFUL
;
161 KeInitializeEvent(&Event
,
165 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_POWER
,
173 IrpSp
= IoGetNextIrpStackLocation(Irp
);
174 IrpSp
->MinorFunction
= IRP_MN_SET_POWER
;
175 IrpSp
->Parameters
.Power
.Type
= SystemPowerState
;
176 IrpSp
->Parameters
.Power
.State
.SystemState
= PowerState
;
178 Status
= PoCallDriver(Fdo
, Irp
);
179 if (Status
== STATUS_PENDING
)
181 KeWaitForSingleObject(&Event
,
186 Status
= IoStatusBlock
.Status
;
189 ObDereferenceObject(Fdo
);
196 PoInit(PLOADER_PARAMETER_BLOCK LoaderBlock
,
197 BOOLEAN ForceAcpiDisable
)
199 /* Set the ACPI State to False if it's been forced that way */
200 if (ForceAcpiDisable
) PopAcpiPresent
= FALSE
;
202 /* Otherwise check the LoaderBlock's Flag */
203 PopAcpiPresent
= LoaderBlock
->Flags
& MB_FLAGS_ACPI_TABLE
;
211 NtInitiatePowerAction (
212 IN POWER_ACTION SystemAction
,
213 IN SYSTEM_POWER_STATE MinSystemState
,
215 IN BOOLEAN Asynchronous
)
218 return STATUS_NOT_IMPLEMENTED
;
227 IN POWER_INFORMATION_LEVEL PowerInformationLevel
,
228 IN PVOID InputBuffer OPTIONAL
,
229 IN ULONG InputBufferLength
,
230 OUT PVOID OutputBuffer OPTIONAL
,
231 IN ULONG OutputBufferLength
238 DPRINT("NtPowerInformation(PowerInformationLevel 0x%x, InputBuffer 0x%x, "
239 "InputBufferLength 0x%x, OutputBuffer 0x%x, OutputBufferLength 0x%x)\n",
240 PowerInformationLevel
,
241 InputBuffer
, InputBufferLength
,
242 OutputBuffer
, OutputBufferLength
);
243 switch (PowerInformationLevel
)
245 case SystemBatteryState
:
247 PSYSTEM_BATTERY_STATE BatteryState
= (PSYSTEM_BATTERY_STATE
)OutputBuffer
;
249 if (InputBuffer
!= NULL
)
250 return STATUS_INVALID_PARAMETER
;
251 if (OutputBufferLength
< sizeof(SYSTEM_BATTERY_STATE
))
252 return STATUS_BUFFER_TOO_SMALL
;
254 /* Just zero the struct (and thus set BatteryState->BatteryPresent = FALSE) */
255 RtlZeroMemory(BatteryState
, sizeof(SYSTEM_BATTERY_STATE
));
256 BatteryState
->EstimatedTime
= (ULONG
)-1;
258 Status
= STATUS_SUCCESS
;
263 Status
= STATUS_NOT_IMPLEMENTED
;
264 DPRINT1("PowerInformationLevel 0x%x is UNIMPLEMENTED! Have a nice day.\n",
265 PowerInformationLevel
);