aboutsummaryrefslogtreecommitdiff
path: root/kernel/kapi/devices.cpp
blob: 2505779ad60fcfa8599b1b449971d868f9847be2 (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
54
55
56
57
#include <kapi/devices.hpp>

#include <kernel/bus/root.hpp>

#include <kapi/system.hpp>
#include <kapi/test_support/devices.hpp>

#include <kstd/flat_map.hpp>
#include <kstd/memory.hpp>
#include <kstd/string.hpp>

#include <string_view>

namespace kapi::devices
{
  namespace
  {
    auto constinit root_bus = kstd::shared_ptr<kernel::bus::root>{};
    auto constinit device_tree = kstd::flat_map<kstd::string, kstd::weak_ptr<device>>{};
  }  // namespace

  auto init() -> void
  {
    if (root_bus)
    {
      kapi::system::panic("[OS:DEV] The device subsystem has already been initialized");
    }

    device_registry::init();
    facet_registry::init();

    root_bus = kstd::make_shared<kernel::bus::root>();
    device_registry::get().add(root_bus);
  }

  auto get_root_bus() -> kstd::shared_ptr<bus>
  {
    if (!root_bus)
    {
      kapi::system::panic("[OS:DEV] Root bus not initialized!");
    }
    return root_bus;
  }

}  // namespace kapi::devices

namespace kapi::test_support::devices
{
  auto deinit() -> void
  {
    deinit_driver_registry();
    deinit_facet_registry();
    deinit_device_registry();

    kapi::devices::root_bus.reset();
  }
}  // namespace kapi::test_support::devices