Skip to contentSkip to conversation

drm/fb_cma_helper: Add drm_fb_cma_prepare_fb() helper

PATCH In review Marek Vasut 3 participants 5 messages Nov 14, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/2 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.

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

---
V2: Rename the function to drm_fb_cma_prepare_fb()
and clarify the documentation (thanks to Lucas Stach)
V3: - Rename the function to drm_fb_cma_prepare_fb()
- Update documentation
V4: Update to latest next/master (b60de3e)

---
 drivers/gpu/drm/drm_fb_cma_helper.c | 35 +++++++++++++++++++++++++++++++++++
 include/drm/drm_fb_cma_helper.h     |  3 +++
 2 files changed, 38 insertions(+)
drivers/gpu/drm/drm_fb_cma_helper.c +35 -0
index 4c66644..7198373 100644
@@ -18,13 +18,16 @@
  */
 
 #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)
 {
include/drm/drm_fb_cma_helper.h +3 -0
index f313211..cc82c73 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);
 
+int drm_fb_cma_prepare_fb(struct drm_plane *plane,
+			  struct drm_plane_state *state);
+
 #ifdef CONFIG_DEBUG_FS
 struct seq_file;
 
Signature · 6 lines
2.10.2

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

PATCH v4 2/2 drm/imx: Switch to drm_fb_cma_prepare_fb() helper

Remove the common code from the driver and use the drm_fb_cma_prepare_fb() 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
V3: - Call drm_fb_cma_prepare_fb directly
V4: - Update to latest next/master (b60de3e)

---
 drivers/gpu/drm/imx/imx-drm-core.c | 32 +-------------------------------
 drivers/gpu/drm/imx/ipuv3-plane.c  |  1 +
 2 files changed, 2 insertions(+), 31 deletions(-)
drivers/gpu/drm/imx/imx-drm-core.c +1 -31
index a16e8b7..3340429 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,40 +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;
-	struct dma_fence *fence;
-	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;
-			fence = reservation_object_get_excl_rcu(dma_buf->resv);
-
-			drm_atomic_set_fence_for_plane(plane_state, fence);
-		}
-	}
-
-	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 +1 -0
index 6a97e396..e74a0ad 100644
@@ -468,6 +468,7 @@ static void ipu_plane_atomic_update(struct drm_plane *plane,
 }
 
 static const struct drm_plane_helper_funcs ipu_plane_helper_funcs = {
+	.prepare_fb = drm_fb_cma_prepare_fb,
 	.atomic_check = ipu_plane_atomic_check,
 	.atomic_disable = ipu_plane_atomic_disable,
 	.atomic_update = ipu_plane_atomic_update,
Signature · 6 lines
2.10.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v4 2/2
#2 lore raw

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

Am Montag, den 14.11.2016, 11:07 +0100 schrieb Marek Vasut:

Quoted 7 lines

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

Cc Daniel Vetter <[email protected]>
Cc Lucas Stach <[email protected]>
Quoted 69 lines

---
V2: - Rename the function to drm_fb_cma_extract_and_attach_fence()
- Add missing newline
V3: - Call drm_fb_cma_prepare_fb directly
V4: - Update to latest next/master (b60de3e)

---
 drivers/gpu/drm/imx/imx-drm-core.c | 32 +-------------------------------
 drivers/gpu/drm/imx/ipuv3-plane.c  |  1 +
 2 files changed, 2 insertions(+), 31 deletions(-)
drivers/gpu/drm/imx/imx-drm-core.c +1 -31
index a16e8b7..3340429 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,40 +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;
-	struct dma_fence *fence;
-	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;
-			fence = reservation_object_get_excl_rcu(dma_buf->resv);
-
-			drm_atomic_set_fence_for_plane(plane_state, fence);
-		}
-	}
-
-	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 6a97e396..e74a0ad 100644

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

Quoted 7 lines
drivers/gpu/drm/imx/ipuv3-plane.c +1 -0
@@ -468,6 +468,7 @@ static void ipu_plane_atomic_update(struct drm_plane *plane,
 }
 
 static const struct drm_plane_helper_funcs ipu_plane_helper_funcs = {
+	.prepare_fb = drm_fb_cma_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 V4 2/2] drm/imx: Switch to drm_fb_cma_prepare_fb() helper

Quoted 10 lines · Lucas Stach

Am Montag, den 14.11.2016, 11:07 +0100 schrieb Marek Vasut:

Quoted 7 lines

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

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

Both patches applied to drm-misc, thanks.
-Daniel

Quoted 79 lines
Quoted 77 lines

---
V2: - Rename the function to drm_fb_cma_extract_and_attach_fence()
- Add missing newline
V3: - Call drm_fb_cma_prepare_fb directly
V4: - Update to latest next/master (b60de3e)

---
 drivers/gpu/drm/imx/imx-drm-core.c | 32 +-------------------------------
 drivers/gpu/drm/imx/ipuv3-plane.c  |  1 +
 2 files changed, 2 insertions(+), 31 deletions(-)
drivers/gpu/drm/imx/imx-drm-core.c +1 -31
index a16e8b7..3340429 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,40 +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;
-	struct dma_fence *fence;
-	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;
-			fence = reservation_object_get_excl_rcu(dma_buf->resv);
-
-			drm_atomic_set_fence_for_plane(plane_state, fence);
-		}
-	}
-
-	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 +1 -0
index 6a97e396..e74a0ad 100644
@@ -468,6 +468,7 @@ static void ipu_plane_atomic_update(struct drm_plane *plane,
 }
 
 static const struct drm_plane_helper_funcs ipu_plane_helper_funcs = {
+	.prepare_fb = drm_fb_cma_prepare_fb,
 	.atomic_check = ipu_plane_atomic_check,
 	.atomic_disable = ipu_plane_atomic_disable,
 	.atomic_update = ipu_plane_atomic_update,
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
Reviewed-by on v4 1/2
#4 lore raw
In reply to Marek Vasut

Am Montag, den 14.11.2016, 11:07 +0100 schrieb Marek Vasut:

Quoted 8 lines

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.

Cc Daniel Vetter <[email protected]>
Cc Lucas Stach <[email protected]>
Quoted 76 lines

---
V2: Rename the function to drm_fb_cma_prepare_fb()
and clarify the documentation (thanks to Lucas Stach)
V3: - Rename the function to drm_fb_cma_prepare_fb()
- Update documentation
V4: Update to latest next/master (b60de3e)

---
 drivers/gpu/drm/drm_fb_cma_helper.c | 35 +++++++++++++++++++++++++++++++++++
 include/drm/drm_fb_cma_helper.h     |  3 +++
 2 files changed, 38 insertions(+)
drivers/gpu/drm/drm_fb_cma_helper.c +35 -0
index 4c66644..7198373 100644
@@ -18,13 +18,16 @@
  */
 
 #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)
 {
include/drm/drm_fb_cma_helper.h +0 -0
index f313211..cc82c73 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);
 
+int drm_fb_cma_prepare_fb(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