ReactOS  0.4.14-dev-554-g2f8d847
power.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for power.c:

Go to the source code of this file.

Classes

struct  _POWER_STATE_TRAVERSE_CONTEXT
 

Macros

#define NDEBUG
 

Typedefs

typedef struct _POWER_STATE_TRAVERSE_CONTEXT POWER_STATE_TRAVERSE_CONTEXT
 
typedef struct _POWER_STATE_TRAVERSE_CONTEXTPPOWER_STATE_TRAVERSE_CONTEXT
 

Functions

static NTSTATUS NTAPI PopRequestPowerIrpCompletion (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
 
VOID NTAPI PopCleanupPowerState (IN PPOWER_STATE PowerState)
 
NTSTATUS PopSendQuerySystemPowerState (PDEVICE_OBJECT DeviceObject, SYSTEM_POWER_STATE SystemState, POWER_ACTION PowerAction)
 
NTSTATUS PopSendSetSystemPowerState (PDEVICE_OBJECT DeviceObject, SYSTEM_POWER_STATE SystemState, POWER_ACTION PowerAction)
 
NTSTATUS PopQuerySystemPowerStateTraverse (PDEVICE_NODE DeviceNode, PVOID Context)
 
NTSTATUS PopSetSystemPowerStateTraverse (PDEVICE_NODE DeviceNode, PVOID Context)
 
NTSTATUS NTAPI PopSetSystemPowerState (SYSTEM_POWER_STATE PowerState, POWER_ACTION PowerAction)
 
INIT_FUNCTION BOOLEAN NTAPI PoInitSystem (IN ULONG BootPhase)
 
VOID NTAPI PopPerfIdle (PPROCESSOR_POWER_STATE PowerState)
 
VOID NTAPI PopPerfIdleDpc (IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
 
VOID FASTCALL PopIdle0 (IN PPROCESSOR_POWER_STATE PowerState)
 
INIT_FUNCTION VOID NTAPI PoInitializePrcb (IN PKPRCB Prcb)
 
NTSTATUS NTAPI PoCancelDeviceNotify (IN PVOID NotifyBlock)
 
NTSTATUS NTAPI PoRegisterDeviceNotify (OUT PVOID Unknown0, IN ULONG Unknown1, IN ULONG Unknown2, IN ULONG Unknown3, IN PVOID Unknown4, IN PVOID Unknown5)
 
VOID NTAPI PoShutdownBugCheck (IN BOOLEAN LogError, IN ULONG BugCheckCode, IN ULONG_PTR BugCheckParameter1, IN ULONG_PTR BugCheckParameter2, IN ULONG_PTR BugCheckParameter3, IN ULONG_PTR BugCheckParameter4)
 
VOID NTAPI PoSetHiberRange (IN PVOID HiberContext, IN ULONG Flags, IN OUT PVOID StartPage, IN ULONG Length, IN ULONG PageTag)
 
NTSTATUS NTAPI PoCallDriver (IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
PULONG NTAPI PoRegisterDeviceForIdleDetection (IN PDEVICE_OBJECT DeviceObject, IN ULONG ConservationIdleTime, IN ULONG PerformanceIdleTime, IN DEVICE_POWER_STATE State)
 
PVOID NTAPI PoRegisterSystemState (IN PVOID StateHandle, IN EXECUTION_STATE Flags)
 
NTSTATUS NTAPI PoRequestPowerIrp (IN PDEVICE_OBJECT DeviceObject, IN UCHAR MinorFunction, IN POWER_STATE PowerState, IN PREQUEST_POWER_COMPLETE CompletionFunction, IN PVOID Context, OUT PIRP *pIrp OPTIONAL)
 
POWER_STATE NTAPI PoSetPowerState (IN PDEVICE_OBJECT DeviceObject, IN POWER_STATE_TYPE Type, IN POWER_STATE State)
 
VOID NTAPI PoSetSystemState (IN EXECUTION_STATE Flags)
 
VOID NTAPI PoStartNextPowerIrp (IN PIRP Irp)
 
VOID NTAPI PoUnregisterSystemState (IN PVOID StateHandle)
 
NTSTATUS NTAPI NtInitiatePowerAction (IN POWER_ACTION SystemAction, IN SYSTEM_POWER_STATE MinSystemState, IN ULONG Flags, IN BOOLEAN Asynchronous)
 
NTSTATUS NTAPI NtPowerInformation (IN POWER_INFORMATION_LEVEL PowerInformationLevel, IN PVOID InputBuffer OPTIONAL, IN ULONG InputBufferLength, OUT PVOID OutputBuffer OPTIONAL, IN ULONG OutputBufferLength)
 
NTSTATUS NTAPI NtGetDevicePowerState (IN HANDLE Device, IN PDEVICE_POWER_STATE PowerState)
 
BOOLEAN NTAPI NtIsSystemResumeAutomatic (VOID)
 
NTSTATUS NTAPI NtRequestWakeupLatency (IN LATENCY_TIME Latency)
 
NTSTATUS NTAPI NtSetThreadExecutionState (IN EXECUTION_STATE esFlags, OUT EXECUTION_STATE *PreviousFlags)
 
NTSTATUS NTAPI NtSetSystemPowerState (IN POWER_ACTION SystemAction, IN SYSTEM_POWER_STATE MinSystemState, IN ULONG Flags)
 

Variables

PDEVICE_NODE PopSystemPowerDeviceNode = NULL
 
BOOLEAN PopAcpiPresent = FALSE
 
POP_POWER_ACTION PopAction
 
WORK_QUEUE_ITEM PopShutdownWorkItem
 
SYSTEM_POWER_CAPABILITIES PopCapabilities
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file power.c.

Typedef Documentation

◆ POWER_STATE_TRAVERSE_CONTEXT

◆ PPOWER_STATE_TRAVERSE_CONTEXT

Function Documentation

◆ NtGetDevicePowerState()

NTSTATUS NTAPI NtGetDevicePowerState ( IN HANDLE  Device,
IN PDEVICE_POWER_STATE  PowerState 
)

Definition at line 787 of file power.c.

789 {
791  return STATUS_NOT_IMPLEMENTED;
792 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define UNIMPLEMENTED
Definition: debug.h:114

Referenced by GetDevicePowerState().

◆ NtInitiatePowerAction()

NTSTATUS NTAPI NtInitiatePowerAction ( IN POWER_ACTION  SystemAction,
IN SYSTEM_POWER_STATE  MinSystemState,
IN ULONG  Flags,
IN BOOLEAN  Asynchronous 
)

Definition at line 646 of file power.c.

650 {
652  return STATUS_NOT_IMPLEMENTED;
653 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define UNIMPLEMENTED
Definition: debug.h:114

Referenced by SetSystemPowerState(), ShutDown_Hibernate(), and ShutDown_StandBy().

◆ NtIsSystemResumeAutomatic()

BOOLEAN NTAPI NtIsSystemResumeAutomatic ( VOID  )

Definition at line 796 of file power.c.

797 {
799  return FALSE;
800 }
#define UNIMPLEMENTED
Definition: debug.h:114

Referenced by IsSystemResumeAutomatic().

◆ NtPowerInformation()

NTSTATUS NTAPI NtPowerInformation ( IN POWER_INFORMATION_LEVEL  PowerInformationLevel,
IN PVOID InputBuffer  OPTIONAL,
IN ULONG  InputBufferLength,
OUT PVOID OutputBuffer  OPTIONAL,
IN ULONG  OutputBufferLength 
)

Definition at line 660 of file power.c.

665 {
668 
669  PAGED_CODE();
670 
671  DPRINT("NtPowerInformation(PowerInformationLevel 0x%x, InputBuffer 0x%p, "
672  "InputBufferLength 0x%x, OutputBuffer 0x%p, OutputBufferLength 0x%x)\n",
673  PowerInformationLevel,
676 
677  if (PreviousMode != KernelMode)
678  {
679  _SEH2_TRY
680  {
683  }
685  {
687  }
688  _SEH2_END;
689  }
690 
691  switch (PowerInformationLevel)
692  {
693  case SystemBatteryState:
694  {
696 
697  if (InputBuffer != NULL)
701 
702  _SEH2_TRY
703  {
704  /* Just zero the struct (and thus set BatteryState->BatteryPresent = FALSE) */
705  RtlZeroMemory(BatteryState, sizeof(SYSTEM_BATTERY_STATE));
706  BatteryState->EstimatedTime = MAXULONG;
707 // BatteryState->AcOnLine = TRUE;
708 
710  }
712  {
714  }
715  _SEH2_END;
716 
717  break;
718  }
719 
721  {
723 
724  if (InputBuffer != NULL)
728 
729  _SEH2_TRY
730  {
731  RtlCopyMemory(PowerCapabilities,
733  sizeof(SYSTEM_POWER_CAPABILITIES));
734 
736  }
738  {
740  }
741  _SEH2_END;
742 
743  break;
744  }
745 
747  {
749 
750  if (InputBuffer != NULL)
754 
755  _SEH2_TRY
756  {
757  PowerInformation->Number = 0;
758  PowerInformation->MaxMhz = 1000;
759  PowerInformation->CurrentMhz = 1000;
760  PowerInformation->MhzLimit = 1000;
761  PowerInformation->MaxIdleState = 0;
762  PowerInformation->CurrentIdleState = 0;
763 
765  }
767  {
769  }
770  _SEH2_END;
771 
772  break;
773  }
774 
775  default:
777  DPRINT1("PowerInformationLevel 0x%x is UNIMPLEMENTED! Have a nice day.\n",
778  PowerInformationLevel);
779  break;
780  }
781 
782  return Status;
783 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define KeGetPreviousMode()
Definition: ketypes.h:1107
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG _In_ ULONG OutputBufferLength
Definition: fltkernel.h:1374
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
#define PAGED_CODE()
Definition: video.h:57
CHAR InputBuffer[80]
Definition: conmgr.c:33
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
_SEH2_TRY
Definition: create.c:4250
struct SYSTEM_POWER_CAPABILITIES * PSYSTEM_POWER_CAPABILITIES
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID OutputBuffer
Definition: iofuncs.h:713
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG InputBufferLength
Definition: fltkernel.h:1372
Status
Definition: gdiplustypes.h:24
#define MAXULONG
Definition: typedefs.h:250
struct SYSTEM_BATTERY_STATE * PSYSTEM_BATTERY_STATE
_SEH2_END
Definition: create.c:4424
SYSTEM_POWER_CAPABILITIES PopCapabilities
Definition: power.c:29
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
return STATUS_SUCCESS
Definition: btrfs.c:2938
struct _PROCESSOR_POWER_INFORMATION * PPROCESSOR_POWER_INFORMATION

Referenced by CallNtPowerInformation(), get_processor_currentclockspeed(), get_processor_maxclockspeed(), GetPwrCapabilities(), GetSystemPowerStatus(), InitFunctionPtrs(), IsPwrHibernateAllowed(), IsPwrShutdownAllowed(), IsPwrSuspendAllowed(), and ValidatePowerPolicies().

◆ NtRequestWakeupLatency()

NTSTATUS NTAPI NtRequestWakeupLatency ( IN LATENCY_TIME  Latency)

Definition at line 804 of file power.c.

805 {
807  return STATUS_NOT_IMPLEMENTED;
808 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define UNIMPLEMENTED
Definition: debug.h:114

Referenced by RequestWakeupLatency().

◆ NtSetSystemPowerState()

NTSTATUS NTAPI NtSetSystemPowerState ( IN POWER_ACTION  SystemAction,
IN SYSTEM_POWER_STATE  MinSystemState,
IN ULONG  Flags 
)

Definition at line 869 of file power.c.

872 {
874  POP_POWER_ACTION Action = {0};
876  ULONG Dummy;
877 
878  /* Check for invalid parameter combinations */
881  (SystemAction > PowerActionWarmEject) ||
882  (SystemAction < PowerActionReserved) ||
890  {
891  DPRINT1("NtSetSystemPowerState: Bad parameters!\n");
892  DPRINT1(" SystemAction: 0x%x\n", SystemAction);
893  DPRINT1(" MinSystemState: 0x%x\n", MinSystemState);
894  DPRINT1(" Flags: 0x%x\n", Flags);
896  }
897 
898  /* Check for user caller */
899  if (PreviousMode != KernelMode)
900  {
901  /* Check for shutdown permission */
903  {
904  /* Not granted */
905  DPRINT1("ERROR: Privilege not held for shutdown\n");
907  }
908 
909  /* Do it as a kernel-mode caller for consistency with system state */
910  return ZwSetSystemPowerState(SystemAction, MinSystemState, Flags);
911  }
912 
913  /* Read policy settings (partial shutdown vs. full shutdown) */
914  if (SystemAction == PowerActionShutdown) PopReadShutdownPolicy();
915 
916  /* Disable lazy flushing of registry */
917  DPRINT("Stopping lazy flush\n");
919 
920  /* Setup the power action */
921  Action.Action = SystemAction;
922  Action.Flags = Flags;
923 
924  /* Notify callbacks */
925  DPRINT("Notifying callbacks\n");
927 
928  /* Swap in any worker thread stacks */
929  DPRINT("Swapping worker threads\n");
931 
932  /* Make our action global */
933  PopAction = Action;
934 
935  /* Start power loop */
937  while (TRUE)
938  {
939  /* Break out if there's nothing to do */
940  if (Action.Action == PowerActionNone) break;
941 
942  /* Check for first-pass or restart */
943  if (Status == STATUS_CANCELLED)
944  {
945  /* Check for shutdown action */
949  {
950  /* Set the action */
952  }
953 
954  /* Now we are good to go */
956  }
957 
958  /* Check if we're still in an invalid status */
959  if (!NT_SUCCESS(Status)) break;
960 
961 #ifndef NEWCC
962  /* Flush dirty cache pages */
963  /* XXX: Is that still mandatory? As now we'll wait on lazy writer to complete? */
964  CcRosFlushDirtyPages(-1, &Dummy, FALSE, FALSE); //HACK: We really should wait here!
965 #else
966  Dummy = 0;
967 #endif
968 
969  /* Flush all volumes and the registry */
970  DPRINT("Flushing volumes, cache flushed %lu pages\n", Dummy);
972 
973  /* Set IRP for drivers */
975  if (PopAction.Shutdown)
976  {
977  DPRINT("Queueing shutdown thread\n");
978  /* Check if we are running in the system context */
980  {
981  /* We're not, so use a worker thread for shutdown */
984  NULL);
985 
987 
988  /* Spend us -- when we wake up, the system is good to go down */
991  goto Exit;
992 
993  }
994  else
995  {
996  /* Do the shutdown inline */
998  }
999  }
1000 
1001  /* You should not have made it this far */
1002  // ASSERTMSG("System is still up and running?!\n", FALSE);
1003  DPRINT1("System is still up and running, you may not have chosen a yet supported power option: %u\n", PopAction.Action);
1004  break;
1005  }
1006 
1007 Exit:
1008  /* We're done, return */
1009  return Status;
1010 }
PCALLBACK_OBJECT PowerStateCallback
Definition: callback.c:29
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
#define TRUE
Definition: types.h:120
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:717
VOID NTAPI ExSwapinWorkerThreads(IN BOOLEAN AllowSwap)
Definition: work.c:631
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
POWER_ACTION Action
Definition: po.h:216
UCHAR IrpMinor
Definition: po.h:220
#define POWER_ACTION_DISABLE_WAKES
Definition: ntpoapi.h:419
#define KeGetPreviousMode()
Definition: ketypes.h:1107
LONG NTSTATUS
Definition: precomp.h:26
#define POWER_ACTION_LOCK_CONSOLE
Definition: ntpoapi.h:418
BOOLEAN NTAPI SeSinglePrivilegeCheck(IN LUID PrivilegeValue, IN KPROCESSOR_MODE PreviousMode)
Definition: priv.c:524
NTSTATUS NTAPI CcRosFlushDirtyPages(ULONG Target, PULONG Count, BOOLEAN Wait, BOOLEAN CalledFromLazy)
Definition: view.c:183
_In_ SYSTEM_POWER_STATE MinSystemState
Definition: ntpoapi.h:303
ULONG NTAPI KeSuspendThread(PKTHREAD Thread)
Definition: thrdobj.c:610
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
PEPROCESS PsInitialSystemProcess
Definition: psmgr.c:50
#define POWER_ACTION_OVERRIDE_APPS
Definition: ntpoapi.h:416
WORK_QUEUE_ITEM PopShutdownWorkItem
Definition: power.c:28
#define PsGetCurrentProcess
Definition: psfuncs.h:17
VOID NTAPI PopReadShutdownPolicy(VOID)
Definition: poshtdwn.c:316
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
POP_POWER_ACTION PopAction
Definition: power.c:27
#define POWER_ACTION_CRITICAL
Definition: ntpoapi.h:420
#define POWER_ACTION_QUERY_ALLOWED
Definition: ntpoapi.h:414
VOID NTAPI ExNotifyCallback(IN PCALLBACK_OBJECT CallbackObject, IN PVOID Argument1, IN PVOID Argument2)
Definition: callback.c:467
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
#define POWER_ACTION_UI_ALLOWED
Definition: ntpoapi.h:415
NTSYSCALLAPI NTSTATUS NTAPI ZwSetSystemPowerState(_In_ POWER_ACTION SystemAction, _In_ SYSTEM_POWER_STATE MinSystemState, _In_ ULONG Flags)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID NTAPI CmSetLazyFlushState(IN BOOLEAN Enable)
Definition: cmlazy.c:442
static void Exit(void)
Definition: sock.c:1331
_In_ PLIST_ENTRY _In_ PSTRING _In_ USHORT _In_opt_ PSTRING _In_opt_ PSTRING _In_ ULONG _In_ ULONG Action
Definition: fsrtlfuncs.h:738
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
VOID NTAPI PopFlushVolumes(IN BOOLEAN ShuttingDown)
Definition: povolume.c:229
#define IRP_MN_SET_POWER
Status
Definition: gdiplustypes.h:24
#define POWER_ACTION_LIGHTEST_FIRST
Definition: ntpoapi.h:417
const LUID SeShutdownPrivilege
Definition: priv.c:40
VOID NTAPI PopGracefulShutdown(IN PVOID Context)
Definition: poshtdwn.c:245
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define KeGetCurrentThread
Definition: hal.h:44
BOOLEAN Shutdown
Definition: po.h:215
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define STATUS_SYSTEM_SHUTDOWN
Definition: ntstatus.h:841

Referenced by NtShutdownSystem(), ShutDown_Hibernate(), and ShutDown_StandBy().

◆ NtSetThreadExecutionState()

NTSTATUS NTAPI NtSetThreadExecutionState ( IN EXECUTION_STATE  esFlags,
OUT EXECUTION_STATE PreviousFlags 
)

Definition at line 812 of file power.c.

814 {
818  PAGED_CODE();
819 
820  /* Validate flags */
821  if (esFlags & ~(ES_CONTINUOUS | ES_USER_PRESENT))
822  {
823  /* Fail the request */
825  }
826 
827  /* Check for user parameters */
828  if (PreviousMode != KernelMode)
829  {
830  /* Protect the probes */
831  _SEH2_TRY
832  {
833  /* Check if the pointer is valid */
835  }
837  {
838  /* It isn't -- fail */
840  }
841  _SEH2_END;
842  }
843 
844  /* Save the previous state, always masking in the continous flag */
845  PreviousState = Thread->PowerState | ES_CONTINUOUS;
846 
847  /* Check if we need to update the power state */
848  if (esFlags & ES_CONTINUOUS) Thread->PowerState = (UCHAR)esFlags;
849 
850  /* Protect the write back to user mode */
851  _SEH2_TRY
852  {
853  /* Return the previous flags */
855  }
857  {
858  /* Something's wrong, fail */
860  }
861  _SEH2_END;
862 
863  /* All is good */
864  return STATUS_SUCCESS;
865 }
#define ProbeForWriteUlong(Ptr)
Definition: probe.h:36
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define KeGetPreviousMode()
Definition: ketypes.h:1107
#define PAGED_CODE()
Definition: video.h:57
_SEH2_TRY
Definition: create.c:4250
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
_Out_ EXECUTION_STATE * PreviousFlags
Definition: ntpoapi.h:288
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
unsigned char UCHAR
Definition: xmlstorage.h:181
ULONG EXECUTION_STATE
Definition: potypes.h:169
_In_ PLARGE_INTEGER _In_opt_ PTIMER_APC_ROUTINE _In_opt_ PVOID _In_ BOOLEAN _In_opt_ LONG _Out_opt_ PBOOLEAN PreviousState
Definition: zwfuncs.h:428
_SEH2_END
Definition: create.c:4424
LONG NTAPI ExSystemExceptionFilter(VOID)
Definition: harderr.c:351
#define ES_CONTINUOUS
Definition: potypes.h:167
#define ES_USER_PRESENT
Definition: potypes.h:166
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
#define KeGetCurrentThread
Definition: hal.h:44
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by SetThreadExecutionState().

◆ PoCallDriver()

NTSTATUS NTAPI PoCallDriver ( IN PDEVICE_OBJECT  DeviceObject,
IN OUT PIRP  Irp 
)

◆ PoCancelDeviceNotify()

NTSTATUS NTAPI PoCancelDeviceNotify ( IN PVOID  NotifyBlock)

Definition at line 418 of file power.c.

419 {
421  return STATUS_NOT_IMPLEMENTED;
422 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define UNIMPLEMENTED
Definition: debug.h:114

◆ PoInitializePrcb()

INIT_FUNCTION VOID NTAPI PoInitializePrcb ( IN PKPRCB  Prcb)

Definition at line 396 of file power.c.

397 {
398  /* Initialize the Power State */
399  RtlZeroMemory(&Prcb->PowerState, sizeof(Prcb->PowerState));
400  Prcb->PowerState.Idle0KernelTimeLimit = 0xFFFFFFFF;
401  Prcb->PowerState.CurrentThrottle = 100;
402  Prcb->PowerState.CurrentThrottleIndex = 0;
403  Prcb->PowerState.IdleFunction = PopIdle0;
404 
405  /* Initialize the Perf DPC and Timer */
406  KeInitializeDpc(&Prcb->PowerState.PerfDpc, PopPerfIdleDpc, Prcb);
407  KeSetTargetProcessorDpc(&Prcb->PowerState.PerfDpc, Prcb->Number);
408  KeInitializeTimerEx(&Prcb->PowerState.PerfTimer, SynchronizationTimer);
409 }
VOID NTAPI PopPerfIdleDpc(IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: power.c:376
VOID FASTCALL PopIdle0(IN PPROCESSOR_POWER_STATE PowerState)
Definition: power.c:387
VOID NTAPI KeSetTargetProcessorDpc(IN PKDPC Dpc, IN CCHAR Number)
Definition: dpc.c:970
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:711
VOID NTAPI KeInitializeTimerEx(OUT PKTIMER Timer, IN TIMER_TYPE Type)
Definition: timerobj.c:244

Referenced by KiInitializeKernel(), and KiSystemStartupBootStack().

◆ PoInitSystem()

INIT_FUNCTION BOOLEAN NTAPI PoInitSystem ( IN ULONG  BootPhase)

Definition at line 296 of file power.c.

297 {
299  PCHAR CommandLine;
300  BOOLEAN ForceAcpiDisable = FALSE;
301 
302  /* Check if this is phase 1 init */
303  if (BootPhase == 1)
304  {
305  /* Register power button notification */
308  (PVOID)&GUID_DEVICE_SYS_BUTTON,
310  PhysicalDeviceObject->DriverObject,
312  NULL,
314 
315  /* Register lid notification */
318  (PVOID)&GUID_DEVICE_LID,
320  PhysicalDeviceObject->DriverObject,
322  NULL,
324  return TRUE;
325  }
326 
327  /* Initialize the power capabilities */
329 
330  /* Get the Command Line */
331  CommandLine = KeLoaderBlock->LoadOptions;
332 
333  /* Upcase it */
334  _strupr(CommandLine);
335 
336  /* Check for ACPI disable */
337  if (strstr(CommandLine, "NOACPI")) ForceAcpiDisable = TRUE;
338 
339  if (ForceAcpiDisable)
340  {
341  /* Set the ACPI State to False if it's been forced that way */
343  }
344  else
345  {
346  /* Otherwise check if the LoaderBlock has a ACPI Table */
348  }
349 
350  /* Enable shutdown by power button */
351  if (PopAcpiPresent)
353 
354  /* Initialize volume support */
357 
358  /* Initialize support for dope */
360 
361  /* Initialize support for shutdown waits and work-items */
363 
364  return TRUE;
365 }
signed char * PCHAR
Definition: retypes.h:7
#define TRUE
Definition: types.h:120
PDEVICE_NODE IopRootDeviceNode
Definition: pnpmgr.c:18
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
PLOADER_PARAMETER_EXTENSION Extension
Definition: arc.h:512
#define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES
Definition: iotypes.h:1196
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1122
BOOLEAN PopAcpiPresent
Definition: power.c:26
_In_ ULONG _In_opt_ PVOID _In_ PDRIVER_OBJECT _In_ PDRIVER_NOTIFICATION_CALLBACK_ROUTINE _Inout_opt_ __drv_aliasesMem PVOID _Outptr_result_nullonfailure_ _At_ * NotificationEntry(return==0, __drv_allocatesMem(Mem))) PVOID *NotificationEntry
LIST_ENTRY PopVolumeDevices
Definition: povolume.c:27
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
unsigned char BOOLEAN
VOID NTAPI PopInitShutdownList(VOID)
Definition: poshtdwn.c:32
smooth NULL
Definition: ftsmooth.c:416
KGUARDED_MUTEX PopVolumeLock
Definition: povolume.c:26
PLOADER_PARAMETER_BLOCK KeLoaderBlock
Definition: krnlinit.c:29
NTSTATUS NTAPI IoRegisterPlugPlayNotification(IN IO_NOTIFICATION_EVENT_CATEGORY EventCategory, IN ULONG EventCategoryFlags, IN PVOID EventCategoryData OPTIONAL, IN PDRIVER_OBJECT DriverObject, IN PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine, IN PVOID Context, OUT PVOID *NotificationEntry)
Definition: pnpnotify.c:249
VOID FASTCALL KeInitializeGuardedMutex(OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:31
_CRTIMP char *__cdecl _strupr(_Inout_z_ char *_String)
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
SYSTEM_POWER_CAPABILITIES PopCapabilities
Definition: power.c:29
NTSTATUS NTAPI PopAddRemoveSysCapsCallback(IN PVOID NotificationStructure, IN PVOID Context)
Definition: events.c:147
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
KSPIN_LOCK PopDopeGlobalLock
Definition: povolume.c:28

Referenced by Phase1InitializationDiscard().

◆ PopCleanupPowerState()

VOID NTAPI PopCleanupPowerState ( IN PPOWER_STATE  PowerState)

Definition at line 63 of file power.c.

64 {
65  //UNIMPLEMENTED;
66 }

Referenced by PspExitProcess(), and PspExitThread().

◆ PopIdle0()

VOID FASTCALL PopIdle0 ( IN PPROCESSOR_POWER_STATE  PowerState)

Definition at line 387 of file power.c.

388 {
389  /* FIXME: Extremly naive implementation */
391 }
VOID NTAPI HalProcessorIdle(VOID)
Definition: processor.c:83

Referenced by PoInitializePrcb().

◆ PopPerfIdle()

VOID NTAPI PopPerfIdle ( PPROCESSOR_POWER_STATE  PowerState)

Definition at line 369 of file power.c.

370 {
371  DPRINT1("PerfIdle function: %p\n", PowerState);
372 }
_In_ UCHAR _In_ POWER_STATE PowerState
Definition: pofuncs.h:42
#define DPRINT1
Definition: precomp.h:8

Referenced by PopPerfIdleDpc().

◆ PopPerfIdleDpc()

VOID NTAPI PopPerfIdleDpc ( IN PKDPC  Dpc,
IN PVOID  DeferredContext,
IN PVOID  SystemArgument1,
IN PVOID  SystemArgument2 
)

Definition at line 376 of file power.c.

380 {
381  /* Call the Perf Idle function */
383 }
_In_ UCHAR _In_ POWER_STATE PowerState
Definition: pofuncs.h:42
VOID NTAPI PopPerfIdle(PPROCESSOR_POWER_STATE PowerState)
Definition: power.c:369
_In_opt_ PVOID DeferredContext
Definition: ketypes.h:675

Referenced by PoInitializePrcb().

◆ PopQuerySystemPowerStateTraverse()

NTSTATUS PopQuerySystemPowerStateTraverse ( PDEVICE_NODE  DeviceNode,
PVOID  Context 
)

Definition at line 153 of file power.c.

155 {
156  PPOWER_STATE_TRAVERSE_CONTEXT PowerStateContext = Context;
157  PDEVICE_OBJECT TopDeviceObject;
159 
160  DPRINT("PopQuerySystemPowerStateTraverse(%p, %p)\n", DeviceNode, Context);
161 
163  return STATUS_SUCCESS;
164 
165  if (DeviceNode->Flags & DNF_LEGACY_DRIVER)
166  return STATUS_SUCCESS;
167 
168  TopDeviceObject = IoGetAttachedDeviceReference(DeviceNode->PhysicalDeviceObject);
169 
170  Status = PopSendQuerySystemPowerState(TopDeviceObject,
171  PowerStateContext->SystemPowerState,
172  PowerStateContext->PowerAction);
173  if (!NT_SUCCESS(Status))
174  {
175  DPRINT1("Device '%wZ' failed IRP_MN_QUERY_POWER\n", &DeviceNode->InstancePath);
176  }
177  ObDereferenceObject(TopDeviceObject);
178 
179 #if 0
180  return Status;
181 #else
182  return STATUS_SUCCESS;
183 #endif
184 }
PDEVICE_NODE IopRootDeviceNode
Definition: pnpmgr.c:18
LONG NTSTATUS
Definition: precomp.h:26
POWER_ACTION PowerAction
Definition: power.c:21
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
NTSTATUS PopSendQuerySystemPowerState(PDEVICE_OBJECT DeviceObject, SYSTEM_POWER_STATE SystemState, POWER_ACTION PowerAction)
Definition: power.c:69
void DPRINT(...)
Definition: polytest.cpp:61
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1406
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Definition: Node.h:9
#define DNF_LEGACY_DRIVER
Definition: iotypes.h:181
Status
Definition: gdiplustypes.h:24
#define DPRINT1
Definition: precomp.h:8
struct tagContext Context
Definition: acpixf.h:1030
SYSTEM_POWER_STATE SystemPowerState
Definition: power.c:20
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by PopSetSystemPowerState().

◆ PopRequestPowerIrpCompletion()

static NTSTATUS NTAPI PopRequestPowerIrpCompletion ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN PVOID  Context 
)
static

Definition at line 36 of file power.c.

39 {
40  PIO_STACK_LOCATION Stack;
43 
46 
47  PowerState.DeviceState = (ULONG_PTR)Stack->Parameters.Others.Argument3;
48  CompletionRoutine(Stack->Parameters.Others.Argument1,
49  (UCHAR)(ULONG_PTR)Stack->Parameters.Others.Argument2,
50  PowerState,
51  Stack->Parameters.Others.Argument4,
52  &Irp->IoStatus);
53 
55  IoFreeIrp(Irp);
57 
59 }
_In_ UCHAR _In_ POWER_STATE PowerState
Definition: pofuncs.h:42
REQUEST_POWER_COMPLETE * PREQUEST_POWER_COMPLETE
Definition: potypes.h:404
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
_In_ PIRP Irp
Definition: csq.h:116
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
DEVICE_POWER_STATE DeviceState
Definition: ntpoapi.h:58
unsigned char UCHAR
Definition: xmlstorage.h:181
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
struct tagContext Context
Definition: acpixf.h:1030
_In_ PIRP _In_opt_ PVOID _In_opt_ POPLOCK_WAIT_COMPLETE_ROUTINE CompletionRoutine
Definition: fsrtlfuncs.h:673
#define ULONG_PTR
Definition: config.h:101
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772

Referenced by PoRequestPowerIrp().

◆ PopSendQuerySystemPowerState()

NTSTATUS PopSendQuerySystemPowerState ( PDEVICE_OBJECT  DeviceObject,
SYSTEM_POWER_STATE  SystemState,
POWER_ACTION  PowerAction 
)

Definition at line 69 of file power.c.

70 {
71  KEVENT Event;
74  PIRP Irp;
76 
79  FALSE);
80 
83  NULL,
84  0,
85  NULL,
86  &Event,
87  &IoStatusBlock);
89 
92  IrpSp->Parameters.Power.Type = SystemPowerState;
93  IrpSp->Parameters.Power.State.SystemState = SystemState;
94  IrpSp->Parameters.Power.ShutdownType = PowerAction;
95 
97  if (Status == STATUS_PENDING)
98  {
100  Executive,
101  KernelMode,
102  FALSE,
103  NULL);
105  }
106 
107  return Status;
108 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define IRP_MN_QUERY_POWER
NTSTATUS NTAPI PoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: power.c:485
PIRP NTAPI IoBuildSynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:1069
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IRP_MJ_POWER
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772

Referenced by PopQuerySystemPowerStateTraverse().

◆ PopSendSetSystemPowerState()

NTSTATUS PopSendSetSystemPowerState ( PDEVICE_OBJECT  DeviceObject,
SYSTEM_POWER_STATE  SystemState,
POWER_ACTION  PowerAction 
)

Definition at line 111 of file power.c.

112 {
113  KEVENT Event;
116  PIRP Irp;
118 
121  FALSE);
122 
124  DeviceObject,
125  NULL,
126  0,
127  NULL,
128  &Event,
129  &IoStatusBlock);
130  if (!Irp) return STATUS_INSUFFICIENT_RESOURCES;
131 
134  IrpSp->Parameters.Power.Type = SystemPowerState;
135  IrpSp->Parameters.Power.State.SystemState = SystemState;
136  IrpSp->Parameters.Power.ShutdownType = PowerAction;
137 
139  if (Status == STATUS_PENDING)
140  {
142  Executive,
143  KernelMode,
144  FALSE,
145  NULL);
147  }
148 
149  return Status;
150 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
NTSTATUS NTAPI PoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: power.c:485
PIRP NTAPI IoBuildSynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:1069
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IRP_MJ_POWER
#define IRP_MN_SET_POWER
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772

Referenced by PopSetSystemPowerState(), and PopSetSystemPowerStateTraverse().

◆ PopSetSystemPowerState()

NTSTATUS NTAPI PopSetSystemPowerState ( SYSTEM_POWER_STATE  PowerState,
POWER_ACTION  PowerAction 
)

Definition at line 231 of file power.c.

232 {
234  PDEVICE_OBJECT Fdo;
237  POWER_STATE_TRAVERSE_CONTEXT PowerContext;
238 
240  if (!NT_SUCCESS(Status))
241  {
242  DPRINT1("No system power driver available\n");
243  Fdo = NULL;
244  }
245  else
246  {
248  if (Fdo == DeviceObject)
249  {
250  DPRINT("An FDO was not attached\n");
251  return STATUS_UNSUCCESSFUL;
252  }
253  }
254 
255  /* Set up context */
256  PowerContext.PowerAction = PowerAction;
257  PowerContext.SystemPowerState = PowerState;
258  PowerContext.PowerDevice = Fdo;
259 
260  /* Query for system power change */
264  &PowerContext);
265 
267  if (!NT_SUCCESS(Status))
268  {
269  DPRINT1("Query system power state failed; changing state anyway\n");
270  }
271 
272  /* Set system power change */
276  &PowerContext);
277 
279 
281 
282  if (Fdo != NULL)
283  {
284  if (PowerAction != PowerActionShutdownReset)
285  PopSendSetSystemPowerState(Fdo, PowerState, PowerAction);
286 
287  ObDereferenceObject(Fdo);
288  }
289 
290  return Status;
291 }
NTSTATUS PopQuerySystemPowerStateTraverse(PDEVICE_NODE DeviceNode, PVOID Context)
Definition: power.c:153
_In_ UCHAR _In_ POWER_STATE PowerState
Definition: pofuncs.h:42
PDEVICE_NODE IopRootDeviceNode
Definition: pnpmgr.c:18
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
NTSTATUS IopTraverseDeviceTree(PDEVICETREE_TRAVERSE_CONTEXT Context)
Definition: pnpmgr.c:1570
LONG NTSTATUS
Definition: precomp.h:26
POWER_ACTION PowerAction
Definition: power.c:21
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
BOOLEAN PopAcpiPresent
Definition: power.c:26
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1406
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS IopGetSystemPowerDeviceObject(IN PDEVICE_OBJECT *DeviceObject)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
NTSTATUS PopSendSetSystemPowerState(PDEVICE_OBJECT DeviceObject, SYSTEM_POWER_STATE SystemState, POWER_ACTION PowerAction)
Definition: power.c:111
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define DPRINT1
Definition: precomp.h:8
#define IopInitDeviceTreeTraverseContext( _DeviceTreeTraverseContext, _DeviceNode, _Action, _Context)
Definition: io.h:225
struct tagContext Context
Definition: acpixf.h:1030
PDEVICE_OBJECT PowerDevice
Definition: power.c:22
SYSTEM_POWER_STATE SystemPowerState
Definition: power.c:20
NTSTATUS PopSetSystemPowerStateTraverse(PDEVICE_NODE DeviceNode, PVOID Context)
Definition: power.c:187

Referenced by PopShutdownSystem().

◆ PopSetSystemPowerStateTraverse()

NTSTATUS PopSetSystemPowerStateTraverse ( PDEVICE_NODE  DeviceNode,
PVOID  Context 
)

Definition at line 187 of file power.c.

189 {
190  PPOWER_STATE_TRAVERSE_CONTEXT PowerStateContext = Context;
191  PDEVICE_OBJECT TopDeviceObject;
193 
194  DPRINT("PopSetSystemPowerStateTraverse(%p, %p)\n", DeviceNode, Context);
195 
197  return STATUS_SUCCESS;
198 
199  if (DeviceNode->PhysicalDeviceObject == PowerStateContext->PowerDevice)
200  return STATUS_SUCCESS;
201 
202  if (DeviceNode->Flags & DNF_LEGACY_DRIVER)
203  return STATUS_SUCCESS;
204 
205  TopDeviceObject = IoGetAttachedDeviceReference(DeviceNode->PhysicalDeviceObject);
206  if (TopDeviceObject == PowerStateContext->PowerDevice)
207  {
208  ObDereferenceObject(TopDeviceObject);
209  return STATUS_SUCCESS;
210  }
211 
212  Status = PopSendSetSystemPowerState(TopDeviceObject,
213  PowerStateContext->SystemPowerState,
214  PowerStateContext->PowerAction);
215  if (!NT_SUCCESS(Status))
216  {
217  DPRINT1("Device '%wZ' failed IRP_MN_SET_POWER\n", &DeviceNode->InstancePath);
218  }
219 
220  ObDereferenceObject(TopDeviceObject);
221 
222 #if 0
223  return Status;
224 #else
225  return STATUS_SUCCESS;
226 #endif
227 }
PDEVICE_NODE IopRootDeviceNode
Definition: pnpmgr.c:18
LONG NTSTATUS
Definition: precomp.h:26
POWER_ACTION PowerAction
Definition: power.c:21
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
void DPRINT(...)
Definition: polytest.cpp:61
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1406
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Definition: Node.h:9
NTSTATUS PopSendSetSystemPowerState(PDEVICE_OBJECT DeviceObject, SYSTEM_POWER_STATE SystemState, POWER_ACTION PowerAction)
Definition: power.c:111
#define DNF_LEGACY_DRIVER
Definition: iotypes.h:181
Status
Definition: gdiplustypes.h:24
#define DPRINT1
Definition: precomp.h:8
struct tagContext Context
Definition: acpixf.h:1030
PDEVICE_OBJECT PowerDevice
Definition: power.c:22
SYSTEM_POWER_STATE SystemPowerState
Definition: power.c:20
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by PopSetSystemPowerState().

◆ PoRegisterDeviceForIdleDetection()

PULONG NTAPI PoRegisterDeviceForIdleDetection ( IN PDEVICE_OBJECT  DeviceObject,
IN ULONG  ConservationIdleTime,
IN ULONG  PerformanceIdleTime,
IN DEVICE_POWER_STATE  State 
)

Definition at line 502 of file power.c.

506 {
508  return NULL;
509 }
smooth NULL
Definition: ftsmooth.c:416
#define UNIMPLEMENTED
Definition: debug.h:114

◆ PoRegisterDeviceNotify()

NTSTATUS NTAPI PoRegisterDeviceNotify ( OUT PVOID  Unknown0,
IN ULONG  Unknown1,
IN ULONG  Unknown2,
IN ULONG  Unknown3,
IN PVOID  Unknown4,
IN PVOID  Unknown5 
)

Definition at line 429 of file power.c.

435 {
437  return STATUS_NOT_IMPLEMENTED;
438 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define UNIMPLEMENTED
Definition: debug.h:114

◆ PoRegisterSystemState()

PVOID NTAPI PoRegisterSystemState ( IN PVOID  StateHandle,
IN EXECUTION_STATE  Flags 
)

Definition at line 516 of file power.c.

518 {
520  return NULL;
521 }
smooth NULL
Definition: ftsmooth.c:416
#define UNIMPLEMENTED
Definition: debug.h:114

◆ PoRequestPowerIrp()

NTSTATUS NTAPI PoRequestPowerIrp ( IN PDEVICE_OBJECT  DeviceObject,
IN UCHAR  MinorFunction,
IN POWER_STATE  PowerState,
IN PREQUEST_POWER_COMPLETE  CompletionFunction,
IN PVOID  Context,
OUT PIRP *pIrp  OPTIONAL 
)

Definition at line 528 of file power.c.

534 {
535  PDEVICE_OBJECT TopDeviceObject;
536  PIO_STACK_LOCATION Stack;
537  PIRP Irp;
538 
543 
544  /* Always call the top of the device stack */
545  TopDeviceObject = IoGetAttachedDeviceReference(DeviceObject);
546 
547  Irp = IoAllocateIrp(TopDeviceObject->StackSize + 2, FALSE);
548  if (!Irp)
549  {
550  ObDereferenceObject(TopDeviceObject);
552  }
553 
554  Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
555  Irp->IoStatus.Information = 0;
556 
558 
560  Stack->Parameters.Others.Argument1 = DeviceObject;
561  Stack->Parameters.Others.Argument2 = (PVOID)(ULONG_PTR)MinorFunction;
562  Stack->Parameters.Others.Argument3 = (PVOID)(ULONG_PTR)PowerState.DeviceState;
563  Stack->Parameters.Others.Argument4 = Context;
564  Stack->DeviceObject = TopDeviceObject;
566 
568  Stack->MajorFunction = IRP_MJ_POWER;
569  Stack->MinorFunction = MinorFunction;
571  {
572  Stack->Parameters.WaitWake.PowerState = PowerState.SystemState;
573  }
574  else
575  {
576  Stack->Parameters.Power.Type = DevicePowerState;
577  Stack->Parameters.Power.State = PowerState;
578  }
579 
580  if (pIrp != NULL)
581  *pIrp = Irp;
582 
584  PoCallDriver(TopDeviceObject, Irp);
585 
586  /* Always return STATUS_PENDING. The completion routine
587  * will call CompletionFunction and complete the Irp.
588  */
589  return STATUS_PENDING;
590 }
#define TRUE
Definition: types.h:120
_In_ UCHAR _In_ POWER_STATE PowerState
Definition: pofuncs.h:42
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define IRP_MN_QUERY_POWER
NTSTATUS NTAPI PoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: power.c:485
_In_ PIRP Irp
Definition: csq.h:116
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:515
uint32_t ULONG_PTR
Definition: typedefs.h:63
SYSTEM_POWER_STATE SystemState
Definition: ntpoapi.h:57
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_INVALID_PARAMETER_2
Definition: ntstatus.h:462
void * PVOID
Definition: retypes.h:9
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1406
#define STATUS_PENDING
Definition: ntstatus.h:82
DEVICE_POWER_STATE DeviceState
Definition: ntpoapi.h:58
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2867
#define IRP_MJ_POWER
_In_ UCHAR _In_ POWER_STATE _In_opt_ PREQUEST_POWER_COMPLETE CompletionFunction
Definition: pofuncs.h:42
#define IRP_MN_SET_POWER
_In_ UCHAR MinorFunction
Definition: pofuncs.h:42
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
static NTSTATUS NTAPI PopRequestPowerIrpCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: power.c:36
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
struct tagContext Context
Definition: acpixf.h:1030
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
#define IRP_MN_WAIT_WAKE
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
FORCEINLINE VOID IoSetNextIrpStackLocation(_Inout_ PIRP Irp)
Definition: iofuncs.h:2632

Referenced by CmBattPnpDispatch(), CmBattWaitWakeLoop(), IdleNotificationCallback(), IdleNotificationRequestComplete(), IssueWaitWake(), PcRequestNewPowerState(), PortClsPower(), SendDeviceIrp(), TestPoRequestPowerIrp(), USBH_FdoIdleNotificationCallback(), USBH_FdoPower(), USBH_FdoSubmitWaitWakeIrp(), USBH_FdoWWIrpIoCompletion(), USBH_HubSetD0(), and WaitWakeCallback().

◆ PoSetHiberRange()

VOID NTAPI PoSetHiberRange ( IN PVOID  HiberContext,
IN ULONG  Flags,
IN OUT PVOID  StartPage,
IN ULONG  Length,
IN ULONG  PageTag 
)

Definition at line 470 of file power.c.

475 {
477  return;
478 }
#define UNIMPLEMENTED
Definition: debug.h:114

◆ PoSetPowerState()

POWER_STATE NTAPI PoSetPowerState ( IN PDEVICE_OBJECT  DeviceObject,
IN POWER_STATE_TYPE  Type,
IN POWER_STATE  State 
)

Definition at line 597 of file power.c.

600 {
601  POWER_STATE ps;
602 
604 
605  ps.SystemState = PowerSystemWorking; // Fully on
606  ps.DeviceState = PowerDeviceD0; // Fully on
607 
608  return ps;
609 }
#define ASSERT_IRQL_LESS_OR_EQUAL(x)
Definition: debug.h:251
SYSTEM_POWER_STATE SystemState
Definition: ntpoapi.h:57
DEVICE_POWER_STATE DeviceState
Definition: ntpoapi.h:58
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696

Referenced by Bus_PDO_PnP(), Bus_PDO_Power(), Bus_StartFdo(), ClasspPowerDownCompletion(), ClasspPowerHandler(), ClasspPowerUpCompletion(), FinishDevPoDnIrp(), FreeBT_AddDevice(), KbdHid_AddDevice(), MouHid_AddDevice(), PciPdoIrpStartDevice(), PcmciaPower(), PortClsPnp(), PortClsPower(), and SetDeviceFunctional().

◆ PoSetSystemState()

VOID NTAPI PoSetSystemState ( IN EXECUTION_STATE  Flags)

Definition at line 616 of file power.c.

617 {
619 }
#define UNIMPLEMENTED
Definition: debug.h:114

◆ PoShutdownBugCheck()

VOID NTAPI PoShutdownBugCheck ( IN BOOLEAN  LogError,
IN ULONG  BugCheckCode,
IN ULONG_PTR  BugCheckParameter1,
IN ULONG_PTR  BugCheckParameter2,
IN ULONG_PTR  BugCheckParameter3,
IN ULONG_PTR  BugCheckParameter4 
)

Definition at line 445 of file power.c.

451 {
452  DPRINT1("PoShutdownBugCheck called\n");
453 
454  /* FIXME: Log error if requested */
455  /* FIXME: Initiate a shutdown */
456 
457  /* Bugcheck the system */
458  KeBugCheckEx(BugCheckCode,
459  BugCheckParameter1,
460  BugCheckParameter2,
461  BugCheckParameter3,
462  BugCheckParameter4);
463 }
#define DPRINT1
Definition: precomp.h:8
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:107

◆ PoStartNextPowerIrp()

VOID NTAPI PoStartNextPowerIrp ( IN PIRP  Irp)

Definition at line 626 of file power.c.

627 {
629 }
#define UNIMPLEMENTED_ONCE
Definition: debug.h:138

Referenced by _Dispatch_type_(), Bus_FDO_Power(), Bus_PDO_Power(), CancelWaitWake(), ClassDispatchPower(), ClassMinimalPowerHandler(), ClasspPowerDownCompletion(), ClasspPowerUpCompletion(), ClasspStartNextPowerIrpCompletion(), CmBattPowerDispatch(), CompBattPowerDispatch(), DevPoCompletionRoutine(), FdcPower(), FDO_Dispatch(), FdoPower(), FdoPowerControl(), FinishDevPoDnIrp(), FinishDevPoUpIrp(), FreeBT_DispatchPower(), GreenPower(), HalpDispatchPower(), HandleDeviceQueryPower(), HandleDeviceSetPower(), CHCDController::HandlePower(), CHubController::HandlePower(), HandleSystemQueryPower(), HDA_Power(), HidClass_Power(), HidPower(), i8042Power(), IntVideoPortDispatchPower(), IrpStub(), KbdHid_Power(), KsDefaultDispatchPower(), MouHid_Power(), NdisIPower(), PciDispatchIrp(), PciPassIrpFromFdoToPdo(), PDO_Dispatch(), PdoPower(), PdoPowerControl(), PnpRootPowerControl(), PortClsPower(), ProcessorPower(), PwrCompletionFunction(), RamdiskPower(), RequestedPowerIrpHandler(), SendDeviceIrp(), SerialPower(), SetDeviceFunctional(), SwDispatchPower(), SysPoCompletionRoutine(), USBH_CompletePowerIrp(), USBH_FdoDeferPoRequestCompletion(), USBH_FdoPower(), USBH_FdoWWIrpIoCompletion(), USBH_HubCancelWakeIrp(), USBH_PdoPower(), USBH_PowerIrpCompletion(), USBHUB_DispatchPower(), USBPORT_FdoPower(), USBPORT_PdoPower(), USBSTOR_DispatchPower(), and WaitWakeCompletionRoutine().

◆ PoUnregisterSystemState()

VOID NTAPI PoUnregisterSystemState ( IN PVOID  StateHandle)

Definition at line 636 of file power.c.

637 {
639 }
#define UNIMPLEMENTED
Definition: debug.h:114

Variable Documentation

◆ PopAcpiPresent

BOOLEAN PopAcpiPresent = FALSE

Definition at line 26 of file power.c.

Referenced by PoInitSystem(), and PopSetSystemPowerState().

◆ PopAction

POP_POWER_ACTION PopAction

Definition at line 27 of file power.c.

Referenced by NtSetSystemPowerState(), and PopGracefulShutdown().

◆ PopCapabilities

SYSTEM_POWER_CAPABILITIES PopCapabilities

Definition at line 29 of file power.c.

Referenced by NtPowerInformation(), PoInitSystem(), and PopAddRemoveSysCapsCallback().

◆ PopShutdownWorkItem

WORK_QUEUE_ITEM PopShutdownWorkItem

Definition at line 28 of file power.c.

Referenced by NtSetSystemPowerState().

◆ PopSystemPowerDeviceNode

PDEVICE_NODE PopSystemPowerDeviceNode = NULL

Definition at line 25 of file power.c.

Referenced by IopGetSystemPowerDeviceObject(), and IopInitializeDevice().