lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240930233257.1189730-4-lyude@redhat.com>
Date: Mon, 30 Sep 2024 19:09:46 -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 03/35] rust: drm/kms/fbdev: Add FbdevShmem

For drivers which use the shmem based GEM helpers, they'll want to use the
relevant drm_fbdev_shmem_setup() functions instead of the
drm_fbdev_dma_setup() functions. To allow for this, introduce another
FbdevImpl that such drivers can use instead of FbdevDma.

Signed-off-by: Lyude Paul <lyude@...hat.com>
---
 rust/bindings/bindings_helper.h    |  1 +
 rust/kernel/drm/kms/fbdev.rs       |  8 +++++++-
 rust/kernel/drm/kms/fbdev/shmem.rs | 33 ++++++++++++++++++++++++++++++
 3 files changed, 41 insertions(+), 1 deletion(-)
 create mode 100644 rust/kernel/drm/kms/fbdev/shmem.rs

diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h
index 4a8e44e11c96a..9803e0ecac7c1 100644
--- a/rust/bindings/bindings_helper.h
+++ b/rust/bindings/bindings_helper.h
@@ -13,6 +13,7 @@
 #include <drm/drm_file.h>
 #include <drm/drm_fourcc.h>
 #include <drm/drm_fbdev_dma.h>
+#include <drm/drm_fbdev_shmem.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/fbdev.rs b/rust/kernel/drm/kms/fbdev.rs
index bdf97500137d8..a1035d948949a 100644
--- a/rust/kernel/drm/kms/fbdev.rs
+++ b/rust/kernel/drm/kms/fbdev.rs
@@ -5,6 +5,12 @@
 use crate::{private::Sealed, drm::{kms::*, device::Device, gem}};
 use bindings;
 
+#[cfg(CONFIG_DRM_GEM_SHMEM_HELPER = "y")]
+mod shmem;
+
+#[cfg(CONFIG_DRM_GEM_SHMEM_HELPER = "y")]
+pub use shmem::FbdevShmem;
+
 pub(crate) mod private {
     use super::*;
 
@@ -17,7 +23,7 @@ pub trait FbdevImpl {
 /// The main trait for a driver's DRM implementation.
 ///
 /// Drivers are expected not to implement this directly, and to instead use one of the objects
-/// provided by this module such as [`FbdevDma`].
+/// provided by this module such as [`FbdevDma`] and [`FbdevShmem`].
 pub trait FbdevImpl: private::FbdevImpl {}
 
 /// The fbdev implementation for drivers using the gem DMA helpers.
diff --git a/rust/kernel/drm/kms/fbdev/shmem.rs b/rust/kernel/drm/kms/fbdev/shmem.rs
new file mode 100644
index 0000000000000..16c3533ad2a0f
--- /dev/null
+++ b/rust/kernel/drm/kms/fbdev/shmem.rs
@@ -0,0 +1,33 @@
+//! The GEM shmem fbdev implementation for rust.
+//!
+//! This module provides an Fbdev implementation that can be used by Rust KMS drivers using the GEM
+//! shmem helpers provided by [`shmem`].
+
+use core::marker::*;
+use crate::drm::{gem::shmem, kms::*, device::Device};
+use super::{private::FbdevImpl as FbdevImplPrivate, FbdevImpl};
+use bindings;
+
+/// The fbdev implementation for drivers using the gem shmem helpers.
+///
+/// KMS Drivers which use the GEM helpers provided by [`shmem`] should use this for [`Kms::Fbdev`].
+pub struct FbdevShmem<T: Driver>(PhantomData<T>);
+
+impl<T, G> FbdevImplPrivate for FbdevShmem<T>
+where
+    T: Driver<Object = shmem::Object<G>>,
+    G: shmem::DriverObject
+{
+    #[inline]
+    fn setup_fbdev<D: Driver>(drm: &Device<D>, mode_config_info: &ModeConfigInfo) {
+        // SAFETY: Our implementation bounds are proof that this driver is using the gem shmem
+        // helpers
+        unsafe { bindings::drm_fbdev_shmem_setup(drm.as_raw(), mode_config_info.preferred_depth) };
+    }
+}
+
+impl<T, G> FbdevImpl for FbdevShmem<T>
+where
+    T: Driver<Object = shmem::Object<G>>,
+    G: shmem::DriverObject
+{}
-- 
2.46.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