sbi_spec::binary

Struct SharedPtr

Source
pub struct SharedPtr<T> { /* private fields */ }
Expand description

Shared memory physical address raw pointer with type annotation.

This is a structure wrapping a raw pointer to the value of the type T without a pointer metadata. SharedPtr’s are thin; they won’t include metadata as RISC-V SBI does not provide an approach to pass them via SBI calls, thus the length of type T should be decided independently of raw pointer structure.

SharedPtr can be used as a parameter to pass the shared memory physical pointer with a given base address in RISC-V SBI calls. For example, a SharedPtr<[u8; 64]> would represent a fixed-size 64 byte array on a RISC-V SBI function argument type.

This structure cannot be dereferenced directly with physical addresses, because on RISC-V systems the physical address space could be larger than the virtual ones. Hence, this structure describes the physical memory range by two usize values: the upper phys_addr_hi and lower phys_addr_lo.

RISC-V SBI extensions may declare special pointer values for shared memory raw pointers. For example, SBI STA declares that steal-time information should stop from reporting when the SBI call is invoked using all-ones bitwise shared pointer, i.e. phys_addr_hi and phys_addr_lo both equals usize::MAX. SharedPtr can be constructed using such special values by providing them to the SharedPtr::new function.

§Requirements

If an SBI function needs to pass a shared memory physical address range to the SBI implementation (or higher privilege mode), then this physical memory address range MUST satisfy the following requirements:

  • The SBI implementation MUST check that the supervisor-mode software is allowed to access the specified physical memory range with the access type requested (read and/or write).
  • The SBI implementation MUST access the specified physical memory range using the PMA attributes.
  • The data in the shared memory MUST follow little-endian byte ordering.

NOTE: If the supervisor-mode software accesses the same physical memory range using a memory type different from the PMA, then a loss of coherence or unexpected memory ordering may occur. The invoking software should follow the rules and sequences defined in the RISC-V Svpbmt specification to prevent the loss of coherence and memory ordering.

It is recommended that a memory physical address passed to an SBI function should use at least two usize parameters to support platforms which have memory physical addresses wider than XLEN bits.

Implementations§

Source§

impl<T> SharedPtr<T>

Source

pub const fn new(phys_addr_lo: usize, phys_addr_hi: usize) -> Self

Create a shared physical memory pointer by physical address.

Source

pub const fn phys_addr_lo(self) -> usize

Returns low-part physical address of the shared physical memory pointer.

Source

pub const fn phys_addr_hi(self) -> usize

Returns high-part physical address of the shared physical memory pointer.

Trait Implementations§

Source§

impl<T> Clone for SharedPtr<T>

Source§

fn clone(&self) -> Self

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<T> Copy for SharedPtr<T>

Auto Trait Implementations§

§

impl<T> Freeze for SharedPtr<T>

§

impl<T> RefUnwindSafe for SharedPtr<T>
where T: RefUnwindSafe,

§

impl<T> !Send for SharedPtr<T>

§

impl<T> !Sync for SharedPtr<T>

§

impl<T> Unpin for SharedPtr<T>

§

impl<T> UnwindSafe for SharedPtr<T>
where T: RefUnwindSafe,

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 T)

🔬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.