Kernel: AML implement SleepOp

This commit is contained in:
Bananymous 2024-04-12 16:17:14 +03:00
parent 6b43d12469
commit 8f2f98b7b4
2 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,38 @@
#pragma once
#include <kernel/ACPI/AML/Bytes.h>
#include <kernel/ACPI/AML/ParseContext.h>
#include <kernel/Timer/Timer.h>
namespace Kernel::ACPI::AML
{
struct Sleep
{
static ParseResult parse(ParseContext& context)
{
ASSERT(context.aml_data.size() >= 2);
ASSERT(static_cast<AML::Byte>(context.aml_data[0]) == AML::Byte::ExtOpPrefix);
ASSERT(static_cast<AML::ExtOp>(context.aml_data[1]) == AML::ExtOp::SleepOp);
context.aml_data = context.aml_data.slice(2);
auto sleep_time_result = AML::parse_object(context);
if (!sleep_time_result.success())
return ParseResult::Failure;
auto sleep_time = sleep_time_result.node() ? sleep_time_result.node()->as_integer() : BAN::Optional<uint64_t>();
if (!sleep_time.has_value())
{
AML_ERROR("Sleep time cannot be evaluated to an integer");
return ParseResult::Failure;
}
#if AML_DEBUG_LEVEL >= 2
AML_DEBUG_PRINTLN("Sleeping for {} ms", sleep_time.value());
#endif
SystemTimer::get().sleep(sleep_time.value());
return ParseResult::Success;
}
};
}

View File

@ -16,6 +16,7 @@
#include <kernel/ACPI/AML/Processor.h> #include <kernel/ACPI/AML/Processor.h>
#include <kernel/ACPI/AML/Reference.h> #include <kernel/ACPI/AML/Reference.h>
#include <kernel/ACPI/AML/Region.h> #include <kernel/ACPI/AML/Region.h>
#include <kernel/ACPI/AML/Sleep.h>
#include <kernel/ACPI/AML/Store.h> #include <kernel/ACPI/AML/Store.h>
#include <kernel/ACPI/AML/String.h> #include <kernel/ACPI/AML/String.h>
#include <kernel/ACPI/AML/ThermalZone.h> #include <kernel/ACPI/AML/ThermalZone.h>
@ -75,6 +76,8 @@ namespace Kernel::ACPI
return AML::ThermalZone::parse(context); return AML::ThermalZone::parse(context);
case AML::ExtOp::CondRefOfOp: case AML::ExtOp::CondRefOfOp:
return AML::Reference::parse(context); return AML::Reference::parse(context);
case AML::ExtOp::SleepOp:
return AML::Sleep::parse(context);
default: default:
break; break;
} }