sel4/vspace.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
//
// Copyright 2023, Colias Group, LLC
// Copyright (c) 2020 Arm Limited
//
// SPDX-License-Identifier: MIT
//
use crate::{
cap_type, CapType, CapTypeForObjectOfFixedSize, FrameObjectType, TranslationTableObjectType,
};
impl FrameObjectType {
pub const fn bits(self) -> usize {
self.blueprint().physical_size_bits()
}
pub const fn bytes(self) -> usize {
1 << self.bits()
}
}
/// Trait for [`CapType`]s which correspond to frame objects.
pub trait CapTypeForFrameObject: CapType {}
impl CapTypeForFrameObject for cap_type::UnspecifiedPage {}
/// Trait for [`CapType`]s which correspond to frame objects of fixed size.
pub trait CapTypeForFrameObjectOfFixedSize:
CapTypeForObjectOfFixedSize + CapTypeForFrameObject
{
const FRAME_OBJECT_TYPE: FrameObjectType;
}
/// Trait for [`CapType`]s which correspond to translation table objects.
pub trait CapTypeForTranslationTableObject: CapTypeForObjectOfFixedSize {
const TRANSLATION_TABLE_OBJECT_TYPE: TranslationTableObjectType;
}
/// Items describing the layout of address translation structures for this kernel configuration.
pub mod vspace_levels {
use crate::{FrameObjectType, TranslationTableObjectType};
/// The maximum number of levels of translation tables for this kernel configuration.
pub use crate::arch::vspace_levels::NUM_LEVELS;
/// Highest level of translation table whose entries can be pages rather than lower-level translation tables.
pub use crate::arch::vspace_levels::HIGHEST_LEVEL_WITH_PAGE_ENTRIES;
/// The number of address bits spanned by the given translation table level.
pub fn span_bits(level: usize) -> usize {
assert!(level < NUM_LEVELS);
(level..NUM_LEVELS)
.map(|level| {
TranslationTableObjectType::from_level(level)
.unwrap()
.index_bits()
})
.sum::<usize>()
+ FrameObjectType::GRANULE.bits()
}
/// The number of address bits spanned by entries of the given translation table level.
pub fn step_bits(level: usize) -> usize {
span_bits(level)
- TranslationTableObjectType::from_level(level)
.unwrap()
.index_bits()
}
}