On Wed, Mar 05, 2025 at 05:59:35PM -0500, Lyude Paul wrote: > An optional trait method for implementing a CRTC's atomic state check. > > Signed-off-by: Lyude Paul <lyude@xxxxxxxxxx> > > --- > V3: > * Document uses of ManuallyDrop > > Signed-off-by: Lyude Paul <lyude@xxxxxxxxxx> > --- > rust/kernel/drm/kms/atomic.rs | 1 - > rust/kernel/drm/kms/crtc.rs | 55 +++++++++++++++++++++++++++++++++-- > 2 files changed, 52 insertions(+), 4 deletions(-) > > diff --git a/rust/kernel/drm/kms/atomic.rs b/rust/kernel/drm/kms/atomic.rs > index 3d5c70dbc4274..e0a1b5b860d6f 100644 > --- a/rust/kernel/drm/kms/atomic.rs > +++ b/rust/kernel/drm/kms/atomic.rs > @@ -274,7 +274,6 @@ impl<T: KmsDriver> AtomicStateComposer<T> { > /// # Safety > /// > /// The caller guarantees that `ptr` points to a valid instance of `drm_atomic_state`. > - #[allow(dead_code)] > pub(crate) unsafe fn new(ptr: NonNull<bindings::drm_atomic_state>) -> Self { > // SAFETY: see `AtomicStateMutator::from_raw()` > Self(unsafe { AtomicStateMutator::new(ptr) }) > diff --git a/rust/kernel/drm/kms/crtc.rs b/rust/kernel/drm/kms/crtc.rs > index 3b9c9d97fcf24..50f5b68f4a3fe 100644 > --- a/rust/kernel/drm/kms/crtc.rs > +++ b/rust/kernel/drm/kms/crtc.rs > @@ -12,7 +12,7 @@ > alloc::KBox, > bindings, > drm::device::Device, > - error::to_result, > + error::{from_result, to_result}, > init::Zeroable, > prelude::*, > private::Sealed, > @@ -21,7 +21,7 @@ > use core::{ > cell::{Cell, UnsafeCell}, > marker::*, > - mem, > + mem::{self, ManuallyDrop}, > ops::{Deref, DerefMut}, > ptr::{addr_of_mut, null, null_mut, NonNull}, > }; > @@ -78,7 +78,11 @@ pub trait DriverCrtc: Send + Sync + Sized { > helper_funcs: bindings::drm_crtc_helper_funcs { > atomic_disable: None, > atomic_enable: None, > - atomic_check: None, > + atomic_check: if Self::HAS_ATOMIC_CHECK { > + Some(atomic_check_callback::<Self>) > + } else { > + None > + }, > dpms: None, > commit: None, > prepare: None, > @@ -113,6 +117,21 @@ pub trait DriverCrtc: Send + Sync + Sized { > /// > /// Drivers may use this to instantiate their [`DriverCrtc`] object. > fn new(device: &Device<Self::Driver>, args: &Self::Args) -> impl PinInit<Self, Error>; > + > + /// The optional [`drm_crtc_helper_funcs.atomic_check`] hook for this crtc. > + /// > + /// Drivers may use this to customize the atomic check phase of their [`Crtc`] objects. The > + /// result of this function determines whether the atomic check passed or failed. > + /// > + /// [`drm_crtc_helper_funcs.atomic_check`]: srctree/include/drm/drm_modeset_helper_vtables.h > + fn atomic_check( > + _crtc: &Crtc<Self>, > + _old_state: &CrtcState<Self::State>, > + _new_state: CrtcStateMutator<'_, CrtcState<Self::State>>, > + _state: &AtomicStateComposer<Self::Driver>, > + ) -> Result { > + build_error::build_error("This should not be reachable") > + } We've spent an awful lot of time trying to get rid of old_state/new_state in the atomic hooks, so I'd prefer to not reintroduce them again in Rust, even more so if you have accessors to go from AtomicStateComposer to CrtcStateMutator, which I think you do. Maxime
Attachment:
signature.asc
Description: PGP signature