SimpleKernel
1.17.0
Loading...
Searching...
No Matches
device_node.hpp
Go to the documentation of this file.
1
5
#pragma once
6
7
#include <concepts>
8
#include <cstddef>
9
#include <cstdint>
10
11
#include "
expected.hpp
"
12
14
enum class
BusType
: uint8_t {
kPlatform
,
kPci
,
kAcpi
};
15
17
enum class
DeviceType
: uint8_t {
19
kChar
,
21
kBlock
,
23
kNet
,
25
kPlatform
,
26
};
27
28
namespace
vfs
{
29
class
BlockDevice
;
30
}
// namespace vfs
31
39
struct
DeviceNode
{
41
char
name
[32]{};
42
43
BusType
bus_type
{
BusType::kPlatform
};
44
DeviceType
type
{
DeviceType::kPlatform
};
45
47
uint64_t
mmio_base
{0};
48
size_t
mmio_size
{0};
49
51
uint32_t
irq
{0};
52
54
char
compatible
[128]{};
55
size_t
compatible_len
{0};
56
58
uint32_t
dev_id
{0};
59
61
bool
bound
{
false
};
62
65
vfs::BlockDevice
*
block_device
{
nullptr
};
66
};
67
69
template
<
typename
B>
70
concept
Bus
=
requires
(B b,
DeviceNode
* out,
size_t
max) {
72
{ b.Enumerate(out, max) } -> std::same_as<Expected<size_t>>;
74
{ B::GetName() } -> std::same_as<const char*>;
75
};
vfs::BlockDevice
块设备抽象基类
Definition
block_device.hpp:19
Bus
总线 concept — 每种总线负责枚举自己管辖范围内的设备
Definition
device_node.hpp:70
BusType
BusType
总线类型标识 — 为将来扩展 PCI/ACPI 总线预留的扩展点
Definition
device_node.hpp:14
BusType::kAcpi
@ kAcpi
BusType::kPlatform
@ kPlatform
BusType::kPci
@ kPci
DeviceType
DeviceType
设备分类
Definition
device_node.hpp:17
DeviceType::kNet
@ kNet
网络设备
DeviceType::kPlatform
@ kPlatform
平台设备(中断控制器、定时器等)
DeviceType::kBlock
@ kBlock
块设备(磁盘等)
DeviceType::kChar
@ kChar
字符设备(串口等)
expected.hpp
vfs
Definition
device_node.hpp:28
DeviceNode
单个设备的硬件资源描述。
Definition
device_node.hpp:39
DeviceNode::irq
uint32_t irq
第一条中断线(需要多 IRQ 支持时扩展)
Definition
device_node.hpp:51
DeviceNode::compatible_len
size_t compatible_len
Definition
device_node.hpp:55
DeviceNode::dev_id
uint32_t dev_id
由 DeviceManager 分配的全局设备 ID
Definition
device_node.hpp:58
DeviceNode::block_device
vfs::BlockDevice * block_device
Definition
device_node.hpp:65
DeviceNode::name
char name[32]
可读的设备名称(来自 FDT 节点名)
Definition
device_node.hpp:41
DeviceNode::mmio_base
uint64_t mmio_base
第一个 MMIO 区域(需要多 BAR 支持时扩展为数组)
Definition
device_node.hpp:47
DeviceNode::compatible
char compatible[128]
FDT compatible 字符串列表(以 '\0' 分隔,如 "ns16550a\0ns16550\0")
Definition
device_node.hpp:54
DeviceNode::bus_type
BusType bus_type
Definition
device_node.hpp:43
DeviceNode::type
DeviceType type
Definition
device_node.hpp:44
DeviceNode::bound
bool bound
由 ProbeAll() 在 DeviceManager::lock_ 保护下设置 — 无需每节点锁。
Definition
device_node.hpp:61
DeviceNode::mmio_size
size_t mmio_size
Definition
device_node.hpp:48
src
device
include
device_node.hpp
Generated by
1.9.8