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