ReactOS 0.4.16-dev-1946-g52006dd
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_reads_opt_(_Inexpressible_("varies")) 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_opt_ PREQUEST_POWER_COMPLETE CompletionFunction, _In_opt_ __drv_aliasesMem PVOID Context, _Outptr_opt_ PIRP *pIrp)
 
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)
 
static NTSTATUS PopQueryBatteryState (_Out_ PSYSTEM_BATTERY_STATE BatteryState)
 
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
 
static IO_COMPLETION_ROUTINE PopRequestPowerIrpCompletion
 

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) &&
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 */
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 {
115#endif
116
118
119#if DBG
121 }
122#endif
123
124 return Status;
125}
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
_In_ PIRP Irp
Definition: csq.h:116
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
Status
Definition: gdiplustypes.h:25
#define C_ASSERT(e)
Definition: intsafe.h:73
#define ASSERT(a)
Definition: mode.c:44
#define IoCallDriver
Definition: irp.c:1225
static WORKER_THREAD_ROUTINE PopPassivePowerCall
Definition: power.c:33
@ PowerSystemWorking
Definition: ntpoapi.h:36
@ DevicePowerState
Definition: ntpoapi.h:63
@ PowerDeviceD0
Definition: ntpoapi.h:49
#define STATUS_PENDING
Definition: telnetd.h:14
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2061
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:723
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
@ DelayedWorkQueue
Definition: extypes.h:190
struct _WORK_QUEUE_ITEM * PWORK_QUEUE_ITEM
#define SL_PENDING_RETURNED
Definition: iotypes.h:3327
#define DO_POWER_PAGABLE
#define IRP_MN_SET_POWER
#define IRP_MJ_POWER
_In_ SYSTEM_POWER_STATE SystemPowerState
Definition: iotypes.h:7522
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

◆ NtGetDevicePowerState()

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

Definition at line 1045 of file power.c.

1047{
1050}
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42

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

782{
785}

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

◆ NtIsSystemResumeAutomatic()

BOOLEAN NTAPI NtIsSystemResumeAutomatic ( VOID  )

Definition at line 1054 of file power.c.

1055{
1057 return FALSE;
1058}

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

