Skip to content

Commit 931d925

Browse files
author
Danilo Krummrich
committed
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>
1 parent 256de48 commit 931d925

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

samples/rust/rust_dma.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44
//!
55
//! To make this driver probe, QEMU must be run with `-device pci-testdev`.
66
7-
use kernel::{bindings, device::Core, dma::CoherentAllocation, pci, prelude::*, types::ARef};
7+
use kernel::{
8+
bindings,
9+
device::Core,
10+
dma::{CoherentAllocation, Device, DmaMask},
11+
pci,
12+
prelude::*,
13+
types::ARef,
14+
};
815

916
struct DmaSampleDriver {
1017
pdev: ARef<pci::Device>,
@@ -51,6 +58,11 @@ impl pci::Driver for DmaSampleDriver {
5158
fn probe(pdev: &pci::Device<Core>, _info: &Self::IdInfo) -> Result<Pin<KBox<Self>>> {
5259
dev_info!(pdev.as_ref(), "Probe DMA test driver.\n");
5360

61+
let mask = DmaMask::new::<64>();
62+
63+
// SAFETY: There are no concurrent calls to DMA allocation and mapping primitives.
64+
unsafe { pdev.dma_set_mask_and_coherent(mask)? };
65+
5466
let ca: CoherentAllocation<MyStruct> =
5567
CoherentAllocation::alloc_coherent(pdev.as_ref(), TEST_VALUES.len(), GFP_KERNEL)?;
5668

0 commit comments

Comments
 (0)