ladybird/Kernel/Firmware/ACPI/Initialize.cpp
Liav A 428afca32b Kernel/ACPI: Make most of StaticParsing methods to be platform-agnostic
Most of the ACPI static parsing methods (methods that can be called
without initializing a full AML parser) are not tied to any specific
platform or CPU architecture.

The only method that is platform-specific is the one that finds the RSDP
structure. Thus, each CPU architecture/platform needs to implement it.
This means that now aarch64 can implement its own method to find the
ACPI RSDP structure, which would be hooked into the rest of the ACPI
code elegantly, but for now I just added a FIXME and that method returns
empty value of Optional<PhysicalAddress>.
2023-06-19 23:49:00 +02:00

44 lines
1.2 KiB
C++

/*
* Copyright (c) 2020-2021, Liav A. <liavalb@hotmail.co.il>
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/Boot/CommandLine.h>
#include <Kernel/Firmware/ACPI/Parser.h>
#include <Kernel/Firmware/ACPI/StaticParsing.h>
#include <Kernel/Memory/TypedMapping.h>
#include <Kernel/Sections.h>
namespace Kernel::ACPI {
UNMAP_AFTER_INIT void initialize()
{
auto feature_level = kernel_command_line().acpi_feature_level();
if (feature_level == AcpiFeatureLevel::Disabled)
return;
auto rsdp = MUST(StaticParsing::find_rsdp_in_platform_specific_memory_locations());
if (!rsdp.has_value())
return;
auto facp = MUST(StaticParsing::find_table(rsdp.value(), "FACP"sv));
if (!facp.has_value())
return;
auto facp_table_or_error = Memory::map_typed<Structures::FADT>(facp.value());
if (facp_table_or_error.is_error())
return;
u8 irq_line = facp_table_or_error.value()->sci_int;
Parser::must_initialize(rsdp.value(), facp.value(), irq_line);
if (kernel_command_line().acpi_feature_level() == AcpiFeatureLevel::Enabled)
Parser::the()->enable_aml_parsing();
}
bool is_enabled()
{
return Parser::the();
}
}