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.

2092 lines
48 KiB

  1. /*++ BUILD Version: 0002
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. pop.h
  5. Abstract:
  6. This module contains the private structure definitions and APIs used by
  7. the NT Power Manager.
  8. Author:
  9. Revision History:
  10. --*/
  11. #ifndef _POP_
  12. #define _POP_
  13. #ifndef FAR
  14. #define FAR
  15. #endif
  16. #include "ntos.h"
  17. #include "ntiolog.h"
  18. #include "ntiologc.h"
  19. #include "poclass.h"
  20. #include "zwapi.h"
  21. #include "wdmguid.h"
  22. #include "..\io\ioverifier.h"
  23. #define NOEXTAPI
  24. #include "wdbgexts.h"
  25. #include "ntdbg.h"
  26. //
  27. // constants
  28. //
  29. #define PO_IDLE_SCAN_INTERVAL 1 // scan interval in seconds
  30. //
  31. // Values for ios.Parameters.SystemContext
  32. #define POP_NO_CONTEXT 0
  33. #define POP_FLAG_CONTEXT 1 // if true, it's flags
  34. #define POP_DEVICE_REQUEST (0x2 | POP_FLAG_CONTEXT) // an irp sent by RequestPowerChange
  35. #define POP_INRUSH_CONTEXT (0x4 | POP_FLAG_CONTEXT) // the active INRUSH irp
  36. #define POP_COUNT_CONTEXT 0xff000000 // byte used for next counting
  37. #define POP_COUNT_SHIFT 24
  38. //
  39. // pool tags
  40. //
  41. #define POP_DOPE_TAG 'EPOD' // Device Object Power Extension
  42. #define POP_POWI_TAG 'IWOP' // power work item
  43. #define POP_THRM_TAG 'mrhT'
  44. #define POP_PSWT_TAG 'twSP'
  45. #define POP_PSTA_TAG 'atsP'
  46. #define POP_PDSS_TAG 'ssDP'
  47. #define POP_VOLF_TAG 'floV'
  48. #define POP_HMAP_TAG 'pamH'
  49. #define POP_CLON_TAG 'NOLC'
  50. #define POP_HIBR_TAG 'rbih'
  51. #define POP_IDLE_TAG 'eldi'
  52. #define POP_DPC_TAG 'PDNP' // power abort dpc
  53. #define POP_PNCS_TAG 'SCNP' // power channel summary
  54. #define POP_PNSC_TAG 'CSNP' // power notify source
  55. #define POP_PNTG_TAG 'GTNP' // power notify target
  56. #define POP_PNB_TAG ' BNP' // power notify block
  57. // tags used in hiber process
  58. #define POP_MEM_TAG ' meM'
  59. #define POP_DEBUG_RANGE_TAG 'RGBD'
  60. #define POP_DEBUGGER_TAG ' gbD'
  61. #define POP_STACK_TAG 'cats'
  62. #define POP_PCR_TAG ' rcp'
  63. #define POP_PCRB_TAG 'brcp'
  64. #define POP_COMMON_BUFFER_TAG 'fubc'
  65. #define POP_MEMIMAGE_TAG 'gmiM'
  66. #define POP_PACW_TAG 'WcAP'
  67. #define POP_NONO 'ONON' // freed structure, compare with pool
  68. // tag to see what it was
  69. // debugging
  70. #define PopInternalError(a) _PopInternalError( (a << 16) | __LINE__ )
  71. #define POP_SWITCH 1
  72. #define POP_ATTRIB 2
  73. #define POP_NTAPI 3
  74. #define POP_BATT 4
  75. #define POP_THERMAL 5
  76. #define POP_INFO 6
  77. #define POP_MISC 7
  78. #define POP_SYS 8
  79. #define POP_IDLE 9
  80. #define POP_HIBER 10
  81. // bugcheck reason codes
  82. #define DEVICE_DELETED_WITH_POWER_IRPS 1
  83. #define DEVICE_SYSTEM_STATE_HUNG 2
  84. #define DEVICE_IRP_PENDING_ERROR 3
  85. //
  86. // Debug
  87. //
  88. #if DBG
  89. extern ULONG PoDebug;
  90. #define PoPrint(l,m) if(l & PoDebug) DbgPrint m
  91. #else
  92. #define PoPrint(l,m)
  93. #endif
  94. #define PO_ERROR 0x00000001
  95. #define PO_WARN 0x00000002
  96. #define PO_BATT 0x00000004
  97. #define PO_PACT 0x00000008
  98. #define PO_NOTIFY 0x00000010
  99. #define PO_THERM 0x00000020
  100. #define PO_THROTTLE 0x00000040
  101. #define PO_HIBERNATE 0x00000080
  102. #define PO_POCALL 0x00000200
  103. #define PO_SYSDEV 0x00000400
  104. #define PO_THROTTLE_DETAIL 0x10000000
  105. #define PO_THERM_DETAIL 0x20000000
  106. #define PO_SIDLE 0x40000000
  107. #define PO_HIBER_MAP 0x80000000
  108. extern ULONG PopSimulate;
  109. #define POP_SIM_CAPABILITIES 0x00000001
  110. #define POP_SIM_ALL_CAPABILITIES 0x00000002
  111. #define POP_ALLOW_AC_THROTTLE 0x00000004
  112. #define POP_IGNORE_S1 0x00000008
  113. #define POP_IGNORE_UNSUPPORTED_DRIVERS 0x00000010
  114. #define POP_IGNORE_S3 0x00000020
  115. #define POP_IGNORE_S2 0x00000040
  116. #define POP_LOOP_ON_FAILED_DRIVERS 0x00000080
  117. #define POP_CRC_MEMORY 0x00000100
  118. #define POP_IGNORE_CRC_FAILURES 0x00000200
  119. #define POP_TEST_CRC_MEMORY 0x00000400
  120. #define POP_DEBUG_HIBER_FILE 0x00000800
  121. #define POP_RESET_ON_HIBER 0x00001000
  122. #define POP_IGNORE_S4 0x00002000
  123. //#define POP_USE_S4BIOS 0x00004000
  124. #define POP_IGNORE_HIBER_SYMBOL_UNLOAD 0x00008000
  125. #define POP_ENABLE_HIBER_PERF 0x00010000
  126. #define POP_WAKE_DEVICE_AFTER_SLEEP 0x00020000
  127. #define POP_WAKE_DEADMAN 0x00040000
  128. #define POP_FORCE_HIBERNATE_FAILURE 0x00080000
  129. //
  130. // These hold the current values for the power policy
  131. //
  132. extern ULONG PopIdleDefaultMinThrottle;
  133. extern ULONG PopIdleThrottleCheckRate;
  134. extern ULONG PopIdleThrottleCheckTimeout;
  135. extern ULONG PopIdleFrom0Delay;
  136. extern ULONG PopIdleFrom0IdlePercent;
  137. extern ULONG PopIdle0PromoteTicks;
  138. extern ULONG PopIdle0PromoteLimit;
  139. extern ULONG PopIdle0TimeCheck;
  140. extern ULONG PopIdleTimeCheck;
  141. extern ULONG PopIdleTo0Percent;
  142. extern ULONG PopIdleDefaultDemotePercent;
  143. extern ULONG PopIdleDefaultDemoteTime;
  144. extern ULONG PopIdleDefaultPromotePercent;
  145. extern ULONG PopIdleDefaultPromoteTime;
  146. extern ULONG PopIdleDefaultDemoteToC1Percent;
  147. extern ULONG PopIdleDefaultDemoteToC1Time;
  148. extern ULONG PopIdleDefaultPromoteFromC1Percent;
  149. extern ULONG PopIdleDefaultPromoteFromC1Time;
  150. //
  151. // These hold the current values for the throttle policy
  152. //
  153. extern ULONG PopPerfTimeDelta;
  154. extern ULONG PopPerfTimeTicks;
  155. extern ULONG PopPerfCriticalTimeDelta;
  156. extern ULONG PopPerfCriticalTimeTicks;
  157. extern ULONG PopPerfCriticalFrequencyDelta;
  158. extern ULONG PopPerfIncreasePercentModifier;
  159. extern ULONG PopPerfIncreaseAbsoluteModifier;
  160. extern ULONG PopPerfDecreasePercentModifier;
  161. extern ULONG PopPerfDecreaseAbsoluteModifier;
  162. extern ULONG PopPerfIncreaseTimeValue;
  163. extern ULONG PopPerfIncreaseMinimumTime;
  164. extern ULONG PopPerfDecreaseTimeValue;
  165. extern ULONG PopPerfDecreaseMinimumTime;
  166. extern ULONG PopPerfDegradeThrottleMinCapacity;
  167. extern ULONG PopPerfDegradeThrottleMinFrequency;
  168. extern ULONG PopPerfMaxC3Frequency;
  169. //
  170. // Universal Power Data - stored in DeviceObject->DeviceObjectExtension->PowerFlags
  171. //
  172. #define POPF_SYSTEM_STATE 0xf // 4 bits for S0 to S5
  173. #define POPF_DEVICE_STATE 0xf0 // 4 bits to hold D0 to D3
  174. #define POPF_SYSTEM_ACTIVE 0x100 // True if S irp active at this DO
  175. #define POPF_SYSTEM_PENDING 0x200 // True if S irp pending (0x100 must be 1)
  176. #define POPF_DEVICE_ACTIVE 0x400 // same as SYSTEM_ACTIVE but for DEVICE
  177. #define POPF_DEVICE_PENDING 0x800 // same as SYSTEM_PENDING but for DEVICE
  178. #define PopSetDoSystemPowerState(doe, value) \
  179. {doe->PowerFlags &= ~POPF_SYSTEM_STATE; doe->PowerFlags |= (value & POPF_SYSTEM_STATE);}
  180. #define PopGetDoSystemPowerState(doe) \
  181. (doe->PowerFlags & POPF_SYSTEM_STATE)
  182. #define PopSetDoDevicePowerState(doe, value) \
  183. {doe->PowerFlags &= ~POPF_DEVICE_STATE; doe->PowerFlags |= ((value << 4) & POPF_DEVICE_STATE);}
  184. #define PopGetDoDevicePowerState(doe) \
  185. ((doe->PowerFlags & POPF_DEVICE_STATE) >> 4)
  186. DEVICE_POWER_STATE
  187. PopLockGetDoDevicePowerState(
  188. IN PDEVOBJ_EXTENSION Doe
  189. );
  190. //
  191. // Power work queue item declaration
  192. //
  193. //
  194. // Power Irp Serialization data
  195. //
  196. extern KSPIN_LOCK PopIrpSerialLock;
  197. extern LIST_ENTRY PopIrpSerialList;
  198. extern ULONG PopIrpSerialListLength;
  199. extern BOOLEAN PopInrushPending;
  200. extern PIRP PopInrushIrpPointer;
  201. extern LONG PopInrushIrpReferenceCount;
  202. #define PopLockIrpSerialList(OldIrql) \
  203. KeAcquireSpinLock(&PopIrpSerialLock, OldIrql);
  204. #define PopUnlockIrpSerialList(OldIrql) \
  205. KeReleaseSpinLock(&PopIrpSerialLock, OldIrql);
  206. //
  207. // PopSystemIrpDispatchWorker control, etc
  208. //
  209. extern KSPIN_LOCK PopWorkerLock;
  210. extern ULONG PopCallSystemState;
  211. #define PO_CALL_SYSDEV_QUEUE 0x01
  212. #define PO_CALL_NON_PAGED 0x02
  213. extern LIST_ENTRY PopRequestedIrps;
  214. #define PopLockWorkerQueue(OldIrql) \
  215. KeAcquireSpinLock(&PopWorkerLock, OldIrql);
  216. #define PopUnlockWorkerQueue(OldIrql) \
  217. KeReleaseSpinLock(&PopWorkerLock, OldIrql);
  218. //
  219. // Idle Detection State
  220. //
  221. extern KDPC PopIdleScanDpc;
  222. extern LARGE_INTEGER PopIdleScanTime;
  223. extern KTIMER PopIdleScanTimer;
  224. extern LIST_ENTRY PopIdleDetectList;
  225. extern KSPIN_LOCK PopDopeGlobalLock;
  226. #define PopLockDopeGlobal(OldIrql) \
  227. KeAcquireSpinLock(&PopDopeGlobalLock, OldIrql)
  228. #define PopUnlockDopeGlobal(OldIrql) \
  229. KeReleaseSpinLock(&PopDopeGlobalLock, OldIrql)
  230. #define PO_IDLE_CONSERVATION FALSE
  231. #define PO_IDLE_PERFORMANCE TRUE
  232. extern BOOLEAN PopIdleDetectionMode;
  233. //
  234. // Notify structures
  235. //
  236. extern ERESOURCE PopNotifyLock;
  237. extern ULONG PopInvalidNotifyBlockCount;
  238. typedef struct _POWER_CHANNEL_SUMMARY {
  239. ULONG Signature;
  240. ULONG TotalCount;
  241. ULONG D0Count;
  242. LIST_ENTRY NotifyList; // or invalid list entry if invalid
  243. } POWER_CHANNEL_SUMMARY, *PPOWER_CHANNEL_SUMMARY;
  244. typedef struct _DEVICE_OBJECT_POWER_EXTENSION {
  245. // embedded idle control variables
  246. ULONG IdleCount;
  247. ULONG ConservationIdleTime;
  248. ULONG PerformanceIdleTime;
  249. PDEVICE_OBJECT DeviceObject;
  250. LIST_ENTRY IdleList; // our link into global idle list
  251. UCHAR DeviceType;
  252. DEVICE_POWER_STATE State;
  253. // notify vars
  254. LIST_ENTRY NotifySourceList; // Head of list of source structures, one
  255. // element in list for each notify channel
  256. // we support.
  257. LIST_ENTRY NotifyTargetList; // Mirror to sources list.
  258. POWER_CHANNEL_SUMMARY PowerChannelSummary; // record of states of devobjs
  259. // that make up power channel
  260. // misc
  261. LIST_ENTRY Volume;
  262. } DEVICE_OBJECT_POWER_EXTENSION, *PDEVICE_OBJECT_POWER_EXTENSION;
  263. typedef struct _POWER_NOTIFY_BLOCK {
  264. ULONG Signature;
  265. LONG RefCount;
  266. LIST_ENTRY NotifyList;
  267. PPO_NOTIFY NotificationFunction;
  268. PVOID NotificationContext;
  269. ULONG NotificationType;
  270. PPOWER_CHANNEL_SUMMARY PowerChannel;
  271. BOOLEAN Invalidated;
  272. } POWER_NOTIFY_BLOCK, *PPOWER_NOTIFY_BLOCK;
  273. //
  274. // Each devobj which is part of a power channel with a notify posted on it
  275. // has a list of these structurs. PoSetPowerState runs this list to go find
  276. // who to notify
  277. //
  278. typedef struct _POWER_NOTIFY_SOURCE {
  279. ULONG Signature;
  280. LIST_ENTRY List;
  281. struct _POWER_NOTIFY_TARGET *Target;
  282. PDEVICE_OBJECT_POWER_EXTENSION Dope;
  283. } POWER_NOTIFY_SOURCE, *PPOWER_NOTIFY_SOURCE;
  284. //
  285. // There is a target structure for each source structure, the target structure is used
  286. // to find the actual notify list, AND to get back to the source structure for cleanup.
  287. //
  288. typedef struct _POWER_NOTIFY_TARGET {
  289. ULONG Signature;
  290. LIST_ENTRY List;
  291. PPOWER_CHANNEL_SUMMARY ChannelSummary;
  292. PPOWER_NOTIFY_SOURCE Source;
  293. } POWER_NOTIFY_TARGET, *PPOWER_NOTIFY_TARGET;
  294. //
  295. // Policy worker thread
  296. // There is never more then one worker thread of each type. Dispatching is
  297. // is always done via MAIN_POLICY_WORKER type which may then alter its type
  298. // to something else to allow another main policy worker thread to start if
  299. // needed
  300. //
  301. #define PO_WORKER_MAIN 0x00000001
  302. #define PO_WORKER_ACTION_PROMOTE 0x00000002
  303. #define PO_WORKER_ACTION_NORMAL 0x00000004
  304. #define PO_WORKER_NOTIFY 0x00000008
  305. #define PO_WORKER_SYS_IDLE 0x00000010
  306. #define PO_WORKER_TIME_CHANGE 0x00000020
  307. #define PO_WORKER_STATUS 0x80000000
  308. typedef ULONG
  309. (*POP_WORKER_TYPES) (
  310. VOID
  311. );
  312. extern KSPIN_LOCK PopWorkerSpinLock;
  313. extern ULONG PopWorkerStatus;
  314. extern ULONG PopWorkerPending;
  315. extern ULONG PopNotifyEvents;
  316. //
  317. // Policy irp handler
  318. //
  319. typedef VOID
  320. (*POP_IRP_HANDLER) (
  321. IN PDEVICE_OBJECT DeviceObject,
  322. IN PIRP Irp,
  323. IN PVOID Context
  324. );
  325. extern const POP_WORKER_TYPES PopWorkerTypes[];
  326. extern LIST_ENTRY PopPolicyIrpQueue;
  327. extern WORK_QUEUE_ITEM PopPolicyWorker;
  328. //
  329. // Notification bits for policy notifcation worker thread
  330. //
  331. typedef struct {
  332. VOID (*Function)(ULONG);
  333. ULONG Arg;
  334. } POP_NOTIFY_WORK, *PPOP_NOTIFY_WORK;
  335. #define PO_NOTIFY_BUTTON_RECURSE 0x00000001
  336. #define PO_NOTIFY_FULL_WAKE 0x00000002
  337. #define PO_NOTIFY_POLICY_CALLBACK 0x00000004
  338. #define PO_NOTIFY_ACDC_CALLBACK 0x00000008
  339. #define PO_NOTIFY_POLICY 0x00000010
  340. #define PO_NOTIFY_DISPLAY_REQUIRED 0x00000020
  341. #define PO_NOTIFY_BATTERY_STATUS 0x00000040
  342. #define PO_NOTIFY_EVENT_CODES 0x00000080
  343. #define PO_NOTIFY_CAPABILITIES 0x00000100
  344. #define PO_NOTIFY_STATE_FAILURE 0x00000200
  345. #define PO_NOTIFY_PROCESSOR_POLICY_CALLBACK 0x00000400
  346. #define PO_NOTIFY_PROCESSOR_POLICY 0x00000800
  347. #define PO_NUMBER_NOTIFY 12
  348. #define POP_MAX_EVENT_CODES 4
  349. extern ULONG PopEventCode[];
  350. extern BOOLEAN PopDispatchPolicyIrps;
  351. //
  352. // Types for POP_ACTION_TRIGGER
  353. //
  354. typedef enum {
  355. PolicyDeviceSystemButton,
  356. PolicyDeviceThermalZone,
  357. PolicyDeviceBattery,
  358. PolicyInitiatePowerActionAPI,
  359. PolicySetPowerStateAPI,
  360. PolicyImmediateDozeS4,
  361. PolicySystemIdle
  362. } POP_POLICY_DEVICE_TYPE;
  363. //
  364. // Types of sleep promotion/substitution.
  365. //
  366. typedef enum {
  367. //
  368. // Power state is lightened until all alternatives have been exhausted.
  369. //
  370. SubstituteLightenSleep,
  371. //
  372. // Power state is lightened until all alternatives have been exhausted. If
  373. // no alternatives were available, lightest overall *sleeping* state is
  374. // chosen (bounded between S1 and S3.)
  375. //
  376. SubstituteLightestOverallDownwardBounded,
  377. //
  378. // Power state is deepened until it is advanced beyond PowerSystemHibernate,
  379. // in which case all alternatives have been exhausted.
  380. //
  381. SubstituteDeepenSleep
  382. } POP_SUBSTITUTION_POLICY;
  383. //
  384. // Wait structure for synchronous triggers
  385. //
  386. typedef struct _POP_TRIGGER_WAIT {
  387. KEVENT Event;
  388. NTSTATUS Status;
  389. LIST_ENTRY Link;
  390. struct _POP_ACTION_TRIGGER *Trigger;
  391. } POP_TRIGGER_WAIT, *PPOP_TRIGGER_WAIT;
  392. //
  393. // Trigger state for something which causes an action
  394. //
  395. typedef struct _POP_ACTION_TRIGGER {
  396. POP_POLICY_DEVICE_TYPE Type;
  397. UCHAR Flags;
  398. UCHAR Spare[3];
  399. union {
  400. struct {
  401. ULONG Level;
  402. } Battery;
  403. PPOP_TRIGGER_WAIT Wait;
  404. } ;
  405. } POP_ACTION_TRIGGER, *PPOP_ACTION_TRIGGER;
  406. #define PO_TRG_USER 0x01 // User action initiated
  407. #define PO_TRG_SYSTEM 0x02 // System action initiated
  408. #define PO_TRG_SYNC 0x20 // Trigger is synchronous
  409. #define PO_TRG_SET 0x80 // Event enabled or disabled
  410. //
  411. // Structure to track systems power state for policy manager
  412. // from composite battery device
  413. //
  414. #define PO_NUM_POWER_LEVELS 4
  415. typedef struct _POP_COMPOSITE_BATTERY {
  416. //
  417. // State of composite battery processing
  418. //
  419. UCHAR State;
  420. UCHAR Spare[3];
  421. //
  422. // Connection to composite battery
  423. //
  424. ULONG Tag;
  425. //
  426. // Battery status and time it was valid
  427. //
  428. ULONGLONG StatusTime;
  429. BATTERY_STATUS Status;
  430. //
  431. // Battery trigger flags to indicate which discharge
  432. // actions have already fired
  433. //
  434. POP_ACTION_TRIGGER Trigger[PO_NUM_POWER_LEVELS];
  435. //
  436. // Battery estimated time and time it was computed
  437. //
  438. ULONGLONG EstTimeTime;
  439. ULONG EstTime; // from battery
  440. ULONG AdjustedEstTime;
  441. //
  442. // Battery information
  443. //
  444. BATTERY_INFORMATION Info;
  445. //
  446. // Info on outstanding status request to composite battery
  447. //
  448. PIRP StatusIrp;
  449. union {
  450. ULONG Tag;
  451. ULONG EstTime;
  452. BATTERY_STATUS Status;
  453. BATTERY_INFORMATION Info;
  454. BATTERY_WAIT_STATUS Wait;
  455. BATTERY_QUERY_INFORMATION QueryInfo;
  456. } u;
  457. //
  458. // Info for threads to wait for the current power state to
  459. // be computed.
  460. //
  461. BOOLEAN ThreadWaiting;
  462. KEVENT Event;
  463. } POP_COMPOSITE_BATTERY;
  464. // state values for POP_COMOSITE_BATTERY.State
  465. #define PO_CB_NONE 0
  466. #define PO_CB_READ_TAG 1
  467. #define PO_CB_WAIT_TAG 2
  468. #define PO_CB_READ_INFO 3
  469. #define PO_CB_READ_STATUS 4
  470. #define PO_CB_READ_EST_TIME 5
  471. #define PO_MAX_CB_CACHE_TIME 50000000 // 5 seconds
  472. extern POP_COMPOSITE_BATTERY PopCB;
  473. //
  474. // Structure to track thermal zone state
  475. //
  476. typedef struct _POP_THERMAL_ZONE {
  477. //
  478. // List of all thermal zones
  479. //
  480. LIST_ENTRY Link;
  481. //
  482. // Current state with driver
  483. //
  484. UCHAR State;
  485. UCHAR Flags;
  486. //
  487. // Cooling mode of thermal zone
  488. //
  489. UCHAR Mode;
  490. UCHAR PendingMode;
  491. //
  492. // Active cooling
  493. //
  494. UCHAR ActivePoint;
  495. UCHAR PendingActivePoint;
  496. //
  497. // Passive cooling state
  498. //
  499. LONG Throttle;
  500. ULONGLONG LastTime;
  501. ULONG SampleRate;
  502. ULONG LastTemp;
  503. KTIMER PassiveTimer;
  504. KDPC PassiveDpc;
  505. POP_ACTION_TRIGGER OverThrottled;
  506. //
  507. // Irp for talking with the thermal driver
  508. //
  509. PIRP Irp;
  510. //
  511. // Thermal info being read
  512. //
  513. THERMAL_INFORMATION Info;
  514. } POP_THERMAL_ZONE, *PPOP_THERMAL_ZONE;
  515. // POP_THERMAL_ZONE.State
  516. #define PO_TZ_NO_STATE 0
  517. #define PO_TZ_READ_STATE 1
  518. #define PO_TZ_SET_MODE 2
  519. #define PO_TZ_SET_ACTIVE 3
  520. // POP_THERMAL_ZONE.Flags
  521. #define PO_TZ_THROTTLING 0x01
  522. #define PO_TZ_CLEANUP 0x80
  523. #define PO_TZ_THROTTLE_SCALE 10 // temp reported in 1/10ths kelin
  524. #define PO_TZ_NO_THROTTLE (100 * PO_TZ_THROTTLE_SCALE)
  525. // PopCoolingMode
  526. #define PO_TZ_ACTIVE 0
  527. #define PO_TZ_PASSIVE 1
  528. #define PO_TZ_INVALID_MODE 2
  529. //
  530. // Action timeouts
  531. //
  532. #define POP_ACTION_TIMEOUT 30
  533. #define POP_ACTION_CANCEL_TIMEOUT 5
  534. //
  535. // Structure to track button & lid devices
  536. //
  537. typedef struct _POP_SWITCH_DEVICE {
  538. //
  539. // List of all switch devices
  540. //
  541. LIST_ENTRY Link;
  542. //
  543. // Current status
  544. //
  545. BOOLEAN GotCaps;
  546. BOOLEAN IsInitializing;
  547. BOOLEAN IsFailed;
  548. UCHAR TriggerState;
  549. ULONG IrpBuffer;
  550. ULONG Caps;
  551. //
  552. // Only valid for switches that
  553. // trigger both opening and shutting.
  554. // I.e. a lid switch.
  555. //
  556. BOOLEAN Opened;
  557. } POP_SWITCH_DEVICE, *PPOP_SWITCH_DEVICE;
  558. //
  559. // Bookkeeping for Thread->PowerState and registered attributes set in the system
  560. //
  561. typedef struct {
  562. ULONG Count;
  563. VOID (*Set)(ULONG);
  564. BOOLEAN NotifyOnClear;
  565. ULONG Arg;
  566. } POP_STATE_ATTRIBUTE, *PPOP_STATE_ATTRIBUTE;
  567. #define POP_SYSTEM_ATTRIBUTE 0
  568. #define POP_DISPLAY_ATTRIBUTE 1
  569. #define POP_USER_ATTRIBUTE 2
  570. #define POP_LOW_LATENCY_ATTRIBUTE 3
  571. #define POP_DISK_SPINDOWN_ATTRIBUTE 4
  572. #define POP_NUMBER_ATTRIBUTES 5
  573. extern POP_STATE_ATTRIBUTE PopAttributes[];
  574. // Flags for Thread->PowerState
  575. // ES_SYSTEM_REQUIRED, ES_DISPLAY_REQUIRED
  576. // Internal attrib flags
  577. // NOTE: this flags are stored in the same flags values as ES_ flags, so they
  578. // can not overlapped
  579. #define POP_LOW_LATENCY 0x08
  580. #define POP_DISK_SPINDOWN 0x10
  581. //
  582. // Presistant settings and heuristics which are not part of the
  583. // saved policy structures
  584. //
  585. typedef struct {
  586. ULONG Version;
  587. BOOLEAN Dirty;
  588. BOOLEAN GetDumpStackVerified;
  589. BOOLEAN HiberFileEnabled;
  590. //
  591. // System idle heuristics
  592. //
  593. ULONG IoTransferTotal;
  594. ULONG IoTransferSamples;
  595. ULONG IoTransferWeight;
  596. } POP_HEURISTICS, *PPOP_HEURISTICS;
  597. extern POP_HEURISTICS PopHeuristics;
  598. //
  599. // Version 2 of the heuristics was always starting off
  600. // with IoTransferWeight set to 99999. This is way too
  601. // high and takes quite a while to get down to a reasonable
  602. // level. With version three, we are smart enough to treat
  603. // IoTransferSamples==0 as the starting point and start off
  604. // much closer to reality.
  605. //
  606. // Version 3 of the heuristics were all built with garbage
  607. // values for IoTransferWeight since the IoOtherTransfers
  608. // counter is using pointers as values. So we upgrade that
  609. // version as well.
  610. //
  611. // Version 4 of the heuristics has the IoOtherTransfers removed.
  612. //
  613. // Version 5 of the heuristics is the current version and is built
  614. // with the corrected IoOtherTransfers.
  615. //
  616. // When a version 2, 3, or 4 heuristics is loaded from the registry,
  617. // we upgrade it to 5, and zero the IoTransferSamples.
  618. //
  619. #define POP_HEURISTICS_VERSION_CLEAR_TRANSFER 0x04
  620. #define POP_HEURISTICS_VERSION 0x05
  621. typedef struct _POP_SHUTDOWN_BUG_CHECK {
  622. ULONG Code;
  623. ULONG_PTR Parameter1;
  624. ULONG_PTR Parameter2;
  625. ULONG_PTR Parameter3;
  626. ULONG_PTR Parameter4;
  627. } POP_SHUTDOWN_BUG_CHECK, *PPOP_SHUTDOWN_BUG_CHECK;
  628. //
  629. // Memory map information
  630. //
  631. typedef struct _POP_MEMORY_RANGE {
  632. LIST_ENTRY Link;
  633. ULONG Tag;
  634. PFN_NUMBER StartPage;
  635. PFN_NUMBER EndPage;
  636. PVOID CloneVa;
  637. } POP_MEMORY_RANGE, *PPOP_MEMORY_RANGE;
  638. //
  639. // Attention: not exceed HIBER_PTES in boot\inc\bldr.h
  640. //
  641. #define POP_MAX_MDL_SIZE 16
  642. #define PO_MAX_MAPPED_CLONES (64*1024*1024)
  643. #define POP_FREE_THRESHOLD 256 // Leave 1MB to 2MB on the free list
  644. #define POP_FREE_ALLOCATE_SIZE 128 // allocate 512kb at a time
  645. typedef struct _POP_HIBER_CONTEXT {
  646. //
  647. // Flags which control the type of hiber operation
  648. //
  649. BOOLEAN WriteToFile;
  650. BOOLEAN ReserveLoaderMemory;
  651. BOOLEAN ReserveFreeMemory;
  652. BOOLEAN VerifyOnWake;
  653. BOOLEAN Reset;
  654. UCHAR HiberFlags;
  655. //
  656. // Hibernate link file
  657. //
  658. BOOLEAN LinkFile;
  659. HANDLE LinkFileHandle;
  660. //
  661. // Map of memory pages and how they should be handled
  662. // during the hibernate operation
  663. //
  664. KSPIN_LOCK Lock;
  665. BOOLEAN MapFrozen;
  666. RTL_BITMAP MemoryMap;
  667. LIST_ENTRY ClonedRanges;
  668. ULONG ClonedRangeCount;
  669. //
  670. // placeholders for enumerating through the ranges
  671. //
  672. PLIST_ENTRY NextCloneRange;
  673. PFN_NUMBER NextPreserve;
  674. //
  675. // Pages of memory collected out of the system
  676. //
  677. PMDL LoaderMdl;
  678. PMDL Clones;
  679. PUCHAR NextClone;
  680. PFN_NUMBER NoClones;
  681. PMDL Spares;
  682. ULONGLONG PagesOut;
  683. //
  684. // hiber file io
  685. //
  686. PVOID IoPage;
  687. PVOID CurrentMcb;
  688. PDUMP_STACK_CONTEXT DumpStack;
  689. PKPROCESSOR_STATE WakeState;
  690. //
  691. // Misc
  692. //
  693. ULONG NoRanges;
  694. ULONG_PTR HiberVa;
  695. PHYSICAL_ADDRESS HiberPte;
  696. NTSTATUS Status;
  697. //
  698. // For generating the image
  699. //
  700. PPO_MEMORY_IMAGE MemoryImage;
  701. PPO_MEMORY_RANGE_ARRAY TableHead;
  702. // Compression
  703. PUCHAR CompressionWorkspace;
  704. PUCHAR CompressedWriteBuffer;
  705. PULONG PerformanceStats; // Performance Stats
  706. PVOID CompressionBlock; // It's of COMPRESSION_BLOCK type (see hiber.c)
  707. PVOID DmaIO; // It's of IOREGIONS type (see hiber.c)
  708. PVOID TemporaryHeap; // It's of POP_HIBER_HEAP type (see hiber.c)
  709. //
  710. // Perf info
  711. //
  712. PO_HIBER_PERF PerfInfo;
  713. } POP_HIBER_CONTEXT, *PPOP_HIBER_CONTEXT;
  714. extern ULONG PopMaxPageRun;
  715. extern BOOLEAN PoHiberInProgress;
  716. extern BOOLEAN PopFailedHibernationAttempt; // we tried to hibernate and failed.
  717. typedef struct {
  718. HANDLE FileHandle;
  719. PFILE_OBJECT FileObject;
  720. PFN_NUMBER FilePages;
  721. PLARGE_INTEGER NonPagedMcb;
  722. PLARGE_INTEGER PagedMcb;
  723. ULONG McbSize;
  724. ULONG McbCheck;
  725. } POP_HIBER_FILE, *PPOP_HIBER_FILE;
  726. extern POP_HIBER_FILE PopHiberFile;
  727. extern POP_HIBER_FILE PopHiberFileDebug;
  728. //
  729. // Policy manager action in progress state
  730. //
  731. #define MAX_SYSTEM_POWER_IRPS 20
  732. typedef struct _POP_DEVICE_POWER_IRP {
  733. SINGLE_LIST_ENTRY Free;
  734. PIRP Irp;
  735. PPO_DEVICE_NOTIFY Notify;
  736. LIST_ENTRY Pending;
  737. LIST_ENTRY Complete;
  738. LIST_ENTRY Abort;
  739. LIST_ENTRY Failed;
  740. } POP_DEVICE_POWER_IRP, *PPOP_DEVICE_POWER_IRP;
  741. typedef struct _POP_DEVICE_SYS_STATE {
  742. //
  743. // Current device notification
  744. //
  745. UCHAR IrpMinor;
  746. SYSTEM_POWER_STATE SystemState;
  747. //
  748. // Device notification synchronization
  749. //
  750. KEVENT Event;
  751. KSPIN_LOCK SpinLock;
  752. PKTHREAD Thread;
  753. //
  754. // Notification list
  755. //
  756. BOOLEAN GetNewDeviceList;
  757. PO_DEVICE_NOTIFY_ORDER Order;
  758. //
  759. // Current device notification state
  760. //
  761. NTSTATUS Status;
  762. PDEVICE_OBJECT FailedDevice;
  763. BOOLEAN Waking;
  764. BOOLEAN Cancelled;
  765. BOOLEAN IgnoreErrors;
  766. BOOLEAN IgnoreNotImplemented;
  767. BOOLEAN WaitAny;
  768. BOOLEAN WaitAll;
  769. //
  770. // PoCall's present irp queue for pagable irp
  771. //
  772. LIST_ENTRY PresentIrpQueue;
  773. //
  774. // Head pointers
  775. //
  776. POP_DEVICE_POWER_IRP Head;
  777. //
  778. // Structure to track each outstanding device power irp
  779. //
  780. POP_DEVICE_POWER_IRP PowerIrpState[MAX_SYSTEM_POWER_IRPS];
  781. } POP_DEVICE_SYS_STATE, *PPOP_DEVICE_SYS_STATE;
  782. typedef struct _POP_POWER_ACTION {
  783. //
  784. // Current state of power action
  785. //
  786. UCHAR Updates;
  787. UCHAR State;
  788. BOOLEAN Shutdown;
  789. //
  790. // Current desired power action
  791. //
  792. POWER_ACTION Action;
  793. SYSTEM_POWER_STATE LightestState;
  794. ULONG Flags;
  795. NTSTATUS Status;
  796. UCHAR IrpMinor;
  797. SYSTEM_POWER_STATE SystemState;
  798. SYSTEM_POWER_STATE NextSystemState;
  799. PPOP_SHUTDOWN_BUG_CHECK ShutdownBugCode;
  800. //
  801. // Current state of device notifiations for the system state
  802. //
  803. PPOP_DEVICE_SYS_STATE DevState;
  804. //
  805. // Hibernation context
  806. //
  807. PPOP_HIBER_CONTEXT HiberContext;
  808. //
  809. // For debugging. The last state which worked and when
  810. //
  811. SYSTEM_POWER_STATE LastWakeState;
  812. ULONGLONG WakeTime;
  813. ULONGLONG SleepTime;
  814. } POP_POWER_ACTION, *PPOP_POWER_ACTION;
  815. //
  816. // PO_PM_USER - Update to action which effects usermode, but if the current
  817. // operation is passed to NtSetSystemPowerState or happens to complete, these
  818. // updates can be ignored
  819. //
  820. // PO_PM_REISSUE - Update to the action which effects the system.
  821. //
  822. // PO_PM_SETSTATE - Update to the action which effects NtSetSystemPowerState
  823. //
  824. #define PO_PM_USER 0x01 // nice to inform user mode, but not needed
  825. #define PO_PM_REISSUE 0x02 // sleep promotoed to shutdown
  826. #define PO_PM_SETSTATE 0x04 // recomputed something to do with the viable state
  827. #define PO_ACT_IDLE 0
  828. #define PO_ACT_NEW_REQUEST 1
  829. #define PO_ACT_CALLOUT 2
  830. #define PO_ACT_SET_SYSTEM_STATE 3
  831. extern POP_POWER_ACTION PopAction;
  832. extern LIST_ENTRY PopActionWaiters;
  833. //
  834. //
  835. //
  836. extern ULONG PopFullWake;
  837. #define PO_FULL_WAKE_STATUS 0x01
  838. #define PO_FULL_WAKE_PENDING 0x02
  839. #define PO_GDI_STATUS 0x04
  840. #define PO_GDI_ON_PENDING 0x08
  841. #define AllBitsSet(a,b) ( ((a) & (b)) == (b) )
  842. #define AnyBitsSet(a,b) ( (a) & (b) )
  843. //
  844. // Misc constants
  845. //
  846. #define PO_NO_FORCED_THROTTLE 100
  847. #define PO_NO_FAN_THROTTLE 100
  848. #define PO_MAX_FAN_THROTTLE 20
  849. #define PO_MIN_MIN_THROTTLE 20
  850. #define PO_MIN_IDLE_TIMEOUT 60
  851. #define PO_MIN_IDLE_SENSITIVITY 10
  852. //
  853. // Processor idle handler info
  854. //
  855. typedef struct _POP_IDLE_HANDLER {
  856. ULONG Latency;
  857. ULONG TimeCheck;
  858. ULONG DemoteLimit;
  859. ULONG PromoteLimit;
  860. ULONG PromoteCount;
  861. UCHAR Demote;
  862. UCHAR Promote;
  863. UCHAR PromotePercent;
  864. UCHAR DemotePercent;
  865. UCHAR State;
  866. UCHAR Spare[3];
  867. PPROCESSOR_IDLE_HANDLER IdleFunction;
  868. } POP_IDLE_HANDLER, *PPOP_IDLE_HANDLER;
  869. #define MAX_IDLE_HANDLER 3
  870. #define PO_IDLE_COMPLETE_DEMOTION (0)
  871. #define PO_IDLE_THROTTLE_PROMOTION (MAX_IDLE_HANDLER+1)
  872. #define US2TIME 10L // scale microseconds by 10 to get 100ns
  873. #define US2SEC 1000000L
  874. #define MAXSECCHECK 10L // max wait below is 10s
  875. typedef struct _POP_SYSTEM_IDLE {
  876. //
  877. // Current idle settings
  878. //
  879. LONG Idleness;
  880. ULONG Time;
  881. ULONG Timeout;
  882. ULONG Sensitivity;
  883. POWER_ACTION_POLICY Action;
  884. SYSTEM_POWER_STATE MinState;
  885. //
  886. // Current idle stats
  887. //
  888. BOOLEAN IdleWorker;
  889. BOOLEAN Sampling;
  890. ULONGLONG LastTick;
  891. ULONGLONG LastIoTransfer;
  892. ULONG LastIoCount;
  893. } POP_SYSTEM_IDLE, *PPOP_SYSTEM_IDLE;
  894. //
  895. // System idle worker once every 15 seconds.
  896. // N.B. value must divide into 60secs evenly
  897. //
  898. #define SYS_IDLE_WORKER 15 // 15 seconds
  899. #define SYS_IDLE_CHECKS_PER_MIN (60/SYS_IDLE_WORKER)
  900. #define SYS_IDLE_SAMPLES 240 // 1hr worth of samples
  901. #define SYS_IDLE_IO_SCALER 100
  902. // defaults for system idle detection on a system wake used
  903. // to re-enter a system sleep when a full wake does not occur
  904. #define SYS_IDLE_REENTER_SENSITIVITY 80
  905. #define SYS_IDLE_REENTER_TIMEOUT (2*60) // 2 minutes
  906. #define SYS_IDLE_REENTER_TIMEOUT_S4 (5*60) // 5 minutes
  907. extern POP_SYSTEM_IDLE PopSIdle;
  908. extern SYSTEM_POWER_POLICY PopAcPolicy;
  909. extern SYSTEM_POWER_POLICY PopDcPolicy;
  910. extern PSYSTEM_POWER_POLICY PopPolicy;
  911. extern PROCESSOR_POWER_POLICY PopAcProcessorPolicy;
  912. extern PROCESSOR_POWER_POLICY PopDcProcessorPolicy;
  913. extern PPROCESSOR_POWER_POLICY PopProcessorPolicy;
  914. extern POWER_STATE_HANDLER PopPowerStateHandlers[];
  915. extern POWER_STATE_NOTIFY_HANDLER PopPowerStateNotifyHandler;
  916. extern const POP_NOTIFY_WORK PopNotifyWork[];
  917. extern PPOP_IDLE_HANDLER PopIdle;
  918. extern NPAGED_LOOKASIDE_LIST PopIdleHandlerLookAsideList;
  919. extern KEVENT PopDumbyEvent;
  920. extern PCALLBACK_OBJECT PopPowerStateCallback;
  921. extern ADMINISTRATOR_POWER_POLICY PopAdminPolicy;
  922. extern const WCHAR PopRegKey[];
  923. extern const WCHAR PopAcRegName[];
  924. extern const WCHAR PopDcRegName[];
  925. extern const WCHAR PopAdminRegName[];
  926. extern const WCHAR PopUndockPolicyRegName[];
  927. extern const WCHAR PopHeuristicsRegName[];
  928. extern const WCHAR PopCompositeBatteryName[];
  929. extern const WCHAR PopSimulateRegKey[];
  930. extern const WCHAR PopSimulateRegName[];
  931. extern const WCHAR PopHiberFileName[];
  932. extern const WCHAR PopDebugHiberFileName[];
  933. extern const WCHAR PopDumpStackPrefix[];
  934. extern const WCHAR PopApmActiveFlag[];
  935. extern const WCHAR PopApmFlag[];
  936. extern const WCHAR PopAcProcessorRegName[];
  937. extern const WCHAR PopDcProcessorRegName[];
  938. extern LIST_ENTRY PopSwitches;
  939. extern LIST_ENTRY PopThermal;
  940. extern KSPIN_LOCK PopThermalLock;
  941. extern ULONG PopCoolingMode;
  942. extern ULONG PopLowLatency;
  943. extern ULONG PopSystemIdleTime;
  944. extern PKWIN32_POWEREVENT_CALLOUT PopEventCallout;
  945. extern PKWIN32_POWERSTATE_CALLOUT PopStateCallout;
  946. extern WORK_QUEUE_ITEM PopUserPresentWorkItem;
  947. extern WORK_QUEUE_ITEM PopUnlockAfterSleepWorkItem;
  948. extern KEVENT PopUnlockComplete;
  949. VOID
  950. PopEventCalloutDispatch (
  951. IN PSPOWEREVENTTYPE EventNumber,
  952. IN ULONG_PTR Code
  953. );
  954. extern LIST_ENTRY PopVolumeDevices;
  955. //
  956. // Undocking policy info
  957. //
  958. typedef struct _UNDOCK_POWER_RESTRICTIONS {
  959. ULONG Version;
  960. ULONG Size;
  961. ULONG HotUndockMinimumCapacity; // In percent
  962. ULONG SleepUndockMinimumCapacity; // In percent
  963. } UNDOCK_POWER_RESTRICTIONS, *PUNDOCK_POWER_RESTRICTIONS;
  964. #define SIZEOF_PARTIAL_INFO_HEADER \
  965. FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data)
  966. #define SIZEOF_EJECT_PARTIAL_INFO \
  967. SIZEOF_PARTIAL_INFO_HEADER + sizeof(UNDOCK_POWER_RESTRICTIONS)
  968. //
  969. // Prototypes
  970. //
  971. extern ERESOURCE PopPolicyLock;
  972. extern PKTHREAD PopPolicyLockThread;
  973. #if DBG
  974. #define ASSERT_POLICY_LOCK_OWNED() PopAssertPolicyLockOwned()
  975. #else
  976. #define ASSERT_POLICY_LOCK_OWNED()
  977. #endif
  978. extern FAST_MUTEX PopVolumeLock;
  979. #define PopAcquireVolumeLock() ExAcquireFastMutex(&PopVolumeLock)
  980. #define PopReleaseVolumeLock() ExReleaseFastMutex(&PopVolumeLock)
  981. #define ClearMember(Member, Set) \
  982. Set = Set & (~(1 << (Member)))
  983. #if defined(_WIN64)
  984. #define InterlockedOrAffinity(Target, Set) { \
  985. LONGLONG _i, _j; \
  986. _j = (*Target); \
  987. do { \
  988. _i = _j; \
  989. _j = InterlockedCompareExchange64((Target), \
  990. (_i | (Set)), \
  991. _i); \
  992. } while (_i != _j) ; \
  993. }
  994. #else
  995. #define InterlockedOrAffinity(Target, Set) InterlockedOr(Target, Set)
  996. #endif // defined(_WIN64)
  997. #if defined(_WIN64)
  998. #define InterlockedAndAffinity(Target, Set) { \
  999. LONGLONG _i, _j; \
  1000. _j = (*Target); \
  1001. do { \
  1002. _i = _j; \
  1003. _j = InterlockedCompareExchange64((Target), \
  1004. (_i & (Set)), \
  1005. _i); \
  1006. } while (_i != _j) ; \
  1007. }
  1008. #else
  1009. #define InterlockedAndAffinity(Target, Set) InterlockedAnd(Target, Set)
  1010. #endif // defined(_WIN64)
  1011. // attrib.c
  1012. VOID
  1013. PopApplyAttributeState (
  1014. IN ULONG NewFlag,
  1015. IN ULONG OldFlag
  1016. );
  1017. VOID
  1018. PopAttribNop (
  1019. IN ULONG Arg
  1020. );
  1021. VOID
  1022. PopSystemRequiredSet (
  1023. IN ULONG Arg
  1024. );
  1025. VOID
  1026. PopDisplayRequired (
  1027. IN ULONG Arg
  1028. );
  1029. VOID
  1030. PopUserPresentSet (
  1031. IN ULONG Arg
  1032. );
  1033. // pocall.c
  1034. VOID
  1035. PopSystemIrpDispatchWorker(
  1036. IN BOOLEAN LastCall
  1037. );
  1038. PIRP
  1039. PopFindIrpByDeviceObject(
  1040. PDEVICE_OBJECT DeviceObject,
  1041. POWER_STATE_TYPE Type
  1042. );
  1043. VOID
  1044. PopSystemIrpsActive (
  1045. VOID
  1046. );
  1047. // hiber.c
  1048. NTSTATUS
  1049. PopEnableHiberFile (
  1050. IN BOOLEAN Enable
  1051. );
  1052. VOID
  1053. PopCloneStack (
  1054. IN PPOP_HIBER_CONTEXT HiberContext
  1055. );
  1056. NTSTATUS
  1057. PopAllocateHiberContext (
  1058. VOID
  1059. );
  1060. VOID
  1061. PopFreeHiberContext (
  1062. BOOLEAN ContextBlock
  1063. );
  1064. NTSTATUS
  1065. PopBuildMemoryImageHeader (
  1066. IN PPOP_HIBER_CONTEXT HiberContext,
  1067. IN SYSTEM_POWER_STATE SystemState
  1068. );
  1069. NTSTATUS
  1070. PopSaveHiberContext (
  1071. IN PPOP_HIBER_CONTEXT HiberContext
  1072. );
  1073. VOID
  1074. PopHiberComplete (
  1075. IN NTSTATUS Status,
  1076. IN PPOP_HIBER_CONTEXT HiberContext
  1077. );
  1078. VOID
  1079. PopFixContext (
  1080. OUT PCONTEXT Context
  1081. );
  1082. ULONG
  1083. PopGatherMemoryForHibernate (
  1084. IN PPOP_HIBER_CONTEXT HiberContext,
  1085. IN PFN_NUMBER NoPages,
  1086. IN PMDL *Mdl,
  1087. IN BOOLEAN Wait
  1088. );
  1089. // idle.c
  1090. VOID
  1091. PopScanIdleList (
  1092. IN PKDPC Dpc,
  1093. IN PVOID DeferredContext,
  1094. IN PVOID SystemArgument1,
  1095. IN PVOID SystemArgument2
  1096. );
  1097. PDEVICE_OBJECT_POWER_EXTENSION
  1098. PopGetDope(
  1099. IN PDEVICE_OBJECT DeviceObject
  1100. );
  1101. // misc.c
  1102. VOID
  1103. FASTCALL
  1104. PopInternalAddToDumpFile (
  1105. IN OPTIONAL PVOID DataBlock,
  1106. IN OPTIONAL ULONG DataBlockSize,
  1107. IN OPTIONAL PDEVICE_OBJECT DeviceObject,
  1108. IN OPTIONAL PDRIVER_OBJECT DriverObject,
  1109. IN OPTIONAL PDEVOBJ_EXTENSION Doe,
  1110. IN OPTIONAL PDEVICE_OBJECT_POWER_EXTENSION Dope
  1111. );
  1112. VOID
  1113. FASTCALL
  1114. _PopInternalError (
  1115. IN ULONG BugCode
  1116. );
  1117. #if DBG
  1118. VOID
  1119. PopAssertPolicyLockOwned(
  1120. VOID
  1121. );
  1122. #endif
  1123. NTSTATUS
  1124. PopAttachToSystemProcess (
  1125. VOID
  1126. );
  1127. #define PopSetCapability(_pflag_) PopChangeCapability(_pflag_, TRUE)
  1128. #define PopClearCapability(_pflag_) PopChangeCapability(_pflag_, FALSE)
  1129. VOID
  1130. PopChangeCapability(
  1131. IN PBOOLEAN PresentFlag,
  1132. IN BOOLEAN IsPresent
  1133. );
  1134. EXCEPTION_DISPOSITION
  1135. PopExceptionFilter (
  1136. IN PEXCEPTION_POINTERS ExceptionInformation,
  1137. IN BOOLEAN AllowRaisedException
  1138. );
  1139. VOID
  1140. PopSaveHeuristics (
  1141. VOID
  1142. );
  1143. PUCHAR
  1144. PopSystemStateString (
  1145. IN SYSTEM_POWER_STATE SystemState
  1146. );
  1147. #if DBG
  1148. PUCHAR
  1149. PopPowerActionString (
  1150. IN POWER_ACTION PowerAction
  1151. );
  1152. #endif
  1153. NTSTATUS
  1154. PopOpenPowerKey (
  1155. OUT PHANDLE handle
  1156. );
  1157. VOID
  1158. PopInitializePowerPolicySimulate(
  1159. VOID
  1160. );
  1161. VOID
  1162. PopUnlockAfterSleepWorker(
  1163. IN PVOID NotUsed
  1164. );
  1165. // paction.c
  1166. VOID
  1167. PopCriticalShutdown (
  1168. POP_POLICY_DEVICE_TYPE Type
  1169. );
  1170. VOID
  1171. PopSetPowerAction (
  1172. IN PPOP_ACTION_TRIGGER Trigger,
  1173. IN ULONG UserNotify,
  1174. IN PPOWER_ACTION_POLICY ActionPolicy,
  1175. IN SYSTEM_POWER_STATE LightestState,
  1176. IN POP_SUBSTITUTION_POLICY SubstitutionPolicy
  1177. );
  1178. LONG
  1179. PopCompareActions(
  1180. POWER_ACTION FutureAction,
  1181. POWER_ACTION CurrentAction
  1182. );
  1183. ULONG
  1184. PopPolicyWorkerAction (
  1185. VOID
  1186. );
  1187. ULONG
  1188. PopPolicyWorkerActionPromote (
  1189. VOID
  1190. );
  1191. VOID
  1192. PopResetActionDefaults(
  1193. VOID
  1194. );
  1195. VOID
  1196. PopActionRetrieveInitialState(
  1197. IN OUT PSYSTEM_POWER_STATE LightestSystemState,
  1198. OUT PSYSTEM_POWER_STATE DeepestSystemState,
  1199. OUT PSYSTEM_POWER_STATE InitialSystemState,
  1200. OUT PBOOLEAN QueryDevices
  1201. );
  1202. // pbatt.c
  1203. VOID
  1204. PopCompositeBatteryDeviceHandler (
  1205. IN PDEVICE_OBJECT DeviceObject,
  1206. IN PIRP Irp,
  1207. IN PVOID Context
  1208. );
  1209. NTSTATUS
  1210. PopCurrentPowerState (
  1211. OUT PSYSTEM_BATTERY_STATE PowerState
  1212. );
  1213. VOID
  1214. PopResetCBTriggers (
  1215. UCHAR Flags
  1216. );
  1217. // switch.c
  1218. VOID
  1219. PopLidHandler (
  1220. IN PDEVICE_OBJECT DeviceObject,
  1221. IN PIRP Irp,
  1222. IN PVOID Context
  1223. );
  1224. VOID
  1225. PopSystemButtonHandler (
  1226. IN PDEVICE_OBJECT DeviceObject,
  1227. IN PIRP Irp,
  1228. IN PVOID Context
  1229. );
  1230. VOID
  1231. PopResetSwitchTriggers (
  1232. VOID
  1233. );
  1234. // pidle.c
  1235. VOID
  1236. PopInitProcessorStateHandlers (
  1237. IN PPROCESSOR_STATE_HANDLER InputBuffer
  1238. );
  1239. VOID
  1240. PopInitProcessorStateHandlers2 (
  1241. IN PPROCESSOR_STATE_HANDLER2 InputBuffer
  1242. );
  1243. NTSTATUS
  1244. PopIdleSwitchIdleHandler(
  1245. IN PPOP_IDLE_HANDLER NewHandler,
  1246. IN ULONG NumElements
  1247. );
  1248. NTSTATUS
  1249. PopIdleSwitchIdleHandlers(
  1250. IN PPOP_IDLE_HANDLER NewHandler,
  1251. IN ULONG NumElements
  1252. );
  1253. NTSTATUS
  1254. PopIdleUpdateIdleHandler(
  1255. IN PPOP_IDLE_HANDLER NewHandler,
  1256. IN PPOP_IDLE_HANDLER OldHandler,
  1257. IN ULONG NumElements
  1258. );
  1259. NTSTATUS
  1260. PopIdleUpdateIdleHandlers(
  1261. VOID
  1262. );
  1263. NTSTATUS
  1264. PopIdleVerifyIdleHandlers(
  1265. IN PPOP_IDLE_HANDLER NewHandler,
  1266. IN ULONG NumElements
  1267. );
  1268. VOID
  1269. PopProcessorInformation (
  1270. OUT PPROCESSOR_POWER_INFORMATION ProcInfo,
  1271. IN ULONG ProcInfoLength,
  1272. OUT PULONG ReturnBufferLength
  1273. );
  1274. // pinfo.c
  1275. BOOLEAN
  1276. PopVerifyPowerActionPolicy (
  1277. IN PPOWER_ACTION_POLICY Action
  1278. );
  1279. VOID
  1280. PopVerifySystemPowerState (
  1281. IN OUT PSYSTEM_POWER_STATE PowerState,
  1282. IN POP_SUBSTITUTION_POLICY SubstitutionPolicy
  1283. );
  1284. VOID
  1285. PopAdvanceSystemPowerState (
  1286. IN OUT PSYSTEM_POWER_STATE PowerState,
  1287. IN POP_SUBSTITUTION_POLICY SubstitutionPolicy,
  1288. IN SYSTEM_POWER_STATE LightestSystemState,
  1289. IN SYSTEM_POWER_STATE DeepestSystemState
  1290. );
  1291. NTSTATUS
  1292. PopNotifyPolicyDevice (
  1293. IN PVOID Notification,
  1294. IN PVOID Context
  1295. );
  1296. VOID
  1297. PopApplyAdminPolicy (
  1298. IN BOOLEAN UpdateRegistry,
  1299. IN PADMINISTRATOR_POWER_POLICY NewPolicy,
  1300. IN ULONG PolicyLength
  1301. );
  1302. VOID
  1303. PopResetCurrentPolicies (
  1304. VOID
  1305. );
  1306. VOID
  1307. PopConnectToPolicyDevice (
  1308. IN POP_POLICY_DEVICE_TYPE DeviceType,
  1309. IN PUNICODE_STRING DriverName
  1310. );
  1311. POWER_ACTION
  1312. PopMapInternalActionToIrpAction (
  1313. IN POWER_ACTION Action,
  1314. IN SYSTEM_POWER_STATE SystemPowerState,
  1315. IN BOOLEAN UnmapWarmEject
  1316. );
  1317. // poinit.c
  1318. VOID
  1319. PopDefaultPolicy (
  1320. IN OUT PSYSTEM_POWER_POLICY Policy
  1321. );
  1322. VOID
  1323. PopDefaultProcessorPolicy(
  1324. IN OUT PPROCESSOR_POWER_POLICY Policy
  1325. );
  1326. // postate.c
  1327. VOID
  1328. PopRequestPowerChange (
  1329. IN PDEVOBJ_EXTENSION PowerExtension,
  1330. IN POWER_STATE SystemPowerState,
  1331. IN ULONG DevicePowerState
  1332. );
  1333. VOID
  1334. PopStateChange (
  1335. IN PKDPC Dpc,
  1336. IN PVOID DeferredContext,
  1337. IN PVOID SystemArgument1,
  1338. IN PVOID SystemArgument2
  1339. );
  1340. NTSTATUS
  1341. PopSetPowerComplete(
  1342. IN PDEVICE_OBJECT DeviceObject,
  1343. IN PIRP Irp,
  1344. IN PVOID Context
  1345. );
  1346. #define PopIsStateDatabaseIdle() \
  1347. (IsListEmpty (&PopStateChangeInProgress) && \
  1348. IsListEmpty (&PopSyncStateChangeQueue) && \
  1349. IsListEmpty (&PopAsyncStateChangeQueue) )
  1350. // pwork.c
  1351. VOID
  1352. PopAcquirePolicyLock(
  1353. VOID
  1354. );
  1355. VOID
  1356. PopReleasePolicyLock(
  1357. IN BOOLEAN CheckForWork
  1358. );
  1359. VOID
  1360. PopGetPolicyWorker (
  1361. IN ULONG WorkerType
  1362. );
  1363. VOID
  1364. PopCheckForWork (
  1365. IN BOOLEAN GetWorker
  1366. );
  1367. NTSTATUS
  1368. PopCompletePolicyIrp (
  1369. IN PDEVICE_OBJECT DeviceObject,
  1370. IN PIRP Irp,
  1371. IN PVOID Context
  1372. );
  1373. VOID
  1374. PopPolicyWorkerThread (
  1375. PVOID Context
  1376. );
  1377. ULONG
  1378. PopPolicyWorkerMain (
  1379. VOID
  1380. );
  1381. VOID
  1382. PopSetNotificationWork (
  1383. IN ULONG Flags
  1384. );
  1385. ULONG
  1386. PopPolicyWorkerNotify (
  1387. VOID
  1388. );
  1389. ULONG
  1390. PopPolicyTimeChange (
  1391. VOID
  1392. );
  1393. VOID
  1394. PopDispatchCallback (
  1395. IN ULONG Arg
  1396. );
  1397. VOID
  1398. PopDispatchAcDcCallback (
  1399. IN ULONG Arg
  1400. );
  1401. VOID
  1402. PopDispatchCallout (
  1403. IN ULONG Arg
  1404. );
  1405. VOID
  1406. PopDispatchProcessorPolicyCallout (
  1407. IN ULONG Arg
  1408. );
  1409. VOID
  1410. PopDispatchPolicyCallout (
  1411. IN ULONG Arg
  1412. );
  1413. VOID
  1414. PopDispatchDisplayRequired (
  1415. IN ULONG Arg
  1416. );
  1417. VOID
  1418. PopDispatchFullWake (
  1419. IN ULONG Arg
  1420. );
  1421. VOID
  1422. PopDispatchEventCodes (
  1423. IN ULONG Arg
  1424. );
  1425. VOID
  1426. PopDispatchSetStateFailure (
  1427. IN ULONG Arg
  1428. );
  1429. // sidle.c
  1430. VOID
  1431. PopInitSIdle (
  1432. VOID
  1433. );
  1434. ULONG
  1435. PopPolicySystemIdle (
  1436. VOID
  1437. );
  1438. NTSTATUS
  1439. PopShutdownHandler (
  1440. IN PVOID Context,
  1441. IN PENTER_STATE_SYSTEM_HANDLER SystemHandler OPTIONAL,
  1442. IN PVOID SystemContext,
  1443. IN LONG NumberProcessors,
  1444. IN volatile PLONG Number
  1445. );
  1446. // sys.c
  1447. DECLSPEC_NORETURN
  1448. VOID
  1449. PopShutdownSystem (
  1450. IN POWER_ACTION SystemAction
  1451. );
  1452. NTSTATUS
  1453. PopSleepSystem (
  1454. IN SYSTEM_POWER_STATE SystemState,
  1455. IN PVOID Memory
  1456. );
  1457. VOID
  1458. PopCheckIdleDevState (
  1459. IN PPOP_DEVICE_SYS_STATE DevState,
  1460. IN BOOLEAN LogErrors,
  1461. IN BOOLEAN FreeAll
  1462. );
  1463. VOID
  1464. PopRestartSetSystemState (
  1465. VOID
  1466. );
  1467. // sysdev.c
  1468. VOID
  1469. PopAllocateDevState(
  1470. VOID
  1471. );
  1472. VOID
  1473. PopCleanupDevState (
  1474. VOID
  1475. );
  1476. VOID
  1477. PopReportDevState (
  1478. IN BOOLEAN LogErrors
  1479. );
  1480. NTSTATUS
  1481. PopSetDevicesSystemState (
  1482. IN BOOLEAN Wake
  1483. );
  1484. VOID
  1485. PopLogNotifyDevice (
  1486. IN PDEVICE_OBJECT TargetDevice,
  1487. IN OPTIONAL PPO_DEVICE_NOTIFY Notify,
  1488. IN PIRP Irp
  1489. );
  1490. // thermal.c
  1491. PUCHAR
  1492. PopTimeString(
  1493. OUT PUCHAR TimeString,
  1494. IN ULONGLONG CurrentTime
  1495. );
  1496. VOID
  1497. PopThermalDeviceHandler (
  1498. IN PDEVICE_OBJECT DeviceObject,
  1499. IN PIRP Irp,
  1500. IN PVOID Context
  1501. );
  1502. VOID
  1503. PopThermalZoneDpc (
  1504. IN struct _KDPC *Dpc,
  1505. IN PVOID DeferredContext,
  1506. IN PVOID SystemArgument1,
  1507. IN PVOID SystemArgument2
  1508. );
  1509. VOID
  1510. PopApplyThermalThrottle (
  1511. VOID
  1512. );
  1513. //
  1514. // throttle.c - dynamic CPU voltage throttling
  1515. //
  1516. //
  1517. // scale that performance levels are kept in. This is the units in the
  1518. // PROCESSOR_PERF_LEVEL scale and what is used internally to track CPU
  1519. // performance levels.
  1520. //
  1521. #define POP_PERF_SCALE POWER_PERF_SCALE
  1522. #define POP_CUR_TIME(X) (X->KernelTime + X->UserTime)
  1523. UCHAR
  1524. PopCalculateBusyPercentage(
  1525. IN PPROCESSOR_POWER_STATE PState
  1526. );
  1527. UCHAR
  1528. PopCalculateC3Percentage(
  1529. IN PPROCESSOR_POWER_STATE PState
  1530. );
  1531. VOID
  1532. PopCalculatePerfDecreaseLevel(
  1533. IN PPROCESSOR_PERF_STATE PerfStates,
  1534. IN ULONG PerfStatesCount
  1535. );
  1536. VOID
  1537. PopCalculatePerfIncreaseDecreaseTime(
  1538. IN PPROCESSOR_PERF_STATE PerfStates,
  1539. IN ULONG PerfStatesCount,
  1540. IN PPROCESSOR_STATE_HANDLER2 PerfHandler
  1541. );
  1542. VOID
  1543. PopCalculatePerfIncreaseLevel(
  1544. IN PPROCESSOR_PERF_STATE PerfStates,
  1545. IN ULONG PerfStatesCount
  1546. );
  1547. VOID
  1548. PopCalculatePerfMinCapacity(
  1549. IN PPROCESSOR_PERF_STATE PerfStates,
  1550. IN ULONG PerfStatesCount
  1551. );
  1552. UCHAR
  1553. PopGetThrottle(
  1554. VOID
  1555. );
  1556. VOID
  1557. PopPerfHandleInrush(
  1558. IN BOOLEAN EnableHandler
  1559. );
  1560. VOID
  1561. PopPerfIdle(
  1562. IN PPROCESSOR_POWER_STATE PState
  1563. );
  1564. VOID
  1565. PopPerfIdleDpc(
  1566. IN PKDPC Dpc,
  1567. IN PVOID DpcContext,
  1568. IN PVOID SystemArgument1,
  1569. IN PVOID SystemArgument2
  1570. );
  1571. VOID
  1572. PopRoundThrottle(
  1573. IN UCHAR Throttle,
  1574. OUT OPTIONAL PUCHAR RoundDown,
  1575. OUT OPTIONAL PUCHAR RoundUp,
  1576. OUT OPTIONAL PUCHAR RoundDownIndex,
  1577. OUT OPTIONAL PUCHAR RoundUpIndex
  1578. );
  1579. VOID
  1580. PopSetPerfFlag(
  1581. IN ULONG PerfFlag,
  1582. IN BOOLEAN Clear
  1583. );
  1584. NTSTATUS
  1585. PopSetPerfLevels(
  1586. IN PPROCESSOR_STATE_HANDLER2 ProcessorHandler
  1587. );
  1588. NTSTATUS
  1589. PopSetThrottle(
  1590. IN PPROCESSOR_POWER_STATE PState,
  1591. IN PPROCESSOR_PERF_STATE PerfStates,
  1592. IN ULONG Index,
  1593. IN ULONG SystemTime,
  1594. IN ULONG IdleTime
  1595. );
  1596. NTSTATUS
  1597. PopSetTimer(
  1598. IN PPROCESSOR_POWER_STATE PState,
  1599. IN UCHAR Index
  1600. );
  1601. //
  1602. // Some globals that thunk the old processor throttling callout into the
  1603. // new one.
  1604. //
  1605. NTSTATUS
  1606. FASTCALL
  1607. PopThunkSetThrottle(
  1608. IN UCHAR Throttle
  1609. );
  1610. VOID
  1611. PopUpdateAllThrottles(
  1612. VOID
  1613. );
  1614. VOID
  1615. PopUpdateProcessorThrottle(
  1616. VOID
  1617. );
  1618. extern PSET_PROCESSOR_THROTTLE PopRealSetThrottle;
  1619. extern UCHAR PopThunkThrottleScale;
  1620. extern LARGE_INTEGER PopPerfCounterFrequency;
  1621. // volume.c
  1622. VOID
  1623. PopFlushVolumes (
  1624. VOID
  1625. );
  1626. // notify.c
  1627. VOID
  1628. PopStateChangeNotify(
  1629. PDEVICE_OBJECT DeviceObject,
  1630. ULONG NotificationType
  1631. );
  1632. VOID
  1633. PopRunDownSourceTargetList(
  1634. PDEVICE_OBJECT DeviceObject
  1635. );
  1636. // poshtdwn.c
  1637. NTSTATUS
  1638. PopInitShutdownList (
  1639. VOID
  1640. );
  1641. DECLSPEC_NORETURN
  1642. VOID
  1643. PopGracefulShutdown (
  1644. IN PVOID WorkItemParameter
  1645. );
  1646. #endif // _POP_