pub struct DeviceManager {
devices: Mutex<BTreeMap<usize, SharedDevice>>,
device_by_name: Mutex<BTreeMap<String, SharedDevice>>,
name_to_id: Mutex<BTreeMap<String, usize>>,
drivers: Mutex<BTreeMap<DriverPriority, Vec<Box<dyn DeviceDriver>>>>,
next_device_id: AtomicUsize,
}Expand description
DeviceManager
This struct is the main device management system. It handles all devices and drivers with priority-based initialization.
§Fields
devices: A mutex-protected map of all registered devices by ID.device_by_name: A mutex-protected map of devices by name.name_to_id: A mutex-protected map from device name to device ID.drivers: A mutex-protected map of device drivers organized by priority.next_device_id: Atomic counter for generating unique device IDs.
Fields§
§devices: Mutex<BTreeMap<usize, SharedDevice>>§device_by_name: Mutex<BTreeMap<String, SharedDevice>>§name_to_id: Mutex<BTreeMap<String, usize>>§drivers: Mutex<BTreeMap<DriverPriority, Vec<Box<dyn DeviceDriver>>>>§next_device_id: AtomicUsizeImplementations§
Source§impl DeviceManager
impl DeviceManager
const fn new() -> Self
pub fn get_manager() -> &'static DeviceManager
Sourcepub fn register_device(&self, device: Arc<dyn Device>) -> usize
pub fn register_device(&self, device: Arc<dyn Device>) -> usize
Sourcepub fn register_device_with_name(
&self,
name: String,
device: Arc<dyn Device>,
) -> usize
pub fn register_device_with_name( &self, name: String, device: Arc<dyn Device>, ) -> usize
Sourcepub fn get_device(&self, id: usize) -> Option<SharedDevice>
pub fn get_device(&self, id: usize) -> Option<SharedDevice>
Sourcepub fn get_device_by_name(&self, name: &str) -> Option<SharedDevice>
pub fn get_device_by_name(&self, name: &str) -> Option<SharedDevice>
Sourcepub fn get_device_id_by_name(&self, name: &str) -> Option<usize>
pub fn get_device_id_by_name(&self, name: &str) -> Option<usize>
Sourcepub fn get_devices_count(&self) -> usize
pub fn get_devices_count(&self) -> usize
Sourcepub fn get_first_device_by_type(&self, device_type: DeviceType) -> Option<usize>
pub fn get_first_device_by_type(&self, device_type: DeviceType) -> Option<usize>
Sourcepub fn get_named_devices(&self) -> Vec<(String, SharedDevice)>
pub fn get_named_devices(&self) -> Vec<(String, SharedDevice)>
Get all devices registered by name
Returns an iterator over (name, device) pairs for all devices that were registered with explicit names.
§Returns
Vector of (name, device) tuples
pub fn borrow_drivers( &self, ) -> &Mutex<BTreeMap<DriverPriority, Vec<Box<dyn DeviceDriver>>>>
Sourcepub fn populate_devices(&self)
pub fn populate_devices(&self)
Populates devices from the FDT (Flattened Device Tree).
This function searches for the /soc node in the FDT and iterates through its children.
For each child node, it checks if there is a compatible driver registered.
If a matching driver is found, it probes the device using the driver’s probe method.
If the probe is successful, the device is registered with the driver.
§Deprecated
Use populate_devices_from_source with DeviceSource::Fdt instead.
Sourcepub fn populate_devices_from_source(
&self,
device_source: &DeviceSource,
priorities: Option<&[DriverPriority]>,
)
pub fn populate_devices_from_source( &self, device_source: &DeviceSource, priorities: Option<&[DriverPriority]>, )
Populate devices using a specific device source
§Arguments
device_source- The source of device information (FDT, UEFI, ACPI, etc.)priorities- Optional slice of priority levels to use. If None, uses all priorities in order.
Sourcefn populate_devices_from_fdt(&self, priorities: Option<&[DriverPriority]>)
fn populate_devices_from_fdt(&self, priorities: Option<&[DriverPriority]>)
Populate devices from FDT
Sourcefn process_priority_level(&self, fdt: &Fdt<'_>, priority: DriverPriority)
fn process_priority_level(&self, fdt: &Fdt<'_>, priority: DriverPriority)
Process devices for a single priority level - reduces stack nesting
Sourcefn process_single_device_node(
&self,
child: FdtNode<'_, '_>,
priority: DriverPriority,
idx: &mut usize,
)
fn process_single_device_node( &self, child: FdtNode<'_, '_>, priority: DriverPriority, idx: &mut usize, )
Process a single device node with minimal stack usage
Sourcefn build_minimal_resources(
&self,
child: &FdtNode<'_, '_>,
) -> Vec<PlatformDeviceResource>
fn build_minimal_resources( &self, child: &FdtNode<'_, '_>, ) -> Vec<PlatformDeviceResource>
Build device resources with minimal stack allocation
Sourcefn try_match_and_probe_device(
&self,
child: FdtNode<'_, '_>,
priority: DriverPriority,
idx: &mut usize,
compatible: Vec<&str>,
resources: Vec<PlatformDeviceResource>,
)
fn try_match_and_probe_device( &self, child: FdtNode<'_, '_>, priority: DriverPriority, idx: &mut usize, compatible: Vec<&str>, resources: Vec<PlatformDeviceResource>, )
Try to match device with drivers and probe if successful
Sourcefn populate_devices_from_uefi(&self, _priorities: Option<&[DriverPriority]>)
fn populate_devices_from_uefi(&self, _priorities: Option<&[DriverPriority]>)
Sourcefn populate_devices_from_acpi(&self, _priorities: Option<&[DriverPriority]>)
fn populate_devices_from_acpi(&self, _priorities: Option<&[DriverPriority]>)
Sourcepub fn populate_devices_by_priority(
&self,
priorities: Option<&[DriverPriority]>,
)
pub fn populate_devices_by_priority( &self, priorities: Option<&[DriverPriority]>, )
Sourcepub fn register_driver(
&self,
driver: Box<dyn DeviceDriver>,
priority: DriverPriority,
)
pub fn register_driver( &self, driver: Box<dyn DeviceDriver>, priority: DriverPriority, )
Registers a device driver with the device manager.
This function takes a boxed device driver and adds it to the list of registered drivers at the specified priority level.
§Arguments
driver- A boxed device driver that implements theDeviceDrivertrait.priority- The priority level for this driver.
§Example
let driver = Box::new(MyDeviceDriver::new());
DeviceManager::get_manager().register_driver(driver, DriverPriority::Standard);Sourcepub fn register_driver_default(&self, driver: Box<dyn DeviceDriver>)
pub fn register_driver_default(&self, driver: Box<dyn DeviceDriver>)
Registers a device driver with default Standard priority.
This is a convenience method for backward compatibility.
§Arguments
driver- A boxed device driver that implements theDeviceDrivertrait.