Struct IoRequest

Source
pub struct IoRequest<'a> { /* private fields */ }
Expand description

An IO request for a specific device and resource.

Implementations§

Source§

impl<'a> IoRequest<'a>

Source

pub fn iomap_sized<const SIZE: usize>( self, ) -> impl PinInit<Devres<IoMem<SIZE>>, Error> + 'a

Maps an IoRequest where the size is known at compile time.

This uses the ioremap() C API.

§Examples

The following example uses a kernel::platform::Device for illustration purposes.

use kernel::{bindings, c_str, platform, of, device::Core};
struct SampleDriver;

impl platform::Driver for SampleDriver {

   fn probe(
      pdev: &platform::Device<Core>,
      info: Option<&Self::IdInfo>,
   ) -> Result<Pin<KBox<Self>>> {
      let offset = 0; // Some offset.

      // If the size is known at compile time, use [`Self::iomap_sized`].
      //
      // No runtime checks will apply when reading and writing.
      let request = pdev.io_request_by_index(0).ok_or(ENODEV)?;
      let iomem = request.iomap_sized::<42>();
      let iomem = KBox::pin_init(iomem, GFP_KERNEL)?;

      let io = iomem.access(pdev.as_ref())?;

      // Read and write a 32-bit value at `offset`.
      let data = io.read32_relaxed(offset);

      io.write32_relaxed(data, offset);

    }
}
Source

pub fn iomap_exclusive_sized<const SIZE: usize>( self, ) -> impl PinInit<Devres<ExclusiveIoMem<SIZE>>, Error> + 'a

Same as Self::iomap_sized but with exclusive access to the underlying region.

This uses the ioremap() C API.

Source

pub fn iomap(self) -> impl PinInit<Devres<IoMem<0>>, Error> + 'a

Maps an IoRequest where the size is not known at compile time,

This uses the ioremap() C API.

§Examples

The following example uses a kernel::platform::Device for illustration purposes.

use kernel::{bindings, c_str, platform, of, device::Core};
struct SampleDriver;

impl platform::Driver for SampleDriver {

   fn probe(
      pdev: &platform::Device<Core>,
      info: Option<&Self::IdInfo>,
   ) -> Result<Pin<KBox<Self>>> {
      let offset = 0; // Some offset.

      // Unlike [`Self::iomap_sized`], here the size of the memory region
      // is not known at compile time, so only the `try_read*` and `try_write*`
      // family of functions should be used, leading to runtime checks on every
      // access.
      let request = pdev.io_request_by_index(0).ok_or(ENODEV)?;
      let iomem = request.iomap();
      let iomem = KBox::pin_init(iomem, GFP_KERNEL)?;

      let io = iomem.access(pdev.as_ref())?;

      let data = io.try_read32_relaxed(offset)?;

      io.try_write32_relaxed(data, offset)?;

    }
}
Source

pub fn iomap_exclusive( self, ) -> impl PinInit<Devres<ExclusiveIoMem<0>>, Error> + 'a

Same as Self::iomap but with exclusive access to the underlying region.

Auto Trait Implementations§

§

impl<'a> Freeze for IoRequest<'a>

§

impl<'a> !RefUnwindSafe for IoRequest<'a>

§

impl<'a> !Send for IoRequest<'a>

§

impl<'a> !Sync for IoRequest<'a>

§

impl<'a> Unpin for IoRequest<'a>

§

impl<'a> !UnwindSafe for IoRequest<'a>

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> Init<T> for T

Source§

unsafe fn __init(self, slot: *mut T) -> Result<(), Infallible>

Initializes slot. Read more
Source§

fn chain<F>(self, f: F) -> ChainInit<Self, F, T, E>
where F: FnOnce(&mut T) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
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> PinInit<T> for T

Source§

unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>

Initializes slot. Read more
Source§

fn pin_chain<F>(self, f: F) -> ChainPinInit<Self, F, T, E>
where F: FnOnce(Pin<&mut T>) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
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.