ReactOS  0.4.15-dev-1392-g3014417
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 _Use_decl_annotations_ VOID NTAPI PopPassivePowerCall (PVOID Parameter)
 
 _IRQL_requires_max_ (DISPATCH_LEVEL)
 
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)
 
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)
 
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)
 
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
 
static WORKER_THREAD_ROUTINE PopPassivePowerCall
 

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

◆ _IRQL_requires_max_()

_IRQL_requires_max_ ( DISPATCH_LEVEL  )

Definition at line 52 of file power.c.

59 {
61  BOOLEAN CallAtPassiveLevel;
63  PWORK_QUEUE_ITEM WorkQueueItem;
64 
65  ASSERT(NextStack->MajorFunction == IRP_MJ_POWER);
66 
67  DeviceObject = NextStack->DeviceObject;
68 
69  /* Determine whether the IRP must be handled at PASSIVE_LEVEL.
70  * Only SET_POWER to working state can happen at raised IRQL. */
71  CallAtPassiveLevel = TRUE;
72  if ((NextStack->MinorFunction == IRP_MN_SET_POWER) &&
73  !(DeviceObject->Flags & DO_POWER_PAGABLE))
74  {
75  if (NextStack->Parameters.Power.Type == DevicePowerState &&
76  NextStack->Parameters.Power.State.DeviceState == PowerDeviceD0)
77  {
78  CallAtPassiveLevel = FALSE;
79  }
80  if (NextStack->Parameters.Power.Type == SystemPowerState &&
81  NextStack->Parameters.Power.State.SystemState == PowerSystemWorking)
82  {
83  CallAtPassiveLevel = FALSE;
84  }
85  }
86 
87  if (CallAtPassiveLevel)
88  {
89  /* We need to fit a work item into the DriverContext below */
90  C_ASSERT(sizeof(Irp->Tail.Overlay.DriverContext) >= sizeof(WORK_QUEUE_ITEM));
91 
93  {
94  /* Already at passive, call next driver directly */
95  return IoCallDriver(DeviceObject, Irp);
96  }
97 
98  /* Need to schedule a work item and return pending */
99  NextStack->Control |= SL_PENDING_RETURNED;
100 
101  WorkQueueItem = (PWORK_QUEUE_ITEM)&Irp->Tail.Overlay.DriverContext;
102  ExInitializeWorkItem(WorkQueueItem,
104  Irp);
105  ExQueueWorkItem(WorkQueueItem, DelayedWorkQueue);
106 
107  return STATUS_PENDING;
108  }
109 
110  /* Direct call. Raise IRQL in debug to catch invalid paged memory access. */
111 #if DBG
112  {
113  KIRQL OldIrql;
115 #endif
116 
118 
119 #if DBG
121  }
122 #endif
123 
124  return Status;
125 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define DO_POWER_PAGABLE
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:711
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
#define SL_PENDING_RETURNED
Definition: iotypes.h:3304
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
UCHAR KIRQL
Definition: env_spec_w32.h:591
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
unsigned char BOOLEAN
#define C_ASSERT(e)
Definition: intsafe.h:71
Status
Definition: gdiplustypes.h:24
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
#define ASSERT(a)
Definition: mode.c:45
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IRP_MJ_POWER
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
#define IRP_MN_SET_POWER
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
static WORKER_THREAD_ROUTINE PopPassivePowerCall
Definition: power.c:33
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
struct _WORK_QUEUE_ITEM * PWORK_QUEUE_ITEM
_In_ SYSTEM_POWER_STATE SystemPowerState
Definition: iotypes.h:7498

◆ NtGetDevicePowerState()

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

Definition at line 901 of file power.c.

903 {
905  return STATUS_NOT_IMPLEMENTED;
906 }
return STATUS_NOT_IMPLEMENTED
#define UNIMPLEMENTED
Definition: debug.h:115

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 757 of file power.c.

761 {
763  return STATUS_NOT_IMPLEMENTED;
764 }
return STATUS_NOT_IMPLEMENTED
#define UNIMPLEMENTED
Definition: debug.h:115

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

◆ NtIsSystemResumeAutomatic()

BOOLEAN NTAPI NtIsSystemResumeAutomatic ( VOID  )

Definition at line 910 of file power.c.

911 {
913  return FALSE;
914 }
#define FALSE
Definition: types.h:117
#define UNIMPLEMENTED
Definition: debug.h:115

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 771 of file power.c.

776 {
779 
780  PAGED_CODE();
781 
782  DPRINT("NtPowerInformation(PowerInformationLevel 0x%x, InputBuffer 0x%p, "
783  "InputBufferLength 0x%x, OutputBuffer 0x%p, OutputBufferLength 0x%x)\n",
784  PowerInformationLevel,
787 
788  if (PreviousMode != KernelMode)
789  {
790  _SEH2_TRY
791  {
794  }
796  {
798  }
799  _SEH2_END;
800  }
801 
802  switch (PowerInformationLevel)
803  {
804  case SystemBatteryState:
805  {
807 
808  if (InputBuffer != NULL)
812 
813  _SEH2_TRY
814  {
815  /* Just zero the struct (and thus set BatteryState->BatteryPresent = FALSE) */
816  RtlZeroMemory(BatteryState, sizeof(SYSTEM_BATTERY_STATE));
817  BatteryState->EstimatedTime = MAXULONG;
818 // BatteryState->AcOnLine = TRUE;
819 
821  }
823  {
825  }
826  _SEH2_END;
827 
828  break;
829  }
830 
832  {
834 
835  if (InputBuffer != NULL)
839 
840  _SEH2_TRY
841  {
844  sizeof(SYSTEM_POWER_CAPABILITIES));
845 
847  }
849  {
851  }
852  _SEH2_END;
853 
854  break;
855  }
856 
858  {
860 
861  if (InputBuffer != NULL)
865 
866  /* FIXME: return structures for all processors */
867 
868  _SEH2_TRY
869  {
870  /* FIXME: some values are hardcoded */
871  PowerInformation->Number = 0;
872  PowerInformation->MaxMhz = 1000;
873  PowerInformation->CurrentMhz = KeGetCurrentPrcb()->MHz;
874  PowerInformation->MhzLimit = 1000;
875  PowerInformation->MaxIdleState = 0;
876  PowerInformation->CurrentIdleState = 0;
877 
879  }
881  {
883  }
884  _SEH2_END;
885 
886  break;
887  }
888 
889  default:
891  DPRINT1("PowerInformationLevel 0x%x is UNIMPLEMENTED! Have a nice day.\n",
892  PowerInformationLevel);
893  break;
894  }
895 
896  return Status;
897 }
_In_ WDFDEVICE _In_ PWDF_DEVICE_POWER_CAPABILITIES PowerCapabilities
Definition: wdfdevice.h:3883
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define KeGetPreviousMode()
Definition: ketypes.h:1107
LONG NTSTATUS
Definition: precomp.h:26
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1075
_In_ WDFREQUEST _In_ size_t _In_ size_t InputBufferLength
Definition: wdfio.h:318
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
_SEH2_TRY
Definition: create.c:4226
_In_ WDFREQUEST _In_ size_t OutputBufferLength
Definition: wdfio.h:318
return STATUS_NOT_IMPLEMENTED
struct SYSTEM_POWER_CAPABILITIES * PSYSTEM_POWER_CAPABILITIES
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
void DPRINT(...)
Definition: polytest.cpp:61
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR OutputBuffer
Definition: wdfiotarget.h:859
Status
Definition: gdiplustypes.h:24
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR InputBuffer
Definition: wdfiotarget.h:949
_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
#define MAXULONG
Definition: typedefs.h:251
struct SYSTEM_BATTERY_STATE * PSYSTEM_BATTERY_STATE
_SEH2_END
Definition: create.c:4400
SYSTEM_POWER_CAPABILITIES PopCapabilities
Definition: power.c:29
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
struct _PROCESSOR_POWER_INFORMATION * PPROCESSOR_POWER_INFORMATION
#define PAGED_CODE()

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 918 of file power.c.

919 {
921  return STATUS_NOT_IMPLEMENTED;
922 }
return STATUS_NOT_IMPLEMENTED
#define UNIMPLEMENTED
Definition: debug.h:115

Referenced by RequestWakeupLatency().

◆ NtSetSystemPowerState()

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

Definition at line 983 of file power.c.

986 {
988  POP_POWER_ACTION Action = {0};
990  ULONG Dummy;
991 
992  /* Check for invalid parameter combinations */
995  (SystemAction > PowerActionWarmEject) ||
996  (SystemAction < PowerActionReserved) ||
1004  {
1005  DPRINT1("NtSetSystemPowerState: Bad parameters!\n");
1006  DPRINT1(" SystemAction: 0x%x\n", SystemAction);
1007  DPRINT1(" MinSystemState: 0x%x\n", MinSystemState);
1008  DPRINT1(" Flags: 0x%x\n", Flags);
1009  return STATUS_INVALID_PARAMETER;
1010  }
1011 
1012  /* Check for user caller */
1013  if (PreviousMode != KernelMode)
1014  {
1015  /* Check for shutdown permission */
1017  {
1018  /* Not granted */
1019  DPRINT1("ERROR: Privilege not held for shutdown\n");
1021  }
1022 
1023  /* Do it as a kernel-mode caller for consistency with system state */
1024  return ZwSetSystemPowerState(SystemAction, MinSystemState, Flags);
1025  }
1026 
1027  /* Read policy settings (partial shutdown vs. full shutdown) */
1028  if (SystemAction == PowerActionShutdown) PopReadShutdownPolicy();
1029 
1030  /* Disable lazy flushing of registry */
1031  DPRINT("Stopping lazy flush\n");
1033 
1034  /* Setup the power action */
1035  Action.Action = SystemAction;
1036  Action.Flags = Flags;
1037 
1038  /* Notify callbacks */
1039  DPRINT("Notifying callbacks\n");
1041 
1042  /* Swap in any worker thread stacks */
1043  DPRINT("Swapping worker threads\n");
1045 
1046  /* Make our action global */
1047  PopAction = Action;
1048 
1049  /* Start power loop */
1051  while (TRUE)
1052  {
1053  /* Break out if there's nothing to do */
1054  if (Action.Action == PowerActionNone) break;
1055 
1056  /* Check for first-pass or restart */
1057  if (Status == STATUS_CANCELLED)
1058  {
1059  /* Check for shutdown action */
1063  {
1064  /* Set the action */
1066  }
1067 
1068  /* Now we are good to go */
1070  }
1071 
1072  /* Check if we're still in an invalid status */
1073  if (!NT_SUCCESS(Status)) break;
1074 
1075 #ifndef NEWCC
1076  /* Flush dirty cache pages */
1077  /* XXX: Is that still mandatory? As now we'll wait on lazy writer to complete? */
1078  CcRosFlushDirtyPages(-1, &Dummy, FALSE, FALSE); //HACK: We really should wait here!
1079 #else
1080  Dummy = 0;
1081 #endif
1082 
1083  /* Flush all volumes and the registry */
1084  DPRINT("Flushing volumes, cache flushed %lu pages\n", Dummy);
1086 
1087  /* Set IRP for drivers */
1089  if (PopAction.Shutdown)
1090  {
1091  DPRINT("Queueing shutdown thread\n");
1092  /* Check if we are running in the system context */
1094  {
1095  /* We're not, so use a worker thread for shutdown */
1098  NULL);
1099 
1101 
1102  /* Spend us -- when we wake up, the system is good to go down */
1105  goto Exit;
1106 
1107  }
1108  else
1109  {
1110  /* Do the shutdown inline */
1112  }
1113  }
1114 
1115  /* You should not have made it this far */
1116  // ASSERTMSG("System is still up and running?!\n", FALSE);
1117  DPRINT1("System is still up and running, you may not have chosen a yet supported power option: %u\n", PopAction.Action);
1118  break;
1119  }
1120 
1121 Exit:
1122  /* We're done, return */
1123  return Status;
1124 }
PCALLBACK_OBJECT PowerStateCallback
Definition: callback.c:29
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:711
VOID NTAPI ExSwapinWorkerThreads(IN BOOLEAN AllowSwap)
Definition: work.c:625
#define TRUE
Definition: types.h:120
#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:520
NTSTATUS NTAPI CcRosFlushDirtyPages(ULONG Target, PULONG Count, BOOLEAN Wait, BOOLEAN CalledFromLazy)
Definition: view.c:179
_In_ SYSTEM_POWER_STATE MinSystemState
Definition: ntpoapi.h:303
ULONG NTAPI KeSuspendThread(PKTHREAD Thread)
Definition: thrdobj.c:610
#define FALSE
Definition: types.h:117
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:318
void DPRINT(...)
Definition: polytest.cpp:61
POP_POWER_ACTION PopAction
Definition: power.c:27
#define POWER_ACTION_CRITICAL
Definition: ntpoapi.h:420
Status
Definition: gdiplustypes.h:24
#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
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#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
#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
#define POWER_ACTION_LIGHTEST_FIRST
Definition: ntpoapi.h:417
const LUID SeShutdownPrivilege
Definition: priv.c:36
_In_ WDFIOTARGET _In_ _Strict_type_match_ WDF_IO_TARGET_SENT_IO_ACTION Action
Definition: wdfiotarget.h:506
VOID NTAPI PopGracefulShutdown(IN PVOID Context)
Definition: poshtdwn.c:247
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
#define KeGetCurrentThread
Definition: hal.h:44
BOOLEAN Shutdown
Definition: po.h:215
#define STATUS_SYSTEM_SHUTDOWN
Definition: ntstatus.h:855

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

