[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240930233257.1189730-28-lyude@redhat.com>
Date: Mon, 30 Sep 2024 19:10:10 -0400
From: Lyude Paul <lyude@...hat.com>
To: dri-devel@...ts.freedesktop.org,
rust-for-linux@...r.kernel.org
Cc: 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>,
Danilo Krummrich <dakr@...hat.com>,
Mika Westerberg <mika.westerberg@...ux.intel.com>,
linux-kernel@...r.kernel.org (open list)
Subject: [WIP RFC v2 27/35] rust: drm/kms: Add drm_framebuffer bindings
This adds some very simple bindings for drm_framebuffer. We don't use them
much yet, but we'll eventually be using them when rvkms eventually gets CRC
and writeback support. Just like Connector objects, these use RcModeObject.
Signed-off-by: Lyude Paul <lyude@...hat.com>
---
rust/bindings/bindings_helper.h | 1 +
rust/kernel/drm/kms.rs | 1 +
rust/kernel/drm/kms/framebuffer.rs | 58 ++++++++++++++++++++++++++++++
3 files changed, 60 insertions(+)
create mode 100644 rust/kernel/drm/kms/framebuffer.rs
diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h
index 7695f11f4363c..7c324003c3885 100644
--- a/rust/bindings/bindings_helper.h
+++ b/rust/bindings/bindings_helper.h
@@ -15,6 +15,7 @@
#include <drm/drm_fourcc.h>
#include <drm/drm_fbdev_dma.h>
#include <drm/drm_fbdev_shmem.h>
+#include <drm/drm_framebuffer.h>
#include <drm/drm_gem.h>
#include <drm/drm_gem_framebuffer_helper.h>
#include <drm/drm_gem_shmem_helper.h>
diff --git a/rust/kernel/drm/kms.rs b/rust/kernel/drm/kms.rs
index 4ab039d67352e..3edd90bc0025a 100644
--- a/rust/kernel/drm/kms.rs
+++ b/rust/kernel/drm/kms.rs
@@ -7,6 +7,7 @@
pub mod crtc;
pub mod encoder;
pub mod fbdev;
+pub mod framebuffer;
pub mod plane;
use crate::{
diff --git a/rust/kernel/drm/kms/framebuffer.rs b/rust/kernel/drm/kms/framebuffer.rs
new file mode 100644
index 0000000000000..bbe408c187670
--- /dev/null
+++ b/rust/kernel/drm/kms/framebuffer.rs
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: GPL-2.0 OR MIT
+//! DRM Framebuffer related bindings
+
+use crate::{
+ drm::{
+ device::Device,
+ fourcc::*,
+ },
+ types::*,
+ prelude::*,
+};
+use bindings;
+use core::{
+ marker::*,
+ slice,
+};
+use super::{ModeObject, RcModeObject, KmsDriver};
+
+/// The main interface for [`struct drm_framebuffer`].
+///
+/// [`struct drm_framebuffer`]: srctree/include/drm/drm_framebuffer.h
+#[repr(transparent)]
+pub struct Framebuffer<T: KmsDriver> {
+ inner: Opaque<bindings::drm_framebuffer>,
+ _p: PhantomData<T>,
+}
+
+impl<T: KmsDriver> ModeObject for Framebuffer<T> {
+ type Driver = T;
+
+ fn drm_dev(&self) -> &Device<Self::Driver> {
+ unsafe { Device::borrow((*self.inner.get()).dev) }
+ }
+
+ fn raw_mode_obj(&self) -> *mut bindings::drm_mode_object {
+ // SAFETY: We don't expose Framebuffer<T> to users before it's initialized, so `base` is
+ // always initialized
+ unsafe { &mut (*self.inner.get()).base }
+ }
+}
+
+// SAFETY: Framebuffers are refcounted mode objects.
+unsafe impl<T: KmsDriver> RcModeObject for Framebuffer<T> {}
+
+// SAFETY: References to framebuffers are safe to be accessed from any thread
+unsafe impl<T: KmsDriver> Send for Framebuffer<T> {}
+// SAFETY: References to framebuffers are safe to be accessed from any thread
+unsafe impl<T: KmsDriver> Sync for Framebuffer<T> {}
+
+impl<T: KmsDriver> crate::private::Sealed for Framebuffer<T> {}
+
+impl<T: KmsDriver> Framebuffer<T> {
+ #[inline]
+ pub(super) unsafe fn from_raw<'a>(ptr: *const bindings::drm_framebuffer) -> &'a Self {
+ // SAFETY: Our data layout is identical to drm_framebuffer
+ unsafe { &*ptr.cast() }
+ }
+}
--
2.46.1
Powered by blists - more mailing lists