2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/po/power.c
5 * PURPOSE: Power Manager
6 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
7 * Hervé Poussineau (hpoussin@reactos.com)
10 /* INCLUDES ******************************************************************/
17 /* GLOBALS *******************************************************************/
19 typedef struct _REQUEST_POWER_ITEM
21 PREQUEST_POWER_COMPLETE CompletionRoutine
;
22 POWER_STATE PowerState
;
24 PDEVICE_OBJECT TopDeviceObject
;
25 } REQUEST_POWER_ITEM
, *PREQUEST_POWER_ITEM
;
27 typedef struct _POWER_STATE_TRAVERSE_CONTEXT
29 SYSTEM_POWER_STATE SystemPowerState
;
30 POWER_ACTION PowerAction
;
31 PDEVICE_OBJECT PowerDevice
;
32 } POWER_STATE_TRAVERSE_CONTEXT
, *PPOWER_STATE_TRAVERSE_CONTEXT
;
34 PDEVICE_NODE PopSystemPowerDeviceNode
= NULL
;
35 BOOLEAN PopAcpiPresent
= FALSE
;
36 POP_POWER_ACTION PopAction
;
37 WORK_QUEUE_ITEM PopShutdownWorkItem
;
39 /* PRIVATE FUNCTIONS *********************************************************/
44 PopRequestPowerIrpCompletion(IN PDEVICE_OBJECT DeviceObject
,
48 PIO_STACK_LOCATION Stack
;
49 PREQUEST_POWER_ITEM RequestPowerItem
;
51 Stack
= IoGetNextIrpStackLocation(Irp
);
52 RequestPowerItem
= (PREQUEST_POWER_ITEM
)Context
;
54 RequestPowerItem
->CompletionRoutine(DeviceObject
,
56 RequestPowerItem
->PowerState
,
57 RequestPowerItem
->Context
,
62 ObDereferenceObject(RequestPowerItem
->TopDeviceObject
);
65 return STATUS_MORE_PROCESSING_REQUIRED
;
70 PopCleanupPowerState(IN PPOWER_STATE PowerState
)
76 PopSendQuerySystemPowerState(PDEVICE_OBJECT DeviceObject
, SYSTEM_POWER_STATE SystemState
, POWER_ACTION PowerAction
)
79 IO_STATUS_BLOCK IoStatusBlock
;
80 PIO_STACK_LOCATION IrpSp
;
84 KeInitializeEvent(&Event
,
88 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_POWER
,
95 if (!Irp
) return STATUS_INSUFFICIENT_RESOURCES
;
97 IrpSp
= IoGetNextIrpStackLocation(Irp
);
98 IrpSp
->MinorFunction
= IRP_MN_QUERY_POWER
;
99 IrpSp
->Parameters
.Power
.Type
= SystemPowerState
;
100 IrpSp
->Parameters
.Power
.State
.SystemState
= SystemState
;
101 IrpSp
->Parameters
.Power
.ShutdownType
= PowerAction
;
103 Status
= PoCallDriver(DeviceObject
, Irp
);
104 if (Status
== STATUS_PENDING
)
106 KeWaitForSingleObject(&Event
,
111 Status
= IoStatusBlock
.Status
;
118 PopSendSetSystemPowerState(PDEVICE_OBJECT DeviceObject
, SYSTEM_POWER_STATE SystemState
, POWER_ACTION PowerAction
)
121 IO_STATUS_BLOCK IoStatusBlock
;
122 PIO_STACK_LOCATION IrpSp
;
126 KeInitializeEvent(&Event
,
130 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_POWER
,
137 if (!Irp
) return STATUS_INSUFFICIENT_RESOURCES
;
139 IrpSp
= IoGetNextIrpStackLocation(Irp
);
140 IrpSp
->MinorFunction
= IRP_MN_SET_POWER
;
141 IrpSp
->Parameters
.Power
.Type
= SystemPowerState
;
142 IrpSp
->Parameters
.Power
.State
.SystemState
= SystemState
;
143 IrpSp
->Parameters
.Power
.ShutdownType
= PowerAction
;
145 Status
= PoCallDriver(DeviceObject
, Irp
);
146 if (Status
== STATUS_PENDING
)
148 KeWaitForSingleObject(&Event
,
153 Status
= IoStatusBlock
.Status
;
160 PopQuerySystemPowerStateTraverse(PDEVICE_NODE DeviceNode
,
163 PPOWER_STATE_TRAVERSE_CONTEXT PowerStateContext
= Context
;
166 DPRINT("PopQuerySystemPowerStateTraverse(%p, %p)\n", DeviceNode
, Context
);
168 if (DeviceNode
== IopRootDeviceNode
)
169 return STATUS_SUCCESS
;
171 if (DeviceNode
->Flags
& DNF_LEGACY_DRIVER
)
172 return STATUS_SUCCESS
;
174 Status
= PopSendQuerySystemPowerState(DeviceNode
->PhysicalDeviceObject
,
175 PowerStateContext
->SystemPowerState
,
176 PowerStateContext
->PowerAction
);
177 if (!NT_SUCCESS(Status
))
179 DPRINT1("Device '%wZ' failed IRP_MN_QUERY_POWER\n", &DeviceNode
->InstancePath
);
185 return STATUS_SUCCESS
;
190 PopSetSystemPowerStateTraverse(PDEVICE_NODE DeviceNode
,
193 PPOWER_STATE_TRAVERSE_CONTEXT PowerStateContext
= Context
;
196 DPRINT("PopSetSystemPowerStateTraverse(%p, %p)\n", DeviceNode
, Context
);
198 if (DeviceNode
== IopRootDeviceNode
)
199 return STATUS_SUCCESS
;
201 if (DeviceNode
->PhysicalDeviceObject
== PowerStateContext
->PowerDevice
)
202 return STATUS_SUCCESS
;
204 if (DeviceNode
->Flags
& DNF_LEGACY_DRIVER
)
205 return STATUS_SUCCESS
;
207 Status
= PopSendSetSystemPowerState(DeviceNode
->PhysicalDeviceObject
,
208 PowerStateContext
->SystemPowerState
,
209 PowerStateContext
->PowerAction
);
210 if (!NT_SUCCESS(Status
))
212 DPRINT1("Device '%wZ' failed IRP_MN_SET_POWER\n", &DeviceNode
->InstancePath
);
218 return STATUS_SUCCESS
;
224 PopSetSystemPowerState(SYSTEM_POWER_STATE PowerState
, POWER_ACTION PowerAction
)
226 PDEVICE_OBJECT DeviceObject
;
229 DEVICETREE_TRAVERSE_CONTEXT Context
;
230 POWER_STATE_TRAVERSE_CONTEXT PowerContext
;
232 Status
= IopGetSystemPowerDeviceObject(&DeviceObject
);
233 if (!NT_SUCCESS(Status
))
235 DPRINT1("No system power driver available\n");
240 Fdo
= IoGetAttachedDeviceReference(DeviceObject
);
241 if (Fdo
== DeviceObject
)
243 DPRINT("An FDO was not attached\n");
244 return STATUS_UNSUCCESSFUL
;
249 PowerContext
.PowerAction
= PowerAction
;
250 PowerContext
.SystemPowerState
= PowerState
;
251 PowerContext
.PowerDevice
= Fdo
;
253 /* Query for system power change */
254 IopInitDeviceTreeTraverseContext(&Context
,
256 PopQuerySystemPowerStateTraverse
,
259 Status
= IopTraverseDeviceTree(&Context
);
260 if (!NT_SUCCESS(Status
))
262 DPRINT1("Query system power state failed; changing state anyway\n");
265 /* Set system power change */
266 IopInitDeviceTreeTraverseContext(&Context
,
268 PopSetSystemPowerStateTraverse
,
271 IopTraverseDeviceTree(&Context
);
273 if (!PopAcpiPresent
) return STATUS_NOT_IMPLEMENTED
;
277 if (PowerAction
!= PowerActionShutdownReset
)
278 PopSendSetSystemPowerState(Fdo
, PowerState
, PowerAction
);
280 ObDereferenceObject(Fdo
);
289 PoInitSystem(IN ULONG BootPhase
)
291 PVOID NotificationEntry
;
293 BOOLEAN ForceAcpiDisable
= FALSE
;
295 /* Check if this is phase 1 init */
298 /* Register power button notification */
299 IoRegisterPlugPlayNotification(EventCategoryDeviceInterfaceChange
,
300 PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES
,
301 (PVOID
)&GUID_DEVICE_SYS_BUTTON
,
303 PhysicalDeviceObject
->DriverObject
,
304 PopAddRemoveSysCapsCallback
,
308 /* Register lid notification */
309 IoRegisterPlugPlayNotification(EventCategoryDeviceInterfaceChange
,
310 PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES
,
311 (PVOID
)&GUID_DEVICE_LID
,
313 PhysicalDeviceObject
->DriverObject
,
314 PopAddRemoveSysCapsCallback
,
320 /* Get the Command Line */
321 CommandLine
= KeLoaderBlock
->LoadOptions
;
324 _strupr(CommandLine
);
326 /* Check for ACPI disable */
327 if (strstr(CommandLine
, "NOACPI")) ForceAcpiDisable
= TRUE
;
329 if (ForceAcpiDisable
)
331 /* Set the ACPI State to False if it's been forced that way */
332 PopAcpiPresent
= FALSE
;
336 /* Otherwise check if the LoaderBlock has a ACPI Table */
337 PopAcpiPresent
= KeLoaderBlock
->Extension
->AcpiTable
!= NULL
? TRUE
: FALSE
;
341 /* Initialize volume support */
342 InitializeListHead(&PopVolumeDevices
);
343 KeInitializeGuardedMutex(&PopVolumeLock
);
345 /* Initialize support for dope */
346 KeInitializeSpinLock(&PopDopeGlobalLock
);
348 /* Initialize support for shutdown waits and work-items */
349 PopInitShutdownList();
356 PopPerfIdle(PPROCESSOR_POWER_STATE PowerState
)
358 DPRINT1("PerfIdle function: %p\n", PowerState
);
363 PopPerfIdleDpc(IN PKDPC Dpc
,
364 IN PVOID DeferredContext
,
365 IN PVOID SystemArgument1
,
366 IN PVOID SystemArgument2
)
368 /* Call the Perf Idle function */
369 PopPerfIdle(&((PKPRCB
)DeferredContext
)->PowerState
);
374 PopIdle0(IN PPROCESSOR_POWER_STATE PowerState
)
376 /* FIXME: Extremly naive implementation */
383 PoInitializePrcb(IN PKPRCB Prcb
)
385 /* Initialize the Power State */
386 RtlZeroMemory(&Prcb
->PowerState
, sizeof(Prcb
->PowerState
));
387 Prcb
->PowerState
.Idle0KernelTimeLimit
= 0xFFFFFFFF;
388 Prcb
->PowerState
.CurrentThrottle
= 100;
389 Prcb
->PowerState
.CurrentThrottleIndex
= 0;
390 Prcb
->PowerState
.IdleFunction
= PopIdle0
;
392 /* Initialize the Perf DPC and Timer */
393 KeInitializeDpc(&Prcb
->PowerState
.PerfDpc
, PopPerfIdleDpc
, Prcb
);
394 KeSetTargetProcessorDpc(&Prcb
->PowerState
.PerfDpc
, Prcb
->Number
);
395 KeInitializeTimerEx(&Prcb
->PowerState
.PerfTimer
, SynchronizationTimer
);
398 /* PUBLIC FUNCTIONS **********************************************************/
405 PoCancelDeviceNotify(IN PVOID NotifyBlock
)
408 return STATUS_NOT_IMPLEMENTED
;
416 PoRegisterDeviceNotify(OUT PVOID Unknown0
,
424 return STATUS_NOT_IMPLEMENTED
;
432 PoShutdownBugCheck(IN BOOLEAN LogError
,
433 IN ULONG BugCheckCode
,
434 IN ULONG_PTR BugCheckParameter1
,
435 IN ULONG_PTR BugCheckParameter2
,
436 IN ULONG_PTR BugCheckParameter3
,
437 IN ULONG_PTR BugCheckParameter4
)
439 DPRINT1("PoShutdownBugCheck called\n");
441 /* FIXME: Log error if requested */
442 /* FIXME: Initiate a shutdown */
444 /* Bugcheck the system */
445 KeBugCheckEx(BugCheckCode
,
457 PoSetHiberRange(IN PVOID HiberContext
,
459 IN OUT PVOID StartPage
,
472 PoCallDriver(IN PDEVICE_OBJECT DeviceObject
,
477 /* Forward to Io -- FIXME! */
478 Status
= IoCallDriver(DeviceObject
, Irp
);
489 PoRegisterDeviceForIdleDetection(IN PDEVICE_OBJECT DeviceObject
,
490 IN ULONG ConservationIdleTime
,
491 IN ULONG PerformanceIdleTime
,
492 IN DEVICE_POWER_STATE State
)
503 PoRegisterSystemState(IN PVOID StateHandle
,
504 IN EXECUTION_STATE Flags
)
515 PoRequestPowerIrp(IN PDEVICE_OBJECT DeviceObject
,
516 IN UCHAR MinorFunction
,
517 IN POWER_STATE PowerState
,
518 IN PREQUEST_POWER_COMPLETE CompletionFunction
,
520 OUT PIRP
*pIrp OPTIONAL
)
522 PDEVICE_OBJECT TopDeviceObject
;
523 PIO_STACK_LOCATION Stack
;
525 PREQUEST_POWER_ITEM RequestPowerItem
;
527 if (MinorFunction
!= IRP_MN_QUERY_POWER
528 && MinorFunction
!= IRP_MN_SET_POWER
529 && MinorFunction
!= IRP_MN_WAIT_WAKE
)
530 return STATUS_INVALID_PARAMETER_2
;
532 RequestPowerItem
= ExAllocatePool(NonPagedPool
, sizeof(REQUEST_POWER_ITEM
));
533 if (!RequestPowerItem
)
534 return STATUS_INSUFFICIENT_RESOURCES
;
536 /* Always call the top of the device stack */
537 TopDeviceObject
= IoGetAttachedDeviceReference(DeviceObject
);
539 Irp
= IoBuildAsynchronousFsdRequest(IRP_MJ_POWER
,
547 ObDereferenceObject(TopDeviceObject
);
548 ExFreePool(RequestPowerItem
);
549 return STATUS_INSUFFICIENT_RESOURCES
;
552 /* POWER IRPs are always initialized with a status code of
553 STATUS_NOT_IMPLEMENTED */
554 Irp
->IoStatus
.Status
= STATUS_NOT_IMPLEMENTED
;
555 Irp
->IoStatus
.Information
= 0;
557 Stack
= IoGetNextIrpStackLocation(Irp
);
558 Stack
->MinorFunction
= MinorFunction
;
559 if (MinorFunction
== IRP_MN_WAIT_WAKE
)
560 Stack
->Parameters
.WaitWake
.PowerState
= PowerState
.SystemState
;
563 Stack
->Parameters
.Power
.Type
= DevicePowerState
;
564 Stack
->Parameters
.Power
.State
= PowerState
;
567 RequestPowerItem
->CompletionRoutine
= CompletionFunction
;
568 RequestPowerItem
->PowerState
= PowerState
;
569 RequestPowerItem
->Context
= Context
;
570 RequestPowerItem
->TopDeviceObject
= TopDeviceObject
;
575 IoSetCompletionRoutine(Irp
, PopRequestPowerIrpCompletion
, RequestPowerItem
, TRUE
, TRUE
, TRUE
);
576 PoCallDriver(TopDeviceObject
, Irp
);
578 /* Always return STATUS_PENDING. The completion routine
579 * will call CompletionFunction and complete the Irp.
581 return STATUS_PENDING
;
589 PoSetPowerState(IN PDEVICE_OBJECT DeviceObject
,
590 IN POWER_STATE_TYPE Type
,
591 IN POWER_STATE State
)
595 ASSERT_IRQL_LESS_OR_EQUAL(DISPATCH_LEVEL
);
597 ps
.SystemState
= PowerSystemWorking
; // Fully on
598 ps
.DeviceState
= PowerDeviceD0
; // Fully on
608 PoSetSystemState(IN EXECUTION_STATE Flags
)
618 PoStartNextPowerIrp(IN PIRP Irp
)
628 PoUnregisterSystemState(IN PVOID StateHandle
)
638 NtInitiatePowerAction (IN POWER_ACTION SystemAction
,
639 IN SYSTEM_POWER_STATE MinSystemState
,
641 IN BOOLEAN Asynchronous
)
644 return STATUS_NOT_IMPLEMENTED
;
652 NtPowerInformation(IN POWER_INFORMATION_LEVEL PowerInformationLevel
,
653 IN PVOID InputBuffer OPTIONAL
,
654 IN ULONG InputBufferLength
,
655 OUT PVOID OutputBuffer OPTIONAL
,
656 IN ULONG OutputBufferLength
)
662 DPRINT("NtPowerInformation(PowerInformationLevel 0x%x, InputBuffer 0x%p, "
663 "InputBufferLength 0x%x, OutputBuffer 0x%p, OutputBufferLength 0x%x)\n",
664 PowerInformationLevel
,
665 InputBuffer
, InputBufferLength
,
666 OutputBuffer
, OutputBufferLength
);
668 switch (PowerInformationLevel
)
670 case SystemBatteryState
:
672 PSYSTEM_BATTERY_STATE BatteryState
= (PSYSTEM_BATTERY_STATE
)OutputBuffer
;
674 if (InputBuffer
!= NULL
)
675 return STATUS_INVALID_PARAMETER
;
676 if (OutputBufferLength
< sizeof(SYSTEM_BATTERY_STATE
))
677 return STATUS_BUFFER_TOO_SMALL
;
679 /* Just zero the struct (and thus set BatteryState->BatteryPresent = FALSE) */
680 RtlZeroMemory(BatteryState
, sizeof(SYSTEM_BATTERY_STATE
));
681 BatteryState
->EstimatedTime
= MAXULONG
;
683 Status
= STATUS_SUCCESS
;
686 case SystemPowerCapabilities
:
688 PSYSTEM_POWER_CAPABILITIES PowerCapabilities
= (PSYSTEM_POWER_CAPABILITIES
)OutputBuffer
;
690 if (InputBuffer
!= NULL
)
691 return STATUS_INVALID_PARAMETER
;
692 if (OutputBufferLength
< sizeof(SYSTEM_POWER_CAPABILITIES
))
693 return STATUS_BUFFER_TOO_SMALL
;
695 /* Just zero the struct (and thus set BatteryState->BatteryPresent = FALSE) */
696 RtlZeroMemory(PowerCapabilities
, sizeof(SYSTEM_POWER_CAPABILITIES
));
697 //PowerCapabilities->SystemBatteriesPresent = 0;
699 Status
= STATUS_SUCCESS
;
704 Status
= STATUS_NOT_IMPLEMENTED
;
705 DPRINT1("PowerInformationLevel 0x%x is UNIMPLEMENTED! Have a nice day.\n",
706 PowerInformationLevel
);
715 NtGetDevicePowerState(IN HANDLE Device
,
716 IN PDEVICE_POWER_STATE PowerState
)
719 return STATUS_NOT_IMPLEMENTED
;
724 NtIsSystemResumeAutomatic(VOID
)
732 NtRequestWakeupLatency(IN LATENCY_TIME Latency
)
735 return STATUS_NOT_IMPLEMENTED
;
740 NtSetThreadExecutionState(IN EXECUTION_STATE esFlags
,
741 OUT EXECUTION_STATE
*PreviousFlags
)
743 PKTHREAD Thread
= KeGetCurrentThread();
744 KPROCESSOR_MODE PreviousMode
= KeGetPreviousMode();
745 EXECUTION_STATE PreviousState
;
749 if (esFlags
& ~(ES_CONTINUOUS
| ES_USER_PRESENT
))
751 /* Fail the request */
752 return STATUS_INVALID_PARAMETER
;
755 /* Check for user parameters */
756 if (PreviousMode
!= KernelMode
)
758 /* Protect the probes */
761 /* Check if the pointer is valid */
762 ProbeForWriteUlong(PreviousFlags
);
764 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
766 /* It isn't -- fail */
767 _SEH2_YIELD(return _SEH2_GetExceptionCode());
772 /* Save the previous state, always masking in the continous flag */
773 PreviousState
= Thread
->PowerState
| ES_CONTINUOUS
;
775 /* Check if we need to update the power state */
776 if (esFlags
& ES_CONTINUOUS
) Thread
->PowerState
= (UCHAR
)esFlags
;
778 /* Protect the write back to user mode */
781 /* Return the previous flags */
782 *PreviousFlags
= PreviousState
;
784 _SEH2_EXCEPT(ExSystemExceptionFilter())
786 /* Something's wrong, fail */
787 _SEH2_YIELD(return _SEH2_GetExceptionCode());
792 return STATUS_SUCCESS
;
797 NtSetSystemPowerState(IN POWER_ACTION SystemAction
,
798 IN SYSTEM_POWER_STATE MinSystemState
,
801 KPROCESSOR_MODE PreviousMode
= KeGetPreviousMode();
802 POP_POWER_ACTION Action
= {0};
806 /* Check for invalid parameter combinations */
807 if ((MinSystemState
>= PowerSystemMaximum
) ||
808 (MinSystemState
<= PowerSystemUnspecified
) ||
809 (SystemAction
> PowerActionWarmEject
) ||
810 (SystemAction
< PowerActionReserved
) ||
811 (Flags
& ~(POWER_ACTION_QUERY_ALLOWED
|
812 POWER_ACTION_UI_ALLOWED
|
813 POWER_ACTION_OVERRIDE_APPS
|
814 POWER_ACTION_LIGHTEST_FIRST
|
815 POWER_ACTION_LOCK_CONSOLE
|
816 POWER_ACTION_DISABLE_WAKES
|
817 POWER_ACTION_CRITICAL
)))
819 DPRINT1("NtSetSystemPowerState: Bad parameters!\n");
820 DPRINT1(" SystemAction: 0x%x\n", SystemAction
);
821 DPRINT1(" MinSystemState: 0x%x\n", MinSystemState
);
822 DPRINT1(" Flags: 0x%x\n", Flags
);
823 return STATUS_INVALID_PARAMETER
;
826 /* Check for user caller */
827 if (PreviousMode
!= KernelMode
)
829 /* Check for shutdown permission */
830 if (!SeSinglePrivilegeCheck(SeShutdownPrivilege
, PreviousMode
))
833 DPRINT1("ERROR: Privilege not held for shutdown\n");
834 //return STATUS_PRIVILEGE_NOT_HELD; HACK!
837 /* Do it as a kernel-mode caller for consistency with system state */
838 return ZwSetSystemPowerState (SystemAction
, MinSystemState
, Flags
);
841 /* Read policy settings (partial shutdown vs. full shutdown) */
842 if (SystemAction
== PowerActionShutdown
) PopReadShutdownPolicy();
844 /* Disable lazy flushing of registry */
845 DPRINT1("Stopping lazy flush\n");
846 CmSetLazyFlushState(FALSE
);
848 /* Setup the power action */
849 Action
.Action
= SystemAction
;
850 Action
.Flags
= Flags
;
852 /* Notify callbacks */
853 DPRINT1("Notifying callbacks\n");
854 ExNotifyCallback(PowerStateCallback
, (PVOID
)3, NULL
);
856 /* Swap in any worker thread stacks */
857 DPRINT1("Swapping worker threads\n");
858 ExSwapinWorkerThreads(FALSE
);
860 /* Make our action global */
863 /* Start power loop */
864 Status
= STATUS_CANCELLED
;
867 /* Break out if there's nothing to do */
868 if (Action
.Action
== PowerActionNone
) break;
870 /* Check for first-pass or restart */
871 if (Status
== STATUS_CANCELLED
)
873 /* Check for shutdown action */
874 if ((PopAction
.Action
== PowerActionShutdown
) ||
875 (PopAction
.Action
== PowerActionShutdownReset
) ||
876 (PopAction
.Action
== PowerActionShutdownOff
))
879 PopAction
.Shutdown
= TRUE
;
882 /* Now we are good to go */
883 Status
= STATUS_SUCCESS
;
886 /* Check if we're still in an invalid status */
887 if (!NT_SUCCESS(Status
)) break;
890 /* Flush dirty cache pages */
891 CcRosFlushDirtyPages(-1, &Dummy
, FALSE
); //HACK: We really should wait here!
896 /* Flush all volumes and the registry */
897 DPRINT1("Flushing volumes, cache flushed %lu pages\n", Dummy
);
898 PopFlushVolumes(PopAction
.Shutdown
);
900 /* Set IRP for drivers */
901 PopAction
.IrpMinor
= IRP_MN_SET_POWER
;
902 if (PopAction
.Shutdown
)
904 DPRINT1("Queueing shutdown thread\n");
905 /* Check if we are running in the system context */
906 if (PsGetCurrentProcess() != PsInitialSystemProcess
)
908 /* We're not, so use a worker thread for shutdown */
909 ExInitializeWorkItem(&PopShutdownWorkItem
,
910 &PopGracefulShutdown
,
913 ExQueueWorkItem(&PopShutdownWorkItem
, CriticalWorkQueue
);
915 /* Spend us -- when we wake up, the system is good to go down */
916 KeSuspendThread(KeGetCurrentThread());
917 Status
= STATUS_SYSTEM_SHUTDOWN
;
923 /* Do the shutdown inline */
924 PopGracefulShutdown(NULL
);
928 /* You should not have made it this far */
929 ASSERT(FALSE
&& "System is still up and running?!");
934 /* We're done, return */