[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20250305230406.567126-14-lyude@redhat.com>
Date: Wed, 5 Mar 2025 17:59:29 -0500
From: Lyude Paul <lyude@...hat.com>
To: dri-devel@...ts.freedesktop.org,
rust-for-linux@...r.kernel.org
Cc: Danilo Krummrich <dakr@...nel.org>,
mcanal@...lia.com,
Alice Ryhl <aliceryhl@...gle.com>,
Maxime Ripard <mripard@...nel.org>,
Simona Vetter <sima@...ll.ch>,
Daniel Almeida <daniel.almeida@...labora.com>,
Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>,
Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>,
Andreas Hindborg <a.hindborg@...nel.org>,
Trevor Gross <tmgross@...ch.edu>,
linux-kernel@...r.kernel.org (open list)
Subject: [RFC v3 13/33] rust: drm/kms: Add RawPlane and RawPlaneState
Same thing as RawCrtc and RawCrtcState, but for DRM planes now
Signed-off-by: Lyude Paul <lyude@...hat.com>
---
V3:
* Limit unsafe scope in RawPlane::index()
* Improve safety comments
Signed-off-by: Lyude Paul <lyude@...hat.com>
---
rust/kernel/drm/kms/plane.rs | 37 ++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/rust/kernel/drm/kms/plane.rs b/rust/kernel/drm/kms/plane.rs
index 9f262156eac6c..d1fabdf42df54 100644
--- a/rust/kernel/drm/kms/plane.rs
+++ b/rust/kernel/drm/kms/plane.rs
@@ -373,6 +373,29 @@ pub unsafe trait ModesettablePlane: AsRawPlane {
type State: FromRawPlaneState;
}
+/// Common methods available on any type which implements [`AsRawPlane`].
+///
+/// This is implemented internally by DRM, and provides many of the basic methods for working with
+/// planes.
+pub trait RawPlane: AsRawPlane {
+ /// Return the index of this DRM plane
+ #[inline]
+ fn index(&self) -> u32 {
+ // SAFETY:
+ // - The index is initialized by the time we expose planes to users, and does not change
+ // throughout its lifetime
+ // - `.as_raw()` always returns a valid poiinter.
+ unsafe { *self.as_raw() }.index
+ }
+
+ /// Return the index of this DRM plane in the form of a bitmask
+ #[inline]
+ fn mask(&self) -> u32 {
+ 1 << self.index()
+ }
+}
+impl<T: AsRawPlane> RawPlane for T {}
+
/// A trait implemented by any type which can produce a reference to a [`struct drm_plane_state`].
///
/// This is implemented internally by DRM.
@@ -436,6 +459,20 @@ pub trait FromRawPlaneState: AsRawPlaneState {
unsafe fn from_raw_mut<'a>(ptr: *mut bindings::drm_plane_state) -> &'a mut Self;
}
+/// Common methods available on any type which implements [`AsRawPlane`].
+///
+/// This is implemented internally by DRM, and provides many of the basic methods for working with
+/// the atomic state of [`Plane`]s.
+pub trait RawPlaneState: AsRawPlaneState {
+ /// Return the plane that this plane state belongs to.
+ fn plane(&self) -> &Self::Plane {
+ // SAFETY: The index is initialized by the time we expose Plane objects to users, and is
+ // invariant throughout the lifetime of the Plane
+ unsafe { Self::Plane::from_raw(self.as_raw().plane) }
+ }
+}
+impl<T: AsRawPlaneState + ?Sized> RawPlaneState for T {}
+
/// The main interface for a [`struct drm_plane_state`].
///
/// This type is the main interface for dealing with the atomic state of DRM planes. In addition, it
--
2.48.1
Powered by blists - more mailing lists