Pa

Struct Pa 

Source
#[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 usize type.

§Example:

let pa = Pa::new(0x1234_5678_9ABC_DEF0).unwrap();
let kva = pa.into_kva(); // Convert to a kernel virtual address.

Tuple Fields§

§0: usize

Implementations§

Source§

impl Pa

Source

pub const ZERO: Self

The physical address 0.

This constant represents the special address 0.

Source

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: A usize representing the physical address.
§Returns
  • Some(Pa) if the address is valid.
  • None if the address is outside the valid range.
§Example:
let pa = Pa::new(0x1234_5678_9ABC_DEF0);
Source

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 usize value representing the physical address.
Source

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 address
Source

pub const fn page_down(self) -> Self

Align down the physical address to the page boundary.

Source

pub const fn page_up(self) -> Self

Align up to the physical address to the page boundary.

Source

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 page

Trait Implementations§

Source§

impl Add<usize> for Pa

Source§

type Output = Pa

The resulting type after applying the + operator.
Source§

fn add(self, other: usize) -> Self::Output

Performs the + operation. Read more
Source§

impl AddAssign<usize> for Pa

Source§

fn add_assign(&mut self, other: usize)

Performs the += operation. Read more
Source§

impl BitAnd<usize> for Pa

Source§

type Output = Pa

The resulting type after applying the & operator.
Source§

fn bitand(self, other: usize) -> Self

Performs the & operation. Read more
Source§

impl BitAndAssign<usize> for Pa

Source§

fn bitand_assign(&mut self, other: usize)

Performs the &= operation. Read more
Source§

impl BitOr<usize> for Pa

Source§

type Output = Pa

The resulting type after applying the | operator.
Source§

fn bitor(self, other: usize) -> Self

Performs the | operation. Read more
Source§

impl BitOrAssign<usize> for Pa

Source§

fn bitor_assign(&mut self, other: usize)

Performs the |= operation. Read more
Source§

impl Clone for Pa

Source§

fn clone(&self) -> Pa

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Pa

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Pa

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Ord for Pa

Source§

fn cmp(&self, other: &Pa) -> Ordering

This method returns an [Ordering] between self and other. Read more
1.21.0§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Pa

Source§

fn eq(&self, other: &Pa) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Pa

Source§

fn partial_cmp(&self, other: &Pa) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Sub<usize> for Pa

Source§

type Output = Pa

The resulting type after applying the - operator.
Source§

fn sub(self, other: usize) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub for Pa

Source§

type Output = usize

The resulting type after applying the - operator.
Source§

fn sub(self, other: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl SubAssign<usize> for Pa

Source§

fn sub_assign(&mut self, other: usize)

Performs the -= operation. Read more
Source§

impl Copy for Pa

Source§

impl Eq for Pa

Source§

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 T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T> ToString for T
where T: Display + ?Sized,

§

fn to_string(&self) -> String

Converts the given value to a String. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.