rust/helpers/dma.c | 5 +++++ rust/kernel/dma.rs | 17 +++++++++++++++++ 2 files changed, 22 insertions(+)
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>
---
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
On 23.01.26 14:13, Beata Michalska wrote:
> 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>
> ---
>
> 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);
> +}
I was about to ask "please add __rust_helper" [1]. But looking into
driver-core-next it looks like some of the function in dma.c have
__rust_helper (from [1]) and some don't (from [2]). Is this by
intention or was this an omission in [2]?
Best regards
Dirk
[1]
https://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git/commit/rust/helpers/dma.c?h=driver-core-next&id=8a03afe94763108537e33b48378bbc7472b4cc9d
[2]
https://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git/commit/rust/helpers/dma.c?h=driver-core-next&id=d8932355f8c5673106eca49abd142f8fe0c1fe8b
On Fri Jan 23, 2026 at 4:39 PM GMT, Dirk Behme wrote:
> On 23.01.26 14:13, Beata Michalska wrote:
>> 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>
>> ---
>>
>> 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);
>> +}
>
> I was about to ask "please add __rust_helper" [1]. But looking into
> driver-core-next it looks like some of the function in dma.c have
> __rust_helper (from [1]) and some don't (from [2]). Is this by
> intention or was this an omission in [2]?
This is an omission. It's an also a relatively new addition which means that
it's not covered in Alice's series.
Best,
Gary
© 2016 - 2026 Red Hat, Inc.