From patchwork Tue Mar 4 11:10:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 14000488 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 84212C282D3 for ; Tue, 4 Mar 2025 11:11:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F376C10E306; Tue, 4 Mar 2025 11:11:26 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="MK+NjEmm"; dkim-atps=neutral Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by gabe.freedesktop.org (Postfix) with ESMTPS id B76D810E592 for ; Tue, 4 Mar 2025 11:11:25 +0000 (UTC) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 502095C5AF4; Tue, 4 Mar 2025 11:09:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99A02C4CEEC; Tue, 4 Mar 2025 11:11:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741086684; bh=Xt3tyJYOhvKRkneUvpuVFBQt7kxeuH06uiim8XR86PY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=MK+NjEmm/Dw4ZX3fI1zVULGQFMfi2ghzwqaqWDkQEZrdT1Wwb3mOqlH1MDPQQ1CgZ ijbeqw/G5nkKnWMZG1oyCK6FDyUFMUDLDGy2C62bfu0TVx9x8MOSyGkYe1E/a1IXsF LbzApN17PjjX5abvl0VkO3uIDCPAIyPOIFJ+6+detlyxhGEfPZSXmecwzfpN4xF33E dAdbHHO1uuuQAxa6JQ4cIzSBnlZlntVBpf9CgRGXdQPvlyZihHrT5JVRly6GMa3mSO dyfjjtUb38xKvFwkZ22NoCKayMrcL7RZtD15Yi20IOJY5yyrP5DVw0L8TYKqZo6Cxj ql3rgj3i/eLng== From: Maxime Ripard Date: Tue, 04 Mar 2025 12:10:51 +0100 Subject: [PATCH v5 08/16] drm/bridge: Add helper to reset bridge pipeline MIME-Version: 1.0 Message-Id: <20250304-bridge-connector-v5-8-aacf461d2157@kernel.org> References: <20250304-bridge-connector-v5-0-aacf461d2157@kernel.org> In-Reply-To: <20250304-bridge-connector-v5-0-aacf461d2157@kernel.org> To: Maarten Lankhorst , Thomas Zimmermann , David Airlie , Simona Vetter , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Douglas Anderson Cc: Herve Codina , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Maxime Ripard , Simona Vetter X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3565; i=mripard@kernel.org; h=from:subject:message-id; bh=Xt3tyJYOhvKRkneUvpuVFBQt7kxeuH06uiim8XR86PY=; b=owGbwMvMwCmsHn9OcpHtvjLG02pJDOnH7u+3iAu7/J7B4azGRXfN1H0r120t4PkreXBeZfmPS n2+jd2XOqayMAhzMsiKKbI8kQk7vbx9cZWD/cofMHNYmUCGMHBxCsBEzixhbLjJciVtpe3OHx19 80RPFF4V2LR9TVDlSWX/QlZp5z5fX46+ivrkl4yL+sqlNpZI354ayVjvKiAb+cB4+9k6b/+TlU9 U7k8MWZ33SDv35L2cKNN/q3y5U3rZ4nTbYzuO3bQ/YWJ96h4A X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Let's provide an helper to make it easier for bridge drivers to power-cycle their bridge. In order to avoid a circular dependency between that new helper and drm_atomic_helper_reset_crtc(), this new helper will be in a drm_bridge_helper.c file to follow the pattern we have for other objects. Co-developed-by: Simona Vetter Signed-off-by: Maxime Ripard --- drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_bridge_helper.c | 55 +++++++++++++++++++++++++++++++++++++ include/drm/drm_bridge_helper.h | 12 ++++++++ 3 files changed, 68 insertions(+) diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index 4cd054188faf0b3dec442efd99ae52604541bce1..5a332f7d3ecccb6e5e1fb9fb811eab7aa5a84a21 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile @@ -131,10 +131,11 @@ obj-$(CONFIG_DRM_TTM_HELPER) += drm_ttm_helper.o # drm_kms_helper-y := \ drm_atomic_helper.o \ drm_atomic_state_helper.o \ + drm_bridge_helper.o \ drm_crtc_helper.o \ drm_damage_helper.o \ drm_flip_work.o \ drm_format_helper.o \ drm_gem_atomic_helper.o \ diff --git a/drivers/gpu/drm/drm_bridge_helper.c b/drivers/gpu/drm/drm_bridge_helper.c new file mode 100644 index 0000000000000000000000000000000000000000..521df9d5dcb3fef842a95cdb2865a8b8d09b0fbe --- /dev/null +++ b/drivers/gpu/drm/drm_bridge_helper.c @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include +#include +#include +#include +#include + +/** + * drm_bridge_helper_reset_crtc - Reset the pipeline feeding a bridge + * @bridge: DRM bridge to reset + * @ctx: lock acquisition context + * + * Reset a @bridge pipeline. It will power-cycle all active components + * between the CRTC and connector that bridge is connected to. + * + * Returns: + * + * 0 on success or a negative error code on failure. If the error + * returned is EDEADLK, the whole atomic sequence must be restarted. + */ +int drm_bridge_helper_reset_crtc(struct drm_bridge *bridge, + struct drm_modeset_acquire_ctx *ctx) +{ + struct drm_connector *connector; + struct drm_encoder *encoder = bridge->encoder; + struct drm_device *dev = encoder->dev; + struct drm_crtc *crtc; + int ret; + + ret = drm_modeset_lock(&dev->mode_config.connection_mutex, ctx); + if (ret) + return ret; + + connector = drm_atomic_get_connector_for_encoder(encoder, ctx); + if (IS_ERR(connector)) { + ret = PTR_ERR(connector); + goto out; + } + + if (!connector->state) { + ret = -EINVAL; + goto out; + } + + crtc = connector->state->crtc; + ret = drm_atomic_helper_reset_crtc(crtc, ctx); + if (ret) + goto out; + +out: + drm_modeset_unlock(&dev->mode_config.connection_mutex); + return ret; +} +EXPORT_SYMBOL(drm_bridge_helper_reset_crtc); diff --git a/include/drm/drm_bridge_helper.h b/include/drm/drm_bridge_helper.h new file mode 100644 index 0000000000000000000000000000000000000000..6c35b479ec2a84aa43283351a6f18e49a9f9c177 --- /dev/null +++ b/include/drm/drm_bridge_helper.h @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#ifndef __DRM_BRIDGE_HELPER_H_ +#define __DRM_BRIDGE_HELPER_H_ + +struct drm_bridge; +struct drm_modeset_acquire_ctx; + +int drm_bridge_helper_reset_crtc(struct drm_bridge *bridge, + struct drm_modeset_acquire_ctx *ctx); + +#endif // __DRM_BRIDGE_HELPER_H_