@@ -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>
@@ -7,6 +7,7 @@
pub mod crtc;
pub mod encoder;
pub mod fbdev;
+pub mod framebuffer;
pub mod plane;
use crate::{
new file mode 100644
@@ -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() }
+ }
+}
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@redhat.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