[RFC v3 08/33] rust: drm/kms: Add UnregisteredConnector::attach_encoder()
From: Lyude Paul
Date: Wed Mar 05 2025 - 18:10:05 EST
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@xxxxxxxxxx>
---
V3:
* Move to UnregisteredConnector interface
* Improve safety comments
Signed-off-by: Lyude Paul <lyude@xxxxxxxxxx>
---
rust/kernel/drm/kms/connector.rs | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/rust/kernel/drm/kms/connector.rs b/rust/kernel/drm/kms/connector.rs
index ed65c06ece627..6fe0a7517bd55 100644
--- a/rust/kernel/drm/kms/connector.rs
+++ b/rust/kernel/drm/kms/connector.rs
@@ -4,7 +4,7 @@
//!
//! C header: [`include/drm/drm_connector.h`](srctree/include/drm/drm_connector.h)
-use super::{KmsDriver, ModeObject, RcModeObject};
+use super::{encoder::*, KmsDriver, ModeObject, RcModeObject};
use crate::{
alloc::KBox,
bindings,
@@ -362,6 +362,18 @@ pub fn new<'a>(
// SAFETY: We just allocated the connector above, so this pointer must be valid
Ok(unsafe { &*this })
}
+
+ /// Attach an encoder to this [`Connector`].
+ #[must_use]
+ pub fn attach_encoder(&self, encoder: &impl AsRawEncoder) -> Result {
+ // SAFETY:
+ // - Both as_raw() calls are guaranteed to return a valid pointer
+ // - We're guaranteed this connector is not registered via our type invariants, thus this
+ // function is safe to call
+ to_result(unsafe {
+ bindings::drm_connector_attach_encoder(self.as_raw(), encoder.as_raw())
+ })
+ }
}
unsafe extern "C" fn connector_destroy_callback<T: DriverConnector>(
--
2.48.1