906{
909
910 PAGED_CODE();
911
912 DPRINT("NtPowerInformation(PowerInformationLevel 0x%x, InputBuffer 0x%p, "
913 "InputBufferLength 0x%x, OutputBuffer 0x%p, OutputBufferLength 0x%x)\n",
914 PowerInformationLevel,
917
919 {
921 {
924 }
926 {
928 }
929 _SEH2_END;
930 }
931
932 switch (PowerInformationLevel)
933 {
935 {
936 SYSTEM_BATTERY_STATE BatteryState;
937
938 if (InputBuffer != NULL)
942
944 {
945 /* Open the battery driver and query the battery state */
946 Status = PopQueryBatteryState(&BatteryState);
947 if (!NT_SUCCESS(Status))
948 {
949 DPRINT1("Failed to query battery state: Status: 0x%08X\n", Status);
950 return Status;
951 }
952 }
953 else
954 {
955 /* No batteries present, set defaults */
956 RtlZeroMemory(&BatteryState, sizeof(BatteryState));
957 BatteryState.AcOnLine = TRUE;
958 }
959
961 {
962 /* Copy the battery state to the output buffer */
963 RtlCopyMemory(OutputBuffer, &BatteryState, sizeof(BatteryState));
965 }
967 {
969 }
970 _SEH2_END;
971
972 break;
973 }
974
976 {
978
979 if (InputBuffer != NULL)
983
985 {
989
991 }
993 {
995 }
996 _SEH2_END;
997
998 break;
999 }
1000
1002 {
1004
1005 if (InputBuffer != NULL)
1009
1010 /* FIXME: return structures for all processors */
1011
1012 _SEH2_TRY
1013 {
1014 /* FIXME: some values are hardcoded */
1015 PowerInformation->Number = 0;
1016 PowerInformation->MaxMhz = 1000;
1017 PowerInformation->CurrentMhz = KeGetCurrentPrcb()->MHz;
1018 PowerInformation->MhzLimit = 1000;
1019 PowerInformation->MaxIdleState = 0;
1020 PowerInformation->CurrentIdleState = 0;
1021
1023 }
1025 {
1027 }
1028 _SEH2_END;
1029
1030 break;
1031 }
1032
1033 default:
1035 DPRINT1("PowerInformationLevel 0x%x is UNIMPLEMENTED! Have a nice day.\n",
1036 PowerInformationLevel);
1037 break;
1038 }
1039
1040 return Status;
1041}
#define PAGED_CODE()
_In_ PVOID _In_ ULONG _Out_ PVOID _In_ ULONG _Inout_ PULONG _In_ KPROCESSOR_MODE PreviousMode
#define DPRINT1
Definition: precomp.h:8
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1187
#define KeGetPreviousMode()
Definition: ketypes.h:1115
#define KernelMode
Definition: asm.h:38
SYSTEM_POWER_CAPABILITIES PopCapabilities
Definition: power.c:29
static NTSTATUS PopQueryBatteryState(_Out_ PSYSTEM_BATTERY_STATE BatteryState)
Definition: power.c:789
struct SYSTEM_POWER_CAPABILITIES * PSYSTEM_POWER_CAPABILITIES
@ SystemBatteryState
Definition: ntpoapi.h:72
@ SystemPowerCapabilities
Definition: ntpoapi.h:71
@ ProcessorInformation
Definition: ntpoapi.h:78
struct _PROCESSOR_POWER_INFORMATION * PPROCESSOR_POWER_INFORMATION
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:181
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:82
#define _SEH2_END
Definition: pseh2_64.h:171
#define _SEH2_TRY
Definition: pseh2_64.h:71
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:184
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define DPRINT
Definition: sndvol32.h:73
BOOLEAN SystemBatteriesPresent
Definition: ntpoapi.h:374
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_ WDFDEVICE _In_ PWDF_DEVICE_POWER_CAPABILITIES PowerCapabilities
Definition: wdfdevice.h:3892
_In_ WDFREQUEST _In_ size_t OutputBufferLength
Definition: wdfio.h:320
_In_ WDFREQUEST _In_ size_t _In_ size_t InputBufferLength
Definition: wdfio.h:322
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR OutputBuffer
Definition: wdfiotarget.h:863
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR InputBuffer
Definition: wdfiotarget.h:953
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7

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

◆ NtRequestWakeupLatency()

NTSTATUS NTAPI NtRequestWakeupLatency ( IN LATENCY_TIME  Latency)

Definition at line 1062 of file power.c.

1063{
1066}

Referenced by RequestWakeupLatency().

◆ NtSetSystemPowerState()

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

Definition at line 1127 of file power.c.

1130{
1134 ULONG Dummy;
1135
1136 /* Check for invalid parameter combinations */
1139 (SystemAction > PowerActionWarmEject) ||
1140 (SystemAction < PowerActionReserved) ||
1148 {
1149 DPRINT1("NtSetSystemPowerState: Bad parameters!\n");
1150 DPRINT1(" SystemAction: 0x%x\n", SystemAction);
1151 DPRINT1(" MinSystemState: 0x%x\n", MinSystemState);
1152 DPRINT1(" Flags: 0x%x\n", Flags);
1154 }
1155
1156 /* Check for user caller */
1157 if (PreviousMode != KernelMode)
1158 {
1159 /* Check for shutdown permission */
1161 {
1162 /* Not granted */
1163 DPRINT1("ERROR: Privilege not held for shutdown\n");
1165 }
1166
1167 /* Do it as a kernel-mode caller for consistency with system state */
1168 return ZwSetSystemPowerState(SystemAction, MinSystemState, Flags);
1169 }
1170
1171 /* Read policy settings (partial shutdown vs. full shutdown) */
1172 if (SystemAction == PowerActionShutdown) PopReadShutdownPolicy();
1173
1174 /* Disable lazy flushing of registry */
1175 DPRINT("Stopping lazy flush\n");
1177
1178 /* Setup the power action */
1179 Action.Action = SystemAction;
1180 Action.Flags = Flags;
1181
1182 /* Notify callbacks */
1183 DPRINT("Notifying callbacks\n");
1185
1186 /* Swap in any worker thread stacks */
1187 DPRINT("Swapping worker threads\n");
1189
1190 /* Make our action global */
1191 PopAction = Action;
1192
1193 /* Start power loop */
1195 while (TRUE)
1196 {
1197 /* Break out if there's nothing to do */
1198 if (Action.Action == PowerActionNone) break;
1199
1200 /* Check for first-pass or restart */
1201 if (Status == STATUS_CANCELLED)
1202 {
1203 /* Check for shutdown action */
1207 {
1208 /* Set the action */
1210 }
1211
1212 /* Now we are good to go */
1214 }
1215
1216 /* Check if we're still in an invalid status */
1217 if (!NT_SUCCESS(Status)) break;
1218
1219 /* Flush all volumes and the registry */
1220 DPRINT("Flushing volumes\n");
1222
1223#ifndef NEWCC
1224 /* Flush dirty cache pages */
1225 /* XXX: Is that still mandatory? As now we'll wait on lazy writer to complete? */
1227 DPRINT("Cache flushed %lu pages\n", Dummy);
1228#else
1229 Dummy = 0;
1230#endif
1231
1232 /* Set IRP for drivers */
1234 if (PopAction.Shutdown)
1235 {
1236 DPRINT("Queueing shutdown thread\n");
1237 /* Check if we are running in the system context */
1239 {
1240 /* We're not, so use a worker thread for shutdown */
1243 NULL);
1244
1246
1247 /* Spend us -- when we wake up, the system is good to go down */
1250 goto Exit;
1251
1252 }
1253 else
1254 {
1255 /* Do the shutdown inline */
1257 }
1258 }
1259
1260 /* You should not have made it this far */
1261 // ASSERTMSG("System is still up and running?!\n", FALSE);
1262 DPRINT1("System is still up and running, you may not have chosen a yet supported power option: %u\n", PopAction.Action);
1263 break;
1264 }
1265
1266Exit:
1267 /* We're done, return */
1268 return Status;
1269}
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
VOID NTAPI CmSetLazyFlushState(IN BOOLEAN Enable)
Definition: cmlazy.c:446
#define KeGetCurrentThread
Definition: hal.h:55
NTSYSCALLAPI NTSTATUS NTAPI ZwSetSystemPowerState(_In_ POWER_ACTION SystemAction, _In_ SYSTEM_POWER_STATE MinSystemState, _In_ ULONG Flags)
NTSTATUS CcRosFlushDirtyPages(ULONG Target, PULONG Count, BOOLEAN Wait, BOOLEAN CalledFromLazy)
Definition: view.c:309
PCALLBACK_OBJECT PowerStateCallback
Definition: callback.c:29
VOID NTAPI ExNotifyCallback(IN PCALLBACK_OBJECT CallbackObject, IN PVOID Argument1, IN PVOID Argument2)
Definition: callback.c:467
ULONG NTAPI KeSuspendThread(PKTHREAD Thread)
Definition: thrdobj.c:601
const LUID SeShutdownPrivilege
Definition: priv.c:38
WORK_QUEUE_ITEM PopShutdownWorkItem
Definition: power.c:28
POP_POWER_ACTION PopAction
Definition: power.c:27
BOOLEAN NTAPI SeSinglePrivilegeCheck(_In_ LUID PrivilegeValue, _In_ KPROCESSOR_MODE PreviousMode)
Checks if a single privilege is present in the context of the calling thread.
Definition: priv.c:744
_In_ SYSTEM_POWER_STATE MinSystemState
Definition: ntpoapi.h:303
#define POWER_ACTION_UI_ALLOWED
Definition: ntpoapi.h:416
@ PowerSystemMaximum
Definition: ntpoapi.h:42
@ PowerSystemUnspecified
Definition: ntpoapi.h:35
#define POWER_ACTION_LOCK_CONSOLE
Definition: ntpoapi.h:419
#define POWER_ACTION_QUERY_ALLOWED
Definition: ntpoapi.h:415
#define POWER_ACTION_OVERRIDE_APPS
Definition: ntpoapi.h:417
@ PowerActionShutdownOff
Definition: ntpoapi.h:129
@ PowerActionNone
Definition: ntpoapi.h:123
@ PowerActionShutdown
Definition: ntpoapi.h:127
@ PowerActionShutdownReset
Definition: ntpoapi.h:128
@ PowerActionWarmEject
Definition: ntpoapi.h:130
@ PowerActionReserved
Definition: ntpoapi.h:124
#define POWER_ACTION_LIGHTEST_FIRST
Definition: ntpoapi.h:418
#define POWER_ACTION_DISABLE_WAKES
Definition: ntpoapi.h:420
#define POWER_ACTION_CRITICAL
Definition: ntpoapi.h:421
#define STATUS_SYSTEM_SHUTDOWN
Definition: ntstatus.h:981
VOID NTAPI PopReadShutdownPolicy(VOID)
Definition: poshtdwn.c:303
VOID NTAPI PopFlushVolumes(IN BOOLEAN ShuttingDown)
Definition: povolume.c:227
VOID NTAPI PopGracefulShutdown(IN PVOID Context)
Definition: poshtdwn.c:232
PEPROCESS PsInitialSystemProcess
Definition: psmgr.c:50
static void Exit(void)
Definition: sock.c:1330
UCHAR IrpMinor
Definition: po.h:233
POWER_ACTION Action
Definition: po.h:229
BOOLEAN Shutdown
Definition: po.h:228
#define MAXULONG
Definition: typedefs.h:251
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
_In_ WDFIOTARGET _In_ _Strict_type_match_ WDF_IO_TARGET_SENT_IO_ACTION Action
Definition: wdfiotarget.h:510
VOID NTAPI ExSwapinWorkerThreads(IN BOOLEAN AllowSwap)
Definition: work.c:637
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
@ CriticalWorkQueue
Definition: extypes.h:189
#define PsGetCurrentProcess
Definition: psfuncs.h:17

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

