[vmbase] Add crosvm layout constant MEM_START to vmbase

And uses it in pvmfw.

Other layout constants will be added in subsequent cls.

Bug: 284462758
Test: m pvmfw_img
Change-Id: If17f9a8da381cbdb2b13e0eb8be0bd409035eea9
diff --git a/pvmfw/src/fdt.rs b/pvmfw/src/fdt.rs
index 89d9457..a68cf3a 100644
--- a/pvmfw/src/fdt.rs
+++ b/pvmfw/src/fdt.rs
@@ -18,7 +18,6 @@
 use crate::cstr;
 use crate::helpers::RangeExt as _;
 use crate::helpers::GUEST_PAGE_SIZE;
-use crate::memory::BASE_ADDR;
 use crate::memory::MAX_ADDR;
 use crate::Box;
 use crate::RebootReason;
@@ -41,6 +40,7 @@
 use log::info;
 use log::warn;
 use tinyvec::ArrayVec;
+use vmbase::layout::crosvm::MEM_START;
 use vmbase::memory::SIZE_4KB;
 use vmbase::util::flatten;
 
@@ -115,8 +115,8 @@
 /// Check if memory range is ok
 fn validate_memory_range(range: &Range<usize>) -> Result<(), RebootReason> {
     let base = range.start;
-    if base != BASE_ADDR {
-        error!("Memory base address {:#x} is not {:#x}", base, BASE_ADDR);
+    if base != MEM_START {
+        error!("Memory base address {:#x} is not {:#x}", base, MEM_START);
         return Err(RebootReason::InvalidFdt);
     }
 
@@ -137,7 +137,7 @@
     let size = memory_range.len() as u64;
     fdt.node_mut(cstr!("/memory"))?
         .ok_or(FdtError::NotFound)?
-        .setprop_inplace(cstr!("reg"), flatten(&[BASE_ADDR.to_be_bytes(), size.to_be_bytes()]))
+        .setprop_inplace(cstr!("reg"), flatten(&[MEM_START.to_be_bytes(), size.to_be_bytes()]))
 }
 
 /// Read the number of CPUs from DT
diff --git a/pvmfw/src/memory.rs b/pvmfw/src/memory.rs
index 323ac74..30c11eb 100644
--- a/pvmfw/src/memory.rs
+++ b/pvmfw/src/memory.rs
@@ -37,7 +37,8 @@
 use spin::mutex::SpinMutex;
 use tinyvec::ArrayVec;
 use vmbase::{
-    dsb, isb, layout,
+    dsb, isb,
+    layout::{self, crosvm::MEM_START},
     memory::{
         flush_dirty_range, is_leaf_pte, page_4kb_of, set_dbm_enabled, MemorySharer, PageTable,
         MMIO_LAZY_MAP_FLAG, SIZE_2MB, SIZE_4KB, SIZE_4MB,
@@ -46,8 +47,6 @@
     util::align_up,
 };
 
-/// Base of the system's contiguous "main" memory.
-pub const BASE_ADDR: usize = 0x8000_0000;
 /// First address that can't be translated by a level 1 TTBR0_EL1.
 pub const MAX_ADDR: usize = 1 << 40;
 
@@ -148,7 +147,7 @@
 impl MemoryTracker {
     const CAPACITY: usize = 5;
     const MMIO_CAPACITY: usize = 5;
-    const PVMFW_RANGE: MemoryRange = (BASE_ADDR - SIZE_4MB)..BASE_ADDR;
+    const PVMFW_RANGE: MemoryRange = (MEM_START - SIZE_4MB)..MEM_START;
 
     /// Create a new instance from an active page table, covering the maximum RAM size.
     pub fn new(mut page_table: PageTable) -> Self {
@@ -164,7 +163,7 @@
         debug!("... Success!");
 
         Self {
-            total: BASE_ADDR..MAX_ADDR,
+            total: MEM_START..MAX_ADDR,
             page_table,
             regions: ArrayVec::new(),
             mmio_regions: ArrayVec::new(),
diff --git a/vmbase/src/layout/crosvm.rs b/vmbase/src/layout/crosvm.rs
new file mode 100644
index 0000000..66b9e44
--- /dev/null
+++ b/vmbase/src/layout/crosvm.rs
@@ -0,0 +1,20 @@
+// Copyright 2023, The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+//! Memory layout for crosvm for aarch64 architecture.
+//!
+//! https://crosvm.dev/book/appendix/memory_layout.html#common-layout
+
+/// The start of the system's contiguous "main" memory.
+pub const MEM_START: usize = 0x8000_0000;
diff --git a/vmbase/src/layout.rs b/vmbase/src/layout/mod.rs
similarity index 98%
rename from vmbase/src/layout.rs
rename to vmbase/src/layout/mod.rs
index 43bcb2c..dd3e0e0 100644
--- a/vmbase/src/layout.rs
+++ b/vmbase/src/layout/mod.rs
@@ -14,6 +14,8 @@
 
 //! Memory layout.
 
+pub mod crosvm;
+
 use crate::console::BASE_ADDRESS;
 use core::ops::Range;
 use core::ptr::addr_of;