diff --git a/rust/kernel/drm/kms/plane.rs b/rust/kernel/drm/kms/plane.rs index 66d11754c203e802def4941bef31ee7984494b24..4d542963da88115ca170ed8577b4d76d05775242 100644 --- a/rust/kernel/drm/kms/plane.rs +++ b/rust/kernel/drm/kms/plane.rs @@ -30,6 +30,7 @@ use super::{ ModeObjectVtable, StaticModeObject, atomic::*, + crtc::*, }; /// The main trait for implementing the [`struct drm_plane`] API for [`Plane`] @@ -607,6 +608,16 @@ pub trait RawPlaneState: AsRawPlaneState { // invariant throughout the lifetime of the Plane unsafe { Self::Plane::from_raw(self.as_raw().plane) } } + + /// Return the current [`OpaqueCrtc`] assigned to this plane, if there is one. + fn crtc<'a, 'b: 'a, D>(&'a self) -> Option<&'b OpaqueCrtc<D>> + where + Self::Plane: ModeObject<Driver = D>, + D: KmsDriver + { + // SAFETY: This cast is guaranteed safe by `OpaqueCrtc`s invariants. + NonNull::new(self.as_raw().crtc).map(|c| unsafe { OpaqueCrtc::from_raw(c.as_ptr()) }) + } } impl<T: AsRawPlaneState + ?Sized> RawPlaneState for T {}