Skip to content

Commit dd14f00

Browse files
committedJul 27, 2024
uefi: memory_map: streamline documentation
1 parent 3278e5d commit dd14f00

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed
 

‎uefi/src/mem/memory_map/api.rs

-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ use core::ops::{Index, IndexMut};
2727
///
2828
/// [0]: https://github.com/tianocore/edk2/blob/7142e648416ff5d3eac6c6d607874805f5de0ca8/MdeModulePkg/Core/PiSmmCore/Page.c#L1059
2929
pub trait MemoryMap: Debug + Index<usize, Output = MemoryDescriptor> {
30-
// TODO also require IntoIterator?! :)
31-
3230
/// Returns the associated [`MemoryMapMeta`].
3331
#[must_use]
3432
fn meta(&self) -> MemoryMapMeta;

‎uefi/src/mem/memory_map/impl_.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ impl IndexMut<usize> for MemoryMapRefMut<'_> {
201201
/// 1. create it using [`MemoryMapBackingMemory::new`]
202202
/// 2. pass it to [`BootServices::get_memory_map`]
203203
/// 3. construct a [`MemoryMapOwned`] from it
204+
///
205+
/// [`BootServices::get_memory_map`]: crate::table::boot::BootServices::get_memory_map
204206
#[derive(Debug)]
205207
#[allow(clippy::len_without_is_empty)] // this type is never empty
206208
pub(crate) struct MemoryMapBackingMemory(NonNull<[u8]>);
@@ -247,8 +249,9 @@ impl MemoryMapBackingMemory {
247249
}
248250

249251
/// Returns a "safe" best-effort size hint for the memory map size with
250-
/// some additional bytes in buffer compared to the [`crate::table::boot::mmap::MemoryMapMeta`].
251-
/// This helps
252+
/// some additional bytes in buffer compared to the [`MemoryMapMeta`]. This
253+
/// takes into account that, as you go, more (small) allocations might
254+
/// happen.
252255
#[must_use]
253256
fn safe_allocation_size_hint(mmm: MemoryMapMeta) -> usize {
254257
// Allocate space for extra entries beyond the current size of the

‎uefi/src/mem/memory_map/iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::*;
22

33
/// An iterator of [`MemoryDescriptor`]. The underlying memory map is always
4-
/// associated with a unique [`crate::table::boot::mmap::MemoryMapKey`].
4+
/// associated with a unique [`MemoryMapKey`].
55
#[derive(Debug, Clone)]
66
pub struct MemoryMapIter<'a> {
77
pub(crate) memory_map: &'a dyn MemoryMap,

‎uefi/src/mem/memory_map/mod.rs

+27-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,36 @@
1-
//! This module bundles all relevant types and helpers to work with the UEFI
2-
//! memory map. Specifically, it provides
1+
//! Bundles all relevant types and helpers to work with the UEFI memory map.
2+
//!
3+
//! To work with the memory map, you should use one of the structs
4+
//! [`MemoryMapOwned`], [`MemoryMapRef`], or [`MemoryMapRefMut`] - depending on
5+
//! your use-case. The traits [`MemoryMap`] and [`MemoryMapMut`] mainly exist
6+
//! to guarantee a streamlined API across these types. We recommend to work with
7+
//! the specific implementation.
8+
//!
9+
//! # Usecase: Obtain UEFI Memory Map
10+
//!
11+
//! You can use [`SystemTable::exit_boot_services`] or
12+
//! [`BootServices::memory_map`], which returns an properly initialized
13+
//! [`MemoryMapOwned`].
14+
//!
15+
//! # Usecase: Parse Memory Slice as UEFI Memory Map
16+
//!
17+
//! If you have a chunk of memory and want to parse it as UEFI memory map, which
18+
//! might be the case if a bootloader such as GRUB or Limine passes its boot
19+
//! information, you can use [`MemoryMapRef`] or [`MemoryMapRefMut`].
20+
//! TODO add constructors.
21+
//!
22+
//! # All relevant exports:
323
//!
424
//! - the traits [`MemoryMap`] and [`MemoryMapMut`],
525
//! - the trait implementations [`MemoryMapOwned`], [`MemoryMapRef`], and
626
//! [`MemoryMapRefMut`],
727
//! - the iterator [`MemoryMapIter`]
8-
//! - various associated helper types, such as [`MemoryMapKey`] and
28+
//! - various associated helper types, such as [`MemoryMapKey`] and
929
//! [`MemoryMapMeta`],
10-
//! - and re-exports the types [`MemoryDescriptor`], [`MemoryType`],
11-
//! [`MemoryAttribute`]
30+
//! - re-exports [`MemoryDescriptor`], [`MemoryType`], and [`MemoryAttribute`].
31+
//!
32+
//! [`SystemTable::exit_boot_services`]: uefi::table::SystemTable::exit_boot_services
33+
//! [`BootServices::memory_map`]: uefi::table::boot::BootServices::memory_map
1234
1335
mod api;
1436
mod impl_;

0 commit comments

Comments
 (0)
Please sign in to comment.