Merge changes Id552d6dc,I417e197f

* changes:
  pvmfw: Issue MMIO_GUARD_ENROLL before UART setup
  pvmfw: smccc: Move MMIO_GUARD HVCs to mmio_guard
diff --git a/pvmfw/src/mmio_guard.rs b/pvmfw/src/mmio_guard.rs
index 4cde737..421f2c4 100644
--- a/pvmfw/src/mmio_guard.rs
+++ b/pvmfw/src/mmio_guard.rs
@@ -20,6 +20,8 @@
 
 #[derive(Debug, Clone)]
 pub enum Error {
+    /// Failed the necessary MMIO_GUARD_ENROLL call.
+    EnrollFailed(smccc::Error),
     /// Failed to obtain the MMIO_GUARD granule size.
     InfoFailed(smccc::Error),
     /// Failed to MMIO_GUARD_MAP a page.
@@ -33,6 +35,7 @@
 impl fmt::Display for Error {
     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::MapFailed(e) => write!(f, "Failed to MMIO_GUARD map: {e}"),
             Self::UnsupportedGranule(g) => write!(f, "Unsupported MMIO_GUARD granule: {g}"),
@@ -41,7 +44,8 @@
 }
 
 pub fn init() -> Result<()> {
-    let mmio_granule = smccc::mmio_guard_info().map_err(Error::InfoFailed)? as usize;
+    mmio_guard_enroll().map_err(Error::EnrollFailed)?;
+    let mmio_granule = mmio_guard_info().map_err(Error::InfoFailed)? as usize;
     if mmio_granule != helpers::SIZE_4KB {
         return Err(Error::UnsupportedGranule(mmio_granule));
     }
@@ -49,5 +53,27 @@
 }
 
 pub fn map(addr: usize) -> Result<()> {
-    smccc::mmio_guard_map(helpers::page_4kb_of(addr) as u64).map_err(Error::MapFailed)
+    mmio_guard_map(helpers::page_4kb_of(addr) as u64).map_err(Error::MapFailed)
+}
+
+fn mmio_guard_info() -> smccc::Result<u64> {
+    const VENDOR_HYP_KVM_MMIO_GUARD_INFO_FUNC_ID: u32 = 0xc6000005;
+    let args = [0u64; 17];
+
+    smccc::checked_hvc64(VENDOR_HYP_KVM_MMIO_GUARD_INFO_FUNC_ID, args)
+}
+
+fn mmio_guard_enroll() -> smccc::Result<()> {
+    const VENDOR_HYP_KVM_MMIO_GUARD_ENROLL_FUNC_ID: u32 = 0xc6000006;
+    let args = [0u64; 17];
+
+    smccc::checked_hvc64_expect_zero(VENDOR_HYP_KVM_MMIO_GUARD_ENROLL_FUNC_ID, args)
+}
+
+fn mmio_guard_map(ipa: u64) -> smccc::Result<()> {
+    const VENDOR_HYP_KVM_MMIO_GUARD_MAP_FUNC_ID: u32 = 0xc6000007;
+    let mut args = [0u64; 17];
+    args[0] = ipa;
+
+    smccc::checked_hvc64_expect_zero(VENDOR_HYP_KVM_MMIO_GUARD_MAP_FUNC_ID, args)
 }
diff --git a/pvmfw/src/smccc.rs b/pvmfw/src/smccc.rs
index 18128e1..f92c076 100644
--- a/pvmfw/src/smccc.rs
+++ b/pvmfw/src/smccc.rs
@@ -75,43 +75,21 @@
     }
 }
 
-type Result<T> = result::Result<T, Error>;
+pub type Result<T> = result::Result<T, Error>;
 
-fn check_smccc_err(ret: i64) -> Result<()> {
-    match check_smccc_value(ret)? {
+pub fn checked_hvc64_expect_zero(function: u32, args: [u64; 17]) -> Result<()> {
+    match checked_hvc64(function, args)? {
         0 => Ok(()),
         v => Err(Error::Unexpected(v)),
     }
 }
 
-fn check_smccc_value(ret: i64) -> Result<u64> {
-    match ret {
-        x if x >= 0 => Ok(ret as u64),
+pub fn checked_hvc64(function: u32, args: [u64; 17]) -> Result<u64> {
+    match hvc64(function, args)[0] as i64 {
+        ret if ret >= 0 => Ok(ret as u64),
         -1 => Err(Error::NotSupported),
         -2 => Err(Error::NotRequired),
         -3 => Err(Error::InvalidParameter),
-        _ => Err(Error::Unknown(ret)),
+        ret => Err(Error::Unknown(ret)),
     }
 }
-
-const VENDOR_HYP_KVM_MMIO_GUARD_INFO_FUNC_ID: u32 = 0xc6000005;
-const VENDOR_HYP_KVM_MMIO_GUARD_MAP_FUNC_ID: u32 = 0xc6000007;
-
-/// Issue pKVM-specific MMIO_GUARD_INFO HVC64.
-pub fn mmio_guard_info() -> Result<u64> {
-    let args = [0u64; 17];
-
-    let res = hvc64(VENDOR_HYP_KVM_MMIO_GUARD_INFO_FUNC_ID, args);
-
-    check_smccc_value(res[0] as i64)
-}
-
-/// Issue pKVM-specific MMIO_GUARD_MAP HVC64.
-pub fn mmio_guard_map(ipa: u64) -> Result<()> {
-    let mut args = [0u64; 17];
-    args[0] = ipa;
-
-    let res = hvc64(VENDOR_HYP_KVM_MMIO_GUARD_MAP_FUNC_ID, args);
-
-    check_smccc_err(res[0] as i64)
-}