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

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.

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(())
}

Reads IO data from the given offset known, at compile time.

If the offset is not known at compile time, the build will fail.

Reads IO data from the given offset.

It fails if/when the offset (plus the type size) is out of bounds.

Reads IO data from the given offset known, at compile time.

If the offset is not known at compile time, the build will fail.

Reads IO data from the given offset.

It fails if/when the offset (plus the type size) is out of bounds.

Reads IO data from the given offset known, at compile time.

If the offset is not known at compile time, the build will fail.

Reads IO data from the given offset.

It fails if/when the offset (plus the type size) is out of bounds.

Reads IO data from the given offset known, at compile time.

If the offset is not known at compile time, the build will fail.

Reads IO data from the given offset.

It fails if/when the offset (plus the type size) is out of bounds.

Reads IO data from the given offset known, at compile time.

If the offset is not known at compile time, the build will fail.

Reads IO data from the given offset.

It fails if/when the offset (plus the type size) is out of bounds.

Reads IO data from the given offset known, at compile time.

If the offset is not known at compile time, the build will fail.

Reads IO data from the given offset.

It fails if/when the offset (plus the type size) is out of bounds.

Reads IO data from the given offset known, at compile time.

If the offset is not known at compile time, the build will fail.

Reads IO data from the given offset.

It fails if/when the offset (plus the type size) is out of bounds.

Reads IO data from the given offset known, at compile time.

If the offset is not known at compile time, the build will fail.

Reads IO data from the given offset.

It fails if/when the offset (plus the type size) is out of bounds.

Writes IO data to the given offset, known at compile time.

If the offset is not known at compile time, the build will fail.

Writes IO data to the given offset.

It fails if/when the offset (plus the type size) is out of bounds.

Writes IO data to the given offset, known at compile time.

If the offset is not known at compile time, the build will fail.

Writes IO data to the given offset.

It fails if/when the offset (plus the type size) is out of bounds.

Writes IO data to the given offset, known at compile time.

If the offset is not known at compile time, the build will fail.

Writes IO data to the given offset.

It fails if/when the offset (plus the type size) is out of bounds.

Writes IO data to the given offset, known at compile time.

If the offset is not known at compile time, the build will fail.

Writes IO data to the given offset.

It fails if/when the offset (plus the type size) is out of bounds.

Writes IO data to the given offset, known at compile time.

If the offset is not known at compile time, the build will fail.

Writes IO data to the given offset.

It fails if/when the offset (plus the type size) is out of bounds.

Writes IO data to the given offset, known at compile time.

If the offset is not known at compile time, the build will fail.

Writes IO data to the given offset.

It fails if/when the offset (plus the type size) is out of bounds.

Writes IO data to the given offset, known at compile time.

If the offset is not known at compile time, the build will fail.

Writes IO data to the given offset.

It fails if/when the offset (plus the type size) is out of bounds.

Writes IO data to the given offset, known at compile time.

If the offset is not known at compile time, the build will fail.

Writes IO data to the given offset.

It fails if/when the offset (plus the type size) is out of bounds.

Trait Implementations

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.