◆ NtSetThreadExecutionState()

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

Definition at line 1070 of file power.c.

1072{
1076 PAGED_CODE();
1077
1078 /* Validate flags */
1079 if (esFlags & ~(ES_CONTINUOUS | ES_USER_PRESENT))
1080 {
1081 /* Fail the request */
1083 }
1084
1085 /* Check for user parameters */
1086 if (PreviousMode != KernelMode)
1087 {
1088 /* Protect the probes */
1089 _SEH2_TRY
1090 {
1091 /* Check if the pointer is valid */
1093 }
1095 {
1096 /* It isn't -- fail */
1098 }
1099 _SEH2_END;
1100 }
1101
1102 /* Save the previous state, always masking in the continous flag */
1103 PreviousState = Thread->PowerState | ES_CONTINUOUS;
1104
1105 /* Check if we need to update the power state */
1106 if (esFlags & ES_CONTINUOUS) Thread->PowerState = (UCHAR)esFlags;
1107
1108 /* Protect the write back to user mode */
1109 _SEH2_TRY
1110 {
1111 /* Return the previous flags */
1113 }
1115 {
1116 /* Something's wrong, fail */
1118 }
1119 _SEH2_END;
1120
1121 /* All is good */
1122 return STATUS_SUCCESS;
1123}
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
LONG NTAPI ExSystemExceptionFilter(VOID)
Definition: harderr.c:349
_Out_ EXECUTION_STATE * PreviousFlags
Definition: ntpoapi.h:288
#define ProbeForWriteUlong(Ptr)
Definition: probe.h:36
_In_ WDF_POWER_DEVICE_STATE PreviousState
Definition: wdfdevice.h:829
ULONG EXECUTION_STATE
Definition: potypes.h:213
#define ES_USER_PRESENT
Definition: potypes.h:210
#define ES_CONTINUOUS
Definition: potypes.h:211
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by SetThreadExecutionState().

