summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/KernelKit/PCI/Device.h
diff options
context:
space:
mode:
authorAmlal <amlal@nekernel.org>2025-04-25 13:08:33 +0200
committerAmlal <amlal@nekernel.org>2025-04-25 13:08:33 +0200
commitfb790b07aeba8e22e4190cf3e1834d11ecde6c96 (patch)
tree4cec7d1b321307b1d5935577631dae116a658a37 /dev/kernel/KernelKit/PCI/Device.h
parent63a2d92c5dfe976175cda024ec01905d11b43738 (diff)
dev: better .clang-format, ran format command.
Signed-off-by: Amlal <amlal@nekernel.org>
Diffstat (limited to 'dev/kernel/KernelKit/PCI/Device.h')
-rw-r--r--dev/kernel/KernelKit/PCI/Device.h135
1 files changed, 65 insertions, 70 deletions
diff --git a/dev/kernel/KernelKit/PCI/Device.h b/dev/kernel/KernelKit/PCI/Device.h
index 0c434b0b..d9bb4e70 100644
--- a/dev/kernel/KernelKit/PCI/Device.h
+++ b/dev/kernel/KernelKit/PCI/Device.h
@@ -1,78 +1,73 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
#pragma once
#include <NewKit/Defines.h>
-namespace Kernel::PCI
-{
- enum class PciConfigKind : UShort
- {
- ConfigAddress = 0xCF8,
- ConfigData = 0xCFC,
- CommandReg = 0x0004,
- Invalid = 0xFFFF,
- };
-
- /// @brief Device interface class
- class Device final
- {
- public:
- Device() = default;
-
- public:
- Device(UShort bus, UShort device, UShort function, UInt32 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) <= sizeof(UInt32), "64-bit PCI addressing is unsupported");
- return Read(bar, sizeof(T));
- }
-
- template <typename T>
- void Write(UInt bar, UIntPtr data)
- {
- static_assert(sizeof(T) <= sizeof(UInt32), "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();
- UIntPtr Bar(UInt32 bar_in);
-
- public:
- void EnableMmio();
- void BecomeBusMaster(); // for PCI-DMA, PC-DMA does not need that.
-
- UShort Vendor();
-
- private:
- UShort fBus;
- UShort fDevice;
- UShort fFunction;
- UInt32 fBar;
- };
-} // namespace Kernel::PCI
+namespace Kernel::PCI {
+enum class PciConfigKind : UShort {
+ ConfigAddress = 0xCF8,
+ ConfigData = 0xCFC,
+ CommandReg = 0x0004,
+ Invalid = 0xFFFF,
+};
+
+/// @brief Device interface class
+class Device final {
+ public:
+ Device() = default;
+
+ public:
+ Device(UShort bus, UShort device, UShort function, UInt32 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) <= sizeof(UInt32), "64-bit PCI addressing is unsupported");
+ return Read(bar, sizeof(T));
+ }
+
+ template <typename T>
+ void Write(UInt bar, UIntPtr data) {
+ static_assert(sizeof(T) <= sizeof(UInt32), "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();
+ UIntPtr Bar(UInt32 bar_in);
+
+ public:
+ void EnableMmio();
+ void BecomeBusMaster(); // for PCI-DMA, PC-DMA does not need that.
+
+ UShort Vendor();
+
+ private:
+ UShort fBus;
+ UShort fDevice;
+ UShort fFunction;
+ UInt32 fBar;
+};
+} // namespace Kernel::PCI