1 // SPDX-License-Identifier: MIT
2 //
3 // Copyright 2024 Advanced Micro Devices, Inc.
4 
5 #include "dm_services.h"
6 #include "dc.h"
7 
8 #include "dcn32/dcn32_init.h"
9 #include "dcn401/dcn401_init.h"
10 
11 #include "resource.h"
12 #include "include/irq_service_interface.h"
13 #include "dcn401_resource.h"
14 
15 #include "dcn20/dcn20_resource.h"
16 #include "dcn30/dcn30_resource.h"
17 #include "dcn32/dcn32_resource.h"
18 #include "dcn321/dcn321_resource.h"
19 
20 #include "dcn10/dcn10_ipp.h"
21 #include "dcn401/dcn401_hubbub.h"
22 #include "dcn401/dcn401_mpc.h"
23 #include "dcn401/dcn401_hubp.h"
24 #include "irq/dcn401/irq_service_dcn401.h"
25 #include "dcn401/dcn401_dpp.h"
26 #include "dcn401/dcn401_optc.h"
27 #include "dcn20/dcn20_hwseq.h"
28 #include "dcn30/dcn30_hwseq.h"
29 #include "dce110/dce110_hwseq.h"
30 #include "dcn20/dcn20_opp.h"
31 #include "dcn401/dcn401_dsc.h"
32 #include "dcn30/dcn30_vpg.h"
33 #include "dcn31/dcn31_vpg.h"
34 #include "dcn30/dcn30_afmt.h"
35 #include "dcn30/dcn30_dio_stream_encoder.h"
36 #include "dcn401/dcn401_dio_stream_encoder.h"
37 #include "dcn31/dcn31_hpo_dp_stream_encoder.h"
38 #include "dcn31/dcn31_hpo_dp_link_encoder.h"
39 #include "dcn32/dcn32_hpo_dp_link_encoder.h"
40 #include "dcn31/dcn31_apg.h"
41 #include "dcn31/dcn31_dio_link_encoder.h"
42 #include "dcn401/dcn401_dio_link_encoder.h"
43 #include "dcn10/dcn10_link_encoder.h"
44 #include "dcn321/dcn321_dio_link_encoder.h"
45 #include "dce/dce_clock_source.h"
46 #include "dce/dce_audio.h"
47 #include "dce/dce_hwseq.h"
48 #include "clk_mgr.h"
49 #include "virtual/virtual_stream_encoder.h"
50 #include "dml/display_mode_vba.h"
51 #include "dcn401/dcn401_dccg.h"
52 #include "dcn10/dcn10_resource.h"
53 #include "link.h"
54 #include "link_enc_cfg.h"
55 #include "dcn31/dcn31_panel_cntl.h"
56 
57 #include "dcn30/dcn30_dwb.h"
58 #include "dcn32/dcn32_mmhubbub.h"
59 
60 #include "dcn/dcn_4_1_0_offset.h"
61 #include "dcn/dcn_4_1_0_sh_mask.h"
62 #include "nbif/nbif_6_3_1_offset.h"
63 
64 #include "reg_helper.h"
65 #include "dce/dmub_abm.h"
66 #include "dce/dmub_psr.h"
67 #include "dce/dce_aux.h"
68 #include "dce/dce_i2c.h"
69 
70 #include "dml/dcn30/display_mode_vba_30.h"
71 #include "vm_helper.h"
72 #include "dcn20/dcn20_vmid.h"
73 #include "dml/dcn401/dcn401_fpu.h"
74 
75 #include "dc_state_priv.h"
76 
77 #include "dml2/dml2_wrapper.h"
78 
79 #define DC_LOGGER_INIT(logger)
80 
81 enum dcn401_clk_src_array_id {
82 	DCN401_CLK_SRC_PLL0,
83 	DCN401_CLK_SRC_PLL1,
84 	DCN401_CLK_SRC_PLL2,
85 	DCN401_CLK_SRC_PLL3,
86 	//DCN401_CLK_SRC_PLL4,
87 	DCN401_CLK_SRC_TOTAL
88 };
89 
90 /* begin *********************
91  * macros to expend register list macro defined in HW object header file
92  */
93 
94 /* DCN */
95 #define BASE_INNER(seg) ctx->dcn_reg_offsets[seg]
96 
97 #define BASE(seg) BASE_INNER(seg)
98 
99 #define SR(reg_name)\
100 	REG_STRUCT.reg_name = BASE(reg ## reg_name ## _BASE_IDX) +  \
101 		reg ## reg_name
102 #define SR_ARR(reg_name, id)\
103 	REG_STRUCT[id].reg_name = BASE(reg ## reg_name ## _BASE_IDX) +  \
104 		reg ## reg_name
105 #define SR_ARR_INIT(reg_name, id, value)\
106 	REG_STRUCT[id].reg_name =  value
107 
108 #define SRI(reg_name, block, id)\
109 	REG_STRUCT.reg_name = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
110 		reg ## block ## id ## _ ## reg_name
111 
112 #define SRI_ARR(reg_name, block, id)\
113 	REG_STRUCT[id].reg_name = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
114 		reg ## block ## id ## _ ## reg_name
115 
116 /*
117  * Used when a reg_name would otherwise begin with an integer
118  */
119 #define SRI_ARR_US(reg_name, block, id)\
120 	REG_STRUCT[id].reg_name = BASE(reg ## block ## id ## reg_name ## _BASE_IDX) + \
121 		reg ## block ## id ## reg_name
122 #define SR_ARR_I2C(reg_name, id) \
123 	REG_STRUCT[id-1].reg_name = BASE(reg##reg_name##_BASE_IDX) + reg##reg_name
124 
125 #define SRI_ARR_I2C(reg_name, block, id)\
126 	REG_STRUCT[id-1].reg_name = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
127 		reg ## block ## id ## _ ## reg_name
128 
129 #define SRI_ARR_ALPHABET(reg_name, block, index, id)\
130 	REG_STRUCT[index].reg_name = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
131 		reg ## block ## id ## _ ## reg_name
132 
133 #define SRI2(reg_name, block, id)\
134 	.reg_name = BASE(reg ## reg_name ## _BASE_IDX) + \
135 		reg ## reg_name
136 #define SRI2_ARR(reg_name, block, id)\
137 	REG_STRUCT[id].reg_name = BASE(reg ## reg_name ## _BASE_IDX) + \
138 		reg ## reg_name
139 
140 #define SRIR(var_name, reg_name, block, id)\
141 	.var_name = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
142 		reg ## block ## id ## _ ## reg_name
143 
144 #define SRII(reg_name, block, id)\
145 	REG_STRUCT.reg_name[id] = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
146 		reg ## block ## id ## _ ## reg_name
147 
148 #define SRII_ARR_2(reg_name, block, id, inst)\
149 	REG_STRUCT[inst].reg_name[id] = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
150 		reg ## block ## id ## _ ## reg_name
151 
152 #define SRII_MPC_RMU(reg_name, block, id)\
153 	.RMU##_##reg_name[id] = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
154 		reg ## block ## id ## _ ## reg_name
155 
156 #define SRII_DWB(reg_name, temp_name, block, id)\
157 	REG_STRUCT.reg_name[id] = BASE(reg ## block ## id ## _ ## temp_name ## _BASE_IDX) + \
158 		reg ## block ## id ## _ ## temp_name
159 
160 #define DCCG_SRII(reg_name, block, id)\
161 	REG_STRUCT.block ## _ ## reg_name[id] = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
162 		reg ## block ## id ## _ ## reg_name
163 
164 #define SF_DWB2(reg_name, block, id, field_name, post_fix) \
165 	.field_name = reg_name ## __ ## field_name ## post_fix
166 
167 #define VUPDATE_SRII(reg_name, block, id)\
168 	REG_STRUCT.reg_name[id] = BASE(reg ## reg_name ## _ ## block ## id ## _BASE_IDX) + \
169 		reg ## reg_name ## _ ## block ## id
170 
171 /* NBIO */
172 #define NBIO_BASE_INNER(seg) ctx->nbio_reg_offsets[seg]
173 
174 #define NBIO_BASE(seg) \
175 	NBIO_BASE_INNER(seg)
176 
177 #define NBIO_SR(reg_name)\
178 	REG_STRUCT.reg_name = NBIO_BASE(regBIF_BX0_ ## reg_name ## _BASE_IDX) + \
179 		regBIF_BX0_ ## reg_name
180 #define NBIO_SR_ARR(reg_name, id)\
181 	REG_STRUCT[id].reg_name = NBIO_BASE(regBIF_BX0_ ## reg_name ## _BASE_IDX) + \
182 		regBIF_BX0_ ## reg_name
183 
184 #define CTX ctx
185 #define REG(reg_name) \
186 	(ctx->dcn_reg_offsets[reg ## reg_name ## _BASE_IDX] + reg ## reg_name)
187 
188 static struct bios_registers bios_regs;
189 
190 #define bios_regs_init() \
191 		NBIO_SR(BIOS_SCRATCH_3),\
192 		NBIO_SR(BIOS_SCRATCH_6)
193 
194 #define clk_src_regs_init(index, pllid)\
195 	CS_COMMON_REG_LIST_DCN3_0_RI(index, pllid)
196 
197 static struct dce110_clk_src_regs clk_src_regs[5];
198 
199 static const struct dce110_clk_src_shift cs_shift = {
200 		CS_COMMON_MASK_SH_LIST_DCN3_2(__SHIFT)
201 };
202 
203 static const struct dce110_clk_src_mask cs_mask = {
204 		CS_COMMON_MASK_SH_LIST_DCN3_2(_MASK)
205 };
206 
207 #define abm_regs_init(id)\
208 		ABM_DCN401_REG_LIST_RI(id)
209 
210 static struct dce_abm_registers abm_regs[4];
211 
212 static const struct dce_abm_shift abm_shift = {
213 		ABM_MASK_SH_LIST_DCN401(__SHIFT)
214 };
215 
216 static const struct dce_abm_mask abm_mask = {
217 		ABM_MASK_SH_LIST_DCN401(_MASK)
218 };
219 
220 #define audio_regs_init(id)\
221 		AUD_COMMON_REG_LIST_RI(id)
222 
223 static struct dce_audio_registers audio_regs[5];
224 
225 #define DCE120_AUD_COMMON_MASK_SH_LIST(mask_sh)\
226 		SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_INDEX, AZALIA_ENDPOINT_REG_INDEX, mask_sh),\
227 		SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_DATA, AZALIA_ENDPOINT_REG_DATA, mask_sh),\
228 		AUD_COMMON_MASK_SH_LIST_BASE(mask_sh)
229 
230 static const struct dce_audio_shift audio_shift = {
231 		DCE120_AUD_COMMON_MASK_SH_LIST(__SHIFT)
232 };
233 
234 static const struct dce_audio_mask audio_mask = {
235 		DCE120_AUD_COMMON_MASK_SH_LIST(_MASK)
236 };
237 
238 #define vpg_regs_init(id)\
239 		VPG_DCN401_REG_LIST_RI(id)
240 
241 static struct dcn31_vpg_registers vpg_regs[9];
242 
243 static const struct dcn31_vpg_shift vpg_shift = {
244 	DCN31_VPG_MASK_SH_LIST(__SHIFT)
245 };
246 
247 static const struct dcn31_vpg_mask vpg_mask = {
248 	DCN31_VPG_MASK_SH_LIST(_MASK)
249 };
250 
251 #define afmt_regs_init(id)\
252 		AFMT_DCN3_REG_LIST_RI(id)
253 
254 static struct dcn30_afmt_registers afmt_regs[5];
255 
256 static const struct dcn30_afmt_shift afmt_shift = {
257 	DCN3_AFMT_MASK_SH_LIST(__SHIFT)
258 };
259 
260 static const struct dcn30_afmt_mask afmt_mask = {
261 	DCN3_AFMT_MASK_SH_LIST(_MASK)
262 };
263 
264 #define apg_regs_init(id)\
265 	APG_DCN31_REG_LIST_RI(id)
266 
267 static struct dcn31_apg_registers apg_regs[4];
268 
269 static const struct dcn31_apg_shift apg_shift = {
270 	DCN31_APG_MASK_SH_LIST(__SHIFT)
271 };
272 
273 static const struct dcn31_apg_mask apg_mask = {
274 		DCN31_APG_MASK_SH_LIST(_MASK)
275 };
276 
277 #define stream_enc_regs_init(id)\
278 	SE_DCN4_01_REG_LIST_RI(id)
279 
280 static struct dcn10_stream_enc_registers stream_enc_regs[4];
281 
282 static const struct dcn10_stream_encoder_shift se_shift = {
283 		SE_COMMON_MASK_SH_LIST_DCN401(__SHIFT)
284 };
285 
286 static const struct dcn10_stream_encoder_mask se_mask = {
287 		SE_COMMON_MASK_SH_LIST_DCN401(_MASK)
288 };
289 
290 #define aux_regs_init(id)\
291 	DCN2_AUX_REG_LIST_RI(id)
292 
293 static struct dcn10_link_enc_aux_registers link_enc_aux_regs[5];
294 
295 #define hpd_regs_init(id)\
296 	HPD_REG_LIST_RI(id)
297 
298 static struct dcn10_link_enc_hpd_registers link_enc_hpd_regs[5];
299 
300 #define link_regs_init(id, phyid)\
301 	LE_DCN401_REG_LIST_RI(id)
302 
303 static struct dcn10_link_enc_registers link_enc_regs[4];
304 
305 
306 static const struct dcn10_link_enc_shift le_shift = {
307 	LINK_ENCODER_MASK_SH_LIST_DCN401(__SHIFT)
308 };
309 
310 
311 static const struct dcn10_link_enc_mask le_mask = {
312 	LINK_ENCODER_MASK_SH_LIST_DCN401(_MASK)
313 };
314 
315 
316 #define hpo_dp_stream_encoder_reg_init(id)\
317 	DCN3_1_HPO_DP_STREAM_ENC_REG_LIST_RI(id)
318 
319 static struct dcn31_hpo_dp_stream_encoder_registers hpo_dp_stream_enc_regs[4];
320 
321 static const struct dcn31_hpo_dp_stream_encoder_shift hpo_dp_se_shift = {
322 	DCN3_1_HPO_DP_STREAM_ENC_MASK_SH_LIST(__SHIFT)
323 };
324 
325 static const struct dcn31_hpo_dp_stream_encoder_mask hpo_dp_se_mask = {
326 	DCN3_1_HPO_DP_STREAM_ENC_MASK_SH_LIST(_MASK)
327 };
328 
329 
330 #define hpo_dp_link_encoder_reg_init(id)\
331 	DCN3_1_HPO_DP_LINK_ENC_REG_LIST_RI(id)
332 	/*DCN3_1_RDPCSTX_REG_LIST(0),*/
333 	/*DCN3_1_RDPCSTX_REG_LIST(1),*/
334 	/*DCN3_1_RDPCSTX_REG_LIST(2),*/
335 	/*DCN3_1_RDPCSTX_REG_LIST(3),*/
336 
337 static struct dcn31_hpo_dp_link_encoder_registers hpo_dp_link_enc_regs[4];
338 
339 static const struct dcn31_hpo_dp_link_encoder_shift hpo_dp_le_shift = {
340 	DCN3_2_HPO_DP_LINK_ENC_MASK_SH_LIST(__SHIFT)
341 };
342 
343 static const struct dcn31_hpo_dp_link_encoder_mask hpo_dp_le_mask = {
344 	DCN3_2_HPO_DP_LINK_ENC_MASK_SH_LIST(_MASK)
345 };
346 
347 #define dpp_regs_init(id)\
348 	DPP_REG_LIST_DCN401_COMMON_RI(id)
349 
350 static struct dcn401_dpp_registers dpp_regs[4];
351 
352 static const struct dcn401_dpp_shift tf_shift = {
353 		DPP_REG_LIST_SH_MASK_DCN401_COMMON(__SHIFT)
354 };
355 
356 static const struct dcn401_dpp_mask tf_mask = {
357 		DPP_REG_LIST_SH_MASK_DCN401_COMMON(_MASK)
358 };
359 
360 #define opp_regs_init(id)\
361 	OPP_REG_LIST_DCN401_RI(id)
362 
363 static struct dcn20_opp_registers opp_regs[4];
364 
365 static const struct dcn20_opp_shift opp_shift = {
366 	OPP_MASK_SH_LIST_DCN20(__SHIFT)
367 };
368 
369 static const struct dcn20_opp_mask opp_mask = {
370 	OPP_MASK_SH_LIST_DCN20(_MASK)
371 };
372 
373 #define aux_engine_regs_init(id) \
374 	AUX_COMMON_REG_LIST0_RI(id), SR_ARR_INIT(AUXN_IMPCAL, id, 0), \
375 	SR_ARR_INIT(AUXP_IMPCAL, id, 0), \
376 	SR_ARR_INIT(AUX_RESET_MASK, id, DP_AUX0_AUX_CONTROL__AUX_RESET_MASK), \
377 	SR_ARR_INIT(AUX_RESET_MASK, id, DP_AUX0_AUX_CONTROL__AUX_RESET_MASK)
378 
379 static struct dce110_aux_registers aux_engine_regs[5];
380 
381 static const struct dce110_aux_registers_shift aux_shift = {
382 	DCN_AUX_MASK_SH_LIST(__SHIFT)
383 };
384 
385 static const struct dce110_aux_registers_mask aux_mask = {
386 	DCN_AUX_MASK_SH_LIST(_MASK)
387 };
388 
389 #define dwbc_regs_dcn401_init(id)\
390 	DWBC_COMMON_REG_LIST_DCN30_RI(id)
391 
392 static struct dcn30_dwbc_registers dwbc401_regs[1];
393 
394 static const struct dcn30_dwbc_shift dwbc401_shift = {
395 	DWBC_COMMON_MASK_SH_LIST_DCN30(__SHIFT)
396 };
397 
398 static const struct dcn30_dwbc_mask dwbc401_mask = {
399 	DWBC_COMMON_MASK_SH_LIST_DCN30(_MASK)
400 };
401 
402 
403 #define mcif_wb_regs_dcn3_init(id)\
404 	MCIF_WB_COMMON_REG_LIST_DCN32_RI(id)
405 
406 static struct dcn30_mmhubbub_registers mcif_wb30_regs[1];
407 
408 static const struct dcn30_mmhubbub_shift mcif_wb30_shift = {
409 	MCIF_WB_COMMON_MASK_SH_LIST_DCN32(__SHIFT)
410 };
411 
412 static const struct dcn30_mmhubbub_mask mcif_wb30_mask = {
413 	MCIF_WB_COMMON_MASK_SH_LIST_DCN32(_MASK)
414 };
415 
416 #define dsc_regs_init(id)\
417 	DSC_REG_LIST_DCN401_RI(id)
418 
419 static struct dcn401_dsc_registers dsc_regs[4];
420 
421 static const struct dcn401_dsc_shift dsc_shift = {
422 	DSC_REG_LIST_SH_MASK_DCN401(__SHIFT)
423 };
424 
425 static const struct dcn401_dsc_mask dsc_mask = {
426 	DSC_REG_LIST_SH_MASK_DCN401(_MASK)
427 };
428 
429 static struct dcn401_mpc_registers mpc_regs;
430 
431 #define dcn_mpc_regs_init()\
432 	MPC_REG_LIST_DCN4_01_RI(0),\
433 	MPC_REG_LIST_DCN4_01_RI(1),\
434 	MPC_REG_LIST_DCN4_01_RI(2),\
435 	MPC_REG_LIST_DCN4_01_RI(3),\
436 	MPC_OUT_MUX_REG_LIST_DCN3_0_RI(0),\
437 	MPC_OUT_MUX_REG_LIST_DCN3_0_RI(1),\
438 	MPC_OUT_MUX_REG_LIST_DCN3_0_RI(2),\
439 	MPC_OUT_MUX_REG_LIST_DCN3_0_RI(3),\
440 	MPC_DWB_MUX_REG_LIST_DCN3_0_RI(0)
441 
442 static const struct dcn401_mpc_shift mpc_shift = {
443 	MPC_COMMON_MASK_SH_LIST_DCN4_01(__SHIFT)
444 };
445 
446 static const struct dcn401_mpc_mask mpc_mask = {
447 	MPC_COMMON_MASK_SH_LIST_DCN4_01(_MASK)
448 };
449 
450 #define optc_regs_init(id)\
451 	OPTC_COMMON_REG_LIST_DCN401_RI(id)
452 
453 static struct dcn_optc_registers optc_regs[4];
454 
455 static const struct dcn_optc_shift optc_shift = {
456 	OPTC_COMMON_MASK_SH_LIST_DCN401(__SHIFT)
457 };
458 
459 static const struct dcn_optc_mask optc_mask = {
460 	OPTC_COMMON_MASK_SH_LIST_DCN401(_MASK)
461 };
462 
463 #define hubp_regs_init(id)\
464 	HUBP_REG_LIST_DCN401_RI(id)
465 
466 static struct dcn_hubp2_registers hubp_regs[4];
467 
468 static const struct dcn_hubp2_shift hubp_shift = {
469 		HUBP_MASK_SH_LIST_DCN401(__SHIFT)
470 };
471 
472 static const struct dcn_hubp2_mask hubp_mask = {
473 		HUBP_MASK_SH_LIST_DCN401(_MASK)
474 };
475 
476 static struct dcn_hubbub_registers hubbub_reg;
477 #define hubbub_reg_init()\
478 		HUBBUB_REG_LIST_DCN4_01_RI(0)
479 
480 static const struct dcn_hubbub_shift hubbub_shift = {
481 		HUBBUB_MASK_SH_LIST_DCN4_01(__SHIFT)
482 };
483 
484 static const struct dcn_hubbub_mask hubbub_mask = {
485 		HUBBUB_MASK_SH_LIST_DCN4_01(_MASK)
486 };
487 
488 static struct dccg_registers dccg_regs;
489 
490 #define dccg_regs_init()\
491 	DCCG_REG_LIST_DCN401_RI()
492 
493 static const struct dccg_shift dccg_shift = {
494 		DCCG_MASK_SH_LIST_DCN401(__SHIFT)
495 };
496 
497 static const struct dccg_mask dccg_mask = {
498 		DCCG_MASK_SH_LIST_DCN401(_MASK)
499 };
500 
501 #define SRII2(reg_name_pre, reg_name_post, id)\
502 	.reg_name_pre ## _ ##  reg_name_post[id] = BASE(reg ## reg_name_pre \
503 			## id ## _ ## reg_name_post ## _BASE_IDX) + \
504 			reg ## reg_name_pre ## id ## _ ## reg_name_post
505 
506 
507 #define HWSEQ_DCN401_REG_LIST()\
508 	SR(DCHUBBUB_GLOBAL_TIMER_CNTL), \
509 	SR(DIO_MEM_PWR_CTRL), \
510 	SR(ODM_MEM_PWR_CTRL3), \
511 	SR(MMHUBBUB_MEM_PWR_CNTL), \
512 	SR(DCCG_GATE_DISABLE_CNTL), \
513 	SR(DCCG_GATE_DISABLE_CNTL2), \
514 	SR(DCFCLK_CNTL),\
515 	SR(DC_MEM_GLOBAL_PWR_REQ_CNTL), \
516 	SRII(PIXEL_RATE_CNTL, OTG, 0), \
517 	SRII(PIXEL_RATE_CNTL, OTG, 1),\
518 	SRII(PIXEL_RATE_CNTL, OTG, 2),\
519 	SRII(PIXEL_RATE_CNTL, OTG, 3),\
520 	SRII(PHYPLL_PIXEL_RATE_CNTL, OTG, 0),\
521 	SRII(PHYPLL_PIXEL_RATE_CNTL, OTG, 1),\
522 	SRII(PHYPLL_PIXEL_RATE_CNTL, OTG, 2),\
523 	SRII(PHYPLL_PIXEL_RATE_CNTL, OTG, 3),\
524 	SR(MICROSECOND_TIME_BASE_DIV), \
525 	SR(MILLISECOND_TIME_BASE_DIV), \
526 	SR(DISPCLK_FREQ_CHANGE_CNTL), \
527 	SR(RBBMIF_TIMEOUT_DIS), \
528 	SR(RBBMIF_TIMEOUT_DIS_2), \
529 	SR(DCHUBBUB_CRC_CTRL), \
530 	SR(DPP_TOP0_DPP_CRC_CTRL), \
531 	SR(DPP_TOP0_DPP_CRC_VAL_B_A), \
532 	SR(DPP_TOP0_DPP_CRC_VAL_R_G), \
533 	SR(MPC_CRC_CTRL), \
534 	SR(MPC_CRC_RESULT_GB), \
535 	SR(MPC_CRC_RESULT_C), \
536 	SR(MPC_CRC_RESULT_AR), \
537 	SR(DOMAIN0_PG_CONFIG), \
538 	SR(DOMAIN1_PG_CONFIG), \
539 	SR(DOMAIN2_PG_CONFIG), \
540 	SR(DOMAIN3_PG_CONFIG), \
541 	SR(DOMAIN16_PG_CONFIG), \
542 	SR(DOMAIN17_PG_CONFIG), \
543 	SR(DOMAIN18_PG_CONFIG), \
544 	SR(DOMAIN19_PG_CONFIG), \
545 	SR(DOMAIN22_PG_CONFIG), \
546 	SR(DOMAIN23_PG_CONFIG), \
547 	SR(DOMAIN24_PG_CONFIG), \
548 	SR(DOMAIN25_PG_CONFIG), \
549 	SR(DOMAIN0_PG_STATUS), \
550 	SR(DOMAIN1_PG_STATUS), \
551 	SR(DOMAIN2_PG_STATUS), \
552 	SR(DOMAIN3_PG_STATUS), \
553 	SR(DOMAIN16_PG_STATUS), \
554 	SR(DOMAIN17_PG_STATUS), \
555 	SR(DOMAIN18_PG_STATUS), \
556 	SR(DOMAIN19_PG_STATUS), \
557 	SR(DOMAIN22_PG_STATUS), \
558 	SR(DOMAIN23_PG_STATUS), \
559 	SR(DOMAIN24_PG_STATUS), \
560 	SR(DOMAIN25_PG_STATUS), \
561 	SR(DC_IP_REQUEST_CNTL), \
562 	SR(AZALIA_AUDIO_DTO), \
563 	SR(HPO_TOP_HW_CONTROL),\
564 	SR(AZALIA_CONTROLLER_CLOCK_GATING)
565 
566 static struct dce_hwseq_registers hwseq_reg;
567 
568 #define hwseq_reg_init()\
569 	HWSEQ_DCN401_REG_LIST()
570 
571 #define HWSEQ_DCN401_MASK_SH_LIST(mask_sh)\
572 	HWSEQ_DCN_MASK_SH_LIST(mask_sh), \
573 	HWS_SF(, DCHUBBUB_GLOBAL_TIMER_CNTL, DCHUBBUB_GLOBAL_TIMER_REFDIV, mask_sh), \
574 	HWS_SF(, DOMAIN0_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
575 	HWS_SF(, DOMAIN0_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
576 	HWS_SF(, DOMAIN1_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
577 	HWS_SF(, DOMAIN1_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
578 	HWS_SF(, DOMAIN2_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
579 	HWS_SF(, DOMAIN2_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
580 	HWS_SF(, DOMAIN3_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
581 	HWS_SF(, DOMAIN3_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
582 	HWS_SF(, DOMAIN16_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
583 	HWS_SF(, DOMAIN16_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
584 	HWS_SF(, DOMAIN17_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
585 	HWS_SF(, DOMAIN17_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
586 	HWS_SF(, DOMAIN18_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
587 	HWS_SF(, DOMAIN18_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
588 	HWS_SF(, DOMAIN19_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
589 	HWS_SF(, DOMAIN19_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
590 	HWS_SF(, DOMAIN22_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
591 	HWS_SF(, DOMAIN22_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
592 	HWS_SF(, DOMAIN23_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
593 	HWS_SF(, DOMAIN23_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
594 	HWS_SF(, DOMAIN24_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
595 	HWS_SF(, DOMAIN24_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
596 	HWS_SF(, DOMAIN25_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
597 	HWS_SF(, DOMAIN25_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
598 	HWS_SF(, DOMAIN0_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
599 	HWS_SF(, DOMAIN1_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
600 	HWS_SF(, DOMAIN2_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
601 	HWS_SF(, DOMAIN3_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
602 	HWS_SF(, DOMAIN16_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
603 	HWS_SF(, DOMAIN17_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
604 	HWS_SF(, DOMAIN18_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
605 	HWS_SF(, DOMAIN19_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
606 	HWS_SF(, DOMAIN22_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
607 	HWS_SF(, DOMAIN23_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
608 	HWS_SF(, DOMAIN24_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
609 	HWS_SF(, DOMAIN25_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
610 	HWS_SF(, DC_IP_REQUEST_CNTL, IP_REQUEST_EN, mask_sh), \
611 	HWS_SF(, AZALIA_AUDIO_DTO, AZALIA_AUDIO_DTO_MODULE, mask_sh), \
612 	HWS_SF(, HPO_TOP_CLOCK_CONTROL, HPO_HDMISTREAMCLK_G_GATE_DIS, mask_sh), \
613 	HWS_SF(, HPO_TOP_HW_CONTROL, HPO_IO_EN, mask_sh), \
614 	HWS_SF(, ODM_MEM_PWR_CTRL3, ODM_MEM_UNASSIGNED_PWR_MODE, mask_sh), \
615 	HWS_SF(, ODM_MEM_PWR_CTRL3, ODM_MEM_VBLANK_PWR_MODE, mask_sh)
616 
617 static const struct dce_hwseq_shift hwseq_shift = {
618 		HWSEQ_DCN401_MASK_SH_LIST(__SHIFT)
619 };
620 
621 static const struct dce_hwseq_mask hwseq_mask = {
622 		HWSEQ_DCN401_MASK_SH_LIST(_MASK)
623 };
624 
625 #define vmid_regs_init(id)\
626 		DCN20_VMID_REG_LIST_RI(id)
627 
628 static struct dcn_vmid_registers vmid_regs[16];
629 
630 static const struct dcn20_vmid_shift vmid_shifts = {
631 		DCN20_VMID_MASK_SH_LIST(__SHIFT)
632 };
633 
634 static const struct dcn20_vmid_mask vmid_masks = {
635 		DCN20_VMID_MASK_SH_LIST(_MASK)
636 };
637 
638 static const struct resource_caps res_cap_dcn4_01 = {
639 	.num_timing_generator = 4,
640 	.num_opp = 4,
641 	.num_video_plane = 4,
642 	.num_audio = 4,
643 	.num_stream_encoder = 4,
644 	.num_hpo_dp_stream_encoder = 4,
645 	.num_hpo_dp_link_encoder = 4,
646 	.num_pll = 4,
647 	.num_dwb = 1,
648 	.num_ddc = 4,
649 	.num_vmid = 16,
650 	.num_mpc_3dlut = 4,
651 	.num_dsc = 4,
652 };
653 
654 static const struct dc_plane_cap plane_cap = {
655 	.type = DC_PLANE_TYPE_DCN_UNIVERSAL,
656 	.per_pixel_alpha = true,
657 
658 	.pixel_format_support = {
659 			.argb8888 = true,
660 			.nv12 = true,
661 			.fp16 = true,
662 			.p010 = true,
663 			.ayuv = false,
664 	},
665 
666 	.max_upscale_factor = {
667 			.argb8888 = 16000,
668 			.nv12 = 16000,
669 			.fp16 = 16000
670 	},
671 
672 	// 6:1 downscaling ratio: 1000/6 = 166.666
673 	.max_downscale_factor = {
674 			.argb8888 = 167,
675 			.nv12 = 167,
676 			.fp16 = 167
677 	},
678 	64,
679 	64
680 };
681 
682 static const struct dc_debug_options debug_defaults_drv = {
683 	.disable_dmcu = true,
684 	.force_abm_enable = false,
685 	.clock_trace = true,
686 	.disable_pplib_clock_request = false,
687 	.pipe_split_policy = MPC_SPLIT_AVOID,
688 	.force_single_disp_pipe_split = false,
689 	.disable_dcc = DCC_ENABLE,
690 	.vsr_support = true,
691 	.performance_trace = false,
692 	.max_downscale_src_width = 7680,/*upto 8K*/
693 	.disable_pplib_wm_range = false,
694 	.scl_reset_length10 = true,
695 	.sanity_checks = false,
696 	.underflow_assert_delay_us = 0xFFFFFFFF,
697 	.dwb_fi_phase = -1, // -1 = disable,
698 	.dmub_command_table = true,
699 	.enable_mem_low_power = {
700 		.bits = {
701 			.vga = false,
702 			.i2c = false,
703 			.dmcu = false, // This is previously known to cause hang on S3 cycles if enabled
704 			.dscl = false,
705 			.cm = false,
706 			.mpc = false,
707 			.optc = true,
708 		}
709 	},
710 	.use_max_lb = true,
711 	.force_disable_subvp = false,
712 	.exit_idle_opt_for_cursor_updates = true,
713 	.using_dml2 = true,
714 	.using_dml21 = true,
715 	.enable_single_display_2to1_odm_policy = true,
716 
717 	//must match enable_single_display_2to1_odm_policy to support dynamic ODM transitions
718 	.enable_double_buffered_dsc_pg_support = true,
719 	.enable_dp_dig_pixel_rate_div_policy = 1,
720 	.allow_sw_cursor_fallback = false,
721 	.alloc_extra_way_for_cursor = true,
722 	.min_prefetch_in_strobe_ns = 60000, // 60us
723 	.disable_unbounded_requesting = false,
724 	.enable_legacy_fast_update = false,
725 	.dcc_meta_propagation_delay_us = 10,
726 	.fams_version = {
727 		.minor = 1,
728 		.major = 2,
729 	}, //v2.1
730 	.fams2_config = {
731 		.bits = {
732 			.enable = true,
733 			.enable_offload_flip = true,
734 			.enable_stall_recovery = true,
735 		}
736 	},
737 	.force_cositing = CHROMA_COSITING_NONE + 1,
738 };
739 
dcn401_aux_engine_create(struct dc_context * ctx,uint32_t inst)740 static struct dce_aux *dcn401_aux_engine_create(
741 	struct dc_context *ctx,
742 	uint32_t inst)
743 {
744 	struct aux_engine_dce110 *aux_engine =
745 		kzalloc(sizeof(struct aux_engine_dce110), GFP_KERNEL);
746 
747 	if (!aux_engine)
748 		return NULL;
749 
750 #undef REG_STRUCT
751 #define REG_STRUCT aux_engine_regs
752 	aux_engine_regs_init(0),
753 	aux_engine_regs_init(1),
754 	aux_engine_regs_init(2),
755 	aux_engine_regs_init(3);
756 
757 	dce110_aux_engine_construct(aux_engine, ctx, inst,
758 				    SW_AUX_TIMEOUT_PERIOD_MULTIPLIER * AUX_TIMEOUT_PERIOD,
759 				    &aux_engine_regs[inst],
760 					&aux_mask,
761 					&aux_shift,
762 					ctx->dc->caps.extended_aux_timeout_support);
763 
764 	return &aux_engine->base;
765 }
766 #define i2c_inst_regs_init(id)\
767 	I2C_HW_ENGINE_COMMON_REG_LIST_DCN30_RI(id)
768 
769 static struct dce_i2c_registers i2c_hw_regs[5];
770 
771 static const struct dce_i2c_shift i2c_shifts = {
772 		I2C_COMMON_MASK_SH_LIST_DCN401(__SHIFT)
773 };
774 
775 static const struct dce_i2c_mask i2c_masks = {
776 		I2C_COMMON_MASK_SH_LIST_DCN401(_MASK)
777 };
778 
dcn401_i2c_hw_create(struct dc_context * ctx,uint32_t inst)779 static struct dce_i2c_hw *dcn401_i2c_hw_create(
780 	struct dc_context *ctx,
781 	uint32_t inst)
782 {
783 	struct dce_i2c_hw *dce_i2c_hw =
784 		kzalloc(sizeof(struct dce_i2c_hw), GFP_KERNEL);
785 
786 	if (!dce_i2c_hw)
787 		return NULL;
788 
789 #undef REG_STRUCT
790 #define REG_STRUCT i2c_hw_regs
791 		i2c_inst_regs_init(1),
792 		i2c_inst_regs_init(2),
793 		i2c_inst_regs_init(3),
794 		i2c_inst_regs_init(4);
795 
796 	dcn2_i2c_hw_construct(dce_i2c_hw, ctx, inst,
797 				    &i2c_hw_regs[inst], &i2c_shifts, &i2c_masks);
798 
799 	return dce_i2c_hw;
800 }
801 
dcn401_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)802 static struct clock_source *dcn401_clock_source_create(
803 		struct dc_context *ctx,
804 		struct dc_bios *bios,
805 		enum clock_source_id id,
806 		const struct dce110_clk_src_regs *regs,
807 		bool dp_clk_src)
808 {
809 	struct dce110_clk_src *clk_src =
810 		kzalloc(sizeof(struct dce110_clk_src), GFP_KERNEL);
811 
812 	if (!clk_src)
813 		return NULL;
814 
815 	if (dcn401_clk_src_construct(clk_src, ctx, bios, id,
816 			regs, &cs_shift, &cs_mask)) {
817 		clk_src->base.dp_clk_src = dp_clk_src;
818 		return &clk_src->base;
819 	}
820 
821 	kfree(clk_src);
822 	BREAK_TO_DEBUGGER();
823 	return NULL;
824 }
825 
dcn401_hubbub_create(struct dc_context * ctx)826 static struct hubbub *dcn401_hubbub_create(struct dc_context *ctx)
827 {
828 	int i;
829 
830 	struct dcn20_hubbub *hubbub2 = kzalloc(sizeof(struct dcn20_hubbub),
831 					  GFP_KERNEL);
832 
833 	if (!hubbub2)
834 		return NULL;
835 
836 
837 #undef REG_STRUCT
838 #define REG_STRUCT hubbub_reg
839 	hubbub_reg_init();
840 
841 #undef REG_STRUCT
842 #define REG_STRUCT vmid_regs
843 	vmid_regs_init(0),
844 	vmid_regs_init(1),
845 	vmid_regs_init(2),
846 	vmid_regs_init(3),
847 	vmid_regs_init(4),
848 	vmid_regs_init(5),
849 	vmid_regs_init(6),
850 	vmid_regs_init(7),
851 	vmid_regs_init(8),
852 	vmid_regs_init(9),
853 	vmid_regs_init(10),
854 	vmid_regs_init(11),
855 	vmid_regs_init(12),
856 	vmid_regs_init(13),
857 	vmid_regs_init(14),
858 	vmid_regs_init(15);
859 
860 	hubbub401_construct(hubbub2, ctx,
861 			&hubbub_reg,
862 			&hubbub_shift,
863 			&hubbub_mask,
864 			DCN4_01_DEFAULT_DET_SIZE, //nominal (default) detile buffer size in kbytes,
865 			8, //dml2 ip_params_st.pixel_chunk_size_kbytes
866 			DCN4_01_CRB_SIZE_KB); //dml2 ip_params_st.config_return_buffer_size_in_kbytes
867 
868 	for (i = 0; i < res_cap_dcn4_01.num_vmid; i++) {
869 		struct dcn20_vmid *vmid = &hubbub2->vmid[i];
870 
871 		vmid->ctx = ctx;
872 
873 		vmid->regs = &vmid_regs[i];
874 		vmid->shifts = &vmid_shifts;
875 		vmid->masks = &vmid_masks;
876 	}
877 
878 	return &hubbub2->base;
879 }
880 
dcn401_hubp_create(struct dc_context * ctx,uint32_t inst)881 static struct hubp *dcn401_hubp_create(
882 	struct dc_context *ctx,
883 	uint32_t inst)
884 {
885 	struct dcn20_hubp *hubp2 =
886 		kzalloc(sizeof(struct dcn20_hubp), GFP_KERNEL);
887 
888 	if (!hubp2)
889 		return NULL;
890 
891 #undef REG_STRUCT
892 #define REG_STRUCT hubp_regs
893 		hubp_regs_init(0),
894 		hubp_regs_init(1),
895 		hubp_regs_init(2),
896 		hubp_regs_init(3);
897 
898 	if (hubp401_construct(hubp2, ctx, inst,
899 			&hubp_regs[inst], &hubp_shift, &hubp_mask))
900 		return &hubp2->base;
901 
902 	BREAK_TO_DEBUGGER();
903 	kfree(hubp2);
904 	return NULL;
905 }
906 
dcn401_dpp_destroy(struct dpp ** dpp)907 static void dcn401_dpp_destroy(struct dpp **dpp)
908 {
909 	kfree(TO_DCN401_DPP(*dpp));
910 	*dpp = NULL;
911 }
912 
dcn401_dpp_create(struct dc_context * ctx,uint32_t inst)913 static struct dpp *dcn401_dpp_create(
914 	struct dc_context *ctx,
915 	uint32_t inst)
916 {
917 	struct dcn401_dpp *dpp401 =
918 		kzalloc(sizeof(struct dcn401_dpp), GFP_KERNEL);
919 
920 	if (!dpp401)
921 		return NULL;
922 
923 #undef REG_STRUCT
924 #define REG_STRUCT dpp_regs
925 	dpp_regs_init(0),
926 	dpp_regs_init(1),
927 	dpp_regs_init(2),
928 	dpp_regs_init(3);
929 
930 	if (dpp401_construct(dpp401, ctx, inst,
931 			&dpp_regs[inst], &tf_shift, &tf_mask))
932 		return &dpp401->base;
933 
934 	BREAK_TO_DEBUGGER();
935 	kfree(dpp401);
936 	return NULL;
937 }
938 
dcn401_mpc_create(struct dc_context * ctx,int num_mpcc,int num_rmu)939 static struct mpc *dcn401_mpc_create(
940 		struct dc_context *ctx,
941 		int num_mpcc,
942 		int num_rmu)
943 {
944 	struct dcn401_mpc *mpc401 = kzalloc(sizeof(struct dcn401_mpc),
945 					  GFP_KERNEL);
946 
947 	if (!mpc401)
948 		return NULL;
949 
950 #undef REG_STRUCT
951 #define REG_STRUCT mpc_regs
952 	dcn_mpc_regs_init();
953 
954 	dcn401_mpc_construct(mpc401, ctx,
955 			&mpc_regs,
956 			&mpc_shift,
957 			&mpc_mask,
958 			num_mpcc,
959 			num_rmu);
960 
961 	return &mpc401->base;
962 }
963 
dcn401_opp_create(struct dc_context * ctx,uint32_t inst)964 static struct output_pixel_processor *dcn401_opp_create(
965 	struct dc_context *ctx, uint32_t inst)
966 {
967 	struct dcn20_opp *opp4 =
968 		kzalloc(sizeof(struct dcn20_opp), GFP_KERNEL);
969 
970 	if (!opp4) {
971 		BREAK_TO_DEBUGGER();
972 		return NULL;
973 	}
974 
975 #undef REG_STRUCT
976 #define REG_STRUCT opp_regs
977 	opp_regs_init(0),
978 	opp_regs_init(1),
979 	opp_regs_init(2),
980 	opp_regs_init(3);
981 
982 	dcn20_opp_construct(opp4, ctx, inst,
983 			&opp_regs[inst], &opp_shift, &opp_mask);
984 	return &opp4->base;
985 }
986 
987 
dcn401_timing_generator_create(struct dc_context * ctx,uint32_t instance)988 static struct timing_generator *dcn401_timing_generator_create(
989 		struct dc_context *ctx,
990 		uint32_t instance)
991 {
992 	struct optc *tgn10 =
993 		kzalloc(sizeof(struct optc), GFP_KERNEL);
994 
995 	if (!tgn10)
996 		return NULL;
997 #undef REG_STRUCT
998 #define REG_STRUCT optc_regs
999 	optc_regs_init(0),
1000 	optc_regs_init(1),
1001 	optc_regs_init(2),
1002 	optc_regs_init(3);
1003 
1004 	tgn10->base.inst = instance;
1005 	tgn10->base.ctx = ctx;
1006 
1007 	tgn10->tg_regs = &optc_regs[instance];
1008 	tgn10->tg_shift = &optc_shift;
1009 	tgn10->tg_mask = &optc_mask;
1010 
1011 	dcn401_timing_generator_init(tgn10);
1012 
1013 	return &tgn10->base;
1014 }
1015 
1016 static const struct encoder_feature_support link_enc_feature = {
1017 		.max_hdmi_deep_color = COLOR_DEPTH_121212,
1018 		.max_hdmi_pixel_clock = 600000,
1019 		.hdmi_ycbcr420_supported = true,
1020 		.dp_ycbcr420_supported = true,
1021 		.fec_supported = true,
1022 		.flags.bits.IS_HBR2_CAPABLE = true,
1023 		.flags.bits.IS_HBR3_CAPABLE = true,
1024 		.flags.bits.IS_TPS3_CAPABLE = true,
1025 		.flags.bits.IS_TPS4_CAPABLE = true
1026 };
1027 
dcn401_link_encoder_create(struct dc_context * ctx,const struct encoder_init_data * enc_init_data)1028 static struct link_encoder *dcn401_link_encoder_create(
1029 	struct dc_context *ctx,
1030 	const struct encoder_init_data *enc_init_data)
1031 {
1032 	struct dcn20_link_encoder *enc20 =
1033 		kzalloc(sizeof(struct dcn20_link_encoder), GFP_KERNEL);
1034 
1035 	if (!enc20 || enc_init_data->hpd_source >= ARRAY_SIZE(link_enc_hpd_regs))
1036 		return NULL;
1037 
1038 #undef REG_STRUCT
1039 #define REG_STRUCT link_enc_aux_regs
1040 	aux_regs_init(0),
1041 	aux_regs_init(1),
1042 	aux_regs_init(2),
1043 	aux_regs_init(3);
1044 
1045 #undef REG_STRUCT
1046 #define REG_STRUCT link_enc_hpd_regs
1047 	hpd_regs_init(0),
1048 	hpd_regs_init(1),
1049 	hpd_regs_init(2),
1050 	hpd_regs_init(3);
1051 #undef REG_STRUCT
1052 #define REG_STRUCT link_enc_regs
1053 	link_regs_init(0, A),
1054 	link_regs_init(1, B),
1055 	link_regs_init(2, C),
1056 	link_regs_init(3, D);
1057 
1058 	dcn401_link_encoder_construct(enc20,
1059 			enc_init_data,
1060 			&link_enc_feature,
1061 			&link_enc_regs[enc_init_data->transmitter],
1062 			&link_enc_aux_regs[enc_init_data->channel - 1],
1063 			&link_enc_hpd_regs[enc_init_data->hpd_source],
1064 			&le_shift,
1065 			&le_mask);
1066 	return &enc20->enc10.base;
1067 }
1068 
read_dce_straps(struct dc_context * ctx,struct resource_straps * straps)1069 static void read_dce_straps(
1070 	struct dc_context *ctx,
1071 	struct resource_straps *straps)
1072 {
1073 	generic_reg_get(ctx, ctx->dcn_reg_offsets[regDC_PINSTRAPS_BASE_IDX] + regDC_PINSTRAPS,
1074 		FN(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO), &straps->dc_pinstraps_audio);
1075 
1076 }
1077 
dcn401_create_audio(struct dc_context * ctx,unsigned int inst)1078 static struct audio *dcn401_create_audio(
1079 		struct dc_context *ctx, unsigned int inst)
1080 {
1081 
1082 #undef REG_STRUCT
1083 #define REG_STRUCT audio_regs
1084 	audio_regs_init(0),
1085 	audio_regs_init(1),
1086 	audio_regs_init(2),
1087 	audio_regs_init(3),
1088 	audio_regs_init(4);
1089 
1090 	return dce_audio_create(ctx, inst,
1091 			&audio_regs[inst], &audio_shift, &audio_mask);
1092 }
1093 
dcn401_vpg_create(struct dc_context * ctx,uint32_t inst)1094 static struct vpg *dcn401_vpg_create(
1095 	struct dc_context *ctx,
1096 	uint32_t inst)
1097 {
1098 	struct dcn31_vpg *vpg4 = kzalloc(sizeof(struct dcn31_vpg), GFP_KERNEL);
1099 
1100 	if (!vpg4)
1101 		return NULL;
1102 
1103 
1104 #undef REG_STRUCT
1105 #define REG_STRUCT vpg_regs
1106 	vpg_regs_init(0),
1107 	vpg_regs_init(1),
1108 	vpg_regs_init(2),
1109 	vpg_regs_init(3),
1110 	vpg_regs_init(4),
1111 	vpg_regs_init(5),
1112 	vpg_regs_init(6),
1113 	vpg_regs_init(7),
1114 	vpg_regs_init(8);
1115 
1116 	vpg31_construct(vpg4, ctx, inst,
1117 			&vpg_regs[inst],
1118 			&vpg_shift,
1119 			&vpg_mask);
1120 
1121 	return &vpg4->base;
1122 }
1123 
dcn401_afmt_create(struct dc_context * ctx,uint32_t inst)1124 static struct afmt *dcn401_afmt_create(
1125 	struct dc_context *ctx,
1126 	uint32_t inst)
1127 {
1128 	struct dcn30_afmt *afmt401 = kzalloc(sizeof(struct dcn30_afmt), GFP_KERNEL);
1129 
1130 	if (!afmt401)
1131 		return NULL;
1132 
1133 #undef REG_STRUCT
1134 #define REG_STRUCT afmt_regs
1135 	afmt_regs_init(0),
1136 	afmt_regs_init(1),
1137 	afmt_regs_init(2),
1138 	afmt_regs_init(3),
1139 	afmt_regs_init(4);
1140 
1141 	afmt3_construct(afmt401, ctx, inst,
1142 			&afmt_regs[inst],
1143 			&afmt_shift,
1144 			&afmt_mask);
1145 
1146 	return &afmt401->base;
1147 }
1148 
dcn401_apg_create(struct dc_context * ctx,uint32_t inst)1149 static struct apg *dcn401_apg_create(
1150 	struct dc_context *ctx,
1151 	uint32_t inst)
1152 {
1153 	struct dcn31_apg *apg31 = kzalloc(sizeof(struct dcn31_apg), GFP_KERNEL);
1154 
1155 	if (!apg31)
1156 		return NULL;
1157 
1158 #undef REG_STRUCT
1159 #define REG_STRUCT apg_regs
1160 	apg_regs_init(0),
1161 	apg_regs_init(1),
1162 	apg_regs_init(2),
1163 	apg_regs_init(3);
1164 
1165 	apg31_construct(apg31, ctx, inst,
1166 			&apg_regs[inst],
1167 			&apg_shift,
1168 			&apg_mask);
1169 
1170 	return &apg31->base;
1171 }
1172 
dcn401_stream_encoder_create(enum engine_id eng_id,struct dc_context * ctx)1173 static struct stream_encoder *dcn401_stream_encoder_create(
1174 	enum engine_id eng_id,
1175 	struct dc_context *ctx)
1176 {
1177 	struct dcn10_stream_encoder *enc1;
1178 	struct vpg *vpg;
1179 	struct afmt *afmt;
1180 	int vpg_inst;
1181 	int afmt_inst;
1182 
1183 	/* Mapping of VPG, AFMT, DME register blocks to DIO block instance */
1184 	if (eng_id <= ENGINE_ID_DIGF) {
1185 		vpg_inst = eng_id;
1186 		afmt_inst = eng_id;
1187 	} else
1188 		return NULL;
1189 
1190 	enc1 = kzalloc(sizeof(struct dcn10_stream_encoder), GFP_KERNEL);
1191 	vpg = dcn401_vpg_create(ctx, vpg_inst);
1192 	afmt = dcn401_afmt_create(ctx, afmt_inst);
1193 
1194 	if (!enc1 || !vpg || !afmt || eng_id >= ARRAY_SIZE(stream_enc_regs)) {
1195 		kfree(enc1);
1196 		kfree(vpg);
1197 		kfree(afmt);
1198 		return NULL;
1199 	}
1200 #undef REG_STRUCT
1201 #define REG_STRUCT stream_enc_regs
1202 	stream_enc_regs_init(0),
1203 	stream_enc_regs_init(1),
1204 	stream_enc_regs_init(2),
1205 	stream_enc_regs_init(3);
1206 	//stream_enc_regs_init(4);
1207 
1208 	dcn401_dio_stream_encoder_construct(enc1, ctx, ctx->dc_bios,
1209 					eng_id, vpg, afmt,
1210 					&stream_enc_regs[eng_id],
1211 					&se_shift, &se_mask);
1212 	return &enc1->base;
1213 }
1214 
dcn401_hpo_dp_stream_encoder_create(enum engine_id eng_id,struct dc_context * ctx)1215 static struct hpo_dp_stream_encoder *dcn401_hpo_dp_stream_encoder_create(
1216 	enum engine_id eng_id,
1217 	struct dc_context *ctx)
1218 {
1219 	struct dcn31_hpo_dp_stream_encoder *hpo_dp_enc31;
1220 	struct vpg *vpg;
1221 	struct apg *apg;
1222 	uint32_t hpo_dp_inst;
1223 	uint32_t vpg_inst;
1224 	uint32_t apg_inst;
1225 
1226 	ASSERT((eng_id >= ENGINE_ID_HPO_DP_0) && (eng_id <= ENGINE_ID_HPO_DP_3));
1227 	hpo_dp_inst = eng_id - ENGINE_ID_HPO_DP_0;
1228 
1229 	/* Mapping of VPG register blocks to HPO DP block instance:
1230 	 * VPG[6] -> HPO_DP[0]
1231 	 * VPG[7] -> HPO_DP[1]
1232 	 * VPG[8] -> HPO_DP[2]
1233 	 * VPG[9] -> HPO_DP[3]
1234 	 */
1235 	vpg_inst = hpo_dp_inst + 5;
1236 
1237 	/* Mapping of APG register blocks to HPO DP block instance:
1238 	 * APG[0] -> HPO_DP[0]
1239 	 * APG[1] -> HPO_DP[1]
1240 	 * APG[2] -> HPO_DP[2]
1241 	 * APG[3] -> HPO_DP[3]
1242 	 */
1243 	apg_inst = hpo_dp_inst;
1244 
1245 	/* allocate HPO stream encoder and create VPG sub-block */
1246 	hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_stream_encoder), GFP_KERNEL);
1247 	vpg = dcn401_vpg_create(ctx, vpg_inst);
1248 	apg = dcn401_apg_create(ctx, apg_inst);
1249 
1250 	if (!hpo_dp_enc31 || !vpg || !apg) {
1251 		kfree(hpo_dp_enc31);
1252 		kfree(vpg);
1253 		kfree(apg);
1254 		return NULL;
1255 	}
1256 
1257 #undef REG_STRUCT
1258 #define REG_STRUCT hpo_dp_stream_enc_regs
1259 	hpo_dp_stream_encoder_reg_init(0),
1260 	hpo_dp_stream_encoder_reg_init(1),
1261 	hpo_dp_stream_encoder_reg_init(2),
1262 	hpo_dp_stream_encoder_reg_init(3);
1263 
1264 	dcn31_hpo_dp_stream_encoder_construct(hpo_dp_enc31, ctx, ctx->dc_bios,
1265 					hpo_dp_inst, eng_id, vpg, apg,
1266 					&hpo_dp_stream_enc_regs[hpo_dp_inst],
1267 					&hpo_dp_se_shift, &hpo_dp_se_mask);
1268 
1269 	return &hpo_dp_enc31->base;
1270 }
1271 
dcn401_hpo_dp_link_encoder_create(uint8_t inst,struct dc_context * ctx)1272 static struct hpo_dp_link_encoder *dcn401_hpo_dp_link_encoder_create(
1273 	uint8_t inst,
1274 	struct dc_context *ctx)
1275 {
1276 	struct dcn31_hpo_dp_link_encoder *hpo_dp_enc31;
1277 
1278 	/* allocate HPO link encoder */
1279 	hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_link_encoder), GFP_KERNEL);
1280 	if (!hpo_dp_enc31)
1281 		return NULL; /* out of memory */
1282 
1283 #undef REG_STRUCT
1284 #define REG_STRUCT hpo_dp_link_enc_regs
1285 	hpo_dp_link_encoder_reg_init(0),
1286 	hpo_dp_link_encoder_reg_init(1),
1287 	hpo_dp_link_encoder_reg_init(2),
1288 	hpo_dp_link_encoder_reg_init(3);
1289 
1290 	hpo_dp_link_encoder32_construct(hpo_dp_enc31, ctx, inst,
1291 					&hpo_dp_link_enc_regs[inst],
1292 					&hpo_dp_le_shift, &hpo_dp_le_mask);
1293 
1294 	return &hpo_dp_enc31->base;
1295 }
1296 
dcn401_calc_num_avail_chans_for_mall(struct dc * dc,unsigned int num_chans)1297 static unsigned int dcn401_calc_num_avail_chans_for_mall(struct dc *dc, unsigned int num_chans)
1298 {
1299 	unsigned int num_available_chans = 1;
1300 
1301 	/* channels for MALL must be a power of 2 */
1302 	while (num_chans > 1) {
1303 		num_available_chans = (num_available_chans << 1);
1304 		num_chans = (num_chans >> 1);
1305 	}
1306 
1307 	/* cannot be odd */
1308 	num_available_chans &= ~1;
1309 
1310 	/* clamp to max available channels for MALL per ASIC */
1311 	if (ASICREV_IS_GC_12_0_0_A0(dc->ctx->asic_id.hw_internal_rev)) {
1312 		num_available_chans = num_available_chans > 16 ? 16 : num_available_chans;
1313 	} else if (ASICREV_IS_GC_12_0_1_A0(dc->ctx->asic_id.hw_internal_rev)) {
1314 		num_available_chans = num_available_chans > 8 ? 8 : num_available_chans;
1315 	}
1316 
1317 	return num_available_chans;
1318 }
1319 
dcn401_hwseq_create(struct dc_context * ctx)1320 static struct dce_hwseq *dcn401_hwseq_create(
1321 	struct dc_context *ctx)
1322 {
1323 	struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL);
1324 
1325 #undef REG_STRUCT
1326 #define REG_STRUCT hwseq_reg
1327 	hwseq_reg_init();
1328 
1329 	if (hws) {
1330 		hws->ctx = ctx;
1331 		hws->regs = &hwseq_reg;
1332 		hws->shifts = &hwseq_shift;
1333 		hws->masks = &hwseq_mask;
1334 	}
1335 
1336 	return hws;
1337 }
1338 static const struct resource_create_funcs res_create_funcs = {
1339 	.read_dce_straps = read_dce_straps,
1340 	.create_audio = dcn401_create_audio,
1341 	.create_stream_encoder = dcn401_stream_encoder_create,
1342 	.create_hpo_dp_stream_encoder = dcn401_hpo_dp_stream_encoder_create,
1343 	.create_hpo_dp_link_encoder = dcn401_hpo_dp_link_encoder_create,
1344 	.create_hwseq = dcn401_hwseq_create,
1345 };
1346 
dcn401_dsc_destroy(struct display_stream_compressor ** dsc)1347 static void dcn401_dsc_destroy(struct display_stream_compressor **dsc)
1348 {
1349 	kfree(container_of(*dsc, struct dcn401_dsc, base));
1350 	*dsc = NULL;
1351 }
1352 
dcn401_resource_destruct(struct dcn401_resource_pool * pool)1353 static void dcn401_resource_destruct(struct dcn401_resource_pool *pool)
1354 {
1355 	unsigned int i;
1356 
1357 	for (i = 0; i < pool->base.stream_enc_count; i++) {
1358 		if (pool->base.stream_enc[i] != NULL) {
1359 			if (pool->base.stream_enc[i]->vpg != NULL) {
1360 				kfree(DCN31_VPG_FROM_VPG(pool->base.stream_enc[i]->vpg));
1361 				pool->base.stream_enc[i]->vpg = NULL;
1362 			}
1363 			if (pool->base.stream_enc[i]->afmt != NULL) {
1364 				kfree(DCN30_AFMT_FROM_AFMT(pool->base.stream_enc[i]->afmt));
1365 				pool->base.stream_enc[i]->afmt = NULL;
1366 			}
1367 			kfree(DCN10STRENC_FROM_STRENC(pool->base.stream_enc[i]));
1368 			pool->base.stream_enc[i] = NULL;
1369 		}
1370 	}
1371 
1372 	for (i = 0; i < pool->base.hpo_dp_stream_enc_count; i++) {
1373 		if (pool->base.hpo_dp_stream_enc[i] != NULL) {
1374 			if (pool->base.hpo_dp_stream_enc[i]->vpg != NULL) {
1375 				kfree(DCN31_VPG_FROM_VPG(pool->base.hpo_dp_stream_enc[i]->vpg));
1376 				pool->base.hpo_dp_stream_enc[i]->vpg = NULL;
1377 			}
1378 			if (pool->base.hpo_dp_stream_enc[i]->apg != NULL) {
1379 				kfree(DCN31_APG_FROM_APG(pool->base.hpo_dp_stream_enc[i]->apg));
1380 				pool->base.hpo_dp_stream_enc[i]->apg = NULL;
1381 			}
1382 			kfree(DCN3_1_HPO_DP_STREAM_ENC_FROM_HPO_STREAM_ENC(pool->base.hpo_dp_stream_enc[i]));
1383 			pool->base.hpo_dp_stream_enc[i] = NULL;
1384 		}
1385 	}
1386 
1387 	for (i = 0; i < pool->base.hpo_dp_link_enc_count; i++) {
1388 		if (pool->base.hpo_dp_link_enc[i] != NULL) {
1389 			kfree(DCN3_1_HPO_DP_LINK_ENC_FROM_HPO_LINK_ENC(pool->base.hpo_dp_link_enc[i]));
1390 			pool->base.hpo_dp_link_enc[i] = NULL;
1391 		}
1392 	}
1393 
1394 	for (i = 0; i < pool->base.res_cap->num_dsc; i++) {
1395 		if (pool->base.dscs[i] != NULL)
1396 			dcn401_dsc_destroy(&pool->base.dscs[i]);
1397 	}
1398 
1399 	if (pool->base.mpc != NULL) {
1400 		kfree(TO_DCN20_MPC(pool->base.mpc));
1401 		pool->base.mpc = NULL;
1402 	}
1403 	if (pool->base.hubbub != NULL) {
1404 		kfree(TO_DCN20_HUBBUB(pool->base.hubbub));
1405 		pool->base.hubbub = NULL;
1406 	}
1407 	for (i = 0; i < pool->base.pipe_count; i++) {
1408 		if (pool->base.dpps[i] != NULL)
1409 			dcn401_dpp_destroy(&pool->base.dpps[i]);
1410 
1411 		if (pool->base.ipps[i] != NULL)
1412 			pool->base.ipps[i]->funcs->ipp_destroy(&pool->base.ipps[i]);
1413 
1414 		if (pool->base.hubps[i] != NULL) {
1415 			kfree(TO_DCN20_HUBP(pool->base.hubps[i]));
1416 			pool->base.hubps[i] = NULL;
1417 		}
1418 
1419 		if (pool->base.irqs != NULL) {
1420 			dal_irq_service_destroy(&pool->base.irqs);
1421 		}
1422 	}
1423 
1424 	for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
1425 		if (pool->base.engines[i] != NULL)
1426 			dce110_engine_destroy(&pool->base.engines[i]);
1427 		if (pool->base.hw_i2cs[i] != NULL) {
1428 			kfree(pool->base.hw_i2cs[i]);
1429 			pool->base.hw_i2cs[i] = NULL;
1430 		}
1431 		if (pool->base.sw_i2cs[i] != NULL) {
1432 			kfree(pool->base.sw_i2cs[i]);
1433 			pool->base.sw_i2cs[i] = NULL;
1434 		}
1435 	}
1436 
1437 	for (i = 0; i < pool->base.res_cap->num_opp; i++) {
1438 		if (pool->base.opps[i] != NULL)
1439 			pool->base.opps[i]->funcs->opp_destroy(&pool->base.opps[i]);
1440 	}
1441 
1442 	for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) {
1443 		if (pool->base.timing_generators[i] != NULL)	{
1444 			kfree(DCN10TG_FROM_TG(pool->base.timing_generators[i]));
1445 			pool->base.timing_generators[i] = NULL;
1446 		}
1447 	}
1448 
1449 	for (i = 0; i < pool->base.res_cap->num_dwb; i++) {
1450 		if (pool->base.dwbc[i] != NULL) {
1451 			kfree(TO_DCN30_DWBC(pool->base.dwbc[i]));
1452 			pool->base.dwbc[i] = NULL;
1453 		}
1454 		if (pool->base.mcif_wb[i] != NULL) {
1455 			kfree(TO_DCN30_MMHUBBUB(pool->base.mcif_wb[i]));
1456 			pool->base.mcif_wb[i] = NULL;
1457 		}
1458 	}
1459 
1460 	for (i = 0; i < pool->base.audio_count; i++) {
1461 		if (pool->base.audios[i])
1462 			dce_aud_destroy(&pool->base.audios[i]);
1463 	}
1464 
1465 	for (i = 0; i < pool->base.clk_src_count; i++) {
1466 		if (pool->base.clock_sources[i] != NULL) {
1467 			dcn20_clock_source_destroy(&pool->base.clock_sources[i]);
1468 			pool->base.clock_sources[i] = NULL;
1469 		}
1470 	}
1471 
1472 	for (i = 0; i < pool->base.res_cap->num_mpc_3dlut; i++) {
1473 		if (pool->base.mpc_lut[i] != NULL) {
1474 			dc_3dlut_func_release(pool->base.mpc_lut[i]);
1475 			pool->base.mpc_lut[i] = NULL;
1476 		}
1477 		if (pool->base.mpc_shaper[i] != NULL) {
1478 			dc_transfer_func_release(pool->base.mpc_shaper[i]);
1479 			pool->base.mpc_shaper[i] = NULL;
1480 		}
1481 	}
1482 
1483 	if (pool->base.dp_clock_source != NULL) {
1484 		dcn20_clock_source_destroy(&pool->base.dp_clock_source);
1485 		pool->base.dp_clock_source = NULL;
1486 	}
1487 
1488 	for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) {
1489 		if (pool->base.multiple_abms[i] != NULL)
1490 			dce_abm_destroy(&pool->base.multiple_abms[i]);
1491 	}
1492 
1493 	if (pool->base.psr != NULL)
1494 		dmub_psr_destroy(&pool->base.psr);
1495 
1496 	if (pool->base.dccg != NULL)
1497 		dcn_dccg_destroy(&pool->base.dccg);
1498 
1499 	if (pool->base.oem_device != NULL) {
1500 		struct dc *dc = pool->base.oem_device->ctx->dc;
1501 
1502 		dc->link_srv->destroy_ddc_service(&pool->base.oem_device);
1503 	}
1504 }
1505 
1506 
dcn401_dwbc_create(struct dc_context * ctx,struct resource_pool * pool)1507 static bool dcn401_dwbc_create(struct dc_context *ctx, struct resource_pool *pool)
1508 {
1509 	int i;
1510 	uint32_t dwb_count = pool->res_cap->num_dwb;
1511 
1512 	for (i = 0; i < dwb_count; i++) {
1513 		struct dcn30_dwbc *dwbc401 = kzalloc(sizeof(struct dcn30_dwbc),
1514 						    GFP_KERNEL);
1515 
1516 		if (!dwbc401) {
1517 			dm_error("DC: failed to create dwbc401!\n");
1518 			return false;
1519 		}
1520 
1521 
1522 #undef REG_STRUCT
1523 #define REG_STRUCT dwbc401_regs
1524 		dwbc_regs_dcn401_init(0);
1525 
1526 		dcn30_dwbc_construct(dwbc401, ctx,
1527 				&dwbc401_regs[i],
1528 				&dwbc401_shift,
1529 				&dwbc401_mask,
1530 				i);
1531 
1532 		pool->dwbc[i] = &dwbc401->base;
1533 
1534 	}
1535 	return true;
1536 }
1537 
dcn401_mmhubbub_create(struct dc_context * ctx,struct resource_pool * pool)1538 static bool dcn401_mmhubbub_create(struct dc_context *ctx, struct resource_pool *pool)
1539 {
1540 	int i;
1541 	uint32_t dwb_count = pool->res_cap->num_dwb;
1542 
1543 	for (i = 0; i < dwb_count; i++) {
1544 		struct dcn30_mmhubbub *mcif_wb30 = kzalloc(sizeof(struct dcn30_mmhubbub),
1545 						    GFP_KERNEL);
1546 
1547 		if (!mcif_wb30) {
1548 			dm_error("DC: failed to create mcif_wb30!\n");
1549 			return false;
1550 		}
1551 
1552 #undef REG_STRUCT
1553 #define REG_STRUCT mcif_wb30_regs
1554 		mcif_wb_regs_dcn3_init(0);
1555 
1556 		dcn32_mmhubbub_construct(mcif_wb30, ctx,
1557 				&mcif_wb30_regs[i],
1558 				&mcif_wb30_shift,
1559 				&mcif_wb30_mask,
1560 				i);
1561 
1562 		pool->mcif_wb[i] = &mcif_wb30->base;
1563 	}
1564 	return true;
1565 }
1566 
dcn401_dsc_create(struct dc_context * ctx,uint32_t inst)1567 static struct display_stream_compressor *dcn401_dsc_create(
1568 	struct dc_context *ctx, uint32_t inst)
1569 {
1570 	struct dcn401_dsc *dsc =
1571 		kzalloc(sizeof(struct dcn401_dsc), GFP_KERNEL);
1572 
1573 	if (!dsc) {
1574 		BREAK_TO_DEBUGGER();
1575 		return NULL;
1576 	}
1577 
1578 #undef REG_STRUCT
1579 #define REG_STRUCT dsc_regs
1580 	dsc_regs_init(0),
1581 	dsc_regs_init(1),
1582 	dsc_regs_init(2),
1583 	dsc_regs_init(3);
1584 
1585 	dsc401_construct(dsc, ctx, inst, &dsc_regs[inst], &dsc_shift, &dsc_mask);
1586 	dsc401_set_fgcg(dsc,
1587 			       ctx->dc->debug.enable_fine_grain_clock_gating.bits.dsc);
1588 
1589 	//dsc->max_image_width = 6016;
1590 	dsc->max_image_width = 5760;
1591 
1592 	return &dsc->base;
1593 }
1594 
dcn401_destroy_resource_pool(struct resource_pool ** pool)1595 static void dcn401_destroy_resource_pool(struct resource_pool **pool)
1596 {
1597 	struct dcn401_resource_pool *dcn401_pool = TO_DCN401_RES_POOL(*pool);
1598 
1599 	dcn401_resource_destruct(dcn401_pool);
1600 	kfree(dcn401_pool);
1601 	*pool = NULL;
1602 }
1603 
1604 static struct dc_cap_funcs cap_funcs = {
1605 	.get_dcc_compression_cap = dcn20_get_dcc_compression_cap,
1606 	.get_subvp_en = dcn32_subvp_in_use,
1607 };
1608 
dcn401_update_bw_bounding_box(struct dc * dc,struct clk_bw_params * bw_params)1609 static void dcn401_update_bw_bounding_box(struct dc *dc, struct clk_bw_params *bw_params)
1610 {
1611 	struct dml2_configuration_options *dml2_opt = &dc->dml2_tmp;
1612 
1613 	memcpy(dml2_opt, &dc->dml2_options, sizeof(dc->dml2_options));
1614 
1615 	/* re-calculate the available MALL size if required */
1616 	if (bw_params->num_channels > 0) {
1617 		dc->caps.max_cab_allocation_bytes = dcn401_calc_num_avail_chans_for_mall(
1618 			dc, bw_params->num_channels) *
1619 			dc->caps.mall_size_per_mem_channel * 1024 * 1024;
1620 		dc->caps.mall_size_total = dc->caps.max_cab_allocation_bytes;
1621 	}
1622 
1623 	DC_FP_START();
1624 
1625 	dcn401_update_bw_bounding_box_fpu(dc, bw_params);
1626 
1627 	dml2_opt->use_clock_dc_limits = false;
1628 	if (dc->debug.using_dml2 && dc->current_state && dc->current_state->bw_ctx.dml2)
1629 		dml2_reinit(dc, dml2_opt, &dc->current_state->bw_ctx.dml2);
1630 
1631 	dml2_opt->use_clock_dc_limits = true;
1632 	if (dc->debug.using_dml2 && dc->current_state && dc->current_state->bw_ctx.dml2_dc_power_source)
1633 		dml2_reinit(dc, dml2_opt, &dc->current_state->bw_ctx.dml2_dc_power_source);
1634 
1635 	DC_FP_END();
1636 }
1637 
dcn401_patch_unknown_plane_state(struct dc_plane_state * plane_state)1638 enum dc_status dcn401_patch_unknown_plane_state(struct dc_plane_state *plane_state)
1639 {
1640 	plane_state->tiling_info.gfxversion = DcGfxAddr3;
1641 	plane_state->tiling_info.gfx_addr3.swizzle = DC_ADDR3_SW_64KB_2D;
1642 	return DC_OK;
1643 }
1644 
dcn401_validate_bandwidth(struct dc * dc,struct dc_state * context,bool fast_validate)1645 bool dcn401_validate_bandwidth(struct dc *dc,
1646 		struct dc_state *context,
1647 		bool fast_validate)
1648 {
1649 	bool out = false;
1650 	if (dc->debug.using_dml2)
1651 		out = dml2_validate(dc, context,
1652 				context->power_source == DC_POWER_SOURCE_DC ? context->bw_ctx.dml2_dc_power_source : context->bw_ctx.dml2,
1653 				fast_validate);
1654 	return out;
1655 }
1656 
dcn401_prepare_mcache_programming(struct dc * dc,struct dc_state * context)1657 void dcn401_prepare_mcache_programming(struct dc *dc,
1658 		struct dc_state *context)
1659 {
1660 	if (dc->debug.using_dml21)
1661 		dml2_prepare_mcache_programming(dc, context,
1662 				context->power_source == DC_POWER_SOURCE_DC ? context->bw_ctx.dml2_dc_power_source : context->bw_ctx.dml2);
1663 }
1664 
dcn401_build_pipe_pix_clk_params(struct pipe_ctx * pipe_ctx)1665 static void dcn401_build_pipe_pix_clk_params(struct pipe_ctx *pipe_ctx)
1666 {
1667 	const struct dc_stream_state *stream = pipe_ctx->stream;
1668 	struct dc_link *link = stream->link;
1669 	struct link_encoder *link_enc = pipe_ctx->link_res.dio_link_enc;
1670 	struct pixel_clk_params *pixel_clk_params = &pipe_ctx->stream_res.pix_clk_params;
1671 
1672 	pixel_clk_params->requested_pix_clk_100hz = stream->timing.pix_clk_100hz;
1673 
1674 	if (!pipe_ctx->stream->ctx->dc->config.unify_link_enc_assignment)
1675 		link_enc = link_enc_cfg_get_link_enc(link);
1676 	if (link_enc)
1677 		pixel_clk_params->encoder_object_id = link_enc->id;
1678 
1679 	pixel_clk_params->signal_type = pipe_ctx->stream->signal;
1680 	pixel_clk_params->controller_id = pipe_ctx->stream_res.tg->inst + 1;
1681 	/* TODO: un-hardcode*/
1682 
1683 	/* TODO - DP2.0 HW: calculate requested_sym_clk for UHBR rates */
1684 
1685 	pixel_clk_params->requested_sym_clk = LINK_RATE_LOW *
1686 		LINK_RATE_REF_FREQ_IN_KHZ;
1687 	pixel_clk_params->flags.ENABLE_SS = 0;
1688 	pixel_clk_params->color_depth =
1689 		stream->timing.display_color_depth;
1690 	pixel_clk_params->flags.DISPLAY_BLANKED = 1;
1691 	pixel_clk_params->pixel_encoding = stream->timing.pixel_encoding;
1692 
1693 	if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR422)
1694 		pixel_clk_params->color_depth = COLOR_DEPTH_888;
1695 
1696 	if (stream->timing.timing_3d_format == TIMING_3D_FORMAT_HW_FRAME_PACKING)
1697 		pixel_clk_params->requested_pix_clk_100hz *= 2;
1698 	if (dc_is_tmds_signal(stream->signal) &&
1699 			stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR420)
1700 		pixel_clk_params->requested_pix_clk_100hz /= 2;
1701 
1702 	pipe_ctx->clock_source->funcs->get_pix_clk_dividers(
1703 			pipe_ctx->clock_source,
1704 			&pipe_ctx->stream_res.pix_clk_params,
1705 			&pipe_ctx->pll_settings);
1706 
1707 	pixel_clk_params->dio_se_pix_per_cycle = 1;
1708 	if (dc_is_tmds_signal(stream->signal) &&
1709 			stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR420) {
1710 		pixel_clk_params->dio_se_pix_per_cycle = 2;
1711 	} else if (dc_is_dp_signal(stream->signal)) {
1712 		/* round up to nearest power of 2, or max at 8 pixels per cycle */
1713 		if (pixel_clk_params->requested_pix_clk_100hz > 4 * stream->ctx->dc->clk_mgr->dprefclk_khz * 10) {
1714 			pixel_clk_params->dio_se_pix_per_cycle = 8;
1715 		} else if (pixel_clk_params->requested_pix_clk_100hz > 2 * stream->ctx->dc->clk_mgr->dprefclk_khz * 10) {
1716 			pixel_clk_params->dio_se_pix_per_cycle = 4;
1717 		} else if (pixel_clk_params->requested_pix_clk_100hz > stream->ctx->dc->clk_mgr->dprefclk_khz * 10) {
1718 			pixel_clk_params->dio_se_pix_per_cycle = 2;
1719 		} else {
1720 			pixel_clk_params->dio_se_pix_per_cycle = 1;
1721 		}
1722 	}
1723 }
1724 
dcn401_get_power_profile(const struct dc_state * context)1725 static int dcn401_get_power_profile(const struct dc_state *context)
1726 {
1727 	int uclk_mhz = context->bw_ctx.bw.dcn.clk.dramclk_khz / 1000;
1728 	int dpm_level = 0;
1729 
1730 	for (int i = 0; i < context->clk_mgr->bw_params->clk_table.num_entries_per_clk.num_memclk_levels; i++) {
1731 		if (context->clk_mgr->bw_params->clk_table.entries[i].memclk_mhz == 0 ||
1732 			uclk_mhz < context->clk_mgr->bw_params->clk_table.entries[i].memclk_mhz)
1733 			break;
1734 		if (uclk_mhz > context->clk_mgr->bw_params->clk_table.entries[i].memclk_mhz)
1735 			dpm_level++;
1736 	}
1737 
1738 	return dpm_level;
1739 }
1740 
dcn401_get_vstartup_for_pipe(struct pipe_ctx * pipe_ctx)1741 static unsigned int dcn401_get_vstartup_for_pipe(struct pipe_ctx *pipe_ctx)
1742 {
1743 	return pipe_ctx->global_sync.dcn4x.vstartup_lines;
1744 }
1745 
1746 static struct resource_funcs dcn401_res_pool_funcs = {
1747 	.destroy = dcn401_destroy_resource_pool,
1748 	.link_enc_create = dcn401_link_encoder_create,
1749 	.link_enc_create_minimal = NULL,
1750 	.panel_cntl_create = dcn32_panel_cntl_create,
1751 	.validate_bandwidth = dcn401_validate_bandwidth,
1752 	.calculate_wm_and_dlg = NULL,
1753 	.populate_dml_pipes = NULL,
1754 	.acquire_free_pipe_as_secondary_dpp_pipe = dcn32_acquire_free_pipe_as_secondary_dpp_pipe,
1755 	.acquire_free_pipe_as_secondary_opp_head = dcn32_acquire_free_pipe_as_secondary_opp_head,
1756 	.release_pipe = dcn20_release_pipe,
1757 	.add_stream_to_ctx = dcn30_add_stream_to_ctx,
1758 	.add_dsc_to_stream_resource = dcn20_add_dsc_to_stream_resource,
1759 	.remove_stream_from_ctx = dcn20_remove_stream_from_ctx,
1760 	.populate_dml_writeback_from_context = dcn30_populate_dml_writeback_from_context,
1761 	.set_mcif_arb_params = dcn30_set_mcif_arb_params,
1762 	.find_first_free_match_stream_enc_for_link = dcn10_find_first_free_match_stream_enc_for_link,
1763 	.acquire_post_bldn_3dlut = dcn32_acquire_post_bldn_3dlut,
1764 	.release_post_bldn_3dlut = dcn32_release_post_bldn_3dlut,
1765 	.update_bw_bounding_box = dcn401_update_bw_bounding_box,
1766 	.patch_unknown_plane_state = dcn401_patch_unknown_plane_state,
1767 	.update_soc_for_wm_a = dcn30_update_soc_for_wm_a,
1768 	.add_phantom_pipes = dcn32_add_phantom_pipes,
1769 	.prepare_mcache_programming = dcn401_prepare_mcache_programming,
1770 	.build_pipe_pix_clk_params = dcn401_build_pipe_pix_clk_params,
1771 	.calculate_mall_ways_from_bytes = dcn32_calculate_mall_ways_from_bytes,
1772 	.get_power_profile = dcn401_get_power_profile,
1773 	.get_vstartup_for_pipe = dcn401_get_vstartup_for_pipe
1774 };
1775 
read_pipe_fuses(struct dc_context * ctx)1776 static uint32_t read_pipe_fuses(struct dc_context *ctx)
1777 {
1778 	uint32_t value = REG_READ(CC_DC_PIPE_DIS);
1779 	/* DCN401 support max 4 pipes */
1780 	value = value & 0xf;
1781 	return value;
1782 }
1783 
1784 
dcn401_resource_construct(uint8_t num_virtual_links,struct dc * dc,struct dcn401_resource_pool * pool)1785 static bool dcn401_resource_construct(
1786 	uint8_t num_virtual_links,
1787 	struct dc *dc,
1788 	struct dcn401_resource_pool *pool)
1789 {
1790 	int i, j;
1791 	struct dc_context *ctx = dc->ctx;
1792 	struct irq_service_init_data init_data;
1793 	struct ddc_service_init_data ddc_init_data = {0};
1794 	uint32_t pipe_fuses = 0;
1795 	uint32_t num_pipes  = 4;
1796 
1797 #undef REG_STRUCT
1798 #define REG_STRUCT bios_regs
1799 	bios_regs_init();
1800 
1801 #undef REG_STRUCT
1802 #define REG_STRUCT clk_src_regs
1803 	clk_src_regs_init(0, A),
1804 	clk_src_regs_init(1, B),
1805 	clk_src_regs_init(2, C),
1806 	clk_src_regs_init(3, D);
1807 
1808 #undef REG_STRUCT
1809 #define REG_STRUCT abm_regs
1810 		abm_regs_init(0),
1811 		abm_regs_init(1),
1812 		abm_regs_init(2),
1813 		abm_regs_init(3);
1814 
1815 #undef REG_STRUCT
1816 #define REG_STRUCT dccg_regs
1817 	dccg_regs_init();
1818 
1819 	ctx->dc_bios->regs = &bios_regs;
1820 
1821 	pool->base.res_cap = &res_cap_dcn4_01;
1822 
1823 	/* max number of pipes for ASIC before checking for pipe fuses */
1824 	num_pipes  = pool->base.res_cap->num_timing_generator;
1825 	pipe_fuses = read_pipe_fuses(ctx);
1826 
1827 	for (i = 0; i < pool->base.res_cap->num_timing_generator; i++)
1828 		if (pipe_fuses & 1 << i)
1829 			num_pipes--;
1830 
1831 	if (pipe_fuses & 1)
1832 		ASSERT(0); //Unexpected - Pipe 0 should always be fully functional!
1833 
1834 	if (pipe_fuses & CC_DC_PIPE_DIS__DC_FULL_DIS_MASK)
1835 		ASSERT(0); //Entire DCN is harvested!
1836 
1837 	pool->base.funcs = &dcn401_res_pool_funcs;
1838 
1839 	/*************************************************
1840 	 *  Resource + asic cap harcoding                *
1841 	 *************************************************/
1842 	pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
1843 	pool->base.timing_generator_count = num_pipes;
1844 	pool->base.pipe_count = num_pipes;
1845 	pool->base.mpcc_count = num_pipes;
1846 	dc->caps.max_downscale_ratio = 600;
1847 	dc->caps.i2c_speed_in_khz = 95;
1848 	dc->caps.i2c_speed_in_khz_hdcp = 95; /*1.4 w/a applied by default*/
1849 	/* TODO: Bring max cursor size back to 256 after subvp cursor corruption is fixed*/
1850 	dc->caps.max_cursor_size = 64;
1851 	dc->caps.cursor_not_scaled = true;
1852 	dc->caps.min_horizontal_blanking_period = 80;
1853 	dc->caps.dmdata_alloc_size = 2048;
1854 	dc->caps.mall_size_per_mem_channel = 4;
1855 	dc->caps.cursor_cache_size = dc->caps.max_cursor_size * dc->caps.max_cursor_size * 8;
1856 	dc->caps.cache_line_size = 64;
1857 	dc->caps.cache_num_ways = 16;
1858 
1859 	/* Calculate the available MALL space */
1860 	dc->caps.max_cab_allocation_bytes = dcn401_calc_num_avail_chans_for_mall(
1861 		dc, dc->ctx->dc_bios->vram_info.num_chans) *
1862 		dc->caps.mall_size_per_mem_channel * 1024 * 1024;
1863 	dc->caps.mall_size_total = dc->caps.max_cab_allocation_bytes;
1864 
1865 	dc->caps.subvp_fw_processing_delay_us = 15;
1866 	dc->caps.subvp_drr_max_vblank_margin_us = 40;
1867 	dc->caps.subvp_prefetch_end_to_mall_start_us = 15;
1868 	dc->caps.subvp_swath_height_margin_lines = 16;
1869 	dc->caps.subvp_pstate_allow_width_us = 20;
1870 	dc->caps.subvp_vertical_int_margin_us = 30;
1871 	dc->caps.subvp_drr_vblank_start_margin_us = 100; // 100us margin
1872 
1873 	dc->caps.max_slave_planes = 3;
1874 	dc->caps.max_slave_yuv_planes = 3;
1875 	dc->caps.max_slave_rgb_planes = 3;
1876 	dc->caps.post_blend_color_processing = true;
1877 	dc->caps.force_dp_tps4_for_cp2520 = true;
1878 	dc->caps.dp_hpo = true;
1879 	dc->caps.dp_hdmi21_pcon_support = true;
1880 	dc->caps.edp_dsc_support = true;
1881 	dc->caps.extended_aux_timeout_support = true;
1882 	dc->caps.dmcub_support = true;
1883 	dc->caps.max_v_total = (1 << 15) - 1;
1884 	dc->caps.vtotal_limited_by_fp2 = true;
1885 
1886 	if (ASICREV_IS_GC_12_0_1_A0(dc->ctx->asic_id.hw_internal_rev))
1887 		dc->caps.dcc_plane_width_limit = 7680;
1888 
1889 	/* Color pipeline capabilities */
1890 	dc->caps.color.dpp.dcn_arch = 1;
1891 	dc->caps.color.dpp.input_lut_shared = 0;
1892 	dc->caps.color.dpp.icsc = 1;
1893 	dc->caps.color.dpp.dgam_ram = 0; // must use gamma_corr
1894 	dc->caps.color.dpp.dgam_rom_caps.srgb = 1;
1895 	dc->caps.color.dpp.dgam_rom_caps.bt2020 = 1;
1896 	dc->caps.color.dpp.dgam_rom_caps.gamma2_2 = 1;
1897 	dc->caps.color.dpp.dgam_rom_caps.pq = 1;
1898 	dc->caps.color.dpp.dgam_rom_caps.hlg = 1;
1899 	dc->caps.color.dpp.post_csc = 1;
1900 	dc->caps.color.dpp.gamma_corr = 1;
1901 	dc->caps.color.dpp.dgam_rom_for_yuv = 0;
1902 
1903 	dc->caps.color.dpp.hw_3d_lut = 1;
1904 	dc->caps.color.dpp.ogam_ram = 1;
1905 	// no OGAM ROM on DCN2 and later ASICs
1906 	dc->caps.color.dpp.ogam_rom_caps.srgb = 0;
1907 	dc->caps.color.dpp.ogam_rom_caps.bt2020 = 0;
1908 	dc->caps.color.dpp.ogam_rom_caps.gamma2_2 = 0;
1909 	dc->caps.color.dpp.ogam_rom_caps.pq = 0;
1910 	dc->caps.color.dpp.ogam_rom_caps.hlg = 0;
1911 	dc->caps.color.dpp.ocsc = 0;
1912 
1913 	dc->caps.color.mpc.gamut_remap = 1;
1914 	dc->caps.color.mpc.num_3dluts = pool->base.res_cap->num_mpc_3dlut; //4, configurable to be before or after BLND in MPCC
1915 	dc->caps.color.mpc.ogam_ram = 1;
1916 	dc->caps.color.mpc.ogam_rom_caps.srgb = 0;
1917 	dc->caps.color.mpc.ogam_rom_caps.bt2020 = 0;
1918 	dc->caps.color.mpc.ogam_rom_caps.gamma2_2 = 0;
1919 	dc->caps.color.mpc.ogam_rom_caps.pq = 0;
1920 	dc->caps.color.mpc.ogam_rom_caps.hlg = 0;
1921 	dc->caps.color.mpc.ocsc = 1;
1922 	dc->config.use_spl = true;
1923 	dc->config.prefer_easf = true;
1924 	dc->config.dc_mode_clk_limit_support = true;
1925 	dc->config.enable_windowed_mpo_odm = true;
1926 	dc->config.set_pipe_unlock_order = true; /* Need to ensure DET gets freed before allocating */
1927 
1928 	/* read VBIOS LTTPR caps */
1929 	{
1930 		if (ctx->dc_bios->funcs->get_lttpr_caps) {
1931 			enum bp_result bp_query_result;
1932 			uint8_t is_vbios_lttpr_enable = 0;
1933 
1934 			bp_query_result = ctx->dc_bios->funcs->get_lttpr_caps(ctx->dc_bios, &is_vbios_lttpr_enable);
1935 			dc->caps.vbios_lttpr_enable = (bp_query_result == BP_RESULT_OK) && !!is_vbios_lttpr_enable;
1936 		}
1937 
1938 		/* interop bit is implicit */
1939 		{
1940 			dc->caps.vbios_lttpr_aware = true;
1941 		}
1942 	}
1943 
1944 	if (dc->ctx->dce_environment == DCE_ENV_PRODUCTION_DRV)
1945 		dc->debug = debug_defaults_drv;
1946 
1947 	// Init the vm_helper
1948 	if (dc->vm_helper)
1949 		vm_helper_init(dc->vm_helper, 16);
1950 
1951 	/*************************************************
1952 	 *  Create resources                             *
1953 	 *************************************************/
1954 
1955 	/* Clock Sources for Pixel Clock*/
1956 	pool->base.clock_sources[DCN401_CLK_SRC_PLL0] =
1957 			dcn401_clock_source_create(ctx, ctx->dc_bios,
1958 				CLOCK_SOURCE_COMBO_PHY_PLL0,
1959 				&clk_src_regs[0], false);
1960 	pool->base.clock_sources[DCN401_CLK_SRC_PLL1] =
1961 			dcn401_clock_source_create(ctx, ctx->dc_bios,
1962 				CLOCK_SOURCE_COMBO_PHY_PLL1,
1963 				&clk_src_regs[1], false);
1964 	pool->base.clock_sources[DCN401_CLK_SRC_PLL2] =
1965 			dcn401_clock_source_create(ctx, ctx->dc_bios,
1966 				CLOCK_SOURCE_COMBO_PHY_PLL2,
1967 				&clk_src_regs[2], false);
1968 	pool->base.clock_sources[DCN401_CLK_SRC_PLL3] =
1969 			dcn401_clock_source_create(ctx, ctx->dc_bios,
1970 				CLOCK_SOURCE_COMBO_PHY_PLL3,
1971 				&clk_src_regs[3], false);
1972 	// pool->base.clock_sources[DCN401_CLK_SRC_PLL4] =
1973 	// 		dcn401_clock_source_create(ctx, ctx->dc_bios,
1974 	// 			CLOCK_SOURCE_COMBO_PHY_PLL4,
1975 	// 			&clk_src_regs[4], false);
1976 
1977 	pool->base.clk_src_count = DCN401_CLK_SRC_TOTAL;
1978 
1979 	/* todo: not reuse phy_pll registers */
1980 	pool->base.dp_clock_source =
1981 			dcn401_clock_source_create(ctx, ctx->dc_bios,
1982 				CLOCK_SOURCE_ID_DP_DTO,
1983 				&clk_src_regs[0], true);
1984 
1985 	for (i = 0; i < pool->base.clk_src_count; i++) {
1986 		if (pool->base.clock_sources[i] == NULL) {
1987 			dm_error("DC: failed to create clock sources!\n");
1988 			BREAK_TO_DEBUGGER();
1989 			goto create_fail;
1990 		}
1991 	}
1992 
1993 	/* DCCG */
1994 	pool->base.dccg = dccg401_create(ctx, &dccg_regs, &dccg_shift, &dccg_mask);
1995 	if (pool->base.dccg == NULL) {
1996 		dm_error("DC: failed to create dccg!\n");
1997 		BREAK_TO_DEBUGGER();
1998 		goto create_fail;
1999 	}
2000 
2001 	/* IRQ Service */
2002 	init_data.ctx = dc->ctx;
2003 	pool->base.irqs = dal_irq_service_dcn401_create(&init_data);
2004 	if (!pool->base.irqs)
2005 		goto create_fail;
2006 
2007 	/* HUBBUB */
2008 	pool->base.hubbub = dcn401_hubbub_create(ctx);
2009 	if (pool->base.hubbub == NULL) {
2010 		BREAK_TO_DEBUGGER();
2011 		dm_error("DC: failed to create hubbub!\n");
2012 		goto create_fail;
2013 	}
2014 
2015 	/* HUBPs, DPPs, OPPs, TGs, ABMs */
2016 	for (i = 0, j = 0; i < pool->base.res_cap->num_timing_generator; i++) {
2017 
2018 		/* if pipe is disabled, skip instance of HW pipe,
2019 		 * i.e, skip ASIC register instance
2020 		 */
2021 		if (pipe_fuses & 1 << i)
2022 			continue;
2023 
2024 		pool->base.hubps[j] = dcn401_hubp_create(ctx, i);
2025 		if (pool->base.hubps[j] == NULL) {
2026 			BREAK_TO_DEBUGGER();
2027 			dm_error(
2028 				"DC: failed to create hubps!\n");
2029 			goto create_fail;
2030 		}
2031 
2032 		pool->base.dpps[j] = dcn401_dpp_create(ctx, i);
2033 		if (pool->base.dpps[j] == NULL) {
2034 			BREAK_TO_DEBUGGER();
2035 			dm_error(
2036 				"DC: failed to create dpps!\n");
2037 			goto create_fail;
2038 		}
2039 
2040 		pool->base.opps[j] = dcn401_opp_create(ctx, i);
2041 		if (pool->base.opps[j] == NULL) {
2042 			BREAK_TO_DEBUGGER();
2043 			dm_error(
2044 				"DC: failed to create output pixel processor!\n");
2045 			goto create_fail;
2046 		}
2047 
2048 		pool->base.timing_generators[j] = dcn401_timing_generator_create(
2049 				ctx, i);
2050 		if (pool->base.timing_generators[j] == NULL) {
2051 			BREAK_TO_DEBUGGER();
2052 			dm_error("DC: failed to create tg!\n");
2053 			goto create_fail;
2054 		}
2055 
2056 		pool->base.multiple_abms[j] = dmub_abm_create(ctx,
2057 				&abm_regs[i],
2058 				&abm_shift,
2059 				&abm_mask);
2060 		if (pool->base.multiple_abms[j] == NULL) {
2061 			dm_error("DC: failed to create abm for pipe %d!\n", i);
2062 			BREAK_TO_DEBUGGER();
2063 			goto create_fail;
2064 		}
2065 
2066 		/* index for resource pool arrays for next valid pipe */
2067 		j++;
2068 	}
2069 
2070 	/* PSR */
2071 	pool->base.psr = dmub_psr_create(ctx);
2072 	if (pool->base.psr == NULL) {
2073 		dm_error("DC: failed to create psr obj!\n");
2074 		BREAK_TO_DEBUGGER();
2075 		goto create_fail;
2076 	}
2077 
2078 	/* MPCCs */
2079 	pool->base.mpc = dcn401_mpc_create(ctx,  pool->base.res_cap->num_timing_generator, pool->base.res_cap->num_mpc_3dlut);
2080 	if (pool->base.mpc == NULL) {
2081 		BREAK_TO_DEBUGGER();
2082 		dm_error("DC: failed to create mpc!\n");
2083 		goto create_fail;
2084 	}
2085 
2086 	/* DSCs */
2087 	for (i = 0; i < pool->base.res_cap->num_dsc; i++) {
2088 		pool->base.dscs[i] = dcn401_dsc_create(ctx, i);
2089 		if (pool->base.dscs[i] == NULL) {
2090 			BREAK_TO_DEBUGGER();
2091 			dm_error("DC: failed to create display stream compressor %d!\n", i);
2092 			goto create_fail;
2093 		}
2094 	}
2095 
2096 	/* DWB */
2097 	if (!dcn401_dwbc_create(ctx, &pool->base)) {
2098 		BREAK_TO_DEBUGGER();
2099 		dm_error("DC: failed to create dwbc!\n");
2100 		goto create_fail;
2101 	}
2102 
2103 	/* MMHUBBUB */
2104 	if (!dcn401_mmhubbub_create(ctx, &pool->base)) {
2105 		BREAK_TO_DEBUGGER();
2106 		dm_error("DC: failed to create mcif_wb!\n");
2107 		goto create_fail;
2108 	}
2109 
2110 	/* AUX and I2C */
2111 	for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
2112 		pool->base.engines[i] = dcn401_aux_engine_create(ctx, i);
2113 		if (pool->base.engines[i] == NULL) {
2114 			BREAK_TO_DEBUGGER();
2115 			dm_error(
2116 				"DC:failed to create aux engine!!\n");
2117 			goto create_fail;
2118 		}
2119 		pool->base.hw_i2cs[i] = dcn401_i2c_hw_create(ctx, i);
2120 		if (pool->base.hw_i2cs[i] == NULL) {
2121 			BREAK_TO_DEBUGGER();
2122 			dm_error(
2123 				"DC:failed to create hw i2c!!\n");
2124 			goto create_fail;
2125 		}
2126 		pool->base.sw_i2cs[i] = NULL;
2127 	}
2128 
2129 	/* Audio, HWSeq, Stream Encoders including HPO and virtual, MPC 3D LUTs */
2130 	if (!resource_construct(num_virtual_links, dc, &pool->base,
2131 			&res_create_funcs))
2132 		goto create_fail;
2133 
2134 	/* HW Sequencer init functions and Plane caps */
2135 	dcn401_hw_sequencer_init_functions(dc);
2136 
2137 	dc->caps.max_planes =  pool->base.pipe_count;
2138 
2139 	for (i = 0; i < dc->caps.max_planes; ++i)
2140 		dc->caps.planes[i] = plane_cap;
2141 
2142 	dc->cap_funcs = cap_funcs;
2143 
2144 	if (dc->ctx->dc_bios->fw_info.oem_i2c_present) {
2145 		ddc_init_data.ctx = dc->ctx;
2146 		ddc_init_data.link = NULL;
2147 		ddc_init_data.id.id = dc->ctx->dc_bios->fw_info.oem_i2c_obj_id;
2148 		ddc_init_data.id.enum_id = 0;
2149 		ddc_init_data.id.type = OBJECT_TYPE_GENERIC;
2150 		pool->base.oem_device = dc->link_srv->create_ddc_service(&ddc_init_data);
2151 	} else {
2152 		pool->base.oem_device = NULL;
2153 	}
2154 
2155 	//For now enable SDPIF_REQUEST_RATE_LIMIT on DCN4_01 when vram_info.num_chans provided
2156 	if (dc->config.sdpif_request_limit_words_per_umc == 0)
2157 		dc->config.sdpif_request_limit_words_per_umc = 16;
2158 
2159 	dc->dml2_options.dcn_pipe_count = pool->base.pipe_count;
2160 	dc->dml2_options.use_native_pstate_optimization = false;
2161 	dc->dml2_options.use_native_soc_bb_construction = true;
2162 	dc->dml2_options.minimize_dispclk_using_odm = true;
2163 	dc->dml2_options.map_dc_pipes_with_callbacks = true;
2164 	dc->dml2_options.force_tdlut_enable = true;
2165 
2166 	resource_init_common_dml2_callbacks(dc, &dc->dml2_options);
2167 	dc->dml2_options.callbacks.can_support_mclk_switch_using_fw_based_vblank_stretch = &dcn30_can_support_mclk_switch_using_fw_based_vblank_stretch;
2168 	dc->dml2_options.svp_pstate.callbacks.release_dsc = &dcn20_release_dsc;
2169 	dc->dml2_options.svp_pstate.callbacks.calculate_mall_ways_from_bytes = pool->base.funcs->calculate_mall_ways_from_bytes;
2170 
2171 	dc->dml2_options.svp_pstate.subvp_fw_processing_delay_us = dc->caps.subvp_fw_processing_delay_us;
2172 	dc->dml2_options.svp_pstate.subvp_prefetch_end_to_mall_start_us = dc->caps.subvp_prefetch_end_to_mall_start_us;
2173 	dc->dml2_options.svp_pstate.subvp_pstate_allow_width_us = dc->caps.subvp_pstate_allow_width_us;
2174 	dc->dml2_options.svp_pstate.subvp_swath_height_margin_lines = dc->caps.subvp_swath_height_margin_lines;
2175 
2176 	dc->dml2_options.svp_pstate.force_disable_subvp = dc->debug.force_disable_subvp;
2177 	dc->dml2_options.svp_pstate.force_enable_subvp = dc->debug.force_subvp_mclk_switch;
2178 
2179 	dc->dml2_options.mall_cfg.cache_line_size_bytes = dc->caps.cache_line_size;
2180 	dc->dml2_options.mall_cfg.cache_num_ways = dc->caps.cache_num_ways;
2181 	dc->dml2_options.mall_cfg.max_cab_allocation_bytes = dc->caps.max_cab_allocation_bytes;
2182 	dc->dml2_options.mall_cfg.mblk_height_4bpe_pixels = DCN3_2_MBLK_HEIGHT_4BPE;
2183 	dc->dml2_options.mall_cfg.mblk_height_8bpe_pixels = DCN3_2_MBLK_HEIGHT_8BPE;
2184 	dc->dml2_options.mall_cfg.mblk_size_bytes = DCN3_2_MALL_MBLK_SIZE_BYTES;
2185 	dc->dml2_options.mall_cfg.mblk_width_pixels = DCN3_2_MBLK_WIDTH;
2186 
2187 	dc->dml2_options.max_segments_per_hubp = 20;
2188 	dc->dml2_options.det_segment_size = DCN4_01_CRB_SEGMENT_SIZE_KB;
2189 
2190 	/* SPL */
2191 	dc->caps.scl_caps.sharpener_support = true;
2192 
2193 	return true;
2194 
2195 create_fail:
2196 
2197 	dcn401_resource_destruct(pool);
2198 
2199 	return false;
2200 }
2201 
dcn401_create_resource_pool(const struct dc_init_data * init_data,struct dc * dc)2202 struct resource_pool *dcn401_create_resource_pool(
2203 		const struct dc_init_data *init_data,
2204 		struct dc *dc)
2205 {
2206 	struct dcn401_resource_pool *pool =
2207 		kzalloc(sizeof(struct dcn401_resource_pool), GFP_KERNEL);
2208 
2209 	if (!pool)
2210 		return NULL;
2211 
2212 	if (dcn401_resource_construct(init_data->num_virtual_links, dc, pool))
2213 		return &pool->base;
2214 
2215 	BREAK_TO_DEBUGGER();
2216 	kfree(pool);
2217 	return NULL;
2218 }
2219