◆ NtSetThreadExecutionState()

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

Definition at line 926 of file power.c.

928 {
932  PAGED_CODE();
933 
934  /* Validate flags */
935  if (esFlags & ~(ES_CONTINUOUS | ES_USER_PRESENT))
936  {
937  /* Fail the request */
939  }
940 
941  /* Check for user parameters */
942  if (PreviousMode != KernelMode)
943  {
944  /* Protect the probes */
945  _SEH2_TRY
946  {
947  /* Check if the pointer is valid */
949  }
951  {
952  /* It isn't -- fail */
954  }
955  _SEH2_END;
956  }
957 
958  /* Save the previous state, always masking in the continous flag */
959  PreviousState = Thread->PowerState | ES_CONTINUOUS;
960 
961  /* Check if we need to update the power state */
962  if (esFlags & ES_CONTINUOUS) Thread->PowerState = (UCHAR)esFlags;
963 
964  /* Protect the write back to user mode */
965  _SEH2_TRY
966  {
967  /* Return the previous flags */
969  }
971  {
972  /* Something's wrong, fail */
974  }
975  _SEH2_END;
976 
977  /* All is good */
978  return STATUS_SUCCESS;
979 }
#define ProbeForWriteUlong(Ptr)
Definition: probe.h:36
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define KeGetPreviousMode()
Definition: ketypes.h:1107
_SEH2_TRY
Definition: create.c:4226
#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:213
_SEH2_END
Definition: create.c:4400
LONG NTAPI ExSystemExceptionFilter(VOID)
Definition: harderr.c:351
#define ES_CONTINUOUS
Definition: potypes.h:211
#define ES_USER_PRESENT
Definition: potypes.h:210
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
#define KeGetCurrentThread
Definition: hal.h:44
_In_ WDF_POWER_DEVICE_STATE PreviousState
Definition: wdfdevice.h:829
#define PAGED_CODE()

