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
12
namespace
Kernel::PCI
{
13
enum class
PciConfigKind
:
UShort
{
14
ConfigAddress
= 0xCF8,
15
ConfigData
= 0xCFC,
16
CommandReg
= 0x0004,
17
Invalid
= 0xFFFF,
18
};
19
21
class
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
31
~Device
();
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
:
54
UShort
DeviceId
();
55
UShort
VendorId
();
56
UShort
InterfaceId
();
57
UChar
Class
();
58
UChar
Subclass
();
59
UChar
ProgIf
();
60
UChar
HeaderType
();
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
:
70
UShort
fBus
;
71
UShort
fDevice
;
72
UShort
fFunction
;
73
UInt32
fBar
;
74
};
75
}
// namespace Kernel::PCI
KernelPanic.h
STATIC_PASS
#define STATIC_PASS(EXPR, MSG)
Checks during compile time whether a condition passes.
Definition
KernelPanic.h:13
Kernel::PCI::Device::Subclass
UChar Subclass()
Definition
Device.cc:96
Kernel::PCI::Device::fFunction
UShort fFunction
Definition
Device.h:72
Kernel::PCI::Device::HeaderType
UChar HeaderType()
Definition
Device.cc:104
Kernel::PCI::Device::DeviceId
UShort DeviceId()
Definition
Device.cc:80
Kernel::PCI::Device::Device
Device()=default
Kernel::PCI::Device::Device
Device(const Device &)=default
Kernel::PCI::Device::operator=
Device & operator=(const Device &)=default
Kernel::PCI::Device::VendorId
UShort VendorId()
Definition
Device.cc:84
Kernel::PCI::Device::fBar
UInt32 fBar
Definition
Device.h:73
Kernel::PCI::Device::BecomeBusMaster
void BecomeBusMaster()
Definition
Device.cc:115
Kernel::PCI::Device::ProgIf
UChar ProgIf()
Definition
Device.cc:100
Kernel::PCI::Device::Vendor
UShort Vendor()
Definition
Device.cc:134
Kernel::PCI::Device::EnableMmio
void EnableMmio()
Definition
Device.cc:108
Kernel::PCI::Device::Read
UInt Read(UInt bar)
Definition
Device.h:42
Kernel::PCI::Device::InterfaceId
UShort InterfaceId()
Definition
Device.cc:88
Kernel::PCI::Device::fDevice
UShort fDevice
Definition
Device.h:71
Kernel::PCI::Device::Read
UInt Read(UInt bar, Size szData)
Definition
Device.cc:44
Kernel::PCI::Device::~Device
~Device()
Kernel::PCI::Device::Class
UChar Class()
Definition
Device.cc:92
Kernel::PCI::Device::fBus
UShort fBus
Definition
Device.h:70
Kernel::PCI::Device::Bar
UIntPtr Bar(UInt32 bar_in)
Definition
Device.cc:121
Kernel::PCI::Device::Write
void Write(UInt bar, UIntPtr data, Size szData)
Definition
Device.cc:58
Kernel::PCI::Device::Write
void Write(UInt bar, UIntPtr data)
Definition
Device.h:48
Config.h
Kernel::PCI
Definition
Device.cc:38
Kernel::PCI::PciConfigKind
PciConfigKind
Definition
Device.h:13
Kernel::PCI::PciConfigKind::CommandReg
@ CommandReg
Definition
Device.h:16
Kernel::PCI::PciConfigKind::Invalid
@ Invalid
Definition
Device.h:17
Kernel::PCI::PciConfigKind::ConfigAddress
@ ConfigAddress
Definition
Device.h:14
Kernel::PCI::PciConfigKind::ConfigData
@ ConfigData
Definition
Device.h:15
Kernel::Size
__SIZE_TYPE__ Size
Definition
Config.h:59
Kernel::UChar
__UINT8_TYPE__ UChar
Definition
Config.h:54
Kernel::UInt32
__UINT32_TYPE__ UInt32
Definition
Config.h:44
Kernel::UShort
__UINT16_TYPE__ UShort
Definition
Config.h:39
Kernel::UInt
__UINT32_TYPE__ UInt
Definition
Config.h:43
Kernel::UIntPtr
__UINTPTR_TYPE__ UIntPtr
Definition
Config.h:62
src
kernel
KernelKit
PCI
Device.h
Generated by
1.15.0