diff mbox series

[WIP,RFC,v2,09/35] WIP: rust: drm/kms: Add Connector.attach_encoder()

Message ID 20240930233257.1189730-10-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:09 p.m. UTC
This adds a simple binding for completing the last step of creating a DRM
connector - attaching its encoder. This function should only be called
before the connector is registered, and DRM should enforce this itself by
returning an error if a driver tries to add an encoder to an
already-registered DRM connector.

Note that unlike most of the methods we'll be adding to DRM mode objects,
this is directly implemented on the Connector<T> type since I don't really
think it would make sense for us to allow this operation on an
OpaqueConnector (a DRM connector without a known DriverConnector
implementation, something we'll be adding in the next few commits).

Signed-off-by: Lyude Paul <lyude@redhat.com>

---

TODO:
* Figure out a solution for making sure that this can only be called when a
  Connector is unregistered, probably via an UnregisteredConnector type.

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

Patch

diff --git a/rust/kernel/drm/kms/connector.rs b/rust/kernel/drm/kms/connector.rs
index 0fa927a3743b2..54457b327c365 100644
--- a/rust/kernel/drm/kms/connector.rs
+++ b/rust/kernel/drm/kms/connector.rs
@@ -28,6 +28,7 @@ 
 use super::{
     ModeObject,
     RcModeObject,
+    encoder::*,
     KmsDriver,
 };
 use macros::pin_data;
@@ -227,6 +228,20 @@  pub fn new(
             ARef::from_raw(NonNull::new_unchecked(Box::into_raw(Pin::into_inner_unchecked(new))))
         })
     }
+
+    /// Attach an encoder to this [`Connector`].
+    ///
+    /// TODO: Move this to an `UnregisteredConnector` interface somehow…
+    #[must_use]
+    pub fn attach_encoder<E>(&self, encoder: &Encoder<E>) -> Result
+    where
+        E: DriverEncoder<Driver = T::Driver>
+    {
+        // SAFETY: FFI call with no special requirements
+        to_result(unsafe {
+            bindings::drm_connector_attach_encoder(self.as_raw(), encoder.as_raw())
+        })
+    }
 }
 
 /// A trait implemented by any type that acts as a [`struct drm_connector`] interface.