]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
rust: dma: allow drivers to tune max segment size
authorBeata Michalska <beata.michalska@arm.com>
Wed, 28 Jan 2026 13:53:20 +0000 (14:53 +0100)
committerDanilo Krummrich <dakr@kernel.org>
Wed, 28 Jan 2026 15:53:24 +0000 (16:53 +0100)
Make dma_set_max_seg_size() available to Rust so drivers can perform
standard DMA setup steps.

Signed-off-by: Beata Michalska <beata.michalska@arm.com>
Acked-by: Robin Murphy <robvin.murphy@arm.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://patch.msgid.link/20260128135320.689046-1-beata.michalska@arm.com
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
rust/helpers/dma.c
rust/kernel/dma.rs

index e7defeecda71b9babbe10143cc4ed31f39157d2c..20232ac64850bd8365881398f5ff3b6c3d251765 100644 (file)
@@ -43,3 +43,9 @@ size_t rust_helper_dma_max_mapping_size(struct device *dev)
 {
        return dma_max_mapping_size(dev);
 }
+
+__rust_helper void rust_helper_dma_set_max_seg_size(struct device *dev,
+                                                   unsigned int size)
+{
+       dma_set_max_seg_size(dev, size);
+}
index acc65b1e0f245c0c6f15ccf3c104fb6189e427e7..909d56fd5118ee1db3585a8c10a99fe1d091dd00 100644 (file)
@@ -85,6 +85,23 @@ pub trait Device: AsRef<device::Device<Core>> {
             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.