From: Mike Lothian <mike@fireburn.co.uk>
To: rust-for-linux@vger.kernel.org
Cc: dri-devel@lists.freedesktop.org,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Danilo Krummrich" <dakr@kernel.org>,
"Lyude Paul" <lyude@redhat.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
linux-kernel@vger.kernel.org,
"Mike Lothian" <mike@fireburn.co.uk>
Subject: [RFC PATCH v2 16/18] rust: drm: add CRTC gamma LUT and plane rotation property bindings
Date: Fri, 3 Jul 2026 04:01:03 +0100 [thread overview]
Message-ID: <20260703030123.2814-17-mike@fireburn.co.uk> (raw)
In-Reply-To: <20260703030123.2814-1-mike@fireburn.co.uk>
Two more mode-object properties a real driver reaches for, and the last
the DisplayLink vino driver needs to match its pre-safe-KMS feature set:
- CRTC gamma: UnregisteredCrtc::enable_gamma()
(drm_crtc_enable_color_mgmt, creating a GAMMA_LUT property) and
RawCrtcState::gamma_lut() to read the set ramp back as a
&[drm_color_lut].
- Plane rotation: UnregisteredPlane::create_rotation_property()
(drm_plane_create_rotation_property) and RawPlaneState::rotation() /
crtc_x()/crtc_y()/hotspot_x()/hotspot_y() to read the plane's
placement and orientation.
drm_plane_create_rotation_property lives in <drm/drm_blend.h>, so add
that to bindings_helper.h.
Signed-off-by: Mike Lothian <mike@fireburn.co.uk>
Assisted-by: Claude:claude-opus-4-8 [Claude-Code]
---
rust/bindings/bindings_helper.h | 1 +
rust/kernel/drm/kms/crtc.rs | 33 +++++++++++++++++++++++++++++++++
rust/kernel/drm/kms/plane.rs | 29 +++++++++++++++++++++++++++++
3 files changed, 63 insertions(+)
diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h
index e5cfda610781..7d04abec1215 100644
--- a/rust/bindings/bindings_helper.h
+++ b/rust/bindings/bindings_helper.h
@@ -39,6 +39,7 @@
#include <drm/drm_atomic_helper.h>
#include <drm/drm_connector.h>
#include <drm/drm_crtc.h>
+#include <drm/drm_blend.h>
#include <drm/drm_edid.h>
#include <drm/drm_encoder.h>
#include <drm/drm_framebuffer.h>
diff --git a/rust/kernel/drm/kms/crtc.rs b/rust/kernel/drm/kms/crtc.rs
index fbe113676e2f..b5128ae1ca95 100644
--- a/rust/kernel/drm/kms/crtc.rs
+++ b/rust/kernel/drm/kms/crtc.rs
@@ -356,6 +356,17 @@ pub fn new<'a, 'b: 'a, PrimaryData, CursorData>(
// SAFETY: We just allocated the crtc above, so this pointer must be valid
Ok(unsafe { &*this })
}
+
+ /// Enable colour management on this CRTC, creating a `GAMMA_LUT` property of `gamma_size`
+ /// entries that userspace can program (no degamma LUT, no CTM). The set LUT is then readable
+ /// from the CRTC state via [`RawCrtcState::gamma_lut`].
+ ///
+ /// Call this during [`KmsDriver::probe`](crate::drm::kms::KmsDriver::probe), before the device
+ /// is registered.
+ pub fn enable_gamma(&self, gamma_size: u32) {
+ // SAFETY: `as_raw()` is a valid, not-yet-registered CRTC.
+ unsafe { bindings::drm_crtc_enable_color_mgmt(self.as_raw(), 0, false, gamma_size) };
+ }
}
// SAFETY: We inherit all relevant invariants of `Crtc`
@@ -686,6 +697,28 @@ fn mode(&self) -> &DisplayMode {
// interface can ensure this access is serialized.
unsafe { DisplayMode::as_ref(&(*self.as_raw()).mode) }
}
+
+ /// Returns the CRTC's gamma LUT for this state as an array of [`drm_color_lut`] entries, or
+ /// [`None`] if no gamma LUT is programmed. Requires gamma to have been enabled on the CRTC
+ /// (see [`UnregisteredCrtc::enable_gamma`]).
+ ///
+ /// [`drm_color_lut`]: bindings::drm_color_lut
+ fn gamma_lut(&self) -> Option<&[bindings::drm_color_lut]> {
+ // SAFETY: `as_raw()` is a valid `drm_crtc_state`.
+ let blob = unsafe { (*self.as_raw()).gamma_lut };
+ if blob.is_null() {
+ return None;
+ }
+ // SAFETY: a non-null gamma_lut blob is valid for the state's lifetime.
+ let (data, length) = unsafe { ((*blob).data, (*blob).length) };
+ let n = length / core::mem::size_of::<bindings::drm_color_lut>();
+ if data.is_null() || n == 0 {
+ return None;
+ }
+ // SAFETY: the blob's `data` holds `n` contiguous `drm_color_lut` entries (the blob length
+ // is a multiple of the entry size), valid for the state's lifetime.
+ Some(unsafe { core::slice::from_raw_parts(data.cast::<bindings::drm_color_lut>(), n) })
+ }
}
impl<T: AsRawCrtcState> RawCrtcState for T {}
diff --git a/rust/kernel/drm/kms/plane.rs b/rust/kernel/drm/kms/plane.rs
index fcaa8ba550fe..ead875316829 100644
--- a/rust/kernel/drm/kms/plane.rs
+++ b/rust/kernel/drm/kms/plane.rs
@@ -328,6 +328,28 @@ pub fn new<'a, 'b: 'a>(
// SAFETY: We just allocated the plane above, so this pointer must be valid
Ok(unsafe { &*this })
}
+
+ /// Attach a rotation property to this plane, advertising `supported_rotations` (a bitmask of
+ /// `DRM_MODE_ROTATE_*` | `DRM_MODE_REFLECT_*`) with initial value `default_rotation`. The
+ /// selected value is then readable from the plane state via
+ /// [`RawPlaneState::rotation`](crate::drm::kms::plane::RawPlaneState::rotation).
+ ///
+ /// Call this during [`KmsDriver::probe`](crate::drm::kms::KmsDriver::probe), before the device
+ /// is registered.
+ pub fn create_rotation_property(
+ &self,
+ default_rotation: u32,
+ supported_rotations: u32,
+ ) -> Result {
+ // SAFETY: `as_raw()` is a valid, not-yet-registered plane.
+ to_result(unsafe {
+ bindings::drm_plane_create_rotation_property(
+ self.as_raw(),
+ default_rotation,
+ supported_rotations,
+ )
+ })
+ }
}
/// A trait implemented by any type that acts as a [`struct drm_plane`] interface.
@@ -625,6 +647,13 @@ fn hotspot_y(&self) -> i32 {
self.as_raw().hotspot_y
}
+ /// The plane's rotation/reflection (`DRM_MODE_ROTATE_*` | `DRM_MODE_REFLECT_*` bitmask), for a
+ /// plane with a rotation property (see
+ /// [`UnregisteredPlane::create_rotation_property`]). Defaults to `DRM_MODE_ROTATE_0`.
+ fn rotation(&self) -> u32 {
+ self.as_raw().rotation
+ }
+
/// Return the current [`OpaqueCrtc`] assigned to this plane, if there is one.
fn crtc<'a, 'b: 'a, D>(&'a self) -> Option<&'b OpaqueCrtc<D>>
where
--
2.55.0
next prev parent reply other threads:[~2026-07-03 3:02 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-17 15:02 [RFC PATCH 0/5] rust: drm: minimal KMS bindings, EDID read, rotation, HDCP defs Mike Lothian
2026-06-17 15:02 ` [RFC PATCH 1/4] rust: drm: add minimal KMS bindings for simple-display-pipe drivers Mike Lothian
2026-06-17 15:02 ` [RFC PATCH 2/4] rust: drm: expose drm_edid.h for reading connector EDID Mike Lothian
2026-06-17 15:02 ` [RFC PATCH 3/4] rust: drm: expose drm::Device::as_raw() Mike Lothian
2026-06-17 15:02 ` [RFC PATCH 4/4] rust: drm: expose drm_blend.h and the atomic new-CRTC-state accessor Mike Lothian
2026-06-17 15:11 ` [RFC PATCH 0/5] rust: drm: minimal KMS bindings, EDID read, rotation, HDCP defs Miguel Ojeda
2026-06-17 15:29 ` Mike Lothian
2026-07-03 3:00 ` [RFC PATCH v2 00/18] rust: drm: safe KMS mode-object layer + evdi bindings Mike Lothian
2026-07-03 3:00 ` [RFC PATCH v2 01/18] rust: drm: kms: forward-port the safe mode-object layer onto the typestate device Mike Lothian
2026-07-07 21:46 ` lyude
2026-07-07 22:21 ` lyude
2026-07-03 3:00 ` [RFC PATCH v2 02/18] rust: drm: kms: adapt the port to current drm-next Mike Lothian
2026-07-03 3:00 ` [RFC PATCH v2 03/18] rust: drm: kms: break the Driver* trait well-formedness cycle Mike Lothian
2026-07-03 3:00 ` [RFC PATCH v2 04/18] rust: drm: kms: build the kernel crate clean under -Znext-solver Mike Lothian
2026-07-03 3:00 ` [RFC PATCH v2 05/18] rust: drm: expose <drm/display/drm_hdcp.h> HDCP 2.2 message definitions Mike Lothian
2026-07-03 3:00 ` [RFC PATCH v2 06/18] rust: drm: kms: add a Framebuffer::vmap() guard Mike Lothian
2026-07-07 21:51 ` lyude
2026-07-03 3:00 ` [RFC PATCH v2 07/18] rust: drm: kms: add safe accessors for common state and connector modes Mike Lothian
2026-07-03 3:00 ` [RFC PATCH v2 08/18] rust: drm: tyr: add the Kms associated type Mike Lothian
2026-07-03 3:00 ` [RFC PATCH v2 09/18] rust: drm: add drm_event delivery Mike Lothian
2026-07-03 3:00 ` [RFC PATCH v2 10/18] rust: drm: allow drivers to declare ioctls from their own uAPI module Mike Lothian
2026-07-03 3:00 ` [RFC PATCH v2 11/18] rust: platform: add runtime platform device creation Mike Lothian
2026-07-03 3:00 ` [RFC PATCH v2 12/18] rust: drm: framebuffer: add geometry accessors, refcounting and a byte-slice vmap Mike Lothian
2026-07-03 3:01 ` [RFC PATCH v2 13/18] rust: i2c: add adapter-provider (bus controller) registration Mike Lothian
2026-07-03 3:01 ` [RFC PATCH v2 14/18] rust: add sysfs device attribute groups Mike Lothian
2026-07-03 3:01 ` [RFC PATCH v2 15/18] rust: drm: support hardware cursor planes with sleepable event delivery Mike Lothian
2026-07-03 3:01 ` Mike Lothian [this message]
2026-07-03 3:01 ` [RFC PATCH v2 17/18] rust: drm: kms: add connector detect() and mode_valid() hooks Mike Lothian
2026-07-03 3:01 ` [RFC PATCH v2 18/18] rust: drm: kms: add plane damage-clip accessors Mike Lothian
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=20260703030123.2814-17-mike@fireburn.co.uk \
--to=mike@fireburn.co.uk \
--cc=a.hindborg@kernel.org \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=lyude@redhat.com \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
--cc=tmgross@umich.edu \
/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