xref: /linux/drivers/gpu/drm/amd/display/dc/resource/dcn301/dcn301_resource.c (revision 60d9212c6932376a337507b20fc45b2c2785b5ac)
1 /*
2  * Copyright 2019-2021 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 "dcn301/dcn301_init.h"
31 
32 #include "resource.h"
33 #include "include/irq_service_interface.h"
34 #include "dcn30/dcn30_resource.h"
35 #include "dcn301_resource.h"
36 
37 #include "dcn20/dcn20_resource.h"
38 
39 #include "dcn10/dcn10_ipp.h"
40 #include "dcn301/dcn301_hubbub.h"
41 #include "dcn30/dcn30_mpc.h"
42 #include "dcn30/dcn30_hubp.h"
43 #include "irq/dcn30/irq_service_dcn30.h"
44 #include "dcn30/dcn30_dpp.h"
45 #include "dcn301/dcn301_optc.h"
46 #include "dcn20/dcn20_hwseq.h"
47 #include "dcn30/dcn30_hwseq.h"
48 #include "dce110/dce110_hwseq.h"
49 #include "dcn30/dcn30_opp.h"
50 #include "dcn20/dcn20_dsc.h"
51 #include "dcn30/dcn30_vpg.h"
52 #include "dcn30/dcn30_afmt.h"
53 #include "dce/dce_clock_source.h"
54 #include "dce/dce_audio.h"
55 #include "dce/dce_hwseq.h"
56 #include "clk_mgr.h"
57 #include "dio/virtual/virtual_stream_encoder.h"
58 #include "dce110/dce110_resource.h"
59 #include "dml/display_mode_vba.h"
60 #include "dcn301/dcn301_dccg.h"
61 #include "dcn10/dcn10_resource.h"
62 #include "dio/dcn10/dcn10_dio.h"
63 #include "dcn30/dcn30_dio_stream_encoder.h"
64 #include "dcn301/dcn301_dio_link_encoder.h"
65 #include "dcn301/dcn301_panel_cntl.h"
66 
67 #include "vangogh_ip_offset.h"
68 
69 #include "dcn30/dcn30_dwb.h"
70 #include "dcn30/dcn30_mmhubbub.h"
71 
72 #include "dcn/dcn_3_0_1_offset.h"
73 #include "dcn/dcn_3_0_1_sh_mask.h"
74 
75 #include "nbio/nbio_7_2_0_offset.h"
76 
77 #include "dpcs/dpcs_3_0_0_offset.h"
78 #include "dpcs/dpcs_3_0_0_sh_mask.h"
79 
80 #include "reg_helper.h"
81 #include "dce/dmub_abm.h"
82 #include "dce/dce_aux.h"
83 #include "dce/dce_i2c.h"
84 
85 #include "dml/dcn30/dcn30_fpu.h"
86 
87 #include "dml/dcn30/display_mode_vba_30.h"
88 #include "dml/dcn301/dcn301_fpu.h"
89 #include "vm_helper.h"
90 #include "dcn20/dcn20_vmid.h"
91 #include "amdgpu_socbb.h"
92 
93 #define TO_DCN301_RES_POOL(pool)\
94 	container_of(pool, struct dcn301_resource_pool, base)
95 
96 #define DC_LOGGER \
97 	dc->ctx->logger
98 #define DC_LOGGER_INIT(logger)
99 
100 enum dcn301_clk_src_array_id {
101 	DCN301_CLK_SRC_PLL0,
102 	DCN301_CLK_SRC_PLL1,
103 	DCN301_CLK_SRC_PLL2,
104 	DCN301_CLK_SRC_PLL3,
105 	DCN301_CLK_SRC_TOTAL
106 };
107 
108 /* begin *********************
109  * macros to expend register list macro defined in HW object header file
110  */
111 
112 /* DCN */
113 #define BASE_INNER(seg) DCN_BASE__INST0_SEG ## seg
114 
115 #define BASE(seg) BASE_INNER(seg)
116 
117 #define SR(reg_name)\
118 		.reg_name = BASE(mm ## reg_name ## _BASE_IDX) +  \
119 					mm ## reg_name
120 
121 #define SRI(reg_name, block, id)\
122 	.reg_name = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
123 					mm ## block ## id ## _ ## reg_name
124 
125 #define SRI2(reg_name, block, id)\
126 	.reg_name = BASE(mm ## reg_name ## _BASE_IDX) + \
127 					mm ## reg_name
128 
129 #define SRIR(var_name, reg_name, block, id)\
130 	.var_name = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
131 					mm ## block ## id ## _ ## reg_name
132 
133 #define SRII(reg_name, block, id)\
134 	.reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
135 					mm ## block ## id ## _ ## reg_name
136 
137 #define SRII2(reg_name_pre, reg_name_post, id)\
138 	.reg_name_pre ## _ ##  reg_name_post[id] = BASE(mm ## reg_name_pre \
139 			## id ## _ ## reg_name_post ## _BASE_IDX) + \
140 			mm ## reg_name_pre ## id ## _ ## reg_name_post
141 
142 #define SRII_MPC_RMU(reg_name, block, id)\
143 	.RMU##_##reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
144 					mm ## block ## id ## _ ## reg_name
145 
146 #define SRII_DWB(reg_name, temp_name, block, id)\
147 	.reg_name[id] = BASE(mm ## block ## id ## _ ## temp_name ## _BASE_IDX) + \
148 					mm ## block ## id ## _ ## temp_name
149 
150 #define SF_DWB2(reg_name, block, id, field_name, post_fix)	\
151 	.field_name = reg_name ## __ ## field_name ## post_fix
152 
153 #define DCCG_SRII(reg_name, block, id)\
154 	.block ## _ ## reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
155 					mm ## block ## id ## _ ## reg_name
156 
157 #define VUPDATE_SRII(reg_name, block, id)\
158 	.reg_name[id] = BASE(mm ## reg_name ## _ ## block ## id ## _BASE_IDX) + \
159 					mm ## reg_name ## _ ## block ## id
160 
161 /* NBIO */
162 #define NBIO_BASE_INNER(seg) \
163 	NBIO_BASE__INST0_SEG ## seg
164 
165 #define NBIO_BASE(seg) \
166 	NBIO_BASE_INNER(seg)
167 
168 #define NBIO_SR(reg_name)\
169 		.reg_name = NBIO_BASE(regBIF_BX0_ ## reg_name ## _BASE_IDX) + \
170 					regBIF_BX0_ ## reg_name
171 
172 /* MMHUB */
173 #define MMHUB_BASE_INNER(seg) \
174 	MMHUB_BASE__INST0_SEG ## seg
175 
176 #define MMHUB_BASE(seg) \
177 	MMHUB_BASE_INNER(seg)
178 
179 #define MMHUB_SR(reg_name)\
180 		.reg_name = MMHUB_BASE(regMM ## reg_name ## _BASE_IDX) + \
181 					regMM ## reg_name
182 
183 /* CLOCK */
184 #define CLK_BASE_INNER(seg) \
185 	CLK_BASE__INST0_SEG ## seg
186 
187 #define CLK_BASE(seg) \
188 	CLK_BASE_INNER(seg)
189 
190 #define CLK_SRI(reg_name, block, inst)\
191 	.reg_name = CLK_BASE(mm ## block ## _ ## inst ## _ ## reg_name ## _BASE_IDX) + \
192 					mm ## block ## _ ## inst ## _ ## reg_name
193 
194 static const struct bios_registers bios_regs = {
195 		NBIO_SR(BIOS_SCRATCH_3),
196 		NBIO_SR(BIOS_SCRATCH_6)
197 };
198 
199 #define clk_src_regs(index, pllid)\
200 [index] = {\
201 	CS_COMMON_REG_LIST_DCN3_01(index, pllid),\
202 }
203 
204 static const struct dce110_clk_src_regs clk_src_regs[] = {
205 	clk_src_regs(0, A),
206 	clk_src_regs(1, B),
207 	clk_src_regs(2, C),
208 	clk_src_regs(3, D)
209 };
210 
211 static const struct dce110_clk_src_shift cs_shift = {
212 		CS_COMMON_MASK_SH_LIST_DCN2_0(__SHIFT)
213 };
214 
215 static const struct dce110_clk_src_mask cs_mask = {
216 		CS_COMMON_MASK_SH_LIST_DCN2_0(_MASK)
217 };
218 
219 #define abm_regs(id)\
220 [id] = {\
221 		ABM_DCN301_REG_LIST(id)\
222 }
223 
224 static const struct dce_abm_registers abm_regs[] = {
225 		abm_regs(0),
226 		abm_regs(1),
227 		abm_regs(2),
228 		abm_regs(3),
229 };
230 
231 static const struct dce_abm_shift abm_shift = {
232 		ABM_MASK_SH_LIST_DCN30(__SHIFT)
233 };
234 
235 static const struct dce_abm_mask abm_mask = {
236 		ABM_MASK_SH_LIST_DCN30(_MASK)
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 };
278 
279 static const struct dcn30_vpg_shift vpg_shift = {
280 	DCN3_VPG_MASK_SH_LIST(__SHIFT)
281 };
282 
283 static const struct dcn30_vpg_mask vpg_mask = {
284 	DCN3_VPG_MASK_SH_LIST(_MASK)
285 };
286 
287 #define afmt_regs(id)\
288 [id] = {\
289 	AFMT_DCN3_REG_LIST(id)\
290 }
291 
292 static const struct dcn30_afmt_registers afmt_regs[] = {
293 	afmt_regs(0),
294 	afmt_regs(1),
295 	afmt_regs(2),
296 	afmt_regs(3),
297 };
298 
299 static const struct dcn30_afmt_shift afmt_shift = {
300 	DCN3_AFMT_MASK_SH_LIST(__SHIFT)
301 };
302 
303 static const struct dcn30_afmt_mask afmt_mask = {
304 	DCN3_AFMT_MASK_SH_LIST(_MASK)
305 };
306 
307 #define stream_enc_regs(id)\
308 [id] = {\
309 	SE_DCN3_REG_LIST(id)\
310 }
311 
312 static const struct dcn10_stream_enc_registers stream_enc_regs[] = {
313 	stream_enc_regs(0),
314 	stream_enc_regs(1),
315 	stream_enc_regs(2),
316 	stream_enc_regs(3),
317 };
318 
319 static const struct dcn10_stream_encoder_shift se_shift = {
320 		SE_COMMON_MASK_SH_LIST_DCN30(__SHIFT)
321 };
322 
323 static const struct dcn10_stream_encoder_mask se_mask = {
324 		SE_COMMON_MASK_SH_LIST_DCN30(_MASK)
325 };
326 
327 
328 #define aux_regs(id)\
329 [id] = {\
330 	DCN2_AUX_REG_LIST(id)\
331 }
332 
333 static const struct dcn10_link_enc_aux_registers link_enc_aux_regs[] = {
334 		aux_regs(0),
335 		aux_regs(1),
336 		aux_regs(2),
337 		aux_regs(3),
338 };
339 
340 #define hpd_regs(id)\
341 [id] = {\
342 	HPD_REG_LIST(id)\
343 }
344 
345 static const struct dcn10_link_enc_hpd_registers link_enc_hpd_regs[] = {
346 		hpd_regs(0),
347 		hpd_regs(1),
348 		hpd_regs(2),
349 		hpd_regs(3),
350 };
351 
352 
353 #define link_regs(id, phyid)\
354 [id] = {\
355 	LE_DCN301_REG_LIST(id), \
356 	UNIPHY_DCN2_REG_LIST(phyid), \
357 	DPCS_DCN2_REG_LIST(id), \
358 	SRI(DP_DPHY_INTERNAL_CTRL, DP, id) \
359 }
360 
361 static const struct dce110_aux_registers_shift aux_shift = {
362 	DCN_AUX_MASK_SH_LIST(__SHIFT)
363 };
364 
365 static const struct dce110_aux_registers_mask aux_mask = {
366 	DCN_AUX_MASK_SH_LIST(_MASK)
367 };
368 
369 static const struct dcn10_link_enc_registers link_enc_regs[] = {
370 	link_regs(0, A),
371 	link_regs(1, B),
372 	link_regs(2, C),
373 	link_regs(3, D),
374 };
375 
376 static const struct dcn10_link_enc_shift le_shift = {
377 	LINK_ENCODER_MASK_SH_LIST_DCN301(__SHIFT),\
378 	DPCS_DCN2_MASK_SH_LIST(__SHIFT)
379 };
380 
381 static const struct dcn10_link_enc_mask le_mask = {
382 	LINK_ENCODER_MASK_SH_LIST_DCN301(_MASK),\
383 	DPCS_DCN2_MASK_SH_LIST(_MASK)
384 };
385 
386 #define panel_cntl_regs(id)\
387 [id] = {\
388 	DCN301_PANEL_CNTL_REG_LIST(id),\
389 }
390 
391 static const struct dce_panel_cntl_registers panel_cntl_regs[] = {
392 	panel_cntl_regs(0),
393 	panel_cntl_regs(1),
394 };
395 
396 static const struct dcn301_panel_cntl_shift panel_cntl_shift = {
397 	DCN301_PANEL_CNTL_MASK_SH_LIST(__SHIFT)
398 };
399 
400 static const struct dcn301_panel_cntl_mask panel_cntl_mask = {
401 	DCN301_PANEL_CNTL_MASK_SH_LIST(_MASK)
402 };
403 
404 #define dpp_regs(id)\
405 [id] = {\
406 	DPP_REG_LIST_DCN30(id),\
407 }
408 
409 static const struct dcn3_dpp_registers dpp_regs[] = {
410 	dpp_regs(0),
411 	dpp_regs(1),
412 	dpp_regs(2),
413 	dpp_regs(3),
414 };
415 
416 static const struct dcn3_dpp_shift tf_shift = {
417 		DPP_REG_LIST_SH_MASK_DCN30(__SHIFT)
418 };
419 
420 static const struct dcn3_dpp_mask tf_mask = {
421 		DPP_REG_LIST_SH_MASK_DCN30(_MASK)
422 };
423 
424 #define opp_regs(id)\
425 [id] = {\
426 	OPP_REG_LIST_DCN30(id),\
427 }
428 
429 static const struct dcn20_opp_registers opp_regs[] = {
430 	opp_regs(0),
431 	opp_regs(1),
432 	opp_regs(2),
433 	opp_regs(3),
434 };
435 
436 static const struct dcn20_opp_shift opp_shift = {
437 	OPP_MASK_SH_LIST_DCN20(__SHIFT)
438 };
439 
440 static const struct dcn20_opp_mask opp_mask = {
441 	OPP_MASK_SH_LIST_DCN20(_MASK)
442 };
443 
444 #define aux_engine_regs(id)\
445 [id] = {\
446 	AUX_COMMON_REG_LIST0(id), \
447 	.AUXN_IMPCAL = 0, \
448 	.AUXP_IMPCAL = 0, \
449 	.AUX_RESET_MASK = DP_AUX0_AUX_CONTROL__AUX_RESET_MASK, \
450 }
451 
452 static const struct dce110_aux_registers aux_engine_regs[] = {
453 		aux_engine_regs(0),
454 		aux_engine_regs(1),
455 		aux_engine_regs(2),
456 		aux_engine_regs(3),
457 };
458 
459 #define dwbc_regs_dcn3(id)\
460 [id] = {\
461 	DWBC_COMMON_REG_LIST_DCN30(id),\
462 }
463 
464 static const struct dcn30_dwbc_registers dwbc30_regs[] = {
465 	dwbc_regs_dcn3(0),
466 };
467 
468 static const struct dcn30_dwbc_shift dwbc30_shift = {
469 	DWBC_COMMON_MASK_SH_LIST_DCN30(__SHIFT)
470 };
471 
472 static const struct dcn30_dwbc_mask dwbc30_mask = {
473 	DWBC_COMMON_MASK_SH_LIST_DCN30(_MASK)
474 };
475 
476 #define mcif_wb_regs_dcn3(id)\
477 [id] = {\
478 	MCIF_WB_COMMON_REG_LIST_DCN30(id),\
479 }
480 
481 static const struct dcn30_mmhubbub_registers mcif_wb30_regs[] = {
482 	mcif_wb_regs_dcn3(0)
483 };
484 
485 static const struct dcn30_mmhubbub_shift mcif_wb30_shift = {
486 	MCIF_WB_COMMON_MASK_SH_LIST_DCN30(__SHIFT)
487 };
488 
489 static const struct dcn30_mmhubbub_mask mcif_wb30_mask = {
490 	MCIF_WB_COMMON_MASK_SH_LIST_DCN30(_MASK)
491 };
492 
493 #define dsc_regsDCN20(id)\
494 [id] = {\
495 	DSC_REG_LIST_DCN20(id)\
496 }
497 
498 static const struct dcn20_dsc_registers dsc_regs[] = {
499 	dsc_regsDCN20(0),
500 	dsc_regsDCN20(1),
501 	dsc_regsDCN20(2),
502 };
503 
504 static const struct dcn20_dsc_shift dsc_shift = {
505 	DSC_REG_LIST_SH_MASK_DCN20(__SHIFT)
506 };
507 
508 static const struct dcn20_dsc_mask dsc_mask = {
509 	DSC_REG_LIST_SH_MASK_DCN20(_MASK)
510 };
511 
512 static const struct dcn30_mpc_registers mpc_regs = {
513 		MPC_REG_LIST_DCN3_0(0),
514 		MPC_REG_LIST_DCN3_0(1),
515 		MPC_REG_LIST_DCN3_0(2),
516 		MPC_REG_LIST_DCN3_0(3),
517 		MPC_OUT_MUX_REG_LIST_DCN3_0(0),
518 		MPC_OUT_MUX_REG_LIST_DCN3_0(1),
519 		MPC_OUT_MUX_REG_LIST_DCN3_0(2),
520 		MPC_OUT_MUX_REG_LIST_DCN3_0(3),
521 		MPC_RMU_GLOBAL_REG_LIST_DCN3AG,
522 		MPC_RMU_REG_LIST_DCN3AG(0),
523 		MPC_RMU_REG_LIST_DCN3AG(1),
524 		MPC_DWB_MUX_REG_LIST_DCN3_0(0),
525 };
526 
527 static const struct dcn30_mpc_shift mpc_shift = {
528 	MPC_COMMON_MASK_SH_LIST_DCN30(__SHIFT)
529 };
530 
531 static const struct dcn30_mpc_mask mpc_mask = {
532 	MPC_COMMON_MASK_SH_LIST_DCN30(_MASK)
533 };
534 
535 #define optc_regs(id)\
536 [id] = {OPTC_COMMON_REG_LIST_DCN3_0(id)}
537 
538 
539 static const struct dcn_optc_registers optc_regs[] = {
540 	optc_regs(0),
541 	optc_regs(1),
542 	optc_regs(2),
543 	optc_regs(3),
544 };
545 
546 static const struct dcn_optc_shift optc_shift = {
547 	OPTC_COMMON_MASK_SH_LIST_DCN30(__SHIFT)
548 };
549 
550 static const struct dcn_optc_mask optc_mask = {
551 	OPTC_COMMON_MASK_SH_LIST_DCN30(_MASK)
552 };
553 
554 #define hubp_regs(id)\
555 [id] = {\
556 	HUBP_REG_LIST_DCN30(id)\
557 }
558 
559 static const struct dcn_hubp2_registers hubp_regs[] = {
560 		hubp_regs(0),
561 		hubp_regs(1),
562 		hubp_regs(2),
563 		hubp_regs(3),
564 };
565 
566 static const struct dcn_hubp2_shift hubp_shift = {
567 		HUBP_MASK_SH_LIST_DCN30(__SHIFT)
568 };
569 
570 static const struct dcn_hubp2_mask hubp_mask = {
571 		HUBP_MASK_SH_LIST_DCN30(_MASK)
572 };
573 
574 static const struct dcn_hubbub_registers hubbub_reg = {
575 		HUBBUB_REG_LIST_DCN301(0)
576 };
577 
578 static const struct dcn_hubbub_shift hubbub_shift = {
579 		HUBBUB_MASK_SH_LIST_DCN301(__SHIFT)
580 };
581 
582 static const struct dcn_hubbub_mask hubbub_mask = {
583 		HUBBUB_MASK_SH_LIST_DCN301(_MASK)
584 };
585 
586 static const struct dccg_registers dccg_regs = {
587 		DCCG_REG_LIST_DCN301()
588 };
589 
590 static const struct dccg_shift dccg_shift = {
591 		DCCG_MASK_SH_LIST_DCN301(__SHIFT)
592 };
593 
594 static const struct dccg_mask dccg_mask = {
595 		DCCG_MASK_SH_LIST_DCN301(_MASK)
596 };
597 
598 static const struct dce_hwseq_registers hwseq_reg = {
599 		HWSEQ_DCN301_REG_LIST()
600 };
601 
602 static const struct dce_hwseq_shift hwseq_shift = {
603 		HWSEQ_DCN301_MASK_SH_LIST(__SHIFT)
604 };
605 
606 static const struct dce_hwseq_mask hwseq_mask = {
607 		HWSEQ_DCN301_MASK_SH_LIST(_MASK)
608 };
609 #define vmid_regs(id)\
610 [id] = {\
611 		DCN20_VMID_REG_LIST(id)\
612 }
613 
614 static const struct dcn_vmid_registers vmid_regs[] = {
615 	vmid_regs(0),
616 	vmid_regs(1),
617 	vmid_regs(2),
618 	vmid_regs(3),
619 	vmid_regs(4),
620 	vmid_regs(5),
621 	vmid_regs(6),
622 	vmid_regs(7),
623 	vmid_regs(8),
624 	vmid_regs(9),
625 	vmid_regs(10),
626 	vmid_regs(11),
627 	vmid_regs(12),
628 	vmid_regs(13),
629 	vmid_regs(14),
630 	vmid_regs(15)
631 };
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 struct resource_caps res_cap_dcn301 = {
642 	.num_timing_generator = 4,
643 	.num_opp = 4,
644 	.num_video_plane = 4,
645 	.num_audio = 4,
646 	.num_stream_encoder = 4,
647 	.num_pll = 4,
648 	.num_dwb = 1,
649 	.num_ddc = 4,
650 	.num_vmid = 16,
651 	.num_mpc_3dlut = 2,
652 	.num_dsc = 3,
653 };
654 
655 static const struct dc_plane_cap plane_cap = {
656 	.type = DC_PLANE_TYPE_DCN_UNIVERSAL,
657 	.per_pixel_alpha = true,
658 
659 	.pixel_format_support = {
660 			.argb8888 = true,
661 			.nv12 = true,
662 			.fp16 = true,
663 			.p010 = true,
664 			.ayuv = false,
665 	},
666 
667 	.max_upscale_factor = {
668 			.argb8888 = 16000,
669 			.nv12 = 16000,
670 			.fp16 = 16000
671 	},
672 
673 	/* 6:1 downscaling ratio: 1000/6 = 166.666 */
674 	.max_downscale_factor = {
675 			.argb8888 = 358,
676 			.nv12 = 358,
677 			.fp16 = 358
678 	},
679 	64,
680 	64
681 };
682 
683 static const struct dc_debug_options debug_defaults_drv = {
684 	.disable_dmcu = true,
685 	.force_abm_enable = false,
686 	.clock_trace = true,
687 	.disable_dpp_power_gate = false,
688 	.disable_hubp_power_gate = false,
689 	.disable_clock_gate = true,
690 	.disable_pplib_clock_request = true,
691 	.disable_pplib_wm_range = true,
692 	.pipe_split_policy = MPC_SPLIT_DYNAMIC,
693 	.force_single_disp_pipe_split = false,
694 	.disable_dcc = DCC_ENABLE,
695 	.vsr_support = true,
696 	.performance_trace = false,
697 	.max_downscale_src_width = 4096,/*upto true 4k*/
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 	.use_max_lb = false,
704 	.exit_idle_opt_for_cursor_updates = true,
705 	.using_dml2 = false,
706 };
707 
708 static const struct dc_check_config config_defaults = {
709 	.enable_legacy_fast_update = true,
710 };
711 
dcn301_dpp_destroy(struct dpp ** dpp)712 static void dcn301_dpp_destroy(struct dpp **dpp)
713 {
714 	kfree(TO_DCN20_DPP(*dpp));
715 	*dpp = NULL;
716 }
717 
dcn301_dpp_create(struct dc_context * ctx,uint32_t inst)718 static struct dpp *dcn301_dpp_create(struct dc_context *ctx, uint32_t inst)
719 {
720 	struct dcn3_dpp *dpp =
721 		kzalloc_obj(struct dcn3_dpp);
722 
723 	if (!dpp)
724 		return NULL;
725 
726 	if (dpp3_construct(dpp, ctx, inst,
727 			&dpp_regs[inst], &tf_shift, &tf_mask))
728 		return &dpp->base;
729 
730 	BREAK_TO_DEBUGGER();
731 	kfree(dpp);
732 	return NULL;
733 }
dcn301_opp_create(struct dc_context * ctx,uint32_t inst)734 static struct output_pixel_processor *dcn301_opp_create(struct dc_context *ctx,
735 							uint32_t inst)
736 {
737 	struct dcn20_opp *opp =
738 		kzalloc_obj(struct dcn20_opp);
739 
740 	if (!opp) {
741 		BREAK_TO_DEBUGGER();
742 		return NULL;
743 	}
744 
745 	dcn20_opp_construct(opp, ctx, inst,
746 			&opp_regs[inst], &opp_shift, &opp_mask);
747 	return &opp->base;
748 }
749 
dcn301_aux_engine_create(struct dc_context * ctx,uint32_t inst)750 static struct dce_aux *dcn301_aux_engine_create(struct dc_context *ctx, uint32_t inst)
751 {
752 	struct aux_engine_dce110 *aux_engine =
753 		kzalloc_obj(struct aux_engine_dce110);
754 
755 	if (!aux_engine)
756 		return NULL;
757 
758 	dce110_aux_engine_construct(aux_engine, ctx, inst,
759 				    SW_AUX_TIMEOUT_PERIOD_MULTIPLIER * AUX_TIMEOUT_PERIOD,
760 				    &aux_engine_regs[inst],
761 					&aux_mask,
762 					&aux_shift,
763 					ctx->dc->caps.extended_aux_timeout_support);
764 
765 	return &aux_engine->base;
766 }
767 #define i2c_inst_regs(id) { I2C_HW_ENGINE_COMMON_REG_LIST(id) }
768 
769 static const struct dce_i2c_registers i2c_hw_regs[] = {
770 		i2c_inst_regs(1),
771 		i2c_inst_regs(2),
772 		i2c_inst_regs(3),
773 		i2c_inst_regs(4),
774 };
775 
776 static const struct dce_i2c_shift i2c_shifts = {
777 		I2C_COMMON_MASK_SH_LIST_DCN2(__SHIFT)
778 };
779 
780 static const struct dce_i2c_mask i2c_masks = {
781 		I2C_COMMON_MASK_SH_LIST_DCN2(_MASK)
782 };
783 
dcn301_i2c_hw_create(struct dc_context * ctx,uint32_t inst)784 static struct dce_i2c_hw *dcn301_i2c_hw_create(struct dc_context *ctx, uint32_t inst)
785 {
786 	struct dce_i2c_hw *dce_i2c_hw =
787 		kzalloc_obj(struct dce_i2c_hw);
788 
789 	if (!dce_i2c_hw)
790 		return NULL;
791 
792 	dcn2_i2c_hw_construct(dce_i2c_hw, ctx, inst,
793 				    &i2c_hw_regs[inst], &i2c_shifts, &i2c_masks);
794 
795 	return dce_i2c_hw;
796 }
dcn301_mpc_create(struct dc_context * ctx,int num_mpcc,int num_rmu)797 static struct mpc *dcn301_mpc_create(
798 		struct dc_context *ctx,
799 		int num_mpcc,
800 		int num_rmu)
801 {
802 	struct dcn30_mpc *mpc30 = kzalloc_obj(struct dcn30_mpc);
803 
804 	if (!mpc30)
805 		return NULL;
806 
807 	dcn30_mpc_construct(mpc30, ctx,
808 			&mpc_regs,
809 			&mpc_shift,
810 			&mpc_mask,
811 			num_mpcc,
812 			num_rmu);
813 
814 	return &mpc30->base;
815 }
816 
dcn301_hubbub_create(struct dc_context * ctx)817 static struct hubbub *dcn301_hubbub_create(struct dc_context *ctx)
818 {
819 	int i;
820 
821 	struct dcn20_hubbub *hubbub3 = kzalloc_obj(struct dcn20_hubbub);
822 
823 	if (!hubbub3)
824 		return NULL;
825 
826 	hubbub301_construct(hubbub3, ctx,
827 			&hubbub_reg,
828 			&hubbub_shift,
829 			&hubbub_mask);
830 
831 
832 	for (i = 0; i < res_cap_dcn301.num_vmid; i++) {
833 		struct dcn20_vmid *vmid = &hubbub3->vmid[i];
834 
835 		vmid->ctx = ctx;
836 
837 		vmid->regs = &vmid_regs[i];
838 		vmid->shifts = &vmid_shifts;
839 		vmid->masks = &vmid_masks;
840 	}
841 
842 	hubbub3->num_vmid = res_cap_dcn301.num_vmid;
843 
844 	return &hubbub3->base;
845 }
846 
847 static const struct dcn_dio_registers dio_regs = {
848 		DIO_REG_LIST_DCN10()
849 };
850 
851 #define DIO_MASK_SH_LIST(mask_sh)\
852 		HWS_SF(, DIO_MEM_PWR_CTRL, I2C_LIGHT_SLEEP_FORCE, mask_sh)
853 
854 static const struct dcn_dio_shift dio_shift = {
855 		DIO_MASK_SH_LIST(__SHIFT)
856 };
857 
858 static const struct dcn_dio_mask dio_mask = {
859 		DIO_MASK_SH_LIST(_MASK)
860 };
861 
dcn301_dio_create(struct dc_context * ctx)862 static struct dio *dcn301_dio_create(struct dc_context *ctx)
863 {
864 	struct dcn10_dio *dio10 = kzalloc_obj(struct dcn10_dio);
865 
866 	if (!dio10)
867 		return NULL;
868 
869 	dcn10_dio_construct(dio10, ctx, &dio_regs, &dio_shift, &dio_mask);
870 
871 	return &dio10->base;
872 }
873 
dcn301_timing_generator_create(struct dc_context * ctx,uint32_t instance)874 static struct timing_generator *dcn301_timing_generator_create(
875 	struct dc_context *ctx, uint32_t instance)
876 {
877 	struct optc *tgn10 =
878 		kzalloc_obj(struct optc);
879 
880 	if (!tgn10)
881 		return NULL;
882 
883 	tgn10->base.inst = instance;
884 	tgn10->base.ctx = ctx;
885 
886 	tgn10->tg_regs = &optc_regs[instance];
887 	tgn10->tg_shift = &optc_shift;
888 	tgn10->tg_mask = &optc_mask;
889 
890 	dcn301_timing_generator_init(tgn10);
891 
892 	return &tgn10->base;
893 }
894 
895 static const struct encoder_feature_support link_enc_feature = {
896 		.max_hdmi_deep_color = COLOR_DEPTH_121212,
897 		.max_hdmi_pixel_clock = 600000,
898 		.hdmi_ycbcr420_supported = true,
899 		.dp_ycbcr420_supported = true,
900 		.fec_supported = true,
901 		.flags.bits.IS_HBR2_CAPABLE = true,
902 		.flags.bits.IS_HBR3_CAPABLE = true,
903 		.flags.bits.IS_TPS3_CAPABLE = true,
904 		.flags.bits.IS_TPS4_CAPABLE = true
905 };
906 
dcn301_link_encoder_create(struct dc_context * ctx,const struct encoder_init_data * enc_init_data)907 static struct link_encoder *dcn301_link_encoder_create(
908 	struct dc_context *ctx,
909 	const struct encoder_init_data *enc_init_data)
910 {
911 	struct dcn20_link_encoder *enc20 =
912 		kzalloc_obj(struct dcn20_link_encoder);
913 
914 	if (!enc20 || enc_init_data->hpd_source >= ARRAY_SIZE(link_enc_hpd_regs))
915 		return NULL;
916 
917 	dcn301_link_encoder_construct(enc20,
918 			enc_init_data,
919 			&link_enc_feature,
920 			&link_enc_regs[enc_init_data->transmitter],
921 			&link_enc_aux_regs[enc_init_data->channel - 1],
922 			&link_enc_hpd_regs[enc_init_data->hpd_source],
923 			&le_shift,
924 			&le_mask);
925 
926 	return &enc20->enc10.base;
927 }
928 
dcn301_panel_cntl_create(const struct panel_cntl_init_data * init_data)929 static struct panel_cntl *dcn301_panel_cntl_create(const struct panel_cntl_init_data *init_data)
930 {
931 	struct dcn301_panel_cntl *panel_cntl =
932 		kzalloc_obj(struct dcn301_panel_cntl);
933 
934 	if (!panel_cntl)
935 		return NULL;
936 
937 	dcn301_panel_cntl_construct(panel_cntl,
938 			init_data,
939 			&panel_cntl_regs[init_data->inst],
940 			&panel_cntl_shift,
941 			&panel_cntl_mask);
942 
943 	return &panel_cntl->base;
944 }
945 
946 
947 #define CTX ctx
948 
949 #define REG(reg_name) \
950 	(DCN_BASE.instance[0].segment[mm ## reg_name ## _BASE_IDX] + mm ## reg_name)
951 
read_pipe_fuses(struct dc_context * ctx)952 static uint32_t read_pipe_fuses(struct dc_context *ctx)
953 {
954 	uint32_t value = REG_READ(CC_DC_PIPE_DIS);
955 	/* RV1 support max 4 pipes */
956 	value = value & 0xf;
957 	return value;
958 }
959 
960 
read_dce_straps(struct dc_context * ctx,struct resource_straps * straps)961 static void read_dce_straps(
962 	struct dc_context *ctx,
963 	struct resource_straps *straps)
964 {
965 	generic_reg_get(ctx, mmDC_PINSTRAPS + BASE(mmDC_PINSTRAPS_BASE_IDX),
966 		FN(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO), &straps->dc_pinstraps_audio);
967 
968 }
969 
dcn301_create_audio(struct dc_context * ctx,unsigned int inst)970 static struct audio *dcn301_create_audio(
971 		struct dc_context *ctx, unsigned int inst)
972 {
973 	return dce_audio_create(ctx, inst,
974 			&audio_regs[inst], &audio_shift, &audio_mask);
975 }
976 
dcn301_vpg_create(struct dc_context * ctx,uint32_t inst)977 static struct vpg *dcn301_vpg_create(
978 	struct dc_context *ctx,
979 	uint32_t inst)
980 {
981 	struct dcn30_vpg *vpg3 = kzalloc_obj(struct dcn30_vpg);
982 
983 	if (!vpg3)
984 		return NULL;
985 
986 	vpg3_construct(vpg3, ctx, inst,
987 			&vpg_regs[inst],
988 			&vpg_shift,
989 			&vpg_mask);
990 
991 	return &vpg3->base;
992 }
993 
dcn301_afmt_create(struct dc_context * ctx,uint32_t inst)994 static struct afmt *dcn301_afmt_create(
995 	struct dc_context *ctx,
996 	uint32_t inst)
997 {
998 	struct dcn30_afmt *afmt3 = kzalloc_obj(struct dcn30_afmt);
999 
1000 	if (!afmt3)
1001 		return NULL;
1002 
1003 	afmt3_construct(afmt3, ctx, inst,
1004 			&afmt_regs[inst],
1005 			&afmt_shift,
1006 			&afmt_mask);
1007 
1008 	return &afmt3->base;
1009 }
1010 
dcn301_stream_encoder_create(enum engine_id eng_id,struct dc_context * ctx)1011 static struct stream_encoder *dcn301_stream_encoder_create(enum engine_id eng_id,
1012 							   struct dc_context *ctx)
1013 {
1014 	struct dcn10_stream_encoder *enc1;
1015 	struct vpg *vpg;
1016 	struct afmt *afmt;
1017 	int vpg_inst;
1018 	int afmt_inst;
1019 
1020 	/* Mapping of VPG, AFMT, DME register blocks to DIO block instance */
1021 	if (eng_id <= ENGINE_ID_DIGF) {
1022 		vpg_inst = eng_id;
1023 		afmt_inst = eng_id;
1024 	} else
1025 		return NULL;
1026 
1027 	enc1 = kzalloc_obj(struct dcn10_stream_encoder);
1028 	vpg = dcn301_vpg_create(ctx, vpg_inst);
1029 	afmt = dcn301_afmt_create(ctx, afmt_inst);
1030 
1031 	if (!enc1 || !vpg || !afmt || eng_id >= ARRAY_SIZE(stream_enc_regs)) {
1032 		kfree(enc1);
1033 		kfree(vpg);
1034 		kfree(afmt);
1035 		return NULL;
1036 	}
1037 
1038 	dcn30_dio_stream_encoder_construct(enc1, ctx, ctx->dc_bios,
1039 					eng_id, vpg, afmt,
1040 					&stream_enc_regs[eng_id],
1041 					&se_shift, &se_mask);
1042 
1043 	return &enc1->base;
1044 }
1045 
dcn301_hwseq_create(struct dc_context * ctx)1046 static struct dce_hwseq *dcn301_hwseq_create(struct dc_context *ctx)
1047 {
1048 	struct dce_hwseq *hws = kzalloc_obj(struct dce_hwseq);
1049 
1050 	if (hws) {
1051 		hws->ctx = ctx;
1052 		hws->regs = &hwseq_reg;
1053 		hws->shifts = &hwseq_shift;
1054 		hws->masks = &hwseq_mask;
1055 	}
1056 	return hws;
1057 }
1058 static const struct resource_create_funcs res_create_funcs = {
1059 	.read_dce_straps = read_dce_straps,
1060 	.create_audio = dcn301_create_audio,
1061 	.create_stream_encoder = dcn301_stream_encoder_create,
1062 	.create_hwseq = dcn301_hwseq_create,
1063 };
1064 
dcn301_destruct(struct dcn301_resource_pool * pool)1065 static void dcn301_destruct(struct dcn301_resource_pool *pool)
1066 {
1067 	unsigned int i;
1068 
1069 	for (i = 0; i < pool->base.stream_enc_count; i++) {
1070 		if (pool->base.stream_enc[i] != NULL) {
1071 			if (pool->base.stream_enc[i]->vpg != NULL) {
1072 				kfree(DCN30_VPG_FROM_VPG(pool->base.stream_enc[i]->vpg));
1073 				pool->base.stream_enc[i]->vpg = NULL;
1074 			}
1075 			if (pool->base.stream_enc[i]->afmt != NULL) {
1076 				kfree(DCN30_AFMT_FROM_AFMT(pool->base.stream_enc[i]->afmt));
1077 				pool->base.stream_enc[i]->afmt = NULL;
1078 			}
1079 			kfree(DCN10STRENC_FROM_STRENC(pool->base.stream_enc[i]));
1080 			pool->base.stream_enc[i] = NULL;
1081 		}
1082 	}
1083 
1084 	for (i = 0; i < pool->base.res_cap->num_dsc; i++) {
1085 		if (pool->base.dscs[i] != NULL)
1086 			dcn20_dsc_destroy(&pool->base.dscs[i]);
1087 	}
1088 
1089 	if (pool->base.mpc != NULL) {
1090 		kfree(TO_DCN20_MPC(pool->base.mpc));
1091 		pool->base.mpc = NULL;
1092 	}
1093 	if (pool->base.hubbub != NULL) {
1094 		kfree(pool->base.hubbub);
1095 		pool->base.hubbub = NULL;
1096 	}
1097 
1098 	if (pool->base.dio != NULL) {
1099 		kfree(TO_DCN10_DIO(pool->base.dio));
1100 		pool->base.dio = NULL;
1101 	}
1102 
1103 	for (i = 0; i < pool->base.pipe_count; i++) {
1104 		if (pool->base.dpps[i] != NULL)
1105 			dcn301_dpp_destroy(&pool->base.dpps[i]);
1106 
1107 		if (pool->base.ipps[i] != NULL)
1108 			pool->base.ipps[i]->funcs->ipp_destroy(&pool->base.ipps[i]);
1109 
1110 		if (pool->base.hubps[i] != NULL) {
1111 			kfree(TO_DCN20_HUBP(pool->base.hubps[i]));
1112 			pool->base.hubps[i] = NULL;
1113 		}
1114 
1115 		if (pool->base.irqs != NULL) {
1116 			dal_irq_service_destroy(&pool->base.irqs);
1117 		}
1118 	}
1119 
1120 	for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
1121 		if (pool->base.engines[i] != NULL)
1122 			dce110_engine_destroy(&pool->base.engines[i]);
1123 		if (pool->base.hw_i2cs[i] != NULL) {
1124 			kfree(pool->base.hw_i2cs[i]);
1125 			pool->base.hw_i2cs[i] = NULL;
1126 		}
1127 		if (pool->base.sw_i2cs[i] != NULL) {
1128 			kfree(pool->base.sw_i2cs[i]);
1129 			pool->base.sw_i2cs[i] = NULL;
1130 		}
1131 	}
1132 
1133 	for (i = 0; i < pool->base.res_cap->num_opp; i++) {
1134 		if (pool->base.opps[i] != NULL)
1135 			pool->base.opps[i]->funcs->opp_destroy(&pool->base.opps[i]);
1136 	}
1137 
1138 	for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) {
1139 		if (pool->base.timing_generators[i] != NULL)	{
1140 			kfree(DCN10TG_FROM_TG(pool->base.timing_generators[i]));
1141 			pool->base.timing_generators[i] = NULL;
1142 		}
1143 	}
1144 
1145 	for (i = 0; i < pool->base.res_cap->num_dwb; i++) {
1146 		if (pool->base.dwbc[i] != NULL) {
1147 			kfree(TO_DCN30_DWBC(pool->base.dwbc[i]));
1148 			pool->base.dwbc[i] = NULL;
1149 		}
1150 		if (pool->base.mcif_wb[i] != NULL) {
1151 			kfree(TO_DCN30_MMHUBBUB(pool->base.mcif_wb[i]));
1152 			pool->base.mcif_wb[i] = NULL;
1153 		}
1154 	}
1155 
1156 	for (i = 0; i < pool->base.audio_count; i++) {
1157 		if (pool->base.audios[i])
1158 			dce_aud_destroy(&pool->base.audios[i]);
1159 	}
1160 
1161 	for (i = 0; i < pool->base.clk_src_count; i++) {
1162 		if (pool->base.clock_sources[i] != NULL) {
1163 			dcn20_clock_source_destroy(&pool->base.clock_sources[i]);
1164 			pool->base.clock_sources[i] = NULL;
1165 		}
1166 	}
1167 
1168 	for (i = 0; i < pool->base.res_cap->num_mpc_3dlut; i++) {
1169 		if (pool->base.mpc_lut[i] != NULL) {
1170 			dc_3dlut_func_release(pool->base.mpc_lut[i]);
1171 			pool->base.mpc_lut[i] = NULL;
1172 		}
1173 		if (pool->base.mpc_shaper[i] != NULL) {
1174 			dc_transfer_func_release(pool->base.mpc_shaper[i]);
1175 			pool->base.mpc_shaper[i] = NULL;
1176 		}
1177 	}
1178 
1179 	if (pool->base.dp_clock_source != NULL) {
1180 		dcn20_clock_source_destroy(&pool->base.dp_clock_source);
1181 		pool->base.dp_clock_source = NULL;
1182 	}
1183 
1184 	for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) {
1185 		if (pool->base.multiple_abms[i] != NULL)
1186 			dce_abm_destroy(&pool->base.multiple_abms[i]);
1187 	}
1188 
1189 	if (pool->base.dccg != NULL)
1190 		dcn_dccg_destroy(&pool->base.dccg);
1191 }
1192 
dcn301_hubp_create(struct dc_context * ctx,uint32_t inst)1193 static struct hubp *dcn301_hubp_create(struct dc_context *ctx, uint32_t inst)
1194 {
1195 	struct dcn20_hubp *hubp2 =
1196 		kzalloc_obj(struct dcn20_hubp);
1197 
1198 	if (!hubp2)
1199 		return NULL;
1200 
1201 	if (hubp3_construct(hubp2, ctx, inst,
1202 			&hubp_regs[inst], &hubp_shift, &hubp_mask))
1203 		return &hubp2->base;
1204 
1205 	BREAK_TO_DEBUGGER();
1206 	kfree(hubp2);
1207 	return NULL;
1208 }
1209 
dcn301_dwbc_create(struct dc_context * ctx,struct resource_pool * pool)1210 static bool dcn301_dwbc_create(struct dc_context *ctx, struct resource_pool *pool)
1211 {
1212 	int i;
1213 	uint32_t pipe_count = pool->res_cap->num_dwb;
1214 
1215 	for (i = 0; i < pipe_count; i++) {
1216 		struct dcn30_dwbc *dwbc30 = kzalloc_obj(struct dcn30_dwbc);
1217 
1218 		if (!dwbc30) {
1219 			dm_error("DC: failed to create dwbc30!\n");
1220 			return false;
1221 		}
1222 
1223 		dcn30_dwbc_construct(dwbc30, ctx,
1224 				&dwbc30_regs[i],
1225 				&dwbc30_shift,
1226 				&dwbc30_mask,
1227 				i);
1228 
1229 		pool->dwbc[i] = &dwbc30->base;
1230 	}
1231 	return true;
1232 }
1233 
dcn301_mmhubbub_create(struct dc_context * ctx,struct resource_pool * pool)1234 static bool dcn301_mmhubbub_create(struct dc_context *ctx, struct resource_pool *pool)
1235 {
1236 	int i;
1237 	uint32_t pipe_count = pool->res_cap->num_dwb;
1238 
1239 	for (i = 0; i < pipe_count; i++) {
1240 		struct dcn30_mmhubbub *mcif_wb30 = kzalloc_obj(struct dcn30_mmhubbub);
1241 
1242 		if (!mcif_wb30) {
1243 			dm_error("DC: failed to create mcif_wb30!\n");
1244 			return false;
1245 		}
1246 
1247 		dcn30_mmhubbub_construct(mcif_wb30, ctx,
1248 				&mcif_wb30_regs[i],
1249 				&mcif_wb30_shift,
1250 				&mcif_wb30_mask,
1251 				i);
1252 
1253 		pool->mcif_wb[i] = &mcif_wb30->base;
1254 	}
1255 	return true;
1256 }
1257 
dcn301_dsc_create(struct dc_context * ctx,uint32_t inst)1258 static struct display_stream_compressor *dcn301_dsc_create(
1259 	struct dc_context *ctx, uint32_t inst)
1260 {
1261 	struct dcn20_dsc *dsc =
1262 		kzalloc_obj(struct dcn20_dsc);
1263 
1264 	if (!dsc) {
1265 		BREAK_TO_DEBUGGER();
1266 		return NULL;
1267 	}
1268 
1269 	dsc2_construct(dsc, ctx, inst, &dsc_regs[inst], &dsc_shift, &dsc_mask);
1270 	return &dsc->base;
1271 }
1272 
1273 
dcn301_destroy_resource_pool(struct resource_pool ** pool)1274 static void dcn301_destroy_resource_pool(struct resource_pool **pool)
1275 {
1276 	struct dcn301_resource_pool *dcn301_pool = TO_DCN301_RES_POOL(*pool);
1277 
1278 	dcn301_destruct(dcn301_pool);
1279 	kfree(dcn301_pool);
1280 	*pool = NULL;
1281 }
1282 
dcn301_clock_source_create(struct dc_context * ctx,struct dc_bios * bios,enum clock_source_id id,const struct dce110_clk_src_regs * regs,bool dp_clk_src)1283 static struct clock_source *dcn301_clock_source_create(
1284 		struct dc_context *ctx,
1285 		struct dc_bios *bios,
1286 		enum clock_source_id id,
1287 		const struct dce110_clk_src_regs *regs,
1288 		bool dp_clk_src)
1289 {
1290 	struct dce110_clk_src *clk_src =
1291 		kzalloc_obj(struct dce110_clk_src);
1292 
1293 	if (!clk_src)
1294 		return NULL;
1295 
1296 	if (dcn301_clk_src_construct(clk_src, ctx, bios, id,
1297 			regs, &cs_shift, &cs_mask)) {
1298 		clk_src->base.dp_clk_src = dp_clk_src;
1299 		return &clk_src->base;
1300 	}
1301 
1302 	kfree(clk_src);
1303 	BREAK_TO_DEBUGGER();
1304 	return NULL;
1305 }
1306 
1307 static struct dc_cap_funcs cap_funcs = {
1308 	.get_dcc_compression_cap = dcn20_get_dcc_compression_cap
1309 };
1310 
1311 
is_soc_bounding_box_valid(struct dc * dc)1312 static bool is_soc_bounding_box_valid(struct dc *dc)
1313 {
1314 	uint32_t hw_internal_rev = dc->ctx->asic_id.hw_internal_rev;
1315 
1316 	if (ASICREV_IS_VANGOGH(hw_internal_rev))
1317 		return true;
1318 
1319 	return false;
1320 }
1321 
init_soc_bounding_box(struct dc * dc,struct dcn301_resource_pool * pool)1322 static bool init_soc_bounding_box(struct dc *dc,
1323 				  struct dcn301_resource_pool *pool)
1324 {
1325 	struct _vcs_dpi_soc_bounding_box_st *loaded_bb = &dcn3_01_soc;
1326 	struct _vcs_dpi_ip_params_st *loaded_ip = &dcn3_01_ip;
1327 
1328 	DC_LOGGER_INIT(dc->ctx->logger);
1329 
1330 	if (!is_soc_bounding_box_valid(dc)) {
1331 		DC_LOG_ERROR("%s: not valid soc bounding box\n", __func__);
1332 		return false;
1333 	}
1334 
1335 	loaded_ip->max_num_otg = pool->base.res_cap->num_timing_generator;
1336 	loaded_ip->max_num_dpp = pool->base.pipe_count;
1337 	DC_FP_START();
1338 	dcn20_patch_bounding_box(dc, loaded_bb);
1339 	DC_FP_END();
1340 
1341 	if (dc->ctx->dc_bios->funcs->get_soc_bb_info) {
1342 		struct bp_soc_bb_info bb_info = {0};
1343 
1344 		if (dc->ctx->dc_bios->funcs->get_soc_bb_info(dc->ctx->dc_bios, &bb_info) == BP_RESULT_OK) {
1345 			DC_FP_START();
1346 			dcn301_fpu_init_soc_bounding_box(bb_info);
1347 			DC_FP_END();
1348 		}
1349 	}
1350 
1351 	return true;
1352 }
1353 
1354 
set_wm_ranges(struct pp_smu_funcs * pp_smu,struct _vcs_dpi_soc_bounding_box_st * loaded_bb)1355 static void set_wm_ranges(
1356 		struct pp_smu_funcs *pp_smu,
1357 		struct _vcs_dpi_soc_bounding_box_st *loaded_bb)
1358 {
1359 	struct pp_smu_wm_range_sets ranges = {0};
1360 	int i;
1361 
1362 	ranges.num_reader_wm_sets = 0;
1363 
1364 	if (loaded_bb->num_states == 1) {
1365 		ranges.reader_wm_sets[0].wm_inst = 0;
1366 		ranges.reader_wm_sets[0].min_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN;
1367 		ranges.reader_wm_sets[0].max_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX;
1368 		ranges.reader_wm_sets[0].min_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN;
1369 		ranges.reader_wm_sets[0].max_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX;
1370 
1371 		ranges.num_reader_wm_sets = 1;
1372 	} else if (loaded_bb->num_states > 1) {
1373 		for (i = 0; i < 4 && i < loaded_bb->num_states; i++) {
1374 			ranges.reader_wm_sets[i].wm_inst = i;
1375 			ranges.reader_wm_sets[i].min_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN;
1376 			ranges.reader_wm_sets[i].max_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX;
1377 			DC_FP_START();
1378 			dcn301_fpu_set_wm_ranges(i, &ranges, loaded_bb);
1379 			DC_FP_END();
1380 			ranges.num_reader_wm_sets = i + 1;
1381 		}
1382 
1383 		ranges.reader_wm_sets[0].min_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN;
1384 		ranges.reader_wm_sets[ranges.num_reader_wm_sets - 1].max_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX;
1385 	}
1386 
1387 	ranges.num_writer_wm_sets = 1;
1388 
1389 	ranges.writer_wm_sets[0].wm_inst = 0;
1390 	ranges.writer_wm_sets[0].min_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN;
1391 	ranges.writer_wm_sets[0].max_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX;
1392 	ranges.writer_wm_sets[0].min_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN;
1393 	ranges.writer_wm_sets[0].max_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX;
1394 
1395 	/* Notify PP Lib/SMU which Watermarks to use for which clock ranges */
1396 	pp_smu->nv_funcs.set_wm_ranges(&pp_smu->nv_funcs.pp_smu, &ranges);
1397 }
1398 
dcn301_update_bw_bounding_box(struct dc * dc,struct clk_bw_params * bw_params)1399 static void dcn301_update_bw_bounding_box(struct dc *dc, struct clk_bw_params *bw_params)
1400 {
1401 	DC_FP_START();
1402 	dcn301_fpu_update_bw_bounding_box(dc, bw_params);
1403 	DC_FP_END();
1404 }
1405 
dcn301_calculate_wm_and_dlg(struct dc * dc,struct dc_state * context,display_e2e_pipe_params_st * pipes,int pipe_cnt,int vlevel_req)1406 static void dcn301_calculate_wm_and_dlg(struct dc *dc,
1407 					struct dc_state *context,
1408 					display_e2e_pipe_params_st *pipes,
1409 					int pipe_cnt,
1410 					int vlevel_req)
1411 {
1412 	DC_FP_START();
1413 	dcn301_fpu_calculate_wm_and_dlg(dc, context, pipes, pipe_cnt, vlevel_req);
1414 	DC_FP_END();
1415 }
1416 
1417 static struct resource_funcs dcn301_res_pool_funcs = {
1418 	.destroy = dcn301_destroy_resource_pool,
1419 	.link_enc_create = dcn301_link_encoder_create,
1420 	.panel_cntl_create = dcn301_panel_cntl_create,
1421 	.validate_bandwidth = dcn30_validate_bandwidth,
1422 	.calculate_wm_and_dlg = dcn301_calculate_wm_and_dlg,
1423 	.update_soc_for_wm_a = dcn30_update_soc_for_wm_a,
1424 	.populate_dml_pipes = dcn30_populate_dml_pipes_from_context,
1425 	.acquire_free_pipe_as_secondary_dpp_pipe = dcn20_acquire_free_pipe_for_layer,
1426 	.release_pipe = dcn20_release_pipe,
1427 	.add_stream_to_ctx = dcn30_add_stream_to_ctx,
1428 	.add_dsc_to_stream_resource = dcn20_add_dsc_to_stream_resource,
1429 	.remove_stream_from_ctx = dcn20_remove_stream_from_ctx,
1430 	.populate_dml_writeback_from_context = dcn30_populate_dml_writeback_from_context,
1431 	.set_mcif_arb_params = dcn30_set_mcif_arb_params,
1432 	.find_first_free_match_stream_enc_for_link = dcn10_find_first_free_match_stream_enc_for_link,
1433 	.acquire_post_bldn_3dlut = dcn30_acquire_post_bldn_3dlut,
1434 	.release_post_bldn_3dlut = dcn30_release_post_bldn_3dlut,
1435 	.update_bw_bounding_box = dcn301_update_bw_bounding_box,
1436 	.patch_unknown_plane_state = dcn20_patch_unknown_plane_state,
1437 	.get_vstartup_for_pipe = dcn10_get_vstartup_for_pipe
1438 };
1439 
dcn301_resource_construct(uint8_t num_virtual_links,struct dc * dc,struct dcn301_resource_pool * pool)1440 static bool dcn301_resource_construct(
1441 	uint8_t num_virtual_links,
1442 	struct dc *dc,
1443 	struct dcn301_resource_pool *pool)
1444 {
1445 	int i, j;
1446 	struct dc_context *ctx = dc->ctx;
1447 	struct irq_service_init_data init_data;
1448 	uint32_t pipe_fuses = read_pipe_fuses(ctx);
1449 	uint32_t num_pipes = 0;
1450 
1451 	DC_LOGGER_INIT(dc->ctx->logger);
1452 
1453 	ctx->dc_bios->regs = &bios_regs;
1454 
1455 	if (dc->ctx->asic_id.chip_id == DEVICE_ID_VGH_1435)
1456 		res_cap_dcn301.num_pll = 2;
1457 	pool->base.res_cap = &res_cap_dcn301;
1458 
1459 	pool->base.funcs = &dcn301_res_pool_funcs;
1460 
1461 	/*************************************************
1462 	 *  Resource + asic cap harcoding                *
1463 	 *************************************************/
1464 	pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
1465 	pool->base.pipe_count = pool->base.res_cap->num_timing_generator;
1466 	pool->base.mpcc_count = pool->base.res_cap->num_timing_generator;
1467 	dc->caps.max_downscale_ratio = 600;
1468 	dc->caps.i2c_speed_in_khz = 100;
1469 	dc->caps.i2c_speed_in_khz_hdcp = 5; /*1.4 w/a enabled by default*/
1470 	dc->caps.max_cursor_size = 256;
1471 	dc->caps.min_horizontal_blanking_period = 80;
1472 	dc->caps.dmdata_alloc_size = 2048;
1473 	dc->caps.max_slave_planes = 2;
1474 	dc->caps.max_slave_yuv_planes = 2;
1475 	dc->caps.max_slave_rgb_planes = 2;
1476 	dc->caps.is_apu = true;
1477 	dc->caps.post_blend_color_processing = true;
1478 	dc->caps.force_dp_tps4_for_cp2520 = true;
1479 	dc->caps.extended_aux_timeout_support = true;
1480 	dc->caps.dmcub_support = true;
1481 
1482 	/* Color pipeline capabilities */
1483 	dc->caps.color.dpp.dcn_arch = 1;
1484 	dc->caps.color.dpp.input_lut_shared = 0;
1485 	dc->caps.color.dpp.icsc = 1;
1486 	dc->caps.color.dpp.dgam_ram = 0; // must use gamma_corr
1487 	dc->caps.color.dpp.dgam_rom_caps.srgb = 1;
1488 	dc->caps.color.dpp.dgam_rom_caps.bt2020 = 1;
1489 	dc->caps.color.dpp.dgam_rom_caps.gamma2_2 = 1;
1490 	dc->caps.color.dpp.dgam_rom_caps.pq = 1;
1491 	dc->caps.color.dpp.dgam_rom_caps.hlg = 1;
1492 	dc->caps.color.dpp.post_csc = 1;
1493 	dc->caps.color.dpp.gamma_corr = 1;
1494 	dc->caps.color.dpp.dgam_rom_for_yuv = 0;
1495 
1496 	dc->caps.color.dpp.hw_3d_lut = 1;
1497 	dc->caps.color.dpp.ogam_ram = 1;
1498 	// no OGAM ROM on DCN301
1499 	dc->caps.color.dpp.ogam_rom_caps.srgb = 0;
1500 	dc->caps.color.dpp.ogam_rom_caps.bt2020 = 0;
1501 	dc->caps.color.dpp.ogam_rom_caps.gamma2_2 = 0;
1502 	dc->caps.color.dpp.ogam_rom_caps.pq = 0;
1503 	dc->caps.color.dpp.ogam_rom_caps.hlg = 0;
1504 	dc->caps.color.dpp.ocsc = 0;
1505 
1506 	dc->caps.color.mpc.gamut_remap = 1;
1507 	dc->caps.color.mpc.num_3dluts = pool->base.res_cap->num_mpc_3dlut; //2
1508 	dc->caps.color.mpc.ogam_ram = 1;
1509 	dc->caps.color.mpc.ogam_rom_caps.srgb = 0;
1510 	dc->caps.color.mpc.ogam_rom_caps.bt2020 = 0;
1511 	dc->caps.color.mpc.ogam_rom_caps.gamma2_2 = 0;
1512 	dc->caps.color.mpc.ogam_rom_caps.pq = 0;
1513 	dc->caps.color.mpc.ogam_rom_caps.hlg = 0;
1514 	dc->caps.color.mpc.ocsc = 1;
1515 
1516 	dc->caps.dp_hdmi21_pcon_support = true;
1517 
1518 	/* read VBIOS LTTPR caps */
1519 	if (ctx->dc_bios->funcs->get_lttpr_caps) {
1520 		enum bp_result bp_query_result;
1521 		uint8_t is_vbios_lttpr_enable = 0;
1522 
1523 		bp_query_result = ctx->dc_bios->funcs->get_lttpr_caps(ctx->dc_bios, &is_vbios_lttpr_enable);
1524 		dc->caps.vbios_lttpr_enable = (bp_query_result == BP_RESULT_OK) && !!is_vbios_lttpr_enable;
1525 	}
1526 
1527 	if (ctx->dc_bios->funcs->get_lttpr_interop) {
1528 		enum bp_result bp_query_result;
1529 		uint8_t is_vbios_interop_enabled = 0;
1530 
1531 		bp_query_result = ctx->dc_bios->funcs->get_lttpr_interop(ctx->dc_bios, &is_vbios_interop_enabled);
1532 		dc->caps.vbios_lttpr_aware = (bp_query_result == BP_RESULT_OK) && !!is_vbios_interop_enabled;
1533 	}
1534 	dc->check_config = config_defaults;
1535 
1536 	if (dc->ctx->dce_environment == DCE_ENV_PRODUCTION_DRV)
1537 		dc->debug = debug_defaults_drv;
1538 
1539 	// Init the vm_helper
1540 	if (dc->vm_helper)
1541 		vm_helper_init(dc->vm_helper, 16);
1542 
1543 	/*************************************************
1544 	 *  Create resources                             *
1545 	 *************************************************/
1546 
1547 	/* Clock Sources for Pixel Clock*/
1548 	pool->base.clock_sources[DCN301_CLK_SRC_PLL0] =
1549 			dcn301_clock_source_create(ctx, ctx->dc_bios,
1550 				CLOCK_SOURCE_COMBO_PHY_PLL0,
1551 				&clk_src_regs[0], false);
1552 	pool->base.clock_sources[DCN301_CLK_SRC_PLL1] =
1553 			dcn301_clock_source_create(ctx, ctx->dc_bios,
1554 				CLOCK_SOURCE_COMBO_PHY_PLL1,
1555 				&clk_src_regs[1], false);
1556 	pool->base.clock_sources[DCN301_CLK_SRC_PLL2] =
1557 			dcn301_clock_source_create(ctx, ctx->dc_bios,
1558 				CLOCK_SOURCE_COMBO_PHY_PLL2,
1559 				&clk_src_regs[2], false);
1560 	pool->base.clock_sources[DCN301_CLK_SRC_PLL3] =
1561 			dcn301_clock_source_create(ctx, ctx->dc_bios,
1562 				CLOCK_SOURCE_COMBO_PHY_PLL3,
1563 				&clk_src_regs[3], false);
1564 
1565 	pool->base.clk_src_count = DCN301_CLK_SRC_TOTAL;
1566 
1567 	/* todo: not reuse phy_pll registers */
1568 	pool->base.dp_clock_source =
1569 			dcn301_clock_source_create(ctx, ctx->dc_bios,
1570 				CLOCK_SOURCE_ID_DP_DTO,
1571 				&clk_src_regs[0], true);
1572 
1573 	for (i = 0; i < pool->base.clk_src_count; i++) {
1574 		if (pool->base.clock_sources[i] == NULL) {
1575 			dm_error("DC: failed to create clock sources!\n");
1576 			BREAK_TO_DEBUGGER();
1577 			goto create_fail;
1578 		}
1579 	}
1580 
1581 	/* DCCG */
1582 	pool->base.dccg = dccg301_create(ctx, &dccg_regs, &dccg_shift, &dccg_mask);
1583 	if (pool->base.dccg == NULL) {
1584 		dm_error("DC: failed to create dccg!\n");
1585 		BREAK_TO_DEBUGGER();
1586 		goto create_fail;
1587 	}
1588 
1589 	init_soc_bounding_box(dc, pool);
1590 
1591 	if (!dc->debug.disable_pplib_wm_range && pool->base.pp_smu->nv_funcs.set_wm_ranges)
1592 		set_wm_ranges(pool->base.pp_smu, &dcn3_01_soc);
1593 
1594 	num_pipes = dcn3_01_ip.max_num_dpp;
1595 
1596 	for (i = 0; i < dcn3_01_ip.max_num_dpp; i++)
1597 		if (pipe_fuses & 1 << i)
1598 			num_pipes--;
1599 	dcn3_01_ip.max_num_dpp = num_pipes;
1600 	dcn3_01_ip.max_num_otg = num_pipes;
1601 
1602 
1603 	dml_init_instance(&dc->dml, &dcn3_01_soc, &dcn3_01_ip, DML_PROJECT_DCN30);
1604 
1605 	/* IRQ */
1606 	init_data.ctx = dc->ctx;
1607 	pool->base.irqs = dal_irq_service_dcn30_create(&init_data);
1608 	if (!pool->base.irqs)
1609 		goto create_fail;
1610 
1611 	/* HUBBUB */
1612 	pool->base.hubbub = dcn301_hubbub_create(ctx);
1613 	if (pool->base.hubbub == NULL) {
1614 		BREAK_TO_DEBUGGER();
1615 		dm_error("DC: failed to create hubbub!\n");
1616 		goto create_fail;
1617 	}
1618 
1619 	/* DIO */
1620 	pool->base.dio = dcn301_dio_create(ctx);
1621 	if (pool->base.dio == NULL) {
1622 		BREAK_TO_DEBUGGER();
1623 		dm_error("DC: failed to create dio!\n");
1624 		goto create_fail;
1625 	}
1626 
1627 	j = 0;
1628 	/* HUBPs, DPPs, OPPs and TGs */
1629 	for (i = 0; i < pool->base.pipe_count; i++) {
1630 
1631 		/* if pipe is disabled, skip instance of HW pipe,
1632 		 * i.e, skip ASIC register instance
1633 		 */
1634 		if ((pipe_fuses & (1 << i)) != 0) {
1635 			DC_LOG_DEBUG("%s: fusing pipe %d\n", __func__, i);
1636 			continue;
1637 		}
1638 
1639 		pool->base.hubps[j] = dcn301_hubp_create(ctx, i);
1640 		if (pool->base.hubps[j] == NULL) {
1641 			BREAK_TO_DEBUGGER();
1642 			dm_error(
1643 				"DC: failed to create hubps!\n");
1644 			goto create_fail;
1645 		}
1646 
1647 		pool->base.dpps[j] = dcn301_dpp_create(ctx, i);
1648 		if (pool->base.dpps[j] == NULL) {
1649 			BREAK_TO_DEBUGGER();
1650 			dm_error(
1651 				"DC: failed to create dpps!\n");
1652 			goto create_fail;
1653 		}
1654 
1655 		pool->base.opps[j] = dcn301_opp_create(ctx, i);
1656 		if (pool->base.opps[j] == NULL) {
1657 			BREAK_TO_DEBUGGER();
1658 			dm_error(
1659 				"DC: failed to create output pixel processor!\n");
1660 			goto create_fail;
1661 		}
1662 
1663 		pool->base.timing_generators[j] = dcn301_timing_generator_create(ctx, i);
1664 		if (pool->base.timing_generators[j] == NULL) {
1665 			BREAK_TO_DEBUGGER();
1666 			dm_error("DC: failed to create tg!\n");
1667 			goto create_fail;
1668 		}
1669 		j++;
1670 	}
1671 	pool->base.timing_generator_count = j;
1672 	pool->base.pipe_count = j;
1673 	pool->base.mpcc_count = j;
1674 
1675 	/* ABM (or ABMs for NV2x) */
1676 	/* TODO: */
1677 	for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) {
1678 		pool->base.multiple_abms[i] = dmub_abm_create(ctx,
1679 				&abm_regs[i],
1680 				&abm_shift,
1681 				&abm_mask);
1682 		if (pool->base.multiple_abms[i] == NULL) {
1683 			dm_error("DC: failed to create abm for pipe %d!\n", i);
1684 			BREAK_TO_DEBUGGER();
1685 			goto create_fail;
1686 		}
1687 	}
1688 
1689 	/* MPC and DSC */
1690 	pool->base.mpc = dcn301_mpc_create(ctx, pool->base.mpcc_count, pool->base.res_cap->num_mpc_3dlut);
1691 	if (pool->base.mpc == NULL) {
1692 		BREAK_TO_DEBUGGER();
1693 		dm_error("DC: failed to create mpc!\n");
1694 		goto create_fail;
1695 	}
1696 
1697 	for (i = 0; i < pool->base.res_cap->num_dsc; i++) {
1698 		pool->base.dscs[i] = dcn301_dsc_create(ctx, i);
1699 		if (pool->base.dscs[i] == NULL) {
1700 			BREAK_TO_DEBUGGER();
1701 			dm_error("DC: failed to create display stream compressor %d!\n", i);
1702 			goto create_fail;
1703 		}
1704 	}
1705 
1706 	/* DWB and MMHUBBUB */
1707 	if (!dcn301_dwbc_create(ctx, &pool->base)) {
1708 		BREAK_TO_DEBUGGER();
1709 		dm_error("DC: failed to create dwbc!\n");
1710 		goto create_fail;
1711 	}
1712 
1713 	if (!dcn301_mmhubbub_create(ctx, &pool->base)) {
1714 		BREAK_TO_DEBUGGER();
1715 		dm_error("DC: failed to create mcif_wb!\n");
1716 		goto create_fail;
1717 	}
1718 
1719 	/* AUX and I2C */
1720 	for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
1721 		pool->base.engines[i] = dcn301_aux_engine_create(ctx, i);
1722 		if (pool->base.engines[i] == NULL) {
1723 			BREAK_TO_DEBUGGER();
1724 			dm_error(
1725 				"DC:failed to create aux engine!!\n");
1726 			goto create_fail;
1727 		}
1728 		pool->base.hw_i2cs[i] = dcn301_i2c_hw_create(ctx, i);
1729 		if (pool->base.hw_i2cs[i] == NULL) {
1730 			BREAK_TO_DEBUGGER();
1731 			dm_error(
1732 				"DC:failed to create hw i2c!!\n");
1733 			goto create_fail;
1734 		}
1735 		pool->base.sw_i2cs[i] = NULL;
1736 	}
1737 
1738 	/* Audio, Stream Encoders including HPO and virtual, MPC 3D LUTs */
1739 	if (!resource_construct(num_virtual_links, dc, &pool->base,
1740 			&res_create_funcs))
1741 		goto create_fail;
1742 
1743 	/* HW Sequencer and Plane caps */
1744 	dcn301_hw_sequencer_construct(dc);
1745 
1746 	dc->caps.max_planes =  pool->base.pipe_count;
1747 
1748 	for (i = 0; i < dc->caps.max_planes; ++i)
1749 		dc->caps.planes[i] = plane_cap;
1750 
1751 	dc->caps.max_odm_combine_factor = 4;
1752 
1753 	dc->cap_funcs = cap_funcs;
1754 
1755 	return true;
1756 
1757 create_fail:
1758 
1759 	dcn301_destruct(pool);
1760 
1761 	return false;
1762 }
1763 
dcn301_create_resource_pool(const struct dc_init_data * init_data,struct dc * dc)1764 struct resource_pool *dcn301_create_resource_pool(
1765 		const struct dc_init_data *init_data,
1766 		struct dc *dc)
1767 {
1768 	struct dcn301_resource_pool *pool =
1769 		kzalloc_obj(struct dcn301_resource_pool);
1770 
1771 	if (!pool)
1772 		return NULL;
1773 
1774 	if (dcn301_resource_construct(init_data->num_virtual_links, dc, pool))
1775 		return &pool->base;
1776 
1777 	BREAK_TO_DEBUGGER();
1778 	kfree(pool);
1779 	return NULL;
1780 }
1781