Kernel: Cleanup AML code and fix bugs

I can enter ACPI mode on my own laptop!
This commit is contained in:
2024-04-12 16:03:14 +03:00
parent 17871bb3ca
commit 74940ed33c
13 changed files with 240 additions and 118 deletions

View File

@@ -77,7 +77,7 @@ namespace Kernel::ACPI
AML_DEBUG_PRINTLN("");
#endif
dprintln("Parsed ACPI namespace");
dprintln("Parsed ACPI namespace, total of {} nodes created", AML::Node::total_node_count);
return ns;
}

View File

@@ -1,3 +1,4 @@
#include <kernel/ACPI/AML/Integer.h>
#include <kernel/ACPI/AML/Method.h>
#include <kernel/ACPI/AML/Namespace.h>
#include <kernel/ACPI/AML/ParseContext.h>
@@ -9,6 +10,10 @@ namespace Kernel::ACPI
static BAN::RefPtr<AML::Namespace> s_root_namespace;
static BAN::Vector<uint8_t> s_osi_aml_data;
BAN::RefPtr<AML::Integer> AML::Integer::Constants::Zero;
BAN::RefPtr<AML::Integer> AML::Integer::Constants::One;
BAN::RefPtr<AML::Integer> AML::Integer::Constants::Ones;
BAN::RefPtr<AML::Namespace> AML::Namespace::root_namespace()
{
ASSERT(s_root_namespace);
@@ -198,6 +203,10 @@ namespace Kernel::ACPI
ASSERT(!s_root_namespace);
s_root_namespace = MUST(BAN::RefPtr<Namespace>::create(NameSeg("\\"sv)));
Integer::Constants::Zero = MUST(BAN::RefPtr<Integer>::create(0, true));
Integer::Constants::One = MUST(BAN::RefPtr<Integer>::create(1, true));
Integer::Constants::Ones = MUST(BAN::RefPtr<Integer>::create(0xFFFFFFFFFFFFFFFF, true));
AML::ParseContext context;
context.scope = AML::NameString("\\"sv);

View File

@@ -27,6 +27,8 @@ namespace Kernel::ACPI
AML::ParseResult AML::ParseResult::Failure = AML::ParseResult(AML::ParseResult::Result::Failure);
AML::ParseResult AML::ParseResult::Success = AML::ParseResult(AML::ParseResult::Result::Success);
uint64_t AML::Node::total_node_count = 0;
BAN::Optional<uint64_t> AML::Node::as_integer()
{
if (type == Type::Integer)
@@ -214,6 +216,8 @@ namespace Kernel::ACPI
AML_ERROR("Failed to evaluate {}", name_string.value());
return ParseResult::Failure;
}
if (!result.value())
return ParseResult::Success;
return ParseResult(result.value());
}
return ParseResult(aml_object);

View File

@@ -101,24 +101,19 @@ namespace Kernel::ACPI
auto result = method->evaluate({}, sync_stack);
if (!result.has_value())
{
AML_ERROR("Failed to evaluate {}._STA", scope->scope);
return false;
AML_ERROR("Failed to evaluate {}._STA, ignoring device", scope->scope);
return true;
}
if (!result.value())
{
AML_ERROR("Failed to evaluate {}._STA, return value is null", scope->scope);
return false;
}
auto result_val = result.value()->as_integer();
if (!result_val.has_value())
auto result_value = result.has_value() ? result.value()->as_integer() : BAN::Optional<uint64_t>();
if (!result_value.has_value())
{
AML_ERROR("Failed to evaluate {}._STA, return value could not be resolved to integer", scope->scope);
AML_ERROR(" Return value: ");
result.value()->debug_print(0);
return false;
}
run_ini = (result_val.value() & 0x01);
init_children = run_ini || (result_val.value() & 0x02);
run_ini = (result_value.value() & 0x01);
init_children = run_ini || (result_value.value() & 0x02);
}
if (run_ini)