summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/KernelKit/PCI/IO.h
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2025-03-23 19:13:48 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2025-03-23 19:15:17 +0100
commita13e1c0911c0627184bc38f18c7fdda64447b3ad (patch)
tree073a62c09bf216e85a3f310376640fa1805147f9 /dev/kernel/KernelKit/PCI/IO.h
parent149fa096eb306d03686b3b67e813cf1a78e08cd0 (diff)
meta(kernel): Reworked repository's filesystem structure.
Removing useless parts of the project too. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/kernel/KernelKit/PCI/IO.h')
-rw-r--r--dev/kernel/KernelKit/PCI/IO.h75
1 files changed, 75 insertions, 0 deletions
diff --git a/dev/kernel/KernelKit/PCI/IO.h b/dev/kernel/KernelKit/PCI/IO.h
new file mode 100644
index 00000000..1d60df8e
--- /dev/null
+++ b/dev/kernel/KernelKit/PCI/IO.h
@@ -0,0 +1,75 @@
+/* -------------------------------------------
+
+ Copyright (C) 2024-2025, Amlal EL Mahrouss, all rights reserved.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <ArchKit/ArchKit.h>
+#include <NewKit/Array.h>
+#include <NewKit/Defines.h>
+#include <NewKit/Ref.h>
+
+namespace NeOS
+{
+ 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 NeOS
+
+#ifdef __x86_64__
+#include <KernelKit/PCI/IOArray+AMD64.inl>
+#else
+#error Please provide platform specific code for the I/O
+#endif // ifdef __x86_64__