From d7b4f549835c3dedfd224e7c3975528c083dff7b Mon Sep 17 00:00:00 2001 From: Bananymous Date: Thu, 19 Dec 2024 01:53:10 +0200 Subject: [PATCH] Kernel: Check Control Method Battery _STA bit 4 This bit indicates wheter the battery is actually present. --- kernel/kernel/ACPI/BatterySystem.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/kernel/kernel/ACPI/BatterySystem.cpp b/kernel/kernel/ACPI/BatterySystem.cpp index 922a8f19..8bb2ee3a 100644 --- a/kernel/kernel/ACPI/BatterySystem.cpp +++ b/kernel/kernel/ACPI/BatterySystem.cpp @@ -119,6 +119,17 @@ namespace Kernel::ACPI auto batteries = TRY(m_acpi_namespace.find_device_with_eisa_id("PNP0C0A"_sv)); for (const auto& battery : batteries) { + auto [_0, sta_ref] = TRY(m_acpi_namespace.find_named_object(battery, TRY(AML::NameString::from_string("_STA"_sv)))); + if (sta_ref != nullptr) + { + auto sta_result = AML::evaluate_node(_0, sta_ref->node); + if (sta_result.is_error() || sta_result.value().type != AML::Node::Type::Integer) + continue; + // "battery is present" + if (!(sta_result.value().as.integer.value & 0x10)) + continue; + } + auto [_1, bif_ref] = TRY(m_acpi_namespace.find_named_object(battery, TRY(AML::NameString::from_string("_BIF"_sv)))); if (!bif_ref || bif_ref->node.type != AML::Node::Type::Method || bif_ref->node.as.method.arg_count != 0) {