SimpleKernel 1.17.0
Loading...
Searching...
No Matches
PlatformBus Class Reference

平台总线 — 从扁平设备树(FDT)枚举设备 More...

#include <platform_bus.hpp>

Collaboration diagram for PlatformBus:
Collaboration graph

Public Member Functions

 PlatformBus (KernelFdt &fdt)
 
auto Enumerate (DeviceNode *out, size_t max) -> Expected< size_t >
 枚举所有含 compatible 字符串的 FDT 设备节点。
 
构造 / 析构
 PlatformBus ()=delete
 
 ~PlatformBus ()=default
 
 PlatformBus (const PlatformBus &)=delete
 
 PlatformBus (PlatformBus &&)=delete
 
auto operator= (const PlatformBus &) -> PlatformBus &=delete
 
auto operator= (PlatformBus &&) -> PlatformBus &=delete
 

Static Public Member Functions

static auto GetName () -> const char *
 

Private Attributes

KernelFdtfdt_
 

Detailed Description

平台总线 — 从扁平设备树(FDT)枚举设备

Definition at line 14 of file platform_bus.hpp.

Constructor & Destructor Documentation

◆ PlatformBus() [1/4]

PlatformBus::PlatformBus ( KernelFdt fdt)
inlineexplicit

Definition at line 16 of file platform_bus.hpp.

16: fdt_(fdt) {}
KernelFdt & fdt_

◆ PlatformBus() [2/4]

PlatformBus::PlatformBus ( )
delete

◆ ~PlatformBus()

PlatformBus::~PlatformBus ( )
default

◆ PlatformBus() [3/4]

PlatformBus::PlatformBus ( const PlatformBus )
delete

◆ PlatformBus() [4/4]

PlatformBus::PlatformBus ( PlatformBus &&  )
delete

Member Function Documentation

◆ Enumerate()

auto PlatformBus::Enumerate ( DeviceNode out,
size_t  max 
) -> Expected<size_t>
inline

枚举所有含 compatible 字符串的 FDT 设备节点。

Parameters
out输出的 DeviceNode 数组
max最多写入的节点数
Returns
Expected<size_t> 已写入的节点数

Definition at line 27 of file platform_bus.hpp.

27 {
28 size_t count = 0;
29
30 auto result = fdt_.ForEachDeviceNode(
31 [&out, &count, max](const char* node_name, const char* compatible_data,
32 size_t compatible_len, uint64_t mmio_base,
33 size_t mmio_size, uint32_t irq) -> bool {
34 if (count >= max) return false;
35 if (compatible_data == nullptr || compatible_len == 0) return true;
36
37 auto& node = out[count];
38
39 kstd::strncpy(node.name, node_name, sizeof(node.name) - 1);
40 node.name[sizeof(node.name) - 1] = '\0';
41
42 node.bus_type = BusType::kPlatform;
43 node.type = DeviceType::kPlatform;
44 node.mmio_base = mmio_base;
45 node.mmio_size = mmio_size;
46 node.irq = irq;
47
48 size_t copy_len = compatible_len < sizeof(node.compatible)
49 ? compatible_len
50 : sizeof(node.compatible);
51 if (compatible_len > sizeof(node.compatible)) {
52 klog::Warn("PlatformBus: compatible truncated {}\u2192{} for '{}'",
53 compatible_len, sizeof(node.compatible), node_name);
54 }
55 kstd::memcpy(node.compatible, compatible_data, copy_len);
56 node.compatible_len = copy_len;
57
59 "PlatformBus: found '{}' compatible='{}' mmio={:#x} size={:#x} "
60 "irq={}",
61 node_name, compatible_data, mmio_base, mmio_size, irq);
62
63 ++count;
64 return true;
65 });
66
67 if (!result.has_value()) {
68 return std::unexpected(result.error());
69 }
70 return count;
71 }
auto ForEachDeviceNode(Callback &&callback) const -> Expected< void >
遍历 FDT 中所有"叶设备"节点,自动跳过基础设施节点。
@ kPlatform
平台设备(中断控制器、定时器等)
auto Info(etl::format_string< Args... > fmt, Args &&... args) -> void
以 INFO 级别记录日志
auto Warn(etl::format_string< Args... > fmt, Args &&... args) -> void
以 WARN 级别记录日志
Here is the call graph for this function:

◆ GetName()

static auto PlatformBus::GetName ( ) -> const char*
inlinestatic

Definition at line 18 of file platform_bus.hpp.

18{ return "platform"; }

◆ operator=() [1/2]

auto PlatformBus::operator= ( const PlatformBus ) -> PlatformBus &=delete
delete

◆ operator=() [2/2]

auto PlatformBus::operator= ( PlatformBus &&  ) -> PlatformBus &=delete
delete

Member Data Documentation

◆ fdt_

KernelFdt& PlatformBus::fdt_
private

Definition at line 84 of file platform_bus.hpp.


The documentation for this class was generated from the following file: