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 CODE_SEG("INIT") 268 BOOLEAN 269 NTAPI 270 PoInitSystem( 271 IN ULONG BootPhase 272 ); 273 274 CODE_SEG("INIT") 275 VOID 276 NTAPI 277 PoInitializePrcb( 278 IN PKPRCB Prcb 279 ); 280 281 VOID 282 NTAPI 283 PopInitShutdownList( 284 VOID 285 ); 286 287 // 288 // I/O Routines 289 // 290 VOID 291 NTAPI 292 PoInitializeDeviceObject( 293 IN OUT PDEVOBJ_EXTENSION DeviceObjectExtension 294 ); 295 296 VOID 297 NTAPI 298 PoVolumeDevice( 299 IN PDEVICE_OBJECT DeviceObject 300 ); 301 302 VOID 303 NTAPI 304 PoRemoveVolumeDevice( 305 IN PDEVICE_OBJECT DeviceObject); 306 307 // 308 // Power State routines 309 // 310 NTSTATUS 311 NTAPI 312 PopSetSystemPowerState( 313 SYSTEM_POWER_STATE PowerState, 314 POWER_ACTION PowerAction 315 ); 316 317 VOID 318 NTAPI 319 PopCleanupPowerState( 320 IN PPOWER_STATE PowerState 321 ); 322 323 NTSTATUS 324 NTAPI 325 PopAddRemoveSysCapsCallback( 326 IN PVOID NotificationStructure, 327 IN PVOID Context 328 ); 329 330 // 331 // Notifications 332 // 333 VOID 334 NTAPI 335 PoNotifySystemTimeSet( 336 VOID 337 ); 338 339 // 340 // Shutdown routines 341 // 342 VOID 343 NTAPI 344 PopReadShutdownPolicy( 345 VOID 346 ); 347 348 VOID 349 NTAPI 350 PopGracefulShutdown( 351 IN PVOID Context 352 ); 353 354 VOID 355 NTAPI 356 PopFlushVolumes( 357 IN BOOLEAN ShuttingDown 358 ); 359 360 // 361 // Global data inside the Power Manager 362 // 363 extern PDEVICE_NODE PopSystemPowerDeviceNode; 364 extern KGUARDED_MUTEX PopVolumeLock; 365 extern LIST_ENTRY PopVolumeDevices; 366 extern KSPIN_LOCK PopDopeGlobalLock; 367 extern POP_POWER_ACTION PopAction; 368 extern SYSTEM_POWER_CAPABILITIES PopCapabilities; 369 370