diff options
author | Andreas Kling <kling@serenityos.org> | 2020-04-09 14:10:44 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-09 14:10:44 +0200 |
commit | e983c745f72fa855c40c3eb85cfa6853a9f7f3b2 (patch) | |
tree | d3fac9c25987e9bb48adae3d2eee62c5743ef7b2 | |
parent | 85c05578390a8f3c09101a1dae3b57935d0dd018 (diff) | |
download | serenity-e983c745f72fa855c40c3eb85cfa6853a9f7f3b2.zip |
Kernel: Simplify ACPI initialization a bit
Construct the parser, no matter which kind, in ACPI::initialize().
-rw-r--r-- | Kernel/ACPI/ACPIDynamicParser.cpp | 15 | ||||
-rw-r--r-- | Kernel/ACPI/ACPIDynamicParser.h | 11 | ||||
-rw-r--r-- | Kernel/ACPI/ACPIParser.cpp | 16 | ||||
-rw-r--r-- | Kernel/ACPI/ACPIParser.h | 15 | ||||
-rw-r--r-- | Kernel/ACPI/ACPIStaticParser.cpp | 18 | ||||
-rw-r--r-- | Kernel/ACPI/ACPIStaticParser.h | 8 | ||||
-rw-r--r-- | Kernel/ACPI/Initialize.cpp | 6 |
7 files changed, 30 insertions, 59 deletions
diff --git a/Kernel/ACPI/ACPIDynamicParser.cpp b/Kernel/ACPI/ACPIDynamicParser.cpp index 3f70bf6ce6..19658f56bb 100644 --- a/Kernel/ACPI/ACPIDynamicParser.cpp +++ b/Kernel/ACPI/ACPIDynamicParser.cpp @@ -29,26 +29,13 @@ namespace Kernel { namespace ACPI { -void DynamicParser::initialize(PhysicalAddress rsdp) -{ - if (!StaticParser::is_initialized()) { - new DynamicParser(rsdp); - } -} -void DynamicParser::initialize_without_rsdp() -{ - if (!StaticParser::is_initialized()) { - new DynamicParser(); - } -} DynamicParser::DynamicParser() : IRQHandler(9) - , StaticParser() - { klog() << "ACPI: Dynamic Parsing Enabled, Can parse AML"; } + DynamicParser::DynamicParser(PhysicalAddress rsdp) : IRQHandler(9) , StaticParser(rsdp) diff --git a/Kernel/ACPI/ACPIDynamicParser.h b/Kernel/ACPI/ACPIDynamicParser.h index 0918fecfbf..97e35d33b6 100644 --- a/Kernel/ACPI/ACPIDynamicParser.h +++ b/Kernel/ACPI/ACPIDynamicParser.h @@ -35,12 +35,13 @@ namespace Kernel { namespace ACPI { -class DynamicParser final : public IRQHandler - , StaticParser { -public: - static void initialize(PhysicalAddress rsdp); - static void initialize_without_rsdp(); +class DynamicParser final + : public IRQHandler + , public StaticParser { + friend class Parser; + +public: virtual void enable_aml_interpretation() override; virtual void enable_aml_interpretation(File& dsdt_file) override; virtual void enable_aml_interpretation(u8* physical_dsdt, u32 dsdt_payload_legnth) override; diff --git a/Kernel/ACPI/ACPIParser.cpp b/Kernel/ACPI/ACPIParser.cpp index c17a6366b7..f72d49176c 100644 --- a/Kernel/ACPI/ACPIParser.cpp +++ b/Kernel/ACPI/ACPIParser.cpp @@ -29,24 +29,19 @@ namespace Kernel { namespace ACPI { + static Parser* s_acpi_parser; Parser& Parser::the() { - ASSERT(s_acpi_parser != nullptr); + ASSERT(s_acpi_parser); return *s_acpi_parser; } -void Parser::initialize_limited() -{ - if (!Parser::is_initialized()) { - s_acpi_parser = new Parser(false); - } -} - -bool Parser::is_initialized() +void Parser::set_the(Parser& parser) { - return (s_acpi_parser != nullptr); + ASSERT(!s_acpi_parser); + s_acpi_parser = &parser; } Parser::Parser(bool usable) @@ -56,7 +51,6 @@ Parser::Parser(bool usable) } else { klog() << "ACPI: Limited Initialization. Vital functions are disabled by a request"; } - s_acpi_parser = this; } PhysicalAddress Parser::find_table(const char*) diff --git a/Kernel/ACPI/ACPIParser.h b/Kernel/ACPI/ACPIParser.h index 294af5196f..133c29d786 100644 --- a/Kernel/ACPI/ACPIParser.h +++ b/Kernel/ACPI/ACPIParser.h @@ -35,12 +35,17 @@ namespace Kernel { namespace ACPI { + class Parser { public: static Parser& the(); - static bool is_initialized(); - static void initialize_limited(); + template<typename ParserType> + static void initialize() + { + set_the(*new ParserType); + } + virtual PhysicalAddress find_table(const char* sig); virtual void try_acpi_reboot(); @@ -58,8 +63,12 @@ public: virtual bool is_operable(); protected: - explicit Parser(bool usable); + explicit Parser(bool usable = false); bool m_operable; + +private: + static void set_the(Parser&); }; + } } diff --git a/Kernel/ACPI/ACPIStaticParser.cpp b/Kernel/ACPI/ACPIStaticParser.cpp index f8d1f3a907..64828c672e 100644 --- a/Kernel/ACPI/ACPIStaticParser.cpp +++ b/Kernel/ACPI/ACPIStaticParser.cpp @@ -36,24 +36,6 @@ namespace Kernel { namespace ACPI { -void StaticParser::initialize(PhysicalAddress rsdp) -{ - if (!Parser::is_initialized()) { - new StaticParser(rsdp); - } -} -void StaticParser::initialize_without_rsdp() -{ - if (!Parser::is_initialized()) { - new StaticParser(); - } -} - -bool StaticParser::is_initialized() -{ - return Parser::is_initialized(); -} - void StaticParser::locate_static_data() { locate_main_system_description_table(); diff --git a/Kernel/ACPI/ACPIStaticParser.h b/Kernel/ACPI/ACPIStaticParser.h index ba56baa9fe..613ba6a8d6 100644 --- a/Kernel/ACPI/ACPIStaticParser.h +++ b/Kernel/ACPI/ACPIStaticParser.h @@ -32,12 +32,10 @@ namespace Kernel { namespace ACPI { -class StaticParser : Parser { -public: - static void initialize(PhysicalAddress rsdp); - static void initialize_without_rsdp(); - static bool is_initialized(); +class StaticParser : public Parser { + friend class Parser; +public: virtual PhysicalAddress find_table(const char* sig) override; virtual void try_acpi_reboot() override; virtual bool can_reboot() override; diff --git a/Kernel/ACPI/Initialize.cpp b/Kernel/ACPI/Initialize.cpp index 76a93d707e..4b7f68f7ce 100644 --- a/Kernel/ACPI/Initialize.cpp +++ b/Kernel/ACPI/Initialize.cpp @@ -51,13 +51,13 @@ void initialize() { switch (determine_feature_level()) { case FeatureLevel::Enabled: - ACPI::DynamicParser::initialize_without_rsdp(); + Parser::initialize<DynamicParser>(); break; case FeatureLevel::Limited: - ACPI::StaticParser::initialize_without_rsdp(); + Parser::initialize<StaticParser>(); break; case FeatureLevel::Disabled: - ACPI::Parser::initialize_limited(); + Parser::initialize<Parser>(); break; } } |