[PATCH v14 10/11] rust: samples: dma: set DMA mask
From: Abdiel Janulgue
Date: Tue Mar 11 2025 - 13:52:36 EST
From: Danilo Krummrich <dakr@xxxxxxxxxx>
Set a DMA mask for the `pci::Device` in the Rust DMA sample driver.
Signed-off-by: Danilo Krummrich <dakr@xxxxxxxxxx>
Signed-off-by: Abdiel Janulgue <abdiel.janulgue@xxxxxxxxx>
---
samples/rust/rust_dma.rs | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/samples/rust/rust_dma.rs b/samples/rust/rust_dma.rs
index 4c7ebf66647a..39b6050aa3b6 100644
--- a/samples/rust/rust_dma.rs
+++ b/samples/rust/rust_dma.rs
@@ -4,7 +4,12 @@
//!
//! To make this driver probe, QEMU must be run with `-device pci-testdev`.
-use kernel::{bindings, dma::CoherentAllocation, pci, prelude::*};
+use kernel::{
+ bindings,
+ dma::{CoherentAllocation, Device},
+ pci,
+ prelude::*,
+};
struct DmaSampleDriver {
pdev: pci::Device,
@@ -51,6 +56,8 @@ impl pci::Driver for DmaSampleDriver {
fn probe(pdev: &mut pci::Device, _info: &Self::IdInfo) -> Result<Pin<KBox<Self>>> {
dev_info!(pdev.as_ref(), "Probe DMA test driver.\n");
+ pdev.dma_set_mask_and_coherent(kernel::dma::dma_bit_mask(64))?;
+
let ca: CoherentAllocation<MyStruct> =
CoherentAllocation::alloc_coherent(pdev, TEST_VALUES.len(), GFP_KERNEL)?;
--
2.43.0