pub struct IoRequest<'a> { /* private fields */ }Expand description
An IO request for a specific device and resource.
Implementations§
Source§impl<'a> IoRequest<'a>
impl<'a> IoRequest<'a>
Sourcepub fn iomap_sized<const SIZE: usize>(self) -> Result<IoMem<'a, SIZE>>
pub fn iomap_sized<const SIZE: usize>(self) -> Result<IoMem<'a, SIZE>>
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,
device::Core,
io::Io,
of,
platform,
};
struct SampleDriver;
impl platform::Driver for SampleDriver {
fn probe<'bound>(
pdev: &'bound platform::Device<Core<'_>>,
info: Option<&'bound Self::IdInfo>,
) -> impl PinInit<Self, Error> + 'bound {
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>()?;
// Read and write a 32-bit value at `offset`.
let data = iomem.read32(offset);
iomem.write32(data, offset);
}
}Sourcepub fn iomap_exclusive_sized<const SIZE: usize>(
self,
) -> Result<ExclusiveIoMem<'a, SIZE>>
pub fn iomap_exclusive_sized<const SIZE: usize>( self, ) -> Result<ExclusiveIoMem<'a, SIZE>>
Same as Self::iomap_sized but with exclusive access to the
underlying region.
This uses the ioremap() C API.
Sourcepub fn iomap(self) -> Result<IoMem<'a>>
pub fn iomap(self) -> Result<IoMem<'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,
device::Core,
io::Io,
of,
platform,
};
struct SampleDriver;
impl platform::Driver for SampleDriver {
fn probe<'bound>(
pdev: &'bound platform::Device<Core<'_>>,
info: Option<&'bound Self::IdInfo>,
) -> impl PinInit<Self, Error> + 'bound {
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 data = iomem.try_read32(offset)?;
iomem.try_write32(data, offset)?;
}
}Sourcepub fn iomap_exclusive(self) -> Result<ExclusiveIoMem<'a, 0>>
pub fn iomap_exclusive(self) -> Result<ExclusiveIoMem<'a, 0>>
Same as Self::iomap but with exclusive access to the underlying
region.
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for IoRequest<'a>
impl<'a> !UnwindSafe for IoRequest<'a>
impl<'a> Freeze for IoRequest<'a>
impl<'a> Send for IoRequest<'a>
impl<'a> Sync for IoRequest<'a>
impl<'a> Unpin for IoRequest<'a>
impl<'a> UnsafeUnpin for IoRequest<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> PinInit<T> for T
impl<T> PinInit<T> for T
Source§unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
Initializes
slot. Read more