]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
drm/fb_cma_helper: Add drm_fb_cma_prepare_fb() helper
authorMarek Vasut <marex@denx.de>
Mon, 14 Nov 2016 10:07:31 +0000 (11:07 +0100)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Mon, 14 Nov 2016 11:43:58 +0000 (12:43 +0100)
Add new drm_fb_cma_prepare_fb() 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>
Reviewed-by: Lucas Stach <l.stach@pengutronix.de>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/20161114100732.3446-1-marex@denx.de
drivers/gpu/drm/drm_fb_cma_helper.c
include/drm/drm_fb_cma_helper.h

index 8bac57e2e41c993b5c580146ad57059081e051aa..81b3558302b5ab7a307bb9c852859b043dd34378 100644 (file)
  */
 
 #include <drm/drmP.h>
+#include <drm/drm_atomic.h>
 #include <drm/drm_crtc.h>
 #include <drm/drm_fb_helper.h>
 #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 +268,38 @@ 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_prepare_fb() - Prepare CMA framebuffer
+ * @plane: Which plane
+ * @state: Plane state attach fence to
+ *
+ * This should be put into prepare_fb hook of struct &drm_plane_helper_funcs .
+ *
+ * This function checks if the plane FB has an dma-buf attached, extracts
+ * the exclusive fence and attaches it to plane state for the atomic helper
+ * to wait on.
+ *
+ * There is no need for cleanup_fb for CMA based framebuffer drivers.
+ */
+int drm_fb_cma_prepare_fb(struct drm_plane *plane,
+                         struct drm_plane_state *state)
+{
+       struct dma_buf *dma_buf;
+       struct dma_fence *fence;
+
+       if ((plane->state->fb == state->fb) || !state->fb)
+               return 0;
+
+       dma_buf = drm_fb_cma_get_gem_obj(state->fb, 0)->base.dma_buf;
+       if (dma_buf) {
+               fence = reservation_object_get_excl_rcu(dma_buf->resv);
+               drm_atomic_set_fence_for_plane(state, fence);
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(drm_fb_cma_prepare_fb);
+
 #ifdef CONFIG_DEBUG_FS
 static void drm_fb_cma_describe(struct drm_framebuffer *fb, struct seq_file *m)
 {
index f313211f8ed52f1e1ecf0a7224a8dd3c26715367..cc82c73b07fc9c7584ec41f815debb34ca1ed3ba 100644 (file)
@@ -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);
 
+int drm_fb_cma_prepare_fb(struct drm_plane *plane,
+                         struct drm_plane_state *state);
+
 #ifdef CONFIG_DEBUG_FS
 struct seq_file;