From patchwork Mon Jul 31 15:42:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 9872313 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A9BA560365 for ; Mon, 31 Jul 2017 15:42:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 975EF2852A for ; Mon, 31 Jul 2017 15:42:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C02828567; Mon, 31 Jul 2017 15:42:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E53BD2852A for ; Mon, 31 Jul 2017 15:42:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 01B696F6E2; Mon, 31 Jul 2017 15:42:50 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x242.google.com (mail-wm0-x242.google.com [IPv6:2a00:1450:400c:c09::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9D0116F6E2 for ; Mon, 31 Jul 2017 15:42:48 +0000 (UTC) Received: by mail-wm0-x242.google.com with SMTP id d40so7234150wma.3 for ; Mon, 31 Jul 2017 08:42:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LhoMqXsf3bWa2San6dUI2WCBZ+DDIe9uUTE3KJmQsk8=; b=EekfNDi0M1wKqWQojXgk9EB88HSAaIdGE1GvqxWFLKOE+XR79VHkqQ7nxTtGclqwHz XVxgGj9+6/8fwGv85ZSY2tTTs9JkwqUG9XPUxfceEPdIhjk8DfP5LfQgKoEVl6rcfbAy 4JY/VCBes8DgE4iuQa2VBInOFlsfXn+rIhp7k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LhoMqXsf3bWa2San6dUI2WCBZ+DDIe9uUTE3KJmQsk8=; b=IdR9IipXtUER78ZIzK3laVbuep7acPmxehuN89LATt7B+q0tzuMFaeCdvTxZ+wTD0x J+j2jP4ri09XX03z69CF+ilxtva21riqc7mV+jPTrLhHrV8u5+dTIigDpoS8bcTN7cdG pIhhGNWEHSwszPIRgP/0IKKxcuv9defHKOIZghMrlBamXUtqp2iovXRFkN8wmxw5JHIf IUVHMH3y/aNOwAO8vEL2wEK3gRD1XVqFBW23MUPukYLyfgq/NNgroLMiixypmN/v1tiD cWCnaCl+FWgBBFGb7hTnLQNeKTZb4uJzeislJ/fUtmTIzR+Tjt76RWsrIbeHOrlZt+di jtkA== X-Gm-Message-State: AIVw111fdKecs/B5nUx7Gr58tmxl/ge9IxJIB4RI3u+Yvw6l3kxleLrM pUIGPbMqRp+N77HB0szInQ== X-Received: by 10.80.186.55 with SMTP id g52mr14611317edc.93.1501515766763; Mon, 31 Jul 2017 08:42:46 -0700 (PDT) Received: from dvetter-linux.ger.corp.intel.com ([194.230.159.105]) by smtp.gmail.com with ESMTPSA id z7sm10679860edi.3.2017.07.31.08.42.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 31 Jul 2017 08:42:45 -0700 (PDT) From: Daniel Vetter To: DRI Development Subject: [PATCH] drm/omap: Rework the rotation-on-crtc hack Date: Mon, 31 Jul 2017 17:42:35 +0200 Message-Id: <20170731154235.6402-1-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170725080122.20548-2-daniel.vetter@ffwll.ch> References: <20170725080122.20548-2-daniel.vetter@ffwll.ch> Cc: Daniel Vetter , Tomi Valkeinen , Laurent Pinchart , Daniel Vetter X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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). Reviewed-by: Laurent Pinchart (v4) Cc: Maarten Lankhorst Cc: Tomi Valkeinen Signed-off-by: Daniel Vetter --- drivers/gpu/drm/omapdrm/omap_crtc.c | 109 ++++++++++++++++++++++++------------ 1 file changed, 72 insertions(+), 37 deletions(-) diff --git a/drivers/gpu/drm/omapdrm/omap_crtc.c b/drivers/gpu/drm/omapdrm/omap_crtc.c index 14e8a7738b06..9014085c33df 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 { @@ -498,39 +508,35 @@ 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 omap_crtc_state *omap_state = to_omap_crtc_state(state); + 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; + omap_state->rotation = val; + } else if (property == priv->zorder_prop) { + plane_state->zpos = val; + omap_state->zpos = val; + } else { + return -EINVAL; } - return -EINVAL; + return 0; } static int omap_crtc_atomic_get_property(struct drm_crtc *crtc, @@ -538,28 +544,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,