linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 3/9] rust: helpers: Add bindings/wrappers for dma_resv_lock
       [not found] <20251016210955.2813186-1-lyude@redhat.com>
@ 2025-10-16 21:08 ` Lyude Paul
  2025-10-17 13:23   ` Alice Ryhl
  2025-10-16 21:08 ` [PATCH v4 4/9] rust: drm: gem: Add raw_dma_resv() function Lyude Paul
  1 sibling, 1 reply; 3+ messages in thread
From: Lyude Paul @ 2025-10-16 21:08 UTC (permalink / raw)
  To: dri-devel, rust-for-linux, Daniel Almeida, Alice Ryhl
  Cc: Asahi Lina, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Trevor Gross, Danilo Krummrich, Sumit Semwal,
	Christian König, Greg Kroah-Hartman, Asahi Lina,
	Viresh Kumar, FUJITA Tomonori, Krishna Ketan Rai, open list,
	open list:DMA BUFFER SHARING FRAMEWORK:Keyword:bdma_(?:buf|fence|resv)b,
	moderated list:DMA BUFFER SHARING FRAMEWORK:Keyword:bdma_(?:buf|fence|resv)b

From: Asahi Lina <lina@asahilina.net>

This is just for basic usage in the DRM shmem abstractions for implied
locking, not intended as a full DMA Reservation abstraction yet.

Signed-off-by: Asahi Lina <lina@asahilina.net>
Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
Signed-off-by: Lyude Paul <lyude@redhat.com>
---
 rust/bindings/bindings_helper.h |  1 +
 rust/helpers/dma-resv.c         | 13 +++++++++++++
 rust/helpers/helpers.c          |  1 +
 3 files changed, 15 insertions(+)
 create mode 100644 rust/helpers/dma-resv.c

diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h
index 2e43c66635a2c..07f79e125c329 100644
--- a/rust/bindings/bindings_helper.h
+++ b/rust/bindings/bindings_helper.h
@@ -48,6 +48,7 @@
 #include <linux/cpumask.h>
 #include <linux/cred.h>
 #include <linux/debugfs.h>
+#include <linux/dma-resv.h>
 #include <linux/device/faux.h>
 #include <linux/dma-direction.h>
 #include <linux/dma-mapping.h>
diff --git a/rust/helpers/dma-resv.c b/rust/helpers/dma-resv.c
new file mode 100644
index 0000000000000..05501cb814513
--- /dev/null
+++ b/rust/helpers/dma-resv.c
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/dma-resv.h>
+
+int rust_helper_dma_resv_lock(struct dma_resv *obj, struct ww_acquire_ctx *ctx)
+{
+	return dma_resv_lock(obj, ctx);
+}
+
+void rust_helper_dma_resv_unlock(struct dma_resv *obj)
+{
+	dma_resv_unlock(obj);
+}
diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c
index 551da6c9b5064..36d40f911345c 100644
--- a/rust/helpers/helpers.c
+++ b/rust/helpers/helpers.c
@@ -25,6 +25,7 @@
 #include "cred.c"
 #include "device.c"
 #include "dma.c"
+#include "dma-resv.c"
 #include "drm.c"
 #include "err.c"
 #include "irq.c"
-- 
2.51.0


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

* [PATCH v4 4/9] rust: drm: gem: Add raw_dma_resv() function
       [not found] <20251016210955.2813186-1-lyude@redhat.com>
  2025-10-16 21:08 ` [PATCH v4 3/9] rust: helpers: Add bindings/wrappers for dma_resv_lock Lyude Paul
@ 2025-10-16 21:08 ` Lyude Paul
  1 sibling, 0 replies; 3+ messages in thread
From: Lyude Paul @ 2025-10-16 21:08 UTC (permalink / raw)
  To: dri-devel, rust-for-linux, Daniel Almeida, Alice Ryhl
  Cc: David Airlie, Simona Vetter, Danilo Krummrich, Miguel Ojeda,
	Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Trevor Gross, Sumit Semwal,
	Christian König, Asahi Lina, Shankari Anand, open list,
	open list:DMA BUFFER SHARING FRAMEWORK:Keyword:bdma_(?:buf|fence|resv)b,
	moderated list:DMA BUFFER SHARING FRAMEWORK:Keyword:bdma_(?:buf|fence|resv)b

For retrieving a pointer to the struct dma_resv for a given GEM object. We
also introduce it in a new trait, BaseObjectPrivate, which we automatically
implement for all gem objects and don't expose to users outside of the
crate.

Signed-off-by: Lyude Paul <lyude@redhat.com>
---
 rust/kernel/drm/gem/mod.rs | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/rust/kernel/drm/gem/mod.rs b/rust/kernel/drm/gem/mod.rs
index 981fbb931e952..760fcd61da0b7 100644
--- a/rust/kernel/drm/gem/mod.rs
+++ b/rust/kernel/drm/gem/mod.rs
@@ -199,6 +199,18 @@ fn create_mmap_offset(&self) -> Result<u64> {
 
 impl<T: IntoGEMObject> BaseObject for T {}
 
+/// Crate-private base operations shared by all GEM object classes.
+#[expect(unused)]
+pub(crate) trait BaseObjectPrivate: IntoGEMObject {
+    /// Return a pointer to this object's dma_resv.
+    fn raw_dma_resv(&self) -> *mut bindings::dma_resv {
+        // SAFETY: `as_gem_obj()` always returns a valid pointer to the base DRM gem object
+        unsafe { (*self.as_raw()).resv }
+    }
+}
+
+impl<T: IntoGEMObject> BaseObjectPrivate for T {}
+
 /// A base GEM object.
 ///
 /// Invariants
-- 
2.51.0


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

* Re: [PATCH v4 3/9] rust: helpers: Add bindings/wrappers for dma_resv_lock
  2025-10-16 21:08 ` [PATCH v4 3/9] rust: helpers: Add bindings/wrappers for dma_resv_lock Lyude Paul
@ 2025-10-17 13:23   ` Alice Ryhl
  0 siblings, 0 replies; 3+ messages in thread
From: Alice Ryhl @ 2025-10-17 13:23 UTC (permalink / raw)
  To: Lyude Paul
  Cc: dri-devel, rust-for-linux, Daniel Almeida, Asahi Lina,
	Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Trevor Gross, Danilo Krummrich, Sumit Semwal,
	Christian König, Greg Kroah-Hartman, Asahi Lina,
	Viresh Kumar, FUJITA Tomonori, Krishna Ketan Rai, open list,
	open list:DMA BUFFER SHARING FRAMEWORK:Keyword:bdma_(?:buf|fence|resv)b,
	moderated list:DMA BUFFER SHARING FRAMEWORK:Keyword:bdma_(?:buf|fence|resv)b

On Thu, Oct 16, 2025 at 05:08:16PM -0400, Lyude Paul wrote:
> From: Asahi Lina <lina@asahilina.net>
> 
> This is just for basic usage in the DRM shmem abstractions for implied
> locking, not intended as a full DMA Reservation abstraction yet.
> 
> Signed-off-by: Asahi Lina <lina@asahilina.net>
> Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
> Signed-off-by: Lyude Paul <lyude@redhat.com>

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

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

end of thread, other threads:[~2025-10-17 13:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20251016210955.2813186-1-lyude@redhat.com>
2025-10-16 21:08 ` [PATCH v4 3/9] rust: helpers: Add bindings/wrappers for dma_resv_lock Lyude Paul
2025-10-17 13:23   ` Alice Ryhl
2025-10-16 21:08 ` [PATCH v4 4/9] rust: drm: gem: Add raw_dma_resv() function Lyude Paul

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).