Referenced by SetThreadExecutionState().

◆ PoCancelDeviceNotify()

NTSTATUS NTAPI PoCancelDeviceNotify ( IN PVOID  NotifyBlock)

Definition at line 512 of file power.c.

513 {
515  return STATUS_NOT_IMPLEMENTED;
516 }
return STATUS_NOT_IMPLEMENTED
#define UNIMPLEMENTED
Definition: debug.h:115

◆ PoInitializePrcb()

VOID NTAPI PoInitializePrcb ( IN PKPRCB  Prcb)

Definition at line 490 of file power.c.

491 {
492  /* Initialize the Power State */
493  RtlZeroMemory(&Prcb->PowerState, sizeof(Prcb->PowerState));
494  Prcb->PowerState.Idle0KernelTimeLimit = 0xFFFFFFFF;
495  Prcb->PowerState.CurrentThrottle = 100;
496  Prcb->PowerState.CurrentThrottleIndex = 0;
497  Prcb->PowerState.IdleFunction = PopIdle0;
498 
499  /* Initialize the Perf DPC and Timer */
500  KeInitializeDpc(&Prcb->PowerState.PerfDpc, PopPerfIdleDpc, Prcb);
501  KeSetTargetProcessorDpc(&Prcb->PowerState.PerfDpc, Prcb->Number);
502  KeInitializeTimerEx(&Prcb->PowerState.PerfTimer, SynchronizationTimer);
503 }
VOID NTAPI PopPerfIdleDpc(IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: power.c:470
VOID FASTCALL PopIdle0(IN PPROCESSOR_POWER_STATE PowerState)
Definition: power.c:481
VOID NTAPI KeSetTargetProcessorDpc(IN PKDPC Dpc, IN CCHAR Number)
Definition: dpc.c:970
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
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()

BOOLEAN NTAPI PoInitSystem ( IN ULONG  BootPhase)

Definition at line 390 of file power.c.

391 {
393  PCHAR CommandLine;
394  BOOLEAN ForceAcpiDisable = FALSE;
395 
396  /* Check if this is phase 1 init */
397  if (BootPhase == 1)
398  {
399  /* Register power button notification */
402  (PVOID)&GUID_DEVICE_SYS_BUTTON,
404  PhysicalDeviceObject->DriverObject,
406  NULL,
408 
409  /* Register lid notification */
412  (PVOID)&GUID_DEVICE_LID,
414  PhysicalDeviceObject->DriverObject,
416  NULL,
418  return TRUE;
419  }
420 
421  /* Initialize the power capabilities */
423 
424  /* Get the Command Line */
425  CommandLine = KeLoaderBlock->LoadOptions;
426 
427  /* Upcase it */
428  _strupr(CommandLine);
429 
430  /* Check for ACPI disable */
431  if (strstr(CommandLine, "NOACPI")) ForceAcpiDisable = TRUE;
432 
433  if (ForceAcpiDisable)
434  {
435  /* Set the ACPI State to False if it's been forced that way */
437  }
438  else
439  {
440  /* Otherwise check if the LoaderBlock has a ACPI Table */
442  }
443 
444  /* Enable shutdown by power button */
445  if (PopAcpiPresent)
447 
448  /* Initialize volume support */
451 
452  /* Initialize support for dope */
454 
455  /* Initialize support for shutdown waits and work-items */
457 
458  return TRUE;
459 }
signed char * PCHAR
Definition: retypes.h:7
PDEVICE_NODE IopRootDeviceNode
Definition: devnode.c:18
#define TRUE
Definition: types.h:120
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:1219
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1155
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
#define FALSE
Definition: types.h:117
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:238
unsigned char BOOLEAN
VOID NTAPI PopInitShutdownList(VOID)
Definition: poshtdwn.c:35
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
#define NULL
Definition: types.h:112
NTSTATUS NTAPI PopAddRemoveSysCapsCallback(IN PVOID NotificationStructure, IN PVOID Context)
Definition: events.c:147
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
KSPIN_LOCK PopDopeGlobalLock
Definition: povolume.c:28

Referenced by Phase1InitializationDiscard().

◆ PopCleanupPowerState()

VOID NTAPI PopCleanupPowerState ( IN PPOWER_STATE  PowerState)

Definition at line 157 of file power.c.

158 {
159  //UNIMPLEMENTED;
160 }

Referenced by PspExitProcess(), and PspExitThread().

◆ PopIdle0()

VOID FASTCALL PopIdle0 ( IN PPROCESSOR_POWER_STATE  PowerState)

Definition at line 481 of file power.c.

482 {
483  /* FIXME: Extremly naive implementation */
485 }
VOID NTAPI HalProcessorIdle(VOID)
Definition: processor.c:83

Referenced by PoInitializePrcb().

◆ PopPassivePowerCall()

static _Use_decl_annotations_ VOID NTAPI PopPassivePowerCall ( PVOID  Parameter)
static

Definition at line 38 of file power.c.

40 {
41  PIRP Irp = Parameter;
42  PIO_STACK_LOCATION IoStack;
43 
45 
47  IoStack = IoGetNextIrpStackLocation(Irp);
48 
49  (VOID)IoCallDriver(IoStack->DeviceObject, Irp);
50 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
_In_ PVOID Parameter
Definition: ldrtypes.h:241
_In_ PIRP Irp
Definition: csq.h:116
#define ASSERT(a)
Definition: mode.c:45
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:3202
#define VOID
Definition: acefi.h:82
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2691
#define _Analysis_assume_
Definition: no_sal2.h:388
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218

◆ PopPerfIdle()

VOID NTAPI PopPerfIdle ( PPROCESSOR_POWER_STATE  PowerState)

Definition at line 463 of file power.c.

464 {
465  DPRINT1("PerfIdle function: %p\n", PowerState);
466 }
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ WDF_DEVICE_POWER_STATE PowerState
Definition: wdfdevice.h:3032
#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 470 of file power.c.

474 {
475  /* Call the Perf Idle function */
477 }
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ WDF_DEVICE_POWER_STATE PowerState
Definition: wdfdevice.h:3032
VOID NTAPI PopPerfIdle(PPROCESSOR_POWER_STATE PowerState)
Definition: power.c:463
_In_opt_ PVOID DeferredContext
Definition: ketypes.h:675

Referenced by PoInitializePrcb().

◆ PopQuerySystemPowerStateTraverse()

NTSTATUS PopQuerySystemPowerStateTraverse ( PDEVICE_NODE  DeviceNode,
PVOID  Context 
)

Definition at line 247 of file power.c.

249 {
250  PPOWER_STATE_TRAVERSE_CONTEXT PowerStateContext = Context;
251  PDEVICE_OBJECT TopDeviceObject;
253 
254  DPRINT("PopQuerySystemPowerStateTraverse(%p, %p)\n", DeviceNode, Context);
255 
257  return STATUS_SUCCESS;
258 
259  if (DeviceNode->Flags & DNF_LEGACY_DRIVER)
260  return STATUS_SUCCESS;
261 
262  TopDeviceObject = IoGetAttachedDeviceReference(DeviceNode->PhysicalDeviceObject);
263 
264  Status = PopSendQuerySystemPowerState(TopDeviceObject,
265  PowerStateContext->SystemPowerState,
266  PowerStateContext->PowerAction);
267  if (!NT_SUCCESS(Status))
268  {
269  DPRINT1("Device '%wZ' failed IRP_MN_QUERY_POWER\n", &DeviceNode->InstancePath);
270  }
271  ObDereferenceObject(TopDeviceObject);
272 
273 #if 0
274  return Status;
275 #else
276  return STATUS_SUCCESS;
277 #endif
278 }
PDEVICE_NODE IopRootDeviceNode
Definition: devnode.c:18
LONG NTSTATUS
Definition: precomp.h:26
POWER_ACTION PowerAction
Definition: power.c:21
NTSTATUS PopSendQuerySystemPowerState(PDEVICE_OBJECT DeviceObject, SYSTEM_POWER_STATE SystemState, POWER_ACTION PowerAction)
Definition: power.c:163
void DPRINT(...)
Definition: polytest.cpp:61
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1406
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ObDereferenceObject
Definition: obfuncs.h:203
Definition: Node.h:9
#define DNF_LEGACY_DRIVER
Definition: iotypes.h:181
#define DPRINT1
Definition: precomp.h:8
struct tagContext Context
Definition: acpixf.h:1034
#define STATUS_SUCCESS
Definition: shellext.h:65
SYSTEM_POWER_STATE SystemPowerState
Definition: power.c:20

Referenced by PopSetSystemPowerState().

◆ PopRequestPowerIrpCompletion()

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

Definition at line 130 of file power.c.

133 {
137 
140 
141  PowerState.DeviceState = (ULONG_PTR)Stack->Parameters.Others.Argument3;
142  CompletionRoutine(Stack->Parameters.Others.Argument1,
143  (UCHAR)(ULONG_PTR)Stack->Parameters.Others.Argument2,
144  PowerState,
145  Stack->Parameters.Others.Argument4,
146  &Irp->IoStatus);
147 
149  IoFreeIrp(Irp);
151 
153 }
REQUEST_POWER_COMPLETE * PREQUEST_POWER_COMPLETE
Definition: potypes.h:469
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:636
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PIRP Irp
Definition: csq.h:116
#define ObDereferenceObject
Definition: obfuncs.h:203
unsigned char UCHAR
Definition: xmlstorage.h:181
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ WDF_DEVICE_POWER_STATE PowerState
Definition: wdfdevice.h:3032
_In_ WDFREQUEST _In_opt_ PFN_WDF_REQUEST_COMPLETION_ROUTINE CompletionRoutine
Definition: wdfrequest.h:893
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
struct tagContext Context
Definition: acpixf.h:1034
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
#define ULONG_PTR
Definition: config.h:101

Referenced by PoRequestPowerIrp().

◆ PopSendQuerySystemPowerState()

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

Definition at line 163 of file power.c.

164 {
165  KEVENT Event;
168  PIRP Irp;
170 
173  FALSE);
174 
176  DeviceObject,
177  NULL,
178  0,
179  NULL,
180  &Event,
181  &IoStatusBlock);
182  if (!Irp) return STATUS_INSUFFICIENT_RESOURCES;
183 
186  IrpSp->Parameters.Power.Type = SystemPowerState;
187  IrpSp->Parameters.Power.State.SystemState = SystemState;
188  IrpSp->Parameters.Power.ShutdownType = PowerAction;
189 
190  Status = PoCallDriver(DeviceObject, Irp);
191  if (Status == STATUS_PENDING)
192  {
194  Executive,
195  KernelMode,
196  FALSE,
197  NULL);
199  }
200 
201  return Status;
202 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define IRP_MN_QUERY_POWER
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
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_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:450
Status
Definition: gdiplustypes.h:24
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IRP_MJ_POWER
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2691
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define NULL
Definition: types.h:112
_In_ SYSTEM_POWER_STATE SystemPowerState
Definition: iotypes.h:7498
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107

