All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
To: Daniel Vetter <daniel.vetter@ffwll.ch>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Daniel Vetter <daniel.vetter@intel.com>,
	Tomi Valkeinen <tomi.valkeinen@ti.com>,
	DRI Development <dri-devel@lists.freedesktop.org>
Subject: [PATCH] drm/omap: Rework the rotation-on-crtc hack
Date: Wed, 2 Aug 2017 15:20:51 +0200	[thread overview]
Message-ID: <0348f52a-94d4-4174-2060-6104e145acfa@linux.intel.com> (raw)
In-Reply-To: <CAKMK7uEcoJSievoYYL7UUDpFZMPqDcXvtKUS_guLTxnQ+LRukw@mail.gmail.com>

Op 02-08-17 om 10:02 schreef Daniel Vetter:
> On Tue, Aug 1, 2017 at 12:20 PM, Laurent Pinchart
> <laurent.pinchart@ideasonboard.com> wrote:
>> On Tuesday 01 Aug 2017 07:59:13 Maarten Lankhorst wrote:
>>> +       pri_state = drm_atomic_get_new_plane_state(crtc->primary,
>>> state->state);
>>> +       if (pri_state) {
>>> +               struct omap_crtc_state *omap_crtc_state =
>>> +                       to_omap_crtc_state(state);
>>> +
>>> +               omap_crtc_state->zpos = pri_state->zpos;
>>> +               omap_crtc_state->rotation = pri_state->rotation;
>>> +       }
>>>
>>> That way even when updating the property through the primary plane, it gets
>>> reflected correctly. For example when vt switching with fbdev.
>> Let's not make it over-complicated. This hack is only needed fo the legacy X
>> OMAP modesetting driver. The CRTC zpos and rotation properties should not be
>> used through the atomic API.
> Marten is right, the atomic properties are all such that you can
> unconditionally restore them (e.g. fences report a no-op value), to
> make compositor switching easier. Not sure anyone implements that, but
> I think it's a useful idea to keep. I'll respin (or maybe Maarten
> simply submits his patch with a proper sob ...).
> -Daniel

Here you go, compile tested version. :)
----8<----
I want/need to rework the core property handling, and this hack is
getting in the way. But since it's a non-standard propety only used by
legacy userspace we know that this will only every be called from
ioctl code. And never on some other free-standing state struct, where
this old hack wouldn't work either.

v2: don't forget zorder and get_property!

v3: Shadow the legacy state to avoid locking issues in get_property
(Maarten).

v4: Review from Laurent
- Move struct omap_crtc_state into omap_crtc.c
- Clean up comments.
- Don't forget to copy the shadowed state over on duplicate.

v5: Don't forget to update the reset handler (Maarten).
v6: Update omap_crtc_state shadow values in omap_crtc_atomic_check (Maarten).

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> (v4)
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Tomi Valkeinen <tomi.valkeinen@ti.com
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
---
 drivers/gpu/drm/omapdrm/omap_crtc.c | 118 +++++++++++++++++++++++++-----------
 1 file changed, 81 insertions(+), 37 deletions(-)

diff --git a/drivers/gpu/drm/omapdrm/omap_crtc.c b/drivers/gpu/drm/omapdrm/omap_crtc.c
index 14e8a7738b06..b842fcd9914a 100644
--- a/drivers/gpu/drm/omapdrm/omap_crtc.c
+++ b/drivers/gpu/drm/omapdrm/omap_crtc.c
@@ -26,6 +26,16 @@
 
 #include "omap_drv.h"
 
