diff mbox series

[RFC,v3,30/33] rust: drm/kms: Add Device::num_crtcs()

Message ID 20250305230406.567126-31-lyude@redhat.com (mailing list archive)
State New
Headers show
Series Rust bindings for KMS + RVKMS | expand

Commit Message

Lyude Paul March 5, 2025, 10:59 p.m. UTC
A binding for checking drm_device.num_crtcs. We'll need this in a moment
for vblank support, since setting it up requires knowing the number of
CRTCs that a driver has initialized.

Signed-off-by: Lyude Paul <lyude@redhat.com>
---
 rust/kernel/drm/kms.rs | 11 +++++++++++
 1 file changed, 11 insertions(+)
diff mbox series

Patch

diff --git a/rust/kernel/drm/kms.rs b/rust/kernel/drm/kms.rs
index 429ce28229c9e..36a0b4c4454ba 100644
--- a/rust/kernel/drm/kms.rs
+++ b/rust/kernel/drm/kms.rs
@@ -311,6 +311,17 @@  pub fn mode_config_lock(&self) -> ModeConfigGuard<'_, T> {
         // held throughout ModeConfigGuard's lifetime.
         ModeConfigGuard(self.mode_config_mutex().lock(), PhantomData)
     }
+
+    /// Return the number of registered CRTCs
+    #[inline]
+    pub fn num_crtcs(&self) -> u32 {
+        // SAFETY:
+        // * This can only be modified during the single-threaded context before registration, so
+        //   this is safe
+        // * num_crtc could be >= 0, but no less - so casting to u32 is fine (and better to prevent
+        //   errors)
+        unsafe { (*self.as_raw()).mode_config.num_crtc as u32 }
+    }
 }
 
 /// A modesetting object in DRM.