rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] rust: Add some DMA helpers for architectures without CONFIG_HAS_DMA
@ 2025-12-04 16:06 FUJITA Tomonori
  2025-12-05  9:21 ` Alice Ryhl
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: FUJITA Tomonori @ 2025-12-04 16:06 UTC (permalink / raw)
  To: dakr, ojeda
  Cc: a.hindborg, abdiel.janulgue, aliceryhl, bjorn3_gh, boqun.feng,
	daniel.almeida, gary, lossin, robin.murphy, rust-for-linux,
	tmgross

Add dma_set_mask(), dma_set_coherent_mask(), dma_map_sgtable(), and
dma_max_mapping_size() helpers to fix a build error when
CONFIG_HAS_DMA is not enabled.

Note that when CONFIG_HAS_DMA is enabled, they are included in both
bindings_generated.rs and bindings_helpers_generated.rs. The former
takes precedence so behavior remains unchanged in that case.

This fixes the following build error on UML:

error[E0425]: cannot find function `dma_set_mask` in crate `bindings`
     --> /linux/rust/kernel/dma.rs:46:38
      |
   46 |         to_result(unsafe { bindings::dma_set_mask(self.as_ref().as_raw(), mask.value()) })
      |                                      ^^^^^^^^^^^^ help: a function with a similar name exists: `xa_set_mark`
      |
     ::: /build/um/rust/bindings/bindings_generated.rs:24690:5
      |
24690 |     pub fn xa_set_mark(arg1: *mut xarray, index: ffi::c_ulong, arg2: xa_mark_t);
      |     ---------------------------------------------------------------------------- similarly named function `xa_set_mark` defined here

error[E0425]: cannot find function `dma_set_coherent_mask` in crate `bindings`
     --> /linux/rust/kernel/dma.rs:63:38
      |
   63 |         to_result(unsafe { bindings::dma_set_coherent_mask(self.as_ref().as_raw(), mask.value()) })
      |                                      ^^^^^^^^^^^^^^^^^^^^^ help: a function with a similar name exists: `dma_coherent_ok`
      |
     ::: /build/um/rust/bindings/bindings_generated.rs:52745:5
      |
52745 |     pub fn dma_coherent_ok(dev: *mut device, phys: phys_addr_t, size: usize) -> bool_;
      |     ---------------------------------------------------------------------------------- similarly named function `dma_coherent_ok` defined here

error[E0425]: cannot find function `dma_map_sgtable` in crate `bindings`
    --> /linux/rust/kernel/scatterlist.rs:212:23
     |
 212 |               bindings::dma_map_sgtable(dev.as_raw(), sgt.as_ptr(), dir.into(), 0)
     |                         ^^^^^^^^^^^^^^^ help: a function with a similar name exists: `dma_unmap_sgtable`
     |
    ::: /build/um/rust/bindings/bindings_helpers_generated.rs:1351:5
     |
1351 | /     pub fn dma_unmap_sgtable(
1352 | |         dev: *mut device,
1353 | |         sgt: *mut sg_table,
1354 | |         dir: dma_data_direction,
1355 | |         attrs: ffi::c_ulong,
1356 | |     );
     | |______- similarly named function `dma_unmap_sgtable` defined here

error[E0425]: cannot find function `dma_max_mapping_size` in crate `bindings`
   --> /linux/rust/kernel/scatterlist.rs:356:52
    |
356 |         let max_segment = match unsafe { bindings::dma_max_mapping_size(dev.as_raw()) } {
    |                                                    ^^^^^^^^^^^^^^^^^^^^ not found in `bindings`

error: aborting due to 4 previous errors

Fixes: 101d66828a4ee ("rust: dma: add DMA addressing capabilities")
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
---
 rust/helpers/dma.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/rust/helpers/dma.c b/rust/helpers/dma.c
index 6e741c197242..2afa32c21c94 100644
--- a/rust/helpers/dma.c
+++ b/rust/helpers/dma.c
@@ -19,3 +19,24 @@ int rust_helper_dma_set_mask_and_coherent(struct device *dev, u64 mask)
 {
 	return dma_set_mask_and_coherent(dev, mask);
 }
+
+int rust_helper_dma_set_mask(struct device *dev, u64 mask)
+{
+	return dma_set_mask(dev, mask);
+}
+
+int rust_helper_dma_set_coherent_mask(struct device *dev, u64 mask)
+{
+	return dma_set_coherent_mask(dev, mask);
+}
+
+int rust_helper_dma_map_sgtable(struct device *dev, struct sg_table *sgt,
+				enum dma_data_direction dir, unsigned long attrs)
+{
+	return dma_map_sgtable(dev, sgt, dir, attrs);
+}
+
+size_t rust_helper_dma_max_mapping_size(struct device *dev)
+{
+	return dma_max_mapping_size(dev);
+}

base-commit: 559e608c46553c107dbba19dae0854af7b219400
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v1] rust: Add some DMA helpers for architectures without CONFIG_HAS_DMA
  2025-12-04 16:06 [PATCH v1] rust: Add some DMA helpers for architectures without CONFIG_HAS_DMA FUJITA Tomonori
@ 2025-12-05  9:21 ` Alice Ryhl
  2025-12-05  9:33   ` Miguel Ojeda
  2025-12-10  1:46 ` David Gow
  2025-12-16 12:29 ` Danilo Krummrich
  2 siblings, 1 reply; 5+ messages in thread
From: Alice Ryhl @ 2025-12-05  9:21 UTC (permalink / raw)
  To: FUJITA Tomonori
  Cc: dakr, ojeda, a.hindborg, abdiel.janulgue, bjorn3_gh, boqun.feng,
	daniel.almeida, gary, lossin, robin.murphy, rust-for-linux,
	tmgross

On Fri, Dec 05, 2025 at 01:06:39AM +0900, FUJITA Tomonori wrote:
> Add dma_set_mask(), dma_set_coherent_mask(), dma_map_sgtable(), and
> dma_max_mapping_size() helpers to fix a build error when
> CONFIG_HAS_DMA is not enabled.
> 
> Note that when CONFIG_HAS_DMA is enabled, they are included in both
> bindings_generated.rs and bindings_helpers_generated.rs. The former
> takes precedence so behavior remains unchanged in that case.
> 
> This fixes the following build error on UML:
> 
> error[E0425]: cannot find function `dma_set_mask` in crate `bindings`
>      --> /linux/rust/kernel/dma.rs:46:38
>       |
>    46 |         to_result(unsafe { bindings::dma_set_mask(self.as_ref().as_raw(), mask.value()) })
>       |                                      ^^^^^^^^^^^^ help: a function with a similar name exists: `xa_set_mark`
>       |
>      ::: /build/um/rust/bindings/bindings_generated.rs:24690:5
>       |
> 24690 |     pub fn xa_set_mark(arg1: *mut xarray, index: ffi::c_ulong, arg2: xa_mark_t);
>       |     ---------------------------------------------------------------------------- similarly named function `xa_set_mark` defined here
> 
> error[E0425]: cannot find function `dma_set_coherent_mask` in crate `bindings`
>      --> /linux/rust/kernel/dma.rs:63:38
>       |
>    63 |         to_result(unsafe { bindings::dma_set_coherent_mask(self.as_ref().as_raw(), mask.value()) })
>       |                                      ^^^^^^^^^^^^^^^^^^^^^ help: a function with a similar name exists: `dma_coherent_ok`
>       |
>      ::: /build/um/rust/bindings/bindings_generated.rs:52745:5
>       |
> 52745 |     pub fn dma_coherent_ok(dev: *mut device, phys: phys_addr_t, size: usize) -> bool_;
>       |     ---------------------------------------------------------------------------------- similarly named function `dma_coherent_ok` defined here
> 
> error[E0425]: cannot find function `dma_map_sgtable` in crate `bindings`
>     --> /linux/rust/kernel/scatterlist.rs:212:23
>      |
>  212 |               bindings::dma_map_sgtable(dev.as_raw(), sgt.as_ptr(), dir.into(), 0)
>      |                         ^^^^^^^^^^^^^^^ help: a function with a similar name exists: `dma_unmap_sgtable`
>      |
>     ::: /build/um/rust/bindings/bindings_helpers_generated.rs:1351:5
>      |
> 1351 | /     pub fn dma_unmap_sgtable(
> 1352 | |         dev: *mut device,
> 1353 | |         sgt: *mut sg_table,
> 1354 | |         dir: dma_data_direction,
> 1355 | |         attrs: ffi::c_ulong,
> 1356 | |     );
>      | |______- similarly named function `dma_unmap_sgtable` defined here
> 
> error[E0425]: cannot find function `dma_max_mapping_size` in crate `bindings`
>    --> /linux/rust/kernel/scatterlist.rs:356:52
>     |
> 356 |         let max_segment = match unsafe { bindings::dma_max_mapping_size(dev.as_raw()) } {
>     |                                                    ^^^^^^^^^^^^^^^^^^^^ not found in `bindings`
> 
> error: aborting due to 4 previous errors
> 
> Fixes: 101d66828a4ee ("rust: dma: add DMA addressing capabilities")
> Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>

should this cc stable?

Reviewed-by: Alice Ryhl <aliceryhl@google.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v1] rust: Add some DMA helpers for architectures without CONFIG_HAS_DMA
  2025-12-05  9:21 ` Alice Ryhl
