From 02fbae62c2a09ce00f828223d602e9b186509daa Mon Sep 17 00:00:00 2001 From: Lyude Paul <lyude@redhat.com> Date: Fri, 6 Sep 2024 13:09:42 -0400 Subject: [PATCH] rust: drm/kms: Add Device::num_crtcs() 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 | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/rust/kernel/drm/kms.rs b/rust/kernel/drm/kms.rs index f6a808279d468..48ae8bc0f52ce 100644 --- a/rust/kernel/drm/kms.rs +++ b/rust/kernel/drm/kms.rs @@ -326,6 +326,20 @@ impl<T: KmsDriver> Device<T> { // prevent errors) unsafe { (*self.as_raw()).mode_config.num_total_plane as u32 } } + + /// Return the number of registered CRTCs + /// TODO: while `num_crtc` is of i32, that type actually makes literally no sense here and just + /// causes problems and unecessary casts. Same for num_plane(). So, fix that at some point (we + /// will never get n < 0 anyway) + #[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. -- GitLab