Signed-off-by: Lyude Paul <lyude@xxxxxxxxxx> --- drivers/gpu/drm/rvkms/plane.rs | 7 +++- rust/bindings/bindings_helper.h | 2 + rust/kernel/drm/kms.rs | 1 + rust/kernel/drm/kms/gem_atomic_helper.rs | 48 ++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 rust/kernel/drm/kms/gem_atomic_helper.rs diff --git a/drivers/gpu/drm/rvkms/plane.rs b/drivers/gpu/drm/rvkms/plane.rs index d98a1f7bf79e2..5fb1b63842929 100644 --- a/drivers/gpu/drm/rvkms/plane.rs +++ b/drivers/gpu/drm/rvkms/plane.rs @@ -4,7 +4,10 @@ prelude::*, drm::{ device::Device, - kms::plane::{self, DriverPlaneState}, + kms::{ + plane::{self, DriverPlaneState}, + gem_atomic_helper::ShadowPlaneState, + } }, }; @@ -15,7 +18,7 @@ pub(crate) struct DriverPlane { } pub(crate) type Plane = plane::Plane<DriverPlane>; -pub(crate) type PlaneState = plane::PlaneState<RvkmsPlaneState>; +pub(crate) type PlaneState = ShadowPlaneState<RvkmsPlaneState>; impl plane::DriverPlane for DriverPlane { type Initializer = impl PinInit<Self, Error>; diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h index 5856afbe6e8f6..73a5eb00e8625 100644 --- a/rust/bindings/bindings_helper.h +++ b/rust/bindings/bindings_helper.h @@ -12,6 +12,8 @@ #include <drm/drm_edid.h> #include <drm/drm_file.h> #include <drm/drm_gem.h> +#include <drm/drm_gem_atomic_helper.h> +#include <drm/drm_gem_framebuffer_helper.h> #include <drm/drm_gem_framebuffer_helper.h> #include <drm/drm_gem_shmem_helper.h> #include <drm/drm_ioctl.h> diff --git a/rust/kernel/drm/kms.rs b/rust/kernel/drm/kms.rs index b55d14415367a..14f4c3842ada0 100644 --- a/rust/kernel/drm/kms.rs +++ b/rust/kernel/drm/kms.rs @@ -6,6 +6,7 @@ pub mod crtc; pub mod encoder; pub mod plane; +pub mod gem_atomic_helper; use crate::{ drm::{drv, device::Device}, diff --git a/rust/kernel/drm/kms/gem_atomic_helper.rs b/rust/kernel/drm/kms/gem_atomic_helper.rs new file mode 100644 index 0000000000000..85bc3df32d8b7 --- /dev/null +++ b/rust/kernel/drm/kms/gem_atomic_helper.rs @@ -0,0 +1,48 @@ +use crate::{ + prelude::*, + private::Sealed, + bindings, + init::Zeroable, +}; +use super::plane::{IntoPlaneState, DriverPlaneState}; + +unsafe impl Zeroable for bindings::drm_shadow_plane_state {} + +#[derive(Default)] +#[repr(C)] +pub struct ShadowPlaneState<T: DriverPlaneState> { + shadow_state: bindings::drm_shadow_plane_state, + inner: T, +} + +impl<T: DriverPlaneState> Sealed for ShadowPlaneState<T> {} + +static_assert!(crate::offset_of!(bindings::drm_shadow_plane_state, base) == 0); + +// SAFETY: Our data layout starts with drm_plane_state (contained at the start of +// drm_shadow_plane_state) +unsafe impl<T: DriverPlaneState> IntoPlaneState for ShadowPlaneState<T> { + fn __duplicate_state(&self, plane: *mut bindings::drm_plane) -> Result<Box<Self>> { + let mut new: Box<Self> = Box::try_init(try_init!(Self { + shadow_state: bindings::drm_shadow_plane_state { ..Default::default() }, + inner: self.inner.clone() + }))?; + + // SAFETY: FFI call with no special requirements + unsafe { bindings::__drm_gem_duplicate_shadow_plane_state(plane, &mut new.shadow_state) }; + + Ok(new) + } + + fn __destroy_state(state: *mut bindings::drm_plane_state) { + // SAFETY: This would not be called without a plane state to destroy, and our data layout + // starts with `bindings::drm_plane_state` + unsafe { bindings::__drm_gem_destroy_shadow_plane_state(state.cast()) }; + } + + fn __reset_state(plane: *mut bindings::drm_plane, state: *mut bindings::drm_plane_state) { + // SAFETY: This would not be called without a plane state to reset, and our data layout + // starts with `bindings::drm_plane_state` + unsafe { bindings::__drm_gem_reset_shadow_plane(plane, state.cast()) } + } +} -- 2.43.0