Struct NAPOTRegionSpec

Source
pub struct NAPOTRegionSpec { /* private fields */ }
Expand description

A RISC-V PMP memory region specification, configured in NAPOT mode.

This type checks that the supplied start and size values meet the RISC-V NAPOT requirements, namely that

  • the region is a power of two bytes in size
  • the region’s start address is aligned to the region size
  • the region is at least 8 bytes long

Finally, RISC-V restricts physical address spaces to 34 bit on RV32, and 56 bit on RV64 platforms. A NAPOTRegionSpec must not cover addresses exceeding this address space, respectively. In practice, this means that on RV64 platforms NAPOTRegionSpecs whose encoded pmpaddrX CSR contains any non-zero bits in the 10 most significant bits will be rejected.

By accepting this type, PMP implementations can rely on these requirements to be verified. Furthermore, they can use the NAPOTRegionSpec::pmpaddr convenience method to retrieve an pmpaddrX CSR value encoding this region’s address and length.

Implementations§

Source§

impl NAPOTRegionSpec

Source

pub fn from_pmpaddr_csr(pmpaddr: usize) -> Option<Self>

Construct a new NAPOTRegionSpec from a pmpaddr CSR value.

For an RV32 platform, every single integer in [0; usize::MAX] is a valid pmpaddrX CSR for a region configured in NAPOT mode, and this operation is thus effectively infallible.

For RV64 platforms, this operation checks if the range would include any address outside of the 56 bit physical address space and, in this case, rejects the pmpaddr (tests whether any of the 10 most significant bits are non-zero).

Source

pub fn from_start_size(start: *const u8, size: usize) -> Option<Self>

Construct a new NAPOTRegionSpec from a start address and size.

This method accepts a start address and a region length. It returns Some(region) when all constraints specified in the NAPOTRegionSpec’s documentation are satisfied, otherwise None.

Source

pub fn from_start_end(start: *const u8, end: *const u8) -> Option<Self>

Construct a new NAPOTRegionSpec from a start address and end address.

This method accepts a start address (inclusive) and end address (exclusive). It returns Some(region) when all constraints specified in the NAPOTRegionSpec’s documentation are satisfied, otherwise None.

Source

pub fn pmpaddr(&self) -> usize

Retrieve a pmpaddrX-CSR compatible representation of this NAPOTRegionSpec’s address and length. For this value to be valid in a CSR register, the pmpcfgX octet’s A (address mode) value belonging to this pmpaddrX-CSR must be set to NAPOT (0b11).

Source

pub fn address_range(&self) -> Range<u64>

Return the range of physical addresses covered by this PMP region.

This follows the regular Rust range semantics (start inclusive, end exclusive). It returns the addresses as u64-integers to ensure that all underlying pmpaddrX CSR values can be represented.

Trait Implementations§

Source§

impl Clone for NAPOTRegionSpec

Source§

fn clone(&self) -> NAPOTRegionSpec

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for NAPOTRegionSpec

Source§

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

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

impl Copy for NAPOTRegionSpec

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.