sel4/arch/arm/
object.rs

1//
2// Copyright 2023, Colias Group, LLC
3// Copyright (c) 2020 Arm Limited
4//
5// SPDX-License-Identifier: MIT
6//
7
8use core::ffi::c_uint;
9
10use sel4_config::{sel4_cfg_enum, sel4_cfg_wrap_match};
11
12use crate::{
13    const_helpers::u32_into_usize, sys, ObjectBlueprint, ObjectBlueprintSeL4Arch, ObjectType,
14    ObjectTypeSeL4Arch,
15};
16
17/// Alias for [`ObjectTypeArm`].
18pub type ObjectTypeArch = ObjectTypeArm;
19
20/// Alias for [`ObjectBlueprintArm`].
21pub type ObjectBlueprintArch = ObjectBlueprintArm;
22
23/// Corresponds to `seL4_ArchObjectType`.
24#[sel4_cfg_enum]
25#[derive(Debug, Clone, Eq, PartialEq)]
26pub enum ObjectTypeArm {
27    SmallPage,
28    LargePage,
29    PT,
30    #[sel4_cfg(ARM_HYPERVISOR_SUPPORT)]
31    VCpu,
32    SeL4Arch(ObjectTypeSeL4Arch),
33}
34
35impl ObjectTypeArm {
36    pub(crate) const fn into_sys(self) -> c_uint {
37        sel4_cfg_wrap_match! {
38            match self {
39                Self::SmallPage => sys::_object::seL4_ARM_SmallPageObject,
40                Self::LargePage => sys::_object::seL4_ARM_LargePageObject,
41                Self::PT => sys::_object::seL4_ARM_PageTableObject,
42                #[sel4_cfg(ARM_HYPERVISOR_SUPPORT)]
43                Self::VCpu => sys::_object::seL4_ARM_VCPUObject,
44                Self::SeL4Arch(sel4_arch) => sel4_arch.into_sys(),
45            }
46        }
47    }
48}
49
50impl From<ObjectTypeSeL4Arch> for ObjectTypeArch {
51    fn from(ty: ObjectTypeSeL4Arch) -> Self {
52        Self::SeL4Arch(ty)
53    }
54}
55
56impl From<ObjectTypeSeL4Arch> for ObjectType {
57    fn from(ty: ObjectTypeSeL4Arch) -> Self {
58        Self::from(ObjectTypeArch::from(ty))
59    }
60}
61
62/// Arm-specific variants of [`ObjectBlueprint`].
63#[sel4_cfg_enum]
64#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
65pub enum ObjectBlueprintArm {
66    SmallPage,
67    LargePage,
68    PT,
69    #[sel4_cfg(ARM_HYPERVISOR_SUPPORT)]
70    VCpu,
71    SeL4Arch(ObjectBlueprintSeL4Arch),
72}
73
74impl ObjectBlueprintArm {
75    pub(crate) const fn ty(self) -> ObjectTypeArch {
76        sel4_cfg_wrap_match! {
77            match self {
78                Self::SmallPage => ObjectTypeArm::SmallPage,
79                Self::LargePage => ObjectTypeArm::LargePage,
80                Self::PT => ObjectTypeArm::PT,
81                #[sel4_cfg(ARM_HYPERVISOR_SUPPORT)]
82                Self::VCpu => ObjectTypeArm::VCpu,
83                Self::SeL4Arch(sel4_arch) => ObjectTypeArch::SeL4Arch(sel4_arch.ty()),
84            }
85        }
86    }
87
88    pub(crate) const fn physical_size_bits(self) -> usize {
89        sel4_cfg_wrap_match! {
90            match self {
91                Self::SmallPage => u32_into_usize(sys::seL4_PageBits),
92                Self::LargePage => u32_into_usize(sys::seL4_LargePageBits),
93                Self::PT => u32_into_usize(sys::seL4_PageTableBits),
94                #[sel4_cfg(ARM_HYPERVISOR_SUPPORT)]
95                Self::VCpu => u32_into_usize(sys::seL4_VCPUBits),
96                Self::SeL4Arch(sel4_arch) => sel4_arch.physical_size_bits(),
97            }
98        }
99    }
100}
101
102impl From<ObjectBlueprintSeL4Arch> for ObjectBlueprintArch {
103    fn from(blueprint: ObjectBlueprintSeL4Arch) -> Self {
104        Self::SeL4Arch(blueprint)
105    }
106}
107
108impl From<ObjectBlueprintSeL4Arch> for ObjectBlueprint {
109    fn from(ty: ObjectBlueprintSeL4Arch) -> Self {
110        Self::from(ObjectBlueprintArch::from(ty))
111    }
112}