hardware_query/
pci.rs

1use crate::Result;
2use serde::{Deserialize, Serialize};
3
4/// PCI device information
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct PCIDevice {
7    /// PCI device ID (vendor:device)
8    pub device_id: String,
9    /// PCI vendor name
10    pub vendor_name: String,
11    /// PCI device name
12    pub device_name: String,
13    /// PCI bus location
14    pub bus_location: String,
15    /// PCI device class
16    pub device_class: String,
17    /// PCI subsystem ID
18    pub subsystem_id: Option<String>,
19    /// Driver name (if loaded)
20    pub driver: Option<String>,
21    /// Device revision
22    pub revision: Option<String>,
23    /// IRQ number
24    pub irq: Option<u32>,
25    /// Memory regions
26    pub memory_regions: Vec<String>,
27}
28
29impl PCIDevice {
30    /// Query all PCI devices
31    pub fn query_all() -> Result<Vec<Self>> {
32        // Platform-specific implementation would go here
33        // For now, return empty vector
34        Ok(vec![])
35    }
36
37    /// Get device ID
38    pub fn device_id(&self) -> &str {
39        &self.device_id
40    }
41
42    /// Get vendor name
43    pub fn vendor_name(&self) -> &str {
44        &self.vendor_name
45    }
46
47    /// Get device name
48    pub fn device_name(&self) -> &str {
49        &self.device_name
50    }
51
52    /// Get device class
53    pub fn device_class(&self) -> &str {
54        &self.device_class
55    }
56
57    /// Check if device is a graphics card
58    pub fn is_graphics_device(&self) -> bool {
59        self.device_class.to_lowercase().contains("vga")
60            || self.device_class.to_lowercase().contains("display")
61            || self.device_class.to_lowercase().contains("graphics")
62    }
63
64    /// Check if device is a network controller
65    pub fn is_network_device(&self) -> bool {
66        self.device_class.to_lowercase().contains("network")
67            || self.device_class.to_lowercase().contains("ethernet")
68            || self.device_class.to_lowercase().contains("wireless")
69    }
70
71    /// Check if device is a storage controller
72    pub fn is_storage_device(&self) -> bool {
73        self.device_class.to_lowercase().contains("storage")
74            || self.device_class.to_lowercase().contains("sata")
75            || self.device_class.to_lowercase().contains("nvme")
76            || self.device_class.to_lowercase().contains("scsi")
77    }
78}