use core::ops::{BitOr, BitOrAssign};
use r_efi::efi;
use super::{BootServices, boxed::BootServicesBox};
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum AllocType {
AnyPage,
MaxAddress(usize),
Address(usize),
}
#[derive(Debug)]
pub struct MemoryMap<'a, B: BootServices + ?Sized> {
pub descriptors: BootServicesBox<'a, [efi::MemoryDescriptor], B>,
pub map_key: usize,
pub descriptor_version: u32,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct MemoryAttribute(u64);
impl MemoryAttribute {
pub const UC: MemoryAttribute = MemoryAttribute(efi::MEMORY_UC);
pub const WC: MemoryAttribute = MemoryAttribute(efi::MEMORY_WC);
pub const WT: MemoryAttribute = MemoryAttribute(efi::MEMORY_WT);
pub const WB: MemoryAttribute = MemoryAttribute(efi::MEMORY_WB);
pub const UCE: MemoryAttribute = MemoryAttribute(efi::MEMORY_UCE);
pub const WP: MemoryAttribute = MemoryAttribute(efi::MEMORY_WP);
pub const RP: MemoryAttribute = MemoryAttribute(efi::MEMORY_RP);
pub const XP: MemoryAttribute = MemoryAttribute(efi::MEMORY_XP);
pub const NV: MemoryAttribute = MemoryAttribute(efi::MEMORY_NV);
pub const MORE_RELIABLE: MemoryAttribute = MemoryAttribute(efi::MEMORY_MORE_RELIABLE);
pub const RO: MemoryAttribute = MemoryAttribute(efi::MEMORY_RO);
pub const SP: MemoryAttribute = MemoryAttribute(efi::MEMORY_SP);
pub const CPU_CRYPTO: MemoryAttribute = MemoryAttribute(efi::MEMORY_CPU_CRYPTO);
pub const RUNTIME: MemoryAttribute = MemoryAttribute(efi::MEMORY_RUNTIME);
pub const ISA_VALID: MemoryAttribute = MemoryAttribute(efi::MEMORY_ISA_VALID);
pub const ISA_MASK: MemoryAttribute = MemoryAttribute(efi::MEMORY_ISA_MASK);
}
impl BitOr for MemoryAttribute {
type Output = MemoryAttribute;
fn bitor(self, rhs: Self) -> Self::Output {
MemoryAttribute(self.0 | rhs.0)
}
}
impl BitOrAssign for MemoryAttribute {
fn bitor_assign(&mut self, rhs: Self) {
self.0 |= rhs.0
}
}
impl From<AllocType> for efi::AllocateType {
fn from(val: AllocType) -> Self {
match val {
AllocType::AnyPage => efi::ALLOCATE_ANY_PAGES,
AllocType::MaxAddress(_) => efi::ALLOCATE_MAX_ADDRESS,
AllocType::Address(_) => efi::ALLOCATE_ADDRESS,
}
}
}
impl From<MemoryAttribute> for u64 {
fn from(val: MemoryAttribute) -> Self {
val.0
}
}