Skip to content

Commit a77817f

Browse files
IsaacWoodsA0lsonrcerc
committed
Improve the documentation for PhysicalMapping
There has been a fair amount of confusion surrounding how to correctly map physical memory requested by `rsdp` and `acpi`, and especially the meaning of the fields on `PhysicalMapping`. This adds more info around the meaning of each field, based off A0lson's PR #162. Co-authored-by: Alex Olson <[email protected]> Co-authored-by: rcerc <[email protected]>
1 parent c6f3327 commit a77817f

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

rsdp/src/handler.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use core::{ops::Deref, ptr::NonNull};
33
/// Describes a physical mapping created by `AcpiHandler::map_physical_region` and unmapped by
44
/// `AcpiHandler::unmap_physical_region`. The region mapped must be at least `size_of::<T>()`
55
/// bytes, but may be bigger.
6+
///
7+
/// See `PhysicalMapping::new` for the meaning of each field.
68
#[derive(Debug)]
79
pub struct PhysicalMapping<H, T>
810
where
@@ -20,15 +22,17 @@ where
2022
H: AcpiHandler,
2123
{
2224
/// Construct a new `PhysicalMapping`.
23-
/// `mapped_length` may differ from `region_length` if padding is added for alignment.
2425
///
25-
/// ## Safety
26-
///
27-
/// This function must only be called by an `AcpiHandler` of type `H` to make sure that it's safe to unmap the mapping.
28-
///
29-
/// - `virtual_start` must be a valid pointer.
30-
/// - `region_length` must be equal to or larger than `size_of::<T>()`.
31-
/// - `handler` must be the same `AcpiHandler` that created the mapping.
26+
/// - `physical_start` should be the physical address of the structure to be mapped.
27+
/// - `virtual_start` should be the corresponding virtual address of that structure. It may differ from the
28+
/// start of the region mapped due to requirements of the paging system. It must be a valid, non-null
29+
/// pointer.
30+
/// - `region_length` should be the number of bytes requested to be mapped. It must be equal to or larger than
31+
/// `size_of::<T>()`.
32+
/// - `mapped_length` should be the number of bytes mapped to fulfill the request. It may be equal to or larger
33+
/// than `region_length`, due to requirements of the paging system or other reasoning.
34+
/// - `handler` should be the same `AcpiHandler` that created the mapping. When the `PhysicalMapping` is
35+
/// dropped, it will be used to unmap the structure.
3236
pub unsafe fn new(
3337
physical_start: usize,
3438
virtual_start: NonNull<T>,
@@ -93,6 +97,9 @@ pub trait AcpiHandler: Clone {
9397
/// implementation may need to map more than `size` bytes. The virtual address the region is mapped to does not
9498
/// matter, as long as it is accessible to `acpi`.
9599
///
100+
/// See the documentation on `PhysicalMapping::new` for an explanation of each field on the `PhysicalMapping`
101+
/// return type.
102+
///
96103
/// ## Safety
97104
///
98105
/// - `physical_address` must point to a valid `T` in physical memory.

0 commit comments

Comments
 (0)