@ 2025-12-05  9:33   ` Miguel Ojeda
  0 siblings, 0 replies; 5+ messages in thread
From: Miguel Ojeda @ 2025-12-05  9:33 UTC (permalink / raw)
  To: Alice Ryhl, David Gow, Richard Weinberger, Anton Ivanov,
	Johannes Berg
  Cc: FUJITA Tomonori, dakr, ojeda, a.hindborg, abdiel.janulgue,
	bjorn3_gh, boqun.feng, daniel.almeida, gary, lossin, robin.murphy,
	rust-for-linux, tmgross

On Fri, Dec 5, 2025 at 10:21 AM Alice Ryhl <aliceryhl@google.com> wrote:
>
> should this cc stable?

If possible, that would be nice. I "unofficially" test UML with Rust
in stable and I have seen these in 6.17.y.

Cc David who does some UML work and UML.

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v1] rust: Add some DMA helpers for architectures without CONFIG_HAS_DMA
  2025-12-04 16:06 [PATCH v1] rust: Add some DMA helpers for architectures without CONFIG_HAS_DMA FUJITA Tomonori
  2025-12-05  9:21 ` Alice Ryhl
@ 2025-12-10  1:46 ` David Gow
  2025-12-16 12:29 ` Danilo Krummrich
  2 siblings, 0 replies; 5+ messages in thread
