1 /* 2 * PROJECT: ReactOS Kernel 3 * LICENSE: GPL - See COPYING in the top level directory 4 * FILE: ntoskrnl/include/internal/po.h 5 * PURPOSE: Internal header for the Power Manager 6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org) 7 */ 8 9 #include <guiddef.h> 10 #include <poclass.h> 11 12 // 13 // Define this if you want debugging support 14 // 15 #define _PO_DEBUG_ 0x00 16 17 // 18 // These define the Debug Masks Supported 19 // 20 #define PO_STATE_DEBUG 0x01 21 22 // 23 // Debug/Tracing support 24 // 25 #if _PO_DEBUG_ 26 #ifdef NEW_DEBUG_SYSTEM_IMPLEMENTED // enable when Debug Filters are implemented 27 #define POTRACE DbgPrintEx 28 #else 29 #define POTRACE(x, ...) \ 30 if (x & PopTraceLevel) DbgPrint(__VA_ARGS__) 31 #endif 32 #else 33 #define POTRACE(x, fmt, ...) DPRINT(fmt, ##__VA_ARGS__) 34 #endif 35 36 typedef enum _POP_POLICY_DEVICE_TYPE 37 { 38 PolicyDeviceSystemButton = 0, 39 PolicyDeviceThermalZone = 1, 40 PolicyDeviceBattery = 2, 41 PolicyDeviceMemory = 3, 42 PolicyInitiatePowerActionAPI = 4, 43 PolicySetPowerStateAPI = 5, 44 PolicyImmediateDozeS4 = 6, 45 PolicySystemIdle = 7, 46 PolicyDeviceMax = 8, 47 } POP_POLICY_DEVICE_TYPE; 48 49 typedef struct _PO_HIBER_PERF 50 { 51 ULONGLONG IoTicks; 52 ULONGLONG InitTicks; 53 ULONGLONG CopyTicks; 54 ULONGLONG StartCount; 55 ULONG ElapsedTime; 56 ULONG IoTime; 57 ULONG CopyTime; 58 ULONG InitTime; 59 ULONG PagesWritten; 60 ULONG PagesProcessed; 61 ULONG BytesCopied; 62 ULONG DumpCount; 63 ULONG FileRuns; 64 } PO_HIBER_PERF, *PPO_HIBER_PERF; 65 66 typedef struct _PO_MEMORY_IMAGE 67 { 68 ULONG Signature; 69 ULONG Version; 70 ULONG CheckSum; 71 ULONG LengthSelf; 72 PFN_NUMBER PageSelf; 73 ULONG PageSize; 74 ULONG ImageType; 75 LARGE_INTEGER SystemTime; 76 ULONGLONG InterruptTime; 77 ULONG FeatureFlags; 78 UCHAR HiberFlags; 79 UCHAR spare[3]; 80 ULONG NoHiberPtes; 81 ULONG_PTR HiberVa; 82 PHYSICAL_ADDRESS HiberPte; 83 ULONG NoFreePages; 84 ULONG FreeMapCheck; 85 ULONG WakeCheck; 86 PFN_NUMBER TotalPages; 87 PFN_NUMBER FirstTablePage; 88 PFN_NUMBER LastFilePage; 89 PO_HIBER_PERF PerfInfo; 90 } PO_MEMORY_IMAGE, *PPO_MEMORY_IMAGE; 91 92 typedef struct _PO_MEMORY_RANGE_ARRAY_RANGE 93 { 94 PFN_NUMBER PageNo; 95 PFN_NUMBER StartPage; 96 PFN_NUMBER EndPage; 97 ULONG CheckSum; 98 } PO_MEMORY_RANGE_ARRAY_RANGE; 99 100 typedef struct _PO_MEMORY_RANGE_ARRAY_LINK 101 { 102 struct _PO_MEMORY_RANGE_ARRAY *Next; 103 PFN_NUMBER NextTable; 104 ULONG CheckSum; 105 ULONG EntryCount; 106 } PO_MEMORY_RANGE_ARRAY_LINK; 107 108 typedef struct _PO_MEMORY_RANGE_ARRAY 109 { 110 union 111 { 112 PO_MEMORY_RANGE_ARRAY_RANGE Range; 113 PO_MEMORY_RANGE_ARRAY_LINK Link; 114 }; 115 } PO_MEMORY_RANGE_ARRAY, *PPO_MEMORY_RANGE_ARRAY; 116 117 typedef struct _POP_HIBER_CONTEXT 118 { 119 BOOLEAN WriteToFile; 120 BOOLEAN ReserveLoaderMemory; 121 BOOLEAN ReserveFreeMemory; 122 BOOLEAN VerifyOnWake; 123 BOOLEAN Reset; 124 UCHAR HiberFlags; 125 BOOLEAN LinkFile; 126 HANDLE LinkFileHandle; 127 PKSPIN_LOCK Lock; 128 BOOLEAN MapFrozen; 129 RTL_BITMAP MemoryMap; 130 LIST_ENTRY ClonedRanges; 131 ULONG ClonedRangeCount; 132 PLIST_ENTRY NextCloneRange; 133 PFN_NUMBER NextPreserve; 134 PMDL LoaderMdl; 135 PMDL Clones; 136 PUCHAR NextClone; 137 ULONG NoClones; 138 PMDL Spares; 139 ULONGLONG PagesOut; 140 PVOID IoPage; 141 PVOID CurrentMcb; 142 PVOID DumpStack; 143 PKPROCESSOR_STATE WakeState; 144 ULONG NoRanges; 145 ULONG_PTR HiberVa; 146 PHYSICAL_ADDRESS HiberPte; 147 NTSTATUS Status; 148 PPO_MEMORY_IMAGE MemoryImage; 149 PPO_MEMORY_RANGE_ARRAY TableHead; 150 PVOID CompressionWorkspace; 151 PUCHAR CompressedWriteBuffer; 152 PULONG PerformanceStats; 153 PVOID CompressionBlock; 154 PVOID DmaIO; 155 PVOID TemporaryHeap; 156 PO_HIBER_PERF PerfInfo; 157 } POP_HIBER_CONTEXT, *PPOP_HIBER_CONTEXT; 158 159 typedef struct _PO_NOTIFY_ORDER_LEVEL 160 { 161 KEVENT LevelReady; 162 ULONG DeviceCount; 163 ULONG ActiveCount; 164 LIST_ENTRY WaitSleep; 165 LIST_ENTRY ReadySleep; 166 LIST_ENTRY Pending; 167 LIST_ENTRY Complete; 168 LIST_ENTRY ReadyS0; 169 LIST_ENTRY WaitS0; 170 } PO_NOTIFY_ORDER_LEVEL, *PPO_NOTIFY_ORDER_LEVEL; 171 172 typedef struct _POP_SHUTDOWN_BUG_CHECK 173 { 174 HANDLE ThreadHandle; 175 HANDLE ThreadId; 176 HANDLE ProcessId; 177 ULONG Code; 178 ULONG_PTR Parameter1; 179 ULONG_PTR Parameter2; 180 ULONG_PTR Parameter3; 181 ULONG_PTR Parameter4; 182 } POP_SHUTDOWN_BUG_CHECK, *PPOP_SHUTDOWN_BUG_CHECK; 183 184 typedef struct _POP_DEVICE_POWER_IRP 185 { 186 SINGLE_LIST_ENTRY Free; 187 PIRP Irp; 188 PPO_DEVICE_NOTIFY Notify; 189 LIST_ENTRY Pending; 190 LIST_ENTRY Complete; 191 LIST_ENTRY Abort; 192 LIST_ENTRY Failed; 193 } POP_DEVICE_POWER_IRP, *PPOP_DEVICE_POWER_IRP; 194 195 typedef struct _PO_DEVICE_NOTIFY_ORDER 196 { 197 ULONG DevNodeSequence; 198 PDEVICE_OBJECT *WarmEjectPdoPointer; 199 PO_NOTIFY_ORDER_LEVEL OrderLevel[8]; 200 } PO_DEVICE_NOTIFY_ORDER, *PPO_DEVICE_NOTIFY_ORDER; 201 202 typedef struct _POP_DEVICE_SYS_STATE 203 { 204 UCHAR IrpMinor; 205 SYSTEM_POWER_STATE SystemState; 206 PKEVENT Event; 207 KSPIN_LOCK SpinLock; 208 PKTHREAD Thread; 209 BOOLEAN GetNewDeviceList; 210 PO_DEVICE_NOTIFY_ORDER Order; 211 NTSTATUS Status; 212 PDEVICE_OBJECT FailedDevice; 213 BOOLEAN Waking; 214 BOOLEAN Cancelled; 215 BOOLEAN IgnoreErrors; 216 BOOLEAN IgnoreNotImplemented; 217 BOOLEAN _WaitAny; 218 BOOLEAN _WaitAll; 219 LIST_ENTRY PresentIrpQueue; 220 POP_DEVICE_POWER_IRP Head; 221 POP_DEVICE_POWER_IRP PowerIrpState[20]; 222 } POP_DEVICE_SYS_STATE, *PPOP_DEVICE_SYS_STATE; 223 224 typedef struct _POP_POWER_ACTION 225 { 226 UCHAR Updates; 227 UCHAR State; 228 BOOLEAN Shutdown; 229 POWER_ACTION Action; 230 SYSTEM_POWER_STATE LightestState; 231 ULONG Flags; 232 NTSTATUS Status; 233 UCHAR IrpMinor; 234 SYSTEM_POWER_STATE SystemState; 235 SYSTEM_POWER_STATE NextSystemState; 236 PPOP_SHUTDOWN_BUG_CHECK ShutdownBugCode; 237 PPOP_DEVICE_SYS_STATE DevState; 238 PPOP_HIBER_CONTEXT HiberContext; 239 ULONGLONG WakeTime; 240 ULONGLONG SleepTime; 241 } POP_POWER_ACTION, *PPOP_POWER_ACTION; 242 243 typedef enum _POP_DEVICE_IDLE_TYPE 244 { 245 DeviceIdleNormal, 246 DeviceIdleDisk, 247 } POP_DEVICE_IDLE_TYPE, *PPOP_DEVICE_IDLE_TYPE; 248 249 typedef struct _POWER_CHANNEL_SUMMARY 250 { 251 ULONG Signature; 252 ULONG TotalCount; 253 ULONG D0Count; 254 LIST_ENTRY NotifyList; 255 } POWER_CHANNEL_SUMMARY, *PPOWER_CHANNEL_SUMMARY; 256 257 typedef struct _DEVICE_OBJECT_POWER_EXTENSION 258 { 259 ULONG IdleCount; 260 ULONG ConservationIdleTime; 261 ULONG PerformanceIdleTime; 262 PDEVICE_OBJECT DeviceObject; 263 LIST_ENTRY IdleList; 264 DEVICE_POWER_STATE State; 265 LIST_ENTRY NotifySourceList; 266 LIST_ENTRY NotifyTargetList; 267 POWER_CHANNEL_SUMMARY PowerChannelSummary; 268 LIST_ENTRY Volume; 269 } DEVICE_OBJECT_POWER_EXTENSION, *PDEVICE_OBJECT_POWER_EXTENSION; 270 271 typedef struct _POP_SHUTDOWN_WAIT_ENTRY 272 { 273 struct _POP_SHUTDOWN_WAIT_ENTRY *NextEntry; 274 PETHREAD Thread; 275 } POP_SHUTDOWN_WAIT_ENTRY, *PPOP_SHUTDOWN_WAIT_ENTRY; 276 277 // 278 // Initialization routines 279 // 280 CODE_SEG("INIT") 281 BOOLEAN 282 NTAPI 283 PoInitSystem( 284 IN ULONG BootPhase 285 ); 286 287 CODE_SEG("INIT") 288 VOID 289 NTAPI 290 PoInitializePrcb( 291 IN PKPRCB Prcb 292 ); 293 294 VOID 295 NTAPI 296 PopInitShutdownList( 297 VOID 298 ); 299 300 // 301 // I/O Routines 302 // 303 VOID 304 NTAPI 305 PoInitializeDeviceObject( 306 IN OUT PDEVOBJ_EXTENSION DeviceObjectExtension 307 ); 308 309 VOID 310 NTAPI 311 PoVolumeDevice( 312 IN PDEVICE_OBJECT DeviceObject 313 ); 314 315 VOID 316 NTAPI 317 PoRemoveVolumeDevice( 318 IN PDEVICE_OBJECT DeviceObject); 319 320 // 321 // Power State routines 322 // 323 NTSTATUS 324 NTAPI 325 PopSetSystemPowerState( 326 SYSTEM_POWER_STATE PowerState, 327 POWER_ACTION PowerAction 328 ); 329 330 VOID 331 NTAPI 332 PopCleanupPowerState( 333 IN PPOWER_STATE PowerState 334 ); 335 336 NTSTATUS 337 NTAPI 338 PopAddRemoveSysCapsCallback( 339 IN PVOID NotificationStructure, 340 IN PVOID Context 341 ); 342 343 // 344 // Notifications 345 // 346 VOID 347 NTAPI 348 PoNotifySystemTimeSet( 349 VOID 350 ); 351 352 // 353 // Shutdown routines 354 // 355 VOID 356 NTAPI 357 PopReadShutdownPolicy( 358 VOID 359 ); 360 361 VOID 362 NTAPI 363 PopGracefulShutdown( 364 IN PVOID Context 365 ); 366 367 VOID 368 NTAPI 369 PopFlushVolumes( 370 IN BOOLEAN ShuttingDown 371 ); 372 373 // 374 // Global data inside the Power Manager 375 // 376 extern PDEVICE_NODE PopSystemPowerDeviceNode; 377 extern KGUARDED_MUTEX PopVolumeLock; 378 extern LIST_ENTRY PopVolumeDevices; 379 extern KSPIN_LOCK PopDopeGlobalLock; 380 extern POP_POWER_ACTION PopAction; 381 extern SYSTEM_POWER_CAPABILITIES PopCapabilities; 382 383