aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/bus/isa.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64/src/bus/isa.cpp')
-rw-r--r--arch/x86_64/src/bus/isa.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/arch/x86_64/src/bus/isa.cpp b/arch/x86_64/src/bus/isa.cpp
new file mode 100644
index 0000000..3fe4f6f
--- /dev/null
+++ b/arch/x86_64/src/bus/isa.cpp
@@ -0,0 +1,56 @@
+#include "arch/bus/isa.hpp"
+
+#include "kapi/devices.hpp"
+#include "kapi/devices/device.hpp"
+#include "kapi/system.hpp"
+
+#include <kstd/memory>
+#include <kstd/print>
+#include <kstd/vector>
+
+#include <algorithm>
+#include <utility>
+
+namespace arch::bus
+{
+
+ isa::isa()
+ : kapi::devices::bus(kapi::devices::allocate_major_number(), 0, "isa")
+ {}
+
+ auto isa::add_child(kstd::unique_ptr<device> child) -> void
+ {
+ auto observer = m_observers.emplace_back(child.get());
+ m_devices.push_back(std::move(child));
+
+ if (m_initialized)
+ {
+ kstd::println("[bus:{}} Initializing child device '{}'", name(), observer->name());
+ if (!observer->init())
+ {
+ kapi::system::panic("[x86_64:devices] Failed to initialize child device");
+ }
+ }
+ }
+
+ auto isa::children() const -> kstd::vector<kstd::observer_ptr<device>> const &
+ {
+ return m_observers;
+ }
+
+ auto isa::init() -> bool
+ {
+ if (m_initialized)
+ {
+ kapi::system::panic("[x86_64:devices] ISA bus already initialized!");
+ }
+
+ m_initialized = std::ranges::fold_left(m_devices, true, [](bool acc, auto & child) -> bool {
+ kstd::println("[x86_64:devices] Initializing child device '{}'", child->name());
+ return acc && child->init();
+ });
+
+ return m_initialized;
+ }
+
+} // namespace arch::bus \ No newline at end of file