mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:14:58 +00:00
Kernel: Make map_bios() and map_ebda() fallible using ErrorOr
This commit is contained in:
parent
ae5f5a4d50
commit
e2e5d4da16
4 changed files with 48 additions and 21 deletions
|
@ -384,21 +384,34 @@ static bool validate_table(const Structures::SDTHeader& v_header, size_t length)
|
|||
// https://uefi.org/specs/ACPI/6.4/05_ACPI_Software_Programming_Model/ACPI_Software_Programming_Model.html#finding-the-rsdp-on-ia-pc-systems
|
||||
UNMAP_AFTER_INIT Optional<PhysicalAddress> StaticParsing::find_rsdp()
|
||||
{
|
||||
StringView signature("RSD PTR ");
|
||||
auto rsdp = map_ebda().find_chunk_starting_with(signature, 16);
|
||||
if (rsdp.has_value())
|
||||
return rsdp;
|
||||
rsdp = map_bios().find_chunk_starting_with(signature, 16);
|
||||
if (rsdp.has_value())
|
||||
return rsdp;
|
||||
static constexpr auto signature = "RSD PTR "sv;
|
||||
auto ebda_or_error = map_ebda();
|
||||
if (!ebda_or_error.is_error()) {
|
||||
auto rsdp = ebda_or_error.value().find_chunk_starting_with(signature, 16);
|
||||
if (rsdp.has_value())
|
||||
return rsdp;
|
||||
}
|
||||
auto bios_or_error = map_bios();
|
||||
if (!bios_or_error.is_error()) {
|
||||
auto rsdp = bios_or_error.value().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
|
||||
Optional<PhysicalAddress> rsdp;
|
||||
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();
|
||||
auto region_size_or_error = Memory::page_round_up(memory_range.length);
|
||||
if (region_size_or_error.is_error())
|
||||
return IterationDecision::Continue;
|
||||
auto region_or_error = MM.allocate_kernel_region(memory_range.start, region_size_or_error.value(), {}, Memory::Region::Access::Read);
|
||||
if (region_or_error.is_error())
|
||||
return IterationDecision::Continue;
|
||||
mapping.region = region_or_error.release_value();
|
||||
mapping.offset = memory_range.start.offset_in_page();
|
||||
mapping.size = memory_range.length;
|
||||
mapping.paddr = memory_range.start;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue