xref: /linux/drivers/gpu/drm/amd/display/dc/resource/dcn321/dcn321_resource.c (revision 442bc81bd344dc52c37d8f80b854cc6da062b2d0)
1 // SPDX-License-Identifier: MIT
2 /*
3  * Copyright 2019 Advanced Micro Devices, Inc.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21  * OTHER DEALINGS IN THE SOFTWARE.
22  *
23  * Authors: AMD
24  *
25  */
26 
27 #include "dm_services.h"
28 #include "dc.h"
29 
30 #include "dcn32/dcn32_init.h"
31 
32 #include "resource.h"
33 #include "include/irq_service_interface.h"
34 #include "dcn32/dcn32_resource.h"
35 #include "dcn321_resource.h"
36 
37 #include "dcn20/dcn20_resource.h"
38 #include "dcn30/dcn30_resource.h"
39 
40 #include "dml/dcn321/dcn321_fpu.h"
41 
42 #include "dcn10/dcn10_ipp.h"
43 #include "dcn30/dcn30_hubbub.h"
44 #include "dcn31/dcn31_hubbub.h"
45 #include "dcn32/dcn32_hubbub.h"
46 #include "dcn32/dcn32_mpc.h"
47 #include "dcn32/dcn32_hubp.h"
48 #include "irq/dcn32/irq_service_dcn32.h"
49 #include "dcn32/dcn32_dpp.h"
50 #include "dcn32/dcn32_optc.h"
51 #include "dcn20/dcn20_hwseq.h"
52 #include "dcn30/dcn30_hwseq.h"
53 #include "dce110/dce110_hwseq.h"
54 #include "dcn30/dcn30_opp.h"
55 #include "dcn20/dcn20_dsc.h"
56 #include "dcn30/dcn30_vpg.h"
57 #include "dcn30/dcn30_afmt.h"
58 #include "dcn30/dcn30_dio_stream_encoder.h"
59 #include "dcn32/dcn32_dio_stream_encoder.h"
60 #include "dcn31/dcn31_hpo_dp_stream_encoder.h"
61 #include "dcn31/dcn31_hpo_dp_link_encoder.h"
62 #include "dcn32/dcn32_hpo_dp_link_encoder.h"
63 #include "dcn31/dcn31_apg.h"
64 #include "dcn31/dcn31_dio_link_encoder.h"
65 #include "dcn32/dcn32_dio_link_encoder.h"
66 #include "dcn321/dcn321_dio_link_encoder.h"
67 #include "dce/dce_clock_source.h"
68 #include "dce/dce_audio.h"
69 #include "dce/dce_hwseq.h"
70 #include "clk_mgr.h"
71 #include "virtual/virtual_stream_encoder.h"
72 #include "dml/display_mode_vba.h"
73 #include "dcn32/dcn32_dccg.h"
74 #include "dcn10/dcn10_resource.h"
75 #include "link.h"
76 #include "dcn31/dcn31_panel_cntl.h"
77 
78 #include "dcn30/dcn30_dwb.h"
79 #include "dcn32/dcn32_mmhubbub.h"
80 
81 #include "dcn/dcn_3_2_1_offset.h"
82 #include "dcn/dcn_3_2_1_sh_mask.h"
83 #include "nbio/nbio_4_3_0_offset.h"
84 
85 #include "reg_helper.h"
86 #include "dce/dmub_abm.h"
87 #include "dce/dmub_psr.h"
88 #include "dce/dce_aux.h"
89 #include "dce/dce_i2c.h"
90 
91 #include "dml/dcn30/display_mode_vba_30.h"
92 #include "vm_helper.h"
93 #include "dcn20/dcn20_vmid.h"
94 
95 #include "dc_state_priv.h"
96 
97 #define DC_LOGGER_INIT(logger)
98 
99 enum dcn321_clk_src_array_id {
100 	DCN321_CLK_SRC_PLL0,
101 	DCN321_CLK_SRC_PLL1,
102 	DCN321_CLK_SRC_PLL2,
103 	DCN321_CLK_SRC_PLL3,
104 	DCN321_CLK_SRC_PLL4,
105 	DCN321_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) ctx->dcn_reg_offsets[seg]
114 
115 #define BASE(seg) BASE_INNER(seg)
116 
117 #define SR(reg_name)\
118 	REG_STRUCT.reg_name = BASE(reg ## reg_name ## _BASE_IDX) +  \
119 		reg ## reg_name
120 #define SR_ARR(reg_name, id)\
121 	REG_STRUCT[id].reg_name = BASE(reg ## reg_name ## _BASE_IDX) +  \
122 		reg ## reg_name
123 #define SR_ARR_INIT(reg_name, id, value)\
124 	REG_STRUCT[id].reg_name =  value
125 
126 #define SRI(reg_name, block, id)\
127 	REG_STRUCT.reg_name = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
128 		reg ## block ## id ## _ ## reg_name
129 
130 #define SRI_ARR(reg_name, block, id)\
131 	REG_STRUCT[id].reg_name = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
132 		reg ## block ## id ## _ ## reg_name
133 
134 #define SR_ARR_I2C(reg_name, id) \
135 	REG_STRUCT[id-1].reg_name = BASE(reg##reg_name##_BASE_IDX) + reg##reg_name
136 
137 #define SRI_ARR_I2C(reg_name, block, id)\
138 	REG_STRUCT[id-1].reg_name = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
139 		reg ## block ## id ## _ ## reg_name
140 
141 #define SRI_ARR_ALPHABET(reg_name, block, index, id)\
142 	REG_STRUCT[index].reg_name = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
143 		reg ## block ## id ## _ ## reg_name
144 
145 #define SRI2(reg_name, block, id)\
146 	.reg_name = BASE(reg ## reg_name ## _BASE_IDX) + \
147 		reg ## reg_name
148 #define SRI2_ARR(reg_name, block, id)\
149 	REG_STRUCT[id].reg_name = BASE(reg ## reg_name ## _BASE_IDX) + \
150 		reg ## reg_name
151 
152 #define SRIR(var_name, reg_name, block, id)\
153 	.var_name = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
154 		reg ## block ## id ## _ ## reg_name
155 
156 #define SRII(reg_name, block, id)\
157 	REG_STRUCT.reg_name[id] = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
158 		reg ## block ## id ## _ ## reg_name
159 
160 #define SRII_ARR_2(reg_name, block, id, inst)\
161 	REG_STRUCT[inst].reg_name[id] = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
162 		reg ## block ## id ## _ ## reg_name
163 
164 #define SRII_MPC_RMU(reg_name, block, id)\
165 	.RMU##_##reg_name[id] = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
166 		reg ## block ## id ## _ ## reg_name
167 
168 #define SRII_DWB(reg_name, temp_name, block, id)\
169 	REG_STRUCT.reg_name[id] = BASE(reg ## block ## id ## _ ## temp_name ## _BASE_IDX) + \
170 		reg ## block ## id ## _ ## temp_name
171 
172 #define DCCG_SRII(reg_name, block, id)\
173 	REG_STRUCT.block ## _ ## reg_name[id] = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
174 		reg ## block ## id ## _ ## reg_name
175 
176 #define SF_DWB2(reg_name, block, id, field_name, post_fix) \
177 	.field_name = reg_name ## __ ## field_name ## post_fix
178 
179 #define VUPDATE_SRII(reg_name, block, id)\
180 	REG_STRUCT.reg_name[id] = BASE(reg ## reg_name ## _ ## block ## id ## _BASE_IDX) + \
181 		reg ## reg_name ## _ ## block ## id
182 
183 /* NBIO */
184 #define NBIO_BASE_INNER(seg) ctx->nbio_reg_offsets[seg]
185 
186 #define NBIO_BASE(seg) \
187 	NBIO_BASE_INNER(seg)
188 
189 #define NBIO_SR(reg_name)\
190 	REG_STRUCT.reg_name = NBIO_BASE(regBIF_BX0_ ## reg_name ## _BASE_IDX) + \
191 		regBIF_BX0_ ## reg_name
192 #define NBIO_SR_ARR(reg_name, id)\
193 	REG_STRUCT[id].reg_name = NBIO_BASE(regBIF_BX0_ ## reg_name ## _BASE_IDX) + \
194 		regBIF_BX0_ ## reg_name
195 
196 #define CTX ctx
197 #define REG(reg_name) \
198 	(ctx->dcn_reg_offsets[reg ## reg_name ## _BASE_IDX] + reg ## reg_name)
199 
200 static struct bios_registers bios_regs;
201 
202 #define bios_regs_init() \
203 		( \
204 		NBIO_SR(BIOS_SCRATCH_3),\
205 		NBIO_SR(BIOS_SCRATCH_6)\
206 		)
207 
208 #define clk_src_regs_init(index, pllid)\
209 	CS_COMMON_REG_LIST_DCN3_0_RI(index, pllid)
210 
211 static struct dce110_clk_src_regs clk_src_regs[5];
212 
213 static const struct dce110_clk_src_shift cs_shift = {
214 		CS_COMMON_MASK_SH_LIST_DCN3_2(__SHIFT)
215 };
216 
217 static const struct dce110_clk_src_mask cs_mask = {
218 		CS_COMMON_MASK_SH_LIST_DCN3_2(_MASK)
219 };
220 
221 #define abm_regs_init(id)\
222 		ABM_DCN32_REG_LIST_RI(id)
223 
224 static struct dce_abm_registers abm_regs[4];
225 
226 static const struct dce_abm_shift abm_shift = {
227 		ABM_MASK_SH_LIST_DCN32(__SHIFT)
228 };
229 
230 static const struct dce_abm_mask abm_mask = {
231 		ABM_MASK_SH_LIST_DCN32(_MASK)
232 };
233 
234 #define audio_regs_init(id)\
235 		AUD_COMMON_REG_LIST_RI(id)
236 
237 static struct dce_audio_registers audio_regs[5];
238 
239 #define DCE120_AUD_COMMON_MASK_SH_LIST(mask_sh)\
240 		SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_INDEX, AZALIA_ENDPOINT_REG_INDEX, mask_sh),\
241 		SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_DATA, AZALIA_ENDPOINT_REG_DATA, mask_sh),\
242 		AUD_COMMON_MASK_SH_LIST_BASE(mask_sh)
243 
244 static const struct dce_audio_shift audio_shift = {
245 		DCE120_AUD_COMMON_MASK_SH_LIST(__SHIFT)
246 };
247 
248 static const struct dce_audio_mask audio_mask = {
249 		DCE120_AUD_COMMON_MASK_SH_LIST(_MASK)
250 };
251 
252 #define vpg_regs_init(id)\
253 	VPG_DCN3_REG_LIST_RI(id)
254 
255 static struct dcn30_vpg_registers vpg_regs[10];
256 
257 static const struct dcn30_vpg_shift vpg_shift = {
258 	DCN3_VPG_MASK_SH_LIST(__SHIFT)
259 };
260 
261 static const struct dcn30_vpg_mask vpg_mask = {
262 	DCN3_VPG_MASK_SH_LIST(_MASK)
263 };
264 
265 #define afmt_regs_init(id)\
266 	AFMT_DCN3_REG_LIST_RI(id)
267 
268 static struct dcn30_afmt_registers afmt_regs[6];
269 
270 static const struct dcn30_afmt_shift afmt_shift = {
271 	DCN3_AFMT_MASK_SH_LIST(__SHIFT)
272 };
273 
274 static const struct dcn30_afmt_mask afmt_mask = {
275 	DCN3_AFMT_MASK_SH_LIST(_MASK)
276 };
277 
278 #define apg_regs_init(id)\
279 	APG_DCN31_REG_LIST_RI(id)
280 
281 static struct dcn31_apg_registers apg_regs[4];
282 
283 static const struct dcn31_apg_shift apg_shift = {
284 	DCN31_APG_MASK_SH_LIST(__SHIFT)
285 };
286 
287 static const struct dcn31_apg_mask apg_mask = {
288 		DCN31_APG_MASK_SH_LIST(_MASK)
289 };
290 
291 #define stream_enc_regs_init(id)\
292 	SE_DCN32_REG_LIST_RI(id)
293 
294 static struct dcn10_stream_enc_registers stream_enc_regs[5];
295 
296 static const struct dcn10_stream_encoder_shift se_shift = {
297 		SE_COMMON_MASK_SH_LIST_DCN32(__SHIFT)
298 };
299 
300 static const struct dcn10_stream_encoder_mask se_mask = {
301 		SE_COMMON_MASK_SH_LIST_DCN32(_MASK)
302 };
303 
304 
305 #define aux_regs_init(id)\
306 	DCN2_AUX_REG_LIST_RI(id)
307 
308 static struct dcn10_link_enc_aux_registers link_enc_aux_regs[5];
309 
310 #define hpd_regs_init(id)\
311 	HPD_REG_LIST_RI(id)
312 
313 static struct dcn10_link_enc_hpd_registers link_enc_hpd_regs[5];
314 
315 #define link_regs_init(id, phyid)\
316 	( \
317 	LE_DCN31_REG_LIST_RI(id), \
318 	UNIPHY_DCN2_REG_LIST_RI(id, phyid)\
319 	)
320 	/*DPCS_DCN31_REG_LIST(id),*/ \
321 
322 static struct dcn10_link_enc_registers link_enc_regs[5];
323 
324 static const struct dcn10_link_enc_shift le_shift = {
325 	LINK_ENCODER_MASK_SH_LIST_DCN31(__SHIFT), \
326 //	DPCS_DCN31_MASK_SH_LIST(__SHIFT)
327 };
328 
329 static const struct dcn10_link_enc_mask le_mask = {
330 	LINK_ENCODER_MASK_SH_LIST_DCN31(_MASK), \
331 //	DPCS_DCN31_MASK_SH_LIST(_MASK)
332 };
333 
334 #define hpo_dp_stream_encoder_reg_init(id)\
335 	DCN3_1_HPO_DP_STREAM_ENC_REG_LIST_RI(id)
336 
337 static struct dcn31_hpo_dp_stream_encoder_registers hpo_dp_stream_enc_regs[4];
338 
339 static const struct dcn31_hpo_dp_stream_encoder_shift hpo_dp_se_shift = {
340 	DCN3_1_HPO_DP_STREAM_ENC_MASK_SH_LIST(__SHIFT)
341 };
342 
343 static const struct dcn31_hpo_dp_stream_encoder_mask hpo_dp_se_mask = {
344 	DCN3_1_HPO_DP_STREAM_ENC_MASK_SH_LIST(_MASK)
345 };
346 
347 
348 #define hpo_dp_link_encoder_reg_init(id)\
349 	DCN3_1_HPO_DP_LINK_ENC_REG_LIST_RI(id)
350 	/*DCN3_1_RDPCSTX_REG_LIST(0),*/
351 	/*DCN3_1_RDPCSTX_REG_LIST(1),*/
352 	/*DCN3_1_RDPCSTX_REG_LIST(2),*/
353 	/*DCN3_1_RDPCSTX_REG_LIST(3),*/
354 
355 static struct dcn31_hpo_dp_link_encoder_registers hpo_dp_link_enc_regs[2];
356 
357 static const struct dcn31_hpo_dp_link_encoder_shift hpo_dp_le_shift = {
358 	DCN3_2_HPO_DP_LINK_ENC_MASK_SH_LIST(__SHIFT)
359 };
360 
361 static const struct dcn31_hpo_dp_link_encoder_mask hpo_dp_le_mask = {
362 	DCN3_2_HPO_DP_LINK_ENC_MASK_SH_LIST(_MASK)
363 };
364 
365 #define dpp_regs_init(id)\
366 	DPP_REG_LIST_DCN30_COMMON_RI(id)
367 
368 static struct dcn3_dpp_registers dpp_regs[4];
369 
370 static const struct dcn3_dpp_shift tf_shift = {
371 		DPP_REG_LIST_SH_MASK_DCN30_COMMON(__SHIFT)
372 };
373 
374 static const struct dcn3_dpp_mask tf_mask = {
375 		DPP_REG_LIST_SH_MASK_DCN30_COMMON(_MASK)
376 };
377 
378 
379 #define opp_regs_init(id)\
380 	OPP_REG_LIST_DCN30_RI(id)
381 
382 static struct dcn20_opp_registers opp_regs[4];
383 
384 static const struct dcn20_opp_shift opp_shift = {
385 	OPP_MASK_SH_LIST_DCN20(__SHIFT)
386 };
387 
388 static const struct dcn20_opp_mask opp_mask = {
389 	OPP_MASK_SH_LIST_DCN20(_MASK)
390 };
391 
392 #define aux_engine_regs_init(id) \
393 	( \
394 	AUX_COMMON_REG_LIST0_RI(id), SR_ARR_INIT(AUXN_IMPCAL, id, 0), \
395 	SR_ARR_INIT(AUXP_IMPCAL, id, 0), \
396 	SR_ARR_INIT(AUX_RESET_MASK, id, DP_AUX0_AUX_CONTROL__AUX_RESET_MASK), \
397 	SR_ARR_INIT(AUX_RESET_MASK, id, DP_AUX0_AUX_CONTROL__AUX_RESET_MASK)\
398 	)
399 
400 static struct dce110_aux_registers aux_engine_regs[5];
401 
402 static const struct dce110_aux_registers_shift aux_shift = {
403 	DCN_AUX_MASK_SH_LIST(__SHIFT)
404 };
405 
406 static const struct dce110_aux_registers_mask aux_mask = {
407 	DCN_AUX_MASK_SH_LIST(_MASK)
408 };
409 
410 #define dwbc_regs_dcn3_init(id)\
411 	DWBC_COMMON_REG_LIST_DCN30_RI(id)
412 
413 static struct dcn30_dwbc_registers dwbc30_regs[1];
414 
415 static const struct dcn30_dwbc_shift dwbc30_shift = {
416 	DWBC_COMMON_MASK_SH_LIST_DCN30(__SHIFT)
417 };
418 
419 static const struct dcn30_dwbc_mask dwbc30_mask = {
420 	DWBC_COMMON_MASK_SH_LIST_DCN30(_MASK)
421 };
422 
423 #define mcif_wb_regs_dcn3_init(id)\
424 	MCIF_WB_COMMON_REG_LIST_DCN32_RI(id)
425 
426 static struct dcn30_mmhubbub_registers mcif_wb30_regs[1];
427 
428 static const struct dcn30_mmhubbub_shift mcif_wb30_shift = {
429 	MCIF_WB_COMMON_MASK_SH_LIST_DCN32(__SHIFT)
430 };
431 
432 static const struct dcn30_mmhubbub_mask mcif_wb30_mask = {
433 	MCIF_WB_COMMON_MASK_SH_LIST_DCN32(_MASK)
434 };
435 
436 #define dsc_regsDCN20_init(id)\
437 	DSC_REG_LIST_DCN20_RI(id)
438 
439 static struct dcn20_dsc_registers dsc_regs[4];
440 
441 static const struct dcn20_dsc_shift dsc_shift = {
442 	DSC_REG_LIST_SH_MASK_DCN20(__SHIFT)
443 };
444 
445 static const struct dcn20_dsc_mask dsc_mask = {
446 	DSC_REG_LIST_SH_MASK_DCN20(_MASK)
447 };
448 
449 static struct dcn30_mpc_registers mpc_regs;
450 #define dcn_mpc_regs_init()\
451 	MPC_REG_LIST_DCN3_2_RI(0),\
452 	MPC_REG_LIST_DCN3_2_RI(1),\
453 	MPC_REG_LIST_DCN3_2_RI(2),\
454 	MPC_REG_LIST_DCN3_2_RI(3),\
455 	MPC_OUT_MUX_REG_LIST_DCN3_0_RI(0),\
456 	MPC_OUT_MUX_REG_LIST_DCN3_0_RI(1),\
457 	MPC_OUT_MUX_REG_LIST_DCN3_0_RI(2),\
458 	MPC_OUT_MUX_REG_LIST_DCN3_0_RI(3),\
459 	MPC_DWB_MUX_REG_LIST_DCN3_0_RI(0)
460 
461 static const struct dcn30_mpc_shift mpc_shift = {
462 	MPC_COMMON_MASK_SH_LIST_DCN32(__SHIFT)
463 };
464 
465 static const struct dcn30_mpc_mask mpc_mask = {
466 	MPC_COMMON_MASK_SH_LIST_DCN32(_MASK)
467 };
468 
469 #define optc_regs_init(id)\
470 	OPTC_COMMON_REG_LIST_DCN3_2_RI(id)
471 
472 static struct dcn_optc_registers optc_regs[4];
473 
474 static const struct dcn_optc_shift optc_shift = {
475 	OPTC_COMMON_MASK_SH_LIST_DCN3_2(__SHIFT)
476 };
477 
478 static const struct dcn_optc_mask optc_mask = {
479 	OPTC_COMMON_MASK_SH_LIST_DCN3_2(_MASK)
480 };
481 
482 #define hubp_regs_init(id) \
483 	HUBP_REG_LIST_DCN32_RI(id)
484 
485 static struct dcn_hubp2_registers hubp_regs[4];
486 
487 static const struct dcn_hubp2_shift hubp_shift = {
488 		HUBP_MASK_SH_LIST_DCN32(__SHIFT)
489 };
490 
491 static const struct dcn_hubp2_mask hubp_mask = {
492 		HUBP_MASK_SH_LIST_DCN32(_MASK)
493 };
494 
495 static struct dcn_hubbub_registers hubbub_reg;
496 #define hubbub_reg_init()\
497 		HUBBUB_REG_LIST_DCN32_RI(0)
498 
499 static const struct dcn_hubbub_shift hubbub_shift = {
500 		HUBBUB_MASK_SH_LIST_DCN32(__SHIFT)
501 };
502 
503 static const struct dcn_hubbub_mask hubbub_mask = {
504 		HUBBUB_MASK_SH_LIST_DCN32(_MASK)
505 };
506 
507 static struct dccg_registers dccg_regs;
508 
509 #define dccg_regs_init()\
510 	DCCG_REG_LIST_DCN32_RI()
511 
512 static const struct dccg_shift dccg_shift = {
513 		DCCG_MASK_SH_LIST_DCN32(__SHIFT)
514 };
515 
516 static const struct dccg_mask dccg_mask = {
517 		DCCG_MASK_SH_LIST_DCN32(_MASK)
518 };
519 
520 
521 #define SRII2(reg_name_pre, reg_name_post, id)\
522 	.reg_name_pre ## _ ##  reg_name_post[id] = BASE(reg ## reg_name_pre \
523 			## id ## _ ## reg_name_post ## _BASE_IDX) + \
524 			reg ## reg_name_pre ## id ## _ ## reg_name_post
525 
526 
527 #define HWSEQ_DCN32_REG_LIST()\
528 	SR(DCHUBBUB_GLOBAL_TIMER_CNTL), \
529 	SR(DIO_MEM_PWR_CTRL), \
530 	SR(ODM_MEM_PWR_CTRL3), \
531 	SR(MMHUBBUB_MEM_PWR_CNTL), \
532 	SR(DCCG_GATE_DISABLE_CNTL), \
533 	SR(DCCG_GATE_DISABLE_CNTL2), \
534 	SR(DCFCLK_CNTL),\
535 	SR(DC_MEM_GLOBAL_PWR_REQ_CNTL), \
536 	SRII(PIXEL_RATE_CNTL, OTG, 0), \
537 	SRII(PIXEL_RATE_CNTL, OTG, 1),\
538 	SRII(PIXEL_RATE_CNTL, OTG, 2),\
539 	SRII(PIXEL_RATE_CNTL, OTG, 3),\
540 	SRII(PHYPLL_PIXEL_RATE_CNTL, OTG, 0),\
541 	SRII(PHYPLL_PIXEL_RATE_CNTL, OTG, 1),\
542 	SRII(PHYPLL_PIXEL_RATE_CNTL, OTG, 2),\
543 	SRII(PHYPLL_PIXEL_RATE_CNTL, OTG, 3),\
544 	SR(MICROSECOND_TIME_BASE_DIV), \
545 	SR(MILLISECOND_TIME_BASE_DIV), \
546 	SR(DISPCLK_FREQ_CHANGE_CNTL), \
547 	SR(RBBMIF_TIMEOUT_DIS), \
548 	SR(RBBMIF_TIMEOUT_DIS_2), \
549 	SR(DCHUBBUB_CRC_CTRL), \
550 	SR(DPP_TOP0_DPP_CRC_CTRL), \
551 	SR(DPP_TOP0_DPP_CRC_VAL_B_A), \
552 	SR(DPP_TOP0_DPP_CRC_VAL_R_G), \
553 	SR(MPC_CRC_CTRL), \
554 	SR(MPC_CRC_RESULT_GB), \
555 	SR(MPC_CRC_RESULT_C), \
556 	SR(MPC_CRC_RESULT_AR), \
557 	SR(DOMAIN0_PG_CONFIG), \
558 	SR(DOMAIN1_PG_CONFIG), \
559 	SR(DOMAIN2_PG_CONFIG), \
560 	SR(DOMAIN3_PG_CONFIG), \
561 	SR(DOMAIN16_PG_CONFIG), \
562 	SR(DOMAIN17_PG_CONFIG), \
563 	SR(DOMAIN18_PG_CONFIG), \
564 	SR(DOMAIN19_PG_CONFIG), \
565 	SR(DOMAIN0_PG_STATUS), \
566 	SR(DOMAIN1_PG_STATUS), \
567 	SR(DOMAIN2_PG_STATUS), \
568 	SR(DOMAIN3_PG_STATUS), \
569 	SR(DOMAIN16_PG_STATUS), \
570 	SR(DOMAIN17_PG_STATUS), \
571 	SR(DOMAIN18_PG_STATUS), \
572 	SR(DOMAIN19_PG_STATUS), \
573 	SR(D1VGA_CONTROL), \
574 	SR(D2VGA_CONTROL), \
575 	SR(D3VGA_CONTROL), \
576 	SR(D4VGA_CONTROL), \
577 	SR(D5VGA_CONTROL), \
578 	SR(D6VGA_CONTROL), \
579 	SR(DC_IP_REQUEST_CNTL), \
580 	SR(AZALIA_AUDIO_DTO), \
581 	SR(AZALIA_CONTROLLER_CLOCK_GATING)
582 
583 static struct dce_hwseq_registers hwseq_reg;
584 
585 #define hwseq_reg_init()\
586 	HWSEQ_DCN32_REG_LIST()
587 
588 #define HWSEQ_DCN32_MASK_SH_LIST(mask_sh)\
589 	HWSEQ_DCN_MASK_SH_LIST(mask_sh), \
590 	HWS_SF(, DCHUBBUB_GLOBAL_TIMER_CNTL, DCHUBBUB_GLOBAL_TIMER_REFDIV, mask_sh), \
591 	HWS_SF(, DOMAIN0_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
592 	HWS_SF(, DOMAIN0_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
593 	HWS_SF(, DOMAIN1_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
594 	HWS_SF(, DOMAIN1_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
595 	HWS_SF(, DOMAIN2_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
596 	HWS_SF(, DOMAIN2_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
597 	HWS_SF(, DOMAIN3_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
598 	HWS_SF(, DOMAIN3_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
599 	HWS_SF(, DOMAIN16_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
600 	HWS_SF(, DOMAIN16_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
601 	HWS_SF(, DOMAIN17_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
602 	HWS_SF(, DOMAIN17_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
603 	HWS_SF(, DOMAIN18_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
604 	HWS_SF(, DOMAIN18_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
605 	HWS_SF(, DOMAIN19_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
606 	HWS_SF(, DOMAIN19_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
607 	HWS_SF(, DOMAIN0_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
608 	HWS_SF(, DOMAIN1_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
609 	HWS_SF(, DOMAIN2_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
610 	HWS_SF(, DOMAIN3_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
611 	HWS_SF(, DOMAIN16_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
612 	HWS_SF(, DOMAIN17_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
613 	HWS_SF(, DOMAIN18_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
614 	HWS_SF(, DOMAIN19_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
615 	HWS_SF(, DC_IP_REQUEST_CNTL, IP_REQUEST_EN, mask_sh), \
616 	HWS_SF(, AZALIA_AUDIO_DTO, AZALIA_AUDIO_DTO_MODULE, mask_sh), \
617 	HWS_SF(, HPO_TOP_CLOCK_CONTROL, HPO_HDMISTREAMCLK_G_GATE_DIS, mask_sh), \
618 	HWS_SF(, ODM_MEM_PWR_CTRL3, ODM_MEM_UNASSIGNED_PWR_MODE, mask_sh), \
619 	HWS_SF(, ODM_MEM_PWR_CTRL3, ODM_MEM_VBLANK_PWR_MODE, mask_sh), \
620 	HWS_SF(, MMHUBBUB_MEM_PWR_CNTL, VGA_MEM_PWR_FORCE, mask_sh)
621 
622 static const struct dce_hwseq_shift hwseq_shift = {
623 		HWSEQ_DCN32_MASK_SH_LIST(__SHIFT)
624 };
625 
626 static const struct dce_hwseq_mask hwseq_mask = {
627 		HWSEQ_DCN32_MASK_SH_LIST(_MASK)
628 };
629 #define vmid_regs_init(id)\
630 		DCN20_VMID_REG_LIST_RI(id)
631 
632 static struct dcn_vmid_registers vmid_regs[16];
633 
634 static const struct dcn20_vmid_shift vmid_shifts = {
635 		DCN20_VMID_MASK_SH_LIST(__SHIFT)
636 };
637 
638 static const struct dcn20_vmid_mask vmid_masks = {
639 		DCN20_VMID_MASK_SH_LIST(_MASK)
640 };
641 
642 static const struct resource_caps res_cap_dcn321 = {
643 	.num_timing_generator = 4,
644 	.num_opp = 4,
645 	.num_video_plane = 4,
646 	.num_audio = 5,
647 	.num_stream_encoder = 5,
648 	.num_hpo_dp_stream_encoder = 4,
649 	.num_hpo_dp_link_encoder = 2,
650 	.num_pll = 5,
651 	.num_dwb = 1,
652 	.num_ddc = 5,
653 	.num_vmid = 16,
654 	.num_mpc_3dlut = 4,
655 	.num_dsc = 4,
656 };
657 
658 static const struct dc_plane_cap plane_cap = {
659 	.type = DC_PLANE_TYPE_DCN_UNIVERSAL,
660 	.per_pixel_alpha = true,
661 
662 	.pixel_format_support = {
663 			.argb8888 = true,
664 			.nv12 = true,
665 			.fp16 = true,
666 			.p010 = true,
667 			.ayuv = false,
668 	},
669 
670 	.max_upscale_factor = {
671 			.argb8888 = 16000,
672 			.nv12 = 16000,
673 			.fp16 = 16000
674 	},
675 
676 	// 6:1 downscaling ratio: 1000/6 = 166.666
677 	.max_downscale_factor = {
678 			.argb8888 = 167,
679 			.nv12 = 167,
680 			.fp16 = 167
681 	},
682 	64,
683 	64
684 };
685 
686 static const struct dc_debug_options debug_defaults_drv = {
687 	.disable_dmcu = true,
688 	.force_abm_enable = false,
689 	.clock_trace = true,
690 	.disable_pplib_clock_request = false,
691 	.pipe_split_policy = MPC_SPLIT_AVOID,
692 	.force_single_disp_pipe_split = false,
693 	.disable_dcc = DCC_ENABLE,
694 	.vsr_support = true,
695 	.performance_trace = false,
696 	.max_downscale_src_width = 7680,/*upto 8K*/
697 	.disable_pplib_wm_range = false,
698 	.scl_reset_length10 = true,
699 	.sanity_checks = false,
700 	.underflow_assert_delay_us = 0xFFFFFFFF,
701 	.dwb_fi_phase = -1, // -1 = disable,
702 	.dmub_command_table = true,
703 	.enable_mem_low_power = {
704 		.bits = {
705 			.vga = false,
706 			.i2c = false,
707 			.dmcu = false, // This is previously known to cause hang on S3 cycles if enabled
708 			.dscl = false,
709 			.cm = false,
710 			.mpc = false,
711 			.optc = true,
712 		}
713 	},
714 	.use_max_lb = true,
715 	.force_disable_subvp = false,
716 	.exit_idle_opt_for_cursor_updates = true,
717 	.enable_single_display_2to1_odm_policy = true,
718 
719 	/*must match enable_single_display_2to1_odm_policy to support dynamic ODM transitions*/
720 	.enable_double_buffered_dsc_pg_support = true,
721 	.enable_dp_dig_pixel_rate_div_policy = 1,
722 	.allow_sw_cursor_fallback = false, // Linux can't do SW cursor "fallback"
723 	.alloc_extra_way_for_cursor = true,
724 	.min_prefetch_in_strobe_ns = 60000, // 60us
725 	.disable_unbounded_requesting = false,
726 	.override_dispclk_programming = true,
727 	.disable_fpo_optimizations = false,
728 	.fpo_vactive_margin_us = 2000, // 2000us
729 	.disable_fpo_vactive = false,
730 	.disable_boot_optimizations = false,
731 	.disable_subvp_high_refresh = false,
732 	.fpo_vactive_min_active_margin_us = 200,
733 	.fpo_vactive_max_blank_us = 1000,
734 	.enable_legacy_fast_update = false,
735 	.disable_dc_mode_overwrite = true,
736 	.using_dml2 = false,
737 };
738 
dcn321_aux_engine_create(struct dc_context * ctx,uint32_t inst)739 static struct dce_aux *dcn321_aux_engine_create(
740 	struct dc_context *ctx,
741 	uint32_t inst)
742 {
743 	struct aux_engine_dce110 *aux_engine =
744 		kzalloc(sizeof(struct aux_engine_dce110), GFP_KERNEL);
745 
746 	if (!aux_engine)
747 		return NULL;
748 
749 #undef REG_STRUCT
750 #define REG_STRUCT aux_engine_regs
751 	aux_engine_regs_init(0),
752 	aux_engine_regs_init(1),
753 	aux_engine_regs_init(2),
754 	aux_engine_regs_init(3),
755 	aux_engine_regs_init(4);
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_DCN30(__SHIFT)
773 };
774 
775 static const struct dce_i2c_mask i2c_masks = {
776 		I2C_COMMON_MASK_SH_LIST_DCN30(_MASK)
777 };
778 
dcn321_i2c_hw_create(struct dc_context * ctx,uint32_t inst)779 static struct dce_i2c_hw *dcn321_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 	i2c_inst_regs_init(5);
796 
797 	dcn2_i2c_hw_construct(dce_i2c_hw, ctx, inst,
798 				    &i2c_hw_regs[inst], &i2c_shifts, &i2c_masks);
799 
800 	return dce_i2c_hw;
801 }
802 
dcn321_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)803 static struct clock_source *dcn321_clock_source_create(
804 		struct dc_context *ctx,
805 		struct dc_bios *bios,
806 		enum clock_source_id id,
807 		const struct dce110_clk_src_regs *regs,
808 		bool dp_clk_src)
809 {
810 	struct dce110_clk_src *clk_src =
811 		kzalloc(sizeof(struct dce110_clk_src), GFP_KERNEL);
812 
813 	if (!clk_src)
814 		return NULL;
815 
816 	if (dcn31_clk_src_construct(clk_src, ctx, bios, id,
817 			regs, &cs_shift, &cs_mask)) {
818 		clk_src->base.dp_clk_src = dp_clk_src;
819 		return &clk_src->base;
820 	}
821 
822 	kfree(clk_src);
823 	BREAK_TO_DEBUGGER();
824 	return NULL;
825 }
826 
dcn321_hubbub_create(struct dc_context * ctx)827 static struct hubbub *dcn321_hubbub_create(struct dc_context *ctx)
828 {
829 	int i;
830 
831 	struct dcn20_hubbub *hubbub2 = kzalloc(sizeof(struct dcn20_hubbub),
832 					  GFP_KERNEL);
833 
834 	if (!hubbub2)
835 		return NULL;
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 	hubbub32_construct(hubbub2, ctx,
861 			&hubbub_reg,
862 			&hubbub_shift,
863 			&hubbub_mask,
864 			ctx->dc->dml.ip.det_buffer_size_kbytes,
865 			ctx->dc->dml.ip.pixel_chunk_size_kbytes,
866 			ctx->dc->dml.ip.config_return_buffer_size_in_kbytes);
867 
868 
869 	for (i = 0; i < res_cap_dcn321.num_vmid; i++) {
870 		struct dcn20_vmid *vmid = &hubbub2->vmid[i];
871 
872 		vmid->ctx = ctx;
873 
874 		vmid->regs = &vmid_regs[i];
875 		vmid->shifts = &vmid_shifts;
876 		vmid->masks = &vmid_masks;
877 	}
878 
879 	return &hubbub2->base;
880 }
881 
dcn321_hubp_create(struct dc_context * ctx,uint32_t inst)882 static struct hubp *dcn321_hubp_create(
883 	struct dc_context *ctx,
884 	uint32_t inst)
885 {
886 	struct dcn20_hubp *hubp2 =
887 		kzalloc(sizeof(struct dcn20_hubp), GFP_KERNEL);
888 
889 	if (!hubp2)
890 		return NULL;
891 
892 #undef REG_STRUCT
893 #define REG_STRUCT hubp_regs
894 	hubp_regs_init(0),
895 	hubp_regs_init(1),
896 	hubp_regs_init(2),
897 	hubp_regs_init(3);
898 
899 	if (hubp32_construct(hubp2, ctx, inst,
900 			&hubp_regs[inst], &hubp_shift, &hubp_mask))
901 		return &hubp2->base;
902 
903 	BREAK_TO_DEBUGGER();
904 	kfree(hubp2);
905 	return NULL;
906 }
907 
dcn321_dpp_destroy(struct dpp ** dpp)908 static void dcn321_dpp_destroy(struct dpp **dpp)
909 {
910 	kfree(TO_DCN30_DPP(*dpp));
911 	*dpp = NULL;
912 }
913 
dcn321_dpp_create(struct dc_context * ctx,uint32_t inst)914 static struct dpp *dcn321_dpp_create(
915 	struct dc_context *ctx,
916 	uint32_t inst)
917 {
918 	struct dcn3_dpp *dpp3 =
919 		kzalloc(sizeof(struct dcn3_dpp), GFP_KERNEL);
920 
921 	if (!dpp3)
922 		return NULL;
923 
924 #undef REG_STRUCT
925 #define REG_STRUCT dpp_regs
926 	dpp_regs_init(0),
927 	dpp_regs_init(1),
928 	dpp_regs_init(2),
929 	dpp_regs_init(3);
930 
931 	if (dpp32_construct(dpp3, ctx, inst,
932 			&dpp_regs[inst], &tf_shift, &tf_mask))
933 		return &dpp3->base;
934 
935 	BREAK_TO_DEBUGGER();
936 	kfree(dpp3);
937 	return NULL;
938 }
939 
dcn321_mpc_create(struct dc_context * ctx,int num_mpcc,int num_rmu)940 static struct mpc *dcn321_mpc_create(
941 		struct dc_context *ctx,
942 		int num_mpcc,
943 		int num_rmu)
944 {
945 	struct dcn30_mpc *mpc30 = kzalloc(sizeof(struct dcn30_mpc),
946 					  GFP_KERNEL);
947 
948 	if (!mpc30)
949 		return NULL;
950 
951 #undef REG_STRUCT
952 #define REG_STRUCT mpc_regs
953 	dcn_mpc_regs_init();
954 
955 	dcn32_mpc_construct(mpc30, ctx,
956 			&mpc_regs,
957 			&mpc_shift,
958 			&mpc_mask,
959 			num_mpcc,
960 			num_rmu);
961 
962 	return &mpc30->base;
963 }
964 
dcn321_opp_create(struct dc_context * ctx,uint32_t inst)965 static struct output_pixel_processor *dcn321_opp_create(
966 	struct dc_context *ctx, uint32_t inst)
967 {
968 	struct dcn20_opp *opp2 =
969 		kzalloc(sizeof(struct dcn20_opp), GFP_KERNEL);
970 
971 	if (!opp2) {
972 		BREAK_TO_DEBUGGER();
973 		return NULL;
974 	}
975 
976 #undef REG_STRUCT
977 #define REG_STRUCT opp_regs
978 	opp_regs_init(0),
979 	opp_regs_init(1),
980 	opp_regs_init(2),
981 	opp_regs_init(3);
982 
983 	dcn20_opp_construct(opp2, ctx, inst,
984 			&opp_regs[inst], &opp_shift, &opp_mask);
985 	return &opp2->base;
986 }
987 
988 
dcn321_timing_generator_create(struct dc_context * ctx,uint32_t instance)989 static struct timing_generator *dcn321_timing_generator_create(
990 		struct dc_context *ctx,
991 		uint32_t instance)
992 {
993 	struct optc *tgn10 =
994 		kzalloc(sizeof(struct optc), GFP_KERNEL);
995 
996 	if (!tgn10)
997 		return NULL;
998 
999 #undef REG_STRUCT
1000 #define REG_STRUCT optc_regs
1001 	optc_regs_init(0),
1002 	optc_regs_init(1),
1003 	optc_regs_init(2),
1004 	optc_regs_init(3);
1005 
1006 	tgn10->base.inst = instance;
1007 	tgn10->base.ctx = ctx;
1008 
1009 	tgn10->tg_regs = &optc_regs[instance];
1010 	tgn10->tg_shift = &optc_shift;
1011 	tgn10->tg_mask = &optc_mask;
1012 
1013 	dcn32_timing_generator_init(tgn10);
1014 
1015 	return &tgn10->base;
1016 }
1017 
1018 static const struct encoder_feature_support link_enc_feature = {
1019 		.max_hdmi_deep_color = COLOR_DEPTH_121212,
1020 		.max_hdmi_pixel_clock = 600000,
1021 		.hdmi_ycbcr420_supported = true,
1022 		.dp_ycbcr420_supported = true,
1023 		.fec_supported = true,
1024 		.flags.bits.IS_HBR2_CAPABLE = true,
1025 		.flags.bits.IS_HBR3_CAPABLE = true,
1026 		.flags.bits.IS_TPS3_CAPABLE = true,
1027 		.flags.bits.IS_TPS4_CAPABLE = true
1028 };
1029 
dcn321_link_encoder_create(struct dc_context * ctx,const struct encoder_init_data * enc_init_data)1030 static struct link_encoder *dcn321_link_encoder_create(
1031 	struct dc_context *ctx,
1032 	const struct encoder_init_data *enc_init_data)
1033 {
1034 	struct dcn20_link_encoder *enc20 =
1035 		kzalloc(sizeof(struct dcn20_link_encoder), GFP_KERNEL);
1036 
1037 	if (!enc20 || enc_init_data->hpd_source >= ARRAY_SIZE(link_enc_hpd_regs))
1038 		return NULL;
1039 
1040 #undef REG_STRUCT
1041 #define REG_STRUCT link_enc_aux_regs
1042 	aux_regs_init(0),
1043 	aux_regs_init(1),
1044 	aux_regs_init(2),
1045 	aux_regs_init(3),
1046 	aux_regs_init(4);
1047 
1048 #undef REG_STRUCT
1049 #define REG_STRUCT link_enc_hpd_regs
1050 	hpd_regs_init(0),
1051 	hpd_regs_init(1),
1052 	hpd_regs_init(2),
1053 	hpd_regs_init(3),
1054 	hpd_regs_init(4);
1055 
1056 #undef REG_STRUCT
1057 #define REG_STRUCT link_enc_regs
1058 	link_regs_init(0, A),
1059 	link_regs_init(1, B),
1060 	link_regs_init(2, C),
1061 	link_regs_init(3, D),
1062 	link_regs_init(4, E);
1063 
1064 	dcn321_link_encoder_construct(enc20,
1065 			enc_init_data,
1066 			&link_enc_feature,
1067 			&link_enc_regs[enc_init_data->transmitter],
1068 			&link_enc_aux_regs[enc_init_data->channel - 1],
1069 			&link_enc_hpd_regs[enc_init_data->hpd_source],
1070 			&le_shift,
1071 			&le_mask);
1072 
1073 	return &enc20->enc10.base;
1074 }
1075 
read_dce_straps(struct dc_context * ctx,struct resource_straps * straps)1076 static void read_dce_straps(
1077 	struct dc_context *ctx,
1078 	struct resource_straps *straps)
1079 {
1080 	generic_reg_get(ctx, ctx->dcn_reg_offsets[regDC_PINSTRAPS_BASE_IDX] + regDC_PINSTRAPS,
1081 		FN(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO), &straps->dc_pinstraps_audio);
1082 
1083 }
1084 
dcn321_create_audio(struct dc_context * ctx,unsigned int inst)1085 static struct audio *dcn321_create_audio(
1086 		struct dc_context *ctx, unsigned int inst)
1087 {
1088 
1089 #undef REG_STRUCT
1090 #define REG_STRUCT audio_regs
1091 	audio_regs_init(0),
1092 	audio_regs_init(1),
1093 	audio_regs_init(2),
1094 	audio_regs_init(3),
1095 	audio_regs_init(4);
1096 
1097 	return dce_audio_create(ctx, inst,
1098 			&audio_regs[inst], &audio_shift, &audio_mask);
1099 }
1100 
dcn321_vpg_create(struct dc_context * ctx,uint32_t inst)1101 static struct vpg *dcn321_vpg_create(
1102 	struct dc_context *ctx,
1103 	uint32_t inst)
1104 {
1105 	struct dcn30_vpg *vpg3 = kzalloc(sizeof(struct dcn30_vpg), GFP_KERNEL);
1106 
1107 	if (!vpg3)
1108 		return NULL;
1109 
1110 #undef REG_STRUCT
1111 #define REG_STRUCT vpg_regs
1112 	vpg_regs_init(0),
1113 	vpg_regs_init(1),
1114 	vpg_regs_init(2),
1115 	vpg_regs_init(3),
1116 	vpg_regs_init(4),
1117 	vpg_regs_init(5),
1118 	vpg_regs_init(6),
1119 	vpg_regs_init(7),
1120 	vpg_regs_init(8),
1121 	vpg_regs_init(9);
1122 
1123 	vpg3_construct(vpg3, ctx, inst,
1124 			&vpg_regs[inst],
1125 			&vpg_shift,
1126 			&vpg_mask);
1127 
1128 	return &vpg3->base;
1129 }
1130 
dcn321_afmt_create(struct dc_context * ctx,uint32_t inst)1131 static struct afmt *dcn321_afmt_create(
1132 	struct dc_context *ctx,
1133 	uint32_t inst)
1134 {
1135 	struct dcn30_afmt *afmt3 = kzalloc(sizeof(struct dcn30_afmt), GFP_KERNEL);
1136 
1137 	if (!afmt3)
1138 		return NULL;
1139 
1140 #undef REG_STRUCT
1141 #define REG_STRUCT afmt_regs
1142 	afmt_regs_init(0),
1143 	afmt_regs_init(1),
1144 	afmt_regs_init(2),
1145 	afmt_regs_init(3),
1146 	afmt_regs_init(4),
1147 	afmt_regs_init(5);
1148 
1149 	afmt3_construct(afmt3, ctx, inst,
1150 			&afmt_regs[inst],
1151 			&afmt_shift,
1152 			&afmt_mask);
1153 
1154 	return &afmt3->base;
1155 }
1156 
dcn321_apg_create(struct dc_context * ctx,uint32_t inst)1157 static struct apg *dcn321_apg_create(
1158 	struct dc_context *ctx,
1159 	uint32_t inst)
1160 {
1161 	struct dcn31_apg *apg31 = kzalloc(sizeof(struct dcn31_apg), GFP_KERNEL);
1162 
1163 	if (!apg31)
1164 		return NULL;
1165 
1166 #undef REG_STRUCT
1167 #define REG_STRUCT apg_regs
1168 	apg_regs_init(0),
1169 	apg_regs_init(1),
1170 	apg_regs_init(2),
1171 	apg_regs_init(3);
1172 
1173 	apg31_construct(apg31, ctx, inst,
1174 			&apg_regs[inst],
1175 			&apg_shift,
1176 			&apg_mask);
1177 
1178 	return &apg31->base;
1179 }
1180 
dcn321_stream_encoder_create(enum engine_id eng_id,struct dc_context * ctx)1181 static struct stream_encoder *dcn321_stream_encoder_create(
1182 	enum engine_id eng_id,
1183 	struct dc_context *ctx)
1184 {
1185 	struct dcn10_stream_encoder *enc1;
1186 	struct vpg *vpg;
1187 	struct afmt *afmt;
1188 	int vpg_inst;
1189 	int afmt_inst;
1190 
1191 	/* Mapping of VPG, AFMT, DME register blocks to DIO block instance */
1192 	if (eng_id <= ENGINE_ID_DIGF) {
1193 		vpg_inst = eng_id;
1194 		afmt_inst = eng_id;
1195 	} else
1196 		return NULL;
1197 
1198 	enc1 = kzalloc(sizeof(struct dcn10_stream_encoder), GFP_KERNEL);
1199 	vpg = dcn321_vpg_create(ctx, vpg_inst);
1200 	afmt = dcn321_afmt_create(ctx, afmt_inst);
1201 
1202 	if (!enc1 || !vpg || !afmt) {
1203 		kfree(enc1);
1204 		kfree(vpg);
1205 		kfree(afmt);
1206 		return NULL;
1207 	}
1208 
1209 #undef REG_STRUCT
1210 #define REG_STRUCT stream_enc_regs
1211 	stream_enc_regs_init(0),
1212 	stream_enc_regs_init(1),
1213 	stream_enc_regs_init(2),
1214 	stream_enc_regs_init(3),
1215 	stream_enc_regs_init(4);
1216 
1217 	dcn32_dio_stream_encoder_construct(enc1, ctx, ctx->dc_bios,
1218 					eng_id, vpg, afmt,
1219 					&stream_enc_regs[eng_id],
1220 					&se_shift, &se_mask);
1221 
1222 	return &enc1->base;
1223 }
1224 
dcn321_hpo_dp_stream_encoder_create(enum engine_id eng_id,struct dc_context * ctx)1225 static struct hpo_dp_stream_encoder *dcn321_hpo_dp_stream_encoder_create(
1226 	enum engine_id eng_id,
1227 	struct dc_context *ctx)
1228 {
1229 	struct dcn31_hpo_dp_stream_encoder *hpo_dp_enc31;
1230 	struct vpg *vpg;
1231 	struct apg *apg;
1232 	uint32_t hpo_dp_inst;
1233 	uint32_t vpg_inst;
1234 	uint32_t apg_inst;
1235 
1236 	ASSERT((eng_id >= ENGINE_ID_HPO_DP_0) && (eng_id <= ENGINE_ID_HPO_DP_3));
1237 	hpo_dp_inst = eng_id - ENGINE_ID_HPO_DP_0;
1238 
1239 	/* Mapping of VPG register blocks to HPO DP block instance:
1240 	 * VPG[6] -> HPO_DP[0]
1241 	 * VPG[7] -> HPO_DP[1]
1242 	 * VPG[8] -> HPO_DP[2]
1243 	 * VPG[9] -> HPO_DP[3]
1244 	 */
1245 	vpg_inst = hpo_dp_inst + 6;
1246 
1247 	/* Mapping of APG register blocks to HPO DP block instance:
1248 	 * APG[0] -> HPO_DP[0]
1249 	 * APG[1] -> HPO_DP[1]
1250 	 * APG[2] -> HPO_DP[2]
1251 	 * APG[3] -> HPO_DP[3]
1252 	 */
1253 	apg_inst = hpo_dp_inst;
1254 
1255 	/* allocate HPO stream encoder and create VPG sub-block */
1256 	hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_stream_encoder), GFP_KERNEL);
1257 	vpg = dcn321_vpg_create(ctx, vpg_inst);
1258 	apg = dcn321_apg_create(ctx, apg_inst);
1259 
1260 	if (!hpo_dp_enc31 || !vpg || !apg) {
1261 		kfree(hpo_dp_enc31);
1262 		kfree(vpg);
1263 		kfree(apg);
1264 		return NULL;
1265 	}
1266 
1267 #undef REG_STRUCT
1268 #define REG_STRUCT hpo_dp_stream_enc_regs
1269 	hpo_dp_stream_encoder_reg_init(0),
1270 	hpo_dp_stream_encoder_reg_init(1),
1271 	hpo_dp_stream_encoder_reg_init(2),
1272 	hpo_dp_stream_encoder_reg_init(3);
1273 
1274 	dcn31_hpo_dp_stream_encoder_construct(hpo_dp_enc31, ctx, ctx->dc_bios,
1275 					hpo_dp_inst, eng_id, vpg, apg,
1276 					&hpo_dp_stream_enc_regs[hpo_dp_inst],
1277 					&hpo_dp_se_shift, &hpo_dp_se_mask);
1278 
1279 	return &hpo_dp_enc31->base;
1280 }
1281 
dcn321_hpo_dp_link_encoder_create(uint8_t inst,struct dc_context * ctx)1282 static struct hpo_dp_link_encoder *dcn321_hpo_dp_link_encoder_create(
1283 	uint8_t inst,
1284 	struct dc_context *ctx)
1285 {
1286 	struct dcn31_hpo_dp_link_encoder *hpo_dp_enc31;
1287 
1288 	/* allocate HPO link encoder */
1289 	hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_link_encoder), GFP_KERNEL);
1290 	if (!hpo_dp_enc31)
1291 		return NULL; /* out of memory */
1292 
1293 #undef REG_STRUCT
1294 #define REG_STRUCT hpo_dp_link_enc_regs
1295 	hpo_dp_link_encoder_reg_init(0),
1296 	hpo_dp_link_encoder_reg_init(1);
1297 
1298 	hpo_dp_link_encoder32_construct(hpo_dp_enc31, ctx, inst,
1299 					&hpo_dp_link_enc_regs[inst],
1300 					&hpo_dp_le_shift, &hpo_dp_le_mask);
1301 
1302 	return &hpo_dp_enc31->base;
1303 }
1304 
dcn321_hwseq_create(struct dc_context * ctx)1305 static struct dce_hwseq *dcn321_hwseq_create(
1306 	struct dc_context *ctx)
1307 {
1308 	struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL);
1309 
1310 #undef REG_STRUCT
1311 #define REG_STRUCT hwseq_reg
1312 	hwseq_reg_init();
1313 
1314 	if (hws) {
1315 		hws->ctx = ctx;
1316 		hws->regs = &hwseq_reg;
1317 		hws->shifts = &hwseq_shift;
1318 		hws->masks = &hwseq_mask;
1319 	}
1320 	return hws;
1321 }
1322 static const struct resource_create_funcs res_create_funcs = {
1323 	.read_dce_straps = read_dce_straps,
1324 	.create_audio = dcn321_create_audio,
1325 	.create_stream_encoder = dcn321_stream_encoder_create,
1326 	.create_hpo_dp_stream_encoder = dcn321_hpo_dp_stream_encoder_create,
1327 	.create_hpo_dp_link_encoder = dcn321_hpo_dp_link_encoder_create,
1328 	.create_hwseq = dcn321_hwseq_create,
1329 };
1330 
dcn321_resource_destruct(struct dcn321_resource_pool * pool)1331 static void dcn321_resource_destruct(struct dcn321_resource_pool *pool)
1332 {
1333 	unsigned int i;
1334 
1335 	for (i = 0; i < pool->base.stream_enc_count; i++) {
1336 		if (pool->base.stream_enc[i] != NULL) {
1337 			if (pool->base.stream_enc[i]->vpg != NULL) {
1338 				kfree(DCN30_VPG_FROM_VPG(pool->base.stream_enc[i]->vpg));
1339 				pool->base.stream_enc[i]->vpg = NULL;
1340 			}
1341 			if (pool->base.stream_enc[i]->afmt != NULL) {
1342 				kfree(DCN30_AFMT_FROM_AFMT(pool->base.stream_enc[i]->afmt));
1343 				pool->base.stream_enc[i]->afmt = NULL;
1344 			}
1345 			kfree(DCN10STRENC_FROM_STRENC(pool->base.stream_enc[i]));
1346 			pool->base.stream_enc[i] = NULL;
1347 		}
1348 	}
1349 
1350 	for (i = 0; i < pool->base.hpo_dp_stream_enc_count; i++) {
1351 		if (pool->base.hpo_dp_stream_enc[i] != NULL) {
1352 			if (pool->base.hpo_dp_stream_enc[i]->vpg != NULL) {
1353 				kfree(DCN30_VPG_FROM_VPG(pool->base.hpo_dp_stream_enc[i]->vpg));
1354 				pool->base.hpo_dp_stream_enc[i]->vpg = NULL;
1355 			}
1356 			if (pool->base.hpo_dp_stream_enc[i]->apg != NULL) {
1357 				kfree(DCN31_APG_FROM_APG(pool->base.hpo_dp_stream_enc[i]->apg));
1358 				pool->base.hpo_dp_stream_enc[i]->apg = NULL;
1359 			}
1360 			kfree(DCN3_1_HPO_DP_STREAM_ENC_FROM_HPO_STREAM_ENC(pool->base.hpo_dp_stream_enc[i]));
1361 			pool->base.hpo_dp_stream_enc[i] = NULL;
1362 		}
1363 	}
1364 
1365 	for (i = 0; i < pool->base.hpo_dp_link_enc_count; i++) {
1366 		if (pool->base.hpo_dp_link_enc[i] != NULL) {
1367 			kfree(DCN3_1_HPO_DP_LINK_ENC_FROM_HPO_LINK_ENC(pool->base.hpo_dp_link_enc[i]));
1368 			pool->base.hpo_dp_link_enc[i] = NULL;
1369 		}
1370 	}
1371 
1372 	for (i = 0; i < pool->base.res_cap->num_dsc; i++) {
1373 		if (pool->base.dscs[i] != NULL)
1374 			dcn20_dsc_destroy(&pool->base.dscs[i]);
1375 	}
1376 
1377 	if (pool->base.mpc != NULL) {
1378 		kfree(TO_DCN20_MPC(pool->base.mpc));
1379 		pool->base.mpc = NULL;
1380 	}
1381 	if (pool->base.hubbub != NULL) {
1382 		kfree(TO_DCN20_HUBBUB(pool->base.hubbub));
1383 		pool->base.hubbub = NULL;
1384 	}
1385 	for (i = 0; i < pool->base.pipe_count; i++) {
1386 		if (pool->base.dpps[i] != NULL)
1387 			dcn321_dpp_destroy(&pool->base.dpps[i]);
1388 
1389 		if (pool->base.ipps[i] != NULL)
1390 			pool->base.ipps[i]->funcs->ipp_destroy(&pool->base.ipps[i]);
1391 
1392 		if (pool->base.hubps[i] != NULL) {
1393 			kfree(TO_DCN20_HUBP(pool->base.hubps[i]));
1394 			pool->base.hubps[i] = NULL;
1395 		}
1396 
1397 		if (pool->base.irqs != NULL)
1398 			dal_irq_service_destroy(&pool->base.irqs);
1399 	}
1400 
1401 	for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
1402 		if (pool->base.engines[i] != NULL)
1403 			dce110_engine_destroy(&pool->base.engines[i]);
1404 		if (pool->base.hw_i2cs[i] != NULL) {
1405 			kfree(pool->base.hw_i2cs[i]);
1406 			pool->base.hw_i2cs[i] = NULL;
1407 		}
1408 		if (pool->base.sw_i2cs[i] != NULL) {
1409 			kfree(pool->base.sw_i2cs[i]);
1410 			pool->base.sw_i2cs[i] = NULL;
1411 		}
1412 	}
1413 
1414 	for (i = 0; i < pool->base.res_cap->num_opp; i++) {
1415 		if (pool->base.opps[i] != NULL)
1416 			pool->base.opps[i]->funcs->opp_destroy(&pool->base.opps[i]);
1417 	}
1418 
1419 	for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) {
1420 		if (pool->base.timing_generators[i] != NULL)	{
1421 			kfree(DCN10TG_FROM_TG(pool->base.timing_generators[i]));
1422 			pool->base.timing_generators[i] = NULL;
1423 		}
1424 	}
1425 
1426 	for (i = 0; i < pool->base.res_cap->num_dwb; i++) {
1427 		if (pool->base.dwbc[i] != NULL) {
1428 			kfree(TO_DCN30_DWBC(pool->base.dwbc[i]));
1429 			pool->base.dwbc[i] = NULL;
1430 		}
1431 		if (pool->base.mcif_wb[i] != NULL) {
1432 			kfree(TO_DCN30_MMHUBBUB(pool->base.mcif_wb[i]));
1433 			pool->base.mcif_wb[i] = NULL;
1434 		}
1435 	}
1436 
1437 	for (i = 0; i < pool->base.audio_count; i++) {
1438 		if (pool->base.audios[i])
1439 			dce_aud_destroy(&pool->base.audios[i]);
1440 	}
1441 
1442 	for (i = 0; i < pool->base.clk_src_count; i++) {
1443 		if (pool->base.clock_sources[i] != NULL) {
1444 			dcn20_clock_source_destroy(&pool->base.clock_sources[i]);
1445 			pool->base.clock_sources[i] = NULL;
1446 		}
1447 	}
1448 
1449 	for (i = 0; i < pool->base.res_cap->num_mpc_3dlut; i++) {
1450 		if (pool->base.mpc_lut[i] != NULL) {
1451 			dc_3dlut_func_release(pool->base.mpc_lut[i]);
1452 			pool->base.mpc_lut[i] = NULL;
1453 		}
1454 		if (pool->base.mpc_shaper[i] != NULL) {
1455 			dc_transfer_func_release(pool->base.mpc_shaper[i]);
1456 			pool->base.mpc_shaper[i] = NULL;
1457 		}
1458 	}
1459 
1460 	if (pool->base.dp_clock_source != NULL) {
1461 		dcn20_clock_source_destroy(&pool->base.dp_clock_source);
1462 		pool->base.dp_clock_source = NULL;
1463 	}
1464 
1465 	for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) {
1466 		if (pool->base.multiple_abms[i] != NULL)
1467 			dce_abm_destroy(&pool->base.multiple_abms[i]);
1468 	}
1469 
1470 	if (pool->base.psr != NULL)
1471 		dmub_psr_destroy(&pool->base.psr);
1472 
1473 	if (pool->base.dccg != NULL)
1474 		dcn_dccg_destroy(&pool->base.dccg);
1475 
1476 	if (pool->base.oem_device != NULL) {
1477 		struct dc *dc = pool->base.oem_device->ctx->dc;
1478 
1479 		dc->link_srv->destroy_ddc_service(&pool->base.oem_device);
1480 	}
1481 }
1482 
1483 
dcn321_dwbc_create(struct dc_context * ctx,struct resource_pool * pool)1484 static bool dcn321_dwbc_create(struct dc_context *ctx, struct resource_pool *pool)
1485 {
1486 	int i;
1487 	uint32_t dwb_count = pool->res_cap->num_dwb;
1488 
1489 	for (i = 0; i < dwb_count; i++) {
1490 		struct dcn30_dwbc *dwbc30 = kzalloc(sizeof(struct dcn30_dwbc),
1491 						    GFP_KERNEL);
1492 
1493 		if (!dwbc30) {
1494 			dm_error("DC: failed to create dwbc30!\n");
1495 			return false;
1496 		}
1497 
1498 #undef REG_STRUCT
1499 #define REG_STRUCT dwbc30_regs
1500 		dwbc_regs_dcn3_init(0);
1501 
1502 		dcn30_dwbc_construct(dwbc30, ctx,
1503 				&dwbc30_regs[i],
1504 				&dwbc30_shift,
1505 				&dwbc30_mask,
1506 				i);
1507 
1508 		pool->dwbc[i] = &dwbc30->base;
1509 	}
1510 	return true;
1511 }
1512 
dcn321_mmhubbub_create(struct dc_context * ctx,struct resource_pool * pool)1513 static bool dcn321_mmhubbub_create(struct dc_context *ctx, struct resource_pool *pool)
1514 {
1515 	int i;
1516 	uint32_t dwb_count = pool->res_cap->num_dwb;
1517 
1518 	for (i = 0; i < dwb_count; i++) {
1519 		struct dcn30_mmhubbub *mcif_wb30 = kzalloc(sizeof(struct dcn30_mmhubbub),
1520 						    GFP_KERNEL);
1521 
1522 		if (!mcif_wb30) {
1523 			dm_error("DC: failed to create mcif_wb30!\n");
1524 			return false;
1525 		}
1526 
1527 #undef REG_STRUCT
1528 #define REG_STRUCT mcif_wb30_regs
1529 		mcif_wb_regs_dcn3_init(0);
1530 
1531 		dcn32_mmhubbub_construct(mcif_wb30, ctx,
1532 				&mcif_wb30_regs[i],
1533 				&mcif_wb30_shift,
1534 				&mcif_wb30_mask,
1535 				i);
1536 
1537 		pool->mcif_wb[i] = &mcif_wb30->base;
1538 	}
1539 	return true;
1540 }
1541 
dcn321_dsc_create(struct dc_context * ctx,uint32_t inst)1542 static struct display_stream_compressor *dcn321_dsc_create(
1543 	struct dc_context *ctx, uint32_t inst)
1544 {
1545 	struct dcn20_dsc *dsc =
1546 		kzalloc(sizeof(struct dcn20_dsc), GFP_KERNEL);
1547 
1548 	if (!dsc) {
1549 		BREAK_TO_DEBUGGER();
1550 		return NULL;
1551 	}
1552 
1553 #undef REG_STRUCT
1554 #define REG_STRUCT dsc_regs
1555 	dsc_regsDCN20_init(0),
1556 	dsc_regsDCN20_init(1),
1557 	dsc_regsDCN20_init(2),
1558 	dsc_regsDCN20_init(3);
1559 
1560 	dsc2_construct(dsc, ctx, inst, &dsc_regs[inst], &dsc_shift, &dsc_mask);
1561 
1562 	dsc->max_image_width = 6016;
1563 
1564 	return &dsc->base;
1565 }
1566 
dcn321_destroy_resource_pool(struct resource_pool ** pool)1567 static void dcn321_destroy_resource_pool(struct resource_pool **pool)
1568 {
1569 	struct dcn321_resource_pool *dcn321_pool = TO_DCN321_RES_POOL(*pool);
1570 
1571 	dcn321_resource_destruct(dcn321_pool);
1572 	kfree(dcn321_pool);
1573 	*pool = NULL;
1574 }
1575 
1576 static struct dc_cap_funcs cap_funcs = {
1577 	.get_dcc_compression_cap = dcn20_get_dcc_compression_cap,
1578 	.get_subvp_en = dcn32_subvp_in_use,
1579 };
1580 
dcn321_update_bw_bounding_box(struct dc * dc,struct clk_bw_params * bw_params)1581 static void dcn321_update_bw_bounding_box(struct dc *dc, struct clk_bw_params *bw_params)
1582 {
1583 	struct dml2_configuration_options *dml2_opt = &dc->dml2_tmp;
1584 
1585 	memcpy(dml2_opt, &dc->dml2_options, sizeof(dc->dml2_options));
1586 
1587 	DC_FP_START();
1588 
1589 	dcn321_update_bw_bounding_box_fpu(dc, bw_params);
1590 
1591 	dml2_opt->use_clock_dc_limits = false;
1592 	if (dc->debug.using_dml2 && dc->current_state && dc->current_state->bw_ctx.dml2)
1593 		dml2_reinit(dc, dml2_opt, &dc->current_state->bw_ctx.dml2);
1594 
1595 	dml2_opt->use_clock_dc_limits = true;
1596 	if (dc->debug.using_dml2 && dc->current_state && dc->current_state->bw_ctx.dml2_dc_power_source)
1597 		dml2_reinit(dc, dml2_opt, &dc->current_state->bw_ctx.dml2_dc_power_source);
1598 
1599 	DC_FP_END();
1600 }
1601 
1602 static struct resource_funcs dcn321_res_pool_funcs = {
1603 	.destroy = dcn321_destroy_resource_pool,
1604 	.link_enc_create = dcn321_link_encoder_create,
1605 	.link_enc_create_minimal = NULL,
1606 	.panel_cntl_create = dcn32_panel_cntl_create,
1607 	.validate_bandwidth = dcn32_validate_bandwidth,
1608 	.calculate_wm_and_dlg = dcn32_calculate_wm_and_dlg,
1609 	.populate_dml_pipes = dcn32_populate_dml_pipes_from_context,
1610 	.acquire_free_pipe_as_secondary_dpp_pipe = dcn32_acquire_free_pipe_as_secondary_dpp_pipe,
1611 	.acquire_free_pipe_as_secondary_opp_head = dcn32_acquire_free_pipe_as_secondary_opp_head,
1612 	.release_pipe = dcn20_release_pipe,
1613 	.add_stream_to_ctx = dcn30_add_stream_to_ctx,
1614 	.add_dsc_to_stream_resource = dcn20_add_dsc_to_stream_resource,
1615 	.remove_stream_from_ctx = dcn20_remove_stream_from_ctx,
1616 	.populate_dml_writeback_from_context = dcn30_populate_dml_writeback_from_context,
1617 	.set_mcif_arb_params = dcn30_set_mcif_arb_params,
1618 	.find_first_free_match_stream_enc_for_link = dcn10_find_first_free_match_stream_enc_for_link,
1619 	.acquire_post_bldn_3dlut = dcn32_acquire_post_bldn_3dlut,
1620 	.release_post_bldn_3dlut = dcn32_release_post_bldn_3dlut,
1621 	.update_bw_bounding_box = dcn321_update_bw_bounding_box,
1622 	.patch_unknown_plane_state = dcn20_patch_unknown_plane_state,
1623 	.update_soc_for_wm_a = dcn30_update_soc_for_wm_a,
1624 	.add_phantom_pipes = dcn32_add_phantom_pipes,
1625 	.build_pipe_pix_clk_params = dcn20_build_pipe_pix_clk_params,
1626 	.calculate_mall_ways_from_bytes = dcn32_calculate_mall_ways_from_bytes,
1627 	.get_vstartup_for_pipe = dcn10_get_vstartup_for_pipe
1628 };
1629 
read_pipe_fuses(struct dc_context * ctx)1630 static uint32_t read_pipe_fuses(struct dc_context *ctx)
1631 {
1632 	uint32_t value = REG_READ(CC_DC_PIPE_DIS);
1633 	/* DCN321 support max 4 pipes */
1634 	value = value & 0xf;
1635 	return value;
1636 }
1637 
1638 
dcn321_resource_construct(uint8_t num_virtual_links,struct dc * dc,struct dcn321_resource_pool * pool)1639 static bool dcn321_resource_construct(
1640 	uint8_t num_virtual_links,
1641 	struct dc *dc,
1642 	struct dcn321_resource_pool *pool)
1643 {
1644 	int i, j;
1645 	struct dc_context *ctx = dc->ctx;
1646 	struct irq_service_init_data init_data;
1647 	struct ddc_service_init_data ddc_init_data = {0};
1648 	uint32_t pipe_fuses = 0;
1649 	uint32_t num_pipes  = 4;
1650 
1651 #undef REG_STRUCT
1652 #define REG_STRUCT bios_regs
1653 	bios_regs_init();
1654 
1655 #undef REG_STRUCT
1656 #define REG_STRUCT clk_src_regs
1657 	clk_src_regs_init(0, A),
1658 	clk_src_regs_init(1, B),
1659 	clk_src_regs_init(2, C),
1660 	clk_src_regs_init(3, D),
1661 	clk_src_regs_init(4, E);
1662 
1663 #undef REG_STRUCT
1664 #define REG_STRUCT abm_regs
1665 	abm_regs_init(0),
1666 	abm_regs_init(1),
1667 	abm_regs_init(2),
1668 	abm_regs_init(3);
1669 
1670 #undef REG_STRUCT
1671 #define REG_STRUCT dccg_regs
1672 	dccg_regs_init();
1673 
1674 
1675 	ctx->dc_bios->regs = &bios_regs;
1676 
1677 	pool->base.res_cap = &res_cap_dcn321;
1678 	/* max number of pipes for ASIC before checking for pipe fuses */
1679 	num_pipes  = pool->base.res_cap->num_timing_generator;
1680 	pipe_fuses = read_pipe_fuses(ctx);
1681 
1682 	for (i = 0; i < pool->base.res_cap->num_timing_generator; i++)
1683 		if (pipe_fuses & 1 << i)
1684 			num_pipes--;
1685 
1686 	if (pipe_fuses & 1)
1687 		ASSERT(0); //Unexpected - Pipe 0 should always be fully functional!
1688 
1689 	if (pipe_fuses & CC_DC_PIPE_DIS__DC_FULL_DIS_MASK)
1690 		ASSERT(0); //Entire DCN is harvested!
1691 
1692 	/* within dml lib, initial value is hard coded, if ASIC pipe is fused, the
1693 	 * value will be changed, update max_num_dpp and max_num_otg for dml.
1694 	 */
1695 	dcn3_21_ip.max_num_dpp = num_pipes;
1696 	dcn3_21_ip.max_num_otg = num_pipes;
1697 
1698 	pool->base.funcs = &dcn321_res_pool_funcs;
1699 
1700 	/*************************************************
1701 	 *  Resource + asic cap harcoding                *
1702 	 *************************************************/
1703 	pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
1704 	pool->base.timing_generator_count = num_pipes;
1705 	pool->base.pipe_count = num_pipes;
1706 	pool->base.mpcc_count = num_pipes;
1707 	dc->caps.max_downscale_ratio = 600;
1708 	dc->caps.i2c_speed_in_khz = 100;
1709 	dc->caps.i2c_speed_in_khz_hdcp = 100; /*1.4 w/a applied by default*/
1710 	/* TODO: Bring max cursor size back to 256 after subvp cursor corruption is fixed*/
1711 	dc->caps.max_cursor_size = 64;
1712 	dc->caps.min_horizontal_blanking_period = 80;
1713 	dc->caps.dmdata_alloc_size = 2048;
1714 	dc->caps.mall_size_per_mem_channel = 4;
1715 	/* total size = mall per channel * num channels * 1024 * 1024 */
1716 	dc->caps.mall_size_total = dc->caps.mall_size_per_mem_channel * dc->ctx->dc_bios->vram_info.num_chans * 1048576;
1717 
1718 	dc->caps.cursor_cache_size = dc->caps.max_cursor_size * dc->caps.max_cursor_size * 8;
1719 	dc->caps.cache_line_size = 64;
1720 	dc->caps.cache_num_ways = 16;
1721 
1722 	/* Calculate the available MALL space */
1723 	dc->caps.max_cab_allocation_bytes = dcn32_calc_num_avail_chans_for_mall(
1724 		dc, dc->ctx->dc_bios->vram_info.num_chans) *
1725 		dc->caps.mall_size_per_mem_channel * 1024 * 1024;
1726 	dc->caps.mall_size_total = dc->caps.max_cab_allocation_bytes;
1727 
1728 	dc->caps.subvp_fw_processing_delay_us = 15;
1729 	dc->caps.subvp_drr_max_vblank_margin_us = 40;
1730 	dc->caps.subvp_prefetch_end_to_mall_start_us = 15;
1731 	dc->caps.subvp_swath_height_margin_lines = 16;
1732 	dc->caps.subvp_pstate_allow_width_us = 20;
1733 	dc->caps.subvp_vertical_int_margin_us = 30;
1734 	dc->caps.subvp_drr_vblank_start_margin_us = 100; // 100us margin
1735 	dc->caps.max_slave_planes = 2;
1736 	dc->caps.max_slave_yuv_planes = 2;
1737 	dc->caps.max_slave_rgb_planes = 2;
1738 	dc->caps.post_blend_color_processing = true;
1739 	dc->caps.force_dp_tps4_for_cp2520 = true;
1740 	dc->caps.dp_hpo = true;
1741 	dc->caps.dp_hdmi21_pcon_support = true;
1742 	dc->caps.edp_dsc_support = true;
1743 	dc->caps.extended_aux_timeout_support = true;
1744 	dc->caps.dmcub_support = true;
1745 	dc->caps.max_v_total = (1 << 15) - 1;
1746 	dc->caps.vtotal_limited_by_fp2 = true;
1747 
1748 	/* Color pipeline capabilities */
1749 	dc->caps.color.dpp.dcn_arch = 1;
1750 	dc->caps.color.dpp.input_lut_shared = 0;
1751 	dc->caps.color.dpp.icsc = 1;
1752 	dc->caps.color.dpp.dgam_ram = 0; // must use gamma_corr
1753 	dc->caps.color.dpp.dgam_rom_caps.srgb = 1;
1754 	dc->caps.color.dpp.dgam_rom_caps.bt2020 = 1;
1755 	dc->caps.color.dpp.dgam_rom_caps.gamma2_2 = 1;
1756 	dc->caps.color.dpp.dgam_rom_caps.pq = 1;
1757 	dc->caps.color.dpp.dgam_rom_caps.hlg = 1;
1758 	dc->caps.color.dpp.post_csc = 1;
1759 	dc->caps.color.dpp.gamma_corr = 1;
1760 	dc->caps.color.dpp.dgam_rom_for_yuv = 0;
1761 
1762 	dc->caps.color.dpp.hw_3d_lut = 1;
1763 	dc->caps.color.dpp.ogam_ram = 1;
1764 	// no OGAM ROM on DCN2 and later ASICs
1765 	dc->caps.color.dpp.ogam_rom_caps.srgb = 0;
1766 	dc->caps.color.dpp.ogam_rom_caps.bt2020 = 0;
1767 	dc->caps.color.dpp.ogam_rom_caps.gamma2_2 = 0;
1768 	dc->caps.color.dpp.ogam_rom_caps.pq = 0;
1769 	dc->caps.color.dpp.ogam_rom_caps.hlg = 0;
1770 	dc->caps.color.dpp.ocsc = 0;
1771 
1772 	dc->caps.color.mpc.gamut_remap = 1;
1773 	dc->caps.color.mpc.num_3dluts = pool->base.res_cap->num_mpc_3dlut; //4, configurable to be before or after BLND in MPCC
1774 	dc->caps.color.mpc.ogam_ram = 1;
1775 	dc->caps.color.mpc.ogam_rom_caps.srgb = 0;
1776 	dc->caps.color.mpc.ogam_rom_caps.bt2020 = 0;
1777 	dc->caps.color.mpc.ogam_rom_caps.gamma2_2 = 0;
1778 	dc->caps.color.mpc.ogam_rom_caps.pq = 0;
1779 	dc->caps.color.mpc.ogam_rom_caps.hlg = 0;
1780 	dc->caps.color.mpc.ocsc = 1;
1781 
1782 	/* Use pipe context based otg sync logic */
1783 	dc->config.use_pipe_ctx_sync_logic = true;
1784 
1785 	dc->config.dc_mode_clk_limit_support = true;
1786 	dc->config.enable_windowed_mpo_odm = true;
1787 	dc->config.disable_hbr_audio_dp2 = true;
1788 	/* read VBIOS LTTPR caps */
1789 	{
1790 		if (ctx->dc_bios->funcs->get_lttpr_caps) {
1791 			enum bp_result bp_query_result;
1792 			uint8_t is_vbios_lttpr_enable = 0;
1793 
1794 			bp_query_result = ctx->dc_bios->funcs->get_lttpr_caps(ctx->dc_bios, &is_vbios_lttpr_enable);
1795 			dc->caps.vbios_lttpr_enable = (bp_query_result == BP_RESULT_OK) && !!is_vbios_lttpr_enable;
1796 		}
1797 
1798 		/* interop bit is implicit */
1799 		{
1800 			dc->caps.vbios_lttpr_aware = true;
1801 		}
1802 	}
1803 
1804 	if (dc->ctx->dce_environment == DCE_ENV_PRODUCTION_DRV)
1805 		dc->debug = debug_defaults_drv;
1806 
1807 	// Init the vm_helper
1808 	if (dc->vm_helper)
1809 		vm_helper_init(dc->vm_helper, 16);
1810 
1811 	/*************************************************
1812 	 *  Create resources                             *
1813 	 *************************************************/
1814 
1815 	/* Clock Sources for Pixel Clock*/
1816 	pool->base.clock_sources[DCN321_CLK_SRC_PLL0] =
1817 			dcn321_clock_source_create(ctx, ctx->dc_bios,
1818 				CLOCK_SOURCE_COMBO_PHY_PLL0,
1819 				&clk_src_regs[0], false);
1820 	pool->base.clock_sources[DCN321_CLK_SRC_PLL1] =
1821 			dcn321_clock_source_create(ctx, ctx->dc_bios,
1822 				CLOCK_SOURCE_COMBO_PHY_PLL1,
1823 				&clk_src_regs[1], false);
1824 	pool->base.clock_sources[DCN321_CLK_SRC_PLL2] =
1825 			dcn321_clock_source_create(ctx, ctx->dc_bios,
1826 				CLOCK_SOURCE_COMBO_PHY_PLL2,
1827 				&clk_src_regs[2], false);
1828 	pool->base.clock_sources[DCN321_CLK_SRC_PLL3] =
1829 			dcn321_clock_source_create(ctx, ctx->dc_bios,
1830 				CLOCK_SOURCE_COMBO_PHY_PLL3,
1831 				&clk_src_regs[3], false);
1832 	pool->base.clock_sources[DCN321_CLK_SRC_PLL4] =
1833 			dcn321_clock_source_create(ctx, ctx->dc_bios,
1834 				CLOCK_SOURCE_COMBO_PHY_PLL4,
1835 				&clk_src_regs[4], false);
1836 
1837 	pool->base.clk_src_count = DCN321_CLK_SRC_TOTAL;
1838 
1839 	/* todo: not reuse phy_pll registers */
1840 	pool->base.dp_clock_source =
1841 			dcn321_clock_source_create(ctx, ctx->dc_bios,
1842 				CLOCK_SOURCE_ID_DP_DTO,
1843 				&clk_src_regs[0], true);
1844 
1845 	for (i = 0; i < pool->base.clk_src_count; i++) {
1846 		if (pool->base.clock_sources[i] == NULL) {
1847 			dm_error("DC: failed to create clock sources!\n");
1848 			BREAK_TO_DEBUGGER();
1849 			goto create_fail;
1850 		}
1851 	}
1852 
1853 	/* DCCG */
1854 	pool->base.dccg = dccg32_create(ctx, &dccg_regs, &dccg_shift, &dccg_mask);
1855 	if (pool->base.dccg == NULL) {
1856 		dm_error("DC: failed to create dccg!\n");
1857 		BREAK_TO_DEBUGGER();
1858 		goto create_fail;
1859 	}
1860 
1861 	/* DML */
1862 	dml_init_instance(&dc->dml, &dcn3_21_soc, &dcn3_21_ip, DML_PROJECT_DCN32);
1863 
1864 	/* IRQ Service */
1865 	init_data.ctx = dc->ctx;
1866 	pool->base.irqs = dal_irq_service_dcn32_create(&init_data);
1867 	if (!pool->base.irqs)
1868 		goto create_fail;
1869 
1870 	/* HUBBUB */
1871 	pool->base.hubbub = dcn321_hubbub_create(ctx);
1872 	if (pool->base.hubbub == NULL) {
1873 		BREAK_TO_DEBUGGER();
1874 		dm_error("DC: failed to create hubbub!\n");
1875 		goto create_fail;
1876 	}
1877 
1878 	/* HUBPs, DPPs, OPPs, TGs, ABMs */
1879 	for (i = 0, j = 0; i < pool->base.res_cap->num_timing_generator; i++) {
1880 
1881 		/* if pipe is disabled, skip instance of HW pipe,
1882 		 * i.e, skip ASIC register instance
1883 		 */
1884 		if (pipe_fuses & 1 << i)
1885 			continue;
1886 
1887 		pool->base.hubps[j] = dcn321_hubp_create(ctx, i);
1888 		if (pool->base.hubps[j] == NULL) {
1889 			BREAK_TO_DEBUGGER();
1890 			dm_error(
1891 				"DC: failed to create hubps!\n");
1892 			goto create_fail;
1893 		}
1894 
1895 		pool->base.dpps[j] = dcn321_dpp_create(ctx, i);
1896 		if (pool->base.dpps[j] == NULL) {
1897 			BREAK_TO_DEBUGGER();
1898 			dm_error(
1899 				"DC: failed to create dpps!\n");
1900 			goto create_fail;
1901 		}
1902 
1903 		pool->base.opps[j] = dcn321_opp_create(ctx, i);
1904 		if (pool->base.opps[j] == NULL) {
1905 			BREAK_TO_DEBUGGER();
1906 			dm_error(
1907 				"DC: failed to create output pixel processor!\n");
1908 			goto create_fail;
1909 		}
1910 
1911 		pool->base.timing_generators[j] = dcn321_timing_generator_create(
1912 				ctx, i);
1913 		if (pool->base.timing_generators[j] == NULL) {
1914 			BREAK_TO_DEBUGGER();
1915 			dm_error("DC: failed to create tg!\n");
1916 			goto create_fail;
1917 		}
1918 
1919 		pool->base.multiple_abms[j] = dmub_abm_create(ctx,
1920 				&abm_regs[i],
1921 				&abm_shift,
1922 				&abm_mask);
1923 		if (pool->base.multiple_abms[j] == NULL) {
1924 			dm_error("DC: failed to create abm for pipe %d!\n", i);
1925 			BREAK_TO_DEBUGGER();
1926 			goto create_fail;
1927 		}
1928 
1929 		/* index for resource pool arrays for next valid pipe */
1930 		j++;
1931 	}
1932 
1933 	/* PSR */
1934 	pool->base.psr = dmub_psr_create(ctx);
1935 	if (pool->base.psr == NULL) {
1936 		dm_error("DC: failed to create psr obj!\n");
1937 		BREAK_TO_DEBUGGER();
1938 		goto create_fail;
1939 	}
1940 
1941 	/* MPCCs */
1942 	pool->base.mpc = dcn321_mpc_create(ctx,  pool->base.res_cap->num_timing_generator, pool->base.res_cap->num_mpc_3dlut);
1943 	if (pool->base.mpc == NULL) {
1944 		BREAK_TO_DEBUGGER();
1945 		dm_error("DC: failed to create mpc!\n");
1946 		goto create_fail;
1947 	}
1948 
1949 	/* DSCs */
1950 	for (i = 0; i < pool->base.res_cap->num_dsc; i++) {
1951 		pool->base.dscs[i] = dcn321_dsc_create(ctx, i);
1952 		if (pool->base.dscs[i] == NULL) {
1953 			BREAK_TO_DEBUGGER();
1954 			dm_error("DC: failed to create display stream compressor %d!\n", i);
1955 			goto create_fail;
1956 		}
1957 	}
1958 
1959 	/* DWB */
1960 	if (!dcn321_dwbc_create(ctx, &pool->base)) {
1961 		BREAK_TO_DEBUGGER();
1962 		dm_error("DC: failed to create dwbc!\n");
1963 		goto create_fail;
1964 	}
1965 
1966 	/* MMHUBBUB */
1967 	if (!dcn321_mmhubbub_create(ctx, &pool->base)) {
1968 		BREAK_TO_DEBUGGER();
1969 		dm_error("DC: failed to create mcif_wb!\n");
1970 		goto create_fail;
1971 	}
1972 
1973 	/* AUX and I2C */
1974 	for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
1975 		pool->base.engines[i] = dcn321_aux_engine_create(ctx, i);
1976 		if (pool->base.engines[i] == NULL) {
1977 			BREAK_TO_DEBUGGER();
1978 			dm_error(
1979 				"DC:failed to create aux engine!!\n");
1980 			goto create_fail;
1981 		}
1982 		pool->base.hw_i2cs[i] = dcn321_i2c_hw_create(ctx, i);
1983 		if (pool->base.hw_i2cs[i] == NULL) {
1984 			BREAK_TO_DEBUGGER();
1985 			dm_error(
1986 				"DC:failed to create hw i2c!!\n");
1987 			goto create_fail;
1988 		}
1989 		pool->base.sw_i2cs[i] = NULL;
1990 	}
1991 
1992 	/* Audio, HWSeq, Stream Encoders including HPO and virtual, MPC 3D LUTs */
1993 	if (!resource_construct(num_virtual_links, dc, &pool->base,
1994 			&res_create_funcs))
1995 		goto create_fail;
1996 
1997 	/* HW Sequencer init functions and Plane caps */
1998 	dcn32_hw_sequencer_init_functions(dc);
1999 
2000 	dc->caps.max_planes =  pool->base.pipe_count;
2001 
2002 	for (i = 0; i < dc->caps.max_planes; ++i)
2003 		dc->caps.planes[i] = plane_cap;
2004 
2005 	dc->cap_funcs = cap_funcs;
2006 
2007 	if (dc->ctx->dc_bios->fw_info.oem_i2c_present) {
2008 		ddc_init_data.ctx = dc->ctx;
2009 		ddc_init_data.link = NULL;
2010 		ddc_init_data.id.id = dc->ctx->dc_bios->fw_info.oem_i2c_obj_id;
2011 		ddc_init_data.id.enum_id = 0;
2012 		ddc_init_data.id.type = OBJECT_TYPE_GENERIC;
2013 		pool->base.oem_device = dc->link_srv->create_ddc_service(&ddc_init_data);
2014 	} else {
2015 		pool->base.oem_device = NULL;
2016 	}
2017 
2018 	dc->dml2_options.dcn_pipe_count = pool->base.pipe_count;
2019 	dc->dml2_options.use_native_pstate_optimization = false;
2020 	dc->dml2_options.use_native_soc_bb_construction = true;
2021 	dc->dml2_options.minimize_dispclk_using_odm = true;
2022 
2023 	resource_init_common_dml2_callbacks(dc, &dc->dml2_options);
2024 	dc->dml2_options.callbacks.can_support_mclk_switch_using_fw_based_vblank_stretch = &dcn30_can_support_mclk_switch_using_fw_based_vblank_stretch;
2025 	dc->dml2_options.svp_pstate.callbacks.release_dsc = &dcn20_release_dsc;
2026 	dc->dml2_options.svp_pstate.callbacks.calculate_mall_ways_from_bytes = pool->base.funcs->calculate_mall_ways_from_bytes;
2027 
2028 	dc->dml2_options.svp_pstate.subvp_fw_processing_delay_us = dc->caps.subvp_fw_processing_delay_us;
2029 	dc->dml2_options.svp_pstate.subvp_prefetch_end_to_mall_start_us = dc->caps.subvp_prefetch_end_to_mall_start_us;
2030 	dc->dml2_options.svp_pstate.subvp_pstate_allow_width_us = dc->caps.subvp_pstate_allow_width_us;
2031 	dc->dml2_options.svp_pstate.subvp_swath_height_margin_lines = dc->caps.subvp_swath_height_margin_lines;
2032 
2033 	dc->dml2_options.svp_pstate.force_disable_subvp = dc->debug.force_disable_subvp;
2034 	dc->dml2_options.svp_pstate.force_enable_subvp = dc->debug.force_subvp_mclk_switch;
2035 
2036 	dc->dml2_options.mall_cfg.cache_line_size_bytes = dc->caps.cache_line_size;
2037 	dc->dml2_options.mall_cfg.cache_num_ways = dc->caps.cache_num_ways;
2038 	dc->dml2_options.mall_cfg.max_cab_allocation_bytes = dc->caps.max_cab_allocation_bytes;
2039 	dc->dml2_options.mall_cfg.mblk_height_4bpe_pixels = DCN3_2_MBLK_HEIGHT_4BPE;
2040 	dc->dml2_options.mall_cfg.mblk_height_8bpe_pixels = DCN3_2_MBLK_HEIGHT_8BPE;
2041 	dc->dml2_options.mall_cfg.mblk_size_bytes = DCN3_2_MALL_MBLK_SIZE_BYTES;
2042 	dc->dml2_options.mall_cfg.mblk_width_pixels = DCN3_2_MBLK_WIDTH;
2043 
2044 	dc->dml2_options.max_segments_per_hubp = 18;
2045 	dc->dml2_options.det_segment_size = DCN3_2_DET_SEG_SIZE;
2046 
2047 	return true;
2048 
2049 create_fail:
2050 
2051 	dcn321_resource_destruct(pool);
2052 
2053 	return false;
2054 }
2055 
dcn321_create_resource_pool(const struct dc_init_data * init_data,struct dc * dc)2056 struct resource_pool *dcn321_create_resource_pool(
2057 		const struct dc_init_data *init_data,
2058 		struct dc *dc)
2059 {
2060 	struct dcn321_resource_pool *pool =
2061 		kzalloc(sizeof(struct dcn321_resource_pool), GFP_KERNEL);
2062 
2063 	if (!pool)
2064 		return NULL;
2065 
2066 	if (dcn321_resource_construct(init_data->num_virtual_links, dc, pool))
2067 		return &pool->base;
2068 
2069 	BREAK_TO_DEBUGGER();
2070 	kfree(pool);
2071 	return NULL;
2072 }
2073