◆ PoCancelDeviceNotify()

NTSTATUS NTAPI PoCancelDeviceNotify ( IN PVOID  NotifyBlock)

Definition at line 532 of file power.c.

533{
536}

◆ PoInitializePrcb()

VOID NTAPI PoInitializePrcb ( IN PKPRCB  Prcb)

Definition at line 510 of file power.c.

511{
512 /* Initialize the Power State */
513 RtlZeroMemory(&Prcb->PowerState, sizeof(Prcb->PowerState));
514 Prcb->PowerState.Idle0KernelTimeLimit = 0xFFFFFFFF;
515 Prcb->PowerState.CurrentThrottle = 100;
516 Prcb->PowerState.CurrentThrottleIndex = 0;
517 Prcb->PowerState.IdleFunction = PopIdle0;
518
519 /* Initialize the Perf DPC and Timer */
520 KeInitializeDpc(&Prcb->PowerState.PerfDpc, PopPerfIdleDpc, Prcb);
521 KeSetTargetProcessorDpc(&Prcb->PowerState.PerfDpc, Prcb->Number);
522 KeInitializeTimerEx(&Prcb->PowerState.PerfTimer, SynchronizationTimer);
523}
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:712
VOID NTAPI KeSetTargetProcessorDpc(IN PKDPC Dpc, IN CCHAR Number)
Definition: dpc.c:989
@ SynchronizationTimer
VOID NTAPI PopPerfIdleDpc(IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: power.c:490
VOID FASTCALL PopIdle0(IN PPROCESSOR_POWER_STATE PowerState)
Definition: power.c:501
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 397 of file power.c.

398{
400 PCHAR CommandLine;
401 BOOLEAN ForceAcpiDisable = FALSE;
402
403 /* Check if this is phase 1 init */
404 if (BootPhase == 1)
405 {
407 /* Register power button notification */
410 (PVOID)&GUID_DEVICE_SYS_BUTTON,
415 if (!NT_SUCCESS(Status))
416 return FALSE;
417
418 /* Register lid notification */
421 (PVOID)&GUID_DEVICE_LID,
426 if (!NT_SUCCESS(Status))
427 return FALSE;
428
429 /* Register battery notification */
432 (PVOID)&GUID_DEVICE_BATTERY,
437
438 return NT_SUCCESS(Status);
439 }
440
441 /* Initialize the power capabilities */
443
444 /* Get the Command Line */
445 CommandLine = KeLoaderBlock->LoadOptions;
446
447 /* Upcase it */
448 _strupr(CommandLine);
449
450 /* Check for ACPI disable */
451 if (strstr(CommandLine, "NOACPI")) ForceAcpiDisable = TRUE;
452
453 if (ForceAcpiDisable)
454 {
455 /* Set the ACPI State to False if it's been forced that way */
457 }
458 else
459 {
460 /* Otherwise check if the LoaderBlock has a ACPI Table */
462 }
463
464 /* Enable shutdown by power button */
465 if (PopAcpiPresent)
467
468 /* Initialize volume support */
471
472 /* Initialize support for dope */
474
475 /* Initialize support for shutdown waits and work-items */
477
478 return TRUE;
479}
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604
VOID FASTCALL KeInitializeGuardedMutex(OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:31
PLOADER_PARAMETER_BLOCK KeLoaderBlock
Definition: krnlinit.c:28
PDEVICE_NODE IopRootDeviceNode
Definition: devnode.c:18
BOOLEAN PopAcpiPresent
Definition: power.c:26
NTSTATUS NTAPI IoRegisterPlugPlayNotification(_In_ IO_NOTIFICATION_EVENT_CATEGORY EventCategory, _In_ ULONG EventCategoryFlags, _In_opt_ PVOID EventCategoryData, _In_ PDRIVER_OBJECT DriverObject, _In_ PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine, _Inout_opt_ PVOID Context, _Out_ PVOID *NotificationEntry)
Definition: pnpnotify.c:346
LIST_ENTRY PopVolumeDevices
Definition: povolume.c:27
VOID NTAPI PopInitShutdownList(VOID)
Definition: poshtdwn.c:35
@ PolicyDeviceBattery
Definition: po.h:40
@ PolicyDeviceSystemButton
Definition: po.h:38
NTSTATUS NTAPI PopAddRemoveSysCapsCallback(IN PVOID NotificationStructure, IN PVOID Context)
Definition: events.c:147
KSPIN_LOCK PopDopeGlobalLock
Definition: povolume.c:28
KGUARDED_MUTEX PopVolumeLock
Definition: povolume.c:26
_strupr
Definition: string.h:453
PDEVICE_OBJECT PhysicalDeviceObject
Definition: iotypes.h:1011
PLOADER_PARAMETER_EXTENSION Extension
Definition: arc.h:857
uint32_t ULONG_PTR
Definition: typedefs.h:65
char * PCHAR
Definition: typedefs.h:51
_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
@ EventCategoryDeviceInterfaceChange
Definition: iotypes.h:1226
#define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES
Definition: iotypes.h:1239

Referenced by Phase1InitializationDiscard().

◆ PopCleanupPowerState()

VOID NTAPI PopCleanupPowerState ( IN PPOWER_STATE  PowerState)

Definition at line 164 of file power.c.

165{
166 //UNIMPLEMENTED;
167}

Referenced by PspExitProcess(), and PspExitThread().

◆ PopIdle0()

VOID FASTCALL PopIdle0 ( IN PPROCESSOR_POWER_STATE  PowerState)

Definition at line 501 of file power.c.

502{
503 /* FIXME: Extremly naive implementation */
505}
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{
42 PIO_STACK_LOCATION IoStack;
43
45
48
50}
#define VOID
Definition: acefi.h:82
#define _Analysis_assume_
Definition: no_sal2.h:388
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:3225
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
_Inout_opt_ PVOID Parameter
Definition: rtltypes.h:336

◆ PopPerfIdle()

VOID NTAPI PopPerfIdle ( PPROCESSOR_POWER_STATE  PowerState)

Definition at line 483 of file power.c.

484{
485 DPRINT1("PerfIdle function: %p\n", PowerState);
486}
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ WDF_DEVICE_POWER_STATE PowerState
Definition: wdfdevice.h:3040

Referenced by PopPerfIdleDpc().

◆ PopPerfIdleDpc()

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

Definition at line 490 of file power.c.

494{
495 /* Call the Perf Idle function */
497}
VOID NTAPI PopPerfIdle(PPROCESSOR_POWER_STATE PowerState)
Definition: power.c:483
_In_opt_ PVOID DeferredContext
Definition: ketypes.h:739

Referenced by PoInitializePrcb().

◆ PopQueryBatteryState()

static NTSTATUS PopQueryBatteryState ( _Out_ PSYSTEM_BATTERY_STATE  BatteryState)
static

Definition at line 789 of file power.c.

791{
792 static const UNICODE_STRING CompBattDeviceName =
793 RTL_CONSTANT_STRING(L"\\Device\\CompositeBattery");
795 &CompBattDeviceName, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE);
796 HANDLE CompBattHandle;
798 BATTERY_QUERY_INFORMATION BatteryQueryInfo = {0};
799 BATTERY_INFORMATION BatteryInfo = { 0 };
802
803 /* Open the CompositeBattery device */
804 Status = ZwOpenFile(&CompBattHandle,
810 if (!NT_SUCCESS(Status))
811 {
812 DPRINT1("Failed to open CompositeBattery device: Status: 0x%08lX\n", Status);
813 return Status;
814 }
815
816 /* Query the battery tag */
817 ULONG Wait = 0;
818 Status = ZwDeviceIoControlFile(CompBattHandle,
819 NULL,
820 NULL,
821 NULL,
824 &Wait,
825 sizeof(Wait),
826 &BatteryQueryInfo.BatteryTag,
827 sizeof(BatteryQueryInfo.BatteryTag));
828 if (!NT_SUCCESS(Status))
829 {
830 DPRINT1("Failed to query battery tag: Status: 0x%08lX\n", Status);
831 goto Exit;
832 }
833
834 /* Query the battery information */
835 BatteryQueryInfo.InformationLevel = BatteryInformation;
836 Status = ZwDeviceIoControlFile(CompBattHandle,
837 NULL,
838 NULL,
839 NULL,
842 &BatteryQueryInfo,
843 sizeof(BatteryQueryInfo),
844 &BatteryInfo,
845 sizeof(BatteryInfo));
846 if (!NT_SUCCESS(Status))
847 {
848 DPRINT1("Failed to query battery information: Status: 0x%08lX\n", Status);
849 }
850
851 /* Query the battery status */
852 BATTERY_WAIT_STATUS BatteryWait = {0};
853 BatteryWait.BatteryTag = BatteryQueryInfo.BatteryTag;
854 BatteryWait.PowerState = 0xF ; // Wait for all power states
855 BatteryWait.HighCapacity = MAXULONG;
856 Status = ZwDeviceIoControlFile(CompBattHandle,
857 NULL,
858 NULL,
859 NULL,
862 &BatteryWait,
863 sizeof(BatteryWait),
865 sizeof(BatteryStatus));
866 if (!NT_SUCCESS(Status))
867 {
868 DPRINT1("Failed to query battery status: Status: 0x%08lX\n", Status);
869 goto Exit;
870 }
871
872 RtlZeroMemory(BatteryState, sizeof(*BatteryState));
873 BatteryState->BatteryPresent = TRUE;
875 BatteryState->Charging = BooleanFlagOn(BatteryStatus.PowerState, BATTERY_CHARGING);
876 BatteryState->Discharging = BooleanFlagOn(BatteryStatus.PowerState, BATTERY_DISCHARGING);
877 BatteryState->MaxCapacity = BatteryInfo.FullChargedCapacity;
878 BatteryState->RemainingCapacity = BatteryStatus.Capacity;
879 BatteryState->Rate = BatteryStatus.Rate;
880 if (BatteryState->Discharging && BatteryStatus.Rate < 0)
881 {
882 BatteryState->EstimatedTime =
883 3600 * BatteryInfo.FullChargedCapacity / -BatteryStatus.Rate;
884 }
885 else
886 {
887 BatteryState->EstimatedTime = 0;
888 }
889
890Exit:
891 ZwClose(CompBattHandle);
892 return Status;
893}
#define IOCTL_BATTERY_QUERY_TAG
Definition: batclass.h:84
_In_ ULONG _Out_ PBATTERY_STATUS BatteryStatus
Definition: batclass.h:199
#define BATTERY_POWER_ON_LINE
Definition: batclass.h:73
#define BATTERY_DISCHARGING
Definition: batclass.h:74
@ BatteryInformation
Definition: batclass.h:97
#define IOCTL_BATTERY_QUERY_INFORMATION
Definition: batclass.h:86
#define BATTERY_CHARGING
Definition: batclass.h:75
#define IOCTL_BATTERY_QUERY_STATUS
Definition: batclass.h:90
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define GENERIC_READ
Definition: compat.h:135
#define FILE_SHARE_READ
Definition: compat.h:136
#define L(x)
Definition: resources.c:13
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
NTSYSAPI NTSTATUS NTAPI ZwOpenFile(_Out_ PHANDLE FileHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes, _Out_ PIO_STATUS_BLOCK IoStatusBlock, _In_ ULONG ShareAccess, _In_ ULONG OpenOptions)
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define SYNCHRONIZE
Definition: nt_native.h:61
#define RTL_CONSTANT_OBJECT_ATTRIBUTES(n, a)
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
NTSYSAPI NTSTATUS NTAPI ZwDeviceIoControlFile(IN HANDLE DeviceHandle, IN HANDLE Event OPTIONAL, IN PIO_APC_ROUTINE UserApcRoutine OPTIONAL, IN PVOID UserApcContext OPTIONAL, OUT PIO_STATUS_BLOCK IoStatusBlock, IN ULONG IoControlCode, IN PVOID InputBuffer, IN ULONG InputBufferSize, OUT PVOID OutputBuffer, IN ULONG OutputBufferSize)
ULONG FullChargedCapacity
Definition: batclass.h:120
BATTERY_QUERY_INFORMATION_LEVEL InformationLevel
Definition: batclass.h:110
ULONG PowerState
Definition: batclass.h:154
ULONG Capacity
Definition: batclass.h:155
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
_In_ WDFDPC _In_ BOOLEAN Wait
Definition: wdfdpc.h:170

Referenced by NtPowerInformation().

◆ PopQuerySystemPowerStateTraverse()

NTSTATUS PopQuerySystemPowerStateTraverse ( PDEVICE_NODE  DeviceNode,
PVOID  Context 
)

Definition at line 254 of file power.c.

256{
257 PPOWER_STATE_TRAVERSE_CONTEXT PowerStateContext = Context;
258 PDEVICE_OBJECT TopDeviceObject;
260
261 DPRINT("PopQuerySystemPowerStateTraverse(%p, %p)\n", DeviceNode, Context);
262
264 return STATUS_SUCCESS;
265
266 if (DeviceNode->Flags & DNF_LEGACY_DRIVER)
267 return STATUS_SUCCESS;
268
269 TopDeviceObject = IoGetAttachedDeviceReference(DeviceNode->PhysicalDeviceObject);
270
271 Status = PopSendQuerySystemPowerState(TopDeviceObject,
272 PowerStateContext->SystemPowerState,
273 PowerStateContext->PowerAction);
274 if (!NT_SUCCESS(Status))
275 {
276 DPRINT1("Device '%wZ' failed IRP_MN_QUERY_POWER\n", &DeviceNode->InstancePath);
277 }
278 ObDereferenceObject(TopDeviceObject);
279
280#if 0
281 return Status;
282#else
283 return STATUS_SUCCESS;
284#endif
285}
@ DeviceNode
Definition: Node.h:9
#define DNF_LEGACY_DRIVER
Definition: iotypes.h:183
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1406
NTSTATUS PopSendQuerySystemPowerState(PDEVICE_OBJECT DeviceObject, SYSTEM_POWER_STATE SystemState, POWER_ACTION PowerAction)
Definition: power.c:170
SYSTEM_POWER_STATE SystemPowerState
Definition: power.c:20
POWER_ACTION PowerAction
Definition: power.c:21
#define ObDereferenceObject
Definition: obfuncs.h:203

Referenced by PopSetSystemPowerState().

◆ PopRequestPowerIrpCompletion()

static NTSTATUS NTAPI PopRequestPowerIrpCompletion ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_ PIRP  Irp,
_In_reads_opt_(_Inexpressible_("varies")) PVOID  Context 
)
static

Definition at line 132 of file power.c.

136{
140
143
144 PowerState.DeviceState = (ULONG_PTR)Stack->Parameters.Others.Argument3;
145
147 {
148 CompletionRoutine(Stack->Parameters.Others.Argument1,
149 (UCHAR)(ULONG_PTR)Stack->Parameters.Others.Argument2,
151 Stack->Parameters.Others.Argument4,
152 &Irp->IoStatus);
153 }
154
156 IoFreeIrp(Irp);
158
160}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#define ULONG_PTR
Definition: config.h:101
if(dx< 0)
Definition: linetemp.h:194
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:639
_In_ WDFREQUEST _In_opt_ PFN_WDF_REQUEST_COMPLETION_ROUTINE CompletionRoutine
Definition: wdfrequest.h:895
REQUEST_POWER_COMPLETE * PREQUEST_POWER_COMPLETE
Definition: potypes.h:472

◆ PopSendQuerySystemPowerState()

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

Definition at line 170 of file power.c.

171{
175 PIRP Irp;
177
180 FALSE);
181
184 NULL,
185 0,
186 NULL,
187 &Event,
190
194 IrpSp->Parameters.Power.State.SystemState = SystemState;
195 IrpSp->Parameters.Power.ShutdownType = PowerAction;
196
197 Status = PoCallDriver(DeviceObject, Irp);
198 if (Status == STATUS_PENDING)
199 {
201 Executive,
203 FALSE,
204 NULL);
206 }
207
208 return Status;
209}
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4138
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
@ NotificationEvent
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
struct _IO_STACK_LOCATION::@4278::@4314 Power
union _IO_STACK_LOCATION::@1694 Parameters
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define IRP_MN_QUERY_POWER
@ Executive
Definition: ketypes.h:467

