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
14enum class BusType : uint8_t { kPlatform, kPci, kAcpi };
15
17enum class DeviceType : uint8_t {
19 kChar,
21 kBlock,
23 kNet,
26};
27
28namespace vfs {
29class BlockDevice;
30} // namespace vfs
31
39struct DeviceNode {
41 char name[32]{};
42
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
66};
67
69template <typename B>
70concept 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};
块设备抽象基类
总线 concept — 每种总线负责枚举自己管辖范围内的设备
BusType
总线类型标识 — 为将来扩展 PCI/ACPI 总线预留的扩展点
DeviceType
设备分类
@ kNet
网络设备
@ kPlatform
平台设备(中断控制器、定时器等)
@ kBlock
块设备(磁盘等)
@ kChar
字符设备(串口等)
单个设备的硬件资源描述。
uint32_t irq
第一条中断线(需要多 IRQ 支持时扩展)
size_t compatible_len
uint32_t dev_id
由 DeviceManager 分配的全局设备 ID
vfs::BlockDevice * block_device
char name[32]
可读的设备名称(来自 FDT 节点名)
uint64_t mmio_base
第一个 MMIO 区域(需要多 BAR 支持时扩展为数组)
char compatible[128]
FDT compatible 字符串列表(以 '\0' 分隔,如 "ns16550a\0ns16550\0")
BusType bus_type
DeviceType type
bool bound
由 ProbeAll() 在 DeviceManager::lock_ 保护下设置 — 无需每节点锁。
size_t mmio_size