Skip to content

Commit fb95378

Browse files
Danilo Krummrichjannau
authored andcommitted
rust: dma: implement dma::Device trait
Add a trait that defines the DMA specific methods of devices. The `dma::Device` trait should be implemented by (bus) device representations, where the underlying bus potentially supports DMA, such as `pci::Device` or `platform::Device`. Signed-off-by: Danilo Krummrich <dakr@kernel.org> Signed-off-by: Abdiel Janulgue <abdiel.janulgue@gmail.com>
1 parent 3fb5c6c commit fb95378

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

rust/kernel/dma.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@
66
77
use crate::{
88
bindings, build_assert,
9-
device::Device,
9+
device,
1010
error::code::*,
1111
error::Result,
1212
transmute::{AsBytes, FromBytes},
1313
types::ARef,
1414
};
1515

16+
/// Trait to be implemented by bus specific devices.
17+
///
18+
/// The [`Device`] trait should be implemented by bus specific device representations, where the
19+
/// underlying bus has potential support for DMA, such as [`crate::pci::Device`] or
20+
/// [crate::platform::Device].
21+
pub trait Device: AsRef<device::Device> {}
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,
162+
dev: &device::Device,
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,
204+
dev: &device::Device,
198205
count: usize,
199206
gfp_flags: kernel::alloc::Flags,
200207
) -> Result<CoherentAllocation<T>> {

0 commit comments

Comments
 (0)