Referenced by PopQuerySystemPowerStateTraverse().

◆ PopSendSetSystemPowerState()

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

Definition at line 212 of file power.c.

213{
217 PIRP Irp;
219
222 FALSE);
223
226 NULL,
227 0,
228 NULL,
229 &Event,
232
236 IrpSp->Parameters.Power.State.SystemState = SystemState;
237 IrpSp->Parameters.Power.ShutdownType = PowerAction;
238
239 Status = PoCallDriver(DeviceObject, Irp);
240 if (Status == STATUS_PENDING)
241 {
243 Executive,
245 FALSE,
246 NULL);
248 }
249
250 return Status;
251}

Referenced by PopSetSystemPowerState(), and PopSetSystemPowerStateTraverse().

◆ PopSetSystemPowerState()

NTSTATUS NTAPI PopSetSystemPowerState ( SYSTEM_POWER_STATE  PowerState,
POWER_ACTION  PowerAction 
)

Definition at line 332 of file power.c.

333{
338 POWER_STATE_TRAVERSE_CONTEXT PowerContext;
339
341 if (!NT_SUCCESS(Status))
342 {
343 DPRINT1("No system power driver available\n");
344 Fdo = NULL;
345 }
346 else
347 {
349 if (Fdo == DeviceObject)
350 {
351 DPRINT("An FDO was not attached\n");
352 return STATUS_UNSUCCESSFUL;
353 }
354 }
355
356 /* Set up context */
357 PowerContext.PowerAction = PowerAction;
358 PowerContext.SystemPowerState = PowerState;
359 PowerContext.PowerDevice = Fdo;
360
361 /* Query for system power change */
365 &PowerContext);
366
368 if (!NT_SUCCESS(Status))
369 {
370 DPRINT1("Query system power state failed; changing state anyway\n");
371 }
372
373 /* Set system power change */
377 &PowerContext);
378
380
382
383 if (Fdo != NULL)
384 {
385 if (PowerAction != PowerActionShutdownReset)
387
389 }
390
391 return Status;
392}
#define IopInitDeviceTreeTraverseContext( _DeviceTreeTraverseContext, _DeviceNode, _Action, _Context)
Definition: io.h:229
NTSTATUS IopGetSystemPowerDeviceObject(IN PDEVICE_OBJECT *DeviceObject)
NTSTATUS IopTraverseDeviceTree(PDEVICETREE_TRAVERSE_CONTEXT Context)
NTSTATUS PopSetSystemPowerStateTraverse(PDEVICE_NODE DeviceNode, PVOID Context)
Definition: power.c:288
NTSTATUS PopSendSetSystemPowerState(PDEVICE_OBJECT DeviceObject, SYSTEM_POWER_STATE SystemState, POWER_ACTION PowerAction)
Definition: power.c:212
NTSTATUS PopQuerySystemPowerStateTraverse(PDEVICE_NODE DeviceNode, PVOID Context)
Definition: power.c:254
PDEVICE_OBJECT PowerDevice
Definition: power.c:22
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_Must_inspect_result_ _In_ WDFDEVICE Fdo
Definition: wdffdo.h:461

