diff mbox

[V2,1/2] drm/fb_cma_helper: Add drm_fb_cma_extract_and_attach_fence() helper

Message ID 20160928201526.13255-1-marex@denx.de (mailing list archive)
State New, archived
Headers show

Commit Message

Marek Vasut Sept. 28, 2016, 8:15 p.m. UTC
Add new drm_fb_cma_extract_and_attach_fence() helper function extracted
from the imx-drm driver. This function checks if the plane has DMABUF
attached to it, extracts the exclusive fence from it and attaches it
to the plane state for the atomic helper to wait on it.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Lucas Stach <l.stach@pengutronix.de>
---
V2: Rename the function to drm_fb_cma_extract_and_attach_fence()
    and clarify the documentation (thanks to Lucas Stach)
---
 drivers/gpu/drm/drm_fb_cma_helper.c | 27 +++++++++++++++++++++++++++
 include/drm/drm_fb_cma_helper.h     |  3 +++
 2 files changed, 30 insertions(+)
diff mbox

Patch

diff --git a/drivers/gpu/drm/drm_fb_cma_helper.c b/drivers/gpu/drm/drm_fb_cma_helper.c
index 1fd6eac..74c7188 100644
--- a/drivers/gpu/drm/drm_fb_cma_helper.c
+++ b/drivers/gpu/drm/drm_fb_cma_helper.c
@@ -23,8 +23,10 @@ 
 #include <drm/drm_crtc_helper.h>
 #include <drm/drm_gem_cma_helper.h>
 #include <drm/drm_fb_cma_helper.h>
+#include <linux/dma-buf.h>
 #include <linux/dma-mapping.h>
 #include <linux/module.h>
+#include <linux/reservation.h>
 
 #define DEFAULT_FBDEFIO_DELAY_MS 50
 
@@ -265,6 +267,31 @@  struct drm_gem_cma_object *drm_fb_cma_get_gem_obj(struct drm_framebuffer *fb,
 }
 EXPORT_SYMBOL_GPL(drm_fb_cma_get_gem_obj);
 
+/**
+ * drm_fb_cma_extract_and_attach_fence() - Extract fence from plane and attach to planestate
+ * @plane: Which plane
+ * @state: Plane state attach fence to
+ *
+ * If the plane fb has an dma-buf attached, fish out the exclusive
+ * fence and attach it to plane state for the atomic helper to wait
+ * on.
+ */
+void drm_fb_cma_extract_and_attach_fence(struct drm_plane *plane,
+					 struct drm_plane_state *state)
+{
+	struct dma_buf *dma_buf;
+
+	if ((plane->state->fb == state->fb) || !state->fb)
+		return;
+
+	dma_buf = drm_fb_cma_get_gem_obj(state->fb, 0)->base.dma_buf;
+	if (!dma_buf)
+		return;
+
+	state->fence = reservation_object_get_excl_rcu(dma_buf->resv);
+}
+EXPORT_SYMBOL_GPL(drm_fb_cma_extract_and_attach_fence);
+
 #ifdef CONFIG_DEBUG_FS
 static void drm_fb_cma_describe(struct drm_framebuffer *fb, struct seq_file *m)
 {
diff --git a/include/drm/drm_fb_cma_helper.h b/include/drm/drm_fb_cma_helper.h
index f313211..d514faa 100644
--- a/include/drm/drm_fb_cma_helper.h
+++ b/include/drm/drm_fb_cma_helper.h
@@ -41,6 +41,9 @@  struct drm_framebuffer *drm_fb_cma_create(struct drm_device *dev,
 struct drm_gem_cma_object *drm_fb_cma_get_gem_obj(struct drm_framebuffer *fb,
 	unsigned int plane);
 
+void drm_fb_cma_extract_and_attach_fence(struct drm_plane *plane,
+					 struct drm_plane_state *state);
+
 #ifdef CONFIG_DEBUG_FS
 struct seq_file;