mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-31 18:15:20 +00:00
virtio-devices: Set AccessPlatform trait through VirtioDevice
Add a new method set_access_platform() to the VirtioDevice trait in order to allow an AccessPlatform trait to be setup on any virtio device. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
7d09df468d
commit
75b9e70ec8
@ -6,8 +6,10 @@
|
|||||||
//
|
//
|
||||||
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
||||||
|
|
||||||
use crate::{ActivateError, ActivateResult, Error};
|
use crate::{
|
||||||
use crate::{GuestMemoryMmap, GuestRegionMmap};
|
ActivateError, ActivateResult, Error, GuestMemoryMmap, GuestRegionMmap,
|
||||||
|
VIRTIO_F_RING_INDIRECT_DESC,
|
||||||
|
};
|
||||||
use libc::EFD_NONBLOCK;
|
use libc::EFD_NONBLOCK;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
@ -17,7 +19,7 @@ use std::sync::{
|
|||||||
Arc, Barrier,
|
Arc, Barrier,
|
||||||
};
|
};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use virtio_queue::Queue;
|
use virtio_queue::{AccessPlatform, Queue};
|
||||||
use vm_memory::{GuestAddress, GuestMemoryAtomic, GuestUsize};
|
use vm_memory::{GuestAddress, GuestMemoryAtomic, GuestUsize};
|
||||||
use vm_migration::{MigratableError, Pausable};
|
use vm_migration::{MigratableError, Pausable};
|
||||||
use vm_virtio::VirtioDeviceType;
|
use vm_virtio::VirtioDeviceType;
|
||||||
@ -191,6 +193,10 @@ pub trait VirtioDevice: Send {
|
|||||||
offset_config.write_all(data).unwrap();
|
offset_config.write_all(data).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set the access platform trait to let the device perform address
|
||||||
|
/// translations if needed.
|
||||||
|
fn set_access_platform(&mut self, _access_platform: Arc<dyn AccessPlatform>) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Trait providing address translation the same way a physical DMA remapping
|
/// Trait providing address translation the same way a physical DMA remapping
|
||||||
@ -218,6 +224,7 @@ pub struct VirtioCommon {
|
|||||||
pub queue_sizes: Vec<u16>,
|
pub queue_sizes: Vec<u16>,
|
||||||
pub device_type: u32,
|
pub device_type: u32,
|
||||||
pub min_queues: u16,
|
pub min_queues: u16,
|
||||||
|
pub access_platform: Option<Arc<dyn AccessPlatform>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VirtioCommon {
|
impl VirtioCommon {
|
||||||
@ -320,6 +327,13 @@ impl VirtioCommon {
|
|||||||
self.pause_evt.as_ref().unwrap().try_clone().unwrap(),
|
self.pause_evt.as_ref().unwrap().try_clone().unwrap(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_access_platform(&mut self, access_platform: Arc<dyn AccessPlatform>) {
|
||||||
|
self.access_platform = Some(access_platform);
|
||||||
|
// Indirect descriptors feature is not supported when the device
|
||||||
|
// requires the addresses held by the descriptors to be translated.
|
||||||
|
self.avail_features &= !(1 << VIRTIO_F_RING_INDIRECT_DESC);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Pausable for VirtioCommon {
|
impl Pausable for VirtioCommon {
|
||||||
|
Loading…
Reference in New Issue
Block a user