hyp: Introduce HypervisorCap::MMIO_GUARD

Similarly to DYNAMIC_MEM_SHARE, introduce a capability that client code
can check before calling MMIO_GUARD functions. This will remove the need
to implement stubs in the backends due to client code unconditionally
calling the functions.

Note that KvmHypervisor currently covers both pKVM and non-protected KVM
and will therefore have HypervisorCap::MMIO_GUARD, for now. As the only
client code that makes use of MMIO_GUARD and is intended to run on both
pKVM and regular KVM, Rialto, already deals with the distinction, this
patch doesn't deal with differentiating between the two modes, which is
done in a following patch.

No functional change intended.

Test: atest DebugPolicyHostTests#testNoAdbInDebugPolicy_withDebugLevelNone_boots
Test: atest rialto_test vmbase_example.integration_test
Change-Id: If45d31e65b2407deaf4df16cd4d354ccd6bf4506
diff --git a/pvmfw/src/entry.rs b/pvmfw/src/entry.rs
index 3d2fea8..a35e945 100644
--- a/pvmfw/src/entry.rs
+++ b/pvmfw/src/entry.rs
@@ -197,15 +197,17 @@
     // Use debug!() to avoid printing to the UART if we failed to configure it as only local
     // builds that have tweaked the logger::init() call will actually attempt to log the message.
 
-    get_hypervisor().mmio_guard_init().map_err(|e| {
-        debug!("{e}");
-        RebootReason::InternalError
-    })?;
+    if get_hypervisor().has_cap(HypervisorCap::MMIO_GUARD) {
+        get_hypervisor().mmio_guard_init().map_err(|e| {
+            debug!("{e}");
+            RebootReason::InternalError
+        })?;
 
-    get_hypervisor().mmio_guard_map(console::BASE_ADDRESS).map_err(|e| {
-        debug!("Failed to configure the UART: {e}");
-        RebootReason::InternalError
-    })?;
+        get_hypervisor().mmio_guard_map(console::BASE_ADDRESS).map_err(|e| {
+            debug!("Failed to configure the UART: {e}");
+            RebootReason::InternalError
+        })?;
+    }
 
     crypto::init();
 
@@ -253,10 +255,12 @@
     })?;
     // Call unshare_all_memory here (instead of relying on the dtor) while UART is still mapped.
     MEMORY.lock().as_mut().unwrap().unshare_all_memory();
-    get_hypervisor().mmio_guard_unmap(console::BASE_ADDRESS).map_err(|e| {
-        error!("Failed to unshare the UART: {e}");
-        RebootReason::InternalError
-    })?;
+    if get_hypervisor().has_cap(HypervisorCap::MMIO_GUARD) {
+        get_hypervisor().mmio_guard_unmap(console::BASE_ADDRESS).map_err(|e| {
+            error!("Failed to unshare the UART: {e}");
+            RebootReason::InternalError
+        })?;
+    }
 
     // Drop MemoryTracker and deactivate page table.
     drop(MEMORY.lock().take());