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

Daniel Almeida daniel.almeida at collabora.com
Wed Nov 27 14:43:18 UTC 2024


Hi Lyude

> On 30 Sep 2024, at 20:09, Lyude Paul <lyude at redhat.com> wrote:
> 
> 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 at 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.
> 

Either that, or via the typestate pattern. But I think a UnregisteredConnector type
will work fine based on your previous UnregisteredKmsDevice.

> Signed-off-by: Lyude Paul <lyude at redhat.com>
> ---
> rust/kernel/drm/kms/connector.rs | 15 +++++++++++++++
> 1 file changed, 15 insertions(+)
> 
> 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.
> -- 
> 2.46.1
> 
> 

LGTM.

— Daniel



More information about the dri-devel mailing list