[NTOSKRNL] Use global power capabilities and report button presence
authorEric Kohl <eric.kohl@reactos.org>
Sun, 7 Apr 2019 14:41:56 +0000 (16:41 +0200)
committerEric Kohl <eric.kohl@reactos.org>
Sun, 7 Apr 2019 14:42:58 +0000 (16:42 +0200)
- 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.

ntoskrnl/include/internal/po.h
ntoskrnl/po/events.c
ntoskrnl/po/power.c

index f9d57e3..0d72234 100644 (file)
@@ -365,4 +365,5 @@ extern KGUARDED_MUTEX PopVolumeLock;
 extern LIST_ENTRY PopVolumeDevices;
 extern KSPIN_LOCK PopDopeGlobalLock;
 extern POP_POWER_ACTION PopAction;
+extern SYSTEM_POWER_CAPABILITIES PopCapabilities;
 
index e79f6df..b6392bd 100644 (file)
@@ -242,13 +242,23 @@ PopAddRemoveSysCapsCallback(IN PVOID NotificationStructure,
             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);
-            if (Caps & SYS_BUTTON_POWER) DPRINT(" POWER");
-            if (Caps & SYS_BUTTON_SLEEP) DPRINT(" SLEEP");
-            if (Caps & SYS_BUTTON_LID) DPRINT(" LID");
-            DPRINT(" )\n");
+            DPRINT("POWER button present\n");
+            PopCapabilities.PowerButtonPresent = TRUE;
+        }
+
+        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,
index a0dd4fb..f249d0e 100644 (file)
@@ -26,6 +26,7 @@ PDEVICE_NODE PopSystemPowerDeviceNode = NULL;
 BOOLEAN PopAcpiPresent = FALSE;
 POP_POWER_ACTION PopAction;
 WORK_QUEUE_ITEM PopShutdownWorkItem;
+SYSTEM_POWER_CAPABILITIES PopCapabilities;
 
 /* PRIVATE FUNCTIONS *********************************************************/
 
@@ -323,6 +324,9 @@ PoInitSystem(IN ULONG BootPhase)
         return TRUE;
     }
 
+    /* Initialize the power capabilities */
+    RtlZeroMemory(&PopCapabilities, sizeof(SYSTEM_POWER_CAPABILITIES));
+
     /* Get the Command Line */
     CommandLine = KeLoaderBlock->LoadOptions;
 
@@ -343,6 +347,9 @@ PoInitSystem(IN ULONG BootPhase)
         PopAcpiPresent = KeLoaderBlock->Extension->AcpiTable != NULL ? TRUE : FALSE;
     }
 
+    /* Enable shutdown by power button */
+    if (PopAcpiPresent)
+        PopCapabilities.SystemS5 = TRUE;
 
     /* Initialize volume support */
     InitializeListHead(&PopVolumeDevices);
@@ -720,9 +727,9 @@ NtPowerInformation(IN POWER_INFORMATION_LEVEL PowerInformationLevel,
 
             _SEH2_TRY
             {
-                /* Just zero the struct (and thus set PowerCapabilities->SystemBatteriesPresent = FALSE) */
-                RtlZeroMemory(PowerCapabilities, sizeof(SYSTEM_POWER_CAPABILITIES));
-                //PowerCapabilities->SystemBatteriesPresent = 0;
+                RtlCopyMemory(PowerCapabilities,
+                              &PopCapabilities,
+                              sizeof(SYSTEM_POWER_CAPABILITIES));
 
                 Status = STATUS_SUCCESS;
             }