Serenity Operating System
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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.

+46 -111
-6
Kernel/ACPI/ACPIDynamicParser.cpp
··· 30 30 namespace Kernel { 31 31 namespace ACPI { 32 32 33 - DynamicParser::DynamicParser() 34 - : IRQHandler(9) 35 - { 36 - klog() << "ACPI: Dynamic Parsing Enabled, Can parse AML"; 37 - } 38 - 39 33 DynamicParser::DynamicParser(PhysicalAddress rsdp) 40 34 : IRQHandler(9) 41 35 , StaticParser(rsdp)
+1 -2
Kernel/ACPI/ACPIDynamicParser.h
··· 51 51 virtual const char* purpose() const override { return "ACPI Parser"; } 52 52 53 53 protected: 54 - DynamicParser(); 55 - explicit DynamicParser(PhysicalAddress); 54 + explicit DynamicParser(PhysicalAddress rsdp); 56 55 57 56 private: 58 57 void build_namespace();
+2 -32
Kernel/ACPI/ACPIParser.cpp
··· 32 32 33 33 static Parser* s_acpi_parser; 34 34 35 - Parser& Parser::the() 35 + Parser* Parser::the() 36 36 { 37 - ASSERT(s_acpi_parser); 38 - return *s_acpi_parser; 37 + return s_acpi_parser; 39 38 } 40 39 41 40 void Parser::set_the(Parser& parser) ··· 44 43 s_acpi_parser = &parser; 45 44 } 46 45 47 - Parser::Parser(bool usable) 48 - { 49 - if (usable) { 50 - klog() << "ACPI: Setting up a functional parser"; 51 - } else { 52 - klog() << "ACPI: Limited Initialization. Vital functions are disabled by a request"; 53 - } 54 - } 55 - 56 - PhysicalAddress Parser::find_table(const char*) 57 - { 58 - klog() << "ACPI: Requested to search for a table, Abort!"; 59 - return {}; 60 - } 61 - 62 - void Parser::try_acpi_reboot() 63 - { 64 - klog() << "ACPI: Cannot invoke reboot!"; 65 - } 66 - 67 - void Parser::try_acpi_shutdown() 68 - { 69 - klog() << "ACPI: Cannot invoke shutdown!"; 70 - } 71 - 72 46 void Parser::enable_aml_interpretation() 73 47 { 74 48 klog() << "ACPI: No AML Interpretation Allowed"; ··· 98 72 { 99 73 klog() << "ACPI Limited: x86 specific features cannot be obtained"; 100 74 ASSERT_NOT_REACHED(); 101 - } 102 - bool Parser::is_operable() 103 - { 104 - return false; 105 75 } 106 76 } 107 77 }
+12 -13
Kernel/ACPI/ACPIParser.h
··· 28 28 29 29 #include <AK/Types.h> 30 30 #include <Kernel/ACPI/Definitions.h> 31 + #include <Kernel/ACPI/Initialize.h> 31 32 #include <Kernel/FileSystem/File.h> 32 33 #include <Kernel/VM/Region.h> 33 34 #include <LibBareMetal/Memory/PhysicalAddress.h> ··· 38 39 39 40 class Parser { 40 41 public: 41 - static Parser& the(); 42 + static Parser* the(); 42 43 43 44 template<typename ParserType> 44 - static void initialize() 45 + static void initialize(PhysicalAddress rsdp) 45 46 { 46 - set_the(*new ParserType); 47 + set_the(*new ParserType(rsdp)); 47 48 } 48 49 49 - virtual PhysicalAddress find_table(const char* sig); 50 + virtual PhysicalAddress find_table(const char* sig) = 0; 50 51 51 - virtual void try_acpi_reboot(); 52 - virtual bool can_reboot() { return false; } 53 - virtual void try_acpi_shutdown(); 54 - virtual bool can_shutdown() { return false; } 52 + virtual void try_acpi_reboot() = 0; 53 + virtual bool can_reboot() = 0; 54 + virtual void try_acpi_shutdown() = 0; 55 + virtual bool can_shutdown() = 0; 55 56 56 - virtual const FADTFlags::HardwareFeatures& hardware_features() const; 57 - virtual const FADTFlags::x86_Specific_Flags& x86_specific_flags() const; 57 + virtual const FADTFlags::HardwareFeatures& hardware_features() const = 0; 58 + virtual const FADTFlags::x86_Specific_Flags& x86_specific_flags() const = 0; 58 59 59 60 virtual void enable_aml_interpretation(); 60 61 virtual void enable_aml_interpretation(File&); 61 62 virtual void enable_aml_interpretation(u8*, u32); 62 63 virtual void disable_aml_interpretation(); 63 - virtual bool is_operable(); 64 64 65 65 protected: 66 - explicit Parser(bool usable = false); 67 - bool m_operable; 66 + Parser() {} 68 67 69 68 private: 70 69 static void set_the(Parser&);
+1 -17
Kernel/ACPI/ACPIStaticParser.cpp
··· 324 324 } 325 325 } 326 326 327 - StaticParser::StaticParser() 328 - : Parser(true) 329 - , m_rsdp(StaticParsing::search_rsdp()) 330 - { 331 - if (!m_rsdp.is_null()) { 332 - klog() << "ACPI: Using RSDP @ " << m_rsdp; 333 - m_operable = true; 334 - locate_static_data(); 335 - } else { 336 - m_operable = false; 337 - klog() << "ACPI: Disabled, due to RSDP being absent"; 338 - } 339 - } 340 - 341 327 StaticParser::StaticParser(PhysicalAddress rsdp) 342 - : Parser(true) 343 - , m_rsdp(rsdp) 328 + : m_rsdp(rsdp) 344 329 { 345 330 klog() << "ACPI: Using RSDP @ " << rsdp; 346 - m_operable = true; 347 331 locate_static_data(); 348 332 } 349 333
+1 -3
Kernel/ACPI/ACPIStaticParser.h
··· 41 41 virtual bool can_reboot() override; 42 42 virtual bool can_shutdown() override { return false; } 43 43 virtual void try_acpi_shutdown() override; 44 - virtual bool is_operable() override { return m_operable; } 45 44 46 45 virtual const FADTFlags::HardwareFeatures& hardware_features() const override; 47 46 virtual const FADTFlags::x86_Specific_Flags& x86_specific_flags() const override; 48 47 49 48 protected: 50 - StaticParser(); 51 - explicit StaticParser(PhysicalAddress); 49 + explicit StaticParser(PhysicalAddress rsdp); 52 50 53 51 private: 54 52 void locate_static_data();
+17 -11
Kernel/ACPI/Initialize.cpp
··· 49 49 50 50 void initialize() 51 51 { 52 - switch (determine_feature_level()) { 53 - case FeatureLevel::Enabled: 54 - Parser::initialize<DynamicParser>(); 55 - break; 56 - case FeatureLevel::Limited: 57 - Parser::initialize<StaticParser>(); 58 - break; 59 - case FeatureLevel::Disabled: 60 - Parser::initialize<Parser>(); 61 - break; 62 - } 52 + auto feature_level = determine_feature_level(); 53 + if (feature_level == FeatureLevel::Disabled) 54 + return; 55 + 56 + auto rsdp = StaticParsing::search_rsdp(); 57 + if (rsdp.is_null()) 58 + return; 59 + 60 + if (feature_level == FeatureLevel::Enabled) 61 + Parser::initialize<DynamicParser>(rsdp); 62 + else 63 + Parser::initialize<StaticParser>(rsdp); 64 + } 65 + 66 + bool is_enabled() 67 + { 68 + return Parser::the(); 63 69 } 64 70 65 71 }
+1
Kernel/ACPI/Initialize.h
··· 29 29 namespace Kernel { 30 30 namespace ACPI { 31 31 32 + bool is_enabled(); 32 33 void initialize(); 33 34 34 35 }
+2 -16
Kernel/PCI/Initializer.cpp
··· 36 36 namespace Kernel { 37 37 namespace PCI { 38 38 39 - static bool test_acpi(); 40 39 static bool test_pci_io(); 41 - static bool test_pci_mmio(); 42 40 43 41 static Access::Type detect_optimal_access_type(bool mmio_allowed) 44 42 { 45 - if (mmio_allowed && test_acpi() && test_pci_mmio()) 43 + if (mmio_allowed && ACPI::is_enabled() && !ACPI::Parser::the()->find_table("MCFG").is_null()) 46 44 return Access::Type::MMIO; 47 45 48 46 if (test_pci_io()) ··· 57 55 bool mmio_allowed = kernel_command_line().lookup("pci_mmio").value_or("off") == "on"; 58 56 59 57 if (detect_optimal_access_type(mmio_allowed) == Access::Type::MMIO) 60 - MMIOAccess::initialize(ACPI::Parser::the().find_table("MCFG")); 58 + MMIOAccess::initialize(ACPI::Parser::the()->find_table("MCFG")); 61 59 else 62 60 IOAccess::initialize(); 63 61 ··· 68 66 }); 69 67 } 70 68 71 - bool test_acpi() 72 - { 73 - if ((kernel_command_line().contains("noacpi")) || !ACPI::Parser::the().is_operable()) 74 - return false; 75 - return true; 76 - } 77 - 78 69 bool test_pci_io() 79 70 { 80 71 klog() << "Testing PCI via manual probing... "; ··· 88 79 89 80 klog() << "PCI IO Not Supported!"; 90 81 return false; 91 - } 92 - 93 - bool test_pci_mmio() 94 - { 95 - return !ACPI::Parser::the().find_table("MCFG").is_null(); 96 82 } 97 83 98 84 }
+2 -1
Kernel/Process.cpp
··· 3993 3993 dbg() << "syncing mounted filesystems..."; 3994 3994 FS::sync(); 3995 3995 dbg() << "attempting reboot via ACPI"; 3996 - ACPI::Parser::the().try_acpi_reboot(); 3996 + if (ACPI::is_enabled()) 3997 + ACPI::Parser::the()->try_acpi_reboot(); 3997 3998 dbg() << "attempting reboot via KB Controller..."; 3998 3999 IO::out8(0x64, 0xFE); 3999 4000
+2 -2
Kernel/Time/HPET.cpp
··· 118 118 { 119 119 ASSERT(!HPET::initialized()); 120 120 hpet_initialized = true; 121 - auto hpet = ACPI::Parser::the().find_table("HPET"); 121 + auto hpet = ACPI::Parser::the()->find_table("HPET"); 122 122 if (hpet.is_null()) 123 123 return false; 124 124 klog() << "HPET @ " << hpet; ··· 141 141 142 142 bool HPET::check_for_exisiting_periodic_timers() 143 143 { 144 - auto hpet = ACPI::Parser::the().find_table("HPET"); 144 + auto hpet = ACPI::Parser::the()->find_table("HPET"); 145 145 if (hpet.is_null()) 146 146 return false; 147 147 auto region = MM.allocate_kernel_region(hpet.page_base(), (PAGE_SIZE * 2), "HPET Initialization", Region::Access::Read);
+5 -5
Kernel/Time/TimeManagement.cpp
··· 92 92 93 93 TimeManagement::TimeManagement(bool probe_non_legacy_hardware_timers) 94 94 { 95 - if (ACPI::Parser::the().is_operable()) { 96 - if (!ACPI::Parser::the().x86_specific_flags().cmos_rtc_not_present) { 95 + if (ACPI::is_enabled()) { 96 + if (!ACPI::Parser::the()->x86_specific_flags().cmos_rtc_not_present) { 97 97 RTC::initialize(); 98 98 m_epoch_time += boot_time(); 99 99 } else { ··· 161 161 162 162 bool TimeManagement::probe_and_set_non_legacy_hardware_timers() 163 163 { 164 - if (!ACPI::Parser::the().is_operable()) 164 + if (!ACPI::is_enabled()) 165 165 return false; 166 166 if (!HPET::test_and_initialize()) 167 167 return false; ··· 211 211 212 212 bool TimeManagement::probe_and_set_legacy_hardware_timers() 213 213 { 214 - if (ACPI::Parser::the().is_operable()) { 215 - if (ACPI::Parser::the().x86_specific_flags().cmos_rtc_not_present) { 214 + if (ACPI::is_enabled()) { 215 + if (ACPI::Parser::the()->x86_specific_flags().cmos_rtc_not_present) { 216 216 dbg() << "ACPI: CMOS RTC Not Present"; 217 217 return false; 218 218 } else {
-3
Kernel/init.cpp
··· 167 167 SyncTask::spawn(); 168 168 FinalizerTask::spawn(); 169 169 170 - // Sample test to see if the ACPI parser is working... 171 - klog() << "ACPI: HPET table @ " << ACPI::Parser::the().find_table("HPET"); 172 - 173 170 PCI::initialize(); 174 171 175 172 if (kernel_command_line().contains("text_debug")) {