Skip to content

Commit d06d5f6

Browse files
author
Danilo Krummrich
committed
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>
1 parent 9a8682f commit d06d5f6

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

rust/kernel/dma.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,21 @@
55
//! C header: [`include/linux/dma-mapping.h`](srctree/include/linux/dma-mapping.h)
66
77
use crate::{
8-
bindings, build_assert,
9-
device::{Bound, Device},
8+
bindings, build_assert, device,
9+
device::Bound,
1010
error::code::*,
1111
error::Result,
1212
transmute::{AsBytes, FromBytes},
1313
types::ARef,
1414
};
1515

16+
/// Trait to be implemented by DMA capable bus devices.
17+
///
18+
/// The [`dma::Device`](Device) trait should be implemented by bus specific device representations,
19+
/// where the underlying bus is DMA capable, such as [`pci::Device`](::kernel::pci::Device) or
20+
/// [`platform::Device`](::kernel::platform::Device).
21+
pub trait Device: AsRef<device::Device<Core>> {}
22+
1623
/// Possible attributes associated with a DMA mapping.
1724
///
1825
/// They can be combined with the operators `|`, `&`, and `!`.
@@ -130,7 +137,7 @@ pub mod attrs {
130137
// Hence, find a way to revoke the device resources of a `CoherentAllocation`, but not the
131138
// entire `CoherentAllocation` including the allocated memory itself.
132139
pub struct CoherentAllocation<T: AsBytes + FromBytes> {
133-
dev: ARef<Device>,
140+
dev: ARef<device::Device>,
134141
dma_handle: bindings::dma_addr_t,
135142
count: usize,
136143
cpu_addr: *mut T,
@@ -152,7 +159,7 @@ impl<T: AsBytes + FromBytes> CoherentAllocation<T> {
152159
/// # Ok::<(), Error>(()) }
153160
/// ```
154161
pub fn alloc_attrs(
155-
dev: &Device<Bound>,
162+
dev: &device::Device<Bound>,
156163
count: usize,
157164
gfp_flags: kernel::alloc::Flags,
158165
dma_attrs: Attrs,
@@ -194,7 +201,7 @@ impl<T: AsBytes + FromBytes> CoherentAllocation<T> {
194201
/// Performs the same functionality as [`CoherentAllocation::alloc_attrs`], except the
195202
/// `dma_attrs` is 0 by default.
196203
pub fn alloc_coherent(
197-
dev: &Device<Bound>,
204+
dev: &device::Device<Bound>,
198205
count: usize,
199206
gfp_flags: kernel::alloc::Flags,
200207
) -> Result<CoherentAllocation<T>> {

0 commit comments

Comments
 (0)