[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <B8CBF3CE-1591-4624-816D-9A528B76E1B2@collabora.com>
Date: Wed, 27 Nov 2024 16:26:06 -0300
From: Daniel Almeida <daniel.almeida@...labora.com>
To: Lyude Paul <lyude@...hat.com>
Cc: dri-devel@...ts.freedesktop.org,
rust-for-linux@...r.kernel.org,
Asahi Lina <lina@...hilina.net>,
Danilo Krummrich <dakr@...nel.org>,
mcanal@...lia.com,
airlied@...hat.com,
zhiw@...dia.com,
cjia@...dia.com,
jhubbard@...dia.com,
Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>,
Wedson Almeida Filho <wedsonaf@...il.com>,
Boqun Feng <boqun.feng@...il.com>,
Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>,
Andreas Hindborg <a.hindborg@...sung.com>,
Alice Ryhl <aliceryhl@...gle.com>,
Trevor Gross <tmgross@...ch.edu>,
open list <linux-kernel@...r.kernel.org>
Subject: Re: [WIP RFC v2 16/35] rust: drm/kms: Add RawConnector and
RawConnectorState
Hi Lyude,
> On 30 Sep 2024, at 20:09, Lyude Paul <lyude@...hat.com> wrote:
>
> Now that we have more then one way to refer to connectors, we also want to
nit: typo here, s/then/than
> ensure that any methods which are common to any kind of connector type can
> be used on all connector representations. This is where RawConnector and
> RawConnectorState come in: we implement these traits for any type which
> implements AsRawConnector or AsRawConnectorState respectively.
>
> Signed-off-by: Lyude Paul <lyude@...hat.com>
> ---
> rust/kernel/drm/kms/connector.rs | 34 ++++++++++++++++++++++++++++++++
> 1 file changed, 34 insertions(+)
>
> diff --git a/rust/kernel/drm/kms/connector.rs b/rust/kernel/drm/kms/connector.rs
> index 98ac7fb781d4e..f62740d7f6469 100644
> --- a/rust/kernel/drm/kms/connector.rs
> +++ b/rust/kernel/drm/kms/connector.rs
> @@ -331,6 +331,27 @@ unsafe fn from_raw<'a>(ptr: *mut bindings::drm_connector) -> &'a Self {
> }
> }
>
> +/// Common methods available on any type which implements [`AsRawConnector`].
> +///
> +/// This is implemented internally by DRM, and provides many of the basic methods for working with
> +/// connectors.
> +pub trait RawConnector: AsRawConnector {
> + /// Return the index of this DRM connector
> + #[inline]
> + fn index(&self) -> u32 {
> + // SAFETY: The index is initialized by the time we expose DRM connector objects to users,
> + // and is invariant throughout the lifetime of the connector
> + unsafe { (*self.as_raw()).index }
> + }
> +
> + /// Return the bitmask derived from this DRM connector's index
> + #[inline]
> + fn mask(&self) -> u32 {
> + 1 << self.index()
> + }
> +}
> +impl<T: AsRawConnector> RawConnector for T {}
> +
> unsafe extern "C" fn connector_destroy_callback<T: DriverConnector>(
> connector: *mut bindings::drm_connector,
> ) {
> @@ -523,6 +544,19 @@ pub trait FromRawConnectorState: AsRawConnectorState {
> unsafe fn from_raw_mut<'a>(ptr: *mut bindings::drm_connector_state) -> &'a mut Self;
> }
>
> +/// Common methods available on any type which implements [`AsRawConnectorState`].
> +///
> +/// This is implemented internally by DRM, and provides many of the basic methods for working with
> +/// the atomic state of [`Connector`]s.
> +pub trait RawConnectorState: AsRawConnectorState {
> + fn connector(&self) -> &Self::Connector {
> + // SAFETY: This is guaranteed safe by type invariance, and we're guaranteed by DRM that
> + // `self.state.connector` points to a valid instance of a `Connector<T>`
> + unsafe { Self::Connector::from_raw((*self.as_raw()).connector) }
> + }
> +}
> +impl<T: AsRawConnectorState> RawConnectorState for T {}
> +
> /// The main interface for a [`struct drm_connector_state`].
> ///
> /// This type is the main interface for dealing with the atomic state of DRM connectors. In
> --
> 2.46.1
>
>
LGTM,
— Daniel
Powered by blists - more mailing lists