UniqueMmioPointer

Struct UniqueMmioPointer 

Source
pub struct UniqueMmioPointer<'a, T>(/* private fields */)
where
    T: ?Sized;
Expand description

A unique owned pointer to the registers of some MMIO device.

It is guaranteed to be valid and unique; no other access to the MMIO space of the device may happen for the lifetime 'a.

A UniqueMmioPointer may be created from a mutable reference, but this should only be used for testing purposes, as references should never be constructed for real MMIO address space.

Implementations§

Source§

impl<T> UniqueMmioPointer<'_, T>

Source

pub unsafe fn read_unsafe(&mut self) -> T

Performs an MMIO read of the entire T.

§Safety

This field must be safe to perform an MMIO read from.

Source

pub unsafe fn write_unsafe(&mut self, value: T)

Performs an MMIO write of the entire T.

Note that this takes &mut self rather than &self because an MMIO read may cause side-effects that change the state of the device.

§Safety

This field must be safe to perform an MMIO write to.

Source§

impl<T> UniqueMmioPointer<'_, T>
where T: ?Sized,

Source

pub const unsafe fn new(regs: NonNull<T>) -> UniqueMmioPointer<'_, T>

Creates a new UniqueMmioPointer from a non-null raw pointer.

§Safety

regs must be a properly aligned and valid pointer to some MMIO address space of type T, which is mapped as device memory and valid to read and write from any thread with volatile operations. There must not be any other aliases which are used to access the same MMIO region while this UniqueMmioPointer exists.

If T contains any fields wrapped in ReadOnly, WriteOnly or ReadWrite then they must indeed be safe to perform MMIO reads or writes on.

Source

pub const unsafe fn child<U>( &mut self, regs: NonNull<U>, ) -> UniqueMmioPointer<'_, U>
where U: ?Sized,

Creates a new UniqueMmioPointer with the same lifetime as this one.

This is used internally by the field! macro and shouldn’t be called directly.

§Safety

regs must be a properly aligned and valid pointer to some MMIO address space of type T, within the allocation that self points to.

Source

pub const fn ptr_mut(&mut self) -> *mut T

Returns a raw mut pointer to the MMIO registers.

Source

pub const fn ptr_nonnull(&mut self) -> NonNull<T>

Returns a NonNull<T> pointer to the MMIO registers.

Source

pub const fn reborrow(&mut self) -> UniqueMmioPointer<'_, T>

Returns a new UniqueMmioPointer with a lifetime no greater than this one.

Source§

impl<'a, T> UniqueMmioPointer<'a, T>
where T: ?Sized,

Source

pub const unsafe fn split_child<U>( &mut self, regs: NonNull<U>, ) -> UniqueMmioPointer<'a, U>
where U: ?Sized,

Creates a new UniqueMmioPointer with the same lifetime as this one, but not tied to the lifetime this one is borrowed for.

This is used internally by the split_fields! macro and shouldn’t be called directly.

§Safety

regs must be a properly aligned and valid pointer to some MMIO address space of type T, within the allocation that self points to. split_child must not be called for the same child field more than once, and the original UniqueMmioPointer must not be used after split_child has been called for one or more of its fields.

Source§

impl<T> UniqueMmioPointer<'_, ReadWrite<T>>
where T: FromBytes + IntoBytes,

Source

pub fn read(&mut self) -> T

Performs an MMIO read of the entire T.

Source§

impl<T> UniqueMmioPointer<'_, ReadWrite<T>>
where T: Immutable + IntoBytes,

Source

pub fn write(&mut self, value: T)

Performs an MMIO write of the entire T.

Source§

impl<T> UniqueMmioPointer<'_, ReadPureWrite<T>>
where T: Immutable + IntoBytes,

Source

pub fn write(&mut self, value: T)

Performs an MMIO write of the entire T.

Source§

impl<T> UniqueMmioPointer<'_, ReadOnly<T>>
where T: FromBytes + IntoBytes,

Source

pub fn read(&mut self) -> T

Performs an MMIO read of the entire T.

Source§

impl<T> UniqueMmioPointer<'_, WriteOnly<T>>
where T: Immutable + IntoBytes,

Source

pub fn write(&mut self, value: T)

Performs an MMIO write of the entire T.

Source§

impl<'a, T> UniqueMmioPointer<'a, [T]>

Source

pub const fn get(&mut self, index: usize) -> Option<UniqueMmioPointer<'_, T>>

Returns a UniqueMmioPointer to an element of this slice, or None if the index is out of bounds.

§Example
use safe_mmio::{UniqueMmioPointer, fields::ReadWrite};

let mut slice: UniqueMmioPointer<[ReadWrite<u32>]>;
let mut element = slice.get(1).unwrap();
element.write(42);
Source

pub const fn take(self, index: usize) -> Option<UniqueMmioPointer<'a, T>>

Returns a UniqueMmioPointer to an element of this slice, or None if the index is out of bounds.

Unlike UniqueMmioPointer::get this takes ownership of the original pointer. This is useful when you want to store the resulting pointer without keeping the original pointer around.

§Example
use safe_mmio::{UniqueMmioPointer, fields::ReadWrite};

