Kernel: AML tries to initialize processors when entering ACPI mode
I had forgotten that Processors used to be a different definition in AML. I also implemented reads/writes for FieldElement/IndexFieldElement that fit in 64 bits. Reads and writes to buffer are still a TODO.
This commit is contained in:
@@ -36,71 +36,6 @@ namespace Kernel::ACPI::AML
|
||||
return device->enter_context_and_parse_term_list(context, name_string.value(), device_pkg.value());
|
||||
}
|
||||
|
||||
void initialize()
|
||||
{
|
||||
bool run_ini = true;
|
||||
bool init_children = true;
|
||||
|
||||
auto _sta = Namespace::root_namespace()->find_object(scope, NameString("_STA"sv));
|
||||
if (_sta && _sta->type == Node::Type::Method)
|
||||
{
|
||||
auto* method = static_cast<Method*>(_sta.ptr());
|
||||
if (method->arg_count != 0)
|
||||
{
|
||||
AML_ERROR("Method {}._STA has {} arguments, expected 0", scope, method->arg_count);
|
||||
return;
|
||||
}
|
||||
auto result = method->evaluate({});
|
||||
if (!result.has_value())
|
||||
{
|
||||
AML_ERROR("Failed to evaluate {}._STA", scope);
|
||||
return;
|
||||
}
|
||||
if (!result.value())
|
||||
{
|
||||
AML_ERROR("Failed to evaluate {}._STA, return value is null", scope);
|
||||
return;
|
||||
}
|
||||
auto result_val = result.value()->as_integer();
|
||||
if (!result_val.has_value())
|
||||
{
|
||||
AML_ERROR("Failed to evaluate {}._STA, return value could not be resolved to integer", scope);
|
||||
AML_ERROR(" Return value: ");
|
||||
result.value()->debug_print(0);
|
||||
return;
|
||||
}
|
||||
run_ini = (result_val.value() & 0x01);
|
||||
init_children = run_ini || (result_val.value() & 0x02);
|
||||
}
|
||||
|
||||
if (run_ini)
|
||||
{
|
||||
auto _ini = Namespace::root_namespace()->find_object(scope, NameString("_INI"sv));
|
||||
if (_ini && _ini->type == Node::Type::Method)
|
||||
{
|
||||
auto* method = static_cast<Method*>(_ini.ptr());
|
||||
if (method->arg_count != 0)
|
||||
{
|
||||
AML_ERROR("Method {}._INI has {} arguments, expected 0", scope, method->arg_count);
|
||||
return;
|
||||
}
|
||||
method->evaluate({});
|
||||
}
|
||||
}
|
||||
|
||||
if (init_children)
|
||||
{
|
||||
for (auto& [_, child] : objects)
|
||||
{
|
||||
if (child->type == Node::Type::Device)
|
||||
{
|
||||
auto* device = static_cast<Device*>(child.ptr());
|
||||
device->initialize();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void debug_print(int indent) const override
|
||||
{
|
||||
AML_DEBUG_PRINT_INDENT(indent);
|
||||
@@ -117,4 +52,6 @@ namespace Kernel::ACPI::AML
|
||||
}
|
||||
};
|
||||
|
||||
bool initialize_device(BAN::RefPtr<NamedObject> device);
|
||||
|
||||
}
|
||||
|
||||
@@ -40,13 +40,13 @@ namespace Kernel::ACPI::AML
|
||||
struct FieldElement : public NamedObject
|
||||
{
|
||||
uint64_t bit_offset;
|
||||
uint32_t bit_count;
|
||||
uint64_t bit_count;
|
||||
|
||||
FieldRules access_rules;
|
||||
|
||||
BAN::RefPtr<OpRegion> op_region = nullptr;
|
||||
BAN::RefPtr<OpRegion> op_region;
|
||||
|
||||
FieldElement(NameSeg name, uint64_t bit_offset, uint32_t bit_count, FieldRules access_rules)
|
||||
FieldElement(NameSeg name, uint64_t bit_offset, uint64_t bit_count, FieldRules access_rules)
|
||||
: NamedObject(Node::Type::FieldElement, name)
|
||||
, bit_offset(bit_offset)
|
||||
, bit_count(bit_count)
|
||||
@@ -59,16 +59,10 @@ namespace Kernel::ACPI::AML
|
||||
void debug_print(int indent) const override;
|
||||
|
||||
private:
|
||||
struct AccessType
|
||||
{
|
||||
uint64_t offset;
|
||||
uint64_t mask;
|
||||
uint32_t access_size;
|
||||
uint32_t shift;
|
||||
};
|
||||
BAN::Optional<AccessType> determine_access_type() const;
|
||||
BAN::Optional<uint64_t> read_field(uint64_t offset, uint32_t access_size) const;
|
||||
bool write_field(uint64_t offset, uint32_t access_size, uint64_t value) const;
|
||||
BAN::Optional<uint64_t> evaluate_internal();
|
||||
bool store_internal(uint64_t value);
|
||||
|
||||
friend struct IndexFieldElement;
|
||||
};
|
||||
|
||||
struct Field
|
||||
@@ -79,20 +73,23 @@ namespace Kernel::ACPI::AML
|
||||
struct IndexFieldElement : public NamedObject
|
||||
{
|
||||
uint64_t bit_offset;
|
||||
uint32_t bit_count;
|
||||
uint64_t bit_count;
|
||||
|
||||
FieldRules access_rules;
|
||||
|
||||
BAN::RefPtr<FieldElement> index_element = nullptr;
|
||||
BAN::RefPtr<FieldElement> data_element = nullptr;
|
||||
BAN::RefPtr<FieldElement> index_element;
|
||||
BAN::RefPtr<FieldElement> data_element;
|
||||
|
||||
IndexFieldElement(NameSeg name, uint64_t bit_offset, uint32_t bit_count, FieldRules access_rules)
|
||||
IndexFieldElement(NameSeg name, uint64_t bit_offset, uint64_t bit_count, FieldRules access_rules)
|
||||
: NamedObject(Node::Type::IndexFieldElement, name)
|
||||
, bit_offset(bit_offset)
|
||||
, bit_count(bit_count)
|
||||
, access_rules(access_rules)
|
||||
{}
|
||||
|
||||
BAN::RefPtr<Node> evaluate() override;
|
||||
bool store(BAN::RefPtr<Node> source) override;
|
||||
|
||||
void debug_print(int indent) const override;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user