Referenced by PopQuerySystemPowerStateTraverse().

◆ PopSendSetSystemPowerState()

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

Definition at line 205 of file power.c.

206 {
207  KEVENT Event;
210  PIRP Irp;
212 
215  FALSE);
216 
218  DeviceObject,
219  NULL,
220  0,
221  NULL,
222  &Event,
223  &IoStatusBlock);
224  if (!Irp) return STATUS_INSUFFICIENT_RESOURCES;
225 
228  IrpSp->Parameters.Power.Type = SystemPowerState;
229  IrpSp->Parameters.Power.State.SystemState = SystemState;
230  IrpSp->Parameters.Power.ShutdownType = PowerAction;
231 
232  Status = PoCallDriver(DeviceObject, Irp);
233  if (Status == STATUS_PENDING)
234  {
236  Executive,
237  KernelMode,
238  FALSE,
239  NULL);
241  }
242 
243  return Status;
244 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
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
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_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:450
Status
Definition: gdiplustypes.h:24
#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:2691
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define NULL
Definition: types.h:112
_In_ SYSTEM_POWER_STATE SystemPowerState
Definition: iotypes.h:7498
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107

Referenced by PopSetSystemPowerState(), and PopSetSystemPowerStateTraverse().

◆ PopSetSystemPowerState()

