1 // SPDX-License-Identifier: MIT
2 /*
3  * Copyright 2022 Advanced Micro Devices, Inc.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21  * OTHER DEALINGS IN THE SOFTWARE.
22  *
23  * Authors: AMD
24  *
25  */
26 
27 #include "dm_services.h"
28 #include "dc.h"
29 
30 #include "dcn32_init.h"
31 
32 #include "resource.h"
33 #include "include/irq_service_interface.h"
34 #include "dcn32_resource.h"
35 
36 #include "dcn20/dcn20_resource.h"
37 #include "dcn30/dcn30_resource.h"
38 
39 #include "dcn10/dcn10_ipp.h"
40 #include "dcn30/dcn30_hubbub.h"
41 #include "dcn31/dcn31_hubbub.h"
42 #include "dcn32/dcn32_hubbub.h"
43 #include "dcn32/dcn32_mpc.h"
44 #include "dcn32_hubp.h"
45 #include "irq/dcn32/irq_service_dcn32.h"
46 #include "dcn32/dcn32_dpp.h"
47 #include "dcn32/dcn32_optc.h"
48 #include "dcn20/dcn20_hwseq.h"
49 #include "dcn30/dcn30_hwseq.h"
50 #include "dce110/dce110_hw_sequencer.h"
51 #include "dcn30/dcn30_opp.h"
52 #include "dcn20/dcn20_dsc.h"
53 #include "dcn30/dcn30_vpg.h"
54 #include "dcn30/dcn30_afmt.h"
55 #include "dcn30/dcn30_dio_stream_encoder.h"
56 #include "dcn32/dcn32_dio_stream_encoder.h"
57 #include "dcn31/dcn31_hpo_dp_stream_encoder.h"
58 #include "dcn31/dcn31_hpo_dp_link_encoder.h"
59 #include "dcn32/dcn32_hpo_dp_link_encoder.h"
60 #include "dcn31/dcn31_apg.h"
61 #include "dcn31/dcn31_dio_link_encoder.h"
62 #include "dcn32/dcn32_dio_link_encoder.h"
63 #include "dce/dce_clock_source.h"
64 #include "dce/dce_audio.h"
65 #include "dce/dce_hwseq.h"
66 #include "clk_mgr.h"
67 #include "virtual/virtual_stream_encoder.h"
68 #include "dml/display_mode_vba.h"
69 #include "dcn32/dcn32_dccg.h"
70 #include "dcn10/dcn10_resource.h"
71 #include "link.h"
72 #include "dcn31/dcn31_panel_cntl.h"
73 
74 #include "dcn30/dcn30_dwb.h"
75 #include "dcn32/dcn32_mmhubbub.h"
76 
77 #include "dcn/dcn_3_2_0_offset.h"
78 #include "dcn/dcn_3_2_0_sh_mask.h"
79 #include "nbio/nbio_4_3_0_offset.h"
80 
81 #include "reg_helper.h"
82 #include "dce/dmub_abm.h"
83 #include "dce/dmub_psr.h"
84 #include "dce/dce_aux.h"
85 #include "dce/dce_i2c.h"
86 
87 #include "dml/dcn30/display_mode_vba_30.h"
88 #include "vm_helper.h"
89 #include "dcn20/dcn20_vmid.h"
90 #include "dml/dcn32/dcn32_fpu.h"
91 
92 #define DC_LOGGER_INIT(logger)
93 
94 enum dcn32_clk_src_array_id {
95 	DCN32_CLK_SRC_PLL0,
96 	DCN32_CLK_SRC_PLL1,
97 	DCN32_CLK_SRC_PLL2,
98 	DCN32_CLK_SRC_PLL3,
99 	DCN32_CLK_SRC_PLL4,
100 	DCN32_CLK_SRC_TOTAL
101 };
102 
103 /* begin *********************
104  * macros to expend register list macro defined in HW object header file
105  */
106 
107 /* DCN */
108 #define BASE_INNER(seg) ctx->dcn_reg_offsets[seg]
109 
110 #define BASE(seg) BASE_INNER(seg)
111 
112 #define SR(reg_name)\
113 		REG_STRUCT.reg_name = BASE(reg ## reg_name ## _BASE_IDX) +  \
114 					reg ## reg_name
115 #define SR_ARR(reg_name, id) \
116 	REG_STRUCT[id].reg_name = BASE(reg##reg_name##_BASE_IDX) + reg##reg_name
117 
118 #define SR_ARR_INIT(reg_name, id, value) \
119 	REG_STRUCT[id].reg_name = value
120 
121 #define SRI(reg_name, block, id)\
122 	REG_STRUCT.reg_name = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
123 		reg ## block ## id ## _ ## reg_name
124 
125 #define SRI_ARR(reg_name, block, id)\
126 	REG_STRUCT[id].reg_name = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
127 		reg ## block ## id ## _ ## reg_name
128 
129 #define SR_ARR_I2C(reg_name, id) \
130 	REG_STRUCT[id-1].reg_name = BASE(reg##reg_name##_BASE_IDX) + reg##reg_name
131 
132 #define SRI_ARR_I2C(reg_name, block, id)\
133 	REG_STRUCT[id-1].reg_name = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
134 		reg ## block ## id ## _ ## reg_name
135 
136 #define SRI_ARR_ALPHABET(reg_name, block, index, id)\
137 	REG_STRUCT[index].reg_name = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
138 		reg ## block ## id ## _ ## reg_name
139 
140 #define SRI2(reg_name, block, id)\
141 	.reg_name = BASE(reg ## reg_name ## _BASE_IDX) +	\
142 		reg ## reg_name
143 #define SRI2_ARR(reg_name, block, id)\
144 	REG_STRUCT[id].reg_name = BASE(reg ## reg_name ## _BASE_IDX) +	\
145 		reg ## reg_name
146 
147 #define SRIR(var_name, reg_name, block, id)\
148 	.var_name = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
149 		reg ## block ## id ## _ ## reg_name
150 
151 #define SRII(reg_name, block, id)\
152 	REG_STRUCT.reg_name[id] = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
153 					reg ## block ## id ## _ ## reg_name
154 
155 #define SRII_ARR_2(reg_name, block, id, inst)\
156 	REG_STRUCT[inst].reg_name[id] = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
157 		reg ## block ## id ## _ ## reg_name
158 
159 #define SRII_MPC_RMU(reg_name, block, id)\
160 	.RMU##_##reg_name[id] = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
161 		reg ## block ## id ## _ ## reg_name
162 
163 #define SRII_DWB(reg_name, temp_name, block, id)\
164 	REG_STRUCT.reg_name[id] = BASE(reg ## block ## id ## _ ## temp_name ## _BASE_IDX) + \
165 		reg ## block ## id ## _ ## temp_name
166 
167 #define SF_DWB2(reg_name, block, id, field_name, post_fix)	\
168 	.field_name = reg_name ## __ ## field_name ## post_fix
169 
170 #define DCCG_SRII(reg_name, block, id)\
171 	REG_STRUCT.block ## _ ## reg_name[id] = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
172 		reg ## block ## id ## _ ## reg_name
173 
174 #define VUPDATE_SRII(reg_name, block, id)\
175 	REG_STRUCT.reg_name[id] = BASE(reg ## reg_name ## _ ## block ## id ## _BASE_IDX) + \
176 		reg ## reg_name ## _ ## block ## id
177 
178 /* NBIO */
179 #define NBIO_BASE_INNER(seg) ctx->nbio_reg_offsets[seg]
180 
181 #define NBIO_BASE(seg) \
182 	NBIO_BASE_INNER(seg)
183 
184 #define NBIO_SR(reg_name)\
185 	REG_STRUCT.reg_name = NBIO_BASE(regBIF_BX0_ ## reg_name ## _BASE_IDX) + \
186 			regBIF_BX0_ ## reg_name
187 #define NBIO_SR_ARR(reg_name, id)\
188 	REG_STRUCT[id].reg_name = NBIO_BASE(regBIF_BX0_ ## reg_name ## _BASE_IDX) + \
189 		regBIF_BX0_ ## reg_name
190 
191 #undef CTX
192 #define CTX ctx
193 #define REG(reg_name) \
194 	(ctx->dcn_reg_offsets[reg ## reg_name ## _BASE_IDX] + reg ## reg_name)
195 
196 static struct bios_registers bios_regs;
197 
198 #define bios_regs_init() \
199 		( \
200 		NBIO_SR(BIOS_SCRATCH_3),\
201 		NBIO_SR(BIOS_SCRATCH_6)\
202 		)
203 
204 #define clk_src_regs_init(index, pllid)\
205 	CS_COMMON_REG_LIST_DCN3_0_RI(index, pllid)
206 
207 static struct dce110_clk_src_regs clk_src_regs[5];
208 
209 static const struct dce110_clk_src_shift cs_shift = {
210 		CS_COMMON_MASK_SH_LIST_DCN3_2(__SHIFT)
211 };
212 
213 static const struct dce110_clk_src_mask cs_mask = {
214 		CS_COMMON_MASK_SH_LIST_DCN3_2(_MASK)
215 };
216 
217 #define abm_regs_init(id)\
218 		ABM_DCN32_REG_LIST_RI(id)
219 
220 static struct dce_abm_registers abm_regs[4];
221 
222 static const struct dce_abm_shift abm_shift = {
223 		ABM_MASK_SH_LIST_DCN32(__SHIFT)
224 };
225 
226 static const struct dce_abm_mask abm_mask = {
227 		ABM_MASK_SH_LIST_DCN32(_MASK)
228 };
229 
230 #define audio_regs_init(id)\
231 		AUD_COMMON_REG_LIST_RI(id)
232 
233 static struct dce_audio_registers audio_regs[5];
234 
235 #define DCE120_AUD_COMMON_MASK_SH_LIST(mask_sh)\
236 		SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_INDEX, AZALIA_ENDPOINT_REG_INDEX, mask_sh),\
237 		SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_DATA, AZALIA_ENDPOINT_REG_DATA, mask_sh),\
238 		AUD_COMMON_MASK_SH_LIST_BASE(mask_sh)
239 
240 static const struct dce_audio_shift audio_shift = {
241 		DCE120_AUD_COMMON_MASK_SH_LIST(__SHIFT)
242 };
243 
244 static const struct dce_audio_mask audio_mask = {
245 		DCE120_AUD_COMMON_MASK_SH_LIST(_MASK)
246 };
247 
248 #define vpg_regs_init(id)\
249 	VPG_DCN3_REG_LIST_RI(id)
250 
251 static struct dcn30_vpg_registers vpg_regs[10];
252 
253 static const struct dcn30_vpg_shift vpg_shift = {
254 	DCN3_VPG_MASK_SH_LIST(__SHIFT)
255 };
256 
257 static const struct dcn30_vpg_mask vpg_mask = {
258 	DCN3_VPG_MASK_SH_LIST(_MASK)
259 };
260 
261 #define afmt_regs_init(id)\
262 	AFMT_DCN3_REG_LIST_RI(id)
263 
264 static struct dcn30_afmt_registers afmt_regs[6];
265 
266 static const struct dcn30_afmt_shift afmt_shift = {
267 	DCN3_AFMT_MASK_SH_LIST(__SHIFT)
268 };
269 
270 static const struct dcn30_afmt_mask afmt_mask = {
271 	DCN3_AFMT_MASK_SH_LIST(_MASK)
272 };
273 
274 #define apg_regs_init(id)\
275 	APG_DCN31_REG_LIST_RI(id)
276 
277 static struct dcn31_apg_registers apg_regs[4];
278 
279 static const struct dcn31_apg_shift apg_shift = {
280 	DCN31_APG_MASK_SH_LIST(__SHIFT)
281 };
282 
283 static const struct dcn31_apg_mask apg_mask = {
284 		DCN31_APG_MASK_SH_LIST(_MASK)
285 };
286 
287 #define stream_enc_regs_init(id)\
288 	SE_DCN32_REG_LIST_RI(id)
289 
290 static struct dcn10_stream_enc_registers stream_enc_regs[5];
291 
292 static const struct dcn10_stream_encoder_shift se_shift = {
293 		SE_COMMON_MASK_SH_LIST_DCN32(__SHIFT)
294 };
295 
296 static const struct dcn10_stream_encoder_mask se_mask = {
297 		SE_COMMON_MASK_SH_LIST_DCN32(_MASK)
298 };
299 
300 
301 #define aux_regs_init(id)\
302 	DCN2_AUX_REG_LIST_RI(id)
303 
304 static struct dcn10_link_enc_aux_registers link_enc_aux_regs[5];
305 
306 #define hpd_regs_init(id)\
307 	HPD_REG_LIST_RI(id)
308 
309 static struct dcn10_link_enc_hpd_registers link_enc_hpd_regs[5];
310 
311 #define link_regs_init(id, phyid)\
312 	( \
313 	LE_DCN31_REG_LIST_RI(id), \
314 	UNIPHY_DCN2_REG_LIST_RI(id, phyid)\
315 	)
316 	/*DPCS_DCN31_REG_LIST(id),*/ \
317 
318 static struct dcn10_link_enc_registers link_enc_regs[5];
319 
320 static const struct dcn10_link_enc_shift le_shift = {
321 	LINK_ENCODER_MASK_SH_LIST_DCN31(__SHIFT), \
322 	//DPCS_DCN31_MASK_SH_LIST(__SHIFT)
323 };
324 
325 static const struct dcn10_link_enc_mask le_mask = {
326 	LINK_ENCODER_MASK_SH_LIST_DCN31(_MASK), \
327 
328 	//DPCS_DCN31_MASK_SH_LIST(_MASK)
329 };
330 
331 #define hpo_dp_stream_encoder_reg_init(id)\
332 	DCN3_1_HPO_DP_STREAM_ENC_REG_LIST_RI(id)
333 
334 static struct dcn31_hpo_dp_stream_encoder_registers hpo_dp_stream_enc_regs[4];
335 
336 static const struct dcn31_hpo_dp_stream_encoder_shift hpo_dp_se_shift = {
337 	DCN3_1_HPO_DP_STREAM_ENC_MASK_SH_LIST(__SHIFT)
338 };
339 
340 static const struct dcn31_hpo_dp_stream_encoder_mask hpo_dp_se_mask = {
341 	DCN3_1_HPO_DP_STREAM_ENC_MASK_SH_LIST(_MASK)
342 };
343 
344 
345 #define hpo_dp_link_encoder_reg_init(id)\
346 	DCN3_1_HPO_DP_LINK_ENC_REG_LIST_RI(id)
347 	/*DCN3_1_RDPCSTX_REG_LIST(0),*/
348 	/*DCN3_1_RDPCSTX_REG_LIST(1),*/
349 	/*DCN3_1_RDPCSTX_REG_LIST(2),*/
350 	/*DCN3_1_RDPCSTX_REG_LIST(3),*/
351 
352 static struct dcn31_hpo_dp_link_encoder_registers hpo_dp_link_enc_regs[2];
353 
354 static const struct dcn31_hpo_dp_link_encoder_shift hpo_dp_le_shift = {
355 	DCN3_2_HPO_DP_LINK_ENC_MASK_SH_LIST(__SHIFT)
356 };
357 
358 static const struct dcn31_hpo_dp_link_encoder_mask hpo_dp_le_mask = {
359 	DCN3_2_HPO_DP_LINK_ENC_MASK_SH_LIST(_MASK)
360 };
361 
362 #define dpp_regs_init(id)\
363 	DPP_REG_LIST_DCN30_COMMON_RI(id)
364 
365 static struct dcn3_dpp_registers dpp_regs[4];
366 
367 static const struct dcn3_dpp_shift tf_shift = {
368 		DPP_REG_LIST_SH_MASK_DCN30_COMMON(__SHIFT)
369 };
370 
371 static const struct dcn3_dpp_mask tf_mask = {
372 		DPP_REG_LIST_SH_MASK_DCN30_COMMON(_MASK)
373 };
374 
375 
376 #define opp_regs_init(id)\
377 	OPP_REG_LIST_DCN30_RI(id)
378 
379 static struct dcn20_opp_registers opp_regs[4];
380 
381 static const struct dcn20_opp_shift opp_shift = {
382 	OPP_MASK_SH_LIST_DCN20(__SHIFT)
383 };
384 
385 static const struct dcn20_opp_mask opp_mask = {
386 	OPP_MASK_SH_LIST_DCN20(_MASK)
387 };
388 
389 #define aux_engine_regs_init(id)\
390 	( \
391 	AUX_COMMON_REG_LIST0_RI(id), \
392 	SR_ARR_INIT(AUXN_IMPCAL, id, 0), \
393 	SR_ARR_INIT(AUXP_IMPCAL, id, 0), \
394 	SR_ARR_INIT(AUX_RESET_MASK, id, DP_AUX0_AUX_CONTROL__AUX_RESET_MASK), \
395 	SR_ARR_INIT(AUX_RESET_MASK, id, DP_AUX0_AUX_CONTROL__AUX_RESET_MASK)\
396 	)
397 
398 static struct dce110_aux_registers aux_engine_regs[5];
399 
400 static const struct dce110_aux_registers_shift aux_shift = {
401 	DCN_AUX_MASK_SH_LIST(__SHIFT)
402 };
403 
404 static const struct dce110_aux_registers_mask aux_mask = {
405 	DCN_AUX_MASK_SH_LIST(_MASK)
406 };
407 
408 #define dwbc_regs_dcn3_init(id)\
409 	DWBC_COMMON_REG_LIST_DCN30_RI(id)
410 
411 static struct dcn30_dwbc_registers dwbc30_regs[1];
412 
413 static const struct dcn30_dwbc_shift dwbc30_shift = {
414 	DWBC_COMMON_MASK_SH_LIST_DCN30(__SHIFT)
415 };
416 
417 static const struct dcn30_dwbc_mask dwbc30_mask = {
418 	DWBC_COMMON_MASK_SH_LIST_DCN30(_MASK)
419 };
420 
421 #define mcif_wb_regs_dcn3_init(id)\
422 	MCIF_WB_COMMON_REG_LIST_DCN32_RI(id)
423 
424 static struct dcn30_mmhubbub_registers mcif_wb30_regs[1];
425 
426 static const struct dcn30_mmhubbub_shift mcif_wb30_shift = {
427 	MCIF_WB_COMMON_MASK_SH_LIST_DCN32(__SHIFT)
428 };
429 
430 static const struct dcn30_mmhubbub_mask mcif_wb30_mask = {
431 	MCIF_WB_COMMON_MASK_SH_LIST_DCN32(_MASK)
432 };
433 
434 #define dsc_regsDCN20_init(id)\
435 	DSC_REG_LIST_DCN20_RI(id)
436 
437 static struct dcn20_dsc_registers dsc_regs[4];
438 
439 static const struct dcn20_dsc_shift dsc_shift = {
440 	DSC_REG_LIST_SH_MASK_DCN20(__SHIFT)
441 };
442 
443 static const struct dcn20_dsc_mask dsc_mask = {
444 	DSC_REG_LIST_SH_MASK_DCN20(_MASK)
445 };
446 
447 static struct dcn30_mpc_registers mpc_regs;
448 
449 #define dcn_mpc_regs_init() \
450 	MPC_REG_LIST_DCN3_2_RI(0),\
451 	MPC_REG_LIST_DCN3_2_RI(1),\
452 	MPC_REG_LIST_DCN3_2_RI(2),\
453 	MPC_REG_LIST_DCN3_2_RI(3),\
454 	MPC_OUT_MUX_REG_LIST_DCN3_0_RI(0),\
455 	MPC_OUT_MUX_REG_LIST_DCN3_0_RI(1),\
456 	MPC_OUT_MUX_REG_LIST_DCN3_0_RI(2),\
457 	MPC_OUT_MUX_REG_LIST_DCN3_0_RI(3),\
458 	MPC_DWB_MUX_REG_LIST_DCN3_0_RI(0)
459 
460 static const struct dcn30_mpc_shift mpc_shift = {
461 	MPC_COMMON_MASK_SH_LIST_DCN32(__SHIFT)
462 };
463 
464 static const struct dcn30_mpc_mask mpc_mask = {
465 	MPC_COMMON_MASK_SH_LIST_DCN32(_MASK)
466 };
467 
468 #define optc_regs_init(id)\
469 	OPTC_COMMON_REG_LIST_DCN3_2_RI(id)
470 
471 static struct dcn_optc_registers optc_regs[4];
472 
473 static const struct dcn_optc_shift optc_shift = {
474 	OPTC_COMMON_MASK_SH_LIST_DCN3_2(__SHIFT)
475 };
476 
477 static const struct dcn_optc_mask optc_mask = {
478 	OPTC_COMMON_MASK_SH_LIST_DCN3_2(_MASK)
479 };
480 
481 #define hubp_regs_init(id)\
482 	HUBP_REG_LIST_DCN32_RI(id)
483 
484 static struct dcn_hubp2_registers hubp_regs[4];
485 
486 
487 static const struct dcn_hubp2_shift hubp_shift = {
488 		HUBP_MASK_SH_LIST_DCN32(__SHIFT)
489 };
490 
491 static const struct dcn_hubp2_mask hubp_mask = {
492 		HUBP_MASK_SH_LIST_DCN32(_MASK)
493 };
494 
495 static struct dcn_hubbub_registers hubbub_reg;
496 #define hubbub_reg_init()\
497 		HUBBUB_REG_LIST_DCN32_RI(0)
498 
499 static const struct dcn_hubbub_shift hubbub_shift = {
500 		HUBBUB_MASK_SH_LIST_DCN32(__SHIFT)
501 };
502 
503 static const struct dcn_hubbub_mask hubbub_mask = {
504 		HUBBUB_MASK_SH_LIST_DCN32(_MASK)
505 };
506 
507 static struct dccg_registers dccg_regs;
508 
509 #define dccg_regs_init()\
510 	DCCG_REG_LIST_DCN32_RI()
511 
512 static const struct dccg_shift dccg_shift = {
513 		DCCG_MASK_SH_LIST_DCN32(__SHIFT)
514 };
515 
516 static const struct dccg_mask dccg_mask = {
517 		DCCG_MASK_SH_LIST_DCN32(_MASK)
518 };
519 
520 
521 #define SRII2(reg_name_pre, reg_name_post, id)\
522 	.reg_name_pre ## _ ##  reg_name_post[id] = BASE(reg ## reg_name_pre \
523 			## id ## _ ## reg_name_post ## _BASE_IDX) + \
524 			reg ## reg_name_pre ## id ## _ ## reg_name_post
525 
526 
527 #define HWSEQ_DCN32_REG_LIST()\
528 	SR(DCHUBBUB_GLOBAL_TIMER_CNTL), \
529 	SR(DIO_MEM_PWR_CTRL), \
530 	SR(ODM_MEM_PWR_CTRL3), \
531 	SR(MMHUBBUB_MEM_PWR_CNTL), \
532 	SR(DCCG_GATE_DISABLE_CNTL), \
533 	SR(DCCG_GATE_DISABLE_CNTL2), \
534 	SR(DCFCLK_CNTL),\
535 	SR(DC_MEM_GLOBAL_PWR_REQ_CNTL), \
536 	SRII(PIXEL_RATE_CNTL, OTG, 0), \
537 	SRII(PIXEL_RATE_CNTL, OTG, 1),\
538 	SRII(PIXEL_RATE_CNTL, OTG, 2),\
539 	SRII(PIXEL_RATE_CNTL, OTG, 3),\
540 	SRII(PHYPLL_PIXEL_RATE_CNTL, OTG, 0),\
541 	SRII(PHYPLL_PIXEL_RATE_CNTL, OTG, 1),\
542 	SRII(PHYPLL_PIXEL_RATE_CNTL, OTG, 2),\
543 	SRII(PHYPLL_PIXEL_RATE_CNTL, OTG, 3),\
544 	SR(MICROSECOND_TIME_BASE_DIV), \
545 	SR(MILLISECOND_TIME_BASE_DIV), \
546 	SR(DISPCLK_FREQ_CHANGE_CNTL), \
547 	SR(RBBMIF_TIMEOUT_DIS), \
548 	SR(RBBMIF_TIMEOUT_DIS_2), \
549 	SR(DCHUBBUB_CRC_CTRL), \
550 	SR(DPP_TOP0_DPP_CRC_CTRL), \
551 	SR(DPP_TOP0_DPP_CRC_VAL_B_A), \
552 	SR(DPP_TOP0_DPP_CRC_VAL_R_G), \
553 	SR(MPC_CRC_CTRL), \
554 	SR(MPC_CRC_RESULT_GB), \
555 	SR(MPC_CRC_RESULT_C), \
556 	SR(MPC_CRC_RESULT_AR), \
557 	SR(DOMAIN0_PG_CONFIG), \
558 	SR(DOMAIN1_PG_CONFIG), \
559 	SR(DOMAIN2_PG_CONFIG), \
560 	SR(DOMAIN3_PG_CONFIG), \
561 	SR(DOMAIN16_PG_CONFIG), \
562 	SR(DOMAIN17_PG_CONFIG), \
563 	SR(DOMAIN18_PG_CONFIG), \
564 	SR(DOMAIN19_PG_CONFIG), \
565 	SR(DOMAIN0_PG_STATUS), \
566 	SR(DOMAIN1_PG_STATUS), \
567 	SR(DOMAIN2_PG_STATUS), \
568 	SR(DOMAIN3_PG_STATUS), \
569 	SR(DOMAIN16_PG_STATUS), \
570 	SR(DOMAIN17_PG_STATUS), \
571 	SR(DOMAIN18_PG_STATUS), \
572 	SR(DOMAIN19_PG_STATUS), \
573 	SR(D1VGA_CONTROL), \
574 	SR(D2VGA_CONTROL), \
575 	SR(D3VGA_CONTROL), \
576 	SR(D4VGA_CONTROL), \
577 	SR(D5VGA_CONTROL), \
578 	SR(D6VGA_CONTROL), \
579 	SR(DC_IP_REQUEST_CNTL), \
580 	SR(AZALIA_AUDIO_DTO), \
581 	SR(AZALIA_CONTROLLER_CLOCK_GATING)
582 
583 static struct dce_hwseq_registers hwseq_reg;
584 
585 #define hwseq_reg_init()\
586 	HWSEQ_DCN32_REG_LIST()
587 
588 #define HWSEQ_DCN32_MASK_SH_LIST(mask_sh)\
589 	HWSEQ_DCN_MASK_SH_LIST(mask_sh), \
590 	HWS_SF(, DCHUBBUB_GLOBAL_TIMER_CNTL, DCHUBBUB_GLOBAL_TIMER_REFDIV, mask_sh), \
591 	HWS_SF(, DOMAIN0_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
592 	HWS_SF(, DOMAIN0_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
593 	HWS_SF(, DOMAIN1_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
594 	HWS_SF(, DOMAIN1_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
595 	HWS_SF(, DOMAIN2_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
596 	HWS_SF(, DOMAIN2_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
597 	HWS_SF(, DOMAIN3_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
598 	HWS_SF(, DOMAIN3_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
599 	HWS_SF(, DOMAIN16_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
600 	HWS_SF(, DOMAIN16_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
601 	HWS_SF(, DOMAIN17_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
602 	HWS_SF(, DOMAIN17_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
603 	HWS_SF(, DOMAIN18_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
604 	HWS_SF(, DOMAIN18_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
605 	HWS_SF(, DOMAIN19_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
606 	HWS_SF(, DOMAIN19_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
607 	HWS_SF(, DOMAIN0_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
608 	HWS_SF(, DOMAIN1_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
609 	HWS_SF(, DOMAIN2_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
610 	HWS_SF(, DOMAIN3_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
611 	HWS_SF(, DOMAIN16_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
612 	HWS_SF(, DOMAIN17_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
613 	HWS_SF(, DOMAIN18_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
614 	HWS_SF(, DOMAIN19_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
615 	HWS_SF(, DC_IP_REQUEST_CNTL, IP_REQUEST_EN, mask_sh), \
616 	HWS_SF(, AZALIA_AUDIO_DTO, AZALIA_AUDIO_DTO_MODULE, mask_sh), \
617 	HWS_SF(, HPO_TOP_CLOCK_CONTROL, HPO_HDMISTREAMCLK_G_GATE_DIS, mask_sh), \
618 	HWS_SF(, ODM_MEM_PWR_CTRL3, ODM_MEM_UNASSIGNED_PWR_MODE, mask_sh), \
619 	HWS_SF(, ODM_MEM_PWR_CTRL3, ODM_MEM_VBLANK_PWR_MODE, mask_sh), \
620 	HWS_SF(, MMHUBBUB_MEM_PWR_CNTL, VGA_MEM_PWR_FORCE, mask_sh)
621 
622 static const struct dce_hwseq_shift hwseq_shift = {
623 		HWSEQ_DCN32_MASK_SH_LIST(__SHIFT)
624 };
625 
626 static const struct dce_hwseq_mask hwseq_mask = {
627 		HWSEQ_DCN32_MASK_SH_LIST(_MASK)
628 };
629 #define vmid_regs_init(id)\
630 		DCN20_VMID_REG_LIST_RI(id)
631 
632 static struct dcn_vmid_registers vmid_regs[16];
633 
634 static const struct dcn20_vmid_shift vmid_shifts = {
635 		DCN20_VMID_MASK_SH_LIST(__SHIFT)
636 };
637 
638 static const struct dcn20_vmid_mask vmid_masks = {
639 		DCN20_VMID_MASK_SH_LIST(_MASK)
640 };
641 
642 static const struct resource_caps res_cap_dcn32 = {
643 	.num_timing_generator = 4,
644 	.num_opp = 4,
645 	.num_video_plane = 4,
646 	.num_audio = 5,
647 	.num_stream_encoder = 5,
648 	.num_hpo_dp_stream_encoder = 4,
649 	.num_hpo_dp_link_encoder = 2,
650 	.num_pll = 5,
651 	.num_dwb = 1,
652 	.num_ddc = 5,
653 	.num_vmid = 16,
654 	.num_mpc_3dlut = 4,
655 	.num_dsc = 4,
656 };
657 
658 static const struct dc_plane_cap plane_cap = {
659 	.type = DC_PLANE_TYPE_DCN_UNIVERSAL,
660 	.per_pixel_alpha = true,
661 
662 	.pixel_format_support = {
663 			.argb8888 = true,
664 			.nv12 = true,
665 			.fp16 = true,
666 			.p010 = true,
667 			.ayuv = false,
668 	},
669 
670 	.max_upscale_factor = {
671 			.argb8888 = 16000,
672 			.nv12 = 16000,
673 			.fp16 = 16000
674 	},
675 
676 	// 6:1 downscaling ratio: 1000/6 = 166.666
677 	.max_downscale_factor = {
678 			.argb8888 = 167,
679 			.nv12 = 167,
680 			.fp16 = 167
681 	},
682 	64,
683 	64
684 };
685 
686 static const struct dc_debug_options debug_defaults_drv = {
687 	.disable_dmcu = true,
688 	.force_abm_enable = false,
689 	.timing_trace = false,
690 	.clock_trace = true,
691 	.disable_pplib_clock_request = false,
692 	.pipe_split_policy = MPC_SPLIT_AVOID, // Due to CRB, no need to MPC split anymore
693 	.force_single_disp_pipe_split = false,
694 	.disable_dcc = DCC_ENABLE,
695 	.vsr_support = true,
696 	.performance_trace = false,
697 	.max_downscale_src_width = 7680,/*upto 8K*/
698 	.disable_pplib_wm_range = false,
699 	.scl_reset_length10 = true,
700 	.sanity_checks = false,
701 	.underflow_assert_delay_us = 0xFFFFFFFF,
702 	.dwb_fi_phase = -1, // -1 = disable,
703 	.dmub_command_table = true,
704 	.enable_mem_low_power = {
705 		.bits = {
706 			.vga = false,
707 			.i2c = false,
708 			.dmcu = false, // This is previously known to cause hang on S3 cycles if enabled
709 			.dscl = false,
710 			.cm = false,
711 			.mpc = false,
712 			.optc = true,
713 		}
714 	},
715 	.use_max_lb = true,
716 	.force_disable_subvp = false,
717 	.exit_idle_opt_for_cursor_updates = true,
718 	.enable_single_display_2to1_odm_policy = true,
719 
720 	/* Must match enable_single_display_2to1_odm_policy to support dynamic ODM transitions*/
721 	.enable_double_buffered_dsc_pg_support = true,
722 	.enable_dp_dig_pixel_rate_div_policy = 1,
723 	.allow_sw_cursor_fallback = false, // Linux can't do SW cursor "fallback"
724 	.alloc_extra_way_for_cursor = true,
725 	.min_prefetch_in_strobe_ns = 60000, // 60us
726 	.disable_unbounded_requesting = false,
727 	.override_dispclk_programming = true,
728 };
729 
730 static const struct dc_debug_options debug_defaults_diags = {
731 	.disable_dmcu = true,
732 	.force_abm_enable = false,
733 	.timing_trace = true,
734 	.clock_trace = true,
735 	.disable_dpp_power_gate = true,
736 	.disable_hubp_power_gate = true,
737 	.disable_dsc_power_gate = true,
738 	.disable_clock_gate = true,
739 	.disable_pplib_clock_request = true,
740 	.disable_pplib_wm_range = true,
741 	.disable_stutter = false,
742 	.scl_reset_length10 = true,
743 	.dwb_fi_phase = -1, // -1 = disable
744 	.dmub_command_table = true,
745 	.enable_tri_buf = true,
746 	.use_max_lb = true,
747 	.force_disable_subvp = true
748 };
749 
750 static struct dce_aux *dcn32_aux_engine_create(
751 	struct dc_context *ctx,
752 	uint32_t inst)
753 {
754 	struct aux_engine_dce110 *aux_engine =
755 		kzalloc(sizeof(struct aux_engine_dce110), GFP_KERNEL);
756 
757 	if (!aux_engine)
758 		return NULL;
759 
760 #undef REG_STRUCT
761 #define REG_STRUCT aux_engine_regs
762 	aux_engine_regs_init(0),
763 	aux_engine_regs_init(1),
764 	aux_engine_regs_init(2),
765 	aux_engine_regs_init(3),
766 	aux_engine_regs_init(4);
767 
768 	dce110_aux_engine_construct(aux_engine, ctx, inst,
769 				    SW_AUX_TIMEOUT_PERIOD_MULTIPLIER * AUX_TIMEOUT_PERIOD,
770 				    &aux_engine_regs[inst],
771 					&aux_mask,
772 					&aux_shift,
773 					ctx->dc->caps.extended_aux_timeout_support);
774 
775 	return &aux_engine->base;
776 }
777 #define i2c_inst_regs_init(id)\
778 	I2C_HW_ENGINE_COMMON_REG_LIST_DCN30_RI(id)
779 
780 static struct dce_i2c_registers i2c_hw_regs[5];
781 
782 static const struct dce_i2c_shift i2c_shifts = {
783 		I2C_COMMON_MASK_SH_LIST_DCN30(__SHIFT)
784 };
785 
786 static const struct dce_i2c_mask i2c_masks = {
787 		I2C_COMMON_MASK_SH_LIST_DCN30(_MASK)
788 };
789 
790 static struct dce_i2c_hw *dcn32_i2c_hw_create(
791 	struct dc_context *ctx,
792 	uint32_t inst)
793 {
794 	struct dce_i2c_hw *dce_i2c_hw =
795 		kzalloc(sizeof(struct dce_i2c_hw), GFP_KERNEL);
796 
797 	if (!dce_i2c_hw)
798 		return NULL;
799 
800 #undef REG_STRUCT
801 #define REG_STRUCT i2c_hw_regs
802 	i2c_inst_regs_init(1),
803 	i2c_inst_regs_init(2),
804 	i2c_inst_regs_init(3),
805 	i2c_inst_regs_init(4),
806 	i2c_inst_regs_init(5);
807 
808 	dcn2_i2c_hw_construct(dce_i2c_hw, ctx, inst,
809 				    &i2c_hw_regs[inst], &i2c_shifts, &i2c_masks);
810 
811 	return dce_i2c_hw;
812 }
813 
814 static struct clock_source *dcn32_clock_source_create(
815 		struct dc_context *ctx,
816 		struct dc_bios *bios,
817 		enum clock_source_id id,
818 		const struct dce110_clk_src_regs *regs,
819 		bool dp_clk_src)
820 {
821 	struct dce110_clk_src *clk_src =
822 		kzalloc(sizeof(struct dce110_clk_src), GFP_KERNEL);
823 
824 	if (!clk_src)
825 		return NULL;
826 
827 	if (dcn31_clk_src_construct(clk_src, ctx, bios, id,
828 			regs, &cs_shift, &cs_mask)) {
829 		clk_src->base.dp_clk_src = dp_clk_src;
830 		return &clk_src->base;
831 	}
832 
833 	kfree(clk_src);
834 	BREAK_TO_DEBUGGER();
835 	return NULL;
836 }
837 
838 static struct hubbub *dcn32_hubbub_create(struct dc_context *ctx)
839 {
840 	int i;
841 
842 	struct dcn20_hubbub *hubbub2 = kzalloc(sizeof(struct dcn20_hubbub),
843 					  GFP_KERNEL);
844 
845 	if (!hubbub2)
846 		return NULL;
847 
848 #undef REG_STRUCT
849 #define REG_STRUCT hubbub_reg
850 	hubbub_reg_init();
851 
852 #undef REG_STRUCT
853 #define REG_STRUCT vmid_regs
854 	vmid_regs_init(0),
855 	vmid_regs_init(1),
856 	vmid_regs_init(2),
857 	vmid_regs_init(3),
858 	vmid_regs_init(4),
859 	vmid_regs_init(5),
860 	vmid_regs_init(6),
861 	vmid_regs_init(7),
862 	vmid_regs_init(8),
863 	vmid_regs_init(9),
864 	vmid_regs_init(10),
865 	vmid_regs_init(11),
866 	vmid_regs_init(12),
867 	vmid_regs_init(13),
868 	vmid_regs_init(14),
869 	vmid_regs_init(15);
870 
871 	hubbub32_construct(hubbub2, ctx,
872 			&hubbub_reg,
873 			&hubbub_shift,
874 			&hubbub_mask,
875 			ctx->dc->dml.ip.det_buffer_size_kbytes,
876 			ctx->dc->dml.ip.pixel_chunk_size_kbytes,
877 			ctx->dc->dml.ip.config_return_buffer_size_in_kbytes);
878 
879 
880 	for (i = 0; i < res_cap_dcn32.num_vmid; i++) {
881 		struct dcn20_vmid *vmid = &hubbub2->vmid[i];
882 
883 		vmid->ctx = ctx;
884 
885 		vmid->regs = &vmid_regs[i];
886 		vmid->shifts = &vmid_shifts;
887 		vmid->masks = &vmid_masks;
888 	}
889 
890 	return &hubbub2->base;
891 }
892 
893 static struct hubp *dcn32_hubp_create(
894 	struct dc_context *ctx,
895 	uint32_t inst)
896 {
897 	struct dcn20_hubp *hubp2 =
898 		kzalloc(sizeof(struct dcn20_hubp), GFP_KERNEL);
899 
900 	if (!hubp2)
901 		return NULL;
902 
903 #undef REG_STRUCT
904 #define REG_STRUCT hubp_regs
905 	hubp_regs_init(0),
906 	hubp_regs_init(1),
907 	hubp_regs_init(2),
908 	hubp_regs_init(3);
909 
910 	if (hubp32_construct(hubp2, ctx, inst,
911 			&hubp_regs[inst], &hubp_shift, &hubp_mask))
912 		return &hubp2->base;
913 
914 	BREAK_TO_DEBUGGER();
915 	kfree(hubp2);
916 	return NULL;
917 }
918 
919 static void dcn32_dpp_destroy(struct dpp **dpp)
920 {
921 	kfree(TO_DCN30_DPP(*dpp));
922 	*dpp = NULL;
923 }
924 
925 static struct dpp *dcn32_dpp_create(
926 	struct dc_context *ctx,
927 	uint32_t inst)
928 {
929 	struct dcn3_dpp *dpp3 =
930 		kzalloc(sizeof(struct dcn3_dpp), GFP_KERNEL);
931 
932 	if (!dpp3)
933 		return NULL;
934 
935 #undef REG_STRUCT
936 #define REG_STRUCT dpp_regs
937 	dpp_regs_init(0),
938 	dpp_regs_init(1),
939 	dpp_regs_init(2),
940 	dpp_regs_init(3);
941 
942 	if (dpp32_construct(dpp3, ctx, inst,
943 			&dpp_regs[inst], &tf_shift, &tf_mask))
944 		return &dpp3->base;
945 
946 	BREAK_TO_DEBUGGER();
947 	kfree(dpp3);
948 	return NULL;
949 }
950 
951 static struct mpc *dcn32_mpc_create(
952 		struct dc_context *ctx,
953 		int num_mpcc,
954 		int num_rmu)
955 {
956 	struct dcn30_mpc *mpc30 = kzalloc(sizeof(struct dcn30_mpc),
957 					  GFP_KERNEL);
958 
959 	if (!mpc30)
960 		return NULL;
961 
962 #undef REG_STRUCT
963 #define REG_STRUCT mpc_regs
964 	dcn_mpc_regs_init();
965 
966 	dcn32_mpc_construct(mpc30, ctx,
967 			&mpc_regs,
968 			&mpc_shift,
969 			&mpc_mask,
970 			num_mpcc,
971 			num_rmu);
972 
973 	return &mpc30->base;
974 }
975 
976 static struct output_pixel_processor *dcn32_opp_create(
977 	struct dc_context *ctx, uint32_t inst)
978 {
979 	struct dcn20_opp *opp2 =
980 		kzalloc(sizeof(struct dcn20_opp), GFP_KERNEL);
981 
982 	if (!opp2) {
983 		BREAK_TO_DEBUGGER();
984 		return NULL;
985 	}
986 
987 #undef REG_STRUCT
988 #define REG_STRUCT opp_regs
989 	opp_regs_init(0),
990 	opp_regs_init(1),
991 	opp_regs_init(2),
992 	opp_regs_init(3);
993 
994 	dcn20_opp_construct(opp2, ctx, inst,
995 			&opp_regs[inst], &opp_shift, &opp_mask);
996 	return &opp2->base;
997 }
998 
999 
1000 static struct timing_generator *dcn32_timing_generator_create(
1001 		struct dc_context *ctx,
1002 		uint32_t instance)
1003 {
1004 	struct optc *tgn10 =
1005 		kzalloc(sizeof(struct optc), GFP_KERNEL);
1006 
1007 	if (!tgn10)
1008 		return NULL;
1009 
1010 #undef REG_STRUCT
1011 #define REG_STRUCT optc_regs
1012 	optc_regs_init(0),
1013 	optc_regs_init(1),
1014 	optc_regs_init(2),
1015 	optc_regs_init(3);
1016 
1017 	tgn10->base.inst = instance;
1018 	tgn10->base.ctx = ctx;
1019 
1020 	tgn10->tg_regs = &optc_regs[instance];
1021 	tgn10->tg_shift = &optc_shift;
1022 	tgn10->tg_mask = &optc_mask;
1023 
1024 	dcn32_timing_generator_init(tgn10);
1025 
1026 	return &tgn10->base;
1027 }
1028 
1029 static const struct encoder_feature_support link_enc_feature = {
1030 		.max_hdmi_deep_color = COLOR_DEPTH_121212,
1031 		.max_hdmi_pixel_clock = 600000,
1032 		.hdmi_ycbcr420_supported = true,
1033 		.dp_ycbcr420_supported = true,
1034 		.fec_supported = true,
1035 		.flags.bits.IS_HBR2_CAPABLE = true,
1036 		.flags.bits.IS_HBR3_CAPABLE = true,
1037 		.flags.bits.IS_TPS3_CAPABLE = true,
1038 		.flags.bits.IS_TPS4_CAPABLE = true
1039 };
1040 
1041 static struct link_encoder *dcn32_link_encoder_create(
1042 	struct dc_context *ctx,
1043 	const struct encoder_init_data *enc_init_data)
1044 {
1045 	struct dcn20_link_encoder *enc20 =
1046 		kzalloc(sizeof(struct dcn20_link_encoder), GFP_KERNEL);
1047 
1048 	if (!enc20)
1049 		return NULL;
1050 
1051 #undef REG_STRUCT
1052 #define REG_STRUCT link_enc_aux_regs
1053 	aux_regs_init(0),
1054 	aux_regs_init(1),
1055 	aux_regs_init(2),
1056 	aux_regs_init(3),
1057 	aux_regs_init(4);
1058 
1059 #undef REG_STRUCT
1060 #define REG_STRUCT link_enc_hpd_regs
1061 	hpd_regs_init(0),
1062 	hpd_regs_init(1),
1063 	hpd_regs_init(2),
1064 	hpd_regs_init(3),
1065 	hpd_regs_init(4);
1066 
1067 #undef REG_STRUCT
1068 #define REG_STRUCT link_enc_regs
1069 	link_regs_init(0, A),
1070 	link_regs_init(1, B),
1071 	link_regs_init(2, C),
1072 	link_regs_init(3, D),
1073 	link_regs_init(4, E);
1074 
1075 	dcn32_link_encoder_construct(enc20,
1076 			enc_init_data,
1077 			&link_enc_feature,
1078 			&link_enc_regs[enc_init_data->transmitter],
1079 			&link_enc_aux_regs[enc_init_data->channel - 1],
1080 			&link_enc_hpd_regs[enc_init_data->hpd_source],
1081 			&le_shift,
1082 			&le_mask);
1083 
1084 	return &enc20->enc10.base;
1085 }
1086 
1087 struct panel_cntl *dcn32_panel_cntl_create(const struct panel_cntl_init_data *init_data)
1088 {
1089 	struct dcn31_panel_cntl *panel_cntl =
1090 		kzalloc(sizeof(struct dcn31_panel_cntl), GFP_KERNEL);
1091 
1092 	if (!panel_cntl)
1093 		return NULL;
1094 
1095 	dcn31_panel_cntl_construct(panel_cntl, init_data);
1096 
1097 	return &panel_cntl->base;
1098 }
1099 
1100 static void read_dce_straps(
1101 	struct dc_context *ctx,
1102 	struct resource_straps *straps)
1103 {
1104 	generic_reg_get(ctx, ctx->dcn_reg_offsets[regDC_PINSTRAPS_BASE_IDX] + regDC_PINSTRAPS,
1105 		FN(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO), &straps->dc_pinstraps_audio);
1106 
1107 }
1108 
1109 static struct audio *dcn32_create_audio(
1110 		struct dc_context *ctx, unsigned int inst)
1111 {
1112 
1113 #undef REG_STRUCT
1114 #define REG_STRUCT audio_regs
1115 	audio_regs_init(0),
1116 	audio_regs_init(1),
1117 	audio_regs_init(2),
1118 	audio_regs_init(3),
1119 	audio_regs_init(4);
1120 
1121 	return dce_audio_create(ctx, inst,
1122 			&audio_regs[inst], &audio_shift, &audio_mask);
1123 }
1124 
1125 static struct vpg *dcn32_vpg_create(
1126 	struct dc_context *ctx,
1127 	uint32_t inst)
1128 {
1129 	struct dcn30_vpg *vpg3 = kzalloc(sizeof(struct dcn30_vpg), GFP_KERNEL);
1130 
1131 	if (!vpg3)
1132 		return NULL;
1133 
1134 #undef REG_STRUCT
1135 #define REG_STRUCT vpg_regs
1136 	vpg_regs_init(0),
1137 	vpg_regs_init(1),
1138 	vpg_regs_init(2),
1139 	vpg_regs_init(3),
1140 	vpg_regs_init(4),
1141 	vpg_regs_init(5),
1142 	vpg_regs_init(6),
1143 	vpg_regs_init(7),
1144 	vpg_regs_init(8),
1145 	vpg_regs_init(9);
1146 
1147 	vpg3_construct(vpg3, ctx, inst,
1148 			&vpg_regs[inst],
1149 			&vpg_shift,
1150 			&vpg_mask);
1151 
1152 	return &vpg3->base;
1153 }
1154 
1155 static struct afmt *dcn32_afmt_create(
1156 	struct dc_context *ctx,
1157 	uint32_t inst)
1158 {
1159 	struct dcn30_afmt *afmt3 = kzalloc(sizeof(struct dcn30_afmt), GFP_KERNEL);
1160 
1161 	if (!afmt3)
1162 		return NULL;
1163 
1164 #undef REG_STRUCT
1165 #define REG_STRUCT afmt_regs
1166 	afmt_regs_init(0),
1167 	afmt_regs_init(1),
1168 	afmt_regs_init(2),
1169 	afmt_regs_init(3),
1170 	afmt_regs_init(4),
1171 	afmt_regs_init(5);
1172 
1173 	afmt3_construct(afmt3, ctx, inst,
1174 			&afmt_regs[inst],
1175 			&afmt_shift,
1176 			&afmt_mask);
1177 
1178 	return &afmt3->base;
1179 }
1180 
1181 static struct apg *dcn31_apg_create(
1182 	struct dc_context *ctx,
1183 	uint32_t inst)
1184 {
1185 	struct dcn31_apg *apg31 = kzalloc(sizeof(struct dcn31_apg), GFP_KERNEL);
1186 
1187 	if (!apg31)
1188 		return NULL;
1189 
1190 #undef REG_STRUCT
1191 #define REG_STRUCT apg_regs
1192 	apg_regs_init(0),
1193 	apg_regs_init(1),
1194 	apg_regs_init(2),
1195 	apg_regs_init(3);
1196 
1197 	apg31_construct(apg31, ctx, inst,
1198 			&apg_regs[inst],
1199 			&apg_shift,
1200 			&apg_mask);
1201 
1202 	return &apg31->base;
1203 }
1204 
1205 static struct stream_encoder *dcn32_stream_encoder_create(
1206 	enum engine_id eng_id,
1207 	struct dc_context *ctx)
1208 {
1209 	struct dcn10_stream_encoder *enc1;
1210 	struct vpg *vpg;
1211 	struct afmt *afmt;
1212 	int vpg_inst;
1213 	int afmt_inst;
1214 
1215 	/* Mapping of VPG, AFMT, DME register blocks to DIO block instance */
1216 	if (eng_id <= ENGINE_ID_DIGF) {
1217 		vpg_inst = eng_id;
1218 		afmt_inst = eng_id;
1219 	} else
1220 		return NULL;
1221 
1222 	enc1 = kzalloc(sizeof(struct dcn10_stream_encoder), GFP_KERNEL);
1223 	vpg = dcn32_vpg_create(ctx, vpg_inst);
1224 	afmt = dcn32_afmt_create(ctx, afmt_inst);
1225 
1226 	if (!enc1 || !vpg || !afmt) {
1227 		kfree(enc1);
1228 		kfree(vpg);
1229 		kfree(afmt);
1230 		return NULL;
1231 	}
1232 
1233 #undef REG_STRUCT
1234 #define REG_STRUCT stream_enc_regs
1235 	stream_enc_regs_init(0),
1236 	stream_enc_regs_init(1),
1237 	stream_enc_regs_init(2),
1238 	stream_enc_regs_init(3),
1239 	stream_enc_regs_init(4);
1240 
1241 	dcn32_dio_stream_encoder_construct(enc1, ctx, ctx->dc_bios,
1242 					eng_id, vpg, afmt,
1243 					&stream_enc_regs[eng_id],
1244 					&se_shift, &se_mask);
1245 
1246 	return &enc1->base;
1247 }
1248 
1249 static struct hpo_dp_stream_encoder *dcn32_hpo_dp_stream_encoder_create(
1250 	enum engine_id eng_id,
1251 	struct dc_context *ctx)
1252 {
1253 	struct dcn31_hpo_dp_stream_encoder *hpo_dp_enc31;
1254 	struct vpg *vpg;
1255 	struct apg *apg;
1256 	uint32_t hpo_dp_inst;
1257 	uint32_t vpg_inst;
1258 	uint32_t apg_inst;
1259 
1260 	ASSERT((eng_id >= ENGINE_ID_HPO_DP_0) && (eng_id <= ENGINE_ID_HPO_DP_3));
1261 	hpo_dp_inst = eng_id - ENGINE_ID_HPO_DP_0;
1262 
1263 	/* Mapping of VPG register blocks to HPO DP block instance:
1264 	 * VPG[6] -> HPO_DP[0]
1265 	 * VPG[7] -> HPO_DP[1]
1266 	 * VPG[8] -> HPO_DP[2]
1267 	 * VPG[9] -> HPO_DP[3]
1268 	 */
1269 	vpg_inst = hpo_dp_inst + 6;
1270 
1271 	/* Mapping of APG register blocks to HPO DP block instance:
1272 	 * APG[0] -> HPO_DP[0]
1273 	 * APG[1] -> HPO_DP[1]
1274 	 * APG[2] -> HPO_DP[2]
1275 	 * APG[3] -> HPO_DP[3]
1276 	 */
1277 	apg_inst = hpo_dp_inst;
1278 
1279 	/* allocate HPO stream encoder and create VPG sub-block */
1280 	hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_stream_encoder), GFP_KERNEL);
1281 	vpg = dcn32_vpg_create(ctx, vpg_inst);
1282 	apg = dcn31_apg_create(ctx, apg_inst);
1283 
1284 	if (!hpo_dp_enc31 || !vpg || !apg) {
1285 		kfree(hpo_dp_enc31);
1286 		kfree(vpg);
1287 		kfree(apg);
1288 		return NULL;
1289 	}
1290 
1291 #undef REG_STRUCT
1292 #define REG_STRUCT hpo_dp_stream_enc_regs
1293 	hpo_dp_stream_encoder_reg_init(0),
1294 	hpo_dp_stream_encoder_reg_init(1),
1295 	hpo_dp_stream_encoder_reg_init(2),
1296 	hpo_dp_stream_encoder_reg_init(3);
1297 
1298 	dcn31_hpo_dp_stream_encoder_construct(hpo_dp_enc31, ctx, ctx->dc_bios,
1299 					hpo_dp_inst, eng_id, vpg, apg,
1300 					&hpo_dp_stream_enc_regs[hpo_dp_inst],
1301 					&hpo_dp_se_shift, &hpo_dp_se_mask);
1302 
1303 	return &hpo_dp_enc31->base;
1304 }
1305 
1306 static struct hpo_dp_link_encoder *dcn32_hpo_dp_link_encoder_create(
1307 	uint8_t inst,
1308 	struct dc_context *ctx)
1309 {
1310 	struct dcn31_hpo_dp_link_encoder *hpo_dp_enc31;
1311 
1312 	/* allocate HPO link encoder */
1313 	hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_link_encoder), GFP_KERNEL);
1314 
1315 #undef REG_STRUCT
1316 #define REG_STRUCT hpo_dp_link_enc_regs
1317 	hpo_dp_link_encoder_reg_init(0),
1318 	hpo_dp_link_encoder_reg_init(1);
1319 
1320 	hpo_dp_link_encoder32_construct(hpo_dp_enc31, ctx, inst,
1321 					&hpo_dp_link_enc_regs[inst],
1322 					&hpo_dp_le_shift, &hpo_dp_le_mask);
1323 
1324 	return &hpo_dp_enc31->base;
1325 }
1326 
1327 static struct dce_hwseq *dcn32_hwseq_create(
1328 	struct dc_context *ctx)
1329 {
1330 	struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL);
1331 
1332 #undef REG_STRUCT
1333 #define REG_STRUCT hwseq_reg
1334 	hwseq_reg_init();
1335 
1336 	if (hws) {
1337 		hws->ctx = ctx;
1338 		hws->regs = &hwseq_reg;
1339 		hws->shifts = &hwseq_shift;
1340 		hws->masks = &hwseq_mask;
1341 	}
1342 	return hws;
1343 }
1344 static const struct resource_create_funcs res_create_funcs = {
1345 	.read_dce_straps = read_dce_straps,
1346 	.create_audio = dcn32_create_audio,
1347 	.create_stream_encoder = dcn32_stream_encoder_create,
1348 	.create_hpo_dp_stream_encoder = dcn32_hpo_dp_stream_encoder_create,
1349 	.create_hpo_dp_link_encoder = dcn32_hpo_dp_link_encoder_create,
1350 	.create_hwseq = dcn32_hwseq_create,
1351 };
1352 
1353 static const struct resource_create_funcs res_create_maximus_funcs = {
1354 	.read_dce_straps = NULL,
1355 	.create_audio = NULL,
1356 	.create_stream_encoder = NULL,
1357 	.create_hpo_dp_stream_encoder = dcn32_hpo_dp_stream_encoder_create,
1358 	.create_hpo_dp_link_encoder = dcn32_hpo_dp_link_encoder_create,
1359 	.create_hwseq = dcn32_hwseq_create,
1360 };
1361 
1362 static void dcn32_resource_destruct(struct dcn32_resource_pool *pool)
1363 {
1364 	unsigned int i;
1365 
1366 	for (i = 0; i < pool->base.stream_enc_count; i++) {
1367 		if (pool->base.stream_enc[i] != NULL) {
1368 			if (pool->base.stream_enc[i]->vpg != NULL) {
1369 				kfree(DCN30_VPG_FROM_VPG(pool->base.stream_enc[i]->vpg));
1370 				pool->base.stream_enc[i]->vpg = NULL;
1371 			}
1372 			if (pool->base.stream_enc[i]->afmt != NULL) {
1373 				kfree(DCN30_AFMT_FROM_AFMT(pool->base.stream_enc[i]->afmt));
1374 				pool->base.stream_enc[i]->afmt = NULL;
1375 			}
1376 			kfree(DCN10STRENC_FROM_STRENC(pool->base.stream_enc[i]));
1377 			pool->base.stream_enc[i] = NULL;
1378 		}
1379 	}
1380 
1381 	for (i = 0; i < pool->base.hpo_dp_stream_enc_count; i++) {
1382 		if (pool->base.hpo_dp_stream_enc[i] != NULL) {
1383 			if (pool->base.hpo_dp_stream_enc[i]->vpg != NULL) {
1384 				kfree(DCN30_VPG_FROM_VPG(pool->base.hpo_dp_stream_enc[i]->vpg));
1385 				pool->base.hpo_dp_stream_enc[i]->vpg = NULL;
1386 			}
1387 			if (pool->base.hpo_dp_stream_enc[i]->apg != NULL) {
1388 				kfree(DCN31_APG_FROM_APG(pool->base.hpo_dp_stream_enc[i]->apg));
1389 				pool->base.hpo_dp_stream_enc[i]->apg = NULL;
1390 			}
1391 			kfree(DCN3_1_HPO_DP_STREAM_ENC_FROM_HPO_STREAM_ENC(pool->base.hpo_dp_stream_enc[i]));
1392 			pool->base.hpo_dp_stream_enc[i] = NULL;
1393 		}
1394 	}
1395 
1396 	for (i = 0; i < pool->base.hpo_dp_link_enc_count; i++) {
1397 		if (pool->base.hpo_dp_link_enc[i] != NULL) {
1398 			kfree(DCN3_1_HPO_DP_LINK_ENC_FROM_HPO_LINK_ENC(pool->base.hpo_dp_link_enc[i]));
1399 			pool->base.hpo_dp_link_enc[i] = NULL;
1400 		}
1401 	}
1402 
1403 	for (i = 0; i < pool->base.res_cap->num_dsc; i++) {
1404 		if (pool->base.dscs[i] != NULL)
1405 			dcn20_dsc_destroy(&pool->base.dscs[i]);
1406 	}
1407 
1408 	if (pool->base.mpc != NULL) {
1409 		kfree(TO_DCN20_MPC(pool->base.mpc));
1410 		pool->base.mpc = NULL;
1411 	}
1412 	if (pool->base.hubbub != NULL) {
1413 		kfree(TO_DCN20_HUBBUB(pool->base.hubbub));
1414 		pool->base.hubbub = NULL;
1415 	}
1416 	for (i = 0; i < pool->base.pipe_count; i++) {
1417 		if (pool->base.dpps[i] != NULL)
1418 			dcn32_dpp_destroy(&pool->base.dpps[i]);
1419 
1420 		if (pool->base.ipps[i] != NULL)
1421 			pool->base.ipps[i]->funcs->ipp_destroy(&pool->base.ipps[i]);
1422 
1423 		if (pool->base.hubps[i] != NULL) {
1424 			kfree(TO_DCN20_HUBP(pool->base.hubps[i]));
1425 			pool->base.hubps[i] = NULL;
1426 		}
1427 
1428 		if (pool->base.irqs != NULL) {
1429 			dal_irq_service_destroy(&pool->base.irqs);
1430 		}
1431 	}
1432 
1433 	for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
1434 		if (pool->base.engines[i] != NULL)
1435 			dce110_engine_destroy(&pool->base.engines[i]);
1436 		if (pool->base.hw_i2cs[i] != NULL) {
1437 			kfree(pool->base.hw_i2cs[i]);
1438 			pool->base.hw_i2cs[i] = NULL;
1439 		}
1440 		if (pool->base.sw_i2cs[i] != NULL) {
1441 			kfree(pool->base.sw_i2cs[i]);
1442 			pool->base.sw_i2cs[i] = NULL;
1443 		}
1444 	}
1445 
1446 	for (i = 0; i < pool->base.res_cap->num_opp; i++) {
1447 		if (pool->base.opps[i] != NULL)
1448 			pool->base.opps[i]->funcs->opp_destroy(&pool->base.opps[i]);
1449 	}
1450 
1451 	for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) {
1452 		if (pool->base.timing_generators[i] != NULL)	{
1453 			kfree(DCN10TG_FROM_TG(pool->base.timing_generators[i]));
1454 			pool->base.timing_generators[i] = NULL;
1455 		}
1456 	}
1457 
1458 	for (i = 0; i < pool->base.res_cap->num_dwb; i++) {
1459 		if (pool->base.dwbc[i] != NULL) {
1460 			kfree(TO_DCN30_DWBC(pool->base.dwbc[i]));
1461 			pool->base.dwbc[i] = NULL;
1462 		}
1463 		if (pool->base.mcif_wb[i] != NULL) {
1464 			kfree(TO_DCN30_MMHUBBUB(pool->base.mcif_wb[i]));
1465 			pool->base.mcif_wb[i] = NULL;
1466 		}
1467 	}
1468 
1469 	for (i = 0; i < pool->base.audio_count; i++) {
1470 		if (pool->base.audios[i])
1471 			dce_aud_destroy(&pool->base.audios[i]);
1472 	}
1473 
1474 	for (i = 0; i < pool->base.clk_src_count; i++) {
1475 		if (pool->base.clock_sources[i] != NULL) {
1476 			dcn20_clock_source_destroy(&pool->base.clock_sources[i]);
1477 			pool->base.clock_sources[i] = NULL;
1478 		}
1479 	}
1480 
1481 	for (i = 0; i < pool->base.res_cap->num_mpc_3dlut; i++) {
1482 		if (pool->base.mpc_lut[i] != NULL) {
1483 			dc_3dlut_func_release(pool->base.mpc_lut[i]);
1484 			pool->base.mpc_lut[i] = NULL;
1485 		}
1486 		if (pool->base.mpc_shaper[i] != NULL) {
1487 			dc_transfer_func_release(pool->base.mpc_shaper[i]);
1488 			pool->base.mpc_shaper[i] = NULL;
1489 		}
1490 	}
1491 
1492 	if (pool->base.dp_clock_source != NULL) {
1493 		dcn20_clock_source_destroy(&pool->base.dp_clock_source);
1494 		pool->base.dp_clock_source = NULL;
1495 	}
1496 
1497 	for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) {
1498 		if (pool->base.multiple_abms[i] != NULL)
1499 			dce_abm_destroy(&pool->base.multiple_abms[i]);
1500 	}
1501 
1502 	if (pool->base.psr != NULL)
1503 		dmub_psr_destroy(&pool->base.psr);
1504 
1505 	if (pool->base.dccg != NULL)
1506 		dcn_dccg_destroy(&pool->base.dccg);
1507 
1508 	if (pool->base.oem_device != NULL) {
1509 		struct dc *dc = pool->base.oem_device->ctx->dc;
1510 
1511 		dc->link_srv->destroy_ddc_service(&pool->base.oem_device);
1512 	}
1513 }
1514 
1515 
1516 static bool dcn32_dwbc_create(struct dc_context *ctx, struct resource_pool *pool)
1517 {
1518 	int i;
1519 	uint32_t dwb_count = pool->res_cap->num_dwb;
1520 
1521 	for (i = 0; i < dwb_count; i++) {
1522 		struct dcn30_dwbc *dwbc30 = kzalloc(sizeof(struct dcn30_dwbc),
1523 						    GFP_KERNEL);
1524 
1525 		if (!dwbc30) {
1526 			dm_error("DC: failed to create dwbc30!\n");
1527 			return false;
1528 		}
1529 
1530 #undef REG_STRUCT
1531 #define REG_STRUCT dwbc30_regs
1532 		dwbc_regs_dcn3_init(0);
1533 
1534 		dcn30_dwbc_construct(dwbc30, ctx,
1535 				&dwbc30_regs[i],
1536 				&dwbc30_shift,
1537 				&dwbc30_mask,
1538 				i);
1539 
1540 		pool->dwbc[i] = &dwbc30->base;
1541 	}
1542 	return true;
1543 }
1544 
1545 static bool dcn32_mmhubbub_create(struct dc_context *ctx, struct resource_pool *pool)
1546 {
1547 	int i;
1548 	uint32_t dwb_count = pool->res_cap->num_dwb;
1549 
1550 	for (i = 0; i < dwb_count; i++) {
1551 		struct dcn30_mmhubbub *mcif_wb30 = kzalloc(sizeof(struct dcn30_mmhubbub),
1552 						    GFP_KERNEL);
1553 
1554 		if (!mcif_wb30) {
1555 			dm_error("DC: failed to create mcif_wb30!\n");
1556 			return false;
1557 		}
1558 
1559 #undef REG_STRUCT
1560 #define REG_STRUCT mcif_wb30_regs
1561 		mcif_wb_regs_dcn3_init(0);
1562 
1563 		dcn32_mmhubbub_construct(mcif_wb30, ctx,
1564 				&mcif_wb30_regs[i],
1565 				&mcif_wb30_shift,
1566 				&mcif_wb30_mask,
1567 				i);
1568 
1569 		pool->mcif_wb[i] = &mcif_wb30->base;
1570 	}
1571 	return true;
1572 }
1573 
1574 static struct display_stream_compressor *dcn32_dsc_create(
1575 	struct dc_context *ctx, uint32_t inst)
1576 {
1577 	struct dcn20_dsc *dsc =
1578 		kzalloc(sizeof(struct dcn20_dsc), GFP_KERNEL);
1579 
1580 	if (!dsc) {
1581 		BREAK_TO_DEBUGGER();
1582 		return NULL;
1583 	}
1584 
1585 #undef REG_STRUCT
1586 #define REG_STRUCT dsc_regs
1587 	dsc_regsDCN20_init(0),
1588 	dsc_regsDCN20_init(1),
1589 	dsc_regsDCN20_init(2),
1590 	dsc_regsDCN20_init(3);
1591 
1592 	dsc2_construct(dsc, ctx, inst, &dsc_regs[inst], &dsc_shift, &dsc_mask);
1593 
1594 	dsc->max_image_width = 6016;
1595 
1596 	return &dsc->base;
1597 }
1598 
1599 static void dcn32_destroy_resource_pool(struct resource_pool **pool)
1600 {
1601 	struct dcn32_resource_pool *dcn32_pool = TO_DCN32_RES_POOL(*pool);
1602 
1603 	dcn32_resource_destruct(dcn32_pool);
1604 	kfree(dcn32_pool);
1605 	*pool = NULL;
1606 }
1607 
1608 bool dcn32_acquire_post_bldn_3dlut(
1609 		struct resource_context *res_ctx,
1610 		const struct resource_pool *pool,
1611 		int mpcc_id,
1612 		struct dc_3dlut **lut,
1613 		struct dc_transfer_func **shaper)
1614 {
1615 	bool ret = false;
1616 
1617 	ASSERT(*lut == NULL && *shaper == NULL);
1618 	*lut = NULL;
1619 	*shaper = NULL;
1620 
1621 	if (!res_ctx->is_mpc_3dlut_acquired[mpcc_id]) {
1622 		*lut = pool->mpc_lut[mpcc_id];
1623 		*shaper = pool->mpc_shaper[mpcc_id];
1624 		res_ctx->is_mpc_3dlut_acquired[mpcc_id] = true;
1625 		ret = true;
1626 	}
1627 	return ret;
1628 }
1629 
1630 bool dcn32_release_post_bldn_3dlut(
1631 		struct resource_context *res_ctx,
1632 		const struct resource_pool *pool,
1633 		struct dc_3dlut **lut,
1634 		struct dc_transfer_func **shaper)
1635 {
1636 	int i;
1637 	bool ret = false;
1638 
1639 	for (i = 0; i < pool->res_cap->num_mpc_3dlut; i++) {
1640 		if (pool->mpc_lut[i] == *lut && pool->mpc_shaper[i] == *shaper) {
1641 			res_ctx->is_mpc_3dlut_acquired[i] = false;
1642 			pool->mpc_lut[i]->state.raw = 0;
1643 			*lut = NULL;
1644 			*shaper = NULL;
1645 			ret = true;
1646 			break;
1647 		}
1648 	}
1649 	return ret;
1650 }
1651 
1652 static void dcn32_enable_phantom_plane(struct dc *dc,
1653 		struct dc_state *context,
1654 		struct dc_stream_state *phantom_stream,
1655 		unsigned int dc_pipe_idx)
1656 {
1657 	struct dc_plane_state *phantom_plane = NULL;
1658 	struct dc_plane_state *prev_phantom_plane = NULL;
1659 	struct pipe_ctx *curr_pipe = &context->res_ctx.pipe_ctx[dc_pipe_idx];
1660 
1661 	while (curr_pipe) {
1662 		if (curr_pipe->top_pipe && curr_pipe->top_pipe->plane_state == curr_pipe->plane_state)
1663 			phantom_plane = prev_phantom_plane;
1664 		else
1665 			phantom_plane = dc_create_plane_state(dc);
1666 
1667 		memcpy(&phantom_plane->address, &curr_pipe->plane_state->address, sizeof(phantom_plane->address));
1668 		memcpy(&phantom_plane->scaling_quality, &curr_pipe->plane_state->scaling_quality,
1669 				sizeof(phantom_plane->scaling_quality));
1670 		memcpy(&phantom_plane->src_rect, &curr_pipe->plane_state->src_rect, sizeof(phantom_plane->src_rect));
1671 		memcpy(&phantom_plane->dst_rect, &curr_pipe->plane_state->dst_rect, sizeof(phantom_plane->dst_rect));
1672 		memcpy(&phantom_plane->clip_rect, &curr_pipe->plane_state->clip_rect, sizeof(phantom_plane->clip_rect));
1673 		memcpy(&phantom_plane->plane_size, &curr_pipe->plane_state->plane_size,
1674 				sizeof(phantom_plane->plane_size));
1675 		memcpy(&phantom_plane->tiling_info, &curr_pipe->plane_state->tiling_info,
1676 				sizeof(phantom_plane->tiling_info));
1677 		memcpy(&phantom_plane->dcc, &curr_pipe->plane_state->dcc, sizeof(phantom_plane->dcc));
1678 		phantom_plane->format = curr_pipe->plane_state->format;
1679 		phantom_plane->rotation = curr_pipe->plane_state->rotation;
1680 		phantom_plane->visible = curr_pipe->plane_state->visible;
1681 
1682 		/* Shadow pipe has small viewport. */
1683 		phantom_plane->clip_rect.y = 0;
1684 		phantom_plane->clip_rect.height = phantom_stream->src.height;
1685 
1686 		phantom_plane->is_phantom = true;
1687 
1688 		dc_add_plane_to_context(dc, phantom_stream, phantom_plane, context);
1689 
1690 		curr_pipe = curr_pipe->bottom_pipe;
1691 		prev_phantom_plane = phantom_plane;
1692 	}
1693 }
1694 
1695 static struct dc_stream_state *dcn32_enable_phantom_stream(struct dc *dc,
1696 		struct dc_state *context,
1697 		display_e2e_pipe_params_st *pipes,
1698 		unsigned int pipe_cnt,
1699 		unsigned int dc_pipe_idx)
1700 {
1701 	struct dc_stream_state *phantom_stream = NULL;
1702 	struct pipe_ctx *ref_pipe = &context->res_ctx.pipe_ctx[dc_pipe_idx];
1703 
1704 	phantom_stream = dc_create_stream_for_sink(ref_pipe->stream->sink);
1705 	phantom_stream->signal = SIGNAL_TYPE_VIRTUAL;
1706 	phantom_stream->dpms_off = true;
1707 	phantom_stream->mall_stream_config.type = SUBVP_PHANTOM;
1708 	phantom_stream->mall_stream_config.paired_stream = ref_pipe->stream;
1709 	ref_pipe->stream->mall_stream_config.type = SUBVP_MAIN;
1710 	ref_pipe->stream->mall_stream_config.paired_stream = phantom_stream;
1711 
1712 	/* stream has limited viewport and small timing */
1713 	memcpy(&phantom_stream->timing, &ref_pipe->stream->timing, sizeof(phantom_stream->timing));
1714 	memcpy(&phantom_stream->src, &ref_pipe->stream->src, sizeof(phantom_stream->src));
1715 	memcpy(&phantom_stream->dst, &ref_pipe->stream->dst, sizeof(phantom_stream->dst));
1716 	DC_FP_START();
1717 	dcn32_set_phantom_stream_timing(dc, context, ref_pipe, phantom_stream, pipes, pipe_cnt, dc_pipe_idx);
1718 	DC_FP_END();
1719 
1720 	dc_add_stream_to_ctx(dc, context, phantom_stream);
1721 	return phantom_stream;
1722 }
1723 
1724 void dcn32_retain_phantom_pipes(struct dc *dc, struct dc_state *context)
1725 {
1726 	int i;
1727 	struct dc_plane_state *phantom_plane = NULL;
1728 	struct dc_stream_state *phantom_stream = NULL;
1729 
1730 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
1731 		struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1732 
1733 		if (!pipe->top_pipe && !pipe->prev_odm_pipe &&
1734 				pipe->plane_state && pipe->stream &&
1735 				pipe->stream->mall_stream_config.type == SUBVP_PHANTOM) {
1736 			phantom_plane = pipe->plane_state;
1737 			phantom_stream = pipe->stream;
1738 
1739 			dc_plane_state_retain(phantom_plane);
1740 			dc_stream_retain(phantom_stream);
1741 		}
1742 	}
1743 }
1744 
1745 // return true if removed piped from ctx, false otherwise
1746 bool dcn32_remove_phantom_pipes(struct dc *dc, struct dc_state *context, bool fast_update)
1747 {
1748 	int i;
1749 	bool removed_pipe = false;
1750 	struct dc_plane_state *phantom_plane = NULL;
1751 	struct dc_stream_state *phantom_stream = NULL;
1752 
1753 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
1754 		struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1755 		// build scaling params for phantom pipes
1756 		if (pipe->plane_state && pipe->stream && pipe->stream->mall_stream_config.type == SUBVP_PHANTOM) {
1757 			phantom_plane = pipe->plane_state;
1758 			phantom_stream = pipe->stream;
1759 
1760 			dc_rem_all_planes_for_stream(dc, pipe->stream, context);
1761 			dc_remove_stream_from_ctx(dc, context, pipe->stream);
1762 
1763 			/* Ref count is incremented on allocation and also when added to the context.
1764 			 * Therefore we must call release for the the phantom plane and stream once
1765 			 * they are removed from the ctx to finally decrement the refcount to 0 to free.
1766 			 */
1767 			dc_plane_state_release(phantom_plane);
1768 			dc_stream_release(phantom_stream);
1769 
1770 			removed_pipe = true;
1771 		}
1772 
1773 		/* For non-full updates, a shallow copy of the current state
1774 		 * is created. In this case we don't want to erase the current
1775 		 * state (there can be 2 HIRQL threads, one in flip, and one in
1776 		 * checkMPO) that can cause a race condition.
1777 		 *
1778 		 * This is just a workaround, needs a proper fix.
1779 		 */
1780 		if (!fast_update) {
1781 			// Clear all phantom stream info
1782 			if (pipe->stream) {
1783 				pipe->stream->mall_stream_config.type = SUBVP_NONE;
1784 				pipe->stream->mall_stream_config.paired_stream = NULL;
1785 			}
1786 
1787 			if (pipe->plane_state) {
1788 				pipe->plane_state->is_phantom = false;
1789 			}
1790 		}
1791 	}
1792 	return removed_pipe;
1793 }
1794 
1795 /* TODO: Input to this function should indicate which pipe indexes (or streams)
1796  * require a phantom pipe / stream
1797  */
1798 void dcn32_add_phantom_pipes(struct dc *dc, struct dc_state *context,
1799 		display_e2e_pipe_params_st *pipes,
1800 		unsigned int pipe_cnt,
1801 		unsigned int index)
1802 {
1803 	struct dc_stream_state *phantom_stream = NULL;
1804 	unsigned int i;
1805 
1806 	// The index of the DC pipe passed into this function is guarenteed to
1807 	// be a valid candidate for SubVP (i.e. has a plane, stream, doesn't
1808 	// already have phantom pipe assigned, etc.) by previous checks.
1809 	phantom_stream = dcn32_enable_phantom_stream(dc, context, pipes, pipe_cnt, index);
1810 	dcn32_enable_phantom_plane(dc, context, phantom_stream, index);
1811 
1812 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
1813 		struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1814 
1815 		// Build scaling params for phantom pipes which were newly added.
1816 		// We determine which phantom pipes were added by comparing with
1817 		// the phantom stream.
1818 		if (pipe->plane_state && pipe->stream && pipe->stream == phantom_stream &&
1819 				pipe->stream->mall_stream_config.type == SUBVP_PHANTOM) {
1820 			pipe->stream->use_dynamic_meta = false;
1821 			pipe->plane_state->flip_immediate = false;
1822 			if (!resource_build_scaling_params(pipe)) {
1823 				// Log / remove phantom pipes since failed to build scaling params
1824 			}
1825 		}
1826 	}
1827 }
1828 
1829 bool dcn32_validate_bandwidth(struct dc *dc,
1830 		struct dc_state *context,
1831 		bool fast_validate)
1832 {
1833 	bool out = false;
1834 
1835 	BW_VAL_TRACE_SETUP();
1836 
1837 	int vlevel = 0;
1838 	int pipe_cnt = 0;
1839 	display_e2e_pipe_params_st *pipes = kzalloc(dc->res_pool->pipe_count * sizeof(display_e2e_pipe_params_st), GFP_KERNEL);
1840 	struct mall_temp_config mall_temp_config;
1841 
1842 	/* To handle Freesync properly, setting FreeSync DML parameters
1843 	 * to its default state for the first stage of validation
1844 	 */
1845 	context->bw_ctx.bw.dcn.clk.fw_based_mclk_switching = false;
1846 	context->bw_ctx.dml.soc.dram_clock_change_requirement_final = true;
1847 
1848 	DC_LOGGER_INIT(dc->ctx->logger);
1849 
1850 	/* For fast validation, there are situations where a shallow copy of
1851 	 * of the dc->current_state is created for the validation. In this case
1852 	 * we want to save and restore the mall config because we always
1853 	 * teardown subvp at the beginning of validation (and don't attempt
1854 	 * to add it back if it's fast validation). If we don't restore the
1855 	 * subvp config in cases of fast validation + shallow copy of the
1856 	 * dc->current_state, the dc->current_state will have a partially
1857 	 * removed subvp state when we did not intend to remove it.
1858 	 */
1859 	if (fast_validate) {
1860 		memset(&mall_temp_config, 0, sizeof(mall_temp_config));
1861 		dcn32_save_mall_state(dc, context, &mall_temp_config);
1862 	}
1863 
1864 	BW_VAL_TRACE_COUNT();
1865 
1866 	DC_FP_START();
1867 	out = dcn32_internal_validate_bw(dc, context, pipes, &pipe_cnt, &vlevel, fast_validate);
1868 	DC_FP_END();
1869 
1870 	if (fast_validate)
1871 		dcn32_restore_mall_state(dc, context, &mall_temp_config);
1872 
1873 	if (pipe_cnt == 0)
1874 		goto validate_out;
1875 
1876 	if (!out)
1877 		goto validate_fail;
1878 
1879 	BW_VAL_TRACE_END_VOLTAGE_LEVEL();
1880 
1881 	if (fast_validate) {
1882 		BW_VAL_TRACE_SKIP(fast);
1883 		goto validate_out;
1884 	}
1885 
1886 	dc->res_pool->funcs->calculate_wm_and_dlg(dc, context, pipes, pipe_cnt, vlevel);
1887 
1888 	BW_VAL_TRACE_END_WATERMARKS();
1889 
1890 	goto validate_out;
1891 
1892 validate_fail:
1893 	DC_LOG_WARNING("Mode Validation Warning: %s failed validation.\n",
1894 		dml_get_status_message(context->bw_ctx.dml.vba.ValidationStatus[context->bw_ctx.dml.vba.soc.num_states]));
1895 
1896 	BW_VAL_TRACE_SKIP(fail);
1897 	out = false;
1898 
1899 validate_out:
1900 	kfree(pipes);
1901 
1902 	BW_VAL_TRACE_FINISH();
1903 
1904 	return out;
1905 }
1906 
1907 int dcn32_populate_dml_pipes_from_context(
1908 	struct dc *dc, struct dc_state *context,
1909 	display_e2e_pipe_params_st *pipes,
1910 	bool fast_validate)
1911 {
1912 	int i, pipe_cnt;
1913 	struct resource_context *res_ctx = &context->res_ctx;
1914 	struct pipe_ctx *pipe;
1915 	bool subvp_in_use = false;
1916 	struct dc_crtc_timing *timing;
1917 	bool vsr_odm_support = false;
1918 
1919 	dcn20_populate_dml_pipes_from_context(dc, context, pipes, fast_validate);
1920 
1921 	/* Determine whether we will apply ODM 2to1 policy:
1922 	 * Applies to single display and where the number of planes is less than 3.
1923 	 * For 3 plane case ( 2 MPO planes ), we will not set the policy for the MPO pipes.
1924 	 *
1925 	 * Apply pipe split policy first so we can predict the pipe split correctly
1926 	 * (dcn32_predict_pipe_split).
1927 	 */
1928 	for (i = 0, pipe_cnt = 0; i < dc->res_pool->pipe_count; i++) {
1929 		if (!res_ctx->pipe_ctx[i].stream)
1930 			continue;
1931 		pipe = &res_ctx->pipe_ctx[i];
1932 		timing = &pipe->stream->timing;
1933 
1934 		pipes[pipe_cnt].pipe.dest.odm_combine_policy = dm_odm_combine_policy_dal;
1935 		vsr_odm_support = (res_ctx->pipe_ctx[i].stream->src.width >= 5120 &&
1936 				res_ctx->pipe_ctx[i].stream->src.width > res_ctx->pipe_ctx[i].stream->dst.width);
1937 		if (context->stream_count == 1 &&
1938 				context->stream_status[0].plane_count == 1 &&
1939 				!dc_is_hdmi_signal(res_ctx->pipe_ctx[i].stream->signal) &&
1940 				is_h_timing_divisible_by_2(res_ctx->pipe_ctx[i].stream) &&
1941 				pipe->stream->timing.pix_clk_100hz * 100 > DCN3_2_VMIN_DISPCLK_HZ &&
1942 				dc->debug.enable_single_display_2to1_odm_policy &&
1943 				!vsr_odm_support) { //excluding 2to1 ODM combine on >= 5k vsr
1944 			pipes[pipe_cnt].pipe.dest.odm_combine_policy = dm_odm_combine_policy_2to1;
1945 		}
1946 		pipe_cnt++;
1947 	}
1948 
1949 	for (i = 0, pipe_cnt = 0; i < dc->res_pool->pipe_count; i++) {
1950 
1951 		if (!res_ctx->pipe_ctx[i].stream)
1952 			continue;
1953 		pipe = &res_ctx->pipe_ctx[i];
1954 		timing = &pipe->stream->timing;
1955 
1956 		pipes[pipe_cnt].pipe.src.gpuvm = true;
1957 		DC_FP_START();
1958 		dcn32_zero_pipe_dcc_fraction(pipes, pipe_cnt);
1959 		DC_FP_END();
1960 		pipes[pipe_cnt].pipe.dest.vfront_porch = timing->v_front_porch;
1961 		pipes[pipe_cnt].pipe.src.gpuvm_min_page_size_kbytes = 256; // according to spreadsheet
1962 		pipes[pipe_cnt].pipe.src.unbounded_req_mode = false;
1963 		pipes[pipe_cnt].pipe.scale_ratio_depth.lb_depth = dm_lb_19;
1964 
1965 		/* Only populate DML input with subvp info for full updates.
1966 		 * This is just a workaround -- needs a proper fix.
1967 		 */
1968 		if (!fast_validate) {
1969 			switch (pipe->stream->mall_stream_config.type) {
1970 			case SUBVP_MAIN:
1971 				pipes[pipe_cnt].pipe.src.use_mall_for_pstate_change = dm_use_mall_pstate_change_sub_viewport;
1972 				subvp_in_use = true;
1973 				break;
1974 			case SUBVP_PHANTOM:
1975 				pipes[pipe_cnt].pipe.src.use_mall_for_pstate_change = dm_use_mall_pstate_change_phantom_pipe;
1976 				pipes[pipe_cnt].pipe.src.use_mall_for_static_screen = dm_use_mall_static_screen_disable;
1977 				// Disallow unbounded req for SubVP according to DCHUB programming guide
1978 				pipes[pipe_cnt].pipe.src.unbounded_req_mode = false;
1979 				break;
1980 			case SUBVP_NONE:
1981 				pipes[pipe_cnt].pipe.src.use_mall_for_pstate_change = dm_use_mall_pstate_change_disable;
1982 				pipes[pipe_cnt].pipe.src.use_mall_for_static_screen = dm_use_mall_static_screen_disable;
1983 				break;
1984 			default:
1985 				break;
1986 			}
1987 		}
1988 
1989 		pipes[pipe_cnt].dout.dsc_input_bpc = 0;
1990 		if (pipes[pipe_cnt].dout.dsc_enable) {
1991 			switch (timing->display_color_depth) {
1992 			case COLOR_DEPTH_888:
1993 				pipes[pipe_cnt].dout.dsc_input_bpc = 8;
1994 				break;
1995 			case COLOR_DEPTH_101010:
1996 				pipes[pipe_cnt].dout.dsc_input_bpc = 10;
1997 				break;
1998 			case COLOR_DEPTH_121212:
1999 				pipes[pipe_cnt].dout.dsc_input_bpc = 12;
2000 				break;
2001 			default:
2002 				ASSERT(0);
2003 				break;
2004 			}
2005 		}
2006 
2007 		DC_FP_START();
2008 		dcn32_predict_pipe_split(context, &pipes[pipe_cnt]);
2009 		DC_FP_END();
2010 
2011 		pipe_cnt++;
2012 	}
2013 
2014 	/* For DET allocation, we don't want to use DML policy (not optimal for utilizing all
2015 	 * the DET available for each pipe). Use the DET override input to maintain our driver
2016 	 * policy.
2017 	 */
2018 	dcn32_set_det_allocations(dc, context, pipes);
2019 
2020 	// In general cases we want to keep the dram clock change requirement
2021 	// (prefer configs that support MCLK switch). Only override to false
2022 	// for SubVP
2023 	if (subvp_in_use)
2024 		context->bw_ctx.dml.soc.dram_clock_change_requirement_final = false;
2025 	else
2026 		context->bw_ctx.dml.soc.dram_clock_change_requirement_final = true;
2027 
2028 	return pipe_cnt;
2029 }
2030 
2031 static struct dc_cap_funcs cap_funcs = {
2032 	.get_dcc_compression_cap = dcn20_get_dcc_compression_cap
2033 };
2034 
2035 void dcn32_calculate_wm_and_dlg(struct dc *dc, struct dc_state *context,
2036 				display_e2e_pipe_params_st *pipes,
2037 				int pipe_cnt,
2038 				int vlevel)
2039 {
2040     DC_FP_START();
2041     dcn32_calculate_wm_and_dlg_fpu(dc, context, pipes, pipe_cnt, vlevel);
2042     DC_FP_END();
2043 }
2044 
2045 static void dcn32_update_bw_bounding_box(struct dc *dc, struct clk_bw_params *bw_params)
2046 {
2047 	DC_FP_START();
2048 	dcn32_update_bw_bounding_box_fpu(dc, bw_params);
2049 	DC_FP_END();
2050 }
2051 
2052 static struct resource_funcs dcn32_res_pool_funcs = {
2053 	.destroy = dcn32_destroy_resource_pool,
2054 	.link_enc_create = dcn32_link_encoder_create,
2055 	.link_enc_create_minimal = NULL,
2056 	.panel_cntl_create = dcn32_panel_cntl_create,
2057 	.validate_bandwidth = dcn32_validate_bandwidth,
2058 	.calculate_wm_and_dlg = dcn32_calculate_wm_and_dlg,
2059 	.populate_dml_pipes = dcn32_populate_dml_pipes_from_context,
2060 	.acquire_idle_pipe_for_head_pipe_in_layer = dcn32_acquire_idle_pipe_for_head_pipe_in_layer,
2061 	.add_stream_to_ctx = dcn30_add_stream_to_ctx,
2062 	.add_dsc_to_stream_resource = dcn20_add_dsc_to_stream_resource,
2063 	.remove_stream_from_ctx = dcn20_remove_stream_from_ctx,
2064 	.populate_dml_writeback_from_context = dcn30_populate_dml_writeback_from_context,
2065 	.set_mcif_arb_params = dcn30_set_mcif_arb_params,
2066 	.find_first_free_match_stream_enc_for_link = dcn10_find_first_free_match_stream_enc_for_link,
2067 	.acquire_post_bldn_3dlut = dcn32_acquire_post_bldn_3dlut,
2068 	.release_post_bldn_3dlut = dcn32_release_post_bldn_3dlut,
2069 	.update_bw_bounding_box = dcn32_update_bw_bounding_box,
2070 	.patch_unknown_plane_state = dcn20_patch_unknown_plane_state,
2071 	.update_soc_for_wm_a = dcn30_update_soc_for_wm_a,
2072 	.add_phantom_pipes = dcn32_add_phantom_pipes,
2073 	.remove_phantom_pipes = dcn32_remove_phantom_pipes,
2074 	.retain_phantom_pipes = dcn32_retain_phantom_pipes,
2075 	.save_mall_state = dcn32_save_mall_state,
2076 	.restore_mall_state = dcn32_restore_mall_state,
2077 };
2078 
2079 
2080 static bool dcn32_resource_construct(
2081 	uint8_t num_virtual_links,
2082 	struct dc *dc,
2083 	struct dcn32_resource_pool *pool)
2084 {
2085 	int i, j;
2086 	struct dc_context *ctx = dc->ctx;
2087 	struct irq_service_init_data init_data;
2088 	struct ddc_service_init_data ddc_init_data = {0};
2089 	uint32_t pipe_fuses = 0;
2090 	uint32_t num_pipes  = 4;
2091 
2092 	#undef REG_STRUCT
2093 	#define REG_STRUCT bios_regs
2094 		bios_regs_init();
2095 
2096 	#undef REG_STRUCT
2097 	#define REG_STRUCT clk_src_regs
2098 		clk_src_regs_init(0, A),
2099 		clk_src_regs_init(1, B),
2100 		clk_src_regs_init(2, C),
2101 		clk_src_regs_init(3, D),
2102 		clk_src_regs_init(4, E);
2103 	#undef REG_STRUCT
2104 	#define REG_STRUCT abm_regs
2105 		abm_regs_init(0),
2106 		abm_regs_init(1),
2107 		abm_regs_init(2),
2108 		abm_regs_init(3);
2109 
2110 	#undef REG_STRUCT
2111 	#define REG_STRUCT dccg_regs
2112 		dccg_regs_init();
2113 
2114 	DC_FP_START();
2115 
2116 	ctx->dc_bios->regs = &bios_regs;
2117 
2118 	pool->base.res_cap = &res_cap_dcn32;
2119 	/* max number of pipes for ASIC before checking for pipe fuses */
2120 	num_pipes  = pool->base.res_cap->num_timing_generator;
2121 	pipe_fuses = REG_READ(CC_DC_PIPE_DIS);
2122 
2123 	for (i = 0; i < pool->base.res_cap->num_timing_generator; i++)
2124 		if (pipe_fuses & 1 << i)
2125 			num_pipes--;
2126 
2127 	if (pipe_fuses & 1)
2128 		ASSERT(0); //Unexpected - Pipe 0 should always be fully functional!
2129 
2130 	if (pipe_fuses & CC_DC_PIPE_DIS__DC_FULL_DIS_MASK)
2131 		ASSERT(0); //Entire DCN is harvested!
2132 
2133 	/* within dml lib, initial value is hard coded, if ASIC pipe is fused, the
2134 	 * value will be changed, update max_num_dpp and max_num_otg for dml.
2135 	 */
2136 	dcn3_2_ip.max_num_dpp = num_pipes;
2137 	dcn3_2_ip.max_num_otg = num_pipes;
2138 
2139 	pool->base.funcs = &dcn32_res_pool_funcs;
2140 
2141 	/*************************************************
2142 	 *  Resource + asic cap harcoding                *
2143 	 *************************************************/
2144 	pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
2145 	pool->base.timing_generator_count = num_pipes;
2146 	pool->base.pipe_count = num_pipes;
2147 	pool->base.mpcc_count = num_pipes;
2148 	dc->caps.max_downscale_ratio = 600;
2149 	dc->caps.i2c_speed_in_khz = 100;
2150 	dc->caps.i2c_speed_in_khz_hdcp = 100; /*1.4 w/a applied by default*/
2151 	/* TODO: Bring max_cursor_size back to 256 after subvp cursor corruption is fixed*/
2152 	dc->caps.max_cursor_size = 64;
2153 	dc->caps.min_horizontal_blanking_period = 80;
2154 	dc->caps.dmdata_alloc_size = 2048;
2155 	dc->caps.mall_size_per_mem_channel = 4;
2156 	dc->caps.mall_size_total = 0;
2157 	dc->caps.cursor_cache_size = dc->caps.max_cursor_size * dc->caps.max_cursor_size * 8;
2158 
2159 	dc->caps.cache_line_size = 64;
2160 	dc->caps.cache_num_ways = 16;
2161 
2162 	/* Calculate the available MALL space */
2163 	dc->caps.max_cab_allocation_bytes = dcn32_calc_num_avail_chans_for_mall(
2164 		dc, dc->ctx->dc_bios->vram_info.num_chans) *
2165 		dc->caps.mall_size_per_mem_channel * 1024 * 1024;
2166 	dc->caps.mall_size_total = dc->caps.max_cab_allocation_bytes;
2167 
2168 	dc->caps.subvp_fw_processing_delay_us = 15;
2169 	dc->caps.subvp_drr_max_vblank_margin_us = 40;
2170 	dc->caps.subvp_prefetch_end_to_mall_start_us = 15;
2171 	dc->caps.subvp_swath_height_margin_lines = 16;
2172 	dc->caps.subvp_pstate_allow_width_us = 20;
2173 	dc->caps.subvp_vertical_int_margin_us = 30;
2174 	dc->caps.subvp_drr_vblank_start_margin_us = 100; // 100us margin
2175 
2176 	dc->caps.max_slave_planes = 2;
2177 	dc->caps.max_slave_yuv_planes = 2;
2178 	dc->caps.max_slave_rgb_planes = 2;
2179 	dc->caps.post_blend_color_processing = true;
2180 	dc->caps.force_dp_tps4_for_cp2520 = true;
2181 	if (dc->config.forceHBR2CP2520)
2182 		dc->caps.force_dp_tps4_for_cp2520 = false;
2183 	dc->caps.dp_hpo = true;
2184 	dc->caps.dp_hdmi21_pcon_support = true;
2185 	dc->caps.edp_dsc_support = true;
2186 	dc->caps.extended_aux_timeout_support = true;
2187 	dc->caps.dmcub_support = true;
2188 	dc->caps.seamless_odm = true;
2189 
2190 	/* Color pipeline capabilities */
2191 	dc->caps.color.dpp.dcn_arch = 1;
2192 	dc->caps.color.dpp.input_lut_shared = 0;
2193 	dc->caps.color.dpp.icsc = 1;
2194 	dc->caps.color.dpp.dgam_ram = 0; // must use gamma_corr
2195 	dc->caps.color.dpp.dgam_rom_caps.srgb = 1;
2196 	dc->caps.color.dpp.dgam_rom_caps.bt2020 = 1;
2197 	dc->caps.color.dpp.dgam_rom_caps.gamma2_2 = 1;
2198 	dc->caps.color.dpp.dgam_rom_caps.pq = 1;
2199 	dc->caps.color.dpp.dgam_rom_caps.hlg = 1;
2200 	dc->caps.color.dpp.post_csc = 1;
2201 	dc->caps.color.dpp.gamma_corr = 1;
2202 	dc->caps.color.dpp.dgam_rom_for_yuv = 0;
2203 
2204 	dc->caps.color.dpp.hw_3d_lut = 1;
2205 	dc->caps.color.dpp.ogam_ram = 0;  // no OGAM in DPP since DCN1
2206 	// no OGAM ROM on DCN2 and later ASICs
2207 	dc->caps.color.dpp.ogam_rom_caps.srgb = 0;
2208 	dc->caps.color.dpp.ogam_rom_caps.bt2020 = 0;
2209 	dc->caps.color.dpp.ogam_rom_caps.gamma2_2 = 0;
2210 	dc->caps.color.dpp.ogam_rom_caps.pq = 0;
2211 	dc->caps.color.dpp.ogam_rom_caps.hlg = 0;
2212 	dc->caps.color.dpp.ocsc = 0;
2213 
2214 	dc->caps.color.mpc.gamut_remap = 1;
2215 	dc->caps.color.mpc.num_3dluts = pool->base.res_cap->num_mpc_3dlut; //4, configurable to be before or after BLND in MPCC
2216 	dc->caps.color.mpc.ogam_ram = 1;
2217 	dc->caps.color.mpc.ogam_rom_caps.srgb = 0;
2218 	dc->caps.color.mpc.ogam_rom_caps.bt2020 = 0;
2219 	dc->caps.color.mpc.ogam_rom_caps.gamma2_2 = 0;
2220 	dc->caps.color.mpc.ogam_rom_caps.pq = 0;
2221 	dc->caps.color.mpc.ogam_rom_caps.hlg = 0;
2222 	dc->caps.color.mpc.ocsc = 1;
2223 
2224 	/* Use pipe context based otg sync logic */
2225 	dc->config.use_pipe_ctx_sync_logic = true;
2226 
2227 	/* read VBIOS LTTPR caps */
2228 	{
2229 		if (ctx->dc_bios->funcs->get_lttpr_caps) {
2230 			enum bp_result bp_query_result;
2231 			uint8_t is_vbios_lttpr_enable = 0;
2232 
2233 			bp_query_result = ctx->dc_bios->funcs->get_lttpr_caps(ctx->dc_bios, &is_vbios_lttpr_enable);
2234 			dc->caps.vbios_lttpr_enable = (bp_query_result == BP_RESULT_OK) && !!is_vbios_lttpr_enable;
2235 		}
2236 
2237 		/* interop bit is implicit */
2238 		{
2239 			dc->caps.vbios_lttpr_aware = true;
2240 		}
2241 	}
2242 
2243 	if (dc->ctx->dce_environment == DCE_ENV_PRODUCTION_DRV)
2244 		dc->debug = debug_defaults_drv;
2245 	else if (dc->ctx->dce_environment == DCE_ENV_FPGA_MAXIMUS) {
2246 		dc->debug = debug_defaults_diags;
2247 	} else
2248 		dc->debug = debug_defaults_diags;
2249 	// Init the vm_helper
2250 	if (dc->vm_helper)
2251 		vm_helper_init(dc->vm_helper, 16);
2252 
2253 	/*************************************************
2254 	 *  Create resources                             *
2255 	 *************************************************/
2256 
2257 	/* Clock Sources for Pixel Clock*/
2258 	pool->base.clock_sources[DCN32_CLK_SRC_PLL0] =
2259 			dcn32_clock_source_create(ctx, ctx->dc_bios,
2260 				CLOCK_SOURCE_COMBO_PHY_PLL0,
2261 				&clk_src_regs[0], false);
2262 	pool->base.clock_sources[DCN32_CLK_SRC_PLL1] =
2263 			dcn32_clock_source_create(ctx, ctx->dc_bios,
2264 				CLOCK_SOURCE_COMBO_PHY_PLL1,
2265 				&clk_src_regs[1], false);
2266 	pool->base.clock_sources[DCN32_CLK_SRC_PLL2] =
2267 			dcn32_clock_source_create(ctx, ctx->dc_bios,
2268 				CLOCK_SOURCE_COMBO_PHY_PLL2,
2269 				&clk_src_regs[2], false);
2270 	pool->base.clock_sources[DCN32_CLK_SRC_PLL3] =
2271 			dcn32_clock_source_create(ctx, ctx->dc_bios,
2272 				CLOCK_SOURCE_COMBO_PHY_PLL3,
2273 				&clk_src_regs[3], false);
2274 	pool->base.clock_sources[DCN32_CLK_SRC_PLL4] =
2275 			dcn32_clock_source_create(ctx, ctx->dc_bios,
2276 				CLOCK_SOURCE_COMBO_PHY_PLL4,
2277 				&clk_src_regs[4], false);
2278 
2279 	pool->base.clk_src_count = DCN32_CLK_SRC_TOTAL;
2280 
2281 	/* todo: not reuse phy_pll registers */
2282 	pool->base.dp_clock_source =
2283 			dcn32_clock_source_create(ctx, ctx->dc_bios,
2284 				CLOCK_SOURCE_ID_DP_DTO,
2285 				&clk_src_regs[0], true);
2286 
2287 	for (i = 0; i < pool->base.clk_src_count; i++) {
2288 		if (pool->base.clock_sources[i] == NULL) {
2289 			dm_error("DC: failed to create clock sources!\n");
2290 			BREAK_TO_DEBUGGER();
2291 			goto create_fail;
2292 		}
2293 	}
2294 
2295 	/* DCCG */
2296 	pool->base.dccg = dccg32_create(ctx, &dccg_regs, &dccg_shift, &dccg_mask);
2297 	if (pool->base.dccg == NULL) {
2298 		dm_error("DC: failed to create dccg!\n");
2299 		BREAK_TO_DEBUGGER();
2300 		goto create_fail;
2301 	}
2302 
2303 	/* DML */
2304 	if (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment))
2305 		dml_init_instance(&dc->dml, &dcn3_2_soc, &dcn3_2_ip, DML_PROJECT_DCN32);
2306 
2307 	/* IRQ Service */
2308 	init_data.ctx = dc->ctx;
2309 	pool->base.irqs = dal_irq_service_dcn32_create(&init_data);
2310 	if (!pool->base.irqs)
2311 		goto create_fail;
2312 
2313 	/* HUBBUB */
2314 	pool->base.hubbub = dcn32_hubbub_create(ctx);
2315 	if (pool->base.hubbub == NULL) {
2316 		BREAK_TO_DEBUGGER();
2317 		dm_error("DC: failed to create hubbub!\n");
2318 		goto create_fail;
2319 	}
2320 
2321 	/* HUBPs, DPPs, OPPs, TGs, ABMs */
2322 	for (i = 0, j = 0; i < pool->base.res_cap->num_timing_generator; i++) {
2323 
2324 		/* if pipe is disabled, skip instance of HW pipe,
2325 		 * i.e, skip ASIC register instance
2326 		 */
2327 		if (pipe_fuses & 1 << i)
2328 			continue;
2329 
2330 		/* HUBPs */
2331 		pool->base.hubps[j] = dcn32_hubp_create(ctx, i);
2332 		if (pool->base.hubps[j] == NULL) {
2333 			BREAK_TO_DEBUGGER();
2334 			dm_error(
2335 				"DC: failed to create hubps!\n");
2336 			goto create_fail;
2337 		}
2338 
2339 		/* DPPs */
2340 		pool->base.dpps[j] = dcn32_dpp_create(ctx, i);
2341 		if (pool->base.dpps[j] == NULL) {
2342 			BREAK_TO_DEBUGGER();
2343 			dm_error(
2344 				"DC: failed to create dpps!\n");
2345 			goto create_fail;
2346 		}
2347 
2348 		/* OPPs */
2349 		pool->base.opps[j] = dcn32_opp_create(ctx, i);
2350 		if (pool->base.opps[j] == NULL) {
2351 			BREAK_TO_DEBUGGER();
2352 			dm_error(
2353 				"DC: failed to create output pixel processor!\n");
2354 			goto create_fail;
2355 		}
2356 
2357 		/* TGs */
2358 		pool->base.timing_generators[j] = dcn32_timing_generator_create(
2359 				ctx, i);
2360 		if (pool->base.timing_generators[j] == NULL) {
2361 			BREAK_TO_DEBUGGER();
2362 			dm_error("DC: failed to create tg!\n");
2363 			goto create_fail;
2364 		}
2365 
2366 		/* ABMs */
2367 		pool->base.multiple_abms[j] = dmub_abm_create(ctx,
2368 				&abm_regs[i],
2369 				&abm_shift,
2370 				&abm_mask);
2371 		if (pool->base.multiple_abms[j] == NULL) {
2372 			dm_error("DC: failed to create abm for pipe %d!\n", i);
2373 			BREAK_TO_DEBUGGER();
2374 			goto create_fail;
2375 		}
2376 
2377 		/* index for resource pool arrays for next valid pipe */
2378 		j++;
2379 	}
2380 
2381 	/* PSR */
2382 	pool->base.psr = dmub_psr_create(ctx);
2383 	if (pool->base.psr == NULL) {
2384 		dm_error("DC: failed to create psr obj!\n");
2385 		BREAK_TO_DEBUGGER();
2386 		goto create_fail;
2387 	}
2388 
2389 	/* MPCCs */
2390 	pool->base.mpc = dcn32_mpc_create(ctx, pool->base.res_cap->num_timing_generator, pool->base.res_cap->num_mpc_3dlut);
2391 	if (pool->base.mpc == NULL) {
2392 		BREAK_TO_DEBUGGER();
2393 		dm_error("DC: failed to create mpc!\n");
2394 		goto create_fail;
2395 	}
2396 
2397 	/* DSCs */
2398 	for (i = 0; i < pool->base.res_cap->num_dsc; i++) {
2399 		pool->base.dscs[i] = dcn32_dsc_create(ctx, i);
2400 		if (pool->base.dscs[i] == NULL) {
2401 			BREAK_TO_DEBUGGER();
2402 			dm_error("DC: failed to create display stream compressor %d!\n", i);
2403 			goto create_fail;
2404 		}
2405 	}
2406 
2407 	/* DWB */
2408 	if (!dcn32_dwbc_create(ctx, &pool->base)) {
2409 		BREAK_TO_DEBUGGER();
2410 		dm_error("DC: failed to create dwbc!\n");
2411 		goto create_fail;
2412 	}
2413 
2414 	/* MMHUBBUB */
2415 	if (!dcn32_mmhubbub_create(ctx, &pool->base)) {
2416 		BREAK_TO_DEBUGGER();
2417 		dm_error("DC: failed to create mcif_wb!\n");
2418 		goto create_fail;
2419 	}
2420 
2421 	/* AUX and I2C */
2422 	for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
2423 		pool->base.engines[i] = dcn32_aux_engine_create(ctx, i);
2424 		if (pool->base.engines[i] == NULL) {
2425 			BREAK_TO_DEBUGGER();
2426 			dm_error(
2427 				"DC:failed to create aux engine!!\n");
2428 			goto create_fail;
2429 		}
2430 		pool->base.hw_i2cs[i] = dcn32_i2c_hw_create(ctx, i);
2431 		if (pool->base.hw_i2cs[i] == NULL) {
2432 			BREAK_TO_DEBUGGER();
2433 			dm_error(
2434 				"DC:failed to create hw i2c!!\n");
2435 			goto create_fail;
2436 		}
2437 		pool->base.sw_i2cs[i] = NULL;
2438 	}
2439 
2440 	/* Audio, HWSeq, Stream Encoders including HPO and virtual, MPC 3D LUTs */
2441 	if (!resource_construct(num_virtual_links, dc, &pool->base,
2442 			(!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment) ?
2443 			&res_create_funcs : &res_create_maximus_funcs)))
2444 			goto create_fail;
2445 
2446 	/* HW Sequencer init functions and Plane caps */
2447 	dcn32_hw_sequencer_init_functions(dc);
2448 
2449 	dc->caps.max_planes =  pool->base.pipe_count;
2450 
2451 	for (i = 0; i < dc->caps.max_planes; ++i)
2452 		dc->caps.planes[i] = plane_cap;
2453 
2454 	dc->cap_funcs = cap_funcs;
2455 
2456 	if (dc->ctx->dc_bios->fw_info.oem_i2c_present) {
2457 		ddc_init_data.ctx = dc->ctx;
2458 		ddc_init_data.link = NULL;
2459 		ddc_init_data.id.id = dc->ctx->dc_bios->fw_info.oem_i2c_obj_id;
2460 		ddc_init_data.id.enum_id = 0;
2461 		ddc_init_data.id.type = OBJECT_TYPE_GENERIC;
2462 		pool->base.oem_device = dc->link_srv->create_ddc_service(&ddc_init_data);
2463 	} else {
2464 		pool->base.oem_device = NULL;
2465 	}
2466 
2467 	if (ASICREV_IS_GC_11_0_3(dc->ctx->asic_id.hw_internal_rev) && (dc->config.sdpif_request_limit_words_per_umc == 0))
2468 		dc->config.sdpif_request_limit_words_per_umc = 16;
2469 
2470 	DC_FP_END();
2471 
2472 	return true;
2473 
2474 create_fail:
2475 
2476 	DC_FP_END();
2477 
2478 	dcn32_resource_destruct(pool);
2479 
2480 	return false;
2481 }
2482 
2483 struct resource_pool *dcn32_create_resource_pool(
2484 		const struct dc_init_data *init_data,
2485 		struct dc *dc)
2486 {
2487 	struct dcn32_resource_pool *pool =
2488 		kzalloc(sizeof(struct dcn32_resource_pool), GFP_KERNEL);
2489 
2490 	if (!pool)
2491 		return NULL;
2492 
2493 	if (dcn32_resource_construct(init_data->num_virtual_links, dc, pool))
2494 		return &pool->base;
2495 
2496 	BREAK_TO_DEBUGGER();
2497 	kfree(pool);
2498 	return NULL;
2499 }
2500 
2501 static struct pipe_ctx *find_idle_secondary_pipe_check_mpo(
2502 		struct resource_context *res_ctx,
2503 		const struct resource_pool *pool,
2504 		const struct pipe_ctx *primary_pipe)
2505 {
2506 	int i;
2507 	struct pipe_ctx *secondary_pipe = NULL;
2508 	struct pipe_ctx *next_odm_mpo_pipe = NULL;
2509 	int primary_index, preferred_pipe_idx;
2510 	struct pipe_ctx *old_primary_pipe = NULL;
2511 
2512 	/*
2513 	 * Modified from find_idle_secondary_pipe
2514 	 * With windowed MPO and ODM, we want to avoid the case where we want a
2515 	 *  free pipe for the left side but the free pipe is being used on the
2516 	 *  right side.
2517 	 * Add check on current_state if the primary_pipe is the left side,
2518 	 *  to check the right side ( primary_pipe->next_odm_pipe ) to see if
2519 	 *  it is using a pipe for MPO ( primary_pipe->next_odm_pipe->bottom_pipe )
2520 	 * - If so, then don't use this pipe
2521 	 * EXCEPTION - 3 plane ( 2 MPO plane ) case
2522 	 * - in this case, the primary pipe has already gotten a free pipe for the
2523 	 *  MPO window in the left
2524 	 * - when it tries to get a free pipe for the MPO window on the right,
2525 	 *  it will see that it is already assigned to the right side
2526 	 *  ( primary_pipe->next_odm_pipe ).  But in this case, we want this
2527 	 *  free pipe, since it will be for the right side.  So add an
2528 	 *  additional condition, that skipping the free pipe on the right only
2529 	 *  applies if the primary pipe has no bottom pipe currently assigned
2530 	 */
2531 	if (primary_pipe) {
2532 		primary_index = primary_pipe->pipe_idx;
2533 		old_primary_pipe = &primary_pipe->stream->ctx->dc->current_state->res_ctx.pipe_ctx[primary_index];
2534 		if ((old_primary_pipe->next_odm_pipe) && (old_primary_pipe->next_odm_pipe->bottom_pipe)
2535 			&& (!primary_pipe->bottom_pipe))
2536 			next_odm_mpo_pipe = old_primary_pipe->next_odm_pipe->bottom_pipe;
2537 
2538 		preferred_pipe_idx = (pool->pipe_count - 1) - primary_pipe->pipe_idx;
2539 		if ((res_ctx->pipe_ctx[preferred_pipe_idx].stream == NULL) &&
2540 			!(next_odm_mpo_pipe && next_odm_mpo_pipe->pipe_idx == preferred_pipe_idx)) {
2541 			secondary_pipe = &res_ctx->pipe_ctx[preferred_pipe_idx];
2542 			secondary_pipe->pipe_idx = preferred_pipe_idx;
2543 		}
2544 	}
2545 
2546 	/*
2547 	 * search backwards for the second pipe to keep pipe
2548 	 * assignment more consistent
2549 	 */
2550 	if (!secondary_pipe)
2551 		for (i = pool->pipe_count - 1; i >= 0; i--) {
2552 			if ((res_ctx->pipe_ctx[i].stream == NULL) &&
2553 				!(next_odm_mpo_pipe && next_odm_mpo_pipe->pipe_idx == i)) {
2554 				secondary_pipe = &res_ctx->pipe_ctx[i];
2555 				secondary_pipe->pipe_idx = i;
2556 				break;
2557 			}
2558 		}
2559 
2560 	return secondary_pipe;
2561 }
2562 
2563 struct pipe_ctx *dcn32_acquire_idle_pipe_for_head_pipe_in_layer(
2564 		struct dc_state *state,
2565 		const struct resource_pool *pool,
2566 		struct dc_stream_state *stream,
2567 		struct pipe_ctx *head_pipe)
2568 {
2569 	struct resource_context *res_ctx = &state->res_ctx;
2570 	struct pipe_ctx *idle_pipe, *pipe;
2571 	struct resource_context *old_ctx = &stream->ctx->dc->current_state->res_ctx;
2572 	int head_index;
2573 
2574 	if (!head_pipe)
2575 		ASSERT(0);
2576 
2577 	/*
2578 	 * Modified from dcn20_acquire_idle_pipe_for_layer
2579 	 * Check if head_pipe in old_context already has bottom_pipe allocated.
2580 	 * - If so, check if that pipe is available in the current context.
2581 	 * --  If so, reuse pipe from old_context
2582 	 */
2583 	head_index = head_pipe->pipe_idx;
2584 	pipe = &old_ctx->pipe_ctx[head_index];
2585 	if (pipe->bottom_pipe && res_ctx->pipe_ctx[pipe->bottom_pipe->pipe_idx].stream == NULL) {
2586 		idle_pipe = &res_ctx->pipe_ctx[pipe->bottom_pipe->pipe_idx];
2587 		idle_pipe->pipe_idx = pipe->bottom_pipe->pipe_idx;
2588 	} else {
2589 		idle_pipe = find_idle_secondary_pipe_check_mpo(res_ctx, pool, head_pipe);
2590 		if (!idle_pipe)
2591 			return NULL;
2592 	}
2593 
2594 	idle_pipe->stream = head_pipe->stream;
2595 	idle_pipe->stream_res.tg = head_pipe->stream_res.tg;
2596 	idle_pipe->stream_res.opp = head_pipe->stream_res.opp;
2597 
2598 	idle_pipe->plane_res.hubp = pool->hubps[idle_pipe->pipe_idx];
2599 	idle_pipe->plane_res.ipp = pool->ipps[idle_pipe->pipe_idx];
2600 	idle_pipe->plane_res.dpp = pool->dpps[idle_pipe->pipe_idx];
2601 	idle_pipe->plane_res.mpcc_inst = pool->dpps[idle_pipe->pipe_idx]->inst;
2602 
2603 	return idle_pipe;
2604 }
2605 
2606 unsigned int dcn32_calc_num_avail_chans_for_mall(struct dc *dc, int num_chans)
2607 {
2608 	/*
2609 	 * DCN32 and DCN321 SKUs may have different sizes for MALL
2610 	 *  but we may not be able to access all the MALL space.
2611 	 *  If the num_chans is power of 2, then we can access all
2612 	 *  of the available MALL space.  Otherwise, we can only
2613 	 *  access:
2614 	 *
2615 	 *  max_cab_size_in_bytes = total_cache_size_in_bytes *
2616 	 *    ((2^floor(log2(num_chans)))/num_chans)
2617 	 *
2618 	 * Calculating the MALL sizes for all available SKUs, we
2619 	 *  have come up with the follow simplified check.
2620 	 * - we have max_chans which provides the max MALL size.
2621 	 *  Each chans supports 4MB of MALL so:
2622 	 *
2623 	 *  total_cache_size_in_bytes = max_chans * 4 MB
2624 	 *
2625 	 * - we have avail_chans which shows the number of channels
2626 	 *  we can use if we can't access the entire MALL space.
2627 	 *  It is generally half of max_chans
2628 	 * - so we use the following checks:
2629 	 *
2630 	 *   if (num_chans == max_chans), return max_chans
2631 	 *   if (num_chans < max_chans), return avail_chans
2632 	 *
2633 	 * - exception is GC_11_0_0 where we can't access max_chans,
2634 	 *  so we define max_avail_chans as the maximum available
2635 	 *  MALL space
2636 	 *
2637 	 */
2638 	int gc_11_0_0_max_chans = 48;
2639 	int gc_11_0_0_max_avail_chans = 32;
2640 	int gc_11_0_0_avail_chans = 16;
2641 	int gc_11_0_3_max_chans = 16;
2642 	int gc_11_0_3_avail_chans = 8;
2643 	int gc_11_0_2_max_chans = 8;
2644 	int gc_11_0_2_avail_chans = 4;
2645 
2646 	if (ASICREV_IS_GC_11_0_0(dc->ctx->asic_id.hw_internal_rev)) {
2647 		return (num_chans == gc_11_0_0_max_chans) ?
2648 			gc_11_0_0_max_avail_chans : gc_11_0_0_avail_chans;
2649 	} else if (ASICREV_IS_GC_11_0_2(dc->ctx->asic_id.hw_internal_rev)) {
2650 		return (num_chans == gc_11_0_2_max_chans) ?
2651 			gc_11_0_2_max_chans : gc_11_0_2_avail_chans;
2652 	} else { // if (ASICREV_IS_GC_11_0_3(dc->ctx->asic_id.hw_internal_rev)) {
2653 		return (num_chans == gc_11_0_3_max_chans) ?
2654 			gc_11_0_3_max_chans : gc_11_0_3_avail_chans;
2655 	}
2656 }
2657