Add physical and virtual address types
Create wrapper types for physical and virtual address to limit available
operations on addresses and to be able to require explicit address types
for given function parameters.
Signed-off-by: Imre Kis <imre.kis@arm.com>
Change-Id: Iaef5ab1af24fc153d959d79404b3827d9c85bf53
diff --git a/src/kernel_space.rs b/src/kernel_space.rs
index d0a52a2..1069c1c 100644
--- a/src/kernel_space.rs
+++ b/src/kernel_space.rs
@@ -9,6 +9,7 @@
use spin::Mutex;
use super::{
+ address::{PhysicalAddress, VirtualAddress, VirtualAddressRange},
page_pool::{Page, PagePool},
MemoryAccessRights, Xlat, XlatError,
};
@@ -36,10 +37,9 @@
/// * page_pool: Page pool for allocation kernel translation tables
pub fn new(page_pool: PagePool) -> Self {
Self {
- xlat: Arc::new(Mutex::new(Xlat::new(
- page_pool,
- 0x0000_0000..0x10_0000_0000,
- ))),
+ xlat: Arc::new(Mutex::new(Xlat::new(page_pool, unsafe {
+ VirtualAddressRange::from_range(0x0000_0000..0x10_0000_0000)
+ }))),
}
}
@@ -56,16 +56,19 @@
) -> Result<(), XlatError> {
let mut xlat = self.xlat.lock();
+ let code_pa = PhysicalAddress(code_range.start);
+ let data_pa = PhysicalAddress(data_range.start);
+
xlat.map_physical_address_range(
- Some(code_range.start),
- code_range.start,
+ Some(code_pa.identity_va()),
+ code_pa,
code_range.len(),
MemoryAccessRights::RX | MemoryAccessRights::GLOBAL,
)?;
xlat.map_physical_address_range(
- Some(data_range.start),
- data_range.start,
+ Some(data_pa.identity_va()),
+ data_pa,
data_range.len(),
MemoryAccessRights::RW | MemoryAccessRights::GLOBAL,
)?;
@@ -86,14 +89,16 @@
length: usize,
access_rights: MemoryAccessRights,
) -> Result<usize, XlatError> {
+ let pa = PhysicalAddress(pa);
+
let lower_va = self.xlat.lock().map_physical_address_range(
- Some(pa),
+ Some(pa.identity_va()),
pa,
length,
access_rights | MemoryAccessRights::GLOBAL,
)?;
- Ok(Self::pa_to_kernel(lower_va as u64) as usize)
+ Ok(Self::pa_to_kernel(lower_va.0 as u64) as usize)
}
/// Unmap memory range from the kernel address space
@@ -103,9 +108,10 @@
/// # Return value
/// The result of the operation
pub fn unmap_memory(&self, va: usize, length: usize) -> Result<(), XlatError> {
- self.xlat
- .lock()
- .unmap_virtual_address_range(Self::kernel_to_pa(va as u64) as usize, length)
+ self.xlat.lock().unmap_virtual_address_range(
+ VirtualAddress(Self::kernel_to_pa(va as u64) as usize),
+ length,
+ )
}
/// Activate kernel address space mapping