Skip to contentSkip to conversation

drm/fb_cma_helper: Add drm_fb_cma_setup_fence() helper

PATCH Superseded Marek Vasut 3 participants 14 messages Sep 26, 2016 – Oct 5, 2016

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/fb_cma_helper: Add drm_fb_cma_setup_fence() helper

Add new drm_fb_cma_setup_fence() helper function extracted from the imx-drm driver. This function checks if the plane has DMABUF attached to it and if so, sets up the fence on which the atomic helper can wait.

Cc Daniel Vetter <[email protected]>
Cc Lucas Stach <[email protected]>
---
 drivers/gpu/drm/drm_fb_cma_helper.c | 26 ++++++++++++++++++++++++++
 include/drm/drm_fb_cma_helper.h     |  3 +++
 2 files changed, 29 insertions(+)
drivers/gpu/drm/drm_fb_cma_helper.c +26 -0
index 1fd6eac..2441707 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,30 @@ 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_setup_fence() - Set up the fence for atomic helper to wait on
+ * @plane: Which plane
+ * @state: Plane state to check
+ *
+ * If the plane fb has an dma-buf attached, fish out the exclusive
+ * fence for the atomic helper to wait on.
+ */
+void drm_fb_cma_setup_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_setup_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..fc122d3 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_setup_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 2/2 drm/imx: Switch to drm_fb_cma_setup_fence() helper

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

Cc Daniel Vetter <[email protected]>
Cc Lucas Stach <[email protected]>
---
 drivers/gpu/drm/imx/imx-drm-core.c | 30 +-----------------------------
 drivers/gpu/drm/imx/ipuv3-plane.c  |  8 ++++++++
 2 files changed, 9 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 +8 -0
index ce22d0a..50615e3 100644
@@ -250,6 +250,13 @@ 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_setup_fence(plane, state);
+	return 0;
+}
+
 static int ipu_plane_atomic_check(struct drm_plane *plane,
 				  struct drm_plane_state *state)
 {
@@ -442,6 +449,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
Tested-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] drm/imx: Switch to drm_fb_cma_setup_fence() helper

Am Montag, den 26.09.2016, 15:01 +0200 schrieb Marek Vasut:

Quoted 6 lines

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

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

One nit inline, otherwise looks good and is:

Quoted 62 lines
---
 drivers/gpu/drm/imx/imx-drm-core.c | 30 +-----------------------------
 drivers/gpu/drm/imx/ipuv3-plane.c  |  8 ++++++++
 2 files changed, 9 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 +0 -0
index ce22d0a..50615e3 100644

