Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5CED606A327 for ; Tue, 1 Dec 2026 20:27:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=1ZY+Gf9D Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4839310FCFF; Tue, 1 Dec 2026 20:27:27 +0000 (UTC) Received: from PH8PR06CU001.outbound.protection.outlook.com (mail-westus3azon11012024.outbound.protection.outlook.com [40.107.209.24]) by gabe.freedesktop.org (Postfix) with ESMTPS id 59AC410FCFB for ; Tue, 1 Dec 2026 20:27:20 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ih1ht13/AeFa2fQnyKu/FHJ8pU0Gz76+Lxs7DyfBu0tlv7nV0MlJVabXTPhBrfFFXmYZXoUXXP/lfM9hIPxzHbxqZetLmTmiDOMKGCvE48f7Ol+D3Nmhns5jwXzTFuUgDWMGY2TwSXAIVfPIGzdIww00qNBXYQM+N8t6rd9aaErvsUatIQCLpdIcg58l3TD1NFbFQimEwh6Y1i6J/5WBekiZL71XgRv01Uqqp9wp5H2SBGXpYqpPyWskcsZm9ma0J3efO/tO1CbEUFWkcuVbKm0p6TSXFBRgsoJoVynhZkCcJBrJscv7tcmrywIXS+Pk5/J5mf65gNjad2+WfRv41w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=qjVQp38PutgvTRVoiUDs3e0PwrF6kK22ED+k5xO1lOQ=; b=lHUXBqISNzmjMbQ+FDW+DLzvdKTL/oCL3iP4lEOMFbtlGj4uUQSnkiLpCe3JJVcIZVvuQWJZe2VP84xLEL2X4W1lY0E0prB8xa92Klyo2ElFUv3YRxQaM/WXID7RP00ZhB/n5wHOsGoYFEzwj5zHGJuc0nmWS3JJIqH93sGYutiFfoz6zgYblBuxL1GWyLT+NTLbzwaCFiFILWAftrwjCO00q0wsaJRRHabCnASmUbV6BErhIJJzrHXA/CHONz9eUumUoVxIrKFfTPu9F4pmjpQc0OJr+/Nrcm2gOcZXjR4Phd4r8OOv0+m7li5iwNPAs2LZxufJCR3ZkGb3MO+Kew== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.freedesktop.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qjVQp38PutgvTRVoiUDs3e0PwrF6kK22ED+k5xO1lOQ=; b=1ZY+Gf9DBVMRpZoJRFyEU8GxgK98NQ13YcooaCZSBHBWUZMja7xj6av3qv07xnZ5YuY8TZ001y20TdOYYqDVLMOA4wHphD0dAQuAd2DpZ5tT9kdYCGmhlFCOyB/paJmBHBA5OGTS9DrWl0VmRrKVzCploy0lVmjOVIaS+c5IPi4= Received: from CH2PR08CA0002.namprd08.prod.outlook.com (2603:10b6:610:5a::12) by DS0PR12MB8479.namprd12.prod.outlook.com (2603:10b6:8:155::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Tue, 1 Dec 2026 20:27:08 +0000 Received: from DSM2EPF0000000E.namprd02.prod.outlook.com (2603:10b6:610:5a:cafe::61) by CH2PR08CA0002.outlook.office365.com (2603:10b6:610:5a::12) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.592.13 via Frontend Transport; Tue, 1 Dec 2026 20:27:08 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by DSM2EPF0000000E.mail.protection.outlook.com (10.167.23.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.5 via Frontend Transport; Tue, 1 Dec 2026 20:27:08 +0000 Received: from georzhanmkm.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Tue, 1 Dec 2026 14:26:41 -0600 From: George Zhang To: CC: Harry Wentland , Leo Li , Aurabindo Pillai , Roman Li , Wayne Lin , Tom Chung , "Fangzhi Zuo" , Dan Wheeler , Ray Wu , Ivan Lipski , Alex Hung , James Lin , Chenyu Chen , Tony Cheng , Jun Lei , Dillon Varone , George Zhang Subject: [PATCH v2 28/30] drm/amd/display: Move shared dcn401 builder code to its own file Date: Tue, 1 Dec 2026 15:23:02 -0500 Message-ID: <20261201202451.463794-30-george.zhang@amd.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261201202451.463794-2-george.zhang@amd.com> References: <20261201202451.463794-2-george.zhang@amd.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DSM2EPF0000000E:EE_|DS0PR12MB8479:EE_ X-MS-Office365-Filtering-Correlation-Id: 71caa428-2b74-4ae0-cc52-08df4fe978f8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|376014|36860700016|1800799024|23010399003|11063799006|5023799004|6133799003|261009223027099003|261009221227099003|3023799007|10067099003|56012099006|261021123027099003|261021121427099003|261026140227099003|261102130727099003|261102123227099003|261028144727099003|261022105027099003|261022075727099003|22082099003|18002099003|261026121527099003; X-Microsoft-Antispam-Message-Info: lhplpTUtYlVkhxSramXqq7LaFGDD87z/AXT9Gic3WgIcuUwWMsmtsMftSNU8YPmIukwS92xaU1ysj5x44AX1zD/PMUmu0xWzYIgWl2xqf2ndQ8XZpWVZjapdopQ623w25a8T+2AwFo50G/3Tbjv1elAmf/J/ME3u1v/EFBzhkho9RjDs9FE0EAz5InzTPnCm8Q4wAKsXF4EGf2iqopOQZ8DZkNSE2P+bGhXAlVczRrbY8IG51glZjyL8wGesZbtcet6Kgonaka+kkEL/xNGJT1V+nznuV6RpbiIZwvh3Me4LTtkXZ9mCZSE/+1DLL6guhH3Ws7U9WO0trwu5m0KSGdB3Ns7EFoBd4IOskGnLKv08ThxJkB+LJxMzFygcswnP1pml4TkKMnPR9jRmHv6YHqjaTQB0fiOYPKFNpRfTTQK2r4n7b6YTwGN0rrXhpZSfDju3yV5VrnaHRjEyf2jsDylBtjyPJf9LgIMBgsHZG5MJWqBGv3ZuD7ZBxjdEIJIyl4ymy8bFrsR9KhUxgPDkvJPxjIakIxxcKwJAN0mThacgHB+ISo0yZolG+vr2aNzNt03ae85c2bD4JOoardly5+1KfpJ6TKCL1BcmAfZsKCT2tTxv/OWiV2XhnjsGA5Yjr36ixk41JF8RkUBlkFED1jcwvV9coR4ZUDLSg3nlxOy8n86QlvEFHKzU8MhfCs/wuYMF9iFM9P+GwklqFSSqQA== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:satlexmb07.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(82310400026)(376014)(36860700016)(1800799024)(23010399003)(11063799006)(5023799004)(6133799003)(261009223027099003)(261009221227099003)(3023799007)(10067099003)(56012099006)(261021123027099003)(261021121427099003)(261026140227099003)(261102130727099003)(261102123227099003)(261028144727099003)(261022105027099003)(261022075727099003)(22082099003)(18002099003)(261026121527099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: K6PiFYvKvjvvgVCAG9LriXH7CVicHeAMyhGx8+iuCeW4X1Q/Jh0/ZL1tMltsUraba8BQRKr3rf95C0HsTuWd1bTJ8l8yj6zIaFfu9hRgPO0CFGKjNMbS2eddMUOvGS5P6rrQvck2h0qCsdkt3LzarjUnFI66DHq9kWSDgNvYN/pCK9eAR9E8dViiCQaaiZbW4EebZJx1r0icA7WSOYoqUqdDIGn8s+h8qoA2Fyb4CgJu0ivXpgQT3VQWO1C8Vfrd01cxAHh3T2qNbMf9jtQJcLZ0cqPXwEo2J5IEEVI4ZALvq8Z5ObXO7MElNOHuIJo9jHy2508W6EtBpL2XJUu9Gs9Ib379V8odFnwVvuyW1UsXX1Y5rhsyQpke7KSCuZLrSHTKMPUtWXr8nGypzPoY+9CFn+RKMKOW5ayUNenzZNnKMr+5sDhqF0MsLan2LuUC X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2026 20:27:08.4625 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 71caa428-2b74-4ae0-cc52-08df4fe978f8 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DSM2EPF0000000E.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8479 X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "amd-gfx" X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 From: Tony Cheng [Why] The dcn401 DC2 seamless builder file also holds the code that the non-seamless builder uses, so a change to that code reads as a change to the seamless update. [How] Move the support checks, the pipe removal tables and the step walkers to dcn401_builder_internal.c, unchanged. Export the two helpers both files call. Add the file to the build lists. Cc: Jun Lei Cc: Dillon Varone Signed-off-by: Tony Cheng Signed-off-by: George Zhang --- drivers/gpu/drm/amd/display/dc/Makefile | 1 + .../dc/bls_builder/dcn401_builder_internal.c | 1817 +++++++++++++++++ .../dc/bls_builder/dcn401_builder_internal.h | 6 + .../dc/bls_builder/dcn401_seamless_builder.c | 1792 ---------------- 4 files changed, 1824 insertions(+), 1792 deletions(-) create mode 100644 drivers/gpu/drm/amd/display/dc/bls_builder/dcn401_builder_internal.c diff --git a/drivers/gpu/drm/amd/display/dc/Makefile b/drivers/gpu/drm/amd/display/dc/Makefile index e6ffca083dbb..ec4b873b835f 100644 --- a/drivers/gpu/drm/amd/display/dc/Makefile +++ b/drivers/gpu/drm/amd/display/dc/Makefile @@ -85,6 +85,7 @@ FILES += core2/dc_core2.o FILES += core2/dc_core2_init.o FILES += core2/dc_core2_legacy_init.o FILES += bls_builder/bls_builder.o +FILES += bls_builder/dcn401_builder_internal.o FILES += bls_builder/dcn401_seamless_builder.o FILES += bls_builder/dcn401_init_builder.o FILES += bls_builder/dcn401_init_builder_legacy.o diff --git a/drivers/gpu/drm/amd/display/dc/bls_builder/dcn401_builder_internal.c b/drivers/gpu/drm/amd/display/dc/bls_builder/dcn401_builder_internal.c new file mode 100644 index 000000000000..25cacb1138f1 --- /dev/null +++ b/drivers/gpu/drm/amd/display/dc/bls_builder/dcn401_builder_internal.c @@ -0,0 +1,1817 @@ +// SPDX-License-Identifier: MIT +/* + * Copyright 2026 Advanced Micro Devices, Inc. + */ + +#include "dm_services.h" +#include "core_types.h" +#include "resource.h" +#include "link_encoder.h" +#include "stream_encoder.h" +#include "clk_mgr.h" +#include "dccg.h" +#include "dc_bios_types.h" +#include "dc_dmub_srv.h" +#include "custom_float.h" +#include "dcn32/dcn32_resource.h" +#include "dce/dce_hwseq.h" +#include "bls_builder/bls_builder_internal.h" +#include "bls_builder/dcn401_init_builder.h" +#include "bls_builder/bls_builder_private_types.h" +#include "bls_builder/dcn401_builder_internal.h" +#include "state_facts/state_facts.h" + +#undef DC_LOGGER +#define DC_LOGGER \ + dc->ctx->logger + +/* + * What every dcn401 declarative builder shares: the dc and stream support + * checks, the pipe removal tables, and the step walkers that turn a table + * into BLS entries. + */ + +#define DCN401_DPG_POLL_INTERVAL_US 100 +#define DCN401_DPG_POLL_TIMEOUT_US 100000 +#define DCN401_STATIC_SCREEN_NUM_FRAMES 2 +#define DCN401_PENDING_UPDATE_POLL_INTERVAL_US 1 +#define DCN401_PENDING_UPDATE_TIMEOUT_US 100000 +#define DCN401_RESET_TRIGGER_WAIT_FRAMES 10 +#define DCN401_FLIP_PENDING_POLL_INTERVAL_US 100 +#define DCN401_PLANE_ENABLE_DELAY_US 500 +/* 1.0 in the HDR multiplier and MPCC gain format. */ +#define DCN401_UNITY_GAIN 0x1f000 +#define DCN401_MALL_SEL_SS 2 +#define DCN401_CACHE_CURSOR_BYTES 16384 + +void dcn401_commit_check_failed(const struct dc *dc, const char *msg) +{ + if (dc && dc->ctx && dc->ctx->logger) + DC_LOG_DEBUG("%s\n", msg); +} + +static bool check_dc_resources(const struct dc *dc, + const struct dc_state *current_state, + const struct dc_state *new_state) +{ + (void)current_state; + (void)new_state; + return dc->res_pool && dc->res_pool->hubbub && dc->res_pool->dccg && + dc->res_pool->mpc && dc->hwseq && dc->clk_mgr && + dc->ctx && dc->ctx->dc_bios; +} + +static bool check_fams2_debug(const struct dc *dc, + const struct dc_state *current_state, + const struct dc_state *new_state) +{ + (void)current_state; + (void)new_state; + return !dc->debug.fams2_config.bits.enable; +} + +static bool check_cursor_offload(const struct dc *dc, + const struct dc_state *current_state, + const struct dc_state *new_state) +{ + (void)current_state; + (void)new_state; + return !dc->ctx->dmub_srv || !dc->ctx->dmub_srv->cursor_offload_enabled; +} + +static bool check_dc_mode_softmax(const struct dc *dc, + const struct dc_state *current_state, + const struct dc_state *new_state) +{ + (void)current_state; + (void)new_state; + return !dc->clk_mgr->dc_mode_softmax_enabled; +} + +static bool check_visual_confirm(const struct dc *dc, + const struct dc_state *current_state, + const struct dc_state *new_state) +{ + (void)current_state; + (void)new_state; + return dc->debug.visual_confirm == VISUAL_CONFIRM_DISABLE && + !dc->debug.force_dpg_on_flip && + !dc->debug.enable_hblank_borrow && + !dc->debug.enable_otg_frame_sync_pwa; +} + +/* With the DSC power gate disabled, update_dsc_pg only reads. */ +static bool check_dsc_power_gate(const struct dc *dc, + const struct dc_state *current_state, + const struct dc_state *new_state) +{ + (void)current_state; + (void)new_state; + return dc->debug.disable_dsc_power_gate; +} + +enum bls_builder_result dcn401_check_dc_support(const struct dc *dc) +{ + const struct dc_state *current_state = NULL; + const struct dc_state *new_state = NULL; + + CHECK_RESOURCE(dc_resources, "dc resources are missing"); + CHECK_CONDITION(fams2_debug, "FAMS2 debug is enabled"); + CHECK_CONDITION(cursor_offload, "cursor offload is enabled"); + CHECK_CONDITION(dc_mode_softmax, "dc mode softmax is enabled"); + CHECK_CONDITION(visual_confirm, + "visual confirm, dpg, hblank borrow, or frame sync is set"); + CHECK_CONDITION(dsc_power_gate, "DSC power gate is enabled"); + return BLS_BUILD_SUCCESS; +} + +static bool check_no_phantom(const struct dc *dc, + const struct dc_state *current_state, + const struct dc_state *new_state) +{ + (void)dc; + return !dcn401_checked_state(current_state, + new_state)->phantom_stream_count; +} + +static bool check_fams2_state(const struct dc *dc, + const struct dc_state *current_state, + const struct dc_state *new_state) +{ + const struct dc_state *state = dcn401_checked_state(current_state, + new_state); + + (void)dc; + return !state->bw_ctx.bw.dcn.fams2_global_config.features.bits.enable; +} + +static bool check_stream_link(const struct dc *dc, + const struct dc_state *state, unsigned int i) +{ + (void)dc; + return state->streams[i] && state->streams[i]->link; +} + +/* link_set_dpms_on and _off program nothing for a virtual signal. */ +static bool check_virtual_signal(const struct dc *dc, + const struct dc_state *state, unsigned int i) +{ + (void)dc; + (void)state; + (void)i; + return false; +} + +static bool check_link_encoder(const struct dc *dc, + const struct dc_state *state, unsigned int i) +{ + const struct dc_link *link = state->streams[i]->link; + + (void)dc; + return link->ep_type == DISPLAY_ENDPOINT_PHY && link->link_enc; +} + +static bool check_no_interlace(const struct dc *dc, + const struct dc_state *state, unsigned int i) +{ + (void)dc; + return !state->streams[i]->timing.flags.INTERLACE; +} + +static bool check_no_stereo(const struct dc *dc, + const struct dc_state *state, unsigned int i) +{ + (void)dc; + return state->streams[i]->timing.timing_3d_format == + TIMING_3D_FORMAT_NONE; +} + +static bool check_no_drr(const struct dc *dc, + const struct dc_state *state, unsigned int i) +{ + const struct dc_stream_state *stream = state->streams[i]; + + (void)dc; + return !stream->ignore_msa_timing_param && + !stream->adjust.v_total_min && + !stream->adjust.v_total_max; +} + +static bool check_no_boot_dpms_writeback(const struct dc *dc, + const struct dc_state *state, unsigned int i) +{ + const struct dc_stream_state *stream = state->streams[i]; + + (void)dc; + return !stream->apply_seamless_boot_optimization && !stream->dpms_off && + !stream->num_wb_info; +} + +static bool check_abm(const struct dc *dc, + const struct dc_state *state, unsigned int i) +{ + const struct dc_stream_state *stream = state->streams[i]; + + (void)dc; + return !stream->abm_level || + stream->abm_level == ABM_LEVEL_IMMEDIATE_DISABLE; +} + +/* + * An MPC bottom pipe or an ODM slice of the stream is not an OTG master; + * check_mpc_blend and check_odm_combine bound them. + */ +const struct pipe_ctx *dcn401_otg_master(const struct dc_state *state, + const struct dc_stream_state *stream) +{ + const struct pipe_ctx *otg_master = NULL; + unsigned int i; + + for (i = 0; i < MAX_PIPES; i++) { + const struct pipe_ctx *pipe = &state->res_ctx.pipe_ctx[i]; + + if (!stream || !pipe->stream || + pipe->stream->stream_id != stream->stream_id || + pipe->top_pipe || pipe->prev_odm_pipe) + continue; + if (otg_master) + return NULL; + otg_master = pipe; + } + return otg_master; +} + +int dcn401_stream_index(const struct dc_state *state, + const struct dc_stream_state *stream) +{ + int i; + + if (!stream) + return -1; + for (i = 0; i < state->stream_count; i++) + if (state->streams[i]->stream_id == stream->stream_id) + return i; + return -1; +} + +#define DCN401_SAME_INST(a, b) \ + ((!(a) && !(b)) || ((a) && (b) && (a)->inst == (b)->inst)) + +bool dcn401_pipe_on_stream(const struct pipe_ctx *pipe, + const struct dc_stream_state *stream) +{ + return pipe->stream && pipe->stream->stream_id == stream->stream_id; +} + +/* The plane is compared as an object: planes have no DC-assigned id yet. */ +static bool dcn401_pipe_layout_unchanged(const struct pipe_ctx *cur, + const struct pipe_ctx *new) +{ + return cur->plane_state == new->plane_state && + DCN401_SAME_INST(cur->plane_res.hubp, new->plane_res.hubp) && + DCN401_SAME_INST(cur->plane_res.dpp, new->plane_res.dpp) && + DCN401_SAME_INST(cur->stream_res.tg, new->stream_res.tg) && + DCN401_SAME_INST(cur->stream_res.opp, new->stream_res.opp) && + !cur->top_pipe == !new->top_pipe && + !cur->bottom_pipe == !new->bottom_pipe && + !cur->prev_odm_pipe == !new->prev_odm_pipe && + !cur->next_odm_pipe == !new->next_odm_pipe; +} + +bool dcn401_stream_unchanged(const struct dc_state *current_state, + const struct dc_state *new_state, + const struct dc_stream_state *stream) +{ + const struct pipe_ctx *cur, *new; + unsigned int i; + + if (dcn401_stream_index(current_state, stream) < 0 || + dcn401_stream_index(new_state, stream) < 0) + return false; + for (i = 0; i < MAX_PIPES; i++) { + cur = ¤t_state->res_ctx.pipe_ctx[i]; + new = &new_state->res_ctx.pipe_ctx[i]; + if (dcn401_pipe_on_stream(cur, stream) != + dcn401_pipe_on_stream(new, stream)) + return false; + if (dcn401_pipe_on_stream(new, stream) && + !dcn401_pipe_layout_unchanged(cur, new)) + return false; + } + return true; +} + +static bool check_otg_master_present(const struct dc *dc, + const struct dc_state *state, unsigned int i) +{ + (void)dc; + return dcn401_otg_master(state, state->streams[i]) != NULL; +} + +/* At most DCN401_MAX_OPP_HEADS ODM slices, each with an OPP. */ +static bool check_odm_combine(const struct dc *dc, + const struct dc_state *state, unsigned int i) +{ + const struct pipe_ctx *odm = dcn401_otg_master(state, + state->streams[i]); + unsigned int count = 0; + + (void)dc; + for (; odm; odm = odm->next_odm_pipe) + if (!odm->stream_res.opp || ++count > DCN401_MAX_OPP_HEADS) + return false; + return count; +} + +static bool check_mpc_blend(const struct dc *dc, + const struct dc_state *state, unsigned int i) +{ + struct dc_state_facts facts; + + (void)dc; + dc_state_facts_derive(state, &facts); + /* + * At most one bottom pipe, on the master's OTG and OPP. A bottom pipe + * and ODM do not go together. + */ + return facts.global.blend_tree[i].dpp_pipe_count <= 2 && + facts.global.blend_tree[i].on_otg_master_blocks && + (facts.global.blend_tree[i].dpp_pipe_count == 1 || + !dc_state_facts_any_pipe(&facts, (uint8_t)i, + DC_TRAIT_MATCH(DC_PIPE_TRAIT_ODM, 0))); +} + +static bool check_otg_master_blocks(const struct dc *dc, + const struct dc_state *state, unsigned int i) +{ + const struct pipe_ctx *pipe = dcn401_otg_master(state, + state->streams[i]); + + (void)dc; + return pipe && pipe->stream_res.tg && pipe->stream_res.opp && + pipe->stream_res.stream_enc && pipe->clock_source; +} + +static bool check_pipe_audio(const struct dc *dc, + const struct dc_state *state, unsigned int i) +{ + const struct pipe_ctx *pipe = dcn401_otg_master(state, + state->streams[i]); + + (void)dc; + return pipe && !pipe->stream_res.audio; +} + +static bool check_pipe_dsc(const struct dc *dc, + const struct dc_state *state, unsigned int i) +{ + const struct dc_stream_state *stream = state->streams[i]; + struct pipe_ctx *opp_heads[MAX_PIPES]; + int j, n; + + (void)dc; + n = resource_get_opp_heads_for_stream(stream, + (struct resource_context *)&state->res_ctx, opp_heads); + for (j = 0; j < n; j++) + if (!opp_heads[j]->stream_res.dsc != !stream->timing.flags.DSC) + return false; + return true; +} + +static bool check_dsc_pixel_clock(const struct dc *dc, + const struct dc_state *state, unsigned int i) +{ + const struct dc_crtc_timing *timing = &state->streams[i]->timing; + + (void)dc; + return !timing->flags.DSC || timing->pix_clk_100hz > 480000; +} + +static bool check_pipe_gsl(const struct dc *dc, + const struct dc_state *state, unsigned int i) +{ + const struct pipe_ctx *pipe = dcn401_otg_master(state, + state->streams[i]); + + (void)dc; + return pipe && !pipe->stream_res.gsl_group; +} + +static bool check_link_enc_assignment(const struct dc *dc, + const struct dc_state *state, unsigned int i) +{ + const struct pipe_ctx *pipe = dcn401_otg_master(state, + state->streams[i]); + + if (!dc->config.unify_link_enc_assignment) + return true; + return pipe && pipe->link_res.dio_link_enc == + pipe->stream->link->link_enc; +} + +/* Each stream on its own link. */ +static bool check_own_link(const struct dc *dc, + const struct dc_state *state, unsigned int i) +{ + unsigned int j; + + (void)dc; + for (j = 0; j < i; j++) + if (state->streams[j]->link == state->streams[i]->link) + return false; + return true; +} + +static enum bls_builder_result dcn401_check_one_stream(const struct dc *dc, + const struct dc_state *state, unsigned int i) +{ + CHECK_STREAM_RESOURCE(stream_link, "stream has no link"); + CHECK_STREAM_CONDITION(own_link, "streams share a link"); + CHECK_STREAM_CONDITION(virtual_signal, "signal is not virtual"); + CHECK_STREAM_RESOURCE(link_encoder, "link encoder is not DIO"); + CHECK_STREAM_CONDITION(no_interlace, "timing is interlace"); + CHECK_STREAM_CONDITION(no_stereo, "timing is stereo"); + CHECK_STREAM_CONDITION(dsc_pixel_clock, + "dsc pixel clock is 48 MHz or less"); + CHECK_STREAM_CONDITION(no_drr, "DRR is set"); + CHECK_STREAM_CONDITION(no_boot_dpms_writeback, + "seamless boot, dpms, or writeback is set"); + CHECK_STREAM_CONDITION(abm, "ABM level is set"); + CHECK_STREAM_RESOURCE(otg_master_present, + "stream has no otg master, or more than one"); + CHECK_STREAM_CONDITION(odm_combine, "odm is not bypass, 2:1 or 3:1"); + CHECK_STREAM_CONDITION(mpc_blend, + "more than one bottom pipe, off the otg or opp, or with odm"); + CHECK_STREAM_RESOURCE(otg_master_blocks, + "otg master is missing a stream resource or pixel clock"); + CHECK_STREAM_CONDITION(pipe_audio, "audio is set"); + CHECK_STREAM_RESOURCE(pipe_dsc, + "dsc differs from the timing on an opp head"); + CHECK_STREAM_CONDITION(pipe_gsl, "gsl is set"); + CHECK_STREAM_CONDITION(link_enc_assignment, + "link encoder assignment differs"); + return BLS_BUILD_SUCCESS; +} + +/* Every pipe with a stream belongs to a stream of the state. */ +static bool check_pipe_streams(const struct dc *dc, + const struct dc_state *current_state, + const struct dc_state *new_state) +{ + const struct dc_state *state = dcn401_checked_state(current_state, + new_state); + unsigned int i; + + (void)dc; + for (i = 0; i < MAX_PIPES; i++) + if (state->res_ctx.pipe_ctx[i].stream && + dcn401_stream_index(state, + state->res_ctx.pipe_ctx[i].stream) < 0) + return false; + return true; +} + +enum bls_builder_result dcn401_check_stream_support(const struct dc *dc, + const struct dc_state *current_state, + const struct dc_state *new_state) +{ + const struct dc_state *state = dcn401_checked_state(current_state, + new_state); + enum bls_builder_result result; + unsigned int i; + + if (!state) + return BLS_BUILD_ERROR_UNSUPPORTED_STATE_UPDATE; + CHECK_CONDITION(no_phantom, "a phantom stream is set"); + CHECK_CONDITION(fams2_state, "fams2 is enabled"); + CHECK_CONDITION(pipe_streams, "a pipe has a stream the state lacks"); + for (i = 0; i < state->stream_count; i++) { + result = dcn401_check_one_stream(dc, state, i); + if (result != BLS_BUILD_SUCCESS) + return result; + } + return BLS_BUILD_SUCCESS; +} + +bool dcn401_same_opp_heads(const struct dc_state *current_state, + const struct dc_state *new_state, + const struct dc_stream_state *stream) +{ + const struct pipe_ctx *cur = dcn401_otg_master(current_state, stream); + const struct pipe_ctx *new = dcn401_otg_master(new_state, stream); + struct pipe_ctx *cur_heads[MAX_PIPES], *new_heads[MAX_PIPES]; + int i, n; + + if (!cur || !new) + return false; + n = resource_get_opp_heads_for_otg_master(cur, + (struct resource_context *)¤t_state->res_ctx, + cur_heads); + if (n != resource_get_opp_heads_for_otg_master(new, + (struct resource_context *)&new_state->res_ctx, + new_heads)) + return false; + for (i = 0; i < n; i++) + if (!cur_heads[i]->stream_res.opp || + !new_heads[i]->stream_res.opp || + cur_heads[i]->stream_res.opp->inst != + new_heads[i]->stream_res.opp->inst) + return false; + return true; +} + +/* + * Under the lock, each current pipe that the update removes leaves its + * MPCC and returns its DET segments, as DC1 disconnects a disabled pipe. + */ +const struct dcn401_commit_step dcn401_disconnect[DCN401_DISCONNECT_STEPS] = { + { .func = HUBP_PROGRAM_DET_SEGMENTS, + .meta.skip_if.stream_unchanged = true, + .meta.skip_if.only_addresses_changed = true, + .meta.skip_if.pipe_deltas.current_has_no_plane = true, + .meta.skip_if.pipe_deltas.hubp_dpp_already_enabled = true }, + { .func = MPC_REMOVE_MPCC, + .meta.skip_if.stream_unchanged = true, + .meta.skip_if.only_addresses_changed = true, + .meta.skip_if.pipe_deltas.current_has_no_plane = true, + .meta.skip_if.pipe_deltas.hubp_dpp_already_enabled = true }, +}; + +/* After the unlock, disable_plane on each removed pipe. */ +const struct dcn401_commit_step dcn401_power_down[DCN401_POWER_DOWN_STEPS] = { + { .func = MPC_ASSERT_IDLE_MPCC, + .meta.skip_if.stream_unchanged = true, + .meta.skip_if.only_addresses_changed = true, + .meta.skip_if.pipe_deltas.current_has_no_plane = true, + .meta.skip_if.pipe_deltas.hubp_dpp_already_enabled = true }, + { .func = HUBP_SET_BLANK, + .meta.skip_if.stream_unchanged = true, + .meta.skip_if.only_addresses_changed = true, + .meta.skip_if.pipe_deltas.current_has_no_plane = true, + .meta.skip_if.pipe_deltas.hubp_dpp_already_enabled = true }, + { .func = HUBP_UPDATE_MALL_SEL, + .meta.skip_if.stream_unchanged = true, + .meta.skip_if.only_addresses_changed = true, + .meta.skip_if.pipe_deltas.current_has_no_plane = true, + .meta.skip_if.pipe_deltas.hubp_dpp_already_enabled = true }, + { .func = HUBP_SET_FLIP_CONTROL_GSL, + .meta.skip_if.stream_unchanged = true, + .meta.skip_if.only_addresses_changed = true, + .meta.skip_if.pipe_deltas.current_has_no_plane = true, + .meta.skip_if.pipe_deltas.hubp_dpp_already_enabled = true }, + { .func = HUBP_CLK_CNTL, + .meta.skip_if.stream_unchanged = true, + .meta.skip_if.only_addresses_changed = true, + .meta.skip_if.pipe_deltas.current_has_no_plane = true, + .meta.skip_if.pipe_deltas.hubp_dpp_already_enabled = true }, + { .func = DPP_DPPCLK_CONTROL, + .meta.skip_if.stream_unchanged = true, + .meta.skip_if.only_addresses_changed = true, + .meta.skip_if.pipe_deltas.current_has_no_plane = true, + .meta.skip_if.pipe_deltas.hubp_dpp_already_enabled = true }, + { .func = DC_IP_REQUEST_STATUS, + .meta.skip_if.stream_unchanged = true, + .meta.skip_if.only_addresses_changed = true, + .meta.skip_if.no_ip_request = true, + .meta.skip_if.pipe_deltas.current_has_no_plane = true, + .meta.skip_if.pipe_deltas.hubp_dpp_already_enabled = true }, + { .func = DC_IP_REQUEST_CNTL, + .meta.skip_if.stream_unchanged = true, + .meta.skip_if.only_addresses_changed = true, + .meta.dc_ip_request_cntl.enable = true, + .meta.skip_if.no_ip_request = true, + .meta.skip_if.pipe_deltas.current_has_no_plane = true, + .meta.skip_if.pipe_deltas.hubp_dpp_already_enabled = true }, + { .func = HUBP_PG_CONTROL, + .meta.skip_if.stream_unchanged = true, + .meta.skip_if.only_addresses_changed = true, + .meta.skip_if.pipe_deltas.current_has_no_plane = true, + .meta.skip_if.pipe_deltas.hubp_dpp_already_enabled = true }, + { .func = HUBP_RESET, + .meta.skip_if.stream_unchanged = true, + .meta.skip_if.only_addresses_changed = true, + .meta.skip_if.pipe_deltas.current_has_no_plane = true, + .meta.skip_if.pipe_deltas.hubp_dpp_already_enabled = true }, + { .func = DPP_RESET, + .meta.skip_if.stream_unchanged = true, + .meta.skip_if.only_addresses_changed = true, + .meta.skip_if.pipe_deltas.current_has_no_plane = true, + .meta.skip_if.pipe_deltas.hubp_dpp_already_enabled = true }, + { .func = DC_IP_REQUEST_CNTL, + .meta.skip_if.stream_unchanged = true, + .meta.skip_if.only_addresses_changed = true, + .meta.dc_ip_request_cntl.enable = false, + .meta.skip_if.no_ip_request = true, + .meta.skip_if.pipe_deltas.current_has_no_plane = true, + .meta.skip_if.pipe_deltas.hubp_dpp_already_enabled = true }, +}; + +/* enable_stream_timing_calc: manual mode unless every span is even. */ +static bool dcn401_h_timing_div_manual_mode( + const struct dc_crtc_timing *timing) +{ + unsigned int h_blank_start = timing->h_total - timing->h_front_porch; + unsigned int h_blank_end = h_blank_start - timing->h_addressable; + + return (timing->h_total % 2) || (h_blank_start % 2) || + (h_blank_end % 2) || (timing->h_sync_width % 2); +} + +/* dcn10_get_vupdate_offset_from_vsync for progressive timing. */ +static int dcn401_vupdate_start_line(const struct pipe_ctx *pipe) +{ + const struct dc_crtc_timing *timing = &pipe->stream->timing; + int front_porch = timing->v_front_porch ? timing->v_front_porch : 1; + int vesa_sync_start = timing->v_addressable + timing->v_border_bottom + + front_porch; + int asic_blank_end = timing->v_total - vesa_sync_start - + timing->v_border_top; + int start_line = asic_blank_end - + (int)pipe->pipe_dlg_param.vstartup_start + 1; + + return start_line < 0 ? 0 : start_line; +} + +/* dcn401_enable_stream_calc's early control for this lane count. */ +static uint32_t dcn401_early_cntl(const struct pipe_ctx *pipe) +{ + const struct dc_crtc_timing *timing = &pipe->stream->timing; + unsigned int lane_count = + pipe->stream->link->cur_link_settings.lane_count; + uint32_t early_cntl = 0; + + if (lane_count) + early_cntl = (timing->h_addressable + timing->h_border_left + + timing->h_border_right) % lane_count; + return early_cntl ? early_cntl : lane_count; +} + +/* + * dcn20_blank_pixel_data: the black of the output color space over the ODM + * slice of this OPP head, or the video on unblank. + */ +static void dcn401_opp_blank_params(const struct dc *dc, + struct pipe_ctx *pipe, bool unblank, + struct opp_set_disp_pattern_generator_params *p) +{ + const struct dc_crtc_timing *timing = &pipe->stream->timing; + struct rect slice = resource_get_odm_slice_src_rect(pipe); + + p->opp = pipe->stream_res.opp; + p->test_pattern = unblank ? CONTROLLER_DP_TEST_PATTERN_VIDEOMODE : + CONTROLLER_DP_TEST_PATTERN_SOLID_COLOR; + p->color_space = CONTROLLER_DP_COLOR_SPACE_UDEFINED; + p->color_depth = timing->display_color_depth; + color_space_to_black_color(dc, pipe->stream->output_color_space, + &p->solid_color); + p->use_solid_color = true; + p->width = slice.width; + p->height = slice.height; + p->offset = slice.x; + p->disable_dyn_exp_for_test_pattern = + dc->debug.disable_dynamic_expansion_for_test_pattern; +} + +/* + * dcn401_update_odm: one OPP per ODM slice, in slice order. A table's + * OPTC_SET_ODM_COMBINE programs the ODM unconditionally: N:1 combine for + * N > 1 slices, else bypass. + */ +static void dcn401_odm_combine_params(struct pipe_ctx *otg_master, + struct set_odm_combine_params *p) +{ + struct pipe_ctx *odm; + + p->tg = otg_master->stream_res.tg; + for (odm = otg_master; odm; odm = odm->next_odm_pipe) + p->opp_inst[p->opp_head_count++] = odm->stream_res.opp->inst; + p->odm_slice_width = resource_get_odm_slice_dst_width(otg_master, + false); + p->last_odm_slice_width = resource_get_odm_slice_dst_width(otg_master, + true); +} + +static void dcn401_dsc_config_params(struct pipe_ctx *otg_master, + bool enable, struct tg_set_dsc_config_params *p) +{ + struct dsc_optc_config optc; + + p->tg = otg_master->stream_res.tg; + p->dsc_mode = OPTC_DSC_DISABLED; + if (!enable || !hwss_prepare_dsc_config_for_pipe(otg_master, + resource_get_odm_slice_count(otg_master), 0, &optc)) + return; + p->dsc_mode = optc.is_pixel_format_444 ? OPTC_DSC_ENABLED_444 : + OPTC_DSC_ENABLED_NATIVE_SUBSAMPLED; + p->bytes_per_pixel = optc.bytes_per_pixel; + p->slice_width = optc.slice_width; +} + +static void dcn401_program_timing_params(const struct pipe_ctx *pipe, + struct tg_program_timing_params *p) +{ + const union dml2_global_sync_programming *sync = &pipe->global_sync; + + p->tg = pipe->stream_res.tg; + p->timing = &pipe->stream->timing; + p->vready_offset = sync->dcn4x.vready_offset_pixels; + p->vstartup_start = sync->dcn4x.vstartup_lines; + p->vupdate_offset = sync->dcn4x.vupdate_offset_pixels; + p->vupdate_width = sync->dcn4x.vupdate_vupdate_width_pixels; + p->pstate_keepout = sync->dcn4x.pstate_keepout_start_lines; + p->signal = pipe->stream->signal; + p->use_vbios = true; +} + +static void dcn401_drr_params(const struct pipe_ctx *pipe, bool with_mid, + struct drr_params *drr) +{ + const struct dc_crtc_timing_adjust *adjust = &pipe->stream->adjust; + + drr->vertical_total_min = adjust->v_total_min; + drr->vertical_total_max = adjust->v_total_max; + if (with_mid) { + drr->vertical_total_mid = adjust->v_total_mid; + drr->vertical_total_mid_frame_num = + adjust->v_total_mid_frame_num; + } +} + +static void dcn401_update_clocks_params(const struct dc *dc, + struct dc_state *context, bool safe_to_lower, + struct clk_mgr_update_clocks_for_state_params *p) +{ + p->clk_mgr = dc->clk_mgr; + p->context = context; + p->safe_to_lower = safe_to_lower; + p->disallow_p_state_change = !safe_to_lower && + context->bw_ctx.bw.dcn.clk.p_state_change_support; +} + +/* dcn401_update_mpcc_sequence's blending for the plane. */ +static void dcn401_blnd_cfg(const struct dc_plane_state *plane, + struct mpcc_blnd_cfg *cfg) +{ + cfg->overlap_only = false; + cfg->global_gain = 0xff; + if (plane->per_pixel_alpha) { + cfg->pre_multiplied_alpha = plane->pre_multiplied_alpha; + if (plane->global_alpha) { + cfg->alpha_mode = + MPCC_ALPHA_BLEND_MODE_PER_PIXEL_ALPHA_COMBINED_GLOBAL_GAIN; + cfg->global_gain = plane->global_alpha_value; + } else { + cfg->alpha_mode = MPCC_ALPHA_BLEND_MODE_PER_PIXEL_ALPHA; + } + } else { + cfg->pre_multiplied_alpha = false; + cfg->alpha_mode = MPCC_ALPHA_BLEND_MODE_GLOBAL_ALPHA; + } + cfg->global_alpha = plane->global_alpha ? + plane->global_alpha_value : 0xff; + cfg->background_color_bpc = 4; + cfg->bottom_gain_mode = 0; + cfg->top_gain = DCN401_UNITY_GAIN; + cfg->bottom_inside_gain = DCN401_UNITY_GAIN; + cfg->bottom_outside_gain = DCN401_UNITY_GAIN; + if (plane->format == SURFACE_PIXEL_FORMAT_GRPH_RGBE_ALPHA) + cfg->pre_multiplied_alpha = false; +} + +/* dcn401_set_hdr_multiplier_sequence: 1.0 unless the plane sets one. */ +static uint32_t dcn401_hdr_mult(const struct dc_plane_state *plane) +{ + struct custom_float_format fmt = { + .exponenta_bits = 6, + .mantissa_bits = 12, + .sign = true, + }; + uint32_t hw_mult = DCN401_UNITY_GAIN; + + if (!dc_fixpt_eq(plane->hdr_mult, dc_fixpt_from_int(0)) && + !convert_to_custom_float_format(plane->hdr_mult, &fmt, + &hw_mult)) + hw_mult = DCN401_UNITY_GAIN; + return hw_mult; +} + +/* dcn401_program_mall_pipe_config_sequence for one non-phantom pipe. */ +static void dcn401_mall_sel_params(struct dc *dc, struct dc_state *state, + struct pipe_ctx *pipe, struct hubp_update_mall_sel_params *p) +{ + const struct hubp *hubp = pipe->plane_res.hubp; + const struct dc_plane_address *address = &pipe->plane_state->address; + int cursor_size = hubp->curs_attr.pitch * hubp->curs_attr.height; + uint32_t mall_ss_size_bytes; + uint32_t num_ways = 0; + + switch (hubp->curs_attr.color_format) { + case CURSOR_MODE_MONO: + cursor_size /= 2; + break; + case CURSOR_MODE_COLOR_1BIT_AND: + case CURSOR_MODE_COLOR_PRE_MULTIPLIED_ALPHA: + case CURSOR_MODE_COLOR_UN_PRE_MULTIPLIED_ALPHA: + cursor_size *= 4; + break; + default: + cursor_size *= 8; + break; + } + + /* + * dcn401_calculate_cab_allocation also adds the cursor mall bytes. + * This builder rejects a cursor, so those bytes are zero. The helper + * that computes them is built only with CONFIG_DRM_AMD_DC_FP. + */ + mall_ss_size_bytes = state->bw_ctx.bw.dcn.mall_ss_size_bytes; + if (dc->debug.force_mall_ss_num_ways > 0) + num_ways = dc->debug.force_mall_ss_num_ways; + else if (dc->res_pool->funcs->calculate_mall_ways_from_bytes) + num_ways = dc->res_pool->funcs->calculate_mall_ways_from_bytes( + dc, mall_ss_size_bytes); + + p->hubp = pipe->plane_res.hubp; + p->cache_cursor = cursor_size > DCN401_CACHE_CURSOR_BYTES; + p->mall_sel = num_ways <= dc->caps.cache_num_ways && + pipe->stream->link->psr_settings.psr_version == + DC_PSR_VERSION_UNSUPPORTED && + address->type != PLN_ADDR_TYPE_GRPH_STEREO && + !address->tmz_surface ? DCN401_MALL_SEL_SS : 0; +} + +/* dcn401_set_mcm_luts clears the HUBP 3DLUT fast load with this. */ +static const struct dc_3dlut_dma dcn401_3dlut_dma_off = {0}; + +/* dcn401_set_mcm_luts sizes the off 3DLUT by the plane's LUT. */ +static enum dc_cm_lut_size dcn401_lut_mode_size( + const struct dc_plane_state *plane, enum MCM_LUT_ID id) +{ + if (id != MCM_LUT_3DLUT) + return CM_LUT_SIZE_NONE; + return plane->cm.lut3d_func.lut_3d.use_tetrahedral_9 ? + CM_LUT_SIZE_999 : CM_LUT_SIZE_171717; +} + +/* + * The divider dcn401_enable_stream_timing sets for the virtual signal. The + * divide by one dcn401_enable_stream passes later is a no-op, because + * dccg401_set_pixel_rate_div accepts only 2 and 4. The hwseq is built only + * with DC_FP; the builder is built without it. + */ +static enum pixel_rate_div dcn401_pixel_rate_div( + const struct pipe_ctx *pipe) +{ + return pipe->stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR420 ? + PIXEL_RATE_DIV_BY_2 : PIXEL_RATE_DIV_BY_4; +} + +/* Writes one entry; build sized every sequence before adding to it. */ +static void dcn401_add_step(struct block_sequence_state *sequence, + const struct dcn401_commit_step_args *args, + const struct dcn401_commit_step *step) +{ + struct block_sequence *entry; + union block_sequence_params *p; + struct dc *dc = args->dc; + struct dcn_bw_output *bw = &args->new_state->bw_ctx.bw.dcn; + struct pipe_ctx *pipe; + struct dpp *dpp; + struct dc_plane_state *plane; + const struct dcn401_commit_step_meta *m = &step->meta; + + if (*sequence->num_steps >= DC2_BLS_MAX_STEPS) { + if (*sequence->num_steps == DC2_BLS_MAX_STEPS && + dc->debug.dc2_bls_report_step_overflow && + dc->ctx && dc->ctx->logger) { + DC_LOG_ERROR("%s: more than %u BLS steps\n", __func__, + DC2_BLS_MAX_STEPS); + BREAK_TO_DEBUGGER(); + } + (*sequence->num_steps)++; + return; + } + entry = &sequence->steps[(*sequence->num_steps)++]; + p = &entry->params; + memset(entry, 0, sizeof(*entry)); + entry->func = step->func; + /* + * Bandwidth and p-state steps have no pipe. Handle them before the + * pipe is used, then every later case can use the pipe directly. + */ + if (!args->pipe) { + switch (step->func) { + case CLK_MGR_UPDATE_CLOCKS_FOR_STATE: + dcn401_update_clocks_params(dc, args->new_state, + m->clk_mgr_update_clocks_for_state + .safe_to_lower, + &p->clk_mgr_update_clocks_for_state_params); + return; + case HUBBUB_PROGRAM_WATERMARKS: + p->hubbub_program_watermarks_params = + hwss_prepare_hubbub_program_watermarks(dc, + dc->res_pool->hubbub, &bw->watermarks, + dc->res_pool->ref_clocks.dchub_ref_clock_inKhz / + 1000, + m->hubbub_program_watermarks.safe_to_lower); + return; + case HUBBUB_PROGRAM_ARBITER: + p->hubbub_program_arbiter_params = + hwss_prepare_hubbub_program_arbiter( + dc->res_pool->hubbub, &bw->arb_regs, + m->hubbub_program_arbiter.safe_to_lower); + return; + case HUBBUB_PROGRAM_COMPBUF_SEGMENTS: + p->hubbub_program_compbuf_segments_params.hubbub = + dc->res_pool->hubbub; + p->hubbub_program_compbuf_segments_params.compbuf_size = + m->hubbub_program_compbuf_segments + .use_current_state_size ? + args->current_state->bw_ctx.bw.dcn.arb_regs + .compbuf_size : bw->arb_regs.compbuf_size; + p->hubbub_program_compbuf_segments_params.safe_to_lower = + m->hubbub_program_compbuf_segments + .safe_to_lower; + return; + case HUBBUB_FORCE_PSTATE_CHANGE_CONTROL: + p->hubbub_force_pstate_change_control_params.hubbub = + dc->res_pool->hubbub; + p->hubbub_force_pstate_change_control_params.enable = + m->hubbub_force_pstate_change_control.enable; + return; + default: + (*sequence->num_steps)--; + return; + } + } + pipe = args->pipe; + dpp = pipe->plane_res.dpp; + plane = pipe->plane_state; + switch (step->func) { + case CLK_MGR_UPDATE_CLOCKS_FOR_STATE: + dcn401_update_clocks_params(dc, args->new_state, + m->clk_mgr_update_clocks_for_state + .safe_to_lower, + &p->clk_mgr_update_clocks_for_state_params); + break; + case HUBBUB_PROGRAM_WATERMARKS: + p->hubbub_program_watermarks_params = + hwss_prepare_hubbub_program_watermarks(dc, + dc->res_pool->hubbub, &bw->watermarks, + dc->res_pool->ref_clocks.dchub_ref_clock_inKhz / + 1000, + m->hubbub_program_watermarks.safe_to_lower); + break; + case HUBBUB_PROGRAM_ARBITER: + p->hubbub_program_arbiter_params = + hwss_prepare_hubbub_program_arbiter( + dc->res_pool->hubbub, &bw->arb_regs, + m->hubbub_program_arbiter.safe_to_lower); + break; + case HUBBUB_PROGRAM_COMPBUF_SEGMENTS: + p->hubbub_program_compbuf_segments_params.hubbub = + dc->res_pool->hubbub; + p->hubbub_program_compbuf_segments_params.compbuf_size = + m->hubbub_program_compbuf_segments + .use_current_state_size ? + args->current_state->bw_ctx.bw.dcn.arb_regs + .compbuf_size : bw->arb_regs.compbuf_size; + p->hubbub_program_compbuf_segments_params.safe_to_lower = + m->hubbub_program_compbuf_segments + .safe_to_lower; + break; + case HUBBUB_FORCE_PSTATE_CHANGE_CONTROL: + p->hubbub_force_pstate_change_control_params.hubbub = + dc->res_pool->hubbub; + p->hubbub_force_pstate_change_control_params.enable = + m->hubbub_force_pstate_change_control.enable; + break; + case BIOS_SET_SCRATCH_CRITICAL_STATE: + p->bios_set_scratch_critical_state_params.dcb = + dc->ctx->dc_bios; + p->bios_set_scratch_critical_state_params.state = + m->bios_set_scratch_critical_state.state; + break; + case TG_LOCK: + p->tg_lock_params.dc = dc; + p->tg_lock_params.tg = pipe->stream_res.tg; + p->tg_lock_params.lock = m->tg_lock.lock; + break; + case TG_ENABLE_CRTC: + p->tg_enable_crtc_params.tg = pipe->stream_res.tg; + break; + case TG_DISABLE_CRTC: + p->tg_disable_crtc_params.tg = pipe->stream_res.tg; + break; + case TG_WAIT_ODM_DOUBLEBUFFER_PENDING_CLEAR: + p->tg_wait_odm_doublebuffer_pending_clear_params.tg = + pipe->stream_res.tg; + break; + case TG_ENABLE_RESET_TRIGGER: + p->tg_enable_reset_trigger_params.tg = pipe->stream_res.tg; + p->tg_enable_reset_trigger_params.source_tg_inst = + args->timing_sync_source->stream_res.tg->inst; + break; + case TG_WAIT_FOR_RESET_TRIGGER: + p->tg_wait_for_reset_trigger_params.tg = pipe->stream_res.tg; + p->tg_wait_for_reset_trigger_params.frames = + DCN401_RESET_TRIGGER_WAIT_FRAMES; + p->tg_wait_for_reset_trigger_params.continue_on_error = true; + break; + case TG_DISABLE_RESET_TRIGGER: + p->tg_disable_reset_trigger_params.tg = pipe->stream_res.tg; + break; + case TG_ENABLE_OPTC_CLOCK: + p->tg_enable_optc_clock_params.tg = pipe->stream_res.tg; + p->tg_enable_optc_clock_params.enable = + m->tg_enable_optc_clock.enable; + break; + case TG_SET_DRR: + p->tg_set_drr_params.tg = pipe->stream_res.tg; + if (m->tg_set_drr.from_adjust) + dcn401_drr_params(pipe, m->tg_set_drr.with_mid, + &p->tg_set_drr_params.drr); + break; + case TG_SET_STATIC_SCREEN_CONTROL: + /* DRR is off, so no static-screen event triggers the OTG. */ + p->tg_set_static_screen_control_params.tg = pipe->stream_res.tg; + p->tg_set_static_screen_control_params.num_frames = + DCN401_STATIC_SCREEN_NUM_FRAMES; + break; + case TG_PROGRAM_TIMING: + dcn401_program_timing_params(pipe, + &p->tg_program_timing_params); + break; + case TG_SET_H_TIMING_DIV_MANUAL_MODE: + p->tg_set_h_timing_div_manual_mode_params.tg = + pipe->stream_res.tg; + p->tg_set_h_timing_div_manual_mode_params.manual_mode = + dcn401_h_timing_div_manual_mode( + &pipe->stream->timing); + break; + case TG_SETUP_VERTICAL_INTERRUPT2: + p->tg_setup_vertical_interrupt2_params.tg = pipe->stream_res.tg; + p->tg_setup_vertical_interrupt2_params.start_line = + dcn401_vupdate_start_line(pipe); + break; + case TG_SET_OUT_MUX: + p->tg_set_out_mux_params.tg = pipe->stream_res.tg; + p->tg_set_out_mux_params.dest = OUT_MUX_DIO; + break; + case TG_SET_EARLY_CONTROL: + p->tg_set_early_control_params.tg = pipe->stream_res.tg; + p->tg_set_early_control_params.early_cntl = + dcn401_early_cntl(pipe); + break; + case TG_PROGRAM_STEREO: + p->tg_program_stereo_params.tg = pipe->stream_res.tg; + p->tg_program_stereo_params.timing = &pipe->stream->timing; + break; + case OPTC_SET_ODM_COMBINE: + if (pipe->next_odm_pipe) { + dcn401_odm_combine_params(pipe, + &p->set_odm_combine_params); + break; + } + entry->func = OPTC_SET_ODM_BYPASS; + p->set_odm_bypass_params.tg = pipe->stream_res.tg; + p->set_odm_bypass_params.timing = &pipe->stream->timing; + break; + case OPTC_SET_ODM_BYPASS: + p->set_odm_bypass_params.tg = pipe->stream_res.tg; + p->set_odm_bypass_params.timing = &pipe->stream->timing; + break; + case OPP_PIPE_CLOCK_CONTROL: + p->opp_pipe_clock_control_params.opp = pipe->stream_res.opp; + p->opp_pipe_clock_control_params.enable = true; + break; + case OPP_PROGRAM_LEFT_EDGE_EXTRA_PIXEL: + p->opp_program_left_edge_extra_pixel_params.opp = + pipe->stream_res.opp; + p->opp_program_left_edge_extra_pixel_params.pixel_encoding = + pipe->stream->timing.pixel_encoding; + p->opp_program_left_edge_extra_pixel_params.is_otg_master = + !pipe->prev_odm_pipe; + break; + case DCCG_SET_DTO_DSCCLK: + p->dccg_set_dto_dscclk_params.dccg = dc->res_pool->dccg; + p->dccg_set_dto_dscclk_params.inst = pipe->stream_res.dsc->inst; + p->dccg_set_dto_dscclk_params.num_slices_h = + pipe->stream->timing.dsc_cfg.num_slices_h / + resource_get_odm_slice_count(pipe); + break; + case DSC_SET_CONFIG: + if (!hwss_prepare_dsc_config_for_pipe(pipe, + resource_get_odm_slice_count(pipe), 0, NULL)) { + (*sequence->num_steps)--; + return; + } + p->dsc_set_config_params.dsc = pipe->stream_res.dsc; + break; + case DSC_ENABLE: + p->dsc_enable_params.dsc = pipe->stream_res.dsc; + p->dsc_enable_params.opp_inst = pipe->stream_res.opp->inst; + break; + case TG_SET_DSC_CONFIG: + dcn401_dsc_config_params(pipe, m->tg_set_dsc_config.enable, + &p->tg_set_dsc_config_params); + break; + case DSC_DISCONNECT: + p->dsc_disconnect_params.dsc = pipe->stream_res.dsc; + break; + case DSC_DISABLE: + p->dsc_disable_params.dsc = pipe->stream_res.dsc; + break; + case DCCG_SET_REF_DSCCLK: + p->dccg_set_ref_dscclk_params.dccg = dc->res_pool->dccg; + p->dccg_set_ref_dscclk_params.dsc = pipe->stream_res.dsc; + break; + case OPP_PROGRAM_FMT: + p->opp_program_fmt_params.opp = pipe->stream_res.opp; + p->opp_program_fmt_params.fmt_bit_depth = + &pipe->stream->bit_depth_params; + p->opp_program_fmt_params.clamping = &pipe->stream->clamping; + break; + case OPP_SET_DYN_EXPANSION: + p->opp_set_dyn_expansion_params.opp = pipe->stream_res.opp; + p->opp_set_dyn_expansion_params.color_space = + COLOR_SPACE_YCBCR601; + p->opp_set_dyn_expansion_params.color_depth = + pipe->stream->timing.display_color_depth; + p->opp_set_dyn_expansion_params.signal = pipe->stream->signal; + break; + case OPP_SET_DISP_PATTERN_GENERATOR: + dcn401_opp_blank_params(dc, pipe, + m->opp_set_disp_pattern_generator.unblank, + &p->opp_set_disp_pattern_generator_params); + break; + case OPP_WAIT_FOR_BLANK_COMPLETE: + p->opp_wait_for_blank_complete_params.opp = + pipe->stream_res.opp; + p->opp_wait_for_blank_complete_params.polling_interval_us = + DCN401_DPG_POLL_INTERVAL_US; + p->opp_wait_for_blank_complete_params.timeout_us = + DCN401_DPG_POLL_TIMEOUT_US; + /* DC1 ignores the result of dcn20_wait_for_blank_complete. */ + p->opp_wait_for_blank_complete_params.continue_on_error = true; + break; + case OPP_PROGRAM_STEREO: + p->opp_program_stereo_params.opp = pipe->stream_res.opp; + p->opp_program_stereo_params.timing = &pipe->stream->timing; + break; + case DCCG_SET_DTBCLK_P_SRC: + p->dccg_set_dtbclk_p_src_params.dccg = dc->res_pool->dccg; + p->dccg_set_dtbclk_p_src_params.src = + m->dccg_set_dtbclk_p_src.src; + p->dccg_set_dtbclk_p_src_params.otg_inst = + pipe->stream_res.tg->inst; + break; + case DCCG_SET_PIXEL_RATE_DIV: + p->dccg_set_pixel_rate_div_params.dccg = dc->res_pool->dccg; + p->dccg_set_pixel_rate_div_params.otg_inst = + pipe->stream_res.tg->inst; + p->dccg_set_pixel_rate_div_params.k1 = + dcn401_pixel_rate_div(pipe); + p->dccg_set_pixel_rate_div_params.k2 = PIXEL_RATE_DIV_NA; + break; + case CLK_SRC_PROGRAM_PIX_CLK: + p->clk_src_program_pix_clk_params.clock_source = + pipe->clock_source; + p->clk_src_program_pix_clk_params.pix_clk_params = + &pipe->stream_res.pix_clk_params; + /* DC1 gives virtual a dummy 8b/10b DP link setting. */ + p->clk_src_program_pix_clk_params.encoding = DP_8b_10b_ENCODING; + p->clk_src_program_pix_clk_params.pll_settings = + &pipe->pll_settings; + break; + case CLK_SRC_POWER_DOWN: + p->clk_src_power_down_params.clock_source = pipe->clock_source; + /* dcn401_reset_hw_ctx_wrap ignores a failed power-down. */ + p->clk_src_power_down_params.continue_on_error = true; + break; + case DIO_LINK_ENC_CONNECT_DIG_BE_TO_FE: + p->link_enc_connect_dig_be_to_fe_params.link_enc = + pipe->stream->link->link_enc; + p->link_enc_connect_dig_be_to_fe_params.engine = + pipe->stream_res.stream_enc->id; + p->link_enc_connect_dig_be_to_fe_params.connect = + m->link_enc_connect_dig_be_to_fe.connect; + break; + case DIO_LINK_ENC_ENABLE_DP_OUTPUT: + p->link_enc_enable_dp_output_params.link_enc = + pipe->stream->link->link_enc; + p->link_enc_enable_dp_output_params.link_settings = + &pipe->link_config.dp_link_settings; + p->link_enc_enable_dp_output_params.clock_source = + pipe->clock_source->id; + break; + case DIO_LINK_ENC_DISABLE_OUTPUT: + p->link_enc_disable_output_params.link_enc = + pipe->stream->link->link_enc; + p->link_enc_disable_output_params.signal = + SIGNAL_TYPE_DISPLAY_PORT; + break; + case DCCG_ENABLE_SYMCLK_SE: + p->dccg_enable_symclk_se_params.dccg = dc->res_pool->dccg; + p->dccg_enable_symclk_se_params.stream_enc_inst = + pipe->stream_res.stream_enc->stream_enc_inst; + p->dccg_enable_symclk_se_params.link_enc_inst = + pipe->stream->link->link_enc->transmitter - + TRANSMITTER_UNIPHY_A; + break; + case DCCG_DISABLE_SYMCLK_SE: + p->dccg_disable_symclk_se_params.dccg = dc->res_pool->dccg; + p->dccg_disable_symclk_se_params.stream_enc_inst = + pipe->stream_res.stream_enc->stream_enc_inst; + p->dccg_disable_symclk_se_params.link_enc_inst = + pipe->stream->link->link_enc->transmitter - + TRANSMITTER_UNIPHY_A; + break; + case HUBP_PROGRAM_DET_SEGMENTS: + p->program_det_segments_params.hubbub = dc->res_pool->hubbub; + p->program_det_segments_params.hubp_inst = + pipe->plane_res.hubp->inst; + if (m->hubp_program_det_segments.allocate) + p->program_det_segments_params.det_size = + pipe->hubp_regs.det_size; + break; + case MPC_REMOVE_MPCC: + p->mpc_remove_mpcc_params.mpc = dc->res_pool->mpc; + p->mpc_remove_mpcc_params.mpc_tree_params = + &pipe->stream_res.opp->mpc_tree_params; + p->mpc_remove_mpcc_params.mpcc_to_remove = + &dc->res_pool->mpc->mpcc_array[ + pipe->plane_res.mpcc_inst]; + break; + case MPC_ASSERT_IDLE_MPCC: + p->mpc_assert_idle_mpcc_params.mpc = dc->res_pool->mpc; + p->mpc_assert_idle_mpcc_params.mpcc_id = + pipe->plane_res.mpcc_inst; + break; + case HUBP_SET_BLANK: + p->hubp_set_blank_params.hubp = pipe->plane_res.hubp; + p->hubp_set_blank_params.blank = !m->hubp_set_blank.unblank; + break; + case HUBP_UPDATE_MALL_SEL: + if (m->hubp_update_mall_sel.from_new_state) + dcn401_mall_sel_params(dc, args->new_state, pipe, + &p->hubp_update_mall_sel_params); + else + p->hubp_update_mall_sel_params.hubp = + pipe->plane_res.hubp; + break; + case HUBP_SET_FLIP_CONTROL_GSL: + p->set_flip_control_gsl_params.hubp = pipe->plane_res.hubp; + p->set_flip_control_gsl_params.flip_immediate = + plane->flip_immediate; + break; + case HUBP_CLK_CNTL: + p->hubp_clk_cntl_params.hubp = pipe->plane_res.hubp; + p->hubp_clk_cntl_params.enable = m->hubp_clk_cntl.enable; + break; + case DPP_DPPCLK_CONTROL: + p->dpp_dppclk_control_params.dpp = dpp; + p->dpp_dppclk_control_params.enable = + m->dpp_dppclk_control.enable; + break; + case DC_IP_REQUEST_STATUS: + p->dc_ip_request_status_params.hws = dc->hwseq; + break; + case DC_IP_REQUEST_CNTL: + p->dc_ip_request_cntl_params.hws = dc->hwseq; + p->dc_ip_request_cntl_params.enable = + m->dc_ip_request_cntl.enable; + break; + case HUBP_PG_CONTROL: + p->hubp_pg_control_params.hws = dc->hwseq; + p->hubp_pg_control_params.hubp_inst = + pipe->plane_res.hubp->inst; + p->hubp_pg_control_params.power_on = + m->hubp_pg_control.power_on; + p->hubp_pg_control_params.disable_power_gate = + dc->debug.disable_hubp_power_gate; + p->hubp_pg_control_params.ignore_pg = dc->debug.ignore_pg; + break; + case HUBP_RESET: + p->hubp_reset_params.hubp = pipe->plane_res.hubp; + break; + case DPP_RESET: + p->dpp_reset_params.dpp = dpp; + break; + case TG_WAIT_FOR_ALL_PENDING_UPDATES: + p->tg_wait_for_all_pending_updates_params.tg = + pipe->stream_res.tg; + p->tg_wait_for_all_pending_updates_params.include_pipe_update = + plane != NULL; + p->tg_wait_for_all_pending_updates_params.polling_interval_us = + DCN401_PENDING_UPDATE_POLL_INTERVAL_US; + p->tg_wait_for_all_pending_updates_params.timeout_us = + DCN401_PENDING_UPDATE_TIMEOUT_US; + break; + case HUBP_PROGRAM_TRIPLEBUFFER: + p->program_triplebuffer_params.hubp = pipe->plane_res.hubp; + p->program_triplebuffer_params.enableTripleBuffer = + plane->triplebuffer_flips; + break; + case DC_UDELAY: + p->dc_udelay_params.us = DCN401_PLANE_ENABLE_DELAY_US; + break; + case TG_PROGRAM_GLOBAL_SYNC: + p->tg_program_global_sync_params.tg = pipe->stream_res.tg; + p->tg_program_global_sync_params.vready_offset = + pipe->global_sync.dcn4x.vready_offset_pixels; + p->tg_program_global_sync_params.vstartup_lines = + pipe->global_sync.dcn4x.vstartup_lines; + p->tg_program_global_sync_params.vupdate_offset_pixels = + pipe->global_sync.dcn4x.vupdate_offset_pixels; + p->tg_program_global_sync_params.vupdate_vupdate_width_pixels = + pipe->global_sync.dcn4x + .vupdate_vupdate_width_pixels; + p->tg_program_global_sync_params.pstate_keepout_start_lines = + pipe->global_sync.dcn4x.pstate_keepout_start_lines; + break; + case TG_WAIT_FOR_STATE: + p->tg_wait_for_state_params.tg = pipe->stream_res.tg; + p->tg_wait_for_state_params.state = CRTC_STATE_VACTIVE; + break; + case TG_SET_VTG_PARAMS: + p->tg_set_vtg_params_params.tg = pipe->stream_res.tg; + p->tg_set_vtg_params_params.timing = &pipe->stream->timing; + p->tg_set_vtg_params_params.program_fp2 = true; + break; + case HUBP_INIT: + p->hubp_init_params.hubp = pipe->plane_res.hubp; + break; + case HUBBUB_FORCE_WM_PROPAGATE_TO_PIPES: + p->hubbub_force_wm_propagate_to_pipes_params.hubbub = + dc->res_pool->hubbub; + break; + case DCCG_UPDATE_DPP_DTO: + p->dccg_update_dpp_dto_params.dccg = dc->res_pool->dccg; + p->dccg_update_dpp_dto_params.dpp_inst = dpp->inst; + p->dccg_update_dpp_dto_params.dppclk_khz = + pipe->plane_res.bw.dppclk_khz; + break; + case HUBP_VTG_SEL: + p->hubp_vtg_sel_params.hubp = pipe->plane_res.hubp; + p->hubp_vtg_sel_params.otg_inst = pipe->stream_res.tg->inst; + break; + case HUBP_SETUP2: + p->hubp_setup2_params.hubp = pipe->plane_res.hubp; + p->hubp_setup2_params.hubp_regs = &pipe->hubp_regs; + p->hubp_setup2_params.global_sync = &pipe->global_sync; + p->hubp_setup2_params.timing = &pipe->stream->timing; + break; + case HUBP_SET_UNBOUNDED_REQUESTING: + p->hubp_set_unbounded_requesting_params.hubp = pipe->plane_res.hubp; + p->hubp_set_unbounded_requesting_params.unbounded_req = + pipe->unbounded_req; + break; + case HUBP_SETUP_INTERDEPENDENT2: + p->hubp_setup_interdependent2_params.hubp = pipe->plane_res.hubp; + p->hubp_setup_interdependent2_params.hubp_regs = + &pipe->hubp_regs; + break; + case DPP_SETUP_DPP: + p->setup_dpp_params.dpp = dpp; + p->setup_dpp_params.format = plane->format; + p->setup_dpp_params.input_csc_color_matrix = + plane->input_csc_color_matrix; + p->setup_dpp_params.color_space = plane->color_space; + p->setup_dpp_params.upsp_mode = resource_is_upsp_required( + (bool) plane->ctx->dc->caps.color.dpp.upsp_pre_scaler, plane->format, plane->scaling_linearity); + break; + case DPP_SET_CURSOR_MATRIX: + p->dpp_set_cursor_matrix_params.dpp = dpp; + p->dpp_set_cursor_matrix_params.color_space = + plane->color_space; + p->dpp_set_cursor_matrix_params.cursor_csc_color_matrix = + &plane->cursor_csc_color_matrix; + break; + case DPP_PROGRAM_BIAS_AND_SCALE: + p->program_bias_and_scale_params.dpp = dpp; + p->program_bias_and_scale_params.bias_and_scale = + plane->bias_and_scale; + break; + case MPC_INSERT_PLANE: + p->mpc_insert_plane_params.mpc = dc->res_pool->mpc; + p->mpc_insert_plane_params.mpc_tree_params = + &pipe->stream_res.opp->mpc_tree_params; + dcn401_blnd_cfg(plane, &p->mpc_insert_plane_params.blnd_cfg); + p->mpc_insert_plane_params.dpp_id = pipe->plane_res.hubp->inst; + p->mpc_insert_plane_params.mpcc_id = pipe->plane_res.hubp->inst; + break; + case MPC_UPDATE_VISUAL_CONFIRM: + p->update_visual_confirm_params.mpc = dc->res_pool->mpc; + p->update_visual_confirm_params.color = + &pipe->visual_confirm_color; + p->update_visual_confirm_params.mpcc_id = pipe->plane_res.hubp->inst; + break; + case DPP_SET_SCALER: + p->dpp_set_scaler_params.dpp = dpp; + p->dpp_set_scaler_params.scl_data = &pipe->plane_res.scl_data; + break; + case HUBP_MEM_PROGRAM_VIEWPORT: + p->hubp_mem_program_viewport_params.hubp = pipe->plane_res.hubp; + p->hubp_mem_program_viewport_params.viewport = + &pipe->plane_res.scl_data.viewport; + p->hubp_mem_program_viewport_params.viewport_c = + &pipe->plane_res.scl_data.viewport_c; + break; + case HUBP_PROGRAM_MCACHE_ID: + p->program_mcache_id_and_split_coordinate.hubp = pipe->plane_res.hubp; + p->program_mcache_id_and_split_coordinate.mcache_regs = + &pipe->mcache_regs; + break; + case MPC_SET_GAMUT_REMAP_BYPASS: + p->mpc_set_gamut_remap_bypass_params.mpc = dc->res_pool->mpc; + p->mpc_set_gamut_remap_bypass_params.mpcc_id = + pipe->plane_res.mpcc_inst; + p->mpc_set_gamut_remap_bypass_params.block_id = + m->mpc_set_gamut_remap_bypass.block_id; + break; + case MPC_POWER_ON_MPC_MEM_PWR: + p->power_on_mpc_mem_pwr_params.mpc = dc->res_pool->mpc; + p->power_on_mpc_mem_pwr_params.mpcc_id = pipe->plane_res.hubp->inst; + p->power_on_mpc_mem_pwr_params.power_on = true; + break; + case MPC_SET_OCSC_DEFAULT: + p->set_ocsc_default_params.mpc = dc->res_pool->mpc; + p->set_ocsc_default_params.opp_id = pipe->stream_res.opp->inst; + p->set_ocsc_default_params.color_space = + pipe->stream->output_color_space; + p->set_ocsc_default_params.ocsc_mode = MPC_OUTPUT_CSC_COEF_A; + break; + case HUBP_PROGRAM_SURFACE_CONFIG: + p->program_surface_config_params.hubp = pipe->plane_res.hubp; + p->program_surface_config_params.format = plane->format; + p->program_surface_config_params.tiling_info = + &plane->tiling_info; + p->program_surface_config_params.plane_size = + plane->plane_size; + p->program_surface_config_params.plane_size.surface_size = + pipe->plane_res.scl_data.viewport; + p->program_surface_config_params.rotation = plane->rotation; + p->program_surface_config_params.dcc = &plane->dcc; + p->program_surface_config_params.horizontal_mirror = + plane->horizontal_mirror; + break; + case HUBP_UPDATE_PLANE_ADDR: + p->update_plane_addr_params.hubp = pipe->plane_res.hubp; + p->update_plane_addr_params.address = plane->address; + p->update_plane_addr_params.flip_immediate = + plane->flip_immediate; + p->update_plane_addr_params.dcc = plane->dcc.enable; + break; + case DPP_SET_HDR_MULTIPLIER: + p->dpp_set_hdr_multiplier_params.dpp = dpp; + p->dpp_set_hdr_multiplier_params.hw_mult = + dcn401_hdr_mult(plane); + break; + case DPP_SET_PRE_DEGAM: + p->dpp_set_pre_degam_params.dpp = dpp; + p->dpp_set_pre_degam_params.in_transfer_func = + &plane->in_transfer_func; + break; + case DPP_PROGRAM_GAMCOR_LUT: + p->dpp_program_gamcor_lut_params.dpp = dpp; + if (plane->in_transfer_func.type == TF_TYPE_HWPWL) + p->dpp_program_gamcor_lut_params.params = + &plane->in_transfer_func.pwl; + break; + case MPC_SET_MOVABLE_CM_LOCATION: + p->mpc_set_movable_cm_location_params.mpc = dc->res_pool->mpc; + p->mpc_set_movable_cm_location_params.location = + MPCC_MOVABLE_CM_LOCATION_BEFORE; + p->mpc_set_movable_cm_location_params.mpcc_id = + pipe->plane_res.mpcc_inst; + break; + case MPC_PROGRAM_LUT_MODE: + /* + * Every LUT is off. DC1 reads the bank back with get_lut_mode; + * the build reads no hardware, so it assumes bank A for an + * MPCC that held no plane. + */ + p->mpc_program_lut_mode_params.mpc = dc->res_pool->mpc; + p->mpc_program_lut_mode_params.id = m->mpc_program_lut_mode.id; + p->mpc_program_lut_mode_params.lut_bank_a = true; + p->mpc_program_lut_mode_params.size = dcn401_lut_mode_size( + plane, m->mpc_program_lut_mode.id); + p->mpc_program_lut_mode_params.mpcc_id = + pipe->plane_res.mpcc_inst; + break; + case HUBP_PROGRAM_3DLUT_FL_CONFIG: + p->hubp_program_3dlut_fl_config_params.hubp = pipe->plane_res.hubp; + p->hubp_program_3dlut_fl_config_params.config = + &dcn401_3dlut_dma_off; + break; + case HUBP_SET_3DLUT_FL: + p->hubp_set_3dlut_fl_params.hubp = pipe->plane_res.hubp; + break; + case MPC_SET_OUTPUT_GAMMA: + p->mpc_set_output_gamma_params.mpc = dc->res_pool->mpc; + p->mpc_set_output_gamma_params.mpcc_id = + pipe->plane_res.mpcc_inst; + if (pipe->stream->out_transfer_func.type == TF_TYPE_HWPWL) + p->mpc_set_output_gamma_params.params = + &pipe->stream->out_transfer_func.pwl; + break; + case HUBP_WAIT_FLIP_PENDING: + p->hubp_wait_flip_pending_params.hubp = pipe->plane_res.hubp; + p->hubp_wait_flip_pending_params.polling_interval_us = + DCN401_FLIP_PENDING_POLL_INTERVAL_US; + break; + case OPTC_PROGRAM_MANUAL_TRIGGER: + p->program_manual_trigger_params.tg = pipe->stream_res.tg; + break; + default: + /* The step tables use only the funcs above. */ + ASSERT(false); + break; + } +} + +static void dcn401_eval_pipe_deltas(const struct dcn401_commit_step_args *args, + unsigned int idx, struct dcn401_pipe_deltas *deltas) +{ + const struct dc_state_pipe_flags *cur_f = + &args->update_flags->cur_pipes[idx]; + const struct dc_state_pipe_flags *new_f = + &args->update_flags->new_pipes[idx]; + const struct pipe_ctx *cur = &args->current_state->res_ctx.pipe_ctx[idx]; + const struct pipe_ctx *new = &args->new_state->res_ctx.pipe_ctx[idx]; + + deltas->hubp_dpp_already_enabled = cur_f->enabled && new_f->enabled && + cur->stream->stream_id == new->stream->stream_id && + cur->plane_res.hubp->inst == new->plane_res.hubp->inst && + cur->plane_res.dpp->inst == new->plane_res.dpp->inst && + cur->stream_res.opp->inst == new->stream_res.opp->inst; + deltas->det_unchanged = cur_f->det_size == new_f->det_size; + deltas->current_has_no_plane = !cur_f->has_plane; + deltas->odm_kept = new->stream && dcn401_same_opp_heads( + args->current_state, args->new_state, new->stream); +} + +static bool dcn401_pipe_deltas_match(const struct dcn401_pipe_deltas *skip, + const struct dcn401_pipe_deltas *deltas, bool all) +{ + const bool named[] = { skip->hubp_dpp_already_enabled, + skip->det_unchanged, skip->current_has_no_plane, + skip->odm_kept }; + const bool set[] = { deltas->hubp_dpp_already_enabled, + deltas->det_unchanged, deltas->current_has_no_plane, + deltas->odm_kept }; + bool any = false; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(named); i++) { + if (!named[i]) + continue; + if (all && !set[i]) + return false; + any |= set[i]; + } + return any; +} + +static bool dcn401_skip_step(const struct dcn401_commit_step_args *args, + const struct dcn401_commit_step *step) +{ + const struct dcn401_pipe_deltas *skip = &step->meta.skip_if.pipe_deltas; + struct dcn401_pipe_deltas deltas; + const struct pipe_ctx *cur, *new; + + if (step->meta.skip_if.only_addresses_changed && + !args->hardware_remapped && !args->pipe_configs_changed) + return true; + if (step->meta.only_if.hardware_not_remapped && args->hardware_remapped) + return true; + if (step->meta.only_if.pipe_configs_not_changed && + args->pipe_configs_changed) + return true; + if (step->meta.skip_if.new_state_has_stream && + args->new_state->stream_count) + return true; + if (step->meta.skip_if.stream_unchanged && args->stream_unchanged) + return true; + if (step->meta.skip_if.optimized_not_required && + !args->dc->optimized_required) + return true; + if (step->meta.skip_if.no_ip_request && + (!args->dc->hwseq->funcs.pg_needs_ip_request || + !args->dc->hwseq->funcs.pg_needs_ip_request(args->dc))) + return true; + /* The remaining conditions are for per-pipe steps. */ + if (!args->pipe) + return false; + cur = &args->current_state->res_ctx.pipe_ctx[args->pipe->pipe_idx]; + new = &args->new_state->res_ctx.pipe_ctx[args->pipe->pipe_idx]; + dcn401_eval_pipe_deltas(args, args->pipe->pipe_idx, &deltas); + if (step->meta.skip_if.no_addr_update && + !args->update_flags->new_pipes[args->pipe->pipe_idx] + .plane.addr_update) + return true; + if (step->meta.skip_if.no_manual_trigger && + (!args->pipe->plane_state->update_bits.addr_update || + args->pipe->plane_state->skip_manual_trigger)) + return true; + if (step->meta.skip_if.opp_tree_empty && + (!args->pipe->stream_res.opp || + !args->pipe->stream_res.opp->mpc_tree_params.opp_list)) + return true; + if (step->meta.skip_if.no_dsc && !args->pipe->stream_res.dsc) + return true; + if (step->meta.skip_if.no_timing_sync_source && + !args->timing_sync_source) + return true; + if (dcn401_pipe_deltas_match(skip, &deltas, + step->meta.skip_if.pipe_deltas_all)) + return true; + if (step->meta.skip_if.scaling_unchanged && + !args->pipe->plane_state->update_bits.scaling_change && + !args->pipe->plane_state->update_bits.position_change && + !args->pipe->stream->update_flags.bits.scaling && + (!deltas.hubp_dpp_already_enabled || + !memcmp(&cur->plane_res.scl_data, &new->plane_res.scl_data, + sizeof(cur->plane_res.scl_data)))) + return true; + return false; +} + +static void dcn401_add_steps(struct block_sequence_state *sequence, + const struct dcn401_commit_step_args *args, + const struct dcn401_commit_step *steps, unsigned int count) +{ + unsigned int i; + + for (i = 0; i < count; i++) { + if (!dcn401_skip_step(args, &steps[i])) + dcn401_add_step(sequence, args, &steps[i]); + } +} + +static bool dcn401_walks_stream(const struct dcn401_commit_step_args *args, + const struct dc_stream_state *stream) +{ + if (args->stream) + return stream->stream_id == args->stream->stream_id; + return !dcn401_stream_kept(args->dc, args->current_state, + args->new_state, stream); +} + +/* + * The OTG master that pipe resets to, chosen as program_timing_sync does: + * the first OTG master with the same timing that shows a plane, else the + * first one. NULL when that is pipe. + */ +static const struct pipe_ctx *dcn401_timing_sync_source( + const struct dcn401_commit_step_args *args, + const struct pipe_ctx *pipe) +{ + const struct dc_state_update_flags *flags = args->update_flags; + const struct pipe_ctx *source = NULL; + const struct pipe_ctx *member; + unsigned int i; + + if (args->dc->debug.disable_timing_sync) + return NULL; + for (i = 0; i < args->dc->res_pool->pipe_count; i++) { + member = &args->new_state->res_ctx.pipe_ctx[i]; + if (!member->stream || member->top_pipe || + member->prev_odm_pipe || + !resource_are_streams_timing_synchronizable( + member->stream, pipe->stream)) + continue; + if (flags->cur_pipes[i].has_plane && + flags->new_pipes[i].has_plane) { + source = member; + break; + } + if (!source) + source = member; + } + if (!source || source->pipe_idx == pipe->pipe_idx) + return NULL; + return source; +} + +static void dcn401_add_per_otg_master(struct block_sequence_state *sequence, + const struct dcn401_commit_step_args *state_args, + struct dc_state *state, + const struct dcn401_commit_step *steps, unsigned int count) +{ + struct dcn401_commit_step_args args = *state_args; + unsigned int i; + + for (i = 0; i < state->stream_count; i++) { + if (!dcn401_walks_stream(&args, state->streams[i])) + continue; + args.pipe = resource_get_otg_master_for_stream( + &state->res_ctx, state->streams[i]); + if (!args.pipe) + continue; + args.timing_sync_source = dcn401_timing_sync_source(&args, + args.pipe); + dcn401_add_steps(sequence, &args, steps, count); + } +} + +static void dcn401_add_per_opp_head(struct block_sequence_state *sequence, + const struct dcn401_commit_step_args *state_args, + struct dc_state *state, + const struct dcn401_commit_step *steps, unsigned int count) +{ + struct dcn401_commit_step_args args = *state_args; + struct pipe_ctx *opp_heads[MAX_PIPES]; + unsigned int i; + int j, n; + + for (i = 0; i < state->stream_count; i++) { + if (!dcn401_walks_stream(&args, state->streams[i])) + continue; + n = resource_get_opp_heads_for_stream(state->streams[i], + &state->res_ctx, opp_heads); + for (j = 0; j < n; j++) { + args.pipe = opp_heads[j]; + dcn401_add_steps(sequence, &args, steps, count); + } + } +} + +static void dcn401_add_per_dpp_pipe(struct block_sequence_state *sequence, + const struct dcn401_commit_step_args *state_args, + struct dc_state *state, const struct dcn401_sub_sequence *sub) +{ + struct dcn401_commit_step_args args = *state_args; + struct pipe_ctx *dpp_pipes[MAX_PIPES]; + unsigned int i, k; + int j, n; + + for (i = 0; i < state->stream_count; i++) { + if (!dcn401_walks_stream(&args, state->streams[i])) + continue; + n = resource_get_dpp_pipes_for_stream(state->streams[i], + &state->res_ctx, dpp_pipes); + for (j = 0; j < n; j++) { + args.pipe = dpp_pipes[j]; + if (!sub->stages) { + dcn401_add_steps(sequence, &args, sub->steps, + sub->count); + continue; + } + for (k = 0; k < sub->stage_count; k++) + dcn401_add_steps(sequence, &args, + sub->stages[k].steps, + sub->stages[k].count); + } + } +} + +void dcn401_add_sub_sequences(struct block_sequence_state *sequence, + const struct dcn401_commit_step_args *state_args, + const struct dcn401_sub_sequence *subs, unsigned int count) +{ + const struct dcn401_sub_sequence *sub; + struct dc_state *state; + unsigned int i; + + for (i = 0; i < count; i++) { + sub = &subs[i]; + state = sub->flags & DCN401_CURRENT_STATE ? + state_args->current_state : + state_args->new_state; + if (sub->flags & DCN401_PER_STREAM_PER_OTG_MASTER) + dcn401_add_per_otg_master(sequence, state_args, state, + sub->steps, sub->count); + else if (sub->flags & DCN401_PER_STREAM_PER_OPP_HEAD) + dcn401_add_per_opp_head(sequence, state_args, state, + sub->steps, sub->count); + else if (sub->flags & DCN401_PER_STREAM_PER_DPP_PIPE) + dcn401_add_per_dpp_pipe(sequence, state_args, state, sub); + else + dcn401_add_steps(sequence, state_args, sub->steps, + sub->count); + } +} + +void dcn401_init_and_unpack_params( + struct bls_builder_declarative_params *params, + struct dcn401_commit_step_args *state_args, + struct block_sequence_state *head) +{ + state_args->dc = params->dc; + state_args->current_state = (struct dc_state *)params->current_state; + state_args->new_state = (struct dc_state *)params->new_state; + state_args->stream = NULL; + state_args->pipe = NULL; + state_args->update_flags = params->update_flags; + state_args->stream_unchanged = false; + state_args->hardware_remapped = true; + state_args->pipe_configs_changed = true; + state_args->timing_sync_source = NULL; + + params->head_num_steps = 0; + params->tail_num_steps = 0; + head->steps = params->head_sequence; + head->num_steps = ¶ms->head_num_steps; +} diff --git a/drivers/gpu/drm/amd/display/dc/bls_builder/dcn401_builder_internal.h b/drivers/gpu/drm/amd/display/dc/bls_builder/dcn401_builder_internal.h index d48330fcc64d..7231fb3ad3fb 100644 --- a/drivers/gpu/drm/amd/display/dc/bls_builder/dcn401_builder_internal.h +++ b/drivers/gpu/drm/amd/display/dc/bls_builder/dcn401_builder_internal.h @@ -83,6 +83,12 @@ const struct pipe_ctx *dcn401_otg_master(const struct dc_state *state, /* The index of stream in state, or -1. */ int dcn401_stream_index(const struct dc_state *state, const struct dc_stream_state *stream); +bool dcn401_pipe_on_stream(const struct pipe_ctx *pipe, + const struct dc_stream_state *stream); +/* stream has the same OPP heads in both states. */ +bool dcn401_same_opp_heads(const struct dc_state *current_state, + const struct dc_state *new_state, + const struct dc_stream_state *stream); /* diff --git a/drivers/gpu/drm/amd/display/dc/bls_builder/dcn401_seamless_builder.c b/drivers/gpu/drm/amd/display/dc/bls_builder/dcn401_seamless_builder.c index 9ad9081b1b9a..00b25ec4f57a 100644 --- a/drivers/gpu/drm/amd/display/dc/bls_builder/dcn401_seamless_builder.c +++ b/drivers/gpu/drm/amd/display/dc/bls_builder/dcn401_seamless_builder.c @@ -21,10 +21,6 @@ #include "bls_builder/dcn401_builder_internal.h" #include "state_facts/state_facts.h" -#undef DC_LOGGER -#define DC_LOGGER \ - dc->ctx->logger - /* * DCN_DECL_SEAMLESS_UPDATE for one of the virtual streams that * DCN_DECL_NON_SEAMLESS_COMMIT (dcn401_non_seamless_builder.c) enabled. @@ -43,475 +39,10 @@ * stream changes, the update is a flip: it locks the pipe, programs the * address and unlocks, with no DMUB command and no DMUB lock. * - * This file also holds what both builders share: the dc and stream - * support checks, and the step walkers that turn a table into BLS entries. - * * Neither builder emits a tail_sequence. A tail runs only after a vsync, * and Core has no wait-for-vsync imperative yet, so Core rejects a tail. */ -#define DCN401_DPG_POLL_INTERVAL_US 100 -#define DCN401_DPG_POLL_TIMEOUT_US 100000 -#define DCN401_STATIC_SCREEN_NUM_FRAMES 2 -#define DCN401_PENDING_UPDATE_POLL_INTERVAL_US 1 -#define DCN401_PENDING_UPDATE_TIMEOUT_US 100000 -#define DCN401_RESET_TRIGGER_WAIT_FRAMES 10 -#define DCN401_FLIP_PENDING_POLL_INTERVAL_US 100 -#define DCN401_PLANE_ENABLE_DELAY_US 500 -/* 1.0 in the HDR multiplier and MPCC gain format. */ -#define DCN401_UNITY_GAIN 0x1f000 -#define DCN401_MALL_SEL_SS 2 -#define DCN401_CACHE_CURSOR_BYTES 16384 - -void dcn401_commit_check_failed(const struct dc *dc, const char *msg) -{ - if (dc && dc->ctx && dc->ctx->logger) - DC_LOG_DEBUG("%s\n", msg); -} - -static bool check_dc_resources(const struct dc *dc, - const struct dc_state *current_state, - const struct dc_state *new_state) -{ - (void)current_state; - (void)new_state; - return dc->res_pool && dc->res_pool->hubbub && dc->res_pool->dccg && - dc->res_pool->mpc && dc->hwseq && dc->clk_mgr && - dc->ctx && dc->ctx->dc_bios; -} - -static bool check_fams2_debug(const struct dc *dc, - const struct dc_state *current_state, - const struct dc_state *new_state) -{ - (void)current_state; - (void)new_state; - return !dc->debug.fams2_config.bits.enable; -} - -static bool check_cursor_offload(const struct dc *dc, - const struct dc_state *current_state, - const struct dc_state *new_state) -{ - (void)current_state; - (void)new_state; - return !dc->ctx->dmub_srv || !dc->ctx->dmub_srv->cursor_offload_enabled; -} - -static bool check_dc_mode_softmax(const struct dc *dc, - const struct dc_state *current_state, - const struct dc_state *new_state) -{ - (void)current_state; - (void)new_state; - return !dc->clk_mgr->dc_mode_softmax_enabled; -} - -static bool check_visual_confirm(const struct dc *dc, - const struct dc_state *current_state, - const struct dc_state *new_state) -{ - (void)current_state; - (void)new_state; - return dc->debug.visual_confirm == VISUAL_CONFIRM_DISABLE && - !dc->debug.force_dpg_on_flip && - !dc->debug.enable_hblank_borrow && - !dc->debug.enable_otg_frame_sync_pwa; -} - -/* With the DSC power gate disabled, update_dsc_pg only reads. */ -static bool check_dsc_power_gate(const struct dc *dc, - const struct dc_state *current_state, - const struct dc_state *new_state) -{ - (void)current_state; - (void)new_state; - return dc->debug.disable_dsc_power_gate; -} - -enum bls_builder_result dcn401_check_dc_support(const struct dc *dc) -{ - const struct dc_state *current_state = NULL; - const struct dc_state *new_state = NULL; - - CHECK_RESOURCE(dc_resources, "dc resources are missing"); - CHECK_CONDITION(fams2_debug, "FAMS2 debug is enabled"); - CHECK_CONDITION(cursor_offload, "cursor offload is enabled"); - CHECK_CONDITION(dc_mode_softmax, "dc mode softmax is enabled"); - CHECK_CONDITION(visual_confirm, - "visual confirm, dpg, hblank borrow, or frame sync is set"); - CHECK_CONDITION(dsc_power_gate, "DSC power gate is enabled"); - return BLS_BUILD_SUCCESS; -} - -static bool check_no_phantom(const struct dc *dc, - const struct dc_state *current_state, - const struct dc_state *new_state) -{ - (void)dc; - return !dcn401_checked_state(current_state, - new_state)->phantom_stream_count; -} - -static bool check_fams2_state(const struct dc *dc, - const struct dc_state *current_state, - const struct dc_state *new_state) -{ - const struct dc_state *state = dcn401_checked_state(current_state, - new_state); - - (void)dc; - return !state->bw_ctx.bw.dcn.fams2_global_config.features.bits.enable; -} - -static bool check_stream_link(const struct dc *dc, - const struct dc_state *state, unsigned int i) -{ - (void)dc; - return state->streams[i] && state->streams[i]->link; -} - -/* link_set_dpms_on and _off program nothing for a virtual signal. */ -static bool check_virtual_signal(const struct dc *dc, - const struct dc_state *state, unsigned int i) -{ - (void)dc; - (void)state; - (void)i; - return false; -} - -static bool check_link_encoder(const struct dc *dc, - const struct dc_state *state, unsigned int i) -{ - const struct dc_link *link = state->streams[i]->link; - - (void)dc; - return link->ep_type == DISPLAY_ENDPOINT_PHY && link->link_enc; -} - -static bool check_no_interlace(const struct dc *dc, - const struct dc_state *state, unsigned int i) -{ - (void)dc; - return !state->streams[i]->timing.flags.INTERLACE; -} - -static bool check_no_stereo(const struct dc *dc, - const struct dc_state *state, unsigned int i) -{ - (void)dc; - return state->streams[i]->timing.timing_3d_format == - TIMING_3D_FORMAT_NONE; -} - -static bool check_no_drr(const struct dc *dc, - const struct dc_state *state, unsigned int i) -{ - const struct dc_stream_state *stream = state->streams[i]; - - (void)dc; - return !stream->ignore_msa_timing_param && - !stream->adjust.v_total_min && - !stream->adjust.v_total_max; -} - -static bool check_no_boot_dpms_writeback(const struct dc *dc, - const struct dc_state *state, unsigned int i) -{ - const struct dc_stream_state *stream = state->streams[i]; - - (void)dc; - return !stream->apply_seamless_boot_optimization && !stream->dpms_off && - !stream->num_wb_info; -} - -static bool check_abm(const struct dc *dc, - const struct dc_state *state, unsigned int i) -{ - const struct dc_stream_state *stream = state->streams[i]; - - (void)dc; - return !stream->abm_level || - stream->abm_level == ABM_LEVEL_IMMEDIATE_DISABLE; -} - -/* - * An MPC bottom pipe or an ODM slice of the stream is not an OTG master; - * check_mpc_blend and check_odm_combine bound them. - */ -const struct pipe_ctx *dcn401_otg_master(const struct dc_state *state, - const struct dc_stream_state *stream) -{ - const struct pipe_ctx *otg_master = NULL; - unsigned int i; - - for (i = 0; i < MAX_PIPES; i++) { - const struct pipe_ctx *pipe = &state->res_ctx.pipe_ctx[i]; - - if (!stream || !pipe->stream || - pipe->stream->stream_id != stream->stream_id || - pipe->top_pipe || pipe->prev_odm_pipe) - continue; - if (otg_master) - return NULL; - otg_master = pipe; - } - return otg_master; -} - -int dcn401_stream_index(const struct dc_state *state, - const struct dc_stream_state *stream) -{ - int i; - - if (!stream) - return -1; - for (i = 0; i < state->stream_count; i++) - if (state->streams[i]->stream_id == stream->stream_id) - return i; - return -1; -} - -#define DCN401_SAME_INST(a, b) \ - ((!(a) && !(b)) || ((a) && (b) && (a)->inst == (b)->inst)) - -static bool dcn401_pipe_on_stream(const struct pipe_ctx *pipe, - const struct dc_stream_state *stream) -{ - return pipe->stream && pipe->stream->stream_id == stream->stream_id; -} - -/* The plane is compared as an object: planes have no DC-assigned id yet. */ -static bool dcn401_pipe_layout_unchanged(const struct pipe_ctx *cur, - const struct pipe_ctx *new) -{ - return cur->plane_state == new->plane_state && - DCN401_SAME_INST(cur->plane_res.hubp, new->plane_res.hubp) && - DCN401_SAME_INST(cur->plane_res.dpp, new->plane_res.dpp) && - DCN401_SAME_INST(cur->stream_res.tg, new->stream_res.tg) && - DCN401_SAME_INST(cur->stream_res.opp, new->stream_res.opp) && - !cur->top_pipe == !new->top_pipe && - !cur->bottom_pipe == !new->bottom_pipe && - !cur->prev_odm_pipe == !new->prev_odm_pipe && - !cur->next_odm_pipe == !new->next_odm_pipe; -} - -bool dcn401_stream_unchanged(const struct dc_state *current_state, - const struct dc_state *new_state, - const struct dc_stream_state *stream) -{ - const struct pipe_ctx *cur, *new; - unsigned int i; - - if (dcn401_stream_index(current_state, stream) < 0 || - dcn401_stream_index(new_state, stream) < 0) - return false; - for (i = 0; i < MAX_PIPES; i++) { - cur = ¤t_state->res_ctx.pipe_ctx[i]; - new = &new_state->res_ctx.pipe_ctx[i]; - if (dcn401_pipe_on_stream(cur, stream) != - dcn401_pipe_on_stream(new, stream)) - return false; - if (dcn401_pipe_on_stream(new, stream) && - !dcn401_pipe_layout_unchanged(cur, new)) - return false; - } - return true; -} - -static bool check_otg_master_present(const struct dc *dc, - const struct dc_state *state, unsigned int i) -{ - (void)dc; - return dcn401_otg_master(state, state->streams[i]) != NULL; -} - -/* At most DCN401_MAX_OPP_HEADS ODM slices, each with an OPP. */ -static bool check_odm_combine(const struct dc *dc, - const struct dc_state *state, unsigned int i) -{ - const struct pipe_ctx *odm = dcn401_otg_master(state, - state->streams[i]); - unsigned int count = 0; - - (void)dc; - for (; odm; odm = odm->next_odm_pipe) - if (!odm->stream_res.opp || ++count > DCN401_MAX_OPP_HEADS) - return false; - return count; -} - -static bool check_mpc_blend(const struct dc *dc, - const struct dc_state *state, unsigned int i) -{ - struct dc_state_facts facts; - - (void)dc; - dc_state_facts_derive(state, &facts); - /* - * At most one bottom pipe, on the master's OTG and OPP. A bottom pipe - * and ODM do not go together. - */ - return facts.global.blend_tree[i].dpp_pipe_count <= 2 && - facts.global.blend_tree[i].on_otg_master_blocks && - (facts.global.blend_tree[i].dpp_pipe_count == 1 || - !dc_state_facts_any_pipe(&facts, (uint8_t)i, - DC_TRAIT_MATCH(DC_PIPE_TRAIT_ODM, 0))); -} - -static bool check_otg_master_blocks(const struct dc *dc, - const struct dc_state *state, unsigned int i) -{ - const struct pipe_ctx *pipe = dcn401_otg_master(state, - state->streams[i]); - - (void)dc; - return pipe && pipe->stream_res.tg && pipe->stream_res.opp && - pipe->stream_res.stream_enc && pipe->clock_source; -} - -static bool check_pipe_audio(const struct dc *dc, - const struct dc_state *state, unsigned int i) -{ - const struct pipe_ctx *pipe = dcn401_otg_master(state, - state->streams[i]); - - (void)dc; - return pipe && !pipe->stream_res.audio; -} - -static bool check_pipe_dsc(const struct dc *dc, - const struct dc_state *state, unsigned int i) -{ - const struct dc_stream_state *stream = state->streams[i]; - struct pipe_ctx *opp_heads[MAX_PIPES]; - int j, n; - - (void)dc; - n = resource_get_opp_heads_for_stream(stream, - (struct resource_context *)&state->res_ctx, opp_heads); - for (j = 0; j < n; j++) - if (!opp_heads[j]->stream_res.dsc != !stream->timing.flags.DSC) - return false; - return true; -} - -static bool check_dsc_pixel_clock(const struct dc *dc, - const struct dc_state *state, unsigned int i) -{ - const struct dc_crtc_timing *timing = &state->streams[i]->timing; - - (void)dc; - return !timing->flags.DSC || timing->pix_clk_100hz > 480000; -} - -static bool check_pipe_gsl(const struct dc *dc, - const struct dc_state *state, unsigned int i) -{ - const struct pipe_ctx *pipe = dcn401_otg_master(state, - state->streams[i]); - - (void)dc; - return pipe && !pipe->stream_res.gsl_group; -} - -static bool check_link_enc_assignment(const struct dc *dc, - const struct dc_state *state, unsigned int i) -{ - const struct pipe_ctx *pipe = dcn401_otg_master(state, - state->streams[i]); - - if (!dc->config.unify_link_enc_assignment) - return true; - return pipe && pipe->link_res.dio_link_enc == - pipe->stream->link->link_enc; -} - -/* Each stream on its own link. */ -static bool check_own_link(const struct dc *dc, - const struct dc_state *state, unsigned int i) -{ - unsigned int j; - - (void)dc; - for (j = 0; j < i; j++) - if (state->streams[j]->link == state->streams[i]->link) - return false; - return true; -} - -static enum bls_builder_result dcn401_check_one_stream(const struct dc *dc, - const struct dc_state *state, unsigned int i) -{ - CHECK_STREAM_RESOURCE(stream_link, "stream has no link"); - CHECK_STREAM_CONDITION(own_link, "streams share a link"); - CHECK_STREAM_CONDITION(virtual_signal, "signal is not virtual"); - CHECK_STREAM_RESOURCE(link_encoder, "link encoder is not DIO"); - CHECK_STREAM_CONDITION(no_interlace, "timing is interlace"); - CHECK_STREAM_CONDITION(no_stereo, "timing is stereo"); - CHECK_STREAM_CONDITION(dsc_pixel_clock, - "dsc pixel clock is 48 MHz or less"); - CHECK_STREAM_CONDITION(no_drr, "DRR is set"); - CHECK_STREAM_CONDITION(no_boot_dpms_writeback, - "seamless boot, dpms, or writeback is set"); - CHECK_STREAM_CONDITION(abm, "ABM level is set"); - CHECK_STREAM_RESOURCE(otg_master_present, - "stream has no otg master, or more than one"); - CHECK_STREAM_CONDITION(odm_combine, "odm is not bypass, 2:1 or 3:1"); - CHECK_STREAM_CONDITION(mpc_blend, - "more than one bottom pipe, off the otg or opp, or with odm"); - CHECK_STREAM_RESOURCE(otg_master_blocks, - "otg master is missing a stream resource or pixel clock"); - CHECK_STREAM_CONDITION(pipe_audio, "audio is set"); - CHECK_STREAM_RESOURCE(pipe_dsc, - "dsc differs from the timing on an opp head"); - CHECK_STREAM_CONDITION(pipe_gsl, "gsl is set"); - CHECK_STREAM_CONDITION(link_enc_assignment, - "link encoder assignment differs"); - return BLS_BUILD_SUCCESS; -} - -/* Every pipe with a stream belongs to a stream of the state. */ -static bool check_pipe_streams(const struct dc *dc, - const struct dc_state *current_state, - const struct dc_state *new_state) -{ - const struct dc_state *state = dcn401_checked_state(current_state, - new_state); - unsigned int i; - - (void)dc; - for (i = 0; i < MAX_PIPES; i++) - if (state->res_ctx.pipe_ctx[i].stream && - dcn401_stream_index(state, - state->res_ctx.pipe_ctx[i].stream) < 0) - return false; - return true; -} - -enum bls_builder_result dcn401_check_stream_support(const struct dc *dc, - const struct dc_state *current_state, - const struct dc_state *new_state) -{ - const struct dc_state *state = dcn401_checked_state(current_state, - new_state); - enum bls_builder_result result; - unsigned int i; - - if (!state) - return BLS_BUILD_ERROR_UNSUPPORTED_STATE_UPDATE; - CHECK_CONDITION(no_phantom, "a phantom stream is set"); - CHECK_CONDITION(fams2_state, "fams2 is enabled"); - CHECK_CONDITION(pipe_streams, "a pipe has a stream the state lacks"); - for (i = 0; i < state->stream_count; i++) { - result = dcn401_check_one_stream(dc, state, i); - if (result != BLS_BUILD_SUCCESS) - return result; - } - return BLS_BUILD_SUCCESS; -} - /* * The update keeps every stream. A stream other than the updated one keeps * its pipes, planes and blocks. @@ -933,33 +464,6 @@ static bool check_no_cursor(const struct dc *dc, return !new_state->streams[i]->cursor_attributes.address.quad_part; } -static bool dcn401_same_opp_heads(const struct dc_state *current_state, - const struct dc_state *new_state, - const struct dc_stream_state *stream) -{ - const struct pipe_ctx *cur = dcn401_otg_master(current_state, stream); - const struct pipe_ctx *new = dcn401_otg_master(new_state, stream); - struct pipe_ctx *cur_heads[MAX_PIPES], *new_heads[MAX_PIPES]; - int i, n; - - if (!cur || !new) - return false; - n = resource_get_opp_heads_for_otg_master(cur, - (struct resource_context *)¤t_state->res_ctx, - cur_heads); - if (n != resource_get_opp_heads_for_otg_master(new, - (struct resource_context *)&new_state->res_ctx, - new_heads)) - return false; - for (i = 0; i < n; i++) - if (!cur_heads[i]->stream_res.opp || - !new_heads[i]->stream_res.opp || - cur_heads[i]->stream_res.opp->inst != - new_heads[i]->stream_res.opp->inst) - return false; - return true; -} - static bool check_dsc_odm_kept(const struct dc *dc, const struct dc_state *current_state, const struct dc_state *new_state, unsigned int i) @@ -1452,92 +956,6 @@ static const struct dcn401_commit_step optc_dsc[] = { .meta.skip_if.pipe_deltas_all = true }, }; -/* - * Under the lock, each current pipe that the update removes leaves its - * MPCC and returns its DET segments, as DC1 disconnects a disabled pipe. - */ -const struct dcn401_commit_step dcn401_disconnect[DCN401_DISCONNECT_STEPS] = { - { .func = HUBP_PROGRAM_DET_SEGMENTS, - .meta.skip_if.stream_unchanged = true, - .meta.skip_if.only_addresses_changed = true, - .meta.skip_if.pipe_deltas.current_has_no_plane = true, - .meta.skip_if.pipe_deltas.hubp_dpp_already_enabled = true }, - { .func = MPC_REMOVE_MPCC, - .meta.skip_if.stream_unchanged = true, - .meta.skip_if.only_addresses_changed = true, - .meta.skip_if.pipe_deltas.current_has_no_plane = true, - .meta.skip_if.pipe_deltas.hubp_dpp_already_enabled = true }, -}; - -/* After the unlock, disable_plane on each removed pipe. */ -const struct dcn401_commit_step dcn401_power_down[DCN401_POWER_DOWN_STEPS] = { - { .func = MPC_ASSERT_IDLE_MPCC, - .meta.skip_if.stream_unchanged = true, - .meta.skip_if.only_addresses_changed = true, - .meta.skip_if.pipe_deltas.current_has_no_plane = true, - .meta.skip_if.pipe_deltas.hubp_dpp_already_enabled = true }, - { .func = HUBP_SET_BLANK, - .meta.skip_if.stream_unchanged = true, - .meta.skip_if.only_addresses_changed = true, - .meta.skip_if.pipe_deltas.current_has_no_plane = true, - .meta.skip_if.pipe_deltas.hubp_dpp_already_enabled = true }, - { .func = HUBP_UPDATE_MALL_SEL, - .meta.skip_if.stream_unchanged = true, - .meta.skip_if.only_addresses_changed = true, - .meta.skip_if.pipe_deltas.current_has_no_plane = true, - .meta.skip_if.pipe_deltas.hubp_dpp_already_enabled = true }, - { .func = HUBP_SET_FLIP_CONTROL_GSL, - .meta.skip_if.stream_unchanged = true, - .meta.skip_if.only_addresses_changed = true, - .meta.skip_if.pipe_deltas.current_has_no_plane = true, - .meta.skip_if.pipe_deltas.hubp_dpp_already_enabled = true }, - { .func = HUBP_CLK_CNTL, - .meta.skip_if.stream_unchanged = true, - .meta.skip_if.only_addresses_changed = true, - .meta.skip_if.pipe_deltas.current_has_no_plane = true, - .meta.skip_if.pipe_deltas.hubp_dpp_already_enabled = true }, - { .func = DPP_DPPCLK_CONTROL, - .meta.skip_if.stream_unchanged = true, - .meta.skip_if.only_addresses_changed = true, - .meta.skip_if.pipe_deltas.current_has_no_plane = true, - .meta.skip_if.pipe_deltas.hubp_dpp_already_enabled = true }, - { .func = DC_IP_REQUEST_STATUS, - .meta.skip_if.stream_unchanged = true, - .meta.skip_if.only_addresses_changed = true, - .meta.skip_if.no_ip_request = true, - .meta.skip_if.pipe_deltas.current_has_no_plane = true, - .meta.skip_if.pipe_deltas.hubp_dpp_already_enabled = true }, - { .func = DC_IP_REQUEST_CNTL, - .meta.skip_if.stream_unchanged = true, - .meta.skip_if.only_addresses_changed = true, - .meta.dc_ip_request_cntl.enable = true, - .meta.skip_if.no_ip_request = true, - .meta.skip_if.pipe_deltas.current_has_no_plane = true, - .meta.skip_if.pipe_deltas.hubp_dpp_already_enabled = true }, - { .func = HUBP_PG_CONTROL, - .meta.skip_if.stream_unchanged = true, - .meta.skip_if.only_addresses_changed = true, - .meta.skip_if.pipe_deltas.current_has_no_plane = true, - .meta.skip_if.pipe_deltas.hubp_dpp_already_enabled = true }, - { .func = HUBP_RESET, - .meta.skip_if.stream_unchanged = true, - .meta.skip_if.only_addresses_changed = true, - .meta.skip_if.pipe_deltas.current_has_no_plane = true, - .meta.skip_if.pipe_deltas.hubp_dpp_already_enabled = true }, - { .func = DPP_RESET, - .meta.skip_if.stream_unchanged = true, - .meta.skip_if.only_addresses_changed = true, - .meta.skip_if.pipe_deltas.current_has_no_plane = true, - .meta.skip_if.pipe_deltas.hubp_dpp_already_enabled = true }, - { .func = DC_IP_REQUEST_CNTL, - .meta.skip_if.stream_unchanged = true, - .meta.skip_if.only_addresses_changed = true, - .meta.dc_ip_request_cntl.enable = false, - .meta.skip_if.no_ip_request = true, - .meta.skip_if.pipe_deltas.current_has_no_plane = true, - .meta.skip_if.pipe_deltas.hubp_dpp_already_enabled = true }, -}; - /* enable_plane, then the watermark propagate and the DET segments. */ /* Ungate and clock the HUBP and DPP of a pipe brought up. */ static const struct dcn401_commit_step ungate_hw[] = { @@ -1818,1216 +1236,6 @@ static const struct dcn401_commit_step trigger[] = { .meta.skip_if.no_manual_trigger = true }, }; -/* enable_stream_timing_calc: manual mode unless every span is even. */ -static bool dcn401_h_timing_div_manual_mode( - const struct dc_crtc_timing *timing) -{ - unsigned int h_blank_start = timing->h_total - timing->h_front_porch; - unsigned int h_blank_end = h_blank_start - timing->h_addressable; - - return (timing->h_total % 2) || (h_blank_start % 2) || - (h_blank_end % 2) || (timing->h_sync_width % 2); -} - -/* dcn10_get_vupdate_offset_from_vsync for progressive timing. */ -static int dcn401_vupdate_start_line(const struct pipe_ctx *pipe) -{ - const struct dc_crtc_timing *timing = &pipe->stream->timing; - int front_porch = timing->v_front_porch ? timing->v_front_porch : 1; - int vesa_sync_start = timing->v_addressable + timing->v_border_bottom + - front_porch; - int asic_blank_end = timing->v_total - vesa_sync_start - - timing->v_border_top; - int start_line = asic_blank_end - - (int)pipe->pipe_dlg_param.vstartup_start + 1; - - return start_line < 0 ? 0 : start_line; -} - -/* dcn401_enable_stream_calc's early control for this lane count. */ -static uint32_t dcn401_early_cntl(const struct pipe_ctx *pipe) -{ - const struct dc_crtc_timing *timing = &pipe->stream->timing; - unsigned int lane_count = - pipe->stream->link->cur_link_settings.lane_count; - uint32_t early_cntl = 0; - - if (lane_count) - early_cntl = (timing->h_addressable + timing->h_border_left + - timing->h_border_right) % lane_count; - return early_cntl ? early_cntl : lane_count; -} - -/* - * dcn20_blank_pixel_data: the black of the output color space over the ODM - * slice of this OPP head, or the video on unblank. - */ -static void dcn401_opp_blank_params(const struct dc *dc, - struct pipe_ctx *pipe, bool unblank, - struct opp_set_disp_pattern_generator_params *p) -{ - const struct dc_crtc_timing *timing = &pipe->stream->timing; - struct rect slice = resource_get_odm_slice_src_rect(pipe); - - p->opp = pipe->stream_res.opp; - p->test_pattern = unblank ? CONTROLLER_DP_TEST_PATTERN_VIDEOMODE : - CONTROLLER_DP_TEST_PATTERN_SOLID_COLOR; - p->color_space = CONTROLLER_DP_COLOR_SPACE_UDEFINED; - p->color_depth = timing->display_color_depth; - color_space_to_black_color(dc, pipe->stream->output_color_space, - &p->solid_color); - p->use_solid_color = true; - p->width = slice.width; - p->height = slice.height; - p->offset = slice.x; - p->disable_dyn_exp_for_test_pattern = - dc->debug.disable_dynamic_expansion_for_test_pattern; -} - -/* - * dcn401_update_odm: one OPP per ODM slice, in slice order. A table's - * OPTC_SET_ODM_COMBINE programs the ODM unconditionally: N:1 combine for - * N > 1 slices, else bypass. - */ -static void dcn401_odm_combine_params(struct pipe_ctx *otg_master, - struct set_odm_combine_params *p) -{ - struct pipe_ctx *odm; - - p->tg = otg_master->stream_res.tg; - for (odm = otg_master; odm; odm = odm->next_odm_pipe) - p->opp_inst[p->opp_head_count++] = odm->stream_res.opp->inst; - p->odm_slice_width = resource_get_odm_slice_dst_width(otg_master, - false); - p->last_odm_slice_width = resource_get_odm_slice_dst_width(otg_master, - true); -} - -static void dcn401_dsc_config_params(struct pipe_ctx *otg_master, - bool enable, struct tg_set_dsc_config_params *p) -{ - struct dsc_optc_config optc; - - p->tg = otg_master->stream_res.tg; - p->dsc_mode = OPTC_DSC_DISABLED; - if (!enable || !hwss_prepare_dsc_config_for_pipe(otg_master, - resource_get_odm_slice_count(otg_master), 0, &optc)) - return; - p->dsc_mode = optc.is_pixel_format_444 ? OPTC_DSC_ENABLED_444 : - OPTC_DSC_ENABLED_NATIVE_SUBSAMPLED; - p->bytes_per_pixel = optc.bytes_per_pixel; - p->slice_width = optc.slice_width; -} - -static void dcn401_program_timing_params(const struct pipe_ctx *pipe, - struct tg_program_timing_params *p) -{ - const union dml2_global_sync_programming *sync = &pipe->global_sync; - - p->tg = pipe->stream_res.tg; - p->timing = &pipe->stream->timing; - p->vready_offset = sync->dcn4x.vready_offset_pixels; - p->vstartup_start = sync->dcn4x.vstartup_lines; - p->vupdate_offset = sync->dcn4x.vupdate_offset_pixels; - p->vupdate_width = sync->dcn4x.vupdate_vupdate_width_pixels; - p->pstate_keepout = sync->dcn4x.pstate_keepout_start_lines; - p->signal = pipe->stream->signal; - p->use_vbios = true; -} - -static void dcn401_drr_params(const struct pipe_ctx *pipe, bool with_mid, - struct drr_params *drr) -{ - const struct dc_crtc_timing_adjust *adjust = &pipe->stream->adjust; - - drr->vertical_total_min = adjust->v_total_min; - drr->vertical_total_max = adjust->v_total_max; - if (with_mid) { - drr->vertical_total_mid = adjust->v_total_mid; - drr->vertical_total_mid_frame_num = - adjust->v_total_mid_frame_num; - } -} - -static void dcn401_update_clocks_params(const struct dc *dc, - struct dc_state *context, bool safe_to_lower, - struct clk_mgr_update_clocks_for_state_params *p) -{ - p->clk_mgr = dc->clk_mgr; - p->context = context; - p->safe_to_lower = safe_to_lower; - p->disallow_p_state_change = !safe_to_lower && - context->bw_ctx.bw.dcn.clk.p_state_change_support; -} - -/* dcn401_update_mpcc_sequence's blending for the plane. */ -static void dcn401_blnd_cfg(const struct dc_plane_state *plane, - struct mpcc_blnd_cfg *cfg) -{ - cfg->overlap_only = false; - cfg->global_gain = 0xff; - if (plane->per_pixel_alpha) { - cfg->pre_multiplied_alpha = plane->pre_multiplied_alpha; - if (plane->global_alpha) { - cfg->alpha_mode = - MPCC_ALPHA_BLEND_MODE_PER_PIXEL_ALPHA_COMBINED_GLOBAL_GAIN; - cfg->global_gain = plane->global_alpha_value; - } else { - cfg->alpha_mode = MPCC_ALPHA_BLEND_MODE_PER_PIXEL_ALPHA; - } - } else { - cfg->pre_multiplied_alpha = false; - cfg->alpha_mode = MPCC_ALPHA_BLEND_MODE_GLOBAL_ALPHA; - } - cfg->global_alpha = plane->global_alpha ? - plane->global_alpha_value : 0xff; - cfg->background_color_bpc = 4; - cfg->bottom_gain_mode = 0; - cfg->top_gain = DCN401_UNITY_GAIN; - cfg->bottom_inside_gain = DCN401_UNITY_GAIN; - cfg->bottom_outside_gain = DCN401_UNITY_GAIN; - if (plane->format == SURFACE_PIXEL_FORMAT_GRPH_RGBE_ALPHA) - cfg->pre_multiplied_alpha = false; -} - -/* dcn401_set_hdr_multiplier_sequence: 1.0 unless the plane sets one. */ -static uint32_t dcn401_hdr_mult(const struct dc_plane_state *plane) -{ - struct custom_float_format fmt = { - .exponenta_bits = 6, - .mantissa_bits = 12, - .sign = true, - }; - uint32_t hw_mult = DCN401_UNITY_GAIN; - - if (!dc_fixpt_eq(plane->hdr_mult, dc_fixpt_from_int(0)) && - !convert_to_custom_float_format(plane->hdr_mult, &fmt, - &hw_mult)) - hw_mult = DCN401_UNITY_GAIN; - return hw_mult; -} - -/* dcn401_program_mall_pipe_config_sequence for one non-phantom pipe. */ -static void dcn401_mall_sel_params(struct dc *dc, struct dc_state *state, - struct pipe_ctx *pipe, struct hubp_update_mall_sel_params *p) -{ - const struct hubp *hubp = pipe->plane_res.hubp; - const struct dc_plane_address *address = &pipe->plane_state->address; - int cursor_size = hubp->curs_attr.pitch * hubp->curs_attr.height; - uint32_t mall_ss_size_bytes; - uint32_t num_ways = 0; - - switch (hubp->curs_attr.color_format) { - case CURSOR_MODE_MONO: - cursor_size /= 2; - break; - case CURSOR_MODE_COLOR_1BIT_AND: - case CURSOR_MODE_COLOR_PRE_MULTIPLIED_ALPHA: - case CURSOR_MODE_COLOR_UN_PRE_MULTIPLIED_ALPHA: - cursor_size *= 4; - break; - default: - cursor_size *= 8; - break; - } - - /* - * dcn401_calculate_cab_allocation also adds the cursor mall bytes. - * This builder rejects a cursor, so those bytes are zero. The helper - * that computes them is built only with CONFIG_DRM_AMD_DC_FP. - */ - mall_ss_size_bytes = state->bw_ctx.bw.dcn.mall_ss_size_bytes; - if (dc->debug.force_mall_ss_num_ways > 0) - num_ways = dc->debug.force_mall_ss_num_ways; - else if (dc->res_pool->funcs->calculate_mall_ways_from_bytes) - num_ways = dc->res_pool->funcs->calculate_mall_ways_from_bytes( - dc, mall_ss_size_bytes); - - p->hubp = pipe->plane_res.hubp; - p->cache_cursor = cursor_size > DCN401_CACHE_CURSOR_BYTES; - p->mall_sel = num_ways <= dc->caps.cache_num_ways && - pipe->stream->link->psr_settings.psr_version == - DC_PSR_VERSION_UNSUPPORTED && - address->type != PLN_ADDR_TYPE_GRPH_STEREO && - !address->tmz_surface ? DCN401_MALL_SEL_SS : 0; -} - -/* dcn401_set_mcm_luts clears the HUBP 3DLUT fast load with this. */ -static const struct dc_3dlut_dma dcn401_3dlut_dma_off = {0}; - -/* dcn401_set_mcm_luts sizes the off 3DLUT by the plane's LUT. */ -static enum dc_cm_lut_size dcn401_lut_mode_size( - const struct dc_plane_state *plane, enum MCM_LUT_ID id) -{ - if (id != MCM_LUT_3DLUT) - return CM_LUT_SIZE_NONE; - return plane->cm.lut3d_func.lut_3d.use_tetrahedral_9 ? - CM_LUT_SIZE_999 : CM_LUT_SIZE_171717; -} - -/* - * The divider dcn401_enable_stream_timing sets for the virtual signal. The - * divide by one dcn401_enable_stream passes later is a no-op, because - * dccg401_set_pixel_rate_div accepts only 2 and 4. The hwseq is built only - * with DC_FP; the builder is built without it. - */ -static enum pixel_rate_div dcn401_pixel_rate_div( - const struct pipe_ctx *pipe) -{ - return pipe->stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR420 ? - PIXEL_RATE_DIV_BY_2 : PIXEL_RATE_DIV_BY_4; -} - -/* Writes one entry; build sized every sequence before adding to it. */ -static void dcn401_add_step(struct block_sequence_state *sequence, - const struct dcn401_commit_step_args *args, - const struct dcn401_commit_step *step) -{ - struct block_sequence *entry; - union block_sequence_params *p; - struct dc *dc = args->dc; - struct dcn_bw_output *bw = &args->new_state->bw_ctx.bw.dcn; - struct pipe_ctx *pipe; - struct dpp *dpp; - struct dc_plane_state *plane; - const struct dcn401_commit_step_meta *m = &step->meta; - - if (*sequence->num_steps >= DC2_BLS_MAX_STEPS) { - if (*sequence->num_steps == DC2_BLS_MAX_STEPS && - dc->debug.dc2_bls_report_step_overflow && - dc->ctx && dc->ctx->logger) { - DC_LOG_ERROR("%s: more than %u BLS steps\n", __func__, - DC2_BLS_MAX_STEPS); - BREAK_TO_DEBUGGER(); - } - (*sequence->num_steps)++; - return; - } - entry = &sequence->steps[(*sequence->num_steps)++]; - p = &entry->params; - memset(entry, 0, sizeof(*entry)); - entry->func = step->func; - /* - * Bandwidth and p-state steps have no pipe. Handle them before the - * pipe is used, then every later case can use the pipe directly. - */ - if (!args->pipe) { - switch (step->func) { - case CLK_MGR_UPDATE_CLOCKS_FOR_STATE: - dcn401_update_clocks_params(dc, args->new_state, - m->clk_mgr_update_clocks_for_state - .safe_to_lower, - &p->clk_mgr_update_clocks_for_state_params); - return; - case HUBBUB_PROGRAM_WATERMARKS: - p->hubbub_program_watermarks_params = - hwss_prepare_hubbub_program_watermarks(dc, - dc->res_pool->hubbub, &bw->watermarks, - dc->res_pool->ref_clocks.dchub_ref_clock_inKhz / - 1000, - m->hubbub_program_watermarks.safe_to_lower); - return; - case HUBBUB_PROGRAM_ARBITER: - p->hubbub_program_arbiter_params = - hwss_prepare_hubbub_program_arbiter( - dc->res_pool->hubbub, &bw->arb_regs, - m->hubbub_program_arbiter.safe_to_lower); - return; - case HUBBUB_PROGRAM_COMPBUF_SEGMENTS: - p->hubbub_program_compbuf_segments_params.hubbub = - dc->res_pool->hubbub; - p->hubbub_program_compbuf_segments_params.compbuf_size = - m->hubbub_program_compbuf_segments - .use_current_state_size ? - args->current_state->bw_ctx.bw.dcn.arb_regs - .compbuf_size : bw->arb_regs.compbuf_size; - p->hubbub_program_compbuf_segments_params.safe_to_lower = - m->hubbub_program_compbuf_segments - .safe_to_lower; - return; - case HUBBUB_FORCE_PSTATE_CHANGE_CONTROL: - p->hubbub_force_pstate_change_control_params.hubbub = - dc->res_pool->hubbub; - p->hubbub_force_pstate_change_control_params.enable = - m->hubbub_force_pstate_change_control.enable; - return; - default: - (*sequence->num_steps)--; - return; - } - } - pipe = args->pipe; - dpp = pipe->plane_res.dpp; - plane = pipe->plane_state; - switch (step->func) { - case CLK_MGR_UPDATE_CLOCKS_FOR_STATE: - dcn401_update_clocks_params(dc, args->new_state, - m->clk_mgr_update_clocks_for_state - .safe_to_lower, - &p->clk_mgr_update_clocks_for_state_params); - break; - case HUBBUB_PROGRAM_WATERMARKS: - p->hubbub_program_watermarks_params = - hwss_prepare_hubbub_program_watermarks(dc, - dc->res_pool->hubbub, &bw->watermarks, - dc->res_pool->ref_clocks.dchub_ref_clock_inKhz / - 1000, - m->hubbub_program_watermarks.safe_to_lower); - break; - case HUBBUB_PROGRAM_ARBITER: - p->hubbub_program_arbiter_params = - hwss_prepare_hubbub_program_arbiter( - dc->res_pool->hubbub, &bw->arb_regs, - m->hubbub_program_arbiter.safe_to_lower); - break; - case HUBBUB_PROGRAM_COMPBUF_SEGMENTS: - p->hubbub_program_compbuf_segments_params.hubbub = - dc->res_pool->hubbub; - p->hubbub_program_compbuf_segments_params.compbuf_size = - m->hubbub_program_compbuf_segments - .use_current_state_size ? - args->current_state->bw_ctx.bw.dcn.arb_regs - .compbuf_size : bw->arb_regs.compbuf_size; - p->hubbub_program_compbuf_segments_params.safe_to_lower = - m->hubbub_program_compbuf_segments - .safe_to_lower; - break; - case HUBBUB_FORCE_PSTATE_CHANGE_CONTROL: - p->hubbub_force_pstate_change_control_params.hubbub = - dc->res_pool->hubbub; - p->hubbub_force_pstate_change_control_params.enable = - m->hubbub_force_pstate_change_control.enable; - break; - case BIOS_SET_SCRATCH_CRITICAL_STATE: - p->bios_set_scratch_critical_state_params.dcb = - dc->ctx->dc_bios; - p->bios_set_scratch_critical_state_params.state = - m->bios_set_scratch_critical_state.state; - break; - case TG_LOCK: - p->tg_lock_params.dc = dc; - p->tg_lock_params.tg = pipe->stream_res.tg; - p->tg_lock_params.lock = m->tg_lock.lock; - break; - case TG_ENABLE_CRTC: - p->tg_enable_crtc_params.tg = pipe->stream_res.tg; - break; - case TG_DISABLE_CRTC: - p->tg_disable_crtc_params.tg = pipe->stream_res.tg; - break; - case TG_WAIT_ODM_DOUBLEBUFFER_PENDING_CLEAR: - p->tg_wait_odm_doublebuffer_pending_clear_params.tg = - pipe->stream_res.tg; - break; - case TG_ENABLE_RESET_TRIGGER: - p->tg_enable_reset_trigger_params.tg = pipe->stream_res.tg; - p->tg_enable_reset_trigger_params.source_tg_inst = - args->timing_sync_source->stream_res.tg->inst; - break; - case TG_WAIT_FOR_RESET_TRIGGER: - p->tg_wait_for_reset_trigger_params.tg = pipe->stream_res.tg; - p->tg_wait_for_reset_trigger_params.frames = - DCN401_RESET_TRIGGER_WAIT_FRAMES; - p->tg_wait_for_reset_trigger_params.continue_on_error = true; - break; - case TG_DISABLE_RESET_TRIGGER: - p->tg_disable_reset_trigger_params.tg = pipe->stream_res.tg; - break; - case TG_ENABLE_OPTC_CLOCK: - p->tg_enable_optc_clock_params.tg = pipe->stream_res.tg; - p->tg_enable_optc_clock_params.enable = - m->tg_enable_optc_clock.enable; - break; - case TG_SET_DRR: - p->tg_set_drr_params.tg = pipe->stream_res.tg; - if (m->tg_set_drr.from_adjust) - dcn401_drr_params(pipe, m->tg_set_drr.with_mid, - &p->tg_set_drr_params.drr); - break; - case TG_SET_STATIC_SCREEN_CONTROL: - /* DRR is off, so no static-screen event triggers the OTG. */ - p->tg_set_static_screen_control_params.tg = pipe->stream_res.tg; - p->tg_set_static_screen_control_params.num_frames = - DCN401_STATIC_SCREEN_NUM_FRAMES; - break; - case TG_PROGRAM_TIMING: - dcn401_program_timing_params(pipe, - &p->tg_program_timing_params); - break; - case TG_SET_H_TIMING_DIV_MANUAL_MODE: - p->tg_set_h_timing_div_manual_mode_params.tg = - pipe->stream_res.tg; - p->tg_set_h_timing_div_manual_mode_params.manual_mode = - dcn401_h_timing_div_manual_mode( - &pipe->stream->timing); - break; - case TG_SETUP_VERTICAL_INTERRUPT2: - p->tg_setup_vertical_interrupt2_params.tg = pipe->stream_res.tg; - p->tg_setup_vertical_interrupt2_params.start_line = - dcn401_vupdate_start_line(pipe); - break; - case TG_SET_OUT_MUX: - p->tg_set_out_mux_params.tg = pipe->stream_res.tg; - p->tg_set_out_mux_params.dest = OUT_MUX_DIO; - break; - case TG_SET_EARLY_CONTROL: - p->tg_set_early_control_params.tg = pipe->stream_res.tg; - p->tg_set_early_control_params.early_cntl = - dcn401_early_cntl(pipe); - break; - case TG_PROGRAM_STEREO: - p->tg_program_stereo_params.tg = pipe->stream_res.tg; - p->tg_program_stereo_params.timing = &pipe->stream->timing; - break; - case OPTC_SET_ODM_COMBINE: - if (pipe->next_odm_pipe) { - dcn401_odm_combine_params(pipe, - &p->set_odm_combine_params); - break; - } - entry->func = OPTC_SET_ODM_BYPASS; - p->set_odm_bypass_params.tg = pipe->stream_res.tg; - p->set_odm_bypass_params.timing = &pipe->stream->timing; - break; - case OPTC_SET_ODM_BYPASS: - p->set_odm_bypass_params.tg = pipe->stream_res.tg; - p->set_odm_bypass_params.timing = &pipe->stream->timing; - break; - case OPP_PIPE_CLOCK_CONTROL: - p->opp_pipe_clock_control_params.opp = pipe->stream_res.opp; - p->opp_pipe_clock_control_params.enable = true; - break; - case OPP_PROGRAM_LEFT_EDGE_EXTRA_PIXEL: - p->opp_program_left_edge_extra_pixel_params.opp = - pipe->stream_res.opp; - p->opp_program_left_edge_extra_pixel_params.pixel_encoding = - pipe->stream->timing.pixel_encoding; - p->opp_program_left_edge_extra_pixel_params.is_otg_master = - !pipe->prev_odm_pipe; - break; - case DCCG_SET_DTO_DSCCLK: - p->dccg_set_dto_dscclk_params.dccg = dc->res_pool->dccg; - p->dccg_set_dto_dscclk_params.inst = pipe->stream_res.dsc->inst; - p->dccg_set_dto_dscclk_params.num_slices_h = - pipe->stream->timing.dsc_cfg.num_slices_h / - resource_get_odm_slice_count(pipe); - break; - case DSC_SET_CONFIG: - if (!hwss_prepare_dsc_config_for_pipe(pipe, - resource_get_odm_slice_count(pipe), 0, NULL)) { - (*sequence->num_steps)--; - return; - } - p->dsc_set_config_params.dsc = pipe->stream_res.dsc; - break; - case DSC_ENABLE: - p->dsc_enable_params.dsc = pipe->stream_res.dsc; - p->dsc_enable_params.opp_inst = pipe->stream_res.opp->inst; - break; - case TG_SET_DSC_CONFIG: - dcn401_dsc_config_params(pipe, m->tg_set_dsc_config.enable, - &p->tg_set_dsc_config_params); - break; - case DSC_DISCONNECT: - p->dsc_disconnect_params.dsc = pipe->stream_res.dsc; - break; - case DSC_DISABLE: - p->dsc_disable_params.dsc = pipe->stream_res.dsc; - break; - case DCCG_SET_REF_DSCCLK: - p->dccg_set_ref_dscclk_params.dccg = dc->res_pool->dccg; - p->dccg_set_ref_dscclk_params.dsc = pipe->stream_res.dsc; - break; - case OPP_PROGRAM_FMT: - p->opp_program_fmt_params.opp = pipe->stream_res.opp; - p->opp_program_fmt_params.fmt_bit_depth = - &pipe->stream->bit_depth_params; - p->opp_program_fmt_params.clamping = &pipe->stream->clamping; - break; - case OPP_SET_DYN_EXPANSION: - p->opp_set_dyn_expansion_params.opp = pipe->stream_res.opp; - p->opp_set_dyn_expansion_params.color_space = - COLOR_SPACE_YCBCR601; - p->opp_set_dyn_expansion_params.color_depth = - pipe->stream->timing.display_color_depth; - p->opp_set_dyn_expansion_params.signal = pipe->stream->signal; - break; - case OPP_SET_DISP_PATTERN_GENERATOR: - dcn401_opp_blank_params(dc, pipe, - m->opp_set_disp_pattern_generator.unblank, - &p->opp_set_disp_pattern_generator_params); - break; - case OPP_WAIT_FOR_BLANK_COMPLETE: - p->opp_wait_for_blank_complete_params.opp = - pipe->stream_res.opp; - p->opp_wait_for_blank_complete_params.polling_interval_us = - DCN401_DPG_POLL_INTERVAL_US; - p->opp_wait_for_blank_complete_params.timeout_us = - DCN401_DPG_POLL_TIMEOUT_US; - /* DC1 ignores the result of dcn20_wait_for_blank_complete. */ - p->opp_wait_for_blank_complete_params.continue_on_error = true; - break; - case OPP_PROGRAM_STEREO: - p->opp_program_stereo_params.opp = pipe->stream_res.opp; - p->opp_program_stereo_params.timing = &pipe->stream->timing; - break; - case DCCG_SET_DTBCLK_P_SRC: - p->dccg_set_dtbclk_p_src_params.dccg = dc->res_pool->dccg; - p->dccg_set_dtbclk_p_src_params.src = - m->dccg_set_dtbclk_p_src.src; - p->dccg_set_dtbclk_p_src_params.otg_inst = - pipe->stream_res.tg->inst; - break; - case DCCG_SET_PIXEL_RATE_DIV: - p->dccg_set_pixel_rate_div_params.dccg = dc->res_pool->dccg; - p->dccg_set_pixel_rate_div_params.otg_inst = - pipe->stream_res.tg->inst; - p->dccg_set_pixel_rate_div_params.k1 = - dcn401_pixel_rate_div(pipe); - p->dccg_set_pixel_rate_div_params.k2 = PIXEL_RATE_DIV_NA; - break; - case CLK_SRC_PROGRAM_PIX_CLK: - p->clk_src_program_pix_clk_params.clock_source = - pipe->clock_source; - p->clk_src_program_pix_clk_params.pix_clk_params = - &pipe->stream_res.pix_clk_params; - /* DC1 gives virtual a dummy 8b/10b DP link setting. */ - p->clk_src_program_pix_clk_params.encoding = DP_8b_10b_ENCODING; - p->clk_src_program_pix_clk_params.pll_settings = - &pipe->pll_settings; - break; - case CLK_SRC_POWER_DOWN: - p->clk_src_power_down_params.clock_source = pipe->clock_source; - /* dcn401_reset_hw_ctx_wrap ignores a failed power-down. */ - p->clk_src_power_down_params.continue_on_error = true; - break; - case DIO_LINK_ENC_CONNECT_DIG_BE_TO_FE: - p->link_enc_connect_dig_be_to_fe_params.link_enc = - pipe->stream->link->link_enc; - p->link_enc_connect_dig_be_to_fe_params.engine = - pipe->stream_res.stream_enc->id; - p->link_enc_connect_dig_be_to_fe_params.connect = - m->link_enc_connect_dig_be_to_fe.connect; - break; - case DIO_LINK_ENC_ENABLE_DP_OUTPUT: - p->link_enc_enable_dp_output_params.link_enc = - pipe->stream->link->link_enc; - p->link_enc_enable_dp_output_params.link_settings = - &pipe->link_config.dp_link_settings; - p->link_enc_enable_dp_output_params.clock_source = - pipe->clock_source->id; - break; - case DIO_LINK_ENC_DISABLE_OUTPUT: - p->link_enc_disable_output_params.link_enc = - pipe->stream->link->link_enc; - p->link_enc_disable_output_params.signal = - SIGNAL_TYPE_DISPLAY_PORT; - break; - case DCCG_ENABLE_SYMCLK_SE: - p->dccg_enable_symclk_se_params.dccg = dc->res_pool->dccg; - p->dccg_enable_symclk_se_params.stream_enc_inst = - pipe->stream_res.stream_enc->stream_enc_inst; - p->dccg_enable_symclk_se_params.link_enc_inst = - pipe->stream->link->link_enc->transmitter - - TRANSMITTER_UNIPHY_A; - break; - case DCCG_DISABLE_SYMCLK_SE: - p->dccg_disable_symclk_se_params.dccg = dc->res_pool->dccg; - p->dccg_disable_symclk_se_params.stream_enc_inst = - pipe->stream_res.stream_enc->stream_enc_inst; - p->dccg_disable_symclk_se_params.link_enc_inst = - pipe->stream->link->link_enc->transmitter - - TRANSMITTER_UNIPHY_A; - break; - case HUBP_PROGRAM_DET_SEGMENTS: - p->program_det_segments_params.hubbub = dc->res_pool->hubbub; - p->program_det_segments_params.hubp_inst = - pipe->plane_res.hubp->inst; - if (m->hubp_program_det_segments.allocate) - p->program_det_segments_params.det_size = - pipe->hubp_regs.det_size; - break; - case MPC_REMOVE_MPCC: - p->mpc_remove_mpcc_params.mpc = dc->res_pool->mpc; - p->mpc_remove_mpcc_params.mpc_tree_params = - &pipe->stream_res.opp->mpc_tree_params; - p->mpc_remove_mpcc_params.mpcc_to_remove = - &dc->res_pool->mpc->mpcc_array[ - pipe->plane_res.mpcc_inst]; - break; - case MPC_ASSERT_IDLE_MPCC: - p->mpc_assert_idle_mpcc_params.mpc = dc->res_pool->mpc; - p->mpc_assert_idle_mpcc_params.mpcc_id = - pipe->plane_res.mpcc_inst; - break; - case HUBP_SET_BLANK: - p->hubp_set_blank_params.hubp = pipe->plane_res.hubp; - p->hubp_set_blank_params.blank = !m->hubp_set_blank.unblank; - break; - case HUBP_UPDATE_MALL_SEL: - if (m->hubp_update_mall_sel.from_new_state) - dcn401_mall_sel_params(dc, args->new_state, pipe, - &p->hubp_update_mall_sel_params); - else - p->hubp_update_mall_sel_params.hubp = - pipe->plane_res.hubp; - break; - case HUBP_SET_FLIP_CONTROL_GSL: - p->set_flip_control_gsl_params.hubp = pipe->plane_res.hubp; - p->set_flip_control_gsl_params.flip_immediate = - plane->flip_immediate; - break; - case HUBP_CLK_CNTL: - p->hubp_clk_cntl_params.hubp = pipe->plane_res.hubp; - p->hubp_clk_cntl_params.enable = m->hubp_clk_cntl.enable; - break; - case DPP_DPPCLK_CONTROL: - p->dpp_dppclk_control_params.dpp = dpp; - p->dpp_dppclk_control_params.enable = - m->dpp_dppclk_control.enable; - break; - case DC_IP_REQUEST_STATUS: - p->dc_ip_request_status_params.hws = dc->hwseq; - break; - case DC_IP_REQUEST_CNTL: - p->dc_ip_request_cntl_params.hws = dc->hwseq; - p->dc_ip_request_cntl_params.enable = - m->dc_ip_request_cntl.enable; - break; - case HUBP_PG_CONTROL: - p->hubp_pg_control_params.hws = dc->hwseq; - p->hubp_pg_control_params.hubp_inst = - pipe->plane_res.hubp->inst; - p->hubp_pg_control_params.power_on = - m->hubp_pg_control.power_on; - p->hubp_pg_control_params.disable_power_gate = - dc->debug.disable_hubp_power_gate; - p->hubp_pg_control_params.ignore_pg = dc->debug.ignore_pg; - break; - case HUBP_RESET: - p->hubp_reset_params.hubp = pipe->plane_res.hubp; - break; - case DPP_RESET: - p->dpp_reset_params.dpp = dpp; - break; - case TG_WAIT_FOR_ALL_PENDING_UPDATES: - p->tg_wait_for_all_pending_updates_params.tg = - pipe->stream_res.tg; - p->tg_wait_for_all_pending_updates_params.include_pipe_update = - plane != NULL; - p->tg_wait_for_all_pending_updates_params.polling_interval_us = - DCN401_PENDING_UPDATE_POLL_INTERVAL_US; - p->tg_wait_for_all_pending_updates_params.timeout_us = - DCN401_PENDING_UPDATE_TIMEOUT_US; - break; - case HUBP_PROGRAM_TRIPLEBUFFER: - p->program_triplebuffer_params.hubp = pipe->plane_res.hubp; - p->program_triplebuffer_params.enableTripleBuffer = - plane->triplebuffer_flips; - break; - case DC_UDELAY: - p->dc_udelay_params.us = DCN401_PLANE_ENABLE_DELAY_US; - break; - case TG_PROGRAM_GLOBAL_SYNC: - p->tg_program_global_sync_params.tg = pipe->stream_res.tg; - p->tg_program_global_sync_params.vready_offset = - pipe->global_sync.dcn4x.vready_offset_pixels; - p->tg_program_global_sync_params.vstartup_lines = - pipe->global_sync.dcn4x.vstartup_lines; - p->tg_program_global_sync_params.vupdate_offset_pixels = - pipe->global_sync.dcn4x.vupdate_offset_pixels; - p->tg_program_global_sync_params.vupdate_vupdate_width_pixels = - pipe->global_sync.dcn4x - .vupdate_vupdate_width_pixels; - p->tg_program_global_sync_params.pstate_keepout_start_lines = - pipe->global_sync.dcn4x.pstate_keepout_start_lines; - break; - case TG_WAIT_FOR_STATE: - p->tg_wait_for_state_params.tg = pipe->stream_res.tg; - p->tg_wait_for_state_params.state = CRTC_STATE_VACTIVE; - break; - case TG_SET_VTG_PARAMS: - p->tg_set_vtg_params_params.tg = pipe->stream_res.tg; - p->tg_set_vtg_params_params.timing = &pipe->stream->timing; - p->tg_set_vtg_params_params.program_fp2 = true; - break; - case HUBP_INIT: - p->hubp_init_params.hubp = pipe->plane_res.hubp; - break; - case HUBBUB_FORCE_WM_PROPAGATE_TO_PIPES: - p->hubbub_force_wm_propagate_to_pipes_params.hubbub = - dc->res_pool->hubbub; - break; - case DCCG_UPDATE_DPP_DTO: - p->dccg_update_dpp_dto_params.dccg = dc->res_pool->dccg; - p->dccg_update_dpp_dto_params.dpp_inst = dpp->inst; - p->dccg_update_dpp_dto_params.dppclk_khz = - pipe->plane_res.bw.dppclk_khz; - break; - case HUBP_VTG_SEL: - p->hubp_vtg_sel_params.hubp = pipe->plane_res.hubp; - p->hubp_vtg_sel_params.otg_inst = pipe->stream_res.tg->inst; - break; - case HUBP_SETUP2: - p->hubp_setup2_params.hubp = pipe->plane_res.hubp; - p->hubp_setup2_params.hubp_regs = &pipe->hubp_regs; - p->hubp_setup2_params.global_sync = &pipe->global_sync; - p->hubp_setup2_params.timing = &pipe->stream->timing; - break; - case HUBP_SET_UNBOUNDED_REQUESTING: - p->hubp_set_unbounded_requesting_params.hubp = pipe->plane_res.hubp; - p->hubp_set_unbounded_requesting_params.unbounded_req = - pipe->unbounded_req; - break; - case HUBP_SETUP_INTERDEPENDENT2: - p->hubp_setup_interdependent2_params.hubp = pipe->plane_res.hubp; - p->hubp_setup_interdependent2_params.hubp_regs = - &pipe->hubp_regs; - break; - case DPP_SETUP_DPP: - p->setup_dpp_params.dpp = dpp; - p->setup_dpp_params.format = plane->format; - p->setup_dpp_params.input_csc_color_matrix = - plane->input_csc_color_matrix; - p->setup_dpp_params.color_space = plane->color_space; - p->setup_dpp_params.upsp_mode = resource_is_upsp_required( - (bool) plane->ctx->dc->caps.color.dpp.upsp_pre_scaler, plane->format, plane->scaling_linearity); - break; - case DPP_SET_CURSOR_MATRIX: - p->dpp_set_cursor_matrix_params.dpp = dpp; - p->dpp_set_cursor_matrix_params.color_space = - plane->color_space; - p->dpp_set_cursor_matrix_params.cursor_csc_color_matrix = - &plane->cursor_csc_color_matrix; - break; - case DPP_PROGRAM_BIAS_AND_SCALE: - p->program_bias_and_scale_params.dpp = dpp; - p->program_bias_and_scale_params.bias_and_scale = - plane->bias_and_scale; - break; - case MPC_INSERT_PLANE: - p->mpc_insert_plane_params.mpc = dc->res_pool->mpc; - p->mpc_insert_plane_params.mpc_tree_params = - &pipe->stream_res.opp->mpc_tree_params; - dcn401_blnd_cfg(plane, &p->mpc_insert_plane_params.blnd_cfg); - p->mpc_insert_plane_params.dpp_id = pipe->plane_res.hubp->inst; - p->mpc_insert_plane_params.mpcc_id = pipe->plane_res.hubp->inst; - break; - case MPC_UPDATE_VISUAL_CONFIRM: - p->update_visual_confirm_params.mpc = dc->res_pool->mpc; - p->update_visual_confirm_params.color = - &pipe->visual_confirm_color; - p->update_visual_confirm_params.mpcc_id = pipe->plane_res.hubp->inst; - break; - case DPP_SET_SCALER: - p->dpp_set_scaler_params.dpp = dpp; - p->dpp_set_scaler_params.scl_data = &pipe->plane_res.scl_data; - break; - case HUBP_MEM_PROGRAM_VIEWPORT: - p->hubp_mem_program_viewport_params.hubp = pipe->plane_res.hubp; - p->hubp_mem_program_viewport_params.viewport = - &pipe->plane_res.scl_data.viewport; - p->hubp_mem_program_viewport_params.viewport_c = - &pipe->plane_res.scl_data.viewport_c; - break; - case HUBP_PROGRAM_MCACHE_ID: - p->program_mcache_id_and_split_coordinate.hubp = pipe->plane_res.hubp; - p->program_mcache_id_and_split_coordinate.mcache_regs = - &pipe->mcache_regs; - break; - case MPC_SET_GAMUT_REMAP_BYPASS: - p->mpc_set_gamut_remap_bypass_params.mpc = dc->res_pool->mpc; - p->mpc_set_gamut_remap_bypass_params.mpcc_id = - pipe->plane_res.mpcc_inst; - p->mpc_set_gamut_remap_bypass_params.block_id = - m->mpc_set_gamut_remap_bypass.block_id; - break; - case MPC_POWER_ON_MPC_MEM_PWR: - p->power_on_mpc_mem_pwr_params.mpc = dc->res_pool->mpc; - p->power_on_mpc_mem_pwr_params.mpcc_id = pipe->plane_res.hubp->inst; - p->power_on_mpc_mem_pwr_params.power_on = true; - break; - case MPC_SET_OCSC_DEFAULT: - p->set_ocsc_default_params.mpc = dc->res_pool->mpc; - p->set_ocsc_default_params.opp_id = pipe->stream_res.opp->inst; - p->set_ocsc_default_params.color_space = - pipe->stream->output_color_space; - p->set_ocsc_default_params.ocsc_mode = MPC_OUTPUT_CSC_COEF_A; - break; - case HUBP_PROGRAM_SURFACE_CONFIG: - p->program_surface_config_params.hubp = pipe->plane_res.hubp; - p->program_surface_config_params.format = plane->format; - p->program_surface_config_params.tiling_info = - &plane->tiling_info; - p->program_surface_config_params.plane_size = - plane->plane_size; - p->program_surface_config_params.plane_size.surface_size = - pipe->plane_res.scl_data.viewport; - p->program_surface_config_params.rotation = plane->rotation; - p->program_surface_config_params.dcc = &plane->dcc; - p->program_surface_config_params.horizontal_mirror = - plane->horizontal_mirror; - break; - case HUBP_UPDATE_PLANE_ADDR: - p->update_plane_addr_params.hubp = pipe->plane_res.hubp; - p->update_plane_addr_params.address = plane->address; - p->update_plane_addr_params.flip_immediate = - plane->flip_immediate; - p->update_plane_addr_params.dcc = plane->dcc.enable; - break; - case DPP_SET_HDR_MULTIPLIER: - p->dpp_set_hdr_multiplier_params.dpp = dpp; - p->dpp_set_hdr_multiplier_params.hw_mult = - dcn401_hdr_mult(plane); - break; - case DPP_SET_PRE_DEGAM: - p->dpp_set_pre_degam_params.dpp = dpp; - p->dpp_set_pre_degam_params.in_transfer_func = - &plane->in_transfer_func; - break; - case DPP_PROGRAM_GAMCOR_LUT: - p->dpp_program_gamcor_lut_params.dpp = dpp; - if (plane->in_transfer_func.type == TF_TYPE_HWPWL) - p->dpp_program_gamcor_lut_params.params = - &plane->in_transfer_func.pwl; - break; - case MPC_SET_MOVABLE_CM_LOCATION: - p->mpc_set_movable_cm_location_params.mpc = dc->res_pool->mpc; - p->mpc_set_movable_cm_location_params.location = - MPCC_MOVABLE_CM_LOCATION_BEFORE; - p->mpc_set_movable_cm_location_params.mpcc_id = - pipe->plane_res.mpcc_inst; - break; - case MPC_PROGRAM_LUT_MODE: - /* - * Every LUT is off. DC1 reads the bank back with get_lut_mode; - * the build reads no hardware, so it assumes bank A for an - * MPCC that held no plane. - */ - p->mpc_program_lut_mode_params.mpc = dc->res_pool->mpc; - p->mpc_program_lut_mode_params.id = m->mpc_program_lut_mode.id; - p->mpc_program_lut_mode_params.lut_bank_a = true; - p->mpc_program_lut_mode_params.size = dcn401_lut_mode_size( - plane, m->mpc_program_lut_mode.id); - p->mpc_program_lut_mode_params.mpcc_id = - pipe->plane_res.mpcc_inst; - break; - case HUBP_PROGRAM_3DLUT_FL_CONFIG: - p->hubp_program_3dlut_fl_config_params.hubp = pipe->plane_res.hubp; - p->hubp_program_3dlut_fl_config_params.config = - &dcn401_3dlut_dma_off; - break; - case HUBP_SET_3DLUT_FL: - p->hubp_set_3dlut_fl_params.hubp = pipe->plane_res.hubp; - break; - case MPC_SET_OUTPUT_GAMMA: - p->mpc_set_output_gamma_params.mpc = dc->res_pool->mpc; - p->mpc_set_output_gamma_params.mpcc_id = - pipe->plane_res.mpcc_inst; - if (pipe->stream->out_transfer_func.type == TF_TYPE_HWPWL) - p->mpc_set_output_gamma_params.params = - &pipe->stream->out_transfer_func.pwl; - break; - case HUBP_WAIT_FLIP_PENDING: - p->hubp_wait_flip_pending_params.hubp = pipe->plane_res.hubp; - p->hubp_wait_flip_pending_params.polling_interval_us = - DCN401_FLIP_PENDING_POLL_INTERVAL_US; - break; - case OPTC_PROGRAM_MANUAL_TRIGGER: - p->program_manual_trigger_params.tg = pipe->stream_res.tg; - break; - default: - /* The step tables use only the funcs above. */ - ASSERT(false); - break; - } -} - -static void dcn401_eval_pipe_deltas(const struct dcn401_commit_step_args *args, - unsigned int idx, struct dcn401_pipe_deltas *deltas) -{ - const struct dc_state_pipe_flags *cur_f = - &args->update_flags->cur_pipes[idx]; - const struct dc_state_pipe_flags *new_f = - &args->update_flags->new_pipes[idx]; - const struct pipe_ctx *cur = &args->current_state->res_ctx.pipe_ctx[idx]; - const struct pipe_ctx *new = &args->new_state->res_ctx.pipe_ctx[idx]; - - deltas->hubp_dpp_already_enabled = cur_f->enabled && new_f->enabled && - cur->stream->stream_id == new->stream->stream_id && - cur->plane_res.hubp->inst == new->plane_res.hubp->inst && - cur->plane_res.dpp->inst == new->plane_res.dpp->inst && - cur->stream_res.opp->inst == new->stream_res.opp->inst; - deltas->det_unchanged = cur_f->det_size == new_f->det_size; - deltas->current_has_no_plane = !cur_f->has_plane; - deltas->odm_kept = new->stream && dcn401_same_opp_heads( - args->current_state, args->new_state, new->stream); -} - -static bool dcn401_pipe_deltas_match(const struct dcn401_pipe_deltas *skip, - const struct dcn401_pipe_deltas *deltas, bool all) -{ - const bool named[] = { skip->hubp_dpp_already_enabled, - skip->det_unchanged, skip->current_has_no_plane, - skip->odm_kept }; - const bool set[] = { deltas->hubp_dpp_already_enabled, - deltas->det_unchanged, deltas->current_has_no_plane, - deltas->odm_kept }; - bool any = false; - unsigned int i; - - for (i = 0; i < ARRAY_SIZE(named); i++) { - if (!named[i]) - continue; - if (all && !set[i]) - return false; - any |= set[i]; - } - return any; -} - -static bool dcn401_skip_step(const struct dcn401_commit_step_args *args, - const struct dcn401_commit_step *step) -{ - const struct dcn401_pipe_deltas *skip = &step->meta.skip_if.pipe_deltas; - struct dcn401_pipe_deltas deltas; - const struct pipe_ctx *cur, *new; - - if (step->meta.skip_if.only_addresses_changed && - !args->hardware_remapped && !args->pipe_configs_changed) - return true; - if (step->meta.only_if.hardware_not_remapped && args->hardware_remapped) - return true; - if (step->meta.only_if.pipe_configs_not_changed && - args->pipe_configs_changed) - return true; - if (step->meta.skip_if.new_state_has_stream && - args->new_state->stream_count) - return true; - if (step->meta.skip_if.stream_unchanged && args->stream_unchanged) - return true; - if (step->meta.skip_if.optimized_not_required && - !args->dc->optimized_required) - return true; - if (step->meta.skip_if.no_ip_request && - (!args->dc->hwseq->funcs.pg_needs_ip_request || - !args->dc->hwseq->funcs.pg_needs_ip_request(args->dc))) - return true; - /* The remaining conditions are for per-pipe steps. */ - if (!args->pipe) - return false; - cur = &args->current_state->res_ctx.pipe_ctx[args->pipe->pipe_idx]; - new = &args->new_state->res_ctx.pipe_ctx[args->pipe->pipe_idx]; - dcn401_eval_pipe_deltas(args, args->pipe->pipe_idx, &deltas); - if (step->meta.skip_if.no_addr_update && - !args->update_flags->new_pipes[args->pipe->pipe_idx] - .plane.addr_update) - return true; - if (step->meta.skip_if.no_manual_trigger && - (!args->pipe->plane_state->update_bits.addr_update || - args->pipe->plane_state->skip_manual_trigger)) - return true; - if (step->meta.skip_if.opp_tree_empty && - (!args->pipe->stream_res.opp || - !args->pipe->stream_res.opp->mpc_tree_params.opp_list)) - return true; - if (step->meta.skip_if.no_dsc && !args->pipe->stream_res.dsc) - return true; - if (step->meta.skip_if.no_timing_sync_source && - !args->timing_sync_source) - return true; - if (dcn401_pipe_deltas_match(skip, &deltas, - step->meta.skip_if.pipe_deltas_all)) - return true; - if (step->meta.skip_if.scaling_unchanged && - !args->pipe->plane_state->update_bits.scaling_change && - !args->pipe->plane_state->update_bits.position_change && - !args->pipe->stream->update_flags.bits.scaling && - (!deltas.hubp_dpp_already_enabled || - !memcmp(&cur->plane_res.scl_data, &new->plane_res.scl_data, - sizeof(cur->plane_res.scl_data)))) - return true; - return false; -} - -static void dcn401_add_steps(struct block_sequence_state *sequence, - const struct dcn401_commit_step_args *args, - const struct dcn401_commit_step *steps, unsigned int count) -{ - unsigned int i; - - for (i = 0; i < count; i++) { - if (!dcn401_skip_step(args, &steps[i])) - dcn401_add_step(sequence, args, &steps[i]); - } -} - -static bool dcn401_walks_stream(const struct dcn401_commit_step_args *args, - const struct dc_stream_state *stream) -{ - if (args->stream) - return stream->stream_id == args->stream->stream_id; - return !dcn401_stream_kept(args->dc, args->current_state, - args->new_state, stream); -} - -/* - * The OTG master that pipe resets to, chosen as program_timing_sync does: - * the first OTG master with the same timing that shows a plane, else the - * first one. NULL when that is pipe. - */ -static const struct pipe_ctx *dcn401_timing_sync_source( - const struct dcn401_commit_step_args *args, - const struct pipe_ctx *pipe) -{ - const struct dc_state_update_flags *flags = args->update_flags; - const struct pipe_ctx *source = NULL; - const struct pipe_ctx *member; - unsigned int i; - - if (args->dc->debug.disable_timing_sync) - return NULL; - for (i = 0; i < args->dc->res_pool->pipe_count; i++) { - member = &args->new_state->res_ctx.pipe_ctx[i]; - if (!member->stream || member->top_pipe || - member->prev_odm_pipe || - !resource_are_streams_timing_synchronizable( - member->stream, pipe->stream)) - continue; - if (flags->cur_pipes[i].has_plane && - flags->new_pipes[i].has_plane) { - source = member; - break; - } - if (!source) - source = member; - } - if (!source || source->pipe_idx == pipe->pipe_idx) - return NULL; - return source; -} - -static void dcn401_add_per_otg_master(struct block_sequence_state *sequence, - const struct dcn401_commit_step_args *state_args, - struct dc_state *state, - const struct dcn401_commit_step *steps, unsigned int count) -{ - struct dcn401_commit_step_args args = *state_args; - unsigned int i; - - for (i = 0; i < state->stream_count; i++) { - if (!dcn401_walks_stream(&args, state->streams[i])) - continue; - args.pipe = resource_get_otg_master_for_stream( - &state->res_ctx, state->streams[i]); - if (!args.pipe) - continue; - args.timing_sync_source = dcn401_timing_sync_source(&args, - args.pipe); - dcn401_add_steps(sequence, &args, steps, count); - } -} - -static void dcn401_add_per_opp_head(struct block_sequence_state *sequence, - const struct dcn401_commit_step_args *state_args, - struct dc_state *state, - const struct dcn401_commit_step *steps, unsigned int count) -{ - struct dcn401_commit_step_args args = *state_args; - struct pipe_ctx *opp_heads[MAX_PIPES]; - unsigned int i; - int j, n; - - for (i = 0; i < state->stream_count; i++) { - if (!dcn401_walks_stream(&args, state->streams[i])) - continue; - n = resource_get_opp_heads_for_stream(state->streams[i], - &state->res_ctx, opp_heads); - for (j = 0; j < n; j++) { - args.pipe = opp_heads[j]; - dcn401_add_steps(sequence, &args, steps, count); - } - } -} - -static void dcn401_add_per_dpp_pipe(struct block_sequence_state *sequence, - const struct dcn401_commit_step_args *state_args, - struct dc_state *state, const struct dcn401_sub_sequence *sub) -{ - struct dcn401_commit_step_args args = *state_args; - struct pipe_ctx *dpp_pipes[MAX_PIPES]; - unsigned int i, k; - int j, n; - - for (i = 0; i < state->stream_count; i++) { - if (!dcn401_walks_stream(&args, state->streams[i])) - continue; - n = resource_get_dpp_pipes_for_stream(state->streams[i], - &state->res_ctx, dpp_pipes); - for (j = 0; j < n; j++) { - args.pipe = dpp_pipes[j]; - if (!sub->stages) { - dcn401_add_steps(sequence, &args, sub->steps, - sub->count); - continue; - } - for (k = 0; k < sub->stage_count; k++) - dcn401_add_steps(sequence, &args, - sub->stages[k].steps, - sub->stages[k].count); - } - } -} - -void dcn401_add_sub_sequences(struct block_sequence_state *sequence, - const struct dcn401_commit_step_args *state_args, - const struct dcn401_sub_sequence *subs, unsigned int count) -{ - const struct dcn401_sub_sequence *sub; - struct dc_state *state; - unsigned int i; - - for (i = 0; i < count; i++) { - sub = &subs[i]; - state = sub->flags & DCN401_CURRENT_STATE ? - state_args->current_state : - state_args->new_state; - if (sub->flags & DCN401_PER_STREAM_PER_OTG_MASTER) - dcn401_add_per_otg_master(sequence, state_args, state, - sub->steps, sub->count); - else if (sub->flags & DCN401_PER_STREAM_PER_OPP_HEAD) - dcn401_add_per_opp_head(sequence, state_args, state, - sub->steps, sub->count); - else if (sub->flags & DCN401_PER_STREAM_PER_DPP_PIPE) - dcn401_add_per_dpp_pipe(sequence, state_args, state, sub); - else - dcn401_add_steps(sequence, state_args, sub->steps, - sub->count); - } -} - -void dcn401_init_and_unpack_params( - struct bls_builder_declarative_params *params, - struct dcn401_commit_step_args *state_args, - struct block_sequence_state *head) -{ - state_args->dc = params->dc; - state_args->current_state = (struct dc_state *)params->current_state; - state_args->new_state = (struct dc_state *)params->new_state; - state_args->stream = NULL; - state_args->pipe = NULL; - state_args->update_flags = params->update_flags; - state_args->stream_unchanged = false; - state_args->hardware_remapped = true; - state_args->pipe_configs_changed = true; - state_args->timing_sync_source = NULL; - - params->head_num_steps = 0; - params->tail_num_steps = 0; - head->steps = params->head_sequence; - head->num_steps = ¶ms->head_num_steps; -} - /* * The waits and the bandwidth raise, then the updated stream only. * skip_if drops the steps a kept pipe or ODM layout does not need, so -- 2.56.1