SimpleKernel 1.17.0
Loading...
Searching...
No Matches
device.cpp
Go to the documentation of this file.
1
5#include "device_manager.hpp"
6#include "kernel.h"
7#include "kernel_fdt.hpp"
8#include "kernel_log.hpp"
11#include "platform_bus.hpp"
13
14namespace {
15
18using GetEntryFn = auto (*)() -> const DriverEntry&;
19static constexpr GetEntryFn kBuiltinDrivers[] = {
23};
24
25} // namespace
26
28auto DeviceInit() -> void {
29 DeviceManagerSingleton::create();
30 auto& dm = DeviceManagerSingleton::instance();
31
32 // 创建驱动单例
33 Ns16550aDriverSingleton::create();
34 Pl011DriverSingleton::create();
35 VirtioDriverSingleton::create();
36
37 for (const auto& get_entry : kBuiltinDrivers) {
38 const auto& entry = get_entry();
39 if (auto r = dm.GetRegistry().Register(entry); !r) {
40 klog::Err("DeviceInit: register driver '{}' failed: {}", entry.name,
41 r.error().message());
42 return;
43 }
44 }
45
46 PlatformBus platform_bus(KernelFdtSingleton::instance());
47 if (auto r = dm.RegisterBus(platform_bus); !r) {
48 klog::Err("DeviceInit: PlatformBus enumeration failed: {}",
49 r.error().message());
50 return;
51 }
52
53 if (auto r = dm.ProbeAll(); !r) {
54 klog::Err("DeviceInit: ProbeAll failed: {}", r.error().message());
55 return;
56 }
57
58 klog::Info("DeviceInit: complete");
59}
static auto GetEntry() -> const DriverEntry &
返回用于注册的 DriverEntry
static auto GetEntry() -> const DriverEntry &
返回用于注册的 DriverEntry
平台总线 — 从扁平设备树(FDT)枚举设备
static auto GetEntry() -> const DriverEntry &
返回驱动注册入口
auto DeviceInit() -> void
设备子系统初始化入口
Definition device.cpp:28
auto Err(etl::format_string< Args... > fmt, Args &&... args) -> void
以 ERROR 级别记录日志
auto Info(etl::format_string< Args... > fmt, Args &&... args) -> void
以 INFO 级别记录日志
类型擦除的驱动条目 — 每个已注册驱动对应一条。