NTSTATUS NTAPI PopSetSystemPowerState ( SYSTEM_POWER_STATE  PowerState,
POWER_ACTION  PowerAction 
)

Definition at line 325 of file power.c.

326 {
331  POWER_STATE_TRAVERSE_CONTEXT PowerContext;
332 
334  if (!NT_SUCCESS(Status))
335  {
336  DPRINT1("No system power driver available\n");
337  Fdo = NULL;
338  }
339  else
340  {
342  if (Fdo == DeviceObject)
343  {
344  DPRINT("An FDO was not attached\n");
345  return STATUS_UNSUCCESSFUL;
346  }
347  }
348 
349  /* Set up context */
350  PowerContext.PowerAction = PowerAction;
351  PowerContext.SystemPowerState = PowerState;
352  PowerContext.PowerDevice = Fdo;
353 
354  /* Query for system power change */
358  &PowerContext);
359 
361  if (!NT_SUCCESS(Status))
362  {
363  DPRINT1("Query system power state failed; changing state anyway\n");
364  }
365 
366  /* Set system power change */
370  &PowerContext);
371 
373 
375 
376  if (Fdo != NULL)
377  {
378  if (PowerAction != PowerActionShutdownReset)
380 
382  }
383 
384  return Status;
385 }
NTSTATUS PopQuerySystemPowerStateTraverse(PDEVICE_NODE DeviceNode, PVOID Context)
Definition: power.c:247
PDEVICE_NODE IopRootDeviceNode
Definition: devnode.c:18
NTSTATUS IopTraverseDeviceTree(PDEVICETREE_TRAVERSE_CONTEXT Context)
LONG NTSTATUS
Definition: precomp.h:26
POWER_ACTION PowerAction
Definition: power.c:21
BOOLEAN PopAcpiPresent
Definition: power.c:26
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
return STATUS_NOT_IMPLEMENTED
void DPRINT(...)
Definition: polytest.cpp:61
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1406
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ObDereferenceObject
Definition: obfuncs.h:203
NTSTATUS IopGetSystemPowerDeviceObject(IN PDEVICE_OBJECT *DeviceObject)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_Must_inspect_result_ _In_ WDFDEVICE Fdo
Definition: wdffdo.h:461
NTSTATUS PopSendSetSystemPowerState(PDEVICE_OBJECT DeviceObject, SYSTEM_POWER_STATE SystemState, POWER_ACTION PowerAction)
Definition: power.c:205
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ WDF_DEVICE_POWER_STATE PowerState
Definition: wdfdevice.h:3032
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
struct tagContext Context
Definition: acpixf.h:1034
#define IopInitDeviceTreeTraverseContext( _DeviceTreeTraverseContext, _DeviceNode, _Action, _Context)
Definition: io.h:225
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:281

