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 NAPOTRegionSpec
s 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
impl NAPOTRegionSpec
Sourcepub fn from_pmpaddr_csr(pmpaddr: usize) -> Option<Self>
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).
Sourcepub fn from_start_size(start: *const u8, size: usize) -> Option<Self>
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
.
Sourcepub fn from_start_end(start: *const u8, end: *const u8) -> Option<Self>
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
.
Sourcepub fn pmpaddr(&self) -> usize
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).
Sourcepub fn address_range(&self) -> Range<u64>
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
impl Clone for NAPOTRegionSpec
Source§fn clone(&self) -> NAPOTRegionSpec
fn clone(&self) -> NAPOTRegionSpec
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more