[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/libs/hyp/src/mmio_guard.rs b/libs/hyp/src/mmio_guard.rs
index 512eb88..84dac64 100644
--- a/libs/hyp/src/mmio_guard.rs
+++ b/libs/hyp/src/mmio_guard.rs
@@ -14,7 +14,7 @@
 
 //! Safe MMIO_GUARD support.
 
-use crate::hypervisor::{mmio_guard_enroll, mmio_guard_info, mmio_guard_map, mmio_guard_unmap};
+use crate::hypervisor::get_hypervisor;
 use crate::util::{page_address, SIZE_4KB};
 use core::{fmt, result};
 
@@ -24,7 +24,7 @@
     /// Failed the necessary MMIO_GUARD_ENROLL call.
     EnrollFailed(smccc::Error),
     /// Failed to obtain the MMIO_GUARD granule size.
-    InfoFailed(smccc::Error),
+    GranuleQueryFailed(smccc::Error),
     /// Failed to MMIO_GUARD_MAP a page.
     MapFailed(smccc::Error),
     /// Failed to MMIO_GUARD_UNMAP a page.
@@ -37,7 +37,7 @@
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         match self {
             Self::EnrollFailed(e) => write!(f, "Failed to enroll into MMIO_GUARD: {e}"),
-            Self::InfoFailed(e) => write!(f, "Failed to get the MMIO_GUARD granule: {e}"),
+            Self::GranuleQueryFailed(e) => write!(f, "Failed to get the MMIO_GUARD granule: {e}"),
             Self::MapFailed(e) => write!(f, "Failed to MMIO_GUARD map: {e}"),
             Self::UnmapFailed(e) => write!(f, "Failed to MMIO_GUARD unmap: {e}"),
             Self::UnsupportedGranule(g) => write!(f, "Unsupported MMIO_GUARD granule: {g}"),
@@ -50,8 +50,9 @@
 
 /// Initializes the hypervisor by enrolling a MMIO guard and checking the memory granule size.
 pub fn init() -> Result<()> {
-    mmio_guard_enroll().map_err(Error::EnrollFailed)?;
-    let mmio_granule = mmio_guard_info().map_err(Error::InfoFailed)? as usize;
+    let hyp = get_hypervisor();
+    hyp.mmio_guard_enroll().map_err(Error::EnrollFailed)?;
+    let mmio_granule = hyp.mmio_guard_granule().map_err(Error::GranuleQueryFailed)?;
     if mmio_granule != SIZE_4KB {
         return Err(Error::UnsupportedGranule(mmio_granule));
     }
@@ -60,10 +61,10 @@
 
 /// Maps a memory address to the hypervisor MMIO guard.
 pub fn map(addr: usize) -> Result<()> {
-    mmio_guard_map(page_address(addr)).map_err(Error::MapFailed)
+    get_hypervisor().mmio_guard_map(page_address(addr)).map_err(Error::MapFailed)
 }
 
 /// Unmaps a memory address from the hypervisor MMIO guard.
 pub fn unmap(addr: usize) -> Result<()> {
-    mmio_guard_unmap(page_address(addr)).map_err(Error::UnmapFailed)
+    get_hypervisor().mmio_guard_unmap(page_address(addr)).map_err(Error::UnmapFailed)
 }