From a5fb73a8ab4fe9cc0ffc31e8c43bd2636f9c5427 Mon Sep 17 00:00:00 2001 From: Lyude Paul <lyude@redhat.com> Date: Thu, 23 May 2024 16:50:22 -0400 Subject: [PATCH] rust: drm/kms: Add RawPlaneState::crtc() Add a binding for checking drm_plane_state.crtc. Note that we don't have a way of knowing what DriverCrtc implementation would be used here (and want to make this function also available on OpaquePlaneState types), so we return an OpaqueCrtc. Signed-off-by: Lyude Paul <lyude@redhat.com> --- rust/kernel/drm/kms/plane.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/rust/kernel/drm/kms/plane.rs b/rust/kernel/drm/kms/plane.rs index 66d11754c203e..4d542963da881 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 {} -- GitLab