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