+#define to_omap_crtc_state(x) container_of(x, struct omap_crtc_state, base)
+
+struct omap_crtc_state {
+	/* Must be first. */
+	struct drm_crtc_state base;
+	/* Shadow values for legacy userspace support. */
+	unsigned int rotation;
+	unsigned int zpos;
+};
+
 #define to_omap_crtc(x) container_of(x, struct omap_crtc, base)
 
 struct omap_crtc {
@@ -445,6 +455,8 @@ static void omap_crtc_mode_set_nofb(struct drm_crtc *crtc)
 static int omap_crtc_atomic_check(struct drm_crtc *crtc,
 				struct drm_crtc_state *state)
 {
+	struct drm_plane_state *pri_state;
+
 	if (state->color_mgmt_changed && state->gamma_lut) {
 		uint length = state->gamma_lut->length /
 			sizeof(struct drm_color_lut);
@@ -453,6 +465,16 @@ static int omap_crtc_atomic_check(struct drm_crtc *crtc,
 			return -EINVAL;
 	}
 
+	pri_state = drm_atomic_get_new_plane_state(state->state, crtc->primary);
+	if (pri_state) {
+		struct omap_crtc_state *omap_crtc_state =
+			to_omap_crtc_state(state);
+
+		/* Mirror new values for zpos and rotation in omap_crtc_state */
+		omap_crtc_state->zpos = pri_state->zpos;
+		omap_crtc_state->rotation = pri_state->rotation;
+	}
+
 	return 0;
 }
 
@@ -498,39 +520,32 @@ static void omap_crtc_atomic_flush(struct drm_crtc *crtc,
 	spin_unlock_irq(&crtc->dev->event_lock);
 }
 
-static bool omap_crtc_is_plane_prop(struct drm_crtc *crtc,
-	struct drm_property *property)
-{
-	struct drm_device *dev = crtc->dev;
-	struct omap_drm_private *priv = dev->dev_private;
-
-	return property == priv->zorder_prop ||
-		property == crtc->primary->rotation_property;
-}
-
 static int omap_crtc_atomic_set_property(struct drm_crtc *crtc,
 					 struct drm_crtc_state *state,
 					 struct drm_property *property,
 					 uint64_t val)
 {
-	if (omap_crtc_is_plane_prop(crtc, property)) {
-		struct drm_plane_state *plane_state;
-		struct drm_plane *plane = crtc->primary;
-
-		/*
-		 * Delegate property set to the primary plane. Get the plane
-		 * state and set the property directly.
-		 */
-
-		plane_state = drm_atomic_get_plane_state(state->state, plane);
-		if (IS_ERR(plane_state))
-			return PTR_ERR(plane_state);
+	struct omap_drm_private *priv = crtc->dev->dev_private;
+	struct drm_plane_state *plane_state;
 
-		return drm_atomic_plane_set_property(plane, plane_state,
-				property, val);
+	/*
+	 * Delegate property set to the primary plane. Get the plane state and
+	 * set the property directly, but keep a shadow copy for the
+	 * atomic_get_property callback.
+	 */
+	plane_state = drm_atomic_get_plane_state(state->state, crtc->primary);
+	if (IS_ERR(plane_state))
+		return PTR_ERR(plane_state);
+
+	if (property == crtc->primary->rotation_property) {
+		plane_state->rotation = val;
+	} else if (property == priv->zorder_prop) {
+		plane_state->zpos = val;
+	} else {
+		return -EINVAL;
 	}
 
-	return -EINVAL;
+	return 0;
 }
 
 static int omap_crtc_atomic_get_property(struct drm_crtc *crtc,
@@ -538,28 +553,57 @@ static int omap_crtc_atomic_get_property(struct drm_crtc *crtc,
 					 struct drm_property *property,
 					 uint64_t *val)
 {
-	if (omap_crtc_is_plane_prop(crtc, property)) {
-		/*
-		 * Delegate property get to the primary plane. The
-		 * drm_atomic_plane_get_property() function isn't exported, but
-		 * can be called through drm_object_property_get_value() as that
-		 * will call drm_atomic_get_property() for atomic drivers.
-		 */
-		return drm_object_property_get_value(&crtc->primary->base,
-				property, val);
-	}
+	struct omap_drm_private *priv = crtc->dev->dev_private;
+	struct omap_crtc_state *omap_state = to_omap_crtc_state(state);
+
+	if (property == crtc->primary->rotation_property)
+		return omap_state->rotation;
+	else if (property == priv->zorder_prop)
+		return omap_state->zpos;
 
 	return -EINVAL;
 }
 
+static void omap_crtc_reset(struct drm_crtc *crtc)
+{
+	if (crtc->state)
+		__drm_atomic_helper_crtc_destroy_state(crtc->state);
+
+	kfree(crtc->state);
+	crtc->state = kzalloc(sizeof(struct omap_crtc_state), GFP_KERNEL);
+
+	if (crtc->state)
+		crtc->state->crtc = crtc;
+}
+
+static struct drm_crtc_state *
+omap_crtc_duplicate_state(struct drm_crtc *crtc)
+{
+	struct omap_crtc_state *state, *current_state;
+
+	if (WARN_ON(!crtc->state))
+		return NULL;
+
+	current_state = to_omap_crtc_state(crtc->state);
+
+	state = kmalloc(sizeof(*state), GFP_KERNEL);
+	if (state)
+		__drm_atomic_helper_crtc_duplicate_state(crtc, &state->base);
+
+	state->zpos = current_state->zpos;
+	state->rotation = current_state->rotation;
+
+	return &state->base;
+}
+
 static const struct drm_crtc_funcs omap_crtc_funcs = {
-	.reset = drm_atomic_helper_crtc_reset,
+	.reset = omap_crtc_reset,
 	.set_config = drm_atomic_helper_set_config,
 	.destroy = omap_crtc_destroy,
 	.page_flip = drm_atomic_helper_page_flip,
 	.gamma_set = drm_atomic_helper_legacy_gamma_set,
 	.set_property = drm_atomic_helper_crtc_set_property,
-	.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
+	.atomic_duplicate_state = omap_crtc_duplicate_state,
 	.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
 	.atomic_set_property = omap_crtc_atomic_set_property,
 	.atomic_get_property = omap_crtc_atomic_get_property,
-- 
2.11.0


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

  reply	other threads:[~2017-08-02 13:20 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-25  8:01 [PATCH 0/8] acquire ctx for everyone! Daniel Vetter
2017-07-25  8:01 ` [PATCH 1/8] drm/omap: Simplify the rotation-on-crtc hack Daniel Vetter
2017-07-25  8:47   ` Maarten Lankhorst
2017-07-25  9:24     ` [Intel-gfx] " Daniel Vetter
2017-07-31 11:48       ` Laurent Pinchart
2017-07-31 11:56         ` Tomi Valkeinen
2017-07-31 10:54   ` [PATCH] drm/omap: Rework " Daniel Vetter
2017-07-31 11:57     ` Laurent Pinchart
2017-07-31 12:45   ` Daniel Vetter
2017-07-31 13:30     ` Laurent Pinchart
2017-07-31 15:42   ` Daniel Vetter
2017-08-01  5:59     ` Maarten Lankhorst
2017-08-01 10:20       ` Laurent Pinchart
2017-08-02  8:02         ` Daniel Vetter
2017-08-02 13:20           ` Maarten Lankhorst [this message]
2017-08-04  9:57             ` Tomi Valkeinen
2017-08-04 10:02               ` Daniel Vetter
2017-08-07  9:24                 ` Maarten Lankhorst
2017-08-07  9:56                 ` Maarten Lankhorst
2017-08-07 10:20                 ` [PATCH v7] " Maarten Lankhorst
2017-08-08 12:08                   ` Tomi Valkeinen
2017-07-25  8:01 ` [PATCH 2/8] drm: Don't update property values for atomic drivers Daniel Vetter
2017-07-25  8:32   ` Maarten Lankhorst
2017-07-25 12:01   ` [PATCH] " Daniel Vetter
2017-08-11 22:20   ` [PATCH 2/8] " Laurent Pinchart
2017-08-14  7:25     ` Daniel Vetter
2017-08-14 10:32       ` Laurent Pinchart
2017-08-14 14:09         ` Daniel Vetter
2017-07-25  8:01 ` [PATCH 3/8] drm: Handle properties in the core " Daniel Vetter
2017-07-25  9:36   ` Archit Taneja
2017-07-25 12:02   ` [PATCH] " Daniel Vetter
2017-07-25  8:01 ` [PATCH 4/8] drm: Nuke drm_atomic_helper_crtc_set_property Daniel Vetter
2017-07-25  9:38   ` Archit Taneja
2017-07-25 10:05   ` Philippe CORNU
2017-08-03 13:34   ` Thomas Hellstrom
2017-07-25  8:01 ` [PATCH 5/8] drm: Nuke drm_atomic_helper_plane_set_property Daniel Vetter
2017-07-25  8:01   ` Daniel Vetter
2017-07-25  8:01   ` Daniel Vetter
2017-07-25  9:38   ` Archit Taneja
2017-07-25  9:38     ` Archit Taneja
2017-07-25  9:38     ` Archit Taneja
2017-07-25 10:06   ` Philippe CORNU
2017-07-25 10:06     ` Philippe CORNU
2017-07-25 10:06     ` Philippe CORNU
2017-07-28 16:45   ` Liviu Dudau
2017-07-28 16:45     ` Liviu Dudau
2017-07-28 16:45     ` Liviu Dudau
2017-08-08 10:03   ` Vincent ABRIOU
2017-08-08 10:03     ` Vincent ABRIOU
2017-08-08 10:03     ` Vincent ABRIOU
2017-08-08 12:31   ` Laurent Pinchart
     [not found] ` <20170725080122.20548-1-daniel.vetter-/w4YWyX8dFk@public.gmane.org>
2017-07-25  8:01   ` [PATCH 6/8] drm: Nuke drm_atomic_helper_connector_set_property Daniel Vetter
     [not found]     ` <20170725080122.20548-7-daniel.vetter-/w4YWyX8dFk@public.gmane.org>
2017-07-25  9:23       ` [Intel-gfx] " Maarten Lankhorst
2017-07-25  9:26         ` Daniel Vetter
2017-08-08 10:04     ` Vincent ABRIOU
2017-07-25  8:01 ` [PATCH 7/8] drm: Nuke drm_atomic_helper_connector_dpms Daniel Vetter
2017-07-25  8:01   ` Daniel Vetter
2017-07-25  8:04   ` Neil Armstrong
2017-07-25  8:04     ` Neil Armstrong
2017-07-25  8:04   ` Neil Armstrong
2017-07-25  8:59   ` Philipp Zabel
2017-07-25  8:59     ` Philipp Zabel
2017-07-25  8:59   ` Philipp Zabel
2017-07-25  9:30   ` Archit Taneja
2017-07-25  9:30     ` Archit Taneja
2017-07-25  9:30   ` Archit Taneja
2017-07-25 10:07   ` Philippe CORNU
2017-07-25 10:07   ` Philippe CORNU
2017-07-25 10:07     ` Philippe CORNU
2017-07-25 14:01   ` Laurent Pinchart
2017-07-25 14:01   ` Laurent Pinchart
2017-07-25 14:42   ` Shawn Guo
2017-07-25 14:42   ` Shawn Guo
2017-07-25 14:42     ` Shawn Guo
2017-07-26 19:00   ` Noralf Trønnes
2017-07-26 19:00   ` Noralf Trønnes
2017-07-26 19:00     ` Noralf Trønnes
2017-08-08 10:05   ` Vincent ABRIOU
2017-08-08 10:05     ` Vincent ABRIOU
2017-08-08 10:05   ` Vincent ABRIOU
2017-07-25  8:01 ` [PATCH 8/8] drm: Nuke drm_atomic_legacy_backoff Daniel Vetter
2017-07-25  9:36   ` [Intel-gfx] " Maarten Lankhorst
2017-07-25  8:44 ` ✓ Fi.CI.BAT: success for acquire ctx for everyone! Patchwork
2017-07-25 12:05 ` ✗ Fi.CI.BAT: failure for acquire ctx for everyone! (rev3) Patchwork

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=0348f52a-94d4-4174-2060-6104e145acfa@linux.intel.com \
    --to=maarten.lankhorst@linux.intel.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=daniel.vetter@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=tomi.valkeinen@ti.com \
    /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.