aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/kapi/devices.cpp
blob: 62754f0838d63cbabee2347f1e783f712419afc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#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();
  }

  auto init_platform_devices() -> void
  {
    arch::devices::init_acpi_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!");
    }

    kapi::devices::get_root_bus()->add_child(cpu_bus);

    cpu_bus = kstd::make_shared<arch::bus::cpu>();
    cpu_bus->facet<kapi::devices::bus_protocol>()->enumerate(*cpu_bus);
  }

}  // namespace kapi::devices