From patchwork Tue Mar 21 01:18:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 665612 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A158C761A6 for ; Tue, 21 Mar 2023 01:20:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230249AbjCUBUC (ORCPT ); Mon, 20 Mar 2023 21:20:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231193AbjCUBT5 (ORCPT ); Mon, 20 Mar 2023 21:19:57 -0400 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB56D12062 for ; Mon, 20 Mar 2023 18:19:27 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id bi9so17190528lfb.12 for ; Mon, 20 Mar 2023 18:19:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1679361503; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kyKsHi3GCpQsQBL3ZUsB7GqCNqmr8gVxqyeAbsz/AVg=; b=LAcWfLlNbVJI/jBqzT3qpnzVjMdHfGZMWvIDRAV3VjocoMGwSCV+Kj8wp1DT7u9ZTH Lhj3GjvF6smFm6cIf4URzb8H7cRSDLccWI1ZpQxHDkGaIuGAnhoMg29MyELACue2BwmC 9pTkm9U64nW18OHr51H2P3Iq7VO/bLgQLdOz1MVTWrKto78XkjhnmyfKC71I+cPCKzXA PqpzZ8rV8H8wsqV9ni22c+Xsy+kNyp5fgvdTK3TnVmabZid1lHYkdKhaP/loLTpSjLgr 5g8WeEyfZ7vQvto219sIFz0DCPKO6oWGcYeaUuGFNNyqNmBptYV/XxIiPCaQkT5vZgl3 JDvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679361503; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kyKsHi3GCpQsQBL3ZUsB7GqCNqmr8gVxqyeAbsz/AVg=; b=ZUEEk6Rkxrns9ihsX3e03p3dYTnx0Z/2oNRBaaUXXROsk2kkzx/aRgr6Xm+ibrc3Xz Ottd3NG1tWsmYuxoD3a/eWpAOTY8SStRqRhR0QgdezxQhZAdR3pIaeu5CbaGtBSL2uEE ktPgKlwsuFuA+qgoXzmOmECpVNA1GO3fVYMv5nUexlkUO3JlyTCeV9SBbNLQnGWb6bHC KNe88xLkadWy35xG7vNO92ctk2msZN5fTIYQD8FOApxNZ4P0rI3+5HURcA3m2PZ7Nbir VNXXjoNdVJrB4PH/IxLH36/9A9VMDzhiCeqYuMtwxmjeotdvChrKeYFN4ZApknsMX3Jv jjwA== X-Gm-Message-State: AO0yUKUlzBMm0x5mxhK9jDi25WwPNezisBbbIqvxWQzwSkMw8gq9DpuN kdsX8X1SZKttxhxp2a8N7vxcF7BTCRh+5yNSd+Xf+PfM X-Google-Smtp-Source: AK7set8RWsq4Zrhl6918J+yefTewlO3hLlJHbTFge15wK46WfuTBOw3fO0GhCrbwotXebulBLCcsDA== X-Received: by 2002:ac2:495e:0:b0:4a4:7be4:9baf with SMTP id o30-20020ac2495e000000b004a47be49bafmr262536lfi.59.1679361503228; Mon, 20 Mar 2023 18:18:23 -0700 (PDT) Received: from umbar.unikie.fi ([192.130.178.91]) by smtp.gmail.com with ESMTPSA id c18-20020ac25312000000b004eaec70c68esm46863lfh.294.2023.03.20.18.18.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Mar 2023 18:18:22 -0700 (PDT) From: Dmitry Baryshkov To: Rob Clark , Sean Paul , Abhinav Kumar Cc: Stephen Boyd , David Airlie , Daniel Vetter , Bjorn Andersson , linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org Subject: [RFC PATCH v2 01/13] drm/atomic-helper: split not-scaling part of drm_atomic_helper_check_plane_state Date: Tue, 21 Mar 2023 04:18:09 +0300 Message-Id: <20230321011821.635977-2-dmitry.baryshkov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230321011821.635977-1-dmitry.baryshkov@linaro.org> References: <20230321011821.635977-1-dmitry.baryshkov@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The helper drm_atomic_helper_check_plane_state() runs several checks on plane src and dst rectangles, including the check whether required scaling fits into the required margins. The msm driver would benefit from having a function that does all these checks except the scaling one. Split them into a new helper called drm_atomic_helper_check_plane_noscale(). Signed-off-by: Dmitry Baryshkov --- drivers/gpu/drm/drm_atomic_helper.c | 85 ++++++++++++++++++++++------- include/drm/drm_atomic_helper.h | 4 ++ 2 files changed, 68 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c index d579fd8f7cb8..86c5e19c7bdb 100644 --- a/drivers/gpu/drm/drm_atomic_helper.c +++ b/drivers/gpu/drm/drm_atomic_helper.c @@ -825,11 +825,9 @@ drm_atomic_helper_check_wb_encoder_state(struct drm_encoder *encoder, EXPORT_SYMBOL(drm_atomic_helper_check_wb_encoder_state); /** - * drm_atomic_helper_check_plane_state() - Check plane state for validity + * drm_atomic_helper_check_plane_noscale() - Check plane state for validity * @plane_state: plane state to check * @crtc_state: CRTC state to check - * @min_scale: minimum @src:@dest scaling factor in 16.16 fixed point - * @max_scale: maximum @src:@dest scaling factor in 16.16 fixed point * @can_position: is it legal to position the plane such that it * doesn't cover the entire CRTC? This will generally * only be false for primary planes. @@ -845,19 +843,16 @@ EXPORT_SYMBOL(drm_atomic_helper_check_wb_encoder_state); * RETURNS: * Zero if update appears valid, error code on failure */ -int drm_atomic_helper_check_plane_state(struct drm_plane_state *plane_state, - const struct drm_crtc_state *crtc_state, - int min_scale, - int max_scale, - bool can_position, - bool can_update_disabled) +int drm_atomic_helper_check_plane_noscale(struct drm_plane_state *plane_state, + const struct drm_crtc_state *crtc_state, + bool can_position, + bool can_update_disabled) { struct drm_framebuffer *fb = plane_state->fb; struct drm_rect *src = &plane_state->src; struct drm_rect *dst = &plane_state->dst; unsigned int rotation = plane_state->rotation; struct drm_rect clip = {}; - int hscale, vscale; WARN_ON(plane_state->crtc && plane_state->crtc != crtc_state->crtc); @@ -883,17 +878,6 @@ int drm_atomic_helper_check_plane_state(struct drm_plane_state *plane_state, drm_rect_rotate(src, fb->width << 16, fb->height << 16, rotation); - /* Check scaling */ - hscale = drm_rect_calc_hscale(src, dst, min_scale, max_scale); - vscale = drm_rect_calc_vscale(src, dst, min_scale, max_scale); - if (hscale < 0 || vscale < 0) { - drm_dbg_kms(plane_state->plane->dev, - "Invalid scaling of plane\n"); - drm_rect_debug_print("src: ", &plane_state->src, true); - drm_rect_debug_print("dst: ", &plane_state->dst, false); - return -ERANGE; - } - if (crtc_state->enable) drm_mode_get_hv_timing(&crtc_state->mode, &clip.x2, &clip.y2); @@ -921,6 +905,65 @@ int drm_atomic_helper_check_plane_state(struct drm_plane_state *plane_state, return 0; } +EXPORT_SYMBOL(drm_atomic_helper_check_plane_noscale); + +/** + * drm_atomic_helper_check_plane_state() - Check plane state for validity + * @plane_state: plane state to check + * @crtc_state: CRTC state to check + * @min_scale: minimum @src:@dest scaling factor in 16.16 fixed point + * @max_scale: maximum @src:@dest scaling factor in 16.16 fixed point + * @can_position: is it legal to position the plane such that it + * doesn't cover the entire CRTC? This will generally + * only be false for primary planes. + * @can_update_disabled: can the plane be updated while the CRTC + * is disabled? + * + * Checks that a desired plane update is valid, and updates various + * bits of derived state (clipped coordinates etc.). Drivers that provide + * their own plane handling rather than helper-provided implementations may + * still wish to call this function to avoid duplication of error checking + * code. + * + * RETURNS: + * Zero if update appears valid, error code on failure + */ +int drm_atomic_helper_check_plane_state(struct drm_plane_state *plane_state, + const struct drm_crtc_state *crtc_state, + int min_scale, + int max_scale, + bool can_position, + bool can_update_disabled) +{ + struct drm_framebuffer *fb = plane_state->fb; + struct drm_rect src; + struct drm_rect dst; + int hscale, vscale, ret; + + ret = drm_atomic_helper_check_plane_noscale(plane_state, crtc_state, can_position, can_update_disabled); + if (ret < 0) + return ret; + + if (!plane_state->visible) + return 0; + + src = drm_plane_state_src(plane_state); + dst = drm_plane_state_dest(plane_state); + + drm_rect_rotate(&src, fb->width << 16, fb->height << 16, plane_state->rotation); + + hscale = drm_rect_calc_hscale(&src, &dst, min_scale, max_scale); + vscale = drm_rect_calc_vscale(&src, &dst, min_scale, max_scale); + if (hscale < 0 || vscale < 0) { + drm_dbg_kms(plane_state->plane->dev, + "Invalid scaling of plane\n"); + drm_rect_debug_print("src: ", &plane_state->src, true); + drm_rect_debug_print("dst: ", &plane_state->dst, false); + return -ERANGE; + } + + return 0; +} EXPORT_SYMBOL(drm_atomic_helper_check_plane_state); /** diff --git a/include/drm/drm_atomic_helper.h b/include/drm/drm_atomic_helper.h index 33f982cd1a27..ebf95437431d 100644 --- a/include/drm/drm_atomic_helper.h +++ b/include/drm/drm_atomic_helper.h @@ -52,6 +52,10 @@ int drm_atomic_helper_check_modeset(struct drm_device *dev, int drm_atomic_helper_check_wb_encoder_state(struct drm_encoder *encoder, struct drm_connector_state *conn_state); +int drm_atomic_helper_check_plane_noscale(struct drm_plane_state *plane_state, + const struct drm_crtc_state *crtc_state, + bool can_position, + bool can_update_disabled); int drm_atomic_helper_check_plane_state(struct drm_plane_state *plane_state, const struct drm_crtc_state *crtc_state, int min_scale,