Leaked source code of windows server 2003
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.

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