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, all rights reserved.
4
5------------------------------------------- */
6#pragma once
7
8#include <NeKit/Defines.h>
9
10namespace Kernel::PCI {
11enum class PciConfigKind : UShort {
13 ConfigData = 0xCFC,
14 CommandReg = 0x0004,
15 Invalid = 0xFFFF,
16};
17
19class Device final {
20 public:
21 Device() = default;
22
23 public:
24 Device(UShort bus, UShort device, UShort function, UInt32 bar);
25
26 Device& operator=(const Device&) = default;
27 Device(const Device&) = default;
28
30
31 public:
32 UInt Read(UInt bar, Size szData);
33 void Write(UInt bar, UIntPtr data, Size szData);
34
35 public:
36 operator bool();
37
38 public:
39 template <typename T>
40 UInt Read(UInt bar) {
41 static_assert(sizeof(T) <= sizeof(UInt32), "64-bit PCI addressing is unsupported");
42 return Read(bar, sizeof(T));
43 }
44
45 template <typename T>
46 void Write(UInt bar, UIntPtr data) {
47 static_assert(sizeof(T) <= sizeof(UInt32), "64-bit PCI addressing is unsupported");
48 Write(bar, data, sizeof(T));
49 }
50
51 public:
55 UChar Class();
57 UChar ProgIf();
59 UIntPtr Bar(UInt32 bar_in);
60
61 public:
62 void EnableMmio();
63 void BecomeBusMaster(); // for PCI-DMA, PC-DMA does not need that.
64
65 UShort Vendor();
66
67 private:
72};
73} // namespace Kernel::PCI
UShort InterfaceId()
Definition Device.cc:88
UShort fFunction
Definition Device.h:70
UChar ProgIf()
Definition Device.cc:100
UChar HeaderType()
Definition Device.cc:104
UShort VendorId()
Definition Device.cc:84
Device(const Device &)=default
UShort DeviceId()
Definition Device.cc:80
UChar Class()
Definition Device.cc:92
UShort Vendor()
Definition Device.cc:134
Device & operator=(const Device &)=default
void BecomeBusMaster()
Definition Device.cc:115
void EnableMmio()
Definition Device.cc:108
UInt32 fBar
Definition Device.h:71
UInt Read(UInt bar, Size szData)
Definition Device.cc:44
UChar Subclass()
Definition Device.cc:96
void Write(UInt bar, UIntPtr data, Size szData)
Definition Device.cc:58
UInt Read(UInt bar)
Definition Device.h:40
UShort fDevice
Definition Device.h:69
UShort fBus
Definition Device.h:68
UIntPtr Bar(UInt32 bar_in)
Definition Device.cc:121
void Write(UInt bar, UIntPtr data)
Definition Device.h:46
Definition Device.cc:38
PciConfigKind
Definition Device.h:11
@ CommandReg
Definition Device.h:14
@ Invalid
Definition Device.h:15
@ ConfigAddress
Definition Device.h:12
@ ConfigData
Definition Device.h:13
__SIZE_TYPE__ Size
Definition Defines.h:57
unsigned int UInt32
Definition Defines.h:44
unsigned char UChar
Definition Defines.h:52
unsigned short UShort
Definition Defines.h:39
__UINTPTR_TYPE__ UIntPtr
Definition Defines.h:60
unsigned int UInt
Definition Defines.h:43