From patchwork Tue Mar 28 16:50:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 2821 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 660C4414B2 for ; Tue, 28 Mar 2023 18:51:45 +0200 (CEST) Received: by mail-pl1-f198.google.com with SMTP id u18-20020a170902e5d200b001a1d70ea3b6sf7894661plf.6 for ; Tue, 28 Mar 2023 09:51:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1680022304; cv=pass; d=google.com; s=arc-20160816; b=uQW+/mzldyH1kLNctDJ/1Xh9RbxczXHrL9XhFis/PqWGTnz1Uv3moL22LC+z8RC1+/ qv6xxOUh13JWvINf6bMXKBAxTMpSlwonarkiW43m3+gOzQIn8ifs1IvEd6CC0uqxwS1v 9wtCp/4IMKhHMYPZNwCb/XI0lv6VcylK1C9Gfi9I5zxBtb2bLT5C99afT5vl0jiGu/CD NJo+rAQgFC16DTvt9SYzRwC0uOHuyF6hgEhtSpoAtivo2ygjSfLJoYxLfmp9uFU1Xbk1 u+UPpMhy5ycRwxeRPGokN5vLmkuLPrF7Q2R2Gh6G39gn8FckEx4mhgUPdxDv08uh3w5X rYyQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:message-id:date:subject:cc:to :from:dkim-signature; bh=JzRP1QwezYj3bC8PmQ/08TLmQyexxGjohwaTfVR7AXM=; b=0Sh6MVxK7ptciD0b4dS31g66jCNwGpsZZxjzzgWshlXlXpEsZBmB8s7VV4DHcbYSqD 4wUlqziJIV1sUDWT40KPMRSK0RxaFvxlQKRsWr9qbpEx6+Jc5LNlAEV0TQadTWcM/KdL coqqBOId1SpZMBdsIOiLqiPEw+O78HPMyOrTcmYoZ3Z2dKY9fqo28ZRCQTBmH1iQINHJ lw1yLzQApwZ56B01uviCoru4Ykn+9+X6Sar6Tl9vVKLqblOs0LrDxFb86oH2A+qEfB/K CBdlMBKOobh0Yea6jOs2IARyFlx6vFDjAUVlrQ8dXZa5iGSqGAyJFU0UoOsqRbFLAS4M V/Yw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=aZBXu1mi; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1680022304; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:message-id:date:subject:cc:to:from :from:to:cc:subject:date:message-id:reply-to; bh=JzRP1QwezYj3bC8PmQ/08TLmQyexxGjohwaTfVR7AXM=; b=mGdhUevj4ZAlBhTK+VxjsTgYybo2gxVOFQXivVFPCbPIlxfp4F+7eSWFEmIKeTHo3L 0yU9m5znNMSfdU2gmr5CU+hvF8UMyxfze6A/rS/2FA3wCP+0Ga80f2P0rOYzHjUtj2cH hCK2zTE5WJr+9+SUpij5yoJu6L7iyqEnsqNR8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680022304; h=list-unsubscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JzRP1QwezYj3bC8PmQ/08TLmQyexxGjohwaTfVR7AXM=; b=JiY0hRfiDGGN4xgQcNQeWuZVFLrV+HRbqHsmaEOm5UVwU9rp3fROus1cJR+E1WowjY yuAhiagFmF3gZJrCgssWqFymW1JzXf7yR+pPDhAxDCrl4vpcdIJFB/IFq8TwLwFAabyr 0sYMWovHDUx2WKShcF89/jEpot7YlpOLhudCuCFD6BP9gXNW7+nN9EyRT0wNHIZ7a5TO 2YmK4U1Khg5B4fPvJjBxcewwB2USzyEuj6+JxHzRGF0Nzk7Rn28zEiBvfZDe6J2Rp9Ua Xy/kVLy+gk3oZtMAHcRNHB4UnKKaFcdATJlU0laSkXp50iU5MBLEHzH2e68hwIWS4q/v pphQ== X-Gm-Message-State: AAQBX9fW87jgLYKotlCkQvUvf2TW7vkEeoNxlJUrY3e1/Sj6n5vN2aed S646PRQtSUR8aZijxPb0x0/HTrfK X-Google-Smtp-Source: AKy350bdxudAKDibAoCoSHHSgd/LQtfPJqyuVRxT2nQd6jktqmp0+rUiafzzfuQRwFQoYMOhvVdKCg== X-Received: by 2002:a05:6a00:a09:b0:625:dc5b:9d1d with SMTP id p9-20020a056a000a0900b00625dc5b9d1dmr8719026pfh.0.1680022303955; Tue, 28 Mar 2023 09:51:43 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a63:2012:0:b0:503:a9:c2b8 with SMTP id g18-20020a632012000000b0050300a9c2b8ls1902140pgg.7.-pod-prod-gmail; Tue, 28 Mar 2023 09:51:43 -0700 (PDT) X-Received: by 2002:aa7:9ace:0:b0:626:248d:4ece with SMTP id x14-20020aa79ace000000b00626248d4ecemr15008190pfp.30.1680022302786; Tue, 28 Mar 2023 09:51:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680022302; cv=none; d=google.com; s=arc-20160816; b=0iBAsHzNp4ZrZKoY8pu/HjdvBgM82S+8HC68B4SuBeOioMllpLpzfDgksX1PkFp2qZ uwFrNAcgKrMpWuazdxB+md7Rdz57Uf2YfGoQxzSBXdzA3Z0ePZr1sf32QgOWLDz9CbbS hR3PTIFg3GZJifP7+4Pyh5eUsMrkHZQe2vc+tCTB3nZmbKg1lVRwigbKd76Fgxn7u+L6 CnJIwl0el4xHhXTGvrF6OSnYmrNuDDpJZg/kQ3DW4QxptmVCmbGzdzBgX8ylq0/UDpHZ BC/DrzGD42ZfneTbm9v1oHENNxuzFTNxjWQyVvRkMuSTlLkvT37N0/ilJxEZJWl/EiTk IysA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=y+csMJlZsqxFhr/e1f6wWRnXfPCTpSy58rS62NCEqwE=; b=Ug6ULPhr4+ok+QBxfPdKSTMPLsRIpNSy7OCjF6mIhYEP6agvMIJ+pzPPvPCIP9CSSr s01OxEmCID9Iz/AefnaEHvEwiYpqo81mm0XCe5hi9StTnHhbGhVnrSDk5dqYK6JERVvI WYiXWdn3OB1t9Ks8Eky9Gh6WAtsycKMVkZar/z7uGR4YB5+OQnjpEykPkvNJRnpaQFcj Vw58b42LGXo73j1UNybA648zZC2VWDcYL6D+5vClsmbTgKC9kp9kti1yGcIPday7qVNz zlExFzINq3Z5/84wwT212LC+6M7q1rCBYfeVcWHR9x9Iy5HE2zKuIGXLKIa2tUxRAtK4 H1Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=aZBXu1mi; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id d7-20020aa78e47000000b006262684200csor13285263pfr.7.2023.03.28.09.51.42 for (Google Transport Security); Tue, 28 Mar 2023 09:51:42 -0700 (PDT) Received-SPF: pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Received: by 2002:a62:1b12:0:b0:627:f9ac:8a33 with SMTP id b18-20020a621b12000000b00627f9ac8a33mr14166662pfb.13.1680022302308; Tue, 28 Mar 2023 09:51:42 -0700 (PDT) Received: from localhost.localdomain ([2405:201:c00a:a047:2fbc:aff5:d52a:cc2c]) by smtp.gmail.com with ESMTPSA id 15-20020aa7910f000000b0062c0cfbb264sm7583700pfh.93.2023.03.28.09.51.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 09:51:41 -0700 (PDT) From: Jagan Teki To: Dave Stevenson , Maarten Lankhorst , Thomas Zimmermann , David Airlie , Daniel Vetter , Andrzej Hajda , Neil Armstrong Cc: Marek Vasut , linux-amarula , Jagan Teki Subject: [PATCH 1/2] drm/bridge: Fix improper bridge init order with pre_enable_prev_first Date: Tue, 28 Mar 2023 22:20:57 +0530 Message-Id: <20230328165058.1100680-1-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Original-Sender: jagan@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=aZBXu1mi; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , For a given bridge pipeline if any bridge sets pre_enable_prev_first flag then the pre_enable for the previous bridge will be called before pre_enable of this bridge and opposite is done for post_disable. These are the potential bridge flags to alter bridge init order in order to satisfy the MIPI DSI host and downstream panel or bridge to function. However the existing pre_enable_prev_first logic with associated bridge ordering has broken for both pre_enable and post_disable calls. [pre_enable] The altered bridge ordering has failed if two consecutive bridges on a given pipeline enables the pre_enable_prev_first flag. Example: - Panel - Bridge 1 - Bridge 2 pre_enable_prev_first - Bridge 3 - Bridge 4 pre_enable_prev_first - Bridge 5 pre_enable_prev_first - Bridge 6 - Encoder In this example, Bridge 4 and Bridge 5 have pre_enable_prev_first. The logic looks for a bridge which enabled pre_enable_prev_first flag on each iteration and assigned the previou bridge to limit pointer if the bridge doesn't enable pre_enable_prev_first flags. If control found Bridge 2 is pre_enable_prev_first then the iteration looks for Bridge 3 and found it is not pre_enable_prev_first and assigns it's previous Bridge 4 to limit pointer and calls pre_enable of Bridge 3 and Bridge 2 and assign iter pointer with limit which is Bridge 4. Here is the actual problem, for the next iteration control look for Bridge 5 instead of Bridge 4 has iter pointer in previous iteration moved to Bridge 4 so this iteration skips the Bridge 4. The iteration found Bridge 6 doesn't pre_enable_prev_first flags so the limit assigned to Encoder. From next iteration Encoder skips as it is the last bridge for reverse order pipeline. So, the resulting pre_enable bridge order would be, - Panel, Bridge 1, Bridge 3, Bridge 2, Bridge 6, Bridge 5. This patch fixes this by assigning limit to next pointer instead of previous bridge since the iteration always looks for bridge that does NOT request prev so assigning next makes sure the last bridge on a given iteration what exactly the limit bridge is. So, the resulting pre_enable bridge order with fix would be, - Panel, Bridge 1, Bridge 3, Bridge 2, Bridge 6, Bridge 5, Bridge 4, Encoder. [post_disable] The altered bridge ordering has failed if two consecutive bridges on a given pipeline enables the pre_enable_prev_first flag. Example: - Panel - Bridge 1 - Bridge 2 pre_enable_prev_first - Bridge 3 - Bridge 4 pre_enable_prev_first - Bridge 5 pre_enable_prev_first - Bridge 6 - Encoder In this example Bridge 5 and Bridge 4 have pre_enable_prev_first. The logic looks for a bridge which enabled pre_enable_prev_first flags on each iteration and assigned the previou bridge to next and next to limit pointer if the bridge does enable pre_enable_prev_first flag. If control starts from Bridge 6 then it found next Bridge 5 is pre_enable_prev_first and immediately the next assigned to previous Bridge 6 and limit assignments to next Bridge 6 and call post_enable of Bridge 6 even though the next consecutive Bridge 5 is enabled with pre_enable_prev_first. This clearly misses the logic to find the state of next conducive bridge as everytime the next and limit assigns previous bridge if given bridge enabled pre_enable_prev_first. So, the resulting post_disable bridge order would be, - Encoder, Bridge 6, Bridge 5, Bridge 4, Bridge 3, Bridge 2, Bridge 1, Panel. This patch fixes this by assigning next with previou bridge only if the bridge doesn't enable pre_enable_prev_first flag and the next further assign it to limit. This way we can find the bridge that NOT requested prev to disable last. So, the resulting pre_enable bridge order with fix would be, - Encoder, Bridge 4, Bridge 5, Bridge 6, Bridge 2, Bridge 3, Bridge 1, Panel. Validated the bridge init ordering by incorporating dummy bridges in the sun6i-mipi-dsi pipeline Fixes: 4fb912e5e190 ("drm/bridge: Introduce pre_enable_prev_first to alter bridge init order") Signed-off-by: Jagan Teki --- drivers/gpu/drm/drm_bridge.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c index c3d69af02e79..052a8e6c9961 100644 --- a/drivers/gpu/drm/drm_bridge.c +++ b/drivers/gpu/drm/drm_bridge.c @@ -684,11 +684,17 @@ void drm_atomic_bridge_chain_post_disable(struct drm_bridge *bridge, */ list_for_each_entry_from(next, &encoder->bridge_chain, chain_node) { - if (next->pre_enable_prev_first) { + if (!next->pre_enable_prev_first) { next = list_prev_entry(next, chain_node); limit = next; break; } + + if (list_is_last(&next->chain_node, + &encoder->bridge_chain)) { + limit = next; + break; + } } /* Call these bridges in reverse order */ @@ -771,7 +777,7 @@ void drm_atomic_bridge_chain_pre_enable(struct drm_bridge *bridge, /* Found first bridge that does NOT * request prev to be enabled first */ - limit = list_prev_entry(next, chain_node); + limit = next; break; } }