Received: by 10.223.176.46 with SMTP id f43csp2685820wra; Mon, 22 Jan 2018 01:34:44 -0800 (PST) X-Google-Smtp-Source: AH8x225ND6cBwvdz9mFLW/bUV8eaAZIVdPmryN4jMCCZd41lp4OJxJ3A1/T0QJtLvPfZF5CDSQDD X-Received: by 2002:a17:902:9683:: with SMTP id n3-v6mr3037152plp.177.1516613684727; Mon, 22 Jan 2018 01:34:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516613684; cv=none; d=google.com; s=arc-20160816; b=gshq14JWzAHcw9GpvS9UYktLW5lDLCElnufCFANADwapDFR7o5agQn2uTxITT8g7oZ 5mkrS2do0ftdbTwyT/JuOY61PZpQ1Gkd4SFabg4Ya3WzW69qcYDZOdV+gPFQORKF3tk7 iO9VziBFGyEFiLGFG1J54JRnZ8ULHQaltQVyESGukydeZDpK/URk7KR5ukzbo/pyeDv1 BO/1qJv3MMSBEsN+Gr6+FYLT5pqCE2n1e5ejdW4NOJZ0Ip6ipetrQooYvyQXpV1IPL0d qGOGDoMCeisMoWyUDeZYGMQkXXaeEmFfvjS7uxLQ2P1DYA04GlodSGE2ykDKlTHukdep OHoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=+1rzl4mH6+DQULWcIsuHM5gigJMFotySXG0vC7UQvOc=; b=ARKTDcHn0dsHg2Dtl2tizJ30iAvP8q93IAAPFYz7RwC8KG3EcJKUuLGlYuD+dl4R4B ppHAQYHvuZ+n85RIdTnSFQb9jpkzDs+evy4Sa3Y5cQ62qKW8u0+pdF8WYx6u8lwvIcYW OCI0OQIXD+yBq88T+4iDcLcCXmupxKuCBM2QCGrgqZVXn4+SsfKwV3jXvPJzAfTxM7ZW jmwqeZqfmXpSnLdFwCSxegralqYN5gWJcCdFOVCCU7TF6IL2vDwEIE4CJAZ5BW2OF2qW AvPf3KZGkgMmblDOq6UQMowUkimntsuy8J8uI2X3GchSbYpsvuezhtKbvk9zy9kRCfBT u6RA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s6si13621508pgr.221.2018.01.22.01.34.30; Mon, 22 Jan 2018 01:34:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752236AbeAVJdf (ORCPT + 99 others); Mon, 22 Jan 2018 04:33:35 -0500 Received: from mail.free-electrons.com ([62.4.15.54]:44075 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751947AbeAVJZk (ORCPT ); Mon, 22 Jan 2018 04:25:40 -0500 Received: by mail.free-electrons.com (Postfix, from userid 110) id 4C31D207C8; Mon, 22 Jan 2018 10:25:39 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.free-electrons.com (Postfix) with ESMTPSA id 1F79F2069C; Mon, 22 Jan 2018 10:25:29 +0100 (CET) From: Maxime Ripard To: Chen-Yu Tsai , Maxime Ripard Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, narmstrong@baylibre.com, thomas@vitsch.nl Subject: [PATCH v4 10/13] drm/sun4i: backend: Add a custom atomic_check for the frontend Date: Mon, 22 Jan 2018 10:25:24 +0100 Message-Id: <278e6c514a8311750fe627c7f28d58b3e2cbd825.1516613040.git-series.maxime.ripard@free-electrons.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that we have everything in place, we can start enabling the frontend. This is more difficult than one would assume since there can only be one plane using the frontend per-backend. We therefore need to make sure that the userspace will not try to setup multiple planes using it, since that would be impossible. In order to prevent that, we can create an atomic_check callback that will check that only one plane will effectively make use of the frontend in a given configuration, and will toggle the switch in that plane state so that the proper setup function can do their role. Reviewed-by: Chen-Yu Tsai Reviewed-by: Neil Armstrong Signed-off-by: Maxime Ripard --- drivers/gpu/drm/sun4i/sun4i_backend.c | 65 ++++++++++++++++++++++++++++- drivers/gpu/drm/sun4i/sun4i_backend.h | 2 +- 2 files changed, 67 insertions(+) diff --git a/drivers/gpu/drm/sun4i/sun4i_backend.c b/drivers/gpu/drm/sun4i/sun4i_backend.c index 21b047e5b4b7..1b8e3dcbe47a 100644 --- a/drivers/gpu/drm/sun4i/sun4i_backend.c +++ b/drivers/gpu/drm/sun4i/sun4i_backend.c @@ -11,6 +11,7 @@ */ #include +#include #include #include #include @@ -271,6 +272,69 @@ int sun4i_backend_update_layer_buffer(struct sun4i_backend *backend, return 0; } +static bool sun4i_backend_plane_uses_scaler(struct drm_plane_state *state) +{ + u16 src_h = state->src_h >> 16; + u16 src_w = state->src_w >> 16; + + DRM_DEBUG_DRIVER("Input size %dx%d, output size %dx%d\n", + src_w, src_h, state->crtc_w, state->crtc_h); + + if ((state->crtc_h != src_h) || (state->crtc_w != src_w)) + return true; + + return false; +} + +static bool sun4i_backend_plane_uses_frontend(struct drm_plane_state *state) +{ + struct sun4i_layer *layer = plane_to_sun4i_layer(state->plane); + struct sun4i_backend *backend = layer->backend; + + if (IS_ERR(backend->frontend)) + return false; + + return sun4i_backend_plane_uses_scaler(state); +} + +static int sun4i_backend_atomic_check(struct sunxi_engine *engine, + struct drm_crtc_state *crtc_state) +{ + struct drm_atomic_state *state = crtc_state->state; + struct drm_device *drm = state->dev; + struct drm_plane *plane; + unsigned int num_frontend_planes = 0; + + DRM_DEBUG_DRIVER("Starting checking our planes\n"); + + if (!crtc_state->planes_changed) + return 0; + + drm_for_each_plane_mask(plane, drm, crtc_state->plane_mask) { + struct drm_plane_state *plane_state = + drm_atomic_get_plane_state(state, plane); + struct sun4i_layer_state *layer_state = + state_to_sun4i_layer_state(plane_state); + + if (sun4i_backend_plane_uses_frontend(plane_state)) { + DRM_DEBUG_DRIVER("Using the frontend for plane %d\n", + plane->index); + + layer_state->uses_frontend = true; + num_frontend_planes++; + } else { + layer_state->uses_frontend = false; + } + } + + if (num_frontend_planes > SUN4I_BACKEND_NUM_FRONTEND_LAYERS) { + DRM_DEBUG_DRIVER("Too many planes going through the frontend, rejecting\n"); + return -EINVAL; + } + + return 0; +} + static void sun4i_backend_vblank_quirk(struct sunxi_engine *engine) { struct sun4i_backend *backend = engine_to_sun4i_backend(engine); @@ -415,6 +479,7 @@ static struct sun4i_frontend *sun4i_backend_find_frontend(struct sun4i_drv *drv, } static const struct sunxi_engine_ops sun4i_backend_engine_ops = { + .atomic_check = sun4i_backend_atomic_check, .commit = sun4i_backend_commit, .layers_init = sun4i_layers_init, .apply_color_correction = sun4i_backend_apply_color_correction, diff --git a/drivers/gpu/drm/sun4i/sun4i_backend.h b/drivers/gpu/drm/sun4i/sun4i_backend.h index 350a2dbde31a..b5edf2d50a24 100644 --- a/drivers/gpu/drm/sun4i/sun4i_backend.h +++ b/drivers/gpu/drm/sun4i/sun4i_backend.h @@ -144,6 +144,8 @@ #define SUN4I_BACKEND_HWCCOLORTAB_OFF 0x4c00 #define SUN4I_BACKEND_PIPE_OFF(p) (0x5000 + (0x400 * (p))) +#define SUN4I_BACKEND_NUM_FRONTEND_LAYERS 1 + struct sun4i_backend { struct sunxi_engine engine; struct sun4i_frontend *frontend; -- git-series 0.9.1