Merge "pvmfw: smccc: Print error codes in hex format"
diff --git a/pvmfw/src/exceptions.rs b/pvmfw/src/exceptions.rs
index 0fb2911..03fc220 100644
--- a/pvmfw/src/exceptions.rs
+++ b/pvmfw/src/exceptions.rs
@@ -20,14 +20,14 @@
 use vmbase::{console::emergency_write_str, eprintln, power::reboot};
 
 const ESR_32BIT_EXT_DABT: u64 = 0x96000010;
-const UART_PAGE: u64 = page_4kb_of(console::BASE_ADDRESS as u64);
+const UART_PAGE: usize = page_4kb_of(console::BASE_ADDRESS);
 
 #[no_mangle]
 extern "C" fn sync_exception_current(_elr: u64, _spsr: u64) {
     let esr = read_esr();
     let far = read_far();
     // Don't print to the UART if we're handling the exception it could raise.
-    if esr != ESR_32BIT_EXT_DABT || page_4kb_of(far) != UART_PAGE {
+    if esr != ESR_32BIT_EXT_DABT || page_4kb_of(far as usize) != UART_PAGE {
         emergency_write_str("sync_exception_current\n");
         print_esr(esr);
     }
diff --git a/pvmfw/src/helpers.rs b/pvmfw/src/helpers.rs
index 781c1ac..ac3a48e 100644
--- a/pvmfw/src/helpers.rs
+++ b/pvmfw/src/helpers.rs
@@ -14,13 +14,15 @@
 
 //! Miscellaneous helper functions.
 
+pub const SIZE_4KB: usize = 4 << 10;
+
 /// Computes the address of the page containing a given address.
-pub const fn page_of(addr: u64, page_size: u64) -> u64 {
+pub const fn page_of(addr: usize, page_size: usize) -> usize {
     addr & !(page_size - 1)
 }
 
 /// Validates a page size and computes the address of the page containing a given address.
-pub const fn checked_page_of(addr: u64, page_size: u64) -> Option<u64> {
+pub const fn checked_page_of(addr: usize, page_size: usize) -> Option<usize> {
     if page_size.is_power_of_two() {
         Some(page_of(addr, page_size))
     } else {
@@ -29,8 +31,6 @@
 }
 
 /// Computes the address of the 4KiB page containing a given address.
-pub const fn page_4kb_of(addr: u64) -> u64 {
-    const PAGE_SIZE: u64 = 4 << 10;
-
-    page_of(addr, PAGE_SIZE)
+pub const fn page_4kb_of(addr: usize) -> usize {
+    page_of(addr, SIZE_4KB)
 }
diff --git a/pvmfw/src/main.rs b/pvmfw/src/main.rs
index eb97961..b9b01c8 100644
--- a/pvmfw/src/main.rs
+++ b/pvmfw/src/main.rs
@@ -43,10 +43,10 @@
 
 fn main(fdt_address: u64, payload_start: u64, payload_size: u64, arg3: u64) -> Result<(), Error> {
     // We need to inform the hypervisor that the MMIO page containing the UART may be shared back.
-    let uart = console::BASE_ADDRESS as u64;
     let mmio_granule = smccc::mmio_guard_info().map_err(|_| Error::FailedUartSetup)?;
-    let uart_page = checked_page_of(uart, mmio_granule).ok_or(Error::FailedUartSetup)?;
-    smccc::mmio_guard_map(uart_page).map_err(|_| Error::FailedUartSetup)?;
+    let uart_page = checked_page_of(console::BASE_ADDRESS, mmio_granule as usize)
+        .ok_or(Error::FailedUartSetup)?;
+    smccc::mmio_guard_map(uart_page as u64).map_err(|_| Error::FailedUartSetup)?;
 
     println!("pVM firmware");
     println!(
diff --git a/pvmfw/src/smccc.rs b/pvmfw/src/smccc.rs
index 7da6ead..18128e1 100644
--- a/pvmfw/src/smccc.rs
+++ b/pvmfw/src/smccc.rs
@@ -12,7 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-use core::fmt;
+use core::{fmt, result};
 
 // TODO(b/245889995): use psci-0.1.1 crate
 #[inline(always)]
@@ -75,14 +75,16 @@
     }
 }
 
-fn check_smccc_err(ret: i64) -> Result<(), Error> {
+type Result<T> = result::Result<T, Error>;
+
+fn check_smccc_err(ret: i64) -> Result<()> {
     match check_smccc_value(ret)? {
         0 => Ok(()),
         v => Err(Error::Unexpected(v)),
     }
 }
 
-fn check_smccc_value(ret: i64) -> Result<u64, Error> {
+fn check_smccc_value(ret: i64) -> Result<u64> {
     match ret {
         x if x >= 0 => Ok(ret as u64),
         -1 => Err(Error::NotSupported),
@@ -96,7 +98,7 @@
 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, Error> {
+pub fn mmio_guard_info() -> Result<u64> {
     let args = [0u64; 17];
 
     let res = hvc64(VENDOR_HYP_KVM_MMIO_GUARD_INFO_FUNC_ID, args);
@@ -105,7 +107,7 @@
 }
 
 /// Issue pKVM-specific MMIO_GUARD_MAP HVC64.
-pub fn mmio_guard_map(ipa: u64) -> Result<(), Error> {
+pub fn mmio_guard_map(ipa: u64) -> Result<()> {
     let mut args = [0u64; 17];
     args[0] = ipa;