Skip to content

uefi-raw: Add more MemoryType constants #1253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions uefi-raw/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# uefi-raw - [Unreleased]

## Added
- New `MemoryType` constants: `UNACCEPTED`, `MAX`, `RESERVED_FOR_OEM`, and
`RESERVED_FOR_OS_LOADER`.


# uefi-raw - 0.6.0 (2024-07-02)

Expand Down
18 changes: 15 additions & 3 deletions uefi-raw/src/table/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::table::Header;
use crate::{Char16, Event, Guid, Handle, PhysicalAddress, Status, VirtualAddress};
use bitflags::bitflags;
use core::ffi::c_void;
use core::ops::RangeInclusive;

/// Table of pointers to all the boot services.
#[derive(Debug)]
Expand Down Expand Up @@ -381,11 +382,11 @@ newtype_enum! {
/// The type of a memory range.
///
/// UEFI allows firmwares and operating systems to introduce new memory types
/// in the 0x70000000..0xFFFFFFFF range. Therefore, we don't know the full set
/// in the `0x7000_0000..=0xFFFF_FFFF` range. Therefore, we don't know the full set
/// of memory types at compile time, and it is _not_ safe to model this C enum
/// as a Rust enum.
pub enum MemoryType: u32 => {
/// This enum variant is not used.
/// Not usable.
RESERVED = 0,
/// The code portions of a loaded UEFI application.
LOADER_CODE = 1,
Expand Down Expand Up @@ -421,10 +422,21 @@ pub enum MemoryType: u32 => {
PAL_CODE = 13,
/// Memory region which is usable and is also non-volatile.
PERSISTENT_MEMORY = 14,
/// Memory that must be accepted by the boot target before it can be used.
UNACCEPTED = 15,
/// End of the defined memory types. Higher values are possible though, see
/// [`MemoryType::RESERVED_FOR_OEM`] and [`MemoryType::RESERVED_FOR_OS_LOADER`].
MAX = 16,
}}

impl MemoryType {
/// Construct a custom `MemoryType`. Values in the range `0x80000000..=0xffffffff` are free for use if you are
/// Range reserved for OEM use.
pub const RESERVED_FOR_OEM: RangeInclusive<u32> = 0x7000_0000..=0x7fff_ffff;

/// Range reserved for OS loaders.
pub const RESERVED_FOR_OS_LOADER: RangeInclusive<u32> = 0x8000_0000..=0xffff_ffff;

/// Construct a custom `MemoryType`. Values in the range `0x8000_0000..=0xffff_ffff` are free for use if you are
/// an OS loader.
#[must_use]
pub const fn custom(value: u32) -> MemoryType {
Expand Down