[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20260123131308.3218421-1-beata.michalska@arm.com>
Date: Fri, 23 Jan 2026 14:13:08 +0100
From: Beata Michalska <beata.michalska@....com>
To: dakr@...nel.org,
ojeda@...nel.org,
rust-for-linux@...r.kernel.org
Cc: abdiel.janulgue@...il.com,
daniel.almeida@...labora.com,
aliceryhl@...gle.com,
robin.murphy@....com,
a.hindborg@...nel.org,
boqun.feng@...il.com,
gary@...yguo.net,
bjorn3_gh@...tonmail.com,
lossin@...nel.org,
tmgross@...ch.edu,
linux-kernel@...r.kernel.org
Subject: [PATCH v2] rust: dma: allow drivers to tune max segment size
Make dma_set_max_seg_size() available to Rust so drivers can perform
standard DMA setup steps.
Signed-off-by: Beata Michalska <beata.michalska@....com>
---
v2:
- Aligned safety requirements
rust/helpers/dma.c | 5 +++++
rust/kernel/dma.rs | 17 +++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/rust/helpers/dma.c b/rust/helpers/dma.c
index 2afa32c21c94..220b9308830f 100644
--- a/rust/helpers/dma.c
+++ b/rust/helpers/dma.c
@@ -40,3 +40,8 @@ size_t rust_helper_dma_max_mapping_size(struct device *dev)
{
return dma_max_mapping_size(dev);
}
+
+void rust_helper_dma_set_max_seg_size(struct device *dev, unsigned int size)
+{
+ dma_set_max_seg_size(dev, size);
+}
diff --git a/rust/kernel/dma.rs b/rust/kernel/dma.rs
index acc65b1e0f24..909d56fd5118 100644
--- a/rust/kernel/dma.rs
+++ b/rust/kernel/dma.rs
@@ -85,6 +85,23 @@ unsafe fn dma_set_mask_and_coherent(&self, mask: DmaMask) -> Result {
bindings::dma_set_mask_and_coherent(self.as_ref().as_raw(), mask.value())
})
}
+
+ /// Set the maximum size of a single DMA segment the device may request.
+ ///
+ /// This method is usually called once from `probe()` as soon as the device capabilities are
+ /// known.
+ ///
+ /// # Safety
+ ///
+ /// This method must not be called concurrently with any DMA allocation or mapping primitives,
+ /// such as [`CoherentAllocation::alloc_attrs`].
+ unsafe fn dma_set_max_seg_size(&self, size: u32) {
+ // SAFETY:
+ // - By the type invariant of `device::Device`, `self.as_ref().as_raw()` is valid.
+ // - The safety requirement of this function guarantees that there are no concurrent calls
+ // to DMA allocation and mapping primitives using this parameter.
+ unsafe { bindings::dma_set_max_seg_size(self.as_ref().as_raw(), size) }
+ }
}
/// A DMA mask that holds a bitmask with the lowest `n` bits set.
--
2.25.1
Powered by blists - more mailing lists