Struct DeviceManager

Source
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 of BasicDeviceManager 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

Source

const fn new() -> Self

Source

pub fn get_manager() -> &'static DeviceManager

Source

pub fn get_mut_manager() -> &'static mut DeviceManager

Source

pub fn register_device(&self, device: Box<dyn Device>) -> usize

Register a device with the manager

§Arguments
  • device: The device to register.
§Returns
  • The id of the registered device.
§Example
let device = Box::new(MyDevice::new());
let id = DeviceManager::get_mut_manager().register_device(device);
Source

pub fn borrow_device( &self, id: usize, ) -> Result<BorrowedDeviceGuard, &'static str>

Borrow a device by type and index

§Arguments
  • id: The id of the device to borrow.
§Returns

A result containing a reference to the borrowed device, or an error if the device type is not found or the index is out of bounds.

Source

pub fn borrow_exclusive_device( &self, id: usize, ) -> Result<BorrowedDeviceGuard, &'static str>

Borrow an exclusive device by type and index

§Arguments
  • id: The id of the device to borrow.
§Returns

A result containing a reference to the borrowed device, or an error if the device type is not found or the index is out of bounds.

Source

pub fn get_devices_count(&self) -> usize

Get the number of devices of a specific type

§Returns

The number of devices of the specified type.

Source

pub fn borrow_drivers(&self) -> &Mutex<Vec<Box<dyn DeviceDriver>>>

Source

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.

Source

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 the DeviceDriver trait.
§Example
let driver = Box::new(MyDeviceDriver::new());
DeviceManager::get_mut_manager().register_driver(driver);

Auto Trait Implementations§

§

impl !Freeze for DeviceManager

§

impl !RefUnwindSafe for DeviceManager

§

impl !Send for DeviceManager

§

impl !Sync for DeviceManager

§

impl Unpin for DeviceManager

§

impl !UnwindSafe for DeviceManager

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.