Same thing as RawConnector and RawConnectorState, just for CRTCs now. Signed-off-by: Lyude Paul <lyude@xxxxxxxxxx> --- rust/kernel/drm/kms/crtc.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/rust/kernel/drm/kms/crtc.rs b/rust/kernel/drm/kms/crtc.rs index 1a3c9c448afcc..246d15a15c14d 100644 --- a/rust/kernel/drm/kms/crtc.rs +++ b/rust/kernel/drm/kms/crtc.rs @@ -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 { -- 2.46.1