[hypervisor] Add hypervisor backend trait to facilitate hyp support
This cl adds a hypervisor backend trait to make it easier to support
different hypervisors in the future for both Rialto and pvmfw
(e.g. aosp/2479400).
Test: m pvmfw_img
Bug: 272226230
Change-Id: I0a1b568f37b819c047ae3b09048a791cb40f3372
diff --git a/pvmfw/src/memory.rs b/pvmfw/src/memory.rs
index fde3f9b..3f44f8a 100644
--- a/pvmfw/src/memory.rs
+++ b/pvmfw/src/memory.rs
@@ -29,7 +29,7 @@
use core::ops::Range;
use core::ptr::NonNull;
use core::result;
-use hyp::{hyp_meminfo, mem_share, mem_unshare, mmio_guard};
+use hyp::{get_hypervisor, mmio_guard};
use log::error;
use tinyvec::ArrayVec;
@@ -283,7 +283,7 @@
.expect("Memory protection granule was not a power of two")..range.end)
.step_by(granule)
{
- mem_share(base as u64)?;
+ get_hypervisor().mem_share(base as u64)?;
}
Ok(())
}
@@ -296,7 +296,7 @@
.expect("Memory protection granule was not a power of two")..range.end)
.step_by(granule)
{
- mem_unshare(base as u64)?;
+ get_hypervisor().mem_unshare(base as u64)?;
}
Ok(())
}
@@ -354,7 +354,7 @@
/// Panics if `size` is 0.
fn shared_buffer_layout(size: usize) -> smccc::Result<Layout> {
assert_ne!(size, 0);
- let granule = hyp_meminfo()? as usize;
+ let granule = get_hypervisor().memory_protection_granule()?;
let allocated_size =
align_up(size, granule).expect("Memory protection granule was not a power of two");
Ok(Layout::from_size_align(allocated_size, granule).unwrap())