diff mbox series

[WIP,RFC,v2,31/35] rust: drm: Add Device::event_lock()

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

Commit Message

Lyude Paul Sept. 30, 2024, 11:10 p.m. UTC
This is just a crate-private helper to use Lock::from_raw() to provide an
immutable reference to the DRM event_lock, so that it can be used like a
normal rust spinlock. We'll need this for adding vblank related bindings.

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

Patch

diff --git a/rust/kernel/drm/device.rs b/rust/kernel/drm/device.rs
index d4d6b1185f6a6..207e7ea87cf8f 100644
--- a/rust/kernel/drm/device.rs
+++ b/rust/kernel/drm/device.rs
@@ -15,6 +15,7 @@ 
     error::from_err_ptr,
     error::Result,
     types::{ARef, AlwaysRefCounted, ForeignOwnable, Opaque},
+    sync::*,
 };
 use core::{
     ffi::c_void,
@@ -159,6 +160,12 @@  pub fn data(&self) -> <T::Data as ForeignOwnable>::Borrowed<'_> {
         unsafe { <T::Data as ForeignOwnable>::from_foreign(drm.raw_data()) };
     }
 
+    /// Returns a reference to the `event` spinlock
+    pub(crate) fn event_lock(&self) -> &SpinLockIrq<()> {
+        // SAFETY: `event_lock` is initialized for as long as `self` is exposed to users
+        unsafe { SpinLockIrq::from_raw(&mut (*self.as_raw()).event_lock) }
+    }
+
     pub(crate) const fn has_kms() -> bool {
         <T::Kms as KmsImplPrivate>::MODE_CONFIG_OPS.is_some()
     }