From: Lyude Paul <lyude@redhat.com>
To: dri-devel@lists.freedesktop.org
Cc: "Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"David Airlie" <airlied@gmail.com>,
"Daniel Vetter" <daniel@ffwll.ch>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Wedson Almeida Filho" <wedsonaf@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <benno.lossin@proton.me>,
"Andreas Hindborg" <a.hindborg@samsung.com>,
"Alice Ryhl" <aliceryhl@google.com>,
"Asahi Lina" <lina@asahilina.net>,
"Martin Rodriguez Reboredo" <yakoyoku@gmail.com>,
"FUJITA Tomonori" <fujita.tomonori@gmail.com>,
linux-kernel@vger.kernel.org (open list),
rust-for-linux@vger.kernel.org (open list:RUST)
Subject: [PATCH 4/4] WIP: rust/drm/kms: Add ShadowPlaneState<T>
Date: Fri, 22 Mar 2024 18:03:36 -0400 [thread overview]
Message-ID: <20240322221305.1403600-5-lyude@redhat.com> (raw)
In-Reply-To: <20240322221305.1403600-1-lyude@redhat.com>
Signed-off-by: Lyude Paul <lyude@redhat.com>
---
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
prev parent reply other threads:[~2024-03-22 22:15 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-22 22:03 [RFC WIP 0/4] Rust bindings for KMS + RVKMS Lyude Paul
2024-03-22 22:03 ` [PATCH 1/4] WIP: rust: Add basic KMS bindings Lyude Paul
2024-03-27 20:50 ` Benno Lossin
2024-04-22 1:47 ` Lyude Paul
2024-04-25 15:42 ` Benno Lossin
2024-03-22 22:03 ` [PATCH 2/4] WIP: drm: Introduce rvkms Lyude Paul
2024-03-27 21:06 ` Benno Lossin
2024-04-22 1:54 ` Lyude Paul
2024-04-25 15:46 ` Benno Lossin
2024-04-29 19:54 ` Lyude Paul
2024-03-22 22:03 ` [PATCH 3/4] rust/drm/kms: Extract PlaneState<T> into IntoPlaneState Lyude Paul
2024-03-22 22:03 ` Lyude Paul [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240322221305.1403600-5-lyude@redhat.com \
--to=lyude@redhat.com \
--cc=a.hindborg@samsung.com \
--cc=airlied@gmail.com \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=fujita.tomonori@gmail.com \
--cc=gary@garyguo.net \
--cc=lina@asahilina.net \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tzimmermann@suse.de \
--cc=wedsonaf@gmail.com \
--cc=yakoyoku@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).