All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel.vetter@ffwll.ch>
To: DRI Development <dri-devel@lists.freedesktop.org>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>,
	Intel Graphics Development <intel-gfx@lists.freedesktop.org>
Subject: [PATCH] drm/plane-helper: transitional atomic plane helpers
Date: Wed,  5 Nov 2014 17:59:14 +0100	[thread overview]
Message-ID: <1415206754-27851-1-git-send-email-daniel.vetter@ffwll.ch> (raw)
In-Reply-To: <1414934370-11924-9-git-send-email-daniel.vetter@ffwll.ch>

Converting a driver to the atomic interface can be a daunting
undertaking. One of the prerequisites is to have full universal planes
support.

To make that transition a bit easier this patch provides plane helpers
which use the new atomic helper callbacks just only for the plane
changes. This way the plane update functionality can be tested without
being forced to convert everything at once.

Of course a real atomic update capable driver will implement the
all plane properties through the atomic interface, so these helpers
are mostly transitional. But they can be used to enable proper
universal plane support, especially once the crtc helpers have also
been adapted.

v2: Use ->atomic_duplicate_state if available.

v3: Don't forget to call ->atomic_destroy_state if available.

v4: Fixup kerneldoc, reported by Paulo.

v5: Extract a common plane_commit helper and fix some bugs in the
plane_state setup of the plane_disable implementation.

v6: Fix issues with the cleanup of the old fb. Since transitional
helpers can be mixed we need to assume that the old fb has been set up
by a legacy path (e.g. set_config or page_flip when the primary plane
is converted to use these functions already). Hence pass an additional
old_fb parameter to plane_commit to do that cleanup work correctly.

v7:
- Fix spurious WARNING (crtc helpers really love to disable stuff
  harder) and fix array index bonghits.
- Correctly handle the lack of plane->state object, necessary for
  transitional use.
- Don't indicate failure if drm_vblank_get doesn't work - that's
  expected when the pipe is in dpms off mode.

v8: Review from Sean:
- s/fail/out/ to make the meaning of a label more clear.
- spelling fix in the commit message.

Cc: Paulo Zanoni <przanoni@gmail.com>
Cc: Sean Paul <seanpaul@chromium.org>
Reviewed-by: Sean Paul <seanpaul@chromium.org>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/drm_plane_helper.c | 172 ++++++++++++++++++++++++++++++++++++-
 include/drm/drm_plane_helper.h     |   8 ++
 2 files changed, 179 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_plane_helper.c b/drivers/gpu/drm/drm_plane_helper.c
index 827ec1a3040b..a202b89e14eb 100644
--- a/drivers/gpu/drm/drm_plane_helper.c
+++ b/drivers/gpu/drm/drm_plane_helper.c
@@ -27,7 +27,7 @@
 #include <drm/drmP.h>
 #include <drm/drm_plane_helper.h>
 #include <drm/drm_rect.h>
-#include <drm/drm_plane_helper.h>
+#include <drm/drm_crtc_helper.h>
 
 #define SUBPIXEL_MASK 0xffff
 
@@ -369,3 +369,173 @@ int drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
 	return drm_crtc_init_with_planes(dev, crtc, primary, NULL, funcs);
 }
 EXPORT_SYMBOL(drm_crtc_init);