Referenced by PopShutdownSystem().

◆ PopSetSystemPowerStateTraverse()

NTSTATUS PopSetSystemPowerStateTraverse ( PDEVICE_NODE  DeviceNode,
PVOID  Context 
)

Definition at line 281 of file power.c.

283 {
284  PPOWER_STATE_TRAVERSE_CONTEXT PowerStateContext = Context;
285  PDEVICE_OBJECT TopDeviceObject;
287 
288  DPRINT("PopSetSystemPowerStateTraverse(%p, %p)\n", DeviceNode, Context);
289 
291  return STATUS_SUCCESS;
292 
293  if (DeviceNode->PhysicalDeviceObject == PowerStateContext->PowerDevice)
294  return STATUS_SUCCESS;
295 
296  if (DeviceNode->Flags & DNF_LEGACY_DRIVER)
297  return STATUS_SUCCESS;
298 
299  TopDeviceObject = IoGetAttachedDeviceReference(DeviceNode->PhysicalDeviceObject);
300  if (TopDeviceObject == PowerStateContext->PowerDevice)
301  {
302  ObDereferenceObject(TopDeviceObject);
303  return STATUS_SUCCESS;
304  }
305 
306  Status = PopSendSetSystemPowerState(TopDeviceObject,
307  PowerStateContext->SystemPowerState,
308  PowerStateContext->PowerAction);
309  if (!NT_SUCCESS(Status))
310  {
311  DPRINT1("Device '%wZ' failed IRP_MN_SET_POWER\n", &DeviceNode->InstancePath);
312  }
313 
314  ObDereferenceObject(TopDeviceObject);
315 
316 #if 0
317  return Status;
318 #else
319  return STATUS_SUCCESS;
320 #endif
321 }
PDEVICE_NODE IopRootDeviceNode
Definition: devnode.c:18
LONG NTSTATUS
Definition: precomp.h:26
POWER_ACTION PowerAction
Definition: power.c:21
void DPRINT(...)
Definition: polytest.cpp:61
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1406
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ObDereferenceObject
Definition: obfuncs.h:203
Definition: Node.h:9
NTSTATUS PopSendSetSystemPowerState(PDEVICE_OBJECT DeviceObject, SYSTEM_POWER_STATE SystemState, POWER_ACTION PowerAction)
Definition: power.c:205
#define DNF_LEGACY_DRIVER
Definition: iotypes.h:181
#define DPRINT1
Definition: precomp.h:8
struct tagContext Context
Definition: acpixf.h:1034
#define STATUS_SUCCESS
Definition: shellext.h:65
PDEVICE_OBJECT PowerDevice
Definition: power.c:22
SYSTEM_POWER_STATE SystemPowerState
Definition: power.c:20

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 613 of file power.c.

