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