1use crate::{
9 cap_type, CapType, CapTypeForObjectOfFixedSize, FrameObjectType, TranslationTableObjectType,
10};
11
12impl FrameObjectType {
13 pub const fn bits(self) -> usize {
14 self.blueprint().physical_size_bits()
15 }
16
17 pub const fn bytes(self) -> usize {
18 1 << self.bits()
19 }
20}
21
22pub trait CapTypeForFrameObject: CapType {}
24
25impl CapTypeForFrameObject for cap_type::UnspecifiedPage {}
26
27pub trait CapTypeForFrameObjectOfFixedSize:
29 CapTypeForObjectOfFixedSize + CapTypeForFrameObject
30{
31 const FRAME_OBJECT_TYPE: FrameObjectType;
32}
33
34pub trait CapTypeForTranslationTableObject: CapTypeForObjectOfFixedSize {
36 const TRANSLATION_TABLE_OBJECT_TYPE: TranslationTableObjectType;
37}
38
39pub mod vspace_levels {
41 use crate::{FrameObjectType, TranslationTableObjectType};
42
43 pub use crate::arch::vspace_levels::NUM_LEVELS;
45
46 pub use crate::arch::vspace_levels::HIGHEST_LEVEL_WITH_PAGE_ENTRIES;
48
49 pub fn span_bits(level: usize) -> usize {
51 assert!(level < NUM_LEVELS);
52 (level..NUM_LEVELS)
53 .map(|level| {
54 TranslationTableObjectType::from_level(level)
55 .unwrap()
56 .index_bits()
57 })
58 .sum::<usize>()
59 + FrameObjectType::GRANULE.bits()
60 }
61
62 pub fn step_bits(level: usize) -> usize {
64 span_bits(level)
65 - TranslationTableObjectType::from_level(level)
66 .unwrap()
67 .index_bits()
68 }
69}