Referenced by PopShutdownSystem().

◆ PopSetSystemPowerStateTraverse()

NTSTATUS PopSetSystemPowerStateTraverse ( PDEVICE_NODE  DeviceNode,
PVOID  Context 
)

Definition at line 288 of file power.c.

290{
291 PPOWER_STATE_TRAVERSE_CONTEXT PowerStateContext = Context;
292 PDEVICE_OBJECT TopDeviceObject;
294
295 DPRINT("PopSetSystemPowerStateTraverse(%p, %p)\n", DeviceNode, Context);
296
298 return STATUS_SUCCESS;
299
300 if (DeviceNode->PhysicalDeviceObject == PowerStateContext->PowerDevice)
301 return STATUS_SUCCESS;
302
303 if (DeviceNode->Flags & DNF_LEGACY_DRIVER)
304 return STATUS_SUCCESS;
305
306 TopDeviceObject = IoGetAttachedDeviceReference(DeviceNode->PhysicalDeviceObject);
307 if (TopDeviceObject == PowerStateContext->PowerDevice)
308 {
309 ObDereferenceObject(TopDeviceObject);
310 return STATUS_SUCCESS;
311 }
312
313 Status = PopSendSetSystemPowerState(TopDeviceObject,
314 PowerStateContext->SystemPowerState,
315 PowerStateContext->PowerAction);
316 if (!NT_SUCCESS(Status))
317 {
318 DPRINT1("Device '%wZ' failed IRP_MN_SET_POWER\n", &DeviceNode->InstancePath);
319 }
320
321 ObDereferenceObject(TopDeviceObject);
322
323#if 0
324 return Status;
325#else
326 return STATUS_SUCCESS;
327#endif
328}

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

