Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

654 lines
18 KiB

  1. /*++ BUILD Version: 0001 // Increment this if a change has global effects
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. ntpoapi.h
  5. Abstract:
  6. This module contains the user APIs for the NT Power Management.
  7. Author:
  8. Revision History:
  9. --*/
  10. #ifndef _NTPOAPI_
  11. #define _NTPOAPI_
  12. #if _MSC_VER > 1000
  13. #pragma once
  14. #endif
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. //
  19. // Power Management user APIs
  20. //
  21. // begin_ntddk begin_ntifs begin_nthal begin_ntminiport begin_wdm
  22. #ifndef _PO_DDK_
  23. #define _PO_DDK_
  24. // begin_winnt
  25. typedef enum _SYSTEM_POWER_STATE {
  26. PowerSystemUnspecified = 0,
  27. PowerSystemWorking = 1,
  28. PowerSystemSleeping1 = 2,
  29. PowerSystemSleeping2 = 3,
  30. PowerSystemSleeping3 = 4,
  31. PowerSystemHibernate = 5,
  32. PowerSystemShutdown = 6,
  33. PowerSystemMaximum = 7
  34. } SYSTEM_POWER_STATE, *PSYSTEM_POWER_STATE;
  35. #define POWER_SYSTEM_MAXIMUM 7
  36. typedef enum {
  37. PowerActionNone = 0,
  38. PowerActionReserved,
  39. PowerActionSleep,
  40. PowerActionHibernate,
  41. PowerActionShutdown,
  42. PowerActionShutdownReset,
  43. PowerActionShutdownOff,
  44. PowerActionWarmEject
  45. } POWER_ACTION, *PPOWER_ACTION;
  46. typedef enum _DEVICE_POWER_STATE {
  47. PowerDeviceUnspecified = 0,
  48. PowerDeviceD0,
  49. PowerDeviceD1,
  50. PowerDeviceD2,
  51. PowerDeviceD3,
  52. PowerDeviceMaximum
  53. } DEVICE_POWER_STATE, *PDEVICE_POWER_STATE;
  54. // end_winnt
  55. typedef union _POWER_STATE {
  56. SYSTEM_POWER_STATE SystemState;
  57. DEVICE_POWER_STATE DeviceState;
  58. } POWER_STATE, *PPOWER_STATE;
  59. typedef enum _POWER_STATE_TYPE {
  60. SystemPowerState = 0,
  61. DevicePowerState
  62. } POWER_STATE_TYPE, *PPOWER_STATE_TYPE;
  63. //
  64. // Generic power related IOCTLs
  65. //
  66. #define IOCTL_QUERY_DEVICE_POWER_STATE \
  67. CTL_CODE(FILE_DEVICE_BATTERY, 0x0, METHOD_BUFFERED, FILE_READ_ACCESS)
  68. #define IOCTL_SET_DEVICE_WAKE \
  69. CTL_CODE(FILE_DEVICE_BATTERY, 0x1, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  70. #define IOCTL_CANCEL_DEVICE_WAKE \
  71. CTL_CODE(FILE_DEVICE_BATTERY, 0x2, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  72. //
  73. // Defines for W32 interfaces
  74. //
  75. // begin_winnt
  76. #define ES_SYSTEM_REQUIRED ((ULONG)0x00000001)
  77. #define ES_DISPLAY_REQUIRED ((ULONG)0x00000002)
  78. #define ES_USER_PRESENT ((ULONG)0x00000004)
  79. #define ES_CONTINUOUS ((ULONG)0x80000000)
  80. typedef ULONG EXECUTION_STATE;
  81. typedef enum {
  82. LT_DONT_CARE,
  83. LT_LOWEST_LATENCY
  84. } LATENCY_TIME;
  85. // end_ntminiport end_ntifs end_wdm end_ntddk
  86. //-----------------------------------------------------------------------------
  87. // Device Power Information
  88. // Accessable via CM_Get_DevInst_Registry_Property_Ex(CM_DRP_DEVICE_POWER_DATA)
  89. //-----------------------------------------------------------------------------
  90. #define PDCAP_D0_SUPPORTED 0x00000001
  91. #define PDCAP_D1_SUPPORTED 0x00000002
  92. #define PDCAP_D2_SUPPORTED 0x00000004
  93. #define PDCAP_D3_SUPPORTED 0x00000008
  94. #define PDCAP_WAKE_FROM_D0_SUPPORTED 0x00000010
  95. #define PDCAP_WAKE_FROM_D1_SUPPORTED 0x00000020
  96. #define PDCAP_WAKE_FROM_D2_SUPPORTED 0x00000040
  97. #define PDCAP_WAKE_FROM_D3_SUPPORTED 0x00000080
  98. #define PDCAP_WARM_EJECT_SUPPORTED 0x00000100
  99. typedef struct CM_Power_Data_s {
  100. ULONG PD_Size;
  101. DEVICE_POWER_STATE PD_MostRecentPowerState;
  102. ULONG PD_Capabilities;
  103. ULONG PD_D1Latency;
  104. ULONG PD_D2Latency;
  105. ULONG PD_D3Latency;
  106. DEVICE_POWER_STATE PD_PowerStateMapping[POWER_SYSTEM_MAXIMUM];
  107. SYSTEM_POWER_STATE PD_DeepestSystemWake;
  108. } CM_POWER_DATA, *PCM_POWER_DATA;
  109. // begin_ntddk
  110. typedef enum {
  111. SystemPowerPolicyAc,
  112. SystemPowerPolicyDc,
  113. VerifySystemPolicyAc,
  114. VerifySystemPolicyDc,
  115. SystemPowerCapabilities,
  116. SystemBatteryState,
  117. SystemPowerStateHandler,
  118. ProcessorStateHandler,
  119. SystemPowerPolicyCurrent,
  120. AdministratorPowerPolicy,
  121. SystemReserveHiberFile,
  122. ProcessorInformation,
  123. SystemPowerInformation,
  124. ProcessorStateHandler2,
  125. LastWakeTime, // Compare with KeQueryInterruptTime()
  126. LastSleepTime, // Compare with KeQueryInterruptTime()
  127. SystemExecutionState,
  128. SystemPowerStateNotifyHandler,
  129. ProcessorPowerPolicyAc,
  130. ProcessorPowerPolicyDc,
  131. VerifyProcessorPowerPolicyAc,
  132. VerifyProcessorPowerPolicyDc,
  133. ProcessorPowerPolicyCurrent
  134. } POWER_INFORMATION_LEVEL;
  135. // begin_wdm
  136. //
  137. // System power manager capabilities
  138. //
  139. typedef struct {
  140. ULONG Granularity;
  141. ULONG Capacity;
  142. } BATTERY_REPORTING_SCALE, *PBATTERY_REPORTING_SCALE;
  143. // end_winnt
  144. // begin_ntminiport
  145. // begin_ntifs
  146. #endif // !_PO_DDK_
  147. // end_ntddk end_ntminiport end_wdm end_ntifs
  148. #define POWER_PERF_SCALE 100
  149. #define PERF_LEVEL_TO_PERCENT(_x_) ((_x_ * 1000) / (POWER_PERF_SCALE * 10))
  150. #define PERCENT_TO_PERF_LEVEL(_x_) ((_x_ * POWER_PERF_SCALE * 10) / 1000)
  151. //
  152. // Policy manager state handler interfaces
  153. //
  154. // power state handlers
  155. typedef enum {
  156. PowerStateSleeping1,
  157. PowerStateSleeping2,
  158. PowerStateSleeping3,
  159. PowerStateSleeping4,
  160. PowerStateSleeping4Firmware,
  161. PowerStateShutdownReset,
  162. PowerStateShutdownOff,
  163. PowerStateMaximum
  164. } POWER_STATE_HANDLER_TYPE, *PPOWER_STATE_HANDLER_TYPE;
  165. typedef
  166. NTSTATUS
  167. (*PENTER_STATE_SYSTEM_HANDLER)(
  168. IN PVOID SystemContext
  169. );
  170. typedef
  171. NTSTATUS
  172. (*PENTER_STATE_HANDLER)(
  173. IN PVOID Context,
  174. IN PENTER_STATE_SYSTEM_HANDLER SystemHandler OPTIONAL,
  175. IN PVOID SystemContext,
  176. IN LONG NumberProcessors,
  177. IN volatile PLONG Number
  178. );
  179. typedef struct {
  180. POWER_STATE_HANDLER_TYPE Type;
  181. BOOLEAN RtcWake;
  182. UCHAR Spare[3];
  183. PENTER_STATE_HANDLER Handler;
  184. PVOID Context;
  185. } POWER_STATE_HANDLER, *PPOWER_STATE_HANDLER;
  186. typedef
  187. NTSTATUS
  188. (*PENTER_STATE_NOTIFY_HANDLER)(
  189. IN POWER_STATE_HANDLER_TYPE State,
  190. IN PVOID Context,
  191. IN BOOLEAN Entering
  192. );
  193. typedef struct {
  194. PENTER_STATE_NOTIFY_HANDLER Handler;
  195. PVOID Context;
  196. } POWER_STATE_NOTIFY_HANDLER, *PPOWER_STATE_NOTIFY_HANDLER;
  197. NTSYSCALLAPI
  198. NTSTATUS
  199. NTAPI
  200. NtPowerInformation(
  201. IN POWER_INFORMATION_LEVEL InformationLevel,
  202. IN PVOID InputBuffer OPTIONAL,
  203. IN ULONG InputBufferLength,
  204. OUT PVOID OutputBuffer OPTIONAL,
  205. IN ULONG OutputBufferLength
  206. );
  207. // processor idle functions
  208. typedef struct {
  209. ULONGLONG StartTime;
  210. ULONGLONG EndTime;
  211. ULONG IdleHandlerReserved[4];
  212. } PROCESSOR_IDLE_TIMES, *PPROCESSOR_IDLE_TIMES;
  213. typedef
  214. BOOLEAN
  215. (FASTCALL *PPROCESSOR_IDLE_HANDLER) (
  216. IN OUT PPROCESSOR_IDLE_TIMES IdleTimes
  217. );
  218. typedef struct {
  219. ULONG HardwareLatency;
  220. PPROCESSOR_IDLE_HANDLER Handler;
  221. } PROCESSOR_IDLE_HANDLER_INFO, *PPROCESSOR_IDLE_HANDLER_INFO;
  222. typedef
  223. VOID
  224. (FASTCALL *PSET_PROCESSOR_THROTTLE) (
  225. IN UCHAR Throttle
  226. );
  227. typedef
  228. NTSTATUS
  229. (FASTCALL *PSET_PROCESSOR_THROTTLE2) (
  230. IN UCHAR Throttle
  231. );
  232. #define MAX_IDLE_HANDLERS 3
  233. typedef struct {
  234. UCHAR ThrottleScale;
  235. BOOLEAN ThrottleOnIdle;
  236. PSET_PROCESSOR_THROTTLE SetThrottle;
  237. ULONG NumIdleHandlers;
  238. PROCESSOR_IDLE_HANDLER_INFO IdleHandler[MAX_IDLE_HANDLERS];
  239. } PROCESSOR_STATE_HANDLER, *PPROCESSOR_STATE_HANDLER;
  240. // Processor_Perf_Level Flags
  241. #define PROCESSOR_STATE_TYPE_PERFORMANCE 0x1
  242. #define PROCESSOR_STATE_TYPE_THROTTLE 0x2
  243. typedef struct {
  244. UCHAR PercentFrequency; // max == POWER_PERF_SCALE
  245. UCHAR Reserved;
  246. USHORT Flags;
  247. } PROCESSOR_PERF_LEVEL, *PPROCESSOR_PERF_LEVEL;
  248. typedef struct {
  249. UCHAR PercentFrequency; // max == POWER_PERF_SCALE
  250. UCHAR MinCapacity; // battery capacity %
  251. USHORT Power; // in milliwatts
  252. UCHAR IncreaseLevel; // goto higher state
  253. UCHAR DecreaseLevel; // goto lower state
  254. USHORT Flags;
  255. ULONG IncreaseTime; // in tick counts
  256. ULONG DecreaseTime; // in tick counts
  257. ULONG IncreaseCount; // goto higher state
  258. ULONG DecreaseCount; // goto lower state
  259. ULONGLONG PerformanceTime; // Tick count
  260. } PROCESSOR_PERF_STATE, *PPROCESSOR_PERF_STATE;
  261. typedef struct {
  262. ULONG NumIdleHandlers;
  263. PROCESSOR_IDLE_HANDLER_INFO IdleHandler[MAX_IDLE_HANDLERS];
  264. PSET_PROCESSOR_THROTTLE2 SetPerfLevel;
  265. ULONG HardwareLatency;
  266. UCHAR NumPerfStates;
  267. PROCESSOR_PERF_LEVEL PerfLevel[1]; // variable size
  268. } PROCESSOR_STATE_HANDLER2, *PPROCESSOR_STATE_HANDLER2;
  269. // begin_winnt
  270. //
  271. // Power Policy Management interfaces
  272. //
  273. typedef struct {
  274. POWER_ACTION Action;
  275. ULONG Flags;
  276. ULONG EventCode;
  277. } POWER_ACTION_POLICY, *PPOWER_ACTION_POLICY;
  278. // POWER_ACTION_POLICY->Flags:
  279. #define POWER_ACTION_QUERY_ALLOWED 0x00000001
  280. #define POWER_ACTION_UI_ALLOWED 0x00000002
  281. #define POWER_ACTION_OVERRIDE_APPS 0x00000004
  282. #define POWER_ACTION_LIGHTEST_FIRST 0x10000000
  283. #define POWER_ACTION_LOCK_CONSOLE 0x20000000
  284. #define POWER_ACTION_DISABLE_WAKES 0x40000000
  285. #define POWER_ACTION_CRITICAL 0x80000000
  286. // POWER_ACTION_POLICY->EventCode flags
  287. #define POWER_LEVEL_USER_NOTIFY_TEXT 0x00000001
  288. #define POWER_LEVEL_USER_NOTIFY_SOUND 0x00000002
  289. #define POWER_LEVEL_USER_NOTIFY_EXEC 0x00000004
  290. #define POWER_USER_NOTIFY_BUTTON 0x00000008
  291. #define POWER_USER_NOTIFY_SHUTDOWN 0x00000010
  292. #define POWER_FORCE_TRIGGER_RESET 0x80000000
  293. // system battery drain policies
  294. typedef struct {
  295. BOOLEAN Enable;
  296. UCHAR Spare[3];
  297. ULONG BatteryLevel;
  298. POWER_ACTION_POLICY PowerPolicy;
  299. SYSTEM_POWER_STATE MinSystemState;
  300. } SYSTEM_POWER_LEVEL, *PSYSTEM_POWER_LEVEL;
  301. // Discharge policy constants
  302. #define NUM_DISCHARGE_POLICIES 4
  303. #define DISCHARGE_POLICY_CRITICAL 0
  304. #define DISCHARGE_POLICY_LOW 1
  305. //
  306. // Throttling policies
  307. //
  308. #define PO_THROTTLE_NONE 0
  309. #define PO_THROTTLE_CONSTANT 1
  310. #define PO_THROTTLE_DEGRADE 2
  311. #define PO_THROTTLE_ADAPTIVE 3
  312. #define PO_THROTTLE_MAXIMUM 4 // not a policy, just a limit
  313. // system power policies
  314. typedef struct _SYSTEM_POWER_POLICY {
  315. ULONG Revision; // 1
  316. // events
  317. POWER_ACTION_POLICY PowerButton;
  318. POWER_ACTION_POLICY SleepButton;
  319. POWER_ACTION_POLICY LidClose;
  320. SYSTEM_POWER_STATE LidOpenWake;
  321. ULONG Reserved;
  322. // "system idle" detection
  323. POWER_ACTION_POLICY Idle;
  324. ULONG IdleTimeout;
  325. UCHAR IdleSensitivity;
  326. // dynamic throttling policy
  327. // PO_THROTTLE_NONE, PO_THROTTLE_CONSTANT, PO_THROTTLE_DEGRADE, or PO_THROTTLE_ADAPTIVE
  328. UCHAR DynamicThrottle;
  329. UCHAR Spare2[2];
  330. // meaning of power action "sleep"
  331. SYSTEM_POWER_STATE MinSleep;
  332. SYSTEM_POWER_STATE MaxSleep;
  333. SYSTEM_POWER_STATE ReducedLatencySleep;
  334. ULONG WinLogonFlags;
  335. // parameters for dozing
  336. ULONG Spare3;
  337. ULONG DozeS4Timeout;
  338. // battery policies
  339. ULONG BroadcastCapacityResolution;
  340. SYSTEM_POWER_LEVEL DischargePolicy[NUM_DISCHARGE_POLICIES];
  341. // video policies
  342. ULONG VideoTimeout;
  343. BOOLEAN VideoDimDisplay;
  344. ULONG VideoReserved[3];
  345. // hard disk policies
  346. ULONG SpindownTimeout;
  347. // processor policies
  348. BOOLEAN OptimizeForPower;
  349. UCHAR FanThrottleTolerance;
  350. UCHAR ForcedThrottle;
  351. UCHAR MinThrottle;
  352. POWER_ACTION_POLICY OverThrottled;
  353. } SYSTEM_POWER_POLICY, *PSYSTEM_POWER_POLICY;
  354. // processor power policy state
  355. typedef struct _PROCESSOR_POWER_POLICY_INFO {
  356. // Time based information (will be converted to kernel units)
  357. ULONG TimeCheck; // in US
  358. ULONG DemoteLimit; // in US
  359. ULONG PromoteLimit; // in US
  360. // Percentage based information
  361. UCHAR DemotePercent;
  362. UCHAR PromotePercent;
  363. UCHAR Spare[2];
  364. // Flags
  365. ULONG AllowDemotion:1;
  366. ULONG AllowPromotion:1;
  367. ULONG Reserved:30;
  368. } PROCESSOR_POWER_POLICY_INFO, *PPROCESSOR_POWER_POLICY_INFO;
  369. // processor power policy
  370. typedef struct _PROCESSOR_POWER_POLICY {
  371. ULONG Revision; // 1
  372. // Dynamic Throttling Policy
  373. UCHAR DynamicThrottle;
  374. UCHAR Spare[3];
  375. // Flags
  376. ULONG Reserved;
  377. // System policy information
  378. // The Array is last, in case it needs to be grown and the structure
  379. // revision incremented.
  380. ULONG PolicyCount;
  381. PROCESSOR_POWER_POLICY_INFO Policy[3];
  382. } PROCESSOR_POWER_POLICY, *PPROCESSOR_POWER_POLICY;
  383. // administrator power policy overrides
  384. typedef struct _ADMINISTRATOR_POWER_POLICY {
  385. // meaning of power action "sleep"
  386. SYSTEM_POWER_STATE MinSleep;
  387. SYSTEM_POWER_STATE MaxSleep;
  388. // video policies
  389. ULONG MinVideoTimeout;
  390. ULONG MaxVideoTimeout;
  391. // disk policies
  392. ULONG MinSpindownTimeout;
  393. ULONG MaxSpindownTimeout;
  394. } ADMINISTRATOR_POWER_POLICY, *PADMINISTRATOR_POWER_POLICY;
  395. // end_winnt
  396. NTSYSCALLAPI
  397. NTSTATUS
  398. NTAPI
  399. NtSetThreadExecutionState(
  400. IN EXECUTION_STATE esFlags, // ES_xxx flags
  401. OUT EXECUTION_STATE *PreviousFlags
  402. );
  403. NTSYSCALLAPI
  404. NTSTATUS
  405. NTAPI
  406. NtRequestWakeupLatency(
  407. IN LATENCY_TIME latency
  408. );
  409. NTSYSCALLAPI
  410. NTSTATUS
  411. NTAPI
  412. NtInitiatePowerAction(
  413. IN POWER_ACTION SystemAction,
  414. IN SYSTEM_POWER_STATE MinSystemState,
  415. IN ULONG Flags, // POWER_ACTION_xxx flags
  416. IN BOOLEAN Asynchronous
  417. );
  418. NTSYSCALLAPI // only called by WinLogon
  419. NTSTATUS
  420. NTAPI
  421. NtSetSystemPowerState(
  422. IN POWER_ACTION SystemAction,
  423. IN SYSTEM_POWER_STATE MinSystemState,
  424. IN ULONG Flags // POWER_ACTION_xxx flags
  425. );
  426. NTSYSCALLAPI
  427. NTSTATUS
  428. NTAPI
  429. NtGetDevicePowerState(
  430. IN HANDLE Device,
  431. OUT DEVICE_POWER_STATE *State
  432. );
  433. NTSYSCALLAPI
  434. NTSTATUS
  435. NTAPI
  436. NtCancelDeviceWakeupRequest(
  437. IN HANDLE Device
  438. );
  439. NTSYSCALLAPI
  440. BOOLEAN
  441. NTAPI
  442. NtIsSystemResumeAutomatic(
  443. VOID
  444. );
  445. NTSYSCALLAPI
  446. NTSTATUS
  447. NTAPI
  448. NtRequestDeviceWakeup(
  449. IN HANDLE Device
  450. );
  451. // WinLogonFlags:
  452. #define WINLOGON_LOCK_ON_SLEEP 0x00000001
  453. // begin_winnt
  454. typedef struct {
  455. // Misc supported system features
  456. BOOLEAN PowerButtonPresent;
  457. BOOLEAN SleepButtonPresent;
  458. BOOLEAN LidPresent;
  459. BOOLEAN SystemS1;
  460. BOOLEAN SystemS2;
  461. BOOLEAN SystemS3;
  462. BOOLEAN SystemS4; // hibernate
  463. BOOLEAN SystemS5; // off
  464. BOOLEAN HiberFilePresent;
  465. BOOLEAN FullWake;
  466. BOOLEAN VideoDimPresent;
  467. BOOLEAN ApmPresent;
  468. BOOLEAN UpsPresent;
  469. // Processors
  470. BOOLEAN ThermalControl;
  471. BOOLEAN ProcessorThrottle;
  472. UCHAR ProcessorMinThrottle;
  473. UCHAR ProcessorMaxThrottle;
  474. UCHAR spare2[4];
  475. // Disk
  476. BOOLEAN DiskSpinDown;
  477. UCHAR spare3[8];
  478. // System Battery
  479. BOOLEAN SystemBatteriesPresent;
  480. BOOLEAN BatteriesAreShortTerm;
  481. BATTERY_REPORTING_SCALE BatteryScale[3];
  482. // Wake
  483. SYSTEM_POWER_STATE AcOnLineWake;
  484. SYSTEM_POWER_STATE SoftLidWake;
  485. SYSTEM_POWER_STATE RtcWake;
  486. SYSTEM_POWER_STATE MinDeviceWakeState; // note this may change on driver load
  487. SYSTEM_POWER_STATE DefaultLowLatencyWake;
  488. } SYSTEM_POWER_CAPABILITIES, *PSYSTEM_POWER_CAPABILITIES;
  489. typedef struct {
  490. BOOLEAN AcOnLine;
  491. BOOLEAN BatteryPresent;
  492. BOOLEAN Charging;
  493. BOOLEAN Discharging;
  494. BOOLEAN Spare1[4];
  495. ULONG MaxCapacity;
  496. ULONG RemainingCapacity;
  497. ULONG Rate;
  498. ULONG EstimatedTime;
  499. ULONG DefaultAlert1;
  500. ULONG DefaultAlert2;
  501. } SYSTEM_BATTERY_STATE, *PSYSTEM_BATTERY_STATE;
  502. // end_winnt
  503. // end_nthal
  504. typedef struct _PROCESSOR_POWER_INFORMATION {
  505. ULONG Number;
  506. ULONG MaxMhz;
  507. ULONG CurrentMhz;
  508. ULONG MhzLimit;
  509. ULONG MaxIdleState;
  510. ULONG CurrentIdleState;
  511. } PROCESSOR_POWER_INFORMATION, *PPROCESSOR_POWER_INFORMATION;
  512. typedef struct _SYSTEM_POWER_INFORMATION {
  513. ULONG MaxIdlenessAllowed;
  514. ULONG Idleness;
  515. ULONG TimeRemaining;
  516. UCHAR CoolingMode;
  517. } SYSTEM_POWER_INFORMATION, *PSYSTEM_POWER_INFORMATION;
  518. #ifdef __cplusplus
  519. }
  520. #endif
  521. #endif // _NTPOAPI_