vm-allocator: Add page size related functions

To avoid code duplication extract page related functions to their
own module and add utility functions for manipulating addresses
related to page sizes

Signed-off-by: Jianyong Wu <jianyong.wu@arm.com>
This commit is contained in:
Jianyong Wu
2023-06-02 03:02:52 +00:00
committed by Bo Chen
parent 8a8fe39c99
commit 42ad38d28c
3 changed files with 43 additions and 10 deletions

View File

@@ -14,14 +14,7 @@ use crate::gsi::GsiAllocator;
#[cfg(target_arch = "x86_64")]
use crate::gsi::GsiApic;
use libc::{sysconf, _SC_PAGESIZE};
/// Safe wrapper for `sysconf(_SC_PAGESIZE)`.
#[inline(always)]
fn pagesize() -> usize {
// SAFETY: FFI call. Trivially safe.
unsafe { sysconf(_SC_PAGESIZE) as usize }
}
use crate::page_size::get_page_size;
/// Manages allocating system resources such as address space and interrupt numbers.
///
@@ -126,7 +119,7 @@ impl SystemAllocator {
self.platform_mmio_address_space.allocate(
address,
size,
Some(align_size.unwrap_or(pagesize() as u64)),
Some(align_size.unwrap_or(get_page_size())),
)
}
@@ -140,7 +133,7 @@ impl SystemAllocator {
self.mmio_hole_address_space.allocate(
address,
size,
Some(align_size.unwrap_or(pagesize() as u64)),
Some(align_size.unwrap_or(get_page_size())),
)
}