Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/fb_cma_helper: Add drm_fb_cma_prepare_fb() helper

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

authored by

Marek Vasut and committed by
Daniel Vetter
14d7f96f 3da6c2f3

+38
+35
drivers/gpu/drm/drm_fb_cma_helper.c
··· 18 18 */ 19 19 20 20 #include <drm/drmP.h> 21 + #include <drm/drm_atomic.h> 21 22 #include <drm/drm_crtc.h> 22 23 #include <drm/drm_fb_helper.h> 23 24 #include <drm/drm_crtc_helper.h> 24 25 #include <drm/drm_gem_cma_helper.h> 25 26 #include <drm/drm_fb_cma_helper.h> 27 + #include <linux/dma-buf.h> 26 28 #include <linux/dma-mapping.h> 27 29 #include <linux/module.h> 30 + #include <linux/reservation.h> 28 31 29 32 #define DEFAULT_FBDEFIO_DELAY_MS 50 30 33 ··· 267 264 return fb_cma->obj[plane]; 268 265 } 269 266 EXPORT_SYMBOL_GPL(drm_fb_cma_get_gem_obj); 267 + 268 + /** 269 + * drm_fb_cma_prepare_fb() - Prepare CMA framebuffer 270 + * @plane: Which plane 271 + * @state: Plane state attach fence to 272 + * 273 + * This should be put into prepare_fb hook of struct &drm_plane_helper_funcs . 274 + * 275 + * This function checks if the plane FB has an dma-buf attached, extracts 276 + * the exclusive fence and attaches it to plane state for the atomic helper 277 + * to wait on. 278 + * 279 + * There is no need for cleanup_fb for CMA based framebuffer drivers. 280 + */ 281 + int drm_fb_cma_prepare_fb(struct drm_plane *plane, 282 + struct drm_plane_state *state) 283 + { 284 + struct dma_buf *dma_buf; 285 + struct dma_fence *fence; 286 + 287 + if ((plane->state->fb == state->fb) || !state->fb) 288 + return 0; 289 + 290 + dma_buf = drm_fb_cma_get_gem_obj(state->fb, 0)->base.dma_buf; 291 + if (dma_buf) { 292 + fence = reservation_object_get_excl_rcu(dma_buf->resv); 293 + drm_atomic_set_fence_for_plane(state, fence); 294 + } 295 + 296 + return 0; 297 + } 298 + EXPORT_SYMBOL_GPL(drm_fb_cma_prepare_fb); 270 299 271 300 #ifdef CONFIG_DEBUG_FS 272 301 static void drm_fb_cma_describe(struct drm_framebuffer *fb, struct seq_file *m)
+3
include/drm/drm_fb_cma_helper.h
··· 41 41 struct drm_gem_cma_object *drm_fb_cma_get_gem_obj(struct drm_framebuffer *fb, 42 42 unsigned int plane); 43 43 44 + int drm_fb_cma_prepare_fb(struct drm_plane *plane, 45 + struct drm_plane_state *state); 46 + 44 47 #ifdef CONFIG_DEBUG_FS 45 48 struct seq_file; 46 49