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 ******************************************************************/
16 /* GLOBALS *******************************************************************/
18 typedef struct _POWER_STATE_TRAVERSE_CONTEXT
20 SYSTEM_POWER_STATE SystemPowerState
;
21 POWER_ACTION PowerAction
;
22 PDEVICE_OBJECT PowerDevice
;
23 } POWER_STATE_TRAVERSE_CONTEXT
, *PPOWER_STATE_TRAVERSE_CONTEXT
;
25 PDEVICE_NODE PopSystemPowerDeviceNode
= NULL
;
26 BOOLEAN PopAcpiPresent
= FALSE
;
27 POP_POWER_ACTION PopAction
;
28 WORK_QUEUE_ITEM PopShutdownWorkItem
;
30 /* PRIVATE FUNCTIONS *********************************************************/
35 PopRequestPowerIrpCompletion(IN PDEVICE_OBJECT DeviceObject
,
39 PIO_STACK_LOCATION Stack
;
40 PREQUEST_POWER_COMPLETE CompletionRoutine
;
41 POWER_STATE PowerState
;
43 Stack
= IoGetCurrentIrpStackLocation(Irp
);
44 CompletionRoutine
= Context
;
46 PowerState
.DeviceState
= (ULONG_PTR
)Stack
->Parameters
.Others
.Argument3
;
47 CompletionRoutine(Stack
->Parameters
.Others
.Argument1
,
48 (UCHAR
)(ULONG_PTR
)Stack
->Parameters
.Others
.Argument2
,
50 Stack
->Parameters
.Others
.Argument4
,
53 IoSkipCurrentIrpStackLocation(Irp
);
55 ObDereferenceObject(DeviceObject
);
57 return STATUS_MORE_PROCESSING_REQUIRED
;
62 PopCleanupPowerState(IN PPOWER_STATE PowerState
)
68 PopSendQuerySystemPowerState(PDEVICE_OBJECT DeviceObject
, SYSTEM_POWER_STATE SystemState
, POWER_ACTION PowerAction
)
71 IO_STATUS_BLOCK IoStatusBlock
;
72 PIO_STACK_LOCATION IrpSp
;
76 KeInitializeEvent(&Event
,
80 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_POWER
,
87 if (!Irp
) return STATUS_INSUFFICIENT_RESOURCES
;
89 IrpSp
= IoGetNextIrpStackLocation(Irp
);
90 IrpSp
->MinorFunction
= IRP_MN_QUERY_POWER
;
91 IrpSp
->Parameters
.Power
.Type
= SystemPowerState
;
92 IrpSp
->Parameters
.Power
.State
.SystemState
= SystemState
;
93 IrpSp
->Parameters
.Power
.ShutdownType
= PowerAction
;
95 Status
= PoCallDriver(DeviceObject
, Irp
);
96 if (Status
== STATUS_PENDING
)
98 KeWaitForSingleObject(&Event
,
103 Status
= IoStatusBlock
.Status
;
110 PopSendSetSystemPowerState(PDEVICE_OBJECT DeviceObject
, SYSTEM_POWER_STATE SystemState
, POWER_ACTION PowerAction
)
113 IO_STATUS_BLOCK IoStatusBlock
;
114 PIO_STACK_LOCATION IrpSp
;
118 KeInitializeEvent(&Event
,
122 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_POWER
,
129 if (!Irp
) return STATUS_INSUFFICIENT_RESOURCES
;
131 IrpSp
= IoGetNextIrpStackLocation(Irp
);
132 IrpSp
->MinorFunction
= IRP_MN_SET_POWER
;
133 IrpSp
->Parameters
.Power
.Type
= SystemPowerState
;
134 IrpSp
->Parameters
.Power
.State
.SystemState
= SystemState
;
135 IrpSp
->Parameters
.Power
.ShutdownType
= PowerAction
;
137 Status
= PoCallDriver(DeviceObject
, Irp
);
138 if (Status
== STATUS_PENDING
)
140 KeWaitForSingleObject(&Event
,
145 Status
= IoStatusBlock
.Status
;
152 PopQuerySystemPowerStateTraverse(PDEVICE_NODE DeviceNode
,
155 PPOWER_STATE_TRAVERSE_CONTEXT PowerStateContext
= Context
;
158 DPRINT("PopQuerySystemPowerStateTraverse(%p, %p)\n", DeviceNode
, Context
);
160 if (DeviceNode
== IopRootDeviceNode
)
161 return STATUS_SUCCESS
;
163 if (DeviceNode
->Flags
& DNF_LEGACY_DRIVER
)
164 return STATUS_SUCCESS
;
166 Status
= PopSendQuerySystemPowerState(DeviceNode
->PhysicalDeviceObject
,
167 PowerStateContext
->SystemPowerState
,
168 PowerStateContext
->PowerAction
);
169 if (!NT_SUCCESS(Status
))
171 DPRINT1("Device '%wZ' failed IRP_MN_QUERY_POWER\n", &DeviceNode
->InstancePath
);
177 return STATUS_SUCCESS
;
182 PopSetSystemPowerStateTraverse(PDEVICE_NODE DeviceNode
,
185 PPOWER_STATE_TRAVERSE_CONTEXT PowerStateContext
= Context
;
188 DPRINT("PopSetSystemPowerStateTraverse(%p, %p)\n", DeviceNode
, Context
);
190 if (DeviceNode
== IopRootDeviceNode
)
191 return STATUS_SUCCESS
;
193 if (DeviceNode
->PhysicalDeviceObject
== PowerStateContext
->PowerDevice
)
194 return STATUS_SUCCESS
;
196 if (DeviceNode
->Flags
& DNF_LEGACY_DRIVER
)
197 return STATUS_SUCCESS
;
199 Status
= PopSendSetSystemPowerState(DeviceNode
->PhysicalDeviceObject
,
200 PowerStateContext
->SystemPowerState
,
201 PowerStateContext
->PowerAction
);
202 if (!NT_SUCCESS(Status
))
204 DPRINT1("Device '%wZ' failed IRP_MN_SET_POWER\n", &DeviceNode
->InstancePath
);
210 return STATUS_SUCCESS
;
216 PopSetSystemPowerState(SYSTEM_POWER_STATE PowerState
, POWER_ACTION PowerAction
)
218 PDEVICE_OBJECT DeviceObject
;
221 DEVICETREE_TRAVERSE_CONTEXT Context
;
222 POWER_STATE_TRAVERSE_CONTEXT PowerContext
;
224 Status
= IopGetSystemPowerDeviceObject(&DeviceObject
);
225 if (!NT_SUCCESS(Status
))
227 DPRINT1("No system power driver available\n");
232 Fdo
= IoGetAttachedDeviceReference(DeviceObject
);
233 if (Fdo
== DeviceObject
)
235 DPRINT("An FDO was not attached\n");
236 return STATUS_UNSUCCESSFUL
;
241 PowerContext
.PowerAction
= PowerAction
;
242 PowerContext
.SystemPowerState
= PowerState
;
243 PowerContext
.PowerDevice
= Fdo
;
245 /* Query for system power change */
246 IopInitDeviceTreeTraverseContext(&Context
,
248 PopQuerySystemPowerStateTraverse
,
251 Status
= IopTraverseDeviceTree(&Context
);
252 if (!NT_SUCCESS(Status
))
254 DPRINT1("Query system power state failed; changing state anyway\n");
257 /* Set system power change */
258 IopInitDeviceTreeTraverseContext(&Context
,
260 PopSetSystemPowerStateTraverse
,
263 IopTraverseDeviceTree(&Context
);
265 if (!PopAcpiPresent
) return STATUS_NOT_IMPLEMENTED
;
269 if (PowerAction
!= PowerActionShutdownReset
)
270 PopSendSetSystemPowerState(Fdo
, PowerState
, PowerAction
);
272 ObDereferenceObject(Fdo
);
281 PoInitSystem(IN ULONG BootPhase
)
283 PVOID NotificationEntry
;
285 BOOLEAN ForceAcpiDisable
= FALSE
;
287 /* Check if this is phase 1 init */
290 /* Register power button notification */
291 IoRegisterPlugPlayNotification(EventCategoryDeviceInterfaceChange
,
292 PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES
,
293 (PVOID
)&GUID_DEVICE_SYS_BUTTON
,
295 PhysicalDeviceObject
->DriverObject
,
296 PopAddRemoveSysCapsCallback
,
300 /* Register lid notification */
301 IoRegisterPlugPlayNotification(EventCategoryDeviceInterfaceChange
,
302 PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES
,
303 (PVOID
)&GUID_DEVICE_LID
,
305 PhysicalDeviceObject
->DriverObject
,
306 PopAddRemoveSysCapsCallback
,
312 /* Get the Command Line */
313 CommandLine
= KeLoaderBlock
->LoadOptions
;
316 _strupr(CommandLine
);
318 /* Check for ACPI disable */
319 if (strstr(CommandLine
, "NOACPI")) ForceAcpiDisable
= TRUE
;
321 if (ForceAcpiDisable
)
323 /* Set the ACPI State to False if it's been forced that way */
324 PopAcpiPresent
= FALSE
;
328 /* Otherwise check if the LoaderBlock has a ACPI Table */
329 PopAcpiPresent
= KeLoaderBlock
->Extension
->AcpiTable
!= NULL
? TRUE
: FALSE
;
333 /* Initialize volume support */
334 InitializeListHead(&PopVolumeDevices
);
335 KeInitializeGuardedMutex(&PopVolumeLock
);
337 /* Initialize support for dope */
338 KeInitializeSpinLock(&PopDopeGlobalLock
);
340 /* Initialize support for shutdown waits and work-items */
341 PopInitShutdownList();
348 PopPerfIdle(PPROCESSOR_POWER_STATE PowerState
)
350 DPRINT1("PerfIdle function: %p\n", PowerState
);
355 PopPerfIdleDpc(IN PKDPC Dpc
,
356 IN PVOID DeferredContext
,
357 IN PVOID SystemArgument1
,
358 IN PVOID SystemArgument2
)
360 /* Call the Perf Idle function */
361 PopPerfIdle(&((PKPRCB
)DeferredContext
)->PowerState
);
366 PopIdle0(IN PPROCESSOR_POWER_STATE PowerState
)
368 /* FIXME: Extremly naive implementation */
375 PoInitializePrcb(IN PKPRCB Prcb
)
377 /* Initialize the Power State */
378 RtlZeroMemory(&Prcb
->PowerState
, sizeof(Prcb
->PowerState
));
379 Prcb
->PowerState
.Idle0KernelTimeLimit
= 0xFFFFFFFF;
380 Prcb
->PowerState
.CurrentThrottle
= 100;
381 Prcb
->PowerState
.CurrentThrottleIndex
= 0;
382 Prcb
->PowerState
.IdleFunction
= PopIdle0
;
384 /* Initialize the Perf DPC and Timer */
385 KeInitializeDpc(&Prcb
->PowerState
.PerfDpc
, PopPerfIdleDpc
, Prcb
);
386 KeSetTargetProcessorDpc(&Prcb
->PowerState
.PerfDpc
, Prcb
->Number
);
387 KeInitializeTimerEx(&Prcb
->PowerState
.PerfTimer
, SynchronizationTimer
);
390 /* PUBLIC FUNCTIONS **********************************************************/
397 PoCancelDeviceNotify(IN PVOID NotifyBlock
)
400 return STATUS_NOT_IMPLEMENTED
;
408 PoRegisterDeviceNotify(OUT PVOID Unknown0
,
416 return STATUS_NOT_IMPLEMENTED
;
424 PoShutdownBugCheck(IN BOOLEAN LogError
,
425 IN ULONG BugCheckCode
,
426 IN ULONG_PTR BugCheckParameter1
,
427 IN ULONG_PTR BugCheckParameter2
,
428 IN ULONG_PTR BugCheckParameter3
,
429 IN ULONG_PTR BugCheckParameter4
)
431 DPRINT1("PoShutdownBugCheck called\n");
433 /* FIXME: Log error if requested */
434 /* FIXME: Initiate a shutdown */
436 /* Bugcheck the system */
437 KeBugCheckEx(BugCheckCode
,
449 PoSetHiberRange(IN PVOID HiberContext
,
451 IN OUT PVOID StartPage
,
464 PoCallDriver(IN PDEVICE_OBJECT DeviceObject
,
469 /* Forward to Io -- FIXME! */
470 Status
= IoCallDriver(DeviceObject
, Irp
);
481 PoRegisterDeviceForIdleDetection(IN PDEVICE_OBJECT DeviceObject
,
482 IN ULONG ConservationIdleTime
,
483 IN ULONG PerformanceIdleTime
,
484 IN DEVICE_POWER_STATE State
)
495 PoRegisterSystemState(IN PVOID StateHandle
,
496 IN EXECUTION_STATE Flags
)
507 PoRequestPowerIrp(IN PDEVICE_OBJECT DeviceObject
,
508 IN UCHAR MinorFunction
,
509 IN POWER_STATE PowerState
,
510 IN PREQUEST_POWER_COMPLETE CompletionFunction
,
512 OUT PIRP
*pIrp OPTIONAL
)
514 PDEVICE_OBJECT TopDeviceObject
;
515 PIO_STACK_LOCATION Stack
;
518 if (MinorFunction
!= IRP_MN_QUERY_POWER
519 && MinorFunction
!= IRP_MN_SET_POWER
520 && MinorFunction
!= IRP_MN_WAIT_WAKE
)
521 return STATUS_INVALID_PARAMETER_2
;
523 /* Always call the top of the device stack */
524 TopDeviceObject
= IoGetAttachedDeviceReference(DeviceObject
);
526 Irp
= IoAllocateIrp(TopDeviceObject
->StackSize
+ 2, FALSE
);
529 ObDereferenceObject(TopDeviceObject
);
530 return STATUS_INSUFFICIENT_RESOURCES
;
533 Irp
->IoStatus
.Status
= STATUS_NOT_SUPPORTED
;
534 Irp
->IoStatus
.Information
= 0;
536 IoSetNextIrpStackLocation(Irp
);
538 Stack
= IoGetNextIrpStackLocation(Irp
);
539 Stack
->Parameters
.Others
.Argument1
= DeviceObject
;
540 Stack
->Parameters
.Others
.Argument2
= (PVOID
)(ULONG_PTR
)MinorFunction
;
541 Stack
->Parameters
.Others
.Argument3
= (PVOID
)(ULONG_PTR
)PowerState
.DeviceState
;
542 Stack
->Parameters
.Others
.Argument4
= Context
;
543 Stack
->DeviceObject
= TopDeviceObject
;
544 IoSetNextIrpStackLocation(Irp
);
546 Stack
= IoGetNextIrpStackLocation(Irp
);
547 Stack
->MajorFunction
= IRP_MJ_POWER
;
548 Stack
->MinorFunction
= MinorFunction
;
549 if (MinorFunction
== IRP_MN_WAIT_WAKE
)
551 Stack
->Parameters
.WaitWake
.PowerState
= PowerState
.SystemState
;
555 Stack
->Parameters
.Power
.Type
= DevicePowerState
;
556 Stack
->Parameters
.Power
.State
= PowerState
;
562 IoSetCompletionRoutine(Irp
, PopRequestPowerIrpCompletion
, CompletionFunction
, TRUE
, TRUE
, TRUE
);
563 PoCallDriver(TopDeviceObject
, Irp
);
565 /* Always return STATUS_PENDING. The completion routine
566 * will call CompletionFunction and complete the Irp.
568 return STATUS_PENDING
;
576 PoSetPowerState(IN PDEVICE_OBJECT DeviceObject
,
577 IN POWER_STATE_TYPE Type
,
578 IN POWER_STATE State
)
582 ASSERT_IRQL_LESS_OR_EQUAL(DISPATCH_LEVEL
);
584 ps
.SystemState
= PowerSystemWorking
; // Fully on
585 ps
.DeviceState
= PowerDeviceD0
; // Fully on
595 PoSetSystemState(IN EXECUTION_STATE Flags
)
605 PoStartNextPowerIrp(IN PIRP Irp
)
615 PoUnregisterSystemState(IN PVOID StateHandle
)
625 NtInitiatePowerAction (IN POWER_ACTION SystemAction
,
626 IN SYSTEM_POWER_STATE MinSystemState
,
628 IN BOOLEAN Asynchronous
)
631 return STATUS_NOT_IMPLEMENTED
;
639 NtPowerInformation(IN POWER_INFORMATION_LEVEL PowerInformationLevel
,
640 IN PVOID InputBuffer OPTIONAL
,
641 IN ULONG InputBufferLength
,
642 OUT PVOID OutputBuffer OPTIONAL
,
643 IN ULONG OutputBufferLength
)
649 DPRINT("NtPowerInformation(PowerInformationLevel 0x%x, InputBuffer 0x%p, "
650 "InputBufferLength 0x%x, OutputBuffer 0x%p, OutputBufferLength 0x%x)\n",
651 PowerInformationLevel
,
652 InputBuffer
, InputBufferLength
,
653 OutputBuffer
, OutputBufferLength
);
655 switch (PowerInformationLevel
)
657 case SystemBatteryState
:
659 PSYSTEM_BATTERY_STATE BatteryState
= (PSYSTEM_BATTERY_STATE
)OutputBuffer
;
661 if (InputBuffer
!= NULL
)
662 return STATUS_INVALID_PARAMETER
;
663 if (OutputBufferLength
< sizeof(SYSTEM_BATTERY_STATE
))
664 return STATUS_BUFFER_TOO_SMALL
;
666 /* Just zero the struct (and thus set BatteryState->BatteryPresent = FALSE) */
667 RtlZeroMemory(BatteryState
, sizeof(SYSTEM_BATTERY_STATE
));
668 BatteryState
->EstimatedTime
= MAXULONG
;
670 Status
= STATUS_SUCCESS
;
674 case SystemPowerCapabilities
:
676 PSYSTEM_POWER_CAPABILITIES PowerCapabilities
= (PSYSTEM_POWER_CAPABILITIES
)OutputBuffer
;
678 if (InputBuffer
!= NULL
)
679 return STATUS_INVALID_PARAMETER
;
680 if (OutputBufferLength
< sizeof(SYSTEM_POWER_CAPABILITIES
))
681 return STATUS_BUFFER_TOO_SMALL
;
683 /* Just zero the struct (and thus set BatteryState->BatteryPresent = FALSE) */
684 RtlZeroMemory(PowerCapabilities
, sizeof(SYSTEM_POWER_CAPABILITIES
));
685 //PowerCapabilities->SystemBatteriesPresent = 0;
687 Status
= STATUS_SUCCESS
;
692 Status
= STATUS_NOT_IMPLEMENTED
;
693 DPRINT1("PowerInformationLevel 0x%x is UNIMPLEMENTED! Have a nice day.\n",
694 PowerInformationLevel
);
703 NtGetDevicePowerState(IN HANDLE Device
,
704 IN PDEVICE_POWER_STATE PowerState
)
707 return STATUS_NOT_IMPLEMENTED
;
712 NtIsSystemResumeAutomatic(VOID
)
720 NtRequestWakeupLatency(IN LATENCY_TIME Latency
)
723 return STATUS_NOT_IMPLEMENTED
;
728 NtSetThreadExecutionState(IN EXECUTION_STATE esFlags
,
729 OUT EXECUTION_STATE
*PreviousFlags
)
731 PKTHREAD Thread
= KeGetCurrentThread();
732 KPROCESSOR_MODE PreviousMode
= KeGetPreviousMode();
733 EXECUTION_STATE PreviousState
;
737 if (esFlags
& ~(ES_CONTINUOUS
| ES_USER_PRESENT
))
739 /* Fail the request */
740 return STATUS_INVALID_PARAMETER
;
743 /* Check for user parameters */
744 if (PreviousMode
!= KernelMode
)
746 /* Protect the probes */
749 /* Check if the pointer is valid */
750 ProbeForWriteUlong(PreviousFlags
);
752 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
754 /* It isn't -- fail */
755 _SEH2_YIELD(return _SEH2_GetExceptionCode());
760 /* Save the previous state, always masking in the continous flag */
761 PreviousState
= Thread
->PowerState
| ES_CONTINUOUS
;
763 /* Check if we need to update the power state */
764 if (esFlags
& ES_CONTINUOUS
) Thread
->PowerState
= (UCHAR
)esFlags
;
766 /* Protect the write back to user mode */
769 /* Return the previous flags */
770 *PreviousFlags
= PreviousState
;
772 _SEH2_EXCEPT(ExSystemExceptionFilter())
774 /* Something's wrong, fail */
775 _SEH2_YIELD(return _SEH2_GetExceptionCode());
780 return STATUS_SUCCESS
;
785 NtSetSystemPowerState(IN POWER_ACTION SystemAction
,
786 IN SYSTEM_POWER_STATE MinSystemState
,
789 KPROCESSOR_MODE PreviousMode
= KeGetPreviousMode();
790 POP_POWER_ACTION Action
= {0};
794 /* Check for invalid parameter combinations */
795 if ((MinSystemState
>= PowerSystemMaximum
) ||
796 (MinSystemState
<= PowerSystemUnspecified
) ||
797 (SystemAction
> PowerActionWarmEject
) ||
798 (SystemAction
< PowerActionReserved
) ||
799 (Flags
& ~(POWER_ACTION_QUERY_ALLOWED
|
800 POWER_ACTION_UI_ALLOWED
|
801 POWER_ACTION_OVERRIDE_APPS
|
802 POWER_ACTION_LIGHTEST_FIRST
|
803 POWER_ACTION_LOCK_CONSOLE
|
804 POWER_ACTION_DISABLE_WAKES
|
805 POWER_ACTION_CRITICAL
)))
807 DPRINT1("NtSetSystemPowerState: Bad parameters!\n");
808 DPRINT1(" SystemAction: 0x%x\n", SystemAction
);
809 DPRINT1(" MinSystemState: 0x%x\n", MinSystemState
);
810 DPRINT1(" Flags: 0x%x\n", Flags
);
811 return STATUS_INVALID_PARAMETER
;
814 /* Check for user caller */
815 if (PreviousMode
!= KernelMode
)
817 /* Check for shutdown permission */
818 if (!SeSinglePrivilegeCheck(SeShutdownPrivilege
, PreviousMode
))
821 DPRINT1("ERROR: Privilege not held for shutdown\n");
822 return STATUS_PRIVILEGE_NOT_HELD
;
825 /* Do it as a kernel-mode caller for consistency with system state */
826 return ZwSetSystemPowerState(SystemAction
, MinSystemState
, Flags
);
829 /* Read policy settings (partial shutdown vs. full shutdown) */
830 if (SystemAction
== PowerActionShutdown
) PopReadShutdownPolicy();
832 /* Disable lazy flushing of registry */
833 DPRINT("Stopping lazy flush\n");
834 CmSetLazyFlushState(FALSE
);
836 /* Setup the power action */
837 Action
.Action
= SystemAction
;
838 Action
.Flags
= Flags
;
840 /* Notify callbacks */
841 DPRINT("Notifying callbacks\n");
842 ExNotifyCallback(PowerStateCallback
, (PVOID
)3, NULL
);
844 /* Swap in any worker thread stacks */
845 DPRINT("Swapping worker threads\n");
846 ExSwapinWorkerThreads(FALSE
);
848 /* Make our action global */
851 /* Start power loop */
852 Status
= STATUS_CANCELLED
;
855 /* Break out if there's nothing to do */
856 if (Action
.Action
== PowerActionNone
) break;
858 /* Check for first-pass or restart */
859 if (Status
== STATUS_CANCELLED
)
861 /* Check for shutdown action */
862 if ((PopAction
.Action
== PowerActionShutdown
) ||
863 (PopAction
.Action
== PowerActionShutdownReset
) ||
864 (PopAction
.Action
== PowerActionShutdownOff
))
867 PopAction
.Shutdown
= TRUE
;
870 /* Now we are good to go */
871 Status
= STATUS_SUCCESS
;
874 /* Check if we're still in an invalid status */
875 if (!NT_SUCCESS(Status
)) break;
878 /* Flush dirty cache pages */
879 CcRosFlushDirtyPages(-1, &Dummy
, FALSE
); //HACK: We really should wait here!
884 /* Flush all volumes and the registry */
885 DPRINT("Flushing volumes, cache flushed %lu pages\n", Dummy
);
886 PopFlushVolumes(PopAction
.Shutdown
);
888 /* Set IRP for drivers */
889 PopAction
.IrpMinor
= IRP_MN_SET_POWER
;
890 if (PopAction
.Shutdown
)
892 DPRINT("Queueing shutdown thread\n");
893 /* Check if we are running in the system context */
894 if (PsGetCurrentProcess() != PsInitialSystemProcess
)
896 /* We're not, so use a worker thread for shutdown */
897 ExInitializeWorkItem(&PopShutdownWorkItem
,
898 &PopGracefulShutdown
,
901 ExQueueWorkItem(&PopShutdownWorkItem
, CriticalWorkQueue
);
903 /* Spend us -- when we wake up, the system is good to go down */
904 KeSuspendThread(KeGetCurrentThread());
905 Status
= STATUS_SYSTEM_SHUTDOWN
;
911 /* Do the shutdown inline */
912 PopGracefulShutdown(NULL
);
916 /* You should not have made it this far */
917 // ASSERTMSG("System is still up and running?!", FALSE);
918 DPRINT1("System is still up and running, you may not have chosen a yet supported power option: %u\n", PopAction
.Action
);
923 /* We're done, return */