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