drivers/gpu/drm/imx/ipuv3-plane.c static const struct drm_plane_funcs ipu_plane_funcs = { · line 256

Quoted 7 lines
drivers/gpu/drm/imx/ipuv3-plane.c +4 -0
@@ -250,6 +250,13 @@ 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_setup_fence(plane, state);

Blank line here to match the style in this driver.

Quoted 7 lines
drivers/gpu/drm/imx/ipuv3-plane.c +3 -0
+	return 0;
+}
+
 static int ipu_plane_atomic_check(struct drm_plane *plane,
 				  struct drm_plane_state *state)
 {

drivers/gpu/drm/imx/ipuv3-plane.c static void ipu_plane_atomic_update(struct drm_plane *plane, · line 455

Quoted 7 lines
drivers/gpu/drm/imx/ipuv3-plane.c +1 -0
@@ -442,6 +449,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,

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

#3 lore raw

Re: [PATCH 2/2] drm/imx: Switch to drm_fb_cma_setup_fence() helper

Quoted 77 lines · Lucas Stach

Am Montag, den 26.09.2016, 15:01 +0200 schrieb Marek Vasut:

Quoted 6 lines

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

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

One nit inline, otherwise looks good and is:

Quoted 65 lines
---
 drivers/gpu/drm/imx/imx-drm-core.c | 30 +-----------------------------
 drivers/gpu/drm/imx/ipuv3-plane.c  |  8 ++++++++
 2 files changed, 9 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 +0 -0
index ce22d0a..50615e3 100644
@@ -250,6 +250,13 @@ static const struct drm_plane_funcs ipu_plane_funcs = {
 	.atomic_destroy_state	= drm_atomic_helper_plane_destroy_state,
 };
 
Quoted 6 lines

drivers/gpu/drm/imx/ipuv3-plane.c static const struct drm_plane_funcs ipu_plane_funcs = { · line 256

Quoted 4 lines
drivers/gpu/drm/imx/ipuv3-plane.c +4 -0
+static int ipu_plane_prepare_fb(struct drm_plane *plane,
+				struct drm_plane_state *state)
+{
+	drm_fb_cma_setup_fence(plane, state);

Blank line here to match the style in this driver.

Done, thanks.

Quoted 16 lines
Quoted 14 lines
drivers/gpu/drm/imx/ipuv3-plane.c +4 -0
+	return 0;
+}
+
 static int ipu_plane_atomic_check(struct drm_plane *plane,
 				  struct drm_plane_state *state)
 {
@@ -442,6 +449,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
Best regards,
Marek Vasut
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw

Re: [PATCH 2/2] drm/imx: Switch to drm_fb_cma_setup_fence() helper

In reply to Marek Vasut
Quoted 82 lines · Marek Vasut

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

Cc Daniel Vetter <[email protected]>
Cc Lucas Stach <[email protected]>
---
 drivers/gpu/drm/imx/imx-drm-core.c | 30 +-----------------------------
 drivers/gpu/drm/imx/ipuv3-plane.c  |  8 ++++++++
 2 files changed, 9 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 +7 -0
index ce22d0a..50615e3 100644
@@ -250,6 +250,13 @@ 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_setup_fence(plane, state);
+	return 0;
+}
+
 static int ipu_plane_atomic_check(struct drm_plane *plane,
 				  struct drm_plane_state *state)
 {

drivers/gpu/drm/imx/ipuv3-plane.c static void ipu_plane_atomic_update(struct drm_plane *plane, · line 452

Quoted 4 lines
drivers/gpu/drm/imx/ipuv3-plane.c +1 -0
@@ -442,6 +449,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,

See my coment about the function naming, but imo drm_fb_cma_prepare_fb should have a function type matching prepare_fb. Otherwise every driver needs a dummy wrapper function like ipu_plane_prepare_fb, which imo would be pointless.
-Daniel

Quoted 6 lines
drivers/gpu/drm/imx/ipuv3-plane.c +0 -0
 	.atomic_check = ipu_plane_atomic_check,
 	.atomic_disable = ipu_plane_atomic_disable,
 	.atomic_update = ipu_plane_atomic_update,
Signature · 1 line
2.9.3
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#5 lore raw

Re: [PATCH 2/2] drm/imx: Switch to drm_fb_cma_setup_fence() helper

Quoted 85 lines · Daniel Vetter
Quoted 84 lines · Marek Vasut

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

Cc Daniel Vetter <[email protected]>
Cc Lucas Stach <[email protected]>
---
 drivers/gpu/drm/imx/imx-drm-core.c | 30 +-----------------------------
 drivers/gpu/drm/imx/ipuv3-plane.c  |  8 ++++++++
 2 files changed, 9 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 +7 -0
index ce22d0a..50615e3 100644
@@ -250,6 +250,13 @@ 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_setup_fence(plane, state);
+	return 0;
+}
+
 static int ipu_plane_atomic_check(struct drm_plane *plane,
 				  struct drm_plane_state *state)
 {
@@ -442,6 +449,7 @@ static void ipu_plane_atomic_update(struct drm_plane *plane,
 }
 
Quoted 4 lines

drivers/gpu/drm/imx/ipuv3-plane.c static void ipu_plane_atomic_update(struct drm_plane *plane, · line 452

Quoted 2 lines
drivers/gpu/drm/imx/ipuv3-plane.c +1 -0
 static const struct drm_plane_helper_funcs ipu_plane_helper_funcs = {
+	.prepare_fb = ipu_plane_prepare_fb,

See my coment about the function naming, but imo drm_fb_cma_prepare_fb

You mean drm_fb_cma_setup_fence() , so it can be used directly in .prepare_fb ?

Quoted 3 lines

should have a function type matching prepare_fb. Otherwise every driver needs a dummy wrapper function like ipu_plane_prepare_fb, which imo would be pointless.

Indeed.

Quoted 9 lines

-Daniel

Quoted 6 lines
drivers/gpu/drm/imx/ipuv3-plane.c +0 -0
 	.atomic_check = ipu_plane_atomic_check,
 	.atomic_disable = ipu_plane_atomic_disable,
 	.atomic_update = ipu_plane_atomic_update,
Signature · 1 line
2.9.3
Signature · 6 lines
Best regards,
Marek Vasut
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#6 lore raw
In reply to Marek Vasut

Hi Marek,

Am Montag, den 26.09.2016, 15:01 +0200 schrieb Marek Vasut:

Quoted 28 lines

Add new drm_fb_cma_setup_fence() helper function extracted from the imx-drm driver. This function checks if the plane has DMABUF attached to it and if so, sets up the fence on which the atomic helper can wait.

Cc Daniel Vetter <[email protected]>
Cc Lucas Stach <[email protected]>
---
 drivers/gpu/drm/drm_fb_cma_helper.c | 26 ++++++++++++++++++++++++++
 include/drm/drm_fb_cma_helper.h     |  3 +++
 2 files changed, 29 insertions(+)
drivers/gpu/drm/drm_fb_cma_helper.c +2 -0
index 1fd6eac..2441707 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
 

drivers/gpu/drm/drm_fb_cma_helper.c struct drm_gem_cma_object *drm_fb_cma_get_gem_obj(struct drm_framebuffer *fb, · line 271

Quoted 5 lines
drivers/gpu/drm/drm_fb_cma_helper.c +2 -0
@@ -265,6 +267,30 @@ 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_setup_fence() - Set up the fence for atomic helper to wait on

I don't really like the naming of the helper. It's not setting up any fence, it's either extracting it from the plane and/or attaching it to the planestate, so I would have expected the name to include extract or attach.

drivers/gpu/drm/drm_fb_cma_helper.c struct drm_gem_cma_object *drm_fb_cma_get_gem_obj(struct drm_framebuffer *fb, · line 273

Quoted 2 lines
drivers/gpu/drm/drm_fb_cma_helper.c +2 -0
+ * @plane: Which plane
+ * @state: Plane state to check

s/check/attach fence to

Quoted 28 lines
drivers/gpu/drm/drm_fb_cma_helper.c +20 -0
+ *
+ * If the plane fb has an dma-buf attached, fish out the exclusive
+ * fence for the atomic helper to wait on.
+ */
+void drm_fb_cma_setup_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_setup_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 +0 -0
index f313211..fc122d3 100644

include/drm/drm_fb_cma_helper.h struct drm_framebuffer *drm_fb_cma_create(struct drm_device *dev, · line 49

Quoted 9 lines
include/drm/drm_fb_cma_helper.h +3 -0
@@ -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_setup_fence(struct drm_plane *plane,
+			    struct drm_plane_state *state);
+
 #ifdef CONFIG_DEBUG_FS
 struct seq_file;
 

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

#7 lore raw
Quoted 42 lines · Lucas Stach

Hi Marek,

Am Montag, den 26.09.2016, 15:01 +0200 schrieb Marek Vasut:

Quoted 28 lines

Add new drm_fb_cma_setup_fence() helper function extracted from the imx-drm driver. This function checks if the plane has DMABUF attached to it and if so, sets up the fence on which the atomic helper can wait.

Cc Daniel Vetter <[email protected]>
Cc Lucas Stach <[email protected]>
---
 drivers/gpu/drm/drm_fb_cma_helper.c | 26 ++++++++++++++++++++++++++
 include/drm/drm_fb_cma_helper.h     |  3 +++
 2 files changed, 29 insertions(+)
drivers/gpu/drm/drm_fb_cma_helper.c +2 -0
index 1fd6eac..2441707 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
 

drivers/gpu/drm/drm_fb_cma_helper.c struct drm_gem_cma_object *drm_fb_cma_get_gem_obj(struct drm_framebuffer *fb, · line 271

Quoted 5 lines
drivers/gpu/drm/drm_fb_cma_helper.c +2 -0
@@ -265,6 +267,30 @@ 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_setup_fence() - Set up the fence for atomic helper to wait on

I don't really like the naming of the helper. It's not setting up any fence, it's either extracting it from the plane and/or attaching it to the planestate, so I would have expected the name to include extract or attach.

Quoted 4 lines

drivers/gpu/drm/drm_fb_cma_helper.c struct drm_gem_cma_object *drm_fb_cma_get_gem_obj(struct drm_framebuffer *fb, · line 273

Quoted 2 lines
drivers/gpu/drm/drm_fb_cma_helper.c +2 -0
+ * @plane: Which plane
+ * @state: Plane state to check

s/check/attach fence to

Both fixed in V2, thanks.

Quoted 39 lines
Quoted 37 lines
drivers/gpu/drm/drm_fb_cma_helper.c +20 -0
+ *
+ * If the plane fb has an dma-buf attached, fish out the exclusive
+ * fence for the atomic helper to wait on.
+ */
+void drm_fb_cma_setup_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_setup_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..fc122d3 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_setup_fence(struct drm_plane *plane,
+			    struct drm_plane_state *state);
+
 #ifdef CONFIG_DEBUG_FS
 struct seq_file;
 
Signature · 6 lines
Best regards,
Marek Vasut
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#8 lore raw
Quoted 35 lines · Marek Vasut
Quoted 34 lines · Lucas Stach

Hi Marek,

Am Montag, den 26.09.2016, 15:01 +0200 schrieb Marek Vasut:

Quoted 31 lines

Add new drm_fb_cma_setup_fence() helper function extracted from the imx-drm driver. This function checks if the plane has DMABUF attached to it and if so, sets up the fence on which the atomic helper can wait.

Cc Daniel Vetter <[email protected]>
Cc Lucas Stach <[email protected]>
---
 drivers/gpu/drm/drm_fb_cma_helper.c | 26 ++++++++++++++++++++++++++
 include/drm/drm_fb_cma_helper.h     |  3 +++
 2 files changed, 29 insertions(+)
drivers/gpu/drm/drm_fb_cma_helper.c +2 -0
index 1fd6eac..2441707 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,30 @@ struct drm_gem_cma_object *drm_fb_cma_get_gem_obj(struct drm_framebuffer *fb,
 }
 EXPORT_SYMBOL_GPL(drm_fb_cma_get_gem_obj);
 
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/drm_fb_cma_helper.c struct drm_gem_cma_object *drm_fb_cma_get_gem_obj(struct drm_framebuffer *fb, · line 271

Quoted 2 lines
drivers/gpu/drm/drm_fb_cma_helper.c +2 -0
+/**
+ * drm_fb_cma_setup_fence() - Set up the fence for atomic helper to wait on

I don't really like the naming of the helper. It's not setting up any fence, it's either extracting it from the plane and/or attaching it to the planestate, so I would have expected the name to include extract or attach.

Imo for helpers that should be put into a specific vhook like this here, it'd go with that vhooks name. So here drm_fb_cma_prepare_fb.

And then in the kerneldoc also mention where it should be put (both for drivers using atomic helpers, and those using simple pipe helpers), e.g. "This should be put into the prepare_fb hook of struct &drm_plane_helper_funcs."

Please run $ make htmldocs to make sure the docs look pretty and the generated links are correct.
-Daniel

Quoted 52 lines
Quoted 5 lines

drivers/gpu/drm/drm_fb_cma_helper.c struct drm_gem_cma_object *drm_fb_cma_get_gem_obj(struct drm_framebuffer *fb, · line 273

Quoted 3 lines
drivers/gpu/drm/drm_fb_cma_helper.c +2 -0
+ * @plane: Which plane
+ * @state: Plane state to check

s/check/attach fence to

Both fixed in V2, thanks.

Quoted 39 lines
Quoted 37 lines
drivers/gpu/drm/drm_fb_cma_helper.c +20 -0
+ *
+ * If the plane fb has an dma-buf attached, fish out the exclusive
+ * fence for the atomic helper to wait on.
+ */
+void drm_fb_cma_setup_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_setup_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..fc122d3 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_setup_fence(struct drm_plane *plane,
+			    struct drm_plane_state *state);
+
 #ifdef CONFIG_DEBUG_FS
 struct seq_file;
 
Signature · 2 lines
Best regards,
Marek Vasut
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#9 lore raw
Quoted 44 lines · Daniel Vetter
Quoted 35 lines · Marek Vasut
Quoted 34 lines · Lucas Stach

Hi Marek,

Am Montag, den 26.09.2016, 15:01 +0200 schrieb Marek Vasut:

Quoted 31 lines

Add new drm_fb_cma_setup_fence() helper function extracted from the imx-drm driver. This function checks if the plane has DMABUF attached to it and if so, sets up the fence on which the atomic helper can wait.

Cc Daniel Vetter <[email protected]>
Cc Lucas Stach <[email protected]>
---
 drivers/gpu/drm/drm_fb_cma_helper.c | 26 ++++++++++++++++++++++++++
 include/drm/drm_fb_cma_helper.h     |  3 +++
 2 files changed, 29 insertions(+)
drivers/gpu/drm/drm_fb_cma_helper.c +2 -0
index 1fd6eac..2441707 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,30 @@ struct drm_gem_cma_object *drm_fb_cma_get_gem_obj(struct drm_framebuffer *fb,
 }
 EXPORT_SYMBOL_GPL(drm_fb_cma_get_gem_obj);
 
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/drm_fb_cma_helper.c struct drm_gem_cma_object *drm_fb_cma_get_gem_obj(struct drm_framebuffer *fb, · line 271

Quoted 2 lines
drivers/gpu/drm/drm_fb_cma_helper.c +2 -0
+/**
+ * drm_fb_cma_setup_fence() - Set up the fence for atomic helper to wait on

I don't really like the naming of the helper. It's not setting up any fence, it's either extracting it from the plane and/or attaching it to the planestate, so I would have expected the name to include extract or attach.

Quoted 2 lines

Imo for helpers that should be put into a specific vhook like this here, it'd go with that vhooks name. So here drm_fb_cma_prepare_fb.

I have the following right now, I think that's more descriptive as this function is not preparing the FB in any way.

/**
* 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.
*/

Quoted 62 lines

And then in the kerneldoc also mention where it should be put (both for drivers using atomic helpers, and those using simple pipe helpers), e.g. "This should be put into the prepare_fb hook of struct &drm_plane_helper_funcs."

Please run $ make htmldocs to make sure the docs look pretty and the generated links are correct.
-Daniel

Quoted 52 lines
Quoted 5 lines

drivers/gpu/drm/drm_fb_cma_helper.c struct drm_gem_cma_object *drm_fb_cma_get_gem_obj(struct drm_framebuffer *fb, · line 273

Quoted 3 lines
drivers/gpu/drm/drm_fb_cma_helper.c +2 -0
+ * @plane: Which plane
+ * @state: Plane state to check

s/check/attach fence to

Both fixed in V2, thanks.

Quoted 39 lines
Quoted 37 lines
drivers/gpu/drm/drm_fb_cma_helper.c +20 -0
+ *
+ * If the plane fb has an dma-buf attached, fish out the exclusive
+ * fence for the atomic helper to wait on.
+ */
+void drm_fb_cma_setup_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_setup_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..fc122d3 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_setup_fence(struct drm_plane *plane,
+			    struct drm_plane_state *state);
+
 #ifdef CONFIG_DEBUG_FS
 struct seq_file;
 
Signature · 2 lines
Best regards,
Marek Vasut
Signature · 6 lines
Best regards,
Marek Vasut
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#10 lore raw
Quoted 13 lines · Marek Vasut

I have the following right now, I think that's more descriptive as this function is not preparing the FB in any way.

/**
* 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.
*/

That choice of color is ok with me too, but then you need to have a pile of text to explain where it should be used (i.e. directly as the prepare_fb hook). And it is a bit inconsistent with all the other helpers that can be put into hooks directly. Also, extract_and_attach_fence _is_ officially part of what a driver should do in their ->prepare_fb hook. Hence I'm still leaning towards that (and it's shorter!). And with cma there's nothing else to do (dma memory is always pinned, which is the other thing prepare_fb should do), so really it's not even a lie: Your function fully prapares a cma fb for display as expected by th atomic helpers.
-Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#11 lore raw
Quoted 15 lines · Daniel Vetter
Quoted 13 lines · Marek Vasut

I have the following right now, I think that's more descriptive as this function is not preparing the FB in any way.

/**
* 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.
*/

Quoted 3 lines

That choice of color is ok with me too, but then you need to have a pile of text to explain where it should be used (i.e. directly as the prepare_fb hook).

There can be more stuff in the prepare_fb hook though.

Quoted 8 lines

And it is a bit inconsistent with all the other
helpers that can be put into hooks directly. Also, extract_and_attach_fence _is_ officially part of what a driver should do in their ->prepare_fb hook. Hence I'm still leaning towards that (and it's shorter!). And with cma there's nothing else to do (dma memory is always pinned, which is the other thing prepare_fb should do), so really it's not even a lie: Your function fully prapares a cma fb for display as expected by th atomic helpers.

OK, I have no good argument not to go for this one. Unless someone has, I will redo it.

Quoted 2 lines

-Daniel

Signature · 6 lines
Best regards,
Marek Vasut
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#12 lore raw
Quoted 11 lines · Marek Vasut
Quoted 11 lines
Quoted 10 lines

/**
* 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.
*/

Quoted 5 lines
Quoted 3 lines

That choice of color is ok with me too, but then you need to have a pile of text to explain where it should be used (i.e. directly as the prepare_fb hook).

There can be more stuff in the prepare_fb hook though.

There's 3 things prepare/cleanup_fb should do:
- pin/upin the backing storage. CMA memory is always pinned, so nothing to do.
- setup/tear down iommu mappings: Already done when allocating CMA memory, again nothing to do.
- grab fences in prepare.

So for plain cma drivers this hook is indeed the complete implementation they need for prepare_fb. I guess you could mention in the kernel-doc that cma based drivers don't need a cleanup_fb, hence why there is none.
-Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#13 lore raw
Quoted 24 lines · Daniel Vetter
Quoted 11 lines · Marek Vasut
Quoted 11 lines
Quoted 10 lines

/**
* 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.
*/

Quoted 5 lines
Quoted 3 lines

That choice of color is ok with me too, but then you need to have a pile of text to explain where it should be used (i.e. directly as the prepare_fb hook).

There can be more stuff in the prepare_fb hook though.

There's 3 things prepare/cleanup_fb should do:
- pin/upin the backing storage. CMA memory is always pinned, so nothing to do.
- setup/tear down iommu mappings: Already done when allocating CMA memory, again nothing to do.
- grab fences in prepare.

Quoted 4 lines

So for plain cma drivers this hook is indeed the complete implementation they need for prepare_fb. I guess you could mention in the kernel-doc that cma based drivers don't need a cleanup_fb, hence why there is none.

OK, understood. I'll roll V3 shortly.

Signature · 6 lines
Best regards,
Marek Vasut
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel