From: Philipp Stanner <[email protected]>

This adds a trivial DMA Fence type for use in other abstractions that
need to take a DMA fence as a parameter. For now, the type is a stub,
but may be used with fences defined by C.

Signed-off-by: Philipp Stanner <[email protected]>
Signed-off-by: Alice Ryhl <[email protected]>
---
This stub is included only for completeness. Most likely we will land
this on top of the Philipp's patch that actually adds Fence for real,
and this stub commit will not be necessary.

Taken from:
https://gitlab.freedesktop.org/pstanner/linux-drm-work/-/merge_requests/1
---
 rust/kernel/dma_buf/dma_fence.rs | 32 ++++++++++++++++++++++++++++++++
 rust/kernel/dma_buf/mod.rs       |  7 +++++++
 rust/kernel/lib.rs               |  1 +
 3 files changed, 40 insertions(+)

diff --git a/rust/kernel/dma_buf/dma_fence.rs b/rust/kernel/dma_buf/dma_fence.rs
new file mode 100644
index 000000000000..135df74013db
--- /dev/null
+++ b/rust/kernel/dma_buf/dma_fence.rs
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// Copyright (C) 2025, 2026 Red Hat Inc.:
+//   - Philipp Stanner <[email protected]>
+
+//! DMA Fence support.
+//!
+//! Reference: <https://docs.kernel.org/driver-api/dma-buf.html#c.dma_fence>
+//!
+//! C header: [`include/linux/dma-fence.h`](srctree/include/linux/dma-fence.h)
+
+use crate::{
+    bindings,
+    prelude::*,
+    types::Opaque, //
+};
+
+/// A dma fence.
+#[pin_data]
+#[repr(transparent)]
+pub struct Fence {
+    #[pin]
+    inner: Opaque<bindings::dma_fence>,
+}
+
+impl Fence {
+    /// Access the raw dma fence.
+    #[inline]
+    pub fn as_raw(&self) -> *mut bindings::dma_fence {
+        self.inner.get()
+    }
+}
diff --git a/rust/kernel/dma_buf/mod.rs b/rust/kernel/dma_buf/mod.rs
new file mode 100644
index 000000000000..b66e747c35ad
--- /dev/null
+++ b/rust/kernel/dma_buf/mod.rs
@@ -0,0 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0 OR MIT
+
+//! DMA-buf subsystem abstractions.
+
+pub mod dma_fence;
+
+pub use self::dma_fence::Fence;
diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
index b72b2fbe046d..a05ccaa7598c 100644
--- a/rust/kernel/lib.rs
+++ b/rust/kernel/lib.rs
@@ -63,6 +63,7 @@
 pub mod device_id;
 pub mod devres;
 pub mod dma;
+pub mod dma_buf;
 pub mod driver;
 #[cfg(CONFIG_DRM = "y")]
 pub mod drm;

-- 
2.54.0.545.g6539524ca2-goog

Reply via email to