+
+static int
+plane_commit(struct drm_plane *plane, struct drm_plane_state *plane_state,
+	     struct drm_framebuffer *old_fb)
+{
+	struct drm_plane_helper_funcs *plane_funcs;
+	struct drm_crtc *crtc[2];
+	struct drm_crtc_helper_funcs *crtc_funcs[2];
+	int i, ret = 0;
+
+	plane_funcs = plane->helper_private;
+
+	/* Since this is a transitional helper we can't assume that plane->state
+	 * is always valid. Hence we need to use plane->crtc instead of
+	 * plane->state->crtc as the old crtc. */
+	crtc[0] = plane->crtc;
+	crtc[1] = crtc[0] != plane_state->crtc ? plane_state->crtc : NULL;
+
+	for (i = 0; i < 2; i++)
+		crtc_funcs[i] = crtc[i] ? crtc[i]->helper_private : NULL;
+
+	if (plane_funcs->atomic_check) {
+		ret = plane_funcs->atomic_check(plane, plane_state);
+		if (ret)
+			goto out;
+	}
+
+	if (plane_funcs->prepare_fb && plane_state->fb) {
+		ret = plane_funcs->prepare_fb(plane, plane_state->fb);
+		if (ret)
+			goto out;
+	}
+
+	/* Point of no return, commit sw state. */
+	swap(plane->state, plane_state);
+
+	for (i = 0; i < 2; i++) {
+		if (crtc_funcs[i] && crtc_funcs[i]->atomic_begin)
+			crtc_funcs[i]->atomic_begin(crtc[i]);
+	}
+
+	plane_funcs->atomic_update(plane);
+
+	for (i = 0; i < 2; i++) {
+		if (crtc_funcs[i] && crtc_funcs[i]->atomic_flush)
+			crtc_funcs[i]->atomic_flush(crtc[i]);
+	}
+
+	for (i = 0; i < 2; i++) {
+		if (!crtc[i])
+			continue;
+
+		/* There's no other way to figure out whether the crtc is running. */
+		ret = drm_crtc_vblank_get(crtc[i]);
+		if (ret == 0) {
+			drm_crtc_wait_one_vblank(crtc[i]);
+			drm_crtc_vblank_put(crtc[i]);
+		}
+
+		ret = 0;
+	}
+
+	if (plane_funcs->cleanup_fb && old_fb)
+		plane_funcs->cleanup_fb(plane, old_fb);
+out:
+	if (plane_state) {
+		if (plane->funcs->atomic_destroy_state)
+			plane->funcs->atomic_destroy_state(plane, plane_state);
+		else
+			kfree(plane_state);
+	}
+
+	return ret;
+}
+
+/**
+ * drm_plane_helper_update() - Helper for primary plane update
+ * @plane: plane object to update
+ * @crtc: owning CRTC of owning plane
+ * @fb: framebuffer to flip onto plane
+ * @crtc_x: x offset of primary plane on crtc
+ * @crtc_y: y offset of primary plane on crtc
+ * @crtc_w: width of primary plane rectangle on crtc
+ * @crtc_h: height of primary plane rectangle on crtc
+ * @src_x: x offset of @fb for panning
+ * @src_y: y offset of @fb for panning
+ * @src_w: width of source rectangle in @fb
+ * @src_h: height of source rectangle in @fb
+ *
+ * Provides a default plane update handler using the atomic plane update
+ * functions. It is fully left to the driver to check plane constraints and
+ * handle corner-cases like a fully occluded or otherwise invisible plane.
+ *
+ * This is useful for piecewise transitioning of a driver to the atomic helpers.
+ *
+ * RETURNS:
+ * Zero on success, error code on failure
+ */
+int drm_plane_helper_update(struct drm_plane *plane, struct drm_crtc *crtc,
+			    struct drm_framebuffer *fb,
+			    int crtc_x, int crtc_y,
+			    unsigned int crtc_w, unsigned int crtc_h,
+			    uint32_t src_x, uint32_t src_y,
+			    uint32_t src_w, uint32_t src_h)
+{
+	struct drm_plane_state *plane_state;
+
+	if (plane->funcs->atomic_duplicate_state)
+		plane_state = plane->funcs->atomic_duplicate_state(plane);
+	else if (plane->state)
+		plane_state = kmemdup(plane->state, sizeof(*plane_state),
+				      GFP_KERNEL);
+	else
+		plane_state = kzalloc(sizeof(*plane_state), GFP_KERNEL);
+	if (!plane_state)
+		return -ENOMEM;
+
+	plane_state->crtc = crtc;
+	plane_state->fb = fb;
+	plane_state->crtc_x = crtc_x;
+	plane_state->crtc_y = crtc_y;
+	plane_state->crtc_h = crtc_h;
+	plane_state->crtc_w = crtc_w;
+	plane_state->src_x = src_x;
+	plane_state->src_y = src_y;
+	plane_state->src_h = src_h;
+	plane_state->src_w = src_w;
+
+	return plane_commit(plane, plane_state, plane->fb);
+}
+EXPORT_SYMBOL(drm_plane_helper_update);
+
+/**
+ * drm_plane_helper_disable() - Helper for primary plane disable
+ * @plane: plane to disable
+ *
+ * Provides a default plane disable handler using the atomic plane update
+ * functions. It is fully left to the driver to check plane constraints and
+ * handle corner-cases like a fully occluded or otherwise invisible plane.
+ *
+ * This is useful for piecewise transitioning of a driver to the atomic helpers.
+ *
+ * RETURNS:
+ * Zero on success, error code on failure
+ */
+int drm_plane_helper_disable(struct drm_plane *plane)
+{
+	struct drm_plane_state *plane_state;
+
+	/* crtc helpers love to call disable functions for already disabled hw
+	 * functions. So cope with that. */
+	if (!plane->crtc)
+		return 0;
+
+	if (plane->funcs->atomic_duplicate_state)
+		plane_state = plane->funcs->atomic_duplicate_state(plane);
+	else if (plane->state)
+		plane_state = kmemdup(plane->state, sizeof(*plane_state),
+				      GFP_KERNEL);
+	else
+		plane_state = kzalloc(sizeof(*plane_state), GFP_KERNEL);
+	if (!plane_state)
+		return -ENOMEM;
+
+	plane_state->crtc = NULL;
+	plane_state->fb = NULL;
+
+	return plane_commit(plane, plane_state, plane->fb);
+}
+EXPORT_SYMBOL(drm_plane_helper_disable);
diff --git a/include/drm/drm_plane_helper.h b/include/drm/drm_plane_helper.h
index 8577ec8f3e6c..92bceccaa62a 100644
--- a/include/drm/drm_plane_helper.h
+++ b/include/drm/drm_plane_helper.h
@@ -95,4 +95,12 @@ extern struct drm_plane *drm_primary_helper_create_plane(struct drm_device *dev,
 							 int num_formats);
 
 
