From patchwork Thu Sep 23 07:06:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 12512059 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9BEAAC433F5 for ; Thu, 23 Sep 2021 07:07:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 787A160F56 for ; Thu, 23 Sep 2021 07:07:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239562AbhIWHIk (ORCPT ); Thu, 23 Sep 2021 03:08:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239459AbhIWHIh (ORCPT ); Thu, 23 Sep 2021 03:08:37 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2400DC061757 for ; Thu, 23 Sep 2021 00:07:06 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id d21so14060717wra.12 for ; Thu, 23 Sep 2021 00:07:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8HkXcUapewu82KBB1gXmaAcbZqEIMBeeJjKrQlA3wl8=; b=kdbZRyS3uBfVzfoCyU4cth1ygtEi1nK6wFlIhDFb5LpuDQp8RQYPv5aR2h1n89Zs+V K8e9nlWAIMA73sVf2K+fBE3Zc/fkDVM7iGOtaSc+YpPpoPt+LjK0J8pylkzzCrk0EfLp DOfk3KTGgR9NBLRk+RgcPVGzr6twBsfwO7SsWzURty+b/0ddBf205zZEv2BTIEdY+xfa tcNPy8W+3Z/zxhGtksskOpnC54sjaKcLis71o19Rsg4XbyGVbAbQhIcaX0pLG55gp0DF O+fKvEn8uPkaF5WcMuM3ZbuhHqxqP2y5wOtBxXaGWZK45BeObtB9wt4nYHGN5C6qLLFW BROg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8HkXcUapewu82KBB1gXmaAcbZqEIMBeeJjKrQlA3wl8=; b=RJQZT1fNjvkvtJHVjr/CzHZPRorf3ypwfArru4oZdTZsBmA79DA3wz8yQnum1a0YIw 2tBqDQzig9sMq2K/eydBSkmfHDlIMJdyddAWSAbDhvLHZx6LBSK487+L6uHG5Br2pJYK KwVrrtFVlf1+lpum+GlxhmMvhP80RBcLoiYEadJrkouQlM6vUx/zzaif8CucCskHFZ+S lkhkqwvLETA8C38fxYrZIQeByq9MabnC2UmMoA0HDc5eF9Z0Q14FAOaJ/BI+9/pjesib XbNTYX1cHsfqdBT6Oy/AgsDzMynPJCE5fjMXEHANOXPQ1urNvShIlsMWn+KbmDH2F4/2 cOUA== X-Gm-Message-State: AOAM533NtizDGKuLXKuWo9dmzDpJDUW0rexzjOU6LCcIpQDnpWs7j+93 9RBjza9rXBNmacJxkTPkZmdn7w== X-Google-Smtp-Source: ABdhPJw2AkDQx97XcJhdGhSspbvOqkhiH5cnECScWJgTWxZIoZUxnZjPYfrI+xdUudK41PyL14O7ng== X-Received: by 2002:a05:6000:14a:: with SMTP id r10mr3225950wrx.380.1632380824566; Thu, 23 Sep 2021 00:07:04 -0700 (PDT) Received: from localhost.localdomain ([2001:861:44c0:66c0:74cf:b054:76f4:7692]) by smtp.gmail.com with ESMTPSA id d2sm4380357wrc.32.2021.09.23.00.07.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Sep 2021 00:07:04 -0700 (PDT) From: Neil Armstrong To: tomba@kernel.org Cc: linux-omap@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, khilman@baylibre.com, Benoit Parrot , Neil Armstrong Subject: [PATCH v5 1/8] drm/omap: Add ability to check if requested plane modes can be supported Date: Thu, 23 Sep 2021 09:06:54 +0200 Message-Id: <20210923070701.145377-2-narmstrong@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210923070701.145377-1-narmstrong@baylibre.com> References: <20210923070701.145377-1-narmstrong@baylibre.com> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5866; i=narmstrong@baylibre.com; h=from:subject; bh=P5+E5cFrNeFYH1fKkbVYhvBhPZrKTj5Rlw+bm+rz1Hk=; b=owEBbQKS/ZANAwAKAXfc29rIyEnRAcsmYgBhTCcgIZ9bICJ8Fn3kbLi5bRfas5gz4n1h8o9VdO+4 Yv8BApWJAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCYUwnIAAKCRB33NvayMhJ0fHsD/ wKcQpzCcBjMDqOlCnea+RrmlpG5ZHlz2QLv/xFx2/GMsHRg8/svhN3Um1AHCUk1mj7fElJ54caGLgL IaFf5u1++aaqZsVlaJwaYcgjTkv3zOez3jDcdFBEjsW90sWooTqbdEouYMWxt9Plbv8BvxMTUEXhSH pWmGh128yRgDwUOZfGRb3uSaH/LBHQegY2GmLR/FtuZpOX+PRU6IH1giiVVZ6XCbj/2nVwfaiJAVg3 Uno/qnaDLypTmMC3rKzC8TZtd3HbMQqBnjYtXBTQuOg2104ggChCxzwzIp3v19+649kDvJ3aQ5kW0I mmq84uqgYPEeHvZNysqXfCUhFrYkobjZIEKTivR4Kg/G1sRkM7O48pgjGu7lVCtewBXzyLtFPUJuLg d9u0tGU86uaOM5UwS/LuL4OFQO+t+IZttbYM/LoB3oIBMScD6yiTL66rVELFsExaFrFrw2FC7RCB7o XqGOP/ezu2J5JrObdOEzRVrGNppEj06rKcdL+njyeYStIEK6oyrnnnQWw9OcctJetKroWIFpt/pkwr Y6g3QW3pXzxCIIjSWn2hd2xdfb4T8uCoDxbLNFCUkj3GjZL1I2gD+DfuiR4O3L06BacPWtd3v6CXtL DolA3IL9ycpEi6Wm96jshCWBYwAdk2UqFbBo+0tjizTlitq6AamS2Jb9MpWw== X-Developer-Key: i=narmstrong@baylibre.com; a=openpgp; fpr=89EC3D058446217450F22848169AB7B1A4CFF8AE Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org From: Benoit Parrot We currently assume that an overlay has the same maximum width and maximum height as the overlay manager. This assumption is incorrect. On some variants the overlay manager maximum width is twice the maximum width that the overlay can handle. We need to add the appropriate data per variant as well as export a helper function to retrieve the data so check can be made dynamically in omap_plane_atomic_check(). Signed-off-by: Benoit Parrot Signed-off-by: Neil Armstrong --- drivers/gpu/drm/omapdrm/dss/dispc.c | 22 ++++++++++++++++++++++ drivers/gpu/drm/omapdrm/dss/dss.h | 2 ++ drivers/gpu/drm/omapdrm/omap_plane.c | 14 ++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/drivers/gpu/drm/omapdrm/dss/dispc.c b/drivers/gpu/drm/omapdrm/dss/dispc.c index 3c4a4991e45a..bdecec8f4d88 100644 --- a/drivers/gpu/drm/omapdrm/dss/dispc.c +++ b/drivers/gpu/drm/omapdrm/dss/dispc.c @@ -92,6 +92,8 @@ struct dispc_features { u8 mgr_height_start; u16 mgr_width_max; u16 mgr_height_max; + u16 ovl_width_max; + u16 ovl_height_max; unsigned long max_lcd_pclk; unsigned long max_tv_pclk; unsigned int max_downscale; @@ -2599,6 +2601,12 @@ static int dispc_ovl_calc_scaling(struct dispc_device *dispc, return 0; } +void dispc_ovl_get_max_size(struct dispc_device *dispc, u16 *width, u16 *height) +{ + *width = dispc->feat->ovl_width_max; + *height = dispc->feat->ovl_height_max; +} + static int dispc_ovl_setup_common(struct dispc_device *dispc, enum omap_plane_id plane, enum omap_overlay_caps caps, @@ -4240,6 +4248,8 @@ static const struct dispc_features omap24xx_dispc_feats = { .mgr_height_start = 26, .mgr_width_max = 2048, .mgr_height_max = 2048, + .ovl_width_max = 2048, + .ovl_height_max = 2048, .max_lcd_pclk = 66500000, .max_downscale = 2, /* @@ -4278,6 +4288,8 @@ static const struct dispc_features omap34xx_rev1_0_dispc_feats = { .mgr_height_start = 26, .mgr_width_max = 2048, .mgr_height_max = 2048, + .ovl_width_max = 2048, + .ovl_height_max = 2048, .max_lcd_pclk = 173000000, .max_tv_pclk = 59000000, .max_downscale = 4, @@ -4313,6 +4325,8 @@ static const struct dispc_features omap34xx_rev3_0_dispc_feats = { .mgr_height_start = 26, .mgr_width_max = 2048, .mgr_height_max = 2048, + .ovl_width_max = 2048, + .ovl_height_max = 2048, .max_lcd_pclk = 173000000, .max_tv_pclk = 59000000, .max_downscale = 4, @@ -4348,6 +4362,8 @@ static const struct dispc_features omap36xx_dispc_feats = { .mgr_height_start = 26, .mgr_width_max = 2048, .mgr_height_max = 2048, + .ovl_width_max = 2048, + .ovl_height_max = 2048, .max_lcd_pclk = 173000000, .max_tv_pclk = 59000000, .max_downscale = 4, @@ -4383,6 +4399,8 @@ static const struct dispc_features am43xx_dispc_feats = { .mgr_height_start = 26, .mgr_width_max = 2048, .mgr_height_max = 2048, + .ovl_width_max = 2048, + .ovl_height_max = 2048, .max_lcd_pclk = 173000000, .max_tv_pclk = 59000000, .max_downscale = 4, @@ -4418,6 +4436,8 @@ static const struct dispc_features omap44xx_dispc_feats = { .mgr_height_start = 26, .mgr_width_max = 2048, .mgr_height_max = 2048, + .ovl_width_max = 2048, + .ovl_height_max = 2048, .max_lcd_pclk = 170000000, .max_tv_pclk = 185625000, .max_downscale = 4, @@ -4457,6 +4477,8 @@ static const struct dispc_features omap54xx_dispc_feats = { .mgr_height_start = 27, .mgr_width_max = 4096, .mgr_height_max = 4096, + .ovl_width_max = 2048, + .ovl_height_max = 4096, .max_lcd_pclk = 170000000, .max_tv_pclk = 192000000, .max_downscale = 4, diff --git a/drivers/gpu/drm/omapdrm/dss/dss.h b/drivers/gpu/drm/omapdrm/dss/dss.h index a547527bb2f3..14c39f7c3988 100644 --- a/drivers/gpu/drm/omapdrm/dss/dss.h +++ b/drivers/gpu/drm/omapdrm/dss/dss.h @@ -397,6 +397,8 @@ int dispc_get_num_mgrs(struct dispc_device *dispc); const u32 *dispc_ovl_get_color_modes(struct dispc_device *dispc, enum omap_plane_id plane); +void dispc_ovl_get_max_size(struct dispc_device *dispc, u16 *width, u16 *height); + u32 dispc_read_irqstatus(struct dispc_device *dispc); void dispc_clear_irqstatus(struct dispc_device *dispc, u32 mask); void dispc_write_irqenable(struct dispc_device *dispc, u32 mask); diff --git a/drivers/gpu/drm/omapdrm/omap_plane.c b/drivers/gpu/drm/omapdrm/omap_plane.c index 512af976b7e9..d0a67b7ed1a0 100644 --- a/drivers/gpu/drm/omapdrm/omap_plane.c +++ b/drivers/gpu/drm/omapdrm/omap_plane.c @@ -109,11 +109,18 @@ static int omap_plane_atomic_check(struct drm_plane *plane, { struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state, plane); + struct omap_drm_private *priv = plane->dev->dev_private; struct drm_crtc_state *crtc_state; + u16 width, height; + u32 width_fp, height_fp; if (!new_plane_state->fb) return 0; + dispc_ovl_get_max_size(priv->dispc, &width, &height); + width_fp = width << 16; + height_fp = height << 16; + /* crtc should only be NULL when disabling (i.e., !new_plane_state->fb) */ if (WARN_ON(!new_plane_state->crtc)) return 0; @@ -136,6 +143,13 @@ static int omap_plane_atomic_check(struct drm_plane *plane, if (new_plane_state->crtc_y + new_plane_state->crtc_h > crtc_state->adjusted_mode.vdisplay) return -EINVAL; + /* Make sure dimensions are within bounds. */ + if (new_plane_state->src_h > height_fp || new_plane_state->crtc_h > height) + return -EINVAL; + + if (new_plane_state->src_w > width_fp || new_plane_state->crtc_w > width) + return -EINVAL; + if (new_plane_state->rotation != DRM_MODE_ROTATE_0 && !omap_framebuffer_supports_rotation(new_plane_state->fb)) return -EINVAL; From patchwork Thu Sep 23 07:06:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 12512061 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 278F1C4332F for ; Thu, 23 Sep 2021 07:07:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0AD6661214 for ; Thu, 23 Sep 2021 07:07:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239544AbhIWHIk (ORCPT ); Thu, 23 Sep 2021 03:08:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239538AbhIWHIi (ORCPT ); Thu, 23 Sep 2021 03:08:38 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED2C1C061762 for ; Thu, 23 Sep 2021 00:07:06 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id g16so14223502wrb.3 for ; Thu, 23 Sep 2021 00:07:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/81sSyyxvMo1ibeq3AtPzZF+vUWnLboV86d+Wu7gvLo=; b=XGz7zHiTqUzR1wmtOzMHkib8qZf+yqVPgG2Kxb9agUMdSa74B5PAzvnGhksC0J61l+ gbeiTnIEg4T+LXsyNjyb8+oXknkm2d/Q8jBLRCOFQVRVy/EEhuldm9M2V7ID34rXkSBD lMm8YTqbFBV8J4U13o4EGthVqG4ZlgyCK8F68hvY5xwUJqRc8z1Qysp7LJoRKtayA+lw wAAYh256XFoyaSzuZDSBY0d7s41VjvDgFX5ZlbvxaPKtNYr4DUbnw36ZwuP5Oz5PwvcD c7JUf8XtPzX7fmi4lhNTgjLjWZf17Tg4jXSKFgJkA0NbE/Ikl35HtkaWUTbZGy3ECct4 SsBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/81sSyyxvMo1ibeq3AtPzZF+vUWnLboV86d+Wu7gvLo=; b=nQ3csqEwNDrYqBT9LNXhJbInpzqX77IcmMQG2euX9rVIAihdS9o+exY02+9yzRzAyz Gu9sBxkFnD0viyWvgw3DQ3bA/0pBQ+lL1RttT9HD2UAsSUa/Sk15W4bKu600WAmgfrv/ CGi0BB4lliYW0trbRfW+D7sQ85xYKCceXb0TujWYGhDUuuHIqcKCjYQrK/0Vs88j0pIr IAUlhZpyT9e6+U/YRd3y8O6zfGHxt2/hxmS1Lvv+WemuQrjBrDHKBfVmPdbejFJWT31t twRtwSTSCginYhHpBGP1VzniruyqkP5Cd19CvGbjyzfintiDeWjBESaEnjjbNksP44k8 yybA== X-Gm-Message-State: AOAM533vl0EUpH5qSt6otq+GMDFvCC9SjkdImy4e+44hLCwY1zTkHiOT Qd55POx0RYV43zcz6ng/mqlk+w== X-Google-Smtp-Source: ABdhPJzvK6+kkW7WQP3/h9qj7aFOHACeP1+5CPokeFbIVV+WS6TnnNKWAZewOmf9t7VSKZ47PK3nZg== X-Received: by 2002:adf:edc7:: with SMTP id v7mr3218835wro.63.1632380825408; Thu, 23 Sep 2021 00:07:05 -0700 (PDT) Received: from localhost.localdomain ([2001:861:44c0:66c0:74cf:b054:76f4:7692]) by smtp.gmail.com with ESMTPSA id d2sm4380357wrc.32.2021.09.23.00.07.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Sep 2021 00:07:04 -0700 (PDT) From: Neil Armstrong To: tomba@kernel.org Cc: linux-omap@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, khilman@baylibre.com, Benoit Parrot , Neil Armstrong Subject: [PATCH v5 2/8] drm/omap: Add ovl checking funcs to dispc_ops Date: Thu, 23 Sep 2021 09:06:55 +0200 Message-Id: <20210923070701.145377-3-narmstrong@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210923070701.145377-1-narmstrong@baylibre.com> References: <20210923070701.145377-1-narmstrong@baylibre.com> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2331; i=narmstrong@baylibre.com; h=from:subject; bh=Wlxh4ChQtQ3J8QTuldvFif6dgGSQt01TuE/tUnTUmZU=; b=owEBbQKS/ZANAwAKAXfc29rIyEnRAcsmYgBhTCchLvhFU34Ve0/Nb7xWC7pqWPlUGUB7Oe3pfZy0 i0xGPk+JAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCYUwnIQAKCRB33NvayMhJ0Y1yEA ClKhNhzDjL7ymUKnrKgJNt0URG2tcFseQ2cMa/nQz3M185rpH7m2YpireAuB2fEh63xJgSNC6uMD71 5JFxzRR9Ln8mOzVI2HibMsVtdqlHcKNmyfVsHqQEe7APDXKOEyzVPkCk52PcUM1gWTvjhApniBuOzq WETV6RA8HJpPmea9S4H2A7s1ANetH6mjKmtdFhjJejk/KbHT9BDYmL31lrUkscJPmFqQG1In0h2J6r CcuMVqPIFrw5VM2Y6Xj18DEZBbu9RSXYe2UDDmswX+FFPemDEQhYlL4qGy+NHJ2esGlkyWjKUMnUVg gRZrAh+s92M+j9XblWS5Yz12QnuUMzSqIT80Yzk+Jhn8ztJXJQnL2csjpKEcAMBh0brzA8zJxU1XFh cqZKoFZgla6vmUCHzgu32HnCgJVkjbeh+glS0InDwdV1i1weAm0RbOdzA4avP8GWl5flcnKt9k2YlI 84RhCeMBzZsUZ/sblrwNTGAsWYMiqwKdl3GCR684p+yuXPtHYXn+k6laRh5r7i+OIxRwAYJUZSmjYx ZAkgfh0J909RbB4FJqQryJP7CO7OfIZY84Wu5yKGqr8vBJpsMjLBmVSsycq6BfTP/wcEUQyj5exTin kITumX6LNqgV//czhZU1/j5VKlc5RsThZ28nL3THaV+sRfF/eGD13m/8vZ6g== X-Developer-Key: i=narmstrong@baylibre.com; a=openpgp; fpr=89EC3D058446217450F22848169AB7B1A4CFF8AE Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org From: Benoit Parrot In order to be able to dynamically assign overlays to planes we need to be able to asses the overlay capabilities. Add a helper function to be able to retrieve the supported capabilities of an overlay. And export the function to check if a fourcc is supported on a given overlay. Signed-off-by: Benoit Parrot Signed-off-by: Neil Armstrong --- drivers/gpu/drm/omapdrm/dss/dispc.c | 9 +++++++-- drivers/gpu/drm/omapdrm/dss/dss.h | 3 +++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/omapdrm/dss/dispc.c b/drivers/gpu/drm/omapdrm/dss/dispc.c index bdecec8f4d88..df945e4b1fd3 100644 --- a/drivers/gpu/drm/omapdrm/dss/dispc.c +++ b/drivers/gpu/drm/omapdrm/dss/dispc.c @@ -1281,8 +1281,8 @@ static u32 dispc_ovl_get_burst_size(struct dispc_device *dispc, return dispc->feat->burst_size_unit * 8; } -static bool dispc_ovl_color_mode_supported(struct dispc_device *dispc, - enum omap_plane_id plane, u32 fourcc) +bool dispc_ovl_color_mode_supported(struct dispc_device *dispc, + enum omap_plane_id plane, u32 fourcc) { const u32 *modes; unsigned int i; @@ -2489,6 +2489,11 @@ static int dispc_ovl_calc_scaling_44xx(struct dispc_device *dispc, return 0; } +enum omap_overlay_caps dispc_ovl_get_caps(struct dispc_device *dispc, enum omap_plane_id plane) +{ + return dispc->feat->overlay_caps[plane]; +} + #define DIV_FRAC(dividend, divisor) \ ((dividend) * 100 / (divisor) - ((dividend) / (divisor) * 100)) diff --git a/drivers/gpu/drm/omapdrm/dss/dss.h b/drivers/gpu/drm/omapdrm/dss/dss.h index 14c39f7c3988..4ff02fbc0e71 100644 --- a/drivers/gpu/drm/omapdrm/dss/dss.h +++ b/drivers/gpu/drm/omapdrm/dss/dss.h @@ -398,6 +398,9 @@ const u32 *dispc_ovl_get_color_modes(struct dispc_device *dispc, enum omap_plane_id plane); void dispc_ovl_get_max_size(struct dispc_device *dispc, u16 *width, u16 *height); +bool dispc_ovl_color_mode_supported(struct dispc_device *dispc, + enum omap_plane_id plane, u32 fourcc); +enum omap_overlay_caps dispc_ovl_get_caps(struct dispc_device *dispc, enum omap_plane_id plane); u32 dispc_read_irqstatus(struct dispc_device *dispc); void dispc_clear_irqstatus(struct dispc_device *dispc, u32 mask); From patchwork Thu Sep 23 07:06:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 12512065 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6B01C43217 for ; Thu, 23 Sep 2021 07:07:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BC1D961261 for ; Thu, 23 Sep 2021 07:07:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239569AbhIWHIl (ORCPT ); Thu, 23 Sep 2021 03:08:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239550AbhIWHIj (ORCPT ); Thu, 23 Sep 2021 03:08:39 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDF36C061764 for ; Thu, 23 Sep 2021 00:07:07 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id g16so14223584wrb.3 for ; Thu, 23 Sep 2021 00:07:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Wl17Sf97iY4+CSQLIuQXO5q/f+FclNaJ+Vy/LLxmins=; b=wadVxuPECaq6jBXx+vE0dAlmtjq1K60UUU8UhDYaCZaHgp0OWgpQMOby+IVKehWhqL eJ0O5eHemyoNQ95y9RNhE3NqzFwxJt/jWpyk5Q9djCPV9ZZFj6jloHuixhs+CTvZ1hx4 Dluu7ru+cCV1hPjkJhanveEw5S/mSqeBEQqdbRb2ewoRM/KW/cUvsp5PxngGMAN7lg8D utMqD2TOFguFdpxs9+hrR2DPbYpppAq4PhlHGA1PNxYAPCnfGsz32s41qFvYFZp0H7m2 GDcY2xUC7Y7kCwDuCU6HmtuZHjAW9gbsUBwO8xCYdVSsAVT8svO0N5HrUFaVm50H8tPg RdWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Wl17Sf97iY4+CSQLIuQXO5q/f+FclNaJ+Vy/LLxmins=; b=f3TGdnc9ckPocZ/ddG73L6lPH1eiFUXsqyUGqfwmmFep/93ZIqW4Io8w80SgyvGZ0p pHczJZGvhIc7ZLOCv/iMJrGb/8+RudZmCOA8FLb82v0MipcWrkNGYJdoK4YJ/HWuaIE4 0dXJJmPUMjq4vZVMhtUjOFhnMhTPsF40jQb1niV0KWH78usBsuQbNr6zQbhULoCx2+Xu 8qVBouyi7bZlEq9rnRiFyDYCgw03+AwD6Ak53h5uBzjCf5o8cYIMiRWs2l7bMxySE5XQ VI1uTlDu9Js8wNDkF1HDIXHZ5RqOR23+qZX4cqmciIR3RINQFsXXE693G+sT+qR6yg93 9n7Q== X-Gm-Message-State: AOAM5315k6+VwO7MmbCp9ZNF41xaSmJLV3ibmZ3DSnFCMfv0N4CxAN0D c/R31eUTDAcAW+vdEByV5nNsSQ== X-Google-Smtp-Source: ABdhPJxlI3k77jX0qdlzsxLuFwk8s3QEwsT66ZecdMTqZMnzud3Vhe7JYcVrPxsky/1ouVvDy9PhXw== X-Received: by 2002:adf:ecc9:: with SMTP id s9mr3359188wro.2.1632380826327; Thu, 23 Sep 2021 00:07:06 -0700 (PDT) Received: from localhost.localdomain ([2001:861:44c0:66c0:74cf:b054:76f4:7692]) by smtp.gmail.com with ESMTPSA id d2sm4380357wrc.32.2021.09.23.00.07.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Sep 2021 00:07:05 -0700 (PDT) From: Neil Armstrong To: tomba@kernel.org Cc: linux-omap@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, khilman@baylibre.com, Benoit Parrot , Neil Armstrong Subject: [PATCH v5 3/8] drm/omap: introduce omap_hw_overlay Date: Thu, 23 Sep 2021 09:06:56 +0200 Message-Id: <20210923070701.145377-4-narmstrong@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210923070701.145377-1-narmstrong@baylibre.com> References: <20210923070701.145377-1-narmstrong@baylibre.com> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=11056; i=narmstrong@baylibre.com; h=from:subject; bh=PNSPGHwtK+8fALF03jz6BERDIiy/R3kVBjpu2V6TpVI=; b=owEBbQKS/ZANAwAKAXfc29rIyEnRAcsmYgBhTCchwo1qrutd22RgDCRkGmpEVtqHb96qLhns2I+7 M3TmmnmJAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCYUwnIQAKCRB33NvayMhJ0QQQEA CA/CcJ4NmZvtmXYpvTCYmRsM7FJVX391yp01vJTwnQgnxCP+mpcFeLXqxLPrV1E2yeNAZBvxZ050+o 7QaLkZklHGqY1gmxDewdX6roJFK7CQM2ierO0LnbmrK/jIz6R5zbO7h/GkjQ5SyQ1LiIBbsoKFnJZE u7B4ea22cN9SuKTRo8ERDRT2QI5K6Bq7pIdyaRsngbj2EOOaVy2jCsO4BsOcvi7KFqcr3A1o3c23z5 kmHZP8PRfMT6/WNMs/GrmoIn+ihrQkYJBHEgkEXYU3Zo4gji4HrCD+1o0+9V7cChcqCRGQZRsiWXce Tb/rv5vzh7eClozu7+qxfbTQAtfrLhzD5IUQ0kgM2bvgB+q172cI2L0stwzkuEOxLL4f8wD7rt0564 M5O5YHK4iRedxV1M21o0dU1CxhUrrjJRM38SQvRVoZ2huvjw6A0n9uUPkYt28LLSi5agYUMHRal+iV zyhErLA1qhi/OSyLHEFoiIJI/5lTJZyZPyHWBKgeY189aHRJeFmEqeOI9erWVRro+QaZwgN2LUlKuW DadcLbivBKMHC/NEM6vm/dwsQJUIOPpwmA3nv5nLm0kulnJ2ZPC6SJCh8L3iWZuPCkad8s9MNXnPpX sP8f5fjoOyWnOq6Qbu/ieBCShKk9K1h8n3VM2gwQ34cSDlTk8KrWK6tlFChw== X-Developer-Key: i=narmstrong@baylibre.com; a=openpgp; fpr=89EC3D058446217450F22848169AB7B1A4CFF8AE Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org From: Benoit Parrot Split out the hardware overlay specifics from omap_plane. To start, the hw overlays are statically assigned to planes. The goal is to eventually assign hw overlays dynamically to planes during plane->atomic_check() based on requested caps (scaling, YUV, etc). And then perform hw overlay re-assignment if required. Signed-off-by: Benoit Parrot Signed-off-by: Neil Armstrong --- drivers/gpu/drm/omapdrm/Makefile | 1 + drivers/gpu/drm/omapdrm/omap_drv.c | 9 ++- drivers/gpu/drm/omapdrm/omap_drv.h | 4 ++ drivers/gpu/drm/omapdrm/omap_overlay.c | 87 ++++++++++++++++++++++++++ drivers/gpu/drm/omapdrm/omap_overlay.h | 31 +++++++++ drivers/gpu/drm/omapdrm/omap_plane.c | 42 ++++++------- 6 files changed, 151 insertions(+), 23 deletions(-) create mode 100644 drivers/gpu/drm/omapdrm/omap_overlay.c create mode 100644 drivers/gpu/drm/omapdrm/omap_overlay.h diff --git a/drivers/gpu/drm/omapdrm/Makefile b/drivers/gpu/drm/omapdrm/Makefile index 21e8277ff88f..710b4e0abcf0 100644 --- a/drivers/gpu/drm/omapdrm/Makefile +++ b/drivers/gpu/drm/omapdrm/Makefile @@ -9,6 +9,7 @@ omapdrm-y := omap_drv.o \ omap_debugfs.o \ omap_crtc.o \ omap_plane.o \ + omap_overlay.o \ omap_encoder.o \ omap_fb.o \ omap_gem.o \ diff --git a/drivers/gpu/drm/omapdrm/omap_drv.c b/drivers/gpu/drm/omapdrm/omap_drv.c index f86e20578143..b994014b22e8 100644 --- a/drivers/gpu/drm/omapdrm/omap_drv.c +++ b/drivers/gpu/drm/omapdrm/omap_drv.c @@ -583,10 +583,14 @@ static int omapdrm_init(struct omap_drm_private *priv, struct device *dev) omap_gem_init(ddev); + ret = omap_hwoverlays_init(priv); + if (ret) + goto err_gem_deinit; + ret = omap_modeset_init(ddev); if (ret) { dev_err(priv->dev, "omap_modeset_init failed: ret=%d\n", ret); - goto err_gem_deinit; + goto err_free_overlays; } /* Initialize vblank handling, start with all CRTCs disabled. */ @@ -618,6 +622,8 @@ static int omapdrm_init(struct omap_drm_private *priv, struct device *dev) omap_fbdev_fini(ddev); err_cleanup_modeset: omap_modeset_fini(ddev); +err_free_overlays: + omap_hwoverlays_destroy(priv); err_gem_deinit: omap_gem_deinit(ddev); destroy_workqueue(priv->wq); @@ -642,6 +648,7 @@ static void omapdrm_cleanup(struct omap_drm_private *priv) drm_atomic_helper_shutdown(ddev); omap_modeset_fini(ddev); + omap_hwoverlays_destroy(priv); omap_gem_deinit(ddev); destroy_workqueue(priv->wq); diff --git a/drivers/gpu/drm/omapdrm/omap_drv.h b/drivers/gpu/drm/omapdrm/omap_drv.h index 591d4c273f02..b4d9c2062723 100644 --- a/drivers/gpu/drm/omapdrm/omap_drv.h +++ b/drivers/gpu/drm/omapdrm/omap_drv.h @@ -24,6 +24,7 @@ #include "omap_gem.h" #include "omap_irq.h" #include "omap_plane.h" +#include "omap_overlay.h" #define DBG(fmt, ...) DRM_DEBUG_DRIVER(fmt"\n", ##__VA_ARGS__) #define VERB(fmt, ...) if (0) DRM_DEBUG_DRIVER(fmt, ##__VA_ARGS__) /* verbose debug */ @@ -57,6 +58,9 @@ struct omap_drm_private { unsigned int num_planes; struct drm_plane *planes[8]; + unsigned int num_ovls; + struct omap_hw_overlay *overlays[8]; + struct drm_fb_helper *fbdev; struct workqueue_struct *wq; diff --git a/drivers/gpu/drm/omapdrm/omap_overlay.c b/drivers/gpu/drm/omapdrm/omap_overlay.c new file mode 100644 index 000000000000..2b1416d2aad2 --- /dev/null +++ b/drivers/gpu/drm/omapdrm/omap_overlay.c @@ -0,0 +1,87 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/ + * Author: Benoit Parrot, + */ + +#include +#include +#include + +#include "omap_dmm_tiler.h" +#include "omap_drv.h" + +/* + * overlay funcs + */ +static const char * const overlay_id_to_name[] = { + [OMAP_DSS_GFX] = "gfx", + [OMAP_DSS_VIDEO1] = "vid1", + [OMAP_DSS_VIDEO2] = "vid2", + [OMAP_DSS_VIDEO3] = "vid3", +}; + +static void omap_overlay_destroy(struct omap_hw_overlay *overlay) +{ + kfree(overlay); +} + +static struct omap_hw_overlay *omap_overlay_init(enum omap_plane_id overlay_id, + enum omap_overlay_caps caps) +{ + struct omap_hw_overlay *overlay; + + overlay = kzalloc(sizeof(*overlay), GFP_KERNEL); + if (!overlay) + return ERR_PTR(-ENOMEM); + + overlay->name = overlay_id_to_name[overlay_id]; + overlay->overlay_id = overlay_id; + overlay->caps = caps; + /* + * When this is called priv->num_crtcs is not known yet. + * Use a safe mask value to start with, it will get updated to the + * proper value after the first use. + */ + overlay->possible_crtcs = 0xff; + + return overlay; +} + +int omap_hwoverlays_init(struct omap_drm_private *priv) +{ + static const enum omap_plane_id hw_plane_ids[] = { + OMAP_DSS_GFX, OMAP_DSS_VIDEO1, + OMAP_DSS_VIDEO2, OMAP_DSS_VIDEO3, + }; + u32 num_overlays = dispc_get_num_ovls(priv->dispc); + enum omap_overlay_caps caps; + int i, ret; + + for (i = 0; i < num_overlays; i++) { + struct omap_hw_overlay *overlay; + + caps = dispc_ovl_get_caps(priv->dispc, hw_plane_ids[i]); + overlay = omap_overlay_init(hw_plane_ids[i], caps); + if (IS_ERR(overlay)) { + ret = PTR_ERR(overlay); + dev_err(priv->dev, "failed to construct overlay for %s (%d)\n", + overlay_id_to_name[i], ret); + return ret; + } + overlay->idx = priv->num_ovls; + priv->overlays[priv->num_ovls++] = overlay; + } + + return 0; +} + +void omap_hwoverlays_destroy(struct omap_drm_private *priv) +{ + int i; + + for (i = 0; i < priv->num_ovls; i++) { + omap_overlay_destroy(priv->overlays[i]); + priv->overlays[i] = NULL; + } +} diff --git a/drivers/gpu/drm/omapdrm/omap_overlay.h b/drivers/gpu/drm/omapdrm/omap_overlay.h new file mode 100644 index 000000000000..892fecb67adb --- /dev/null +++ b/drivers/gpu/drm/omapdrm/omap_overlay.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/ + * Author: Benoit Parrot, + */ + +#ifndef __OMAPDRM_OVERLAY_H__ +#define __OMAPDRM_OVERLAY_H__ + +#include + +enum drm_plane_type; + +struct drm_device; +struct drm_mode_object; +struct drm_plane; + +/* Used to associate a HW overlay/plane to a plane */ +struct omap_hw_overlay { + int idx; + + const char *name; + enum omap_plane_id overlay_id; + + enum omap_overlay_caps caps; + u32 possible_crtcs; +}; + +int omap_hwoverlays_init(struct omap_drm_private *priv); +void omap_hwoverlays_destroy(struct omap_drm_private *priv); +#endif /* __OMAPDRM_OVERLAY_H__ */ diff --git a/drivers/gpu/drm/omapdrm/omap_plane.c b/drivers/gpu/drm/omapdrm/omap_plane.c index d0a67b7ed1a0..0df5381cc015 100644 --- a/drivers/gpu/drm/omapdrm/omap_plane.c +++ b/drivers/gpu/drm/omapdrm/omap_plane.c @@ -22,6 +22,8 @@ struct omap_plane { struct drm_plane base; enum omap_plane_id id; const char *name; + + struct omap_hw_overlay *overlay; }; static int omap_plane_prepare_fb(struct drm_plane *plane, @@ -49,6 +51,7 @@ static void omap_plane_atomic_update(struct drm_plane *plane, struct omap_plane *omap_plane = to_omap_plane(plane); struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state, plane); + enum omap_plane_id ovl_id = omap_plane->overlay->overlay_id; struct omap_overlay_info info; int ret; @@ -77,17 +80,17 @@ static void omap_plane_atomic_update(struct drm_plane *plane, &info.paddr, &info.p_uv_addr); /* and finally, update omapdss: */ - ret = dispc_ovl_setup(priv->dispc, omap_plane->id, &info, + ret = dispc_ovl_setup(priv->dispc, ovl_id, &info, omap_crtc_timings(new_state->crtc), false, omap_crtc_channel(new_state->crtc)); if (ret) { dev_err(plane->dev->dev, "Failed to setup plane %s\n", omap_plane->name); - dispc_ovl_enable(priv->dispc, omap_plane->id, false); + dispc_ovl_enable(priv->dispc, ovl_id, false); return; } - dispc_ovl_enable(priv->dispc, omap_plane->id, true); + dispc_ovl_enable(priv->dispc, ovl_id, true); } static void omap_plane_atomic_disable(struct drm_plane *plane, @@ -97,11 +100,12 @@ static void omap_plane_atomic_disable(struct drm_plane *plane, plane); struct omap_drm_private *priv = plane->dev->dev_private; struct omap_plane *omap_plane = to_omap_plane(plane); + enum omap_plane_id ovl_id = omap_plane->overlay->overlay_id; new_state->rotation = DRM_MODE_ROTATE_0; new_state->zpos = plane->type == DRM_PLANE_TYPE_PRIMARY ? 0 : omap_plane->id; - dispc_ovl_enable(priv->dispc, omap_plane->id, false); + dispc_ovl_enable(priv->dispc, ovl_id, false); } static int omap_plane_atomic_check(struct drm_plane *plane, @@ -213,7 +217,7 @@ static void omap_plane_reset(struct drm_plane *plane) * plane. */ plane->state->zpos = plane->type == DRM_PLANE_TYPE_PRIMARY - ? 0 : omap_plane->id; + ? 0 : omap_plane->overlay->overlay_id; plane->state->color_encoding = DRM_COLOR_YCBCR_BT601; plane->state->color_range = DRM_COLOR_YCBCR_FULL_RANGE; } @@ -282,13 +286,6 @@ static const char *plane_id_to_name[] = { [OMAP_DSS_VIDEO3] = "vid3", }; -static const enum omap_plane_id plane_idx_to_id[] = { - OMAP_DSS_GFX, - OMAP_DSS_VIDEO1, - OMAP_DSS_VIDEO2, - OMAP_DSS_VIDEO3, -}; - /* initialize plane */ struct drm_plane *omap_plane_init(struct drm_device *dev, int idx, enum drm_plane_type type, @@ -298,27 +295,28 @@ struct drm_plane *omap_plane_init(struct drm_device *dev, unsigned int num_planes = dispc_get_num_ovls(priv->dispc); struct drm_plane *plane; struct omap_plane *omap_plane; - enum omap_plane_id id; int ret; u32 nformats; const u32 *formats; - if (WARN_ON(idx >= ARRAY_SIZE(plane_idx_to_id))) + if (WARN_ON(idx >= num_planes)) return ERR_PTR(-EINVAL); - id = plane_idx_to_id[idx]; - - DBG("%s: type=%d", plane_id_to_name[id], type); - omap_plane = kzalloc(sizeof(*omap_plane), GFP_KERNEL); if (!omap_plane) return ERR_PTR(-ENOMEM); - formats = dispc_ovl_get_color_modes(priv->dispc, id); + omap_plane->id = idx; + omap_plane->name = plane_id_to_name[idx]; + omap_plane->overlay = priv->overlays[idx]; + + DBG("%s: type=%d", omap_plane->name, type); + DBG(" omap_plane->id: %d", omap_plane->id); + DBG(" crtc_mask: 0x%04x", possible_crtcs); + + formats = dispc_ovl_get_color_modes(priv->dispc, omap_plane->overlay->overlay_id); for (nformats = 0; formats[nformats]; ++nformats) ; - omap_plane->id = id; - omap_plane->name = plane_id_to_name[id]; plane = &omap_plane->base; @@ -349,7 +347,7 @@ struct drm_plane *omap_plane_init(struct drm_device *dev, error: dev_err(dev->dev, "%s(): could not create plane: %s\n", - __func__, plane_id_to_name[id]); + __func__, omap_plane->name); kfree(omap_plane); return NULL; From patchwork Thu Sep 23 07:06:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 12512063 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3510EC43219 for ; Thu, 23 Sep 2021 07:07:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 189FC61164 for ; Thu, 23 Sep 2021 07:07:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239550AbhIWHIl (ORCPT ); Thu, 23 Sep 2021 03:08:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239560AbhIWHIj (ORCPT ); Thu, 23 Sep 2021 03:08:39 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1A2AC061757 for ; Thu, 23 Sep 2021 00:07:08 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id u15so14172767wru.6 for ; Thu, 23 Sep 2021 00:07:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dhy9/QR4L3UcC/+5+wWB+hUZ0V3eL4h1DgQ/CLX1xJ0=; b=eeNb+O7m+K3bKw/yz9oaaxoTxxKLqkl1QJxdlb+5acSY1Efpz6BrzuEV1zEeBTOiuc waJmyVq8Iu5EnoLMtyNU1Ltim6cZ0Bnm6BBLtEFcTorpiZ9rDhiEnXB5bm+BVxS9/okQ iIJdiNRjPJuoBn0/dZSn2P2J2DHAGF6KBvZW7iXjyyZ8KIHsE6eIaPPhIa+zbK7IWZKi tyRHExWws5AYKmLSqwApKZ921IYqnnugJSuHX88z9UpMulmXB73nDrZUdQd3KqVIDnTt QfsnsU8NDeMkUiuNTcXiC01wEgy/E/pzgKQE3WmTjXshweBew7a7WE2U1uLSyPE4Rd7U Kg1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dhy9/QR4L3UcC/+5+wWB+hUZ0V3eL4h1DgQ/CLX1xJ0=; b=s/bfoBOzVThPoQmDKmDNtM1IUWEXEjB0bHJ/l7vWskevIwKt3tXjaKD2YlBy2eBbid Gy5gAXxiestniSSp+OcxPKoPoqsJ7z4p/FQsXAnI4A8hsR9irfDo7gJNTxxzdsXWx/lG UbruD+JNzP26Zii9XTQhN8TIdrijjB3B4DZyUZvRWmNRXIGivNKImhGWXHO1MsnMuMkr x7lV6gn3xFgB3x/GXHmOr6qsXYVReqE08JOHCN/BOW4mC97/2YhHbrHQ7A0bB2XHVS1/ nRBMg6hdmc0eOMJtDR9KMVxIPKSi0R7ft1rad5urmcl6tuy77TI3G116tabv/Z4SFAYz 1h6A== X-Gm-Message-State: AOAM533xG+p0PuJPLqa3Lgv8j8uBBOprfAqSjrhUVptUfBf10vbeKik0 KnwUtS8NPffmWotgmqIES0LRtw== X-Google-Smtp-Source: ABdhPJyc4wwekASLFc5/C6gQyqTnGmAKv0w/S3Te5s0VBUMBraqNQE9yNUXgzsjAxKpJ1Ekas7+LYA== X-Received: by 2002:adf:d1cf:: with SMTP id b15mr3170799wrd.181.1632380827255; Thu, 23 Sep 2021 00:07:07 -0700 (PDT) Received: from localhost.localdomain ([2001:861:44c0:66c0:74cf:b054:76f4:7692]) by smtp.gmail.com with ESMTPSA id d2sm4380357wrc.32.2021.09.23.00.07.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Sep 2021 00:07:06 -0700 (PDT) From: Neil Armstrong To: tomba@kernel.org Cc: linux-omap@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, khilman@baylibre.com, Benoit Parrot , Neil Armstrong Subject: [PATCH v5 4/8] drm/omap: omap_plane: subclass drm_plane_state Date: Thu, 23 Sep 2021 09:06:57 +0200 Message-Id: <20210923070701.145377-5-narmstrong@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210923070701.145377-1-narmstrong@baylibre.com> References: <20210923070701.145377-1-narmstrong@baylibre.com> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2877; i=narmstrong@baylibre.com; h=from:subject; bh=Bv1MHMANvHxeV2t+37ZVGiGFuepdThzrdPx6MB8l2pU=; b=owEBbQKS/ZANAwAKAXfc29rIyEnRAcsmYgBhTCchQiRBSVCNm38RVnltb/bJqf2t0Rf1ZP2TPPIV lyMe5JSJAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCYUwnIQAKCRB33NvayMhJ0SQCD/ 4gnL+7/g669cM6jktAXoRr5TNy8stFoUwRZKuRwpV3k0jCDsl1ZBnqtYyz9JntfQTK3CRprD9uvNbq OVC1TITYxg+cJgCUSzUujaDJGUPHHU0l39kJAtrifllLcfvNzex2UuV64Y3vBJLfuvPbh8WvY8YORg P9PB/ZJosDTh511B5SV1sXyPvoEmE5wjC6UCj/o2He1ulv5oliJM4sCrA2Jh6bo5qWk7W3uUUKjbje pyFu679Vtq7lZQ7oLXVVf6o3iZ4jeOpbl/LsFz2leJxRtwsAOAYHSmkw86mYMfJCU7SUXjMemePV4i 8HTjADsYwgXgvQSBWweyXUrnPM3VQRgfMYAcrLmw04QTlWPcYBjMr1tGtxGvauQ/dDEzazJaaD3YKR aDNzo1vf+wm2gEZAvH5KbtwGD3KsonjkYSXLeThNI3fJht0GG3qH+2PfCX2lK40WhAxPPMU2us0JI5 M1gFAVH2m8kzQngcxbhDcomRBhWRaLxeFpeG1MlYt1nTX/24ZCsRxw+m+nN8FhK0KfI7EhwD1i942S n+dorsMRwNQrZuW3RUdbiZD2Z9ElYXNj+i8zjIP+GUXJW8iWchsgo3CfnL1KslgaZWeShVVxWumrcu fDuJjT2QaUwjwOgX+OclLCyh+7NN6AGarh1UzFXfld1w+/TLiQDz6oqqGqqQ== X-Developer-Key: i=narmstrong@baylibre.com; a=openpgp; fpr=89EC3D058446217450F22848169AB7B1A4CFF8AE Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org From: Benoit Parrot In preparation to add omap plane state specific extensions we need to subclass drm_plane_state and add the relevant helpers. The addition of specific extension will be done separately. Signed-off-by: Benoit Parrot Signed-off-by: Neil Armstrong --- drivers/gpu/drm/omapdrm/omap_plane.c | 38 +++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/omapdrm/omap_plane.c b/drivers/gpu/drm/omapdrm/omap_plane.c index 0df5381cc015..bda794b4c915 100644 --- a/drivers/gpu/drm/omapdrm/omap_plane.c +++ b/drivers/gpu/drm/omapdrm/omap_plane.c @@ -16,6 +16,13 @@ * plane funcs */ +#define to_omap_plane_state(x) container_of(x, struct omap_plane_state, base) + +struct omap_plane_state { + /* Must be first. */ + struct drm_plane_state base; +}; + #define to_omap_plane(x) container_of(x, struct omap_plane, base) struct omap_plane { @@ -207,11 +214,17 @@ void omap_plane_install_properties(struct drm_plane *plane, static void omap_plane_reset(struct drm_plane *plane) { struct omap_plane *omap_plane = to_omap_plane(plane); + struct omap_plane_state *omap_state; - drm_atomic_helper_plane_reset(plane); - if (!plane->state) + if (plane->state) + drm_atomic_helper_plane_destroy_state(plane, plane->state); + + omap_state = kzalloc(sizeof(*omap_state), GFP_KERNEL); + if (!omap_state) return; + __drm_atomic_helper_plane_reset(plane, &omap_state->base); + /* * Set the zpos default depending on whether we are a primary or overlay * plane. @@ -222,6 +235,25 @@ static void omap_plane_reset(struct drm_plane *plane) plane->state->color_range = DRM_COLOR_YCBCR_FULL_RANGE; } +static struct drm_plane_state * +omap_plane_atomic_duplicate_state(struct drm_plane *plane) +{ + struct omap_plane_state *state; + struct omap_plane_state *copy; + + if (WARN_ON(!plane->state)) + return NULL; + + state = to_omap_plane_state(plane->state); + copy = kmemdup(state, sizeof(*state), GFP_KERNEL); + if (!copy) + return NULL; + + __drm_atomic_helper_plane_duplicate_state(plane, ©->base); + + return ©->base; +} + static int omap_plane_atomic_set_property(struct drm_plane *plane, struct drm_plane_state *state, struct drm_property *property, @@ -257,7 +289,7 @@ static const struct drm_plane_funcs omap_plane_funcs = { .disable_plane = drm_atomic_helper_disable_plane, .reset = omap_plane_reset, .destroy = omap_plane_destroy, - .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, + .atomic_duplicate_state = omap_plane_atomic_duplicate_state, .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, .atomic_set_property = omap_plane_atomic_set_property, .atomic_get_property = omap_plane_atomic_get_property, From patchwork Thu Sep 23 07:06:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 12512067 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5D25C433FE for ; Thu, 23 Sep 2021 07:07:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C9C3461164 for ; Thu, 23 Sep 2021 07:07:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239583AbhIWHIm (ORCPT ); Thu, 23 Sep 2021 03:08:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239567AbhIWHIl (ORCPT ); Thu, 23 Sep 2021 03:08:41 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE9F8C061574 for ; Thu, 23 Sep 2021 00:07:09 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id u15so14172919wru.6 for ; Thu, 23 Sep 2021 00:07:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MhWIp0UrXPh24CZld2TkpSz0zhxZL6RpebTBKJIQEs0=; b=zACrs0pfcolWyOc2u+w6I6s2NyMneenBh05GeBLLJSEWdeEJY/Atr2aljjHNmXqM/q /DayN/oDxACZBrN3L081fbtwSBFBoXoS5/BDJ9tRZu2vsDA31WWMbSmHllVaB25+HhE5 pE4SVoDFGf6tCs6yl9ZcfOk68W1ykYdwpb+zPSdhuZxkbo+UMvsbkzAr/dzMwO3osD6t wJJGW+4okxdE6k/Irtp+GHyn1numHkRrDoGMWr0BoeNkUk7C4SHGzj195LcQF7eUHojy hp6JKUtAFTRU9CV7ZREL2R02cvKwzKjFD+Ss/OUJgvNjjBo2ukm4iLr1e442EPc3CS90 suUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MhWIp0UrXPh24CZld2TkpSz0zhxZL6RpebTBKJIQEs0=; b=ww8XHYzcIqEEQQ4bxDb1CDPiH9+vZM0ekDkmad45lC1PleAFDM6Xe5YY1rjjcqO7b/ BnoTRp+kNMQH7vN12D0ILx7hVxYLwAu2Y+VPswJ5bQiAGAW3LUKP38vgPEGZjrCH43Yu CvwIK95B710Vrlh8M9HQ94WHpT7oK/Sj/MHZrL5i9Fi+Nmh5yvLSpVeG75rKVY3wg0Jy 5IXEUnZgiUFgdpF/xT7dZIgeu30LX0zH4MtMFVcu59SjAk4miLBxNg5BnRDXDdJotvz3 jZWHZCTB/9zmU95OMIsUPBqqsPniuT9dbhmImJFYGGUeMHoFue8WlDqks4If++Lo2Kk3 wU+g== X-Gm-Message-State: AOAM530zZAokoNup88Nx7vFb1Y3/03gpwZko40HYwgqlSOEsUkzYmqWx FgSbj9sBXH0Te7elQU3n6ucAew== X-Google-Smtp-Source: ABdhPJxHqtnVog+Xd9wnlR+qnWZFpYpzP97F5H+o+HJ7eRDzQVIvTb6TMG5bdoniPcP/3w6qKTyCVA== X-Received: by 2002:a1c:3b87:: with SMTP id i129mr14503811wma.115.1632380828228; Thu, 23 Sep 2021 00:07:08 -0700 (PDT) Received: from localhost.localdomain ([2001:861:44c0:66c0:74cf:b054:76f4:7692]) by smtp.gmail.com with ESMTPSA id d2sm4380357wrc.32.2021.09.23.00.07.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Sep 2021 00:07:07 -0700 (PDT) From: Neil Armstrong To: tomba@kernel.org Cc: linux-omap@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, khilman@baylibre.com, Benoit Parrot , Neil Armstrong Subject: [PATCH v5 5/8] drm/omap: Add global state as a private atomic object Date: Thu, 23 Sep 2021 09:06:58 +0200 Message-Id: <20210923070701.145377-6-narmstrong@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210923070701.145377-1-narmstrong@baylibre.com> References: <20210923070701.145377-1-narmstrong@baylibre.com> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=6530; i=narmstrong@baylibre.com; h=from:subject; bh=bSg+1BfDSAo3dwQf+G6Jt2gIX5PWaQNLdCzBbuvRQWc=; b=owEBbQKS/ZANAwAKAXfc29rIyEnRAcsmYgBhTCchR26nV3qW8AuUaoQwnqAkIsox28FjcLhgq5bf FIUdDZqJAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCYUwnIQAKCRB33NvayMhJ0R37D/ wNU0IjIPd77tPKcsxwEDvbnjeklqgFmPTe0r0p+HQwA12XcWmu29xZ8A+9bSfQhApkNBbO3AeG3Szs 6kp3axxnZJCR/UeorBYcVWPH0aaW3nES8H0Ov1mSlxRqWE4RHS856N7xx1UFtagVFrlzL0bP+8PuPX YR9Iqp9gWYqKgR5etWwTPiKO/dglCBXXvHMEdG631fOR3zYBDFNe2OJsc4zAeTJJSQ5upIzbqLzYzE 4ETFlv1W1l+Byw/JZ+egf92KLi/bfQbbxePna8KTmCZ8Nf317YWg0yCxBAgGkKyBxmCl6BhoXnc6sf 9RrEj8/hxOjqI6raBYz/x0wvcUCH9PUrLsgd7krg9Y9BmQL+9jGbSrWIsoGVyPJHZ990bnB/P9vbTq XLp7sRJ0Kw97e0VFhCNKBsJK1hIu03Rcp7L5S8SWufDN4CwtL/PiYY4gJhDWWFUmqw5uJYxnk96JEg ADi7qqPufYLwbfAWVVNob3YIuFc9vBVPul/+NZC5pZZ1aTwzmvEvJ/2r60m1Y/ECET/kj2LRBe/9IG prrMm7Nnvp1geu/RN5By4JYpT5eGZYLWXdtwbsZdFbk/AmRrbIdZ6RTXEnVQYBd5OcJnENfp/wt4PY s8P7dNe9uBaatHPPlLsFD7KmktBvusSTUPZ+YujtNg8oL/b4MRNbETcYFyKA== X-Developer-Key: i=narmstrong@baylibre.com; a=openpgp; fpr=89EC3D058446217450F22848169AB7B1A4CFF8AE Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org From: Benoit Parrot Global shared resources (like hw overlays) for omapdrm are implemented as a part of atomic state using the drm_private_obj infrastructure available in the atomic core. omap_global_state is introduced as a drm atomic private object. The two funcs omap_get_global_state() and omap_get_existing_global_state() are the two variants that will be used to access omap_global_state. drm_mode_config_init() needs to be called earlier because it creates/initializes the private_obj link list maintained by the atomic framework. The private_obj link list has to exist prior to calling drm_atomic_private_obj_init(). Similarly the cleanup handler are reordered appropriately. Signed-off-by: Benoit Parrot Signed-off-by: Neil Armstrong --- drivers/gpu/drm/omapdrm/omap_drv.c | 91 +++++++++++++++++++++++++++++- drivers/gpu/drm/omapdrm/omap_drv.h | 21 +++++++ 2 files changed, 109 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/omapdrm/omap_drv.c b/drivers/gpu/drm/omapdrm/omap_drv.c index b994014b22e8..c7912374d393 100644 --- a/drivers/gpu/drm/omapdrm/omap_drv.c +++ b/drivers/gpu/drm/omapdrm/omap_drv.c @@ -128,6 +128,82 @@ static const struct drm_mode_config_funcs omap_mode_config_funcs = { .atomic_commit = drm_atomic_helper_commit, }; +/* Global/shared object state funcs */ + +/* + * This is a helper that returns the private state currently in operation. + * Note that this would return the "old_state" if called in the atomic check + * path, and the "new_state" after the atomic swap has been done. + */ +struct omap_global_state * +omap_get_existing_global_state(struct omap_drm_private *priv) +{ + return to_omap_global_state(priv->glob_obj.state); +} + +/* + * This acquires the modeset lock set aside for global state, creates + * a new duplicated private object state. + */ +struct omap_global_state *__must_check +omap_get_global_state(struct drm_atomic_state *s) +{ + struct omap_drm_private *priv = s->dev->dev_private; + struct drm_private_state *priv_state; + + priv_state = drm_atomic_get_private_obj_state(s, &priv->glob_obj); + if (IS_ERR(priv_state)) + return ERR_CAST(priv_state); + + return to_omap_global_state(priv_state); +} + +static struct drm_private_state * +omap_global_duplicate_state(struct drm_private_obj *obj) +{ + struct omap_global_state *state; + + state = kmemdup(obj->state, sizeof(*state), GFP_KERNEL); + if (!state) + return NULL; + + __drm_atomic_helper_private_obj_duplicate_state(obj, &state->base); + + return &state->base; +} + +static void omap_global_destroy_state(struct drm_private_obj *obj, + struct drm_private_state *state) +{ + struct omap_global_state *omap_state = to_omap_global_state(state); + + kfree(omap_state); +} + +static const struct drm_private_state_funcs omap_global_state_funcs = { + .atomic_duplicate_state = omap_global_duplicate_state, + .atomic_destroy_state = omap_global_destroy_state, +}; + +static int omap_global_obj_init(struct drm_device *dev) +{ + struct omap_drm_private *priv = dev->dev_private; + struct omap_global_state *state; + + state = kzalloc(sizeof(*state), GFP_KERNEL); + if (!state) + return -ENOMEM; + + drm_atomic_private_obj_init(dev, &priv->glob_obj, &state->base, + &omap_global_state_funcs); + return 0; +} + +static void omap_global_obj_fini(struct omap_drm_private *priv) +{ + drm_atomic_private_obj_fini(&priv->glob_obj); +} + static void omap_disconnect_pipelines(struct drm_device *ddev) { struct omap_drm_private *priv = ddev->dev_private; @@ -231,8 +307,6 @@ static int omap_modeset_init(struct drm_device *dev) if (!omapdss_stack_is_ready()) return -EPROBE_DEFER; - drm_mode_config_init(dev); - ret = omap_modeset_init_properties(dev); if (ret < 0) return ret; @@ -583,10 +657,16 @@ static int omapdrm_init(struct omap_drm_private *priv, struct device *dev) omap_gem_init(ddev); - ret = omap_hwoverlays_init(priv); + drm_mode_config_init(ddev); + + ret = omap_global_obj_init(ddev); if (ret) goto err_gem_deinit; + ret = omap_hwoverlays_init(priv); + if (ret) + goto err_free_priv_obj; + ret = omap_modeset_init(ddev); if (ret) { dev_err(priv->dev, "omap_modeset_init failed: ret=%d\n", ret); @@ -624,7 +704,10 @@ static int omapdrm_init(struct omap_drm_private *priv, struct device *dev) omap_modeset_fini(ddev); err_free_overlays: omap_hwoverlays_destroy(priv); +err_free_priv_obj: + omap_global_obj_fini(priv); err_gem_deinit: + drm_mode_config_cleanup(ddev); omap_gem_deinit(ddev); destroy_workqueue(priv->wq); omap_disconnect_pipelines(ddev); @@ -649,6 +732,8 @@ static void omapdrm_cleanup(struct omap_drm_private *priv) omap_modeset_fini(ddev); omap_hwoverlays_destroy(priv); + omap_global_obj_fini(priv); + drm_mode_config_cleanup(ddev); omap_gem_deinit(ddev); destroy_workqueue(priv->wq); diff --git a/drivers/gpu/drm/omapdrm/omap_drv.h b/drivers/gpu/drm/omapdrm/omap_drv.h index b4d9c2062723..280cdd27bc8e 100644 --- a/drivers/gpu/drm/omapdrm/omap_drv.h +++ b/drivers/gpu/drm/omapdrm/omap_drv.h @@ -14,6 +14,7 @@ #include "dss/omapdss.h" #include "dss/dss.h" +#include #include #include @@ -41,6 +42,15 @@ struct omap_drm_pipeline { unsigned int alias_id; }; +/* + * Global private object state for tracking resources that are shared across + * multiple kms objects (planes/crtcs/etc). + */ +#define to_omap_global_state(x) container_of(x, struct omap_global_state, base) +struct omap_global_state { + struct drm_private_state base; +}; + struct omap_drm_private { struct drm_device *ddev; struct device *dev; @@ -61,6 +71,13 @@ struct omap_drm_private { unsigned int num_ovls; struct omap_hw_overlay *overlays[8]; + /* + * Global private object state, Do not access directly, use + * omap_global_get_state() + */ + struct drm_modeset_lock glob_obj_lock; + struct drm_private_obj glob_obj; + struct drm_fb_helper *fbdev; struct workqueue_struct *wq; @@ -88,5 +105,9 @@ struct omap_drm_private { void omap_debugfs_init(struct drm_minor *minor); +struct omap_global_state *__must_check +omap_get_global_state(struct drm_atomic_state *s); +struct omap_global_state * +omap_get_existing_global_state(struct omap_drm_private *priv); #endif /* __OMAPDRM_DRV_H__ */ From patchwork Thu Sep 23 07:06:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 12512071 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9AECC433F5 for ; Thu, 23 Sep 2021 07:07:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AC40461164 for ; Thu, 23 Sep 2021 07:07:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239571AbhIWHIn (ORCPT ); Thu, 23 Sep 2021 03:08:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239575AbhIWHIm (ORCPT ); Thu, 23 Sep 2021 03:08:42 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2C40C061756 for ; Thu, 23 Sep 2021 00:07:10 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id t28so800170wra.7 for ; Thu, 23 Sep 2021 00:07:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FBqrBUoIEhA7zPg5WZi+GKs45CGmVn79mbbh6TY7Vl4=; b=58+brv97DGbXVrVPk+dScj+Ywo5kU4ddu2wC7x0Qfshf5jnTr7pki4BUvvlZbGaRs0 o6b3TIWDnUTCBg40BjLJ/309An4luzBQeK4lvjisnmXEVYzsgX0BhcjwmiXu81/LywxS 4kvHR8z/MrHiHVX2+baN7+gUIbsHg17t1VnAx5vzCoi0UlU1U48c6ORc/j/3PkqcNQp+ hfai/FzJq2eXrHlbcq21/WsisvnUs9vy4iuoEDRzj9BKCx+EBdmTPg3JW9PvAnH12AdW 5kmNgZY5GUJlRZJoVh/pbZR9zEuWouqgUbZiXOSxrxHuA3xOyDaQdXaRRO1RFVYIAmBQ HYjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FBqrBUoIEhA7zPg5WZi+GKs45CGmVn79mbbh6TY7Vl4=; b=r7gPLSk2q/E4pi33a554MrH2gQ2ePK8Yf1+obdcayFhNknoDlaLdw+IHdzk3n62tcv neHEWZQoXTRe0RxuOAlNimiqAy21ME4D9gYtZIQOQqW0vyTXj3ZaGt81rTESpq+nyaFw cWRnJRsAKw+Eiem16WOd4gVlG9WP2eRDKGevWBJFogT12R7LuxeDqC/J2lMasDHpKQZL pdls4/HjvwQRmr1m2PO8R/o4urKU53zxbyHtLRhG+KcdJY7AdDEPapbJn/sz/RvQ1rTi gA5nRD5Li0Y7DuRAYuyxbA0KzNLNmeKVxx5Wl+x5E5L1xVNsBW2l89uyl1vtGOxYfrYz 559Q== X-Gm-Message-State: AOAM53124WVXxu0uijbk4i8DlcGg3mEBTI0i0wkY4Ep2IzCbVEoIzYWC J9N1dgXvsYNBqrcC1WGs7Usmfg== X-Google-Smtp-Source: ABdhPJxHIfQyf8ogJQ2ts31VdlPaWuR1SmXTyKmytU79svWpi+RsDqLaTkOtB1WJfcE0XcxqS4EMGQ== X-Received: by 2002:adf:f789:: with SMTP id q9mr3193355wrp.367.1632380829178; Thu, 23 Sep 2021 00:07:09 -0700 (PDT) Received: from localhost.localdomain ([2001:861:44c0:66c0:74cf:b054:76f4:7692]) by smtp.gmail.com with ESMTPSA id d2sm4380357wrc.32.2021.09.23.00.07.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Sep 2021 00:07:08 -0700 (PDT) From: Neil Armstrong To: tomba@kernel.org Cc: linux-omap@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, khilman@baylibre.com, Benoit Parrot , Neil Armstrong Subject: [PATCH v5 6/8] drm/omap: dynamically assign hw overlays to planes Date: Thu, 23 Sep 2021 09:06:59 +0200 Message-Id: <20210923070701.145377-7-narmstrong@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210923070701.145377-1-narmstrong@baylibre.com> References: <20210923070701.145377-1-narmstrong@baylibre.com> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=16407; i=narmstrong@baylibre.com; h=from:subject; bh=YGAHRpQPqb7639ejCmo/rSM9XWVC0JlfHHP5F6geRgA=; b=owEBbQKS/ZANAwAKAXfc29rIyEnRAcsmYgBhTCchu5T9hs8qazhBdo4pKtf40yfdq+UPNfkPK4tX LgLL1wKJAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCYUwnIQAKCRB33NvayMhJ0c5CEA C/aO2gUGa5Q9dLCDVNrX9n0hnOLsAe8WaaBxYN81LKVtKykp613ZwJXNm2XmlqqMPR448H2nmSdraY 8wwwE3Y504IDLNgqSX3rHGVppGZPcUWJc7L4e2sMoH/+Dp/fjx/BW6SDkt7EJSmx18JJf33n38bzGo Dfwd0Xl0V2NXiMJzH7hKTtsY8b44qpNVJKyO5+w7Ks9DtvVLeVi2SPNCM8/BMbkUrs7cZLEhuOHKMC 6CTrhtpe4JWt3wChLSHEaqc4NqljaNp2FpPGfTUvGJjbQl0SKG4Y1sJnsMMfZ6wFxQMHeLoS9LFHdA /VspWvSk/0TS1y+eIJhXMHBUiBrdqnDP0CVqvgKV3FkWYStF/hKxRD/JdCECVz0zpZ6fNMQyPuSKJe zmMuqoKfRU7ZEgu9hno/qGqpgLtlSxQQVYDXXN8ABGb5tTmBHbZwFk6soZQCMWR/l+ZGcLk+o53W+n me5phpWn7vM8miNX+tfVUlU3fsb7BrsVvhagHvWwbTnXsNkgI6l5gwenQyj9CYwHwQH9BE5Ild+Ht/ S4vcaaLtBCxFMaV4RKeN5mevxw+93ZgHUqC57OSd72OZ/M12w1/KALIrYz5YOFZhwvimD2wjtIsBHr kHDWTv3R4Ue3D9F6C5kjk8Uk4HJBQ38Q/y5eWw6ea/Tty3P3THmJFMNW1PIw== X-Developer-Key: i=narmstrong@baylibre.com; a=openpgp; fpr=89EC3D058446217450F22848169AB7B1A4CFF8AE Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org From: Benoit Parrot (re)assign the hw overlays to planes based on required caps, and to handle situations where we could not modify an in-use plane. This means all planes advertise the superset of formats and properties. Userspace must (as always) use atomic TEST_ONLY step for atomic updates, as not all planes may be available for use on every frame. The mapping of hwoverlays to plane is stored in omap_global_state, so that state updates are atomically committed in the same way that plane/etc state updates are managed. This is needed because the omap_plane_state keeps a pointer to the hwoverlay, and we don't want global state to become out of sync with the plane state if an atomic update fails, we hit deadlock/ backoff scenario, etc. The use of global_state_lock keeps multiple parallel updates which both re-assign hwoverlays properly serialized. Signed-off-by: Benoit Parrot Signed-off-by: Neil Armstrong --- drivers/gpu/drm/omapdrm/omap_drv.h | 3 + drivers/gpu/drm/omapdrm/omap_overlay.c | 140 ++++++++++++++++++++ drivers/gpu/drm/omapdrm/omap_overlay.h | 9 ++ drivers/gpu/drm/omapdrm/omap_plane.c | 170 ++++++++++++++++++++----- 4 files changed, 287 insertions(+), 35 deletions(-) diff --git a/drivers/gpu/drm/omapdrm/omap_drv.h b/drivers/gpu/drm/omapdrm/omap_drv.h index 280cdd27bc8e..2d5928f05a23 100644 --- a/drivers/gpu/drm/omapdrm/omap_drv.h +++ b/drivers/gpu/drm/omapdrm/omap_drv.h @@ -49,6 +49,9 @@ struct omap_drm_pipeline { #define to_omap_global_state(x) container_of(x, struct omap_global_state, base) struct omap_global_state { struct drm_private_state base; + + /* global atomic state of assignment between overlays and planes */ + struct drm_plane *hwoverlay_to_plane[8]; }; struct omap_drm_private { diff --git a/drivers/gpu/drm/omapdrm/omap_overlay.c b/drivers/gpu/drm/omapdrm/omap_overlay.c index 2b1416d2aad2..f1a23c2203aa 100644 --- a/drivers/gpu/drm/omapdrm/omap_overlay.c +++ b/drivers/gpu/drm/omapdrm/omap_overlay.c @@ -21,6 +21,146 @@ static const char * const overlay_id_to_name[] = { [OMAP_DSS_VIDEO3] = "vid3", }; +static struct omap_hw_overlay * +omap_plane_find_free_overlay(struct drm_device *dev, + struct drm_plane *hwoverlay_to_plane[], + u32 caps, u32 fourcc, u32 crtc_mask) +{ + struct omap_drm_private *priv = dev->dev_private; + int i; + + DBG("caps: %x fourcc: %x crtc: %x", caps, fourcc, crtc_mask); + + for (i = 0; i < priv->num_ovls; i++) { + struct omap_hw_overlay *cur = priv->overlays[i]; + + DBG("%d: id: %d cur->caps: %x cur->crtc: %x", + cur->idx, cur->overlay_id, cur->caps, cur->possible_crtcs); + + /* skip if already in-use */ + if (hwoverlay_to_plane[cur->idx]) + continue; + + /* check if allowed on crtc */ + if (!(cur->possible_crtcs & crtc_mask)) + continue; + + /* skip if doesn't support some required caps: */ + if (caps & ~cur->caps) + continue; + + /* check supported format */ + if (!dispc_ovl_color_mode_supported(priv->dispc, + cur->overlay_id, fourcc)) + continue; + + return cur; + } + + DBG("no match"); + return NULL; +} + +int omap_overlay_assign(struct drm_atomic_state *s, struct drm_plane *plane, + u32 caps, u32 fourcc, u32 crtc_mask, + struct omap_hw_overlay **overlay) +{ + struct omap_drm_private *priv = s->dev->dev_private; + struct omap_global_state *new_global_state, *old_global_state; + struct drm_plane **overlay_map; + struct omap_hw_overlay *ovl; + + new_global_state = omap_get_global_state(s); + if (IS_ERR(new_global_state)) + return PTR_ERR(new_global_state); + + /* + * grab old_state after omap_get_global_state(), + * since now we hold lock: + */ + old_global_state = omap_get_existing_global_state(priv); + DBG("new_global_state: %p old_global_state: %p", + new_global_state, old_global_state); + + overlay_map = new_global_state->hwoverlay_to_plane; + + if (!*overlay) { + ovl = omap_plane_find_free_overlay(s->dev, overlay_map, + caps, fourcc, crtc_mask); + if (!ovl) + return -ENOMEM; + + ovl->possible_crtcs = crtc_mask; + overlay_map[ovl->idx] = plane; + *overlay = ovl; + + DBG("%s: assign to plane %s caps %x on crtc %x", + (*overlay)->name, plane->name, caps, crtc_mask); + } + + return 0; +} + +void omap_overlay_release(struct drm_atomic_state *s, + struct drm_plane *plane, + struct omap_hw_overlay *overlay) +{ + struct omap_global_state *state = omap_get_global_state(s); + struct drm_plane **overlay_map = state->hwoverlay_to_plane; + + if (!overlay) + return; + + if (WARN_ON(!overlay_map[overlay->idx])) + return; + /* + * Check that the overlay we are releasing is actually + * assigned to the plane we are trying to release it from. + */ + if (overlay_map[overlay->idx] == plane) { + DBG("%s: release from plane %s", overlay->name, plane->name); + + overlay_map[overlay->idx] = NULL; + } +} + +void omap_overlay_disable(struct drm_atomic_state *s, + struct drm_plane *plane, + struct omap_hw_overlay *overlay) +{ + struct omap_drm_private *priv = s->dev->dev_private; + struct drm_plane **overlay_map; + struct omap_global_state *old_state; + + old_state = omap_get_existing_global_state(priv); + overlay_map = old_state->hwoverlay_to_plane; + + if (!overlay) + return; + + /* + * Check that the overlay we are trying to disable has not + * been re-assigned to another plane already + */ + if (!overlay_map[overlay->idx]) { + DBG("%s: on %s disabled", overlay->name, plane->name); + + /* disable the overlay */ + dispc_ovl_enable(priv->dispc, overlay->overlay_id, false); + + /* + * Since we are disabling this overlay in this + * atomic cycle we can reset the available crtcs + * it can be used on + */ + overlay->possible_crtcs = (1 << priv->num_pipes) - 1; + } + + /* + * Otherwise the overlay is still in use so leave it alone + */ +} + static void omap_overlay_destroy(struct omap_hw_overlay *overlay) { kfree(overlay); diff --git a/drivers/gpu/drm/omapdrm/omap_overlay.h b/drivers/gpu/drm/omapdrm/omap_overlay.h index 892fecb67adb..d5033ee481c2 100644 --- a/drivers/gpu/drm/omapdrm/omap_overlay.h +++ b/drivers/gpu/drm/omapdrm/omap_overlay.h @@ -28,4 +28,13 @@ struct omap_hw_overlay { int omap_hwoverlays_init(struct omap_drm_private *priv); void omap_hwoverlays_destroy(struct omap_drm_private *priv); +int omap_overlay_assign(struct drm_atomic_state *s, struct drm_plane *plane, + u32 caps, u32 fourcc, u32 crtc_mask, + struct omap_hw_overlay **overlay); +void omap_overlay_release(struct drm_atomic_state *s, + struct drm_plane *plane, + struct omap_hw_overlay *overlay); +void omap_overlay_disable(struct drm_atomic_state *s, + struct drm_plane *plane, + struct omap_hw_overlay *overlay); #endif /* __OMAPDRM_OVERLAY_H__ */ diff --git a/drivers/gpu/drm/omapdrm/omap_plane.c b/drivers/gpu/drm/omapdrm/omap_plane.c index bda794b4c915..4b400a8bfe9e 100644 --- a/drivers/gpu/drm/omapdrm/omap_plane.c +++ b/drivers/gpu/drm/omapdrm/omap_plane.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "omap_dmm_tiler.h" #include "omap_drv.h" @@ -21,6 +22,8 @@ struct omap_plane_state { /* Must be first. */ struct drm_plane_state base; + + struct omap_hw_overlay *overlay; }; #define to_omap_plane(x) container_of(x, struct omap_plane, base) @@ -29,8 +32,6 @@ struct omap_plane { struct drm_plane base; enum omap_plane_id id; const char *name; - - struct omap_hw_overlay *overlay; }; static int omap_plane_prepare_fb(struct drm_plane *plane, @@ -58,10 +59,27 @@ static void omap_plane_atomic_update(struct drm_plane *plane, struct omap_plane *omap_plane = to_omap_plane(plane); struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state, plane); - enum omap_plane_id ovl_id = omap_plane->overlay->overlay_id; + struct drm_plane_state *old_state = drm_atomic_get_old_plane_state(state, + plane); + struct omap_plane_state *new_omap_state; + struct omap_plane_state *old_omap_state; struct omap_overlay_info info; + enum omap_plane_id ovl_id; int ret; + new_omap_state = to_omap_plane_state(new_state); + old_omap_state = to_omap_plane_state(old_state); + + /* Cleanup previously held overlay if needed */ + omap_overlay_disable(old_state->state, plane, old_omap_state->overlay); + + if (!new_omap_state->overlay) { + DBG("[PLANE:%d:%s] overlay_id: ??? (%p)", plane->base.id, plane->name, + new_omap_state->overlay); + return; + } + + ovl_id = new_omap_state->overlay->overlay_id; DBG("%s, crtc=%p fb=%p", omap_plane->name, new_state->crtc, new_state->fb); @@ -80,9 +98,9 @@ static void omap_plane_atomic_update(struct drm_plane *plane, /* update scanout: */ omap_framebuffer_update_scanout(new_state->fb, new_state, &info); - DBG("%dx%d -> %dx%d (%d)", info.width, info.height, - info.out_width, info.out_height, - info.screen_width); + DBG("%s: %dx%d -> %dx%d (%d)", + new_omap_state->overlay->name, info.width, info.height, + info.out_width, info.out_height, info.screen_width); DBG("%d,%d %pad %pad", info.pos_x, info.pos_y, &info.paddr, &info.p_uv_addr); @@ -105,55 +123,66 @@ static void omap_plane_atomic_disable(struct drm_plane *plane, { struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state, plane); - struct omap_drm_private *priv = plane->dev->dev_private; - struct omap_plane *omap_plane = to_omap_plane(plane); - enum omap_plane_id ovl_id = omap_plane->overlay->overlay_id; + struct drm_plane_state *old_state = drm_atomic_get_old_plane_state(state, + plane); + struct omap_plane_state *new_omap_state; + struct omap_plane_state *old_omap_state; + + new_omap_state = to_omap_plane_state(new_state); + old_omap_state = to_omap_plane_state(old_state); + + if (!old_omap_state->overlay) + return; new_state->rotation = DRM_MODE_ROTATE_0; - new_state->zpos = plane->type == DRM_PLANE_TYPE_PRIMARY ? 0 : omap_plane->id; + new_state->zpos = plane->type == DRM_PLANE_TYPE_PRIMARY + ? 0 : old_omap_state->overlay->overlay_id; - dispc_ovl_enable(priv->dispc, ovl_id, false); + omap_overlay_disable(old_state->state, plane, old_omap_state->overlay); + new_omap_state->overlay = NULL; } +#define FRAC_16_16(mult, div) (((mult) << 16) / (div)) static int omap_plane_atomic_check(struct drm_plane *plane, struct drm_atomic_state *state) { struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state, plane); + struct drm_plane_state *old_plane_state = drm_atomic_get_old_plane_state(state, + plane); + struct drm_crtc *crtc; struct omap_drm_private *priv = plane->dev->dev_private; + struct omap_plane_state *omap_state = to_omap_plane_state(new_plane_state); + struct omap_global_state *omap_overlay_global_state; + u32 crtc_mask; + u32 fourcc; + u32 caps = 0; + bool new_hw_overlay = false; + int min_scale, max_scale; + int ret; struct drm_crtc_state *crtc_state; u16 width, height; u32 width_fp, height_fp; - if (!new_plane_state->fb) - return 0; + omap_overlay_global_state = omap_get_global_state(state); + if (IS_ERR(omap_overlay_global_state)) + return PTR_ERR(omap_overlay_global_state); + DBG("%s: omap_overlay_global_state: %p", plane->name, + omap_overlay_global_state); dispc_ovl_get_max_size(priv->dispc, &width, &height); width_fp = width << 16; height_fp = height << 16; - /* crtc should only be NULL when disabling (i.e., !new_plane_state->fb) */ - if (WARN_ON(!new_plane_state->crtc)) + crtc = new_plane_state->crtc ? new_plane_state->crtc : plane->state->crtc; + if (!crtc) return 0; - crtc_state = drm_atomic_get_existing_crtc_state(state, - new_plane_state->crtc); + crtc_state = drm_atomic_get_existing_crtc_state(state, crtc); /* we should have a crtc state if the plane is attached to a crtc */ if (WARN_ON(!crtc_state)) return 0; - if (!crtc_state->enable) - return 0; - - if (new_plane_state->crtc_x < 0 || new_plane_state->crtc_y < 0) - return -EINVAL; - - if (new_plane_state->crtc_x + new_plane_state->crtc_w > crtc_state->adjusted_mode.hdisplay) - return -EINVAL; - - if (new_plane_state->crtc_y + new_plane_state->crtc_h > crtc_state->adjusted_mode.vdisplay) - return -EINVAL; - /* Make sure dimensions are within bounds. */ if (new_plane_state->src_h > height_fp || new_plane_state->crtc_h > height) return -EINVAL; @@ -161,9 +190,81 @@ static int omap_plane_atomic_check(struct drm_plane *plane, if (new_plane_state->src_w > width_fp || new_plane_state->crtc_w > width) return -EINVAL; - if (new_plane_state->rotation != DRM_MODE_ROTATE_0 && - !omap_framebuffer_supports_rotation(new_plane_state->fb)) - return -EINVAL; + + /* + * Note: these are just sanity checks to filter out totally bad scaling + * factors. The real limits must be calculated case by case, and + * unfortunately we currently do those checks only at the commit + * phase in dispc. + */ + min_scale = FRAC_16_16(1, 8); + max_scale = FRAC_16_16(8, 1); + + ret = drm_atomic_helper_check_plane_state(new_plane_state, crtc_state, + min_scale, max_scale, + true, true); + if (ret) + return ret; + + DBG("%s: check (%d -> %d)", plane->name, + old_plane_state->visible, new_plane_state->visible); + + if (new_plane_state->visible) { + if (new_plane_state->rotation != DRM_MODE_ROTATE_0 && + !omap_framebuffer_supports_rotation(new_plane_state->fb)) + return -EINVAL; + + if ((new_plane_state->src_w >> 16) != new_plane_state->crtc_w || + (new_plane_state->src_h >> 16) != new_plane_state->crtc_h) + caps |= OMAP_DSS_OVL_CAP_SCALE; + + fourcc = new_plane_state->fb->format->format; + crtc_mask = drm_crtc_mask(new_plane_state->crtc); + + /* + * (re)allocate hw overlay if we don't have one or + * there is a caps mismatch + */ + if (!omap_state->overlay || + (caps & ~omap_state->overlay->caps)) { + new_hw_overlay = true; + } else { + /* check if allowed on crtc */ + if (!(omap_state->overlay->possible_crtcs & crtc_mask)) + new_hw_overlay = true; + + /* check supported format */ + if (!dispc_ovl_color_mode_supported(priv->dispc, + omap_state->overlay->overlay_id, + fourcc)) + new_hw_overlay = true; + } + + if (new_hw_overlay) { + struct omap_hw_overlay *old_ovl = omap_state->overlay; + struct omap_hw_overlay *new_ovl = NULL; + + omap_overlay_release(state, plane, old_ovl); + + ret = omap_overlay_assign(state, plane, caps, + fourcc, crtc_mask, &new_ovl); + if (ret) { + DBG("%s: failed to assign hw_overlay(s)!", + plane->name); + omap_state->overlay = NULL; + return ret; + } + + omap_state->overlay = new_ovl; + } + } else { + omap_overlay_release(state, plane, omap_state->overlay); + omap_state->overlay = NULL; + } + + if (omap_state->overlay) + DBG("plane: %s overlay_id: %d", plane->name, + omap_state->overlay->overlay_id); return 0; } @@ -230,7 +331,7 @@ static void omap_plane_reset(struct drm_plane *plane) * plane. */ plane->state->zpos = plane->type == DRM_PLANE_TYPE_PRIMARY - ? 0 : omap_plane->overlay->overlay_id; + ? 0 : omap_plane->id; plane->state->color_encoding = DRM_COLOR_YCBCR_BT601; plane->state->color_range = DRM_COLOR_YCBCR_FULL_RANGE; } @@ -340,13 +441,12 @@ struct drm_plane *omap_plane_init(struct drm_device *dev, omap_plane->id = idx; omap_plane->name = plane_id_to_name[idx]; - omap_plane->overlay = priv->overlays[idx]; DBG("%s: type=%d", omap_plane->name, type); DBG(" omap_plane->id: %d", omap_plane->id); DBG(" crtc_mask: 0x%04x", possible_crtcs); - formats = dispc_ovl_get_color_modes(priv->dispc, omap_plane->overlay->overlay_id); + formats = dispc_ovl_get_color_modes(priv->dispc, omap_plane->id); for (nformats = 0; formats[nformats]; ++nformats) ; From patchwork Thu Sep 23 07:07:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 12512069 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A95EC4321E for ; Thu, 23 Sep 2021 07:07:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 544DA61131 for ; Thu, 23 Sep 2021 07:07:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239601AbhIWHIn (ORCPT ); Thu, 23 Sep 2021 03:08:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239587AbhIWHIm (ORCPT ); Thu, 23 Sep 2021 03:08:42 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8FF5C061756 for ; Thu, 23 Sep 2021 00:07:11 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id t8so14229557wrq.4 for ; Thu, 23 Sep 2021 00:07:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=spYtq8N9tOYZ3bDuoIAir81jdpnT4AkNUpr6oHbfic8=; b=1RO5ZobrgG5++dYNnzrLOUv0cRpwUlemb5+o+u9Q1gPopjjnubyP6BaIGORmEeuxjc yffM2Byy9QsuWh99hcBLQq6ysJ3yXdTTN3qpeHAJOg1aalCqgUFe6CniN8igzwuf/C6e SjIt+PTPnJOsC2Ak2ovuUFcQNMqlLONXy6IRbzmKVOXNHsE5QRoJNXBuSSrt5/4DwNBY OPIVZiLphjhEQRwfHr3GwaN/PLuDB0bvvq9uSuF4UXRJ0NSCdSO8/ZZYfcj3K+gVIlFY u2git7nzI6k2XQCguwxQcuadg10sqm18637IU7kKeGuCgfZjr/IKe3wK+4Q9Z8zRWeAM qgdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=spYtq8N9tOYZ3bDuoIAir81jdpnT4AkNUpr6oHbfic8=; b=T0+OhAOlEGWo41KkE8M4Bw5pe3wsvsKOzjZ7mIGBpEFMY5LXPbPox4qrqiC+7VzBTa RnoqHCs2I03NkbZTmMvP45ddtZHVtW+z6HySeKrB++e5ZsYsbo8ilTRkRi5ePC+ZGywJ hANIGLurnC6OLDBk/vpHF3z1HKgjrmk6sBcJ2St4YoUqHmIb1VqXwJg2FDb/gdesZhXy f/liyn+xgGsJfCWed5QreEKR9IsSdpd9nC9TkGwG1Uhf+hm7Xx+fTDdZn1q5Ew1lGzBy Eke/oxkYDgr8BSm1Q2A9x4aJ6cPhlklUgatQJZDDsGtsaplzZx3OnfLcSLBcU1BhYc6U 5O9w== X-Gm-Message-State: AOAM5322tea0K7a6GFHnhgfdE18QCo1GRRlqYtlEEz1TBStUU3K36xrg aociEL5eAd6b/q8qTcwNPOeukw== X-Google-Smtp-Source: ABdhPJwOv7McjYGzFwHzxGJAV+ts3fm09N336sM14adogDpXQRV9SjPwiwhmsdpZNlzYLAKpJMKXmw== X-Received: by 2002:a5d:598c:: with SMTP id n12mr3030473wri.391.1632380830122; Thu, 23 Sep 2021 00:07:10 -0700 (PDT) Received: from localhost.localdomain ([2001:861:44c0:66c0:74cf:b054:76f4:7692]) by smtp.gmail.com with ESMTPSA id d2sm4380357wrc.32.2021.09.23.00.07.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Sep 2021 00:07:09 -0700 (PDT) From: Neil Armstrong To: tomba@kernel.org Cc: linux-omap@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, khilman@baylibre.com, Benoit Parrot , Neil Armstrong Subject: [PATCH v5 7/8] drm/omap: add plane_atomic_print_state support Date: Thu, 23 Sep 2021 09:07:00 +0200 Message-Id: <20210923070701.145377-8-narmstrong@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210923070701.145377-1-narmstrong@baylibre.com> References: <20210923070701.145377-1-narmstrong@baylibre.com> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1894; i=narmstrong@baylibre.com; h=from:subject; bh=ut7MrM2quhUltiKLTR0Hvs3i6r3x/VqxCeFv4yQK71M=; b=owEBbQKS/ZANAwAKAXfc29rIyEnRAcsmYgBhTCchINs7VR8suG1q30wHKBeLlE92EeTR8kdg4y/a rQCD7P+JAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCYUwnIQAKCRB33NvayMhJ0WPUEA CWqjItqPiNBCOoAuFwrxfJbSdx2CgxQO1mppCAJWVfvDExE5YGcNJubbARXWHCab8y99LGzTImdTil LY1hKI8xDTwoq2c1EA+g36lWk+7cn7NFQHWAW01tgiTWo2sWh4ZJP4ZspXo5QH8UHBfMsmasgurlfs 5/e3UIagRfBX/k7J6fdkwe2RYGGveaeVut60rTB1lpk7n7WmHUs6hTGuk5e2MwUSnS6TgC+uD+RWTS kiKKsALVsXJsted3MhasB2N/V/weowNXc92xb6q5OUOjhuBM2QBNJmtPO0jHB1bSK8N83YHok6O+H9 g81/5TFMd0ZoTGI7MnenlM+FZFQNjn9dwr/I+e+DLCbQohvjfSlHaRU1bUmcbg/vVeWgJbc2Q9qxxd FqYS+V5R3yEJxBrbD1kPdL5d1gRyM/qDgj41nUYCDmN+eDaThAGlWDHvPTiI0QA6bpswfEzDpfDj3z oXu6n2U3GcoJs9eKvXPbGEmaBFPDffD780mkc0CvwRZviEDm15OBWMEh/62y1OfEoF5/w4YPdAujGf kSsFcEaH+XzICDbuUFU1EuVMMdJF5D0ZfVQgsPVoKY9KNy1aX1FWTCdU7ROUuJKtEPm30/qU7fyCeq tt5vsHeOOo1f8gkReDboK7QuK8z6jUJzhLaU6jW34LcVm5wEEoEWHzW1Fifg== X-Developer-Key: i=narmstrong@baylibre.com; a=openpgp; fpr=89EC3D058446217450F22848169AB7B1A4CFF8AE Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org From: Benoit Parrot Now that we added specific item to our subclassed drm_plane_state we can add omap_plane_atomic_print_state() helper to dump out our own driver specific plane state. Signed-off-by: Benoit Parrot Signed-off-by: Neil Armstrong --- drivers/gpu/drm/omapdrm/omap_plane.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/gpu/drm/omapdrm/omap_plane.c b/drivers/gpu/drm/omapdrm/omap_plane.c index 4b400a8bfe9e..badbafeb3402 100644 --- a/drivers/gpu/drm/omapdrm/omap_plane.c +++ b/drivers/gpu/drm/omapdrm/omap_plane.c @@ -355,6 +355,23 @@ omap_plane_atomic_duplicate_state(struct drm_plane *plane) return ©->base; } +static void omap_plane_atomic_print_state(struct drm_printer *p, + const struct drm_plane_state *state) +{ + struct omap_plane_state *omap_state = to_omap_plane_state(state); + + drm_printf(p, "\toverlay=%s\n", omap_state->overlay ? + omap_state->overlay->name : "(null)"); + if (omap_state->overlay) { + drm_printf(p, "\t\tidx=%d\n", omap_state->overlay->idx); + drm_printf(p, "\t\toverlay_id=%d\n", + omap_state->overlay->overlay_id); + drm_printf(p, "\t\tcaps=0x%x\n", omap_state->overlay->caps); + drm_printf(p, "\t\tpossible_crtcs=0x%x\n", + omap_state->overlay->possible_crtcs); + } +} + static int omap_plane_atomic_set_property(struct drm_plane *plane, struct drm_plane_state *state, struct drm_property *property, @@ -394,6 +411,7 @@ static const struct drm_plane_funcs omap_plane_funcs = { .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, .atomic_set_property = omap_plane_atomic_set_property, .atomic_get_property = omap_plane_atomic_get_property, + .atomic_print_state = omap_plane_atomic_print_state, }; static bool omap_plane_supports_yuv(struct drm_plane *plane) From patchwork Thu Sep 23 07:07:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 12512073 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D85AC433FE for ; Thu, 23 Sep 2021 07:07:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 82FCA60F56 for ; Thu, 23 Sep 2021 07:07:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239608AbhIWHIo (ORCPT ); Thu, 23 Sep 2021 03:08:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239598AbhIWHIo (ORCPT ); Thu, 23 Sep 2021 03:08:44 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9032DC061756 for ; Thu, 23 Sep 2021 00:07:12 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id t18so14288863wrb.0 for ; Thu, 23 Sep 2021 00:07:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4PMS3EsUME0yXf2wLvBhrQWzVpCL17iuqXFXZ3vBBGU=; b=hxnkdMrp/zCZbfmK/ZpCTr4ZvDNcRAcLxpMTC0tZOK2Nc0tHIECQTEENMafOC/zLKt NMZnCuz/UD8GlaTjDGlMuweVUU8VOZ6M5Y0lYAGgyXO8NMgZkSDd4jBhieZUslTgN9yc U89amw5vZ8JRM2fzKry0KNZjPYfAwq8qTE/YYe3P3fB5HAvUDRYTvRn2pDgvW7j8TJcI dSTLU4UhVphkf1bx/5NXiCXvmtzSrGWzxD8QkgyQTjaTc3xK9FDebnZMUK1SxHBzUqzA nDY9+PJU47DQ7wXMEFXkkTpZKBsQLilMih19smSXPun866JglBIICDCsCdgOD7HP/P17 2dIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4PMS3EsUME0yXf2wLvBhrQWzVpCL17iuqXFXZ3vBBGU=; b=PD3+1iRHGk1oUeaWfk8T7X63ZHsLBTTmlvffu9iuUM8JSGMD8EFbGlAkTpm+wFC0eG TSb9OvV2BE6oDiLhlKB7gXh0RApVh2rTVH3OWLk9JLu9kiYpi8V0qDbynOf9EW+1pzFM KbnV0BiF2eBikBx19TssexinSdh7sKPIaXvQpaqe/tamLoKoML2eV98193qCn0CTr+sD K9pBKYu65aM1O2zXB1B9nUNh0NeC8XjC6wMyR/8uWVE9aRdFUOa0L5B19UJNt9yy3fuc IuF5cs8q74S3q4H/0xeeXeju32a760AoSOIiNl859/Hjk+sRsutxNbHdkCdkZQ1SQEuA Z6Ng== X-Gm-Message-State: AOAM531PoZg0jMq0mgnWpWdCDNYEBBLfihu417hFqCtwuvo5bvK8J250 5zjrQjeIOlAMsNr+6yk4oHZGww== X-Google-Smtp-Source: ABdhPJy+VHRxQjQATb+jYkzmG8h26CDN11px9sSgv57dZ833thRPpO+aVzUegA/K7WmJ+BvE4Tl2WQ== X-Received: by 2002:a05:600c:19cb:: with SMTP id u11mr2713543wmq.185.1632380831031; Thu, 23 Sep 2021 00:07:11 -0700 (PDT) Received: from localhost.localdomain ([2001:861:44c0:66c0:74cf:b054:76f4:7692]) by smtp.gmail.com with ESMTPSA id d2sm4380357wrc.32.2021.09.23.00.07.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Sep 2021 00:07:10 -0700 (PDT) From: Neil Armstrong To: tomba@kernel.org Cc: linux-omap@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, khilman@baylibre.com, Benoit Parrot , Neil Armstrong Subject: [PATCH v5 8/8] drm/omap: Add a 'right overlay' to plane state Date: Thu, 23 Sep 2021 09:07:01 +0200 Message-Id: <20210923070701.145377-9-narmstrong@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210923070701.145377-1-narmstrong@baylibre.com> References: <20210923070701.145377-1-narmstrong@baylibre.com> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=18742; i=narmstrong@baylibre.com; h=from:subject; bh=+661j1zEvtnPsQWVJxVE4D5iAlVcnnSzmTVhaUnKJeQ=; b=owEBbQKS/ZANAwAKAXfc29rIyEnRAcsmYgBhTCcigKd8NpYUe5LxbQdysXRRqUlvbRHszGL0OwN5 1QVBnVWJAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCYUwnIgAKCRB33NvayMhJ0UDKD/ 48G39msyg+6hkP2+AYsP+MKh43ZwCiIOeqlNdlsIDu+AmaherC4FKeuLWH03m2l9fgbHaJuztYaAX4 XzsOtrt22uKi9kBzLv+VKX5QKLoREW4Dc++2A4QIIQNHyPyVmd68HSmFmD6pEENw/wC3CaBeN3i80X pAafl7j39lV+tHRG+uJbR6QALvQ9J/LLIog6/ld7d7vq3vN3mQz+KsO27uph4viN7iy5SKGTo1QNcw jmNbmcYR5cvMHoVhbyZZuZLQn5wIsk/3VWwkRHvl1iwAAdgQHWIRH24nHakbNEY8k3NHv4DmuJhNTA tHl86IgnbMfHXlLbWRfC9Fx/Xa4k/+l7GwSWUNtXJRzP32B2jsbYXlqy96HT8Kjkd8SptxtpB3Si/M qjaSRZr8pqK4nXqms14IB4zsKU6+WmGyzweXqiqT8EQj9hqTbt5urYeFHC9aTSH7ZajemcrH1C74yn v9j+bENP8/Id3fOV43zS0dPZuo73OwgGyDMUBZcb2ySyY9u6ePAFXHx1Jki7JyQFNoYi5XdSxIAfED Ge2RXlCeKSLtxYHv735Jid9Vj2gqOMXdnhXeoD731Wu63VYZUOHn7lnjGvXtFbguQ6L7utYhnCLxbe +N2qYS0DJ8+n6mDhUFp3c3cxO+KjUzxYOtdbNsXXpdeIqRzm0+xrmO1XKCEw== X-Developer-Key: i=narmstrong@baylibre.com; a=openpgp; fpr=89EC3D058446217450F22848169AB7B1A4CFF8AE Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org From: Benoit Parrot If the drm_plane has a source width that's greater than the max width supported by a single hw overlay, then we assign a 'r_overlay' to it in omap_plane_atomic_check(). Both overlays should have the capabilities required to handle the source framebuffer. The only parameters that vary between the left and right hwoverlays are the src_w, crtc_w, src_x and crtc_x as we just even chop the fb into left and right halves. We also take care of not creating odd width size when dealing with YUV formats. Since both halves need to be 'appear' side by side the zpos is recalculated when dealing with dual overlay cases so that the other planes zpos is consistent. Depending on user space usage it is possible that on occasion the number of requested planes exceeds the numbers of overlays required to display them. In that case a failure would be returned for the plane that cannot be handled at that time. It is up to user space to make sure the H/W resource are not over-subscribed. Signed-off-by: Benoit Parrot Signed-off-by: Neil Armstrong --- drivers/gpu/drm/omapdrm/omap_drv.c | 91 +++++++++++++++++- drivers/gpu/drm/omapdrm/omap_fb.c | 33 ++++++- drivers/gpu/drm/omapdrm/omap_fb.h | 4 +- drivers/gpu/drm/omapdrm/omap_overlay.c | 31 +++++- drivers/gpu/drm/omapdrm/omap_overlay.h | 3 +- drivers/gpu/drm/omapdrm/omap_plane.c | 127 +++++++++++++++++++++++-- drivers/gpu/drm/omapdrm/omap_plane.h | 1 + 7 files changed, 276 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/omapdrm/omap_drv.c b/drivers/gpu/drm/omapdrm/omap_drv.c index c7912374d393..f088b6313950 100644 --- a/drivers/gpu/drm/omapdrm/omap_drv.c +++ b/drivers/gpu/drm/omapdrm/omap_drv.c @@ -117,6 +117,95 @@ static void omap_atomic_commit_tail(struct drm_atomic_state *old_state) dispc_runtime_put(priv->dispc); } +static int drm_atomic_state_normalized_zpos_cmp(const void *a, const void *b) +{ + const struct drm_plane_state *sa = *(struct drm_plane_state **)a; + const struct drm_plane_state *sb = *(struct drm_plane_state **)b; + + if (sa->normalized_zpos != sb->normalized_zpos) + return sa->normalized_zpos - sb->normalized_zpos; + else + return sa->plane->base.id - sb->plane->base.id; +} + +static int omap_atomic_update_normalize_zpos(struct drm_device *dev, + struct drm_atomic_state *state) +{ + struct drm_crtc *crtc; + struct drm_crtc_state *old_state, *new_state; + struct drm_plane *plane; + int c, i, n, inc; + int total_planes = dev->mode_config.num_total_plane; + struct drm_plane_state **states; + int ret = 0; + + states = kmalloc_array(total_planes, sizeof(*states), GFP_KERNEL); + if (!states) + return -ENOMEM; + + for_each_oldnew_crtc_in_state(state, crtc, old_state, new_state, c) { + if (old_state->plane_mask == new_state->plane_mask && + !new_state->zpos_changed) + continue; + + /* Reset plane increment and index value for every crtc */ + n = 0; + + /* + * Normalization process might create new states for planes + * which normalized_zpos has to be recalculated. + */ + drm_for_each_plane_mask(plane, dev, new_state->plane_mask) { + struct drm_plane_state *plane_state = + drm_atomic_get_plane_state(new_state->state, + plane); + if (IS_ERR(plane_state)) { + ret = PTR_ERR(plane_state); + goto done; + } + states[n++] = plane_state; + } + + sort(states, n, sizeof(*states), + drm_atomic_state_normalized_zpos_cmp, NULL); + + for (i = 0, inc = 0; i < n; i++) { + plane = states[i]->plane; + + states[i]->normalized_zpos = i + inc; + DRM_DEBUG_ATOMIC("[PLANE:%d:%s] updated normalized zpos value %d\n", + plane->base.id, plane->name, + states[i]->normalized_zpos); + + if (is_omap_plane_dual_overlay(states[i])) + inc++; + } + new_state->zpos_changed = true; + } + +done: + kfree(states); + return ret; +} + +static int omap_atomic_check(struct drm_device *dev, + struct drm_atomic_state *state) +{ + int ret; + + ret = drm_atomic_helper_check(dev, state); + if (ret) + return ret; + + if (dev->mode_config.normalize_zpos) { + ret = omap_atomic_update_normalize_zpos(dev, state); + if (ret) + return ret; + } + + return 0; +} + static const struct drm_mode_config_helper_funcs omap_mode_config_helper_funcs = { .atomic_commit_tail = omap_atomic_commit_tail, }; @@ -124,7 +213,7 @@ static const struct drm_mode_config_helper_funcs omap_mode_config_helper_funcs = static const struct drm_mode_config_funcs omap_mode_config_funcs = { .fb_create = omap_framebuffer_create, .output_poll_changed = drm_fb_helper_output_poll_changed, - .atomic_check = drm_atomic_helper_check, + .atomic_check = omap_atomic_check, .atomic_commit = drm_atomic_helper_commit, }; diff --git a/drivers/gpu/drm/omapdrm/omap_fb.c b/drivers/gpu/drm/omapdrm/omap_fb.c index 190afc564914..895e66b08a81 100644 --- a/drivers/gpu/drm/omapdrm/omap_fb.c +++ b/drivers/gpu/drm/omapdrm/omap_fb.c @@ -131,7 +131,9 @@ static u32 drm_rotation_to_tiler(unsigned int drm_rot) /* update ovl info for scanout, handles cases of multi-planar fb's, etc. */ void omap_framebuffer_update_scanout(struct drm_framebuffer *fb, - struct drm_plane_state *state, struct omap_overlay_info *info) + struct drm_plane_state *state, + struct omap_overlay_info *info, + struct omap_overlay_info *r_info) { struct omap_framebuffer *omap_fb = to_omap_framebuffer(fb); const struct drm_format_info *format = omap_fb->format; @@ -218,6 +220,35 @@ void omap_framebuffer_update_scanout(struct drm_framebuffer *fb, } else { info->p_uv_addr = 0; } + + if (r_info) { + info->width /= 2; + info->out_width /= 2; + + *r_info = *info; + + if (fb->format->is_yuv) { + if (info->width & 1) { + info->width++; + r_info->width--; + } + + if (info->out_width & 1) { + info->out_width++; + r_info->out_width--; + } + } + + r_info->pos_x = info->pos_x + info->out_width; + + r_info->paddr = get_linear_addr(fb, format, 0, + x + info->width, y); + if (fb->format->format == DRM_FORMAT_NV12) { + r_info->p_uv_addr = + get_linear_addr(fb, format, 1, + x + info->width, y); + } + } } /* pin, prepare for scanout: */ diff --git a/drivers/gpu/drm/omapdrm/omap_fb.h b/drivers/gpu/drm/omapdrm/omap_fb.h index c0e19aed8220..b75f0b5ef1d8 100644 --- a/drivers/gpu/drm/omapdrm/omap_fb.h +++ b/drivers/gpu/drm/omapdrm/omap_fb.h @@ -26,7 +26,9 @@ struct drm_framebuffer *omap_framebuffer_init(struct drm_device *dev, int omap_framebuffer_pin(struct drm_framebuffer *fb); void omap_framebuffer_unpin(struct drm_framebuffer *fb); void omap_framebuffer_update_scanout(struct drm_framebuffer *fb, - struct drm_plane_state *state, struct omap_overlay_info *info); + struct drm_plane_state *state, + struct omap_overlay_info *info, + struct omap_overlay_info *r_info); bool omap_framebuffer_supports_rotation(struct drm_framebuffer *fb); void omap_framebuffer_describe(struct drm_framebuffer *fb, struct seq_file *m); diff --git a/drivers/gpu/drm/omapdrm/omap_overlay.c b/drivers/gpu/drm/omapdrm/omap_overlay.c index f1a23c2203aa..a4f4be008bd5 100644 --- a/drivers/gpu/drm/omapdrm/omap_overlay.c +++ b/drivers/gpu/drm/omapdrm/omap_overlay.c @@ -63,12 +63,14 @@ omap_plane_find_free_overlay(struct drm_device *dev, int omap_overlay_assign(struct drm_atomic_state *s, struct drm_plane *plane, u32 caps, u32 fourcc, u32 crtc_mask, - struct omap_hw_overlay **overlay) + struct omap_hw_overlay **overlay, + struct omap_hw_overlay **r_overlay) { struct omap_drm_private *priv = s->dev->dev_private; struct omap_global_state *new_global_state, *old_global_state; struct drm_plane **overlay_map; - struct omap_hw_overlay *ovl; + struct omap_hw_overlay *ovl, *r_ovl; + u32 save_possible_crtcs; new_global_state = omap_get_global_state(s); if (IS_ERR(new_global_state)) @@ -90,12 +92,37 @@ int omap_overlay_assign(struct drm_atomic_state *s, struct drm_plane *plane, if (!ovl) return -ENOMEM; + /* in case we need to backtrack */ + save_possible_crtcs = ovl->possible_crtcs; + ovl->possible_crtcs = crtc_mask; overlay_map[ovl->idx] = plane; *overlay = ovl; + if (r_overlay) { + r_ovl = omap_plane_find_free_overlay(s->dev, + overlay_map, + caps, fourcc, + crtc_mask); + if (!r_ovl) { + ovl->possible_crtcs = save_possible_crtcs; + overlay_map[ovl->idx] = NULL; + *overlay = NULL; + return -ENOMEM; + } + + r_ovl->possible_crtcs = crtc_mask; + overlay_map[r_ovl->idx] = plane; + *r_overlay = r_ovl; + } + DBG("%s: assign to plane %s caps %x on crtc %x", (*overlay)->name, plane->name, caps, crtc_mask); + + if (r_overlay) { + DBG("%s: assign to right of plane %s caps %x on crtc %x", + (*r_overlay)->name, plane->name, caps, crtc_mask); + } } return 0; diff --git a/drivers/gpu/drm/omapdrm/omap_overlay.h b/drivers/gpu/drm/omapdrm/omap_overlay.h index d5033ee481c2..a800468511f1 100644 --- a/drivers/gpu/drm/omapdrm/omap_overlay.h +++ b/drivers/gpu/drm/omapdrm/omap_overlay.h @@ -30,7 +30,8 @@ int omap_hwoverlays_init(struct omap_drm_private *priv); void omap_hwoverlays_destroy(struct omap_drm_private *priv); int omap_overlay_assign(struct drm_atomic_state *s, struct drm_plane *plane, u32 caps, u32 fourcc, u32 crtc_mask, - struct omap_hw_overlay **overlay); + struct omap_hw_overlay **overlay, + struct omap_hw_overlay **r_overlay); void omap_overlay_release(struct drm_atomic_state *s, struct drm_plane *plane, struct omap_hw_overlay *overlay); diff --git a/drivers/gpu/drm/omapdrm/omap_plane.c b/drivers/gpu/drm/omapdrm/omap_plane.c index badbafeb3402..13bfda7305e9 100644 --- a/drivers/gpu/drm/omapdrm/omap_plane.c +++ b/drivers/gpu/drm/omapdrm/omap_plane.c @@ -24,6 +24,7 @@ struct omap_plane_state { struct drm_plane_state base; struct omap_hw_overlay *overlay; + struct omap_hw_overlay *r_overlay; /* right overlay */ }; #define to_omap_plane(x) container_of(x, struct omap_plane, base) @@ -34,6 +35,13 @@ struct omap_plane { const char *name; }; +bool is_omap_plane_dual_overlay(struct drm_plane_state *state) +{ + struct omap_plane_state *omap_state = to_omap_plane_state(state); + + return !!omap_state->r_overlay; +} + static int omap_plane_prepare_fb(struct drm_plane *plane, struct drm_plane_state *new_state) { @@ -63,15 +71,20 @@ static void omap_plane_atomic_update(struct drm_plane *plane, plane); struct omap_plane_state *new_omap_state; struct omap_plane_state *old_omap_state; - struct omap_overlay_info info; - enum omap_plane_id ovl_id; + struct omap_overlay_info info, r_info; + enum omap_plane_id ovl_id, r_ovl_id; int ret; + bool dual_ovl; new_omap_state = to_omap_plane_state(new_state); old_omap_state = to_omap_plane_state(old_state); + dual_ovl = is_omap_plane_dual_overlay(new_state); + /* Cleanup previously held overlay if needed */ omap_overlay_disable(old_state->state, plane, old_omap_state->overlay); + omap_overlay_disable(old_state->state, plane, + old_omap_state->r_overlay); if (!new_omap_state->overlay) { DBG("[PLANE:%d:%s] overlay_id: ??? (%p)", plane->base.id, plane->name, @@ -95,8 +108,11 @@ static void omap_plane_atomic_update(struct drm_plane *plane, info.color_encoding = new_state->color_encoding; info.color_range = new_state->color_range; + r_info = info; + /* update scanout: */ - omap_framebuffer_update_scanout(new_state->fb, new_state, &info); + omap_framebuffer_update_scanout(new_state->fb, new_state, &info, + dual_ovl ? &r_info : NULL); DBG("%s: %dx%d -> %dx%d (%d)", new_omap_state->overlay->name, info.width, info.height, @@ -104,18 +120,50 @@ static void omap_plane_atomic_update(struct drm_plane *plane, DBG("%d,%d %pad %pad", info.pos_x, info.pos_y, &info.paddr, &info.p_uv_addr); + if (dual_ovl) { + r_ovl_id = new_omap_state->r_overlay->overlay_id; + /* + * If the current plane uses 2 hw planes the very next + * zorder is used by the r_overlay so we just use the + * main overlay zorder + 1 + */ + r_info.zorder = info.zorder + 1; + + DBG("%s: %dx%d -> %dx%d (%d)", + new_omap_state->r_overlay->name, + r_info.width, r_info.height, + r_info.out_width, r_info.out_height, r_info.screen_width); + DBG("%d,%d %pad %pad", r_info.pos_x, r_info.pos_y, + &r_info.paddr, &r_info.p_uv_addr); + } + /* and finally, update omapdss: */ ret = dispc_ovl_setup(priv->dispc, ovl_id, &info, omap_crtc_timings(new_state->crtc), false, omap_crtc_channel(new_state->crtc)); if (ret) { - dev_err(plane->dev->dev, "Failed to setup plane %s\n", + dev_err(plane->dev->dev, "Failed to setup plane1 %s\n", omap_plane->name); dispc_ovl_enable(priv->dispc, ovl_id, false); return; } dispc_ovl_enable(priv->dispc, ovl_id, true); + + if (dual_ovl) { + ret = dispc_ovl_setup(priv->dispc, r_ovl_id, &r_info, + omap_crtc_timings(new_state->crtc), false, + omap_crtc_channel(new_state->crtc)); + if (ret) { + dev_err(plane->dev->dev, "Failed to setup plane2 %s\n", + omap_plane->name); + dispc_ovl_enable(priv->dispc, r_ovl_id, false); + dispc_ovl_enable(priv->dispc, ovl_id, false); + return; + } + + dispc_ovl_enable(priv->dispc, r_ovl_id, true); + } } static void omap_plane_atomic_disable(struct drm_plane *plane, @@ -140,6 +188,11 @@ static void omap_plane_atomic_disable(struct drm_plane *plane, omap_overlay_disable(old_state->state, plane, old_omap_state->overlay); new_omap_state->overlay = NULL; + if (is_omap_plane_dual_overlay(old_state)) { + omap_overlay_disable(old_state->state, plane, + old_omap_state->r_overlay); + new_omap_state->r_overlay = NULL; + } } #define FRAC_16_16(mult, div) (((mult) << 16) / (div)) @@ -158,6 +211,8 @@ static int omap_plane_atomic_check(struct drm_plane *plane, u32 fourcc; u32 caps = 0; bool new_hw_overlay = false; + bool new_r_hw_overlay = false; + bool is_fourcc_yuv = false; int min_scale, max_scale; int ret; struct drm_crtc_state *crtc_state; @@ -187,9 +242,31 @@ static int omap_plane_atomic_check(struct drm_plane *plane, if (new_plane_state->src_h > height_fp || new_plane_state->crtc_h > height) return -EINVAL; - if (new_plane_state->src_w > width_fp || new_plane_state->crtc_w > width) - return -EINVAL; - + if (new_plane_state->fb) + is_fourcc_yuv = new_plane_state->fb->format->is_yuv; + + if (new_plane_state->src_w > width_fp || new_plane_state->crtc_w > width) { + if (is_fourcc_yuv && + (((new_plane_state->src_w >> 16) / 2 & 1) || + new_plane_state->crtc_w / 2 & 1)) { + /* + * When calculating the split overlay width + * and it yield an odd value we will need to adjust + * the indivual width +/- 1. So make sure it fits + */ + if (new_plane_state->src_w <= ((2 * width - 1) << 16) && + new_plane_state->crtc_w <= (2 * width - 1)) + new_r_hw_overlay = true; + else + return -EINVAL; + } else { + if (new_plane_state->src_w <= (2 * width_fp) && + new_plane_state->crtc_w <= (2 * width)) + new_r_hw_overlay = true; + else + return -EINVAL; + } + } /* * Note: these are just sanity checks to filter out totally bad scaling @@ -239,32 +316,55 @@ static int omap_plane_atomic_check(struct drm_plane *plane, fourcc)) new_hw_overlay = true; } + /* + * check if we need two overlays and only have 1 or + * if we had 2 overlays but will only need 1 + */ + if ((new_r_hw_overlay && !omap_state->r_overlay) || + (!new_r_hw_overlay && omap_state->r_overlay)) + new_hw_overlay = true; if (new_hw_overlay) { struct omap_hw_overlay *old_ovl = omap_state->overlay; + struct omap_hw_overlay *old_r_ovl = + omap_state->r_overlay; struct omap_hw_overlay *new_ovl = NULL; + struct omap_hw_overlay *new_r_ovl = NULL; omap_overlay_release(state, plane, old_ovl); + omap_overlay_release(state, plane, old_r_ovl); ret = omap_overlay_assign(state, plane, caps, - fourcc, crtc_mask, &new_ovl); + fourcc, crtc_mask, &new_ovl, + new_r_hw_overlay ? + &new_r_ovl : NULL); if (ret) { DBG("%s: failed to assign hw_overlay(s)!", plane->name); omap_state->overlay = NULL; + omap_state->r_overlay = NULL; return ret; } omap_state->overlay = new_ovl; + if (new_r_hw_overlay) + omap_state->r_overlay = new_r_ovl; + else + omap_state->r_overlay = NULL; } } else { omap_overlay_release(state, plane, omap_state->overlay); + omap_overlay_release(state, plane, omap_state->r_overlay); omap_state->overlay = NULL; + omap_state->r_overlay = NULL; } if (omap_state->overlay) DBG("plane: %s overlay_id: %d", plane->name, omap_state->overlay->overlay_id); + if (omap_state->r_overlay) + DBG("plane: %s r_overlay_id: %d", plane->name, + omap_state->r_overlay->overlay_id); return 0; } @@ -370,6 +470,17 @@ static void omap_plane_atomic_print_state(struct drm_printer *p, drm_printf(p, "\t\tpossible_crtcs=0x%x\n", omap_state->overlay->possible_crtcs); } + + drm_printf(p, "\tr_overlay=%s\n", omap_state->r_overlay ? + omap_state->r_overlay->name : "(null)"); + if (omap_state->r_overlay) { + drm_printf(p, "\t\tidx=%d\n", omap_state->r_overlay->idx); + drm_printf(p, "\t\toverlay_id=%d\n", + omap_state->r_overlay->overlay_id); + drm_printf(p, "\t\tcaps=0x%x\n", omap_state->r_overlay->caps); + drm_printf(p, "\t\tpossible_crtcs=0x%x\n", + omap_state->r_overlay->possible_crtcs); + } } static int omap_plane_atomic_set_property(struct drm_plane *plane, diff --git a/drivers/gpu/drm/omapdrm/omap_plane.h b/drivers/gpu/drm/omapdrm/omap_plane.h index 0c28fe8ffa20..a9a33e12722a 100644 --- a/drivers/gpu/drm/omapdrm/omap_plane.h +++ b/drivers/gpu/drm/omapdrm/omap_plane.h @@ -22,5 +22,6 @@ struct drm_plane *omap_plane_init(struct drm_device *dev, u32 possible_crtcs); void omap_plane_install_properties(struct drm_plane *plane, struct drm_mode_object *obj); +bool is_omap_plane_dual_overlay(struct drm_plane_state *state); #endif /* __OMAPDRM_PLANE_H__ */