Kernel: Fix AML aliases and package elements
This commit is contained in:
parent
19d16620a6
commit
c65613901f
|
@ -7,37 +7,8 @@
|
||||||
namespace Kernel::ACPI::AML
|
namespace Kernel::ACPI::AML
|
||||||
{
|
{
|
||||||
|
|
||||||
struct Alias final : public AML::NamedObject
|
struct Alias
|
||||||
{
|
{
|
||||||
BAN::RefPtr<AML::Node> target;
|
|
||||||
|
|
||||||
Alias(NameSeg name, BAN::RefPtr<AML::Node> target)
|
|
||||||
: NamedObject(Node::Type::Alias, name)
|
|
||||||
, target(target)
|
|
||||||
{}
|
|
||||||
|
|
||||||
BAN::RefPtr<AML::Node> to_underlying() override { return target; }
|
|
||||||
|
|
||||||
bool is_scope() const override { return target->is_scope(); }
|
|
||||||
|
|
||||||
BAN::RefPtr<AML::Node> convert(uint8_t mask) override
|
|
||||||
{
|
|
||||||
ASSERT(target);
|
|
||||||
return target->convert(mask);
|
|
||||||
}
|
|
||||||
|
|
||||||
BAN::RefPtr<Node> copy() override
|
|
||||||
{
|
|
||||||
ASSERT(target);
|
|
||||||
return target->copy();
|
|
||||||
}
|
|
||||||
|
|
||||||
BAN::RefPtr<AML::Node> store(BAN::RefPtr<AML::Node> node) override
|
|
||||||
{
|
|
||||||
ASSERT(target);
|
|
||||||
return target->store(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
static ParseResult parse(ParseContext& context)
|
static ParseResult parse(ParseContext& context)
|
||||||
{
|
{
|
||||||
ASSERT(context.aml_data.size() >= 1);
|
ASSERT(context.aml_data.size() >= 1);
|
||||||
|
@ -59,27 +30,19 @@ namespace Kernel::ACPI::AML
|
||||||
return ParseResult::Success;
|
return ParseResult::Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto alias = MUST(BAN::RefPtr<Alias>::create(alias_string.value().path.back(), source_object->to_underlying()));
|
if (!Namespace::root_namespace()->add_named_object(context, alias_string.value(), source_object))
|
||||||
if (!Namespace::root_namespace()->add_named_object(context, alias_string.value(), alias))
|
|
||||||
return ParseResult::Success;
|
return ParseResult::Success;
|
||||||
|
|
||||||
#if AML_DEBUG_LEVEL >= 2
|
#if AML_DEBUG_LEVEL >= 2
|
||||||
alias->debug_print(0);
|
AML_DEBUG_PRINT("Alias \"");
|
||||||
|
alias_string->debug_print();
|
||||||
|
AML_DEBUG_PRINT("\" => ");
|
||||||
|
source_object->debug_print(0);
|
||||||
AML_DEBUG_PRINTLN("");
|
AML_DEBUG_PRINTLN("");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return ParseResult::Success;
|
return ParseResult::Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
void debug_print(int indent) const override
|
|
||||||
{
|
|
||||||
AML_DEBUG_PRINT_INDENT(indent);
|
|
||||||
AML_DEBUG_PRINTLN("Alias {} { ", name);
|
|
||||||
target->debug_print(indent + 1);
|
|
||||||
AML_DEBUG_PRINTLN("");
|
|
||||||
AML_DEBUG_PRINT_INDENT(indent);
|
|
||||||
AML_DEBUG_PRINT("}");
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,9 +50,6 @@ namespace Kernel::ACPI::AML
|
||||||
|
|
||||||
switch (destination->type)
|
switch (destination->type)
|
||||||
{
|
{
|
||||||
case AML::Node::Type::Alias:
|
|
||||||
static_cast<AML::Alias*>(destination.ptr())->target = source->copy();
|
|
||||||
return source;
|
|
||||||
case AML::Node::Type::Name:
|
case AML::Node::Type::Name:
|
||||||
static_cast<AML::Name*>(destination.ptr())->object = source->copy();
|
static_cast<AML::Name*>(destination.ptr())->object = source->copy();
|
||||||
return source;
|
return source;
|
||||||
|
|
|
@ -67,7 +67,12 @@ namespace Kernel::ACPI::AML
|
||||||
return ParseResult::Failure;
|
return ParseResult::Failure;
|
||||||
}
|
}
|
||||||
auto package_element = package->elements[index];
|
auto package_element = package->elements[index];
|
||||||
result = MUST(BAN::RefPtr<AML::Reference>::create(package_element->to_underlying()));
|
if (!package_element)
|
||||||
|
{
|
||||||
|
AML_ERROR("IndexOp target is null package element");
|
||||||
|
return ParseResult::Failure;
|
||||||
|
}
|
||||||
|
result = MUST(BAN::RefPtr<AML::Reference>::create(package_element));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case AML::Node::Type::String:
|
case AML::Node::Type::String:
|
||||||
|
|
|
@ -29,7 +29,6 @@ namespace Kernel::ACPI::AML
|
||||||
enum class Type : uint8_t
|
enum class Type : uint8_t
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
Alias,
|
|
||||||
BankFieldElement,
|
BankFieldElement,
|
||||||
Buffer,
|
Buffer,
|
||||||
BufferField,
|
BufferField,
|
||||||
|
|
|
@ -31,7 +31,6 @@ namespace Kernel::ACPI::AML
|
||||||
switch (object->type)
|
switch (object->type)
|
||||||
{
|
{
|
||||||
case AML::Node::Type::None:
|
case AML::Node::Type::None:
|
||||||
case AML::Node::Type::Alias:
|
|
||||||
case AML::Node::Type::Name:
|
case AML::Node::Type::Name:
|
||||||
case AML::Node::Type::PackageElement:
|
case AML::Node::Type::PackageElement:
|
||||||
case AML::Node::Type::Reference:
|
case AML::Node::Type::Reference:
|
||||||
|
|
|
@ -84,7 +84,7 @@ namespace Kernel::ACPI::AML
|
||||||
{
|
{
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
{
|
{
|
||||||
AML_ERROR("Trying to store into uninitialized PackageElement");
|
AML_ERROR("Trying to convert uninitialized PackageElement");
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
if (!resolved && !resolve())
|
if (!resolved && !resolve())
|
||||||
|
@ -96,7 +96,7 @@ namespace Kernel::ACPI::AML
|
||||||
{
|
{
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
{
|
{
|
||||||
AML_ERROR("Trying to store into uninitialized PackageElement");
|
AML_ERROR("Trying to read uninitialized PackageElement");
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
if (!resolved && !resolve())
|
if (!resolved && !resolve())
|
||||||
|
@ -108,17 +108,17 @@ namespace Kernel::ACPI::AML
|
||||||
{
|
{
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
{
|
{
|
||||||
AML_ERROR("Trying to store into uninitialized PackageElement");
|
initialized = true;
|
||||||
return {};
|
resolved = true;
|
||||||
}
|
}
|
||||||
if (!resolved && !resolve())
|
if (!resolved && !resolve())
|
||||||
return {};
|
return {};
|
||||||
ASSERT(element->type != AML::Node::Type::Reference);
|
ASSERT(!element || element->type != AML::Node::Type::Reference);
|
||||||
if (node->type == AML::Node::Type::Reference)
|
if (node->type == AML::Node::Type::Reference)
|
||||||
element = static_cast<AML::Reference*>(element.ptr())->node;
|
element = static_cast<AML::Reference*>(node.ptr())->node;
|
||||||
else
|
else
|
||||||
element = element->copy();
|
element = node->copy();
|
||||||
return element;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ParseResult parse(AML::ParseContext& context, BAN::RefPtr<AML::Package> package)
|
static ParseResult parse(AML::ParseContext& context, BAN::RefPtr<AML::Package> package)
|
||||||
|
|
|
@ -22,8 +22,8 @@ namespace Kernel::ACPI::AML
|
||||||
if (!object_result.success())
|
if (!object_result.success())
|
||||||
return ParseResult::Failure;
|
return ParseResult::Failure;
|
||||||
auto object_node = object_result.node();
|
auto object_node = object_result.node();
|
||||||
if (object_node && object_node->type == AML::Node::Type::Register)
|
if (object_node)
|
||||||
object_node = static_cast<AML::Register*>(object_node.ptr())->value;
|
object_node = object_node->to_underlying();
|
||||||
if (!object_node)
|
if (!object_node)
|
||||||
{
|
{
|
||||||
AML_ERROR("SizeOf object is null");
|
AML_ERROR("SizeOf object is null");
|
||||||
|
|
|
@ -495,25 +495,7 @@ acpi_release_global_lock:
|
||||||
dwarnln("\\_S5 not found");
|
dwarnln("\\_S5 not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BAN::RefPtr<AML::Node> s5_evaluated = s5_object;
|
auto s5_evaluated = s5_object->to_underlying();
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
bool done = false;
|
|
||||||
switch (s5_evaluated->type)
|
|
||||||
{
|
|
||||||
case AML::Node::Type::Alias:
|
|
||||||
s5_evaluated = static_cast<AML::Alias*>(s5_evaluated.ptr())->target;
|
|
||||||
break;
|
|
||||||
case AML::Node::Type::Name:
|
|
||||||
s5_evaluated = static_cast<AML::Name*>(s5_evaluated.ptr())->object;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
done = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (done)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (!s5_evaluated)
|
if (!s5_evaluated)
|
||||||
{
|
{
|
||||||
dwarnln("Failed to evaluate \\_S5");
|
dwarnln("Failed to evaluate \\_S5");
|
||||||
|
|
|
@ -159,7 +159,6 @@ namespace Kernel::ACPI
|
||||||
LockGuard _(m_object_mutex);
|
LockGuard _(m_object_mutex);
|
||||||
|
|
||||||
ASSERT(!object_path.path.empty());
|
ASSERT(!object_path.path.empty());
|
||||||
ASSERT(object_path.path.back() == object->name);
|
|
||||||
|
|
||||||
auto canonical_path = resolve_path(parse_context.scope, object_path, FindMode::ForceAbsolute, false);
|
auto canonical_path = resolve_path(parse_context.scope, object_path, FindMode::ForceAbsolute, false);
|
||||||
ASSERT(canonical_path.has_value());
|
ASSERT(canonical_path.has_value());
|
||||||
|
|
|
@ -93,6 +93,8 @@ namespace Kernel::ACPI
|
||||||
auto result_integer = result.value()
|
auto result_integer = result.value()
|
||||||
? result.value()->convert(AML::Node::ConvInteger)
|
? result.value()->convert(AML::Node::ConvInteger)
|
||||||
: BAN::RefPtr<AML::Node>();
|
: BAN::RefPtr<AML::Node>();
|
||||||
|
if (!result_integer)
|
||||||
|
return {};
|
||||||
return static_cast<AML::Integer*>(result_integer.ptr());
|
return static_cast<AML::Integer*>(result_integer.ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue