mirror of
https://github.com/torvalds/linux.git
synced 2026-01-24 23:16:46 +00:00
rust: dma: implement dma::Device trait
Add a trait that defines the DMA specific methods of devices. The `dma::Device` trait is to be implemented by bus device representations, where the underlying bus is capable of DMA, such as `pci::Device` or `platform::Device`. Reviewed-by: Abdiel Janulgue <abdiel.janulgue@gmail.com> Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Link: https://lore.kernel.org/r/20250716150354.51081-2-dakr@kernel.org Signed-off-by: Danilo Krummrich <dakr@kernel.org>
This commit is contained in:
@@ -5,14 +5,21 @@
|
|||||||
//! C header: [`include/linux/dma-mapping.h`](srctree/include/linux/dma-mapping.h)
|
//! C header: [`include/linux/dma-mapping.h`](srctree/include/linux/dma-mapping.h)
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
bindings, build_assert,
|
bindings, build_assert, device,
|
||||||
device::{Bound, Device},
|
device::Bound,
|
||||||
error::code::*,
|
error::code::*,
|
||||||
error::Result,
|
error::Result,
|
||||||
transmute::{AsBytes, FromBytes},
|
transmute::{AsBytes, FromBytes},
|
||||||
types::ARef,
|
types::ARef,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Trait to be implemented by DMA capable bus devices.
|
||||||
|
///
|
||||||
|
/// The [`dma::Device`](Device) trait should be implemented by bus specific device representations,
|
||||||
|
/// where the underlying bus is DMA capable, such as [`pci::Device`](::kernel::pci::Device) or
|
||||||
|
/// [`platform::Device`](::kernel::platform::Device).
|
||||||
|
pub trait Device: AsRef<device::Device<Core>> {}
|
||||||
|
|
||||||
/// Possible attributes associated with a DMA mapping.
|
/// Possible attributes associated with a DMA mapping.
|
||||||
///
|
///
|
||||||
/// They can be combined with the operators `|`, `&`, and `!`.
|
/// They can be combined with the operators `|`, `&`, and `!`.
|
||||||
@@ -130,7 +137,7 @@ pub mod attrs {
|
|||||||
// Hence, find a way to revoke the device resources of a `CoherentAllocation`, but not the
|
// Hence, find a way to revoke the device resources of a `CoherentAllocation`, but not the
|
||||||
// entire `CoherentAllocation` including the allocated memory itself.
|
// entire `CoherentAllocation` including the allocated memory itself.
|
||||||
pub struct CoherentAllocation<T: AsBytes + FromBytes> {
|
pub struct CoherentAllocation<T: AsBytes + FromBytes> {
|
||||||
dev: ARef<Device>,
|
dev: ARef<device::Device>,
|
||||||
dma_handle: bindings::dma_addr_t,
|
dma_handle: bindings::dma_addr_t,
|
||||||
count: usize,
|
count: usize,
|
||||||
cpu_addr: *mut T,
|
cpu_addr: *mut T,
|
||||||
@@ -152,7 +159,7 @@ impl<T: AsBytes + FromBytes> CoherentAllocation<T> {
|
|||||||
/// # Ok::<(), Error>(()) }
|
/// # Ok::<(), Error>(()) }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn alloc_attrs(
|
pub fn alloc_attrs(
|
||||||
dev: &Device<Bound>,
|
dev: &device::Device<Bound>,
|
||||||
count: usize,
|
count: usize,
|
||||||
gfp_flags: kernel::alloc::Flags,
|
gfp_flags: kernel::alloc::Flags,
|
||||||
dma_attrs: Attrs,
|
dma_attrs: Attrs,
|
||||||
@@ -194,7 +201,7 @@ impl<T: AsBytes + FromBytes> CoherentAllocation<T> {
|
|||||||
/// Performs the same functionality as [`CoherentAllocation::alloc_attrs`], except the
|
/// Performs the same functionality as [`CoherentAllocation::alloc_attrs`], except the
|
||||||
/// `dma_attrs` is 0 by default.
|
/// `dma_attrs` is 0 by default.
|
||||||
pub fn alloc_coherent(
|
pub fn alloc_coherent(
|
||||||
dev: &Device<Bound>,
|
dev: &device::Device<Bound>,
|
||||||
count: usize,
|
count: usize,
|
||||||
gfp_flags: kernel::alloc::Flags,
|
gfp_flags: kernel::alloc::Flags,
|
||||||
) -> Result<CoherentAllocation<T>> {
|
) -> Result<CoherentAllocation<T>> {
|
||||||
|
|||||||
Reference in New Issue
Block a user