aboutsummaryrefslogtreecommitdiff
path: root/kernel/devices/src/storage/StorageManagement.cpp
blob: 2daae0a738bb8f1ab36bf254dbb1aeedc393ab54 (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
#include "devices/storage/StorageManagement.hpp"

#include "kapi/boot_modules.hpp"
#include "kapi/system.hpp"

#include "devices/BlockDevice.hpp"
#include "devices/storage/RAMDisk/RAMDiskController.hpp"
#include "devices/storage/StorageController.hpp"

#include <algorithm>
#include <optional>

namespace devices::storage
{
  namespace
  {
    constinit auto static active_storage_management = std::optional<storage_management>{};
    constinit auto static active_ram_disk_controller = std::optional<ram_disk::ram_disk_controller>{};
  }  // namespace

  auto storage_management::init() -> void
  {
    if (active_storage_management)
    {
      kapi::system::panic("[DEVICES] Storage management has already been initialized.");
    }
    active_storage_management.emplace(storage_management{});

    active_ram_disk_controller.emplace(&kapi::boot_modules::get_boot_module_registry());
    active_storage_management->add_controller(&active_ram_disk_controller.value());

    std::ranges::for_each(active_storage_management->m_controllers, [](auto controller) { controller->probe(); });
  }

  auto storage_management::get() -> storage_management &
  {
    if (!active_storage_management)
    {
      kapi::system::panic("[DEVICES] Storage management has not been initialized.");
    }

    return *active_storage_management;
  }

  auto storage_management::add_controller(storage_controller * controller) -> void
  {
    m_controllers.at(0) = controller;  // TODO BA-FS26 use push_back from kstd:vector
  }

  auto storage_management::add_device(block_device * device) -> void
  {
    m_devices.at(0) = device;  // TODO BA-FS26 use push_back from kstd:vector
  }

}  // namespace devices::storage