aboutsummaryrefslogtreecommitdiff
path: root/kernel/kapi
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/kapi')
-rw-r--r--kernel/kapi/devices.cpp16
-rw-r--r--kernel/kapi/devices/bus.cpp14
-rw-r--r--kernel/kapi/devices/cpu.cpp11
-rw-r--r--kernel/kapi/devices/device.cpp18
-rw-r--r--kernel/kapi/devices/interface_registry.tests.cpp2
5 files changed, 21 insertions, 40 deletions
diff --git a/kernel/kapi/devices.cpp b/kernel/kapi/devices.cpp
index ef72c667..ae2d4d7a 100644
--- a/kernel/kapi/devices.cpp
+++ b/kernel/kapi/devices.cpp
@@ -8,6 +8,7 @@
#include <kstd/flat_map.hpp>
#include <kstd/memory.hpp>
#include <kstd/print.hpp>
+#include <kstd/string.hpp>
#include <atomic>
#include <cstddef>
@@ -21,7 +22,7 @@ namespace kapi::devices
{
auto constinit next_major_number = std::atomic_size_t{1};
auto constinit root_bus = std::optional<kernel::devices::root_bus>{};
- auto constinit device_tree = kstd::flat_map<std::pair<std::size_t, std::size_t>, kstd::observer_ptr<device>>{};
+ auto constinit device_tree = kstd::flat_map<kstd::string, kstd::observer_ptr<device>>{};
} // namespace
auto init() -> void
@@ -54,8 +55,8 @@ namespace kapi::devices
auto register_device(device & device) -> bool
{
- kstd::println("[OS:DEV] Registering device {}@{}:{}", device.name(), device.major(), device.minor());
- return device_tree.emplace(std::pair{device.major(), device.minor()}, &device).second;
+ kstd::println("[OS:DEV] Registering device {}", device.name());
+ return device_tree.emplace(device.name(), &device).second;
}
auto unregister_device(device &) -> bool
@@ -64,15 +65,6 @@ namespace kapi::devices
return false;
}
- auto find_device(std::size_t major, std::size_t minor) -> kstd::observer_ptr<device>
- {
- if (device_tree.contains(std::pair{major, minor}))
- {
- return device_tree.at(std::pair{major, minor});
- }
- return nullptr;
- }
-
auto find_device(std::string_view name) -> kstd::observer_ptr<device>
{
for (auto const & [key, value] : device_tree)
diff --git a/kernel/kapi/devices/bus.cpp b/kernel/kapi/devices/bus.cpp
index 4695ae39..d9f3f991 100644
--- a/kernel/kapi/devices/bus.cpp
+++ b/kernel/kapi/devices/bus.cpp
@@ -9,26 +9,25 @@
#include <kstd/vector.hpp>
#include <algorithm>
-#include <cstddef>
#include <utility>
namespace kapi::devices
{
- bus::bus(std::size_t major, std::size_t minor, kstd::string const & name)
- : device(major, minor, name)
+ bus::bus(kstd::string const & name)
+ : device{name}
{}
auto bus::init() -> bool
{
if (m_init_was_called.test_and_set())
{
- kstd::println(kstd::print_sink::stderr, "[OS:DEV] Bus {}:{}:{} already initialized", name(), major(), minor());
+ kstd::println(kstd::print_sink::stderr, "[OS:DEV] Bus {} already initialized", name());
return true;
}
if (!enumerate())
{
- kstd::println(kstd::print_sink::stderr, "[OS:DEV] Bus {}:{}:{} enumeration failed", name(), major(), minor());
+ kstd::println(kstd::print_sink::stderr, "[OS:DEV] Bus {} enumeration failed", name());
return false;
}
@@ -47,7 +46,10 @@ namespace kapi::devices
auto observer = m_observers.emplace_back(child.get());
child->set_parent(kstd::make_observer(this));
m_devices.push_back(std::move(child));
- kapi::devices::register_device(*observer);
+ if (!kapi::devices::register_device(*observer))
+ {
+ kapi::system::panic("[OS:DEV] Failed to register child device");
+ }
if (m_initialized.test())
{
diff --git a/kernel/kapi/devices/cpu.cpp b/kernel/kapi/devices/cpu.cpp
index 457b9d56..daba34a8 100644
--- a/kernel/kapi/devices/cpu.cpp
+++ b/kernel/kapi/devices/cpu.cpp
@@ -2,14 +2,15 @@
#include <kapi/devices.hpp>
-#include <cstddef>
+#include <kstd/format.hpp>
+
#include <cstdint>
namespace kapi::devices
{
- cpu::core::core(std::size_t major, std::size_t minor, std::uint64_t index, std::uint64_t hardware_id, bool is_bsp)
- : kapi::devices::bus{major, minor, "cpu_core"}
+ cpu::core::core(std::uint64_t index, std::uint64_t hardware_id, bool is_bsp)
+ : kapi::devices::bus{kstd::format("cpu_core{}", index)}
, m_index{index}
, m_hardware_id{hardware_id}
, m_is_bsp{is_bsp}
@@ -30,8 +31,8 @@ namespace kapi::devices
return m_is_bsp;
}
- cpu::cpu(std::size_t major, std::size_t minor)
- : kapi::devices::bus{major, minor, "cpu"}
+ cpu::cpu()
+ : kapi::devices::bus{"cpu"}
{}
} // namespace kapi::devices \ No newline at end of file
diff --git a/kernel/kapi/devices/device.cpp b/kernel/kapi/devices/device.cpp
index 6ac92e79..0d00d8fd 100644
--- a/kernel/kapi/devices/device.cpp
+++ b/kernel/kapi/devices/device.cpp
@@ -6,26 +6,12 @@
#include <kstd/memory.hpp>
#include <kstd/string.hpp>
-#include <cstddef>
-
namespace kapi::devices
{
- device::device(size_t major, size_t minor, kstd::string const & name)
- : m_major(major)
- , m_minor(minor)
- , m_name(name)
+ device::device(kstd::string const & name)
+ : m_name(name)
{}
- [[nodiscard]] auto device::major() const -> size_t
- {
- return m_major;
- }
-
- [[nodiscard]] auto device::minor() const -> size_t
- {
- return m_minor;
- }
-
[[nodiscard]] auto device::name() const -> kstd::string const &
{
return m_name;
diff --git a/kernel/kapi/devices/interface_registry.tests.cpp b/kernel/kapi/devices/interface_registry.tests.cpp
index ffd9f0d6..aea7776c 100644
--- a/kernel/kapi/devices/interface_registry.tests.cpp
+++ b/kernel/kapi/devices/interface_registry.tests.cpp
@@ -30,7 +30,7 @@ namespace
struct test_device final : kapi::devices::device, probe_device
{
explicit test_device(int value, const_device & const_device)
- : device{0, 0, "probeable"}
+ : device{"probeable"}
, m_value{value}
, m_const_device{&const_device}
{}