Skip to contentSkip to conversation

drm/fb_cma_helper: Add drm_fb_cma_extract_and_attach_fence() helper

PATCH Superseded Marek Vasut 1 participant 2 messages Sep 28, 2016

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 drm/fb_cma_helper: Add drm_fb_cma_extract_and_attach_fence() helper

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.

Cc Daniel Vetter <[email protected]>
Cc Lucas Stach <[email protected]>

---
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(+)
drivers/gpu/drm/drm_fb_cma_helper.c +27 -0
index 1fd6eac..74c7188 100644
@@ -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)
 {
include/drm/drm_fb_cma_helper.h +3 -0
index f313211..d514faa 100644
@@ -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;
 
Signature · 6 lines
2.9.3

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH v2 2/2 drm/imx: Switch to drm_fb_cma_extract_and_attach_fence() helper

Remove the common code from the driver and use the drm_fb_cma_extract_and_attach_fence() helper instead. Moveover, call the helper from prepare_fb() plane hook .

Cc Daniel Vetter <[email protected]>
Cc Lucas Stach <[email protected]>

---
V2: - Rename the function to drm_fb_cma_extract_and_attach_fence()
- Add missing newline

---
 drivers/gpu/drm/imx/imx-drm-core.c | 30 +-----------------------------
 drivers/gpu/drm/imx/ipuv3-plane.c  |  9 +++++++++
 2 files changed, 10 insertions(+), 29 deletions(-)
drivers/gpu/drm/imx/imx-drm-core.c +1 -29
index 98df09c..c7faa1f 100644
@@ -18,7 +18,6 @@
 #include <linux/dma-buf.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
-#include <linux/reservation.h>
 #include <drm/drmP.h>
 #include <drm/drm_atomic.h>
 #include <drm/drm_atomic_helper.h>
@@ -151,38 +150,11 @@ static int imx_drm_atomic_check(struct drm_device *dev,
 	return ret;
 }
 
-static int imx_drm_atomic_commit(struct drm_device *dev,
-				 struct drm_atomic_state *state,
-				 bool nonblock)
-{
-	struct drm_plane_state *plane_state;
-	struct drm_plane *plane;
-	struct dma_buf *dma_buf;
-	int i;
-
-	/*
-	 * If the plane fb has an dma-buf attached, fish out the exclusive
-	 * fence for the atomic helper to wait on.
-	 */
-	for_each_plane_in_state(state, plane, plane_state, i) {
-		if ((plane->state->fb != plane_state->fb) && plane_state->fb) {
-			dma_buf = drm_fb_cma_get_gem_obj(plane_state->fb,
-							 0)->base.dma_buf;
-			if (!dma_buf)
-				continue;
-			plane_state->fence =
-				reservation_object_get_excl_rcu(dma_buf->resv);
-		}
-	}
-
-	return drm_atomic_helper_commit(dev, state, nonblock);
-}
-
 static const struct drm_mode_config_funcs imx_drm_mode_config_funcs = {
 	.fb_create = drm_fb_cma_create,
 	.output_poll_changed = imx_drm_output_poll_changed,
 	.atomic_check = imx_drm_atomic_check,
-	.atomic_commit = imx_drm_atomic_commit,
+	.atomic_commit = drm_atomic_helper_commit,
 };
 
 static void imx_drm_atomic_commit_tail(struct drm_atomic_state *state)
drivers/gpu/drm/imx/ipuv3-plane.c +9 -0
index ce22d0a..eb115a3 100644
@@ -250,6 +250,14 @@ static const struct drm_plane_funcs ipu_plane_funcs = {
 	.atomic_destroy_state	= drm_atomic_helper_plane_destroy_state,
 };
 
+static int ipu_plane_prepare_fb(struct drm_plane *plane,
+				struct drm_plane_state *state)
+{
+	drm_fb_cma_extract_and_attach_fence(plane, state);
+
+	return 0;
+}
+
 static int ipu_plane_atomic_check(struct drm_plane *plane,
 				  struct drm_plane_state *state)
 {
@@ -442,6 +450,7 @@ static void ipu_plane_atomic_update(struct drm_plane *plane,
 }
 
 static const struct drm_plane_helper_funcs ipu_plane_helper_funcs = {
+	.prepare_fb = ipu_plane_prepare_fb,
 	.atomic_check = ipu_plane_atomic_check,
 	.atomic_disable = ipu_plane_atomic_disable,
 	.atomic_update = ipu_plane_atomic_update,
Signature · 6 lines
2.9.3

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel