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 } REQUEST_POWER_ITEM
, *PREQUEST_POWER_ITEM
;
26 typedef struct _POWER_STATE_TRAVERSE_CONTEXT
28 SYSTEM_POWER_STATE SystemPowerState
;
29 POWER_ACTION PowerAction
;
30 PDEVICE_OBJECT PowerDevice
;
31 } POWER_STATE_TRAVERSE_CONTEXT
, *PPOWER_STATE_TRAVERSE_CONTEXT
;
33 PDEVICE_NODE PopSystemPowerDeviceNode
= NULL
;
34 BOOLEAN PopAcpiPresent
= FALSE
;
35 POP_POWER_ACTION PopAction
;
36 WORK_QUEUE_ITEM PopShutdownWorkItem
;
38 /* PRIVATE FUNCTIONS *********************************************************/
43 PopRequestPowerIrpCompletion(IN PDEVICE_OBJECT DeviceObject
,
47 PIO_STACK_LOCATION Stack
;
48 PREQUEST_POWER_ITEM RequestPowerItem
;
50 Stack
= IoGetNextIrpStackLocation(Irp
);
51 RequestPowerItem
= (PREQUEST_POWER_ITEM
)Context
;
53 RequestPowerItem
->CompletionRoutine(DeviceObject
,
55 RequestPowerItem
->PowerState
,
56 RequestPowerItem
->Context
,
62 ObDereferenceObject(DeviceObject
);
64 return STATUS_MORE_PROCESSING_REQUIRED
;
69 PopCleanupPowerState(IN PPOWER_STATE PowerState
)
75 PopSendQuerySystemPowerState(PDEVICE_OBJECT DeviceObject
, SYSTEM_POWER_STATE SystemState
, POWER_ACTION PowerAction
)
78 IO_STATUS_BLOCK IoStatusBlock
;
79 PIO_STACK_LOCATION IrpSp
;
83 KeInitializeEvent(&Event
,
87 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_POWER
,
94 if (!Irp
) return STATUS_INSUFFICIENT_RESOURCES
;
96 IrpSp
= IoGetNextIrpStackLocation(Irp
);
97 IrpSp
->MinorFunction
= IRP_MN_QUERY_POWER
;
98 IrpSp
->Parameters
.Power
.Type
= SystemPowerState
;
99 IrpSp
->Parameters
.Power
.State
.SystemState
= SystemState
;
100 IrpSp
->Parameters
.Power
.ShutdownType
= PowerAction
;
102 Status
= PoCallDriver(DeviceObject
, Irp
);
103 if (Status
== STATUS_PENDING
)
105 KeWaitForSingleObject(&Event
,
110 Status
= IoStatusBlock
.Status
;
117 PopSendSetSystemPowerState(PDEVICE_OBJECT DeviceObject
, SYSTEM_POWER_STATE SystemState
, POWER_ACTION PowerAction
)
120 IO_STATUS_BLOCK IoStatusBlock
;
121 PIO_STACK_LOCATION IrpSp
;
125 KeInitializeEvent(&Event
,
129 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_POWER
,
136 if (!Irp
) return STATUS_INSUFFICIENT_RESOURCES
;
138 IrpSp
= IoGetNextIrpStackLocation(Irp
);
139 IrpSp
->MinorFunction
= IRP_MN_SET_POWER
;
140 IrpSp
->Parameters
.Power
.Type
= SystemPowerState
;
141 IrpSp
->Parameters
.Power
.State
.SystemState
= SystemState
;
142 IrpSp
->Parameters
.Power
.ShutdownType
= PowerAction
;
144 Status
= PoCallDriver(DeviceObject
, Irp
);
145 if (Status
== STATUS_PENDING
)
147 KeWaitForSingleObject(&Event
,
152 Status
= IoStatusBlock
.Status
;
159 PopQuerySystemPowerStateTraverse(PDEVICE_NODE DeviceNode
,
162 PPOWER_STATE_TRAVERSE_CONTEXT PowerStateContext
= Context
;
165 DPRINT("PopQuerySystemPowerStateTraverse(%p, %p)\n", DeviceNode
, Context
);
167 if (DeviceNode
== IopRootDeviceNode
)
168 return STATUS_SUCCESS
;
170 if (DeviceNode
->Flags
& DNF_LEGACY_DRIVER
)
171 return STATUS_SUCCESS
;
173 Status
= PopSendQuerySystemPowerState(DeviceNode
->PhysicalDeviceObject
,
174 PowerStateContext
->SystemPowerState
,
175 PowerStateContext
->PowerAction
);
176 if (!NT_SUCCESS(Status
))
178 DPRINT1("Device '%wZ' failed IRP_MN_QUERY_POWER\n", &DeviceNode
->InstancePath
);
184 return STATUS_SUCCESS
;
189 PopSetSystemPowerStateTraverse(PDEVICE_NODE DeviceNode
,
192 PPOWER_STATE_TRAVERSE_CONTEXT PowerStateContext
= Context
;
195 DPRINT("PopSetSystemPowerStateTraverse(%p, %p)\n", DeviceNode
, Context
);
197 if (DeviceNode
== IopRootDeviceNode
)
198 return STATUS_SUCCESS
;
200 if (DeviceNode
->PhysicalDeviceObject
== PowerStateContext
->PowerDevice
)
201 return STATUS_SUCCESS
;
203 if (DeviceNode
->Flags
& DNF_LEGACY_DRIVER
)
204 return STATUS_SUCCESS
;
206 Status
= PopSendSetSystemPowerState(DeviceNode
->PhysicalDeviceObject
,
207 PowerStateContext
->SystemPowerState
,
208 PowerStateContext
->PowerAction
);
209 if (!NT_SUCCESS(Status
))
211 DPRINT1("Device '%wZ' failed IRP_MN_SET_POWER\n", &DeviceNode
->InstancePath
);
217 return STATUS_SUCCESS
;
223 PopSetSystemPowerState(SYSTEM_POWER_STATE PowerState
, POWER_ACTION PowerAction
)
225 PDEVICE_OBJECT DeviceObject
;
228 DEVICETREE_TRAVERSE_CONTEXT Context
;
229 POWER_STATE_TRAVERSE_CONTEXT PowerContext
;
231 Status
= IopGetSystemPowerDeviceObject(&DeviceObject
);
232 if (!NT_SUCCESS(Status
))
234 DPRINT1("No system power driver available\n");
239 Fdo
= IoGetAttachedDeviceReference(DeviceObject
);
240 if (Fdo
== DeviceObject
)
242 DPRINT("An FDO was not attached\n");
243 return STATUS_UNSUCCESSFUL
;
248 PowerContext
.PowerAction
= PowerAction
;
249 PowerContext
.SystemPowerState
= PowerState
;
250 PowerContext
.PowerDevice
= Fdo
;
252 /* Query for system power change */
253 IopInitDeviceTreeTraverseContext(&Context
,
255 PopQuerySystemPowerStateTraverse
,
258 Status
= IopTraverseDeviceTree(&Context
);
259 if (!NT_SUCCESS(Status
))
261 DPRINT1("Query system power state failed; changing state anyway\n");
264 /* Set system power change */
265 IopInitDeviceTreeTraverseContext(&Context
,
267 PopSetSystemPowerStateTraverse
,
270 IopTraverseDeviceTree(&Context
);
272 if (!PopAcpiPresent
) return STATUS_NOT_IMPLEMENTED
;
276 if (PowerAction
!= PowerActionShutdownReset
)
277 PopSendSetSystemPowerState(Fdo
, PowerState
, PowerAction
);
279 ObDereferenceObject(Fdo
);
288 PoInitSystem(IN ULONG BootPhase
)
290 PVOID NotificationEntry
;
292 BOOLEAN ForceAcpiDisable
= FALSE
;
294 /* Check if this is phase 1 init */
297 /* Register power button notification */
298 IoRegisterPlugPlayNotification(EventCategoryDeviceInterfaceChange
,
299 PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES
,
300 (PVOID
)&GUID_DEVICE_SYS_BUTTON
,
302 PhysicalDeviceObject
->DriverObject
,
303 PopAddRemoveSysCapsCallback
,
307 /* Register lid notification */
308 IoRegisterPlugPlayNotification(EventCategoryDeviceInterfaceChange
,
309 PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES
,
310 (PVOID
)&GUID_DEVICE_LID
,
312 PhysicalDeviceObject
->DriverObject
,
313 PopAddRemoveSysCapsCallback
,
319 /* Get the Command Line */
320 CommandLine
= KeLoaderBlock
->LoadOptions
;
323 _strupr(CommandLine
);
325 /* Check for ACPI disable */
326 if (strstr(CommandLine
, "NOACPI")) ForceAcpiDisable
= TRUE
;
328 if (ForceAcpiDisable
)
330 /* Set the ACPI State to False if it's been forced that way */
331 PopAcpiPresent
= FALSE
;
335 /* Otherwise check if the LoaderBlock has a ACPI Table */
336 PopAcpiPresent
= KeLoaderBlock
->Extension
->AcpiTable
!= NULL
? TRUE
: FALSE
;
340 /* Initialize volume support */
341 InitializeListHead(&PopVolumeDevices
);
342 KeInitializeGuardedMutex(&PopVolumeLock
);
344 /* Initialize support for dope */
345 KeInitializeSpinLock(&PopDopeGlobalLock
);
351 PopPerfIdle(PPROCESSOR_POWER_STATE PowerState
)
353 DPRINT1("PerfIdle function: %p\n", PowerState
);
358 PopPerfIdleDpc(IN PKDPC Dpc
,
359 IN PVOID DeferredContext
,
360 IN PVOID SystemArgument1
,
361 IN PVOID SystemArgument2
)
363 /* Call the Perf Idle function */
364 PopPerfIdle(&((PKPRCB
)DeferredContext
)->PowerState
);
369 PopIdle0(IN PPROCESSOR_POWER_STATE PowerState
)
371 /* FIXME: Extremly naive implementation */
378 PoInitializePrcb(IN PKPRCB Prcb
)
380 /* Initialize the Power State */
381 RtlZeroMemory(&Prcb
->PowerState
, sizeof(Prcb
->PowerState
));
382 Prcb
->PowerState
.Idle0KernelTimeLimit
= 0xFFFFFFFF;
383 Prcb
->PowerState
.CurrentThrottle
= 100;
384 Prcb
->PowerState
.CurrentThrottleIndex
= 0;
385 Prcb
->PowerState
.IdleFunction
= PopIdle0
;
387 /* Initialize the Perf DPC and Timer */
388 KeInitializeDpc(&Prcb
->PowerState
.PerfDpc
, PopPerfIdleDpc
, Prcb
);
389 KeSetTargetProcessorDpc(&Prcb
->PowerState
.PerfDpc
, Prcb
->Number
);
390 KeInitializeTimerEx(&Prcb
->PowerState
.PerfTimer
, SynchronizationTimer
);
393 /* PUBLIC FUNCTIONS **********************************************************/
400 PoCancelDeviceNotify(IN PVOID NotifyBlock
)
403 return STATUS_NOT_IMPLEMENTED
;
411 PoRegisterDeviceNotify(OUT PVOID Unknown0
,
419 return STATUS_NOT_IMPLEMENTED
;
427 PoShutdownBugCheck(IN BOOLEAN LogError
,
428 IN ULONG BugCheckCode
,
429 IN ULONG_PTR BugCheckParameter1
,
430 IN ULONG_PTR BugCheckParameter2
,
431 IN ULONG_PTR BugCheckParameter3
,
432 IN ULONG_PTR BugCheckParameter4
)
434 DPRINT1("PoShutdownBugCheck called\n");
436 /* FIXME: Log error if requested */
437 /* FIXME: Initiate a shutdown */
439 /* Bugcheck the system */
440 KeBugCheckEx(BugCheckCode
,
452 PoRequestShutdownEvent(OUT PVOID
*Event
)
455 return STATUS_NOT_IMPLEMENTED
;
463 PoSetHiberRange(IN PVOID HiberContext
,
465 IN OUT PVOID StartPage
,
478 PoCallDriver(IN PDEVICE_OBJECT DeviceObject
,
483 /* Forward to Io -- FIXME! */
484 Status
= IoCallDriver(DeviceObject
, Irp
);
495 PoRegisterDeviceForIdleDetection(IN PDEVICE_OBJECT DeviceObject
,
496 IN ULONG ConservationIdleTime
,
497 IN ULONG PerformanceIdleTime
,
498 IN DEVICE_POWER_STATE State
)
509 PoRegisterSystemState(IN PVOID StateHandle
,
510 IN EXECUTION_STATE Flags
)
521 PoRequestPowerIrp(IN PDEVICE_OBJECT DeviceObject
,
522 IN UCHAR MinorFunction
,
523 IN POWER_STATE PowerState
,
524 IN PREQUEST_POWER_COMPLETE CompletionFunction
,
526 OUT PIRP
*pIrp OPTIONAL
)
528 PDEVICE_OBJECT TopDeviceObject
;
529 PIO_STACK_LOCATION Stack
;
531 PREQUEST_POWER_ITEM RequestPowerItem
;
533 if (MinorFunction
!= IRP_MN_QUERY_POWER
534 && MinorFunction
!= IRP_MN_SET_POWER
535 && MinorFunction
!= IRP_MN_WAIT_WAKE
)
536 return STATUS_INVALID_PARAMETER_2
;
538 RequestPowerItem
= ExAllocatePool(NonPagedPool
, sizeof(REQUEST_POWER_ITEM
));
539 if (!RequestPowerItem
)
540 return STATUS_INSUFFICIENT_RESOURCES
;
542 /* Always call the top of the device stack */
543 TopDeviceObject
= IoGetAttachedDeviceReference(DeviceObject
);
545 Irp
= IoBuildAsynchronousFsdRequest(IRP_MJ_POWER
,
553 ObDereferenceObject(TopDeviceObject
);
554 ExFreePool(RequestPowerItem
);
555 return STATUS_INSUFFICIENT_RESOURCES
;
558 /* POWER IRPs are always initialized with a status code of
559 STATUS_NOT_IMPLEMENTED */
560 Irp
->IoStatus
.Status
= STATUS_NOT_IMPLEMENTED
;
561 Irp
->IoStatus
.Information
= 0;
563 Stack
= IoGetNextIrpStackLocation(Irp
);
564 Stack
->MinorFunction
= MinorFunction
;
565 if (MinorFunction
== IRP_MN_WAIT_WAKE
)
566 Stack
->Parameters
.WaitWake
.PowerState
= PowerState
.SystemState
;
569 Stack
->Parameters
.Power
.Type
= DevicePowerState
;
570 Stack
->Parameters
.Power
.State
= PowerState
;
573 RequestPowerItem
->CompletionRoutine
= CompletionFunction
;
574 RequestPowerItem
->PowerState
= PowerState
;
575 RequestPowerItem
->Context
= Context
;
580 IoSetCompletionRoutine(Irp
, PopRequestPowerIrpCompletion
, RequestPowerItem
, TRUE
, TRUE
, TRUE
);
581 PoCallDriver(TopDeviceObject
, Irp
);
583 /* Always return STATUS_PENDING. The completion routine
584 * will call CompletionFunction and complete the Irp.
586 return STATUS_PENDING
;
594 PoSetPowerState(IN PDEVICE_OBJECT DeviceObject
,
595 IN POWER_STATE_TYPE Type
,
596 IN POWER_STATE State
)
600 ASSERT_IRQL_LESS_OR_EQUAL(DISPATCH_LEVEL
);
602 ps
.SystemState
= PowerSystemWorking
; // Fully on
603 ps
.DeviceState
= PowerDeviceD0
; // Fully on
613 PoSetSystemState(IN EXECUTION_STATE Flags
)
623 PoStartNextPowerIrp(IN PIRP Irp
)
633 PoUnregisterSystemState(IN PVOID StateHandle
)
643 PoQueueShutdownWorkItem(IN PWORK_QUEUE_ITEM WorkItem
)
648 return STATUS_NOT_IMPLEMENTED
;
656 NtInitiatePowerAction (IN POWER_ACTION SystemAction
,
657 IN SYSTEM_POWER_STATE MinSystemState
,
659 IN BOOLEAN Asynchronous
)
662 return STATUS_NOT_IMPLEMENTED
;
670 NtPowerInformation(IN POWER_INFORMATION_LEVEL PowerInformationLevel
,
671 IN PVOID InputBuffer OPTIONAL
,
672 IN ULONG InputBufferLength
,
673 OUT PVOID OutputBuffer OPTIONAL
,
674 IN ULONG OutputBufferLength
)
680 DPRINT("NtPowerInformation(PowerInformationLevel 0x%x, InputBuffer 0x%x, "
681 "InputBufferLength 0x%x, OutputBuffer 0x%x, OutputBufferLength 0x%x)\n",
682 PowerInformationLevel
,
683 InputBuffer
, InputBufferLength
,
684 OutputBuffer
, OutputBufferLength
);
686 switch (PowerInformationLevel
)
688 case SystemBatteryState
:
690 PSYSTEM_BATTERY_STATE BatteryState
= (PSYSTEM_BATTERY_STATE
)OutputBuffer
;
692 if (InputBuffer
!= NULL
)
693 return STATUS_INVALID_PARAMETER
;
694 if (OutputBufferLength
< sizeof(SYSTEM_BATTERY_STATE
))
695 return STATUS_BUFFER_TOO_SMALL
;
697 /* Just zero the struct (and thus set BatteryState->BatteryPresent = FALSE) */
698 RtlZeroMemory(BatteryState
, sizeof(SYSTEM_BATTERY_STATE
));
699 BatteryState
->EstimatedTime
= MAXULONG
;
701 Status
= STATUS_SUCCESS
;
704 case SystemPowerCapabilities
:
706 PSYSTEM_POWER_CAPABILITIES PowerCapabilities
= (PSYSTEM_POWER_CAPABILITIES
)OutputBuffer
;
708 if (InputBuffer
!= NULL
)
709 return STATUS_INVALID_PARAMETER
;
710 if (OutputBufferLength
< sizeof(SYSTEM_POWER_CAPABILITIES
))
711 return STATUS_BUFFER_TOO_SMALL
;
713 /* Just zero the struct (and thus set BatteryState->BatteryPresent = FALSE) */
714 RtlZeroMemory(PowerCapabilities
, sizeof(SYSTEM_POWER_CAPABILITIES
));
715 //PowerCapabilities->SystemBatteriesPresent = 0;
717 Status
= STATUS_SUCCESS
;
722 Status
= STATUS_NOT_IMPLEMENTED
;
723 DPRINT1("PowerInformationLevel 0x%x is UNIMPLEMENTED! Have a nice day.\n",
724 PowerInformationLevel
);
733 NtGetDevicePowerState(IN HANDLE Device
,
734 IN PDEVICE_POWER_STATE PowerState
)
737 return STATUS_NOT_IMPLEMENTED
;
742 NtIsSystemResumeAutomatic(VOID
)
750 NtRequestWakeupLatency(IN LATENCY_TIME Latency
)
753 return STATUS_NOT_IMPLEMENTED
;
758 NtSetThreadExecutionState(IN EXECUTION_STATE esFlags
,
759 OUT EXECUTION_STATE
*PreviousFlags
)
761 PKTHREAD Thread
= KeGetCurrentThread();
762 KPROCESSOR_MODE PreviousMode
= KeGetPreviousMode();
763 EXECUTION_STATE PreviousState
;
767 if (esFlags
& ~(ES_CONTINUOUS
| ES_USER_PRESENT
))
769 /* Fail the request */
770 return STATUS_INVALID_PARAMETER
;
773 /* Check for user parameters */
774 if (PreviousMode
!= KernelMode
)
776 /* Protect the probes */
779 /* Check if the pointer is valid */
780 ProbeForWriteUlong(PreviousFlags
);
782 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
784 /* It isn't -- fail */
785 _SEH2_YIELD(return _SEH2_GetExceptionCode());
790 /* Save the previous state, always masking in the continous flag */
791 PreviousState
= Thread
->PowerState
| ES_CONTINUOUS
;
793 /* Check if we need to update the power state */
794 if (esFlags
& ES_CONTINUOUS
) Thread
->PowerState
= (UCHAR
)esFlags
;
796 /* Protect the write back to user mode */
799 /* Return the previous flags */
800 *PreviousFlags
= PreviousState
;
802 _SEH2_EXCEPT(ExSystemExceptionFilter())
804 /* Something's wrong, fail */
805 _SEH2_YIELD(return _SEH2_GetExceptionCode());
810 return STATUS_SUCCESS
;
815 NtSetSystemPowerState(IN POWER_ACTION SystemAction
,
816 IN SYSTEM_POWER_STATE MinSystemState
,
819 KPROCESSOR_MODE PreviousMode
= KeGetPreviousMode();
820 POP_POWER_ACTION Action
= {0};
824 /* Check for invalid parameter combinations */
825 if ((MinSystemState
>= PowerSystemMaximum
) ||
826 (MinSystemState
<= PowerSystemUnspecified
) ||
827 (SystemAction
> PowerActionWarmEject
) ||
828 (SystemAction
< PowerActionReserved
) ||
829 (Flags
& ~(POWER_ACTION_QUERY_ALLOWED
|
830 POWER_ACTION_UI_ALLOWED
|
831 POWER_ACTION_OVERRIDE_APPS
|
832 POWER_ACTION_LIGHTEST_FIRST
|
833 POWER_ACTION_LOCK_CONSOLE
|
834 POWER_ACTION_DISABLE_WAKES
|
835 POWER_ACTION_CRITICAL
)))
837 DPRINT1("NtSetSystemPowerState: Bad parameters!\n");
838 DPRINT1(" SystemAction: 0x%x\n", SystemAction
);
839 DPRINT1(" MinSystemState: 0x%x\n", MinSystemState
);
840 DPRINT1(" Flags: 0x%x\n", Flags
);
841 return STATUS_INVALID_PARAMETER
;
844 /* Check for user caller */
845 if (PreviousMode
!= KernelMode
)
847 /* Check for shutdown permission */
848 if (!SeSinglePrivilegeCheck(SeShutdownPrivilege
, PreviousMode
))
851 DPRINT1("ERROR: Privilege not held for shutdown\n");
852 //return STATUS_PRIVILEGE_NOT_HELD; HACK!
855 /* Do it as a kernel-mode caller for consistency with system state */
856 return ZwSetSystemPowerState (SystemAction
, MinSystemState
, Flags
);
859 /* Read policy settings (partial shutdown vs. full shutdown) */
860 if (SystemAction
== PowerActionShutdown
) PopReadShutdownPolicy();
862 /* Disable lazy flushing of registry */
863 DPRINT1("Stopping lazy flush\n");
864 CmSetLazyFlushState(FALSE
);
866 /* Setup the power action */
867 Action
.Action
= SystemAction
;
868 Action
.Flags
= Flags
;
870 /* Notify callbacks */
871 DPRINT1("Notifying callbacks\n");
872 ExNotifyCallback(PowerStateCallback
, (PVOID
)3, NULL
);
874 /* Swap in any worker thread stacks */
875 DPRINT1("Swapping worker threads\n");
876 ExSwapinWorkerThreads(FALSE
);
878 /* Make our action global */
881 /* Start power loop */
882 Status
= STATUS_CANCELLED
;
885 /* Break out if there's nothing to do */
886 if (Action
.Action
== PowerActionNone
) break;
888 /* Check for first-pass or restart */
889 if (Status
== STATUS_CANCELLED
)
891 /* Check for shutdown action */
892 if ((PopAction
.Action
== PowerActionShutdown
) ||
893 (PopAction
.Action
== PowerActionShutdownReset
) ||
894 (PopAction
.Action
== PowerActionShutdownOff
))
897 PopAction
.Shutdown
= TRUE
;
900 /* Now we are good to go */
901 Status
= STATUS_SUCCESS
;
904 /* Check if we're still in an invalid status */
905 if (!NT_SUCCESS(Status
)) break;
908 /* Flush dirty cache pages */
909 CcRosFlushDirtyPages(-1, &Dummy
, FALSE
); //HACK: We really should wait here!
914 /* Flush all volumes and the registry */
915 DPRINT1("Flushing volumes, cache flushed %d pages\n", Dummy
);
916 PopFlushVolumes(PopAction
.Shutdown
);
918 /* Set IRP for drivers */
919 PopAction
.IrpMinor
= IRP_MN_SET_POWER
;
920 if (PopAction
.Shutdown
)
922 DPRINT1("Queueing shutdown thread\n");
923 /* Check if we are running in the system context */
924 if (PsGetCurrentProcess() != PsInitialSystemProcess
)
926 /* We're not, so use a worker thread for shutdown */
927 ExInitializeWorkItem(&PopShutdownWorkItem
,
928 &PopGracefulShutdown
,
931 ExQueueWorkItem(&PopShutdownWorkItem
, CriticalWorkQueue
);
933 /* Spend us -- when we wake up, the system is good to go down */
934 KeSuspendThread(KeGetCurrentThread());
935 Status
= STATUS_SYSTEM_SHUTDOWN
;
941 /* Do the shutdown inline */
942 PopGracefulShutdown(NULL
);
946 /* You should not have made it this far */
947 ASSERT(FALSE
&& "System is still up and running?!");
952 /* We're done, return */