device-tree: better driver search, missing reports

This commit is contained in:
2025-07-27 14:08:44 +03:00
parent 51b72aa4d8
commit 96350f1eaf
4 changed files with 104 additions and 37 deletions
+23 -7
View File
@@ -40,7 +40,7 @@ pub struct Node {
bus_size_cells: usize,
interrupt_parent: Option<Phandle>,
name: Option<&'static str>,
compatible: Option<&'static str>,
compatible: Option<TProp<'static>>,
// Hierachy info
children: OneTimeInit<Vec<Arc<Node>>>,
@@ -87,11 +87,28 @@ impl NodeDevice {
impl Node {
fn probe_single(node: &Arc<Node>, cx: &mut ProbeContext) -> Option<ProbedDevice> {
let compatible = node.compatible?;
let compatible = node.compatible.as_ref()?;
let drivers = DRIVERS.read();
let driver = drivers.iter().find(|d| d.matches(compatible));
if driver.is_none() {
// log::warn!("No driver for {compatible:?}");
// Find a matching driver
let driver = compatible
.as_str_list()
.find_map(|c| drivers.iter().find(|d| d.matches(c)));
if libk::config::get().device_tree.log_missing {
if driver.is_none() {
let name = node.name();
// FIXME don't spam virtio missing stuff
if !name.map_or(false, |n| n.starts_with("virtio_mmio")) {
for (i, compatible) in compatible.as_str_list().enumerate() {
if i == 0 {
log::warn!("No driver for {name:?} ({compatible:?})");
} else {
log::warn!(" also {compatible:?}");
}
}
}
}
}
let driver = driver?;
@@ -438,8 +455,7 @@ fn unflatten_node(
ctx: &EnumerationContext,
) -> Arc<Node> {
let name = dt.name().ok();
// TODO <stringlist>
let compatible = dt.prop_string("compatible");
let compatible = dt.property("compatible");
// Extract #...-cells for children
let address_cells = dt
+29
View File
@@ -15,6 +15,13 @@ pub struct DebugOptions {
pub disable_program_trace: bool,
}
/// Device-tree related options
#[derive(Debug)]
pub struct DeviceTreeOptions {
/// If set, logs missing drivers for device tree nodes
pub log_missing: bool,
}
impl Default for DebugOptions {
fn default() -> Self {
Self {
@@ -55,3 +62,25 @@ impl SetOption for DebugOptions {
}
}
}
impl Default for DeviceTreeOptions {
fn default() -> Self {
Self { log_missing: true }
}
}
impl SetOption for DeviceTreeOptions {
fn set_key_value(&mut self, _key: &str, _value: &str) -> bool {
false
}
fn set_flag(&mut self, value: &str) -> bool {
match value {
"log-missing" => {
self.log_missing = true;
true
}
_ => false,
}
}
}
+10
View File
@@ -21,6 +21,8 @@ pub use x86_64::X86_64Options;
mod general;
pub use general::DebugOptions;
#[cfg(any(rust_analyzer, target_arch = "aarch64", target_arch = "riscv64"))]
pub use general::DeviceTreeOptions;
trait SetOption {
fn set_key_value(&mut self, key: &str, value: &str) -> bool;
@@ -31,6 +33,8 @@ trait SetOption {
#[derive(Debug, Default)]
pub struct Options {
pub debug: DebugOptions,
#[cfg(any(rust_analyzer, target_arch = "aarch64", target_arch = "riscv64"))]
pub device_tree: DeviceTreeOptions,
#[cfg(any(target_arch = "x86_64", target_arch = "x86", rust_analyzer))]
pub x86: X86Options,
#[cfg(any(target_arch = "x86_64", rust_analyzer))]
@@ -41,6 +45,8 @@ impl SetOption for Options {
fn set_flag(&mut self, value: &str) -> bool {
match value {
_ if let Some(value) = value.strip_prefix("debug.") => self.debug.set_flag(value),
#[cfg(any(rust_analyzer, target_arch = "aarch64", target_arch = "riscv64"))]
_ if let Some(value) = value.strip_prefix("dt.") => self.device_tree.set_flag(value),
#[cfg(any(target_arch = "x86_64", target_arch = "x86", rust_analyzer))]
_ if let Some(value) = value.strip_prefix("x86.") => self.x86.set_flag(value),
#[cfg(any(target_arch = "x86_64", rust_analyzer))]
@@ -52,6 +58,10 @@ impl SetOption for Options {
fn set_key_value(&mut self, key: &str, value: &str) -> bool {
match key {
_ if let Some(key) = key.strip_prefix("debug.") => self.debug.set_key_value(key, value),
#[cfg(any(rust_analyzer, target_arch = "aarch64", target_arch = "riscv64"))]
_ if let Some(key) = key.strip_prefix("dt.") => {
self.device_tree.set_key_value(key, value)
}
#[cfg(any(target_arch = "x86_64", target_arch = "x86", rust_analyzer))]
_ if let Some(key) = key.strip_prefix("x86.") => self.x86.set_key_value(key, value),
#[cfg(any(target_arch = "x86_64", rust_analyzer))]