1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-22 13:45:08 +00:00

Kernel/ACPI: Return Optional container after table search

This is a better pattern than returning a PhysicalAddress with a zero
value, so the code is more understandable now.
This commit is contained in:
Liav A 2021-09-07 07:29:11 +03:00 committed by Andreas Kling
parent 43b17f27a3
commit bde3c7301e
7 changed files with 26 additions and 25 deletions

View file

@ -103,8 +103,8 @@ void Parser::set_the(Parser& parser)
}
static bool match_table_signature(PhysicalAddress table_header, const StringView& signature);
static PhysicalAddress search_table_in_xsdt(PhysicalAddress xsdt, const StringView& signature);
static PhysicalAddress search_table_in_rsdt(PhysicalAddress rsdt, const StringView& signature);
static Optional<PhysicalAddress> search_table_in_xsdt(PhysicalAddress xsdt, const StringView& signature);
static Optional<PhysicalAddress> search_table_in_rsdt(PhysicalAddress rsdt, const StringView& signature);
static bool validate_table(const Structures::SDTHeader&, size_t length);
UNMAP_AFTER_INIT void Parser::locate_static_data()
@ -115,7 +115,7 @@ UNMAP_AFTER_INIT void Parser::locate_static_data()
init_facs();
}
UNMAP_AFTER_INIT PhysicalAddress Parser::find_table(const StringView& signature)
UNMAP_AFTER_INIT Optional<PhysicalAddress> Parser::find_table(const StringView& signature)
{
dbgln_if(ACPI_DEBUG, "ACPI: Calling Find Table method!");
for (auto p_sdt : m_sdt_pointers) {
@ -131,7 +131,8 @@ UNMAP_AFTER_INIT PhysicalAddress Parser::find_table(const StringView& signature)
UNMAP_AFTER_INIT void Parser::init_facs()
{
m_facs = find_table("FACS");
if (auto facs = find_table("FACS"); facs.has_value())
m_facs = facs.value();
}
UNMAP_AFTER_INIT void Parser::init_fadt()
@ -139,9 +140,7 @@ UNMAP_AFTER_INIT void Parser::init_fadt()
dmesgln("ACPI: Initializing Fixed ACPI data");
dmesgln("ACPI: Searching for the Fixed ACPI Data Table");
m_fadt = find_table("FACP");
VERIFY(!m_fadt.is_null());
m_fadt = find_table("FACP").value();
auto sdt = Memory::map_typed<const volatile Structures::FADT>(m_fadt);
dbgln_if(ACPI_DEBUG, "ACPI: FADT @ V{}, {}", &sdt, m_fadt);
@ -379,7 +378,7 @@ UNMAP_AFTER_INIT Optional<PhysicalAddress> StaticParsing::find_rsdp()
return map_bios().find_chunk_starting_with(signature, 16);
}
UNMAP_AFTER_INIT PhysicalAddress StaticParsing::find_table(PhysicalAddress rsdp_address, const StringView& signature)
UNMAP_AFTER_INIT Optional<PhysicalAddress> StaticParsing::find_table(PhysicalAddress rsdp_address, const StringView& signature)
{
// FIXME: There's no validation of ACPI tables here. Use the checksum to validate the tables.
VERIFY(signature.length() == 4);
@ -397,7 +396,7 @@ UNMAP_AFTER_INIT PhysicalAddress StaticParsing::find_table(PhysicalAddress rsdp_
VERIFY_NOT_REACHED();
}
UNMAP_AFTER_INIT static PhysicalAddress search_table_in_xsdt(PhysicalAddress xsdt_address, const StringView& signature)
UNMAP_AFTER_INIT static Optional<PhysicalAddress> search_table_in_xsdt(PhysicalAddress xsdt_address, const StringView& signature)
{
// FIXME: There's no validation of ACPI tables here. Use the checksum to validate the tables.
VERIFY(signature.length() == 4);
@ -420,7 +419,7 @@ static bool match_table_signature(PhysicalAddress table_header, const StringView
return !strncmp(table->h.sig, signature.characters_without_null_termination(), 4);
}
UNMAP_AFTER_INIT static PhysicalAddress search_table_in_rsdt(PhysicalAddress rsdt_address, const StringView& signature)
UNMAP_AFTER_INIT static Optional<PhysicalAddress> search_table_in_rsdt(PhysicalAddress rsdt_address, const StringView& signature)
{
// FIXME: There's no validation of ACPI tables here. Use the checksum to validate the tables.
VERIFY(signature.length() == 4);