#[repr(transparent)]pub struct Pa(usize);Expand description
Represents a physical address.
The Pa (Physical Address) struct is a wrapper around the usize type,
which represents a physical address in memory. It is used to handle
addresses that correspond directly to the hardware memory locations in the
physical address space.
This struct provides methods to:
- Create a new physical address with validation.
- Convert a physical address to a virtual address.
- Convert a physical address to a raw
usizetype.
§Example:
let pa = Pa::new(0x1234_5678_9ABC_DEF0).unwrap();
let kva = pa.into_kva(); // Convert to a kernel virtual address.Tuple Fields§
§0: usizeImplementations§
Source§impl Pa
impl Pa
Sourcepub const fn new(addr: usize) -> Option<Self>
pub const fn new(addr: usize) -> Option<Self>
Creates a new physical address if the address is valid.
This method attempts to create a new Pa instance by validating the
provided physical address. The address must be less than
0xffff_0000_0000_0000, which ensures it falls within the valid
physical address range.
§Arguments
addr: Ausizerepresenting the physical address.
§Returns
Some(Pa)if the address is valid.Noneif the address is outside the valid range.
§Example:
let pa = Pa::new(0x1234_5678_9ABC_DEF0);Sourcepub const fn into_usize(self) -> usize
pub const fn into_usize(self) -> usize
Cast the physical address into a raw usize.
This method allows the physical address to be cast into a raw usize
value, which can be used for low-level operations like pointer
arithmetic or addressing.
§Returns
- The underlying
usizevalue representing the physical address.
Sourcepub const fn into_kva(self) -> Kva
pub const fn into_kva(self) -> Kva
Convert the physical address to a virtual address.
This method allows you to convert a Pa (physical address) to a
[Kva] (kernel virtual address). The conversion uses a fixed offset
to transform the physical address into a corresponding kernel virtual
address.
§Returns
- The corresponding kernel virtual address as a [
Kva] instance.
§Example:
let pa = Pa::new(0x1234_5678_9ABC_DEF0).unwrap();
let va = pa.into_kva(); // Convert the physical address to kernel virtual addressSourcepub const fn offset(self) -> usize
pub const fn offset(self) -> usize
Extracts the page offset from the physical address.
This method retrieves the lower bits of the address that represent the offset within a memory page. The offset is useful when working with memory operations that need to determine the position within a page.
§Returns
- The offset within the page as a
usize.
§Example
let pa = Pa::new(0x1234_5678).unwrap();
let offset = pa.offset();
assert_eq!(offset, 0x678); // Example offset within the pageTrait Implementations§
Source§impl AddAssign<usize> for Pa
impl AddAssign<usize> for Pa
Source§fn add_assign(&mut self, other: usize)
fn add_assign(&mut self, other: usize)
+= operation. Read moreSource§impl BitAndAssign<usize> for Pa
impl BitAndAssign<usize> for Pa
Source§fn bitand_assign(&mut self, other: usize)
fn bitand_assign(&mut self, other: usize)
&= operation. Read moreSource§impl BitOrAssign<usize> for Pa
impl BitOrAssign<usize> for Pa
Source§fn bitor_assign(&mut self, other: usize)
fn bitor_assign(&mut self, other: usize)
|= operation. Read moreSource§impl Ord for Pa
impl Ord for Pa
Source§impl PartialOrd for Pa
impl PartialOrd for Pa
Source§impl SubAssign<usize> for Pa
impl SubAssign<usize> for Pa
Source§fn sub_assign(&mut self, other: usize)
fn sub_assign(&mut self, other: usize)
-= operation. Read moreimpl Copy for Pa
impl Eq for Pa
impl StructuralPartialEq for Pa
Auto Trait Implementations§
impl Freeze for Pa
impl RefUnwindSafe for Pa
impl Send for Pa
impl Sync for Pa
impl Unpin for Pa
impl UnwindSafe for Pa
Blanket Implementations§
§impl<T> Any for Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere
T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere
T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)