617 {
619  return NULL;
620 }
#define NULL
Definition: types.h:112
#define UNIMPLEMENTED
Definition: debug.h:115

◆ 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 523 of file power.c.

529 {
531  return STATUS_NOT_IMPLEMENTED;
532 }
return STATUS_NOT_IMPLEMENTED
#define UNIMPLEMENTED
Definition: debug.h:115

◆ PoRegisterSystemState()

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

Definition at line 627 of file power.c.

629 {
631  return NULL;
632 }
#define NULL
Definition: types.h:112
#define UNIMPLEMENTED
Definition: debug.h:115

◆ 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 639 of file power.c.

645 {
646  PDEVICE_OBJECT TopDeviceObject;
648  PIRP Irp;
649 
654 
655  /* Always call the top of the device stack */
656  TopDeviceObject = IoGetAttachedDeviceReference(DeviceObject);
657 
658  Irp = IoAllocateIrp(TopDeviceObject->StackSize + 2, FALSE);
659  if (!Irp)
660  {
661  ObDereferenceObject(TopDeviceObject);
663  }
664 
665  Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
666  Irp->IoStatus.Information = 0;
667 
669 
671  Stack->Parameters.Others.Argument1 = DeviceObject;
672  Stack->Parameters.Others.Argument2 = (PVOID)(ULONG_PTR)MinorFunction;
673  Stack->Parameters.Others.Argument3 = (PVOID)(ULONG_PTR)PowerState.DeviceState;
674  Stack->Parameters.Others.Argument4 = Context;
675  Stack->DeviceObject = TopDeviceObject;
677 
679  Stack->MajorFunction = IRP_MJ_POWER;
680  Stack->MinorFunction = MinorFunction;
682  {
683  Stack->Parameters.WaitWake.PowerState = PowerState.SystemState;
684  }
685  else
686  {
687  Stack->Parameters.Power.Type = DevicePowerState;
688  Stack->Parameters.Power.State = PowerState;
689  }
690 
691  if (pIrp != NULL)
692  *pIrp = Irp;
693 
695  PoCallDriver(TopDeviceObject, Irp);
696 
697  /* Always return STATUS_PENDING. The completion routine
698  * will call CompletionFunction and complete the Irp.
699  */
700  return STATUS_PENDING;
701 }
return STATUS_NOT_SUPPORTED
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define IRP_MN_QUERY_POWER
#define TRUE
Definition: types.h:120
FxIrp * pIrp
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:498
uint32_t ULONG_PTR
Definition: typedefs.h:65
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:636
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
_In_ UCHAR _In_ UCHAR MinorFunction
Definition: wdfdevice.h:1697
#define STATUS_INVALID_PARAMETER_2
Definition: ntstatus.h:476
void * PVOID
Definition: retypes.h:9
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1406
#define STATUS_PENDING
Definition: ntstatus.h:82
#define ObDereferenceObject
Definition: obfuncs.h:203
#define IRP_MJ_POWER
_In_ UCHAR _In_ POWER_STATE _In_opt_ PREQUEST_POWER_COMPLETE CompletionFunction
Definition: pofuncs.h:42
#define IRP_MN_SET_POWER
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2691
static NTSTATUS NTAPI PopRequestPowerIrpCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: power.c:130
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ WDF_DEVICE_POWER_STATE PowerState
Definition: wdfdevice.h:3032
#define NULL
Definition: types.h:112
struct tagContext Context
Definition: acpixf.h:1034
#define IRP_MN_WAIT_WAKE
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
FORCEINLINE VOID IoSetNextIrpStackLocation(_Inout_ PIRP Irp)
Definition: iofuncs.h:2676

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 564 of file power.c.