+int drm_plane_helper_update(struct drm_plane *plane, struct drm_crtc *crtc,
+			    struct drm_framebuffer *fb,
+			    int crtc_x, int crtc_y,
+			    unsigned int crtc_w, unsigned int crtc_h,
+			    uint32_t src_x, uint32_t src_y,
+			    uint32_t src_w, uint32_t src_h);
+int drm_plane_helper_disable(struct drm_plane *plane);
+
 #endif
-- 
2.1.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2014-11-05 16:59 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-02 13:19 [PATCH 00/17] atomic modeset core<->driver interfaces and helpers Daniel Vetter
2014-11-02 13:19 ` [PATCH 01/17] drm: Move drm_crtc_init from drm_crtc.h to drm_plane_helper.h Daniel Vetter
2014-11-04 20:31   ` Sean Paul
2014-11-02 13:19 ` [PATCH 02/17] drm: Pull drm_crtc.h into the kerneldoc template Daniel Vetter
2014-11-02 19:18   ` [PATCH] " Daniel Vetter
2014-11-03  3:04     ` Thierry Reding
2014-11-02 13:19 ` [PATCH 03/17] drm: fixup kerneldoc in drm_crtc.h Daniel Vetter
2014-11-02 19:19   ` Daniel Vetter
2014-11-02 13:19 ` [PATCH 04/17] drm/modeset_lock: document trylock_only in kerneldoc Daniel Vetter
2014-11-04 20:31   ` Sean Paul
2014-11-05 16:18   ` Thierry Reding
2014-11-02 13:19 ` [PATCH 05/17] drm: Add atomic driver interface definitions for objects Daniel Vetter
2014-11-04 20:31   ` Sean Paul
2014-11-05 16:26   ` Thierry Reding
2014-11-05 17:04     ` Daniel Vetter
2014-11-05 17:16       ` [Intel-gfx] " Damien Lespiau
2014-11-02 13:19 ` [PATCH 06/17] drm: Global atomic state handling Daniel Vetter
2014-11-03 23:41   ` Matt Roper
2014-11-04  8:40     ` Daniel Vetter
2014-11-04 20:31   ` Sean Paul
2014-11-04 21:30     ` Daniel Vetter
2014-11-04 21:41       ` Daniel Vetter
2014-11-04 21:37   ` [PATCH] " Daniel Vetter
2014-11-04 22:07     ` Daniel Vetter
2014-11-04 22:32       ` Sean Paul
2014-11-05 13:06       ` Ander Conselvan de Oliveira
2014-11-05 13:45       ` Daniel Vetter
2014-11-05 14:22         ` Daniel Vetter
2014-11-05 17:06           ` Daniel Vetter
2015-02-06  9:58             ` [Intel-gfx] " Jani Nikula
2015-02-06 21:14               ` Daniel Vetter
2014-11-02 13:19 ` [PATCH 07/17] drm: Add atomic/plane helpers Daniel Vetter
2014-11-04 22:30   ` Sean Paul
2014-11-04 23:16     ` Daniel Vetter
2014-11-02 13:19 ` [PATCH 08/17] drm/plane-helper: transitional atomic plane helpers Daniel Vetter
2014-11-05 16:45   ` Sean Paul
2014-11-05 16:51     ` Daniel Vetter
2014-11-05 16:59   ` Daniel Vetter [this message]
2014-11-02 13:19 ` [PATCH 09/17] drm/crtc-helper: Transitional functions using " Daniel Vetter
2014-11-05 17:42   ` Sean Paul
2014-11-02 13:19 ` [PATCH 10/17] drm: Atomic crtc/connector updates using crtc/plane helper interfaces Daniel Vetter
2014-11-05 18:53   ` Sean Paul
2014-11-05 21:44     ` Daniel Vetter
2014-11-06 18:28       ` Sean Paul
2014-11-02 13:19 ` [PATCH 11/17] drm/atomic-helper: implementatations for legacy interfaces Daniel Vetter
2014-11-04 22:08   ` [PATCH] " Daniel Vetter
2014-11-05 13:46     ` Daniel Vetter
2014-11-05 19:48       ` Sean Paul
2014-11-05 22:01         ` Daniel Vetter
2014-11-06 18:31           ` Sean Paul
2014-11-02 13:19 ` [PATCH 12/17] drm/atomic: Integrate fence support Daniel Vetter
2014-11-06 17:43   ` [Intel-gfx] " Sean Paul
2014-11-02 13:19 ` [PATCH 13/17] drm/atomic-helpers: document how to implement async commit Daniel Vetter
2014-11-06 17:43   ` Sean Paul
2014-11-02 13:19 ` [PATCH 14/17] drm/atomic-helper: implement ->page_flip Daniel Vetter
2014-11-04 22:09   ` [PATCH] " Daniel Vetter
2014-11-05 11:35     ` Daniel Thompson
2014-11-05 13:46     ` Daniel Vetter
2014-11-06 17:43   ` [PATCH 14/17] " Sean Paul
2014-11-06 18:13     ` Daniel Vetter
2014-11-06 18:53       ` Sean Paul
2014-11-02 13:19 ` [PATCH 15/17] drm/atomic-helpers: functions for state duplicate/destroy/reset Daniel Vetter
2014-11-03 14:45   ` Daniel Thompson
2014-11-03 14:53     ` Daniel Vetter
2014-11-03 15:06       ` Daniel Thompson
2014-11-03 15:11         ` Daniel Vetter
2014-11-06 17:43   ` Sean Paul
2014-11-06 19:57     ` Daniel Vetter
2014-11-06 20:01       ` Sean Paul
2014-11-06 19:55   ` [PATCH] " Daniel Vetter
2014-11-02 13:19 ` [PATCH 16/17] drm: Docbook integration and over sections for all the new helpers Daniel Vetter
2014-11-06 17:43   ` Sean Paul
2014-11-06 20:00   ` [PATCH] " Daniel Vetter
2014-11-06 20:02     ` Sean Paul
2014-11-02 13:19 ` [PATCH 17/17] drm/atomic: Refcounting for plane_state->fb Daniel Vetter
2014-11-04 21:57   ` [PATCH] " Daniel Vetter
2014-11-06 17:44   ` [PATCH 17/17] " Sean Paul

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1415206754-27851-1-git-send-email-daniel.vetter@ffwll.ch \
    --to=daniel.vetter@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.