Introduce KernelAddressTranslator trait
Add KernelAddressTranslator as a generic parameter of Xlat in order to
decouple dependency on KernelSpace. This trait is used for translating
between physical addresses and virtual addresses of the running kernel
context. Xlat uses the trait for accessing the translation tables.
Signed-off-by: Imre Kis <imre.kis@arm.com>
Change-Id: Iaf4189429f21fced9d40e34fb309388165127124
diff --git a/src/region.rs b/src/region.rs
index d98afa5..1cba7c4 100644
--- a/src/region.rs
+++ b/src/region.rs
@@ -266,7 +266,19 @@
#[cfg(test)]
mod tests {
use super::*;
- use crate::page_pool::PagePoolArea;
+ use crate::{page_pool::PagePoolArea, KernelAddressTranslator};
+
+ struct DummyKernelAddressTranslator {}
+
+ impl KernelAddressTranslator for DummyKernelAddressTranslator {
+ fn kernel_to_pa(va: VirtualAddress) -> PhysicalAddress {
+ va.identity_pa()
+ }
+
+ fn pa_to_kernel(pa: PhysicalAddress) -> VirtualAddress {
+ pa.identity_va()
+ }
+ }
#[test]
#[should_panic]
@@ -282,7 +294,7 @@
static PAGE_POOL_AREA: PagePoolArea<16> = PagePoolArea::new();
let region = PhysicalRegion::Allocated(
- PagePool::new(&PAGE_POOL_AREA),
+ PagePool::new::<DummyKernelAddressTranslator, 16>(&PAGE_POOL_AREA),
Pages::new(PA.0, LENGTH, true),
);
assert_eq!(PA, region.get_pa());
@@ -722,7 +734,7 @@
#[test]
fn test_virtual_region_drop() {
static PAGE_POOL_AREA: PagePoolArea<8192> = PagePoolArea::new();
- let page_pool = PagePool::new(&PAGE_POOL_AREA);
+ let page_pool = PagePool::new::<DummyKernelAddressTranslator, 8192>(&PAGE_POOL_AREA);
let page = page_pool.allocate_pages(4096, None).unwrap();
let physical_region = PhysicalRegion::Allocated(page_pool, page);