pub struct DeviceManager {
pub basic: BasicDeviceManager,
devices: Mutex<Vec<Arc<DeviceHandle>>>,
drivers: Mutex<Vec<Box<dyn DeviceDriver>>>,
}
Expand description
DeviceManager
This struct is the main device management system. It handles all devices and drivers, including basic I/O devices. It provides methods to register devices, populate devices from the FDT, and manage device drivers.
§Fields
basic
: An instance ofBasicDeviceManager
for managing basic I/O devices.devices
: A mutex-protected vector of all registered devices.drivers
: A mutex-protected vector of all registered device drivers.
Fields§
§basic: BasicDeviceManager
§devices: Mutex<Vec<Arc<DeviceHandle>>>
§drivers: Mutex<Vec<Box<dyn DeviceDriver>>>
Implementations§
Source§impl DeviceManager
impl DeviceManager
const fn new() -> Self
pub fn get_manager() -> &'static DeviceManager
pub fn get_mut_manager() -> &'static mut DeviceManager
Sourcepub fn register_device(&self, device: Box<dyn Device>) -> usize
pub fn register_device(&self, device: Box<dyn Device>) -> usize
Sourcepub fn borrow_device(
&self,
id: usize,
) -> Result<BorrowedDeviceGuard, &'static str>
pub fn borrow_device( &self, id: usize, ) -> Result<BorrowedDeviceGuard, &'static str>
Sourcepub fn borrow_exclusive_device(
&self,
id: usize,
) -> Result<BorrowedDeviceGuard, &'static str>
pub fn borrow_exclusive_device( &self, id: usize, ) -> Result<BorrowedDeviceGuard, &'static str>
Sourcepub fn get_devices_count(&self) -> usize
pub fn get_devices_count(&self) -> usize
pub fn borrow_drivers(&self) -> &Mutex<Vec<Box<dyn DeviceDriver>>>
Sourcepub fn populate_devices(&mut self)
pub fn populate_devices(&mut 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.
Sourcepub fn register_driver(&mut self, driver: Box<dyn DeviceDriver>)
pub fn register_driver(&mut self, driver: Box<dyn DeviceDriver>)
Registers a device driver with the device manager.
This function takes a boxed device driver and adds it to the list of registered drivers. It is used to register drivers that can be used to probe and manage devices.
§Arguments
driver
- A boxed device driver that implements theDeviceDriver
trait.
§Example
let driver = Box::new(MyDeviceDriver::new());
DeviceManager::get_mut_manager().register_driver(driver);