let mut slice: UniqueMmioPointer<[ReadWrite<u32>]>;
let mut element = slice.take(1).unwrap();
element.write(42);
// `slice` can no longer be used at this point.
Source§

impl<'a, T, const LEN: usize> UniqueMmioPointer<'a, [T; LEN]>

Source

pub fn split(&mut self) -> [UniqueMmioPointer<'_, T>; LEN]

Splits a UniqueMmioPointer to an array into an array of UniqueMmioPointers.

Source

pub const fn as_mut_slice(&mut self) -> UniqueMmioPointer<'_, [T]>

Converts this array pointer to an equivalent slice pointer.

Source

pub const fn get(&mut self, index: usize) -> Option<UniqueMmioPointer<'_, T>>

Returns a UniqueMmioPointer to an element of this array, or None if the index is out of bounds.

§Example
use safe_mmio::{UniqueMmioPointer, fields::ReadWrite};

let mut slice: UniqueMmioPointer<[ReadWrite<u32>; 3]>;
let mut element = slice.get(1).unwrap();
element.write(42);
slice.get(2).unwrap().write(100);
Source

pub const fn take(self, index: usize) -> Option<UniqueMmioPointer<'a, T>>

Returns a UniqueMmioPointer to an element of this array, or None if the index is out of bounds.

Unlike UniqueMmioPointer::get this takes ownership of the original pointer. This is useful when you want to store the resulting pointer without keeping the original pointer around.

§Example
use safe_mmio::{UniqueMmioPointer, fields::ReadWrite};

let mut array: UniqueMmioPointer<[ReadWrite<u32>; 3]>;
let mut element = array.take(1).unwrap();
element.write(42);
// `array` can no longer be used at this point.

Methods from Deref<Target = SharedMmioPointer<'a, T>>§

Source

pub unsafe fn read_unsafe(&self) -> T

Performs an MMIO read of the entire T.

§Safety

This field must be safe to perform an MMIO read from, and doing so must not cause any side-effects.

Source

pub unsafe fn child<U>(&self, regs: NonNull<U>) -> SharedMmioPointer<'a, U>
where U: ?Sized,

Creates a new SharedMmioPointer with the same lifetime as this one.

This is used internally by the field_shared! macro and shouldn’t be called directly.

§Safety

regs must be a properly aligned and valid pointer to some MMIO address space of type T, within the allocation that self points to.

Source

pub fn ptr(&self) -> *const T

Returns a raw const pointer to the MMIO registers.

Trait Implementations§

Source§

impl<T> Debug for UniqueMmioPointer<'_, T>
where T: ?Sized,

Source§

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

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

impl<'a, T> Deref for UniqueMmioPointer<'a, T>
where T: ?Sized,

Source§

type Target = SharedMmioPointer<'a, T>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &<UniqueMmioPointer<'a, T> as Deref>::Target

Dereferences the value.
Source§

impl<'a, T> From<&'a mut T> for UniqueMmioPointer<'a, T>
where T: ?Sized,

Source§

fn from(r: &'a mut T) -> UniqueMmioPointer<'a, T>

Converts to this type from the input type.
Source§

impl<'a, T, const LEN: usize> From<UniqueMmioPointer<'a, [T; LEN]>> for UniqueMmioPointer<'a, [T]>

Source§

fn from(value: UniqueMmioPointer<'a, [T; LEN]>) -> UniqueMmioPointer<'a, [T]>

Converts to this type from the input type.
Source§

impl<'a, T> From<UniqueMmioPointer<'a, T>> for SharedMmioPointer<'a, T>
where T: ?Sized,

Source§

fn from(unique: UniqueMmioPointer<'a, T>) -> SharedMmioPointer<'a, T>

Converts to this type from the input type.
Source§

impl<'a, T> From<UniqueMmioPointer<'a, T>> for UniqueMmioPointer<'a, [T]>

Source§

fn from(value: UniqueMmioPointer<'a, T>) -> UniqueMmioPointer<'a, [T]>

Converts to this type from the input type.
Source§

impl<'a, T> From<UniqueMmioPointer<'a, T>> for UniqueMmioPointer<'a, [T; 1]>

Source§

fn from(value: UniqueMmioPointer<'a, T>) -> UniqueMmioPointer<'a, [T; 1]>

Converts to this type from the input type.
Source§

impl<T> PartialEq for UniqueMmioPointer<'_, T>
where T: ?Sized,

Source§

fn eq(&self, other: &UniqueMmioPointer<'_, T>) -> 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<T> Eq for UniqueMmioPointer<'_, T>
where T: ?Sized,

Auto Trait Implementations§

§

impl<'a, T> Freeze for UniqueMmioPointer<'a, T>
where T: ?Sized,

§

impl<'a, T> RefUnwindSafe for UniqueMmioPointer<'a, T>
where T: RefUnwindSafe + ?Sized,

§

impl<'a, T> Send for UniqueMmioPointer<'a, T>
where T: Send + Sync + ?Sized,

§

impl<'a, T> !Sync for UniqueMmioPointer<'a, T>

§

impl<'a, T> Unpin for UniqueMmioPointer<'a, T>
where T: ?Sized,

§

impl<'a, T> UnwindSafe for UniqueMmioPointer<'a, T>
where T: RefUnwindSafe + ?Sized,

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> 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
§

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.