summaryrefslogtreecommitdiffhomepage
path: root/src/kernel/KernelKit/PCI/IO.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/KernelKit/PCI/IO.h')
-rw-r--r--src/kernel/KernelKit/PCI/IO.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/kernel/KernelKit/PCI/IO.h b/src/kernel/KernelKit/PCI/IO.h
new file mode 100644
index 00000000..2ab72269
--- /dev/null
+++ b/src/kernel/KernelKit/PCI/IO.h
@@ -0,0 +1,63 @@
+/* ========================================
+
+ Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.
+
+======================================== */
+
+#pragma once
+
+#include <ArchKit/ArchKit.h>
+#include <NeKit/Array.h>
+#include <NeKit/Defines.h>
+#include <NeKit/Ref.h>
+
+namespace Kernel {
+template <SizeT Sz>
+class IOArray final {
+ public:
+ IOArray() = delete;
+
+ IOArray(nullPtr) = delete;
+
+ explicit IOArray(Array<UShort, Sz>& ports) : fPorts(ports) {}
+
+ ~IOArray() {}
+
+ IOArray& operator=(const IOArray&) = default;
+
+ IOArray(const IOArray&) = default;
+
+ operator bool() { return !fPorts.Empty(); }
+
+ public:
+ template <typename T>
+ T In(SizeT index);
+
+ template <typename T>
+ void Out(SizeT index, T value);
+
+ private:
+ Array<UShort, Sz> fPorts;
+};
+
+inline constexpr UInt16 kMaxPorts = 16;
+
+using IOArray16 = IOArray<kMaxPorts>;
+
+template <SizeT Sz>
+inline Array<UShort, Sz> make_ports(UShort base) {
+ Array<UShort, Sz> ports;
+
+ for (UShort i = 0; i < Sz; ++i) {
+ ports[i] = base + i;
+ }
+
+ return ports;
+}
+} // namespace Kernel
+
+#ifdef __NE_AMD64__
+#include <KernelKit/PCI/IOArray+AMD64.inl>
+#else
+#error Please provide platform specific code for the I/O
+#endif // ifdef __NE_AMD64__