@@ -302,6 +302,25 @@ unsafe fn from_raw<'a>(ptr: *mut bindings::drm_crtc) -> &'a Self {
}
}
+/// Common methods available on any type which implements [`AsRawCrtc`].
+///
+/// This is implemented internally by DRM, and provides many of the basic methods for working with
+/// CRTCs.
+pub trait RawCrtc: AsRawCrtc {
+ /// Return the index of this CRTC.
+ fn index(&self) -> u32 {
+ // SAFETY: The index is initialized by the time we expose Crtc objects to users, and is
+ // invariant throughout the lifetime of the Crtc
+ unsafe { (*self.as_raw()).index }
+ }
+
+ /// Return the index of this DRM CRTC in the form of a bitmask.
+ fn mask(&self) -> u32 {
+ 1 << self.index()
+ }
+}
+impl<T: AsRawCrtc> RawCrtc for T {}
+
/// A [`struct drm_crtc`] without a known [`DriverCrtc`] implementation.
///
/// This is mainly for situations where our bindings can't infer the [`DriverCrtc`] implementation
@@ -447,8 +466,10 @@ pub trait AsRawCrtcState {
pub(super) use private::AsRawCrtcState as AsRawCrtcStatePrivate;
-/// A trait for providing common methods which can be used on any type that can be used as an atomic
-/// CRTC state.
+/// Common methods available on any type which implements [`AsRawCrtcState`].
+///
+/// This is implemented internally by DRM, and provides many of the basic methods for working with
+/// the atomic state of [`Crtc`]s.
pub trait RawCrtcState: AsRawCrtcState {
/// Return the CRTC that owns this state.
fn crtc(&self) -> &Self::Crtc {
Same thing as RawConnector and RawConnectorState, just for CRTCs now. Signed-off-by: Lyude Paul <lyude@redhat.com> --- rust/kernel/drm/kms/crtc.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-)