1 /* 2 * ntpoapi.h 3 * 4 * APIs for power management. 5 * 6 * This file is part of the w32api package. 7 * 8 * Contributors: 9 * Created by Casper S. Hornstrup <chorns@users.sourceforge.net> 10 * 11 * THIS SOFTWARE IS NOT COPYRIGHTED 12 * 13 * This source code is offered for use in the public domain. You may 14 * use, modify or distribute it freely. 15 * 16 * This code is distributed in the hope that it will be useful but 17 * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY 18 * DISCLAIMED. This includes but is not limited to warranties of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 20 * 21 */ 22 23 #ifndef __NTPOAPI_H 24 #define __NTPOAPI_H 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 #ifndef _PO_DDK_ 31 #define _PO_DDK_ 32 33 /* Power States/Levels */ 34 typedef enum _SYSTEM_POWER_STATE { 35 PowerSystemUnspecified, 36 PowerSystemWorking, 37 PowerSystemSleeping1, 38 PowerSystemSleeping2, 39 PowerSystemSleeping3, 40 PowerSystemHibernate, 41 PowerSystemShutdown, 42 PowerSystemMaximum 43 } SYSTEM_POWER_STATE, *PSYSTEM_POWER_STATE; 44 45 #define POWER_SYSTEM_MAXIMUM PowerSystemMaximum 46 47 typedef enum _DEVICE_POWER_STATE { 48 PowerDeviceUnspecified, 49 PowerDeviceD0, 50 PowerDeviceD1, 51 PowerDeviceD2, 52 PowerDeviceD3, 53 PowerDeviceMaximum 54 } DEVICE_POWER_STATE, *PDEVICE_POWER_STATE; 55 56 typedef union _POWER_STATE { 57 SYSTEM_POWER_STATE SystemState; 58 DEVICE_POWER_STATE DeviceState; 59 } POWER_STATE, *PPOWER_STATE; 60 61 typedef enum _POWER_STATE_TYPE { 62 SystemPowerState = 0, 63 DevicePowerState 64 } POWER_STATE_TYPE, *PPOWER_STATE_TYPE; 65 66 typedef enum _POWER_INFORMATION_LEVEL { 67 SystemPowerPolicyAc, 68 SystemPowerPolicyDc, 69 VerifySystemPolicyAc, 70 VerifySystemPolicyDc, 71 SystemPowerCapabilities, 72 SystemBatteryState, 73 SystemPowerStateHandler, 74 ProcessorStateHandler, 75 SystemPowerPolicyCurrent, 76 AdministratorPowerPolicy, 77 SystemReserveHiberFile, 78 ProcessorInformation, 79 SystemPowerInformation, 80 ProcessorStateHandler2, 81 LastWakeTime, 82 LastSleepTime, 83 SystemExecutionState, 84 SystemPowerStateNotifyHandler, 85 ProcessorPowerPolicyAc, 86 ProcessorPowerPolicyDc, 87 VerifyProcessorPowerPolicyAc, 88 VerifyProcessorPowerPolicyDc, 89 ProcessorPowerPolicyCurrent, 90 SystemPowerStateLogging, 91 SystemPowerLoggingEntry, 92 SetPowerSettingValue, 93 NotifyUserPowerSetting, 94 PowerInformationLevelUnused0, 95 PowerInformationLevelUnused1, 96 SystemVideoState, 97 TraceApplicationPowerMessage, 98 TraceApplicationPowerMessageEnd, 99 ProcessorPerfStates, 100 ProcessorIdleStates, 101 ProcessorCap, 102 SystemWakeSource, 103 SystemHiberFileInformation, 104 TraceServicePowerMessage, 105 ProcessorLoad, 106 PowerShutdownNotification, 107 MonitorCapabilities, 108 SessionPowerInit, 109 SessionDisplayState, 110 PowerRequestCreate, 111 PowerRequestAction, 112 GetPowerRequestList, 113 ProcessorInformationEx, 114 NotifyUserModeLegacyPowerEvent, 115 GroupPark, 116 ProcessorIdleDomains, 117 WakeTimerList, 118 SystemHiberFileSize, 119 PowerInformationLevelMaximum 120 } POWER_INFORMATION_LEVEL; 121 122 typedef enum { 123 PowerActionNone, 124 PowerActionReserved, 125 PowerActionSleep, 126 PowerActionHibernate, 127 PowerActionShutdown, 128 PowerActionShutdownReset, 129 PowerActionShutdownOff, 130 PowerActionWarmEject 131 } POWER_ACTION, *PPOWER_ACTION; 132 133 #if (NTDDI_VERSION >= NTDDI_WINXP) || !defined(_BATCLASS_) 134 typedef struct { 135 ULONG Granularity; 136 ULONG Capacity; 137 } BATTERY_REPORTING_SCALE, *PBATTERY_REPORTING_SCALE; 138 #endif /* (NTDDI_VERSION >= NTDDI_WINXP) || !defined(_BATCLASS_) */ 139 140 141 #endif /* _PO_DDK_ */ 142 143 #define POWER_PERF_SCALE 100 144 #define PERF_LEVEL_TO_PERCENT(x) (((x) * 1000) / (POWER_PERF_SCALE * 10)) 145 #define PERCENT_TO_PERF_LEVEL(x) (((x) * POWER_PERF_SCALE * 10) / 1000) 146 147 typedef struct _PROCESSOR_IDLE_TIMES { 148 ULONGLONG StartTime; 149 ULONGLONG EndTime; 150 ULONG IdleHandlerReserved[4]; 151 } PROCESSOR_IDLE_TIMES, *PPROCESSOR_IDLE_TIMES; 152 153 _Function_class_(PROCESSOR_IDLE_HANDLER) 154 typedef NTSTATUS 155 (FASTCALL *PPROCESSOR_IDLE_HANDLER)( 156 _In_ ULONG_PTR Context, 157 _Inout_ PPROCESSOR_IDLE_TIMES IdleTimes); 158 159 typedef struct _PROCESSOR_IDLE_HANDLER_INFO { 160 ULONG HardwareLatency; 161 PPROCESSOR_IDLE_HANDLER Handler; 162 } PROCESSOR_IDLE_HANDLER_INFO, *PPROCESSOR_IDLE_HANDLER_INFO; 163 164 typedef VOID 165 (FASTCALL*PSET_PROCESSOR_THROTTLE)( 166 IN UCHAR Throttle); 167 168 typedef NTSTATUS 169 (FASTCALL*PSET_PROCESSOR_THROTTLE2)( 170 IN UCHAR Throttle); 171 172 #define MAX_IDLE_HANDLERS 3 173 174 typedef struct _PROCESSOR_STATE_HANDLER { 175 UCHAR ThrottleScale; 176 BOOLEAN ThrottleOnIdle; 177 PSET_PROCESSOR_THROTTLE SetThrottle; 178 ULONG NumIdleHandlers; 179 PROCESSOR_IDLE_HANDLER_INFO IdleHandler[MAX_IDLE_HANDLERS]; 180 } PROCESSOR_STATE_HANDLER, *PPROCESSOR_STATE_HANDLER; 181 182 typedef enum _POWER_STATE_HANDLER_TYPE { 183 PowerStateSleeping1, 184 PowerStateSleeping2, 185 PowerStateSleeping3, 186 PowerStateSleeping4, 187 PowerStateSleeping4Firmware, 188 PowerStateShutdownReset, 189 PowerStateShutdownOff, 190 PowerStateMaximum 191 } POWER_STATE_HANDLER_TYPE, *PPOWER_STATE_HANDLER_TYPE; 192 193 _Function_class_(ENTER_STATE_SYSTEM_HANDLER) 194 _IRQL_requires_same_ 195 typedef NTSTATUS 196 (NTAPI *PENTER_STATE_SYSTEM_HANDLER)( 197 _In_ PVOID SystemContext); 198 199 _Function_class_(ENTER_STATE_HANDLER) 200 _IRQL_requires_same_ 201 typedef NTSTATUS 202 (NTAPI *PENTER_STATE_HANDLER)( 203 _In_opt_ PVOID Context, 204 _In_opt_ PENTER_STATE_SYSTEM_HANDLER SystemHandler, 205 _In_opt_ PVOID SystemContext, 206 _In_ LONG NumberProcessors, 207 _In_opt_ LONG volatile *Number); 208 209 typedef struct _POWER_STATE_HANDLER { 210 POWER_STATE_HANDLER_TYPE Type; 211 BOOLEAN RtcWake; 212 UCHAR Spare[3]; 213 PENTER_STATE_HANDLER Handler; 214 PVOID Context; 215 } POWER_STATE_HANDLER, *PPOWER_STATE_HANDLER; 216 217 _Function_class_(ENTER_STATE_NOTIFY_HANDLER) 218 _IRQL_requires_same_ 219 typedef NTSTATUS 220 (NTAPI *PENTER_STATE_NOTIFY_HANDLER)( 221 _In_ POWER_STATE_HANDLER_TYPE State, 222 _In_ PVOID Context, 223 _In_ BOOLEAN Entering); 224 225 typedef struct _POWER_STATE_NOTIFY_HANDLER { 226 PENTER_STATE_NOTIFY_HANDLER Handler; 227 PVOID Context; 228 } POWER_STATE_NOTIFY_HANDLER, *PPOWER_STATE_NOTIFY_HANDLER; 229 230 _IRQL_requires_max_(APC_LEVEL) 231 __kernel_entry 232 NTSYSCALLAPI 233 NTSTATUS 234 NTAPI 235 NtPowerInformation( 236 _In_ POWER_INFORMATION_LEVEL InformationLevel, 237 _In_reads_bytes_opt_(InputBufferLength) PVOID InputBuffer, 238 _In_ ULONG InputBufferLength, 239 _Out_writes_bytes_opt_(OutputBufferLength) PVOID OutputBuffer, 240 _In_ ULONG OutputBufferLength); 241 242 #define PROCESSOR_STATE_TYPE_PERFORMANCE 1 243 #define PROCESSOR_STATE_TYPE_THROTTLE 2 244 245 typedef struct _PROCESSOR_PERF_LEVEL { 246 UCHAR PercentFrequency; 247 UCHAR Reserved; 248 USHORT Flags; 249 } PROCESSOR_PERF_LEVEL, *PPROCESSOR_PERF_LEVEL; 250 251 typedef struct _PROCESSOR_PERF_STATE { 252 UCHAR PercentFrequency; 253 UCHAR MinCapacity; 254 USHORT Power; 255 UCHAR IncreaseLevel; 256 UCHAR DecreaseLevel; 257 USHORT Flags; 258 ULONG IncreaseTime; 259 ULONG DecreaseTime; 260 ULONG IncreaseCount; 261 ULONG DecreaseCount; 262 ULONGLONG PerformanceTime; 263 } PROCESSOR_PERF_STATE, *PPROCESSOR_PERF_STATE; 264 265 typedef struct _PROCESSOR_STATE_HANDLER2 { 266 ULONG NumIdleHandlers; 267 PROCESSOR_IDLE_HANDLER_INFO IdleHandler[MAX_IDLE_HANDLERS]; 268 PSET_PROCESSOR_THROTTLE2 SetPerfLevel; 269 ULONG HardwareLatency; 270 UCHAR NumPerfStates; 271 PROCESSOR_PERF_LEVEL PerfLevel[1]; 272 } PROCESSOR_STATE_HANDLER2, *PPROCESSOR_STATE_HANDLER2; 273 274 typedef struct _SYSTEM_POWER_INFORMATION { 275 ULONG MaxIdlenessAllowed; 276 ULONG Idleness; 277 ULONG TimeRemaining; 278 UCHAR CoolingMode; 279 } SYSTEM_POWER_INFORMATION, *PSYSTEM_POWER_INFORMATION; 280 281 _IRQL_requires_max_(PASSIVE_LEVEL) 282 __kernel_entry 283 NTSYSCALLAPI 284 NTSTATUS 285 NTAPI 286 NtSetThreadExecutionState( 287 _In_ EXECUTION_STATE esFlags, 288 _Out_ EXECUTION_STATE *PreviousFlags); 289 290 NTSYSCALLAPI 291 NTSTATUS 292 NTAPI 293 NtRequestWakeupLatency( 294 _In_ LATENCY_TIME latency); 295 296 _IRQL_requires_max_(APC_LEVEL) 297 __kernel_entry 298 NTSYSCALLAPI 299 NTSTATUS 300 NTAPI 301 NtInitiatePowerAction( 302 _In_ POWER_ACTION SystemAction, 303 _In_ SYSTEM_POWER_STATE MinSystemState, 304 _In_ ULONG Flags, 305 _In_ BOOLEAN Asynchronous); 306 307 _IRQL_requires_max_(APC_LEVEL) 308 __kernel_entry 309 NTSYSCALLAPI 310 NTSTATUS 311 NTAPI 312 NtSetSystemPowerState( 313 _In_ POWER_ACTION SystemAction, 314 _In_ SYSTEM_POWER_STATE MinSystemState, 315 _In_ ULONG Flags); 316 317 _IRQL_requires_max_(APC_LEVEL) 318 __kernel_entry 319 NTSYSCALLAPI 320 NTSTATUS 321 NTAPI 322 NtGetDevicePowerState( 323 _In_ HANDLE Device, 324 _Out_ DEVICE_POWER_STATE *State); 325 326 NTSYSCALLAPI 327 NTSTATUS 328 NTAPI 329 NtCancelDeviceWakeupRequest( 330 _In_ HANDLE Device); 331 332 _IRQL_requires_max_(APC_LEVEL) 333 __kernel_entry 334 NTSYSCALLAPI 335 BOOLEAN 336 NTAPI 337 NtIsSystemResumeAutomatic(VOID); 338 339 NTSYSCALLAPI 340 NTSTATUS 341 NTAPI 342 NtRequestDeviceWakeup( 343 _In_ HANDLE Device); 344 345 #define WINLOGON_LOCK_ON_SLEEP 0x00000001 346 347 typedef struct { 348 BOOLEAN PowerButtonPresent; 349 BOOLEAN SleepButtonPresent; 350 BOOLEAN LidPresent; 351 BOOLEAN SystemS1; 352 BOOLEAN SystemS2; 353 BOOLEAN SystemS3; 354 BOOLEAN SystemS4; 355 BOOLEAN SystemS5; 356 BOOLEAN HiberFilePresent; 357 BOOLEAN FullWake; 358 BOOLEAN VideoDimPresent; 359 BOOLEAN ApmPresent; 360 BOOLEAN UpsPresent; 361 BOOLEAN ThermalControl; 362 BOOLEAN ProcessorThrottle; 363 UCHAR ProcessorMinThrottle; 364 #if (NTDDI_VERSION < NTDDI_WINXP) 365 UCHAR ProcessorThrottleScale; 366 UCHAR spare2[4]; 367 #else 368 UCHAR ProcessorMaxThrottle; 369 BOOLEAN FastSystemS4; 370 UCHAR spare2[3]; 371 #endif /* (NTDDI_VERSION < NTDDI_WINXP) */ 372 BOOLEAN DiskSpinDown; 373 UCHAR spare3[8]; 374 BOOLEAN SystemBatteriesPresent; 375 BOOLEAN BatteriesAreShortTerm; 376 BATTERY_REPORTING_SCALE BatteryScale[3]; 377 SYSTEM_POWER_STATE AcOnLineWake; 378 SYSTEM_POWER_STATE SoftLidWake; 379 SYSTEM_POWER_STATE RtcWake; 380 SYSTEM_POWER_STATE MinDeviceWakeState; 381 SYSTEM_POWER_STATE DefaultLowLatencyWake; 382 } SYSTEM_POWER_CAPABILITIES, *PSYSTEM_POWER_CAPABILITIES; 383 384 typedef struct { 385 BOOLEAN AcOnLine; 386 BOOLEAN BatteryPresent; 387 BOOLEAN Charging; 388 BOOLEAN Discharging; 389 BOOLEAN Spare1[4]; 390 ULONG MaxCapacity; 391 ULONG RemainingCapacity; 392 ULONG Rate; 393 ULONG EstimatedTime; 394 ULONG DefaultAlert1; 395 ULONG DefaultAlert2; 396 } SYSTEM_BATTERY_STATE, *PSYSTEM_BATTERY_STATE; 397 398 typedef struct _PROCESSOR_POWER_INFORMATION { 399 ULONG Number; 400 ULONG MaxMhz; 401 ULONG CurrentMhz; 402 ULONG MhzLimit; 403 ULONG MaxIdleState; 404 ULONG CurrentIdleState; 405 } PROCESSOR_POWER_INFORMATION, *PPROCESSOR_POWER_INFORMATION; 406 407 typedef struct _POWER_ACTION_POLICY { 408 POWER_ACTION Action; 409 ULONG Flags; 410 ULONG EventCode; 411 } POWER_ACTION_POLICY, *PPOWER_ACTION_POLICY; 412 413 /* POWER_ACTION_POLICY.Flags constants */ 414 #define POWER_ACTION_QUERY_ALLOWED 0x00000001 415 #define POWER_ACTION_UI_ALLOWED 0x00000002 416 #define POWER_ACTION_OVERRIDE_APPS 0x00000004 417 #define POWER_ACTION_LIGHTEST_FIRST 0x10000000 418 #define POWER_ACTION_LOCK_CONSOLE 0x20000000 419 #define POWER_ACTION_DISABLE_WAKES 0x40000000 420 #define POWER_ACTION_CRITICAL 0x80000000 421 422 /* POWER_ACTION_POLICY.EventCode constants */ 423 #define POWER_LEVEL_USER_NOTIFY_TEXT 0x00000001 424 #define POWER_LEVEL_USER_NOTIFY_SOUND 0x00000002 425 #define POWER_LEVEL_USER_NOTIFY_EXEC 0x00000004 426 #define POWER_USER_NOTIFY_BUTTON 0x00000008 427 #define POWER_USER_NOTIFY_SHUTDOWN 0x00000010 428 #define POWER_FORCE_TRIGGER_RESET 0x80000000 429 430 #define DISCHARGE_POLICY_CRITICAL 0 431 #define DISCHARGE_POLICY_LOW 1 432 #define NUM_DISCHARGE_POLICIES 4 433 434 #define PO_THROTTLE_NONE 0 435 #define PO_THROTTLE_CONSTANT 1 436 #define PO_THROTTLE_DEGRADE 2 437 #define PO_THROTTLE_ADAPTIVE 3 438 #define PO_THROTTLE_MAXIMUM 4 439 440 #ifdef __cplusplus 441 } 442 #endif 443 444 #endif /* __NTPOAPI_H */ 445