637{
639 return NULL;
640}

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

549{
552}

◆ PoRegisterSystemState()

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

Definition at line 647 of file power.c.

649{
651 return NULL;
652}

◆ PoRequestPowerIrp()

NTSTATUS NTAPI PoRequestPowerIrp ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_ UCHAR  MinorFunction,
_In_ POWER_STATE  PowerState,
_In_opt_ PREQUEST_POWER_COMPLETE  CompletionFunction,
_In_opt_ __drv_aliasesMem PVOID  Context,
_Outptr_opt_ PIRP pIrp 
)

Definition at line 659 of file power.c.

666{
667 PDEVICE_OBJECT TopDeviceObject;
669 PIRP Irp;
670
675
676 /* Always call the top of the device stack */
678
679 Irp = IoAllocateIrp(TopDeviceObject->StackSize + 2, FALSE);
680 if (!Irp)
681 {
682 ObDereferenceObject(TopDeviceObject);
684 }
685
686 Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
687 Irp->IoStatus.Information = 0;
688
690
692 Stack->Parameters.Others.Argument1 = DeviceObject;
693 Stack->Parameters.Others.Argument2 = (PVOID)(ULONG_PTR)MinorFunction;
694 Stack->Parameters.Others.Argument3 = (PVOID)(ULONG_PTR)PowerState.DeviceState;
695 Stack->Parameters.Others.Argument4 = Context;
696 Stack->DeviceObject = TopDeviceObject;
698
700 Stack->MajorFunction = IRP_MJ_POWER;
701 Stack->MinorFunction = MinorFunction;
703 {
704 Stack->Parameters.WaitWake.PowerState = PowerState.SystemState;
705 }
706 else
707 {
708 Stack->Parameters.Power.Type = DevicePowerState;
709 Stack->Parameters.Power.State = PowerState;
710 }
711
712 if (pIrp != NULL)
713 *pIrp = Irp;
714
716 PoCallDriver(TopDeviceObject, Irp);
717
718 /* Always return STATUS_PENDING. The completion routine
719 * will call CompletionFunction and complete the Irp.
720 */
721 return STATUS_PENDING;
722}
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
FxIrp * pIrp
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:490
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
static IO_COMPLETION_ROUTINE PopRequestPowerIrpCompletion
Definition: power.c:127
#define STATUS_INVALID_PARAMETER_2
Definition: ntstatus.h:570
void * PVOID
Definition: typedefs.h:50
_In_ UCHAR _In_ UCHAR MinorFunction
Definition: wdfdevice.h:1705
FORCEINLINE VOID IoSetNextIrpStackLocation(_Inout_ PIRP Irp)
Definition: iofuncs.h:2680
#define IRP_MN_WAIT_WAKE
_In_ UCHAR _In_ POWER_STATE _In_opt_ PREQUEST_POWER_COMPLETE CompletionFunction
Definition: pofuncs.h:44

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

