Преглед изворни кода

Kernel: Scan ACPI memory ranges for the RSDP table

On some systems the ACPI RSDP table may be located in ACPI reserved
memory ranges rather than in the EBDA or BIOS areas.
Tom пре 3 година
родитељ
комит
10efbfb09e
3 измењених фајлова са 35 додато и 1 уклоњено
  1. 22 1
      Kernel/Firmware/ACPI/Parser.cpp
  2. 11 0
      Kernel/Memory/MemoryManager.cpp
  3. 2 0
      Kernel/Memory/MemoryManager.h

+ 22 - 1
Kernel/Firmware/ACPI/Parser.cpp

@@ -388,7 +388,28 @@ UNMAP_AFTER_INIT Optional<PhysicalAddress> StaticParsing::find_rsdp()
     auto rsdp = map_ebda().find_chunk_starting_with(signature, 16);
     if (rsdp.has_value())
         return rsdp;
-    return map_bios().find_chunk_starting_with(signature, 16);
+    rsdp = map_bios().find_chunk_starting_with(signature, 16);
+    if (rsdp.has_value())
+        return rsdp;
+
+    // On some systems the RSDP may be located in ACPI NVS or reclaimable memory regions
+    MM.for_each_physical_memory_range([&](auto& memory_range) {
+        if (!(memory_range.type == Memory::PhysicalMemoryRangeType::ACPI_NVS || memory_range.type == Memory::PhysicalMemoryRangeType::ACPI_Reclaimable))
+            return IterationDecision::Continue;
+
+        Memory::MappedROM mapping;
+        mapping.region = MM.allocate_kernel_region(memory_range.start, Memory::page_round_up(memory_range.length).release_value_but_fixme_should_propagate_errors(), {}, Memory::Region::Access::Read).release_value();
+        mapping.offset = memory_range.start.offset_in_page();
+        mapping.size = memory_range.length;
+        mapping.paddr = memory_range.start;
+
+        rsdp = mapping.find_chunk_starting_with(signature, 16);
+        if (rsdp.has_value())
+            return IterationDecision::Break;
+
+        return IterationDecision::Continue;
+    });
+    return rsdp;
 }
 
 UNMAP_AFTER_INIT Optional<PhysicalAddress> StaticParsing::find_table(PhysicalAddress rsdp_address, StringView signature)

+ 11 - 0
Kernel/Memory/MemoryManager.cpp

@@ -174,6 +174,17 @@ UNMAP_AFTER_INIT void MemoryManager::protect_ksyms_after_init()
     dmesgln("Write-protected kernel symbols after init.");
 }
 
+IterationDecision MemoryManager::for_each_physical_memory_range(Function<IterationDecision(PhysicalMemoryRange const&)> callback)
+{
+    VERIFY(!m_physical_memory_ranges.is_empty());
+    for (auto& current_range : m_physical_memory_ranges) {
+        IterationDecision decision = callback(current_range);
+        if (decision != IterationDecision::Continue)
+            return decision;
+    }
+    return IterationDecision::Continue;
+}
+
 UNMAP_AFTER_INIT void MemoryManager::register_reserved_ranges()
 {
     VERIFY(!m_physical_memory_ranges.is_empty());

+ 2 - 0
Kernel/Memory/MemoryManager.h

@@ -237,6 +237,8 @@ public:
 
     void copy_physical_page(PhysicalPage&, u8 page_buffer[PAGE_SIZE]);
 
+    IterationDecision for_each_physical_memory_range(Function<IterationDecision(PhysicalMemoryRange const&)>);
+
 private:
     MemoryManager();
     ~MemoryManager();