Skip to content

Commit f17f166

Browse files
hoshinolinamarcan
authored andcommitted
rust: drm: gem: Add set_exportable() method
This allows drivers to control whether a given GEM object is allowed to be exported via PRIME to other drivers.
1 parent 43f69d9 commit f17f166

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

rust/kernel/drm/gem/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ pub trait IntoGEMObject: Sized + crate::private::Sealed {
5151
/// this owning object is valid.
5252
fn gem_obj(&self) -> &bindings::drm_gem_object;
5353

54+
/// Returns a reference to the raw `drm_gem_object` structure, which must be valid as long as
55+
/// this owning object is valid.
56+
fn mut_gem_obj(&mut self) -> &mut bindings::drm_gem_object;
57+
5458
/// Converts a pointer to a `drm_gem_object` into a pointer to this type.
5559
fn from_gem_obj(obj: *mut bindings::drm_gem_object) -> *mut Self;
5660
}
@@ -120,6 +124,10 @@ impl<T: DriverObject> IntoGEMObject for Object<T> {
120124
&self.obj
121125
}
122126

127+
fn mut_gem_obj(&mut self) -> &mut bindings::drm_gem_object {
128+
&mut self.obj
129+
}
130+
123131
fn from_gem_obj(obj: *mut bindings::drm_gem_object) -> *mut Object<T> {
124132
crate::container_of!(obj, Object<T>, obj) as *mut Object<T>
125133
}
@@ -132,6 +140,11 @@ pub trait BaseObject: IntoGEMObject {
132140
self.gem_obj().size
133141
}
134142

143+
/// Sets the exportable flag, which controls whether the object can be exported via PRIME.
144+
fn set_exportable(&mut self, exportable: bool) {
145+
self.mut_gem_obj().exportable = exportable;
146+
}
147+
135148
/// Creates a new reference to the object.
136149
fn reference(&self) -> ObjectRef<Self> {
137150
// SAFETY: Having a reference to an Object implies holding a GEM reference

rust/kernel/drm/gem/shmem.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ impl<T: DriverObject> gem::IntoGEMObject for Object<T> {
241241
&self.obj.base
242242
}
243243

244+
fn mut_gem_obj(&mut self) -> &mut bindings::drm_gem_object {
245+
&mut self.obj.base
246+
}
247+
244248
fn from_gem_obj(obj: *mut bindings::drm_gem_object) -> *mut Object<T> {
245249
let shmem = crate::container_of!(obj, bindings::drm_gem_shmem_object, base)
246250
as *mut bindings::drm_gem_shmem_object;

0 commit comments

Comments
 (0)