summaryrefslogtreecommitdiffhomepage
path: root/NewKernel/KernelKit/PCI/Device.hpp
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-05-08 12:32:41 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-05-08 12:32:41 +0200
commit09dd11ddf800898c00ecb04a65fb5cd10fb481fa (patch)
treeeda0b4e23d6a71da7de3a78f0bb76ec3201dd2f9 /NewKernel/KernelKit/PCI/Device.hpp
parentca83108fd138cc0398f900e6a6c0a53ad51aee31 (diff)
MHR-23: :boom: changes, reworked project tree.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'NewKernel/KernelKit/PCI/Device.hpp')
-rw-r--r--NewKernel/KernelKit/PCI/Device.hpp79
1 files changed, 79 insertions, 0 deletions
diff --git a/NewKernel/KernelKit/PCI/Device.hpp b/NewKernel/KernelKit/PCI/Device.hpp
new file mode 100644
index 00000000..e34a12b0
--- /dev/null
+++ b/NewKernel/KernelKit/PCI/Device.hpp
@@ -0,0 +1,79 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+------------------------------------------- */
+#pragma once
+
+#include <NewKit/Defines.hpp>
+
+namespace NewOS::PCI
+{
+ enum class PciConfigKind : UShort
+ {
+ ConfigAddress = 0xCF8,
+ ConfigData = 0xCFC,
+ Invalid = 0xFFF
+ };
+
+ class Device final
+ {
+ public:
+ Device() = default;
+
+ public:
+ explicit Device(UShort bus, UShort device, UShort function, UShort bar);
+
+ Device& operator=(const Device&) = default;
+
+ Device(const Device&) = default;
+
+ ~Device();
+
+ public:
+ UInt Read(UInt bar, Size szData);
+ void Write(UInt bar, UIntPtr data, Size szData);
+
+ public:
+ operator bool();
+
+ public:
+ template <typename T>
+ UInt Read(UInt bar)
+ {
+ static_assert(sizeof(T) <= 4, "64-bit PCI addressing is unsupported");
+ return Read(bar, sizeof(T));
+ }
+
+ template <typename T>
+ void Write(UInt bar, UIntPtr data)
+ {
+ static_assert(sizeof(T) <= 4, "64-bit PCI addressing is unsupported");
+ Write(bar, data, sizeof(T));
+ }
+
+ public:
+ UShort DeviceId();
+ UShort VendorId();
+ UShort InterfaceId();
+ UChar Class();
+ UChar Subclass();
+ UChar ProgIf();
+ UChar HeaderType();
+
+ public:
+ void EnableMmio();
+ void BecomeBusMaster(); // for PCI-DMA, PC-DMA does not need that.
+
+ UShort Vendor();
+
+ private:
+ UShort fBus;
+ UShort fDevice;
+ UShort fFunction;
+ UShort fBar;
+ };
+} // namespace NewOS::PCI
+
+EXTERN_C void NewOSPCISetCfgTarget(NewOS::UInt bar);
+EXTERN_C NewOS::UInt NewOSPCIReadRaw(NewOS::UInt bar);