pub struct IoMem<const SIZE: usize> { /* private fields */ }
Expand description
Represents a memory block of at least SIZE
bytes.
Invariants
ptr
is a non-null and valid address of at least SIZE
bytes and returned by an ioremap
variant. ptr
is also 8-byte aligned.
Examples
use kernel::io_mem::{IoMem, Resource};
fn test(res: Resource) -> Result {
// Create an io mem block of at least 100 bytes.
// SAFETY: No DMA operations are initiated through `mem`.
let mem = unsafe { IoMem::<100>::try_new(res) }?;
// Read one byte from offset 10.
let v = mem.readb(10);
// Write value to offset 20.
mem.writeb(v, 20);
Ok(())
}
Implementations
sourceimpl<const SIZE: usize> IoMem<SIZE>
impl<const SIZE: usize> IoMem<SIZE>
sourcepub unsafe fn try_new(res: Resource) -> Result<Self>
pub unsafe fn try_new(res: Resource) -> Result<Self>
Tries to create a new instance of a memory block.
The resource described by res
is mapped into the CPU’s address space so that it can be
accessed directly. It is also consumed by this function so that it can’t be mapped again
to a different address.
Safety
Callers must ensure that either (a) the resulting interface cannot be used to initiate DMA
operations, or (b) that DMA operations initiated via the returned interface use DMA handles
allocated through the dma
module.
sourcepub fn try_memcpy_fromio(&self, buffer: &mut [u8], offset: usize) -> Result
pub fn try_memcpy_fromio(&self, buffer: &mut [u8], offset: usize) -> Result
Copy memory block from an i/o memory by filling the specified buffer with it.
Examples
use kernel::io_mem::{self, IoMem, Resource};
fn test(res: Resource) -> Result {
// Create an i/o memory block of at least 100 bytes.
let mem = unsafe { IoMem::<100>::try_new(res) }?;
let mut buffer: [u8; 32] = [0; 32];
// Memcpy 16 bytes from an offset 10 of i/o memory block into the buffer.
mem.try_memcpy_fromio(&mut buffer[..16], 10)?;
Ok(())
}
sourcepub fn readb(&self, offset: usize) -> u8
pub fn readb(&self, offset: usize) -> u8
Reads IO data from the given offset known, at compile time.
If the offset is not known at compile time, the build will fail.
sourcepub fn try_readb(&self, offset: usize) -> Result<u8>
pub fn try_readb(&self, offset: usize) -> Result<u8>
Reads IO data from the given offset.
It fails if/when the offset (plus the type size) is out of bounds.
sourcepub fn readw(&self, offset: usize) -> u16
pub fn readw(&self, offset: usize) -> u16
Reads IO data from the given offset known, at compile time.
If the offset is not known at compile time, the build will fail.
sourcepub fn try_readw(&self, offset: usize) -> Result<u16>
pub fn try_readw(&self, offset: usize) -> Result<u16>
Reads IO data from the given offset.
It fails if/when the offset (plus the type size) is out of bounds.
sourcepub fn readl(&self, offset: usize) -> u32
pub fn readl(&self, offset: usize) -> u32
Reads IO data from the given offset known, at compile time.
If the offset is not known at compile time, the build will fail.
sourcepub fn try_readl(&self, offset: usize) -> Result<u32>
pub fn try_readl(&self, offset: usize) -> Result<u32>
Reads IO data from the given offset.
It fails if/when the offset (plus the type size) is out of bounds.
sourcepub fn readq(&self, offset: usize) -> u64
pub fn readq(&self, offset: usize) -> u64
Reads IO data from the given offset known, at compile time.
If the offset is not known at compile time, the build will fail.
sourcepub fn try_readq(&self, offset: usize) -> Result<u64>
pub fn try_readq(&self, offset: usize) -> Result<u64>
Reads IO data from the given offset.
It fails if/when the offset (plus the type size) is out of bounds.
sourcepub fn readb_relaxed(&self, offset: usize) -> u8
pub fn readb_relaxed(&self, offset: usize) -> u8
Reads IO data from the given offset known, at compile time.
If the offset is not known at compile time, the build will fail.
sourcepub fn try_readb_relaxed(&self, offset: usize) -> Result<u8>
pub fn try_readb_relaxed(&self, offset: usize) -> Result<u8>
Reads IO data from the given offset.
It fails if/when the offset (plus the type size) is out of bounds.
sourcepub fn readw_relaxed(&self, offset: usize) -> u16
pub fn readw_relaxed(&self, offset: usize) -> u16
Reads IO data from the given offset known, at compile time.
If the offset is not known at compile time, the build will fail.
sourcepub fn try_readw_relaxed(&self, offset: usize) -> Result<u16>
pub fn try_readw_relaxed(&self, offset: usize) -> Result<u16>
Reads IO data from the given offset.
It fails if/when the offset (plus the type size) is out of bounds.
sourcepub fn readl_relaxed(&self, offset: usize) -> u32
pub fn readl_relaxed(&self, offset: usize) -> u32
Reads IO data from the given offset known, at compile time.
If the offset is not known at compile time, the build will fail.
sourcepub fn try_readl_relaxed(&self, offset: usize) -> Result<u32>
pub fn try_readl_relaxed(&self, offset: usize) -> Result<u32>
Reads IO data from the given offset.
It fails if/when the offset (plus the type size) is out of bounds.
sourcepub fn readq_relaxed(&self, offset: usize) -> u64
pub fn readq_relaxed(&self, offset: usize) -> u64
Reads IO data from the given offset known, at compile time.
If the offset is not known at compile time, the build will fail.
sourcepub fn try_readq_relaxed(&self, offset: usize) -> Result<u64>
pub fn try_readq_relaxed(&self, offset: usize) -> Result<u64>
Reads IO data from the given offset.
It fails if/when the offset (plus the type size) is out of bounds.
sourcepub fn writeb(&self, value: u8, offset: usize)
pub fn writeb(&self, value: u8, offset: usize)
Writes IO data to the given offset, known at compile time.
If the offset is not known at compile time, the build will fail.
sourcepub fn try_writeb(&self, value: u8, offset: usize) -> Result
pub fn try_writeb(&self, value: u8, offset: usize) -> Result
Writes IO data to the given offset.
It fails if/when the offset (plus the type size) is out of bounds.
sourcepub fn writew(&self, value: u16, offset: usize)
pub fn writew(&self, value: u16, offset: usize)
Writes IO data to the given offset, known at compile time.
If the offset is not known at compile time, the build will fail.
sourcepub fn try_writew(&self, value: u16, offset: usize) -> Result
pub fn try_writew(&self, value: u16, offset: usize) -> Result
Writes IO data to the given offset.
It fails if/when the offset (plus the type size) is out of bounds.
sourcepub fn writel(&self, value: u32, offset: usize)
pub fn writel(&self, value: u32, offset: usize)
Writes IO data to the given offset, known at compile time.
If the offset is not known at compile time, the build will fail.
sourcepub fn try_writel(&self, value: u32, offset: usize) -> Result
pub fn try_writel(&self, value: u32, offset: usize) -> Result
Writes IO data to the given offset.
It fails if/when the offset (plus the type size) is out of bounds.
sourcepub fn writeq(&self, value: u64, offset: usize)
pub fn writeq(&self, value: u64, offset: usize)
Writes IO data to the given offset, known at compile time.
If the offset is not known at compile time, the build will fail.
sourcepub fn try_writeq(&self, value: u64, offset: usize) -> Result
pub fn try_writeq(&self, value: u64, offset: usize) -> Result
Writes IO data to the given offset.
It fails if/when the offset (plus the type size) is out of bounds.
sourcepub fn writeb_relaxed(&self, value: u8, offset: usize)
pub fn writeb_relaxed(&self, value: u8, offset: usize)
Writes IO data to the given offset, known at compile time.
If the offset is not known at compile time, the build will fail.
sourcepub fn try_writeb_relaxed(&self, value: u8, offset: usize) -> Result
pub fn try_writeb_relaxed(&self, value: u8, offset: usize) -> Result
Writes IO data to the given offset.
It fails if/when the offset (plus the type size) is out of bounds.
sourcepub fn writew_relaxed(&self, value: u16, offset: usize)
pub fn writew_relaxed(&self, value: u16, offset: usize)
Writes IO data to the given offset, known at compile time.
If the offset is not known at compile time, the build will fail.
sourcepub fn try_writew_relaxed(&self, value: u16, offset: usize) -> Result
pub fn try_writew_relaxed(&self, value: u16, offset: usize) -> Result
Writes IO data to the given offset.
It fails if/when the offset (plus the type size) is out of bounds.
sourcepub fn writel_relaxed(&self, value: u32, offset: usize)
pub fn writel_relaxed(&self, value: u32, offset: usize)
Writes IO data to the given offset, known at compile time.
If the offset is not known at compile time, the build will fail.
sourcepub fn try_writel_relaxed(&self, value: u32, offset: usize) -> Result
pub fn try_writel_relaxed(&self, value: u32, offset: usize) -> Result
Writes IO data to the given offset.
It fails if/when the offset (plus the type size) is out of bounds.
sourcepub fn writeq_relaxed(&self, value: u64, offset: usize)
pub fn writeq_relaxed(&self, value: u64, offset: usize)
Writes IO data to the given offset, known at compile time.
If the offset is not known at compile time, the build will fail.
sourcepub fn try_writeq_relaxed(&self, value: u64, offset: usize) -> Result
pub fn try_writeq_relaxed(&self, value: u64, offset: usize) -> Result
Writes IO data to the given offset.
It fails if/when the offset (plus the type size) is out of bounds.
Trait Implementations
Auto Trait Implementations
impl<const SIZE: usize> RefUnwindSafe for IoMem<SIZE>
impl<const SIZE: usize> Send for IoMem<SIZE>
impl<const SIZE: usize> Sync for IoMem<SIZE>
impl<const SIZE: usize> Unpin for IoMem<SIZE>
impl<const SIZE: usize> UnwindSafe for IoMem<SIZE>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more