xref: /linux/drivers/gpu/drm/amd/display/dc/hwss/dcn32/dcn32_hwseq.c (revision ab93e0dd72c37d378dd936f031ffb83ff2bd87ce)
1235c6763SAurabindo Pillai /*
2235c6763SAurabindo Pillai  * Copyright 2016 Advanced Micro Devices, Inc.
3235c6763SAurabindo Pillai  *
4235c6763SAurabindo Pillai  * Permission is hereby granted, free of charge, to any person obtaining a
5235c6763SAurabindo Pillai  * copy of this software and associated documentation files (the "Software"),
6235c6763SAurabindo Pillai  * to deal in the Software without restriction, including without limitation
7235c6763SAurabindo Pillai  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8235c6763SAurabindo Pillai  * and/or sell copies of the Software, and to permit persons to whom the
9235c6763SAurabindo Pillai  * Software is furnished to do so, subject to the following conditions:
10235c6763SAurabindo Pillai  *
11235c6763SAurabindo Pillai  * The above copyright notice and this permission notice shall be included in
12235c6763SAurabindo Pillai  * all copies or substantial portions of the Software.
13235c6763SAurabindo Pillai  *
14235c6763SAurabindo Pillai  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15235c6763SAurabindo Pillai  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16235c6763SAurabindo Pillai  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17235c6763SAurabindo Pillai  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18235c6763SAurabindo Pillai  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19235c6763SAurabindo Pillai  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20235c6763SAurabindo Pillai  * OTHER DEALINGS IN THE SOFTWARE.
21235c6763SAurabindo Pillai  *
22235c6763SAurabindo Pillai  * Authors: AMD
23235c6763SAurabindo Pillai  *
24235c6763SAurabindo Pillai  */
25235c6763SAurabindo Pillai 
26235c6763SAurabindo Pillai 
27235c6763SAurabindo Pillai #include "dm_services.h"
28235c6763SAurabindo Pillai #include "dm_helpers.h"
29235c6763SAurabindo Pillai #include "core_types.h"
30235c6763SAurabindo Pillai #include "resource.h"
31235c6763SAurabindo Pillai #include "dccg.h"
32235c6763SAurabindo Pillai #include "dce/dce_hwseq.h"
33235c6763SAurabindo Pillai #include "dcn30/dcn30_cm_common.h"
34235c6763SAurabindo Pillai #include "reg_helper.h"
35235c6763SAurabindo Pillai #include "abm.h"
36235c6763SAurabindo Pillai #include "hubp.h"
37235c6763SAurabindo Pillai #include "dchubbub.h"
38235c6763SAurabindo Pillai #include "timing_generator.h"
39235c6763SAurabindo Pillai #include "opp.h"
40235c6763SAurabindo Pillai #include "ipp.h"
41235c6763SAurabindo Pillai #include "mpc.h"
42235c6763SAurabindo Pillai #include "mcif_wb.h"
43235c6763SAurabindo Pillai #include "dc_dmub_srv.h"
44235c6763SAurabindo Pillai #include "link_hwss.h"
45235c6763SAurabindo Pillai #include "dpcd_defs.h"
46235c6763SAurabindo Pillai #include "dcn32_hwseq.h"
47235c6763SAurabindo Pillai #include "clk_mgr.h"
48235c6763SAurabindo Pillai #include "dsc.h"
49235c6763SAurabindo Pillai #include "dcn20/dcn20_optc.h"
5085f4bc0cSAlvin Lee #include "dce/dmub_hw_lock_mgr.h"
51e53524cdSMounika Adhuri #include "dcn32/dcn32_resource.h"
52d5a43956SWenjing Liu #include "link.h"
53f583db81SAlvin Lee #include "../dcn20/dcn20_hwseq.h"
5409a4ec5dSDillon Varone #include "dc_state_priv.h"
55235c6763SAurabindo Pillai 
56235c6763SAurabindo Pillai #define DC_LOGGER_INIT(logger)
57235c6763SAurabindo Pillai 
58235c6763SAurabindo Pillai #define CTX \
59235c6763SAurabindo Pillai 	hws->ctx
60235c6763SAurabindo Pillai #define REG(reg)\
61235c6763SAurabindo Pillai 	hws->regs->reg
62235c6763SAurabindo Pillai #define DC_LOGGER \
63176278d8SWenjing Liu 	dc->ctx->logger
64235c6763SAurabindo Pillai 
65235c6763SAurabindo Pillai #undef FN
66235c6763SAurabindo Pillai #define FN(reg_name, field_name) \
67235c6763SAurabindo Pillai 	hws->shifts->field_name, hws->masks->field_name
68235c6763SAurabindo Pillai 
dcn32_dsc_pg_control(struct dce_hwseq * hws,unsigned int dsc_inst,bool power_on)69235c6763SAurabindo Pillai void dcn32_dsc_pg_control(
70235c6763SAurabindo Pillai 		struct dce_hwseq *hws,
71235c6763SAurabindo Pillai 		unsigned int dsc_inst,
72235c6763SAurabindo Pillai 		bool power_on)
73235c6763SAurabindo Pillai {
74235c6763SAurabindo Pillai 	uint32_t power_gate = power_on ? 0 : 1;
75235c6763SAurabindo Pillai 	uint32_t pwr_status = power_on ? 0 : 2;
76235c6763SAurabindo Pillai 	uint32_t org_ip_request_cntl = 0;
77176278d8SWenjing Liu 	struct dc *dc = hws->ctx->dc;
78235c6763SAurabindo Pillai 
79176278d8SWenjing Liu 	if (dc->debug.disable_dsc_power_gate)
80235c6763SAurabindo Pillai 		return;
81235c6763SAurabindo Pillai 
82176278d8SWenjing Liu 	if (!dc->debug.enable_double_buffered_dsc_pg_support)
8340255df3SMuhammad Ahmed 		return;
8440255df3SMuhammad Ahmed 
85235c6763SAurabindo Pillai 	REG_GET(DC_IP_REQUEST_CNTL, IP_REQUEST_EN, &org_ip_request_cntl);
86235c6763SAurabindo Pillai 	if (org_ip_request_cntl == 0)
87235c6763SAurabindo Pillai 		REG_SET(DC_IP_REQUEST_CNTL, 0, IP_REQUEST_EN, 1);
88235c6763SAurabindo Pillai 
89176278d8SWenjing Liu 	DC_LOG_DSC("%s DSC power gate for inst %d", power_gate ? "enable" : "disable", dsc_inst);
90235c6763SAurabindo Pillai 	switch (dsc_inst) {
91235c6763SAurabindo Pillai 	case 0: /* DSC0 */
92235c6763SAurabindo Pillai 		REG_UPDATE(DOMAIN16_PG_CONFIG,
93235c6763SAurabindo Pillai 				DOMAIN_POWER_GATE, power_gate);
94235c6763SAurabindo Pillai 
95235c6763SAurabindo Pillai 		REG_WAIT(DOMAIN16_PG_STATUS,
96235c6763SAurabindo Pillai 				DOMAIN_PGFSM_PWR_STATUS, pwr_status,
97235c6763SAurabindo Pillai 				1, 1000);
98235c6763SAurabindo Pillai 		break;
99235c6763SAurabindo Pillai 	case 1: /* DSC1 */
100235c6763SAurabindo Pillai 		REG_UPDATE(DOMAIN17_PG_CONFIG,
101235c6763SAurabindo Pillai 				DOMAIN_POWER_GATE, power_gate);
102235c6763SAurabindo Pillai 
103235c6763SAurabindo Pillai 		REG_WAIT(DOMAIN17_PG_STATUS,
104235c6763SAurabindo Pillai 				DOMAIN_PGFSM_PWR_STATUS, pwr_status,
105235c6763SAurabindo Pillai 				1, 1000);
106235c6763SAurabindo Pillai 		break;
107235c6763SAurabindo Pillai 	case 2: /* DSC2 */
108235c6763SAurabindo Pillai 		REG_UPDATE(DOMAIN18_PG_CONFIG,
109235c6763SAurabindo Pillai 				DOMAIN_POWER_GATE, power_gate);
110235c6763SAurabindo Pillai 
111235c6763SAurabindo Pillai 		REG_WAIT(DOMAIN18_PG_STATUS,
112235c6763SAurabindo Pillai 				DOMAIN_PGFSM_PWR_STATUS, pwr_status,
113235c6763SAurabindo Pillai 				1, 1000);
114235c6763SAurabindo Pillai 		break;
115235c6763SAurabindo Pillai 	case 3: /* DSC3 */
116235c6763SAurabindo Pillai 		REG_UPDATE(DOMAIN19_PG_CONFIG,
117235c6763SAurabindo Pillai 				DOMAIN_POWER_GATE, power_gate);
118235c6763SAurabindo Pillai 
119235c6763SAurabindo Pillai 		REG_WAIT(DOMAIN19_PG_STATUS,
120235c6763SAurabindo Pillai 				DOMAIN_PGFSM_PWR_STATUS, pwr_status,
121235c6763SAurabindo Pillai 				1, 1000);
122235c6763SAurabindo Pillai 		break;
123235c6763SAurabindo Pillai 	default:
124235c6763SAurabindo Pillai 		BREAK_TO_DEBUGGER();
125235c6763SAurabindo Pillai 		break;
126235c6763SAurabindo Pillai 	}
127235c6763SAurabindo Pillai 
128235c6763SAurabindo Pillai 	if (org_ip_request_cntl == 0)
129235c6763SAurabindo Pillai 		REG_SET(DC_IP_REQUEST_CNTL, 0, IP_REQUEST_EN, 0);
130235c6763SAurabindo Pillai }
131235c6763SAurabindo Pillai 
132235c6763SAurabindo Pillai 
dcn32_enable_power_gating_plane(struct dce_hwseq * hws,bool enable)133235c6763SAurabindo Pillai void dcn32_enable_power_gating_plane(
134235c6763SAurabindo Pillai 	struct dce_hwseq *hws,
135235c6763SAurabindo Pillai 	bool enable)
136235c6763SAurabindo Pillai {
137235c6763SAurabindo Pillai 	bool force_on = true; /* disable power gating */
138504d3caeSHersen Wu 	uint32_t org_ip_request_cntl = 0;
139235c6763SAurabindo Pillai 
140235c6763SAurabindo Pillai 	if (enable)
141235c6763SAurabindo Pillai 		force_on = false;
142235c6763SAurabindo Pillai 
143504d3caeSHersen Wu 	REG_GET(DC_IP_REQUEST_CNTL, IP_REQUEST_EN, &org_ip_request_cntl);
144504d3caeSHersen Wu 	if (org_ip_request_cntl == 0)
145504d3caeSHersen Wu 		REG_SET(DC_IP_REQUEST_CNTL, 0, IP_REQUEST_EN, 1);
146504d3caeSHersen Wu 
147235c6763SAurabindo Pillai 	/* DCHUBP0/1/2/3 */
148235c6763SAurabindo Pillai 	REG_UPDATE(DOMAIN0_PG_CONFIG, DOMAIN_POWER_FORCEON, force_on);
149235c6763SAurabindo Pillai 	REG_UPDATE(DOMAIN1_PG_CONFIG, DOMAIN_POWER_FORCEON, force_on);
150235c6763SAurabindo Pillai 	REG_UPDATE(DOMAIN2_PG_CONFIG, DOMAIN_POWER_FORCEON, force_on);
151235c6763SAurabindo Pillai 	REG_UPDATE(DOMAIN3_PG_CONFIG, DOMAIN_POWER_FORCEON, force_on);
152235c6763SAurabindo Pillai 
153235c6763SAurabindo Pillai 	/* DCS0/1/2/3 */
154235c6763SAurabindo Pillai 	REG_UPDATE(DOMAIN16_PG_CONFIG, DOMAIN_POWER_FORCEON, force_on);
155235c6763SAurabindo Pillai 	REG_UPDATE(DOMAIN17_PG_CONFIG, DOMAIN_POWER_FORCEON, force_on);
156235c6763SAurabindo Pillai 	REG_UPDATE(DOMAIN18_PG_CONFIG, DOMAIN_POWER_FORCEON, force_on);
157235c6763SAurabindo Pillai 	REG_UPDATE(DOMAIN19_PG_CONFIG, DOMAIN_POWER_FORCEON, force_on);
158504d3caeSHersen Wu 
159504d3caeSHersen Wu 	if (org_ip_request_cntl == 0)
160504d3caeSHersen Wu 		REG_SET(DC_IP_REQUEST_CNTL, 0, IP_REQUEST_EN, 0);
161235c6763SAurabindo Pillai }
162235c6763SAurabindo Pillai 
dcn32_hubp_pg_control(struct dce_hwseq * hws,unsigned int hubp_inst,bool power_on)163235c6763SAurabindo Pillai void dcn32_hubp_pg_control(struct dce_hwseq *hws, unsigned int hubp_inst, bool power_on)
164235c6763SAurabindo Pillai {
165235c6763SAurabindo Pillai 	uint32_t power_gate = power_on ? 0 : 1;
166235c6763SAurabindo Pillai 	uint32_t pwr_status = power_on ? 0 : 2;
167235c6763SAurabindo Pillai 
168235c6763SAurabindo Pillai 	if (hws->ctx->dc->debug.disable_hubp_power_gate)
169235c6763SAurabindo Pillai 		return;
170235c6763SAurabindo Pillai 
171235c6763SAurabindo Pillai 	if (REG(DOMAIN0_PG_CONFIG) == 0)
172235c6763SAurabindo Pillai 		return;
173235c6763SAurabindo Pillai 
174235c6763SAurabindo Pillai 	switch (hubp_inst) {
175235c6763SAurabindo Pillai 	case 0:
176235c6763SAurabindo Pillai 		REG_SET(DOMAIN0_PG_CONFIG, 0, DOMAIN_POWER_GATE, power_gate);
177235c6763SAurabindo Pillai 		REG_WAIT(DOMAIN0_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, pwr_status, 1, 1000);
178235c6763SAurabindo Pillai 		break;
179235c6763SAurabindo Pillai 	case 1:
180235c6763SAurabindo Pillai 		REG_SET(DOMAIN1_PG_CONFIG, 0, DOMAIN_POWER_GATE, power_gate);
181235c6763SAurabindo Pillai 		REG_WAIT(DOMAIN1_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, pwr_status, 1, 1000);
182235c6763SAurabindo Pillai 		break;
183235c6763SAurabindo Pillai 	case 2:
184235c6763SAurabindo Pillai 		REG_SET(DOMAIN2_PG_CONFIG, 0, DOMAIN_POWER_GATE, power_gate);
185235c6763SAurabindo Pillai 		REG_WAIT(DOMAIN2_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, pwr_status, 1, 1000);
186235c6763SAurabindo Pillai 		break;
187235c6763SAurabindo Pillai 	case 3:
188235c6763SAurabindo Pillai 		REG_SET(DOMAIN3_PG_CONFIG, 0, DOMAIN_POWER_GATE, power_gate);
189235c6763SAurabindo Pillai 		REG_WAIT(DOMAIN3_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, pwr_status, 1, 1000);
190235c6763SAurabindo Pillai 		break;
191235c6763SAurabindo Pillai 	default:
192235c6763SAurabindo Pillai 		BREAK_TO_DEBUGGER();
193235c6763SAurabindo Pillai 		break;
194235c6763SAurabindo Pillai 	}
195235c6763SAurabindo Pillai }
196235c6763SAurabindo Pillai 
dcn32_check_no_memory_request_for_cab(struct dc * dc)197235c6763SAurabindo Pillai static bool dcn32_check_no_memory_request_for_cab(struct dc *dc)
198235c6763SAurabindo Pillai {
199235c6763SAurabindo Pillai 	int i;
200235c6763SAurabindo Pillai 
201235c6763SAurabindo Pillai     /* First, check no-memory-request case */
202235c6763SAurabindo Pillai 	for (i = 0; i < dc->current_state->stream_count; i++) {
20346604a08SSamson Tam 		if ((dc->current_state->stream_status[i].plane_count) &&
20446604a08SSamson Tam 			(dc->current_state->streams[i]->link->psr_settings.psr_version == DC_PSR_VERSION_UNSUPPORTED))
205235c6763SAurabindo Pillai 			/* Fail eligibility on a visible stream */
206235c6763SAurabindo Pillai 			break;
207235c6763SAurabindo Pillai 	}
208235c6763SAurabindo Pillai 
209235c6763SAurabindo Pillai 	if (i == dc->current_state->stream_count)
210235c6763SAurabindo Pillai 		return true;
211235c6763SAurabindo Pillai 
212235c6763SAurabindo Pillai 	return false;
213235c6763SAurabindo Pillai }
214235c6763SAurabindo Pillai 
215235c6763SAurabindo Pillai 
216235c6763SAurabindo Pillai /* This function loops through every surface that needs to be cached in CAB for SS,
217235c6763SAurabindo Pillai  * and calculates the total number of ways required to store all surfaces (primary,
218235c6763SAurabindo Pillai  * meta, cursor).
219235c6763SAurabindo Pillai  */
dcn32_calculate_cab_allocation(struct dc * dc,struct dc_state * ctx)220235c6763SAurabindo Pillai static uint32_t dcn32_calculate_cab_allocation(struct dc *dc, struct dc_state *ctx)
221235c6763SAurabindo Pillai {
222238debcaSDillon Varone 	int i;
22379f3f1b6SSamson Tam 	uint32_t num_ways = 0;
224238debcaSDillon Varone 	uint32_t mall_ss_size_bytes = 0;
225235c6763SAurabindo Pillai 
226238debcaSDillon Varone 	mall_ss_size_bytes = ctx->bw_ctx.bw.dcn.mall_ss_size_bytes;
227238debcaSDillon Varone 	// TODO add additional logic for PSR active stream exclusion optimization
228238debcaSDillon Varone 	// mall_ss_psr_active_size_bytes = ctx->bw_ctx.bw.dcn.mall_ss_psr_active_size_bytes;
229235c6763SAurabindo Pillai 
230235c6763SAurabindo Pillai 	// Include cursor size for CAB allocation
231238debcaSDillon Varone 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
232238debcaSDillon Varone 		struct pipe_ctx *pipe = &ctx->res_ctx.pipe_ctx[i];
233a3cdb5d2SAurabindo Pillai 
234238debcaSDillon Varone 		if (!pipe->stream || !pipe->plane_state)
235238debcaSDillon Varone 			continue;
236525a65c7SAlvin Lee 
237238debcaSDillon Varone 		mall_ss_size_bytes += dcn32_helper_calculate_mall_bytes_for_cursor(dc, pipe, false);
238719b59a3SDillon Varone 	}
239235c6763SAurabindo Pillai 
240235c6763SAurabindo Pillai 	// Convert number of cache lines required to number of ways
241525a65c7SAlvin Lee 	if (dc->debug.force_mall_ss_num_ways > 0) {
242525a65c7SAlvin Lee 		num_ways = dc->debug.force_mall_ss_num_ways;
2438cffa89bSDillon Varone 	} else if (dc->res_pool->funcs->calculate_mall_ways_from_bytes) {
2448cffa89bSDillon Varone 		num_ways = dc->res_pool->funcs->calculate_mall_ways_from_bytes(dc, mall_ss_size_bytes);
245238debcaSDillon Varone 	} else {
2468cffa89bSDillon Varone 		num_ways = 0;
247525a65c7SAlvin Lee 	}
248238debcaSDillon Varone 
249235c6763SAurabindo Pillai 	return num_ways;
250235c6763SAurabindo Pillai }
251235c6763SAurabindo Pillai 
dcn32_apply_idle_power_optimizations(struct dc * dc,bool enable)252235c6763SAurabindo Pillai bool dcn32_apply_idle_power_optimizations(struct dc *dc, bool enable)
253235c6763SAurabindo Pillai {
254235c6763SAurabindo Pillai 	union dmub_rb_cmd cmd;
25579f3f1b6SSamson Tam 	uint8_t i;
25679f3f1b6SSamson Tam 	uint32_t ways;
257c7dafdfaSJosip Pavic 	int j;
258a6135ddeSAlvin Lee 	bool mall_ss_unsupported = false;
259f0068dd0SAlvin Lee 	struct dc_plane_state *plane = NULL;
260235c6763SAurabindo Pillai 
261235c6763SAurabindo Pillai 	if (!dc->ctx->dmub_srv)
262235c6763SAurabindo Pillai 		return false;
263235c6763SAurabindo Pillai 
2640bed85e4SDillon Varone 	for (i = 0; i < dc->current_state->stream_count; i++) {
2650bed85e4SDillon Varone 		/* MALL SS messaging is not supported with PSR at this time */
2660bed85e4SDillon Varone 		if (dc->current_state->streams[i] != NULL &&
267e37f5bd8SAlvin Lee 				dc->current_state->streams[i]->link->psr_settings.psr_version != DC_PSR_VERSION_UNSUPPORTED &&
268e37f5bd8SAlvin Lee 				(dc->current_state->stream_count > 1 || (!dc->current_state->streams[i]->dpms_off &&
269e37f5bd8SAlvin Lee 						dc->current_state->stream_status[i].plane_count > 0)))
2700bed85e4SDillon Varone 			return false;
2710bed85e4SDillon Varone 	}
2720bed85e4SDillon Varone 
273235c6763SAurabindo Pillai 	if (enable) {
274235c6763SAurabindo Pillai 		/* 1. Check no memory request case for CAB.
275235c6763SAurabindo Pillai 		 * If no memory request case, send CAB_ACTION NO_DF_REQ DMUB message
276235c6763SAurabindo Pillai 		 */
277235c6763SAurabindo Pillai 		if (dcn32_check_no_memory_request_for_cab(dc)) {
278235c6763SAurabindo Pillai 			/* Enable no-memory-requests case */
279235c6763SAurabindo Pillai 			memset(&cmd, 0, sizeof(cmd));
280235c6763SAurabindo Pillai 			cmd.cab.header.type = DMUB_CMD__CAB_FOR_SS;
281235c6763SAurabindo Pillai 			cmd.cab.header.sub_type = DMUB_CMD__CAB_NO_DCN_REQ;
282235c6763SAurabindo Pillai 			cmd.cab.header.payload_bytes = sizeof(cmd.cab) - sizeof(cmd.cab.header);
283235c6763SAurabindo Pillai 
28488927808SNicholas Kazlauskas 			dc_wake_and_execute_dmub_cmd(dc->ctx, &cmd, DM_DMUB_WAIT_TYPE_NO_WAIT);
285235c6763SAurabindo Pillai 
286235c6763SAurabindo Pillai 			return true;
287235c6763SAurabindo Pillai 		}
288235c6763SAurabindo Pillai 
289235c6763SAurabindo Pillai 		/* 2. Check if all surfaces can fit in CAB.
290235c6763SAurabindo Pillai 		 * If surfaces can fit into CAB, send CAB_ACTION_ALLOW DMUB message
291235c6763SAurabindo Pillai 		 * and configure HUBP's to fetch from MALL
292235c6763SAurabindo Pillai 		 */
293235c6763SAurabindo Pillai 		ways = dcn32_calculate_cab_allocation(dc, dc->current_state);
294f0068dd0SAlvin Lee 
295a6135ddeSAlvin Lee 		/* MALL not supported with Stereo3D or TMZ surface. If any plane is using stereo,
296a6135ddeSAlvin Lee 		 * or TMZ surface, don't try to enter MALL.
297f0068dd0SAlvin Lee 		 */
298f0068dd0SAlvin Lee 		for (i = 0; i < dc->current_state->stream_count; i++) {
299f0068dd0SAlvin Lee 			for (j = 0; j < dc->current_state->stream_status[i].plane_count; j++) {
300f0068dd0SAlvin Lee 				plane = dc->current_state->stream_status[i].plane_states[j];
301f0068dd0SAlvin Lee 
302a6135ddeSAlvin Lee 				if (plane->address.type == PLN_ADDR_TYPE_GRPH_STEREO ||
303a6135ddeSAlvin Lee 						plane->address.tmz_surface) {
304a6135ddeSAlvin Lee 					mall_ss_unsupported = true;
305f0068dd0SAlvin Lee 					break;
306f0068dd0SAlvin Lee 				}
307f0068dd0SAlvin Lee 			}
308a6135ddeSAlvin Lee 			if (mall_ss_unsupported)
309f0068dd0SAlvin Lee 				break;
310f0068dd0SAlvin Lee 		}
311a6135ddeSAlvin Lee 		if (ways <= dc->caps.cache_num_ways && !mall_ss_unsupported) {
312235c6763SAurabindo Pillai 			memset(&cmd, 0, sizeof(cmd));
313235c6763SAurabindo Pillai 			cmd.cab.header.type = DMUB_CMD__CAB_FOR_SS;
314235c6763SAurabindo Pillai 			cmd.cab.header.sub_type = DMUB_CMD__CAB_DCN_SS_FIT_IN_CAB;
315235c6763SAurabindo Pillai 			cmd.cab.header.payload_bytes = sizeof(cmd.cab) - sizeof(cmd.cab.header);
31679f3f1b6SSamson Tam 			cmd.cab.cab_alloc_ways = (uint8_t)ways;
317235c6763SAurabindo Pillai 
31888927808SNicholas Kazlauskas 			dc_wake_and_execute_dmub_cmd(dc->ctx, &cmd, DM_DMUB_WAIT_TYPE_NO_WAIT);
3199856893fSAurabindo Pillai 			DC_LOG_MALL("enable scanout from MALL");
320235c6763SAurabindo Pillai 
321235c6763SAurabindo Pillai 			return true;
322235c6763SAurabindo Pillai 		}
323235c6763SAurabindo Pillai 
3249856893fSAurabindo Pillai 		DC_LOG_MALL("surface cannot fit in CAB, disabling scanout from MALL\n");
325235c6763SAurabindo Pillai 		return false;
326235c6763SAurabindo Pillai 	}
327235c6763SAurabindo Pillai 
328235c6763SAurabindo Pillai 	/* Disable CAB */
329235c6763SAurabindo Pillai 	memset(&cmd, 0, sizeof(cmd));
330235c6763SAurabindo Pillai 	cmd.cab.header.type = DMUB_CMD__CAB_FOR_SS;
331235c6763SAurabindo Pillai 	cmd.cab.header.sub_type = DMUB_CMD__CAB_NO_IDLE_OPTIMIZATION;
332235c6763SAurabindo Pillai 	cmd.cab.header.payload_bytes =
333235c6763SAurabindo Pillai 			sizeof(cmd.cab) - sizeof(cmd.cab.header);
334235c6763SAurabindo Pillai 
33588927808SNicholas Kazlauskas 	dc_wake_and_execute_dmub_cmd(dc->ctx, &cmd, DM_DMUB_WAIT_TYPE_WAIT);
336235c6763SAurabindo Pillai 
3371f374171SEvan Quan 	return true;
338235c6763SAurabindo Pillai }
339235c6763SAurabindo Pillai 
340235c6763SAurabindo Pillai /* Send DMCUB message with SubVP pipe info
341235c6763SAurabindo Pillai  * - For each pipe in context, populate payload with required SubVP information
342235c6763SAurabindo Pillai  *   if the pipe is using SubVP for MCLK switch
343235c6763SAurabindo Pillai  * - This function must be called while the DMUB HW lock is acquired by driver
344235c6763SAurabindo Pillai  */
dcn32_commit_subvp_config(struct dc * dc,struct dc_state * context)345235c6763SAurabindo Pillai void dcn32_commit_subvp_config(struct dc *dc, struct dc_state *context)
346235c6763SAurabindo Pillai {
347235c6763SAurabindo Pillai 	int i;
348235c6763SAurabindo Pillai 	bool enable_subvp = false;
349235c6763SAurabindo Pillai 
350235c6763SAurabindo Pillai 	if (!dc->ctx || !dc->ctx->dmub_srv)
351235c6763SAurabindo Pillai 		return;
352235c6763SAurabindo Pillai 
353235c6763SAurabindo Pillai 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
354235c6763SAurabindo Pillai 		struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
355235c6763SAurabindo Pillai 
356012a04b1SDillon Varone 		if (pipe_ctx->stream && dc_state_get_pipe_subvp_type(context, pipe_ctx) == SUBVP_MAIN) {
357235c6763SAurabindo Pillai 			// There is at least 1 SubVP pipe, so enable SubVP
358235c6763SAurabindo Pillai 			enable_subvp = true;
359235c6763SAurabindo Pillai 			break;
360235c6763SAurabindo Pillai 		}
361235c6763SAurabindo Pillai 	}
362235c6763SAurabindo Pillai 	dc_dmub_setup_subvp_dmub_command(dc, context, enable_subvp);
363235c6763SAurabindo Pillai }
364235c6763SAurabindo Pillai 
36585f4bc0cSAlvin Lee /* Sub-Viewport DMUB lock needs to be acquired by driver whenever SubVP is active and:
36685f4bc0cSAlvin Lee  * 1. Any full update for any SubVP main pipe
36785f4bc0cSAlvin Lee  * 2. Any immediate flip for any SubVP pipe
36885f4bc0cSAlvin Lee  * 3. Any flip for DRR pipe
36985f4bc0cSAlvin Lee  * 4. If SubVP was previously in use (i.e. in old context)
37085f4bc0cSAlvin Lee  */
dcn32_subvp_pipe_control_lock(struct dc * dc,struct dc_state * context,bool lock,bool should_lock_all_pipes,struct pipe_ctx * top_pipe_to_program,bool subvp_prev_use)37185f4bc0cSAlvin Lee void dcn32_subvp_pipe_control_lock(struct dc *dc,
37285f4bc0cSAlvin Lee 		struct dc_state *context,
37385f4bc0cSAlvin Lee 		bool lock,
37485f4bc0cSAlvin Lee 		bool should_lock_all_pipes,
37585f4bc0cSAlvin Lee 		struct pipe_ctx *top_pipe_to_program,
37685f4bc0cSAlvin Lee 		bool subvp_prev_use)
37785f4bc0cSAlvin Lee {
37885f4bc0cSAlvin Lee 	unsigned int i = 0;
37985f4bc0cSAlvin Lee 	bool subvp_immediate_flip = false;
38085f4bc0cSAlvin Lee 	bool subvp_in_use = false;
381b83c9e3dSAlex Deucher 	struct pipe_ctx *pipe;
38209a4ec5dSDillon Varone 	enum mall_stream_type pipe_mall_type = SUBVP_NONE;
38385f4bc0cSAlvin Lee 
38485f4bc0cSAlvin Lee 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
38585f4bc0cSAlvin Lee 		pipe = &context->res_ctx.pipe_ctx[i];
38609a4ec5dSDillon Varone 		pipe_mall_type = dc_state_get_pipe_subvp_type(context, pipe);
38785f4bc0cSAlvin Lee 
38809a4ec5dSDillon Varone 		if (pipe->stream && pipe->plane_state && pipe_mall_type == SUBVP_MAIN) {
38985f4bc0cSAlvin Lee 			subvp_in_use = true;
39085f4bc0cSAlvin Lee 			break;
39185f4bc0cSAlvin Lee 		}
39285f4bc0cSAlvin Lee 	}
39385f4bc0cSAlvin Lee 
39485f4bc0cSAlvin Lee 	if (top_pipe_to_program && top_pipe_to_program->stream && top_pipe_to_program->plane_state) {
39509a4ec5dSDillon Varone 		if (dc_state_get_pipe_subvp_type(context, top_pipe_to_program) == SUBVP_MAIN &&
39685f4bc0cSAlvin Lee 				top_pipe_to_program->plane_state->flip_immediate)
39785f4bc0cSAlvin Lee 			subvp_immediate_flip = true;
39885f4bc0cSAlvin Lee 	}
39985f4bc0cSAlvin Lee 
400319568d7SAlvin Lee 	// Don't need to lock for DRR VSYNC flips -- FW will wait for DRR pending update cleared.
401319568d7SAlvin Lee 	if ((subvp_in_use && (should_lock_all_pipes || subvp_immediate_flip)) || (!subvp_in_use && subvp_prev_use)) {
40285f4bc0cSAlvin Lee 		union dmub_inbox0_cmd_lock_hw hw_lock_cmd = { 0 };
40385f4bc0cSAlvin Lee 
40485f4bc0cSAlvin Lee 		if (!lock) {
40585f4bc0cSAlvin Lee 			for (i = 0; i < dc->res_pool->pipe_count; i++) {
40685f4bc0cSAlvin Lee 				pipe = &context->res_ctx.pipe_ctx[i];
40709a4ec5dSDillon Varone 				if (pipe->stream && pipe->plane_state && pipe_mall_type == SUBVP_MAIN &&
40885f4bc0cSAlvin Lee 						should_lock_all_pipes)
40985f4bc0cSAlvin Lee 					pipe->stream_res.tg->funcs->wait_for_state(pipe->stream_res.tg, CRTC_STATE_VBLANK);
41085f4bc0cSAlvin Lee 			}
41185f4bc0cSAlvin Lee 		}
41285f4bc0cSAlvin Lee 
41385f4bc0cSAlvin Lee 		hw_lock_cmd.bits.command_code = DMUB_INBOX0_CMD__HW_LOCK;
41485f4bc0cSAlvin Lee 		hw_lock_cmd.bits.hw_lock_client = HW_LOCK_CLIENT_DRIVER;
41585f4bc0cSAlvin Lee 		hw_lock_cmd.bits.lock = lock;
41685f4bc0cSAlvin Lee 		hw_lock_cmd.bits.should_release = !lock;
41785f4bc0cSAlvin Lee 		dmub_hw_lock_mgr_inbox0_cmd(dc->ctx->dmub_srv, hw_lock_cmd);
41885f4bc0cSAlvin Lee 	}
41985f4bc0cSAlvin Lee }
42085f4bc0cSAlvin Lee 
dcn32_subvp_pipe_control_lock_fast(union block_sequence_params * params)4210baae624SAlvin Lee void dcn32_subvp_pipe_control_lock_fast(union block_sequence_params *params)
4220baae624SAlvin Lee {
4230baae624SAlvin Lee 	struct dc *dc = params->subvp_pipe_control_lock_fast_params.dc;
4240baae624SAlvin Lee 	bool lock = params->subvp_pipe_control_lock_fast_params.lock;
425012a04b1SDillon Varone 	bool subvp_immediate_flip = params->subvp_pipe_control_lock_fast_params.subvp_immediate_flip;
4260baae624SAlvin Lee 
4270baae624SAlvin Lee 	// Don't need to lock for DRR VSYNC flips -- FW will wait for DRR pending update cleared.
4280baae624SAlvin Lee 	if (subvp_immediate_flip) {
4290baae624SAlvin Lee 		union dmub_inbox0_cmd_lock_hw hw_lock_cmd = { 0 };
4300baae624SAlvin Lee 
4310baae624SAlvin Lee 		hw_lock_cmd.bits.command_code = DMUB_INBOX0_CMD__HW_LOCK;
4320baae624SAlvin Lee 		hw_lock_cmd.bits.hw_lock_client = HW_LOCK_CLIENT_DRIVER;
4330baae624SAlvin Lee 		hw_lock_cmd.bits.lock = lock;
4340baae624SAlvin Lee 		hw_lock_cmd.bits.should_release = !lock;
4350baae624SAlvin Lee 		dmub_hw_lock_mgr_inbox0_cmd(dc->ctx->dmub_srv, hw_lock_cmd);
4360baae624SAlvin Lee 	}
4370baae624SAlvin Lee }
43885f4bc0cSAlvin Lee 
dcn32_set_mpc_shaper_3dlut(struct pipe_ctx * pipe_ctx,const struct dc_stream_state * stream)43928e5c9d6SWesley Chalmers bool dcn32_set_mpc_shaper_3dlut(
440235c6763SAurabindo Pillai 	struct pipe_ctx *pipe_ctx, const struct dc_stream_state *stream)
441235c6763SAurabindo Pillai {
442235c6763SAurabindo Pillai 	struct dpp *dpp_base = pipe_ctx->plane_res.dpp;
443235c6763SAurabindo Pillai 	int mpcc_id = pipe_ctx->plane_res.hubp->inst;
444ad6b76cdSAlex Hung 	struct dc *dc = pipe_ctx->stream->ctx->dc;
445235c6763SAurabindo Pillai 	struct mpc *mpc = pipe_ctx->stream_res.opp->ctx->dc->res_pool->mpc;
446235c6763SAurabindo Pillai 	bool result = false;
447235c6763SAurabindo Pillai 
448235c6763SAurabindo Pillai 	const struct pwl_params *shaper_lut = NULL;
449235c6763SAurabindo Pillai 	//get the shaper lut params
450235c6763SAurabindo Pillai 	if (stream->func_shaper) {
451235c6763SAurabindo Pillai 		if (stream->func_shaper->type == TF_TYPE_HWPWL)
452235c6763SAurabindo Pillai 			shaper_lut = &stream->func_shaper->pwl;
453235c6763SAurabindo Pillai 		else if (stream->func_shaper->type == TF_TYPE_DISTRIBUTED_POINTS) {
45427fc10d1SHarry Wentland 			cm_helper_translate_curve_to_hw_format(stream->ctx,
455235c6763SAurabindo Pillai 					stream->func_shaper,
456235c6763SAurabindo Pillai 					&dpp_base->shaper_params, true);
457235c6763SAurabindo Pillai 			shaper_lut = &dpp_base->shaper_params;
458235c6763SAurabindo Pillai 		}
459235c6763SAurabindo Pillai 	}
460235c6763SAurabindo Pillai 
461235c6763SAurabindo Pillai 	if (stream->lut3d_func &&
462235c6763SAurabindo Pillai 		stream->lut3d_func->state.bits.initialized == 1) {
463235c6763SAurabindo Pillai 
464ad6b76cdSAlex Hung 		result = mpc->funcs->program_3dlut(mpc,	&stream->lut3d_func->lut_3d, mpcc_id);
465ad6b76cdSAlex Hung 		if (!result)
466ad6b76cdSAlex Hung 			DC_LOG_ERROR("%s: program_3dlut failed\n", __func__);
467235c6763SAurabindo Pillai 
468ad6b76cdSAlex Hung 		result = mpc->funcs->program_shaper(mpc, shaper_lut, mpcc_id);
469ad6b76cdSAlex Hung 		if (!result)
470ad6b76cdSAlex Hung 			DC_LOG_ERROR("%s: program_shaper failed\n", __func__);
471235c6763SAurabindo Pillai 	}
472235c6763SAurabindo Pillai 
473235c6763SAurabindo Pillai 	return result;
474235c6763SAurabindo Pillai }
47590f33674SMartin Leung 
dcn32_set_mcm_luts(struct pipe_ctx * pipe_ctx,const struct dc_plane_state * plane_state)47690f33674SMartin Leung bool dcn32_set_mcm_luts(
47790f33674SMartin Leung 	struct pipe_ctx *pipe_ctx, const struct dc_plane_state *plane_state)
47890f33674SMartin Leung {
47990f33674SMartin Leung 	struct dpp *dpp_base = pipe_ctx->plane_res.dpp;
48090f33674SMartin Leung 	int mpcc_id = pipe_ctx->plane_res.hubp->inst;
48190f33674SMartin Leung 	struct mpc *mpc = pipe_ctx->stream_res.opp->ctx->dc->res_pool->mpc;
48290f33674SMartin Leung 	bool result = true;
483285a7054SAlvin Lee 	const struct pwl_params *lut_params = NULL;
48490f33674SMartin Leung 
48590f33674SMartin Leung 	// 1D LUT
486285a7054SAlvin Lee 	if (plane_state->blend_tf.type == TF_TYPE_HWPWL)
487285a7054SAlvin Lee 		lut_params = &plane_state->blend_tf.pwl;
488285a7054SAlvin Lee 	else if (plane_state->blend_tf.type == TF_TYPE_DISTRIBUTED_POINTS) {
489c53bb80fSAlex Hung 		result = cm3_helper_translate_curve_to_hw_format(&plane_state->blend_tf,
49090f33674SMartin Leung 				&dpp_base->regamma_params, false);
491c53bb80fSAlex Hung 		if (!result)
492c53bb80fSAlex Hung 			return result;
493c53bb80fSAlex Hung 
49490f33674SMartin Leung 		lut_params = &dpp_base->regamma_params;
49590f33674SMartin Leung 	}
496c53bb80fSAlex Hung 	mpc->funcs->program_1dlut(mpc, lut_params, mpcc_id);
49785ca6e85SIlya Bakoulin 	lut_params = NULL;
49890f33674SMartin Leung 
49990f33674SMartin Leung 	// Shaper
500285a7054SAlvin Lee 	if (plane_state->in_shaper_func.type == TF_TYPE_HWPWL)
501285a7054SAlvin Lee 		lut_params = &plane_state->in_shaper_func.pwl;
502285a7054SAlvin Lee 	else if (plane_state->in_shaper_func.type == TF_TYPE_DISTRIBUTED_POINTS) {
50390f33674SMartin Leung 		// TODO: dpp_base replace
50490f33674SMartin Leung 		ASSERT(false);
505285a7054SAlvin Lee 		cm3_helper_translate_curve_to_hw_format(&plane_state->in_shaper_func,
50690f33674SMartin Leung 				&dpp_base->shaper_params, true);
50790f33674SMartin Leung 		lut_params = &dpp_base->shaper_params;
50890f33674SMartin Leung 	}
50990f33674SMartin Leung 
510c53bb80fSAlex Hung 	mpc->funcs->program_shaper(mpc, lut_params, mpcc_id);
51190f33674SMartin Leung 
51290f33674SMartin Leung 	// 3D
513285a7054SAlvin Lee 	if (plane_state->lut3d_func.state.bits.initialized == 1)
514285a7054SAlvin Lee 		result = mpc->funcs->program_3dlut(mpc, &plane_state->lut3d_func.lut_3d, mpcc_id);
51590f33674SMartin Leung 	else
51690f33674SMartin Leung 		result = mpc->funcs->program_3dlut(mpc, NULL, mpcc_id);
51790f33674SMartin Leung 
51890f33674SMartin Leung 	return result;
51990f33674SMartin Leung }
52090f33674SMartin Leung 
dcn32_set_input_transfer_func(struct dc * dc,struct pipe_ctx * pipe_ctx,const struct dc_plane_state * plane_state)52190f33674SMartin Leung bool dcn32_set_input_transfer_func(struct dc *dc,
52290f33674SMartin Leung 				struct pipe_ctx *pipe_ctx,
52390f33674SMartin Leung 				const struct dc_plane_state *plane_state)
52490f33674SMartin Leung {
52590f33674SMartin Leung 	struct dce_hwseq *hws = dc->hwseq;
52690f33674SMartin Leung 	struct mpc *mpc = dc->res_pool->mpc;
52790f33674SMartin Leung 	struct dpp *dpp_base = pipe_ctx->plane_res.dpp;
52890f33674SMartin Leung 
52990f33674SMartin Leung 	enum dc_transfer_func_predefined tf;
53090f33674SMartin Leung 	bool result = true;
531285a7054SAlvin Lee 	const struct pwl_params *params = NULL;
53290f33674SMartin Leung 
53390f33674SMartin Leung 	if (mpc == NULL || plane_state == NULL)
53490f33674SMartin Leung 		return false;
53590f33674SMartin Leung 
53690f33674SMartin Leung 	tf = TRANSFER_FUNCTION_UNITY;
53790f33674SMartin Leung 
538285a7054SAlvin Lee 	if (plane_state->in_transfer_func.type == TF_TYPE_PREDEFINED)
539285a7054SAlvin Lee 		tf = plane_state->in_transfer_func.tf;
54090f33674SMartin Leung 
54190f33674SMartin Leung 	dpp_base->funcs->dpp_set_pre_degam(dpp_base, tf);
54290f33674SMartin Leung 
543285a7054SAlvin Lee 	if (plane_state->in_transfer_func.type == TF_TYPE_HWPWL)
544285a7054SAlvin Lee 		params = &plane_state->in_transfer_func.pwl;
545285a7054SAlvin Lee 	else if (plane_state->in_transfer_func.type == TF_TYPE_DISTRIBUTED_POINTS &&
546285a7054SAlvin Lee 		cm3_helper_translate_curve_to_hw_format(&plane_state->in_transfer_func,
54790f33674SMartin Leung 				&dpp_base->degamma_params, false))
54890f33674SMartin Leung 		params = &dpp_base->degamma_params;
54990f33674SMartin Leung 
5509691a7a7SMartin Leung 	dpp_base->funcs->dpp_program_gamcor_lut(dpp_base, params);
55190f33674SMartin Leung 
5529691a7a7SMartin Leung 	if (pipe_ctx->stream_res.opp &&
55390f33674SMartin Leung 			pipe_ctx->stream_res.opp->ctx &&
55490f33674SMartin Leung 			hws->funcs.set_mcm_luts)
55590f33674SMartin Leung 		result = hws->funcs.set_mcm_luts(pipe_ctx, plane_state);
55690f33674SMartin Leung 
55790f33674SMartin Leung 	return result;
55890f33674SMartin Leung }
55990f33674SMartin Leung 
dcn32_set_output_transfer_func(struct dc * dc,struct pipe_ctx * pipe_ctx,const struct dc_stream_state * stream)560235c6763SAurabindo Pillai bool dcn32_set_output_transfer_func(struct dc *dc,
561235c6763SAurabindo Pillai 				struct pipe_ctx *pipe_ctx,
562235c6763SAurabindo Pillai 				const struct dc_stream_state *stream)
563235c6763SAurabindo Pillai {
564235c6763SAurabindo Pillai 	int mpcc_id = pipe_ctx->plane_res.hubp->inst;
565235c6763SAurabindo Pillai 	struct mpc *mpc = pipe_ctx->stream_res.opp->ctx->dc->res_pool->mpc;
566285a7054SAlvin Lee 	const struct pwl_params *params = NULL;
567235c6763SAurabindo Pillai 	bool ret = false;
568235c6763SAurabindo Pillai 
569235c6763SAurabindo Pillai 	/* program OGAM or 3DLUT only for the top pipe*/
57053f32880SWenjing Liu 	if (resource_is_pipe_type(pipe_ctx, OPP_HEAD)) {
571235c6763SAurabindo Pillai 		/*program shaper and 3dlut in MPC*/
572235c6763SAurabindo Pillai 		ret = dcn32_set_mpc_shaper_3dlut(pipe_ctx, stream);
573285a7054SAlvin Lee 		if (ret == false && mpc->funcs->set_output_gamma) {
574285a7054SAlvin Lee 			if (stream->out_transfer_func.type == TF_TYPE_HWPWL)
575285a7054SAlvin Lee 				params = &stream->out_transfer_func.pwl;
576285a7054SAlvin Lee 			else if (pipe_ctx->stream->out_transfer_func.type ==
577235c6763SAurabindo Pillai 					TF_TYPE_DISTRIBUTED_POINTS &&
578235c6763SAurabindo Pillai 					cm3_helper_translate_curve_to_hw_format(
579285a7054SAlvin Lee 					&stream->out_transfer_func,
580235c6763SAurabindo Pillai 					&mpc->blender_params, false))
581235c6763SAurabindo Pillai 				params = &mpc->blender_params;
582235c6763SAurabindo Pillai 			/* there are no ROM LUTs in OUTGAM */
583285a7054SAlvin Lee 			if (stream->out_transfer_func.type == TF_TYPE_PREDEFINED)
584235c6763SAurabindo Pillai 				BREAK_TO_DEBUGGER();
585235c6763SAurabindo Pillai 		}
586235c6763SAurabindo Pillai 	}
587235c6763SAurabindo Pillai 
58828574b08SSrinivasan Shanmugam 	if (mpc->funcs->set_output_gamma)
589235c6763SAurabindo Pillai 		mpc->funcs->set_output_gamma(mpc, mpcc_id, params);
59028574b08SSrinivasan Shanmugam 
591235c6763SAurabindo Pillai 	return ret;
592235c6763SAurabindo Pillai }
593235c6763SAurabindo Pillai 
5944ed79308SAlvin Lee /* Program P-State force value according to if pipe is using SubVP / FPO or not:
595235c6763SAurabindo Pillai  * 1. Reset P-State force on all pipes first
596235c6763SAurabindo Pillai  * 2. For each main pipe, force P-State disallow (P-State allow moderated by DMUB)
597235c6763SAurabindo Pillai  */
dcn32_update_force_pstate(struct dc * dc,struct dc_state * context)5984ed79308SAlvin Lee void dcn32_update_force_pstate(struct dc *dc, struct dc_state *context)
599235c6763SAurabindo Pillai {
600235c6763SAurabindo Pillai 	int i;
6014ed79308SAlvin Lee 
6024ed79308SAlvin Lee 	/* Unforce p-state for each pipe if it is not FPO or SubVP.
6034ed79308SAlvin Lee 	 * For FPO and SubVP, if it's already forced disallow, leave
6044ed79308SAlvin Lee 	 * it as disallow.
605235c6763SAurabindo Pillai 	 */
606235c6763SAurabindo Pillai 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
607235c6763SAurabindo Pillai 		struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
608235c6763SAurabindo Pillai 		struct hubp *hubp = pipe->plane_res.hubp;
609e69d4335SAlvin Lee 		struct dc_stream_status *stream_status = NULL;
610e69d4335SAlvin Lee 
611e69d4335SAlvin Lee 		if (pipe->stream)
612e69d4335SAlvin Lee 			stream_status = dc_state_get_stream_status(context, pipe->stream);
613235c6763SAurabindo Pillai 
61409a4ec5dSDillon Varone 		if (!pipe->stream || !(dc_state_get_pipe_subvp_type(context, pipe) == SUBVP_MAIN ||
615e69d4335SAlvin Lee 		    (stream_status && stream_status->fpo_in_use))) {
616235c6763SAurabindo Pillai 			if (hubp && hubp->funcs->hubp_update_force_pstate_disallow)
617235c6763SAurabindo Pillai 				hubp->funcs->hubp_update_force_pstate_disallow(hubp, false);
6184ed79308SAlvin Lee 			if (hubp && hubp->funcs->hubp_update_force_cursor_pstate_disallow)
6194ed79308SAlvin Lee 				hubp->funcs->hubp_update_force_cursor_pstate_disallow(hubp, false);
620235c6763SAurabindo Pillai 		}
6214ed79308SAlvin Lee 	}
622235c6763SAurabindo Pillai 
623235c6763SAurabindo Pillai 	/* Loop through each pipe -- for each subvp main pipe force p-state allow equal to false.
624235c6763SAurabindo Pillai 	 */
625235c6763SAurabindo Pillai 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
626235c6763SAurabindo Pillai 		struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
6274621e10eSAlvin Lee 		struct pipe_ctx *old_pipe = &dc->current_state->res_ctx.pipe_ctx[i];
628235c6763SAurabindo Pillai 		struct hubp *hubp = pipe->plane_res.hubp;
629e69d4335SAlvin Lee 		struct dc_stream_status *stream_status = NULL;
630e69d4335SAlvin Lee 		struct dc_stream_status *old_stream_status = NULL;
631235c6763SAurabindo Pillai 
6324621e10eSAlvin Lee 		/* Today for MED update type we do not call update clocks. However, for FPO
6334621e10eSAlvin Lee 		 * the assumption is that update clocks should be called to disable P-State
6344621e10eSAlvin Lee 		 * switch before any HW programming since FPO in FW and driver are not
6354621e10eSAlvin Lee 		 * synchronized. This causes an issue where on a MED update, an FPO P-State
6364621e10eSAlvin Lee 		 * switch could be taking place, then driver forces P-State disallow in the below
6374621e10eSAlvin Lee 		 * code and prevents FPO from completing the sequence. In this case we add a check
6384621e10eSAlvin Lee 		 * to avoid re-programming (and thus re-setting) the P-State force register by
6394621e10eSAlvin Lee 		 * only reprogramming if the pipe was not previously Subvp or FPO. The assumption
6404621e10eSAlvin Lee 		 * is that the P-State force register should be programmed correctly the first
6414621e10eSAlvin Lee 		 * time SubVP / FPO was enabled, so there's no need to update / reset it if the
6424621e10eSAlvin Lee 		 * pipe config has never exited SubVP / FPO.
6434621e10eSAlvin Lee 		 */
644e69d4335SAlvin Lee 		if (pipe->stream)
645e69d4335SAlvin Lee 			stream_status = dc_state_get_stream_status(context, pipe->stream);
646e69d4335SAlvin Lee 		if (old_pipe->stream)
647e69d4335SAlvin Lee 			old_stream_status = dc_state_get_stream_status(dc->current_state, old_pipe->stream);
648e69d4335SAlvin Lee 
64909a4ec5dSDillon Varone 		if (pipe->stream && (dc_state_get_pipe_subvp_type(context, pipe) == SUBVP_MAIN ||
650e69d4335SAlvin Lee 				(stream_status && stream_status->fpo_in_use)) &&
6515e211d2cSAlvin Lee 				(!old_pipe->stream || (dc_state_get_pipe_subvp_type(dc->current_state, old_pipe) != SUBVP_MAIN &&
652e69d4335SAlvin Lee 				(old_stream_status && !old_stream_status->fpo_in_use)))) {
653235c6763SAurabindo Pillai 			if (hubp && hubp->funcs->hubp_update_force_pstate_disallow)
654235c6763SAurabindo Pillai 				hubp->funcs->hubp_update_force_pstate_disallow(hubp, true);
6554ed79308SAlvin Lee 			if (hubp && hubp->funcs->hubp_update_force_cursor_pstate_disallow)
6564ed79308SAlvin Lee 				hubp->funcs->hubp_update_force_cursor_pstate_disallow(hubp, true);
6574ed79308SAlvin Lee 		}
658235c6763SAurabindo Pillai 	}
659235c6763SAurabindo Pillai }
660235c6763SAurabindo Pillai 
661235c6763SAurabindo Pillai /* Update MALL_SEL register based on if pipe / plane
662235c6763SAurabindo Pillai  * is a phantom pipe, main pipe, and if using MALL
663235c6763SAurabindo Pillai  * for SS.
664235c6763SAurabindo Pillai  */
dcn32_update_mall_sel(struct dc * dc,struct dc_state * context)665235c6763SAurabindo Pillai void dcn32_update_mall_sel(struct dc *dc, struct dc_state *context)
666235c6763SAurabindo Pillai {
667235c6763SAurabindo Pillai 	int i;
668235c6763SAurabindo Pillai 	unsigned int num_ways = dcn32_calculate_cab_allocation(dc, context);
6694074f96dSChris Park 	bool cache_cursor = false;
670235c6763SAurabindo Pillai 
671235c6763SAurabindo Pillai 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
672235c6763SAurabindo Pillai 		struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
673235c6763SAurabindo Pillai 		struct hubp *hubp = pipe->plane_res.hubp;
674235c6763SAurabindo Pillai 
675235c6763SAurabindo Pillai 		if (pipe->stream && pipe->plane_state && hubp && hubp->funcs->hubp_update_mall_sel) {
67657b014f6SGeorge Shen 			int cursor_size = hubp->curs_attr.pitch * hubp->curs_attr.height;
67739fc82b7STaimur Hassan 
67839fc82b7STaimur Hassan 			switch (hubp->curs_attr.color_format) {
67939fc82b7STaimur Hassan 			case CURSOR_MODE_MONO:
68039fc82b7STaimur Hassan 				cursor_size /= 2;
68139fc82b7STaimur Hassan 				break;
68239fc82b7STaimur Hassan 			case CURSOR_MODE_COLOR_1BIT_AND:
68339fc82b7STaimur Hassan 			case CURSOR_MODE_COLOR_PRE_MULTIPLIED_ALPHA:
68439fc82b7STaimur Hassan 			case CURSOR_MODE_COLOR_UN_PRE_MULTIPLIED_ALPHA:
68539fc82b7STaimur Hassan 				cursor_size *= 4;
68639fc82b7STaimur Hassan 				break;
68739fc82b7STaimur Hassan 
68839fc82b7STaimur Hassan 			case CURSOR_MODE_COLOR_64BIT_FP_PRE_MULTIPLIED:
68939fc82b7STaimur Hassan 			case CURSOR_MODE_COLOR_64BIT_FP_UN_PRE_MULTIPLIED:
69039fc82b7STaimur Hassan 			default:
69139fc82b7STaimur Hassan 				cursor_size *= 8;
69239fc82b7STaimur Hassan 				break;
69339fc82b7STaimur Hassan 			}
69439fc82b7STaimur Hassan 
69539fc82b7STaimur Hassan 			if (cursor_size > 16384)
6964074f96dSChris Park 				cache_cursor = true;
6974074f96dSChris Park 
69809a4ec5dSDillon Varone 			if (dc_state_get_pipe_subvp_type(context, pipe) == SUBVP_PHANTOM) {
6994074f96dSChris Park 				hubp->funcs->hubp_update_mall_sel(hubp, 1, false);
700235c6763SAurabindo Pillai 			} else {
701f0068dd0SAlvin Lee 				// MALL not supported with Stereo3D
702235c6763SAurabindo Pillai 				hubp->funcs->hubp_update_mall_sel(hubp,
703235c6763SAurabindo Pillai 					num_ways <= dc->caps.cache_num_ways &&
704f0068dd0SAlvin Lee 					pipe->stream->link->psr_settings.psr_version == DC_PSR_VERSION_UNSUPPORTED &&
705a6135ddeSAlvin Lee 					pipe->plane_state->address.type !=  PLN_ADDR_TYPE_GRPH_STEREO &&
706a6135ddeSAlvin Lee 					!pipe->plane_state->address.tmz_surface ? 2 : 0,
7074074f96dSChris Park 							cache_cursor);
708235c6763SAurabindo Pillai 			}
709235c6763SAurabindo Pillai 		}
710235c6763SAurabindo Pillai 	}
711235c6763SAurabindo Pillai }
712235c6763SAurabindo Pillai 
713235c6763SAurabindo Pillai /* Program the sub-viewport pipe configuration after the main / phantom pipes
714235c6763SAurabindo Pillai  * have been programmed in hardware.
715235c6763SAurabindo Pillai  * 1. Update force P-State for all the main pipes (disallow P-state)
716235c6763SAurabindo Pillai  * 2. Update MALL_SEL register
717235c6763SAurabindo Pillai  * 3. Program FORCE_ONE_ROW_FOR_FRAME for main subvp pipes
718235c6763SAurabindo Pillai  */
dcn32_program_mall_pipe_config(struct dc * dc,struct dc_state * context)719235c6763SAurabindo Pillai void dcn32_program_mall_pipe_config(struct dc *dc, struct dc_state *context)
720235c6763SAurabindo Pillai {
721235c6763SAurabindo Pillai 	int i;
722235c6763SAurabindo Pillai 	struct dce_hwseq *hws = dc->hwseq;
72385f4bc0cSAlvin Lee 
72485f4bc0cSAlvin Lee 	// Don't force p-state disallow -- can't block dummy p-state
725235c6763SAurabindo Pillai 
726235c6763SAurabindo Pillai 	// Update MALL_SEL register for each pipe
727235c6763SAurabindo Pillai 	if (hws && hws->funcs.update_mall_sel)
728235c6763SAurabindo Pillai 		hws->funcs.update_mall_sel(dc, context);
729235c6763SAurabindo Pillai 
730235c6763SAurabindo Pillai 	// Program FORCE_ONE_ROW_FOR_FRAME and CURSOR_REQ_MODE for main subvp pipes
731235c6763SAurabindo Pillai 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
732235c6763SAurabindo Pillai 		struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
733235c6763SAurabindo Pillai 		struct hubp *hubp = pipe->plane_res.hubp;
734235c6763SAurabindo Pillai 
735235c6763SAurabindo Pillai 		if (pipe->stream && hubp && hubp->funcs->hubp_prepare_subvp_buffering) {
736e87b92c6SSamson Tam 			/* TODO - remove setting CURSOR_REQ_MODE to 0 for legacy cases
737e87b92c6SSamson Tam 			 *      - need to investigate single pipe MPO + SubVP case to
738e87b92c6SSamson Tam 			 *        see if CURSOR_REQ_MODE will be back to 1 for SubVP
739e87b92c6SSamson Tam 			 *        when it should be 0 for MPO
740e87b92c6SSamson Tam 			 */
74109a4ec5dSDillon Varone 			if (dc_state_get_pipe_subvp_type(context, pipe) == SUBVP_MAIN)
742235c6763SAurabindo Pillai 				hubp->funcs->hubp_prepare_subvp_buffering(hubp, true);
743235c6763SAurabindo Pillai 		}
744235c6763SAurabindo Pillai 	}
745235c6763SAurabindo Pillai }
746235c6763SAurabindo Pillai 
dcn32_initialize_min_clocks(struct dc * dc)74758330ef1SAlvin Lee static void dcn32_initialize_min_clocks(struct dc *dc)
74858330ef1SAlvin Lee {
74958330ef1SAlvin Lee 	struct dc_clocks *clocks = &dc->current_state->bw_ctx.bw.dcn.clk;
75058330ef1SAlvin Lee 
75101ecd870SAlvin Lee 	clocks->dcfclk_deep_sleep_khz = DCN3_2_DCFCLK_DS_INIT_KHZ;
75258330ef1SAlvin Lee 	clocks->dcfclk_khz = dc->clk_mgr->bw_params->clk_table.entries[0].dcfclk_mhz * 1000;
75358330ef1SAlvin Lee 	clocks->socclk_khz = dc->clk_mgr->bw_params->clk_table.entries[0].socclk_mhz * 1000;
75458330ef1SAlvin Lee 	clocks->dramclk_khz = dc->clk_mgr->bw_params->clk_table.entries[0].memclk_mhz * 1000;
75558330ef1SAlvin Lee 	clocks->dppclk_khz = dc->clk_mgr->bw_params->clk_table.entries[0].dppclk_mhz * 1000;
756d11dfbecSAlvin Lee 	clocks->ref_dtbclk_khz = dc->clk_mgr->bw_params->clk_table.entries[0].dtbclk_mhz * 1000;
757d11dfbecSAlvin Lee 	clocks->fclk_p_state_change_support = true;
758d11dfbecSAlvin Lee 	clocks->p_state_change_support = true;
759d170e938SAlvin Lee 	if (dc->debug.disable_boot_optimizations) {
76058330ef1SAlvin Lee 		clocks->dispclk_khz = dc->clk_mgr->bw_params->clk_table.entries[0].dispclk_mhz * 1000;
761d170e938SAlvin Lee 	} else {
762d170e938SAlvin Lee 		/* Even though DPG_EN = 1 for the connected display, it still requires the
763d170e938SAlvin Lee 		 * correct timing so we cannot set DISPCLK to min freq or it could cause
764d170e938SAlvin Lee 		 * audio corruption. Read current DISPCLK from DENTIST and request the same
765d170e938SAlvin Lee 		 * freq to ensure that the timing is valid and unchanged.
766d170e938SAlvin Lee 		 */
767d170e938SAlvin Lee 		clocks->dispclk_khz = dc->clk_mgr->funcs->get_dispclk_from_dentist(dc->clk_mgr);
768d170e938SAlvin Lee 	}
76958330ef1SAlvin Lee 
77058330ef1SAlvin Lee 	dc->clk_mgr->funcs->update_clocks(
77158330ef1SAlvin Lee 			dc->clk_mgr,
77258330ef1SAlvin Lee 			dc->current_state,
77358330ef1SAlvin Lee 			true);
77458330ef1SAlvin Lee }
77558330ef1SAlvin Lee 
dcn32_init_hw(struct dc * dc)776235c6763SAurabindo Pillai void dcn32_init_hw(struct dc *dc)
777235c6763SAurabindo Pillai {
778235c6763SAurabindo Pillai 	struct abm **abms = dc->res_pool->multiple_abms;
779235c6763SAurabindo Pillai 	struct dce_hwseq *hws = dc->hwseq;
780235c6763SAurabindo Pillai 	struct dc_bios *dcb = dc->ctx->dc_bios;
781235c6763SAurabindo Pillai 	struct resource_pool *res_pool = dc->res_pool;
782235c6763SAurabindo Pillai 	int i;
783235c6763SAurabindo Pillai 	int edp_num;
784235c6763SAurabindo Pillai 	uint32_t backlight = MAX_BACKLIGHT_LEVEL;
785ee8ed250SCamille Cho 	uint32_t user_level = MAX_BACKLIGHT_LEVEL;
786235c6763SAurabindo Pillai 
787c395fd47SSrinivasan Shanmugam 	if (dc->clk_mgr && dc->clk_mgr->funcs && dc->clk_mgr->funcs->init_clocks)
788235c6763SAurabindo Pillai 		dc->clk_mgr->funcs->init_clocks(dc->clk_mgr);
789235c6763SAurabindo Pillai 
790235c6763SAurabindo Pillai 	// Initialize the dccg
791235c6763SAurabindo Pillai 	if (res_pool->dccg->funcs->dccg_init)
792235c6763SAurabindo Pillai 		res_pool->dccg->funcs->dccg_init(res_pool->dccg);
793235c6763SAurabindo Pillai 
794235c6763SAurabindo Pillai 	if (!dcb->funcs->is_accelerated_mode(dcb)) {
795235c6763SAurabindo Pillai 		hws->funcs.bios_golden_init(dc);
796235c6763SAurabindo Pillai 		hws->funcs.disable_vga(dc->hwseq);
797235c6763SAurabindo Pillai 	}
798235c6763SAurabindo Pillai 
799235c6763SAurabindo Pillai 	// Set default OPTC memory power states
800235c6763SAurabindo Pillai 	if (dc->debug.enable_mem_low_power.bits.optc) {
801235c6763SAurabindo Pillai 		// Shutdown when unassigned and light sleep in VBLANK
802235c6763SAurabindo Pillai 		REG_SET_2(ODM_MEM_PWR_CTRL3, 0, ODM_MEM_UNASSIGNED_PWR_MODE, 3, ODM_MEM_VBLANK_PWR_MODE, 1);
803235c6763SAurabindo Pillai 	}
804235c6763SAurabindo Pillai 
805235c6763SAurabindo Pillai 	if (dc->debug.enable_mem_low_power.bits.vga) {
806235c6763SAurabindo Pillai 		// Power down VGA memory
807235c6763SAurabindo Pillai 		REG_UPDATE(MMHUBBUB_MEM_PWR_CNTL, VGA_MEM_PWR_FORCE, 1);
808235c6763SAurabindo Pillai 	}
809235c6763SAurabindo Pillai 
810235c6763SAurabindo Pillai 	if (dc->ctx->dc_bios->fw_info_valid) {
811235c6763SAurabindo Pillai 		res_pool->ref_clocks.xtalin_clock_inKhz =
812235c6763SAurabindo Pillai 				dc->ctx->dc_bios->fw_info.pll_info.crystal_frequency;
813235c6763SAurabindo Pillai 
8141a664dc0SAlex Hung 		if (res_pool->hubbub) {
815235c6763SAurabindo Pillai 			(res_pool->dccg->funcs->get_dccg_ref_freq)(res_pool->dccg,
816235c6763SAurabindo Pillai 					dc->ctx->dc_bios->fw_info.pll_info.crystal_frequency,
817235c6763SAurabindo Pillai 					&res_pool->ref_clocks.dccg_ref_clock_inKhz);
818235c6763SAurabindo Pillai 
819235c6763SAurabindo Pillai 			(res_pool->hubbub->funcs->get_dchub_ref_freq)(res_pool->hubbub,
820235c6763SAurabindo Pillai 					res_pool->ref_clocks.dccg_ref_clock_inKhz,
821235c6763SAurabindo Pillai 					&res_pool->ref_clocks.dchub_ref_clock_inKhz);
822235c6763SAurabindo Pillai 		} else {
823235c6763SAurabindo Pillai 			// Not all ASICs have DCCG sw component
824235c6763SAurabindo Pillai 			res_pool->ref_clocks.dccg_ref_clock_inKhz =
825235c6763SAurabindo Pillai 					res_pool->ref_clocks.xtalin_clock_inKhz;
826235c6763SAurabindo Pillai 			res_pool->ref_clocks.dchub_ref_clock_inKhz =
827235c6763SAurabindo Pillai 					res_pool->ref_clocks.xtalin_clock_inKhz;
828235c6763SAurabindo Pillai 		}
829235c6763SAurabindo Pillai 	} else
830235c6763SAurabindo Pillai 		ASSERT_CRITICAL(false);
831235c6763SAurabindo Pillai 
832235c6763SAurabindo Pillai 	for (i = 0; i < dc->link_count; i++) {
833235c6763SAurabindo Pillai 		/* Power up AND update implementation according to the
834235c6763SAurabindo Pillai 		 * required signal (which may be different from the
835235c6763SAurabindo Pillai 		 * default signal on connector).
836235c6763SAurabindo Pillai 		 */
837235c6763SAurabindo Pillai 		struct dc_link *link = dc->links[i];
838235c6763SAurabindo Pillai 
839235c6763SAurabindo Pillai 		link->link_enc->funcs->hw_init(link->link_enc);
840235c6763SAurabindo Pillai 
841235c6763SAurabindo Pillai 		/* Check for enabled DIG to identify enabled display */
842235c6763SAurabindo Pillai 		if (link->link_enc->funcs->is_dig_enabled &&
8436ea843e0SJingwen Zhu 			link->link_enc->funcs->is_dig_enabled(link->link_enc)) {
844235c6763SAurabindo Pillai 			link->link_status.link_active = true;
8459c75891fSWenjing Liu 			link->phy_state.symclk_state = SYMCLK_ON_TX_ON;
8466ea843e0SJingwen Zhu 			if (link->link_enc->funcs->fec_is_active &&
8476ea843e0SJingwen Zhu 					link->link_enc->funcs->fec_is_active(link->link_enc))
8486ea843e0SJingwen Zhu 				link->fec_state = dc_link_fec_enabled;
8496ea843e0SJingwen Zhu 		}
850235c6763SAurabindo Pillai 	}
851235c6763SAurabindo Pillai 
852504d3caeSHersen Wu 	/* enable_power_gating_plane before dsc_pg_control because
853504d3caeSHersen Wu 	 * FORCEON = 1 with hw default value on bootup, resume from s3
854504d3caeSHersen Wu 	 */
855504d3caeSHersen Wu 	if (hws->funcs.enable_power_gating_plane)
856504d3caeSHersen Wu 		hws->funcs.enable_power_gating_plane(dc->hwseq, true);
857235c6763SAurabindo Pillai 
858235c6763SAurabindo Pillai 	/* we want to turn off all dp displays before doing detection */
85998ce7d32SWenjing Liu 	dc->link_srv->blank_all_dp_displays(dc);
860235c6763SAurabindo Pillai 
861235c6763SAurabindo Pillai 	/* If taking control over from VBIOS, we may want to optimize our first
862235c6763SAurabindo Pillai 	 * mode set, so we need to skip powering down pipes until we know which
863235c6763SAurabindo Pillai 	 * pipes we want to use.
864235c6763SAurabindo Pillai 	 * Otherwise, if taking control is not possible, we need to power
865235c6763SAurabindo Pillai 	 * everything down.
866235c6763SAurabindo Pillai 	 */
8673e80a5b0SDuncan Ma 	if (dcb->funcs->is_accelerated_mode(dcb) || !dc->config.seamless_boot_edp_requested) {
868d170e938SAlvin Lee 		/* Disable boot optimizations means power down everything including PHY, DIG,
869d170e938SAlvin Lee 		 * and OTG (i.e. the boot is not optimized because we do a full power down).
870d170e938SAlvin Lee 		 */
871d170e938SAlvin Lee 		if (dc->hwss.enable_accelerated_mode && dc->debug.disable_boot_optimizations)
872d170e938SAlvin Lee 			dc->hwss.enable_accelerated_mode(dc, dc->current_state);
873d170e938SAlvin Lee 		else
874235c6763SAurabindo Pillai 			hws->funcs.init_pipes(dc, dc->current_state);
875d170e938SAlvin Lee 
876235c6763SAurabindo Pillai 		if (dc->res_pool->hubbub->funcs->allow_self_refresh_control)
877235c6763SAurabindo Pillai 			dc->res_pool->hubbub->funcs->allow_self_refresh_control(dc->res_pool->hubbub,
878235c6763SAurabindo Pillai 					!dc->res_pool->hubbub->ctx->dc->debug.disable_stutter);
87958330ef1SAlvin Lee 
88058330ef1SAlvin Lee 		dcn32_initialize_min_clocks(dc);
881174a05afSAlvin Lee 
882174a05afSAlvin Lee 		/* On HW init, allow idle optimizations after pipes have been turned off.
883174a05afSAlvin Lee 		 *
884174a05afSAlvin Lee 		 * In certain D3 cases (i.e. BOCO / BOMACO) it's possible that hardware state
885174a05afSAlvin Lee 		 * is reset (i.e. not in idle at the time hw init is called), but software state
886174a05afSAlvin Lee 		 * still has idle_optimizations = true, so we must disable idle optimizations first
887174a05afSAlvin Lee 		 * (i.e. set false), then re-enable (set true).
888174a05afSAlvin Lee 		 */
889174a05afSAlvin Lee 		dc_allow_idle_optimizations(dc, false);
890174a05afSAlvin Lee 		dc_allow_idle_optimizations(dc, true);
891235c6763SAurabindo Pillai 	}
892235c6763SAurabindo Pillai 
893235c6763SAurabindo Pillai 	/* In headless boot cases, DIG may be turned
894235c6763SAurabindo Pillai 	 * on which causes HW/SW discrepancies.
895235c6763SAurabindo Pillai 	 * To avoid this, power down hardware on boot
896235c6763SAurabindo Pillai 	 * if DIG is turned on and seamless boot not enabled
897235c6763SAurabindo Pillai 	 */
8983e80a5b0SDuncan Ma 	if (!dc->config.seamless_boot_edp_requested) {
899235c6763SAurabindo Pillai 		struct dc_link *edp_links[MAX_NUM_EDP];
900235c6763SAurabindo Pillai 		struct dc_link *edp_link;
901235c6763SAurabindo Pillai 
9027ae1dbe6SWenjing Liu 		dc_get_edp_links(dc, edp_links, &edp_num);
903235c6763SAurabindo Pillai 		if (edp_num) {
904235c6763SAurabindo Pillai 			for (i = 0; i < edp_num; i++) {
905235c6763SAurabindo Pillai 				edp_link = edp_links[i];
906235c6763SAurabindo Pillai 				if (edp_link->link_enc->funcs->is_dig_enabled &&
907235c6763SAurabindo Pillai 						edp_link->link_enc->funcs->is_dig_enabled(edp_link->link_enc) &&
908235c6763SAurabindo Pillai 						dc->hwss.edp_backlight_control &&
90987325940SJoshua Aberback 						hws->funcs.power_down &&
910235c6763SAurabindo Pillai 						dc->hwss.edp_power_control) {
911235c6763SAurabindo Pillai 					dc->hwss.edp_backlight_control(edp_link, false);
91287325940SJoshua Aberback 					hws->funcs.power_down(dc);
913235c6763SAurabindo Pillai 					dc->hwss.edp_power_control(edp_link, false);
914235c6763SAurabindo Pillai 				}
915235c6763SAurabindo Pillai 			}
916235c6763SAurabindo Pillai 		} else {
917235c6763SAurabindo Pillai 			for (i = 0; i < dc->link_count; i++) {
918235c6763SAurabindo Pillai 				struct dc_link *link = dc->links[i];
919235c6763SAurabindo Pillai 
920235c6763SAurabindo Pillai 				if (link->link_enc->funcs->is_dig_enabled &&
921235c6763SAurabindo Pillai 						link->link_enc->funcs->is_dig_enabled(link->link_enc) &&
92287325940SJoshua Aberback 						hws->funcs.power_down) {
92387325940SJoshua Aberback 					hws->funcs.power_down(dc);
924235c6763SAurabindo Pillai 					break;
925235c6763SAurabindo Pillai 				}
926235c6763SAurabindo Pillai 
927235c6763SAurabindo Pillai 			}
928235c6763SAurabindo Pillai 		}
929235c6763SAurabindo Pillai 	}
930235c6763SAurabindo Pillai 
931235c6763SAurabindo Pillai 	for (i = 0; i < res_pool->audio_count; i++) {
932235c6763SAurabindo Pillai 		struct audio *audio = res_pool->audios[i];
933235c6763SAurabindo Pillai 
934235c6763SAurabindo Pillai 		audio->funcs->hw_init(audio);
935235c6763SAurabindo Pillai 	}
936235c6763SAurabindo Pillai 
937235c6763SAurabindo Pillai 	for (i = 0; i < dc->link_count; i++) {
938235c6763SAurabindo Pillai 		struct dc_link *link = dc->links[i];
939235c6763SAurabindo Pillai 
940ee8ed250SCamille Cho 		if (link->panel_cntl) {
941235c6763SAurabindo Pillai 			backlight = link->panel_cntl->funcs->hw_init(link->panel_cntl);
942ee8ed250SCamille Cho 			user_level = link->panel_cntl->stored_backlight_registers.USER_LEVEL;
943ee8ed250SCamille Cho 		}
944235c6763SAurabindo Pillai 	}
945235c6763SAurabindo Pillai 
946235c6763SAurabindo Pillai 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
947235c6763SAurabindo Pillai 		if (abms[i] != NULL && abms[i]->funcs != NULL)
948ee8ed250SCamille Cho 			abms[i]->funcs->abm_init(abms[i], backlight, user_level);
949235c6763SAurabindo Pillai 	}
950235c6763SAurabindo Pillai 
951235c6763SAurabindo Pillai 	/* power AFMT HDMI memory TODO: may move to dis/en output save power*/
952235c6763SAurabindo Pillai 	REG_WRITE(DIO_MEM_PWR_CTRL, 0);
953235c6763SAurabindo Pillai 
954235c6763SAurabindo Pillai 	if (!dc->debug.disable_clock_gate) {
955235c6763SAurabindo Pillai 		/* enable all DCN clock gating */
956235c6763SAurabindo Pillai 		REG_WRITE(DCCG_GATE_DISABLE_CNTL, 0);
957235c6763SAurabindo Pillai 
958235c6763SAurabindo Pillai 		REG_WRITE(DCCG_GATE_DISABLE_CNTL2, 0);
959235c6763SAurabindo Pillai 
960235c6763SAurabindo Pillai 		REG_UPDATE(DCFCLK_CNTL, DCFCLK_GATE_DIS, 0);
961235c6763SAurabindo Pillai 	}
962235c6763SAurabindo Pillai 
963235c6763SAurabindo Pillai 	if (!dcb->funcs->is_accelerated_mode(dcb) && dc->res_pool->hubbub->funcs->init_watermarks)
964235c6763SAurabindo Pillai 		dc->res_pool->hubbub->funcs->init_watermarks(dc->res_pool->hubbub);
965235c6763SAurabindo Pillai 
966c395fd47SSrinivasan Shanmugam 	if (dc->clk_mgr && dc->clk_mgr->funcs && dc->clk_mgr->funcs->notify_wm_ranges)
967235c6763SAurabindo Pillai 		dc->clk_mgr->funcs->notify_wm_ranges(dc->clk_mgr);
968235c6763SAurabindo Pillai 
969c395fd47SSrinivasan Shanmugam 	if (dc->clk_mgr && dc->clk_mgr->funcs && dc->clk_mgr->funcs->set_hard_max_memclk &&
970c395fd47SSrinivasan Shanmugam 	    !dc->clk_mgr->dc_mode_softmax_enabled)
971235c6763SAurabindo Pillai 		dc->clk_mgr->funcs->set_hard_max_memclk(dc->clk_mgr);
972235c6763SAurabindo Pillai 
973235c6763SAurabindo Pillai 	if (dc->res_pool->hubbub->funcs->force_pstate_change_control)
974235c6763SAurabindo Pillai 		dc->res_pool->hubbub->funcs->force_pstate_change_control(
975235c6763SAurabindo Pillai 				dc->res_pool->hubbub, false, false);
976235c6763SAurabindo Pillai 
977235c6763SAurabindo Pillai 	if (dc->res_pool->hubbub->funcs->init_crb)
978235c6763SAurabindo Pillai 		dc->res_pool->hubbub->funcs->init_crb(dc->res_pool->hubbub);
979235c6763SAurabindo Pillai 
980d97fd7a0SJun Lei 	if (dc->res_pool->hubbub->funcs->set_request_limit && dc->config.sdpif_request_limit_words_per_umc > 0)
981d97fd7a0SJun Lei 		dc->res_pool->hubbub->funcs->set_request_limit(dc->res_pool->hubbub, dc->ctx->dc_bios->vram_info.num_chans, dc->config.sdpif_request_limit_words_per_umc);
982d97fd7a0SJun Lei 
983235c6763SAurabindo Pillai 	// Get DMCUB capabilities
984235c6763SAurabindo Pillai 	if (dc->ctx->dmub_srv) {
985e97cc04fSJosip Pavic 		dc_dmub_srv_query_caps_cmd(dc->ctx->dmub_srv);
986235c6763SAurabindo Pillai 		dc->caps.dmub_caps.psr = dc->ctx->dmub_srv->dmub->feature_caps.psr;
987b058e399SAlvin Lee 		dc->caps.dmub_caps.subvp_psr = dc->ctx->dmub_srv->dmub->feature_caps.subvp_psr_support;
9881938bcdcSAlvin Lee 		dc->caps.dmub_caps.gecc_enable = dc->ctx->dmub_srv->dmub->feature_caps.gecc_enable;
98989e5f42cSDillon Varone 		dc->caps.dmub_caps.mclk_sw = dc->ctx->dmub_srv->dmub->feature_caps.fw_assisted_mclk_switch_ver;
99067958053SHarry VanZyllDeJong 		dc->caps.dmub_caps.aux_backlight_support = dc->ctx->dmub_srv->dmub->feature_caps.abm_aux_backlight_support;
99165550a9cSHamza Mahfooz 
99217b6527dSRodrigo Siqueira 		/* for DCN401 testing only */
99317b6527dSRodrigo Siqueira 		dc->caps.dmub_caps.fams_ver = dc->ctx->dmub_srv->dmub->feature_caps.fw_assisted_mclk_switch_ver;
99417b6527dSRodrigo Siqueira 		if (dc->caps.dmub_caps.fams_ver == 2) {
99517b6527dSRodrigo Siqueira 			/* FAMS2 is enabled */
99617b6527dSRodrigo Siqueira 			dc->debug.fams2_config.bits.enable &= true;
99717b6527dSRodrigo Siqueira 		} else if (dc->ctx->dmub_srv->dmub->fw_version <
99865550a9cSHamza Mahfooz 				DMUB_FW_VERSION(7, 0, 35)) {
99917b6527dSRodrigo Siqueira 			/* FAMS2 is disabled */
100017b6527dSRodrigo Siqueira 			dc->debug.fams2_config.bits.enable = false;
100117b6527dSRodrigo Siqueira 			if (dc->debug.using_dml2 && dc->res_pool->funcs->update_bw_bounding_box) {
100217b6527dSRodrigo Siqueira 				/* update bounding box if FAMS2 disabled */
100317b6527dSRodrigo Siqueira 				dc->res_pool->funcs->update_bw_bounding_box(dc, dc->clk_mgr->bw_params);
100417b6527dSRodrigo Siqueira 			}
100565550a9cSHamza Mahfooz 			dc->debug.force_disable_subvp = true;
100665550a9cSHamza Mahfooz 			dc->debug.disable_fpo_optimizations = true;
100765550a9cSHamza Mahfooz 		}
1008235c6763SAurabindo Pillai 	}
1009235c6763SAurabindo Pillai }
1010235c6763SAurabindo Pillai 
dcn32_update_dsc_on_stream(struct pipe_ctx * pipe_ctx,bool enable)1011176278d8SWenjing Liu void dcn32_update_dsc_on_stream(struct pipe_ctx *pipe_ctx, bool enable)
1012235c6763SAurabindo Pillai {
1013235c6763SAurabindo Pillai 	struct display_stream_compressor *dsc = pipe_ctx->stream_res.dsc;
101408a32addSWenjing Liu 	struct dc *dc = pipe_ctx->stream->ctx->dc;
1015235c6763SAurabindo Pillai 	struct dc_stream_state *stream = pipe_ctx->stream;
1016235c6763SAurabindo Pillai 	struct pipe_ctx *odm_pipe;
1017235c6763SAurabindo Pillai 	int opp_cnt = 1;
101808a32addSWenjing Liu 	struct dccg *dccg = dc->res_pool->dccg;
101908a32addSWenjing Liu 	/* It has been found that when DSCCLK is lower than 16Mhz, we will get DCN
102008a32addSWenjing Liu 	 * register access hung. When DSCCLk is based on refclk, DSCCLk is always a
102108a32addSWenjing Liu 	 * fixed value higher than 16Mhz so the issue doesn't occur. When DSCCLK is
102208a32addSWenjing Liu 	 * generated by DTO, DSCCLK would be based on 1/3 dispclk. For small timings
102308a32addSWenjing Liu 	 * with DSC such as 480p60Hz, the dispclk could be low enough to trigger
102408a32addSWenjing Liu 	 * this problem. We are implementing a workaround here to keep using dscclk
102508a32addSWenjing Liu 	 * based on fixed value refclk when timing is smaller than 3x16Mhz (i.e
102608a32addSWenjing Liu 	 * 48Mhz) pixel clock to avoid hitting this problem.
102708a32addSWenjing Liu 	 */
102808a32addSWenjing Liu 	bool should_use_dto_dscclk = (dccg->funcs->set_dto_dscclk != NULL) &&
102908a32addSWenjing Liu 			stream->timing.pix_clk_100hz > 480000;
1030235c6763SAurabindo Pillai 
1031235c6763SAurabindo Pillai 	ASSERT(dsc);
1032235c6763SAurabindo Pillai 	for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe)
1033235c6763SAurabindo Pillai 		opp_cnt++;
1034235c6763SAurabindo Pillai 
1035235c6763SAurabindo Pillai 	if (enable) {
1036235c6763SAurabindo Pillai 		struct dsc_config dsc_cfg;
1037f851b078SAlex Hung 		struct dsc_optc_config dsc_optc_cfg = {0};
1038235c6763SAurabindo Pillai 		enum optc_dsc_mode optc_dsc_mode;
10394bdc5b50SZhikai Zhai 		struct dcn_dsc_state dsc_state = {0};
10404bdc5b50SZhikai Zhai 
10414bdc5b50SZhikai Zhai 		if (!dsc) {
10424bdc5b50SZhikai Zhai 			DC_LOG_DSC("DSC is NULL for tg instance %d:", pipe_ctx->stream_res.tg->inst);
10434bdc5b50SZhikai Zhai 			return;
10444bdc5b50SZhikai Zhai 		}
10454bdc5b50SZhikai Zhai 
10464bdc5b50SZhikai Zhai 		if (dsc->funcs->dsc_read_state) {
10474bdc5b50SZhikai Zhai 			dsc->funcs->dsc_read_state(dsc, &dsc_state);
10484bdc5b50SZhikai Zhai 			if (!dsc_state.dsc_fw_en) {
10494bdc5b50SZhikai Zhai 				DC_LOG_DSC("DSC has been disabled for tg instance %d:", pipe_ctx->stream_res.tg->inst);
10504bdc5b50SZhikai Zhai 				return;
10514bdc5b50SZhikai Zhai 			}
10524bdc5b50SZhikai Zhai 		}
1053235c6763SAurabindo Pillai 
1054235c6763SAurabindo Pillai 		/* Enable DSC hw block */
10550c0a1943SChris Park 		dsc_cfg.pic_width = (stream->timing.h_addressable + pipe_ctx->hblank_borrow +
10560c0a1943SChris Park 				stream->timing.h_border_left + stream->timing.h_border_right) / opp_cnt;
1057235c6763SAurabindo Pillai 		dsc_cfg.pic_height = stream->timing.v_addressable + stream->timing.v_border_top + stream->timing.v_border_bottom;
1058235c6763SAurabindo Pillai 		dsc_cfg.pixel_encoding = stream->timing.pixel_encoding;
1059235c6763SAurabindo Pillai 		dsc_cfg.color_depth = stream->timing.display_color_depth;
1060235c6763SAurabindo Pillai 		dsc_cfg.is_odm = pipe_ctx->next_odm_pipe ? true : false;
1061235c6763SAurabindo Pillai 		dsc_cfg.dc_dsc_cfg = stream->timing.dsc_cfg;
1062235c6763SAurabindo Pillai 		ASSERT(dsc_cfg.dc_dsc_cfg.num_slices_h % opp_cnt == 0);
1063235c6763SAurabindo Pillai 		dsc_cfg.dc_dsc_cfg.num_slices_h /= opp_cnt;
1064235c6763SAurabindo Pillai 
10653c915431SWenjing Liu 		if (should_use_dto_dscclk)
10663c915431SWenjing Liu 			dccg->funcs->set_dto_dscclk(dccg, dsc->inst, dsc_cfg.dc_dsc_cfg.num_slices_h);
1067235c6763SAurabindo Pillai 		dsc->funcs->dsc_set_config(dsc, &dsc_cfg, &dsc_optc_cfg);
1068235c6763SAurabindo Pillai 		dsc->funcs->dsc_enable(dsc, pipe_ctx->stream_res.opp->inst);
1069235c6763SAurabindo Pillai 		for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe) {
1070235c6763SAurabindo Pillai 			struct display_stream_compressor *odm_dsc = odm_pipe->stream_res.dsc;
1071235c6763SAurabindo Pillai 
1072235c6763SAurabindo Pillai 			ASSERT(odm_dsc);
10733c915431SWenjing Liu 			if (!odm_dsc)
10743c915431SWenjing Liu 				continue;
1075235c6763SAurabindo Pillai 			if (should_use_dto_dscclk)
1076235c6763SAurabindo Pillai 				dccg->funcs->set_dto_dscclk(dccg, odm_dsc->inst, dsc_cfg.dc_dsc_cfg.num_slices_h);
1077235c6763SAurabindo Pillai 			odm_dsc->funcs->dsc_set_config(odm_dsc, &dsc_cfg, &dsc_optc_cfg);
1078235c6763SAurabindo Pillai 			odm_dsc->funcs->dsc_enable(odm_dsc, odm_pipe->stream_res.opp->inst);
1079235c6763SAurabindo Pillai 		}
1080235c6763SAurabindo Pillai 		optc_dsc_mode = dsc_optc_cfg.is_pixel_format_444 ? OPTC_DSC_ENABLED_444 : OPTC_DSC_ENABLED_NATIVE_SUBSAMPLED;
1081235c6763SAurabindo Pillai 		/* Enable DSC in OPTC */
1082235c6763SAurabindo Pillai 		DC_LOG_DSC("Setting optc DSC config for tg instance %d:", pipe_ctx->stream_res.tg->inst);
1083235c6763SAurabindo Pillai 		pipe_ctx->stream_res.tg->funcs->set_dsc_config(pipe_ctx->stream_res.tg,
1084235c6763SAurabindo Pillai 							optc_dsc_mode,
1085235c6763SAurabindo Pillai 							dsc_optc_cfg.bytes_per_pixel,
1086235c6763SAurabindo Pillai 							dsc_optc_cfg.slice_width);
1087235c6763SAurabindo Pillai 	} else {
1088235c6763SAurabindo Pillai 		/* disable DSC in OPTC */
1089235c6763SAurabindo Pillai 		pipe_ctx->stream_res.tg->funcs->set_dsc_config(
1090235c6763SAurabindo Pillai 				pipe_ctx->stream_res.tg,
1091176278d8SWenjing Liu 				OPTC_DSC_DISABLED, 0, 0);
10923c915431SWenjing Liu 
1093235c6763SAurabindo Pillai 		/* only disconnect DSC block, DSC is disabled when OPP head pipe is reset */
1094235c6763SAurabindo Pillai 		dsc->funcs->dsc_disconnect(pipe_ctx->stream_res.dsc);
1095176278d8SWenjing Liu 		for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe) {
1096235c6763SAurabindo Pillai 			ASSERT(odm_pipe->stream_res.dsc);
1097235c6763SAurabindo Pillai 			odm_pipe->stream_res.dsc->funcs->dsc_disconnect(odm_pipe->stream_res.dsc);
1098235c6763SAurabindo Pillai 		}
1099235c6763SAurabindo Pillai 	}
110049f59499SJun Lei }
110149f59499SJun Lei 
110249f59499SJun Lei /*
110349f59499SJun Lei * Given any pipe_ctx, return the total ODM combine factor, and optionally return
110449f59499SJun Lei * the OPPids which are used
110549f59499SJun Lei * */
get_odm_config(struct pipe_ctx * pipe_ctx,unsigned int * opp_instances)110649f59499SJun Lei static unsigned int get_odm_config(struct pipe_ctx *pipe_ctx, unsigned int *opp_instances)
110749f59499SJun Lei {
110849f59499SJun Lei 	unsigned int opp_count = 1;
110949f59499SJun Lei 	struct pipe_ctx *odm_pipe;
111049f59499SJun Lei 
111149f59499SJun Lei 	/* First get to the top pipe */
111249f59499SJun Lei 	for (odm_pipe = pipe_ctx; odm_pipe->prev_odm_pipe; odm_pipe = odm_pipe->prev_odm_pipe)
111349f59499SJun Lei 		;
111449f59499SJun Lei 
111549f59499SJun Lei 	/* First pipe is always used */
111649f59499SJun Lei 	if (opp_instances)
111749f59499SJun Lei 		opp_instances[0] = odm_pipe->stream_res.opp->inst;
111849f59499SJun Lei 
111949f59499SJun Lei 	/* Find and count odm pipes, if any */
112049f59499SJun Lei 	for (odm_pipe = odm_pipe->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe) {
112149f59499SJun Lei 		if (opp_instances)
112249f59499SJun Lei 			opp_instances[opp_count] = odm_pipe->stream_res.opp->inst;
112349f59499SJun Lei 		opp_count++;
112449f59499SJun Lei 	}
112549f59499SJun Lei 
112649f59499SJun Lei 	return opp_count;
1127235c6763SAurabindo Pillai }
1128235c6763SAurabindo Pillai 
dcn32_update_odm(struct dc * dc,struct dc_state * context,struct pipe_ctx * pipe_ctx)1129235c6763SAurabindo Pillai void dcn32_update_odm(struct dc *dc, struct dc_state *context, struct pipe_ctx *pipe_ctx)
113049f59499SJun Lei {
113149f59499SJun Lei 	struct pipe_ctx *odm_pipe;
1132f9d48a88SWenjing Liu 	int opp_cnt = 0;
1133f9d48a88SWenjing Liu 	int opp_inst[MAX_PIPES] = {0};
1134235c6763SAurabindo Pillai 	int odm_slice_width = resource_get_odm_slice_dst_width(pipe_ctx, false);
113549f59499SJun Lei 	int last_odm_slice_width = resource_get_odm_slice_dst_width(pipe_ctx, true);
1136235c6763SAurabindo Pillai 
1137235c6763SAurabindo Pillai 	opp_cnt = get_odm_config(pipe_ctx, opp_inst);
1138235c6763SAurabindo Pillai 
1139235c6763SAurabindo Pillai 	if (opp_cnt > 1)
1140235c6763SAurabindo Pillai 		pipe_ctx->stream_res.tg->funcs->set_odm_combine(
1141f9d48a88SWenjing Liu 				pipe_ctx->stream_res.tg,
1142235c6763SAurabindo Pillai 				opp_inst, opp_cnt,
1143235c6763SAurabindo Pillai 				odm_slice_width, last_odm_slice_width);
1144235c6763SAurabindo Pillai 	else
1145235c6763SAurabindo Pillai 		pipe_ctx->stream_res.tg->funcs->set_odm_bypass(
1146235c6763SAurabindo Pillai 				pipe_ctx->stream_res.tg, &pipe_ctx->stream->timing);
1147235c6763SAurabindo Pillai 
1148235c6763SAurabindo Pillai 	for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe) {
1149235c6763SAurabindo Pillai 		odm_pipe->stream_res.opp->funcs->opp_pipe_clock_control(
1150f9d48a88SWenjing Liu 				odm_pipe->stream_res.opp,
1151f9d48a88SWenjing Liu 				true);
1152f9d48a88SWenjing Liu 		odm_pipe->stream_res.opp->funcs->opp_program_left_edge_extra_pixel(
1153f9d48a88SWenjing Liu 				odm_pipe->stream_res.opp,
1154235c6763SAurabindo Pillai 				pipe_ctx->stream->timing.pixel_encoding,
1155235c6763SAurabindo Pillai 				resource_is_pipe_type(odm_pipe, OTG_MASTER));
115607ebc18cSRodrigo Siqueira 	}
115707ebc18cSRodrigo Siqueira 
1158235c6763SAurabindo Pillai 	if (pipe_ctx->stream_res.dsc) {
1159176278d8SWenjing Liu 		struct pipe_ctx *current_pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[pipe_ctx->pipe_idx];
116007ebc18cSRodrigo Siqueira 
116107ebc18cSRodrigo Siqueira 		dcn32_update_dsc_on_stream(pipe_ctx, pipe_ctx->stream->timing.flags.DSC);
116207ebc18cSRodrigo Siqueira 
116307ebc18cSRodrigo Siqueira 		/* Check if no longer using pipe for ODM, then need to disconnect DSC for that pipe */
116407ebc18cSRodrigo Siqueira 		if (!pipe_ctx->next_odm_pipe && current_pipe_ctx->next_odm_pipe &&
116508a32addSWenjing Liu 				current_pipe_ctx->next_odm_pipe->stream_res.dsc) {
116607ebc18cSRodrigo Siqueira 			struct display_stream_compressor *dsc = current_pipe_ctx->next_odm_pipe->stream_res.dsc;
116707ebc18cSRodrigo Siqueira 
116807ebc18cSRodrigo Siqueira 			/* disconnect DSC block from stream */
116907ebc18cSRodrigo Siqueira 			dsc->funcs->dsc_disconnect(dsc);
117086e9523fSWenjing Liu 		}
117186e9523fSWenjing Liu 	}
117286e9523fSWenjing Liu 
117386e9523fSWenjing Liu 	if (!resource_is_pipe_type(pipe_ctx, DPP_PIPE))
117486e9523fSWenjing Liu 		/*
117586e9523fSWenjing Liu 		 * blank pattern is generated by OPP, reprogram blank pattern
117686e9523fSWenjing Liu 		 * due to OPP count change
1177235c6763SAurabindo Pillai 		 */
1178235c6763SAurabindo Pillai 		dc->hwseq->funcs.blank_pixel_data(dc, pipe_ctx, true);
1179effee878SDmytro Laktyushkin }
118049f59499SJun Lei 
dcn32_calculate_dccg_k1_k2_values(struct pipe_ctx * pipe_ctx,unsigned int * k1_div,unsigned int * k2_div)118149f59499SJun Lei unsigned int dcn32_calculate_dccg_k1_k2_values(struct pipe_ctx *pipe_ctx, unsigned int *k1_div, unsigned int *k2_div)
1182effee878SDmytro Laktyushkin {
1183ffccfdbaSSamson Tam 	struct dc_stream_state *stream = pipe_ctx->stream;
1184*8aaeb253SMeenakshikumar Somasundaram 	unsigned int odm_combine_factor = 0;
118549f59499SJun Lei 	bool two_pix_per_container = false;
1186e6a901a0SWenjing Liu 	struct dce_hwseq *hws = stream->ctx->dc->hwseq;
1187effee878SDmytro Laktyushkin 
118849f59499SJun Lei 	two_pix_per_container = pipe_ctx->stream_res.tg->funcs->is_two_pixels_per_container(&stream->timing);
118998ce7d32SWenjing Liu 	odm_combine_factor = get_odm_config(pipe_ctx, NULL);
1190e3aa827eSTaimur Hassan 
119149f59499SJun Lei 	if (stream->ctx->dc->link_srv->dp_is_128b_132b_signal(pipe_ctx)) {
11923b214bb7SAurabindo Pillai 		*k1_div = PIXEL_RATE_DIV_BY_1;
119349f59499SJun Lei 		*k2_div = PIXEL_RATE_DIV_BY_1;
119449f59499SJun Lei 	} else if (dc_is_hdmi_tmds_signal(stream->signal) || dc_is_dvi_signal(stream->signal)) {
119549f59499SJun Lei 		*k1_div = PIXEL_RATE_DIV_BY_1;
119649f59499SJun Lei 		if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR420)
119749f59499SJun Lei 			*k2_div = PIXEL_RATE_DIV_BY_2;
119874fa4c81SSaaem Rizvi 		else
11992b2b3a75SRodrigo Siqueira 			*k2_div = PIXEL_RATE_DIV_BY_4;
120049f59499SJun Lei 	} else if (dc_is_dp_signal(stream->signal) || dc_is_virtual_signal(stream->signal)) {
120149f59499SJun Lei 		if (two_pix_per_container) {
120249f59499SJun Lei 			*k1_div = PIXEL_RATE_DIV_BY_1;
12032b2b3a75SRodrigo Siqueira 			*k2_div = PIXEL_RATE_DIV_BY_2;
12042b2b3a75SRodrigo Siqueira 		} else {
1205*8aaeb253SMeenakshikumar Somasundaram 			*k1_div = PIXEL_RATE_DIV_BY_1;
1206*8aaeb253SMeenakshikumar Somasundaram 			*k2_div = PIXEL_RATE_DIV_BY_4;
120749f59499SJun Lei 			if ((odm_combine_factor == 2) || (hws->funcs.is_dp_dig_pixel_rate_div_policy &&
120849f59499SJun Lei 				hws->funcs.is_dp_dig_pixel_rate_div_policy(pipe_ctx)))
120949f59499SJun Lei 				*k2_div = PIXEL_RATE_DIV_BY_2;
121049f59499SJun Lei 		}
121149f59499SJun Lei 	}
121249f59499SJun Lei 
1213effee878SDmytro Laktyushkin 	if ((*k1_div == PIXEL_RATE_DIV_NA) && (*k2_div == PIXEL_RATE_DIV_NA))
1214effee878SDmytro Laktyushkin 		ASSERT(false);
121549f59499SJun Lei 
121664a30aafSEric Bernstein 	return odm_combine_factor;
1217975507d7Syi-lchen }
1218975507d7Syi-lchen 
dcn32_calculate_pix_rate_divider(struct dc * dc,struct dc_state * context,const struct dc_stream_state * stream)1219975507d7Syi-lchen void dcn32_calculate_pix_rate_divider(
1220975507d7Syi-lchen 		struct dc *dc,
1221975507d7Syi-lchen 		struct dc_state *context,
1222975507d7Syi-lchen 		const struct dc_stream_state *stream)
1223975507d7Syi-lchen {
1224975507d7Syi-lchen 	struct dce_hwseq *hws = dc->hwseq;
1225975507d7Syi-lchen 	struct pipe_ctx *pipe_ctx = NULL;
1226975507d7Syi-lchen 	unsigned int k1_div = PIXEL_RATE_DIV_NA;
1227975507d7Syi-lchen 	unsigned int k2_div = PIXEL_RATE_DIV_NA;
1228975507d7Syi-lchen 
1229975507d7Syi-lchen 	pipe_ctx = resource_get_otg_master_for_stream(&context->res_ctx, stream);
1230975507d7Syi-lchen 
1231975507d7Syi-lchen 	if (pipe_ctx) {
1232975507d7Syi-lchen 
1233975507d7Syi-lchen 		if (hws->funcs.calculate_dccg_k1_k2_values)
1234975507d7Syi-lchen 			hws->funcs.calculate_dccg_k1_k2_values(pipe_ctx, &k1_div, &k2_div);
1235975507d7Syi-lchen 
1236975507d7Syi-lchen 		pipe_ctx->pixel_rate_divider.div_factor1 = k1_div;
1237975507d7Syi-lchen 		pipe_ctx->pixel_rate_divider.div_factor2 = k2_div;
1238975507d7Syi-lchen 	}
1239b3c9c9afSAlvin Lee }
12402da3556cSSaaem Rizvi 
dcn32_resync_fifo_dccg_dio(struct dce_hwseq * hws,struct dc * dc,struct dc_state * context,unsigned int current_pipe_idx)1241490ddccbSSaaem Rizvi void dcn32_resync_fifo_dccg_dio(struct dce_hwseq *hws, struct dc *dc, struct dc_state *context, unsigned int current_pipe_idx)
12422da3556cSSaaem Rizvi {
12432da3556cSSaaem Rizvi 	unsigned int i;
1244b3c9c9afSAlvin Lee 	struct pipe_ctx *pipe = NULL;
12452da3556cSSaaem Rizvi 	bool otg_disabled[MAX_PIPES] = {false};
12462da3556cSSaaem Rizvi 	struct dc_state *dc_state = NULL;
1247b3c9c9afSAlvin Lee 
1248b3c9c9afSAlvin Lee 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
1249b3c9c9afSAlvin Lee 		if (i <= current_pipe_idx) {
1250b3c9c9afSAlvin Lee 			pipe = &context->res_ctx.pipe_ctx[i];
12512da3556cSSaaem Rizvi 			dc_state = context;
1252b3c9c9afSAlvin Lee 		} else {
1253b3c9c9afSAlvin Lee 			pipe = &dc->current_state->res_ctx.pipe_ctx[i];
12542da3556cSSaaem Rizvi 			dc_state = dc->current_state;
125553f32880SWenjing Liu 		}
12562da3556cSSaaem Rizvi 
12572da3556cSSaaem Rizvi 		if (!resource_is_pipe_type(pipe, OTG_MASTER))
125853f32880SWenjing Liu 			continue;
1259b3c9c9afSAlvin Lee 
12602da3556cSSaaem Rizvi 		if ((pipe->stream->dpms_off || dc_is_virtual_signal(pipe->stream->signal))
12612da3556cSSaaem Rizvi 			&& dc_state_get_pipe_subvp_type(dc_state, pipe) != SUBVP_PHANTOM) {
12622da3556cSSaaem Rizvi 			pipe->stream_res.tg->funcs->disable_crtc(pipe->stream_res.tg);
12632da3556cSSaaem Rizvi 			reset_sync_context_for_pipe(dc, context, i);
12642da3556cSSaaem Rizvi 			otg_disabled[i] = true;
12652da3556cSSaaem Rizvi 		}
12662da3556cSSaaem Rizvi 	}
12672da3556cSSaaem Rizvi 
12682da3556cSSaaem Rizvi 	hws->ctx->dc->res_pool->dccg->funcs->trigger_dio_fifo_resync(hws->ctx->dc->res_pool->dccg);
1269b3c9c9afSAlvin Lee 
1270b3c9c9afSAlvin Lee 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
1271b3c9c9afSAlvin Lee 		if (i <= current_pipe_idx)
12722da3556cSSaaem Rizvi 			pipe = &context->res_ctx.pipe_ctx[i];
12732da3556cSSaaem Rizvi 		else
1274c76f56f2SAlvin Lee 			pipe = &dc->current_state->res_ctx.pipe_ctx[i];
1275c76f56f2SAlvin Lee 
1276c76f56f2SAlvin Lee 		if (otg_disabled[i]) {
1277c76f56f2SAlvin Lee 			int opp_inst[MAX_PIPES] = { pipe->stream_res.opp->inst };
1278c76f56f2SAlvin Lee 			int opp_cnt = 1;
1279c76f56f2SAlvin Lee 			int last_odm_slice_width = resource_get_odm_slice_dst_width(pipe, true);
1280c76f56f2SAlvin Lee 			int odm_slice_width = resource_get_odm_slice_dst_width(pipe, false);
1281c76f56f2SAlvin Lee 			struct pipe_ctx *odm_pipe;
1282c76f56f2SAlvin Lee 
1283c76f56f2SAlvin Lee 			for (odm_pipe = pipe->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe) {
1284c76f56f2SAlvin Lee 				opp_inst[opp_cnt] = odm_pipe->stream_res.opp->inst;
1285c76f56f2SAlvin Lee 				opp_cnt++;
1286c76f56f2SAlvin Lee 			}
1287c76f56f2SAlvin Lee 			if (opp_cnt > 1)
1288c76f56f2SAlvin Lee 				pipe->stream_res.tg->funcs->set_odm_combine(
1289c76f56f2SAlvin Lee 						pipe->stream_res.tg,
1290c76f56f2SAlvin Lee 						opp_inst, opp_cnt,
12912da3556cSSaaem Rizvi 						odm_slice_width,
12922da3556cSSaaem Rizvi 						last_odm_slice_width);
12932da3556cSSaaem Rizvi 			pipe->stream_res.tg->funcs->enable_crtc(pipe->stream_res.tg);
1294f86b47beSTungYu Lu 		}
1295f86b47beSTungYu Lu 	}
1296c76f56f2SAlvin Lee 
12972da3556cSSaaem Rizvi 	dc_trigger_sync(dc, dc->current_state);
129888ef4c5bSSamson Tam }
129988ef4c5bSSamson Tam 
dcn32_unblank_stream(struct pipe_ctx * pipe_ctx,struct dc_link_settings * link_settings)130088ef4c5bSSamson Tam void dcn32_unblank_stream(struct pipe_ctx *pipe_ctx,
130188ef4c5bSSamson Tam 		struct dc_link_settings *link_settings)
130288ef4c5bSSamson Tam {
130388ef4c5bSSamson Tam 	struct encoder_unblank_param params = {0};
130488ef4c5bSSamson Tam 	struct dc_stream_state *stream = pipe_ctx->stream;
130588ef4c5bSSamson Tam 	struct dc_link *link = stream->link;
130688ef4c5bSSamson Tam 	struct dce_hwseq *hws = link->dc->hwseq;
130788ef4c5bSSamson Tam 	struct pipe_ctx *odm_pipe;
1308975507d7Syi-lchen 
1309975507d7Syi-lchen 	params.opp_cnt = 1;
131088ef4c5bSSamson Tam 	params.pix_per_cycle = pipe_ctx->stream_res.pix_clk_params.dio_se_pix_per_cycle;
131188ef4c5bSSamson Tam 
131288ef4c5bSSamson Tam 	for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe)
131388ef4c5bSSamson Tam 		params.opp_cnt++;
131488ef4c5bSSamson Tam 
131588ef4c5bSSamson Tam 	/* only 3 items below are used by unblank */
131688ef4c5bSSamson Tam 	params.timing = pipe_ctx->stream->timing;
131788ef4c5bSSamson Tam 
131898ce7d32SWenjing Liu 	params.link_settings.link_rate = link_settings->link_rate;
131988ef4c5bSSamson Tam 
132088ef4c5bSSamson Tam 	if (link->dc->link_srv->dp_is_128b_132b_signal(pipe_ctx)) {
132188ef4c5bSSamson Tam 		/* TODO - DP2.0 HW: Set ODM mode in dp hpo encoder here */
132288ef4c5bSSamson Tam 		pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->dp_unblank(
132388ef4c5bSSamson Tam 				pipe_ctx->stream_res.hpo_dp_stream_enc,
1324975507d7Syi-lchen 				pipe_ctx->stream_res.tg->inst);
1325975507d7Syi-lchen 	} else if (dc_is_dp_signal(pipe_ctx->stream->signal)) {
132688ef4c5bSSamson Tam 		if (pipe_ctx->stream_res.tg->funcs->is_two_pixels_per_container(&stream->timing) ||
1327975507d7Syi-lchen 			params.opp_cnt > 1) {
1328532a0d2aSWebb Chen 			params.timing.pix_clk_100hz /= 2;
13292739bd12SDmytro 			params.pix_per_cycle = 2;
133088ef4c5bSSamson Tam 		}
1331975507d7Syi-lchen 		if (pipe_ctx->stream_res.stream_enc->funcs->dp_set_odm_combine)
133288ef4c5bSSamson Tam 			pipe_ctx->stream_res.stream_enc->funcs->dp_set_odm_combine(
133388ef4c5bSSamson Tam 				pipe_ctx->stream_res.stream_enc, params.pix_per_cycle > 1);
133488ef4c5bSSamson Tam 		pipe_ctx->stream_res.stream_enc->funcs->dp_unblank(link, pipe_ctx->stream_res.stream_enc, &params);
133588ef4c5bSSamson Tam 	}
133688ef4c5bSSamson Tam 
133788ef4c5bSSamson Tam 	if (link->local_sink && link->local_sink->sink_signal == SIGNAL_TYPE_EDP)
133888ef4c5bSSamson Tam 		hws->funcs.edp_backlight_control(link, true);
133988ef4c5bSSamson Tam }
134088ef4c5bSSamson Tam 
dcn32_is_dp_dig_pixel_rate_div_policy(struct pipe_ctx * pipe_ctx)134188ef4c5bSSamson Tam bool dcn32_is_dp_dig_pixel_rate_div_policy(struct pipe_ctx *pipe_ctx)
134288ef4c5bSSamson Tam {
13432d550a15SMartin Leung 	struct dc *dc = pipe_ctx->stream->ctx->dc;
13442d550a15SMartin Leung 
13452d550a15SMartin Leung 	if (!is_h_timing_divisible_by_2(pipe_ctx->stream))
134698ce7d32SWenjing Liu 		return false;
134788ef4c5bSSamson Tam 
134888ef4c5bSSamson Tam 	if (dc_is_dp_signal(pipe_ctx->stream->signal) && !dc->link_srv->dp_is_128b_132b_signal(pipe_ctx) &&
134988ef4c5bSSamson Tam 		dc->debug.enable_dp_dig_pixel_rate_div_policy)
135088ef4c5bSSamson Tam 		return true;
1351594b237bSAlvin Lee 	return false;
13529c75891fSWenjing Liu }
1353594b237bSAlvin Lee 
apply_symclk_on_tx_off_wa(struct dc_link * link)13549c75891fSWenjing Liu static void apply_symclk_on_tx_off_wa(struct dc_link *link)
13559c75891fSWenjing Liu {
13569c75891fSWenjing Liu 	/* There are use cases where SYMCLK is referenced by OTG. For instance
13579c75891fSWenjing Liu 	 * for TMDS signal, OTG relies SYMCLK even if TX video output is off.
13589c75891fSWenjing Liu 	 * However current link interface will power off PHY when disabling link
13599c75891fSWenjing Liu 	 * output. This will turn off SYMCLK generated by PHY. The workaround is
13609c75891fSWenjing Liu 	 * to identify such case where SYMCLK is still in use by OTG when we
13619c75891fSWenjing Liu 	 * power off PHY. When this is detected, we will temporarily power PHY
13629c75891fSWenjing Liu 	 * back on and move PHY's SYMCLK state to SYMCLK_ON_TX_OFF by calling
13639c75891fSWenjing Liu 	 * program_pix_clk interface. When OTG is disabled, we will then power
13649c75891fSWenjing Liu 	 * off PHY by calling disable link output again.
13659c75891fSWenjing Liu 	 *
13669c75891fSWenjing Liu 	 * In future dcn generations, we plan to rework transmitter control
13679c75891fSWenjing Liu 	 * interface so that we could have an option to set SYMCLK ON TX OFF
1368594b237bSAlvin Lee 	 * state in one step without this workaround
13699c75891fSWenjing Liu 	 */
13709c75891fSWenjing Liu 
13719c75891fSWenjing Liu 	struct dc *dc = link->ctx->dc;
1372594b237bSAlvin Lee 	struct pipe_ctx *pipe_ctx = NULL;
13739c75891fSWenjing Liu 	uint8_t i;
13749c75891fSWenjing Liu 
13759c75891fSWenjing Liu 	if (link->phy_state.symclk_ref_cnts.otg > 0) {
137653f32880SWenjing Liu 		for (i = 0; i < MAX_PIPES; i++) {
1377594b237bSAlvin Lee 			pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
1378594b237bSAlvin Lee 			if (resource_is_pipe_type(pipe_ctx, OPP_HEAD) && pipe_ctx->stream->link == link) {
1379594b237bSAlvin Lee 				pipe_ctx->clock_source->funcs->program_pix_clk(
138098ce7d32SWenjing Liu 						pipe_ctx->clock_source,
138198ce7d32SWenjing Liu 						&pipe_ctx->stream_res.pix_clk_params,
1382594b237bSAlvin Lee 						dc->link_srv->dp_get_encoding_format(
13839c75891fSWenjing Liu 								&pipe_ctx->link_config.dp_link_settings),
13849c75891fSWenjing Liu 						&pipe_ctx->pll_settings);
13859c75891fSWenjing Liu 				link->phy_state.symclk_state = SYMCLK_ON_TX_OFF;
13869c75891fSWenjing Liu 				break;
13879c75891fSWenjing Liu 			}
13889c75891fSWenjing Liu 		}
13899c75891fSWenjing Liu 	}
13909c75891fSWenjing Liu }
13919c75891fSWenjing Liu 
dcn32_disable_link_output(struct dc_link * link,const struct link_resource * link_res,enum signal_type signal)13929c75891fSWenjing Liu void dcn32_disable_link_output(struct dc_link *link,
13939c75891fSWenjing Liu 		const struct link_resource *link_res,
13949c75891fSWenjing Liu 		enum signal_type signal)
13959c75891fSWenjing Liu {
13969c75891fSWenjing Liu 	struct dc *dc = link->ctx->dc;
13979c75891fSWenjing Liu 	const struct link_hwss *link_hwss = get_link_hwss(link, link_res);
13989c75891fSWenjing Liu 	struct dmcu *dmcu = dc->res_pool->dmcu;
13995cf43f2cSIan Chen 
14005cf43f2cSIan Chen 	if (signal == SIGNAL_TYPE_EDP &&
14019c75891fSWenjing Liu 			link->dc->hwss.edp_backlight_control &&
14029c75891fSWenjing Liu 			!link->skip_implict_edp_power_control)
14039c75891fSWenjing Liu 		link->dc->hwss.edp_backlight_control(link, false);
14049c75891fSWenjing Liu 	else if (dmcu != NULL && dmcu->funcs->lock_phy)
14059c75891fSWenjing Liu 		dmcu->funcs->lock_phy(dmcu);
14069c75891fSWenjing Liu 
1407f5860c88SYiling Chen 	link_hwss->disable_link_output(link, link_res, signal);
1408f5860c88SYiling Chen 	link->phy_state.symclk_state = SYMCLK_OFF_TX_OFF;
1409f5860c88SYiling Chen 	/*
1410f5860c88SYiling Chen 	 * Add the logic to extract BOTH power up and power down sequences
1411f5860c88SYiling Chen 	 * from enable/disable link output and only call edp panel control
1412f5860c88SYiling Chen 	 * in enable_link_dp and disable_link_dp once.
14139c75891fSWenjing Liu 	 */
14149c75891fSWenjing Liu 	if (dmcu != NULL && dmcu->funcs->unlock_phy)
141598ce7d32SWenjing Liu 		dmcu->funcs->unlock_phy(dmcu);
14169c75891fSWenjing Liu 
14179c75891fSWenjing Liu 	dc->link_srv->dp_trace_source_sequence(link, DPCD_SOURCE_SEQ_AFTER_DISABLE_LINK_PHY);
1418594b237bSAlvin Lee 
141943080c9bSAlvin Lee 	apply_symclk_on_tx_off_wa(link);
142043080c9bSAlvin Lee }
142143080c9bSAlvin Lee 
142243080c9bSAlvin Lee /* For SubVP the main pipe can have a viewport position change
142343080c9bSAlvin Lee  * without a full update. In this case we must also update the
142443080c9bSAlvin Lee  * viewport positions for the phantom pipe accordingly.
142543080c9bSAlvin Lee  */
dcn32_update_phantom_vp_position(struct dc * dc,struct dc_state * context,struct pipe_ctx * phantom_pipe)142643080c9bSAlvin Lee void dcn32_update_phantom_vp_position(struct dc *dc,
142743080c9bSAlvin Lee 		struct dc_state *context,
1428ca86bbddSJosip Pavic 		struct pipe_ctx *phantom_pipe)
142943080c9bSAlvin Lee {
143043080c9bSAlvin Lee 	uint32_t i;
143143080c9bSAlvin Lee 	struct dc_plane_state *phantom_plane = phantom_pipe->plane_state;
143243080c9bSAlvin Lee 
143343080c9bSAlvin Lee 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
143409a4ec5dSDillon Varone 		struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1435012a04b1SDillon Varone 
143643080c9bSAlvin Lee 		if (pipe->stream && dc_state_get_pipe_subvp_type(context, pipe) == SUBVP_MAIN &&
143743080c9bSAlvin Lee 				dc_state_get_paired_subvp_stream(context, pipe->stream) == phantom_pipe->stream) {
143843080c9bSAlvin Lee 			if (pipe->plane_state && pipe->plane_state->update_flags.bits.position_change) {
143943080c9bSAlvin Lee 
144043080c9bSAlvin Lee 				phantom_plane->src_rect.x = pipe->plane_state->src_rect.x;
144143080c9bSAlvin Lee 				phantom_plane->src_rect.y = pipe->plane_state->src_rect.y;
144243080c9bSAlvin Lee 				phantom_plane->clip_rect.x = pipe->plane_state->clip_rect.x;
144343080c9bSAlvin Lee 				phantom_plane->dst_rect.x = pipe->plane_state->dst_rect.x;
144443080c9bSAlvin Lee 				phantom_plane->dst_rect.y = pipe->plane_state->dst_rect.y;
144543080c9bSAlvin Lee 
144643080c9bSAlvin Lee 				phantom_pipe->plane_state->update_flags.bits.position_change = 1;
144743080c9bSAlvin Lee 				resource_build_scaling_params(phantom_pipe);
144843080c9bSAlvin Lee 				return;
144943080c9bSAlvin Lee 			}
145043080c9bSAlvin Lee 		}
14511e939ea1SDillon Varone 	}
1452e267f5e6SAlvin Lee }
1453e267f5e6SAlvin Lee 
1454e267f5e6SAlvin Lee /* Treat the phantom pipe as if it needs to be fully enabled.
1455e267f5e6SAlvin Lee  * If the pipe was previously in use but not phantom, it would
1456e267f5e6SAlvin Lee  * have been disabled earlier in the sequence so we need to run
1457e267f5e6SAlvin Lee  * the full enable sequence.
1458e267f5e6SAlvin Lee  */
dcn32_apply_update_flags_for_phantom(struct pipe_ctx * phantom_pipe)1459e267f5e6SAlvin Lee void dcn32_apply_update_flags_for_phantom(struct pipe_ctx *phantom_pipe)
146053f32880SWenjing Liu {
1461e267f5e6SAlvin Lee 	phantom_pipe->update_flags.raw = 0;
1462e267f5e6SAlvin Lee 	if (resource_is_pipe_type(phantom_pipe, DPP_PIPE)) {
1463e267f5e6SAlvin Lee 		phantom_pipe->update_flags.bits.enable = 1;
1464e267f5e6SAlvin Lee 		phantom_pipe->update_flags.bits.mpcc = 1;
1465e267f5e6SAlvin Lee 		phantom_pipe->update_flags.bits.dppclk = 1;
1466e267f5e6SAlvin Lee 		phantom_pipe->update_flags.bits.hubp_interdependent = 1;
1467e267f5e6SAlvin Lee 		phantom_pipe->update_flags.bits.hubp_rq_dlg_ttu = 1;
1468e267f5e6SAlvin Lee 		phantom_pipe->update_flags.bits.gamut_remap = 1;
1469e267f5e6SAlvin Lee 		phantom_pipe->update_flags.bits.scaler = 1;
147053f32880SWenjing Liu 		phantom_pipe->update_flags.bits.viewport = 1;
1471e267f5e6SAlvin Lee 		phantom_pipe->update_flags.bits.det_size = 1;
1472e267f5e6SAlvin Lee 		if (resource_is_pipe_type(phantom_pipe, OTG_MASTER)) {
1473e267f5e6SAlvin Lee 			phantom_pipe->update_flags.bits.odm = 1;
1474e267f5e6SAlvin Lee 			phantom_pipe->update_flags.bits.global_sync = 1;
1475e267f5e6SAlvin Lee 		}
1476e267f5e6SAlvin Lee 	}
14771e939ea1SDillon Varone }
14781e939ea1SDillon Varone 
dcn32_dsc_pg_status(struct dce_hwseq * hws,unsigned int dsc_inst)14791e939ea1SDillon Varone bool dcn32_dsc_pg_status(
14801e939ea1SDillon Varone 		struct dce_hwseq *hws,
14811e939ea1SDillon Varone 		unsigned int dsc_inst)
14821e939ea1SDillon Varone {
14831e939ea1SDillon Varone 	uint32_t pwr_status = 0;
14841e939ea1SDillon Varone 
14851e939ea1SDillon Varone 	switch (dsc_inst) {
14861e939ea1SDillon Varone 	case 0: /* DSC0 */
14871e939ea1SDillon Varone 		REG_GET(DOMAIN16_PG_STATUS,
14881e939ea1SDillon Varone 				DOMAIN_PGFSM_PWR_STATUS, &pwr_status);
14891e939ea1SDillon Varone 		break;
14901e939ea1SDillon Varone 	case 1: /* DSC1 */
14911e939ea1SDillon Varone 
14921e939ea1SDillon Varone 		REG_GET(DOMAIN17_PG_STATUS,
14931e939ea1SDillon Varone 				DOMAIN_PGFSM_PWR_STATUS, &pwr_status);
14941e939ea1SDillon Varone 		break;
14951e939ea1SDillon Varone 	case 2: /* DSC2 */
14961e939ea1SDillon Varone 		REG_GET(DOMAIN18_PG_STATUS,
14971e939ea1SDillon Varone 				DOMAIN_PGFSM_PWR_STATUS, &pwr_status);
14981e939ea1SDillon Varone 		break;
14991e939ea1SDillon Varone 	case 3: /* DSC3 */
15001e939ea1SDillon Varone 		REG_GET(DOMAIN19_PG_STATUS,
15011e939ea1SDillon Varone 				DOMAIN_PGFSM_PWR_STATUS, &pwr_status);
15021e939ea1SDillon Varone 		break;
15031e939ea1SDillon Varone 	default:
15041e939ea1SDillon Varone 		BREAK_TO_DEBUGGER();
15051e939ea1SDillon Varone 		break;
15061f768ba4SYang Li 	}
15071e939ea1SDillon Varone 
15081e939ea1SDillon Varone 	return pwr_status == 0;
15091e939ea1SDillon Varone }
15101e939ea1SDillon Varone 
dcn32_update_dsc_pg(struct dc * dc,struct dc_state * context,bool safe_to_disable)15111e939ea1SDillon Varone void dcn32_update_dsc_pg(struct dc *dc,
15121e939ea1SDillon Varone 		struct dc_state *context,
15131e939ea1SDillon Varone 		bool safe_to_disable)
15149e447c81SAsher Song {
15151e939ea1SDillon Varone 	struct dce_hwseq *hws = dc->hwseq;
15169e447c81SAsher Song 	int i;
15171e939ea1SDillon Varone 
15181e939ea1SDillon Varone 	for (i = 0; i < dc->res_pool->res_cap->num_dsc; i++) {
15191e939ea1SDillon Varone 		struct display_stream_compressor *dsc = dc->res_pool->dscs[i];
15201e939ea1SDillon Varone 		bool is_dsc_ungated = hws->funcs.dsc_pg_status(hws, dsc->inst);
15211e939ea1SDillon Varone 
15221e939ea1SDillon Varone 		if (context->res_ctx.is_dsc_acquired[i]) {
15231e939ea1SDillon Varone 			if (!is_dsc_ungated) {
15241e939ea1SDillon Varone 				hws->funcs.dsc_pg_control(hws, dsc->inst, true);
15251e939ea1SDillon Varone 			}
15261e939ea1SDillon Varone 		} else if (safe_to_disable) {
15271e939ea1SDillon Varone 			if (is_dsc_ungated) {
15281e939ea1SDillon Varone 				hws->funcs.dsc_pg_control(hws, dsc->inst, false);
15291e939ea1SDillon Varone 			}
15301e939ea1SDillon Varone 		}
1531a5b50a0cSAlvin Lee 	}
15326a068e64SAlvin Lee }
15336a068e64SAlvin Lee 
dcn32_disable_phantom_streams(struct dc * dc,struct dc_state * context)15346a068e64SAlvin Lee void dcn32_disable_phantom_streams(struct dc *dc, struct dc_state *context)
15356a068e64SAlvin Lee {
15366a068e64SAlvin Lee 	struct dce_hwseq *hws = dc->hwseq;
15376a068e64SAlvin Lee 	int i;
15386a068e64SAlvin Lee 
15396a068e64SAlvin Lee 	for (i = dc->res_pool->pipe_count - 1; i >= 0 ; i--) {
15406a068e64SAlvin Lee 		struct pipe_ctx *pipe_ctx_old =
15416a068e64SAlvin Lee 			&dc->current_state->res_ctx.pipe_ctx[i];
15426a068e64SAlvin Lee 		struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
15436a068e64SAlvin Lee 
15446a068e64SAlvin Lee 		if (!pipe_ctx_old->stream)
15456a068e64SAlvin Lee 			continue;
15466a068e64SAlvin Lee 
15476a068e64SAlvin Lee 		if (dc_state_get_pipe_subvp_type(dc->current_state, pipe_ctx_old) != SUBVP_PHANTOM)
15486a068e64SAlvin Lee 			continue;
15496a068e64SAlvin Lee 
15506a068e64SAlvin Lee 		if (pipe_ctx_old->top_pipe || pipe_ctx_old->prev_odm_pipe)
15516a068e64SAlvin Lee 			continue;
15526a068e64SAlvin Lee 
15536a068e64SAlvin Lee 		if (!pipe_ctx->stream || pipe_need_reprogram(pipe_ctx_old, pipe_ctx) ||
15546a068e64SAlvin Lee 				(pipe_ctx->stream && dc_state_get_pipe_subvp_type(context, pipe_ctx) != SUBVP_PHANTOM)) {
15556a068e64SAlvin Lee 			struct clock_source *old_clk = pipe_ctx_old->clock_source;
15566a068e64SAlvin Lee 
15576a068e64SAlvin Lee 			if (hws->funcs.reset_back_end_for_pipe)
15586a068e64SAlvin Lee 				hws->funcs.reset_back_end_for_pipe(dc, pipe_ctx_old, dc->current_state);
15596a068e64SAlvin Lee 			if (hws->funcs.enable_stream_gating)
15606a068e64SAlvin Lee 				hws->funcs.enable_stream_gating(dc, pipe_ctx_old);
15616a068e64SAlvin Lee 			if (old_clk)
15626a068e64SAlvin Lee 				old_clk->funcs->cs_power_down(old_clk);
15636a068e64SAlvin Lee 		}
15646a068e64SAlvin Lee 	}
1565a5b50a0cSAlvin Lee }
1566a5b50a0cSAlvin Lee 
dcn32_enable_phantom_streams(struct dc * dc,struct dc_state * context)1567a5b50a0cSAlvin Lee void dcn32_enable_phantom_streams(struct dc *dc, struct dc_state *context)
15686a068e64SAlvin Lee {
15696a068e64SAlvin Lee 	unsigned int i;
1570a5b50a0cSAlvin Lee 	enum dc_status status = DC_OK;
1571a5b50a0cSAlvin Lee 	struct dce_hwseq *hws = dc->hwseq;
1572a5b50a0cSAlvin Lee 
1573a5b50a0cSAlvin Lee 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
1574a5b50a0cSAlvin Lee 		struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1575a5b50a0cSAlvin Lee 		struct pipe_ctx *old_pipe = &dc->current_state->res_ctx.pipe_ctx[i];
1576a5b50a0cSAlvin Lee 
1577a5b50a0cSAlvin Lee 		/* If an active, non-phantom pipe is being transitioned into a phantom
1578a5b50a0cSAlvin Lee 		 * pipe, wait for the double buffer update to complete first before we do
157909a4ec5dSDillon Varone 		 * ANY phantom pipe programming.
158009a4ec5dSDillon Varone 		 */
1581a5b50a0cSAlvin Lee 		if (pipe->stream && dc_state_get_pipe_subvp_type(context, pipe) == SUBVP_PHANTOM &&
1582a5b50a0cSAlvin Lee 				old_pipe->stream && dc_state_get_pipe_subvp_type(dc->current_state, old_pipe) != SUBVP_PHANTOM) {
1583a5b50a0cSAlvin Lee 			old_pipe->stream_res.tg->funcs->wait_for_state(
1584a5b50a0cSAlvin Lee 					old_pipe->stream_res.tg,
1585a5b50a0cSAlvin Lee 					CRTC_STATE_VBLANK);
1586a5b50a0cSAlvin Lee 			old_pipe->stream_res.tg->funcs->wait_for_state(
1587a5b50a0cSAlvin Lee 					old_pipe->stream_res.tg,
1588a5b50a0cSAlvin Lee 					CRTC_STATE_VACTIVE);
1589a5b50a0cSAlvin Lee 		}
15906a068e64SAlvin Lee 	}
15916a068e64SAlvin Lee 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
15926a068e64SAlvin Lee 		struct pipe_ctx *pipe_ctx_old =
1593a5b50a0cSAlvin Lee 					&dc->current_state->res_ctx.pipe_ctx[i];
15946a068e64SAlvin Lee 		struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
15956a068e64SAlvin Lee 
15966a068e64SAlvin Lee 		if (pipe_ctx->stream == NULL)
15976a068e64SAlvin Lee 			continue;
15986a068e64SAlvin Lee 
15996a068e64SAlvin Lee 		if (dc_state_get_pipe_subvp_type(context, pipe_ctx) != SUBVP_PHANTOM)
16006a068e64SAlvin Lee 			continue;
16016a068e64SAlvin Lee 
16026a068e64SAlvin Lee 		if (pipe_ctx->stream == pipe_ctx_old->stream &&
1603a5b50a0cSAlvin Lee 			pipe_ctx->stream->link->link_state_valid) {
16046a068e64SAlvin Lee 			continue;
16056a068e64SAlvin Lee 		}
16066a068e64SAlvin Lee 
16076a068e64SAlvin Lee 		if (pipe_ctx_old->stream && !pipe_need_reprogram(pipe_ctx_old, pipe_ctx))
16086a068e64SAlvin Lee 			continue;
16096a068e64SAlvin Lee 
16106a068e64SAlvin Lee 		if (pipe_ctx->top_pipe || pipe_ctx->prev_odm_pipe)
16116a068e64SAlvin Lee 			continue;
16126a068e64SAlvin Lee 
16136a068e64SAlvin Lee 		if (hws->funcs.apply_single_controller_ctx_to_hw)
16146a068e64SAlvin Lee 			status = hws->funcs.apply_single_controller_ctx_to_hw(
16156a068e64SAlvin Lee 					pipe_ctx,
16166a068e64SAlvin Lee 					context,
16176a068e64SAlvin Lee 					dc);
16186a068e64SAlvin Lee 
16196a068e64SAlvin Lee 		ASSERT(status == DC_OK);
16206a068e64SAlvin Lee 
1621b3c9c9afSAlvin Lee #ifdef CONFIG_DRM_AMD_DC_FP
16226a068e64SAlvin Lee 		if (hws->funcs.resync_fifo_dccg_dio)
1623a5b50a0cSAlvin Lee 			hws->funcs.resync_fifo_dccg_dio(hws, dc, context, i);
1624a5b50a0cSAlvin Lee #endif
162567d198daSAlvin Lee 	}
162667d198daSAlvin Lee }
162767d198daSAlvin Lee 
162867d198daSAlvin Lee /* Blank pixel data during initialization */
dcn32_init_blank(struct dc * dc,struct timing_generator * tg)162967d198daSAlvin Lee void dcn32_init_blank(
163067d198daSAlvin Lee 		struct dc *dc,
163167d198daSAlvin Lee 		struct timing_generator *tg)
163267d198daSAlvin Lee {
163367d198daSAlvin Lee 	struct dce_hwseq *hws = dc->hwseq;
163467d198daSAlvin Lee 	enum dc_color_space color_space;
163567d198daSAlvin Lee 	struct tg_color black_color = {0};
163667d198daSAlvin Lee 	struct output_pixel_processor *opp = NULL;
1637f851b078SAlex Hung 	struct output_pixel_processor *bottom_opp = NULL;
163867d198daSAlvin Lee 	uint32_t num_opps, opp_id_src0, opp_id_src1;
163967d198daSAlvin Lee 	uint32_t otg_active_width = 0, otg_active_height = 0;
164067d198daSAlvin Lee 	uint32_t i;
164167d198daSAlvin Lee 
164267d198daSAlvin Lee 	/* program opp dpg blank color */
164367d198daSAlvin Lee 	color_space = COLOR_SPACE_SRGB;
164467d198daSAlvin Lee 	color_space_to_black_color(dc, color_space, &black_color);
164567d198daSAlvin Lee 
164667d198daSAlvin Lee 	/* get the OTG active size */
164767d198daSAlvin Lee 	tg->funcs->get_otg_active_size(tg,
164867d198daSAlvin Lee 			&otg_active_width,
164967d198daSAlvin Lee 			&otg_active_height);
165067d198daSAlvin Lee 
165167d198daSAlvin Lee 	/* get the OPTC source */
165267d198daSAlvin Lee 	tg->funcs->get_optc_source(tg, &num_opps, &opp_id_src0, &opp_id_src1);
165367d198daSAlvin Lee 
165467d198daSAlvin Lee 	if (opp_id_src0 >= dc->res_pool->res_cap->num_opp) {
165567d198daSAlvin Lee 		ASSERT(false);
165667d198daSAlvin Lee 		return;
165767d198daSAlvin Lee 	}
165867d198daSAlvin Lee 
165967d198daSAlvin Lee 	for (i = 0; i < dc->res_pool->res_cap->num_opp; i++) {
166067d198daSAlvin Lee 		if (dc->res_pool->opps[i] != NULL && dc->res_pool->opps[i]->inst == opp_id_src0) {
166167d198daSAlvin Lee 			opp = dc->res_pool->opps[i];
166267d198daSAlvin Lee 			break;
166367d198daSAlvin Lee 		}
166467d198daSAlvin Lee 	}
166567d198daSAlvin Lee 
166667d198daSAlvin Lee 	if (num_opps == 2) {
166767d198daSAlvin Lee 		otg_active_width = otg_active_width / 2;
166867d198daSAlvin Lee 
166967d198daSAlvin Lee 		if (opp_id_src1 >= dc->res_pool->res_cap->num_opp) {
167067d198daSAlvin Lee 			ASSERT(false);
167167d198daSAlvin Lee 			return;
167267d198daSAlvin Lee 		}
167367d198daSAlvin Lee 		for (i = 0; i < dc->res_pool->res_cap->num_opp; i++) {
167467d198daSAlvin Lee 			if (dc->res_pool->opps[i] != NULL && dc->res_pool->opps[i]->inst == opp_id_src1) {
167567d198daSAlvin Lee 				bottom_opp = dc->res_pool->opps[i];
167667d198daSAlvin Lee 				break;
167767d198daSAlvin Lee 			}
167867d198daSAlvin Lee 		}
167967d198daSAlvin Lee 	}
168067d198daSAlvin Lee 
168167d198daSAlvin Lee 	if (opp && opp->funcs->opp_set_disp_pattern_generator)
168267d198daSAlvin Lee 		opp->funcs->opp_set_disp_pattern_generator(
168367d198daSAlvin Lee 				opp,
168467d198daSAlvin Lee 				CONTROLLER_DP_TEST_PATTERN_SOLID_COLOR,
168567d198daSAlvin Lee 				CONTROLLER_DP_COLOR_SPACE_UDEFINED,
168667d198daSAlvin Lee 				COLOR_DEPTH_UNDEFINED,
168767d198daSAlvin Lee 				&black_color,
168867d198daSAlvin Lee 				otg_active_width,
168967d198daSAlvin Lee 				otg_active_height,
169067d198daSAlvin Lee 				0);
169167d198daSAlvin Lee 
169267d198daSAlvin Lee 	if (num_opps == 2) {
169367d198daSAlvin Lee 		if (bottom_opp && bottom_opp->funcs->opp_set_disp_pattern_generator) {
169467d198daSAlvin Lee 			bottom_opp->funcs->opp_set_disp_pattern_generator(
169567d198daSAlvin Lee 					bottom_opp,
169667d198daSAlvin Lee 					CONTROLLER_DP_TEST_PATTERN_SOLID_COLOR,
169767d198daSAlvin Lee 					CONTROLLER_DP_COLOR_SPACE_UDEFINED,
169867d198daSAlvin Lee 					COLOR_DEPTH_UNDEFINED,
169967d198daSAlvin Lee 					&black_color,
170067d198daSAlvin Lee 					otg_active_width,
170167d198daSAlvin Lee 					otg_active_height,
170267d198daSAlvin Lee 					0);
170367d198daSAlvin Lee 			hws->funcs.wait_for_blank_complete(bottom_opp);
170467d198daSAlvin Lee 		}
170567d198daSAlvin Lee 	}
170667d198daSAlvin Lee 
170767d198daSAlvin Lee 	if (opp)
1708e87a6c5bSAlvin Lee 		hws->funcs.wait_for_blank_complete(opp);
1709cc299120SDillon Varone }
1710cc299120SDillon Varone 
1711cc299120SDillon Varone /* phantom stream id's can change often, but can be identical between contexts.
1712cc299120SDillon Varone *  This function checks for the condition the streams are identical to avoid
1713cc299120SDillon Varone *  redundant pipe transitions.
1714cc299120SDillon Varone */
is_subvp_phantom_topology_transition_seamless(const struct dc_state * cur_ctx,const struct dc_state * new_ctx,const struct pipe_ctx * cur_pipe,const struct pipe_ctx * new_pipe)1715cc299120SDillon Varone static bool is_subvp_phantom_topology_transition_seamless(
1716cc299120SDillon Varone 	const struct dc_state *cur_ctx,
1717cc299120SDillon Varone 	const struct dc_state *new_ctx,
1718cc299120SDillon Varone 	const struct pipe_ctx *cur_pipe,
1719cc299120SDillon Varone 	const struct pipe_ctx *new_pipe)
1720cc299120SDillon Varone {
1721cc299120SDillon Varone 	enum mall_stream_type cur_pipe_type = dc_state_get_pipe_subvp_type(cur_ctx, cur_pipe);
1722cc299120SDillon Varone 	enum mall_stream_type new_pipe_type = dc_state_get_pipe_subvp_type(new_ctx, new_pipe);
1723cc299120SDillon Varone 
1724cc299120SDillon Varone 	const struct dc_stream_state *cur_paired_stream = dc_state_get_paired_subvp_stream(cur_ctx, cur_pipe->stream);
1725cc299120SDillon Varone 	const struct dc_stream_state *new_paired_stream = dc_state_get_paired_subvp_stream(new_ctx, new_pipe->stream);
1726cc299120SDillon Varone 
1727cc299120SDillon Varone 	return cur_pipe_type == SUBVP_PHANTOM &&
1728cc299120SDillon Varone 			cur_pipe_type == new_pipe_type &&
1729cc299120SDillon Varone 			cur_paired_stream && new_paired_stream &&
1730cc299120SDillon Varone 			cur_paired_stream->stream_id == new_paired_stream->stream_id;
173115c6798aSWenjing Liu }
173215c6798aSWenjing Liu 
dcn32_is_pipe_topology_transition_seamless(struct dc * dc,const struct dc_state * cur_ctx,const struct dc_state * new_ctx)173315c6798aSWenjing Liu bool dcn32_is_pipe_topology_transition_seamless(struct dc *dc,
173415c6798aSWenjing Liu 		const struct dc_state *cur_ctx,
173515c6798aSWenjing Liu 		const struct dc_state *new_ctx)
173615c6798aSWenjing Liu {
173715c6798aSWenjing Liu 	int i;
173815c6798aSWenjing Liu 	const struct pipe_ctx *cur_pipe, *new_pipe;
173915c6798aSWenjing Liu 	bool is_seamless = true;
174015c6798aSWenjing Liu 
174115c6798aSWenjing Liu 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
174215c6798aSWenjing Liu 		cur_pipe = &cur_ctx->res_ctx.pipe_ctx[i];
174315c6798aSWenjing Liu 		new_pipe = &new_ctx->res_ctx.pipe_ctx[i];
174415c6798aSWenjing Liu 
174515c6798aSWenjing Liu 		if (resource_is_pipe_type(cur_pipe, FREE_PIPE) ||
174615c6798aSWenjing Liu 				resource_is_pipe_type(new_pipe, FREE_PIPE))
174715c6798aSWenjing Liu 			/* adding or removing free pipes is always seamless */
174815c6798aSWenjing Liu 			continue;
1749cc299120SDillon Varone 		else if (resource_is_pipe_type(cur_pipe, OTG_MASTER)) {
1750cc299120SDillon Varone 			if (resource_is_pipe_type(new_pipe, OTG_MASTER))
175115c6798aSWenjing Liu 				if (cur_pipe->stream->stream_id == new_pipe->stream->stream_id ||
175215c6798aSWenjing Liu 						is_subvp_phantom_topology_transition_seamless(cur_ctx, new_ctx, cur_pipe, new_pipe))
175315c6798aSWenjing Liu 				/* OTG master with the same stream is seamless */
175415c6798aSWenjing Liu 					continue;
175515c6798aSWenjing Liu 		} else if (resource_is_pipe_type(cur_pipe, OPP_HEAD)) {
175615c6798aSWenjing Liu 			if (resource_is_pipe_type(new_pipe, OPP_HEAD)) {
175715c6798aSWenjing Liu 				if (cur_pipe->stream_res.tg == new_pipe->stream_res.tg)
175815c6798aSWenjing Liu 					/*
175915c6798aSWenjing Liu 					 * OPP heads sharing the same timing
176015c6798aSWenjing Liu 					 * generator is seamless
176115c6798aSWenjing Liu 					 */
176215c6798aSWenjing Liu 					continue;
176315c6798aSWenjing Liu 			}
176415c6798aSWenjing Liu 		} else if (resource_is_pipe_type(cur_pipe, DPP_PIPE)) {
176515c6798aSWenjing Liu 			if (resource_is_pipe_type(new_pipe, DPP_PIPE)) {
176615c6798aSWenjing Liu 				if (cur_pipe->stream_res.opp == new_pipe->stream_res.opp)
176715c6798aSWenjing Liu 					/*
176815c6798aSWenjing Liu 					 * DPP pipes sharing the same OPP head is
176915c6798aSWenjing Liu 					 * seamless
177015c6798aSWenjing Liu 					 */
177115c6798aSWenjing Liu 					continue;
177215c6798aSWenjing Liu 			}
177315c6798aSWenjing Liu 		}
177415c6798aSWenjing Liu 
177515c6798aSWenjing Liu 		/*
177615c6798aSWenjing Liu 		 * This pipe's transition doesn't fall under any seamless
177715c6798aSWenjing Liu 		 * conditions
177815c6798aSWenjing Liu 		 */
177915c6798aSWenjing Liu 		is_seamless = false;
178015c6798aSWenjing Liu 		break;
178115c6798aSWenjing Liu 	}
178215c6798aSWenjing Liu 
1783f583db81SAlvin Lee 	return is_seamless;
1784f583db81SAlvin Lee }
1785f583db81SAlvin Lee 
dcn32_prepare_bandwidth(struct dc * dc,struct dc_state * context)1786f583db81SAlvin Lee void dcn32_prepare_bandwidth(struct dc *dc,
1787f583db81SAlvin Lee 	struct dc_state *context)
1788f583db81SAlvin Lee {
1789f583db81SAlvin Lee 	bool p_state_change_support = context->bw_ctx.bw.dcn.clk.p_state_change_support;
1790f583db81SAlvin Lee 	/* Any transition into an FPO config should disable MCLK switching first to avoid
1791f583db81SAlvin Lee 	 * driver and FW P-State synchronization issues.
1792f583db81SAlvin Lee 	 */
1793f583db81SAlvin Lee 	if (context->bw_ctx.bw.dcn.clk.fw_based_mclk_switching || dc->clk_mgr->clks.fw_based_mclk_switching) {
1794f583db81SAlvin Lee 		dc->optimized_required = true;
1795f583db81SAlvin Lee 		context->bw_ctx.bw.dcn.clk.p_state_change_support = false;
1796f583db81SAlvin Lee 	}
1797f583db81SAlvin Lee 
1798f583db81SAlvin Lee 	if (dc->clk_mgr->dc_mode_softmax_enabled)
1799f583db81SAlvin Lee 		if (dc->clk_mgr->clks.dramclk_khz <= dc->clk_mgr->bw_params->dc_mode_softmax_memclk * 1000 &&
1800f583db81SAlvin Lee 				context->bw_ctx.bw.dcn.clk.dramclk_khz > dc->clk_mgr->bw_params->dc_mode_softmax_memclk * 1000)
1801f583db81SAlvin Lee 			dc->clk_mgr->funcs->set_max_memclk(dc->clk_mgr, dc->clk_mgr->bw_params->clk_table.entries[dc->clk_mgr->bw_params->clk_table.num_entries - 1].memclk_mhz);
1802f583db81SAlvin Lee 
1803f583db81SAlvin Lee 	dcn20_prepare_bandwidth(dc, context);
1804f583db81SAlvin Lee 
1805f583db81SAlvin Lee 	if (!context->bw_ctx.bw.dcn.clk.fw_based_mclk_switching)
1806f583db81SAlvin Lee 		dc_dmub_srv_p_state_delegate(dc, false, context);
1807f583db81SAlvin Lee 
1808f583db81SAlvin Lee 	if (context->bw_ctx.bw.dcn.clk.fw_based_mclk_switching || dc->clk_mgr->clks.fw_based_mclk_switching) {
1809f583db81SAlvin Lee 		/* After disabling P-State, restore the original value to ensure we get the correct P-State
1810f583db81SAlvin Lee 		 * on the next optimize.
1811f583db81SAlvin Lee 		 */
1812f583db81SAlvin Lee 		context->bw_ctx.bw.dcn.clk.p_state_change_support = p_state_change_support;
181394040c2cSWenjing Liu 	}
181494040c2cSWenjing Liu }
181594040c2cSWenjing Liu 
dcn32_interdependent_update_lock(struct dc * dc,struct dc_state * context,bool lock)181694040c2cSWenjing Liu void dcn32_interdependent_update_lock(struct dc *dc,
181794040c2cSWenjing Liu 		struct dc_state *context, bool lock)
181894040c2cSWenjing Liu {
181994040c2cSWenjing Liu 	unsigned int i;
182094040c2cSWenjing Liu 	struct pipe_ctx *pipe;
182194040c2cSWenjing Liu 	struct timing_generator *tg;
182294040c2cSWenjing Liu 
182394040c2cSWenjing Liu 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
182494040c2cSWenjing Liu 		pipe = &context->res_ctx.pipe_ctx[i];
182594040c2cSWenjing Liu 		tg = pipe->stream_res.tg;
182694040c2cSWenjing Liu 
182794040c2cSWenjing Liu 		if (!resource_is_pipe_type(pipe, OTG_MASTER) ||
182894040c2cSWenjing Liu 				!tg->funcs->is_tg_enabled(tg) ||
182994040c2cSWenjing Liu 				dc_state_get_pipe_subvp_type(context, pipe) == SUBVP_PHANTOM)
183094040c2cSWenjing Liu 			continue;
183194040c2cSWenjing Liu 
183294040c2cSWenjing Liu 		if (lock)
183394040c2cSWenjing Liu 			dc->hwss.pipe_control_lock(dc, pipe, true);
183494040c2cSWenjing Liu 		else
183594040c2cSWenjing Liu 			dc->hwss.pipe_control_lock(dc, pipe, false);
18367a1eb668SDillon Varone 	}
18377a1eb668SDillon Varone }
18387a1eb668SDillon Varone 
dcn32_program_outstanding_updates(struct dc * dc,struct dc_state * context)18397a1eb668SDillon Varone void dcn32_program_outstanding_updates(struct dc *dc,
18407a1eb668SDillon Varone 		struct dc_state *context)
18417a1eb668SDillon Varone {
18427a1eb668SDillon Varone 	struct hubbub *hubbub = dc->res_pool->hubbub;
18437a1eb668SDillon Varone 
18447a1eb668SDillon Varone 	/* update compbuf if required */
18457a1eb668SDillon Varone 	if (hubbub->funcs->program_compbuf_size)
1846 		hubbub->funcs->program_compbuf_size(hubbub, context->bw_ctx.bw.dcn.compbuf_size_kb, true);
1847 }
1848