use super::{is_card_node, is_intel_vendor, resolve_driver};
use crate::device::common::execute_command_default;
use std::path::Path;
pub(super) fn has_intel_client_gpu_from_root(drm_root: &Path) -> bool {
if let Ok(entries) = std::fs::read_dir(drm_root) {
for entry in entries.flatten() {
let path = entry.path();
let name = match path.file_name().and_then(|n| n.to_str()) {
Some(n) => n.to_string(),
None => continue,
};
if !is_card_node(&name) {
continue;
}
let device_dir = path.join("device");
if !is_intel_vendor(&device_dir) {
continue;
}
let driver = resolve_driver(&device_dir);
if driver == "i915" || driver == "xe" {
return true;
}
}
}
if let Ok(output) = execute_command_default("lspci", &["-n"])
&& output.status == 0
{
for line in output.stdout.lines() {
if line_matches_intel_gpu(line) {
return true;
}
}
}
false
}
pub(super) fn line_matches_intel_gpu(line: &str) -> bool {
let mut tokens = line.split_whitespace();
let _bdf = tokens.next();
let class = tokens.next().unwrap_or("").trim_end_matches(':');
let vendor_device = tokens.next().unwrap_or("");
let class_match = matches!(class, "0300" | "0301" | "0302" | "0380");
if !class_match {
return false;
}
vendor_device.split(':').next() == Some("8086")
}