diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-04-10 09:01:59 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-04-10 09:01:59 +0200 |
| commit | 3ad230fab8dc17758559aac3c20ba67a8c619878 (patch) | |
| tree | 8bdac1645e79677acb1e359ddae944dfb9d5a2b2 /arch/x86_64 | |
| parent | 65fe71d4c2cc4fa7b09a83671dccb5d4483f0524 (diff) | |
| download | teachos-3ad230fab8dc17758559aac3c20ba67a8c619878.tar.xz teachos-3ad230fab8dc17758559aac3c20ba67a8c619878.zip | |
kapi: move platform functions to CPU
Diffstat (limited to 'arch/x86_64')
| -rw-r--r-- | arch/x86_64/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | arch/x86_64/kapi/cpu.cpp | 54 | ||||
| -rw-r--r-- | arch/x86_64/kapi/platform.cpp | 62 |
3 files changed, 54 insertions, 63 deletions
diff --git a/arch/x86_64/CMakeLists.txt b/arch/x86_64/CMakeLists.txt index 87cb98c..62a2aad 100644 --- a/arch/x86_64/CMakeLists.txt +++ b/arch/x86_64/CMakeLists.txt @@ -19,7 +19,6 @@ target_sources("x86_64" PRIVATE "kapi/devices.cpp" "kapi/interrupts.cpp" "kapi/memory.cpp" - "kapi/platform.cpp" "kapi/system.cpp" # CPU Initialization diff --git a/arch/x86_64/kapi/cpu.cpp b/arch/x86_64/kapi/cpu.cpp index 12edb0f..1382e08 100644 --- a/arch/x86_64/kapi/cpu.cpp +++ b/arch/x86_64/kapi/cpu.cpp @@ -1,14 +1,28 @@ #include "kapi/cpu.hpp" +#include "kapi/acpi.hpp" +#include "kapi/devices.hpp" #include "kapi/system.hpp" #include "arch/cpu/initialization.hpp" +#include "arch/devices/local_apic.hpp" + +#include <kstd/memory> +#include <kstd/print> #include <atomic> +#include <ranges> +#include <utility> namespace kapi::cpu { + namespace + { + constexpr auto candidate_flags = acpi::processor_local_apic::flags::processor_enabled // + | acpi::processor_local_apic::flags::online_capable; + } + auto init() -> void { auto static constinit is_initialized = std::atomic_flag{}; @@ -28,4 +42,44 @@ namespace kapi::cpu __builtin_unreachable(); } + auto discover_topology(kapi::devices::bus & bus) -> bool + { + auto static const core_major = kapi::devices::allocate_major_number(); + auto static const interrupt_controller_major = kapi::devices::allocate_major_number(); + + auto madt = kapi::acpi::get_table<acpi::madt_table_signature>(); + if (!madt) + { + kstd::println("[x86_64:PLT] Failed to find ACPI APIC table"); + return false; + } + + auto bsp_found = false; + auto core_count = 0uz; + auto local_apic_address = madt->local_interrupt_controller_address(); + + auto lapic_entries = *madt | std::views::filter([](auto const & entry) { + return entry.type() == acpi::multiple_apic_description_table_entry::types::processor_local_apic; + }) | std::views::transform([](auto const & entry) { + return static_cast<acpi::processor_local_apic const &>(entry); + }) | std::views::filter([](auto const & entry) { + return static_cast<bool>(entry.active_flags() & candidate_flags); + }); + + for (auto const & apic : lapic_entries) + { + auto is_bsp = !bsp_found; + bsp_found = true; + auto instance = kstd::make_unique<arch::devices::local_apic>(interrupt_controller_major, core_count, + apic.apic_id(), local_apic_address, is_bsp); + if (core_detected(bus, core_major, core_count, apic.processor_id(), is_bsp, std::move(instance))) + { + ++core_count; + } + } + + kstd::println("[x86_64:PLT] Found {} CPU cores", core_count); + return core_count > 0; + } + } // namespace kapi::cpu diff --git a/arch/x86_64/kapi/platform.cpp b/arch/x86_64/kapi/platform.cpp deleted file mode 100644 index fb27329..0000000 --- a/arch/x86_64/kapi/platform.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include "kapi/platform.hpp" - -#include "kapi/acpi.hpp" -#include "kapi/devices.hpp" - -#include "arch/devices/local_apic.hpp" - -#include <kstd/memory> -#include <kstd/print> - -#include <ranges> -#include <utility> - -namespace kapi::platform -{ - namespace - { - constexpr auto candidate_flags = acpi::processor_local_apic::flags::processor_enabled // - | acpi::processor_local_apic::flags::online_capable; - } - - auto discover_cpu_topology(kapi::devices::bus & bus) -> bool - { - auto static const core_major = kapi::devices::allocate_major_number(); - auto static const interrupt_controller_major = kapi::devices::allocate_major_number(); - - auto madt = kapi::acpi::get_table<acpi::madt_table_signature>(); - if (!madt) - { - kstd::println("[x86_64:PLT] Failed to find ACPI APIC table"); - return false; - } - - auto bsp_found = false; - auto core_count = 0uz; - auto local_apic_address = madt->local_interrupt_controller_address(); - - auto lapic_entries = *madt | std::views::filter([](auto const & entry) { - return entry.type() == acpi::multiple_apic_description_table_entry::types::processor_local_apic; - }) | std::views::transform([](auto const & entry) { - return static_cast<acpi::processor_local_apic const &>(entry); - }) | std::views::filter([](auto const & entry) { - return static_cast<bool>(entry.active_flags() & candidate_flags); - }); - - for (auto const & apic : lapic_entries) - { - auto is_bsp = !bsp_found; - bsp_found = true; - auto instance = kstd::make_unique<arch::devices::local_apic>(interrupt_controller_major, core_count, - apic.apic_id(), local_apic_address, is_bsp); - if (kapi::platform::cpu_detected(bus, core_major, core_count, apic.processor_id(), is_bsp, std::move(instance))) - { - ++core_count; - } - } - - kstd::println("[x86_64:PLT] Found {} CPU cores", core_count); - return core_count > 0; - } - -} // namespace kapi::platform |
