[NTOSKRNL]
[reactos.git] / reactos / ntoskrnl / include / internal / po.h
1 /*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/include/po.h
5 * PURPOSE: Internal header for the Power Manager
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8
9 #include "initguid.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, ...) DPRINT(__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 //
259 // Initialization routines
260 //
261 BOOLEAN
262 NTAPI
263 PoInitSystem(
264 IN ULONG BootPhase
265 );
266
267 VOID
268 NTAPI
269 PoInitializePrcb(
270 IN PKPRCB Prcb
271 );
272
273 //
274 // I/O Routines
275 //
276 VOID
277 NTAPI
278 PoInitializeDeviceObject(
279 IN OUT PDEVOBJ_EXTENSION DeviceObjectExtension
280 );
281
282 VOID
283 NTAPI
284 PoVolumeDevice(
285 IN PDEVICE_OBJECT DeviceObject
286 );
287
288 //
289 // Power State routines
290 //
291 NTSTATUS
292 NTAPI
293 PopSetSystemPowerState(
294 SYSTEM_POWER_STATE PowerState
295 );
296
297 VOID
298 NTAPI
299 PopCleanupPowerState(
300 IN PPOWER_STATE PowerState
301 );
302
303 NTSTATUS
304 NTAPI
305 PopAddRemoveSysCapsCallback(
306 IN PVOID NotificationStructure,
307 IN PVOID Context
308 );
309
310 //
311 // Notifications
312 //
313 VOID
314 NTAPI
315 PoNotifySystemTimeSet(
316 VOID
317 );
318
319 //
320 // Shutdown routines
321 //
322 VOID
323 NTAPI
324 PopReadShutdownPolicy(
325 VOID
326 );
327
328 VOID
329 NTAPI
330 PopGracefulShutdown(
331 IN PVOID Context
332 );
333
334 VOID
335 NTAPI
336 PopFlushVolumes(
337 IN BOOLEAN ShuttingDown
338 );
339
340 //
341 // Global data inside the Power Manager
342 //
343 extern PDEVICE_NODE PopSystemPowerDeviceNode;
344 extern KGUARDED_MUTEX PopVolumeLock;
345 extern LIST_ENTRY PopVolumeDevices;
346 extern KSPIN_LOCK PopDopeGlobalLock;
347 extern POP_POWER_ACTION PopAction;
348