fn read_common_config(
        &mut self,
        device: &Arc<Mutex<dyn VirtioDevice>>,
        interrupt_status: &Arc<AtomicU32>,
        offset: u64,
    ) -> Result<u32> {
        let value = match offset {
            MAGIC_VALUE_REG => MMIO_MAGIC_VALUE,
            VERSION_REG => MMIO_VERSION,
            DEVICE_ID_REG => device.lock().unwrap().device_type() as u32,
            VENDOR_ID_REG => VENDOR_ID,
            DEVICE_FEATURES_REG => {
                let mut features = device
                    .lock()
                    .unwrap()
                    .get_device_features(self.features_select);
                if self.features_select == 1 {
                    features |= 0x1; // enable support of VirtIO Version 1
                }
                features
            }
            QUEUE_NUM_MAX_REG => self
                .get_queue_config()
                .map(|config| u32::from(config.max_size))?,
            QUEUE_READY_REG => self.get_queue_config().map(|config| config.ready as u32)?,
            INTERRUPT_STATUS_REG => {
                self.interrupt_status = interrupt_status.load(Ordering::SeqCst);
                self.interrupt_status
            }
            STATUS_REG => self.device_status,
            CONFIG_GENERATION_REG => self.config_generation,
            _ => {
                return Err(ErrorKind::MmioRegErr(offset).into());
            }
        };

        Ok(value)
    }
/// Read data from the common config of virtio device.
/// Return the config value in u32.
/// # Arguments
///
/// * `device` - Virtio device entity.
/// * `offset` - The offset of common config.
Read data from the common config of virtio device.
Return the config value in u32.
Read data from the common config of virtio device . Return the config value in u32 .
fn read_common_config(
        &mut self,
        device: &Arc<Mutex<dyn VirtioDevice>>,
        interrupt_status: &Arc<AtomicU32>,
        offset: u64,
    ) -> Result<u32> {
        let value = match offset {
            MAGIC_VALUE_REG => MMIO_MAGIC_VALUE,
            VERSION_REG => MMIO_VERSION,
            DEVICE_ID_REG => device.lock().unwrap().device_type() as u32,
            VENDOR_ID_REG => VENDOR_ID,
            DEVICE_FEATURES_REG => {
                let mut features = device
                    .lock()
                    .unwrap()
                    .get_device_features(self.features_select);
                if self.features_select == 1 {
                    features |= 0x1; // enable support of VirtIO Version 1
                }
                features
            }
            QUEUE_NUM_MAX_REG => self
                .get_queue_config()
                .map(|config| u32::from(config.max_size))?,
            QUEUE_READY_REG => self.get_queue_config().map(|config| config.ready as u32)?,
            INTERRUPT_STATUS_REG => {
                self.interrupt_status = interrupt_status.load(Ordering::SeqCst);
                self.interrupt_status
            }
            STATUS_REG => self.device_status,
            CONFIG_GENERATION_REG => self.config_generation,
            _ => {
                return Err(ErrorKind::MmioRegErr(offset).into());
            }
        };
        Ok(value)
    }
fn read_common_config ( & mut self , device : & Arc < Mutex < dyn VirtioDevice > > , interrupt_status : & Arc < AtomicU32 > , offset : u64 , ) -> Result < u32 > { let value = match offset { MAGIC_VALUE_REG => MMIO_MAGIC_VALUE , VERSION_REG => MMIO_VERSION , DEVICE_ID_REG => device . lock ( ) . unwrap ( ) . device_type ( ) as u32 , VENDOR_ID_REG => VENDOR_ID , DEVICE_FEATURES_REG => { let mut features = device . lock ( ) . unwrap ( ) . get_device_features ( self . features_select ) ; if self . features_select == 1 { features |= 0x1 ; // enable support of VirtIO Version 1 } features } QUEUE_NUM_MAX_REG => self . get_queue_config ( ) . map ( | config | u32 :: from ( config . max_size ) ) ? , QUEUE_READY_REG => self . get_queue_config ( ) . map ( | config | config . ready as u32 ) ? , INTERRUPT_STATUS_REG => { self . interrupt_status = interrupt_status . load ( Ordering :: SeqCst ) ; self . interrupt_status } STATUS_REG => self . device_status , CONFIG_GENERATION_REG => self . config_generation , _ => { return Err ( ErrorKind :: MmioRegErr ( offset ) . into ( ) ) ; } } ; Ok ( value ) }
Read data from the common config of virtio device.
Read data from the common config of virtio device .
&mut self
device
&Arc<Mutex<dyn VirtioDevice>>
interrupt_status
&Arc<AtomicU32>
offset
u64
&mut self
device
&Arc<Mutex<dyn VirtioDevice>>
interrupt_status
&Arc<AtomicU32>
offset
u64