[NTOSKRNL] Use global power capabilities and report button presence

- Add and initialize a global power capabilities variable.
- Return the global power capabilities via NtPowerInformation.SystemPowerCapabilities.
- Report the presence of power button, sleep button and lid.
This commit is contained in:
Eric Kohl 2019-04-07 16:41:56 +02:00
parent b71429059a
commit 626aaf227c
3 changed files with 27 additions and 9 deletions

View file

@ -365,4 +365,5 @@ extern KGUARDED_MUTEX PopVolumeLock;
extern LIST_ENTRY PopVolumeDevices; extern LIST_ENTRY PopVolumeDevices;
extern KSPIN_LOCK PopDopeGlobalLock; extern KSPIN_LOCK PopDopeGlobalLock;
extern POP_POWER_ACTION PopAction; extern POP_POWER_ACTION PopAction;
extern SYSTEM_POWER_CAPABILITIES PopCapabilities;

View file

@ -242,13 +242,23 @@ PopAddRemoveSysCapsCallback(IN PVOID NotificationStructure,
return STATUS_INSUFFICIENT_RESOURCES; return STATUS_INSUFFICIENT_RESOURCES;
} }
/* FIXME: What do do with the capabilities? */ DPRINT("Device capabilities: 0x%x\n", Caps);
if (Caps & SYS_BUTTON_POWER)
{ {
DPRINT("Device capabilities: 0x%x (", Caps); DPRINT("POWER button present\n");
if (Caps & SYS_BUTTON_POWER) DPRINT(" POWER"); PopCapabilities.PowerButtonPresent = TRUE;
if (Caps & SYS_BUTTON_SLEEP) DPRINT(" SLEEP"); }
if (Caps & SYS_BUTTON_LID) DPRINT(" LID");
DPRINT(" )\n"); if (Caps & SYS_BUTTON_SLEEP)
{
DPRINT("SLEEP button present\n");
PopCapabilities.SleepButtonPresent = TRUE;
}
if (Caps & SYS_BUTTON_LID)
{
DPRINT("LID present\n");
PopCapabilities.LidPresent = TRUE;
} }
SysButtonContext = ExAllocatePoolWithTag(NonPagedPool, SysButtonContext = ExAllocatePoolWithTag(NonPagedPool,

View file

@ -26,6 +26,7 @@ PDEVICE_NODE PopSystemPowerDeviceNode = NULL;
BOOLEAN PopAcpiPresent = FALSE; BOOLEAN PopAcpiPresent = FALSE;
POP_POWER_ACTION PopAction; POP_POWER_ACTION PopAction;
WORK_QUEUE_ITEM PopShutdownWorkItem; WORK_QUEUE_ITEM PopShutdownWorkItem;
SYSTEM_POWER_CAPABILITIES PopCapabilities;
/* PRIVATE FUNCTIONS *********************************************************/ /* PRIVATE FUNCTIONS *********************************************************/
@ -323,6 +324,9 @@ PoInitSystem(IN ULONG BootPhase)
return TRUE; return TRUE;
} }
/* Initialize the power capabilities */
RtlZeroMemory(&PopCapabilities, sizeof(SYSTEM_POWER_CAPABILITIES));
/* Get the Command Line */ /* Get the Command Line */
CommandLine = KeLoaderBlock->LoadOptions; CommandLine = KeLoaderBlock->LoadOptions;
@ -343,6 +347,9 @@ PoInitSystem(IN ULONG BootPhase)
PopAcpiPresent = KeLoaderBlock->Extension->AcpiTable != NULL ? TRUE : FALSE; PopAcpiPresent = KeLoaderBlock->Extension->AcpiTable != NULL ? TRUE : FALSE;
} }
/* Enable shutdown by power button */
if (PopAcpiPresent)
PopCapabilities.SystemS5 = TRUE;
/* Initialize volume support */ /* Initialize volume support */
InitializeListHead(&PopVolumeDevices); InitializeListHead(&PopVolumeDevices);
@ -720,9 +727,9 @@ NtPowerInformation(IN POWER_INFORMATION_LEVEL PowerInformationLevel,
_SEH2_TRY _SEH2_TRY
{ {
/* Just zero the struct (and thus set PowerCapabilities->SystemBatteriesPresent = FALSE) */ RtlCopyMemory(PowerCapabilities,
RtlZeroMemory(PowerCapabilities, sizeof(SYSTEM_POWER_CAPABILITIES)); &PopCapabilities,
//PowerCapabilities->SystemBatteriesPresent = 0; sizeof(SYSTEM_POWER_CAPABILITIES));
Status = STATUS_SUCCESS; Status = STATUS_SUCCESS;
} }