diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-06 09:14:11 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-06 09:14:11 +0100 |
| commit | 5339d016c07bf717ee388f4feb73544087324af0 (patch) | |
| tree | 94be6f67ed626091f24aee24ec3b3be03d01e4e7 /KernelKit/PCI/Device.hpp | |
git: port from mercurial repo.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'KernelKit/PCI/Device.hpp')
| -rw-r--r-- | KernelKit/PCI/Device.hpp | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/KernelKit/PCI/Device.hpp b/KernelKit/PCI/Device.hpp new file mode 100644 index 00000000..9c89e1b5 --- /dev/null +++ b/KernelKit/PCI/Device.hpp @@ -0,0 +1,84 @@ +/* + * ======================================================== + * + * hCore + * Copyright XPX Corp, all rights reserved. + * + * ======================================================== + */ +#pragma once + +#include <NewKit/Defines.hpp> + +namespace hCore::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 m_Bus; + UShort m_Device; + UShort m_Function; + UShort m_Bar; + + }; +} // namespace hCore::PCI + + +extern "C" void LumiaPCISetCfgTarget(hCore::UInt bar); +extern "C" hCore::UInt LumiaPCIReadRaw(hCore::UInt bar); |
