mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
virtio-devices: Introduce new function translating GPAs into GVAs
In anticipation for the vDPA need to translate a GPA back into a GVA, we extend the existing trait DmaRemapping and AccessPlatform to perform such operation. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
@@ -96,10 +96,13 @@ impl fmt::Display for VirtioDeviceType {
|
||||
pub trait AccessPlatform: Send + Sync + Debug {
|
||||
/// Provide a way to translate GVA address ranges into GPAs.
|
||||
fn translate_gva(&self, base: u64, size: u64) -> std::result::Result<u64, std::io::Error>;
|
||||
/// Provide a way to translate GPA address ranges into GVAs.
|
||||
fn translate_gpa(&self, base: u64, size: u64) -> std::result::Result<u64, std::io::Error>;
|
||||
}
|
||||
|
||||
pub trait Translatable {
|
||||
fn translate_gva(&self, access_platform: Option<&Arc<dyn AccessPlatform>>, len: usize) -> Self;
|
||||
fn translate_gpa(&self, access_platform: Option<&Arc<dyn AccessPlatform>>, len: usize) -> Self;
|
||||
}
|
||||
|
||||
impl Translatable for GuestAddress {
|
||||
@@ -110,4 +113,11 @@ impl Translatable for GuestAddress {
|
||||
*self
|
||||
}
|
||||
}
|
||||
fn translate_gpa(&self, access_platform: Option<&Arc<dyn AccessPlatform>>, len: usize) -> Self {
|
||||
if let Some(access_platform) = access_platform {
|
||||
GuestAddress(access_platform.translate_gpa(self.0, len as u64).unwrap())
|
||||
} else {
|
||||
*self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user