mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 21:07:34 +00:00
Kernel/ACPI: Make most of StaticParsing methods to be platform-agnostic
Most of the ACPI static parsing methods (methods that can be called without initializing a full AML parser) are not tied to any specific platform or CPU architecture. The only method that is platform-specific is the one that finds the RSDP structure. Thus, each CPU architecture/platform needs to implement it. This means that now aarch64 can implement its own method to find the ACPI RSDP structure, which would be hooked into the rest of the ACPI code elegantly, but for now I just added a FIXME and that method returns empty value of Optional<PhysicalAddress>.
This commit is contained in:
parent
be16a91aec
commit
428afca32b
11 changed files with 211 additions and 133 deletions
17
Kernel/Arch/aarch64/Firmware/ACPI/StaticParsing.cpp
Normal file
17
Kernel/Arch/aarch64/Firmware/ACPI/StaticParsing.cpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Liav A. <liavalb@hotmail.co.il>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <Kernel/Firmware/ACPI/StaticParsing.h>
|
||||
|
||||
namespace Kernel::ACPI::StaticParsing {
|
||||
|
||||
ErrorOr<Optional<PhysicalAddress>> find_rsdp_in_platform_specific_memory_locations()
|
||||
{
|
||||
// FIXME: Implement finding RSDP for aarch64.
|
||||
return Optional<PhysicalAddress> {};
|
||||
}
|
||||
|
||||
}
|
57
Kernel/Arch/x86_64/Firmware/ACPI/StaticParsing.cpp
Normal file
57
Kernel/Arch/x86_64/Firmware/ACPI/StaticParsing.cpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Liav A. <liavalb@hotmail.co.il>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <Kernel/Firmware/ACPI/StaticParsing.h>
|
||||
#include <Kernel/Firmware/BIOS.h>
|
||||
#include <Kernel/Memory/MemoryManager.h>
|
||||
|
||||
namespace Kernel::ACPI::StaticParsing {
|
||||
|
||||
// https://uefi.org/specs/ACPI/6.4/05_ACPI_Software_Programming_Model/ACPI_Software_Programming_Model.html#finding-the-rsdp-on-ia-pc-systems
|
||||
ErrorOr<Optional<PhysicalAddress>> find_rsdp_in_platform_specific_memory_locations()
|
||||
{
|
||||
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;
|
||||
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;
|
||||
|
||||
rsdp = mapping.find_chunk_starting_with(signature, 16);
|
||||
if (rsdp.has_value())
|
||||
return IterationDecision::Break;
|
||||
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
return rsdp;
|
||||
}
|
||||
|
||||
}
|
|
@ -12,6 +12,7 @@
|
|||
#include <Kernel/Arch/x86_64/Interrupts/IOAPIC.h>
|
||||
#include <Kernel/Arch/x86_64/Interrupts/PIC.h>
|
||||
#include <Kernel/Boot/CommandLine.h>
|
||||
#include <Kernel/Firmware/ACPI/StaticParsing.h>
|
||||
#include <Kernel/Firmware/MultiProcessor/Parser.h>
|
||||
#include <Kernel/Interrupts/InterruptDisabler.h>
|
||||
#include <Kernel/Interrupts/SharedIRQHandler.h>
|
||||
|
@ -118,20 +119,19 @@ NonnullLockRefPtr<IRQController> InterruptManagement::get_responsible_irq_contro
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT PhysicalAddress InterruptManagement::search_for_madt()
|
||||
UNMAP_AFTER_INIT ErrorOr<Optional<PhysicalAddress>> InterruptManagement::find_madt_physical_address()
|
||||
{
|
||||
dbgln("Early access to ACPI tables for interrupt setup");
|
||||
auto rsdp = ACPI::StaticParsing::find_rsdp();
|
||||
if (!rsdp.has_value())
|
||||
return {};
|
||||
auto apic = ACPI::StaticParsing::find_table(rsdp.value(), "APIC"sv);
|
||||
if (!apic.has_value())
|
||||
return {};
|
||||
return apic.value();
|
||||
auto possible_rsdp_physical_address = TRY(ACPI::StaticParsing::find_rsdp_in_platform_specific_memory_locations());
|
||||
if (!possible_rsdp_physical_address.has_value())
|
||||
return Optional<PhysicalAddress> {};
|
||||
auto possible_apic_physical_address = TRY(ACPI::StaticParsing::find_table(possible_rsdp_physical_address.value(), "APIC"sv));
|
||||
if (!possible_apic_physical_address.has_value())
|
||||
return Optional<PhysicalAddress> {};
|
||||
return possible_apic_physical_address.value();
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT InterruptManagement::InterruptManagement()
|
||||
: m_madt(search_for_madt())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -151,13 +151,15 @@ UNMAP_AFTER_INIT void InterruptManagement::switch_to_ioapic_mode()
|
|||
dmesgln("Interrupts: Switch to IOAPIC mode");
|
||||
InterruptDisabler disabler;
|
||||
|
||||
if (m_madt.is_null()) {
|
||||
m_madt_physical_address = MUST(find_madt_physical_address());
|
||||
|
||||
if (!m_madt_physical_address.has_value()) {
|
||||
dbgln("Interrupts: ACPI MADT is not available, reverting to PIC mode");
|
||||
switch_to_pic_mode();
|
||||
return;
|
||||
}
|
||||
|
||||
dbgln("Interrupts: MADT @ P {}", m_madt.as_ptr());
|
||||
dbgln("Interrupts: MADT @ P {}", m_madt_physical_address.value().as_ptr());
|
||||
locate_apic_data();
|
||||
if (m_interrupt_controllers.size() == 1) {
|
||||
if (get_interrupt_controller(0).type() == IRQControllerType::i8259) {
|
||||
|
@ -187,8 +189,8 @@ UNMAP_AFTER_INIT void InterruptManagement::switch_to_ioapic_mode()
|
|||
|
||||
UNMAP_AFTER_INIT void InterruptManagement::locate_apic_data()
|
||||
{
|
||||
VERIFY(!m_madt.is_null());
|
||||
auto madt = Memory::map_typed<ACPI::Structures::MADT>(m_madt).release_value_but_fixme_should_propagate_errors();
|
||||
VERIFY(m_madt_physical_address.has_value());
|
||||
auto madt = Memory::map_typed<ACPI::Structures::MADT>(m_madt_physical_address.value()).release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
if (madt->flags & PCAT_COMPAT_FLAG)
|
||||
m_interrupt_controllers.append(adopt_lock_ref(*new PIC()));
|
||||
|
|
|
@ -48,8 +48,8 @@ public:
|
|||
static u8 acquire_mapped_interrupt_number(u8 original_irq);
|
||||
static u8 acquire_irq_number(u8 mapped_interrupt_vector);
|
||||
|
||||
virtual void switch_to_pic_mode();
|
||||
virtual void switch_to_ioapic_mode();
|
||||
void switch_to_pic_mode();
|
||||
void switch_to_ioapic_mode();
|
||||
|
||||
NonnullLockRefPtr<IRQController> get_responsible_irq_controller(u8 interrupt_vector);
|
||||
NonnullLockRefPtr<IRQController> get_responsible_irq_controller(IRQControllerType controller_type, u8 interrupt_vector);
|
||||
|
@ -67,12 +67,12 @@ protected:
|
|||
|
||||
private:
|
||||
InterruptManagement();
|
||||
PhysicalAddress search_for_madt();
|
||||
ErrorOr<Optional<PhysicalAddress>> find_madt_physical_address();
|
||||
void locate_apic_data();
|
||||
Vector<NonnullLockRefPtr<IRQController>> m_interrupt_controllers;
|
||||
Vector<ISAInterruptOverrideMetadata> m_isa_interrupt_overrides;
|
||||
Vector<PCIInterruptOverrideMetadata> m_pci_interrupt_overrides;
|
||||
PhysicalAddress m_madt;
|
||||
Optional<PhysicalAddress> m_madt_physical_address;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include <Kernel/Arch/x86_64/Time/APICTimer.h>
|
||||
#include <Kernel/Debug.h>
|
||||
#include <Kernel/Firmware/ACPI/Parser.h>
|
||||
#include <Kernel/Firmware/ACPI/StaticParsing.h>
|
||||
#include <Kernel/Interrupts/SpuriousInterruptHandler.h>
|
||||
#include <Kernel/Library/Panic.h>
|
||||
#include <Kernel/Memory/AnonymousVMObject.h>
|
||||
|
@ -261,19 +262,30 @@ UNMAP_AFTER_INIT bool APIC::init_bsp()
|
|||
m_apic_base = region_or_error.release_value();
|
||||
}
|
||||
|
||||
auto rsdp = ACPI::StaticParsing::find_rsdp();
|
||||
if (!rsdp.has_value()) {
|
||||
auto possible_rsdp_physical_address_or_error = ACPI::StaticParsing::find_rsdp_in_platform_specific_memory_locations();
|
||||
if (possible_rsdp_physical_address_or_error.is_error()) {
|
||||
dbgln("APIC: Failed to map RSDP");
|
||||
return false;
|
||||
}
|
||||
auto possible_rsdp_physical_address = possible_rsdp_physical_address_or_error.release_value();
|
||||
if (!possible_rsdp_physical_address.has_value()) {
|
||||
dbgln("APIC: RSDP not found");
|
||||
return false;
|
||||
}
|
||||
auto madt_address = ACPI::StaticParsing::find_table(rsdp.value(), "APIC"sv);
|
||||
if (!madt_address.has_value()) {
|
||||
|
||||
auto possible_apic_physical_address_or_error = ACPI::StaticParsing::find_table(possible_rsdp_physical_address.value(), "APIC"sv);
|
||||
if (possible_apic_physical_address_or_error.is_error()) {
|
||||
dbgln("APIC: Failed to map RSDT/XSDT");
|
||||
return false;
|
||||
}
|
||||
auto possible_apic_physical_address = possible_apic_physical_address_or_error.release_value();
|
||||
if (!possible_apic_physical_address.has_value()) {
|
||||
dbgln("APIC: MADT table not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (kernel_command_line().is_smp_enabled()) {
|
||||
auto madt_or_error = Memory::map_typed<ACPI::Structures::MADT>(madt_address.value());
|
||||
auto madt_or_error = Memory::map_typed<ACPI::Structures::MADT>(possible_apic_physical_address.value());
|
||||
if (madt_or_error.is_error()) {
|
||||
dbgln("APIC: Failed to map MADT table");
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue