[RFC PATCH 2/9] rust: drm: gem: add method to return DmaResv from GEMObject

Maíra Canal mcanal at igalia.com
Fri Mar 17 12:12:06 UTC 2023


A GEMObject, related to struct drm_gem_object, holds a pointer
to reservation object associated with the this GEM object. Therefore,
expose this reservation object through the DmaResv safe abstraction.

Signed-off-by: Maíra Canal <mcanal at igalia.com>
---
 rust/kernel/drm/gem/mod.rs | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/rust/kernel/drm/gem/mod.rs b/rust/kernel/drm/gem/mod.rs
index c4a42bb2f718..dae95e5748a7 100644
--- a/rust/kernel/drm/gem/mod.rs
+++ b/rust/kernel/drm/gem/mod.rs
@@ -11,6 +11,7 @@ use alloc::boxed::Box;
 
 use crate::{
     bindings,
+    dma_resv::DmaResv,
     drm::{device, drv, file},
     error::{to_result, Result},
     prelude::*,
@@ -136,6 +137,12 @@ pub trait BaseObject: IntoGEMObject {
         self.gem_obj().size
     }
 
+    /// Returns the pointer to reservation object associated with this GEM object.
+    fn resv(&self) -> DmaResv {
+        // SAFETY: Every GEM object holds a reference to a reservation object
+        unsafe { DmaResv::from_raw(self.gem_obj().resv) }
+    }
+
     /// Sets the exportable flag, which controls whether the object can be exported via PRIME.
     fn set_exportable(&mut self, exportable: bool) {
         self.mut_gem_obj().exportable = exportable;
-- 
2.39.2



More information about the dri-devel mailing list