2020-04-09 08:39:10 -03:00
|
|
|
/*
|
2021-09-10 10:45:12 -03:00
|
|
|
* Copyright (c) 2020-2021, Liav A. <liavalb@hotmail.co.il>
|
2020-04-09 08:39:10 -03:00
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-04-09 08:39:10 -03:00
|
|
|
*/
|
|
|
|
|
|
2023-02-24 15:21:53 -03:00
|
|
|
#include <Kernel/Boot/CommandLine.h>
|
2021-09-11 04:39:47 -03:00
|
|
|
#include <Kernel/Firmware/ACPI/Parser.h>
|
2023-06-09 16:50:11 -03:00
|
|
|
#include <Kernel/Firmware/ACPI/StaticParsing.h>
|
2021-09-10 10:45:12 -03:00
|
|
|
#include <Kernel/Memory/TypedMapping.h>
|
2021-06-22 12:40:16 -03:00
|
|
|
#include <Kernel/Sections.h>
|
2020-04-09 08:39:10 -03:00
|
|
|
|
2021-07-10 20:36:30 -03:00
|
|
|
namespace Kernel::ACPI {
|
2020-04-09 08:39:10 -03:00
|
|
|
|
2021-02-19 17:29:46 -03:00
|
|
|
UNMAP_AFTER_INIT void initialize()
|
2020-04-09 08:39:10 -03:00
|
|
|
{
|
2021-03-03 05:51:55 -03:00
|
|
|
auto feature_level = kernel_command_line().acpi_feature_level();
|
|
|
|
|
if (feature_level == AcpiFeatureLevel::Disabled)
|
2020-04-09 09:31:47 -03:00
|
|
|
return;
|
|
|
|
|
|
2023-06-09 16:50:11 -03:00
|
|
|
auto rsdp = MUST(StaticParsing::find_rsdp_in_platform_specific_memory_locations());
|
2020-05-22 08:34:53 -03:00
|
|
|
if (!rsdp.has_value())
|
2020-04-09 09:31:47 -03:00
|
|
|
return;
|
|
|
|
|
|
2023-06-09 16:50:11 -03:00
|
|
|
auto facp = MUST(StaticParsing::find_table(rsdp.value(), "FACP"sv));
|
2021-09-10 10:45:12 -03:00
|
|
|
if (!facp.has_value())
|
|
|
|
|
return;
|
2022-01-13 13:20:22 -03:00
|
|
|
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;
|
2021-09-10 10:45:12 -03:00
|
|
|
|
|
|
|
|
Parser::must_initialize(rsdp.value(), facp.value(), irq_line);
|
|
|
|
|
if (kernel_command_line().acpi_feature_level() == AcpiFeatureLevel::Enabled)
|
|
|
|
|
Parser::the()->enable_aml_parsing();
|
2020-04-09 09:31:47 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_enabled()
|
|
|
|
|
{
|
|
|
|
|
return Parser::the();
|
2020-04-09 08:39:10 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|