[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <B531D8E8-056C-4081-9741-373EE835B0F4@collabora.com>
Date: Thu, 28 Nov 2024 10:49:21 -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 23/35] rust: drm/kms: Add DriverPlane::atomic_check()
Hi Lyude,
> On 30 Sep 2024, at 20:10, Lyude Paul <lyude@...hat.com> wrote:
>
> Optional trait method for implementing a plane's atomic_check().
>
> Signed-off-by: Lyude Paul <lyude@...hat.com>
> ---
> rust/kernel/drm/kms/plane.rs | 41 +++++++++++++++++++++++++++++++++++-
> 1 file changed, 40 insertions(+), 1 deletion(-)
>
> diff --git a/rust/kernel/drm/kms/plane.rs b/rust/kernel/drm/kms/plane.rs
> index 506ed5ced1270..04f1bdfbb1ea2 100644
> --- a/rust/kernel/drm/kms/plane.rs
> +++ b/rust/kernel/drm/kms/plane.rs
> @@ -74,7 +74,7 @@ pub trait DriverPlane: Send + Sync + Sized {
> cleanup_fb: None,
> begin_fb_access: None, // TODO: someday?
> end_fb_access: None, // TODO: someday?
> - atomic_check: None,
> + atomic_check: if Self::HAS_ATOMIC_CHECK { Some(atomic_check_callback::<Self>) } else { None },
> atomic_update: if Self::HAS_ATOMIC_UPDATE { Some(atomic_update_callback::<Self>) } else { None },
> atomic_enable: None, // TODO
> atomic_disable: None, // TODO
> @@ -118,6 +118,21 @@ fn atomic_update(
> ) {
> build_error::build_error("This should not be reachable")
> }
> +
> + /// The optional [`drm_plane_helper_funcs.atomic_check`] hook for this plane.
> + ///
> + /// Drivers may use this to customize the atomic check phase of their [`Plane`] objects. The
> + /// result of this function determines whether the atomic check passed or failed.
> + ///
> + /// [`drm_plane_helper_funcs.atomic_check`]: srctree/include/drm/drm_modeset_helper_vtables.h
> + fn atomic_check(
> + plane: &Plane<Self>,
> + new_state: BorrowedPlaneState<'_, PlaneState<Self::State>>,
> + old_state: &PlaneState<Self::State>,
> + state: &AtomicStateComposer<Self::Driver>
> + ) -> Result {
> + build_error::build_error("This should not be reachable")
> + }
Also same comment from the last two patches apply here.
> }
>
> /// The generated C vtable for a [`DriverPlane`].
> @@ -794,3 +809,27 @@ fn deref_mut(&mut self) -> &mut Self::Target {
>
> T::atomic_update(plane, new_state, old_state, &state);
> }
> +
> +unsafe extern "C" fn atomic_check_callback<T: DriverPlane>(
> + plane: *mut bindings::drm_plane,
> + state: *mut bindings::drm_atomic_state,
> +) -> i32 {
> + // SAFETY:
> + // * We're guaranteed `plane` is of type `Plane<T>` via type invariants.
> + // * We're guaranteed by DRM that `plane` is pointing to a valid initialized state.
> + let plane = unsafe { Plane::from_raw(plane) };
> +
> + // SAFETY: We're guaranteed by DRM that `state` points to a valid instance of `drm_atomic_state`
> + let state = ManuallyDrop::new(unsafe {
> + AtomicStateComposer::<T::Driver>::new(NonNull::new_unchecked(state))
> + });
By the way, let me see if I get the bigger picture here: drivers get a composer, from which they can derive a mutator
(i.e. BorrowedPlaneState, BorrowedCrtcState, BorrowedConnectorState) that they can use to optionally mutate the
modes before atomic_update, right?
Where do the Opaque versions introduced in previous commits come in?
> +
> + // SAFETY: We're guaranteed by DRM that both the old and new atomic state are present within
> + // this `drm_atomic_state`
> + let (old_state, new_state) = unsafe {(
> + state.get_old_plane_state(plane).unwrap_unchecked(),
> + state.get_new_plane_state(plane).unwrap_unchecked(),
> + )};
> +
> + from_result(|| T::atomic_check(plane, new_state, old_state, &state).map(|_| 0))
> +}
> --
> 2.46.1
>
>
— Daniel
Powered by blists - more mailing lists