From 36248bb63a396dfea762d5b2cf028bf4b7a2b62e Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Tue, 28 Jul 2026 13:09:08 +0200 Subject: x86_64: split lapic according to UDM --- arch/x86_64/kapi/cpu.cpp | 54 -------------------------------------------- arch/x86_64/kapi/devices.cpp | 31 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 54 deletions(-) (limited to 'arch/x86_64/kapi') diff --git a/arch/x86_64/kapi/cpu.cpp b/arch/x86_64/kapi/cpu.cpp index 100f53df..2bec841c 100644 --- a/arch/x86_64/kapi/cpu.cpp +++ b/arch/x86_64/kapi/cpu.cpp @@ -1,32 +1,14 @@ #include #include -#include -#include -#include -#include -#include #include -#include - -#include -#include - #include -#include -#include namespace kapi::cpu { - namespace - { - constexpr auto candidate_flags = ::acpi::processor_local_apic_entry::flags::processor_enabled // - | ::acpi::processor_local_apic_entry::flags::online_capable; - } - auto init() -> void { auto static constinit is_initialized = std::atomic_flag{}; @@ -46,42 +28,6 @@ namespace kapi::cpu __builtin_unreachable(); } - auto discover_topology() -> bool - { - auto madt = kapi::acpi::get_table<::acpi::table_signature_v<::acpi::madt>>(); - if (!madt) - { - kstd::println("[x86_64:PLT] Failed to find ACPI APIC table"); - return false; - } - - auto lapic_entries = *madt | std::views::filter([](auto const & entry) { - return entry.type() == ::acpi::madt_entry::type::processor_local_apic; - }) | std::views::transform([](auto const & entry) { - return static_cast<::acpi::processor_local_apic_entry const &>(entry); - }) | std::views::filter([](auto const & entry) { return static_cast(entry.flags() & candidate_flags); }); - - auto bsp_found = false; - auto core_index = 0uz; - auto local_apic_address = memory::physical_address{madt->local_interrupt_controller_address()}; - auto cpu_bus = kstd::make_shared(); - - for (auto const & apic : lapic_entries) - { - auto is_bsp = !bsp_found; - bsp_found = true; - auto core = kstd::make_shared(core_index, apic.processor_id(), is_bsp); - core->add_child(kstd::make_shared(core_index, apic.id(), local_apic_address, is_bsp)); - cpu_bus->add_child(std::move(core)); - ++core_index; - } - - devices::get_root_bus()->add_child(std::move(cpu_bus)); - - kstd::println("[x86_64:PLT] Found {} CPU cores", core_index); - return core_index > 0; - } - auto current_id() -> id { // TODO: implement actual ID reading once APs are being set up. diff --git a/arch/x86_64/kapi/devices.cpp b/arch/x86_64/kapi/devices.cpp index 748e0a6a..04b6fa2d 100644 --- a/arch/x86_64/kapi/devices.cpp +++ b/arch/x86_64/kapi/devices.cpp @@ -1,11 +1,21 @@ #include +#include #include #include +#include + +#include + namespace kapi::devices { + namespace + { + auto static constinit cpu_bus = kstd::shared_ptr{}; + } + auto init_platform_drivers() -> void { arch::drivers::init_legacy_drivers(); @@ -17,4 +27,25 @@ namespace kapi::devices arch::devices::init_legacy_devices(); } + auto get_cpu_bus() -> kstd::shared_ptr + { + if (!cpu_bus) + { + system::panic("[x86_64:DEV] The CPU topology has not yet been initialized!"); + } + + return cpu_bus; + } + + auto discover_cpu_topology() -> void + { + if (cpu_bus) + { + system::panic("[x86_64:DEV] The CPU topology has already been initialized!"); + } + + cpu_bus = kstd::make_shared(); + cpu_bus->facet()->enumerate(*cpu_bus); + } + } // namespace kapi::devices \ No newline at end of file -- cgit v1.2.3