NeKernel dev
Loading...
Searching...
No Matches
Device.h
Go to the documentation of this file.
1/* ========================================
2
3 Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.
4
5======================================== */
6
7#pragma once
8
9#include <NeKit/Config.h>
10#include <NeKit/KernelPanic.h>
11
12namespace Kernel::PCI {
13enum class PciConfigKind : UShort {
15 ConfigData = 0xCFC,
16 CommandReg = 0x0004,
17 Invalid = 0xFFFF,
18};
19
21class Device final {
22 public:
23 Device() = default;
24
25 public:
26 Device(UShort bus, UShort device, UShort function, UInt32 bar);
27
28 Device& operator=(const Device&) = default;
29 Device(const Device&) = default;
30
32
33 public:
34 UInt Read(UInt bar, Size szData);
35 void Write(UInt bar, UIntPtr data, Size szData);
36
37 public:
38 operator bool();
39
40 public:
41 template <typename T>
42 UInt Read(UInt bar) {
43 STATIC_PASS(sizeof(T) <= sizeof(UInt32), "64-bit PCI addressing is unsupported");
44 return Read(bar, sizeof(T));
45 }
46
47 template <typename T>
48 void Write(UInt bar, UIntPtr data) {
49 STATIC_PASS(sizeof(T) <= sizeof(UInt32), "64-bit PCI addressing is unsupported");
50 Write(bar, data, sizeof(T));
51 }
52
53 public:
57 UChar Class();
59 UChar ProgIf();
61 UIntPtr Bar(UInt32 bar_in);
62
63 public:
64 void EnableMmio();
65 void BecomeBusMaster(); // for PCI-DMA, PC-DMA does not need that.
66
67 UShort Vendor();
68
69 private:
74};
75} // namespace Kernel::PCI
#define STATIC_PASS(EXPR, MSG)
Checks during compile time whether a condition passes.
Definition KernelPanic.h:13
UChar Subclass()
Definition Device.cc:96
UShort fFunction
Definition Device.h:72
UChar HeaderType()
Definition Device.cc:104
UShort DeviceId()
Definition Device.cc:80
Device(const Device &)=default
Device & operator=(const Device &)=default
UShort VendorId()
Definition Device.cc:84
UInt32 fBar
Definition Device.h:73
void BecomeBusMaster()
Definition Device.cc:115
UChar ProgIf()
Definition Device.cc:100
UShort Vendor()
Definition Device.cc:134
void EnableMmio()
Definition Device.cc:108
UInt Read(UInt bar)
Definition Device.h:42
UShort InterfaceId()
Definition Device.cc:88
UShort fDevice
Definition Device.h:71
UInt Read(UInt bar, Size szData)
Definition Device.cc:44
UChar Class()
Definition Device.cc:92
UShort fBus
Definition Device.h:70
UIntPtr Bar(UInt32 bar_in)
Definition Device.cc:121
void Write(UInt bar, UIntPtr data, Size szData)
Definition Device.cc:58
void Write(UInt bar, UIntPtr data)
Definition Device.h:48
Definition Device.cc:38
PciConfigKind
Definition Device.h:13
@ CommandReg
Definition Device.h:16
@ Invalid
Definition Device.h:17
@ ConfigAddress
Definition Device.h:14
@ ConfigData
Definition Device.h:15
__SIZE_TYPE__ Size
Definition Config.h:59
__UINT8_TYPE__ UChar
Definition Config.h:54
__UINT32_TYPE__ UInt32
Definition Config.h:44
__UINT16_TYPE__ UShort
Definition Config.h:39
__UINT32_TYPE__ UInt
Definition Config.h:43
__UINTPTR_TYPE__ UIntPtr
Definition Config.h:62