589{
591 return;
592}

◆ PoSetPowerState()

◆ PoSetSystemState()

VOID NTAPI PoSetSystemState ( IN EXECUTION_STATE  Flags)

Definition at line 748 of file power.c.

749{
751}

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

565{
566 DPRINT1("PoShutdownBugCheck called\n");
567
568 /* FIXME: Log error if requested */
569 /* FIXME: Initiate a shutdown */
570
571 /* Bugcheck the system */
572 KeBugCheckEx(BugCheckCode,
573 BugCheckParameter1,
574 BugCheckParameter2,
575 BugCheckParameter3,
576 BugCheckParameter4);
577}
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 758 of file power.c.

759{
761}
#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(), KbdHid_Power(), KsDefaultDispatchPower(), MouHid_Power(), NdisIPower(), PartMgrPower(), PciDispatchIrp(), PciIdeXFdoDispatchPower(), PciIdeXPdoDispatchPower(), PciPassIrpFromFdoToPdo(), PDO_HandlePower(), PdoPower(), PdoPowerControl(), PnpRootPowerControl(), PortClsPower(), ProcessorPower(), PwrCompletionFunction(), RamdiskPower(), RequestedPowerIrpHandler(), ScsiPortDispatchPower(), 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 768 of file power.c.

769{
771}

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

◆ PopRequestPowerIrpCompletion

IO_COMPLETION_ROUTINE PopRequestPowerIrpCompletion
static

Definition at line 127 of file power.c.

Referenced by PoRequestPowerIrp().

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