1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:37:36 +00:00

Kernel: Remove "non-operational" ACPI parser state

If we don't support ACPI, just don't instantiate an ACPI parser.
This is way less confusing than having a special parser class whose
only purpose is to do nothing.

We now search for the RSDP in ACPI::initialize() instead of letting
the parser constructor do it. This allows us to defer the decision
to create a parser until we're sure we can make a useful one.
This commit is contained in:
Andreas Kling 2020-04-09 14:31:47 +02:00
parent d95362d8cd
commit 4644217094
13 changed files with 46 additions and 111 deletions

View file

@ -30,12 +30,6 @@
namespace Kernel {
namespace ACPI {
DynamicParser::DynamicParser()
: IRQHandler(9)
{
klog() << "ACPI: Dynamic Parsing Enabled, Can parse AML";
}
DynamicParser::DynamicParser(PhysicalAddress rsdp)
: IRQHandler(9)
, StaticParser(rsdp)

View file

@ -51,8 +51,7 @@ public:
virtual const char* purpose() const override { return "ACPI Parser"; }
protected:
DynamicParser();
explicit DynamicParser(PhysicalAddress);
explicit DynamicParser(PhysicalAddress rsdp);
private:
void build_namespace();

View file

@ -32,10 +32,9 @@ namespace ACPI {
static Parser* s_acpi_parser;
Parser& Parser::the()
Parser* Parser::the()
{
ASSERT(s_acpi_parser);
return *s_acpi_parser;
return s_acpi_parser;
}
void Parser::set_the(Parser& parser)
@ -44,31 +43,6 @@ void Parser::set_the(Parser& parser)
s_acpi_parser = &parser;
}
Parser::Parser(bool usable)
{
if (usable) {
klog() << "ACPI: Setting up a functional parser";
} else {
klog() << "ACPI: Limited Initialization. Vital functions are disabled by a request";
}
}
PhysicalAddress Parser::find_table(const char*)
{
klog() << "ACPI: Requested to search for a table, Abort!";
return {};
}
void Parser::try_acpi_reboot()
{
klog() << "ACPI: Cannot invoke reboot!";
}
void Parser::try_acpi_shutdown()
{
klog() << "ACPI: Cannot invoke shutdown!";
}
void Parser::enable_aml_interpretation()
{
klog() << "ACPI: No AML Interpretation Allowed";
@ -99,9 +73,5 @@ const FADTFlags::x86_Specific_Flags& Parser::x86_specific_flags() const
klog() << "ACPI Limited: x86 specific features cannot be obtained";
ASSERT_NOT_REACHED();
}
bool Parser::is_operable()
{
return false;
}
}
}

View file

@ -28,6 +28,7 @@
#include <AK/Types.h>
#include <Kernel/ACPI/Definitions.h>
#include <Kernel/ACPI/Initialize.h>
#include <Kernel/FileSystem/File.h>
#include <Kernel/VM/Region.h>
#include <LibBareMetal/Memory/PhysicalAddress.h>
@ -38,33 +39,31 @@ namespace ACPI {
class Parser {
public:
static Parser& the();
static Parser* the();
template<typename ParserType>
static void initialize()
static void initialize(PhysicalAddress rsdp)
{
set_the(*new ParserType);
set_the(*new ParserType(rsdp));
}
virtual PhysicalAddress find_table(const char* sig);
virtual PhysicalAddress find_table(const char* sig) = 0;
virtual void try_acpi_reboot();
virtual bool can_reboot() { return false; }
virtual void try_acpi_shutdown();
virtual bool can_shutdown() { return false; }
virtual void try_acpi_reboot() = 0;
virtual bool can_reboot() = 0;
virtual void try_acpi_shutdown() = 0;
virtual bool can_shutdown() = 0;
virtual const FADTFlags::HardwareFeatures& hardware_features() const;
virtual const FADTFlags::x86_Specific_Flags& x86_specific_flags() const;
virtual const FADTFlags::HardwareFeatures& hardware_features() const = 0;
virtual const FADTFlags::x86_Specific_Flags& x86_specific_flags() const = 0;
virtual void enable_aml_interpretation();
virtual void enable_aml_interpretation(File&);
virtual void enable_aml_interpretation(u8*, u32);
virtual void disable_aml_interpretation();
virtual bool is_operable();
protected:
explicit Parser(bool usable = false);
bool m_operable;
Parser() {}
private:
static void set_the(Parser&);

View file

@ -324,26 +324,10 @@ void StaticParser::locate_main_system_description_table()
}
}
StaticParser::StaticParser()
: Parser(true)
, m_rsdp(StaticParsing::search_rsdp())
{
if (!m_rsdp.is_null()) {
klog() << "ACPI: Using RSDP @ " << m_rsdp;
m_operable = true;
locate_static_data();
} else {
m_operable = false;
klog() << "ACPI: Disabled, due to RSDP being absent";
}
}
StaticParser::StaticParser(PhysicalAddress rsdp)
: Parser(true)
, m_rsdp(rsdp)
: m_rsdp(rsdp)
{
klog() << "ACPI: Using RSDP @ " << rsdp;
m_operable = true;
locate_static_data();
}

View file

@ -41,14 +41,12 @@ public:
virtual bool can_reboot() override;
virtual bool can_shutdown() override { return false; }
virtual void try_acpi_shutdown() override;
virtual bool is_operable() override { return m_operable; }
virtual const FADTFlags::HardwareFeatures& hardware_features() const override;
virtual const FADTFlags::x86_Specific_Flags& x86_specific_flags() const override;
protected:
StaticParser();
explicit StaticParser(PhysicalAddress);
explicit StaticParser(PhysicalAddress rsdp);
private:
void locate_static_data();

View file

@ -49,17 +49,23 @@ static FeatureLevel determine_feature_level()
void initialize()
{
switch (determine_feature_level()) {
case FeatureLevel::Enabled:
Parser::initialize<DynamicParser>();
break;
case FeatureLevel::Limited:
Parser::initialize<StaticParser>();
break;
case FeatureLevel::Disabled:
Parser::initialize<Parser>();
break;
}
auto feature_level = determine_feature_level();
if (feature_level == FeatureLevel::Disabled)
return;
auto rsdp = StaticParsing::search_rsdp();
if (rsdp.is_null())
return;
if (feature_level == FeatureLevel::Enabled)
Parser::initialize<DynamicParser>(rsdp);
else
Parser::initialize<StaticParser>(rsdp);
}
bool is_enabled()
{
return Parser::the();
}
}

View file

@ -29,6 +29,7 @@
namespace Kernel {
namespace ACPI {
bool is_enabled();
void initialize();
}