[vmbase] Move SwiotlbInfo from pvmfw to vmbase
for reuse in both pvmfw and rialto to init shared memory.
Bug: 284462758
Test: m pvmfw_img
Change-Id: Ibe7b8b1bb8d10fbbdc4ec3348e801084c9a93bfd
diff --git a/pvmfw/src/crypto.rs b/pvmfw/src/crypto.rs
index d607bee..3d9c8d1 100644
--- a/pvmfw/src/crypto.rs
+++ b/pvmfw/src/crypto.rs
@@ -21,8 +21,6 @@
use core::num::NonZeroU32;
use core::ptr;
-use crate::cstr;
-
use bssl_ffi::CRYPTO_library_init;
use bssl_ffi::ERR_get_error_line;
use bssl_ffi::ERR_lib_error_string;
@@ -37,6 +35,7 @@
use bssl_ffi::EVP_AEAD;
use bssl_ffi::EVP_AEAD_CTX;
use bssl_ffi::HKDF;
+use vmbase::cstr;
#[derive(Debug)]
pub struct Error {
diff --git a/pvmfw/src/dice.rs b/pvmfw/src/dice.rs
index 3116456..fbab013 100644
--- a/pvmfw/src/dice.rs
+++ b/pvmfw/src/dice.rs
@@ -14,17 +14,16 @@
//! Support for DICE derivation and BCC generation.
-use crate::cstr;
use core::ffi::c_void;
use core::mem::size_of;
use core::slice;
-use vmbase::memory::flushed_zeroize;
-
use diced_open_dice::{
bcc_format_config_descriptor, bcc_handover_main_flow, hash, Config, DiceMode, Hash,
InputValues, HIDDEN_SIZE,
};
use pvmfw_avb::{DebugLevel, Digest, VerifiedBootData};
+use vmbase::cstr;
+use vmbase::memory::flushed_zeroize;
fn to_dice_mode(debug_level: DebugLevel) -> DiceMode {
match debug_level {
diff --git a/pvmfw/src/fdt.rs b/pvmfw/src/fdt.rs
index d4c8385..b5b1958 100644
--- a/pvmfw/src/fdt.rs
+++ b/pvmfw/src/fdt.rs
@@ -15,7 +15,6 @@
//! High-level FDT functions.
use crate::bootargs::BootArgsIterator;
-use crate::cstr;
use crate::helpers::GUEST_PAGE_SIZE;
use crate::Box;
use crate::RebootReason;
@@ -38,6 +37,8 @@
use log::info;
use log::warn;
use tinyvec::ArrayVec;
+use vmbase::cstr;
+use vmbase::fdt::SwiotlbInfo;
use vmbase::layout::{crosvm::MEM_START, MAX_VIRT_ADDR};
use vmbase::memory::SIZE_4KB;
use vmbase::util::flatten;
@@ -430,36 +431,6 @@
Ok(())
}
-#[derive(Debug)]
-pub struct SwiotlbInfo {
- addr: Option<usize>,
- size: usize,
- align: Option<usize>,
-}
-
-impl SwiotlbInfo {
- /// Creates a `SwiotlbInfo` struct from the given device tree.
- pub fn new_from_fdt(fdt: &Fdt) -> libfdt::Result<SwiotlbInfo> {
- let node =
- fdt.compatible_nodes(cstr!("restricted-dma-pool"))?.next().ok_or(FdtError::NotFound)?;
-
- let (addr, size, align) = if let Some(mut reg) = node.reg()? {
- let reg = reg.next().ok_or(FdtError::NotFound)?;
- let size = reg.size.ok_or(FdtError::NotFound)?;
- (Some(reg.addr.try_into().unwrap()), size.try_into().unwrap(), None)
- } else {
- let size = node.getprop_u64(cstr!("size"))?.ok_or(FdtError::NotFound)?;
- let align = node.getprop_u64(cstr!("alignment"))?.ok_or(FdtError::NotFound)?;
- (None, size.try_into().unwrap(), Some(align.try_into().unwrap()))
- };
- Ok(Self { addr, size, align })
- }
-
- pub fn fixed_range(&self) -> Option<Range<usize>> {
- self.addr.map(|addr| addr..addr + self.size)
- }
-}
-
fn validate_swiotlb_info(
swiotlb_info: &SwiotlbInfo,
memory: &Range<usize>,
diff --git a/pvmfw/src/helpers.rs b/pvmfw/src/helpers.rs
index 5ad721e..8981408 100644
--- a/pvmfw/src/helpers.rs
+++ b/pvmfw/src/helpers.rs
@@ -18,11 +18,3 @@
pub const GUEST_PAGE_SIZE: usize = SIZE_4KB;
pub const PVMFW_PAGE_SIZE: usize = PAGE_SIZE;
-
-/// Create &CStr out of &str literal
-#[macro_export]
-macro_rules! cstr {
- ($str:literal) => {{
- core::ffi::CStr::from_bytes_with_nul(concat!($str, "\0").as_bytes()).unwrap()
- }};
-}