[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250710194556.62605-6-dakr@kernel.org>
Date: Thu, 10 Jul 2025 21:45:47 +0200
From: Danilo Krummrich <dakr@...nel.org>
To: abdiel.janulgue@...il.com,
daniel.almeida@...labora.com,
robin.murphy@....com,
a.hindborg@...nel.org,
ojeda@...nel.org,
alex.gaynor@...il.com,
boqun.feng@...il.com,
gary@...yguo.net,
bjorn3_gh@...tonmail.com,
lossin@...nel.org,
aliceryhl@...gle.com,
tmgross@...ch.edu,
bhelgaas@...gle.com,
kwilczynski@...nel.org,
gregkh@...uxfoundation.org,
rafael@...nel.org
Cc: rust-for-linux@...r.kernel.org,
linux-pci@...r.kernel.org,
linux-kernel@...r.kernel.org,
Danilo Krummrich <dakr@...nel.org>
Subject: [PATCH 5/5] rust: samples: dma: set DMA mask
Set a DMA mask for the `pci::Device` in the Rust DMA sample driver.
Signed-off-by: Danilo Krummrich <dakr@...nel.org>
---
samples/rust/rust_dma.rs | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/samples/rust/rust_dma.rs b/samples/rust/rust_dma.rs
index 9e05d5c0cdae..b295c346252f 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, dma_bit_mask},
+ pci,
+ prelude::*,
+ types::ARef,
+};
struct DmaSampleDriver {
pdev: ARef<pci::Device>,
@@ -51,6 +58,9 @@ 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");
+ // SAFETY: There are no concurrent calls to DMA allocation and mapping primitives.
+ unsafe { pdev.dma_set_mask_and_coherent(dma_bit_mask(64))? };
+
let ca: CoherentAllocation<MyStruct> =
CoherentAllocation::alloc_coherent(pdev.as_ref(), TEST_VALUES.len(), GFP_KERNEL)?;
--
2.50.0
Powered by blists - more mailing lists