569 {
571  return;
572 }
#define UNIMPLEMENTED
Definition: debug.h:115

◆ PoSetPowerState()

◆ PoSetSystemState()

VOID NTAPI PoSetSystemState ( IN EXECUTION_STATE  Flags)

Definition at line 727 of file power.c.

728 {
730 }
#define UNIMPLEMENTED
Definition: debug.h:115

◆ 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 539 of file power.c.

545 {
546  DPRINT1("PoShutdownBugCheck called\n");
547 
548  /* FIXME: Log error if requested */
549  /* FIXME: Initiate a shutdown */
550 
551  /* Bugcheck the system */
552  KeBugCheckEx(BugCheckCode,
553  BugCheckParameter1,
554  BugCheckParameter2,
555  BugCheckParameter3,
556  BugCheckParameter4);
557 }
#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:108

◆ PoStartNextPowerIrp()

VOID NTAPI PoStartNextPowerIrp ( IN PIRP  Irp)

Definition at line 737 of file power.c.

738 {
740 }
#define UNIMPLEMENTED_ONCE
Definition: typedefs.h:30

Referenced by _Dispatch_type_(), Bus_FDO_Power(), Bus_PDO_Power(), CancelWaitWake(), ClassDispatchPower(), ClassDispatchUnimplemented(), ClassMinimalPowerHandler(), ClasspDeviceLockFailurePowerIrpCompletion(), ClassPower(), ClasspPowerDownCompletion(), ClasspPowerHandler(), ClasspPowerUpCompletion(), ClasspStartNextPowerIrpCompletion(), CmBattPowerDispatch(), CompBattPowerDispatch(), DevPoCompletionRoutine(), FdcPower(), FDO_Dispatch(), FdoPower(), FdoPowerControl(), FinishDevPoDnIrp(), FinishDevPoUpIrp(), FreeBT_DispatchPower(), GreenPower(), HalpDispatchPower(), HandleDeviceQueryPower(), HandleDeviceSetPower(), HandleSystemQueryPower(), HDA_Power(), HidClass_Power(), HidPower(), i8042Power(), InPortPower(), IntVideoPortDispatchPower(), IsaPower(), KbdHid_Power(), KsDefaultDispatchPower(), MouHid_Power(), NdisIPower(), PartMgrPower(), PciDispatchIrp(), PciPassIrpFromFdoToPdo(), PDO_HandlePower(), 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(), USBPORT_FdoPower(), USBPORT_PdoPower(), USBSTOR_DispatchPower(), and WaitWakeCompletionRoutine().

◆ PoUnregisterSystemState()

VOID NTAPI PoUnregisterSystemState ( IN PVOID  StateHandle)

Definition at line 747 of file power.c.

748 {
750 }
#define UNIMPLEMENTED
Definition: debug.h:115

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().

◆ PopPassivePowerCall

WORKER_THREAD_ROUTINE PopPassivePowerCall
static

Definition at line 33 of file power.c.

Referenced by _IRQL_requires_max_().

◆ 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().