drm/amd/display: fix dcn315 single stream crb allocation
[linux-block.git] / drivers / gpu / drm / amd / display / dc / dcn20 / dcn20_resource.c
CommitLineData
7ed4e635
HW
1/*
2* Copyright 2016 Advanced Micro Devices, Inc.
6ca3928d 3 * Copyright 2019 Raptor Engineering, LLC
7ed4e635
HW
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
d7929c1e
AD
27#include <linux/slab.h>
28
7ed4e635
HW
29#include "dm_services.h"
30#include "dc.h"
31
78c77382
AK
32#include "dcn20_init.h"
33
7ed4e635
HW
34#include "resource.h"
35#include "include/irq_service_interface.h"
36#include "dcn20/dcn20_resource.h"
37
ee373411 38#include "dml/dcn20/dcn20_fpu.h"
c8b3538d 39
7ed4e635
HW
40#include "dcn10/dcn10_hubp.h"
41#include "dcn10/dcn10_ipp.h"
42#include "dcn20_hubbub.h"
43#include "dcn20_mpc.h"
44#include "dcn20_hubp.h"
45#include "irq/dcn20/irq_service_dcn20.h"
46#include "dcn20_dpp.h"
47#include "dcn20_optc.h"
48#include "dcn20_hwseq.h"
49#include "dce110/dce110_hw_sequencer.h"
278141f5 50#include "dcn10/dcn10_resource.h"
7ed4e635
HW
51#include "dcn20_opp.h"
52
97bda032 53#include "dcn20_dsc.h"
97bda032 54
7ed4e635
HW
55#include "dcn20_link_encoder.h"
56#include "dcn20_stream_encoder.h"
57#include "dce/dce_clock_source.h"
58#include "dce/dce_audio.h"
59#include "dce/dce_hwseq.h"
60#include "virtual/virtual_stream_encoder.h"
61#include "dce110/dce110_resource.h"
62#include "dml/display_mode_vba.h"
63#include "dcn20_dccg.h"
64#include "dcn20_vmid.h"
d4caa72e 65#include "dce/dce_panel_cntl.h"
7ed4e635
HW
66
67#include "navi10_ip_offset.h"
68
69#include "dcn/dcn_2_0_0_offset.h"
70#include "dcn/dcn_2_0_0_sh_mask.h"
a771ded8
RL
71#include "dpcs/dpcs_2_0_0_offset.h"
72#include "dpcs/dpcs_2_0_0_sh_mask.h"
7ed4e635
HW
73
74#include "nbio/nbio_2_3_offset.h"
75
bb21290f
CL
76#include "dcn20/dcn20_dwb.h"
77#include "dcn20/dcn20_mmhubbub.h"
78
7ed4e635
HW
79#include "mmhub/mmhub_2_0_0_offset.h"
80#include "mmhub/mmhub_2_0_0_sh_mask.h"
81
82#include "reg_helper.h"
83#include "dce/dce_abm.h"
84#include "dce/dce_dmcu.h"
85#include "dce/dce_aux.h"
86#include "dce/dce_i2c.h"
87#include "vm_helper.h"
64d283cb 88#include "link_enc_cfg.h"
7ed4e635
HW
89
90#include "amdgpu_socbb.h"
91
a98cdd8c 92#include "link.h"
7ed4e635
HW
93#define DC_LOGGER_INIT(logger)
94
7ed4e635
HW
95#ifndef mmDP0_DP_DPHY_INTERNAL_CTRL
96 #define mmDP0_DP_DPHY_INTERNAL_CTRL 0x210f
97 #define mmDP0_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
98 #define mmDP1_DP_DPHY_INTERNAL_CTRL 0x220f
99 #define mmDP1_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
100 #define mmDP2_DP_DPHY_INTERNAL_CTRL 0x230f
101 #define mmDP2_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
102 #define mmDP3_DP_DPHY_INTERNAL_CTRL 0x240f
103 #define mmDP3_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
104 #define mmDP4_DP_DPHY_INTERNAL_CTRL 0x250f
105 #define mmDP4_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
106 #define mmDP5_DP_DPHY_INTERNAL_CTRL 0x260f
107 #define mmDP5_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
108 #define mmDP6_DP_DPHY_INTERNAL_CTRL 0x270f
109 #define mmDP6_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
110#endif
111
112
113enum dcn20_clk_src_array_id {
114 DCN20_CLK_SRC_PLL0,
115 DCN20_CLK_SRC_PLL1,
116 DCN20_CLK_SRC_PLL2,
117 DCN20_CLK_SRC_PLL3,
118 DCN20_CLK_SRC_PLL4,
119 DCN20_CLK_SRC_PLL5,
120 DCN20_CLK_SRC_TOTAL
121};
122
123/* begin *********************
124 * macros to expend register list macro defined in HW object header file */
125
126/* DCN */
7ed4e635
HW
127#define BASE_INNER(seg) DCN_BASE__INST0_SEG ## seg
128
129#define BASE(seg) BASE_INNER(seg)
130
131#define SR(reg_name)\
132 .reg_name = BASE(mm ## reg_name ## _BASE_IDX) + \
133 mm ## reg_name
134
135#define SRI(reg_name, block, id)\
136 .reg_name = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
137 mm ## block ## id ## _ ## reg_name
138
158858bf
AP
139#define SRI2_DWB(reg_name, block, id)\
140 .reg_name = BASE(mm ## reg_name ## _BASE_IDX) + \
141 mm ## reg_name
142#define SF_DWB(reg_name, field_name, post_fix)\
143 .field_name = reg_name ## __ ## field_name ## post_fix
144
145#define SF_DWB2(reg_name, block, id, field_name, post_fix) \
146 .field_name = reg_name ## __ ## field_name ## post_fix
147
7ed4e635
HW
148#define SRIR(var_name, reg_name, block, id)\
149 .var_name = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
150 mm ## block ## id ## _ ## reg_name
151
152#define SRII(reg_name, block, id)\
153 .reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
154 mm ## block ## id ## _ ## reg_name
155
156#define DCCG_SRII(reg_name, block, id)\
157 .block ## _ ## reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
158 mm ## block ## id ## _ ## reg_name
159
1e461c37
AC
160#define VUPDATE_SRII(reg_name, block, id)\
161 .reg_name[id] = BASE(mm ## reg_name ## _ ## block ## id ## _BASE_IDX) + \
162 mm ## reg_name ## _ ## block ## id
163
7ed4e635
HW
164/* NBIO */
165#define NBIO_BASE_INNER(seg) \
166 NBIO_BASE__INST0_SEG ## seg
167
168#define NBIO_BASE(seg) \
169 NBIO_BASE_INNER(seg)
170
171#define NBIO_SR(reg_name)\
172 .reg_name = NBIO_BASE(mm ## reg_name ## _BASE_IDX) + \
173 mm ## reg_name
174
175/* MMHUB */
176#define MMHUB_BASE_INNER(seg) \
177 MMHUB_BASE__INST0_SEG ## seg
178
179#define MMHUB_BASE(seg) \
180 MMHUB_BASE_INNER(seg)
181
182#define MMHUB_SR(reg_name)\
183 .reg_name = MMHUB_BASE(mmMM ## reg_name ## _BASE_IDX) + \
184 mmMM ## reg_name
185
186static const struct bios_registers bios_regs = {
187 NBIO_SR(BIOS_SCRATCH_3),
188 NBIO_SR(BIOS_SCRATCH_6)
189};
190
191#define clk_src_regs(index, pllid)\
192[index] = {\
193 CS_COMMON_REG_LIST_DCN2_0(index, pllid),\
194}
195
196static const struct dce110_clk_src_regs clk_src_regs[] = {
197 clk_src_regs(0, A),
198 clk_src_regs(1, B),
199 clk_src_regs(2, C),
200 clk_src_regs(3, D),
201 clk_src_regs(4, E),
202 clk_src_regs(5, F)
203};
204
205static const struct dce110_clk_src_shift cs_shift = {
206 CS_COMMON_MASK_SH_LIST_DCN2_0(__SHIFT)
207};
208
209static const struct dce110_clk_src_mask cs_mask = {
210 CS_COMMON_MASK_SH_LIST_DCN2_0(_MASK)
211};
212
213static const struct dce_dmcu_registers dmcu_regs = {
214 DMCU_DCN10_REG_LIST()
215};
216
217static const struct dce_dmcu_shift dmcu_shift = {
218 DMCU_MASK_SH_LIST_DCN10(__SHIFT)
219};
220
221static const struct dce_dmcu_mask dmcu_mask = {
222 DMCU_MASK_SH_LIST_DCN10(_MASK)
223};
d7c29549 224
7ed4e635 225static const struct dce_abm_registers abm_regs = {
d7c29549 226 ABM_DCN20_REG_LIST()
7ed4e635
HW
227};
228
229static const struct dce_abm_shift abm_shift = {
d7c29549 230 ABM_MASK_SH_LIST_DCN20(__SHIFT)
7ed4e635
HW
231};
232
233static const struct dce_abm_mask abm_mask = {
d7c29549 234 ABM_MASK_SH_LIST_DCN20(_MASK)
7ed4e635 235};
d7c29549 236
7ed4e635
HW
237#define audio_regs(id)\
238[id] = {\
239 AUD_COMMON_REG_LIST(id)\
240}
241
242static const struct dce_audio_registers audio_regs[] = {
243 audio_regs(0),
244 audio_regs(1),
245 audio_regs(2),
246 audio_regs(3),
247 audio_regs(4),
248 audio_regs(5),
249 audio_regs(6),
250};
251
252#define DCE120_AUD_COMMON_MASK_SH_LIST(mask_sh)\
253 SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_INDEX, AZALIA_ENDPOINT_REG_INDEX, mask_sh),\
254 SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_DATA, AZALIA_ENDPOINT_REG_DATA, mask_sh),\
255 AUD_COMMON_MASK_SH_LIST_BASE(mask_sh)
256
257static const struct dce_audio_shift audio_shift = {
258 DCE120_AUD_COMMON_MASK_SH_LIST(__SHIFT)
259};
260
54a9bcb0 261static const struct dce_audio_mask audio_mask = {
7ed4e635
HW
262 DCE120_AUD_COMMON_MASK_SH_LIST(_MASK)
263};
264
265#define stream_enc_regs(id)\
266[id] = {\
267 SE_DCN2_REG_LIST(id)\
268}
269
270static const struct dcn10_stream_enc_registers stream_enc_regs[] = {
271 stream_enc_regs(0),
272 stream_enc_regs(1),
273 stream_enc_regs(2),
274 stream_enc_regs(3),
275 stream_enc_regs(4),
276 stream_enc_regs(5),
277};
278
279static const struct dcn10_stream_encoder_shift se_shift = {
280 SE_COMMON_MASK_SH_LIST_DCN20(__SHIFT)
281};
282
283static const struct dcn10_stream_encoder_mask se_mask = {
284 SE_COMMON_MASK_SH_LIST_DCN20(_MASK)
285};
286
287
288#define aux_regs(id)\
289[id] = {\
290 DCN2_AUX_REG_LIST(id)\
291}
292
293static const struct dcn10_link_enc_aux_registers link_enc_aux_regs[] = {
294 aux_regs(0),
295 aux_regs(1),
296 aux_regs(2),
297 aux_regs(3),
298 aux_regs(4),
299 aux_regs(5)
300};
301
302#define hpd_regs(id)\
303[id] = {\
304 HPD_REG_LIST(id)\
305}
306
307static const struct dcn10_link_enc_hpd_registers link_enc_hpd_regs[] = {
308 hpd_regs(0),
309 hpd_regs(1),
310 hpd_regs(2),
311 hpd_regs(3),
312 hpd_regs(4),
313 hpd_regs(5)
314};
315
316#define link_regs(id, phyid)\
317[id] = {\
318 LE_DCN10_REG_LIST(id), \
319 UNIPHY_DCN2_REG_LIST(phyid), \
a771ded8 320 DPCS_DCN2_REG_LIST(id), \
7ed4e635
HW
321 SRI(DP_DPHY_INTERNAL_CTRL, DP, id) \
322}
323
324static const struct dcn10_link_enc_registers link_enc_regs[] = {
325 link_regs(0, A),
326 link_regs(1, B),
327 link_regs(2, C),
328 link_regs(3, D),
329 link_regs(4, E),
330 link_regs(5, F)
331};
332
333static const struct dcn10_link_enc_shift le_shift = {
a771ded8
RL
334 LINK_ENCODER_MASK_SH_LIST_DCN20(__SHIFT),\
335 DPCS_DCN2_MASK_SH_LIST(__SHIFT)
7ed4e635
HW
336};
337
338static const struct dcn10_link_enc_mask le_mask = {
a771ded8
RL
339 LINK_ENCODER_MASK_SH_LIST_DCN20(_MASK),\
340 DPCS_DCN2_MASK_SH_LIST(_MASK)
7ed4e635
HW
341};
342
d4caa72e
AK
343static const struct dce_panel_cntl_registers panel_cntl_regs[] = {
344 { DCN_PANEL_CNTL_REG_LIST() }
904fb6e0
AK
345};
346
d4caa72e
AK
347static const struct dce_panel_cntl_shift panel_cntl_shift = {
348 DCE_PANEL_CNTL_MASK_SH_LIST(__SHIFT)
904fb6e0
AK
349};
350
d4caa72e
AK
351static const struct dce_panel_cntl_mask panel_cntl_mask = {
352 DCE_PANEL_CNTL_MASK_SH_LIST(_MASK)
904fb6e0
AK
353};
354
7ed4e635
HW
355#define ipp_regs(id)\
356[id] = {\
357 IPP_REG_LIST_DCN20(id),\
358}
359
360static const struct dcn10_ipp_registers ipp_regs[] = {
361 ipp_regs(0),
362 ipp_regs(1),
363 ipp_regs(2),
364 ipp_regs(3),
365 ipp_regs(4),
366 ipp_regs(5),
367};
368
369static const struct dcn10_ipp_shift ipp_shift = {
370 IPP_MASK_SH_LIST_DCN20(__SHIFT)
371};
372
373static const struct dcn10_ipp_mask ipp_mask = {
374 IPP_MASK_SH_LIST_DCN20(_MASK),
375};
376
377#define opp_regs(id)\
378[id] = {\
379 OPP_REG_LIST_DCN20(id),\
380}
381
382static const struct dcn20_opp_registers opp_regs[] = {
383 opp_regs(0),
384 opp_regs(1),
385 opp_regs(2),
386 opp_regs(3),
387 opp_regs(4),
388 opp_regs(5),
389};
390
391static const struct dcn20_opp_shift opp_shift = {
392 OPP_MASK_SH_LIST_DCN20(__SHIFT)
393};
394
395static const struct dcn20_opp_mask opp_mask = {
396 OPP_MASK_SH_LIST_DCN20(_MASK)
397};
398
399#define aux_engine_regs(id)\
400[id] = {\
401 AUX_COMMON_REG_LIST0(id), \
402 .AUXN_IMPCAL = 0, \
403 .AUXP_IMPCAL = 0, \
404 .AUX_RESET_MASK = DP_AUX0_AUX_CONTROL__AUX_RESET_MASK, \
405}
406
407static const struct dce110_aux_registers aux_engine_regs[] = {
408 aux_engine_regs(0),
409 aux_engine_regs(1),
410 aux_engine_regs(2),
411 aux_engine_regs(3),
412 aux_engine_regs(4),
413 aux_engine_regs(5)
414};
415
416#define tf_regs(id)\
417[id] = {\
418 TF_REG_LIST_DCN20(id),\
d9eb70ae 419 TF_REG_LIST_DCN20_COMMON_APPEND(id),\
7ed4e635
HW
420}
421
422static const struct dcn2_dpp_registers tf_regs[] = {
423 tf_regs(0),
424 tf_regs(1),
425 tf_regs(2),
426 tf_regs(3),
427 tf_regs(4),
428 tf_regs(5),
429};
430
431static const struct dcn2_dpp_shift tf_shift = {
d56eaa7c 432 TF_REG_LIST_SH_MASK_DCN20(__SHIFT),
c1e34175 433 TF_DEBUG_REG_LIST_SH_DCN20
7ed4e635
HW
434};
435
436static const struct dcn2_dpp_mask tf_mask = {
d56eaa7c 437 TF_REG_LIST_SH_MASK_DCN20(_MASK),
c1e34175 438 TF_DEBUG_REG_LIST_MASK_DCN20
7ed4e635
HW
439};
440
bb21290f
CL
441#define dwbc_regs_dcn2(id)\
442[id] = {\
443 DWBC_COMMON_REG_LIST_DCN2_0(id),\
444 }
445
446static const struct dcn20_dwbc_registers dwbc20_regs[] = {
447 dwbc_regs_dcn2(0),
448};
449
450static const struct dcn20_dwbc_shift dwbc20_shift = {
451 DWBC_COMMON_MASK_SH_LIST_DCN2_0(__SHIFT)
452};
453
454static const struct dcn20_dwbc_mask dwbc20_mask = {
455 DWBC_COMMON_MASK_SH_LIST_DCN2_0(_MASK)
456};
457
458#define mcif_wb_regs_dcn2(id)\
459[id] = {\
460 MCIF_WB_COMMON_REG_LIST_DCN2_0(id),\
461 }
462
463static const struct dcn20_mmhubbub_registers mcif_wb20_regs[] = {
464 mcif_wb_regs_dcn2(0),
465};
466
467static const struct dcn20_mmhubbub_shift mcif_wb20_shift = {
468 MCIF_WB_COMMON_MASK_SH_LIST_DCN2_0(__SHIFT)
469};
470
471static const struct dcn20_mmhubbub_mask mcif_wb20_mask = {
472 MCIF_WB_COMMON_MASK_SH_LIST_DCN2_0(_MASK)
473};
474
7ed4e635
HW
475static const struct dcn20_mpc_registers mpc_regs = {
476 MPC_REG_LIST_DCN2_0(0),
477 MPC_REG_LIST_DCN2_0(1),
478 MPC_REG_LIST_DCN2_0(2),
479 MPC_REG_LIST_DCN2_0(3),
480 MPC_REG_LIST_DCN2_0(4),
481 MPC_REG_LIST_DCN2_0(5),
482 MPC_OUT_MUX_REG_LIST_DCN2_0(0),
483 MPC_OUT_MUX_REG_LIST_DCN2_0(1),
484 MPC_OUT_MUX_REG_LIST_DCN2_0(2),
485 MPC_OUT_MUX_REG_LIST_DCN2_0(3),
486 MPC_OUT_MUX_REG_LIST_DCN2_0(4),
487 MPC_OUT_MUX_REG_LIST_DCN2_0(5),
e8027e08 488 MPC_DBG_REG_LIST_DCN2_0()
7ed4e635
HW
489};
490
491static const struct dcn20_mpc_shift mpc_shift = {
c1e34175
NA
492 MPC_COMMON_MASK_SH_LIST_DCN2_0(__SHIFT),
493 MPC_DEBUG_REG_LIST_SH_DCN20
7ed4e635
HW
494};
495
496static const struct dcn20_mpc_mask mpc_mask = {
c1e34175
NA
497 MPC_COMMON_MASK_SH_LIST_DCN2_0(_MASK),
498 MPC_DEBUG_REG_LIST_MASK_DCN20
7ed4e635
HW
499};
500
501#define tg_regs(id)\
502[id] = {TG_COMMON_REG_LIST_DCN2_0(id)}
503
504
505static const struct dcn_optc_registers tg_regs[] = {
506 tg_regs(0),
507 tg_regs(1),
508 tg_regs(2),
509 tg_regs(3),
510 tg_regs(4),
511 tg_regs(5)
512};
513
514static const struct dcn_optc_shift tg_shift = {
515 TG_COMMON_MASK_SH_LIST_DCN2_0(__SHIFT)
516};
517
518static const struct dcn_optc_mask tg_mask = {
519 TG_COMMON_MASK_SH_LIST_DCN2_0(_MASK)
520};
521
522#define hubp_regs(id)\
523[id] = {\
524 HUBP_REG_LIST_DCN20(id)\
525}
526
527static const struct dcn_hubp2_registers hubp_regs[] = {
528 hubp_regs(0),
529 hubp_regs(1),
530 hubp_regs(2),
531 hubp_regs(3),
532 hubp_regs(4),
533 hubp_regs(5)
534};
535
536static const struct dcn_hubp2_shift hubp_shift = {
537 HUBP_MASK_SH_LIST_DCN20(__SHIFT)
538};
539
540static const struct dcn_hubp2_mask hubp_mask = {
541 HUBP_MASK_SH_LIST_DCN20(_MASK)
542};
543
544static const struct dcn_hubbub_registers hubbub_reg = {
545 HUBBUB_REG_LIST_DCN20(0)
546};
547
548static const struct dcn_hubbub_shift hubbub_shift = {
549 HUBBUB_MASK_SH_LIST_DCN20(__SHIFT)
550};
551
552static const struct dcn_hubbub_mask hubbub_mask = {
553 HUBBUB_MASK_SH_LIST_DCN20(_MASK)
554};
555
556#define vmid_regs(id)\
557[id] = {\
558 DCN20_VMID_REG_LIST(id)\
559}
560
561static const struct dcn_vmid_registers vmid_regs[] = {
562 vmid_regs(0),
563 vmid_regs(1),
564 vmid_regs(2),
565 vmid_regs(3),
566 vmid_regs(4),
567 vmid_regs(5),
568 vmid_regs(6),
569 vmid_regs(7),
570 vmid_regs(8),
571 vmid_regs(9),
572 vmid_regs(10),
573 vmid_regs(11),
574 vmid_regs(12),
575 vmid_regs(13),
576 vmid_regs(14),
577 vmid_regs(15)
578};
579
580static const struct dcn20_vmid_shift vmid_shifts = {
581 DCN20_VMID_MASK_SH_LIST(__SHIFT)
582};
583
584static const struct dcn20_vmid_mask vmid_masks = {
585 DCN20_VMID_MASK_SH_LIST(_MASK)
586};
587
8276dd87 588static const struct dce110_aux_registers_shift aux_shift = {
589 DCN_AUX_MASK_SH_LIST(__SHIFT)
590};
591
592static const struct dce110_aux_registers_mask aux_mask = {
593 DCN_AUX_MASK_SH_LIST(_MASK)
594};
595
bf7f5ac3
YMM
596static int map_transmitter_id_to_phy_instance(
597 enum transmitter transmitter)
598{
599 switch (transmitter) {
600 case TRANSMITTER_UNIPHY_A:
601 return 0;
602 break;
603 case TRANSMITTER_UNIPHY_B:
604 return 1;
605 break;
606 case TRANSMITTER_UNIPHY_C:
607 return 2;
608 break;
609 case TRANSMITTER_UNIPHY_D:
610 return 3;
611 break;
612 case TRANSMITTER_UNIPHY_E:
613 return 4;
614 break;
615 case TRANSMITTER_UNIPHY_F:
616 return 5;
617 break;
618 default:
619 ASSERT(0);
620 return 0;
621 }
622}
8276dd87 623
97bda032
HW
624#define dsc_regsDCN20(id)\
625[id] = {\
626 DSC_REG_LIST_DCN20(id)\
627}
628
629static const struct dcn20_dsc_registers dsc_regs[] = {
630 dsc_regsDCN20(0),
631 dsc_regsDCN20(1),
632 dsc_regsDCN20(2),
633 dsc_regsDCN20(3),
634 dsc_regsDCN20(4),
635 dsc_regsDCN20(5)
636};
637
638static const struct dcn20_dsc_shift dsc_shift = {
639 DSC_REG_LIST_SH_MASK_DCN20(__SHIFT)
640};
641
642static const struct dcn20_dsc_mask dsc_mask = {
643 DSC_REG_LIST_SH_MASK_DCN20(_MASK)
644};
7ed4e635
HW
645
646static const struct dccg_registers dccg_regs = {
647 DCCG_REG_LIST_DCN2()
648};
649
650static const struct dccg_shift dccg_shift = {
651 DCCG_MASK_SH_LIST_DCN2(__SHIFT)
652};
653
654static const struct dccg_mask dccg_mask = {
655 DCCG_MASK_SH_LIST_DCN2(_MASK)
656};
657
658static const struct resource_caps res_cap_nv10 = {
659 .num_timing_generator = 6,
660 .num_opp = 6,
661 .num_video_plane = 6,
662 .num_audio = 7,
663 .num_stream_encoder = 6,
664 .num_pll = 6,
9cbee6ef 665 .num_dwb = 1,
7ed4e635
HW
666 .num_ddc = 6,
667 .num_vmid = 16,
97bda032 668 .num_dsc = 6,
7ed4e635
HW
669};
670
671static const struct dc_plane_cap plane_cap = {
672 .type = DC_PLANE_TYPE_DCN_UNIVERSAL,
7ed4e635 673 .per_pixel_alpha = true,
5b1b2f20
AD
674
675 .pixel_format_support = {
676 .argb8888 = true,
677 .nv12 = true,
cbec6477
SW
678 .fp16 = true,
679 .p010 = true
5b1b2f20
AD
680 },
681
682 .max_upscale_factor = {
683 .argb8888 = 16000,
684 .nv12 = 16000,
685 .fp16 = 1
686 },
687
688 .max_downscale_factor = {
689 .argb8888 = 250,
690 .nv12 = 250,
691 .fp16 = 1
3b26ca2d
IK
692 },
693 16,
694 16
7ed4e635 695};
2ebe1773
BL
696static const struct resource_caps res_cap_nv14 = {
697 .num_timing_generator = 5,
698 .num_opp = 5,
699 .num_video_plane = 5,
700 .num_audio = 6,
701 .num_stream_encoder = 5,
702 .num_pll = 5,
80df905d 703 .num_dwb = 1,
2ebe1773 704 .num_ddc = 5,
6bb27085
ZL
705 .num_vmid = 16,
706 .num_dsc = 5,
2ebe1773 707};
7ed4e635
HW
708
709static const struct dc_debug_options debug_defaults_drv = {
f0a574c9 710 .disable_dmcu = false,
7ed4e635
HW
711 .force_abm_enable = false,
712 .timing_trace = false,
713 .clock_trace = true,
714 .disable_pplib_clock_request = true,
27dd79c0 715 .pipe_split_policy = MPC_SPLIT_DYNAMIC,
4d25a0d5 716 .force_single_disp_pipe_split = false,
7ed4e635
HW
717 .disable_dcc = DCC_ENABLE,
718 .vsr_support = true,
719 .performance_trace = false,
720 .max_downscale_src_width = 5120,/*upto 5K*/
721 .disable_pplib_wm_range = false,
722 .scl_reset_length10 = true,
9e14d4f1 723 .sanity_checks = false,
1a7d296d 724 .underflow_assert_delay_us = 0xFFFFFFFF,
7ed4e635
HW
725};
726
7ed4e635
HW
727void dcn20_dpp_destroy(struct dpp **dpp)
728{
729 kfree(TO_DCN20_DPP(*dpp));
730 *dpp = NULL;
731}
732
733struct dpp *dcn20_dpp_create(
734 struct dc_context *ctx,
735 uint32_t inst)
736{
737 struct dcn20_dpp *dpp =
3bb11050 738 kzalloc(sizeof(struct dcn20_dpp), GFP_ATOMIC);
7ed4e635
HW
739
740 if (!dpp)
741 return NULL;
742
743 if (dpp2_construct(dpp, ctx, inst,
744 &tf_regs[inst], &tf_shift, &tf_mask))
745 return &dpp->base;
746
747 BREAK_TO_DEBUGGER();
748 kfree(dpp);
749 return NULL;
750}
751
752struct input_pixel_processor *dcn20_ipp_create(
753 struct dc_context *ctx, uint32_t inst)
754{
755 struct dcn10_ipp *ipp =
3bb11050 756 kzalloc(sizeof(struct dcn10_ipp), GFP_ATOMIC);
7ed4e635
HW
757
758 if (!ipp) {
759 BREAK_TO_DEBUGGER();
760 return NULL;
761 }
762
763 dcn20_ipp_construct(ipp, ctx, inst,
764 &ipp_regs[inst], &ipp_shift, &ipp_mask);
765 return &ipp->base;
766}
767
768
769struct output_pixel_processor *dcn20_opp_create(
770 struct dc_context *ctx, uint32_t inst)
771{
772 struct dcn20_opp *opp =
3bb11050 773 kzalloc(sizeof(struct dcn20_opp), GFP_ATOMIC);
7ed4e635
HW
774
775 if (!opp) {
776 BREAK_TO_DEBUGGER();
777 return NULL;
778 }
779
780 dcn20_opp_construct(opp, ctx, inst,
781 &opp_regs[inst], &opp_shift, &opp_mask);
782 return &opp->base;
783}
784
785struct dce_aux *dcn20_aux_engine_create(
786 struct dc_context *ctx,
787 uint32_t inst)
788{
789 struct aux_engine_dce110 *aux_engine =
3bb11050 790 kzalloc(sizeof(struct aux_engine_dce110), GFP_ATOMIC);
7ed4e635
HW
791
792 if (!aux_engine)
793 return NULL;
794
795 dce110_aux_engine_construct(aux_engine, ctx, inst,
796 SW_AUX_TIMEOUT_PERIOD_MULTIPLIER * AUX_TIMEOUT_PERIOD,
8276dd87 797 &aux_engine_regs[inst],
798 &aux_mask,
f6040a43 799 &aux_shift,
800 ctx->dc->caps.extended_aux_timeout_support);
7ed4e635
HW
801
802 return &aux_engine->base;
803}
804#define i2c_inst_regs(id) { I2C_HW_ENGINE_COMMON_REG_LIST(id) }
805
806static const struct dce_i2c_registers i2c_hw_regs[] = {
807 i2c_inst_regs(1),
808 i2c_inst_regs(2),
809 i2c_inst_regs(3),
810 i2c_inst_regs(4),
811 i2c_inst_regs(5),
812 i2c_inst_regs(6),
813};
814
815static const struct dce_i2c_shift i2c_shifts = {
816 I2C_COMMON_MASK_SH_LIST_DCN2(__SHIFT)
817};
818
819static const struct dce_i2c_mask i2c_masks = {
820 I2C_COMMON_MASK_SH_LIST_DCN2(_MASK)
821};
822
823struct dce_i2c_hw *dcn20_i2c_hw_create(
824 struct dc_context *ctx,
825 uint32_t inst)
826{
827 struct dce_i2c_hw *dce_i2c_hw =
3bb11050 828 kzalloc(sizeof(struct dce_i2c_hw), GFP_ATOMIC);
7ed4e635
HW
829
830 if (!dce_i2c_hw)
831 return NULL;
832
833 dcn2_i2c_hw_construct(dce_i2c_hw, ctx, inst,
834 &i2c_hw_regs[inst], &i2c_shifts, &i2c_masks);
835
836 return dce_i2c_hw;
837}
838struct mpc *dcn20_mpc_create(struct dc_context *ctx)
839{
840 struct dcn20_mpc *mpc20 = kzalloc(sizeof(struct dcn20_mpc),
3bb11050 841 GFP_ATOMIC);
7ed4e635
HW
842
843 if (!mpc20)
844 return NULL;
845
846 dcn20_mpc_construct(mpc20, ctx,
847 &mpc_regs,
848 &mpc_shift,
849 &mpc_mask,
850 6);
851
852 return &mpc20->base;
853}
854
855struct hubbub *dcn20_hubbub_create(struct dc_context *ctx)
856{
857 int i;
858 struct dcn20_hubbub *hubbub = kzalloc(sizeof(struct dcn20_hubbub),
3bb11050 859 GFP_ATOMIC);
7ed4e635
HW
860
861 if (!hubbub)
862 return NULL;
863
864 hubbub2_construct(hubbub, ctx,
865 &hubbub_reg,
866 &hubbub_shift,
867 &hubbub_mask);
868
869 for (i = 0; i < res_cap_nv10.num_vmid; i++) {
870 struct dcn20_vmid *vmid = &hubbub->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 &hubbub->base;
880}
881
882struct timing_generator *dcn20_timing_generator_create(
883 struct dc_context *ctx,
884 uint32_t instance)
885{
886 struct optc *tgn10 =
3bb11050 887 kzalloc(sizeof(struct optc), GFP_ATOMIC);
7ed4e635
HW
888
889 if (!tgn10)
890 return NULL;
891
892 tgn10->base.inst = instance;
893 tgn10->base.ctx = ctx;
894
895 tgn10->tg_regs = &tg_regs[instance];
896 tgn10->tg_shift = &tg_shift;
897 tgn10->tg_mask = &tg_mask;
898
899 dcn20_timing_generator_init(tgn10);
900
901 return &tgn10->base;
902}
903
904static const struct encoder_feature_support link_enc_feature = {
905 .max_hdmi_deep_color = COLOR_DEPTH_121212,
906 .max_hdmi_pixel_clock = 600000,
907 .hdmi_ycbcr420_supported = true,
908 .dp_ycbcr420_supported = true,
c14b726e 909 .fec_supported = true,
7ed4e635
HW
910 .flags.bits.IS_HBR2_CAPABLE = true,
911 .flags.bits.IS_HBR3_CAPABLE = true,
912 .flags.bits.IS_TPS3_CAPABLE = true,
913 .flags.bits.IS_TPS4_CAPABLE = true
914};
915
916struct link_encoder *dcn20_link_encoder_create(
e216431b 917 struct dc_context *ctx,
7ed4e635
HW
918 const struct encoder_init_data *enc_init_data)
919{
920 struct dcn20_link_encoder *enc20 =
921 kzalloc(sizeof(struct dcn20_link_encoder), GFP_KERNEL);
bf7f5ac3 922 int link_regs_id;
7ed4e635
HW
923
924 if (!enc20)
925 return NULL;
926
bf7f5ac3
YMM
927 link_regs_id =
928 map_transmitter_id_to_phy_instance(enc_init_data->transmitter);
929
7ed4e635
HW
930 dcn20_link_encoder_construct(enc20,
931 enc_init_data,
932 &link_enc_feature,
bf7f5ac3 933 &link_enc_regs[link_regs_id],
7ed4e635
HW
934 &link_enc_aux_regs[enc_init_data->channel - 1],
935 &link_enc_hpd_regs[enc_init_data->hpd_source],
936 &le_shift,
937 &le_mask);
938
939 return &enc20->enc10.base;
940}
941
d4caa72e 942static struct panel_cntl *dcn20_panel_cntl_create(const struct panel_cntl_init_data *init_data)
904fb6e0 943{
d4caa72e
AK
944 struct dce_panel_cntl *panel_cntl =
945 kzalloc(sizeof(struct dce_panel_cntl), GFP_KERNEL);
904fb6e0 946
d4caa72e 947 if (!panel_cntl)
904fb6e0
AK
948 return NULL;
949
d4caa72e 950 dce_panel_cntl_construct(panel_cntl,
904fb6e0 951 init_data,
d4caa72e
AK
952 &panel_cntl_regs[init_data->inst],
953 &panel_cntl_shift,
954 &panel_cntl_mask);
904fb6e0 955
d4caa72e 956 return &panel_cntl->base;
904fb6e0
AK
957}
958
dfd84d90 959static struct clock_source *dcn20_clock_source_create(
7ed4e635
HW
960 struct dc_context *ctx,
961 struct dc_bios *bios,
962 enum clock_source_id id,
963 const struct dce110_clk_src_regs *regs,
964 bool dp_clk_src)
965{
966 struct dce110_clk_src *clk_src =
3bb11050 967 kzalloc(sizeof(struct dce110_clk_src), GFP_ATOMIC);
7ed4e635
HW
968
969 if (!clk_src)
970 return NULL;
971
972 if (dcn20_clk_src_construct(clk_src, ctx, bios, id,
973 regs, &cs_shift, &cs_mask)) {
974 clk_src->base.dp_clk_src = dp_clk_src;
975 return &clk_src->base;
976 }
977
cabe144b 978 kfree(clk_src);
7ed4e635
HW
979 BREAK_TO_DEBUGGER();
980 return NULL;
981}
982
983static void read_dce_straps(
984 struct dc_context *ctx,
985 struct resource_straps *straps)
986{
987 generic_reg_get(ctx, mmDC_PINSTRAPS + BASE(mmDC_PINSTRAPS_BASE_IDX),
988 FN(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO), &straps->dc_pinstraps_audio);
989}
990
991static struct audio *dcn20_create_audio(
992 struct dc_context *ctx, unsigned int inst)
993{
994 return dce_audio_create(ctx, inst,
995 &audio_regs[inst], &audio_shift, &audio_mask);
996}
997
998struct stream_encoder *dcn20_stream_encoder_create(
999 enum engine_id eng_id,
1000 struct dc_context *ctx)
1001{
1002 struct dcn10_stream_encoder *enc1 =
1003 kzalloc(sizeof(struct dcn10_stream_encoder), GFP_KERNEL);
1004
1005 if (!enc1)
1006 return NULL;
1007
9fd4c2d7
ZL
1008 if (ASICREV_IS_NAVI14_M(ctx->asic_id.hw_internal_rev)) {
1009 if (eng_id >= ENGINE_ID_DIGD)
1010 eng_id++;
1011 }
1012
7ed4e635
HW
1013 dcn20_stream_encoder_construct(enc1, ctx, ctx->dc_bios, eng_id,
1014 &stream_enc_regs[eng_id],
1015 &se_shift, &se_mask);
1016
1017 return &enc1->base;
1018}
1019
1020static const struct dce_hwseq_registers hwseq_reg = {
1021 HWSEQ_DCN2_REG_LIST()
1022};
1023
1024static const struct dce_hwseq_shift hwseq_shift = {
1025 HWSEQ_DCN2_MASK_SH_LIST(__SHIFT)
1026};
1027
1028static const struct dce_hwseq_mask hwseq_mask = {
1029 HWSEQ_DCN2_MASK_SH_LIST(_MASK)
1030};
1031
1032struct dce_hwseq *dcn20_hwseq_create(
1033 struct dc_context *ctx)
1034{
1035 struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL);
1036
1037 if (hws) {
1038 hws->ctx = ctx;
1039 hws->regs = &hwseq_reg;
1040 hws->shifts = &hwseq_shift;
1041 hws->masks = &hwseq_mask;
1042 }
1043 return hws;
1044}
1045
1046static const struct resource_create_funcs res_create_funcs = {
1047 .read_dce_straps = read_dce_straps,
1048 .create_audio = dcn20_create_audio,
1049 .create_stream_encoder = dcn20_stream_encoder_create,
1050 .create_hwseq = dcn20_hwseq_create,
1051};
1052
44e149bb
AD
1053static void dcn20_pp_smu_destroy(struct pp_smu_funcs **pp_smu);
1054
7ed4e635
HW
1055void dcn20_clock_source_destroy(struct clock_source **clk_src)
1056{
1057 kfree(TO_DCE110_CLK_SRC(*clk_src));
1058 *clk_src = NULL;
1059}
1060
97bda032
HW
1061
1062struct display_stream_compressor *dcn20_dsc_create(
1063 struct dc_context *ctx, uint32_t inst)
1064{
1065 struct dcn20_dsc *dsc =
3bb11050 1066 kzalloc(sizeof(struct dcn20_dsc), GFP_ATOMIC);
97bda032
HW
1067
1068 if (!dsc) {
1069 BREAK_TO_DEBUGGER();
1070 return NULL;
1071 }
1072
1073 dsc2_construct(dsc, ctx, inst, &dsc_regs[inst], &dsc_shift, &dsc_mask);
1074 return &dsc->base;
1075}
1076
1077void dcn20_dsc_destroy(struct display_stream_compressor **dsc)
1078{
1079 kfree(container_of(*dsc, struct dcn20_dsc, base));
1080 *dsc = NULL;
1081}
1082
7ed4e635 1083
d9e32672 1084static void dcn20_resource_destruct(struct dcn20_resource_pool *pool)
7ed4e635
HW
1085{
1086 unsigned int i;
1087
1088 for (i = 0; i < pool->base.stream_enc_count; i++) {
1089 if (pool->base.stream_enc[i] != NULL) {
1090 kfree(DCN10STRENC_FROM_STRENC(pool->base.stream_enc[i]));
1091 pool->base.stream_enc[i] = NULL;
1092 }
1093 }
1094
97bda032
HW
1095 for (i = 0; i < pool->base.res_cap->num_dsc; i++) {
1096 if (pool->base.dscs[i] != NULL)
1097 dcn20_dsc_destroy(&pool->base.dscs[i]);
1098 }
7ed4e635
HW
1099
1100 if (pool->base.mpc != NULL) {
1101 kfree(TO_DCN20_MPC(pool->base.mpc));
1102 pool->base.mpc = NULL;
1103 }
1104 if (pool->base.hubbub != NULL) {
1105 kfree(pool->base.hubbub);
1106 pool->base.hubbub = NULL;
1107 }
1108 for (i = 0; i < pool->base.pipe_count; i++) {
1109 if (pool->base.dpps[i] != NULL)
1110 dcn20_dpp_destroy(&pool->base.dpps[i]);
1111
1112 if (pool->base.ipps[i] != NULL)
1113 pool->base.ipps[i]->funcs->ipp_destroy(&pool->base.ipps[i]);
1114
1115 if (pool->base.hubps[i] != NULL) {
1116 kfree(TO_DCN20_HUBP(pool->base.hubps[i]));
1117 pool->base.hubps[i] = NULL;
1118 }
1119
1120 if (pool->base.irqs != NULL) {
1121 dal_irq_service_destroy(&pool->base.irqs);
1122 }
1123 }
1124
1125 for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
1126 if (pool->base.engines[i] != NULL)
1127 dce110_engine_destroy(&pool->base.engines[i]);
1128 if (pool->base.hw_i2cs[i] != NULL) {
1129 kfree(pool->base.hw_i2cs[i]);
1130 pool->base.hw_i2cs[i] = NULL;
1131 }
1132 if (pool->base.sw_i2cs[i] != NULL) {
1133 kfree(pool->base.sw_i2cs[i]);
1134 pool->base.sw_i2cs[i] = NULL;
1135 }
1136 }
1137
1138 for (i = 0; i < pool->base.res_cap->num_opp; i++) {
1139 if (pool->base.opps[i] != NULL)
1140 pool->base.opps[i]->funcs->opp_destroy(&pool->base.opps[i]);
1141 }
1142
1143 for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) {
1144 if (pool->base.timing_generators[i] != NULL) {
1145 kfree(DCN10TG_FROM_TG(pool->base.timing_generators[i]));
1146 pool->base.timing_generators[i] = NULL;
1147 }
1148 }
1149
bb21290f
CL
1150 for (i = 0; i < pool->base.res_cap->num_dwb; i++) {
1151 if (pool->base.dwbc[i] != NULL) {
1152 kfree(TO_DCN20_DWBC(pool->base.dwbc[i]));
1153 pool->base.dwbc[i] = NULL;
1154 }
1155 if (pool->base.mcif_wb[i] != NULL) {
1156 kfree(TO_DCN20_MMHUBBUB(pool->base.mcif_wb[i]));
1157 pool->base.mcif_wb[i] = NULL;
1158 }
1159 }
1160
7ed4e635
HW
1161 for (i = 0; i < pool->base.audio_count; i++) {
1162 if (pool->base.audios[i])
1163 dce_aud_destroy(&pool->base.audios[i]);
1164 }
1165
1166 for (i = 0; i < pool->base.clk_src_count; i++) {
1167 if (pool->base.clock_sources[i] != NULL) {
1168 dcn20_clock_source_destroy(&pool->base.clock_sources[i]);
1169 pool->base.clock_sources[i] = NULL;
1170 }
1171 }
1172
1173 if (pool->base.dp_clock_source != NULL) {
1174 dcn20_clock_source_destroy(&pool->base.dp_clock_source);
1175 pool->base.dp_clock_source = NULL;
1176 }
1177
1178
1179 if (pool->base.abm != NULL)
1180 dce_abm_destroy(&pool->base.abm);
1181
1182 if (pool->base.dmcu != NULL)
1183 dce_dmcu_destroy(&pool->base.dmcu);
1184
1185 if (pool->base.dccg != NULL)
1186 dcn_dccg_destroy(&pool->base.dccg);
1187
1188 if (pool->base.pp_smu != NULL)
1189 dcn20_pp_smu_destroy(&pool->base.pp_smu);
1190
98ce7d32
WL
1191 if (pool->base.oem_device != NULL) {
1192 struct dc *dc = pool->base.oem_device->ctx->dc;
1193
1194 dc->link_srv->destroy_ddc_service(&pool->base.oem_device);
1195 }
7ed4e635
HW
1196}
1197
1198struct hubp *dcn20_hubp_create(
1199 struct dc_context *ctx,
1200 uint32_t inst)
1201{
1202 struct dcn20_hubp *hubp2 =
3bb11050 1203 kzalloc(sizeof(struct dcn20_hubp), GFP_ATOMIC);
7ed4e635
HW
1204
1205 if (!hubp2)
1206 return NULL;
1207
1208 if (hubp2_construct(hubp2, ctx, inst,
1209 &hubp_regs[inst], &hubp_shift, &hubp_mask))
1210 return &hubp2->base;
1211
1212 BREAK_TO_DEBUGGER();
1213 kfree(hubp2);
1214 return NULL;
1215}
1216
1217static void get_pixel_clock_parameters(
1218 struct pipe_ctx *pipe_ctx,
1219 struct pixel_clk_params *pixel_clk_params)
1220{
1221 const struct dc_stream_state *stream = pipe_ctx->stream;
b1f6d01c
DL
1222 struct pipe_ctx *odm_pipe;
1223 int opp_cnt = 1;
64d283cb
JK
1224 struct dc_link *link = stream->link;
1225 struct link_encoder *link_enc = NULL;
88ef4c5b
ST
1226 struct dc *dc = pipe_ctx->stream->ctx->dc;
1227 struct dce_hwseq *hws = dc->hwseq;
b1f6d01c
DL
1228
1229 for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe)
1230 opp_cnt++;
7ed4e635
HW
1231
1232 pixel_clk_params->requested_pix_clk_100hz = stream->timing.pix_clk_100hz;
64d283cb 1233
66d58bf7 1234 link_enc = link_enc_cfg_get_link_enc(link);
64d283cb
JK
1235 if (link_enc)
1236 pixel_clk_params->encoder_object_id = link_enc->id;
0c7ea6f8 1237
7ed4e635
HW
1238 pixel_clk_params->signal_type = pipe_ctx->stream->signal;
1239 pixel_clk_params->controller_id = pipe_ctx->stream_res.tg->inst + 1;
1240 /* TODO: un-hardcode*/
f01ee019 1241 /* TODO - DP2.0 HW: calculate requested_sym_clk for UHBR rates */
7ed4e635
HW
1242 pixel_clk_params->requested_sym_clk = LINK_RATE_LOW *
1243 LINK_RATE_REF_FREQ_IN_KHZ;
1244 pixel_clk_params->flags.ENABLE_SS = 0;
1245 pixel_clk_params->color_depth =
1246 stream->timing.display_color_depth;
1247 pixel_clk_params->flags.DISPLAY_BLANKED = 1;
1248 pixel_clk_params->pixel_encoding = stream->timing.pixel_encoding;
1249
1250 if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR422)
1251 pixel_clk_params->color_depth = COLOR_DEPTH_888;
1252
b1f6d01c
DL
1253 if (opp_cnt == 4)
1254 pixel_clk_params->requested_pix_clk_100hz /= 4;
78c77382 1255 else if (optc2_is_two_pixels_per_containter(&stream->timing) || opp_cnt == 2)
7ed4e635 1256 pixel_clk_params->requested_pix_clk_100hz /= 2;
88ef4c5b
ST
1257 else if (hws->funcs.is_dp_dig_pixel_rate_div_policy) {
1258 if (hws->funcs.is_dp_dig_pixel_rate_div_policy(pipe_ctx))
1259 pixel_clk_params->requested_pix_clk_100hz /= 2;
1260 }
1261
7ed4e635
HW
1262 if (stream->timing.timing_3d_format == TIMING_3D_FORMAT_HW_FRAME_PACKING)
1263 pixel_clk_params->requested_pix_clk_100hz *= 2;
1264
1265}
1266
1267static void build_clamping_params(struct dc_stream_state *stream)
1268{
1269 stream->clamping.clamping_level = CLAMPING_FULL_RANGE;
1270 stream->clamping.c_depth = stream->timing.display_color_depth;
1271 stream->clamping.pixel_encoding = stream->timing.pixel_encoding;
1272}
1273
1274static enum dc_status build_pipe_hw_param(struct pipe_ctx *pipe_ctx)
1275{
1276
1277 get_pixel_clock_parameters(pipe_ctx, &pipe_ctx->stream_res.pix_clk_params);
1278
1279 pipe_ctx->clock_source->funcs->get_pix_clk_dividers(
1280 pipe_ctx->clock_source,
1281 &pipe_ctx->stream_res.pix_clk_params,
1282 &pipe_ctx->pll_settings);
1283
1284 pipe_ctx->stream->clamping.pixel_encoding = pipe_ctx->stream->timing.pixel_encoding;
1285
1286 resource_build_bit_depth_reduction_params(pipe_ctx->stream,
1287 &pipe_ctx->stream->bit_depth_params);
1288 build_clamping_params(pipe_ctx->stream);
1289
1290 return DC_OK;
1291}
1292
1293enum dc_status dcn20_build_mapped_resource(const struct dc *dc, struct dc_state *context, struct dc_stream_state *stream)
1294{
1295 enum dc_status status = DC_OK;
1296 struct pipe_ctx *pipe_ctx = resource_get_head_pipe_for_stream(&context->res_ctx, stream);
1297
7ed4e635
HW
1298 if (!pipe_ctx)
1299 return DC_ERROR_UNEXPECTED;
1300
1301
1302 status = build_pipe_hw_param(pipe_ctx);
1303
1304 return status;
1305}
1306
97bda032 1307
570bc18c 1308void dcn20_acquire_dsc(const struct dc *dc,
14e49bb3 1309 struct resource_context *res_ctx,
eab4bb97
NC
1310 struct display_stream_compressor **dsc,
1311 int pipe_idx)
97bda032
HW
1312{
1313 int i;
14e49bb3
NC
1314 const struct resource_pool *pool = dc->res_pool;
1315 struct display_stream_compressor *dsc_old = dc->current_state->res_ctx.pipe_ctx[pipe_idx].stream_res.dsc;
c9ae6e16 1316
14e49bb3 1317 ASSERT(*dsc == NULL); /* If this ASSERT fails, dsc was not released properly */
c9ae6e16 1318 *dsc = NULL;
97bda032 1319
14e49bb3 1320 /* Always do 1-to-1 mapping when number of DSCs is same as number of pipes */
eab4bb97
NC
1321 if (pool->res_cap->num_dsc == pool->res_cap->num_opp) {
1322 *dsc = pool->dscs[pipe_idx];
1323 res_ctx->is_dsc_acquired[pipe_idx] = true;
1324 return;
1325 }
1326
14e49bb3
NC
1327 /* Return old DSC to avoid the need for re-programming */
1328 if (dsc_old && !res_ctx->is_dsc_acquired[dsc_old->inst]) {
1329 *dsc = dsc_old;
1330 res_ctx->is_dsc_acquired[dsc_old->inst] = true;
1331 return ;
1332 }
1333
97bda032
HW
1334 /* Find first free DSC */
1335 for (i = 0; i < pool->res_cap->num_dsc; i++)
1336 if (!res_ctx->is_dsc_acquired[i]) {
c9ae6e16 1337 *dsc = pool->dscs[i];
97bda032
HW
1338 res_ctx->is_dsc_acquired[i] = true;
1339 break;
1340 }
97bda032
HW
1341}
1342
7287a675 1343void dcn20_release_dsc(struct resource_context *res_ctx,
97bda032 1344 const struct resource_pool *pool,
c9ae6e16 1345 struct display_stream_compressor **dsc)
97bda032
HW
1346{
1347 int i;
1348
1349 for (i = 0; i < pool->res_cap->num_dsc; i++)
c9ae6e16 1350 if (pool->dscs[i] == *dsc) {
97bda032 1351 res_ctx->is_dsc_acquired[i] = false;
c9ae6e16 1352 *dsc = NULL;
97bda032
HW
1353 break;
1354 }
1355}
1356
7ed4e635 1357
7ed4e635 1358
8c20a1ed 1359enum dc_status dcn20_add_dsc_to_stream_resource(struct dc *dc,
c9ae6e16
NC
1360 struct dc_state *dc_ctx,
1361 struct dc_stream_state *dc_stream)
1362{
1363 enum dc_status result = DC_OK;
1364 int i;
97bda032 1365
c9ae6e16
NC
1366 /* Get a DSC if required and available */
1367 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1368 struct pipe_ctx *pipe_ctx = &dc_ctx->res_ctx.pipe_ctx[i];
97bda032 1369
2e68ad8f
BL
1370 if (pipe_ctx->top_pipe)
1371 continue;
1372
c9ae6e16
NC
1373 if (pipe_ctx->stream != dc_stream)
1374 continue;
97bda032 1375
8c20a1ed
DF
1376 if (pipe_ctx->stream_res.dsc)
1377 continue;
1378
570bc18c 1379 dcn20_acquire_dsc(dc, &dc_ctx->res_ctx, &pipe_ctx->stream_res.dsc, i);
97bda032 1380
c9ae6e16
NC
1381 /* The number of DSCs can be less than the number of pipes */
1382 if (!pipe_ctx->stream_res.dsc) {
c9ae6e16 1383 result = DC_NO_DSC_RESOURCE;
97bda032 1384 }
7ed4e635 1385
c9ae6e16
NC
1386 break;
1387 }
7ed4e635
HW
1388
1389 return result;
1390}
1391
1392
ba32c50f 1393static enum dc_status remove_dsc_from_stream_resource(struct dc *dc,
c9ae6e16
NC
1394 struct dc_state *new_ctx,
1395 struct dc_stream_state *dc_stream)
7ed4e635
HW
1396{
1397 struct pipe_ctx *pipe_ctx = NULL;
1398 int i;
1399
7ed4e635
HW
1400 for (i = 0; i < MAX_PIPES; i++) {
1401 if (new_ctx->res_ctx.pipe_ctx[i].stream == dc_stream && !new_ctx->res_ctx.pipe_ctx[i].top_pipe) {
1402 pipe_ctx = &new_ctx->res_ctx.pipe_ctx[i];
b1f6d01c
DL
1403
1404 if (pipe_ctx->stream_res.dsc)
7287a675 1405 dcn20_release_dsc(&new_ctx->res_ctx, dc->res_pool, &pipe_ctx->stream_res.dsc);
7ed4e635
HW
1406 }
1407 }
1408
1409 if (!pipe_ctx)
1410 return DC_ERROR_UNEXPECTED;
b1f6d01c
DL
1411 else
1412 return DC_OK;
7ed4e635 1413}
c9ae6e16
NC
1414
1415
1416enum dc_status dcn20_add_stream_to_ctx(struct dc *dc, struct dc_state *new_ctx, struct dc_stream_state *dc_stream)
1417{
1418 enum dc_status result = DC_ERROR_UNEXPECTED;
1419
1420 result = resource_map_pool_resources(dc, new_ctx, dc_stream);
1421
1422 if (result == DC_OK)
1423 result = resource_map_phy_clock_resources(dc, new_ctx, dc_stream);
1424
c9ae6e16
NC
1425 /* Get a DSC if required and available */
1426 if (result == DC_OK && dc_stream->timing.flags.DSC)
8c20a1ed 1427 result = dcn20_add_dsc_to_stream_resource(dc, new_ctx, dc_stream);
c9ae6e16
NC
1428
1429 if (result == DC_OK)
1430 result = dcn20_build_mapped_resource(dc, new_ctx, dc_stream);
1431
1432 return result;
1433}
1434
1435
1436enum dc_status dcn20_remove_stream_from_ctx(struct dc *dc, struct dc_state *new_ctx, struct dc_stream_state *dc_stream)
1437{
1438 enum dc_status result = DC_OK;
1439
ba32c50f 1440 result = remove_dsc_from_stream_resource(dc, new_ctx, dc_stream);
c9ae6e16
NC
1441
1442 return result;
1443}
7ed4e635 1444
a6126e14
RS
1445/**
1446 * dcn20_split_stream_for_odm - Check if stream can be splited for ODM
1447 *
1448 * @dc: DC object with resource pool info required for pipe split
1449 * @res_ctx: Persistent state of resources
1450 * @prev_odm_pipe: Reference to the previous ODM pipe
1451 * @next_odm_pipe: Reference to the next ODM pipe
1452 *
1453 * This function takes a logically active pipe and a logically free pipe and
1454 * halves all the scaling parameters that need to be halved while populating
1455 * the free pipe with the required resources and configuring the next/previous
1456 * ODM pipe pointers.
1457 *
1458 * Return:
1459 * Return true if split stream for ODM is possible, otherwise, return false.
1460 */
b6bfba6c 1461bool dcn20_split_stream_for_odm(
14e49bb3 1462 const struct dc *dc,
b1f6d01c 1463 struct resource_context *res_ctx,
b1f6d01c
DL
1464 struct pipe_ctx *prev_odm_pipe,
1465 struct pipe_ctx *next_odm_pipe)
1466{
1467 int pipe_idx = next_odm_pipe->pipe_idx;
14e49bb3 1468 const struct resource_pool *pool = dc->res_pool;
b1f6d01c
DL
1469
1470 *next_odm_pipe = *prev_odm_pipe;
b1f6d01c
DL
1471
1472 next_odm_pipe->pipe_idx = pipe_idx;
1473 next_odm_pipe->plane_res.mi = pool->mis[next_odm_pipe->pipe_idx];
1474 next_odm_pipe->plane_res.hubp = pool->hubps[next_odm_pipe->pipe_idx];
1475 next_odm_pipe->plane_res.ipp = pool->ipps[next_odm_pipe->pipe_idx];
1476 next_odm_pipe->plane_res.xfm = pool->transforms[next_odm_pipe->pipe_idx];
1477 next_odm_pipe->plane_res.dpp = pool->dpps[next_odm_pipe->pipe_idx];
1478 next_odm_pipe->plane_res.mpcc_inst = pool->dpps[next_odm_pipe->pipe_idx]->inst;
b1f6d01c 1479 next_odm_pipe->stream_res.dsc = NULL;
b1f6d01c 1480 if (prev_odm_pipe->next_odm_pipe && prev_odm_pipe->next_odm_pipe != next_odm_pipe) {
b1f6d01c
DL
1481 next_odm_pipe->next_odm_pipe = prev_odm_pipe->next_odm_pipe;
1482 next_odm_pipe->next_odm_pipe->prev_odm_pipe = next_odm_pipe;
1483 }
2e7b43e6
DL
1484 if (prev_odm_pipe->top_pipe && prev_odm_pipe->top_pipe->next_odm_pipe) {
1485 prev_odm_pipe->top_pipe->next_odm_pipe->bottom_pipe = next_odm_pipe;
1486 next_odm_pipe->top_pipe = prev_odm_pipe->top_pipe->next_odm_pipe;
1487 }
1488 if (prev_odm_pipe->bottom_pipe && prev_odm_pipe->bottom_pipe->next_odm_pipe) {
1489 prev_odm_pipe->bottom_pipe->next_odm_pipe->top_pipe = next_odm_pipe;
1490 next_odm_pipe->bottom_pipe = prev_odm_pipe->bottom_pipe->next_odm_pipe;
1491 }
b1f6d01c
DL
1492 prev_odm_pipe->next_odm_pipe = next_odm_pipe;
1493 next_odm_pipe->prev_odm_pipe = prev_odm_pipe;
b1f6d01c
DL
1494
1495 if (prev_odm_pipe->plane_state) {
c0358809
DL
1496 struct scaler_data *sd = &prev_odm_pipe->plane_res.scl_data;
1497 int new_width;
1498
b1f6d01c
DL
1499 /* HACTIVE halved for odm combine */
1500 sd->h_active /= 2;
b1f6d01c
DL
1501 /* Calculate new vp and recout for left pipe */
1502 /* Need at least 16 pixels width per side */
1503 if (sd->recout.x + 16 >= sd->h_active)
1504 return false;
1505 new_width = sd->h_active - sd->recout.x;
1506 sd->viewport.width -= dc_fixpt_floor(dc_fixpt_mul_int(
1507 sd->ratios.horz, sd->recout.width - new_width));
1508 sd->viewport_c.width -= dc_fixpt_floor(dc_fixpt_mul_int(
1509 sd->ratios.horz_c, sd->recout.width - new_width));
1510 sd->recout.width = new_width;
1511
1512 /* Calculate new vp and recout for right pipe */
1513 sd = &next_odm_pipe->plane_res.scl_data;
c0358809
DL
1514 /* HACTIVE halved for odm combine */
1515 sd->h_active /= 2;
b1f6d01c
DL
1516 /* Need at least 16 pixels width per side */
1517 if (new_width <= 16)
1518 return false;
c0358809 1519 new_width = sd->recout.width + sd->recout.x - sd->h_active;
b1f6d01c
DL
1520 sd->viewport.width -= dc_fixpt_floor(dc_fixpt_mul_int(
1521 sd->ratios.horz, sd->recout.width - new_width));
1522 sd->viewport_c.width -= dc_fixpt_floor(dc_fixpt_mul_int(
1523 sd->ratios.horz_c, sd->recout.width - new_width));
1524 sd->recout.width = new_width;
1525 sd->viewport.x += dc_fixpt_floor(dc_fixpt_mul_int(
1526 sd->ratios.horz, sd->h_active - sd->recout.x));
1527 sd->viewport_c.x += dc_fixpt_floor(dc_fixpt_mul_int(
1528 sd->ratios.horz_c, sd->h_active - sd->recout.x));
1529 sd->recout.x = 0;
1530 }
2e7b43e6
DL
1531 if (!next_odm_pipe->top_pipe)
1532 next_odm_pipe->stream_res.opp = pool->opps[next_odm_pipe->pipe_idx];
1533 else
1534 next_odm_pipe->stream_res.opp = next_odm_pipe->top_pipe->stream_res.opp;
73d48f08 1535 if (next_odm_pipe->stream->timing.flags.DSC == 1 && !next_odm_pipe->top_pipe) {
570bc18c 1536 dcn20_acquire_dsc(dc, res_ctx, &next_odm_pipe->stream_res.dsc, next_odm_pipe->pipe_idx);
b1f6d01c
DL
1537 ASSERT(next_odm_pipe->stream_res.dsc);
1538 if (next_odm_pipe->stream_res.dsc == NULL)
1539 return false;
1540 }
b1f6d01c
DL
1541
1542 return true;
1543}
1544
65d68369 1545void dcn20_split_stream_for_mpc(
7ed4e635
HW
1546 struct resource_context *res_ctx,
1547 const struct resource_pool *pool,
1548 struct pipe_ctx *primary_pipe,
b1f6d01c 1549 struct pipe_ctx *secondary_pipe)
7ed4e635
HW
1550{
1551 int pipe_idx = secondary_pipe->pipe_idx;
7ed4e635 1552 struct pipe_ctx *sec_bot_pipe = secondary_pipe->bottom_pipe;
7ed4e635
HW
1553
1554 *secondary_pipe = *primary_pipe;
1555 secondary_pipe->bottom_pipe = sec_bot_pipe;
1556
1557 secondary_pipe->pipe_idx = pipe_idx;
1558 secondary_pipe->plane_res.mi = pool->mis[secondary_pipe->pipe_idx];
1559 secondary_pipe->plane_res.hubp = pool->hubps[secondary_pipe->pipe_idx];
1560 secondary_pipe->plane_res.ipp = pool->ipps[secondary_pipe->pipe_idx];
1561 secondary_pipe->plane_res.xfm = pool->transforms[secondary_pipe->pipe_idx];
1562 secondary_pipe->plane_res.dpp = pool->dpps[secondary_pipe->pipe_idx];
1563 secondary_pipe->plane_res.mpcc_inst = pool->dpps[secondary_pipe->pipe_idx]->inst;
c92b4c46 1564 secondary_pipe->stream_res.dsc = NULL;
7ed4e635
HW
1565 if (primary_pipe->bottom_pipe && primary_pipe->bottom_pipe != secondary_pipe) {
1566 ASSERT(!secondary_pipe->bottom_pipe);
1567 secondary_pipe->bottom_pipe = primary_pipe->bottom_pipe;
1568 secondary_pipe->bottom_pipe->top_pipe = secondary_pipe;
1569 }
1570 primary_pipe->bottom_pipe = secondary_pipe;
1571 secondary_pipe->top_pipe = primary_pipe;
1572
b1f6d01c 1573 ASSERT(primary_pipe->plane_state);
7ed4e635
HW
1574}
1575
7ed4e635
HW
1576unsigned int dcn20_calc_max_scaled_time(
1577 unsigned int time_per_pixel,
1578 enum mmhubbub_wbif_mode mode,
1579 unsigned int urgent_watermark)
1580{
1581 unsigned int time_per_byte = 0;
1582 unsigned int total_y_free_entry = 0x200; /* two memory piece for luma */
1583 unsigned int total_c_free_entry = 0x140; /* two memory piece for chroma */
1584 unsigned int small_free_entry, max_free_entry;
1585 unsigned int buf_lh_capability;
1586 unsigned int max_scaled_time;
1587
1588 if (mode == PACKED_444) /* packed mode */
1589 time_per_byte = time_per_pixel/4;
1590 else if (mode == PLANAR_420_8BPC)
1591 time_per_byte = time_per_pixel;
1592 else if (mode == PLANAR_420_10BPC) /* p010 */
1593 time_per_byte = time_per_pixel * 819/1024;
1594
1595 if (time_per_byte == 0)
1596 time_per_byte = 1;
1597
1598 small_free_entry = (total_y_free_entry > total_c_free_entry) ? total_c_free_entry : total_y_free_entry;
1599 max_free_entry = (mode == PACKED_444) ? total_y_free_entry + total_c_free_entry : small_free_entry;
1600 buf_lh_capability = max_free_entry*time_per_byte*32/16; /* there is 4bit fraction */
1601 max_scaled_time = buf_lh_capability - urgent_watermark;
1602 return max_scaled_time;
1603}
1604
1605void dcn20_set_mcif_arb_params(
1606 struct dc *dc,
1607 struct dc_state *context,
1608 display_e2e_pipe_params_st *pipes,
1609 int pipe_cnt)
1610{
1611 enum mmhubbub_wbif_mode wbif_mode;
1612 struct mcif_arb_params *wb_arb_params;
cf689e86 1613 int i, j, dwb_pipe;
7ed4e635
HW
1614
1615 /* Writeback MCIF_WB arbitration parameters */
1616 dwb_pipe = 0;
1617 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1618
1619 if (!context->res_ctx.pipe_ctx[i].stream)
1620 continue;
1621
1622 for (j = 0; j < MAX_DWB_PIPES; j++) {
1623 if (context->res_ctx.pipe_ctx[i].stream->writeback_info[j].wb_enabled == false)
1624 continue;
1625
1626 //wb_arb_params = &context->res_ctx.pipe_ctx[i].stream->writeback_info[j].mcif_arb_params;
1627 wb_arb_params = &context->bw_ctx.bw.dcn.bw_writeback.mcif_wb_arb[dwb_pipe];
1628
1629 if (context->res_ctx.pipe_ctx[i].stream->writeback_info[j].dwb_params.out_format == dwb_scaler_mode_yuv420) {
1630 if (context->res_ctx.pipe_ctx[i].stream->writeback_info[j].dwb_params.output_depth == DWB_OUTPUT_PIXEL_DEPTH_8BPC)
1631 wbif_mode = PLANAR_420_8BPC;
1632 else
1633 wbif_mode = PLANAR_420_10BPC;
1634 } else
1635 wbif_mode = PACKED_444;
1636
cf689e86
MW
1637 DC_FP_START();
1638 dcn20_fpu_set_wb_arb_params(wb_arb_params, context, pipes, pipe_cnt, i);
1639 DC_FP_END();
1640
7ed4e635
HW
1641 wb_arb_params->slice_lines = 32;
1642 wb_arb_params->arbitration_slice = 2;
1643 wb_arb_params->max_scaled_time = dcn20_calc_max_scaled_time(wb_arb_params->time_per_pixel,
1644 wbif_mode,
1645 wb_arb_params->cli_watermark[0]); /* assume 4 watermark sets have the same value */
1646
1647 dwb_pipe++;
1648
1649 if (dwb_pipe >= MAX_DWB_PIPES)
1650 return;
1651 }
1652 if (dwb_pipe >= MAX_DWB_PIPES)
1653 return;
1654 }
1655}
1656
b6bfba6c 1657bool dcn20_validate_dsc(struct dc *dc, struct dc_state *new_ctx)
0ba37b20
DL
1658{
1659 int i;
1660
1661 /* Validate DSC config, dsc count validation is already done */
1662 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1663 struct pipe_ctx *pipe_ctx = &new_ctx->res_ctx.pipe_ctx[i];
1664 struct dc_stream_state *stream = pipe_ctx->stream;
1665 struct dsc_config dsc_cfg;
b1f6d01c
DL
1666 struct pipe_ctx *odm_pipe;
1667 int opp_cnt = 1;
1668
1669 for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe)
1670 opp_cnt++;
0ba37b20
DL
1671
1672 /* Only need to validate top pipe */
b1f6d01c 1673 if (pipe_ctx->top_pipe || pipe_ctx->prev_odm_pipe || !stream || !stream->timing.flags.DSC)
0ba37b20
DL
1674 continue;
1675
b1f6d01c
DL
1676 dsc_cfg.pic_width = (stream->timing.h_addressable + stream->timing.h_border_left
1677 + stream->timing.h_border_right) / opp_cnt;
0ba37b20
DL
1678 dsc_cfg.pic_height = stream->timing.v_addressable + stream->timing.v_border_top
1679 + stream->timing.v_border_bottom;
0ba37b20
DL
1680 dsc_cfg.pixel_encoding = stream->timing.pixel_encoding;
1681 dsc_cfg.color_depth = stream->timing.display_color_depth;
df8e34ac 1682 dsc_cfg.is_odm = pipe_ctx->next_odm_pipe ? true : false;
0ba37b20 1683 dsc_cfg.dc_dsc_cfg = stream->timing.dsc_cfg;
b1f6d01c 1684 dsc_cfg.dc_dsc_cfg.num_slices_h /= opp_cnt;
0ba37b20
DL
1685
1686 if (!pipe_ctx->stream_res.dsc->funcs->dsc_validate_stream(pipe_ctx->stream_res.dsc, &dsc_cfg))
1687 return false;
1688 }
1689 return true;
1690}
0ba37b20 1691
b6bfba6c 1692struct pipe_ctx *dcn20_find_secondary_pipe(struct dc *dc,
c681491a
JL
1693 struct resource_context *res_ctx,
1694 const struct resource_pool *pool,
1695 const struct pipe_ctx *primary_pipe)
1696{
1697 struct pipe_ctx *secondary_pipe = NULL;
1698
1699 if (dc && primary_pipe) {
1700 int j;
1701 int preferred_pipe_idx = 0;
1702
1703 /* first check the prev dc state:
1704 * if this primary pipe has a bottom pipe in prev. state
1705 * and if the bottom pipe is still available (which it should be),
1706 * pick that pipe as secondary
7a214cd8 1707 * Same logic applies for ODM pipes
c681491a 1708 */
324b1fcb 1709 if (dc->current_state->res_ctx.pipe_ctx[primary_pipe->pipe_idx].next_odm_pipe) {
1710 preferred_pipe_idx = dc->current_state->res_ctx.pipe_ctx[primary_pipe->pipe_idx].next_odm_pipe->pipe_idx;
c681491a
JL
1711 if (res_ctx->pipe_ctx[preferred_pipe_idx].stream == NULL) {
1712 secondary_pipe = &res_ctx->pipe_ctx[preferred_pipe_idx];
1713 secondary_pipe->pipe_idx = preferred_pipe_idx;
1714 }
7a214cd8
SL
1715 }
1716 if (secondary_pipe == NULL &&
324b1fcb 1717 dc->current_state->res_ctx.pipe_ctx[primary_pipe->pipe_idx].bottom_pipe) {
1718 preferred_pipe_idx = dc->current_state->res_ctx.pipe_ctx[primary_pipe->pipe_idx].bottom_pipe->pipe_idx;
b1f6d01c
DL
1719 if (res_ctx->pipe_ctx[preferred_pipe_idx].stream == NULL) {
1720 secondary_pipe = &res_ctx->pipe_ctx[preferred_pipe_idx];
1721 secondary_pipe->pipe_idx = preferred_pipe_idx;
1722 }
c681491a
JL
1723 }
1724
1725 /*
1726 * if this primary pipe does not have a bottom pipe in prev. state
1727 * start backward and find a pipe that did not used to be a bottom pipe in
1728 * prev. dc state. This way we make sure we keep the same assignment as
1729 * last state and will not have to reprogram every pipe
1730 */
1731 if (secondary_pipe == NULL) {
1732 for (j = dc->res_pool->pipe_count - 1; j >= 0; j--) {
8b8eda01
DL
1733 if (dc->current_state->res_ctx.pipe_ctx[j].top_pipe == NULL
1734 && dc->current_state->res_ctx.pipe_ctx[j].prev_odm_pipe == NULL) {
c681491a
JL
1735 preferred_pipe_idx = j;
1736
1737 if (res_ctx->pipe_ctx[preferred_pipe_idx].stream == NULL) {
1738 secondary_pipe = &res_ctx->pipe_ctx[preferred_pipe_idx];
1739 secondary_pipe->pipe_idx = preferred_pipe_idx;
1740 break;
1741 }
1742 }
1743 }
1744 }
1745 /*
1746 * We should never hit this assert unless assignments are shuffled around
1747 * if this happens we will prob. hit a vsync tdr
1748 */
1749 ASSERT(secondary_pipe);
1750 /*
1751 * search backwards for the second pipe to keep pipe
1752 * assignment more consistent
1753 */
1754 if (secondary_pipe == NULL) {
1755 for (j = dc->res_pool->pipe_count - 1; j >= 0; j--) {
1756 preferred_pipe_idx = j;
1757
1758 if (res_ctx->pipe_ctx[preferred_pipe_idx].stream == NULL) {
1759 secondary_pipe = &res_ctx->pipe_ctx[preferred_pipe_idx];
1760 secondary_pipe->pipe_idx = preferred_pipe_idx;
1761 break;
1762 }
1763 }
1764 }
1765 }
1766
1767 return secondary_pipe;
1768}
1769
ea817dd5 1770void dcn20_merge_pipes_for_validate(
6de20237 1771 struct dc *dc,
b6bfba6c 1772 struct dc_state *context)
7ed4e635 1773{
b6bfba6c 1774 int i;
7ed4e635 1775
b1f6d01c
DL
1776 /* merge previously split odm pipes since mode support needs to make the decision */
1777 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1778 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1779 struct pipe_ctx *odm_pipe = pipe->next_odm_pipe;
1780
1781 if (pipe->prev_odm_pipe)
1782 continue;
1783
1784 pipe->next_odm_pipe = NULL;
1785 while (odm_pipe) {
1786 struct pipe_ctx *next_odm_pipe = odm_pipe->next_odm_pipe;
1787
1788 odm_pipe->plane_state = NULL;
1789 odm_pipe->stream = NULL;
1790 odm_pipe->top_pipe = NULL;
1791 odm_pipe->bottom_pipe = NULL;
1792 odm_pipe->prev_odm_pipe = NULL;
1793 odm_pipe->next_odm_pipe = NULL;
b1f6d01c 1794 if (odm_pipe->stream_res.dsc)
7287a675 1795 dcn20_release_dsc(&context->res_ctx, dc->res_pool, &odm_pipe->stream_res.dsc);
b1f6d01c
DL
1796 /* Clear plane_res and stream_res */
1797 memset(&odm_pipe->plane_res, 0, sizeof(odm_pipe->plane_res));
1798 memset(&odm_pipe->stream_res, 0, sizeof(odm_pipe->stream_res));
1799 odm_pipe = next_odm_pipe;
1800 }
1801 if (pipe->plane_state)
1802 resource_build_scaling_params(pipe);
1803 }
1804
1805 /* merge previously mpc split pipes since mode support needs to make the decision */
7ed4e635
HW
1806 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1807 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1808 struct pipe_ctx *hsplit_pipe = pipe->bottom_pipe;
1809
1810 if (!hsplit_pipe || hsplit_pipe->plane_state != pipe->plane_state)
1811 continue;
1812
7ed4e635
HW
1813 pipe->bottom_pipe = hsplit_pipe->bottom_pipe;
1814 if (hsplit_pipe->bottom_pipe)
1815 hsplit_pipe->bottom_pipe->top_pipe = pipe;
1816 hsplit_pipe->plane_state = NULL;
1817 hsplit_pipe->stream = NULL;
1818 hsplit_pipe->top_pipe = NULL;
1819 hsplit_pipe->bottom_pipe = NULL;
b1f6d01c 1820
7ed4e635
HW
1821 /* Clear plane_res and stream_res */
1822 memset(&hsplit_pipe->plane_res, 0, sizeof(hsplit_pipe->plane_res));
1823 memset(&hsplit_pipe->stream_res, 0, sizeof(hsplit_pipe->stream_res));
1824 if (pipe->plane_state)
1825 resource_build_scaling_params(pipe);
1826 }
b6bfba6c 1827}
7ed4e635 1828
b6bfba6c
DL
1829int dcn20_validate_apply_pipe_split_flags(
1830 struct dc *dc,
1831 struct dc_state *context,
1832 int vlevel,
65d68369 1833 int *split,
7287a675 1834 bool *merge)
b6bfba6c 1835{
b745ecdb 1836 int i, pipe_idx, vlevel_split;
cd3e05a7 1837 int plane_count = 0;
b6bfba6c 1838 bool force_split = false;
cd3e05a7 1839 bool avoid_split = dc->debug.pipe_split_policy == MPC_SPLIT_AVOID;
570bc18c
DL
1840 struct vba_vars_st *v = &context->bw_ctx.dml.vba;
1841 int max_mpc_comb = v->maxMpcComb;
7ed4e635 1842
cd3e05a7
DL
1843 if (context->stream_count > 1) {
1844 if (dc->debug.pipe_split_policy == MPC_SPLIT_AVOID_MULT_DISP)
1845 avoid_split = true;
1846 } else if (dc->debug.force_single_disp_pipe_split)
1847 force_split = true;
1848
7ed4e635
HW
1849 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1850 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
7ed4e635 1851
b6dbb8ff
NK
1852 /**
1853 * Workaround for avoiding pipe-split in cases where we'd split
1854 * planes that are too small, resulting in splits that aren't
1855 * valid for the scaler.
1856 */
1857 if (pipe->plane_state &&
1858 (pipe->plane_state->dst_rect.width <= 16 ||
1859 pipe->plane_state->dst_rect.height <= 16 ||
1860 pipe->plane_state->src_rect.width <= 16 ||
1861 pipe->plane_state->src_rect.height <= 16))
1862 avoid_split = true;
1863
1864 /* TODO: fix dc bugs and remove this split threshold thing */
cd3e05a7
DL
1865 if (pipe->stream && !pipe->prev_odm_pipe &&
1866 (!pipe->top_pipe || pipe->top_pipe->plane_state != pipe->plane_state))
1867 ++plane_count;
7ed4e635 1868 }
cd3e05a7 1869 if (plane_count > dc->res_pool->pipe_count / 2)
7ed4e635
HW
1870 avoid_split = true;
1871
a0a85ac4
DZ
1872 /* W/A: Mode timing with borders may not work well with pipe split, avoid for this corner case */
1873 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1874 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1875 struct dc_crtc_timing timing;
1876
1877 if (!pipe->stream)
1878 continue;
1879 else {
1880 timing = pipe->stream->timing;
1881 if (timing.h_border_left + timing.h_border_right
1882 + timing.v_border_top + timing.v_border_bottom > 0) {
1883 avoid_split = true;
1884 break;
1885 }
1886 }
1887 }
1888
b745ecdb 1889 /* Avoid split loop looks for lowest voltage level that allows most unsplit pipes possible */
b6bfba6c
DL
1890 if (avoid_split) {
1891 for (i = 0, pipe_idx = 0; i < dc->res_pool->pipe_count; i++) {
1892 if (!context->res_ctx.pipe_ctx[i].stream)
1893 continue;
1894
b745ecdb 1895 for (vlevel_split = vlevel; vlevel <= context->bw_ctx.dml.soc.num_states; vlevel++)
570bc18c
DL
1896 if (v->NoOfDPP[vlevel][0][pipe_idx] == 1 &&
1897 v->ModeSupport[vlevel][0])
b6bfba6c
DL
1898 break;
1899 /* Impossible to not split this pipe */
b745ecdb
DL
1900 if (vlevel > context->bw_ctx.dml.soc.num_states)
1901 vlevel = vlevel_split;
1dfedb39
SL
1902 else
1903 max_mpc_comb = 0;
b6bfba6c
DL
1904 pipe_idx++;
1905 }
570bc18c 1906 v->maxMpcComb = max_mpc_comb;
b6bfba6c
DL
1907 }
1908
b745ecdb 1909 /* Split loop sets which pipe should be split based on dml outputs and dc flags */
7ed4e635 1910 for (i = 0, pipe_idx = 0; i < dc->res_pool->pipe_count; i++) {
b6bfba6c 1911 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
570bc18c
DL
1912 int pipe_plane = v->pipe_plane[pipe_idx];
1913 bool split4mpc = context->stream_count == 1 && plane_count == 1
1914 && dc->config.enable_4to1MPC && dc->res_pool->pipe_count >= 4;
b6bfba6c 1915
7ed4e635
HW
1916 if (!context->res_ctx.pipe_ctx[i].stream)
1917 continue;
b6bfba6c 1918
4d765d31
DL
1919 if (split4mpc || v->NoOfDPP[vlevel][max_mpc_comb][pipe_plane] == 4)
1920 split[i] = 4;
1921 else if (force_split || v->NoOfDPP[vlevel][max_mpc_comb][pipe_plane] == 2)
65d68369 1922 split[i] = 2;
4d765d31 1923
b6bfba6c
DL
1924 if ((pipe->stream->view_format ==
1925 VIEW_3D_FORMAT_SIDE_BY_SIDE ||
1926 pipe->stream->view_format ==
1927 VIEW_3D_FORMAT_TOP_AND_BOTTOM) &&
1928 (pipe->stream->timing.timing_3d_format ==
1929 TIMING_3D_FORMAT_TOP_AND_BOTTOM ||
1930 pipe->stream->timing.timing_3d_format ==
1931 TIMING_3D_FORMAT_SIDE_BY_SIDE))
65d68369 1932 split[i] = 2;
b6bfba6c 1933 if (dc->debug.force_odm_combine & (1 << pipe->stream_res.tg->inst)) {
65d68369 1934 split[i] = 2;
570bc18c 1935 v->ODMCombineEnablePerState[vlevel][pipe_plane] = dm_odm_combine_mode_2to1;
b6bfba6c 1936 }
5dba4991
BL
1937 if (dc->debug.force_odm_combine_4to1 & (1 << pipe->stream_res.tg->inst)) {
1938 split[i] = 4;
1939 v->ODMCombineEnablePerState[vlevel][pipe_plane] = dm_odm_combine_mode_4to1;
1940 }
5e908012
CP
1941 /*420 format workaround*/
1942 if (pipe->stream->timing.h_addressable > 7680 &&
1943 pipe->stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR420) {
1944 split[i] = 4;
1945 }
570bc18c
DL
1946 v->ODMCombineEnabled[pipe_plane] =
1947 v->ODMCombineEnablePerState[vlevel][pipe_plane];
1948
1949 if (v->ODMCombineEnabled[pipe_plane] == dm_odm_combine_mode_disabled) {
1950 if (get_num_mpc_splits(pipe) == 1) {
1951 /*If need split for mpc but 2 way split already*/
1952 if (split[i] == 4)
1953 split[i] = 2; /* 2 -> 4 MPC */
1954 else if (split[i] == 2)
1955 split[i] = 0; /* 2 -> 2 MPC */
1956 else if (pipe->top_pipe && pipe->top_pipe->plane_state == pipe->plane_state)
1957 merge[i] = true; /* 2 -> 1 MPC */
1958 } else if (get_num_mpc_splits(pipe) == 3) {
1959 /*If need split for mpc but 4 way split already*/
1960 if (split[i] == 2 && ((pipe->top_pipe && !pipe->top_pipe->top_pipe)
1961 || !pipe->bottom_pipe)) {
1962 merge[i] = true; /* 4 -> 2 MPC */
1963 } else if (split[i] == 0 && pipe->top_pipe &&
1964 pipe->top_pipe->plane_state == pipe->plane_state)
1965 merge[i] = true; /* 4 -> 1 MPC */
65d68369 1966 split[i] = 0;
570bc18c
DL
1967 } else if (get_num_odm_splits(pipe)) {
1968 /* ODM -> MPC transition */
7287a675 1969 if (pipe->prev_odm_pipe) {
570bc18c
DL
1970 split[i] = 0;
1971 merge[i] = true;
7287a675
DL
1972 }
1973 }
570bc18c
DL
1974 } else {
1975 if (get_num_odm_splits(pipe) == 1) {
1976 /*If need split for odm but 2 way split already*/
1977 if (split[i] == 4)
1978 split[i] = 2; /* 2 -> 4 ODM */
1979 else if (split[i] == 2)
1980 split[i] = 0; /* 2 -> 2 ODM */
1981 else if (pipe->prev_odm_pipe) {
1982 ASSERT(0); /* NOT expected yet */
1983 merge[i] = true; /* exit ODM */
1984 }
1985 } else if (get_num_odm_splits(pipe) == 3) {
1986 /*If need split for odm but 4 way split already*/
1987 if (split[i] == 2 && ((pipe->prev_odm_pipe && !pipe->prev_odm_pipe->prev_odm_pipe)
1988 || !pipe->next_odm_pipe)) {
570bc18c
DL
1989 merge[i] = true; /* 4 -> 2 ODM */
1990 } else if (split[i] == 0 && pipe->prev_odm_pipe) {
1991 ASSERT(0); /* NOT expected yet */
1992 merge[i] = true; /* exit ODM */
1993 }
65d68369 1994 split[i] = 0;
570bc18c
DL
1995 } else if (get_num_mpc_splits(pipe)) {
1996 /* MPC -> ODM transition */
1997 ASSERT(0); /* NOT expected yet */
1998 if (pipe->top_pipe && pipe->top_pipe->plane_state == pipe->plane_state) {
1999 split[i] = 0;
2000 merge[i] = true;
2001 }
65d68369 2002 }
7287a675
DL
2003 }
2004
b6bfba6c 2005 /* Adjust dppclk when split is forced, do not bother with dispclk */
cf689e86
MW
2006 if (split[i] != 0 && v->NoOfDPP[vlevel][max_mpc_comb][pipe_idx] == 1) {
2007 DC_FP_START();
2008 dcn20_fpu_adjust_dppclk(v, vlevel, max_mpc_comb, pipe_idx, false);
2009 DC_FP_END();
2010 }
7ed4e635
HW
2011 pipe_idx++;
2012 }
2013
b6bfba6c
DL
2014 return vlevel;
2015}
2016
2017bool dcn20_fast_validate_bw(
2018 struct dc *dc,
2019 struct dc_state *context,
2020 display_e2e_pipe_params_st *pipes,
2021 int *pipe_cnt_out,
2022 int *pipe_split_from,
fa896813
IZ
2023 int *vlevel_out,
2024 bool fast_validate)
b6bfba6c
DL
2025{
2026 bool out = false;
65d68369 2027 int split[MAX_PIPES] = { 0 };
b6bfba6c
DL
2028 int pipe_cnt, i, pipe_idx, vlevel;
2029
2030 ASSERT(pipes);
2031 if (!pipes)
2032 return false;
2033
2034 dcn20_merge_pipes_for_validate(dc, context);
2035
cf689e86 2036 DC_FP_START();
fa896813 2037 pipe_cnt = dc->res_pool->funcs->populate_dml_pipes(dc, context, pipes, fast_validate);
cf689e86 2038 DC_FP_END();
b6bfba6c
DL
2039
2040 *pipe_cnt_out = pipe_cnt;
2041
2042 if (!pipe_cnt) {
2043 out = true;
2044 goto validate_out;
2045 }
2046
2047 vlevel = dml_get_voltage_level(&context->bw_ctx.dml, pipes, pipe_cnt);
2048
2049 if (vlevel > context->bw_ctx.dml.soc.num_states)
2050 goto validate_fail;
2051
7287a675 2052 vlevel = dcn20_validate_apply_pipe_split_flags(dc, context, vlevel, split, NULL);
b6bfba6c
DL
2053
2054 /*initialize pipe_just_split_from to invalid idx*/
2055 for (i = 0; i < MAX_PIPES; i++)
2056 pipe_split_from[i] = -1;
2057
7ed4e635
HW
2058 for (i = 0, pipe_idx = -1; i < dc->res_pool->pipe_count; i++) {
2059 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
2060 struct pipe_ctx *hsplit_pipe = pipe->bottom_pipe;
7ed4e635
HW
2061
2062 if (!pipe->stream || pipe_split_from[i] >= 0)
2063 continue;
2064
2065 pipe_idx++;
2066
7ed4e635 2067 if (!pipe->top_pipe && !pipe->plane_state && context->bw_ctx.dml.vba.ODMCombineEnabled[pipe_idx]) {
c681491a 2068 hsplit_pipe = dcn20_find_secondary_pipe(dc, &context->res_ctx, dc->res_pool, pipe);
7ed4e635 2069 ASSERT(hsplit_pipe);
b1f6d01c 2070 if (!dcn20_split_stream_for_odm(
14e49bb3 2071 dc, &context->res_ctx,
b1f6d01c 2072 pipe, hsplit_pipe))
7ed4e635
HW
2073 goto validate_fail;
2074 pipe_split_from[hsplit_pipe->pipe_idx] = pipe_idx;
2075 dcn20_build_mapped_resource(dc, context, pipe->stream);
2076 }
2077
2078 if (!pipe->plane_state)
2079 continue;
2080 /* Skip 2nd half of already split pipe */
2081 if (pipe->top_pipe && pipe->plane_state == pipe->top_pipe->plane_state)
2082 continue;
2083
02ce5a79
DL
2084 /* We do not support mpo + odm at the moment */
2085 if (hsplit_pipe && hsplit_pipe->plane_state != pipe->plane_state
2086 && context->bw_ctx.dml.vba.ODMCombineEnabled[pipe_idx])
2087 goto validate_fail;
2088
65d68369 2089 if (split[i] == 2) {
7ed4e635
HW
2090 if (!hsplit_pipe || hsplit_pipe->plane_state != pipe->plane_state) {
2091 /* pipe not split previously needs split */
c681491a 2092 hsplit_pipe = dcn20_find_secondary_pipe(dc, &context->res_ctx, dc->res_pool, pipe);
b6bfba6c 2093 ASSERT(hsplit_pipe);
ff86391e 2094 if (!hsplit_pipe) {
cf689e86
MW
2095 DC_FP_START();
2096 dcn20_fpu_adjust_dppclk(&context->bw_ctx.dml.vba, vlevel, context->bw_ctx.dml.vba.maxMpcComb, pipe_idx, true);
2097 DC_FP_END();
7ed4e635 2098 continue;
ff86391e 2099 }
b1f6d01c
DL
2100 if (context->bw_ctx.dml.vba.ODMCombineEnabled[pipe_idx]) {
2101 if (!dcn20_split_stream_for_odm(
14e49bb3 2102 dc, &context->res_ctx,
b1f6d01c
DL
2103 pipe, hsplit_pipe))
2104 goto validate_fail;
387596ef 2105 dcn20_build_mapped_resource(dc, context, pipe->stream);
65d68369
IZ
2106 } else {
2107 dcn20_split_stream_for_mpc(
b8a8d34b 2108 &context->res_ctx, dc->res_pool,
65d68369 2109 pipe, hsplit_pipe);
65f9ace4
SL
2110 resource_build_scaling_params(pipe);
2111 resource_build_scaling_params(hsplit_pipe);
65d68369 2112 }
7ed4e635
HW
2113 pipe_split_from[hsplit_pipe->pipe_idx] = pipe_idx;
2114 }
02ce5a79 2115 } else if (hsplit_pipe && hsplit_pipe->plane_state == pipe->plane_state) {
7ed4e635
HW
2116 /* merge should already have been done */
2117 ASSERT(0);
2118 }
2119 }
0ba37b20 2120 /* Actual dsc count per stream dsc validation*/
c84ad0d6 2121 if (!dcn20_validate_dsc(dc, context)) {
0ba37b20
DL
2122 context->bw_ctx.dml.vba.ValidationStatus[context->bw_ctx.dml.vba.soc.num_states] =
2123 DML_FAIL_DSC_VALIDATION_FAILURE;
2124 goto validate_fail;
2125 }
7ed4e635 2126
6de20237 2127 *vlevel_out = vlevel;
42351c66 2128
6de20237
EY
2129 out = true;
2130 goto validate_out;
2131
2132validate_fail:
2133 out = false;
2134
2135validate_out:
2136 return out;
2137}
2138
8b91fd8b
DK
2139bool dcn20_validate_bandwidth(struct dc *dc, struct dc_state *context,
2140 bool fast_validate)
2141{
41401ac6 2142 bool voltage_supported;
8b91fd8b
DK
2143 DC_FP_START();
2144 voltage_supported = dcn20_validate_bandwidth_fp(dc, context, fast_validate);
7a8a3430 2145 DC_FP_END();
057fc695
JL
2146 return voltage_supported;
2147}
2148
7ed4e635
HW
2149struct pipe_ctx *dcn20_acquire_idle_pipe_for_layer(
2150 struct dc_state *state,
2151 const struct resource_pool *pool,
2152 struct dc_stream_state *stream)
2153{
2154 struct resource_context *res_ctx = &state->res_ctx;
2155 struct pipe_ctx *head_pipe = resource_get_head_pipe_for_stream(res_ctx, stream);
2156 struct pipe_ctx *idle_pipe = find_idle_secondary_pipe(res_ctx, pool, head_pipe);
2157
2158 if (!head_pipe)
2159 ASSERT(0);
2160
2161 if (!idle_pipe)
7a17c8ce 2162 return NULL;
7ed4e635
HW
2163
2164 idle_pipe->stream = head_pipe->stream;
2165 idle_pipe->stream_res.tg = head_pipe->stream_res.tg;
2166 idle_pipe->stream_res.opp = head_pipe->stream_res.opp;
2167
2168 idle_pipe->plane_res.hubp = pool->hubps[idle_pipe->pipe_idx];
2169 idle_pipe->plane_res.ipp = pool->ipps[idle_pipe->pipe_idx];
2170 idle_pipe->plane_res.dpp = pool->dpps[idle_pipe->pipe_idx];
2171 idle_pipe->plane_res.mpcc_inst = pool->dpps[idle_pipe->pipe_idx]->inst;
2172
2173 return idle_pipe;
2174}
2175
2176bool dcn20_get_dcc_compression_cap(const struct dc *dc,
2177 const struct dc_dcc_surface_param *input,
2178 struct dc_surface_dcc_cap *output)
2179{
2180 return dc->res_pool->hubbub->funcs->get_dcc_compression_cap(
2181 dc->res_pool->hubbub,
2182 input,
2183 output);
2184}
2185
2186static void dcn20_destroy_resource_pool(struct resource_pool **pool)
2187{
2188 struct dcn20_resource_pool *dcn20_pool = TO_DCN20_RES_POOL(*pool);
2189
d9e32672 2190 dcn20_resource_destruct(dcn20_pool);
7ed4e635
HW
2191 kfree(dcn20_pool);
2192 *pool = NULL;
2193}
2194
2195
2196static struct dc_cap_funcs cap_funcs = {
2197 .get_dcc_compression_cap = dcn20_get_dcc_compression_cap
2198};
2199
2200
8d8c82b6 2201enum dc_status dcn20_patch_unknown_plane_state(struct dc_plane_state *plane_state)
7ed4e635 2202{
7ed4e635
HW
2203 enum surface_pixel_format surf_pix_format = plane_state->format;
2204 unsigned int bpp = resource_pixel_format_to_bpp(surf_pix_format);
2205
febb4147 2206 plane_state->tiling_info.gfx9.swizzle = DC_SW_64KB_S;
7ed4e635 2207 if (bpp == 64)
febb4147 2208 plane_state->tiling_info.gfx9.swizzle = DC_SW_64KB_D;
7ed4e635 2209
b1c3b7f1 2210 return DC_OK;
7ed4e635
HW
2211}
2212
25457a1f 2213static const struct resource_funcs dcn20_res_pool_funcs = {
7ed4e635
HW
2214 .destroy = dcn20_destroy_resource_pool,
2215 .link_enc_create = dcn20_link_encoder_create,
d4caa72e 2216 .panel_cntl_create = dcn20_panel_cntl_create,
7ed4e635 2217 .validate_bandwidth = dcn20_validate_bandwidth,
7ed4e635
HW
2218 .acquire_idle_pipe_for_layer = dcn20_acquire_idle_pipe_for_layer,
2219 .add_stream_to_ctx = dcn20_add_stream_to_ctx,
b4f71c8c 2220 .add_dsc_to_stream_resource = dcn20_add_dsc_to_stream_resource,
7ed4e635
HW
2221 .remove_stream_from_ctx = dcn20_remove_stream_from_ctx,
2222 .populate_dml_writeback_from_context = dcn20_populate_dml_writeback_from_context,
8d8c82b6 2223 .patch_unknown_plane_state = dcn20_patch_unknown_plane_state,
c9ae6e16 2224 .set_mcif_arb_params = dcn20_set_mcif_arb_params,
b6bfba6c 2225 .populate_dml_pipes = dcn20_populate_dml_pipes_from_context,
278141f5 2226 .find_first_free_match_stream_enc_for_link = dcn10_find_first_free_match_stream_enc_for_link
7ed4e635
HW
2227};
2228
bb21290f
CL
2229bool dcn20_dwbc_create(struct dc_context *ctx, struct resource_pool *pool)
2230{
2231 int i;
2232 uint32_t pipe_count = pool->res_cap->num_dwb;
2233
bb21290f
CL
2234 for (i = 0; i < pipe_count; i++) {
2235 struct dcn20_dwbc *dwbc20 = kzalloc(sizeof(struct dcn20_dwbc),
2236 GFP_KERNEL);
2237
2238 if (!dwbc20) {
2239 dm_error("DC: failed to create dwbc20!\n");
2240 return false;
2241 }
2242 dcn20_dwbc_construct(dwbc20, ctx,
2243 &dwbc20_regs[i],
2244 &dwbc20_shift,
2245 &dwbc20_mask,
2246 i);
2247 pool->dwbc[i] = &dwbc20->base;
2248 }
2249 return true;
2250}
2251
2252bool dcn20_mmhubbub_create(struct dc_context *ctx, struct resource_pool *pool)
2253{
2254 int i;
2255 uint32_t pipe_count = pool->res_cap->num_dwb;
2256
2257 ASSERT(pipe_count > 0);
2258
2259 for (i = 0; i < pipe_count; i++) {
2260 struct dcn20_mmhubbub *mcif_wb20 = kzalloc(sizeof(struct dcn20_mmhubbub),
2261 GFP_KERNEL);
2262
2263 if (!mcif_wb20) {
2264 dm_error("DC: failed to create mcif_wb20!\n");
2265 return false;
2266 }
2267
2268 dcn20_mmhubbub_construct(mcif_wb20, ctx,
2269 &mcif_wb20_regs[i],
2270 &mcif_wb20_shift,
2271 &mcif_wb20_mask,
2272 i);
2273
2274 pool->mcif_wb[i] = &mcif_wb20->base;
2275 }
2276 return true;
2277}
2278
44e149bb 2279static struct pp_smu_funcs *dcn20_pp_smu_create(struct dc_context *ctx)
7ed4e635 2280{
3bb11050 2281 struct pp_smu_funcs *pp_smu = kzalloc(sizeof(*pp_smu), GFP_ATOMIC);
7ed4e635
HW
2282
2283 if (!pp_smu)
2284 return pp_smu;
2285
2286 dm_pp_get_funcs(ctx, pp_smu);
2287
2288 if (pp_smu->ctx.ver != PP_SMU_VER_NV)
2289 pp_smu = memset(pp_smu, 0, sizeof(struct pp_smu_funcs));
2290
2291 return pp_smu;
2292}
2293
44e149bb 2294static void dcn20_pp_smu_destroy(struct pp_smu_funcs **pp_smu)
7ed4e635
HW
2295{
2296 if (pp_smu && *pp_smu) {
2297 kfree(*pp_smu);
2298 *pp_smu = NULL;
2299 }
2300}
2301
675a9e38
LL
2302static struct _vcs_dpi_soc_bounding_box_st *get_asic_rev_soc_bb(
2303 uint32_t hw_internal_rev)
2304{
e1ab4a91
ML
2305 if (ASICREV_IS_NAVI14_M(hw_internal_rev))
2306 return &dcn2_0_nv14_soc;
2307
675a9e38
LL
2308 if (ASICREV_IS_NAVI12_P(hw_internal_rev))
2309 return &dcn2_0_nv12_soc;
2310
2311 return &dcn2_0_soc;
2312}
2313
2314static struct _vcs_dpi_ip_params_st *get_asic_rev_ip_params(
2315 uint32_t hw_internal_rev)
2316{
72b741af
Z
2317 /* NV14 */
2318 if (ASICREV_IS_NAVI14_M(hw_internal_rev))
2319 return &dcn2_0_nv14_ip;
2320
675a9e38
LL
2321 /* NV12 and NV10 */
2322 return &dcn2_0_ip;
2323}
2324
2325static enum dml_project get_dml_project_version(uint32_t hw_internal_rev)
2326{
2327 return DML_PROJECT_NAVI10v2;
2328}
2329
7ed4e635
HW
2330static bool init_soc_bounding_box(struct dc *dc,
2331 struct dcn20_resource_pool *pool)
2332{
675a9e38
LL
2333 struct _vcs_dpi_soc_bounding_box_st *loaded_bb =
2334 get_asic_rev_soc_bb(dc->ctx->asic_id.hw_internal_rev);
2335 struct _vcs_dpi_ip_params_st *loaded_ip =
2336 get_asic_rev_ip_params(dc->ctx->asic_id.hw_internal_rev);
2337
7ed4e635
HW
2338 DC_LOGGER_INIT(dc->ctx->logger);
2339
7ed4e635
HW
2340 if (pool->base.pp_smu) {
2341 struct pp_smu_nv_clock_table max_clocks = {0};
2342 unsigned int uclk_states[8] = {0};
2343 unsigned int num_states = 0;
2344 enum pp_smu_status status;
2345 bool clock_limits_available = false;
2346 bool uclk_states_available = false;
2347
2348 if (pool->base.pp_smu->nv_funcs.get_uclk_dpm_states) {
2349 status = (pool->base.pp_smu->nv_funcs.get_uclk_dpm_states)
2350 (&pool->base.pp_smu->nv_funcs.pp_smu, uclk_states, &num_states);
2351
2352 uclk_states_available = (status == PP_SMU_RESULT_OK);
2353 }
2354
2355 if (pool->base.pp_smu->nv_funcs.get_maximum_sustainable_clocks) {
2356 status = (*pool->base.pp_smu->nv_funcs.get_maximum_sustainable_clocks)
2357 (&pool->base.pp_smu->nv_funcs.pp_smu, &max_clocks);
c2ad17c3
AW
2358 /* SMU cannot set DCF clock to anything equal to or higher than SOC clock
2359 */
2360 if (max_clocks.dcfClockInKhz >= max_clocks.socClockInKhz)
2361 max_clocks.dcfClockInKhz = max_clocks.socClockInKhz - 1000;
7ed4e635
HW
2362 clock_limits_available = (status == PP_SMU_RESULT_OK);
2363 }
2364
bc39a69a
AJ
2365 if (clock_limits_available && uclk_states_available && num_states) {
2366 DC_FP_START();
44ce0cd3 2367 dcn20_update_bounding_box(dc, loaded_bb, &max_clocks, uclk_states, num_states);
bc39a69a
AJ
2368 DC_FP_END();
2369 } else if (clock_limits_available) {
2370 DC_FP_START();
44ce0cd3 2371 dcn20_cap_soc_clocks(loaded_bb, max_clocks);
bc39a69a
AJ
2372 DC_FP_END();
2373 }
7ed4e635
HW
2374 }
2375
675a9e38
LL
2376 loaded_ip->max_num_otg = pool->base.res_cap->num_timing_generator;
2377 loaded_ip->max_num_dpp = pool->base.pipe_count;
bc39a69a 2378 DC_FP_START();
44ce0cd3 2379 dcn20_patch_bounding_box(dc, loaded_bb);
bc39a69a 2380 DC_FP_END();
7ed4e635
HW
2381 return true;
2382}
2383
d9e32672 2384static bool dcn20_resource_construct(
7ed4e635
HW
2385 uint8_t num_virtual_links,
2386 struct dc *dc,
2387 struct dcn20_resource_pool *pool)
2388{
2389 int i;
2390 struct dc_context *ctx = dc->ctx;
2391 struct irq_service_init_data init_data;
130ac6d8 2392 struct ddc_service_init_data ddc_init_data = {0};
675a9e38
LL
2393 struct _vcs_dpi_soc_bounding_box_st *loaded_bb =
2394 get_asic_rev_soc_bb(ctx->asic_id.hw_internal_rev);
2395 struct _vcs_dpi_ip_params_st *loaded_ip =
2396 get_asic_rev_ip_params(ctx->asic_id.hw_internal_rev);
2397 enum dml_project dml_project_version =
2398 get_dml_project_version(ctx->asic_id.hw_internal_rev);
7ed4e635
HW
2399
2400 ctx->dc_bios->regs = &bios_regs;
7ed4e635
HW
2401 pool->base.funcs = &dcn20_res_pool_funcs;
2402
2ebe1773
BL
2403 if (ASICREV_IS_NAVI14_M(ctx->asic_id.hw_internal_rev)) {
2404 pool->base.res_cap = &res_cap_nv14;
2405 pool->base.pipe_count = 5;
2406 pool->base.mpcc_count = 5;
2407 } else {
2408 pool->base.res_cap = &res_cap_nv10;
2409 pool->base.pipe_count = 6;
2410 pool->base.mpcc_count = 6;
2411 }
7ed4e635
HW
2412 /*************************************************
2413 * Resource + asic cap harcoding *
2414 *************************************************/
2415 pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
2416
7ed4e635
HW
2417 dc->caps.max_downscale_ratio = 200;
2418 dc->caps.i2c_speed_in_khz = 100;
b15cde19 2419 dc->caps.i2c_speed_in_khz_hdcp = 100; /*1.4 w/a not applied by default*/
7ed4e635 2420 dc->caps.max_cursor_size = 256;
9248681f 2421 dc->caps.min_horizontal_blanking_period = 80;
7ed4e635
HW
2422 dc->caps.dmdata_alloc_size = 2048;
2423
2424 dc->caps.max_slave_planes = 1;
ae030570
AK
2425 dc->caps.max_slave_yuv_planes = 1;
2426 dc->caps.max_slave_rgb_planes = 1;
7ed4e635
HW
2427 dc->caps.post_blend_color_processing = true;
2428 dc->caps.force_dp_tps4_for_cp2520 = true;
ca4f844e 2429 dc->caps.extended_aux_timeout_support = true;
7ed4e635 2430
a8bf7164
KK
2431 /* Color pipeline capabilities */
2432 dc->caps.color.dpp.dcn_arch = 1;
2433 dc->caps.color.dpp.input_lut_shared = 0;
2434 dc->caps.color.dpp.icsc = 1;
2435 dc->caps.color.dpp.dgam_ram = 1;
2436 dc->caps.color.dpp.dgam_rom_caps.srgb = 1;
2437 dc->caps.color.dpp.dgam_rom_caps.bt2020 = 1;
2438 dc->caps.color.dpp.dgam_rom_caps.gamma2_2 = 0;
2439 dc->caps.color.dpp.dgam_rom_caps.pq = 0;
2440 dc->caps.color.dpp.dgam_rom_caps.hlg = 0;
2441 dc->caps.color.dpp.post_csc = 0;
2442 dc->caps.color.dpp.gamma_corr = 0;
c6160900 2443 dc->caps.color.dpp.dgam_rom_for_yuv = 1;
a8bf7164
KK
2444
2445 dc->caps.color.dpp.hw_3d_lut = 1;
2446 dc->caps.color.dpp.ogam_ram = 1;
2447 // no OGAM ROM on DCN2, only MPC ROM
2448 dc->caps.color.dpp.ogam_rom_caps.srgb = 0;
2449 dc->caps.color.dpp.ogam_rom_caps.bt2020 = 0;
2450 dc->caps.color.dpp.ogam_rom_caps.gamma2_2 = 0;
2451 dc->caps.color.dpp.ogam_rom_caps.pq = 0;
2452 dc->caps.color.dpp.ogam_rom_caps.hlg = 0;
2453 dc->caps.color.dpp.ocsc = 0;
2454
2455 dc->caps.color.mpc.gamut_remap = 0;
2456 dc->caps.color.mpc.num_3dluts = 0;
2457 dc->caps.color.mpc.shared_3d_lut = 0;
2458 dc->caps.color.mpc.ogam_ram = 1;
2459 dc->caps.color.mpc.ogam_rom_caps.srgb = 0;
2460 dc->caps.color.mpc.ogam_rom_caps.bt2020 = 0;
2461 dc->caps.color.mpc.ogam_rom_caps.gamma2_2 = 0;
2462 dc->caps.color.mpc.ogam_rom_caps.pq = 0;
2463 dc->caps.color.mpc.ogam_rom_caps.hlg = 0;
2464 dc->caps.color.mpc.ocsc = 1;
2465
068ab0cd 2466 dc->caps.dp_hdmi21_pcon_support = true;
c022375a 2467
25879d7b 2468 if (dc->ctx->dce_environment == DCE_ENV_PRODUCTION_DRV)
7ed4e635 2469 dc->debug = debug_defaults_drv;
25879d7b 2470
7ed4e635
HW
2471 //dcn2.0x
2472 dc->work_arounds.dedcn20_305_wa = true;
2473
2474 // Init the vm_helper
2475 if (dc->vm_helper)
bda9afda 2476 vm_helper_init(dc->vm_helper, 16);
7ed4e635
HW
2477
2478 /*************************************************
2479 * Create resources *
2480 *************************************************/
2481
2482 pool->base.clock_sources[DCN20_CLK_SRC_PLL0] =
2483 dcn20_clock_source_create(ctx, ctx->dc_bios,
2484 CLOCK_SOURCE_COMBO_PHY_PLL0,
2485 &clk_src_regs[0], false);
2486 pool->base.clock_sources[DCN20_CLK_SRC_PLL1] =
2487 dcn20_clock_source_create(ctx, ctx->dc_bios,
2488 CLOCK_SOURCE_COMBO_PHY_PLL1,
2489 &clk_src_regs[1], false);
2490 pool->base.clock_sources[DCN20_CLK_SRC_PLL2] =
2491 dcn20_clock_source_create(ctx, ctx->dc_bios,
2492 CLOCK_SOURCE_COMBO_PHY_PLL2,
2493 &clk_src_regs[2], false);
2494 pool->base.clock_sources[DCN20_CLK_SRC_PLL3] =
2495 dcn20_clock_source_create(ctx, ctx->dc_bios,
2496 CLOCK_SOURCE_COMBO_PHY_PLL3,
2497 &clk_src_regs[3], false);
2498 pool->base.clock_sources[DCN20_CLK_SRC_PLL4] =
2499 dcn20_clock_source_create(ctx, ctx->dc_bios,
2500 CLOCK_SOURCE_COMBO_PHY_PLL4,
2501 &clk_src_regs[4], false);
2502 pool->base.clock_sources[DCN20_CLK_SRC_PLL5] =
2503 dcn20_clock_source_create(ctx, ctx->dc_bios,
2504 CLOCK_SOURCE_COMBO_PHY_PLL5,
2505 &clk_src_regs[5], false);
2506 pool->base.clk_src_count = DCN20_CLK_SRC_TOTAL;
2507 /* todo: not reuse phy_pll registers */
2508 pool->base.dp_clock_source =
2509 dcn20_clock_source_create(ctx, ctx->dc_bios,
2510 CLOCK_SOURCE_ID_DP_DTO,
2511 &clk_src_regs[0], true);
2512
2513 for (i = 0; i < pool->base.clk_src_count; i++) {
2514 if (pool->base.clock_sources[i] == NULL) {
2515 dm_error("DC: failed to create clock sources!\n");
2516 BREAK_TO_DEBUGGER();
2517 goto create_fail;
2518 }
2519 }
2520
2521 pool->base.dccg = dccg2_create(ctx, &dccg_regs, &dccg_shift, &dccg_mask);
2522 if (pool->base.dccg == NULL) {
2523 dm_error("DC: failed to create dccg!\n");
2524 BREAK_TO_DEBUGGER();
2525 goto create_fail;
2526 }
2527
2528 pool->base.dmcu = dcn20_dmcu_create(ctx,
2529 &dmcu_regs,
2530 &dmcu_shift,
2531 &dmcu_mask);
2532 if (pool->base.dmcu == NULL) {
2533 dm_error("DC: failed to create dmcu!\n");
2534 BREAK_TO_DEBUGGER();
2535 goto create_fail;
2536 }
2537
d7c29549 2538 pool->base.abm = dce_abm_create(ctx,
7ed4e635
HW
2539 &abm_regs,
2540 &abm_shift,
2541 &abm_mask);
2542 if (pool->base.abm == NULL) {
2543 dm_error("DC: failed to create abm!\n");
2544 BREAK_TO_DEBUGGER();
2545 goto create_fail;
d7c29549 2546 }
7ed4e635
HW
2547
2548 pool->base.pp_smu = dcn20_pp_smu_create(ctx);
2549
2550
2551 if (!init_soc_bounding_box(dc, pool)) {
2552 dm_error("DC: failed to initialize soc bounding box!\n");
2553 BREAK_TO_DEBUGGER();
2554 goto create_fail;
2555 }
2556
675a9e38 2557 dml_init_instance(&dc->dml, loaded_bb, loaded_ip, dml_project_version);
7ed4e635
HW
2558
2559 if (!dc->debug.disable_pplib_wm_range) {
2560 struct pp_smu_wm_range_sets ranges = {0};
2561 int i = 0;
2562
2563 ranges.num_reader_wm_sets = 0;
2564
675a9e38 2565 if (loaded_bb->num_states == 1) {
7ed4e635
HW
2566 ranges.reader_wm_sets[0].wm_inst = i;
2567 ranges.reader_wm_sets[0].min_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN;
2568 ranges.reader_wm_sets[0].max_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX;
2569 ranges.reader_wm_sets[0].min_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN;
2570 ranges.reader_wm_sets[0].max_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX;
2571
2572 ranges.num_reader_wm_sets = 1;
675a9e38
LL
2573 } else if (loaded_bb->num_states > 1) {
2574 for (i = 0; i < 4 && i < loaded_bb->num_states; i++) {
7ed4e635
HW
2575 ranges.reader_wm_sets[i].wm_inst = i;
2576 ranges.reader_wm_sets[i].min_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN;
2577 ranges.reader_wm_sets[i].max_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX;
cf689e86
MW
2578 DC_FP_START();
2579 dcn20_fpu_set_wm_ranges(i, &ranges, loaded_bb);
2580 DC_FP_END();
7ed4e635
HW
2581
2582 ranges.num_reader_wm_sets = i + 1;
2583 }
7ed4e635 2584
5d36f783
JL
2585 ranges.reader_wm_sets[0].min_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN;
2586 ranges.reader_wm_sets[ranges.num_reader_wm_sets - 1].max_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX;
2587 }
7ed4e635
HW
2588
2589 ranges.num_writer_wm_sets = 1;
2590
2591 ranges.writer_wm_sets[0].wm_inst = 0;
2592 ranges.writer_wm_sets[0].min_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN;
2593 ranges.writer_wm_sets[0].max_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX;
2594 ranges.writer_wm_sets[0].min_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN;
2595 ranges.writer_wm_sets[0].max_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX;
2596
2597 /* Notify PP Lib/SMU which Watermarks to use for which clock ranges */
2598 if (pool->base.pp_smu->nv_funcs.set_wm_ranges)
2599 pool->base.pp_smu->nv_funcs.set_wm_ranges(&pool->base.pp_smu->nv_funcs.pp_smu, &ranges);
2600 }
2601
2602 init_data.ctx = dc->ctx;
2603 pool->base.irqs = dal_irq_service_dcn20_create(&init_data);
2604 if (!pool->base.irqs)
2605 goto create_fail;
2606
2607 /* mem input -> ipp -> dpp -> opp -> TG */
2608 for (i = 0; i < pool->base.pipe_count; i++) {
2609 pool->base.hubps[i] = dcn20_hubp_create(ctx, i);
2610 if (pool->base.hubps[i] == NULL) {
2611 BREAK_TO_DEBUGGER();
2612 dm_error(
2613 "DC: failed to create memory input!\n");
2614 goto create_fail;
2615 }
2616
2617 pool->base.ipps[i] = dcn20_ipp_create(ctx, i);
2618 if (pool->base.ipps[i] == NULL) {
2619 BREAK_TO_DEBUGGER();
2620 dm_error(
2621 "DC: failed to create input pixel processor!\n");
2622 goto create_fail;
2623 }
2624
2625 pool->base.dpps[i] = dcn20_dpp_create(ctx, i);
2626 if (pool->base.dpps[i] == NULL) {
2627 BREAK_TO_DEBUGGER();
2628 dm_error(
2629 "DC: failed to create dpps!\n");
2630 goto create_fail;
2631 }
2632 }
2633 for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
2634 pool->base.engines[i] = dcn20_aux_engine_create(ctx, i);
2635 if (pool->base.engines[i] == NULL) {
2636 BREAK_TO_DEBUGGER();
2637 dm_error(
2638 "DC:failed to create aux engine!!\n");
2639 goto create_fail;
2640 }
2641 pool->base.hw_i2cs[i] = dcn20_i2c_hw_create(ctx, i);
2642 if (pool->base.hw_i2cs[i] == NULL) {
2643 BREAK_TO_DEBUGGER();
2644 dm_error(
2645 "DC:failed to create hw i2c!!\n");
2646 goto create_fail;
2647 }
2648 pool->base.sw_i2cs[i] = NULL;
2649 }
2650
2651 for (i = 0; i < pool->base.res_cap->num_opp; i++) {
2652 pool->base.opps[i] = dcn20_opp_create(ctx, i);
2653 if (pool->base.opps[i] == NULL) {
2654 BREAK_TO_DEBUGGER();
2655 dm_error(
2656 "DC: failed to create output pixel processor!\n");
2657 goto create_fail;
2658 }
2659 }
2660
2661 for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) {
2662 pool->base.timing_generators[i] = dcn20_timing_generator_create(
2663 ctx, i);
2664 if (pool->base.timing_generators[i] == NULL) {
2665 BREAK_TO_DEBUGGER();
2666 dm_error("DC: failed to create tg!\n");
2667 goto create_fail;
2668 }
2669 }
2670
2671 pool->base.timing_generator_count = i;
2672
2673 pool->base.mpc = dcn20_mpc_create(ctx);
2674 if (pool->base.mpc == NULL) {
2675 BREAK_TO_DEBUGGER();
2676 dm_error("DC: failed to create mpc!\n");
2677 goto create_fail;
2678 }
2679
2680 pool->base.hubbub = dcn20_hubbub_create(ctx);
2681 if (pool->base.hubbub == NULL) {
2682 BREAK_TO_DEBUGGER();
2683 dm_error("DC: failed to create hubbub!\n");
2684 goto create_fail;
2685 }
2686
97bda032
HW
2687 for (i = 0; i < pool->base.res_cap->num_dsc; i++) {
2688 pool->base.dscs[i] = dcn20_dsc_create(ctx, i);
2689 if (pool->base.dscs[i] == NULL) {
2690 BREAK_TO_DEBUGGER();
2691 dm_error("DC: failed to create display stream compressor %d!\n", i);
2692 goto create_fail;
2693 }
2694 }
7ed4e635 2695
bb21290f
CL
2696 if (!dcn20_dwbc_create(ctx, &pool->base)) {
2697 BREAK_TO_DEBUGGER();
2698 dm_error("DC: failed to create dwbc!\n");
2699 goto create_fail;
2700 }
2701 if (!dcn20_mmhubbub_create(ctx, &pool->base)) {
2702 BREAK_TO_DEBUGGER();
2703 dm_error("DC: failed to create mcif_wb!\n");
2704 goto create_fail;
2705 }
2706
7ed4e635 2707 if (!resource_construct(num_virtual_links, dc, &pool->base,
25879d7b
QZ
2708 &res_create_funcs))
2709 goto create_fail;
7ed4e635
HW
2710
2711 dcn20_hw_sequencer_construct(dc);
2712
3c9de4da
AL
2713 // IF NV12, set PG function pointer to NULL. It's not that
2714 // PG isn't supported for NV12, it's that we don't want to
2715 // program the registers because that will cause more power
2716 // to be consumed. We could have created dcn20_init_hw to get
2717 // the same effect by checking ASIC rev, but there was a
2718 // request at some point to not check ASIC rev on hw sequencer.
15ce104c 2719 if (ASICREV_IS_NAVI12_P(dc->ctx->asic_id.hw_internal_rev)) {
3c9de4da 2720 dc->hwseq->funcs.enable_power_gating_plane = NULL;
15ce104c
AL
2721 dc->debug.disable_dpp_power_gate = true;
2722 dc->debug.disable_hubp_power_gate = true;
2723 }
2724
3c9de4da 2725
7ed4e635
HW
2726 dc->caps.max_planes = pool->base.pipe_count;
2727
2728 for (i = 0; i < dc->caps.max_planes; ++i)
2729 dc->caps.planes[i] = plane_cap;
2730
2731 dc->cap_funcs = cap_funcs;
2732
d9a07577
JL
2733 if (dc->ctx->dc_bios->fw_info.oem_i2c_present) {
2734 ddc_init_data.ctx = dc->ctx;
2735 ddc_init_data.link = NULL;
2736 ddc_init_data.id.id = dc->ctx->dc_bios->fw_info.oem_i2c_obj_id;
2737 ddc_init_data.id.enum_id = 0;
2738 ddc_init_data.id.type = OBJECT_TYPE_GENERIC;
98ce7d32 2739 pool->base.oem_device = dc->link_srv->create_ddc_service(&ddc_init_data);
d9a07577
JL
2740 } else {
2741 pool->base.oem_device = NULL;
2742 }
2743
7ed4e635
HW
2744 return true;
2745
2746create_fail:
2747
d9e32672 2748 dcn20_resource_destruct(pool);
7ed4e635
HW
2749
2750 return false;
2751}
2752
2753struct resource_pool *dcn20_create_resource_pool(
2754 const struct dc_init_data *init_data,
2755 struct dc *dc)
2756{
2757 struct dcn20_resource_pool *pool =
3bb11050 2758 kzalloc(sizeof(struct dcn20_resource_pool), GFP_ATOMIC);
7ed4e635
HW
2759
2760 if (!pool)
2761 return NULL;
2762
d9e32672 2763 if (dcn20_resource_construct(init_data->num_virtual_links, dc, pool))
7ed4e635
HW
2764 return &pool->base;
2765
2766 BREAK_TO_DEBUGGER();
2767 kfree(pool);
2768 return NULL;
2769}