1 /*
2  * Copyright 2020 Advanced Micro Devices, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * Authors: AMD
23  *
24  */
25 
26 
27 #include "dm_services.h"
28 #include "dc.h"
29 
30 #include "dcn30_init.h"
31 
32 #include "resource.h"
33 #include "include/irq_service_interface.h"
34 #include "dcn20/dcn20_resource.h"
35 
36 #include "dcn30_resource.h"
37 
38 #include "dcn10/dcn10_ipp.h"
39 #include "dcn30/dcn30_hubbub.h"
40 #include "dcn30/dcn30_mpc.h"
41 #include "dcn30/dcn30_hubp.h"
42 #include "irq/dcn30/irq_service_dcn30.h"
43 #include "dcn30/dcn30_dpp.h"
44 #include "dcn30/dcn30_optc.h"
45 #include "dcn20/dcn20_hwseq.h"
46 #include "dcn30/dcn30_hwseq.h"
47 #include "dce110/dce110_hw_sequencer.h"
48 #include "dcn30/dcn30_opp.h"
49 #include "dcn20/dcn20_dsc.h"
50 #include "dcn30/dcn30_vpg.h"
51 #include "dcn30/dcn30_afmt.h"
52 #include "dcn30/dcn30_dio_stream_encoder.h"
53 #include "dcn30/dcn30_dio_link_encoder.h"
54 #include "dce/dce_clock_source.h"
55 #include "dce/dce_audio.h"
56 #include "dce/dce_hwseq.h"
57 #include "clk_mgr.h"
58 #include "virtual/virtual_stream_encoder.h"
59 #include "dce110/dce110_resource.h"
60 #include "dml/display_mode_vba.h"
61 #include "dcn30/dcn30_dccg.h"
62 #include "dcn10/dcn10_resource.h"
63 #include "link.h"
64 #include "dce/dce_panel_cntl.h"
65 
66 #include "dcn30/dcn30_dwb.h"
67 #include "dcn30/dcn30_mmhubbub.h"
68 
69 #include "sienna_cichlid_ip_offset.h"
70 #include "dcn/dcn_3_0_0_offset.h"
71 #include "dcn/dcn_3_0_0_sh_mask.h"
72 
73 #include "nbio/nbio_7_4_offset.h"
74 
75 #include "dpcs/dpcs_3_0_0_offset.h"
76 #include "dpcs/dpcs_3_0_0_sh_mask.h"
77 
78 #include "mmhub/mmhub_2_0_0_offset.h"
79 #include "mmhub/mmhub_2_0_0_sh_mask.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/dcn30_fpu.h"
88 #include "dml/dcn30/display_mode_vba_30.h"
89 #include "vm_helper.h"
90 #include "dcn20/dcn20_vmid.h"
91 #include "amdgpu_socbb.h"
92 #include "dc_dmub_srv.h"
93 
94 #define DC_LOGGER_INIT(logger)
95 
96 enum dcn30_clk_src_array_id {
97 	DCN30_CLK_SRC_PLL0,
98 	DCN30_CLK_SRC_PLL1,
99 	DCN30_CLK_SRC_PLL2,
100 	DCN30_CLK_SRC_PLL3,
101 	DCN30_CLK_SRC_PLL4,
102 	DCN30_CLK_SRC_PLL5,
103 	DCN30_CLK_SRC_TOTAL
104 };
105 
106 /* begin *********************
107  * macros to expend register list macro defined in HW object header file
108  */
109 
110 /* DCN */
111 #define BASE_INNER(seg) DCN_BASE__INST0_SEG ## seg
112 
113 #define BASE(seg) BASE_INNER(seg)
114 
115 #define SR(reg_name)\
116 		.reg_name = BASE(mm ## reg_name ## _BASE_IDX) +  \
117 					mm ## reg_name
118 
119 #define SRI(reg_name, block, id)\
120 	.reg_name = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
121 					mm ## block ## id ## _ ## reg_name
122 
123 #define SRI2(reg_name, block, id)\
124 	.reg_name = BASE(mm ## reg_name ## _BASE_IDX) + \
125 					mm ## reg_name
126 
127 #define SRIR(var_name, reg_name, block, id)\
128 	.var_name = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
129 					mm ## block ## id ## _ ## reg_name
130 
131 #define SRII(reg_name, block, id)\
132 	.reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
133 					mm ## block ## id ## _ ## reg_name
134 
135 #define SRII_MPC_RMU(reg_name, block, id)\
136 	.RMU##_##reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
137 					mm ## block ## id ## _ ## reg_name
138 
139 #define SRII_DWB(reg_name, temp_name, block, id)\
140 	.reg_name[id] = BASE(mm ## block ## id ## _ ## temp_name ## _BASE_IDX) + \
141 					mm ## block ## id ## _ ## temp_name
142 
143 #define SF_DWB2(reg_name, block, id, field_name, post_fix)	\
144 	.field_name = reg_name ## __ ## field_name ## post_fix
145 
146 #define DCCG_SRII(reg_name, block, id)\
147 	.block ## _ ## reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
148 					mm ## block ## id ## _ ## reg_name
149 
150 #define VUPDATE_SRII(reg_name, block, id)\
151 	.reg_name[id] = BASE(mm ## reg_name ## _ ## block ## id ## _BASE_IDX) + \
152 					mm ## reg_name ## _ ## block ## id
153 
154 /* NBIO */
155 #define NBIO_BASE_INNER(seg) \
156 	NBIO_BASE__INST0_SEG ## seg
157 
158 #define NBIO_BASE(seg) \
159 	NBIO_BASE_INNER(seg)
160 
161 #define NBIO_SR(reg_name)\
162 		.reg_name = NBIO_BASE(mm ## reg_name ## _BASE_IDX) + \
163 					mm ## reg_name
164 
165 /* MMHUB */
166 #define MMHUB_BASE_INNER(seg) \
167 	MMHUB_BASE__INST0_SEG ## seg
168 
169 #define MMHUB_BASE(seg) \
170 	MMHUB_BASE_INNER(seg)
171 
172 #define MMHUB_SR(reg_name)\
173 		.reg_name = MMHUB_BASE(mmMM ## reg_name ## _BASE_IDX) + \
174 					mmMM ## reg_name
175 
176 /* CLOCK */
177 #define CLK_BASE_INNER(seg) \
178 	CLK_BASE__INST0_SEG ## seg
179 
180 #define CLK_BASE(seg) \
181 	CLK_BASE_INNER(seg)
182 
183 #define CLK_SRI(reg_name, block, inst)\
184 	.reg_name = CLK_BASE(mm ## block ## _ ## inst ## _ ## reg_name ## _BASE_IDX) + \
185 					mm ## block ## _ ## inst ## _ ## reg_name
186 
187 
188 static const struct bios_registers bios_regs = {
189 		NBIO_SR(BIOS_SCRATCH_3),
190 		NBIO_SR(BIOS_SCRATCH_6)
191 };
192 
193 #define clk_src_regs(index, pllid)\
194 [index] = {\
195 	CS_COMMON_REG_LIST_DCN2_0(index, pllid),\
196 }
197 
198 static const struct dce110_clk_src_regs clk_src_regs[] = {
199 	clk_src_regs(0, A),
200 	clk_src_regs(1, B),
201 	clk_src_regs(2, C),
202 	clk_src_regs(3, D),
203 	clk_src_regs(4, E),
204 	clk_src_regs(5, F)
205 };
206 
207 static const struct dce110_clk_src_shift cs_shift = {
208 		CS_COMMON_MASK_SH_LIST_DCN2_0(__SHIFT)
209 };
210 
211 static const struct dce110_clk_src_mask cs_mask = {
212 		CS_COMMON_MASK_SH_LIST_DCN2_0(_MASK)
213 };
214 
215 #define abm_regs(id)\
216 [id] = {\
217 		ABM_DCN30_REG_LIST(id)\
218 }
219 
220 static const struct dce_abm_registers abm_regs[] = {
221 		abm_regs(0),
222 		abm_regs(1),
223 		abm_regs(2),
224 		abm_regs(3),
225 		abm_regs(4),
226 		abm_regs(5),
227 };
228 
229 static const struct dce_abm_shift abm_shift = {
230 		ABM_MASK_SH_LIST_DCN30(__SHIFT)
231 };
232 
233 static const struct dce_abm_mask abm_mask = {
234 		ABM_MASK_SH_LIST_DCN30(_MASK)
235 };
236 
237 
238 
239 #define audio_regs(id)\
240 [id] = {\
241 		AUD_COMMON_REG_LIST(id)\
242 }
243 
244 static const struct dce_audio_registers audio_regs[] = {
245 	audio_regs(0),
246 	audio_regs(1),
247 	audio_regs(2),
248 	audio_regs(3),
249 	audio_regs(4),
250 	audio_regs(5),
251 	audio_regs(6)
252 };
253 
254 #define DCE120_AUD_COMMON_MASK_SH_LIST(mask_sh)\
255 		SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_INDEX, AZALIA_ENDPOINT_REG_INDEX, mask_sh),\
256 		SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_DATA, AZALIA_ENDPOINT_REG_DATA, mask_sh),\
257 		AUD_COMMON_MASK_SH_LIST_BASE(mask_sh)
258 
259 static const struct dce_audio_shift audio_shift = {
260 		DCE120_AUD_COMMON_MASK_SH_LIST(__SHIFT)
261 };
262 
263 static const struct dce_audio_mask audio_mask = {
264 		DCE120_AUD_COMMON_MASK_SH_LIST(_MASK)
265 };
266 
267 #define vpg_regs(id)\
268 [id] = {\
269 	VPG_DCN3_REG_LIST(id)\
270 }
271 
272 static const struct dcn30_vpg_registers vpg_regs[] = {
273 	vpg_regs(0),
274 	vpg_regs(1),
275 	vpg_regs(2),
276 	vpg_regs(3),
277 	vpg_regs(4),
278 	vpg_regs(5),
279 	vpg_regs(6),
280 };
281 
282 static const struct dcn30_vpg_shift vpg_shift = {
283 	DCN3_VPG_MASK_SH_LIST(__SHIFT)
284 };
285 
286 static const struct dcn30_vpg_mask vpg_mask = {
287 	DCN3_VPG_MASK_SH_LIST(_MASK)
288 };
289 
290 #define afmt_regs(id)\
291 [id] = {\
292 	AFMT_DCN3_REG_LIST(id)\
293 }
294 
295 static const struct dcn30_afmt_registers afmt_regs[] = {
296 	afmt_regs(0),
297 	afmt_regs(1),
298 	afmt_regs(2),
299 	afmt_regs(3),
300 	afmt_regs(4),
301 	afmt_regs(5),
302 	afmt_regs(6),
303 };
304 
305 static const struct dcn30_afmt_shift afmt_shift = {
306 	DCN3_AFMT_MASK_SH_LIST(__SHIFT)
307 };
308 
309 static const struct dcn30_afmt_mask afmt_mask = {
310 	DCN3_AFMT_MASK_SH_LIST(_MASK)
311 };
312 
313 #define stream_enc_regs(id)\
314 [id] = {\
315 	SE_DCN3_REG_LIST(id)\
316 }
317 
318 static const struct dcn10_stream_enc_registers stream_enc_regs[] = {
319 	stream_enc_regs(0),
320 	stream_enc_regs(1),
321 	stream_enc_regs(2),
322 	stream_enc_regs(3),
323 	stream_enc_regs(4),
324 	stream_enc_regs(5)
325 };
326 
327 static const struct dcn10_stream_encoder_shift se_shift = {
328 		SE_COMMON_MASK_SH_LIST_DCN30(__SHIFT)
329 };
330 
331 static const struct dcn10_stream_encoder_mask se_mask = {
332 		SE_COMMON_MASK_SH_LIST_DCN30(_MASK)
333 };
334 
335 
336 #define aux_regs(id)\
337 [id] = {\
338 	DCN2_AUX_REG_LIST(id)\
339 }
340 
341 static const struct dcn10_link_enc_aux_registers link_enc_aux_regs[] = {
342 		aux_regs(0),
343 		aux_regs(1),
344 		aux_regs(2),
345 		aux_regs(3),
346 		aux_regs(4),
347 		aux_regs(5)
348 };
349 
350 #define hpd_regs(id)\
351 [id] = {\
352 	HPD_REG_LIST(id)\
353 }
354 
355 static const struct dcn10_link_enc_hpd_registers link_enc_hpd_regs[] = {
356 		hpd_regs(0),
357 		hpd_regs(1),
358 		hpd_regs(2),
359 		hpd_regs(3),
360 		hpd_regs(4),
361 		hpd_regs(5)
362 };
363 
364 #define link_regs(id, phyid)\
365 [id] = {\
366 	LE_DCN3_REG_LIST(id), \
367 	UNIPHY_DCN2_REG_LIST(phyid), \
368 	DPCS_DCN2_REG_LIST(id), \
369 	SRI(DP_DPHY_INTERNAL_CTRL, DP, id) \
370 }
371 
372 static const struct dce110_aux_registers_shift aux_shift = {
373 	DCN_AUX_MASK_SH_LIST(__SHIFT)
374 };
375 
376 static const struct dce110_aux_registers_mask aux_mask = {
377 	DCN_AUX_MASK_SH_LIST(_MASK)
378 };
379 
380 static const struct dcn10_link_enc_registers link_enc_regs[] = {
381 	link_regs(0, A),
382 	link_regs(1, B),
383 	link_regs(2, C),
384 	link_regs(3, D),
385 	link_regs(4, E),
386 	link_regs(5, F)
387 };
388 
389 static const struct dcn10_link_enc_shift le_shift = {
390 	LINK_ENCODER_MASK_SH_LIST_DCN30(__SHIFT),\
391 	DPCS_DCN2_MASK_SH_LIST(__SHIFT)
392 };
393 
394 static const struct dcn10_link_enc_mask le_mask = {
395 	LINK_ENCODER_MASK_SH_LIST_DCN30(_MASK),\
396 	DPCS_DCN2_MASK_SH_LIST(_MASK)
397 };
398 
399 
400 static const struct dce_panel_cntl_registers panel_cntl_regs[] = {
401 	{ DCN_PANEL_CNTL_REG_LIST() }
402 };
403 
404 static const struct dce_panel_cntl_shift panel_cntl_shift = {
405 	DCE_PANEL_CNTL_MASK_SH_LIST(__SHIFT)
406 };
407 
408 static const struct dce_panel_cntl_mask panel_cntl_mask = {
409 	DCE_PANEL_CNTL_MASK_SH_LIST(_MASK)
410 };
411 
412 #define dpp_regs(id)\
413 [id] = {\
414 	DPP_REG_LIST_DCN30(id),\
415 }
416 
417 static const struct dcn3_dpp_registers dpp_regs[] = {
418 	dpp_regs(0),
419 	dpp_regs(1),
420 	dpp_regs(2),
421 	dpp_regs(3),
422 	dpp_regs(4),
423 	dpp_regs(5),
424 };
425 
426 static const struct dcn3_dpp_shift tf_shift = {
427 		DPP_REG_LIST_SH_MASK_DCN30(__SHIFT)
428 };
429 
430 static const struct dcn3_dpp_mask tf_mask = {
431 		DPP_REG_LIST_SH_MASK_DCN30(_MASK)
432 };
433 
434 #define opp_regs(id)\
435 [id] = {\
436 	OPP_REG_LIST_DCN30(id),\
437 }
438 
439 static const struct dcn20_opp_registers opp_regs[] = {
440 	opp_regs(0),
441 	opp_regs(1),
442 	opp_regs(2),
443 	opp_regs(3),
444 	opp_regs(4),
445 	opp_regs(5)
446 };
447 
448 static const struct dcn20_opp_shift opp_shift = {
449 	OPP_MASK_SH_LIST_DCN20(__SHIFT)
450 };
451 
452 static const struct dcn20_opp_mask opp_mask = {
453 	OPP_MASK_SH_LIST_DCN20(_MASK)
454 };
455 
456 #define aux_engine_regs(id)\
457 [id] = {\
458 	AUX_COMMON_REG_LIST0(id), \
459 	.AUXN_IMPCAL = 0, \
460 	.AUXP_IMPCAL = 0, \
461 	.AUX_RESET_MASK = DP_AUX0_AUX_CONTROL__AUX_RESET_MASK, \
462 }
463 
464 static const struct dce110_aux_registers aux_engine_regs[] = {
465 		aux_engine_regs(0),
466 		aux_engine_regs(1),
467 		aux_engine_regs(2),
468 		aux_engine_regs(3),
469 		aux_engine_regs(4),
470 		aux_engine_regs(5)
471 };
472 
473 #define dwbc_regs_dcn3(id)\
474 [id] = {\
475 	DWBC_COMMON_REG_LIST_DCN30(id),\
476 }
477 
478 static const struct dcn30_dwbc_registers dwbc30_regs[] = {
479 	dwbc_regs_dcn3(0),
480 };
481 
482 static const struct dcn30_dwbc_shift dwbc30_shift = {
483 	DWBC_COMMON_MASK_SH_LIST_DCN30(__SHIFT)
484 };
485 
486 static const struct dcn30_dwbc_mask dwbc30_mask = {
487 	DWBC_COMMON_MASK_SH_LIST_DCN30(_MASK)
488 };
489 
490 #define mcif_wb_regs_dcn3(id)\
491 [id] = {\
492 	MCIF_WB_COMMON_REG_LIST_DCN30(id),\
493 }
494 
495 static const struct dcn30_mmhubbub_registers mcif_wb30_regs[] = {
496 	mcif_wb_regs_dcn3(0)
497 };
498 
499 static const struct dcn30_mmhubbub_shift mcif_wb30_shift = {
500 	MCIF_WB_COMMON_MASK_SH_LIST_DCN30(__SHIFT)
501 };
502 
503 static const struct dcn30_mmhubbub_mask mcif_wb30_mask = {
504 	MCIF_WB_COMMON_MASK_SH_LIST_DCN30(_MASK)
505 };
506 
507 #define dsc_regsDCN20(id)\
508 [id] = {\
509 	DSC_REG_LIST_DCN20(id)\
510 }
511 
512 static const struct dcn20_dsc_registers dsc_regs[] = {
513 	dsc_regsDCN20(0),
514 	dsc_regsDCN20(1),
515 	dsc_regsDCN20(2),
516 	dsc_regsDCN20(3),
517 	dsc_regsDCN20(4),
518 	dsc_regsDCN20(5)
519 };
520 
521 static const struct dcn20_dsc_shift dsc_shift = {
522 	DSC_REG_LIST_SH_MASK_DCN20(__SHIFT)
523 };
524 
525 static const struct dcn20_dsc_mask dsc_mask = {
526 	DSC_REG_LIST_SH_MASK_DCN20(_MASK)
527 };
528 
529 static const struct dcn30_mpc_registers mpc_regs = {
530 		MPC_REG_LIST_DCN3_0(0),
531 		MPC_REG_LIST_DCN3_0(1),
532 		MPC_REG_LIST_DCN3_0(2),
533 		MPC_REG_LIST_DCN3_0(3),
534 		MPC_REG_LIST_DCN3_0(4),
535 		MPC_REG_LIST_DCN3_0(5),
536 		MPC_OUT_MUX_REG_LIST_DCN3_0(0),
537 		MPC_OUT_MUX_REG_LIST_DCN3_0(1),
538 		MPC_OUT_MUX_REG_LIST_DCN3_0(2),
539 		MPC_OUT_MUX_REG_LIST_DCN3_0(3),
540 		MPC_OUT_MUX_REG_LIST_DCN3_0(4),
541 		MPC_OUT_MUX_REG_LIST_DCN3_0(5),
542 		MPC_RMU_GLOBAL_REG_LIST_DCN3AG,
543 		MPC_RMU_REG_LIST_DCN3AG(0),
544 		MPC_RMU_REG_LIST_DCN3AG(1),
545 		MPC_RMU_REG_LIST_DCN3AG(2),
546 		MPC_DWB_MUX_REG_LIST_DCN3_0(0),
547 };
548 
549 static const struct dcn30_mpc_shift mpc_shift = {
550 	MPC_COMMON_MASK_SH_LIST_DCN30(__SHIFT)
551 };
552 
553 static const struct dcn30_mpc_mask mpc_mask = {
554 	MPC_COMMON_MASK_SH_LIST_DCN30(_MASK)
555 };
556 
557 #define optc_regs(id)\
558 [id] = {OPTC_COMMON_REG_LIST_DCN3_0(id)}
559 
560 
561 static const struct dcn_optc_registers optc_regs[] = {
562 	optc_regs(0),
563 	optc_regs(1),
564 	optc_regs(2),
565 	optc_regs(3),
566 	optc_regs(4),
567 	optc_regs(5)
568 };
569 
570 static const struct dcn_optc_shift optc_shift = {
571 	OPTC_COMMON_MASK_SH_LIST_DCN30(__SHIFT)
572 };
573 
574 static const struct dcn_optc_mask optc_mask = {
575 	OPTC_COMMON_MASK_SH_LIST_DCN30(_MASK)
576 };
577 
578 #define hubp_regs(id)\
579 [id] = {\
580 	HUBP_REG_LIST_DCN30(id)\
581 }
582 
583 static const struct dcn_hubp2_registers hubp_regs[] = {
584 		hubp_regs(0),
585 		hubp_regs(1),
586 		hubp_regs(2),
587 		hubp_regs(3),
588 		hubp_regs(4),
589 		hubp_regs(5)
590 };
591 
592 static const struct dcn_hubp2_shift hubp_shift = {
593 		HUBP_MASK_SH_LIST_DCN30(__SHIFT)
594 };
595 
596 static const struct dcn_hubp2_mask hubp_mask = {
597 		HUBP_MASK_SH_LIST_DCN30(_MASK)
598 };
599 
600 static const struct dcn_hubbub_registers hubbub_reg = {
601 		HUBBUB_REG_LIST_DCN30(0)
602 };
603 
604 static const struct dcn_hubbub_shift hubbub_shift = {
605 		HUBBUB_MASK_SH_LIST_DCN30(__SHIFT)
606 };
607 
608 static const struct dcn_hubbub_mask hubbub_mask = {
609 		HUBBUB_MASK_SH_LIST_DCN30(_MASK)
610 };
611 
612 static const struct dccg_registers dccg_regs = {
613 		DCCG_REG_LIST_DCN30()
614 };
615 
616 static const struct dccg_shift dccg_shift = {
617 		DCCG_MASK_SH_LIST_DCN3(__SHIFT)
618 };
619 
620 static const struct dccg_mask dccg_mask = {
621 		DCCG_MASK_SH_LIST_DCN3(_MASK)
622 };
623 
624 static const struct dce_hwseq_registers hwseq_reg = {
625 		HWSEQ_DCN30_REG_LIST()
626 };
627 
628 static const struct dce_hwseq_shift hwseq_shift = {
629 		HWSEQ_DCN30_MASK_SH_LIST(__SHIFT)
630 };
631 
632 static const struct dce_hwseq_mask hwseq_mask = {
633 		HWSEQ_DCN30_MASK_SH_LIST(_MASK)
634 };
635 #define vmid_regs(id)\
636 [id] = {\
637 		DCN20_VMID_REG_LIST(id)\
638 }
639 
640 static const struct dcn_vmid_registers vmid_regs[] = {
641 	vmid_regs(0),
642 	vmid_regs(1),
643 	vmid_regs(2),
644 	vmid_regs(3),
645 	vmid_regs(4),
646 	vmid_regs(5),
647 	vmid_regs(6),
648 	vmid_regs(7),
649 	vmid_regs(8),
650 	vmid_regs(9),
651 	vmid_regs(10),
652 	vmid_regs(11),
653 	vmid_regs(12),
654 	vmid_regs(13),
655 	vmid_regs(14),
656 	vmid_regs(15)
657 };
658 
659 static const struct dcn20_vmid_shift vmid_shifts = {
660 		DCN20_VMID_MASK_SH_LIST(__SHIFT)
661 };
662 
663 static const struct dcn20_vmid_mask vmid_masks = {
664 		DCN20_VMID_MASK_SH_LIST(_MASK)
665 };
666 
667 static const struct resource_caps res_cap_dcn3 = {
668 	.num_timing_generator = 6,
669 	.num_opp = 6,
670 	.num_video_plane = 6,
671 	.num_audio = 6,
672 	.num_stream_encoder = 6,
673 	.num_pll = 6,
674 	.num_dwb = 1,
675 	.num_ddc = 6,
676 	.num_vmid = 16,
677 	.num_mpc_3dlut = 3,
678 	.num_dsc = 6,
679 };
680 
681 static const struct dc_plane_cap plane_cap = {
682 	.type = DC_PLANE_TYPE_DCN_UNIVERSAL,
683 	.per_pixel_alpha = true,
684 
685 	.pixel_format_support = {
686 			.argb8888 = true,
687 			.nv12 = true,
688 			.fp16 = true,
689 			.p010 = true,
690 			.ayuv = false,
691 	},
692 
693 	.max_upscale_factor = {
694 			.argb8888 = 16000,
695 			.nv12 = 16000,
696 			.fp16 = 16000
697 	},
698 
699 	/* 6:1 downscaling ratio: 1000/6 = 166.666 */
700 	.max_downscale_factor = {
701 			.argb8888 = 167,
702 			.nv12 = 167,
703 			.fp16 = 167
704 	},
705 	16,
706 	16
707 };
708 
709 static const struct dc_debug_options debug_defaults_drv = {
710 	.disable_dmcu = true, //No DMCU on DCN30
711 	.force_abm_enable = false,
712 	.timing_trace = false,
713 	.clock_trace = true,
714 	.disable_pplib_clock_request = true,
715 	.pipe_split_policy = MPC_SPLIT_DYNAMIC,
716 	.force_single_disp_pipe_split = false,
717 	.disable_dcc = DCC_ENABLE,
718 	.vsr_support = true,
719 	.performance_trace = false,
720 	.max_downscale_src_width = 7680,/*upto 8K*/
721 	.disable_pplib_wm_range = false,
722 	.scl_reset_length10 = true,
723 	.sanity_checks = false,
724 	.underflow_assert_delay_us = 0xFFFFFFFF,
725 	.dwb_fi_phase = -1, // -1 = disable,
726 	.dmub_command_table = true,
727 	.use_max_lb = true,
728 	.exit_idle_opt_for_cursor_updates = true
729 };
730 
731 static const struct dc_debug_options debug_defaults_diags = {
732 	.disable_dmcu = true, //No dmcu on DCN30
733 	.force_abm_enable = false,
734 	.timing_trace = true,
735 	.clock_trace = true,
736 	.disable_dpp_power_gate = true,
737 	.disable_hubp_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 };
748 
749 static const struct dc_panel_config panel_config_defaults = {
750 	.psr = {
751 		.disable_psr = false,
752 		.disallow_psrsu = false,
753 	},
754 };
755 
756 static void dcn30_dpp_destroy(struct dpp **dpp)
757 {
758 	kfree(TO_DCN20_DPP(*dpp));
759 	*dpp = NULL;
760 }
761 
762 static struct dpp *dcn30_dpp_create(
763 	struct dc_context *ctx,
764 	uint32_t inst)
765 {
766 	struct dcn3_dpp *dpp =
767 		kzalloc(sizeof(struct dcn3_dpp), GFP_KERNEL);
768 
769 	if (!dpp)
770 		return NULL;
771 
772 	if (dpp3_construct(dpp, ctx, inst,
773 			&dpp_regs[inst], &tf_shift, &tf_mask))
774 		return &dpp->base;
775 
776 	BREAK_TO_DEBUGGER();
777 	kfree(dpp);
778 	return NULL;
779 }
780 
781 static struct output_pixel_processor *dcn30_opp_create(
782 	struct dc_context *ctx, uint32_t inst)
783 {
784 	struct dcn20_opp *opp =
785 		kzalloc(sizeof(struct dcn20_opp), GFP_KERNEL);
786 
787 	if (!opp) {
788 		BREAK_TO_DEBUGGER();
789 		return NULL;
790 	}
791 
792 	dcn20_opp_construct(opp, ctx, inst,
793 			&opp_regs[inst], &opp_shift, &opp_mask);
794 	return &opp->base;
795 }
796 
797 static struct dce_aux *dcn30_aux_engine_create(
798 	struct dc_context *ctx,
799 	uint32_t inst)
800 {
801 	struct aux_engine_dce110 *aux_engine =
802 		kzalloc(sizeof(struct aux_engine_dce110), GFP_KERNEL);
803 
804 	if (!aux_engine)
805 		return NULL;
806 
807 	dce110_aux_engine_construct(aux_engine, ctx, inst,
808 				    SW_AUX_TIMEOUT_PERIOD_MULTIPLIER * AUX_TIMEOUT_PERIOD,
809 				    &aux_engine_regs[inst],
810 					&aux_mask,
811 					&aux_shift,
812 					ctx->dc->caps.extended_aux_timeout_support);
813 
814 	return &aux_engine->base;
815 }
816 
817 #define i2c_inst_regs(id) { I2C_HW_ENGINE_COMMON_REG_LIST_DCN30(id) }
818 
819 static const struct dce_i2c_registers i2c_hw_regs[] = {
820 		i2c_inst_regs(1),
821 		i2c_inst_regs(2),
822 		i2c_inst_regs(3),
823 		i2c_inst_regs(4),
824 		i2c_inst_regs(5),
825 		i2c_inst_regs(6),
826 };
827 
828 static const struct dce_i2c_shift i2c_shifts = {
829 		I2C_COMMON_MASK_SH_LIST_DCN30(__SHIFT)
830 };
831 
832 static const struct dce_i2c_mask i2c_masks = {
833 		I2C_COMMON_MASK_SH_LIST_DCN30(_MASK)
834 };
835 
836 static struct dce_i2c_hw *dcn30_i2c_hw_create(
837 	struct dc_context *ctx,
838 	uint32_t inst)
839 {
840 	struct dce_i2c_hw *dce_i2c_hw =
841 		kzalloc(sizeof(struct dce_i2c_hw), GFP_KERNEL);
842 
843 	if (!dce_i2c_hw)
844 		return NULL;
845 
846 	dcn2_i2c_hw_construct(dce_i2c_hw, ctx, inst,
847 				    &i2c_hw_regs[inst], &i2c_shifts, &i2c_masks);
848 
849 	return dce_i2c_hw;
850 }
851 
852 static struct mpc *dcn30_mpc_create(
853 		struct dc_context *ctx,
854 		int num_mpcc,
855 		int num_rmu)
856 {
857 	struct dcn30_mpc *mpc30 = kzalloc(sizeof(struct dcn30_mpc),
858 					  GFP_KERNEL);
859 
860 	if (!mpc30)
861 		return NULL;
862 
863 	dcn30_mpc_construct(mpc30, ctx,
864 			&mpc_regs,
865 			&mpc_shift,
866 			&mpc_mask,
867 			num_mpcc,
868 			num_rmu);
869 
870 	return &mpc30->base;
871 }
872 
873 static struct hubbub *dcn30_hubbub_create(struct dc_context *ctx)
874 {
875 	int i;
876 
877 	struct dcn20_hubbub *hubbub3 = kzalloc(sizeof(struct dcn20_hubbub),
878 					  GFP_KERNEL);
879 
880 	if (!hubbub3)
881 		return NULL;
882 
883 	hubbub3_construct(hubbub3, ctx,
884 			&hubbub_reg,
885 			&hubbub_shift,
886 			&hubbub_mask);
887 
888 
889 	for (i = 0; i < res_cap_dcn3.num_vmid; i++) {
890 		struct dcn20_vmid *vmid = &hubbub3->vmid[i];
891 
892 		vmid->ctx = ctx;
893 
894 		vmid->regs = &vmid_regs[i];
895 		vmid->shifts = &vmid_shifts;
896 		vmid->masks = &vmid_masks;
897 	}
898 
899 	return &hubbub3->base;
900 }
901 
902 static struct timing_generator *dcn30_timing_generator_create(
903 		struct dc_context *ctx,
904 		uint32_t instance)
905 {
906 	struct optc *tgn10 =
907 		kzalloc(sizeof(struct optc), GFP_KERNEL);
908 
909 	if (!tgn10)
910 		return NULL;
911 
912 	tgn10->base.inst = instance;
913 	tgn10->base.ctx = ctx;
914 
915 	tgn10->tg_regs = &optc_regs[instance];
916 	tgn10->tg_shift = &optc_shift;
917 	tgn10->tg_mask = &optc_mask;
918 
919 	dcn30_timing_generator_init(tgn10);
920 
921 	return &tgn10->base;
922 }
923 
924 static const struct encoder_feature_support link_enc_feature = {
925 		.max_hdmi_deep_color = COLOR_DEPTH_121212,
926 		.max_hdmi_pixel_clock = 600000,
927 		.hdmi_ycbcr420_supported = true,
928 		.dp_ycbcr420_supported = true,
929 		.fec_supported = true,
930 		.flags.bits.IS_HBR2_CAPABLE = true,
931 		.flags.bits.IS_HBR3_CAPABLE = true,
932 		.flags.bits.IS_TPS3_CAPABLE = true,
933 		.flags.bits.IS_TPS4_CAPABLE = true
934 };
935 
936 static struct link_encoder *dcn30_link_encoder_create(
937 	struct dc_context *ctx,
938 	const struct encoder_init_data *enc_init_data)
939 {
940 	struct dcn20_link_encoder *enc20 =
941 		kzalloc(sizeof(struct dcn20_link_encoder), GFP_KERNEL);
942 
943 	if (!enc20)
944 		return NULL;
945 
946 	dcn30_link_encoder_construct(enc20,
947 			enc_init_data,
948 			&link_enc_feature,
949 			&link_enc_regs[enc_init_data->transmitter],
950 			&link_enc_aux_regs[enc_init_data->channel - 1],
951 			&link_enc_hpd_regs[enc_init_data->hpd_source],
952 			&le_shift,
953 			&le_mask);
954 
955 	return &enc20->enc10.base;
956 }
957 
958 static struct panel_cntl *dcn30_panel_cntl_create(const struct panel_cntl_init_data *init_data)
959 {
960 	struct dce_panel_cntl *panel_cntl =
961 		kzalloc(sizeof(struct dce_panel_cntl), GFP_KERNEL);
962 
963 	if (!panel_cntl)
964 		return NULL;
965 
966 	dce_panel_cntl_construct(panel_cntl,
967 			init_data,
968 			&panel_cntl_regs[init_data->inst],
969 			&panel_cntl_shift,
970 			&panel_cntl_mask);
971 
972 	return &panel_cntl->base;
973 }
974 
975 static void read_dce_straps(
976 	struct dc_context *ctx,
977 	struct resource_straps *straps)
978 {
979 	generic_reg_get(ctx, mmDC_PINSTRAPS + BASE(mmDC_PINSTRAPS_BASE_IDX),
980 		FN(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO), &straps->dc_pinstraps_audio);
981 
982 }
983 
984 static struct audio *dcn30_create_audio(
985 		struct dc_context *ctx, unsigned int inst)
986 {
987 	return dce_audio_create(ctx, inst,
988 			&audio_regs[inst], &audio_shift, &audio_mask);
989 }
990 
991 static struct vpg *dcn30_vpg_create(
992 	struct dc_context *ctx,
993 	uint32_t inst)
994 {
995 	struct dcn30_vpg *vpg3 = kzalloc(sizeof(struct dcn30_vpg), GFP_KERNEL);
996 
997 	if (!vpg3)
998 		return NULL;
999 
1000 	vpg3_construct(vpg3, ctx, inst,
1001 			&vpg_regs[inst],
1002 			&vpg_shift,
1003 			&vpg_mask);
1004 
1005 	return &vpg3->base;
1006 }
1007 
1008 static struct afmt *dcn30_afmt_create(
1009 	struct dc_context *ctx,
1010 	uint32_t inst)
1011 {
1012 	struct dcn30_afmt *afmt3 = kzalloc(sizeof(struct dcn30_afmt), GFP_KERNEL);
1013 
1014 	if (!afmt3)
1015 		return NULL;
1016 
1017 	afmt3_construct(afmt3, ctx, inst,
1018 			&afmt_regs[inst],
1019 			&afmt_shift,
1020 			&afmt_mask);
1021 
1022 	return &afmt3->base;
1023 }
1024 
1025 static struct stream_encoder *dcn30_stream_encoder_create(enum engine_id eng_id,
1026 							  struct dc_context *ctx)
1027 {
1028 	struct dcn10_stream_encoder *enc1;
1029 	struct vpg *vpg;
1030 	struct afmt *afmt;
1031 	int vpg_inst;
1032 	int afmt_inst;
1033 
1034 	/* Mapping of VPG, AFMT, DME register blocks to DIO block instance */
1035 	if (eng_id <= ENGINE_ID_DIGF) {
1036 		vpg_inst = eng_id;
1037 		afmt_inst = eng_id;
1038 	} else
1039 		return NULL;
1040 
1041 	enc1 = kzalloc(sizeof(struct dcn10_stream_encoder), GFP_KERNEL);
1042 	vpg = dcn30_vpg_create(ctx, vpg_inst);
1043 	afmt = dcn30_afmt_create(ctx, afmt_inst);
1044 
1045 	if (!enc1 || !vpg || !afmt) {
1046 		kfree(enc1);
1047 		kfree(vpg);
1048 		kfree(afmt);
1049 		return NULL;
1050 	}
1051 
1052 	dcn30_dio_stream_encoder_construct(enc1, ctx, ctx->dc_bios,
1053 					eng_id, vpg, afmt,
1054 					&stream_enc_regs[eng_id],
1055 					&se_shift, &se_mask);
1056 
1057 	return &enc1->base;
1058 }
1059 
1060 static struct dce_hwseq *dcn30_hwseq_create(struct dc_context *ctx)
1061 {
1062 	struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL);
1063 
1064 	if (hws) {
1065 		hws->ctx = ctx;
1066 		hws->regs = &hwseq_reg;
1067 		hws->shifts = &hwseq_shift;
1068 		hws->masks = &hwseq_mask;
1069 	}
1070 	return hws;
1071 }
1072 static const struct resource_create_funcs res_create_funcs = {
1073 	.read_dce_straps = read_dce_straps,
1074 	.create_audio = dcn30_create_audio,
1075 	.create_stream_encoder = dcn30_stream_encoder_create,
1076 	.create_hwseq = dcn30_hwseq_create,
1077 };
1078 
1079 static const struct resource_create_funcs res_create_maximus_funcs = {
1080 	.read_dce_straps = NULL,
1081 	.create_audio = NULL,
1082 	.create_stream_encoder = NULL,
1083 	.create_hwseq = dcn30_hwseq_create,
1084 };
1085 
1086 static void dcn30_resource_destruct(struct dcn30_resource_pool *pool)
1087 {
1088 	unsigned int i;
1089 
1090 	for (i = 0; i < pool->base.stream_enc_count; i++) {
1091 		if (pool->base.stream_enc[i] != NULL) {
1092 			if (pool->base.stream_enc[i]->vpg != NULL) {
1093 				kfree(DCN30_VPG_FROM_VPG(pool->base.stream_enc[i]->vpg));
1094 				pool->base.stream_enc[i]->vpg = NULL;
1095 			}
1096 			if (pool->base.stream_enc[i]->afmt != NULL) {
1097 				kfree(DCN30_AFMT_FROM_AFMT(pool->base.stream_enc[i]->afmt));
1098 				pool->base.stream_enc[i]->afmt = NULL;
1099 			}
1100 			kfree(DCN10STRENC_FROM_STRENC(pool->base.stream_enc[i]));
1101 			pool->base.stream_enc[i] = NULL;
1102 		}
1103 	}
1104 
1105 	for (i = 0; i < pool->base.res_cap->num_dsc; i++) {
1106 		if (pool->base.dscs[i] != NULL)
1107 			dcn20_dsc_destroy(&pool->base.dscs[i]);
1108 	}
1109 
1110 	if (pool->base.mpc != NULL) {
1111 		kfree(TO_DCN20_MPC(pool->base.mpc));
1112 		pool->base.mpc = NULL;
1113 	}
1114 	if (pool->base.hubbub != NULL) {
1115 		kfree(pool->base.hubbub);
1116 		pool->base.hubbub = NULL;
1117 	}
1118 	for (i = 0; i < pool->base.pipe_count; i++) {
1119 		if (pool->base.dpps[i] != NULL)
1120 			dcn30_dpp_destroy(&pool->base.dpps[i]);
1121 
1122 		if (pool->base.ipps[i] != NULL)
1123 			pool->base.ipps[i]->funcs->ipp_destroy(&pool->base.ipps[i]);
1124 
1125 		if (pool->base.hubps[i] != NULL) {
1126 			kfree(TO_DCN20_HUBP(pool->base.hubps[i]));
1127 			pool->base.hubps[i] = NULL;
1128 		}
1129 
1130 		if (pool->base.irqs != NULL) {
1131 			dal_irq_service_destroy(&pool->base.irqs);
1132 		}
1133 	}
1134 
1135 	for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
1136 		if (pool->base.engines[i] != NULL)
1137 			dce110_engine_destroy(&pool->base.engines[i]);
1138 		if (pool->base.hw_i2cs[i] != NULL) {
1139 			kfree(pool->base.hw_i2cs[i]);
1140 			pool->base.hw_i2cs[i] = NULL;
1141 		}
1142 		if (pool->base.sw_i2cs[i] != NULL) {
1143 			kfree(pool->base.sw_i2cs[i]);
1144 			pool->base.sw_i2cs[i] = NULL;
1145 		}
1146 	}
1147 
1148 	for (i = 0; i < pool->base.res_cap->num_opp; i++) {
1149 		if (pool->base.opps[i] != NULL)
1150 			pool->base.opps[i]->funcs->opp_destroy(&pool->base.opps[i]);
1151 	}
1152 
1153 	for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) {
1154 		if (pool->base.timing_generators[i] != NULL)	{
1155 			kfree(DCN10TG_FROM_TG(pool->base.timing_generators[i]));
1156 			pool->base.timing_generators[i] = NULL;
1157 		}
1158 	}
1159 
1160 	for (i = 0; i < pool->base.res_cap->num_dwb; i++) {
1161 		if (pool->base.dwbc[i] != NULL) {
1162 			kfree(TO_DCN30_DWBC(pool->base.dwbc[i]));
1163 			pool->base.dwbc[i] = NULL;
1164 		}
1165 		if (pool->base.mcif_wb[i] != NULL) {
1166 			kfree(TO_DCN30_MMHUBBUB(pool->base.mcif_wb[i]));
1167 			pool->base.mcif_wb[i] = NULL;
1168 		}
1169 	}
1170 
1171 	for (i = 0; i < pool->base.audio_count; i++) {
1172 		if (pool->base.audios[i])
1173 			dce_aud_destroy(&pool->base.audios[i]);
1174 	}
1175 
1176 	for (i = 0; i < pool->base.clk_src_count; i++) {
1177 		if (pool->base.clock_sources[i] != NULL) {
1178 			dcn20_clock_source_destroy(&pool->base.clock_sources[i]);
1179 			pool->base.clock_sources[i] = NULL;
1180 		}
1181 	}
1182 
1183 	for (i = 0; i < pool->base.res_cap->num_mpc_3dlut; i++) {
1184 		if (pool->base.mpc_lut[i] != NULL) {
1185 			dc_3dlut_func_release(pool->base.mpc_lut[i]);
1186 			pool->base.mpc_lut[i] = NULL;
1187 		}
1188 		if (pool->base.mpc_shaper[i] != NULL) {
1189 			dc_transfer_func_release(pool->base.mpc_shaper[i]);
1190 			pool->base.mpc_shaper[i] = NULL;
1191 		}
1192 	}
1193 
1194 	if (pool->base.dp_clock_source != NULL) {
1195 		dcn20_clock_source_destroy(&pool->base.dp_clock_source);
1196 		pool->base.dp_clock_source = NULL;
1197 	}
1198 
1199 	for (i = 0; i < pool->base.pipe_count; i++) {
1200 		if (pool->base.multiple_abms[i] != NULL)
1201 			dce_abm_destroy(&pool->base.multiple_abms[i]);
1202 	}
1203 
1204 	if (pool->base.psr != NULL)
1205 		dmub_psr_destroy(&pool->base.psr);
1206 
1207 	if (pool->base.dccg != NULL)
1208 		dcn_dccg_destroy(&pool->base.dccg);
1209 
1210 	if (pool->base.oem_device != NULL) {
1211 		struct dc *dc = pool->base.oem_device->ctx->dc;
1212 
1213 		dc->link_srv->destroy_ddc_service(&pool->base.oem_device);
1214 	}
1215 }
1216 
1217 static struct hubp *dcn30_hubp_create(
1218 	struct dc_context *ctx,
1219 	uint32_t inst)
1220 {
1221 	struct dcn20_hubp *hubp2 =
1222 		kzalloc(sizeof(struct dcn20_hubp), GFP_KERNEL);
1223 
1224 	if (!hubp2)
1225 		return NULL;
1226 
1227 	if (hubp3_construct(hubp2, ctx, inst,
1228 			&hubp_regs[inst], &hubp_shift, &hubp_mask))
1229 		return &hubp2->base;
1230 
1231 	BREAK_TO_DEBUGGER();
1232 	kfree(hubp2);
1233 	return NULL;
1234 }
1235 
1236 static bool dcn30_dwbc_create(struct dc_context *ctx, struct resource_pool *pool)
1237 {
1238 	int i;
1239 	uint32_t pipe_count = pool->res_cap->num_dwb;
1240 
1241 	for (i = 0; i < pipe_count; i++) {
1242 		struct dcn30_dwbc *dwbc30 = kzalloc(sizeof(struct dcn30_dwbc),
1243 						    GFP_KERNEL);
1244 
1245 		if (!dwbc30) {
1246 			dm_error("DC: failed to create dwbc30!\n");
1247 			return false;
1248 		}
1249 
1250 		dcn30_dwbc_construct(dwbc30, ctx,
1251 				&dwbc30_regs[i],
1252 				&dwbc30_shift,
1253 				&dwbc30_mask,
1254 				i);
1255 
1256 		pool->dwbc[i] = &dwbc30->base;
1257 	}
1258 	return true;
1259 }
1260 
1261 static bool dcn30_mmhubbub_create(struct dc_context *ctx, struct resource_pool *pool)
1262 {
1263 	int i;
1264 	uint32_t pipe_count = pool->res_cap->num_dwb;
1265 
1266 	for (i = 0; i < pipe_count; i++) {
1267 		struct dcn30_mmhubbub *mcif_wb30 = kzalloc(sizeof(struct dcn30_mmhubbub),
1268 						    GFP_KERNEL);
1269 
1270 		if (!mcif_wb30) {
1271 			dm_error("DC: failed to create mcif_wb30!\n");
1272 			return false;
1273 		}
1274 
1275 		dcn30_mmhubbub_construct(mcif_wb30, ctx,
1276 				&mcif_wb30_regs[i],
1277 				&mcif_wb30_shift,
1278 				&mcif_wb30_mask,
1279 				i);
1280 
1281 		pool->mcif_wb[i] = &mcif_wb30->base;
1282 	}
1283 	return true;
1284 }
1285 
1286 static struct display_stream_compressor *dcn30_dsc_create(
1287 	struct dc_context *ctx, uint32_t inst)
1288 {
1289 	struct dcn20_dsc *dsc =
1290 		kzalloc(sizeof(struct dcn20_dsc), GFP_KERNEL);
1291 
1292 	if (!dsc) {
1293 		BREAK_TO_DEBUGGER();
1294 		return NULL;
1295 	}
1296 
1297 	dsc2_construct(dsc, ctx, inst, &dsc_regs[inst], &dsc_shift, &dsc_mask);
1298 	return &dsc->base;
1299 }
1300 
1301 enum dc_status dcn30_add_stream_to_ctx(struct dc *dc, struct dc_state *new_ctx, struct dc_stream_state *dc_stream)
1302 {
1303 
1304 	return dcn20_add_stream_to_ctx(dc, new_ctx, dc_stream);
1305 }
1306 
1307 static void dcn30_destroy_resource_pool(struct resource_pool **pool)
1308 {
1309 	struct dcn30_resource_pool *dcn30_pool = TO_DCN30_RES_POOL(*pool);
1310 
1311 	dcn30_resource_destruct(dcn30_pool);
1312 	kfree(dcn30_pool);
1313 	*pool = NULL;
1314 }
1315 
1316 static struct clock_source *dcn30_clock_source_create(
1317 		struct dc_context *ctx,
1318 		struct dc_bios *bios,
1319 		enum clock_source_id id,
1320 		const struct dce110_clk_src_regs *regs,
1321 		bool dp_clk_src)
1322 {
1323 	struct dce110_clk_src *clk_src =
1324 		kzalloc(sizeof(struct dce110_clk_src), GFP_KERNEL);
1325 
1326 	if (!clk_src)
1327 		return NULL;
1328 
1329 	if (dcn3_clk_src_construct(clk_src, ctx, bios, id,
1330 			regs, &cs_shift, &cs_mask)) {
1331 		clk_src->base.dp_clk_src = dp_clk_src;
1332 		return &clk_src->base;
1333 	}
1334 
1335 	kfree(clk_src);
1336 	BREAK_TO_DEBUGGER();
1337 	return NULL;
1338 }
1339 
1340 int dcn30_populate_dml_pipes_from_context(
1341 	struct dc *dc, struct dc_state *context,
1342 	display_e2e_pipe_params_st *pipes,
1343 	bool fast_validate)
1344 {
1345 	int i, pipe_cnt;
1346 	struct resource_context *res_ctx = &context->res_ctx;
1347 
1348 	DC_FP_START();
1349 	dcn20_populate_dml_pipes_from_context(dc, context, pipes, fast_validate);
1350 	DC_FP_END();
1351 
1352 	for (i = 0, pipe_cnt = 0; i < dc->res_pool->pipe_count; i++) {
1353 		if (!res_ctx->pipe_ctx[i].stream)
1354 			continue;
1355 
1356 		pipes[pipe_cnt++].pipe.scale_ratio_depth.lb_depth =
1357 			dm_lb_16;
1358 	}
1359 
1360 	return pipe_cnt;
1361 }
1362 
1363 void dcn30_populate_dml_writeback_from_context(
1364 	struct dc *dc, struct resource_context *res_ctx, display_e2e_pipe_params_st *pipes)
1365 {
1366 	DC_FP_START();
1367 	dcn30_fpu_populate_dml_writeback_from_context(dc, res_ctx, pipes);
1368 	DC_FP_END();
1369 }
1370 
1371 unsigned int dcn30_calc_max_scaled_time(
1372 		unsigned int time_per_pixel,
1373 		enum mmhubbub_wbif_mode mode,
1374 		unsigned int urgent_watermark)
1375 {
1376 	unsigned int time_per_byte = 0;
1377 	unsigned int total_free_entry = 0xb40;
1378 	unsigned int buf_lh_capability;
1379 	unsigned int max_scaled_time;
1380 
1381 	if (mode == PACKED_444) /* packed mode 32 bpp */
1382 		time_per_byte = time_per_pixel/4;
1383 	else if (mode == PACKED_444_FP16) /* packed mode 64 bpp */
1384 		time_per_byte = time_per_pixel/8;
1385 
1386 	if (time_per_byte == 0)
1387 		time_per_byte = 1;
1388 
1389 	buf_lh_capability = (total_free_entry*time_per_byte*32) >> 6; /* time_per_byte is in u6.6*/
1390 	max_scaled_time   = buf_lh_capability - urgent_watermark;
1391 	return max_scaled_time;
1392 }
1393 
1394 void dcn30_set_mcif_arb_params(
1395 		struct dc *dc,
1396 		struct dc_state *context,
1397 		display_e2e_pipe_params_st *pipes,
1398 		int pipe_cnt)
1399 {
1400 	enum mmhubbub_wbif_mode wbif_mode;
1401 	struct display_mode_lib *dml = &context->bw_ctx.dml;
1402 	struct mcif_arb_params *wb_arb_params;
1403 	int i, j, dwb_pipe;
1404 
1405 	/* Writeback MCIF_WB arbitration parameters */
1406 	dwb_pipe = 0;
1407 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
1408 
1409 		if (!context->res_ctx.pipe_ctx[i].stream)
1410 			continue;
1411 
1412 		for (j = 0; j < MAX_DWB_PIPES; j++) {
1413 			struct dc_writeback_info *writeback_info = &context->res_ctx.pipe_ctx[i].stream->writeback_info[j];
1414 
1415 			if (writeback_info->wb_enabled == false)
1416 				continue;
1417 
1418 			//wb_arb_params = &context->res_ctx.pipe_ctx[i].stream->writeback_info[j].mcif_arb_params;
1419 			wb_arb_params = &context->bw_ctx.bw.dcn.bw_writeback.mcif_wb_arb[dwb_pipe];
1420 
1421 			if (writeback_info->dwb_params.cnv_params.fc_out_format == DWB_OUT_FORMAT_64BPP_ARGB ||
1422 				writeback_info->dwb_params.cnv_params.fc_out_format == DWB_OUT_FORMAT_64BPP_RGBA)
1423 				wbif_mode = PACKED_444_FP16;
1424 			else
1425 				wbif_mode = PACKED_444;
1426 
1427 			DC_FP_START();
1428 			dcn30_fpu_set_mcif_arb_params(wb_arb_params, dml, pipes, pipe_cnt, j);
1429 			DC_FP_END();
1430 			wb_arb_params->time_per_pixel = (1000000 << 6) / context->res_ctx.pipe_ctx[i].stream->phy_pix_clk; /* time_per_pixel should be in u6.6 format */
1431 			wb_arb_params->slice_lines = 32;
1432 			wb_arb_params->arbitration_slice = 2; /* irrelevant since there is no YUV output */
1433 			wb_arb_params->max_scaled_time = dcn30_calc_max_scaled_time(wb_arb_params->time_per_pixel,
1434 					wbif_mode,
1435 					wb_arb_params->cli_watermark[0]); /* assume 4 watermark sets have the same value */
1436 
1437 			dwb_pipe++;
1438 
1439 			if (dwb_pipe >= MAX_DWB_PIPES)
1440 				return;
1441 		}
1442 		if (dwb_pipe >= MAX_DWB_PIPES)
1443 			return;
1444 	}
1445 
1446 }
1447 
1448 static struct dc_cap_funcs cap_funcs = {
1449 	.get_dcc_compression_cap = dcn20_get_dcc_compression_cap
1450 };
1451 
1452 bool dcn30_acquire_post_bldn_3dlut(
1453 		struct resource_context *res_ctx,
1454 		const struct resource_pool *pool,
1455 		int mpcc_id,
1456 		struct dc_3dlut **lut,
1457 		struct dc_transfer_func **shaper)
1458 {
1459 	int i;
1460 	bool ret = false;
1461 	union dc_3dlut_state *state;
1462 
1463 	ASSERT(*lut == NULL && *shaper == NULL);
1464 	*lut = NULL;
1465 	*shaper = NULL;
1466 
1467 	for (i = 0; i < pool->res_cap->num_mpc_3dlut; i++) {
1468 		if (!res_ctx->is_mpc_3dlut_acquired[i]) {
1469 			*lut = pool->mpc_lut[i];
1470 			*shaper = pool->mpc_shaper[i];
1471 			state = &pool->mpc_lut[i]->state;
1472 			res_ctx->is_mpc_3dlut_acquired[i] = true;
1473 			state->bits.rmu_idx_valid = 1;
1474 			state->bits.rmu_mux_num = i;
1475 			if (state->bits.rmu_mux_num == 0)
1476 				state->bits.mpc_rmu0_mux = mpcc_id;
1477 			else if (state->bits.rmu_mux_num == 1)
1478 				state->bits.mpc_rmu1_mux = mpcc_id;
1479 			else if (state->bits.rmu_mux_num == 2)
1480 				state->bits.mpc_rmu2_mux = mpcc_id;
1481 			ret = true;
1482 			break;
1483 		}
1484 	}
1485 	return ret;
1486 }
1487 
1488 bool dcn30_release_post_bldn_3dlut(
1489 		struct resource_context *res_ctx,
1490 		const struct resource_pool *pool,
1491 		struct dc_3dlut **lut,
1492 		struct dc_transfer_func **shaper)
1493 {
1494 	int i;
1495 	bool ret = false;
1496 
1497 	for (i = 0; i < pool->res_cap->num_mpc_3dlut; i++) {
1498 		if (pool->mpc_lut[i] == *lut && pool->mpc_shaper[i] == *shaper) {
1499 			res_ctx->is_mpc_3dlut_acquired[i] = false;
1500 			pool->mpc_lut[i]->state.raw = 0;
1501 			*lut = NULL;
1502 			*shaper = NULL;
1503 			ret = true;
1504 			break;
1505 		}
1506 	}
1507 	return ret;
1508 }
1509 
1510 static bool is_soc_bounding_box_valid(struct dc *dc)
1511 {
1512 	uint32_t hw_internal_rev = dc->ctx->asic_id.hw_internal_rev;
1513 
1514 	if (ASICREV_IS_SIENNA_CICHLID_P(hw_internal_rev))
1515 		return true;
1516 
1517 	return false;
1518 }
1519 
1520 static bool init_soc_bounding_box(struct dc *dc,
1521 				  struct dcn30_resource_pool *pool)
1522 {
1523 	struct _vcs_dpi_soc_bounding_box_st *loaded_bb = &dcn3_0_soc;
1524 	struct _vcs_dpi_ip_params_st *loaded_ip = &dcn3_0_ip;
1525 
1526 	DC_LOGGER_INIT(dc->ctx->logger);
1527 
1528 	if (!is_soc_bounding_box_valid(dc)) {
1529 		DC_LOG_ERROR("%s: not valid soc bounding box\n", __func__);
1530 		return false;
1531 	}
1532 
1533 	loaded_ip->max_num_otg = pool->base.res_cap->num_timing_generator;
1534 	loaded_ip->max_num_dpp = pool->base.pipe_count;
1535 	loaded_ip->clamp_min_dcfclk = dc->config.clamp_min_dcfclk;
1536 	dcn20_patch_bounding_box(dc, loaded_bb);
1537 	DC_FP_START();
1538 	patch_dcn30_soc_bounding_box(dc, &dcn3_0_soc);
1539 	DC_FP_END();
1540 
1541 	return true;
1542 }
1543 
1544 static bool dcn30_split_stream_for_mpc_or_odm(
1545 		const struct dc *dc,
1546 		struct resource_context *res_ctx,
1547 		struct pipe_ctx *pri_pipe,
1548 		struct pipe_ctx *sec_pipe,
1549 		bool odm)
1550 {
1551 	int pipe_idx = sec_pipe->pipe_idx;
1552 	const struct resource_pool *pool = dc->res_pool;
1553 
1554 	*sec_pipe = *pri_pipe;
1555 
1556 	sec_pipe->pipe_idx = pipe_idx;
1557 	sec_pipe->plane_res.mi = pool->mis[pipe_idx];
1558 	sec_pipe->plane_res.hubp = pool->hubps[pipe_idx];
1559 	sec_pipe->plane_res.ipp = pool->ipps[pipe_idx];
1560 	sec_pipe->plane_res.xfm = pool->transforms[pipe_idx];
1561 	sec_pipe->plane_res.dpp = pool->dpps[pipe_idx];
1562 	sec_pipe->plane_res.mpcc_inst = pool->dpps[pipe_idx]->inst;
1563 	sec_pipe->stream_res.dsc = NULL;
1564 	if (odm) {
1565 		if (pri_pipe->next_odm_pipe) {
1566 			ASSERT(pri_pipe->next_odm_pipe != sec_pipe);
1567 			sec_pipe->next_odm_pipe = pri_pipe->next_odm_pipe;
1568 			sec_pipe->next_odm_pipe->prev_odm_pipe = sec_pipe;
1569 		}
1570 		if (pri_pipe->top_pipe && pri_pipe->top_pipe->next_odm_pipe) {
1571 			pri_pipe->top_pipe->next_odm_pipe->bottom_pipe = sec_pipe;
1572 			sec_pipe->top_pipe = pri_pipe->top_pipe->next_odm_pipe;
1573 		}
1574 		if (pri_pipe->bottom_pipe && pri_pipe->bottom_pipe->next_odm_pipe) {
1575 			pri_pipe->bottom_pipe->next_odm_pipe->top_pipe = sec_pipe;
1576 			sec_pipe->bottom_pipe = pri_pipe->bottom_pipe->next_odm_pipe;
1577 		}
1578 		pri_pipe->next_odm_pipe = sec_pipe;
1579 		sec_pipe->prev_odm_pipe = pri_pipe;
1580 
1581 		if (!sec_pipe->top_pipe)
1582 			sec_pipe->stream_res.opp = pool->opps[pipe_idx];
1583 		else
1584 			sec_pipe->stream_res.opp = sec_pipe->top_pipe->stream_res.opp;
1585 		if (sec_pipe->stream->timing.flags.DSC == 1) {
1586 			dcn20_acquire_dsc(dc, res_ctx, &sec_pipe->stream_res.dsc, pipe_idx);
1587 			ASSERT(sec_pipe->stream_res.dsc);
1588 			if (sec_pipe->stream_res.dsc == NULL)
1589 				return false;
1590 		}
1591 	} else {
1592 		if (pri_pipe->bottom_pipe) {
1593 			ASSERT(pri_pipe->bottom_pipe != sec_pipe);
1594 			sec_pipe->bottom_pipe = pri_pipe->bottom_pipe;
1595 			sec_pipe->bottom_pipe->top_pipe = sec_pipe;
1596 		}
1597 		pri_pipe->bottom_pipe = sec_pipe;
1598 		sec_pipe->top_pipe = pri_pipe;
1599 
1600 		ASSERT(pri_pipe->plane_state);
1601 	}
1602 
1603 	return true;
1604 }
1605 
1606 static struct pipe_ctx *dcn30_find_split_pipe(
1607 		struct dc *dc,
1608 		struct dc_state *context,
1609 		int old_index)
1610 {
1611 	struct pipe_ctx *pipe = NULL;
1612 	int i;
1613 
1614 	if (old_index >= 0 && context->res_ctx.pipe_ctx[old_index].stream == NULL) {
1615 		pipe = &context->res_ctx.pipe_ctx[old_index];
1616 		pipe->pipe_idx = old_index;
1617 	}
1618 
1619 	if (!pipe)
1620 		for (i = dc->res_pool->pipe_count - 1; i >= 0; i--) {
1621 			if (dc->current_state->res_ctx.pipe_ctx[i].top_pipe == NULL
1622 					&& dc->current_state->res_ctx.pipe_ctx[i].prev_odm_pipe == NULL) {
1623 				if (context->res_ctx.pipe_ctx[i].stream == NULL) {
1624 					pipe = &context->res_ctx.pipe_ctx[i];
1625 					pipe->pipe_idx = i;
1626 					break;
1627 				}
1628 			}
1629 		}
1630 
1631 	/*
1632 	 * May need to fix pipes getting tossed from 1 opp to another on flip
1633 	 * Add for debugging transient underflow during topology updates:
1634 	 * ASSERT(pipe);
1635 	 */
1636 	if (!pipe)
1637 		for (i = dc->res_pool->pipe_count - 1; i >= 0; i--) {
1638 			if (context->res_ctx.pipe_ctx[i].stream == NULL) {
1639 				pipe = &context->res_ctx.pipe_ctx[i];
1640 				pipe->pipe_idx = i;
1641 				break;
1642 			}
1643 		}
1644 
1645 	return pipe;
1646 }
1647 
1648 noinline bool dcn30_internal_validate_bw(
1649 		struct dc *dc,
1650 		struct dc_state *context,
1651 		display_e2e_pipe_params_st *pipes,
1652 		int *pipe_cnt_out,
1653 		int *vlevel_out,
1654 		bool fast_validate,
1655 		bool allow_self_refresh_only)
1656 {
1657 	bool out = false;
1658 	bool repopulate_pipes = false;
1659 	int split[MAX_PIPES] = { 0 };
1660 	bool merge[MAX_PIPES] = { false };
1661 	bool newly_split[MAX_PIPES] = { false };
1662 	int pipe_cnt, i, pipe_idx, vlevel;
1663 	struct vba_vars_st *vba = &context->bw_ctx.dml.vba;
1664 
1665 	ASSERT(pipes);
1666 	if (!pipes)
1667 		return false;
1668 
1669 	context->bw_ctx.dml.vba.maxMpcComb = 0;
1670 	context->bw_ctx.dml.vba.VoltageLevel = 0;
1671 	context->bw_ctx.dml.vba.DRAMClockChangeSupport[0][0] = dm_dram_clock_change_vactive;
1672 	dc->res_pool->funcs->update_soc_for_wm_a(dc, context);
1673 	pipe_cnt = dc->res_pool->funcs->populate_dml_pipes(dc, context, pipes, fast_validate);
1674 
1675 	if (!pipe_cnt) {
1676 		out = true;
1677 		goto validate_out;
1678 	}
1679 
1680 	dml_log_pipe_params(&context->bw_ctx.dml, pipes, pipe_cnt);
1681 
1682 	if (!fast_validate || !allow_self_refresh_only) {
1683 		/*
1684 		 * DML favors voltage over p-state, but we're more interested in
1685 		 * supporting p-state over voltage. We can't support p-state in
1686 		 * prefetch mode > 0 so try capping the prefetch mode to start.
1687 		 */
1688 		context->bw_ctx.dml.soc.allow_dram_self_refresh_or_dram_clock_change_in_vblank =
1689 			dm_allow_self_refresh_and_mclk_switch;
1690 		vlevel = dml_get_voltage_level(&context->bw_ctx.dml, pipes, pipe_cnt);
1691 		/* This may adjust vlevel and maxMpcComb */
1692 		if (vlevel < context->bw_ctx.dml.soc.num_states)
1693 			vlevel = dcn20_validate_apply_pipe_split_flags(dc, context, vlevel, split, merge);
1694 	}
1695 	if (allow_self_refresh_only &&
1696 	    (fast_validate || vlevel == context->bw_ctx.dml.soc.num_states ||
1697 			vba->DRAMClockChangeSupport[vlevel][vba->maxMpcComb] == dm_dram_clock_change_unsupported)) {
1698 		/*
1699 		 * If mode is unsupported or there's still no p-state support
1700 		 * then fall back to favoring voltage.
1701 		 *
1702 		 * We don't actually support prefetch mode 2, so require that we
1703 		 * at least support prefetch mode 1.
1704 		 */
1705 		context->bw_ctx.dml.soc.allow_dram_self_refresh_or_dram_clock_change_in_vblank =
1706 			dm_allow_self_refresh;
1707 
1708 		vlevel = dml_get_voltage_level(&context->bw_ctx.dml, pipes, pipe_cnt);
1709 		if (vlevel < context->bw_ctx.dml.soc.num_states) {
1710 			memset(split, 0, sizeof(split));
1711 			memset(merge, 0, sizeof(merge));
1712 			vlevel = dcn20_validate_apply_pipe_split_flags(dc, context, vlevel, split, merge);
1713 		}
1714 	}
1715 
1716 	dml_log_mode_support_params(&context->bw_ctx.dml);
1717 
1718 	if (vlevel == context->bw_ctx.dml.soc.num_states)
1719 		goto validate_fail;
1720 
1721 	if (!dc->config.enable_windowed_mpo_odm) {
1722 		for (i = 0, pipe_idx = 0; i < dc->res_pool->pipe_count; i++) {
1723 			struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1724 			struct pipe_ctx *mpo_pipe = pipe->bottom_pipe;
1725 
1726 			if (!pipe->stream)
1727 				continue;
1728 
1729 			/* We only support full screen mpo with ODM */
1730 			if (vba->ODMCombineEnabled[vba->pipe_plane[pipe_idx]] != dm_odm_combine_mode_disabled
1731 					&& pipe->plane_state && mpo_pipe
1732 					&& memcmp(&mpo_pipe->plane_res.scl_data.recout,
1733 							&pipe->plane_res.scl_data.recout,
1734 							sizeof(struct rect)) != 0) {
1735 				ASSERT(mpo_pipe->plane_state != pipe->plane_state);
1736 				goto validate_fail;
1737 			}
1738 			pipe_idx++;
1739 		}
1740 	}
1741 
1742 	/* merge pipes if necessary */
1743 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
1744 		struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1745 
1746 		/*skip pipes that don't need merging*/
1747 		if (!merge[i])
1748 			continue;
1749 
1750 		/* if ODM merge we ignore mpc tree, mpo pipes will have their own flags */
1751 		if (pipe->prev_odm_pipe) {
1752 			/*split off odm pipe*/
1753 			pipe->prev_odm_pipe->next_odm_pipe = pipe->next_odm_pipe;
1754 			if (pipe->next_odm_pipe)
1755 				pipe->next_odm_pipe->prev_odm_pipe = pipe->prev_odm_pipe;
1756 
1757 			pipe->bottom_pipe = NULL;
1758 			pipe->next_odm_pipe = NULL;
1759 			pipe->plane_state = NULL;
1760 			pipe->stream = NULL;
1761 			pipe->top_pipe = NULL;
1762 			pipe->prev_odm_pipe = NULL;
1763 			if (pipe->stream_res.dsc)
1764 				dcn20_release_dsc(&context->res_ctx, dc->res_pool, &pipe->stream_res.dsc);
1765 			memset(&pipe->plane_res, 0, sizeof(pipe->plane_res));
1766 			memset(&pipe->stream_res, 0, sizeof(pipe->stream_res));
1767 			repopulate_pipes = true;
1768 		} else if (pipe->top_pipe && pipe->top_pipe->plane_state == pipe->plane_state) {
1769 			struct pipe_ctx *top_pipe = pipe->top_pipe;
1770 			struct pipe_ctx *bottom_pipe = pipe->bottom_pipe;
1771 
1772 			top_pipe->bottom_pipe = bottom_pipe;
1773 			if (bottom_pipe)
1774 				bottom_pipe->top_pipe = top_pipe;
1775 
1776 			pipe->top_pipe = NULL;
1777 			pipe->bottom_pipe = NULL;
1778 			pipe->plane_state = NULL;
1779 			pipe->stream = NULL;
1780 			memset(&pipe->plane_res, 0, sizeof(pipe->plane_res));
1781 			memset(&pipe->stream_res, 0, sizeof(pipe->stream_res));
1782 			repopulate_pipes = true;
1783 		} else
1784 			ASSERT(0); /* Should never try to merge master pipe */
1785 
1786 	}
1787 
1788 	for (i = 0, pipe_idx = -1; i < dc->res_pool->pipe_count; i++) {
1789 		struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1790 		struct pipe_ctx *old_pipe = &dc->current_state->res_ctx.pipe_ctx[i];
1791 		struct pipe_ctx *hsplit_pipe = NULL;
1792 		bool odm;
1793 		int old_index = -1;
1794 
1795 		if (!pipe->stream || newly_split[i])
1796 			continue;
1797 
1798 		pipe_idx++;
1799 		odm = vba->ODMCombineEnabled[vba->pipe_plane[pipe_idx]] != dm_odm_combine_mode_disabled;
1800 
1801 		if (!pipe->plane_state && !odm)
1802 			continue;
1803 
1804 		if (split[i]) {
1805 			if (odm) {
1806 				if (split[i] == 4 && old_pipe->next_odm_pipe && old_pipe->next_odm_pipe->next_odm_pipe)
1807 					old_index = old_pipe->next_odm_pipe->next_odm_pipe->pipe_idx;
1808 				else if (old_pipe->next_odm_pipe)
1809 					old_index = old_pipe->next_odm_pipe->pipe_idx;
1810 			} else {
1811 				if (split[i] == 4 && old_pipe->bottom_pipe && old_pipe->bottom_pipe->bottom_pipe &&
1812 						old_pipe->bottom_pipe->bottom_pipe->plane_state == old_pipe->plane_state)
1813 					old_index = old_pipe->bottom_pipe->bottom_pipe->pipe_idx;
1814 				else if (old_pipe->bottom_pipe &&
1815 						old_pipe->bottom_pipe->plane_state == old_pipe->plane_state)
1816 					old_index = old_pipe->bottom_pipe->pipe_idx;
1817 			}
1818 			hsplit_pipe = dcn30_find_split_pipe(dc, context, old_index);
1819 			ASSERT(hsplit_pipe);
1820 			if (!hsplit_pipe)
1821 				goto validate_fail;
1822 
1823 			if (!dcn30_split_stream_for_mpc_or_odm(
1824 					dc, &context->res_ctx,
1825 					pipe, hsplit_pipe, odm))
1826 				goto validate_fail;
1827 
1828 			newly_split[hsplit_pipe->pipe_idx] = true;
1829 			repopulate_pipes = true;
1830 		}
1831 		if (split[i] == 4) {
1832 			struct pipe_ctx *pipe_4to1;
1833 
1834 			if (odm && old_pipe->next_odm_pipe)
1835 				old_index = old_pipe->next_odm_pipe->pipe_idx;
1836 			else if (!odm && old_pipe->bottom_pipe &&
1837 						old_pipe->bottom_pipe->plane_state == old_pipe->plane_state)
1838 				old_index = old_pipe->bottom_pipe->pipe_idx;
1839 			else
1840 				old_index = -1;
1841 			pipe_4to1 = dcn30_find_split_pipe(dc, context, old_index);
1842 			ASSERT(pipe_4to1);
1843 			if (!pipe_4to1)
1844 				goto validate_fail;
1845 			if (!dcn30_split_stream_for_mpc_or_odm(
1846 					dc, &context->res_ctx,
1847 					pipe, pipe_4to1, odm))
1848 				goto validate_fail;
1849 			newly_split[pipe_4to1->pipe_idx] = true;
1850 
1851 			if (odm && old_pipe->next_odm_pipe && old_pipe->next_odm_pipe->next_odm_pipe
1852 					&& old_pipe->next_odm_pipe->next_odm_pipe->next_odm_pipe)
1853 				old_index = old_pipe->next_odm_pipe->next_odm_pipe->next_odm_pipe->pipe_idx;
1854 			else if (!odm && old_pipe->bottom_pipe && old_pipe->bottom_pipe->bottom_pipe &&
1855 					old_pipe->bottom_pipe->bottom_pipe->bottom_pipe &&
1856 					old_pipe->bottom_pipe->bottom_pipe->bottom_pipe->plane_state == old_pipe->plane_state)
1857 				old_index = old_pipe->bottom_pipe->bottom_pipe->bottom_pipe->pipe_idx;
1858 			else
1859 				old_index = -1;
1860 			pipe_4to1 = dcn30_find_split_pipe(dc, context, old_index);
1861 			ASSERT(pipe_4to1);
1862 			if (!pipe_4to1)
1863 				goto validate_fail;
1864 			if (!dcn30_split_stream_for_mpc_or_odm(
1865 					dc, &context->res_ctx,
1866 					hsplit_pipe, pipe_4to1, odm))
1867 				goto validate_fail;
1868 			newly_split[pipe_4to1->pipe_idx] = true;
1869 		}
1870 		if (odm)
1871 			dcn20_build_mapped_resource(dc, context, pipe->stream);
1872 	}
1873 
1874 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
1875 		struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1876 
1877 		if (pipe->plane_state) {
1878 			if (!resource_build_scaling_params(pipe))
1879 				goto validate_fail;
1880 		}
1881 	}
1882 
1883 	/* Actual dsc count per stream dsc validation*/
1884 	if (!dcn20_validate_dsc(dc, context)) {
1885 		vba->ValidationStatus[vba->soc.num_states] = DML_FAIL_DSC_VALIDATION_FAILURE;
1886 		goto validate_fail;
1887 	}
1888 
1889 	if (repopulate_pipes)
1890 		pipe_cnt = dc->res_pool->funcs->populate_dml_pipes(dc, context, pipes, fast_validate);
1891 	context->bw_ctx.dml.vba.VoltageLevel = vlevel;
1892 	*vlevel_out = vlevel;
1893 	*pipe_cnt_out = pipe_cnt;
1894 
1895 	out = true;
1896 	goto validate_out;
1897 
1898 validate_fail:
1899 	out = false;
1900 
1901 validate_out:
1902 	return out;
1903 }
1904 
1905 static int get_refresh_rate(struct dc_state *context)
1906 {
1907 	int refresh_rate = 0;
1908 	int h_v_total = 0;
1909 	struct dc_crtc_timing *timing = NULL;
1910 
1911 	if (context == NULL || context->streams[0] == NULL)
1912 		return 0;
1913 
1914 	/* check if refresh rate at least 120hz */
1915 	timing = &context->streams[0]->timing;
1916 	if (timing == NULL)
1917 		return 0;
1918 
1919 	h_v_total = timing->h_total * timing->v_total;
1920 	if (h_v_total == 0)
1921 		return 0;
1922 
1923 	refresh_rate = ((timing->pix_clk_100hz * 100) / (h_v_total)) + 1;
1924 	return refresh_rate;
1925 }
1926 
1927 #define MAX_STRETCHED_V_BLANK 500 // in micro-seconds
1928 /*
1929  * Scaling factor for v_blank stretch calculations considering timing in
1930  * micro-seconds and pixel clock in 100hz.
1931  * Note: the parenthesis are necessary to ensure the correct order of
1932  * operation where V_SCALE is used.
1933  */
1934 #define V_SCALE (10000 / MAX_STRETCHED_V_BLANK)
1935 
1936 static int get_frame_rate_at_max_stretch_100hz(struct dc_state *context)
1937 {
1938 	struct dc_crtc_timing *timing = NULL;
1939 	uint32_t sec_per_100_lines;
1940 	uint32_t max_v_blank;
1941 	uint32_t curr_v_blank;
1942 	uint32_t v_stretch_max;
1943 	uint32_t stretched_frame_pix_cnt;
1944 	uint32_t scaled_stretched_frame_pix_cnt;
1945 	uint32_t scaled_refresh_rate;
1946 
1947 	if (context == NULL || context->streams[0] == NULL)
1948 		return 0;
1949 
1950 	/* check if refresh rate at least 120hz */
1951 	timing = &context->streams[0]->timing;
1952 	if (timing == NULL)
1953 		return 0;
1954 
1955 	sec_per_100_lines = timing->pix_clk_100hz / timing->h_total + 1;
1956 	max_v_blank = sec_per_100_lines / V_SCALE + 1;
1957 	curr_v_blank = timing->v_total - timing->v_addressable;
1958 	v_stretch_max = (max_v_blank > curr_v_blank) ? (max_v_blank - curr_v_blank) : (0);
1959 	stretched_frame_pix_cnt = (v_stretch_max + timing->v_total) * timing->h_total;
1960 	scaled_stretched_frame_pix_cnt = stretched_frame_pix_cnt / 10000;
1961 	scaled_refresh_rate = (timing->pix_clk_100hz) / scaled_stretched_frame_pix_cnt + 1;
1962 
1963 	return scaled_refresh_rate;
1964 }
1965 
1966 static bool is_refresh_rate_support_mclk_switch_using_fw_based_vblank_stretch(struct dc_state *context)
1967 {
1968 	int refresh_rate_max_stretch_100hz;
1969 	int min_refresh_100hz;
1970 
1971 	if (context == NULL || context->streams[0] == NULL)
1972 		return false;
1973 
1974 	refresh_rate_max_stretch_100hz = get_frame_rate_at_max_stretch_100hz(context);
1975 	min_refresh_100hz = context->streams[0]->timing.min_refresh_in_uhz / 10000;
1976 
1977 	if (refresh_rate_max_stretch_100hz < min_refresh_100hz)
1978 		return false;
1979 
1980 	return true;
1981 }
1982 
1983 bool dcn30_can_support_mclk_switch_using_fw_based_vblank_stretch(struct dc *dc, struct dc_state *context)
1984 {
1985 	int refresh_rate = 0;
1986 	const int minimum_refreshrate_supported = 120;
1987 
1988 	if (context == NULL || context->streams[0] == NULL)
1989 		return false;
1990 
1991 	if (context->streams[0]->sink->edid_caps.panel_patch.disable_fams)
1992 		return false;
1993 
1994 	if (dc->debug.disable_fams)
1995 		return false;
1996 
1997 	if (!dc->caps.dmub_caps.mclk_sw)
1998 		return false;
1999 
2000 	if (context->bw_ctx.bw.dcn.clk.fw_based_mclk_switching_shut_down)
2001 		return false;
2002 
2003 	/* more then 1 monitor connected */
2004 	if (context->stream_count != 1)
2005 		return false;
2006 
2007 	refresh_rate = get_refresh_rate(context);
2008 	if (refresh_rate < minimum_refreshrate_supported)
2009 		return false;
2010 
2011 	if (!is_refresh_rate_support_mclk_switch_using_fw_based_vblank_stretch(context))
2012 		return false;
2013 
2014 	// check if freesync enabled
2015 	if (!context->streams[0]->allow_freesync)
2016 		return false;
2017 
2018 	if (context->streams[0]->vrr_active_variable)
2019 		return false;
2020 
2021 	context->streams[0]->fpo_in_use = true;
2022 
2023 	return true;
2024 }
2025 
2026 /*
2027  * set up FPO watermarks, pstate, dram latency
2028  */
2029 void dcn30_setup_mclk_switch_using_fw_based_vblank_stretch(struct dc *dc, struct dc_state *context)
2030 {
2031 	ASSERT(dc != NULL && context != NULL);
2032 	if (dc == NULL || context == NULL)
2033 		return;
2034 
2035 	/* Set wm_a.pstate so high natural MCLK switches are impossible: 4 seconds */
2036 	context->bw_ctx.bw.dcn.watermarks.a.cstate_pstate.pstate_change_ns = 4U * 1000U * 1000U * 1000U;
2037 }
2038 
2039 void dcn30_update_soc_for_wm_a(struct dc *dc, struct dc_state *context)
2040 {
2041 	DC_FP_START();
2042 	dcn30_fpu_update_soc_for_wm_a(dc, context);
2043 	DC_FP_END();
2044 }
2045 
2046 void dcn30_calculate_wm_and_dlg(
2047 		struct dc *dc, struct dc_state *context,
2048 		display_e2e_pipe_params_st *pipes,
2049 		int pipe_cnt,
2050 		int vlevel)
2051 {
2052 	DC_FP_START();
2053 	dcn30_fpu_calculate_wm_and_dlg(dc, context, pipes, pipe_cnt, vlevel);
2054 	DC_FP_END();
2055 }
2056 
2057 bool dcn30_validate_bandwidth(struct dc *dc,
2058 		struct dc_state *context,
2059 		bool fast_validate)
2060 {
2061 	bool out = false;
2062 
2063 	BW_VAL_TRACE_SETUP();
2064 
2065 	int vlevel = 0;
2066 	int pipe_cnt = 0;
2067 	display_e2e_pipe_params_st *pipes = kzalloc(dc->res_pool->pipe_count * sizeof(display_e2e_pipe_params_st), GFP_KERNEL);
2068 	DC_LOGGER_INIT(dc->ctx->logger);
2069 
2070 	BW_VAL_TRACE_COUNT();
2071 
2072 	DC_FP_START();
2073 	out = dcn30_internal_validate_bw(dc, context, pipes, &pipe_cnt, &vlevel, fast_validate, true);
2074 	DC_FP_END();
2075 
2076 	if (pipe_cnt == 0)
2077 		goto validate_out;
2078 
2079 	if (!out)
2080 		goto validate_fail;
2081 
2082 	BW_VAL_TRACE_END_VOLTAGE_LEVEL();
2083 
2084 	if (fast_validate) {
2085 		BW_VAL_TRACE_SKIP(fast);
2086 		goto validate_out;
2087 	}
2088 
2089 	DC_FP_START();
2090 	dc->res_pool->funcs->calculate_wm_and_dlg(dc, context, pipes, pipe_cnt, vlevel);
2091 	DC_FP_END();
2092 
2093 	BW_VAL_TRACE_END_WATERMARKS();
2094 
2095 	goto validate_out;
2096 
2097 validate_fail:
2098 	DC_LOG_WARNING("Mode Validation Warning: %s failed validation.\n",
2099 		dml_get_status_message(context->bw_ctx.dml.vba.ValidationStatus[context->bw_ctx.dml.vba.soc.num_states]));
2100 
2101 	BW_VAL_TRACE_SKIP(fail);
2102 	out = false;
2103 
2104 validate_out:
2105 	kfree(pipes);
2106 
2107 	BW_VAL_TRACE_FINISH();
2108 
2109 	return out;
2110 }
2111 
2112 void dcn30_update_bw_bounding_box(struct dc *dc, struct clk_bw_params *bw_params)
2113 {
2114 	unsigned int i, j;
2115 	unsigned int num_states = 0;
2116 
2117 	unsigned int dcfclk_mhz[DC__VOLTAGE_STATES] = {0};
2118 	unsigned int dram_speed_mts[DC__VOLTAGE_STATES] = {0};
2119 	unsigned int optimal_uclk_for_dcfclk_sta_targets[DC__VOLTAGE_STATES] = {0};
2120 	unsigned int optimal_dcfclk_for_uclk[DC__VOLTAGE_STATES] = {0};
2121 
2122 	unsigned int dcfclk_sta_targets[DC__VOLTAGE_STATES] = {694, 875, 1000, 1200};
2123 	unsigned int num_dcfclk_sta_targets = 4;
2124 	unsigned int num_uclk_states;
2125 
2126 	struct dc_bounding_box_max_clk dcn30_bb_max_clk;
2127 
2128 	memset(&dcn30_bb_max_clk, 0, sizeof(dcn30_bb_max_clk));
2129 
2130 	if (dc->ctx->dc_bios->vram_info.num_chans)
2131 		dcn3_0_soc.num_chans = dc->ctx->dc_bios->vram_info.num_chans;
2132 
2133 	DC_FP_START();
2134 	dcn30_fpu_update_dram_channel_width_bytes(dc);
2135 	DC_FP_END();
2136 
2137 	if (bw_params->clk_table.entries[0].memclk_mhz) {
2138 
2139 		for (i = 0; i < MAX_NUM_DPM_LVL; i++) {
2140 			if (bw_params->clk_table.entries[i].dcfclk_mhz > dcn30_bb_max_clk.max_dcfclk_mhz)
2141 				dcn30_bb_max_clk.max_dcfclk_mhz = bw_params->clk_table.entries[i].dcfclk_mhz;
2142 			if (bw_params->clk_table.entries[i].dispclk_mhz > dcn30_bb_max_clk.max_dispclk_mhz)
2143 				dcn30_bb_max_clk.max_dispclk_mhz = bw_params->clk_table.entries[i].dispclk_mhz;
2144 			if (bw_params->clk_table.entries[i].dppclk_mhz > dcn30_bb_max_clk.max_dppclk_mhz)
2145 				dcn30_bb_max_clk.max_dppclk_mhz = bw_params->clk_table.entries[i].dppclk_mhz;
2146 			if (bw_params->clk_table.entries[i].phyclk_mhz > dcn30_bb_max_clk.max_phyclk_mhz)
2147 				dcn30_bb_max_clk.max_phyclk_mhz = bw_params->clk_table.entries[i].phyclk_mhz;
2148 		}
2149 
2150 		DC_FP_START();
2151 		dcn30_fpu_update_max_clk(&dcn30_bb_max_clk);
2152 		DC_FP_END();
2153 
2154 		if (dcn30_bb_max_clk.max_dcfclk_mhz > dcfclk_sta_targets[num_dcfclk_sta_targets-1]) {
2155 			// If max DCFCLK is greater than the max DCFCLK STA target, insert into the DCFCLK STA target array
2156 			dcfclk_sta_targets[num_dcfclk_sta_targets] = dcn30_bb_max_clk.max_dcfclk_mhz;
2157 			num_dcfclk_sta_targets++;
2158 		} else if (dcn30_bb_max_clk.max_dcfclk_mhz < dcfclk_sta_targets[num_dcfclk_sta_targets-1]) {
2159 			// If max DCFCLK is less than the max DCFCLK STA target, cap values and remove duplicates
2160 			for (i = 0; i < num_dcfclk_sta_targets; i++) {
2161 				if (dcfclk_sta_targets[i] > dcn30_bb_max_clk.max_dcfclk_mhz) {
2162 					dcfclk_sta_targets[i] = dcn30_bb_max_clk.max_dcfclk_mhz;
2163 					break;
2164 				}
2165 			}
2166 			// Update size of array since we "removed" duplicates
2167 			num_dcfclk_sta_targets = i + 1;
2168 		}
2169 
2170 		num_uclk_states = bw_params->clk_table.num_entries;
2171 
2172 		// Calculate optimal dcfclk for each uclk
2173 		for (i = 0; i < num_uclk_states; i++) {
2174 			DC_FP_START();
2175 			dcn30_fpu_get_optimal_dcfclk_fclk_for_uclk(bw_params->clk_table.entries[i].memclk_mhz * 16,
2176 					&optimal_dcfclk_for_uclk[i], NULL);
2177 			DC_FP_END();
2178 			if (optimal_dcfclk_for_uclk[i] < bw_params->clk_table.entries[0].dcfclk_mhz) {
2179 				optimal_dcfclk_for_uclk[i] = bw_params->clk_table.entries[0].dcfclk_mhz;
2180 			}
2181 		}
2182 
2183 		// Calculate optimal uclk for each dcfclk sta target
2184 		for (i = 0; i < num_dcfclk_sta_targets; i++) {
2185 			for (j = 0; j < num_uclk_states; j++) {
2186 				if (dcfclk_sta_targets[i] < optimal_dcfclk_for_uclk[j]) {
2187 					optimal_uclk_for_dcfclk_sta_targets[i] =
2188 							bw_params->clk_table.entries[j].memclk_mhz * 16;
2189 					break;
2190 				}
2191 			}
2192 		}
2193 
2194 		i = 0;
2195 		j = 0;
2196 		// create the final dcfclk and uclk table
2197 		while (i < num_dcfclk_sta_targets && j < num_uclk_states && num_states < DC__VOLTAGE_STATES) {
2198 			if (dcfclk_sta_targets[i] < optimal_dcfclk_for_uclk[j] && i < num_dcfclk_sta_targets) {
2199 				dcfclk_mhz[num_states] = dcfclk_sta_targets[i];
2200 				dram_speed_mts[num_states++] = optimal_uclk_for_dcfclk_sta_targets[i++];
2201 			} else {
2202 				if (j < num_uclk_states && optimal_dcfclk_for_uclk[j] <= dcn30_bb_max_clk.max_dcfclk_mhz) {
2203 					dcfclk_mhz[num_states] = optimal_dcfclk_for_uclk[j];
2204 					dram_speed_mts[num_states++] = bw_params->clk_table.entries[j++].memclk_mhz * 16;
2205 				} else {
2206 					j = num_uclk_states;
2207 				}
2208 			}
2209 		}
2210 
2211 		while (i < num_dcfclk_sta_targets && num_states < DC__VOLTAGE_STATES) {
2212 			dcfclk_mhz[num_states] = dcfclk_sta_targets[i];
2213 			dram_speed_mts[num_states++] = optimal_uclk_for_dcfclk_sta_targets[i++];
2214 		}
2215 
2216 		while (j < num_uclk_states && num_states < DC__VOLTAGE_STATES &&
2217 				optimal_dcfclk_for_uclk[j] <= dcn30_bb_max_clk.max_dcfclk_mhz) {
2218 			dcfclk_mhz[num_states] = optimal_dcfclk_for_uclk[j];
2219 			dram_speed_mts[num_states++] = bw_params->clk_table.entries[j++].memclk_mhz * 16;
2220 		}
2221 
2222 		dcn3_0_soc.num_states = num_states;
2223 		DC_FP_START();
2224 		dcn30_fpu_update_bw_bounding_box(dc, bw_params, &dcn30_bb_max_clk, dcfclk_mhz, dram_speed_mts);
2225 		DC_FP_END();
2226 	}
2227 }
2228 
2229 static void dcn30_get_panel_config_defaults(struct dc_panel_config *panel_config)
2230 {
2231 	*panel_config = panel_config_defaults;
2232 }
2233 
2234 static const struct resource_funcs dcn30_res_pool_funcs = {
2235 	.destroy = dcn30_destroy_resource_pool,
2236 	.link_enc_create = dcn30_link_encoder_create,
2237 	.panel_cntl_create = dcn30_panel_cntl_create,
2238 	.validate_bandwidth = dcn30_validate_bandwidth,
2239 	.calculate_wm_and_dlg = dcn30_calculate_wm_and_dlg,
2240 	.update_soc_for_wm_a = dcn30_update_soc_for_wm_a,
2241 	.populate_dml_pipes = dcn30_populate_dml_pipes_from_context,
2242 	.acquire_idle_pipe_for_layer = dcn20_acquire_idle_pipe_for_layer,
2243 	.add_stream_to_ctx = dcn30_add_stream_to_ctx,
2244 	.add_dsc_to_stream_resource = dcn20_add_dsc_to_stream_resource,
2245 	.remove_stream_from_ctx = dcn20_remove_stream_from_ctx,
2246 	.populate_dml_writeback_from_context = dcn30_populate_dml_writeback_from_context,
2247 	.set_mcif_arb_params = dcn30_set_mcif_arb_params,
2248 	.find_first_free_match_stream_enc_for_link = dcn10_find_first_free_match_stream_enc_for_link,
2249 	.acquire_post_bldn_3dlut = dcn30_acquire_post_bldn_3dlut,
2250 	.release_post_bldn_3dlut = dcn30_release_post_bldn_3dlut,
2251 	.update_bw_bounding_box = dcn30_update_bw_bounding_box,
2252 	.patch_unknown_plane_state = dcn20_patch_unknown_plane_state,
2253 	.get_panel_config_defaults = dcn30_get_panel_config_defaults,
2254 };
2255 
2256 #define CTX ctx
2257 
2258 #define REG(reg_name) \
2259 	(DCN_BASE.instance[0].segment[mm ## reg_name ## _BASE_IDX] + mm ## reg_name)
2260 
2261 static uint32_t read_pipe_fuses(struct dc_context *ctx)
2262 {
2263 	uint32_t value = REG_READ(CC_DC_PIPE_DIS);
2264 	/* Support for max 6 pipes */
2265 	value = value & 0x3f;
2266 	return value;
2267 }
2268 
2269 static bool dcn30_resource_construct(
2270 	uint8_t num_virtual_links,
2271 	struct dc *dc,
2272 	struct dcn30_resource_pool *pool)
2273 {
2274 	int i;
2275 	struct dc_context *ctx = dc->ctx;
2276 	struct irq_service_init_data init_data;
2277 	struct ddc_service_init_data ddc_init_data = {0};
2278 	uint32_t pipe_fuses = read_pipe_fuses(ctx);
2279 	uint32_t num_pipes = 0;
2280 
2281 	if (!(pipe_fuses == 0 || pipe_fuses == 0x3e)) {
2282 		BREAK_TO_DEBUGGER();
2283 		dm_error("DC: Unexpected fuse recipe for navi2x !\n");
2284 		/* fault to single pipe */
2285 		pipe_fuses = 0x3e;
2286 	}
2287 
2288 	DC_FP_START();
2289 
2290 	ctx->dc_bios->regs = &bios_regs;
2291 
2292 	pool->base.res_cap = &res_cap_dcn3;
2293 
2294 	pool->base.funcs = &dcn30_res_pool_funcs;
2295 
2296 	/*************************************************
2297 	 *  Resource + asic cap harcoding                *
2298 	 *************************************************/
2299 	pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
2300 	pool->base.pipe_count = pool->base.res_cap->num_timing_generator;
2301 	pool->base.mpcc_count = pool->base.res_cap->num_timing_generator;
2302 	dc->caps.max_downscale_ratio = 600;
2303 	dc->caps.i2c_speed_in_khz = 100;
2304 	dc->caps.i2c_speed_in_khz_hdcp = 100; /*1.4 w/a not applied by default*/
2305 	dc->caps.max_cursor_size = 256;
2306 	dc->caps.min_horizontal_blanking_period = 80;
2307 	dc->caps.dmdata_alloc_size = 2048;
2308 	dc->caps.mall_size_per_mem_channel = 8;
2309 	/* total size = mall per channel * num channels * 1024 * 1024 */
2310 	dc->caps.mall_size_total = dc->caps.mall_size_per_mem_channel * dc->ctx->dc_bios->vram_info.num_chans * 1048576;
2311 	dc->caps.cursor_cache_size = dc->caps.max_cursor_size * dc->caps.max_cursor_size * 8;
2312 
2313 	dc->caps.max_slave_planes = 2;
2314 	dc->caps.max_slave_yuv_planes = 2;
2315 	dc->caps.max_slave_rgb_planes = 2;
2316 	dc->caps.post_blend_color_processing = true;
2317 	dc->caps.force_dp_tps4_for_cp2520 = true;
2318 	dc->caps.extended_aux_timeout_support = true;
2319 	dc->caps.dmcub_support = true;
2320 
2321 	/* Color pipeline capabilities */
2322 	dc->caps.color.dpp.dcn_arch = 1;
2323 	dc->caps.color.dpp.input_lut_shared = 0;
2324 	dc->caps.color.dpp.icsc = 1;
2325 	dc->caps.color.dpp.dgam_ram = 0; // must use gamma_corr
2326 	dc->caps.color.dpp.dgam_rom_caps.srgb = 1;
2327 	dc->caps.color.dpp.dgam_rom_caps.bt2020 = 1;
2328 	dc->caps.color.dpp.dgam_rom_caps.gamma2_2 = 1;
2329 	dc->caps.color.dpp.dgam_rom_caps.pq = 1;
2330 	dc->caps.color.dpp.dgam_rom_caps.hlg = 1;
2331 	dc->caps.color.dpp.post_csc = 1;
2332 	dc->caps.color.dpp.gamma_corr = 1;
2333 	dc->caps.color.dpp.dgam_rom_for_yuv = 0;
2334 
2335 	dc->caps.color.dpp.hw_3d_lut = 1;
2336 	dc->caps.color.dpp.ogam_ram = 1;
2337 	// no OGAM ROM on DCN3
2338 	dc->caps.color.dpp.ogam_rom_caps.srgb = 0;
2339 	dc->caps.color.dpp.ogam_rom_caps.bt2020 = 0;
2340 	dc->caps.color.dpp.ogam_rom_caps.gamma2_2 = 0;
2341 	dc->caps.color.dpp.ogam_rom_caps.pq = 0;
2342 	dc->caps.color.dpp.ogam_rom_caps.hlg = 0;
2343 	dc->caps.color.dpp.ocsc = 0;
2344 
2345 	dc->caps.color.mpc.gamut_remap = 1;
2346 	dc->caps.color.mpc.num_3dluts = pool->base.res_cap->num_mpc_3dlut; //3
2347 	dc->caps.color.mpc.ogam_ram = 1;
2348 	dc->caps.color.mpc.ogam_rom_caps.srgb = 0;
2349 	dc->caps.color.mpc.ogam_rom_caps.bt2020 = 0;
2350 	dc->caps.color.mpc.ogam_rom_caps.gamma2_2 = 0;
2351 	dc->caps.color.mpc.ogam_rom_caps.pq = 0;
2352 	dc->caps.color.mpc.ogam_rom_caps.hlg = 0;
2353 	dc->caps.color.mpc.ocsc = 1;
2354 
2355 	dc->caps.dp_hdmi21_pcon_support = true;
2356 
2357 	/* read VBIOS LTTPR caps */
2358 	{
2359 		if (ctx->dc_bios->funcs->get_lttpr_caps) {
2360 			enum bp_result bp_query_result;
2361 			uint8_t is_vbios_lttpr_enable = 0;
2362 
2363 			bp_query_result = ctx->dc_bios->funcs->get_lttpr_caps(ctx->dc_bios, &is_vbios_lttpr_enable);
2364 			dc->caps.vbios_lttpr_enable = (bp_query_result == BP_RESULT_OK) && !!is_vbios_lttpr_enable;
2365 		}
2366 
2367 		if (ctx->dc_bios->funcs->get_lttpr_interop) {
2368 			enum bp_result bp_query_result;
2369 			uint8_t is_vbios_interop_enabled = 0;
2370 
2371 			bp_query_result = ctx->dc_bios->funcs->get_lttpr_interop(ctx->dc_bios,
2372 					&is_vbios_interop_enabled);
2373 			dc->caps.vbios_lttpr_aware = (bp_query_result == BP_RESULT_OK) && !!is_vbios_interop_enabled;
2374 		}
2375 	}
2376 
2377 	if (dc->ctx->dce_environment == DCE_ENV_PRODUCTION_DRV)
2378 		dc->debug = debug_defaults_drv;
2379 	else if (dc->ctx->dce_environment == DCE_ENV_FPGA_MAXIMUS) {
2380 		dc->debug = debug_defaults_diags;
2381 	} else
2382 		dc->debug = debug_defaults_diags;
2383 	// Init the vm_helper
2384 	if (dc->vm_helper)
2385 		vm_helper_init(dc->vm_helper, 16);
2386 
2387 	/*************************************************
2388 	 *  Create resources                             *
2389 	 *************************************************/
2390 
2391 	/* Clock Sources for Pixel Clock*/
2392 	pool->base.clock_sources[DCN30_CLK_SRC_PLL0] =
2393 			dcn30_clock_source_create(ctx, ctx->dc_bios,
2394 				CLOCK_SOURCE_COMBO_PHY_PLL0,
2395 				&clk_src_regs[0], false);
2396 	pool->base.clock_sources[DCN30_CLK_SRC_PLL1] =
2397 			dcn30_clock_source_create(ctx, ctx->dc_bios,
2398 				CLOCK_SOURCE_COMBO_PHY_PLL1,
2399 				&clk_src_regs[1], false);
2400 	pool->base.clock_sources[DCN30_CLK_SRC_PLL2] =
2401 			dcn30_clock_source_create(ctx, ctx->dc_bios,
2402 				CLOCK_SOURCE_COMBO_PHY_PLL2,
2403 				&clk_src_regs[2], false);
2404 	pool->base.clock_sources[DCN30_CLK_SRC_PLL3] =
2405 			dcn30_clock_source_create(ctx, ctx->dc_bios,
2406 				CLOCK_SOURCE_COMBO_PHY_PLL3,
2407 				&clk_src_regs[3], false);
2408 	pool->base.clock_sources[DCN30_CLK_SRC_PLL4] =
2409 			dcn30_clock_source_create(ctx, ctx->dc_bios,
2410 				CLOCK_SOURCE_COMBO_PHY_PLL4,
2411 				&clk_src_regs[4], false);
2412 	pool->base.clock_sources[DCN30_CLK_SRC_PLL5] =
2413 			dcn30_clock_source_create(ctx, ctx->dc_bios,
2414 				CLOCK_SOURCE_COMBO_PHY_PLL5,
2415 				&clk_src_regs[5], false);
2416 
2417 	pool->base.clk_src_count = DCN30_CLK_SRC_TOTAL;
2418 
2419 	/* todo: not reuse phy_pll registers */
2420 	pool->base.dp_clock_source =
2421 			dcn30_clock_source_create(ctx, ctx->dc_bios,
2422 				CLOCK_SOURCE_ID_DP_DTO,
2423 				&clk_src_regs[0], true);
2424 
2425 	for (i = 0; i < pool->base.clk_src_count; i++) {
2426 		if (pool->base.clock_sources[i] == NULL) {
2427 			dm_error("DC: failed to create clock sources!\n");
2428 			BREAK_TO_DEBUGGER();
2429 			goto create_fail;
2430 		}
2431 	}
2432 
2433 	/* DCCG */
2434 	pool->base.dccg = dccg30_create(ctx, &dccg_regs, &dccg_shift, &dccg_mask);
2435 	if (pool->base.dccg == NULL) {
2436 		dm_error("DC: failed to create dccg!\n");
2437 		BREAK_TO_DEBUGGER();
2438 		goto create_fail;
2439 	}
2440 
2441 	/* PP Lib and SMU interfaces */
2442 	init_soc_bounding_box(dc, pool);
2443 
2444 	num_pipes = dcn3_0_ip.max_num_dpp;
2445 
2446 	for (i = 0; i < dcn3_0_ip.max_num_dpp; i++)
2447 		if (pipe_fuses & 1 << i)
2448 			num_pipes--;
2449 
2450 	dcn3_0_ip.max_num_dpp = num_pipes;
2451 	dcn3_0_ip.max_num_otg = num_pipes;
2452 
2453 	dml_init_instance(&dc->dml, &dcn3_0_soc, &dcn3_0_ip, DML_PROJECT_DCN30);
2454 
2455 	/* IRQ */
2456 	init_data.ctx = dc->ctx;
2457 	pool->base.irqs = dal_irq_service_dcn30_create(&init_data);
2458 	if (!pool->base.irqs)
2459 		goto create_fail;
2460 
2461 	/* HUBBUB */
2462 	pool->base.hubbub = dcn30_hubbub_create(ctx);
2463 	if (pool->base.hubbub == NULL) {
2464 		BREAK_TO_DEBUGGER();
2465 		dm_error("DC: failed to create hubbub!\n");
2466 		goto create_fail;
2467 	}
2468 
2469 	/* HUBPs, DPPs, OPPs and TGs */
2470 	for (i = 0; i < pool->base.pipe_count; i++) {
2471 		pool->base.hubps[i] = dcn30_hubp_create(ctx, i);
2472 		if (pool->base.hubps[i] == NULL) {
2473 			BREAK_TO_DEBUGGER();
2474 			dm_error(
2475 				"DC: failed to create hubps!\n");
2476 			goto create_fail;
2477 		}
2478 
2479 		pool->base.dpps[i] = dcn30_dpp_create(ctx, i);
2480 		if (pool->base.dpps[i] == NULL) {
2481 			BREAK_TO_DEBUGGER();
2482 			dm_error(
2483 				"DC: failed to create dpps!\n");
2484 			goto create_fail;
2485 		}
2486 	}
2487 
2488 	for (i = 0; i < pool->base.res_cap->num_opp; i++) {
2489 		pool->base.opps[i] = dcn30_opp_create(ctx, i);
2490 		if (pool->base.opps[i] == NULL) {
2491 			BREAK_TO_DEBUGGER();
2492 			dm_error(
2493 				"DC: failed to create output pixel processor!\n");
2494 			goto create_fail;
2495 		}
2496 	}
2497 
2498 	for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) {
2499 		pool->base.timing_generators[i] = dcn30_timing_generator_create(
2500 				ctx, i);
2501 		if (pool->base.timing_generators[i] == NULL) {
2502 			BREAK_TO_DEBUGGER();
2503 			dm_error("DC: failed to create tg!\n");
2504 			goto create_fail;
2505 		}
2506 	}
2507 	pool->base.timing_generator_count = i;
2508 	/* PSR */
2509 	pool->base.psr = dmub_psr_create(ctx);
2510 
2511 	if (pool->base.psr == NULL) {
2512 		dm_error("DC: failed to create PSR obj!\n");
2513 		BREAK_TO_DEBUGGER();
2514 		goto create_fail;
2515 	}
2516 
2517 	/* ABM */
2518 	for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) {
2519 		pool->base.multiple_abms[i] = dmub_abm_create(ctx,
2520 				&abm_regs[i],
2521 				&abm_shift,
2522 				&abm_mask);
2523 		if (pool->base.multiple_abms[i] == NULL) {
2524 			dm_error("DC: failed to create abm for pipe %d!\n", i);
2525 			BREAK_TO_DEBUGGER();
2526 			goto create_fail;
2527 		}
2528 	}
2529 	/* MPC and DSC */
2530 	pool->base.mpc = dcn30_mpc_create(ctx, pool->base.mpcc_count, pool->base.res_cap->num_mpc_3dlut);
2531 	if (pool->base.mpc == NULL) {
2532 		BREAK_TO_DEBUGGER();
2533 		dm_error("DC: failed to create mpc!\n");
2534 		goto create_fail;
2535 	}
2536 
2537 	for (i = 0; i < pool->base.res_cap->num_dsc; i++) {
2538 		pool->base.dscs[i] = dcn30_dsc_create(ctx, i);
2539 		if (pool->base.dscs[i] == NULL) {
2540 			BREAK_TO_DEBUGGER();
2541 			dm_error("DC: failed to create display stream compressor %d!\n", i);
2542 			goto create_fail;
2543 		}
2544 	}
2545 
2546 	/* DWB and MMHUBBUB */
2547 	if (!dcn30_dwbc_create(ctx, &pool->base)) {
2548 		BREAK_TO_DEBUGGER();
2549 		dm_error("DC: failed to create dwbc!\n");
2550 		goto create_fail;
2551 	}
2552 
2553 	if (!dcn30_mmhubbub_create(ctx, &pool->base)) {
2554 		BREAK_TO_DEBUGGER();
2555 		dm_error("DC: failed to create mcif_wb!\n");
2556 		goto create_fail;
2557 	}
2558 
2559 	/* AUX and I2C */
2560 	for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
2561 		pool->base.engines[i] = dcn30_aux_engine_create(ctx, i);
2562 		if (pool->base.engines[i] == NULL) {
2563 			BREAK_TO_DEBUGGER();
2564 			dm_error(
2565 				"DC:failed to create aux engine!!\n");
2566 			goto create_fail;
2567 		}
2568 		pool->base.hw_i2cs[i] = dcn30_i2c_hw_create(ctx, i);
2569 		if (pool->base.hw_i2cs[i] == NULL) {
2570 			BREAK_TO_DEBUGGER();
2571 			dm_error(
2572 				"DC:failed to create hw i2c!!\n");
2573 			goto create_fail;
2574 		}
2575 		pool->base.sw_i2cs[i] = NULL;
2576 	}
2577 
2578 	/* Audio, Stream Encoders including DIG and virtual, MPC 3D LUTs */
2579 	if (!resource_construct(num_virtual_links, dc, &pool->base,
2580 			(!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment) ?
2581 			&res_create_funcs : &res_create_maximus_funcs)))
2582 		goto create_fail;
2583 
2584 	/* HW Sequencer and Plane caps */
2585 	dcn30_hw_sequencer_construct(dc);
2586 
2587 	dc->caps.max_planes =  pool->base.pipe_count;
2588 
2589 	for (i = 0; i < dc->caps.max_planes; ++i)
2590 		dc->caps.planes[i] = plane_cap;
2591 
2592 	dc->cap_funcs = cap_funcs;
2593 
2594 	if (dc->ctx->dc_bios->fw_info.oem_i2c_present) {
2595 		ddc_init_data.ctx = dc->ctx;
2596 		ddc_init_data.link = NULL;
2597 		ddc_init_data.id.id = dc->ctx->dc_bios->fw_info.oem_i2c_obj_id;
2598 		ddc_init_data.id.enum_id = 0;
2599 		ddc_init_data.id.type = OBJECT_TYPE_GENERIC;
2600 		pool->base.oem_device = dc->link_srv->create_ddc_service(&ddc_init_data);
2601 	} else {
2602 		pool->base.oem_device = NULL;
2603 	}
2604 
2605 	DC_FP_END();
2606 
2607 	return true;
2608 
2609 create_fail:
2610 
2611 	DC_FP_END();
2612 	dcn30_resource_destruct(pool);
2613 
2614 	return false;
2615 }
2616 
2617 struct resource_pool *dcn30_create_resource_pool(
2618 		const struct dc_init_data *init_data,
2619 		struct dc *dc)
2620 {
2621 	struct dcn30_resource_pool *pool =
2622 		kzalloc(sizeof(struct dcn30_resource_pool), GFP_KERNEL);
2623 
2624 	if (!pool)
2625 		return NULL;
2626 
2627 	if (dcn30_resource_construct(init_data->num_virtual_links, dc, pool))
2628 		return &pool->base;
2629 
2630 	BREAK_TO_DEBUGGER();
2631 	kfree(pool);
2632 	return NULL;
2633 }
2634