aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/kapi
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-07-28 13:09:08 +0200
committerFelix Morgner <felix.morgner@ost.ch>2026-07-28 13:09:08 +0200
commit36248bb63a396dfea762d5b2cf028bf4b7a2b62e (patch)
treeb05726555a387b719292a4d19c4c4a5cbc7e31cc /arch/x86_64/kapi
parentb5450cecbffdca1dd9dffdb58dd295a6a5d7f6eb (diff)
downloadkernel-36248bb63a396dfea762d5b2cf028bf4b7a2b62e.tar.xz
kernel-36248bb63a396dfea762d5b2cf028bf4b7a2b62e.zip
x86_64: split lapic according to UDM
Diffstat (limited to 'arch/x86_64/kapi')
-rw-r--r--arch/x86_64/kapi/cpu.cpp54
-rw-r--r--arch/x86_64/kapi/devices.cpp31
2 files changed, 31 insertions, 54 deletions
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 <kapi/cpu.hpp>
#include <arch/cpu/initialization.hpp>
-#include <arch/devices/local_apic.hpp>
-#include <kapi/acpi.hpp>
-#include <kapi/devices.hpp>
-#include <kapi/devices/cpu.hpp>
-#include <kapi/memory.hpp>
#include <kapi/system.hpp>
-#include <acpi/acpi.hpp>
-
-#include <kstd/memory.hpp>
-#include <kstd/print.hpp>
-
#include <atomic>
-#include <ranges>
-#include <utility>
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<bool>(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<devices::cpu>();
-
- for (auto const & apic : lapic_entries)
- {
- auto is_bsp = !bsp_found;
- bsp_found = true;
- auto core = kstd::make_shared<devices::cpu::core>(core_index, apic.processor_id(), is_bsp);
- core->add_child(kstd::make_shared<arch::devices::local_apic>(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 <kapi/devices.hpp>
+#include <arch/bus/cpu.hpp>
#include <arch/devices/init.hpp>
#include <arch/drivers/init.hpp>
+#include <kapi/system.hpp>
+
+#include <kstd/memory.hpp>
+
namespace kapi::devices
{
+ namespace
+ {
+ auto static constinit cpu_bus = kstd::shared_ptr<arch::bus::cpu>{};
+ }
+
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<bus>
+ {
+ 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<arch::bus::cpu>();
+ cpu_bus->facet<kapi::devices::bus_protocol>()->enumerate(*cpu_bus);
+ }
+
} // namespace kapi::devices \ No newline at end of file