From 00b0dcd30660b5f69a01160e9233e5baac3f8d3b Mon Sep 17 00:00:00 2001 From: Bananymous Date: Thu, 19 Dec 2024 01:45:26 +0200 Subject: [PATCH] Kernel: Reorder ACPI initialization method calls --- kernel/kernel/ACPI/ACPI.cpp | 22 +++++++++-------- kernel/kernel/ACPI/AML/Namespace.cpp | 36 +++++++++++++++------------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/kernel/kernel/ACPI/ACPI.cpp b/kernel/kernel/ACPI/ACPI.cpp index 3b51292c..afc27dd3 100644 --- a/kernel/kernel/ACPI/ACPI.cpp +++ b/kernel/kernel/ACPI/ACPI.cpp @@ -624,16 +624,6 @@ acpi_release_global_lock: { ASSERT(!m_namespace); - TRY(AML::Namespace::prepare_root_namespace()); - m_namespace = &AML::Namespace::root_namespace(); - - if (auto ret = load_aml_tables("DSDT"_sv, false); ret.is_error()) - dwarnln("Could not load DSDT: {}", ret.error()); - if (auto ret = load_aml_tables("SSDT"_sv, true); ret.is_error()) - dwarnln("Could not load all SSDTs: {}", ret.error()); - if (auto ret = load_aml_tables("PSDT"_sv, true); ret.is_error()) - dwarnln("Could not load all PSDTs: {}", ret.error()); - // https://uefi.org/htmlspecs/ACPI_Spec_6_4_html/16_Waking_and_Sleeping/initialization.html#placing-the-system-in-acpi-mode // If not hardware-reduced ACPI and SCI_EN is not set @@ -663,6 +653,18 @@ acpi_release_global_lock: dprintln("Entered ACPI mode"); + TRY(AML::Namespace::prepare_root_namespace()); + m_namespace = &AML::Namespace::root_namespace(); + + if (auto ret = load_aml_tables("DSDT"_sv, false); ret.is_error()) + dwarnln("Could not load DSDT: {}", ret.error()); + if (auto ret = load_aml_tables("SSDT"_sv, true); ret.is_error()) + dwarnln("Could not load all SSDTs: {}", ret.error()); + if (auto ret = load_aml_tables("PSDT"_sv, true); ret.is_error()) + dwarnln("Could not load all PSDTs: {}", ret.error()); + + dprintln("Loaded ACPI tables"); + if (auto ret = m_namespace->post_load_initialize(); ret.is_error()) dwarnln("Failed to initialize ACPI namespace: {}", ret.error()); diff --git a/kernel/kernel/ACPI/AML/Namespace.cpp b/kernel/kernel/ACPI/AML/Namespace.cpp index cb0dd5ad..890df5e9 100644 --- a/kernel/kernel/ACPI/AML/Namespace.cpp +++ b/kernel/kernel/ACPI/AML/Namespace.cpp @@ -4,8 +4,8 @@ #include #include -#define STA_PRESENT 0x01 -#define STA_FUNCTION 0x08 +#define STA_PRESENT 0x01 +#define STA_FUNCTIONAL 0x08 #include @@ -150,6 +150,10 @@ namespace Kernel::ACPI::AML BAN::ErrorOr Namespace::post_load_initialize() { + auto [sb_path, sb_ref] = TRY(find_named_object({}, TRY(NameString::from_string("\\_SB_"_sv)))); + if (sb_ref != nullptr) + TRY(evaluate_ini(sb_path)); + BAN::Vector to_init; TRY(to_init.push_back({})); @@ -176,20 +180,6 @@ namespace Kernel::ACPI::AML return BAN::Iteration::Continue; } - auto sta_ret = evaluate_sta(child_path); - if (sta_ret.is_error()) - return BAN::Iteration::Continue; - - if (sta_ret.value() & STA_PRESENT) - (void)evaluate_ini(child_path); - - if ((sta_ret.value() & STA_PRESENT) || (sta_ret.value() & STA_FUNCTION)) - { - auto child_path_copy = child_path.copy(); - if (!child_path_copy.is_error()) - (void)to_init_next.push_back(child_path_copy.release_value()); - } - (void)for_each_child(current, [&](const Scope& opregion_path, Reference* opregion_ref) -> BAN::Iteration { @@ -199,6 +189,20 @@ namespace Kernel::ACPI::AML } ); + auto sta_ret = evaluate_sta(child_path); + if (sta_ret.is_error()) + return BAN::Iteration::Continue; + + if (sta_ret.value() & STA_PRESENT) + (void)evaluate_ini(child_path); + + if ((sta_ret.value() & STA_PRESENT) || (sta_ret.value() & STA_FUNCTIONAL)) + { + auto child_path_copy = child_path.copy(); + if (!child_path_copy.is_error()) + (void)to_init_next.push_back(child_path_copy.release_value()); + } + return BAN::Iteration::Continue; } ));