Skip to main content

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<'_, ReadWrite<T>>

Source

pub fn modify(&mut self, f: impl FnOnce(T) -> T)

Performs an MMIO read of the entire T, applies the given function to it, and then performs an MMIO write of the resulting value.

This is equivalent to calling read then write.

Source

pub fn modify_mut(&mut self, f: impl FnOnce(&mut T))

Performs an MMIO read of the entire T, calls the given function to modify it, and then performs an MMIO write of the resulting value.

This is equivalent to calling read then write.

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<'_, ReadPureWrite<T>>

Source

pub fn modify(&mut self, f: impl FnOnce(T) -> T)

Performs an MMIO read of the entire T, applies the given function to it, and then performs an MMIO write of the resulting value.

This is equivalent to calling read then write.

Source

pub fn modify_mut(&mut self, f: impl FnOnce(&mut T))

Performs an MMIO read of the entire T, calls the given function to modify it, and then performs an MMIO write of the resulting value.

This is equivalent to calling read then write.

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 fn get_range( &mut self, range: Range<usize>, ) -> Option<UniqueMmioPointer<'_, [T]>>

Returns a UniqueMmioPointer to a range of elements of this slice, or None if the range is out of bounds.

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

let mut slice: UniqueMmioPointer<[ReadWrite<u32>]>;
let mut range = slice.get_range(1..3).unwrap();
range.get(0).unwrap().write(100);
range.get(1).unwrap().write(200);
assert_eq!(None, range.get(2));
assert_eq!(100, slice.get(1).unwrap().read());
assert_eq!(200, slice.get(2).unwrap().read());
Source

pub fn iter(&mut self) -> UniqueMmioPointerIterator<'_, T>

Returns a new iterator of the items of the slice.

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(self) -> [UniqueMmioPointer<'a, T>; LEN]

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

Source

pub fn split_some<const N: usize>( self, chosen: [usize; N], ) -> [UniqueMmioPointer<'a, T>; N]

Splits a UniqueMmioPointer to an array into an array of UniqueMmioPointers, taking only the chosen indices.

Panics if chosen contains the same index more than once, or any index out of bounds.

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 fn get_range( &mut self, range: Range<usize>, ) -> Option<UniqueMmioPointer<'_, [T]>>

Returns a UniqueMmioPointer to a range of elements of this array, or None if the range is out of bounds.

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

let mut slice: UniqueMmioPointer<[ReadWrite<u32>; 3]>;
let mut range = slice.get_range(1..3).unwrap();
range.get(0).unwrap().write(100);
range.get(1).unwrap().write(200);
assert_eq!(None, range.get(2));
assert_eq!(100, slice.get(1).unwrap().read());
assert_eq!(200, slice.get(2).unwrap().read());
Source

pub fn iter(&mut self) -> UniqueMmioPointerIterator<'_, T>

Returns a new iterator to the items of the array.

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<'a, T> IntoIterator for UniqueMmioPointer<'a, [T]>

Source§

type Item = UniqueMmioPointer<'a, T>

The type of the elements being iterated over.
Source§

type IntoIter = UniqueMmioPointerIterator<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <UniqueMmioPointer<'a, [T]> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

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

Source§

type Item = UniqueMmioPointer<'a, T>

The type of the elements being iterated over.
Source§

type IntoIter = UniqueMmioPointerIterator<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter( self, ) -> <UniqueMmioPointer<'a, [T; LEN]> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
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 · Source§

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> UnsafeUnpin for UniqueMmioPointer<'a, T>
where T: ?Sized,

§

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

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

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.