/// Register a new device IO with its allocated resources.
/// VMM is responsible for providing the allocated resources to virtual device.
///
/// # Arguments
///
/// * `device`: device instance object to be registered
/// * `resources`: resources that this device owns, might include
///                port I/O and memory-mapped I/O ranges, irq number, etc.
Register a new device IO with its allocated resources.
VMM is responsible for providing the allocated resources to virtual device.
Register a new device IO with its allocated resources . VMM is responsible for providing the allocated resources to virtual device .
pub fn register_device_io(
        &mut self,
        device: Arc<dyn DeviceIo>,
        resources: &[Resource],
    ) -> Result<()> {
        // Register and mark device resources
        // The resources addresses being registered are sucessfully allocated before.
        for (idx, res) in resources.iter().enumerate() {
            match *res {
                Resource::PioAddressRange { base, size } => {
                    if self
                        .pio_bus
                        .insert(IoRange::new_pio_range(base, size), device.clone())
                        .is_some()
                    {
                        // Unregister registered resources.
                        self.unregister_device_io(&resources[0..idx])
                            .expect("failed to unregister devices");
                        return Err(Error::DeviceOverlap);
                    }
                }
                Resource::MmioAddressRange { base, size } => {
                    if self
                        .mmio_bus
                        .insert(IoRange::new_mmio_range(base, size), device.clone())
                        .is_some()
                    {
                        // Unregister registered resources.
                        self.unregister_device_io(&resources[0..idx])
                            .expect("failed to unregister devices");
                        return Err(Error::DeviceOverlap);
                    }
                }
                _ => continue,
            }
        }
        Ok(())
    }
pub fn register_device_io ( & mut self , device : Arc < dyn DeviceIo > , resources : & [ Resource ] , ) -> Result < ( ) > { // Register and mark device resources // The resources addresses being registered are sucessfully allocated before. for ( idx , res ) in resources . iter ( ) . enumerate ( ) { match * res { Resource :: PioAddressRange { base , size } => { if self . pio_bus . insert ( IoRange :: new_pio_range ( base , size ) , device . clone ( ) ) . is_some ( ) { // Unregister registered resources. self . unregister_device_io ( & resources [ 0 .. idx ] ) . expect ( " " ) ; return Err ( Error :: DeviceOverlap ) ; } } Resource :: MmioAddressRange { base , size } => { if self . mmio_bus . insert ( IoRange :: new_mmio_range ( base , size ) , device . clone ( ) ) . is_some ( ) { // Unregister registered resources. self . unregister_device_io ( & resources [ 0 .. idx ] ) . expect ( " " ) ; return Err ( Error :: DeviceOverlap ) ; } } _ => continue , } } Ok ( ( ) ) }
Register a new device IO with its allocated resources.
Register a new device IO with its allocated resources .
&mut self
device
Arc<dyn DeviceIo>
resources
&[Resource]