From: David Gow @ 2025-12-10  1:46 UTC (permalink / raw)
  To: FUJITA Tomonori
  Cc: dakr, ojeda, a.hindborg, abdiel.janulgue, aliceryhl, bjorn3_gh,
	boqun.feng, daniel.almeida, gary, lossin, robin.murphy,
	rust-for-linux, tmgross

[-- Attachment #1: Type: text/plain, Size: 3224 bytes --]

On Fri, 5 Dec 2025 at 00:10, FUJITA Tomonori <fujita.tomonori@gmail.com> wrote:
>
> Add dma_set_mask(), dma_set_coherent_mask(), dma_map_sgtable(), and
> dma_max_mapping_size() helpers to fix a build error when
> CONFIG_HAS_DMA is not enabled.
>
> Note that when CONFIG_HAS_DMA is enabled, they are included in both
> bindings_generated.rs and bindings_helpers_generated.rs. The former
> takes precedence so behavior remains unchanged in that case.
>
> This fixes the following build error on UML:
>
> error[E0425]: cannot find function `dma_set_mask` in crate `bindings`
>      --> /linux/rust/kernel/dma.rs:46:38
>       |
>    46 |         to_result(unsafe { bindings::dma_set_mask(self.as_ref().as_raw(), mask.value()) })
>       |                                      ^^^^^^^^^^^^ help: a function with a similar name exists: `xa_set_mark`
>       |
>      ::: /build/um/rust/bindings/bindings_generated.rs:24690:5
>       |
> 24690 |     pub fn xa_set_mark(arg1: *mut xarray, index: ffi::c_ulong, arg2: xa_mark_t);
>       |     ---------------------------------------------------------------------------- similarly named function `xa_set_mark` defined here
>
> error[E0425]: cannot find function `dma_set_coherent_mask` in crate `bindings`
>      --> /linux/rust/kernel/dma.rs:63:38
>       |
>    63 |         to_result(unsafe { bindings::dma_set_coherent_mask(self.as_ref().as_raw(), mask.value()) })
>       |                                      ^^^^^^^^^^^^^^^^^^^^^ help: a function with a similar name exists: `dma_coherent_ok`
>       |
>      ::: /build/um/rust/bindings/bindings_generated.rs:52745:5
>       |
> 52745 |     pub fn dma_coherent_ok(dev: *mut device, phys: phys_addr_t, size: usize) -> bool_;
>       |     ---------------------------------------------------------------------------------- similarly named function `dma_coherent_ok` defined here
>
> error[E0425]: cannot find function `dma_map_sgtable` in crate `bindings`
>     --> /linux/rust/kernel/scatterlist.rs:212:23
>      |
>  212 |               bindings::dma_map_sgtable(dev.as_raw(), sgt.as_ptr(), dir.into(), 0)
>      |                         ^^^^^^^^^^^^^^^ help: a function with a similar name exists: `dma_unmap_sgtable`
>      |
>     ::: /build/um/rust/bindings/bindings_helpers_generated.rs:1351:5
>      |
> 1351 | /     pub fn dma_unmap_sgtable(
> 1352 | |         dev: *mut device,
> 1353 | |         sgt: *mut sg_table,
> 1354 | |         dir: dma_data_direction,
> 1355 | |         attrs: ffi::c_ulong,
> 1356 | |     );
>      | |______- similarly named function `dma_unmap_sgtable` defined here
>
> error[E0425]: cannot find function `dma_max_mapping_size` in crate `bindings`
>    --> /linux/rust/kernel/scatterlist.rs:356:52
>     |
> 356 |         let max_segment = match unsafe { bindings::dma_max_mapping_size(dev.as_raw()) } {
>     |                                                    ^^^^^^^^^^^^^^^^^^^^ not found in `bindings`
>
> error: aborting due to 4 previous errors
>
> Fixes: 101d66828a4ee ("rust: dma: add DMA addressing capabilities")
> Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
> ---

Thanks -- this works for me.

Reviewed-by: David Gow <davidgow@google.com>

Cheers,
-- David

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 5281 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v1] rust: Add some DMA helpers for architectures without CONFIG_HAS_DMA
  2025-12-04 16:06 [PATCH v1] rust: Add some DMA helpers for architectures without CONFIG_HAS_DMA FUJITA Tomonori
  2025-12-05  9:21 ` Alice Ryhl
  2025-12-10  1:46 ` David Gow
@ 2025-12-16 12:29 ` Danilo Krummrich
  2 siblings, 0 replies; 5+ messages in thread
From: Danilo Krummrich @ 2025-12-16 12:29 UTC (permalink / raw)
  To: FUJITA Tomonori
  Cc: ojeda, a.hindborg, abdiel.janulgue, aliceryhl, bjorn3_gh,
	boqun.feng, daniel.almeida, gary, lossin, robin.murphy,
	rust-for-linux, tmgross, stable

(Cc: stable@vger.kernel.org)

On Thu Dec 4, 2025 at 5:06 PM CET, FUJITA Tomonori wrote:
> Add dma_set_mask(), dma_set_coherent_mask(), dma_map_sgtable(), and
> dma_max_mapping_size() helpers to fix a build error when
> CONFIG_HAS_DMA is not enabled.
>
> Note that when CONFIG_HAS_DMA is enabled, they are included in both
> bindings_generated.rs and bindings_helpers_generated.rs. The former
> takes precedence so behavior remains unchanged in that case.
>
> This fixes the following build error on UML:
>
> error[E0425]: cannot find function `dma_set_mask` in crate `bindings`
>      --> /linux/rust/kernel/dma.rs:46:38
>       |
>    46 |         to_result(unsafe { bindings::dma_set_mask(self.as_ref().as_raw(), mask.value()) })
>       |                                      ^^^^^^^^^^^^ help: a function with a similar name exists: `xa_set_mark`
>       |
>      ::: /build/um/rust/bindings/bindings_generated.rs:24690:5
>       |
> 24690 |     pub fn xa_set_mark(arg1: *mut xarray, index: ffi::c_ulong, arg2: xa_mark_t);
>       |     ---------------------------------------------------------------------------- similarly named function `xa_set_mark` defined here
>
> error[E0425]: cannot find function `dma_set_coherent_mask` in crate `bindings`
>      --> /linux/rust/kernel/dma.rs:63:38
>       |
>    63 |         to_result(unsafe { bindings::dma_set_coherent_mask(self.as_ref().as_raw(), mask.value()) })
>       |                                      ^^^^^^^^^^^^^^^^^^^^^ help: a function with a similar name exists: `dma_coherent_ok`
>       |
>      ::: /build/um/rust/bindings/bindings_generated.rs:52745:5
>       |
> 52745 |     pub fn dma_coherent_ok(dev: *mut device, phys: phys_addr_t, size: usize) -> bool_;
>       |     ---------------------------------------------------------------------------------- similarly named function `dma_coherent_ok` defined here
>
> error[E0425]: cannot find function `dma_map_sgtable` in crate `bindings`
>     --> /linux/rust/kernel/scatterlist.rs:212:23
>      |
>  212 |               bindings::dma_map_sgtable(dev.as_raw(), sgt.as_ptr(), dir.into(), 0)
>      |                         ^^^^^^^^^^^^^^^ help: a function with a similar name exists: `dma_unmap_sgtable`
>      |
>     ::: /build/um/rust/bindings/bindings_helpers_generated.rs:1351:5
>      |
> 1351 | /     pub fn dma_unmap_sgtable(
> 1352 | |         dev: *mut device,
> 1353 | |         sgt: *mut sg_table,
> 1354 | |         dir: dma_data_direction,
> 1355 | |         attrs: ffi::c_ulong,
> 1356 | |     );
>      | |______- similarly named function `dma_unmap_sgtable` defined here
>
> error[E0425]: cannot find function `dma_max_mapping_size` in crate `bindings`
>    --> /linux/rust/kernel/scatterlist.rs:356:52
>     |
> 356 |         let max_segment = match unsafe { bindings::dma_max_mapping_size(dev.as_raw()) } {
>     |                                                    ^^^^^^^^^^^^^^^^^^^^ not found in `bindings`
>
> error: aborting due to 4 previous errors
>
> Fixes: 101d66828a4ee ("rust: dma: add DMA addressing capabilities")
> Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>

Applied to driver-core-linus, thanks!

    [ Use relative paths in the error splat; add 'dma' prefix. - Danilo ]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-12-16 12:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-04 16:06 [PATCH v1] rust: Add some DMA helpers for architectures without CONFIG_HAS_DMA FUJITA Tomonori
2025-12-05  9:21 ` Alice Ryhl
2025-12-05  9:33   ` Miguel Ojeda
2025-12-10  1:46 ` David Gow
2025-12-16 12:29 ` Danilo Krummrich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).