diff options
author | Danilo Krummrich <dakr@kernel.org> | 2025-07-16 17:02:50 +0200 |
---|---|---|
committer | Danilo Krummrich <dakr@kernel.org> | 2025-07-19 19:37:17 +0200 |
commit | 931d9251e4855f79394357eb0071b5c4a189a8bd (patch) | |
tree | 7d8d410b02e7ce12205524601db6c5b0d0ed4050 /samples/rust/rust_dma.rs | |
parent | 256de48f2cad85153b271b66320a9355773db64e (diff) |
rust: samples: dma: set DMA mask
Set a DMA mask for the `pci::Device` in the Rust DMA sample driver.
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-6-dakr@kernel.org
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Diffstat (limited to 'samples/rust/rust_dma.rs')
-rw-r--r-- | samples/rust/rust_dma.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/samples/rust/rust_dma.rs b/samples/rust/rust_dma.rs index 874c2c964afa..12370bca97bc 100644 --- a/samples/rust/rust_dma.rs +++ b/samples/rust/rust_dma.rs @@ -4,7 +4,14 @@ //! //! To make this driver probe, QEMU must be run with `-device pci-testdev`. -use kernel::{bindings, device::Core, dma::CoherentAllocation, pci, prelude::*, types::ARef}; +use kernel::{ + bindings, + device::Core, + dma::{CoherentAllocation, Device, DmaMask}, + pci, + prelude::*, + types::ARef, +}; struct DmaSampleDriver { pdev: ARef<pci::Device>, @@ -51,6 +58,11 @@ impl pci::Driver for DmaSampleDriver { fn probe(pdev: &pci::Device<Core>, _info: &Self::IdInfo) -> Result<Pin<KBox<Self>>> { dev_info!(pdev.as_ref(), "Probe DMA test driver.\n"); + let mask = DmaMask::new::<64>(); + + // SAFETY: There are no concurrent calls to DMA allocation and mapping primitives. + unsafe { pdev.dma_set_mask_and_coherent(mask)? }; + let ca: CoherentAllocation<MyStruct> = CoherentAllocation::alloc_coherent(pdev.as_ref(), TEST_VALUES.len(), GFP_KERNEL)?; |