xref: /linux/drivers/gpu/drm/amd/display/dc/resource/dcn20/dcn20_resource.c (revision ab93e0dd72c37d378dd936f031ffb83ff2bd87ce)
17ed4e635SHarry Wentland /*
27ed4e635SHarry Wentland * Copyright 2016 Advanced Micro Devices, Inc.
36ca3928dSTimothy Pearson  * Copyright 2019 Raptor Engineering, LLC
47ed4e635SHarry Wentland  *
57ed4e635SHarry Wentland  * Permission is hereby granted, free of charge, to any person obtaining a
67ed4e635SHarry Wentland  * copy of this software and associated documentation files (the "Software"),
77ed4e635SHarry Wentland  * to deal in the Software without restriction, including without limitation
87ed4e635SHarry Wentland  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
97ed4e635SHarry Wentland  * and/or sell copies of the Software, and to permit persons to whom the
107ed4e635SHarry Wentland  * Software is furnished to do so, subject to the following conditions:
117ed4e635SHarry Wentland  *
127ed4e635SHarry Wentland  * The above copyright notice and this permission notice shall be included in
137ed4e635SHarry Wentland  * all copies or substantial portions of the Software.
147ed4e635SHarry Wentland  *
157ed4e635SHarry Wentland  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
167ed4e635SHarry Wentland  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
177ed4e635SHarry Wentland  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
187ed4e635SHarry Wentland  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
197ed4e635SHarry Wentland  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
207ed4e635SHarry Wentland  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
217ed4e635SHarry Wentland  * OTHER DEALINGS IN THE SOFTWARE.
227ed4e635SHarry Wentland  *
237ed4e635SHarry Wentland  * Authors: AMD
247ed4e635SHarry Wentland  *
257ed4e635SHarry Wentland  */
267ed4e635SHarry Wentland 
277ed4e635SHarry Wentland #include "dm_services.h"
287ed4e635SHarry Wentland #include "dc.h"
297ed4e635SHarry Wentland 
308b8eed05SMounika Adhuri #include "dcn20/dcn20_init.h"
3178c77382SAnthony Koo 
327ed4e635SHarry Wentland #include "resource.h"
337ed4e635SHarry Wentland #include "include/irq_service_interface.h"
347ed4e635SHarry Wentland #include "dcn20/dcn20_resource.h"
357ed4e635SHarry Wentland 
36ee373411SQingqing Zhuo #include "dml/dcn20/dcn20_fpu.h"
37c8b3538dSRodrigo Siqueira 
387ed4e635SHarry Wentland #include "dcn10/dcn10_hubp.h"
397ed4e635SHarry Wentland #include "dcn10/dcn10_ipp.h"
408b8eed05SMounika Adhuri #include "dcn20/dcn20_hubbub.h"
418b8eed05SMounika Adhuri #include "dcn20/dcn20_mpc.h"
428b8eed05SMounika Adhuri #include "dcn20/dcn20_hubp.h"
437ed4e635SHarry Wentland #include "irq/dcn20/irq_service_dcn20.h"
448b8eed05SMounika Adhuri #include "dcn20/dcn20_dpp.h"
458b8eed05SMounika Adhuri #include "dcn20/dcn20_optc.h"
46e53524cdSMounika Adhuri #include "dcn20/dcn20_hwseq.h"
47e53524cdSMounika Adhuri #include "dce110/dce110_hwseq.h"
48278141f5SWesley Chalmers #include "dcn10/dcn10_resource.h"
498b8eed05SMounika Adhuri #include "dcn20/dcn20_opp.h"
507ed4e635SHarry Wentland 
518b8eed05SMounika Adhuri #include "dcn20/dcn20_dsc.h"
5297bda032SHarry Wentland 
538b8eed05SMounika Adhuri #include "dcn20/dcn20_link_encoder.h"
548b8eed05SMounika Adhuri #include "dcn20/dcn20_stream_encoder.h"
557ed4e635SHarry Wentland #include "dce/dce_clock_source.h"
567ed4e635SHarry Wentland #include "dce/dce_audio.h"
577ed4e635SHarry Wentland #include "dce/dce_hwseq.h"
587ed4e635SHarry Wentland #include "virtual/virtual_stream_encoder.h"
597ed4e635SHarry Wentland #include "dce110/dce110_resource.h"
607ed4e635SHarry Wentland #include "dml/display_mode_vba.h"
618b8eed05SMounika Adhuri #include "dcn20/dcn20_dccg.h"
628b8eed05SMounika Adhuri #include "dcn20/dcn20_vmid.h"
63d4caa72eSAnthony Koo #include "dce/dce_panel_cntl.h"
647ed4e635SHarry Wentland 
657da45e74SRodrigo Siqueira #include "dcn20/dcn20_dwb.h"
667da45e74SRodrigo Siqueira #include "dcn20/dcn20_mmhubbub.h"
677da45e74SRodrigo Siqueira 
687ed4e635SHarry Wentland #include "navi10_ip_offset.h"
697ed4e635SHarry Wentland 
707ed4e635SHarry Wentland #include "dcn/dcn_2_0_0_offset.h"
717ed4e635SHarry Wentland #include "dcn/dcn_2_0_0_sh_mask.h"
72a771ded8SRoman Li #include "dpcs/dpcs_2_0_0_offset.h"
73a771ded8SRoman Li #include "dpcs/dpcs_2_0_0_sh_mask.h"
747ed4e635SHarry Wentland 
757ed4e635SHarry Wentland #include "nbio/nbio_2_3_offset.h"
767ed4e635SHarry Wentland 
777ed4e635SHarry Wentland #include "mmhub/mmhub_2_0_0_offset.h"
787ed4e635SHarry Wentland #include "mmhub/mmhub_2_0_0_sh_mask.h"
797ed4e635SHarry Wentland 
807ed4e635SHarry Wentland #include "reg_helper.h"
817ed4e635SHarry Wentland #include "dce/dce_abm.h"
827ed4e635SHarry Wentland #include "dce/dce_dmcu.h"
837ed4e635SHarry Wentland #include "dce/dce_aux.h"
847ed4e635SHarry Wentland #include "dce/dce_i2c.h"
857ed4e635SHarry Wentland #include "vm_helper.h"
867da45e74SRodrigo Siqueira 
8764d283cbSJimmy Kizito #include "link_enc_cfg.h"
88a98cdd8cSWenjing Liu #include "link.h"
897da45e74SRodrigo Siqueira 
907ed4e635SHarry Wentland #define DC_LOGGER_INIT(logger)
917ed4e635SHarry Wentland 
927ed4e635SHarry Wentland #ifndef mmDP0_DP_DPHY_INTERNAL_CTRL
937ed4e635SHarry Wentland 	#define mmDP0_DP_DPHY_INTERNAL_CTRL		0x210f
947ed4e635SHarry Wentland 	#define mmDP0_DP_DPHY_INTERNAL_CTRL_BASE_IDX	2
957ed4e635SHarry Wentland 	#define mmDP1_DP_DPHY_INTERNAL_CTRL		0x220f
967ed4e635SHarry Wentland 	#define mmDP1_DP_DPHY_INTERNAL_CTRL_BASE_IDX	2
977ed4e635SHarry Wentland 	#define mmDP2_DP_DPHY_INTERNAL_CTRL		0x230f
987ed4e635SHarry Wentland 	#define mmDP2_DP_DPHY_INTERNAL_CTRL_BASE_IDX	2
997ed4e635SHarry Wentland 	#define mmDP3_DP_DPHY_INTERNAL_CTRL		0x240f
1007ed4e635SHarry Wentland 	#define mmDP3_DP_DPHY_INTERNAL_CTRL_BASE_IDX	2
1017ed4e635SHarry Wentland 	#define mmDP4_DP_DPHY_INTERNAL_CTRL		0x250f
1027ed4e635SHarry Wentland 	#define mmDP4_DP_DPHY_INTERNAL_CTRL_BASE_IDX	2
1037ed4e635SHarry Wentland 	#define mmDP5_DP_DPHY_INTERNAL_CTRL		0x260f
1047ed4e635SHarry Wentland 	#define mmDP5_DP_DPHY_INTERNAL_CTRL_BASE_IDX	2
1057ed4e635SHarry Wentland 	#define mmDP6_DP_DPHY_INTERNAL_CTRL		0x270f
1067ed4e635SHarry Wentland 	#define mmDP6_DP_DPHY_INTERNAL_CTRL_BASE_IDX	2
1077ed4e635SHarry Wentland #endif
1087ed4e635SHarry Wentland 
1097ed4e635SHarry Wentland 
1107ed4e635SHarry Wentland enum dcn20_clk_src_array_id {
1117ed4e635SHarry Wentland 	DCN20_CLK_SRC_PLL0,
1127ed4e635SHarry Wentland 	DCN20_CLK_SRC_PLL1,
1137ed4e635SHarry Wentland 	DCN20_CLK_SRC_PLL2,
1147ed4e635SHarry Wentland 	DCN20_CLK_SRC_PLL3,
1157ed4e635SHarry Wentland 	DCN20_CLK_SRC_PLL4,
1167ed4e635SHarry Wentland 	DCN20_CLK_SRC_PLL5,
1177ed4e635SHarry Wentland 	DCN20_CLK_SRC_TOTAL
1187ed4e635SHarry Wentland };
1197ed4e635SHarry Wentland 
1207ed4e635SHarry Wentland /* begin *********************
1217ed4e635SHarry Wentland  * macros to expend register list macro defined in HW object header file */
1227ed4e635SHarry Wentland 
1237ed4e635SHarry Wentland /* DCN */
1247ed4e635SHarry Wentland #define BASE_INNER(seg) DCN_BASE__INST0_SEG ## seg
1257ed4e635SHarry Wentland 
1267ed4e635SHarry Wentland #define BASE(seg) BASE_INNER(seg)
1277ed4e635SHarry Wentland 
1287ed4e635SHarry Wentland #define SR(reg_name)\
1297ed4e635SHarry Wentland 		.reg_name = BASE(mm ## reg_name ## _BASE_IDX) +  \
1307ed4e635SHarry Wentland 					mm ## reg_name
1317ed4e635SHarry Wentland 
1327ed4e635SHarry Wentland #define SRI(reg_name, block, id)\
1337ed4e635SHarry Wentland 	.reg_name = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
1347ed4e635SHarry Wentland 					mm ## block ## id ## _ ## reg_name
1357ed4e635SHarry Wentland 
136158858bfSAurabindo Pillai #define SRI2_DWB(reg_name, block, id)\
137158858bfSAurabindo Pillai 	.reg_name = BASE(mm ## reg_name ## _BASE_IDX) + \
138158858bfSAurabindo Pillai 					mm ## reg_name
139158858bfSAurabindo Pillai #define SF_DWB(reg_name, field_name, post_fix)\
140158858bfSAurabindo Pillai 	.field_name = reg_name ## __ ## field_name ## post_fix
141158858bfSAurabindo Pillai 
142158858bfSAurabindo Pillai #define SF_DWB2(reg_name, block, id, field_name, post_fix)	\
143158858bfSAurabindo Pillai 	.field_name = reg_name ## __ ## field_name ## post_fix
144158858bfSAurabindo Pillai 
1457ed4e635SHarry Wentland #define SRIR(var_name, reg_name, block, id)\
1467ed4e635SHarry Wentland 	.var_name = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
1477ed4e635SHarry Wentland 					mm ## block ## id ## _ ## reg_name
1487ed4e635SHarry Wentland 
1497ed4e635SHarry Wentland #define SRII(reg_name, block, id)\
1507ed4e635SHarry Wentland 	.reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
1517ed4e635SHarry Wentland 					mm ## block ## id ## _ ## reg_name
1527ed4e635SHarry Wentland 
1537ed4e635SHarry Wentland #define DCCG_SRII(reg_name, block, id)\
1547ed4e635SHarry Wentland 	.block ## _ ## reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
1557ed4e635SHarry Wentland 					mm ## block ## id ## _ ## reg_name
1567ed4e635SHarry Wentland 
1571e461c37SAric Cyr #define VUPDATE_SRII(reg_name, block, id)\
1581e461c37SAric Cyr 	.reg_name[id] = BASE(mm ## reg_name ## _ ## block ## id ## _BASE_IDX) + \
1591e461c37SAric Cyr 					mm ## reg_name ## _ ## block ## id
1601e461c37SAric Cyr 
1617ed4e635SHarry Wentland /* NBIO */
1627ed4e635SHarry Wentland #define NBIO_BASE_INNER(seg) \
1637ed4e635SHarry Wentland 	NBIO_BASE__INST0_SEG ## seg
1647ed4e635SHarry Wentland 
1657ed4e635SHarry Wentland #define NBIO_BASE(seg) \
1667ed4e635SHarry Wentland 	NBIO_BASE_INNER(seg)
1677ed4e635SHarry Wentland 
1687ed4e635SHarry Wentland #define NBIO_SR(reg_name)\
1697ed4e635SHarry Wentland 		.reg_name = NBIO_BASE(mm ## reg_name ## _BASE_IDX) + \
1707ed4e635SHarry Wentland 					mm ## reg_name
1717ed4e635SHarry Wentland 
1727ed4e635SHarry Wentland /* MMHUB */
1737ed4e635SHarry Wentland #define MMHUB_BASE_INNER(seg) \
1747ed4e635SHarry Wentland 	MMHUB_BASE__INST0_SEG ## seg
1757ed4e635SHarry Wentland 
1767ed4e635SHarry Wentland #define MMHUB_BASE(seg) \
1777ed4e635SHarry Wentland 	MMHUB_BASE_INNER(seg)
1787ed4e635SHarry Wentland 
1797ed4e635SHarry Wentland #define MMHUB_SR(reg_name)\
1807ed4e635SHarry Wentland 		.reg_name = MMHUB_BASE(mmMM ## reg_name ## _BASE_IDX) + \
1817ed4e635SHarry Wentland 					mmMM ## reg_name
1827ed4e635SHarry Wentland 
1837ed4e635SHarry Wentland static const struct bios_registers bios_regs = {
1847ed4e635SHarry Wentland 		NBIO_SR(BIOS_SCRATCH_3),
1857ed4e635SHarry Wentland 		NBIO_SR(BIOS_SCRATCH_6)
1867ed4e635SHarry Wentland };
1877ed4e635SHarry Wentland 
1887ed4e635SHarry Wentland #define clk_src_regs(index, pllid)\
1897ed4e635SHarry Wentland [index] = {\
1907ed4e635SHarry Wentland 	CS_COMMON_REG_LIST_DCN2_0(index, pllid),\
1917ed4e635SHarry Wentland }
1927ed4e635SHarry Wentland 
1937ed4e635SHarry Wentland static const struct dce110_clk_src_regs clk_src_regs[] = {
1947ed4e635SHarry Wentland 	clk_src_regs(0, A),
1957ed4e635SHarry Wentland 	clk_src_regs(1, B),
1967ed4e635SHarry Wentland 	clk_src_regs(2, C),
1977ed4e635SHarry Wentland 	clk_src_regs(3, D),
1987ed4e635SHarry Wentland 	clk_src_regs(4, E),
1997ed4e635SHarry Wentland 	clk_src_regs(5, F)
2007ed4e635SHarry Wentland };
2017ed4e635SHarry Wentland 
2027ed4e635SHarry Wentland static const struct dce110_clk_src_shift cs_shift = {
2037ed4e635SHarry Wentland 		CS_COMMON_MASK_SH_LIST_DCN2_0(__SHIFT)
2047ed4e635SHarry Wentland };
2057ed4e635SHarry Wentland 
2067ed4e635SHarry Wentland static const struct dce110_clk_src_mask cs_mask = {
2077ed4e635SHarry Wentland 		CS_COMMON_MASK_SH_LIST_DCN2_0(_MASK)
2087ed4e635SHarry Wentland };
2097ed4e635SHarry Wentland 
2107ed4e635SHarry Wentland static const struct dce_dmcu_registers dmcu_regs = {
2117ed4e635SHarry Wentland 		DMCU_DCN10_REG_LIST()
2127ed4e635SHarry Wentland };
2137ed4e635SHarry Wentland 
2147ed4e635SHarry Wentland static const struct dce_dmcu_shift dmcu_shift = {
2157ed4e635SHarry Wentland 		DMCU_MASK_SH_LIST_DCN10(__SHIFT)
2167ed4e635SHarry Wentland };
2177ed4e635SHarry Wentland 
2187ed4e635SHarry Wentland static const struct dce_dmcu_mask dmcu_mask = {
2197ed4e635SHarry Wentland 		DMCU_MASK_SH_LIST_DCN10(_MASK)
2207ed4e635SHarry Wentland };
221d7c29549SJosip Pavic 
2227ed4e635SHarry Wentland static const struct dce_abm_registers abm_regs = {
223d7c29549SJosip Pavic 		ABM_DCN20_REG_LIST()
2247ed4e635SHarry Wentland };
2257ed4e635SHarry Wentland 
2267ed4e635SHarry Wentland static const struct dce_abm_shift abm_shift = {
227d7c29549SJosip Pavic 		ABM_MASK_SH_LIST_DCN20(__SHIFT)
2287ed4e635SHarry Wentland };
2297ed4e635SHarry Wentland 
2307ed4e635SHarry Wentland static const struct dce_abm_mask abm_mask = {
231d7c29549SJosip Pavic 		ABM_MASK_SH_LIST_DCN20(_MASK)
2327ed4e635SHarry Wentland };
233d7c29549SJosip Pavic 
2347ed4e635SHarry Wentland #define audio_regs(id)\
2357ed4e635SHarry Wentland [id] = {\
2367ed4e635SHarry Wentland 		AUD_COMMON_REG_LIST(id)\
2377ed4e635SHarry Wentland }
2387ed4e635SHarry Wentland 
2397ed4e635SHarry Wentland static const struct dce_audio_registers audio_regs[] = {
2407ed4e635SHarry Wentland 	audio_regs(0),
2417ed4e635SHarry Wentland 	audio_regs(1),
2427ed4e635SHarry Wentland 	audio_regs(2),
2437ed4e635SHarry Wentland 	audio_regs(3),
2447ed4e635SHarry Wentland 	audio_regs(4),
2457ed4e635SHarry Wentland 	audio_regs(5),
2467ed4e635SHarry Wentland 	audio_regs(6),
2477ed4e635SHarry Wentland };
2487ed4e635SHarry Wentland 
2497ed4e635SHarry Wentland #define DCE120_AUD_COMMON_MASK_SH_LIST(mask_sh)\
2507ed4e635SHarry Wentland 		SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_INDEX, AZALIA_ENDPOINT_REG_INDEX, mask_sh),\
2517ed4e635SHarry Wentland 		SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_DATA, AZALIA_ENDPOINT_REG_DATA, mask_sh),\
2527ed4e635SHarry Wentland 		AUD_COMMON_MASK_SH_LIST_BASE(mask_sh)
2537ed4e635SHarry Wentland 
2547ed4e635SHarry Wentland static const struct dce_audio_shift audio_shift = {
2557ed4e635SHarry Wentland 		DCE120_AUD_COMMON_MASK_SH_LIST(__SHIFT)
2567ed4e635SHarry Wentland };
2577ed4e635SHarry Wentland 
25854a9bcb0SChristophe JAILLET static const struct dce_audio_mask audio_mask = {
2597ed4e635SHarry Wentland 		DCE120_AUD_COMMON_MASK_SH_LIST(_MASK)
2607ed4e635SHarry Wentland };
2617ed4e635SHarry Wentland 
2627ed4e635SHarry Wentland #define stream_enc_regs(id)\
2637ed4e635SHarry Wentland [id] = {\
2647ed4e635SHarry Wentland 	SE_DCN2_REG_LIST(id)\
2657ed4e635SHarry Wentland }
2667ed4e635SHarry Wentland 
2677ed4e635SHarry Wentland static const struct dcn10_stream_enc_registers stream_enc_regs[] = {
2687ed4e635SHarry Wentland 	stream_enc_regs(0),
2697ed4e635SHarry Wentland 	stream_enc_regs(1),
2707ed4e635SHarry Wentland 	stream_enc_regs(2),
2717ed4e635SHarry Wentland 	stream_enc_regs(3),
2727ed4e635SHarry Wentland 	stream_enc_regs(4),
2737ed4e635SHarry Wentland 	stream_enc_regs(5),
2747ed4e635SHarry Wentland };
2757ed4e635SHarry Wentland 
2767ed4e635SHarry Wentland static const struct dcn10_stream_encoder_shift se_shift = {
2777ed4e635SHarry Wentland 		SE_COMMON_MASK_SH_LIST_DCN20(__SHIFT)
2787ed4e635SHarry Wentland };
2797ed4e635SHarry Wentland 
2807ed4e635SHarry Wentland static const struct dcn10_stream_encoder_mask se_mask = {
2817ed4e635SHarry Wentland 		SE_COMMON_MASK_SH_LIST_DCN20(_MASK)
2827ed4e635SHarry Wentland };
2837ed4e635SHarry Wentland 
2847ed4e635SHarry Wentland 
2857ed4e635SHarry Wentland #define aux_regs(id)\
2867ed4e635SHarry Wentland [id] = {\
2877ed4e635SHarry Wentland 	DCN2_AUX_REG_LIST(id)\
2887ed4e635SHarry Wentland }
2897ed4e635SHarry Wentland 
2907ed4e635SHarry Wentland static const struct dcn10_link_enc_aux_registers link_enc_aux_regs[] = {
2917ed4e635SHarry Wentland 		aux_regs(0),
2927ed4e635SHarry Wentland 		aux_regs(1),
2937ed4e635SHarry Wentland 		aux_regs(2),
2947ed4e635SHarry Wentland 		aux_regs(3),
2957ed4e635SHarry Wentland 		aux_regs(4),
2967ed4e635SHarry Wentland 		aux_regs(5)
2977ed4e635SHarry Wentland };
2987ed4e635SHarry Wentland 
2997ed4e635SHarry Wentland #define hpd_regs(id)\
3007ed4e635SHarry Wentland [id] = {\
3017ed4e635SHarry Wentland 	HPD_REG_LIST(id)\
3027ed4e635SHarry Wentland }
3037ed4e635SHarry Wentland 
3047ed4e635SHarry Wentland static const struct dcn10_link_enc_hpd_registers link_enc_hpd_regs[] = {
3057ed4e635SHarry Wentland 		hpd_regs(0),
3067ed4e635SHarry Wentland 		hpd_regs(1),
3077ed4e635SHarry Wentland 		hpd_regs(2),
3087ed4e635SHarry Wentland 		hpd_regs(3),
3097ed4e635SHarry Wentland 		hpd_regs(4),
3107ed4e635SHarry Wentland 		hpd_regs(5)
3117ed4e635SHarry Wentland };
3127ed4e635SHarry Wentland 
3137ed4e635SHarry Wentland #define link_regs(id, phyid)\
3147ed4e635SHarry Wentland [id] = {\
3157ed4e635SHarry Wentland 	LE_DCN10_REG_LIST(id), \
3167ed4e635SHarry Wentland 	UNIPHY_DCN2_REG_LIST(phyid), \
317a771ded8SRoman Li 	DPCS_DCN2_REG_LIST(id), \
3187ed4e635SHarry Wentland 	SRI(DP_DPHY_INTERNAL_CTRL, DP, id) \
3197ed4e635SHarry Wentland }
3207ed4e635SHarry Wentland 
3217ed4e635SHarry Wentland static const struct dcn10_link_enc_registers link_enc_regs[] = {
3227ed4e635SHarry Wentland 	link_regs(0, A),
3237ed4e635SHarry Wentland 	link_regs(1, B),
3247ed4e635SHarry Wentland 	link_regs(2, C),
3257ed4e635SHarry Wentland 	link_regs(3, D),
3267ed4e635SHarry Wentland 	link_regs(4, E),
3277ed4e635SHarry Wentland 	link_regs(5, F)
3287ed4e635SHarry Wentland };
3297ed4e635SHarry Wentland 
3307ed4e635SHarry Wentland static const struct dcn10_link_enc_shift le_shift = {
331a771ded8SRoman Li 	LINK_ENCODER_MASK_SH_LIST_DCN20(__SHIFT),\
332a771ded8SRoman Li 	DPCS_DCN2_MASK_SH_LIST(__SHIFT)
3337ed4e635SHarry Wentland };
3347ed4e635SHarry Wentland 
3357ed4e635SHarry Wentland static const struct dcn10_link_enc_mask le_mask = {
336a771ded8SRoman Li 	LINK_ENCODER_MASK_SH_LIST_DCN20(_MASK),\
337a771ded8SRoman Li 	DPCS_DCN2_MASK_SH_LIST(_MASK)
3387ed4e635SHarry Wentland };
3397ed4e635SHarry Wentland 
340d4caa72eSAnthony Koo static const struct dce_panel_cntl_registers panel_cntl_regs[] = {
341d4caa72eSAnthony Koo 	{ DCN_PANEL_CNTL_REG_LIST() }
342904fb6e0SAnthony Koo };
343904fb6e0SAnthony Koo 
344d4caa72eSAnthony Koo static const struct dce_panel_cntl_shift panel_cntl_shift = {
345d4caa72eSAnthony Koo 	DCE_PANEL_CNTL_MASK_SH_LIST(__SHIFT)
346904fb6e0SAnthony Koo };
347904fb6e0SAnthony Koo 
348d4caa72eSAnthony Koo static const struct dce_panel_cntl_mask panel_cntl_mask = {
349d4caa72eSAnthony Koo 	DCE_PANEL_CNTL_MASK_SH_LIST(_MASK)
350904fb6e0SAnthony Koo };
351904fb6e0SAnthony Koo 
3527ed4e635SHarry Wentland #define ipp_regs(id)\
3537ed4e635SHarry Wentland [id] = {\
3547ed4e635SHarry Wentland 	IPP_REG_LIST_DCN20(id),\
3557ed4e635SHarry Wentland }
3567ed4e635SHarry Wentland 
3577ed4e635SHarry Wentland static const struct dcn10_ipp_registers ipp_regs[] = {
3587ed4e635SHarry Wentland 	ipp_regs(0),
3597ed4e635SHarry Wentland 	ipp_regs(1),
3607ed4e635SHarry Wentland 	ipp_regs(2),
3617ed4e635SHarry Wentland 	ipp_regs(3),
3627ed4e635SHarry Wentland 	ipp_regs(4),
3637ed4e635SHarry Wentland 	ipp_regs(5),
3647ed4e635SHarry Wentland };
3657ed4e635SHarry Wentland 
3667ed4e635SHarry Wentland static const struct dcn10_ipp_shift ipp_shift = {
3677ed4e635SHarry Wentland 		IPP_MASK_SH_LIST_DCN20(__SHIFT)
3687ed4e635SHarry Wentland };
3697ed4e635SHarry Wentland 
3707ed4e635SHarry Wentland static const struct dcn10_ipp_mask ipp_mask = {
3717ed4e635SHarry Wentland 		IPP_MASK_SH_LIST_DCN20(_MASK),
3727ed4e635SHarry Wentland };
3737ed4e635SHarry Wentland 
3747ed4e635SHarry Wentland #define opp_regs(id)\
3757ed4e635SHarry Wentland [id] = {\
3767ed4e635SHarry Wentland 	OPP_REG_LIST_DCN20(id),\
3777ed4e635SHarry Wentland }
3787ed4e635SHarry Wentland 
3797ed4e635SHarry Wentland static const struct dcn20_opp_registers opp_regs[] = {
3807ed4e635SHarry Wentland 	opp_regs(0),
3817ed4e635SHarry Wentland 	opp_regs(1),
3827ed4e635SHarry Wentland 	opp_regs(2),
3837ed4e635SHarry Wentland 	opp_regs(3),
3847ed4e635SHarry Wentland 	opp_regs(4),
3857ed4e635SHarry Wentland 	opp_regs(5),
3867ed4e635SHarry Wentland };
3877ed4e635SHarry Wentland 
3887ed4e635SHarry Wentland static const struct dcn20_opp_shift opp_shift = {
3897ed4e635SHarry Wentland 		OPP_MASK_SH_LIST_DCN20(__SHIFT)
3907ed4e635SHarry Wentland };
3917ed4e635SHarry Wentland 
3927ed4e635SHarry Wentland static const struct dcn20_opp_mask opp_mask = {
3937ed4e635SHarry Wentland 		OPP_MASK_SH_LIST_DCN20(_MASK)
3947ed4e635SHarry Wentland };
3957ed4e635SHarry Wentland 
3967ed4e635SHarry Wentland #define aux_engine_regs(id)\
3977ed4e635SHarry Wentland [id] = {\
3987ed4e635SHarry Wentland 	AUX_COMMON_REG_LIST0(id), \
3997ed4e635SHarry Wentland 	.AUXN_IMPCAL = 0, \
4007ed4e635SHarry Wentland 	.AUXP_IMPCAL = 0, \
4017ed4e635SHarry Wentland 	.AUX_RESET_MASK = DP_AUX0_AUX_CONTROL__AUX_RESET_MASK, \
4027ed4e635SHarry Wentland }
4037ed4e635SHarry Wentland 
4047ed4e635SHarry Wentland static const struct dce110_aux_registers aux_engine_regs[] = {
4057ed4e635SHarry Wentland 		aux_engine_regs(0),
4067ed4e635SHarry Wentland 		aux_engine_regs(1),
4077ed4e635SHarry Wentland 		aux_engine_regs(2),
4087ed4e635SHarry Wentland 		aux_engine_regs(3),
4097ed4e635SHarry Wentland 		aux_engine_regs(4),
4107ed4e635SHarry Wentland 		aux_engine_regs(5)
4117ed4e635SHarry Wentland };
4127ed4e635SHarry Wentland 
4137ed4e635SHarry Wentland #define tf_regs(id)\
4147ed4e635SHarry Wentland [id] = {\
4157ed4e635SHarry Wentland 	TF_REG_LIST_DCN20(id),\
416d9eb70aeSNoah Abradjian 	TF_REG_LIST_DCN20_COMMON_APPEND(id),\
4177ed4e635SHarry Wentland }
4187ed4e635SHarry Wentland 
4197ed4e635SHarry Wentland static const struct dcn2_dpp_registers tf_regs[] = {
4207ed4e635SHarry Wentland 	tf_regs(0),
4217ed4e635SHarry Wentland 	tf_regs(1),
4227ed4e635SHarry Wentland 	tf_regs(2),
4237ed4e635SHarry Wentland 	tf_regs(3),
4247ed4e635SHarry Wentland 	tf_regs(4),
4257ed4e635SHarry Wentland 	tf_regs(5),
4267ed4e635SHarry Wentland };
4277ed4e635SHarry Wentland 
4287ed4e635SHarry Wentland static const struct dcn2_dpp_shift tf_shift = {
429d56eaa7cSJoshua Aberback 		TF_REG_LIST_SH_MASK_DCN20(__SHIFT),
430c1e34175SNoah Abradjian 		TF_DEBUG_REG_LIST_SH_DCN20
4317ed4e635SHarry Wentland };
4327ed4e635SHarry Wentland 
4337ed4e635SHarry Wentland static const struct dcn2_dpp_mask tf_mask = {
434d56eaa7cSJoshua Aberback 		TF_REG_LIST_SH_MASK_DCN20(_MASK),
435c1e34175SNoah Abradjian 		TF_DEBUG_REG_LIST_MASK_DCN20
4367ed4e635SHarry Wentland };
4377ed4e635SHarry Wentland 
438bb21290fSCharlene Liu #define dwbc_regs_dcn2(id)\
439bb21290fSCharlene Liu [id] = {\
440bb21290fSCharlene Liu 	DWBC_COMMON_REG_LIST_DCN2_0(id),\
441bb21290fSCharlene Liu 		}
442bb21290fSCharlene Liu 
443bb21290fSCharlene Liu static const struct dcn20_dwbc_registers dwbc20_regs[] = {
444bb21290fSCharlene Liu 	dwbc_regs_dcn2(0),
445bb21290fSCharlene Liu };
446bb21290fSCharlene Liu 
447bb21290fSCharlene Liu static const struct dcn20_dwbc_shift dwbc20_shift = {
448bb21290fSCharlene Liu 	DWBC_COMMON_MASK_SH_LIST_DCN2_0(__SHIFT)
449bb21290fSCharlene Liu };
450bb21290fSCharlene Liu 
451bb21290fSCharlene Liu static const struct dcn20_dwbc_mask dwbc20_mask = {
452bb21290fSCharlene Liu 	DWBC_COMMON_MASK_SH_LIST_DCN2_0(_MASK)
453bb21290fSCharlene Liu };
454bb21290fSCharlene Liu 
455bb21290fSCharlene Liu #define mcif_wb_regs_dcn2(id)\
456bb21290fSCharlene Liu [id] = {\
457bb21290fSCharlene Liu 	MCIF_WB_COMMON_REG_LIST_DCN2_0(id),\
458bb21290fSCharlene Liu 		}
459bb21290fSCharlene Liu 
460bb21290fSCharlene Liu static const struct dcn20_mmhubbub_registers mcif_wb20_regs[] = {
461bb21290fSCharlene Liu 	mcif_wb_regs_dcn2(0),
462bb21290fSCharlene Liu };
463bb21290fSCharlene Liu 
464bb21290fSCharlene Liu static const struct dcn20_mmhubbub_shift mcif_wb20_shift = {
465bb21290fSCharlene Liu 	MCIF_WB_COMMON_MASK_SH_LIST_DCN2_0(__SHIFT)
466bb21290fSCharlene Liu };
467bb21290fSCharlene Liu 
468bb21290fSCharlene Liu static const struct dcn20_mmhubbub_mask mcif_wb20_mask = {
469bb21290fSCharlene Liu 	MCIF_WB_COMMON_MASK_SH_LIST_DCN2_0(_MASK)
470bb21290fSCharlene Liu };
471bb21290fSCharlene Liu 
4727ed4e635SHarry Wentland static const struct dcn20_mpc_registers mpc_regs = {
4737ed4e635SHarry Wentland 		MPC_REG_LIST_DCN2_0(0),
4747ed4e635SHarry Wentland 		MPC_REG_LIST_DCN2_0(1),
4757ed4e635SHarry Wentland 		MPC_REG_LIST_DCN2_0(2),
4767ed4e635SHarry Wentland 		MPC_REG_LIST_DCN2_0(3),
4777ed4e635SHarry Wentland 		MPC_REG_LIST_DCN2_0(4),
4787ed4e635SHarry Wentland 		MPC_REG_LIST_DCN2_0(5),
4797ed4e635SHarry Wentland 		MPC_OUT_MUX_REG_LIST_DCN2_0(0),
4807ed4e635SHarry Wentland 		MPC_OUT_MUX_REG_LIST_DCN2_0(1),
4817ed4e635SHarry Wentland 		MPC_OUT_MUX_REG_LIST_DCN2_0(2),
4827ed4e635SHarry Wentland 		MPC_OUT_MUX_REG_LIST_DCN2_0(3),
4837ed4e635SHarry Wentland 		MPC_OUT_MUX_REG_LIST_DCN2_0(4),
4847ed4e635SHarry Wentland 		MPC_OUT_MUX_REG_LIST_DCN2_0(5),
485e8027e08SNoah Abradjian 		MPC_DBG_REG_LIST_DCN2_0()
4867ed4e635SHarry Wentland };
4877ed4e635SHarry Wentland 
4887ed4e635SHarry Wentland static const struct dcn20_mpc_shift mpc_shift = {
489c1e34175SNoah Abradjian 	MPC_COMMON_MASK_SH_LIST_DCN2_0(__SHIFT),
490c1e34175SNoah Abradjian 	MPC_DEBUG_REG_LIST_SH_DCN20
4917ed4e635SHarry Wentland };
4927ed4e635SHarry Wentland 
4937ed4e635SHarry Wentland static const struct dcn20_mpc_mask mpc_mask = {
494c1e34175SNoah Abradjian 	MPC_COMMON_MASK_SH_LIST_DCN2_0(_MASK),
495c1e34175SNoah Abradjian 	MPC_DEBUG_REG_LIST_MASK_DCN20
4967ed4e635SHarry Wentland };
4977ed4e635SHarry Wentland 
4987ed4e635SHarry Wentland #define tg_regs(id)\
4997ed4e635SHarry Wentland [id] = {TG_COMMON_REG_LIST_DCN2_0(id)}
5007ed4e635SHarry Wentland 
5017ed4e635SHarry Wentland 
5027ed4e635SHarry Wentland static const struct dcn_optc_registers tg_regs[] = {
5037ed4e635SHarry Wentland 	tg_regs(0),
5047ed4e635SHarry Wentland 	tg_regs(1),
5057ed4e635SHarry Wentland 	tg_regs(2),
5067ed4e635SHarry Wentland 	tg_regs(3),
5077ed4e635SHarry Wentland 	tg_regs(4),
5087ed4e635SHarry Wentland 	tg_regs(5)
5097ed4e635SHarry Wentland };
5107ed4e635SHarry Wentland 
5117ed4e635SHarry Wentland static const struct dcn_optc_shift tg_shift = {
5127ed4e635SHarry Wentland 	TG_COMMON_MASK_SH_LIST_DCN2_0(__SHIFT)
5137ed4e635SHarry Wentland };
5147ed4e635SHarry Wentland 
5157ed4e635SHarry Wentland static const struct dcn_optc_mask tg_mask = {
5167ed4e635SHarry Wentland 	TG_COMMON_MASK_SH_LIST_DCN2_0(_MASK)
5177ed4e635SHarry Wentland };
5187ed4e635SHarry Wentland 
5197ed4e635SHarry Wentland #define hubp_regs(id)\
5207ed4e635SHarry Wentland [id] = {\
5217ed4e635SHarry Wentland 	HUBP_REG_LIST_DCN20(id)\
5227ed4e635SHarry Wentland }
5237ed4e635SHarry Wentland 
5247ed4e635SHarry Wentland static const struct dcn_hubp2_registers hubp_regs[] = {
5257ed4e635SHarry Wentland 		hubp_regs(0),
5267ed4e635SHarry Wentland 		hubp_regs(1),
5277ed4e635SHarry Wentland 		hubp_regs(2),
5287ed4e635SHarry Wentland 		hubp_regs(3),
5297ed4e635SHarry Wentland 		hubp_regs(4),
5307ed4e635SHarry Wentland 		hubp_regs(5)
5317ed4e635SHarry Wentland };
5327ed4e635SHarry Wentland 
5337ed4e635SHarry Wentland static const struct dcn_hubp2_shift hubp_shift = {
5347ed4e635SHarry Wentland 		HUBP_MASK_SH_LIST_DCN20(__SHIFT)
5357ed4e635SHarry Wentland };
5367ed4e635SHarry Wentland 
5377ed4e635SHarry Wentland static const struct dcn_hubp2_mask hubp_mask = {
5387ed4e635SHarry Wentland 		HUBP_MASK_SH_LIST_DCN20(_MASK)
5397ed4e635SHarry Wentland };
5407ed4e635SHarry Wentland 
5417ed4e635SHarry Wentland static const struct dcn_hubbub_registers hubbub_reg = {
5427ed4e635SHarry Wentland 		HUBBUB_REG_LIST_DCN20(0)
5437ed4e635SHarry Wentland };
5447ed4e635SHarry Wentland 
5457ed4e635SHarry Wentland static const struct dcn_hubbub_shift hubbub_shift = {
5467ed4e635SHarry Wentland 		HUBBUB_MASK_SH_LIST_DCN20(__SHIFT)
5477ed4e635SHarry Wentland };
5487ed4e635SHarry Wentland 
5497ed4e635SHarry Wentland static const struct dcn_hubbub_mask hubbub_mask = {
5507ed4e635SHarry Wentland 		HUBBUB_MASK_SH_LIST_DCN20(_MASK)
5517ed4e635SHarry Wentland };
5527ed4e635SHarry Wentland 
5537ed4e635SHarry Wentland #define vmid_regs(id)\
5547ed4e635SHarry Wentland [id] = {\
5557ed4e635SHarry Wentland 		DCN20_VMID_REG_LIST(id)\
5567ed4e635SHarry Wentland }
5577ed4e635SHarry Wentland 
5587ed4e635SHarry Wentland static const struct dcn_vmid_registers vmid_regs[] = {
5597ed4e635SHarry Wentland 	vmid_regs(0),
5607ed4e635SHarry Wentland 	vmid_regs(1),
5617ed4e635SHarry Wentland 	vmid_regs(2),
5627ed4e635SHarry Wentland 	vmid_regs(3),
5637ed4e635SHarry Wentland 	vmid_regs(4),
5647ed4e635SHarry Wentland 	vmid_regs(5),
5657ed4e635SHarry Wentland 	vmid_regs(6),
5667ed4e635SHarry Wentland 	vmid_regs(7),
5677ed4e635SHarry Wentland 	vmid_regs(8),
5687ed4e635SHarry Wentland 	vmid_regs(9),
5697ed4e635SHarry Wentland 	vmid_regs(10),
5707ed4e635SHarry Wentland 	vmid_regs(11),
5717ed4e635SHarry Wentland 	vmid_regs(12),
5727ed4e635SHarry Wentland 	vmid_regs(13),
5737ed4e635SHarry Wentland 	vmid_regs(14),
5747ed4e635SHarry Wentland 	vmid_regs(15)
5757ed4e635SHarry Wentland };
5767ed4e635SHarry Wentland 
5777ed4e635SHarry Wentland static const struct dcn20_vmid_shift vmid_shifts = {
5787ed4e635SHarry Wentland 		DCN20_VMID_MASK_SH_LIST(__SHIFT)
5797ed4e635SHarry Wentland };
5807ed4e635SHarry Wentland 
5817ed4e635SHarry Wentland static const struct dcn20_vmid_mask vmid_masks = {
5827ed4e635SHarry Wentland 		DCN20_VMID_MASK_SH_LIST(_MASK)
5837ed4e635SHarry Wentland };
5847ed4e635SHarry Wentland 
5858276dd87Sabdoulaye berthe static const struct dce110_aux_registers_shift aux_shift = {
5868276dd87Sabdoulaye berthe 		DCN_AUX_MASK_SH_LIST(__SHIFT)
5878276dd87Sabdoulaye berthe };
5888276dd87Sabdoulaye berthe 
5898276dd87Sabdoulaye berthe static const struct dce110_aux_registers_mask aux_mask = {
5908276dd87Sabdoulaye berthe 		DCN_AUX_MASK_SH_LIST(_MASK)
5918276dd87Sabdoulaye berthe };
5928276dd87Sabdoulaye berthe 
map_transmitter_id_to_phy_instance(enum transmitter transmitter)593bf7f5ac3SYogesh Mohan Marimuthu static int map_transmitter_id_to_phy_instance(
594bf7f5ac3SYogesh Mohan Marimuthu 	enum transmitter transmitter)
595bf7f5ac3SYogesh Mohan Marimuthu {
596bf7f5ac3SYogesh Mohan Marimuthu 	switch (transmitter) {
597bf7f5ac3SYogesh Mohan Marimuthu 	case TRANSMITTER_UNIPHY_A:
598bf7f5ac3SYogesh Mohan Marimuthu 		return 0;
599bf7f5ac3SYogesh Mohan Marimuthu 	break;
600bf7f5ac3SYogesh Mohan Marimuthu 	case TRANSMITTER_UNIPHY_B:
601bf7f5ac3SYogesh Mohan Marimuthu 		return 1;
602bf7f5ac3SYogesh Mohan Marimuthu 	break;
603bf7f5ac3SYogesh Mohan Marimuthu 	case TRANSMITTER_UNIPHY_C:
604bf7f5ac3SYogesh Mohan Marimuthu 		return 2;
605bf7f5ac3SYogesh Mohan Marimuthu 	break;
606bf7f5ac3SYogesh Mohan Marimuthu 	case TRANSMITTER_UNIPHY_D:
607bf7f5ac3SYogesh Mohan Marimuthu 		return 3;
608bf7f5ac3SYogesh Mohan Marimuthu 	break;
609bf7f5ac3SYogesh Mohan Marimuthu 	case TRANSMITTER_UNIPHY_E:
610bf7f5ac3SYogesh Mohan Marimuthu 		return 4;
611bf7f5ac3SYogesh Mohan Marimuthu 	break;
612bf7f5ac3SYogesh Mohan Marimuthu 	case TRANSMITTER_UNIPHY_F:
613bf7f5ac3SYogesh Mohan Marimuthu 		return 5;
614bf7f5ac3SYogesh Mohan Marimuthu 	break;
615bf7f5ac3SYogesh Mohan Marimuthu 	default:
616bf7f5ac3SYogesh Mohan Marimuthu 		ASSERT(0);
617bf7f5ac3SYogesh Mohan Marimuthu 		return 0;
618bf7f5ac3SYogesh Mohan Marimuthu 	}
619bf7f5ac3SYogesh Mohan Marimuthu }
6208276dd87Sabdoulaye berthe 
62197bda032SHarry Wentland #define dsc_regsDCN20(id)\
62297bda032SHarry Wentland [id] = {\
62397bda032SHarry Wentland 	DSC_REG_LIST_DCN20(id)\
62497bda032SHarry Wentland }
62597bda032SHarry Wentland 
62697bda032SHarry Wentland static const struct dcn20_dsc_registers dsc_regs[] = {
62797bda032SHarry Wentland 	dsc_regsDCN20(0),
62897bda032SHarry Wentland 	dsc_regsDCN20(1),
62997bda032SHarry Wentland 	dsc_regsDCN20(2),
63097bda032SHarry Wentland 	dsc_regsDCN20(3),
63197bda032SHarry Wentland 	dsc_regsDCN20(4),
63297bda032SHarry Wentland 	dsc_regsDCN20(5)
63397bda032SHarry Wentland };
63497bda032SHarry Wentland 
63597bda032SHarry Wentland static const struct dcn20_dsc_shift dsc_shift = {
63697bda032SHarry Wentland 	DSC_REG_LIST_SH_MASK_DCN20(__SHIFT)
63797bda032SHarry Wentland };
63897bda032SHarry Wentland 
63997bda032SHarry Wentland static const struct dcn20_dsc_mask dsc_mask = {
64097bda032SHarry Wentland 	DSC_REG_LIST_SH_MASK_DCN20(_MASK)
64197bda032SHarry Wentland };
6427ed4e635SHarry Wentland 
6437ed4e635SHarry Wentland static const struct dccg_registers dccg_regs = {
6447ed4e635SHarry Wentland 		DCCG_REG_LIST_DCN2()
6457ed4e635SHarry Wentland };
6467ed4e635SHarry Wentland 
6477ed4e635SHarry Wentland static const struct dccg_shift dccg_shift = {
6487ed4e635SHarry Wentland 		DCCG_MASK_SH_LIST_DCN2(__SHIFT)
6497ed4e635SHarry Wentland };
6507ed4e635SHarry Wentland 
6517ed4e635SHarry Wentland static const struct dccg_mask dccg_mask = {
6527ed4e635SHarry Wentland 		DCCG_MASK_SH_LIST_DCN2(_MASK)
6537ed4e635SHarry Wentland };
6547ed4e635SHarry Wentland 
6557ed4e635SHarry Wentland static const struct resource_caps res_cap_nv10 = {
6567ed4e635SHarry Wentland 		.num_timing_generator = 6,
6577ed4e635SHarry Wentland 		.num_opp = 6,
6587ed4e635SHarry Wentland 		.num_video_plane = 6,
6597ed4e635SHarry Wentland 		.num_audio = 7,
6607ed4e635SHarry Wentland 		.num_stream_encoder = 6,
6617ed4e635SHarry Wentland 		.num_pll = 6,
6629cbee6efShersen wu 		.num_dwb = 1,
6637ed4e635SHarry Wentland 		.num_ddc = 6,
6647ed4e635SHarry Wentland 		.num_vmid = 16,
66597bda032SHarry Wentland 		.num_dsc = 6,
6667ed4e635SHarry Wentland };
6677ed4e635SHarry Wentland 
6687ed4e635SHarry Wentland static const struct dc_plane_cap plane_cap = {
6697ed4e635SHarry Wentland 	.type = DC_PLANE_TYPE_DCN_UNIVERSAL,
6707ed4e635SHarry Wentland 	.per_pixel_alpha = true,
6715b1b2f20SAlex Deucher 
6725b1b2f20SAlex Deucher 	.pixel_format_support = {
6735b1b2f20SAlex Deucher 			.argb8888 = true,
6745b1b2f20SAlex Deucher 			.nv12 = true,
675cbec6477SStylon Wang 			.fp16 = true,
676cbec6477SStylon Wang 			.p010 = true
6775b1b2f20SAlex Deucher 	},
6785b1b2f20SAlex Deucher 
6795b1b2f20SAlex Deucher 	.max_upscale_factor = {
6805b1b2f20SAlex Deucher 			.argb8888 = 16000,
6815b1b2f20SAlex Deucher 			.nv12 = 16000,
6825b1b2f20SAlex Deucher 			.fp16 = 1
6835b1b2f20SAlex Deucher 	},
6845b1b2f20SAlex Deucher 
6855b1b2f20SAlex Deucher 	.max_downscale_factor = {
6865b1b2f20SAlex Deucher 			.argb8888 = 250,
6875b1b2f20SAlex Deucher 			.nv12 = 250,
6885b1b2f20SAlex Deucher 			.fp16 = 1
6893b26ca2dSIgor Kravchenko 	},
6903b26ca2dSIgor Kravchenko 	16,
6913b26ca2dSIgor Kravchenko 	16
6927ed4e635SHarry Wentland };
6932ebe1773SBhawanpreet Lakha static const struct resource_caps res_cap_nv14 = {
6942ebe1773SBhawanpreet Lakha 		.num_timing_generator = 5,
6952ebe1773SBhawanpreet Lakha 		.num_opp = 5,
6962ebe1773SBhawanpreet Lakha 		.num_video_plane = 5,
6972ebe1773SBhawanpreet Lakha 		.num_audio = 6,
6982ebe1773SBhawanpreet Lakha 		.num_stream_encoder = 5,
6992ebe1773SBhawanpreet Lakha 		.num_pll = 5,
70080df905dSZhan liu 		.num_dwb = 1,
7012ebe1773SBhawanpreet Lakha 		.num_ddc = 5,
7026bb27085SZhan Liu 		.num_vmid = 16,
7036bb27085SZhan Liu 		.num_dsc = 5,
7042ebe1773SBhawanpreet Lakha };
7057ed4e635SHarry Wentland 
7067ed4e635SHarry Wentland static const struct dc_debug_options debug_defaults_drv = {
707f0a574c9SWyatt Wood 		.disable_dmcu = false,
7087ed4e635SHarry Wentland 		.force_abm_enable = false,
7097ed4e635SHarry Wentland 		.clock_trace = true,
7107ed4e635SHarry Wentland 		.disable_pplib_clock_request = true,
711ef35c7baSAlex Deucher 		.pipe_split_policy = MPC_SPLIT_AVOID_MULT_DISP,
7124d25a0d5SMichael Strauss 		.force_single_disp_pipe_split = false,
7137ed4e635SHarry Wentland 		.disable_dcc = DCC_ENABLE,
7147ed4e635SHarry Wentland 		.vsr_support = true,
7157ed4e635SHarry Wentland 		.performance_trace = false,
7167ed4e635SHarry Wentland 		.max_downscale_src_width = 5120,/*upto 5K*/
7177ed4e635SHarry Wentland 		.disable_pplib_wm_range = false,
7187ed4e635SHarry Wentland 		.scl_reset_length10 = true,
7199e14d4f1Shersen wu 		.sanity_checks = false,
7201a7d296dSThomas Lim 		.underflow_assert_delay_us = 0xFFFFFFFF,
7210baae624SAlvin Lee 		.enable_legacy_fast_update = true,
72279de4d9aSRodrigo Siqueira 		.using_dml2 = false,
7237ed4e635SHarry Wentland };
7247ed4e635SHarry Wentland 
dcn20_dpp_destroy(struct dpp ** dpp)7257ed4e635SHarry Wentland void dcn20_dpp_destroy(struct dpp **dpp)
7267ed4e635SHarry Wentland {
7277ed4e635SHarry Wentland 	kfree(TO_DCN20_DPP(*dpp));
7287ed4e635SHarry Wentland 	*dpp = NULL;
7297ed4e635SHarry Wentland }
7307ed4e635SHarry Wentland 
dcn20_dpp_create(struct dc_context * ctx,uint32_t inst)7317ed4e635SHarry Wentland struct dpp *dcn20_dpp_create(
7327ed4e635SHarry Wentland 	struct dc_context *ctx,
7337ed4e635SHarry Wentland 	uint32_t inst)
7347ed4e635SHarry Wentland {
7357ed4e635SHarry Wentland 	struct dcn20_dpp *dpp =
7363bb11050SNirmoy Das 		kzalloc(sizeof(struct dcn20_dpp), GFP_ATOMIC);
7377ed4e635SHarry Wentland 
7387ed4e635SHarry Wentland 	if (!dpp)
7397ed4e635SHarry Wentland 		return NULL;
7407ed4e635SHarry Wentland 
7417ed4e635SHarry Wentland 	if (dpp2_construct(dpp, ctx, inst,
7427ed4e635SHarry Wentland 			&tf_regs[inst], &tf_shift, &tf_mask))
7437ed4e635SHarry Wentland 		return &dpp->base;
7447ed4e635SHarry Wentland 
7457ed4e635SHarry Wentland 	BREAK_TO_DEBUGGER();
7467ed4e635SHarry Wentland 	kfree(dpp);
7477ed4e635SHarry Wentland 	return NULL;
7487ed4e635SHarry Wentland }
7497ed4e635SHarry Wentland 
dcn20_ipp_create(struct dc_context * ctx,uint32_t inst)7507ed4e635SHarry Wentland struct input_pixel_processor *dcn20_ipp_create(
7517ed4e635SHarry Wentland 	struct dc_context *ctx, uint32_t inst)
7527ed4e635SHarry Wentland {
7537ed4e635SHarry Wentland 	struct dcn10_ipp *ipp =
7543bb11050SNirmoy Das 		kzalloc(sizeof(struct dcn10_ipp), GFP_ATOMIC);
7557ed4e635SHarry Wentland 
7567ed4e635SHarry Wentland 	if (!ipp) {
7577ed4e635SHarry Wentland 		BREAK_TO_DEBUGGER();
7587ed4e635SHarry Wentland 		return NULL;
7597ed4e635SHarry Wentland 	}
7607ed4e635SHarry Wentland 
7617ed4e635SHarry Wentland 	dcn20_ipp_construct(ipp, ctx, inst,
7627ed4e635SHarry Wentland 			&ipp_regs[inst], &ipp_shift, &ipp_mask);
7637ed4e635SHarry Wentland 	return &ipp->base;
7647ed4e635SHarry Wentland }
7657ed4e635SHarry Wentland 
7667ed4e635SHarry Wentland 
dcn20_opp_create(struct dc_context * ctx,uint32_t inst)7677ed4e635SHarry Wentland struct output_pixel_processor *dcn20_opp_create(
7687ed4e635SHarry Wentland 	struct dc_context *ctx, uint32_t inst)
7697ed4e635SHarry Wentland {
7707ed4e635SHarry Wentland 	struct dcn20_opp *opp =
7713bb11050SNirmoy Das 		kzalloc(sizeof(struct dcn20_opp), GFP_ATOMIC);
7727ed4e635SHarry Wentland 
7737ed4e635SHarry Wentland 	if (!opp) {
7747ed4e635SHarry Wentland 		BREAK_TO_DEBUGGER();
7757ed4e635SHarry Wentland 		return NULL;
7767ed4e635SHarry Wentland 	}
7777ed4e635SHarry Wentland 
7787ed4e635SHarry Wentland 	dcn20_opp_construct(opp, ctx, inst,
7797ed4e635SHarry Wentland 			&opp_regs[inst], &opp_shift, &opp_mask);
7807ed4e635SHarry Wentland 	return &opp->base;
7817ed4e635SHarry Wentland }
7827ed4e635SHarry Wentland 
dcn20_aux_engine_create(struct dc_context * ctx,uint32_t inst)7837ed4e635SHarry Wentland struct dce_aux *dcn20_aux_engine_create(
7847ed4e635SHarry Wentland 	struct dc_context *ctx,
7857ed4e635SHarry Wentland 	uint32_t inst)
7867ed4e635SHarry Wentland {
7877ed4e635SHarry Wentland 	struct aux_engine_dce110 *aux_engine =
7883bb11050SNirmoy Das 		kzalloc(sizeof(struct aux_engine_dce110), GFP_ATOMIC);
7897ed4e635SHarry Wentland 
7907ed4e635SHarry Wentland 	if (!aux_engine)
7917ed4e635SHarry Wentland 		return NULL;
7927ed4e635SHarry Wentland 
7937ed4e635SHarry Wentland 	dce110_aux_engine_construct(aux_engine, ctx, inst,
7947ed4e635SHarry Wentland 				    SW_AUX_TIMEOUT_PERIOD_MULTIPLIER * AUX_TIMEOUT_PERIOD,
7958276dd87Sabdoulaye berthe 				    &aux_engine_regs[inst],
7968276dd87Sabdoulaye berthe 					&aux_mask,
797f6040a43Sabdoulaye berthe 					&aux_shift,
798f6040a43Sabdoulaye berthe 					ctx->dc->caps.extended_aux_timeout_support);
7997ed4e635SHarry Wentland 
8007ed4e635SHarry Wentland 	return &aux_engine->base;
8017ed4e635SHarry Wentland }
8027ed4e635SHarry Wentland #define i2c_inst_regs(id) { I2C_HW_ENGINE_COMMON_REG_LIST(id) }
8037ed4e635SHarry Wentland 
8047ed4e635SHarry Wentland static const struct dce_i2c_registers i2c_hw_regs[] = {
8057ed4e635SHarry Wentland 		i2c_inst_regs(1),
8067ed4e635SHarry Wentland 		i2c_inst_regs(2),
8077ed4e635SHarry Wentland 		i2c_inst_regs(3),
8087ed4e635SHarry Wentland 		i2c_inst_regs(4),
8097ed4e635SHarry Wentland 		i2c_inst_regs(5),
8107ed4e635SHarry Wentland 		i2c_inst_regs(6),
8117ed4e635SHarry Wentland };
8127ed4e635SHarry Wentland 
8137ed4e635SHarry Wentland static const struct dce_i2c_shift i2c_shifts = {
8147ed4e635SHarry Wentland 		I2C_COMMON_MASK_SH_LIST_DCN2(__SHIFT)
8157ed4e635SHarry Wentland };
8167ed4e635SHarry Wentland 
8177ed4e635SHarry Wentland static const struct dce_i2c_mask i2c_masks = {
8187ed4e635SHarry Wentland 		I2C_COMMON_MASK_SH_LIST_DCN2(_MASK)
8197ed4e635SHarry Wentland };
8207ed4e635SHarry Wentland 
dcn20_i2c_hw_create(struct dc_context * ctx,uint32_t inst)8217ed4e635SHarry Wentland struct dce_i2c_hw *dcn20_i2c_hw_create(
8227ed4e635SHarry Wentland 	struct dc_context *ctx,
8237ed4e635SHarry Wentland 	uint32_t inst)
8247ed4e635SHarry Wentland {
8257ed4e635SHarry Wentland 	struct dce_i2c_hw *dce_i2c_hw =
8263bb11050SNirmoy Das 		kzalloc(sizeof(struct dce_i2c_hw), GFP_ATOMIC);
8277ed4e635SHarry Wentland 
8287ed4e635SHarry Wentland 	if (!dce_i2c_hw)
8297ed4e635SHarry Wentland 		return NULL;
8307ed4e635SHarry Wentland 
8317ed4e635SHarry Wentland 	dcn2_i2c_hw_construct(dce_i2c_hw, ctx, inst,
8327ed4e635SHarry Wentland 				    &i2c_hw_regs[inst], &i2c_shifts, &i2c_masks);
8337ed4e635SHarry Wentland 
8347ed4e635SHarry Wentland 	return dce_i2c_hw;
8357ed4e635SHarry Wentland }
dcn20_mpc_create(struct dc_context * ctx)8367ed4e635SHarry Wentland struct mpc *dcn20_mpc_create(struct dc_context *ctx)
8377ed4e635SHarry Wentland {
8387ed4e635SHarry Wentland 	struct dcn20_mpc *mpc20 = kzalloc(sizeof(struct dcn20_mpc),
8393bb11050SNirmoy Das 					  GFP_ATOMIC);
8407ed4e635SHarry Wentland 
8417ed4e635SHarry Wentland 	if (!mpc20)
8427ed4e635SHarry Wentland 		return NULL;
8437ed4e635SHarry Wentland 
8447ed4e635SHarry Wentland 	dcn20_mpc_construct(mpc20, ctx,
8457ed4e635SHarry Wentland 			&mpc_regs,
8467ed4e635SHarry Wentland 			&mpc_shift,
8477ed4e635SHarry Wentland 			&mpc_mask,
8487ed4e635SHarry Wentland 			6);
8497ed4e635SHarry Wentland 
8507ed4e635SHarry Wentland 	return &mpc20->base;
8517ed4e635SHarry Wentland }
8527ed4e635SHarry Wentland 
dcn20_hubbub_create(struct dc_context * ctx)8537ed4e635SHarry Wentland struct hubbub *dcn20_hubbub_create(struct dc_context *ctx)
8547ed4e635SHarry Wentland {
8557ed4e635SHarry Wentland 	int i;
8567ed4e635SHarry Wentland 	struct dcn20_hubbub *hubbub = kzalloc(sizeof(struct dcn20_hubbub),
8573bb11050SNirmoy Das 					  GFP_ATOMIC);
8587ed4e635SHarry Wentland 
8597ed4e635SHarry Wentland 	if (!hubbub)
8607ed4e635SHarry Wentland 		return NULL;
8617ed4e635SHarry Wentland 
8627ed4e635SHarry Wentland 	hubbub2_construct(hubbub, ctx,
8637ed4e635SHarry Wentland 			&hubbub_reg,
8647ed4e635SHarry Wentland 			&hubbub_shift,
8657ed4e635SHarry Wentland 			&hubbub_mask);
8667ed4e635SHarry Wentland 
8677ed4e635SHarry Wentland 	for (i = 0; i < res_cap_nv10.num_vmid; i++) {
8687ed4e635SHarry Wentland 		struct dcn20_vmid *vmid = &hubbub->vmid[i];
8697ed4e635SHarry Wentland 
8707ed4e635SHarry Wentland 		vmid->ctx = ctx;
8717ed4e635SHarry Wentland 
8727ed4e635SHarry Wentland 		vmid->regs = &vmid_regs[i];
8737ed4e635SHarry Wentland 		vmid->shifts = &vmid_shifts;
8747ed4e635SHarry Wentland 		vmid->masks = &vmid_masks;
8757ed4e635SHarry Wentland 	}
8767ed4e635SHarry Wentland 
8777ed4e635SHarry Wentland 	return &hubbub->base;
8787ed4e635SHarry Wentland }
8797ed4e635SHarry Wentland 
dcn20_timing_generator_create(struct dc_context * ctx,uint32_t instance)8807ed4e635SHarry Wentland struct timing_generator *dcn20_timing_generator_create(
8817ed4e635SHarry Wentland 		struct dc_context *ctx,
8827ed4e635SHarry Wentland 		uint32_t instance)
8837ed4e635SHarry Wentland {
8847ed4e635SHarry Wentland 	struct optc *tgn10 =
8853bb11050SNirmoy Das 		kzalloc(sizeof(struct optc), GFP_ATOMIC);
8867ed4e635SHarry Wentland 
8877ed4e635SHarry Wentland 	if (!tgn10)
8887ed4e635SHarry Wentland 		return NULL;
8897ed4e635SHarry Wentland 
8907ed4e635SHarry Wentland 	tgn10->base.inst = instance;
8917ed4e635SHarry Wentland 	tgn10->base.ctx = ctx;
8927ed4e635SHarry Wentland 
8937ed4e635SHarry Wentland 	tgn10->tg_regs = &tg_regs[instance];
8947ed4e635SHarry Wentland 	tgn10->tg_shift = &tg_shift;
8957ed4e635SHarry Wentland 	tgn10->tg_mask = &tg_mask;
8967ed4e635SHarry Wentland 
8977ed4e635SHarry Wentland 	dcn20_timing_generator_init(tgn10);
8987ed4e635SHarry Wentland 
8997ed4e635SHarry Wentland 	return &tgn10->base;
9007ed4e635SHarry Wentland }
9017ed4e635SHarry Wentland 
9027ed4e635SHarry Wentland static const struct encoder_feature_support link_enc_feature = {
9037ed4e635SHarry Wentland 		.max_hdmi_deep_color = COLOR_DEPTH_121212,
9047ed4e635SHarry Wentland 		.max_hdmi_pixel_clock = 600000,
9057ed4e635SHarry Wentland 		.hdmi_ycbcr420_supported = true,
9067ed4e635SHarry Wentland 		.dp_ycbcr420_supported = true,
907c14b726eSWenjing Liu 		.fec_supported = true,
9087ed4e635SHarry Wentland 		.flags.bits.IS_HBR2_CAPABLE = true,
9097ed4e635SHarry Wentland 		.flags.bits.IS_HBR3_CAPABLE = true,
9107ed4e635SHarry Wentland 		.flags.bits.IS_TPS3_CAPABLE = true,
9117ed4e635SHarry Wentland 		.flags.bits.IS_TPS4_CAPABLE = true
9127ed4e635SHarry Wentland };
9137ed4e635SHarry Wentland 
dcn20_link_encoder_create(struct dc_context * ctx,const struct encoder_init_data * enc_init_data)9147ed4e635SHarry Wentland struct link_encoder *dcn20_link_encoder_create(
915e216431bSAurabindo Pillai 	struct dc_context *ctx,
9167ed4e635SHarry Wentland 	const struct encoder_init_data *enc_init_data)
9177ed4e635SHarry Wentland {
9187ed4e635SHarry Wentland 	struct dcn20_link_encoder *enc20 =
9197ed4e635SHarry Wentland 		kzalloc(sizeof(struct dcn20_link_encoder), GFP_KERNEL);
920bf7f5ac3SYogesh Mohan Marimuthu 	int link_regs_id;
9217ed4e635SHarry Wentland 
92240d7299cSSrinivasan Shanmugam 	if (!enc20 || enc_init_data->hpd_source >= ARRAY_SIZE(link_enc_hpd_regs))
9237ed4e635SHarry Wentland 		return NULL;
9247ed4e635SHarry Wentland 
925bf7f5ac3SYogesh Mohan Marimuthu 	link_regs_id =
926bf7f5ac3SYogesh Mohan Marimuthu 		map_transmitter_id_to_phy_instance(enc_init_data->transmitter);
927bf7f5ac3SYogesh Mohan Marimuthu 
9287ed4e635SHarry Wentland 	dcn20_link_encoder_construct(enc20,
9297ed4e635SHarry Wentland 				      enc_init_data,
9307ed4e635SHarry Wentland 				      &link_enc_feature,
931bf7f5ac3SYogesh Mohan Marimuthu 				      &link_enc_regs[link_regs_id],
9327ed4e635SHarry Wentland 				      &link_enc_aux_regs[enc_init_data->channel - 1],
9337ed4e635SHarry Wentland 				      &link_enc_hpd_regs[enc_init_data->hpd_source],
9347ed4e635SHarry Wentland 				      &le_shift,
9357ed4e635SHarry Wentland 				      &le_mask);
9367ed4e635SHarry Wentland 
9377ed4e635SHarry Wentland 	return &enc20->enc10.base;
9387ed4e635SHarry Wentland }
9397ed4e635SHarry Wentland 
dcn20_panel_cntl_create(const struct panel_cntl_init_data * init_data)940d4caa72eSAnthony Koo static struct panel_cntl *dcn20_panel_cntl_create(const struct panel_cntl_init_data *init_data)
941904fb6e0SAnthony Koo {
942d4caa72eSAnthony Koo 	struct dce_panel_cntl *panel_cntl =
943d4caa72eSAnthony Koo 		kzalloc(sizeof(struct dce_panel_cntl), GFP_KERNEL);
944904fb6e0SAnthony Koo 
945d4caa72eSAnthony Koo 	if (!panel_cntl)
946904fb6e0SAnthony Koo 		return NULL;
947904fb6e0SAnthony Koo 
948d4caa72eSAnthony Koo 	dce_panel_cntl_construct(panel_cntl,
949904fb6e0SAnthony Koo 			init_data,
950d4caa72eSAnthony Koo 			&panel_cntl_regs[init_data->inst],
951d4caa72eSAnthony Koo 			&panel_cntl_shift,
952d4caa72eSAnthony Koo 			&panel_cntl_mask);
953904fb6e0SAnthony Koo 
954d4caa72eSAnthony Koo 	return &panel_cntl->base;
955904fb6e0SAnthony Koo }
956904fb6e0SAnthony Koo 
dcn20_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)957dfd84d90SNirmoy Das static struct clock_source *dcn20_clock_source_create(
9587ed4e635SHarry Wentland 	struct dc_context *ctx,
9597ed4e635SHarry Wentland 	struct dc_bios *bios,
9607ed4e635SHarry Wentland 	enum clock_source_id id,
9617ed4e635SHarry Wentland 	const struct dce110_clk_src_regs *regs,
9627ed4e635SHarry Wentland 	bool dp_clk_src)
9637ed4e635SHarry Wentland {
9647ed4e635SHarry Wentland 	struct dce110_clk_src *clk_src =
9653bb11050SNirmoy Das 		kzalloc(sizeof(struct dce110_clk_src), GFP_ATOMIC);
9667ed4e635SHarry Wentland 
9677ed4e635SHarry Wentland 	if (!clk_src)
9687ed4e635SHarry Wentland 		return NULL;
9697ed4e635SHarry Wentland 
9707ed4e635SHarry Wentland 	if (dcn20_clk_src_construct(clk_src, ctx, bios, id,
9717ed4e635SHarry Wentland 			regs, &cs_shift, &cs_mask)) {
9727ed4e635SHarry Wentland 		clk_src->base.dp_clk_src = dp_clk_src;
9737ed4e635SHarry Wentland 		return &clk_src->base;
9747ed4e635SHarry Wentland 	}
9757ed4e635SHarry Wentland 
976cabe144bSNavid Emamdoost 	kfree(clk_src);
9777ed4e635SHarry Wentland 	BREAK_TO_DEBUGGER();
9787ed4e635SHarry Wentland 	return NULL;
9797ed4e635SHarry Wentland }
9807ed4e635SHarry Wentland 
read_dce_straps(struct dc_context * ctx,struct resource_straps * straps)9817ed4e635SHarry Wentland static void read_dce_straps(
9827ed4e635SHarry Wentland 	struct dc_context *ctx,
9837ed4e635SHarry Wentland 	struct resource_straps *straps)
9847ed4e635SHarry Wentland {
9857ed4e635SHarry Wentland 	generic_reg_get(ctx, mmDC_PINSTRAPS + BASE(mmDC_PINSTRAPS_BASE_IDX),
9867ed4e635SHarry Wentland 		FN(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO), &straps->dc_pinstraps_audio);
9877ed4e635SHarry Wentland }
9887ed4e635SHarry Wentland 
dcn20_create_audio(struct dc_context * ctx,unsigned int inst)9897ed4e635SHarry Wentland static struct audio *dcn20_create_audio(
9907ed4e635SHarry Wentland 		struct dc_context *ctx, unsigned int inst)
9917ed4e635SHarry Wentland {
9927ed4e635SHarry Wentland 	return dce_audio_create(ctx, inst,
9937ed4e635SHarry Wentland 			&audio_regs[inst], &audio_shift, &audio_mask);
9947ed4e635SHarry Wentland }
9957ed4e635SHarry Wentland 
dcn20_stream_encoder_create(enum engine_id eng_id,struct dc_context * ctx)9967ed4e635SHarry Wentland struct stream_encoder *dcn20_stream_encoder_create(
9977ed4e635SHarry Wentland 	enum engine_id eng_id,
9987ed4e635SHarry Wentland 	struct dc_context *ctx)
9997ed4e635SHarry Wentland {
10007ed4e635SHarry Wentland 	struct dcn10_stream_encoder *enc1 =
10017ed4e635SHarry Wentland 		kzalloc(sizeof(struct dcn10_stream_encoder), GFP_KERNEL);
10027ed4e635SHarry Wentland 
10037ed4e635SHarry Wentland 	if (!enc1)
10047ed4e635SHarry Wentland 		return NULL;
10057ed4e635SHarry Wentland 
10069fd4c2d7SZhan Liu 	if (ASICREV_IS_NAVI14_M(ctx->asic_id.hw_internal_rev)) {
10079fd4c2d7SZhan Liu 		if (eng_id >= ENGINE_ID_DIGD)
10089fd4c2d7SZhan Liu 			eng_id++;
10099fd4c2d7SZhan Liu 	}
10109fd4c2d7SZhan Liu 
10117ed4e635SHarry Wentland 	dcn20_stream_encoder_construct(enc1, ctx, ctx->dc_bios, eng_id,
10127ed4e635SHarry Wentland 					&stream_enc_regs[eng_id],
10137ed4e635SHarry Wentland 					&se_shift, &se_mask);
10147ed4e635SHarry Wentland 
10157ed4e635SHarry Wentland 	return &enc1->base;
10167ed4e635SHarry Wentland }
10177ed4e635SHarry Wentland 
10187ed4e635SHarry Wentland static const struct dce_hwseq_registers hwseq_reg = {
10197ed4e635SHarry Wentland 		HWSEQ_DCN2_REG_LIST()
10207ed4e635SHarry Wentland };
10217ed4e635SHarry Wentland 
10227ed4e635SHarry Wentland static const struct dce_hwseq_shift hwseq_shift = {
10237ed4e635SHarry Wentland 		HWSEQ_DCN2_MASK_SH_LIST(__SHIFT)
10247ed4e635SHarry Wentland };
10257ed4e635SHarry Wentland 
10267ed4e635SHarry Wentland static const struct dce_hwseq_mask hwseq_mask = {
10277ed4e635SHarry Wentland 		HWSEQ_DCN2_MASK_SH_LIST(_MASK)
10287ed4e635SHarry Wentland };
10297ed4e635SHarry Wentland 
dcn20_hwseq_create(struct dc_context * ctx)10307ed4e635SHarry Wentland struct dce_hwseq *dcn20_hwseq_create(
10317ed4e635SHarry Wentland 	struct dc_context *ctx)
10327ed4e635SHarry Wentland {
10337ed4e635SHarry Wentland 	struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL);
10347ed4e635SHarry Wentland 
10357ed4e635SHarry Wentland 	if (hws) {
10367ed4e635SHarry Wentland 		hws->ctx = ctx;
10377ed4e635SHarry Wentland 		hws->regs = &hwseq_reg;
10387ed4e635SHarry Wentland 		hws->shifts = &hwseq_shift;
10397ed4e635SHarry Wentland 		hws->masks = &hwseq_mask;
10407ed4e635SHarry Wentland 	}
10417ed4e635SHarry Wentland 	return hws;
10427ed4e635SHarry Wentland }
10437ed4e635SHarry Wentland 
10447ed4e635SHarry Wentland static const struct resource_create_funcs res_create_funcs = {
10457ed4e635SHarry Wentland 	.read_dce_straps = read_dce_straps,
10467ed4e635SHarry Wentland 	.create_audio = dcn20_create_audio,
10477ed4e635SHarry Wentland 	.create_stream_encoder = dcn20_stream_encoder_create,
10487ed4e635SHarry Wentland 	.create_hwseq = dcn20_hwseq_create,
10497ed4e635SHarry Wentland };
10507ed4e635SHarry Wentland 
105144e149bbSAlex Deucher static void dcn20_pp_smu_destroy(struct pp_smu_funcs **pp_smu);
105244e149bbSAlex Deucher 
dcn20_clock_source_destroy(struct clock_source ** clk_src)10537ed4e635SHarry Wentland void dcn20_clock_source_destroy(struct clock_source **clk_src)
10547ed4e635SHarry Wentland {
10557ed4e635SHarry Wentland 	kfree(TO_DCE110_CLK_SRC(*clk_src));
10567ed4e635SHarry Wentland 	*clk_src = NULL;
10577ed4e635SHarry Wentland }
10587ed4e635SHarry Wentland 
105997bda032SHarry Wentland 
dcn20_dsc_create(struct dc_context * ctx,uint32_t inst)106097bda032SHarry Wentland struct display_stream_compressor *dcn20_dsc_create(
106197bda032SHarry Wentland 	struct dc_context *ctx, uint32_t inst)
106297bda032SHarry Wentland {
106397bda032SHarry Wentland 	struct dcn20_dsc *dsc =
10643bb11050SNirmoy Das 		kzalloc(sizeof(struct dcn20_dsc), GFP_ATOMIC);
106597bda032SHarry Wentland 
106697bda032SHarry Wentland 	if (!dsc) {
106797bda032SHarry Wentland 		BREAK_TO_DEBUGGER();
106897bda032SHarry Wentland 		return NULL;
106997bda032SHarry Wentland 	}
107097bda032SHarry Wentland 
107197bda032SHarry Wentland 	dsc2_construct(dsc, ctx, inst, &dsc_regs[inst], &dsc_shift, &dsc_mask);
107297bda032SHarry Wentland 	return &dsc->base;
107397bda032SHarry Wentland }
107497bda032SHarry Wentland 
dcn20_dsc_destroy(struct display_stream_compressor ** dsc)107597bda032SHarry Wentland void dcn20_dsc_destroy(struct display_stream_compressor **dsc)
107697bda032SHarry Wentland {
107797bda032SHarry Wentland 	kfree(container_of(*dsc, struct dcn20_dsc, base));
107897bda032SHarry Wentland 	*dsc = NULL;
107997bda032SHarry Wentland }
108097bda032SHarry Wentland 
10817ed4e635SHarry Wentland 
dcn20_resource_destruct(struct dcn20_resource_pool * pool)1082d9e32672SAnthony Koo static void dcn20_resource_destruct(struct dcn20_resource_pool *pool)
10837ed4e635SHarry Wentland {
10847ed4e635SHarry Wentland 	unsigned int i;
10857ed4e635SHarry Wentland 
10867ed4e635SHarry Wentland 	for (i = 0; i < pool->base.stream_enc_count; i++) {
10877ed4e635SHarry Wentland 		if (pool->base.stream_enc[i] != NULL) {
10887ed4e635SHarry Wentland 			kfree(DCN10STRENC_FROM_STRENC(pool->base.stream_enc[i]));
10897ed4e635SHarry Wentland 			pool->base.stream_enc[i] = NULL;
10907ed4e635SHarry Wentland 		}
10917ed4e635SHarry Wentland 	}
10927ed4e635SHarry Wentland 
109397bda032SHarry Wentland 	for (i = 0; i < pool->base.res_cap->num_dsc; i++) {
109497bda032SHarry Wentland 		if (pool->base.dscs[i] != NULL)
109597bda032SHarry Wentland 			dcn20_dsc_destroy(&pool->base.dscs[i]);
109697bda032SHarry Wentland 	}
10977ed4e635SHarry Wentland 
10987ed4e635SHarry Wentland 	if (pool->base.mpc != NULL) {
10997ed4e635SHarry Wentland 		kfree(TO_DCN20_MPC(pool->base.mpc));
11007ed4e635SHarry Wentland 		pool->base.mpc = NULL;
11017ed4e635SHarry Wentland 	}
11027ed4e635SHarry Wentland 	if (pool->base.hubbub != NULL) {
11037ed4e635SHarry Wentland 		kfree(pool->base.hubbub);
11047ed4e635SHarry Wentland 		pool->base.hubbub = NULL;
11057ed4e635SHarry Wentland 	}
11067ed4e635SHarry Wentland 	for (i = 0; i < pool->base.pipe_count; i++) {
11077ed4e635SHarry Wentland 		if (pool->base.dpps[i] != NULL)
11087ed4e635SHarry Wentland 			dcn20_dpp_destroy(&pool->base.dpps[i]);
11097ed4e635SHarry Wentland 
11107ed4e635SHarry Wentland 		if (pool->base.ipps[i] != NULL)
11117ed4e635SHarry Wentland 			pool->base.ipps[i]->funcs->ipp_destroy(&pool->base.ipps[i]);
11127ed4e635SHarry Wentland 
11137ed4e635SHarry Wentland 		if (pool->base.hubps[i] != NULL) {
11147ed4e635SHarry Wentland 			kfree(TO_DCN20_HUBP(pool->base.hubps[i]));
11157ed4e635SHarry Wentland 			pool->base.hubps[i] = NULL;
11167ed4e635SHarry Wentland 		}
11177ed4e635SHarry Wentland 
11187ed4e635SHarry Wentland 		if (pool->base.irqs != NULL) {
11197ed4e635SHarry Wentland 			dal_irq_service_destroy(&pool->base.irqs);
11207ed4e635SHarry Wentland 		}
11217ed4e635SHarry Wentland 	}
11227ed4e635SHarry Wentland 
11237ed4e635SHarry Wentland 	for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
11247ed4e635SHarry Wentland 		if (pool->base.engines[i] != NULL)
11257ed4e635SHarry Wentland 			dce110_engine_destroy(&pool->base.engines[i]);
11267ed4e635SHarry Wentland 		if (pool->base.hw_i2cs[i] != NULL) {
11277ed4e635SHarry Wentland 			kfree(pool->base.hw_i2cs[i]);
11287ed4e635SHarry Wentland 			pool->base.hw_i2cs[i] = NULL;
11297ed4e635SHarry Wentland 		}
11307ed4e635SHarry Wentland 		if (pool->base.sw_i2cs[i] != NULL) {
11317ed4e635SHarry Wentland 			kfree(pool->base.sw_i2cs[i]);
11327ed4e635SHarry Wentland 			pool->base.sw_i2cs[i] = NULL;
11337ed4e635SHarry Wentland 		}
11347ed4e635SHarry Wentland 	}
11357ed4e635SHarry Wentland 
11367ed4e635SHarry Wentland 	for (i = 0; i < pool->base.res_cap->num_opp; i++) {
11377ed4e635SHarry Wentland 		if (pool->base.opps[i] != NULL)
11387ed4e635SHarry Wentland 			pool->base.opps[i]->funcs->opp_destroy(&pool->base.opps[i]);
11397ed4e635SHarry Wentland 	}
11407ed4e635SHarry Wentland 
11417ed4e635SHarry Wentland 	for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) {
11427ed4e635SHarry Wentland 		if (pool->base.timing_generators[i] != NULL)	{
11437ed4e635SHarry Wentland 			kfree(DCN10TG_FROM_TG(pool->base.timing_generators[i]));
11447ed4e635SHarry Wentland 			pool->base.timing_generators[i] = NULL;
11457ed4e635SHarry Wentland 		}
11467ed4e635SHarry Wentland 	}
11477ed4e635SHarry Wentland 
1148bb21290fSCharlene Liu 	for (i = 0; i < pool->base.res_cap->num_dwb; i++) {
1149bb21290fSCharlene Liu 		if (pool->base.dwbc[i] != NULL) {
1150bb21290fSCharlene Liu 			kfree(TO_DCN20_DWBC(pool->base.dwbc[i]));
1151bb21290fSCharlene Liu 			pool->base.dwbc[i] = NULL;
1152bb21290fSCharlene Liu 		}
1153bb21290fSCharlene Liu 		if (pool->base.mcif_wb[i] != NULL) {
1154bb21290fSCharlene Liu 			kfree(TO_DCN20_MMHUBBUB(pool->base.mcif_wb[i]));
1155bb21290fSCharlene Liu 			pool->base.mcif_wb[i] = NULL;
1156bb21290fSCharlene Liu 		}
1157bb21290fSCharlene Liu 	}
1158bb21290fSCharlene Liu 
11597ed4e635SHarry Wentland 	for (i = 0; i < pool->base.audio_count; i++) {
11607ed4e635SHarry Wentland 		if (pool->base.audios[i])
11617ed4e635SHarry Wentland 			dce_aud_destroy(&pool->base.audios[i]);
11627ed4e635SHarry Wentland 	}
11637ed4e635SHarry Wentland 
11647ed4e635SHarry Wentland 	for (i = 0; i < pool->base.clk_src_count; i++) {
11657ed4e635SHarry Wentland 		if (pool->base.clock_sources[i] != NULL) {
11667ed4e635SHarry Wentland 			dcn20_clock_source_destroy(&pool->base.clock_sources[i]);
11677ed4e635SHarry Wentland 			pool->base.clock_sources[i] = NULL;
11687ed4e635SHarry Wentland 		}
11697ed4e635SHarry Wentland 	}
11707ed4e635SHarry Wentland 
11717ed4e635SHarry Wentland 	if (pool->base.dp_clock_source != NULL) {
11727ed4e635SHarry Wentland 		dcn20_clock_source_destroy(&pool->base.dp_clock_source);
11737ed4e635SHarry Wentland 		pool->base.dp_clock_source = NULL;
11747ed4e635SHarry Wentland 	}
11757ed4e635SHarry Wentland 
11767ed4e635SHarry Wentland 
11777ed4e635SHarry Wentland 	if (pool->base.abm != NULL)
11787ed4e635SHarry Wentland 		dce_abm_destroy(&pool->base.abm);
11797ed4e635SHarry Wentland 
11807ed4e635SHarry Wentland 	if (pool->base.dmcu != NULL)
11817ed4e635SHarry Wentland 		dce_dmcu_destroy(&pool->base.dmcu);
11827ed4e635SHarry Wentland 
11837ed4e635SHarry Wentland 	if (pool->base.dccg != NULL)
11847ed4e635SHarry Wentland 		dcn_dccg_destroy(&pool->base.dccg);
11857ed4e635SHarry Wentland 
11867ed4e635SHarry Wentland 	if (pool->base.pp_smu != NULL)
11877ed4e635SHarry Wentland 		dcn20_pp_smu_destroy(&pool->base.pp_smu);
11887ed4e635SHarry Wentland 
118998ce7d32SWenjing Liu 	if (pool->base.oem_device != NULL) {
119098ce7d32SWenjing Liu 		struct dc *dc = pool->base.oem_device->ctx->dc;
119198ce7d32SWenjing Liu 
119298ce7d32SWenjing Liu 		dc->link_srv->destroy_ddc_service(&pool->base.oem_device);
119398ce7d32SWenjing Liu 	}
11947ed4e635SHarry Wentland }
11957ed4e635SHarry Wentland 
dcn20_hubp_create(struct dc_context * ctx,uint32_t inst)11967ed4e635SHarry Wentland struct hubp *dcn20_hubp_create(
11977ed4e635SHarry Wentland 	struct dc_context *ctx,
11987ed4e635SHarry Wentland 	uint32_t inst)
11997ed4e635SHarry Wentland {
12007ed4e635SHarry Wentland 	struct dcn20_hubp *hubp2 =
12013bb11050SNirmoy Das 		kzalloc(sizeof(struct dcn20_hubp), GFP_ATOMIC);
12027ed4e635SHarry Wentland 
12037ed4e635SHarry Wentland 	if (!hubp2)
12047ed4e635SHarry Wentland 		return NULL;
12057ed4e635SHarry Wentland 
12067ed4e635SHarry Wentland 	if (hubp2_construct(hubp2, ctx, inst,
12077ed4e635SHarry Wentland 			&hubp_regs[inst], &hubp_shift, &hubp_mask))
12087ed4e635SHarry Wentland 		return &hubp2->base;
12097ed4e635SHarry Wentland 
12107ed4e635SHarry Wentland 	BREAK_TO_DEBUGGER();
12117ed4e635SHarry Wentland 	kfree(hubp2);
12127ed4e635SHarry Wentland 	return NULL;
12137ed4e635SHarry Wentland }
12147ed4e635SHarry Wentland 
get_pixel_clock_parameters(struct pipe_ctx * pipe_ctx,struct pixel_clk_params * pixel_clk_params)12157ed4e635SHarry Wentland static void get_pixel_clock_parameters(
12167ed4e635SHarry Wentland 	struct pipe_ctx *pipe_ctx,
12177ed4e635SHarry Wentland 	struct pixel_clk_params *pixel_clk_params)
12187ed4e635SHarry Wentland {
12197ed4e635SHarry Wentland 	const struct dc_stream_state *stream = pipe_ctx->stream;
1220b1f6d01cSDmytro Laktyushkin 	struct pipe_ctx *odm_pipe;
1221b1f6d01cSDmytro Laktyushkin 	int opp_cnt = 1;
122264d283cbSJimmy Kizito 	struct dc_link *link = stream->link;
1223d2957868SPeichen Huang 	struct link_encoder *link_enc = pipe_ctx->link_res.dio_link_enc;
122488ef4c5bSSamson Tam 	struct dc *dc = pipe_ctx->stream->ctx->dc;
122588ef4c5bSSamson Tam 	struct dce_hwseq *hws = dc->hwseq;
1226b1f6d01cSDmytro Laktyushkin 
1227b1f6d01cSDmytro Laktyushkin 	for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe)
1228b1f6d01cSDmytro Laktyushkin 		opp_cnt++;
12297ed4e635SHarry Wentland 
12307ed4e635SHarry Wentland 	pixel_clk_params->requested_pix_clk_100hz = stream->timing.pix_clk_100hz;
123164d283cbSJimmy Kizito 
1232d2957868SPeichen Huang 	if (!dc->config.unify_link_enc_assignment)
123366d58bf7SMartin Tsai 		link_enc = link_enc_cfg_get_link_enc(link);
123464d283cbSJimmy Kizito 	if (link_enc)
123564d283cbSJimmy Kizito 		pixel_clk_params->encoder_object_id = link_enc->id;
12360c7ea6f8SNicholas Kazlauskas 
12377ed4e635SHarry Wentland 	pixel_clk_params->signal_type = pipe_ctx->stream->signal;
12387ed4e635SHarry Wentland 	pixel_clk_params->controller_id = pipe_ctx->stream_res.tg->inst + 1;
12397ed4e635SHarry Wentland 	/* TODO: un-hardcode*/
1240f01ee019SFangzhi Zuo 	/* TODO - DP2.0 HW: calculate requested_sym_clk for UHBR rates */
12417ed4e635SHarry Wentland 	pixel_clk_params->requested_sym_clk = LINK_RATE_LOW *
12427ed4e635SHarry Wentland 		LINK_RATE_REF_FREQ_IN_KHZ;
12437ed4e635SHarry Wentland 	pixel_clk_params->flags.ENABLE_SS = 0;
12447ed4e635SHarry Wentland 	pixel_clk_params->color_depth =
12457ed4e635SHarry Wentland 		stream->timing.display_color_depth;
12467ed4e635SHarry Wentland 	pixel_clk_params->flags.DISPLAY_BLANKED = 1;
12477ed4e635SHarry Wentland 	pixel_clk_params->pixel_encoding = stream->timing.pixel_encoding;
12487ed4e635SHarry Wentland 
12497ed4e635SHarry Wentland 	if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR422)
12507ed4e635SHarry Wentland 		pixel_clk_params->color_depth = COLOR_DEPTH_888;
12517ed4e635SHarry Wentland 
1252b1f6d01cSDmytro Laktyushkin 	if (opp_cnt == 4)
1253b1f6d01cSDmytro Laktyushkin 		pixel_clk_params->requested_pix_clk_100hz /= 4;
1254e6a901a0SWenjing Liu 	else if (pipe_ctx->stream_res.tg->funcs->is_two_pixels_per_container(&stream->timing) || opp_cnt == 2)
12557ed4e635SHarry Wentland 		pixel_clk_params->requested_pix_clk_100hz /= 2;
125688ef4c5bSSamson Tam 	else if (hws->funcs.is_dp_dig_pixel_rate_div_policy) {
125788ef4c5bSSamson Tam 		if (hws->funcs.is_dp_dig_pixel_rate_div_policy(pipe_ctx))
125888ef4c5bSSamson Tam 			pixel_clk_params->requested_pix_clk_100hz /= 2;
125988ef4c5bSSamson Tam 	}
126088ef4c5bSSamson Tam 
12617ed4e635SHarry Wentland 	if (stream->timing.timing_3d_format == TIMING_3D_FORMAT_HW_FRAME_PACKING)
12627ed4e635SHarry Wentland 		pixel_clk_params->requested_pix_clk_100hz *= 2;
12637ed4e635SHarry Wentland 
12640127f044SDillon Varone 	if ((pipe_ctx->stream_res.tg->funcs->is_two_pixels_per_container &&
12650127f044SDillon Varone 			pipe_ctx->stream_res.tg->funcs->is_two_pixels_per_container(&pipe_ctx->stream->timing)) ||
12660127f044SDillon Varone 			(hws->funcs.is_dp_dig_pixel_rate_div_policy &&
12670127f044SDillon Varone 			hws->funcs.is_dp_dig_pixel_rate_div_policy(pipe_ctx)) ||
12680127f044SDillon Varone 			opp_cnt > 1) {
12690127f044SDillon Varone 		pixel_clk_params->dio_se_pix_per_cycle = 2;
12700127f044SDillon Varone 	} else {
12710127f044SDillon Varone 		pixel_clk_params->dio_se_pix_per_cycle = 1;
12720127f044SDillon Varone 	}
12737ed4e635SHarry Wentland }
12747ed4e635SHarry Wentland 
build_clamping_params(struct dc_stream_state * stream)12757ed4e635SHarry Wentland static void build_clamping_params(struct dc_stream_state *stream)
12767ed4e635SHarry Wentland {
12777ed4e635SHarry Wentland 	stream->clamping.clamping_level = CLAMPING_FULL_RANGE;
12787ed4e635SHarry Wentland 	stream->clamping.c_depth = stream->timing.display_color_depth;
12797ed4e635SHarry Wentland 	stream->clamping.pixel_encoding = stream->timing.pixel_encoding;
12807ed4e635SHarry Wentland }
12817ed4e635SHarry Wentland 
dcn20_build_pipe_pix_clk_params(struct pipe_ctx * pipe_ctx)1282cfab8038SWenjing Liu void dcn20_build_pipe_pix_clk_params(struct pipe_ctx *pipe_ctx)
12837ed4e635SHarry Wentland {
12847ed4e635SHarry Wentland 	get_pixel_clock_parameters(pipe_ctx, &pipe_ctx->stream_res.pix_clk_params);
12857ed4e635SHarry Wentland 	pipe_ctx->clock_source->funcs->get_pix_clk_dividers(
12867ed4e635SHarry Wentland 			pipe_ctx->clock_source,
12877ed4e635SHarry Wentland 			&pipe_ctx->stream_res.pix_clk_params,
12887ed4e635SHarry Wentland 			&pipe_ctx->pll_settings);
1289cfab8038SWenjing Liu }
1290cfab8038SWenjing Liu 
build_pipe_hw_param(struct pipe_ctx * pipe_ctx)1291cfab8038SWenjing Liu static enum dc_status build_pipe_hw_param(struct pipe_ctx *pipe_ctx)
1292cfab8038SWenjing Liu {
129322194e71SDillon Varone 	struct resource_pool *pool = pipe_ctx->stream->ctx->dc->res_pool;
1294cfab8038SWenjing Liu 
129522194e71SDillon Varone 	if (pool->funcs->build_pipe_pix_clk_params) {
129622194e71SDillon Varone 		pool->funcs->build_pipe_pix_clk_params(pipe_ctx);
129722194e71SDillon Varone 	} else {
1298cfab8038SWenjing Liu 		dcn20_build_pipe_pix_clk_params(pipe_ctx);
129922194e71SDillon Varone 	}
13007ed4e635SHarry Wentland 
13017ed4e635SHarry Wentland 	pipe_ctx->stream->clamping.pixel_encoding = pipe_ctx->stream->timing.pixel_encoding;
13027ed4e635SHarry Wentland 
13037ed4e635SHarry Wentland 	resource_build_bit_depth_reduction_params(pipe_ctx->stream,
13047ed4e635SHarry Wentland 					&pipe_ctx->stream->bit_depth_params);
13057ed4e635SHarry Wentland 	build_clamping_params(pipe_ctx->stream);
13067ed4e635SHarry Wentland 
13077ed4e635SHarry Wentland 	return DC_OK;
13087ed4e635SHarry Wentland }
13097ed4e635SHarry Wentland 
dcn20_build_mapped_resource(const struct dc * dc,struct dc_state * context,struct dc_stream_state * stream)13107ed4e635SHarry Wentland enum dc_status dcn20_build_mapped_resource(const struct dc *dc, struct dc_state *context, struct dc_stream_state *stream)
13117ed4e635SHarry Wentland {
13127ed4e635SHarry Wentland 	enum dc_status status = DC_OK;
131353f32880SWenjing Liu 	struct pipe_ctx *pipe_ctx = resource_get_otg_master_for_stream(&context->res_ctx, stream);
13147ed4e635SHarry Wentland 
13157ed4e635SHarry Wentland 	if (!pipe_ctx)
13167ed4e635SHarry Wentland 		return DC_ERROR_UNEXPECTED;
13177ed4e635SHarry Wentland 
13187ed4e635SHarry Wentland 
13197ed4e635SHarry Wentland 	status = build_pipe_hw_param(pipe_ctx);
13207ed4e635SHarry Wentland 
13217ed4e635SHarry Wentland 	return status;
13227ed4e635SHarry Wentland }
13237ed4e635SHarry Wentland 
132497bda032SHarry Wentland 
dcn20_acquire_dsc(const struct dc * dc,struct resource_context * res_ctx,struct display_stream_compressor ** dsc,int pipe_idx)1325570bc18cSDmytro Laktyushkin void dcn20_acquire_dsc(const struct dc *dc,
132614e49bb3SNikola Cornij 			struct resource_context *res_ctx,
1327eab4bb97SNikola Cornij 			struct display_stream_compressor **dsc,
1328eab4bb97SNikola Cornij 			int pipe_idx)
132997bda032SHarry Wentland {
133097bda032SHarry Wentland 	int i;
133114e49bb3SNikola Cornij 	const struct resource_pool *pool = dc->res_pool;
133214e49bb3SNikola Cornij 	struct display_stream_compressor *dsc_old = dc->current_state->res_ctx.pipe_ctx[pipe_idx].stream_res.dsc;
1333c9ae6e16SNikola Cornij 
133414e49bb3SNikola Cornij 	ASSERT(*dsc == NULL); /* If this ASSERT fails, dsc was not released properly */
1335c9ae6e16SNikola Cornij 	*dsc = NULL;
133697bda032SHarry Wentland 
133714e49bb3SNikola Cornij 	/* Always do 1-to-1 mapping when number of DSCs is same as number of pipes */
1338eab4bb97SNikola Cornij 	if (pool->res_cap->num_dsc == pool->res_cap->num_opp) {
1339eab4bb97SNikola Cornij 		*dsc = pool->dscs[pipe_idx];
1340eab4bb97SNikola Cornij 		res_ctx->is_dsc_acquired[pipe_idx] = true;
1341eab4bb97SNikola Cornij 		return;
1342eab4bb97SNikola Cornij 	}
1343eab4bb97SNikola Cornij 
134414e49bb3SNikola Cornij 	/* Return old DSC to avoid the need for re-programming */
134514e49bb3SNikola Cornij 	if (dsc_old && !res_ctx->is_dsc_acquired[dsc_old->inst]) {
134614e49bb3SNikola Cornij 		*dsc = dsc_old;
134714e49bb3SNikola Cornij 		res_ctx->is_dsc_acquired[dsc_old->inst] = true;
134814e49bb3SNikola Cornij 		return ;
134914e49bb3SNikola Cornij 	}
135014e49bb3SNikola Cornij 
135197bda032SHarry Wentland 	/* Find first free DSC */
135297bda032SHarry Wentland 	for (i = 0; i < pool->res_cap->num_dsc; i++)
135397bda032SHarry Wentland 		if (!res_ctx->is_dsc_acquired[i]) {
1354c9ae6e16SNikola Cornij 			*dsc = pool->dscs[i];
135597bda032SHarry Wentland 			res_ctx->is_dsc_acquired[i] = true;
135697bda032SHarry Wentland 			break;
135797bda032SHarry Wentland 		}
135897bda032SHarry Wentland }
135997bda032SHarry Wentland 
dcn20_release_dsc(struct resource_context * res_ctx,const struct resource_pool * pool,struct display_stream_compressor ** dsc)13607287a675SDmytro Laktyushkin void dcn20_release_dsc(struct resource_context *res_ctx,
136197bda032SHarry Wentland 			const struct resource_pool *pool,
1362c9ae6e16SNikola Cornij 			struct display_stream_compressor **dsc)
136397bda032SHarry Wentland {
136497bda032SHarry Wentland 	int i;
136597bda032SHarry Wentland 
136697bda032SHarry Wentland 	for (i = 0; i < pool->res_cap->num_dsc; i++)
1367c9ae6e16SNikola Cornij 		if (pool->dscs[i] == *dsc) {
136897bda032SHarry Wentland 			res_ctx->is_dsc_acquired[i] = false;
1369c9ae6e16SNikola Cornij 			*dsc = NULL;
137097bda032SHarry Wentland 			break;
137197bda032SHarry Wentland 		}
137297bda032SHarry Wentland }
137397bda032SHarry Wentland 
13747ed4e635SHarry Wentland 
1375c9ae6e16SNikola Cornij 
dcn20_add_dsc_to_stream_resource(struct dc * dc,struct dc_state * dc_ctx,struct dc_stream_state * dc_stream)13768c20a1edSDavid Francis enum dc_status dcn20_add_dsc_to_stream_resource(struct dc *dc,
1377c9ae6e16SNikola Cornij 		struct dc_state *dc_ctx,
1378c9ae6e16SNikola Cornij 		struct dc_stream_state *dc_stream)
1379c9ae6e16SNikola Cornij {
1380c9ae6e16SNikola Cornij 	enum dc_status result = DC_OK;
1381c9ae6e16SNikola Cornij 	int i;
1382c9ae6e16SNikola Cornij 
1383c9ae6e16SNikola Cornij 	/* Get a DSC if required and available */
1384c9ae6e16SNikola Cornij 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
1385c9ae6e16SNikola Cornij 		struct pipe_ctx *pipe_ctx = &dc_ctx->res_ctx.pipe_ctx[i];
1386c9ae6e16SNikola Cornij 
13872e68ad8fSBhawanpreet Lakha 		if (pipe_ctx->top_pipe)
13882e68ad8fSBhawanpreet Lakha 			continue;
13892e68ad8fSBhawanpreet Lakha 
1390c9ae6e16SNikola Cornij 		if (pipe_ctx->stream != dc_stream)
1391c9ae6e16SNikola Cornij 			continue;
1392c9ae6e16SNikola Cornij 
13938c20a1edSDavid Francis 		if (pipe_ctx->stream_res.dsc)
13948c20a1edSDavid Francis 			continue;
13958c20a1edSDavid Francis 
1396570bc18cSDmytro Laktyushkin 		dcn20_acquire_dsc(dc, &dc_ctx->res_ctx, &pipe_ctx->stream_res.dsc, i);
1397c9ae6e16SNikola Cornij 
1398c9ae6e16SNikola Cornij 		/* The number of DSCs can be less than the number of pipes */
1399c9ae6e16SNikola Cornij 		if (!pipe_ctx->stream_res.dsc) {
1400c9ae6e16SNikola Cornij 			result = DC_NO_DSC_RESOURCE;
1401c9ae6e16SNikola Cornij 		}
1402c9ae6e16SNikola Cornij 
1403c9ae6e16SNikola Cornij 		break;
1404c9ae6e16SNikola Cornij 	}
1405c9ae6e16SNikola Cornij 
1406c9ae6e16SNikola Cornij 	return result;
1407c9ae6e16SNikola Cornij }
1408c9ae6e16SNikola Cornij 
1409c9ae6e16SNikola Cornij 
remove_dsc_from_stream_resource(struct dc * dc,struct dc_state * new_ctx,struct dc_stream_state * dc_stream)1410ba32c50fSWenjing Liu static enum dc_status remove_dsc_from_stream_resource(struct dc *dc,
1411c9ae6e16SNikola Cornij 		struct dc_state *new_ctx,
1412c9ae6e16SNikola Cornij 		struct dc_stream_state *dc_stream)
1413c9ae6e16SNikola Cornij {
1414c9ae6e16SNikola Cornij 	struct pipe_ctx *pipe_ctx = NULL;
1415c9ae6e16SNikola Cornij 	int i;
1416c9ae6e16SNikola Cornij 
1417c9ae6e16SNikola Cornij 	for (i = 0; i < MAX_PIPES; i++) {
1418c9ae6e16SNikola Cornij 		if (new_ctx->res_ctx.pipe_ctx[i].stream == dc_stream && !new_ctx->res_ctx.pipe_ctx[i].top_pipe) {
1419c9ae6e16SNikola Cornij 			pipe_ctx = &new_ctx->res_ctx.pipe_ctx[i];
1420b1f6d01cSDmytro Laktyushkin 
1421b1f6d01cSDmytro Laktyushkin 			if (pipe_ctx->stream_res.dsc)
14227287a675SDmytro Laktyushkin 				dcn20_release_dsc(&new_ctx->res_ctx, dc->res_pool, &pipe_ctx->stream_res.dsc);
1423c9ae6e16SNikola Cornij 		}
1424c9ae6e16SNikola Cornij 	}
1425c9ae6e16SNikola Cornij 
1426c9ae6e16SNikola Cornij 	if (!pipe_ctx)
1427c9ae6e16SNikola Cornij 		return DC_ERROR_UNEXPECTED;
1428b1f6d01cSDmytro Laktyushkin 	else
1429c9ae6e16SNikola Cornij 		return DC_OK;
1430c9ae6e16SNikola Cornij }
1431c9ae6e16SNikola Cornij 
1432c9ae6e16SNikola Cornij 
dcn20_add_stream_to_ctx(struct dc * dc,struct dc_state * new_ctx,struct dc_stream_state * dc_stream)14337ed4e635SHarry Wentland enum dc_status dcn20_add_stream_to_ctx(struct dc *dc, struct dc_state *new_ctx, struct dc_stream_state *dc_stream)
14347ed4e635SHarry Wentland {
14357ed4e635SHarry Wentland 	enum dc_status result = DC_ERROR_UNEXPECTED;
14367ed4e635SHarry Wentland 
14377ed4e635SHarry Wentland 	result = resource_map_pool_resources(dc, new_ctx, dc_stream);
14387ed4e635SHarry Wentland 
14397ed4e635SHarry Wentland 	if (result == DC_OK)
14407ed4e635SHarry Wentland 		result = resource_map_phy_clock_resources(dc, new_ctx, dc_stream);
14417ed4e635SHarry Wentland 
144297bda032SHarry Wentland 	/* Get a DSC if required and available */
1443c9ae6e16SNikola Cornij 	if (result == DC_OK && dc_stream->timing.flags.DSC)
14448c20a1edSDavid Francis 		result = dcn20_add_dsc_to_stream_resource(dc, new_ctx, dc_stream);
14457ed4e635SHarry Wentland 
14467ed4e635SHarry Wentland 	if (result == DC_OK)
14477ed4e635SHarry Wentland 		result = dcn20_build_mapped_resource(dc, new_ctx, dc_stream);
14487ed4e635SHarry Wentland 
14497ed4e635SHarry Wentland 	return result;
14507ed4e635SHarry Wentland }
14517ed4e635SHarry Wentland 
14527ed4e635SHarry Wentland 
dcn20_remove_stream_from_ctx(struct dc * dc,struct dc_state * new_ctx,struct dc_stream_state * dc_stream)14537ed4e635SHarry Wentland enum dc_status dcn20_remove_stream_from_ctx(struct dc *dc, struct dc_state *new_ctx, struct dc_stream_state *dc_stream)
14547ed4e635SHarry Wentland {
1455c9ae6e16SNikola Cornij 	enum dc_status result = DC_OK;
14567ed4e635SHarry Wentland 
1457ba32c50fSWenjing Liu 	result = remove_dsc_from_stream_resource(dc, new_ctx, dc_stream);
14587ed4e635SHarry Wentland 
1459c9ae6e16SNikola Cornij 	return result;
14607ed4e635SHarry Wentland }
14617ed4e635SHarry Wentland 
1462a6126e14SRodrigo Siqueira /**
1463a6126e14SRodrigo Siqueira  * dcn20_split_stream_for_odm - Check if stream can be splited for ODM
1464a6126e14SRodrigo Siqueira  *
1465a6126e14SRodrigo Siqueira  * @dc: DC object with resource pool info required for pipe split
1466a6126e14SRodrigo Siqueira  * @res_ctx: Persistent state of resources
1467a6126e14SRodrigo Siqueira  * @prev_odm_pipe: Reference to the previous ODM pipe
1468a6126e14SRodrigo Siqueira  * @next_odm_pipe: Reference to the next ODM pipe
1469a6126e14SRodrigo Siqueira  *
1470a6126e14SRodrigo Siqueira  * This function takes a logically active pipe and a logically free pipe and
1471a6126e14SRodrigo Siqueira  * halves all the scaling parameters that need to be halved while populating
1472a6126e14SRodrigo Siqueira  * the free pipe with the required resources and configuring the next/previous
1473a6126e14SRodrigo Siqueira  * ODM pipe pointers.
1474a6126e14SRodrigo Siqueira  *
1475a6126e14SRodrigo Siqueira  * Return:
1476a6126e14SRodrigo Siqueira  * Return true if split stream for ODM is possible, otherwise, return false.
1477a6126e14SRodrigo Siqueira  */
dcn20_split_stream_for_odm(const struct dc * dc,struct resource_context * res_ctx,struct pipe_ctx * prev_odm_pipe,struct pipe_ctx * next_odm_pipe)1478b6bfba6cSDmytro Laktyushkin bool dcn20_split_stream_for_odm(
147914e49bb3SNikola Cornij 		const struct dc *dc,
1480b1f6d01cSDmytro Laktyushkin 		struct resource_context *res_ctx,
1481b1f6d01cSDmytro Laktyushkin 		struct pipe_ctx *prev_odm_pipe,
1482b1f6d01cSDmytro Laktyushkin 		struct pipe_ctx *next_odm_pipe)
1483b1f6d01cSDmytro Laktyushkin {
1484b1f6d01cSDmytro Laktyushkin 	int pipe_idx = next_odm_pipe->pipe_idx;
148514e49bb3SNikola Cornij 	const struct resource_pool *pool = dc->res_pool;
1486b1f6d01cSDmytro Laktyushkin 
1487b1f6d01cSDmytro Laktyushkin 	*next_odm_pipe = *prev_odm_pipe;
1488b1f6d01cSDmytro Laktyushkin 
1489b1f6d01cSDmytro Laktyushkin 	next_odm_pipe->pipe_idx = pipe_idx;
1490b1f6d01cSDmytro Laktyushkin 	next_odm_pipe->plane_res.mi = pool->mis[next_odm_pipe->pipe_idx];
1491b1f6d01cSDmytro Laktyushkin 	next_odm_pipe->plane_res.hubp = pool->hubps[next_odm_pipe->pipe_idx];
1492b1f6d01cSDmytro Laktyushkin 	next_odm_pipe->plane_res.ipp = pool->ipps[next_odm_pipe->pipe_idx];
1493b1f6d01cSDmytro Laktyushkin 	next_odm_pipe->plane_res.xfm = pool->transforms[next_odm_pipe->pipe_idx];
1494b1f6d01cSDmytro Laktyushkin 	next_odm_pipe->plane_res.dpp = pool->dpps[next_odm_pipe->pipe_idx];
1495b1f6d01cSDmytro Laktyushkin 	next_odm_pipe->plane_res.mpcc_inst = pool->dpps[next_odm_pipe->pipe_idx]->inst;
1496b1f6d01cSDmytro Laktyushkin 	next_odm_pipe->stream_res.dsc = NULL;
1497b1f6d01cSDmytro Laktyushkin 	if (prev_odm_pipe->next_odm_pipe && prev_odm_pipe->next_odm_pipe != next_odm_pipe) {
1498b1f6d01cSDmytro Laktyushkin 		next_odm_pipe->next_odm_pipe = prev_odm_pipe->next_odm_pipe;
1499b1f6d01cSDmytro Laktyushkin 		next_odm_pipe->next_odm_pipe->prev_odm_pipe = next_odm_pipe;
1500b1f6d01cSDmytro Laktyushkin 	}
15012e7b43e6SDmytro Laktyushkin 	if (prev_odm_pipe->top_pipe && prev_odm_pipe->top_pipe->next_odm_pipe) {
15022e7b43e6SDmytro Laktyushkin 		prev_odm_pipe->top_pipe->next_odm_pipe->bottom_pipe = next_odm_pipe;
15032e7b43e6SDmytro Laktyushkin 		next_odm_pipe->top_pipe = prev_odm_pipe->top_pipe->next_odm_pipe;
15042e7b43e6SDmytro Laktyushkin 	}
15052e7b43e6SDmytro Laktyushkin 	if (prev_odm_pipe->bottom_pipe && prev_odm_pipe->bottom_pipe->next_odm_pipe) {
15062e7b43e6SDmytro Laktyushkin 		prev_odm_pipe->bottom_pipe->next_odm_pipe->top_pipe = next_odm_pipe;
15072e7b43e6SDmytro Laktyushkin 		next_odm_pipe->bottom_pipe = prev_odm_pipe->bottom_pipe->next_odm_pipe;
15082e7b43e6SDmytro Laktyushkin 	}
1509b1f6d01cSDmytro Laktyushkin 	prev_odm_pipe->next_odm_pipe = next_odm_pipe;
1510b1f6d01cSDmytro Laktyushkin 	next_odm_pipe->prev_odm_pipe = prev_odm_pipe;
1511b1f6d01cSDmytro Laktyushkin 
1512b1f6d01cSDmytro Laktyushkin 	if (prev_odm_pipe->plane_state) {
151357ac1175SPeterson 		if (!resource_build_scaling_params(prev_odm_pipe) ||
151457ac1175SPeterson 			!resource_build_scaling_params(next_odm_pipe)) {
1515b1f6d01cSDmytro Laktyushkin 				return false;
1516b1f6d01cSDmytro Laktyushkin 		}
151763e7ee67SPeterson Guo 	}
151863e7ee67SPeterson Guo 
15192e7b43e6SDmytro Laktyushkin 	if (!next_odm_pipe->top_pipe)
1520b1f6d01cSDmytro Laktyushkin 		next_odm_pipe->stream_res.opp = pool->opps[next_odm_pipe->pipe_idx];
15212e7b43e6SDmytro Laktyushkin 	else
15222e7b43e6SDmytro Laktyushkin 		next_odm_pipe->stream_res.opp = next_odm_pipe->top_pipe->stream_res.opp;
152373d48f08SSung Lee 	if (next_odm_pipe->stream->timing.flags.DSC == 1 && !next_odm_pipe->top_pipe) {
1524570bc18cSDmytro Laktyushkin 		dcn20_acquire_dsc(dc, res_ctx, &next_odm_pipe->stream_res.dsc, next_odm_pipe->pipe_idx);
1525b1f6d01cSDmytro Laktyushkin 		ASSERT(next_odm_pipe->stream_res.dsc);
1526b1f6d01cSDmytro Laktyushkin 		if (next_odm_pipe->stream_res.dsc == NULL)
1527b1f6d01cSDmytro Laktyushkin 			return false;
1528b1f6d01cSDmytro Laktyushkin 	}
1529b1f6d01cSDmytro Laktyushkin 
1530b1f6d01cSDmytro Laktyushkin 	return true;
1531b1f6d01cSDmytro Laktyushkin }
1532b1f6d01cSDmytro Laktyushkin 
dcn20_split_stream_for_mpc(struct resource_context * res_ctx,const struct resource_pool * pool,struct pipe_ctx * primary_pipe,struct pipe_ctx * secondary_pipe)153365d68369SIsabel Zhang void dcn20_split_stream_for_mpc(
15347ed4e635SHarry Wentland 		struct resource_context *res_ctx,
15357ed4e635SHarry Wentland 		const struct resource_pool *pool,
15367ed4e635SHarry Wentland 		struct pipe_ctx *primary_pipe,
1537b1f6d01cSDmytro Laktyushkin 		struct pipe_ctx *secondary_pipe)
15387ed4e635SHarry Wentland {
15397ed4e635SHarry Wentland 	int pipe_idx = secondary_pipe->pipe_idx;
15407ed4e635SHarry Wentland 	struct pipe_ctx *sec_bot_pipe = secondary_pipe->bottom_pipe;
15417ed4e635SHarry Wentland 
15427ed4e635SHarry Wentland 	*secondary_pipe = *primary_pipe;
15437ed4e635SHarry Wentland 	secondary_pipe->bottom_pipe = sec_bot_pipe;
15447ed4e635SHarry Wentland 
15457ed4e635SHarry Wentland 	secondary_pipe->pipe_idx = pipe_idx;
15467ed4e635SHarry Wentland 	secondary_pipe->plane_res.mi = pool->mis[secondary_pipe->pipe_idx];
15477ed4e635SHarry Wentland 	secondary_pipe->plane_res.hubp = pool->hubps[secondary_pipe->pipe_idx];
15487ed4e635SHarry Wentland 	secondary_pipe->plane_res.ipp = pool->ipps[secondary_pipe->pipe_idx];
15497ed4e635SHarry Wentland 	secondary_pipe->plane_res.xfm = pool->transforms[secondary_pipe->pipe_idx];
15507ed4e635SHarry Wentland 	secondary_pipe->plane_res.dpp = pool->dpps[secondary_pipe->pipe_idx];
15517ed4e635SHarry Wentland 	secondary_pipe->plane_res.mpcc_inst = pool->dpps[secondary_pipe->pipe_idx]->inst;
1552c92b4c46SNikola Cornij 	secondary_pipe->stream_res.dsc = NULL;
15537ed4e635SHarry Wentland 	if (primary_pipe->bottom_pipe && primary_pipe->bottom_pipe != secondary_pipe) {
15547ed4e635SHarry Wentland 		ASSERT(!secondary_pipe->bottom_pipe);
15557ed4e635SHarry Wentland 		secondary_pipe->bottom_pipe = primary_pipe->bottom_pipe;
15567ed4e635SHarry Wentland 		secondary_pipe->bottom_pipe->top_pipe = secondary_pipe;
15577ed4e635SHarry Wentland 	}
15587ed4e635SHarry Wentland 	primary_pipe->bottom_pipe = secondary_pipe;
15597ed4e635SHarry Wentland 	secondary_pipe->top_pipe = primary_pipe;
15607ed4e635SHarry Wentland 
15617ed4e635SHarry Wentland 	ASSERT(primary_pipe->plane_state);
15627ed4e635SHarry Wentland }
15637ed4e635SHarry Wentland 
dcn20_calc_max_scaled_time(unsigned int time_per_pixel,enum mmhubbub_wbif_mode mode,unsigned int urgent_watermark)15647ed4e635SHarry Wentland unsigned int dcn20_calc_max_scaled_time(
15657ed4e635SHarry Wentland 		unsigned int time_per_pixel,
15667ed4e635SHarry Wentland 		enum mmhubbub_wbif_mode mode,
15677ed4e635SHarry Wentland 		unsigned int urgent_watermark)
15687ed4e635SHarry Wentland {
15697ed4e635SHarry Wentland 	unsigned int time_per_byte = 0;
15707ed4e635SHarry Wentland 	unsigned int total_y_free_entry = 0x200; /* two memory piece for luma */
15717ed4e635SHarry Wentland 	unsigned int total_c_free_entry = 0x140; /* two memory piece for chroma */
15727ed4e635SHarry Wentland 	unsigned int small_free_entry, max_free_entry;
15737ed4e635SHarry Wentland 	unsigned int buf_lh_capability;
15747ed4e635SHarry Wentland 	unsigned int max_scaled_time;
15757ed4e635SHarry Wentland 
15767ed4e635SHarry Wentland 	if (mode == PACKED_444) /* packed mode */
15777ed4e635SHarry Wentland 		time_per_byte = time_per_pixel/4;
15787ed4e635SHarry Wentland 	else if (mode == PLANAR_420_8BPC)
15797ed4e635SHarry Wentland 		time_per_byte  = time_per_pixel;
15807ed4e635SHarry Wentland 	else if (mode == PLANAR_420_10BPC) /* p010 */
15817ed4e635SHarry Wentland 		time_per_byte  = time_per_pixel * 819/1024;
15827ed4e635SHarry Wentland 
15837ed4e635SHarry Wentland 	if (time_per_byte == 0)
15847ed4e635SHarry Wentland 		time_per_byte = 1;
15857ed4e635SHarry Wentland 
15865d1608a8SIvan Lipski 	small_free_entry  = total_c_free_entry;
15877ed4e635SHarry Wentland 	max_free_entry    = (mode == PACKED_444) ? total_y_free_entry + total_c_free_entry : small_free_entry;
15887ed4e635SHarry Wentland 	buf_lh_capability = max_free_entry*time_per_byte*32/16; /* there is 4bit fraction */
15897ed4e635SHarry Wentland 	max_scaled_time   = buf_lh_capability - urgent_watermark;
15907ed4e635SHarry Wentland 	return max_scaled_time;
15917ed4e635SHarry Wentland }
15927ed4e635SHarry Wentland 
dcn20_set_mcif_arb_params(struct dc * dc,struct dc_state * context,display_e2e_pipe_params_st * pipes,int pipe_cnt)15937ed4e635SHarry Wentland void dcn20_set_mcif_arb_params(
15947ed4e635SHarry Wentland 		struct dc *dc,
15957ed4e635SHarry Wentland 		struct dc_state *context,
15967ed4e635SHarry Wentland 		display_e2e_pipe_params_st *pipes,
15977ed4e635SHarry Wentland 		int pipe_cnt)
15987ed4e635SHarry Wentland {
15997ed4e635SHarry Wentland 	enum mmhubbub_wbif_mode wbif_mode;
16007ed4e635SHarry Wentland 	struct mcif_arb_params *wb_arb_params;
1601cf689e86SMelissa Wen 	int i, j, dwb_pipe;
16027ed4e635SHarry Wentland 
16037ed4e635SHarry Wentland 	/* Writeback MCIF_WB arbitration parameters */
16047ed4e635SHarry Wentland 	dwb_pipe = 0;
16057ed4e635SHarry Wentland 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
16067ed4e635SHarry Wentland 
16077ed4e635SHarry Wentland 		if (!context->res_ctx.pipe_ctx[i].stream)
16087ed4e635SHarry Wentland 			continue;
16097ed4e635SHarry Wentland 
16107ed4e635SHarry Wentland 		for (j = 0; j < MAX_DWB_PIPES; j++) {
16117ed4e635SHarry Wentland 			if (context->res_ctx.pipe_ctx[i].stream->writeback_info[j].wb_enabled == false)
16127ed4e635SHarry Wentland 				continue;
16137ed4e635SHarry Wentland 
16147ed4e635SHarry Wentland 			//wb_arb_params = &context->res_ctx.pipe_ctx[i].stream->writeback_info[j].mcif_arb_params;
16157ed4e635SHarry Wentland 			wb_arb_params = &context->bw_ctx.bw.dcn.bw_writeback.mcif_wb_arb[dwb_pipe];
16167ed4e635SHarry Wentland 
16177ed4e635SHarry Wentland 			if (context->res_ctx.pipe_ctx[i].stream->writeback_info[j].dwb_params.out_format == dwb_scaler_mode_yuv420) {
16187ed4e635SHarry Wentland 				if (context->res_ctx.pipe_ctx[i].stream->writeback_info[j].dwb_params.output_depth == DWB_OUTPUT_PIXEL_DEPTH_8BPC)
16197ed4e635SHarry Wentland 					wbif_mode = PLANAR_420_8BPC;
16207ed4e635SHarry Wentland 				else
16217ed4e635SHarry Wentland 					wbif_mode = PLANAR_420_10BPC;
16227ed4e635SHarry Wentland 			} else
16237ed4e635SHarry Wentland 				wbif_mode = PACKED_444;
16247ed4e635SHarry Wentland 
1625cf689e86SMelissa Wen 			DC_FP_START();
1626cf689e86SMelissa Wen 			dcn20_fpu_set_wb_arb_params(wb_arb_params, context, pipes, pipe_cnt, i);
1627cf689e86SMelissa Wen 			DC_FP_END();
1628cf689e86SMelissa Wen 
16297ed4e635SHarry Wentland 			wb_arb_params->slice_lines = 32;
16307ed4e635SHarry Wentland 			wb_arb_params->arbitration_slice = 2;
16317ed4e635SHarry Wentland 			wb_arb_params->max_scaled_time = dcn20_calc_max_scaled_time(wb_arb_params->time_per_pixel,
16327ed4e635SHarry Wentland 				wbif_mode,
16337ed4e635SHarry Wentland 				wb_arb_params->cli_watermark[0]); /* assume 4 watermark sets have the same value */
16347ed4e635SHarry Wentland 
16357ed4e635SHarry Wentland 			dwb_pipe++;
16367ed4e635SHarry Wentland 
16377ed4e635SHarry Wentland 			if (dwb_pipe >= MAX_DWB_PIPES)
16387ed4e635SHarry Wentland 				return;
16397ed4e635SHarry Wentland 		}
16407ed4e635SHarry Wentland 	}
16417ed4e635SHarry Wentland }
16427ed4e635SHarry Wentland 
dcn20_validate_dsc(struct dc * dc,struct dc_state * new_ctx)1643b6bfba6cSDmytro Laktyushkin bool dcn20_validate_dsc(struct dc *dc, struct dc_state *new_ctx)
16440ba37b20SDmytro Laktyushkin {
16450ba37b20SDmytro Laktyushkin 	int i;
16460ba37b20SDmytro Laktyushkin 
16470ba37b20SDmytro Laktyushkin 	/* Validate DSC config, dsc count validation is already done */
16480ba37b20SDmytro Laktyushkin 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
16490ba37b20SDmytro Laktyushkin 		struct pipe_ctx *pipe_ctx = &new_ctx->res_ctx.pipe_ctx[i];
16500ba37b20SDmytro Laktyushkin 		struct dc_stream_state *stream = pipe_ctx->stream;
16510ba37b20SDmytro Laktyushkin 		struct dsc_config dsc_cfg;
1652b1f6d01cSDmytro Laktyushkin 		struct pipe_ctx *odm_pipe;
1653b1f6d01cSDmytro Laktyushkin 		int opp_cnt = 1;
1654b1f6d01cSDmytro Laktyushkin 
1655b1f6d01cSDmytro Laktyushkin 		for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe)
1656b1f6d01cSDmytro Laktyushkin 			opp_cnt++;
16570ba37b20SDmytro Laktyushkin 
16580ba37b20SDmytro Laktyushkin 		/* Only need to validate top pipe */
1659b1f6d01cSDmytro Laktyushkin 		if (pipe_ctx->top_pipe || pipe_ctx->prev_odm_pipe || !stream || !stream->timing.flags.DSC)
16600ba37b20SDmytro Laktyushkin 			continue;
16610ba37b20SDmytro Laktyushkin 
1662b1f6d01cSDmytro Laktyushkin 		dsc_cfg.pic_width = (stream->timing.h_addressable + stream->timing.h_border_left
1663b1f6d01cSDmytro Laktyushkin 				+ stream->timing.h_border_right) / opp_cnt;
16640ba37b20SDmytro Laktyushkin 		dsc_cfg.pic_height = stream->timing.v_addressable + stream->timing.v_border_top
16650ba37b20SDmytro Laktyushkin 				+ stream->timing.v_border_bottom;
16660ba37b20SDmytro Laktyushkin 		dsc_cfg.pixel_encoding = stream->timing.pixel_encoding;
16670ba37b20SDmytro Laktyushkin 		dsc_cfg.color_depth = stream->timing.display_color_depth;
1668df8e34acSWenjing Liu 		dsc_cfg.is_odm = pipe_ctx->next_odm_pipe ? true : false;
16690ba37b20SDmytro Laktyushkin 		dsc_cfg.dc_dsc_cfg = stream->timing.dsc_cfg;
1670b1f6d01cSDmytro Laktyushkin 		dsc_cfg.dc_dsc_cfg.num_slices_h /= opp_cnt;
16710ba37b20SDmytro Laktyushkin 
16720ba37b20SDmytro Laktyushkin 		if (!pipe_ctx->stream_res.dsc->funcs->dsc_validate_stream(pipe_ctx->stream_res.dsc, &dsc_cfg))
16730ba37b20SDmytro Laktyushkin 			return false;
16740ba37b20SDmytro Laktyushkin 	}
16750ba37b20SDmytro Laktyushkin 	return true;
16760ba37b20SDmytro Laktyushkin }
16770ba37b20SDmytro Laktyushkin 
dcn20_find_secondary_pipe(struct dc * dc,struct resource_context * res_ctx,const struct resource_pool * pool,const struct pipe_ctx * primary_pipe)1678b6bfba6cSDmytro Laktyushkin struct pipe_ctx *dcn20_find_secondary_pipe(struct dc *dc,
1679c681491aSJun Lei 		struct resource_context *res_ctx,
1680c681491aSJun Lei 		const struct resource_pool *pool,
1681c681491aSJun Lei 		const struct pipe_ctx *primary_pipe)
1682c681491aSJun Lei {
1683c681491aSJun Lei 	struct pipe_ctx *secondary_pipe = NULL;
1684c681491aSJun Lei 
1685c681491aSJun Lei 	if (dc && primary_pipe) {
1686c681491aSJun Lei 		int j;
1687c681491aSJun Lei 		int preferred_pipe_idx = 0;
1688c681491aSJun Lei 
1689c681491aSJun Lei 		/* first check the prev dc state:
1690c681491aSJun Lei 		 * if this primary pipe has a bottom pipe in prev. state
1691c681491aSJun Lei 		 * and if the bottom pipe is still available (which it should be),
1692c681491aSJun Lei 		 * pick that pipe as secondary
16937a214cd8SSung Lee 		 * Same logic applies for ODM pipes
1694c681491aSJun Lei 		 */
1695324b1fcbSsunglee 		if (dc->current_state->res_ctx.pipe_ctx[primary_pipe->pipe_idx].next_odm_pipe) {
1696324b1fcbSsunglee 			preferred_pipe_idx = dc->current_state->res_ctx.pipe_ctx[primary_pipe->pipe_idx].next_odm_pipe->pipe_idx;
1697c681491aSJun Lei 			if (res_ctx->pipe_ctx[preferred_pipe_idx].stream == NULL) {
1698c681491aSJun Lei 				secondary_pipe = &res_ctx->pipe_ctx[preferred_pipe_idx];
1699c681491aSJun Lei 				secondary_pipe->pipe_idx = preferred_pipe_idx;
1700c681491aSJun Lei 			}
17017a214cd8SSung Lee 		}
17027a214cd8SSung Lee 		if (secondary_pipe == NULL &&
1703324b1fcbSsunglee 				dc->current_state->res_ctx.pipe_ctx[primary_pipe->pipe_idx].bottom_pipe) {
1704324b1fcbSsunglee 			preferred_pipe_idx = dc->current_state->res_ctx.pipe_ctx[primary_pipe->pipe_idx].bottom_pipe->pipe_idx;
1705b1f6d01cSDmytro Laktyushkin 			if (res_ctx->pipe_ctx[preferred_pipe_idx].stream == NULL) {
1706b1f6d01cSDmytro Laktyushkin 				secondary_pipe = &res_ctx->pipe_ctx[preferred_pipe_idx];
1707b1f6d01cSDmytro Laktyushkin 				secondary_pipe->pipe_idx = preferred_pipe_idx;
1708b1f6d01cSDmytro Laktyushkin 			}
1709c681491aSJun Lei 		}
1710c681491aSJun Lei 
1711c681491aSJun Lei 		/*
1712c681491aSJun Lei 		 * if this primary pipe does not have a bottom pipe in prev. state
1713c681491aSJun Lei 		 * start backward and find a pipe that did not used to be a bottom pipe in
1714c681491aSJun Lei 		 * prev. dc state. This way we make sure we keep the same assignment as
1715c681491aSJun Lei 		 * last state and will not have to reprogram every pipe
1716c681491aSJun Lei 		 */
1717c681491aSJun Lei 		if (secondary_pipe == NULL) {
1718c681491aSJun Lei 			for (j = dc->res_pool->pipe_count - 1; j >= 0; j--) {
17198b8eda01SDmytro Laktyushkin 				if (dc->current_state->res_ctx.pipe_ctx[j].top_pipe == NULL
17208b8eda01SDmytro Laktyushkin 						&& dc->current_state->res_ctx.pipe_ctx[j].prev_odm_pipe == NULL) {
1721c681491aSJun Lei 					preferred_pipe_idx = j;
1722c681491aSJun Lei 
1723c681491aSJun Lei 					if (res_ctx->pipe_ctx[preferred_pipe_idx].stream == NULL) {
1724c681491aSJun Lei 						secondary_pipe = &res_ctx->pipe_ctx[preferred_pipe_idx];
1725c681491aSJun Lei 						secondary_pipe->pipe_idx = preferred_pipe_idx;
1726c681491aSJun Lei 						break;
1727c681491aSJun Lei 					}
1728c681491aSJun Lei 				}
1729c681491aSJun Lei 			}
1730c681491aSJun Lei 		}
1731c681491aSJun Lei 		/*
1732c681491aSJun Lei 		 * We should never hit this assert unless assignments are shuffled around
1733c681491aSJun Lei 		 * if this happens we will prob. hit a vsync tdr
1734c681491aSJun Lei 		 */
1735c681491aSJun Lei 		ASSERT(secondary_pipe);
1736c681491aSJun Lei 		/*
1737c681491aSJun Lei 		 * search backwards for the second pipe to keep pipe
1738c681491aSJun Lei 		 * assignment more consistent
1739c681491aSJun Lei 		 */
1740c681491aSJun Lei 		if (secondary_pipe == NULL) {
1741c681491aSJun Lei 			for (j = dc->res_pool->pipe_count - 1; j >= 0; j--) {
1742c681491aSJun Lei 				preferred_pipe_idx = j;
1743c681491aSJun Lei 
1744c681491aSJun Lei 				if (res_ctx->pipe_ctx[preferred_pipe_idx].stream == NULL) {
1745c681491aSJun Lei 					secondary_pipe = &res_ctx->pipe_ctx[preferred_pipe_idx];
1746c681491aSJun Lei 					secondary_pipe->pipe_idx = preferred_pipe_idx;
1747c681491aSJun Lei 					break;
1748c681491aSJun Lei 				}
1749c681491aSJun Lei 			}
1750c681491aSJun Lei 		}
1751c681491aSJun Lei 	}
1752c681491aSJun Lei 
1753c681491aSJun Lei 	return secondary_pipe;
1754c681491aSJun Lei }
1755c681491aSJun Lei 
dcn20_merge_pipes_for_validate(struct dc * dc,struct dc_state * context)1756ea817dd5SDmytro Laktyushkin void dcn20_merge_pipes_for_validate(
17576de20237SEric Yang 		struct dc *dc,
1758b6bfba6cSDmytro Laktyushkin 		struct dc_state *context)
17597ed4e635SHarry Wentland {
1760b6bfba6cSDmytro Laktyushkin 	int i;
17617ed4e635SHarry Wentland 
1762b1f6d01cSDmytro Laktyushkin 	/* merge previously split odm pipes since mode support needs to make the decision */
1763b1f6d01cSDmytro Laktyushkin 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
1764b1f6d01cSDmytro Laktyushkin 		struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1765b1f6d01cSDmytro Laktyushkin 		struct pipe_ctx *odm_pipe = pipe->next_odm_pipe;
1766b1f6d01cSDmytro Laktyushkin 
1767b1f6d01cSDmytro Laktyushkin 		if (pipe->prev_odm_pipe)
1768b1f6d01cSDmytro Laktyushkin 			continue;
1769b1f6d01cSDmytro Laktyushkin 
1770b1f6d01cSDmytro Laktyushkin 		pipe->next_odm_pipe = NULL;
1771b1f6d01cSDmytro Laktyushkin 		while (odm_pipe) {
1772b1f6d01cSDmytro Laktyushkin 			struct pipe_ctx *next_odm_pipe = odm_pipe->next_odm_pipe;
1773b1f6d01cSDmytro Laktyushkin 
1774b1f6d01cSDmytro Laktyushkin 			odm_pipe->plane_state = NULL;
1775b1f6d01cSDmytro Laktyushkin 			odm_pipe->stream = NULL;
1776b1f6d01cSDmytro Laktyushkin 			odm_pipe->top_pipe = NULL;
1777b1f6d01cSDmytro Laktyushkin 			odm_pipe->bottom_pipe = NULL;
1778b1f6d01cSDmytro Laktyushkin 			odm_pipe->prev_odm_pipe = NULL;
1779b1f6d01cSDmytro Laktyushkin 			odm_pipe->next_odm_pipe = NULL;
1780b1f6d01cSDmytro Laktyushkin 			if (odm_pipe->stream_res.dsc)
17817287a675SDmytro Laktyushkin 				dcn20_release_dsc(&context->res_ctx, dc->res_pool, &odm_pipe->stream_res.dsc);
1782b1f6d01cSDmytro Laktyushkin 			/* Clear plane_res and stream_res */
1783b1f6d01cSDmytro Laktyushkin 			memset(&odm_pipe->plane_res, 0, sizeof(odm_pipe->plane_res));
1784b1f6d01cSDmytro Laktyushkin 			memset(&odm_pipe->stream_res, 0, sizeof(odm_pipe->stream_res));
1785b1f6d01cSDmytro Laktyushkin 			odm_pipe = next_odm_pipe;
1786b1f6d01cSDmytro Laktyushkin 		}
1787b1f6d01cSDmytro Laktyushkin 		if (pipe->plane_state)
1788b1f6d01cSDmytro Laktyushkin 			resource_build_scaling_params(pipe);
1789b1f6d01cSDmytro Laktyushkin 	}
1790b1f6d01cSDmytro Laktyushkin 
1791b1f6d01cSDmytro Laktyushkin 	/* merge previously mpc split pipes since mode support needs to make the decision */
17927ed4e635SHarry Wentland 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
17937ed4e635SHarry Wentland 		struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
17947ed4e635SHarry Wentland 		struct pipe_ctx *hsplit_pipe = pipe->bottom_pipe;
17957ed4e635SHarry Wentland 
17967ed4e635SHarry Wentland 		if (!hsplit_pipe || hsplit_pipe->plane_state != pipe->plane_state)
17977ed4e635SHarry Wentland 			continue;
17987ed4e635SHarry Wentland 
17997ed4e635SHarry Wentland 		pipe->bottom_pipe = hsplit_pipe->bottom_pipe;
18007ed4e635SHarry Wentland 		if (hsplit_pipe->bottom_pipe)
18017ed4e635SHarry Wentland 			hsplit_pipe->bottom_pipe->top_pipe = pipe;
18027ed4e635SHarry Wentland 		hsplit_pipe->plane_state = NULL;
18037ed4e635SHarry Wentland 		hsplit_pipe->stream = NULL;
18047ed4e635SHarry Wentland 		hsplit_pipe->top_pipe = NULL;
18057ed4e635SHarry Wentland 		hsplit_pipe->bottom_pipe = NULL;
1806b1f6d01cSDmytro Laktyushkin 
18077ed4e635SHarry Wentland 		/* Clear plane_res and stream_res */
18087ed4e635SHarry Wentland 		memset(&hsplit_pipe->plane_res, 0, sizeof(hsplit_pipe->plane_res));
18097ed4e635SHarry Wentland 		memset(&hsplit_pipe->stream_res, 0, sizeof(hsplit_pipe->stream_res));
18107ed4e635SHarry Wentland 		if (pipe->plane_state)
18117ed4e635SHarry Wentland 			resource_build_scaling_params(pipe);
18127ed4e635SHarry Wentland 	}
1813254eb07cSJoshua Aberback }
18147ed4e635SHarry Wentland 
dcn20_validate_apply_pipe_split_flags(struct dc * dc,struct dc_state * context,int vlevel,int * split,bool * merge)1815b6bfba6cSDmytro Laktyushkin int dcn20_validate_apply_pipe_split_flags(
1816b6bfba6cSDmytro Laktyushkin 		struct dc *dc,
1817b6bfba6cSDmytro Laktyushkin 		struct dc_state *context,
1818b6bfba6cSDmytro Laktyushkin 		int vlevel,
181965d68369SIsabel Zhang 		int *split,
18207287a675SDmytro Laktyushkin 		bool *merge)
1821b6bfba6cSDmytro Laktyushkin {
1822b745ecdbSDmytro Laktyushkin 	int i, pipe_idx, vlevel_split;
1823cd3e05a7SDmytro Laktyushkin 	int plane_count = 0;
1824b6bfba6cSDmytro Laktyushkin 	bool force_split = false;
1825cd3e05a7SDmytro Laktyushkin 	bool avoid_split = dc->debug.pipe_split_policy == MPC_SPLIT_AVOID;
1826570bc18cSDmytro Laktyushkin 	struct vba_vars_st *v = &context->bw_ctx.dml.vba;
1827570bc18cSDmytro Laktyushkin 	int max_mpc_comb = v->maxMpcComb;
18287ed4e635SHarry Wentland 
1829cd3e05a7SDmytro Laktyushkin 	if (context->stream_count > 1) {
1830cd3e05a7SDmytro Laktyushkin 		if (dc->debug.pipe_split_policy == MPC_SPLIT_AVOID_MULT_DISP)
1831cd3e05a7SDmytro Laktyushkin 			avoid_split = true;
1832cd3e05a7SDmytro Laktyushkin 	} else if (dc->debug.force_single_disp_pipe_split)
1833cd3e05a7SDmytro Laktyushkin 			force_split = true;
1834cd3e05a7SDmytro Laktyushkin 
18357ed4e635SHarry Wentland 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
18367ed4e635SHarry Wentland 		struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
18377ed4e635SHarry Wentland 
1838b6dbb8ffSNicholas Kazlauskas 		/**
1839b6dbb8ffSNicholas Kazlauskas 		 * Workaround for avoiding pipe-split in cases where we'd split
1840b6dbb8ffSNicholas Kazlauskas 		 * planes that are too small, resulting in splits that aren't
1841b6dbb8ffSNicholas Kazlauskas 		 * valid for the scaler.
1842b6dbb8ffSNicholas Kazlauskas 		 */
1843b6dbb8ffSNicholas Kazlauskas 		if (pipe->plane_state &&
1844b6dbb8ffSNicholas Kazlauskas 		    (pipe->plane_state->dst_rect.width <= 16 ||
1845b6dbb8ffSNicholas Kazlauskas 		     pipe->plane_state->dst_rect.height <= 16 ||
1846b6dbb8ffSNicholas Kazlauskas 		     pipe->plane_state->src_rect.width <= 16 ||
1847b6dbb8ffSNicholas Kazlauskas 		     pipe->plane_state->src_rect.height <= 16))
1848b6dbb8ffSNicholas Kazlauskas 			avoid_split = true;
1849b6dbb8ffSNicholas Kazlauskas 
1850b6dbb8ffSNicholas Kazlauskas 		/* TODO: fix dc bugs and remove this split threshold thing */
1851cd3e05a7SDmytro Laktyushkin 		if (pipe->stream && !pipe->prev_odm_pipe &&
1852cd3e05a7SDmytro Laktyushkin 				(!pipe->top_pipe || pipe->top_pipe->plane_state != pipe->plane_state))
1853cd3e05a7SDmytro Laktyushkin 			++plane_count;
18547ed4e635SHarry Wentland 	}
1855cd3e05a7SDmytro Laktyushkin 	if (plane_count > dc->res_pool->pipe_count / 2)
18567ed4e635SHarry Wentland 		avoid_split = true;
18577ed4e635SHarry Wentland 
1858a0a85ac4SDale Zhao 	/* W/A: Mode timing with borders may not work well with pipe split, avoid for this corner case */
1859a0a85ac4SDale Zhao 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
1860a0a85ac4SDale Zhao 		struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1861a0a85ac4SDale Zhao 		struct dc_crtc_timing timing;
1862a0a85ac4SDale Zhao 
1863a0a85ac4SDale Zhao 		if (!pipe->stream)
1864a0a85ac4SDale Zhao 			continue;
1865a0a85ac4SDale Zhao 		else {
1866a0a85ac4SDale Zhao 			timing = pipe->stream->timing;
1867a0a85ac4SDale Zhao 			if (timing.h_border_left + timing.h_border_right
1868a0a85ac4SDale Zhao 					+ timing.v_border_top + timing.v_border_bottom > 0) {
1869a0a85ac4SDale Zhao 				avoid_split = true;
1870a0a85ac4SDale Zhao 				break;
1871a0a85ac4SDale Zhao 			}
1872a0a85ac4SDale Zhao 		}
1873a0a85ac4SDale Zhao 	}
1874a0a85ac4SDale Zhao 
1875b745ecdbSDmytro Laktyushkin 	/* Avoid split loop looks for lowest voltage level that allows most unsplit pipes possible */
1876b6bfba6cSDmytro Laktyushkin 	if (avoid_split) {
18777ed4e635SHarry Wentland 		for (i = 0, pipe_idx = 0; i < dc->res_pool->pipe_count; i++) {
18787ed4e635SHarry Wentland 			if (!context->res_ctx.pipe_ctx[i].stream)
18797ed4e635SHarry Wentland 				continue;
1880b6bfba6cSDmytro Laktyushkin 
1881b745ecdbSDmytro Laktyushkin 			for (vlevel_split = vlevel; vlevel <= context->bw_ctx.dml.soc.num_states; vlevel++)
1882570bc18cSDmytro Laktyushkin 				if (v->NoOfDPP[vlevel][0][pipe_idx] == 1 &&
1883570bc18cSDmytro Laktyushkin 						v->ModeSupport[vlevel][0])
18847ed4e635SHarry Wentland 					break;
1885b6bfba6cSDmytro Laktyushkin 			/* Impossible to not split this pipe */
1886b745ecdbSDmytro Laktyushkin 			if (vlevel > context->bw_ctx.dml.soc.num_states)
1887b745ecdbSDmytro Laktyushkin 				vlevel = vlevel_split;
18881dfedb39SSung Lee 			else
18891dfedb39SSung Lee 				max_mpc_comb = 0;
18907ed4e635SHarry Wentland 			pipe_idx++;
18917ed4e635SHarry Wentland 		}
1892570bc18cSDmytro Laktyushkin 		v->maxMpcComb = max_mpc_comb;
1893b6bfba6cSDmytro Laktyushkin 	}
1894b6bfba6cSDmytro Laktyushkin 
1895b745ecdbSDmytro Laktyushkin 	/* Split loop sets which pipe should be split based on dml outputs and dc flags */
1896b6bfba6cSDmytro Laktyushkin 	for (i = 0, pipe_idx = 0; i < dc->res_pool->pipe_count; i++) {
1897b6bfba6cSDmytro Laktyushkin 		struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1898570bc18cSDmytro Laktyushkin 		int pipe_plane = v->pipe_plane[pipe_idx];
1899570bc18cSDmytro Laktyushkin 		bool split4mpc = context->stream_count == 1 && plane_count == 1
1900570bc18cSDmytro Laktyushkin 				&& dc->config.enable_4to1MPC && dc->res_pool->pipe_count >= 4;
1901b6bfba6cSDmytro Laktyushkin 
1902b6bfba6cSDmytro Laktyushkin 		if (!context->res_ctx.pipe_ctx[i].stream)
1903b6bfba6cSDmytro Laktyushkin 			continue;
1904b6bfba6cSDmytro Laktyushkin 
19054d765d31SDmytro Laktyushkin 		if (split4mpc || v->NoOfDPP[vlevel][max_mpc_comb][pipe_plane] == 4)
190665d68369SIsabel Zhang 			split[i] = 4;
19074d765d31SDmytro Laktyushkin 		else if (force_split || v->NoOfDPP[vlevel][max_mpc_comb][pipe_plane] == 2)
190865d68369SIsabel Zhang 				split[i] = 2;
19094d765d31SDmytro Laktyushkin 
1910b6bfba6cSDmytro Laktyushkin 		if ((pipe->stream->view_format ==
1911b6bfba6cSDmytro Laktyushkin 				VIEW_3D_FORMAT_SIDE_BY_SIDE ||
1912b6bfba6cSDmytro Laktyushkin 				pipe->stream->view_format ==
1913b6bfba6cSDmytro Laktyushkin 				VIEW_3D_FORMAT_TOP_AND_BOTTOM) &&
1914b6bfba6cSDmytro Laktyushkin 				(pipe->stream->timing.timing_3d_format ==
1915b6bfba6cSDmytro Laktyushkin 				TIMING_3D_FORMAT_TOP_AND_BOTTOM ||
1916b6bfba6cSDmytro Laktyushkin 				 pipe->stream->timing.timing_3d_format ==
1917b6bfba6cSDmytro Laktyushkin 				TIMING_3D_FORMAT_SIDE_BY_SIDE))
191865d68369SIsabel Zhang 			split[i] = 2;
1919b6bfba6cSDmytro Laktyushkin 		if (dc->debug.force_odm_combine & (1 << pipe->stream_res.tg->inst)) {
192065d68369SIsabel Zhang 			split[i] = 2;
1921570bc18cSDmytro Laktyushkin 			v->ODMCombineEnablePerState[vlevel][pipe_plane] = dm_odm_combine_mode_2to1;
1922b6bfba6cSDmytro Laktyushkin 		}
19235dba4991SBhawanpreet Lakha 		if (dc->debug.force_odm_combine_4to1 & (1 << pipe->stream_res.tg->inst)) {
19245dba4991SBhawanpreet Lakha 			split[i] = 4;
19255dba4991SBhawanpreet Lakha 			v->ODMCombineEnablePerState[vlevel][pipe_plane] = dm_odm_combine_mode_4to1;
19265dba4991SBhawanpreet Lakha 		}
19275e908012SChris Park 		/*420 format workaround*/
19285e908012SChris Park 		if (pipe->stream->timing.h_addressable > 7680 &&
19295e908012SChris Park 				pipe->stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR420) {
19305e908012SChris Park 			split[i] = 4;
19315e908012SChris Park 		}
1932570bc18cSDmytro Laktyushkin 		v->ODMCombineEnabled[pipe_plane] =
1933570bc18cSDmytro Laktyushkin 			v->ODMCombineEnablePerState[vlevel][pipe_plane];
19347287a675SDmytro Laktyushkin 
1935570bc18cSDmytro Laktyushkin 		if (v->ODMCombineEnabled[pipe_plane] == dm_odm_combine_mode_disabled) {
193621741810SWenjing Liu 			if (resource_get_mpc_slice_count(pipe) == 2) {
1937570bc18cSDmytro Laktyushkin 				/*If need split for mpc but 2 way split already*/
1938570bc18cSDmytro Laktyushkin 				if (split[i] == 4)
1939570bc18cSDmytro Laktyushkin 					split[i] = 2; /* 2 -> 4 MPC */
1940570bc18cSDmytro Laktyushkin 				else if (split[i] == 2)
1941570bc18cSDmytro Laktyushkin 					split[i] = 0; /* 2 -> 2 MPC */
1942570bc18cSDmytro Laktyushkin 				else if (pipe->top_pipe && pipe->top_pipe->plane_state == pipe->plane_state)
1943570bc18cSDmytro Laktyushkin 					merge[i] = true; /* 2 -> 1 MPC */
194421741810SWenjing Liu 			} else if (resource_get_mpc_slice_count(pipe) == 4) {
1945570bc18cSDmytro Laktyushkin 				/*If need split for mpc but 4 way split already*/
1946570bc18cSDmytro Laktyushkin 				if (split[i] == 2 && ((pipe->top_pipe && !pipe->top_pipe->top_pipe)
1947570bc18cSDmytro Laktyushkin 						|| !pipe->bottom_pipe)) {
1948570bc18cSDmytro Laktyushkin 					merge[i] = true; /* 4 -> 2 MPC */
1949570bc18cSDmytro Laktyushkin 				} else if (split[i] == 0 && pipe->top_pipe &&
1950570bc18cSDmytro Laktyushkin 						pipe->top_pipe->plane_state == pipe->plane_state)
1951570bc18cSDmytro Laktyushkin 					merge[i] = true; /* 4 -> 1 MPC */
195265d68369SIsabel Zhang 				split[i] = 0;
195321741810SWenjing Liu 			} else if (resource_get_odm_slice_count(pipe) > 1) {
1954570bc18cSDmytro Laktyushkin 				/* ODM -> MPC transition */
19557287a675SDmytro Laktyushkin 				if (pipe->prev_odm_pipe) {
1956570bc18cSDmytro Laktyushkin 					split[i] = 0;
1957570bc18cSDmytro Laktyushkin 					merge[i] = true;
1958570bc18cSDmytro Laktyushkin 				}
1959570bc18cSDmytro Laktyushkin 			}
19607287a675SDmytro Laktyushkin 		} else {
196121741810SWenjing Liu 			if (resource_get_odm_slice_count(pipe) == 2) {
1962570bc18cSDmytro Laktyushkin 				/*If need split for odm but 2 way split already*/
1963570bc18cSDmytro Laktyushkin 				if (split[i] == 4)
1964570bc18cSDmytro Laktyushkin 					split[i] = 2; /* 2 -> 4 ODM */
1965570bc18cSDmytro Laktyushkin 				else if (split[i] == 2)
1966570bc18cSDmytro Laktyushkin 					split[i] = 0; /* 2 -> 2 ODM */
1967570bc18cSDmytro Laktyushkin 				else if (pipe->prev_odm_pipe) {
1968570bc18cSDmytro Laktyushkin 					ASSERT(0); /* NOT expected yet */
1969570bc18cSDmytro Laktyushkin 					merge[i] = true; /* exit ODM */
19707287a675SDmytro Laktyushkin 				}
197121741810SWenjing Liu 			} else if (resource_get_odm_slice_count(pipe) == 4) {
1972570bc18cSDmytro Laktyushkin 				/*If need split for odm but 4 way split already*/
1973570bc18cSDmytro Laktyushkin 				if (split[i] == 2 && ((pipe->prev_odm_pipe && !pipe->prev_odm_pipe->prev_odm_pipe)
1974570bc18cSDmytro Laktyushkin 						|| !pipe->next_odm_pipe)) {
1975570bc18cSDmytro Laktyushkin 					merge[i] = true; /* 4 -> 2 ODM */
1976570bc18cSDmytro Laktyushkin 				} else if (split[i] == 0 && pipe->prev_odm_pipe) {
1977570bc18cSDmytro Laktyushkin 					ASSERT(0); /* NOT expected yet */
1978570bc18cSDmytro Laktyushkin 					merge[i] = true; /* exit ODM */
19797287a675SDmytro Laktyushkin 				}
198065d68369SIsabel Zhang 				split[i] = 0;
198121741810SWenjing Liu 			} else if (resource_get_mpc_slice_count(pipe) > 1) {
1982570bc18cSDmytro Laktyushkin 				/* MPC -> ODM transition */
1983570bc18cSDmytro Laktyushkin 				ASSERT(0); /* NOT expected yet */
1984570bc18cSDmytro Laktyushkin 				if (pipe->top_pipe && pipe->top_pipe->plane_state == pipe->plane_state) {
198565d68369SIsabel Zhang 					split[i] = 0;
1986570bc18cSDmytro Laktyushkin 					merge[i] = true;
1987570bc18cSDmytro Laktyushkin 				}
198865d68369SIsabel Zhang 			}
19897287a675SDmytro Laktyushkin 		}
19907287a675SDmytro Laktyushkin 
1991b6bfba6cSDmytro Laktyushkin 		/* Adjust dppclk when split is forced, do not bother with dispclk */
1992cf689e86SMelissa Wen 		if (split[i] != 0 && v->NoOfDPP[vlevel][max_mpc_comb][pipe_idx] == 1) {
1993cf689e86SMelissa Wen 			DC_FP_START();
1994cf689e86SMelissa Wen 			dcn20_fpu_adjust_dppclk(v, vlevel, max_mpc_comb, pipe_idx, false);
1995cf689e86SMelissa Wen 			DC_FP_END();
1996cf689e86SMelissa Wen 		}
1997b6bfba6cSDmytro Laktyushkin 		pipe_idx++;
1998b6bfba6cSDmytro Laktyushkin 	}
1999b6bfba6cSDmytro Laktyushkin 
2000b6bfba6cSDmytro Laktyushkin 	return vlevel;
2001b6bfba6cSDmytro Laktyushkin }
2002b6bfba6cSDmytro Laktyushkin 
dcn20_fast_validate_bw(struct dc * dc,struct dc_state * context,display_e2e_pipe_params_st * pipes,int * pipe_cnt_out,int * pipe_split_from,int * vlevel_out,enum dc_validate_mode validate_mode)2003b6bfba6cSDmytro Laktyushkin bool dcn20_fast_validate_bw(
2004b6bfba6cSDmytro Laktyushkin 		struct dc *dc,
2005b6bfba6cSDmytro Laktyushkin 		struct dc_state *context,
2006b6bfba6cSDmytro Laktyushkin 		display_e2e_pipe_params_st *pipes,
2007b6bfba6cSDmytro Laktyushkin 		int *pipe_cnt_out,
2008b6bfba6cSDmytro Laktyushkin 		int *pipe_split_from,
2009fa896813SIsabel Zhang 		int *vlevel_out,
2010fa896813SIsabel Zhang 		enum dc_validate_mode validate_mode)
2011b6bfba6cSDmytro Laktyushkin {
2012b6bfba6cSDmytro Laktyushkin 	bool out = false;
201365d68369SIsabel Zhang 	int split[MAX_PIPES] = { 0 };
201455595987SAlex Hung 	bool merge[MAX_PIPES] = { false };
2015b6bfba6cSDmytro Laktyushkin 	int pipe_cnt, i, pipe_idx, vlevel;
2016b6bfba6cSDmytro Laktyushkin 
2017b6bfba6cSDmytro Laktyushkin 	ASSERT(pipes);
2018b6bfba6cSDmytro Laktyushkin 	if (!pipes)
2019b6bfba6cSDmytro Laktyushkin 		return false;
2020b6bfba6cSDmytro Laktyushkin 
2021b6bfba6cSDmytro Laktyushkin 	dcn20_merge_pipes_for_validate(dc, context);
2022b6bfba6cSDmytro Laktyushkin 
2023cf689e86SMelissa Wen 	DC_FP_START();
2024fa896813SIsabel Zhang 	pipe_cnt = dc->res_pool->funcs->populate_dml_pipes(dc, context, pipes, validate_mode);
2025cf689e86SMelissa Wen 	DC_FP_END();
2026b6bfba6cSDmytro Laktyushkin 
2027b6bfba6cSDmytro Laktyushkin 	*pipe_cnt_out = pipe_cnt;
2028b6bfba6cSDmytro Laktyushkin 
2029b6bfba6cSDmytro Laktyushkin 	if (!pipe_cnt) {
2030b6bfba6cSDmytro Laktyushkin 		out = true;
2031b6bfba6cSDmytro Laktyushkin 		goto validate_out;
2032b6bfba6cSDmytro Laktyushkin 	}
2033b6bfba6cSDmytro Laktyushkin 
2034b6bfba6cSDmytro Laktyushkin 	vlevel = dml_get_voltage_level(&context->bw_ctx.dml, pipes, pipe_cnt);
2035b6bfba6cSDmytro Laktyushkin 
2036b6bfba6cSDmytro Laktyushkin 	if (vlevel > context->bw_ctx.dml.soc.num_states)
2037b6bfba6cSDmytro Laktyushkin 		goto validate_fail;
2038b6bfba6cSDmytro Laktyushkin 
203955595987SAlex Hung 	vlevel = dcn20_validate_apply_pipe_split_flags(dc, context, vlevel, split, merge);
2040b6bfba6cSDmytro Laktyushkin 
2041b6bfba6cSDmytro Laktyushkin 	/*initialize pipe_just_split_from to invalid idx*/
2042b6bfba6cSDmytro Laktyushkin 	for (i = 0; i < MAX_PIPES; i++)
2043b6bfba6cSDmytro Laktyushkin 		pipe_split_from[i] = -1;
20447ed4e635SHarry Wentland 
20457ed4e635SHarry Wentland 	for (i = 0, pipe_idx = -1; i < dc->res_pool->pipe_count; i++) {
20467ed4e635SHarry Wentland 		struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
20477ed4e635SHarry Wentland 		struct pipe_ctx *hsplit_pipe = pipe->bottom_pipe;
20487ed4e635SHarry Wentland 
20497ed4e635SHarry Wentland 		if (!pipe->stream || pipe_split_from[i] >= 0)
20507ed4e635SHarry Wentland 			continue;
20517ed4e635SHarry Wentland 
20527ed4e635SHarry Wentland 		pipe_idx++;
20537ed4e635SHarry Wentland 
20547ed4e635SHarry Wentland 		if (!pipe->top_pipe && !pipe->plane_state && context->bw_ctx.dml.vba.ODMCombineEnabled[pipe_idx]) {
2055c681491aSJun Lei 			hsplit_pipe = dcn20_find_secondary_pipe(dc, &context->res_ctx, dc->res_pool, pipe);
20567ed4e635SHarry Wentland 			ASSERT(hsplit_pipe);
2057b1f6d01cSDmytro Laktyushkin 			if (!dcn20_split_stream_for_odm(
205814e49bb3SNikola Cornij 					dc, &context->res_ctx,
2059b1f6d01cSDmytro Laktyushkin 					pipe, hsplit_pipe))
20607ed4e635SHarry Wentland 				goto validate_fail;
20617ed4e635SHarry Wentland 			pipe_split_from[hsplit_pipe->pipe_idx] = pipe_idx;
20627ed4e635SHarry Wentland 			dcn20_build_mapped_resource(dc, context, pipe->stream);
20637ed4e635SHarry Wentland 		}
20647ed4e635SHarry Wentland 
20657ed4e635SHarry Wentland 		if (!pipe->plane_state)
20667ed4e635SHarry Wentland 			continue;
20677ed4e635SHarry Wentland 		/* Skip 2nd half of already split pipe */
20687ed4e635SHarry Wentland 		if (pipe->top_pipe && pipe->plane_state == pipe->top_pipe->plane_state)
20697ed4e635SHarry Wentland 			continue;
20707ed4e635SHarry Wentland 
207102ce5a79SDmytro Laktyushkin 		/* We do not support mpo + odm at the moment */
207202ce5a79SDmytro Laktyushkin 		if (hsplit_pipe && hsplit_pipe->plane_state != pipe->plane_state
207302ce5a79SDmytro Laktyushkin 				&& context->bw_ctx.dml.vba.ODMCombineEnabled[pipe_idx])
207402ce5a79SDmytro Laktyushkin 			goto validate_fail;
207502ce5a79SDmytro Laktyushkin 
207665d68369SIsabel Zhang 		if (split[i] == 2) {
20777ed4e635SHarry Wentland 			if (!hsplit_pipe || hsplit_pipe->plane_state != pipe->plane_state) {
20787ed4e635SHarry Wentland 				/* pipe not split previously needs split */
2079c681491aSJun Lei 				hsplit_pipe = dcn20_find_secondary_pipe(dc, &context->res_ctx, dc->res_pool, pipe);
2080b6bfba6cSDmytro Laktyushkin 				ASSERT(hsplit_pipe);
2081ff86391eSMichael Strauss 				if (!hsplit_pipe) {
2082cf689e86SMelissa Wen 					DC_FP_START();
2083cf689e86SMelissa Wen 					dcn20_fpu_adjust_dppclk(&context->bw_ctx.dml.vba, vlevel, context->bw_ctx.dml.vba.maxMpcComb, pipe_idx, true);
2084cf689e86SMelissa Wen 					DC_FP_END();
20857ed4e635SHarry Wentland 					continue;
2086ff86391eSMichael Strauss 				}
2087b1f6d01cSDmytro Laktyushkin 				if (context->bw_ctx.dml.vba.ODMCombineEnabled[pipe_idx]) {
2088b1f6d01cSDmytro Laktyushkin 					if (!dcn20_split_stream_for_odm(
208914e49bb3SNikola Cornij 							dc, &context->res_ctx,
2090b1f6d01cSDmytro Laktyushkin 							pipe, hsplit_pipe))
20917ed4e635SHarry Wentland 						goto validate_fail;
2092387596efSMikita Lipski 					dcn20_build_mapped_resource(dc, context, pipe->stream);
209365d68369SIsabel Zhang 				} else {
209465d68369SIsabel Zhang 					dcn20_split_stream_for_mpc(
2095b1f6d01cSDmytro Laktyushkin 							&context->res_ctx, dc->res_pool,
209665d68369SIsabel Zhang 							pipe, hsplit_pipe);
209765f9ace4SSung Lee 					resource_build_scaling_params(pipe);
209865f9ace4SSung Lee 					resource_build_scaling_params(hsplit_pipe);
209965d68369SIsabel Zhang 				}
21007ed4e635SHarry Wentland 				pipe_split_from[hsplit_pipe->pipe_idx] = pipe_idx;
21017ed4e635SHarry Wentland 			}
210202ce5a79SDmytro Laktyushkin 		} else if (hsplit_pipe && hsplit_pipe->plane_state == pipe->plane_state) {
21037ed4e635SHarry Wentland 			/* merge should already have been done */
21047ed4e635SHarry Wentland 			ASSERT(0);
21057ed4e635SHarry Wentland 		}
21067ed4e635SHarry Wentland 	}
210763e7ee67SPeterson Guo 
21080ba37b20SDmytro Laktyushkin 	/* Actual dsc count per stream dsc validation*/
2109c84ad0d6SDmytro Laktyushkin 	if (!dcn20_validate_dsc(dc, context)) {
21100ba37b20SDmytro Laktyushkin 		context->bw_ctx.dml.vba.ValidationStatus[context->bw_ctx.dml.vba.soc.num_states] =
21110ba37b20SDmytro Laktyushkin 				DML_FAIL_DSC_VALIDATION_FAILURE;
21120ba37b20SDmytro Laktyushkin 		goto validate_fail;
21130ba37b20SDmytro Laktyushkin 	}
21147ed4e635SHarry Wentland 
21156de20237SEric Yang 	*vlevel_out = vlevel;
211642351c66SJoshua Aberback 
2117254eb07cSJoshua Aberback 	out = true;
2118254eb07cSJoshua Aberback 	goto validate_out;
21196de20237SEric Yang 
21206de20237SEric Yang validate_fail:
21216de20237SEric Yang 	out = false;
21226de20237SEric Yang 
21236de20237SEric Yang validate_out:
21246de20237SEric Yang 	return out;
2125254eb07cSJoshua Aberback }
2126254eb07cSJoshua Aberback 
dcn20_validate_bandwidth(struct dc * dc,struct dc_state * context,enum dc_validate_mode validate_mode)2127*4465dd0eSDillon Varone enum dc_status dcn20_validate_bandwidth(struct dc *dc, struct dc_state *context,
21288b91fd8bSDaniel Kolesa 		enum dc_validate_mode validate_mode)
21298b91fd8bSDaniel Kolesa {
213041401ac6SJan Kokemüller 	bool voltage_supported;
21312091ac69SSebastian Andrzej Siewior 	display_e2e_pipe_params_st *pipes;
21322091ac69SSebastian Andrzej Siewior 
21332091ac69SSebastian Andrzej Siewior 	pipes = kcalloc(dc->res_pool->pipe_count, sizeof(display_e2e_pipe_params_st), GFP_KERNEL);
21342091ac69SSebastian Andrzej Siewior 	if (!pipes)
2135*4465dd0eSDillon Varone 		return DC_FAIL_BANDWIDTH_VALIDATE;
21362091ac69SSebastian Andrzej Siewior 
21378b91fd8bSDaniel Kolesa 	DC_FP_START();
21382091ac69SSebastian Andrzej Siewior 	voltage_supported = dcn20_validate_bandwidth_fp(dc, context, validate_mode, pipes);
21397a8a3430STimothy Pearson 	DC_FP_END();
21402091ac69SSebastian Andrzej Siewior 
21412091ac69SSebastian Andrzej Siewior 	kfree(pipes);
2142*4465dd0eSDillon Varone 	return voltage_supported ? DC_OK : DC_FAIL_BANDWIDTH_VALIDATE;
2143057fc695SJun Lei }
2144057fc695SJun Lei 
dcn20_acquire_free_pipe_for_layer(const struct dc_state * cur_ctx,struct dc_state * new_ctx,const struct resource_pool * pool,const struct pipe_ctx * opp_head)2145198f0e89SWenjing Liu struct pipe_ctx *dcn20_acquire_free_pipe_for_layer(
2146460ea898SWenjing Liu 		const struct dc_state *cur_ctx,
2147460ea898SWenjing Liu 		struct dc_state *new_ctx,
21487ed4e635SHarry Wentland 		const struct resource_pool *pool,
214973d45092SWenjing Liu 		const struct pipe_ctx *opp_head)
21507ed4e635SHarry Wentland {
2151460ea898SWenjing Liu 	struct resource_context *res_ctx = &new_ctx->res_ctx;
215253f32880SWenjing Liu 	struct pipe_ctx *otg_master = resource_get_otg_master_for_stream(res_ctx, opp_head->stream);
215353f32880SWenjing Liu 	struct pipe_ctx *sec_dpp_pipe = resource_find_free_secondary_pipe_legacy(res_ctx, pool, otg_master);
21547ed4e635SHarry Wentland 
215573d45092SWenjing Liu 	ASSERT(otg_master);
21567ed4e635SHarry Wentland 
215773d45092SWenjing Liu 	if (!sec_dpp_pipe)
21587a17c8ceSArnd Bergmann 		return NULL;
21597ed4e635SHarry Wentland 
216073d45092SWenjing Liu 	sec_dpp_pipe->stream = opp_head->stream;
216173d45092SWenjing Liu 	sec_dpp_pipe->stream_res.tg = opp_head->stream_res.tg;
216273d45092SWenjing Liu 	sec_dpp_pipe->stream_res.opp = opp_head->stream_res.opp;
21637ed4e635SHarry Wentland 
216473d45092SWenjing Liu 	sec_dpp_pipe->plane_res.hubp = pool->hubps[sec_dpp_pipe->pipe_idx];
216573d45092SWenjing Liu 	sec_dpp_pipe->plane_res.ipp = pool->ipps[sec_dpp_pipe->pipe_idx];
216673d45092SWenjing Liu 	sec_dpp_pipe->plane_res.dpp = pool->dpps[sec_dpp_pipe->pipe_idx];
216773d45092SWenjing Liu 	sec_dpp_pipe->plane_res.mpcc_inst = pool->dpps[sec_dpp_pipe->pipe_idx]->inst;
21687ed4e635SHarry Wentland 
216973d45092SWenjing Liu 	return sec_dpp_pipe;
21707ed4e635SHarry Wentland }
21717ed4e635SHarry Wentland 
dcn20_get_dcc_compression_cap(const struct dc * dc,const struct dc_dcc_surface_param * input,struct dc_surface_dcc_cap * output)21727ed4e635SHarry Wentland bool dcn20_get_dcc_compression_cap(const struct dc *dc,
21737ed4e635SHarry Wentland 		const struct dc_dcc_surface_param *input,
21747ed4e635SHarry Wentland 		struct dc_surface_dcc_cap *output)
21757ed4e635SHarry Wentland {
2176ecbf6078SAurabindo Pillai 	if (dc->res_pool->hubbub->funcs->get_dcc_compression_cap)
21777ed4e635SHarry Wentland 		return dc->res_pool->hubbub->funcs->get_dcc_compression_cap(
2178ecbf6078SAurabindo Pillai 			dc->res_pool->hubbub, input, output);
2179ecbf6078SAurabindo Pillai 
2180ecbf6078SAurabindo Pillai 	return false;
21817ed4e635SHarry Wentland }
21827ed4e635SHarry Wentland 
dcn20_destroy_resource_pool(struct resource_pool ** pool)21837ed4e635SHarry Wentland static void dcn20_destroy_resource_pool(struct resource_pool **pool)
21847ed4e635SHarry Wentland {
21857ed4e635SHarry Wentland 	struct dcn20_resource_pool *dcn20_pool = TO_DCN20_RES_POOL(*pool);
21867ed4e635SHarry Wentland 
2187d9e32672SAnthony Koo 	dcn20_resource_destruct(dcn20_pool);
21887ed4e635SHarry Wentland 	kfree(dcn20_pool);
21897ed4e635SHarry Wentland 	*pool = NULL;
21907ed4e635SHarry Wentland }
21917ed4e635SHarry Wentland 
21927ed4e635SHarry Wentland 
21937ed4e635SHarry Wentland static struct dc_cap_funcs cap_funcs = {
21947ed4e635SHarry Wentland 	.get_dcc_compression_cap = dcn20_get_dcc_compression_cap
21957ed4e635SHarry Wentland };
21967ed4e635SHarry Wentland 
21977ed4e635SHarry Wentland 
dcn20_patch_unknown_plane_state(struct dc_plane_state * plane_state)21988d8c82b6SJoseph Gravenor enum dc_status dcn20_patch_unknown_plane_state(struct dc_plane_state *plane_state)
21997ed4e635SHarry Wentland {
22007ed4e635SHarry Wentland 	enum surface_pixel_format surf_pix_format = plane_state->format;
22017ed4e635SHarry Wentland 	unsigned int bpp = resource_pixel_format_to_bpp(surf_pix_format);
22027ed4e635SHarry Wentland 
2203febb4147SGuilherme G. Piccoli 	plane_state->tiling_info.gfx9.swizzle = DC_SW_64KB_S;
22047ed4e635SHarry Wentland 	if (bpp == 64)
2205febb4147SGuilherme G. Piccoli 		plane_state->tiling_info.gfx9.swizzle = DC_SW_64KB_D;
22067ed4e635SHarry Wentland 
2207b1c3b7f1SJason Yan 	return DC_OK;
22087ed4e635SHarry Wentland }
22097ed4e635SHarry Wentland 
dcn20_release_pipe(struct dc_state * context,struct pipe_ctx * pipe,const struct resource_pool * pool)221021741810SWenjing Liu void dcn20_release_pipe(struct dc_state *context,
221121741810SWenjing Liu 			struct pipe_ctx *pipe,
221221741810SWenjing Liu 			const struct resource_pool *pool)
221321741810SWenjing Liu {
221421741810SWenjing Liu 	if (resource_is_pipe_type(pipe, OPP_HEAD) && pipe->stream_res.dsc)
221521741810SWenjing Liu 		dcn20_release_dsc(&context->res_ctx, pool, &pipe->stream_res.dsc);
221621741810SWenjing Liu 	memset(pipe, 0, sizeof(*pipe));
221721741810SWenjing Liu }
221821741810SWenjing Liu 
221925457a1fSRikard Falkeborn static const struct resource_funcs dcn20_res_pool_funcs = {
22207ed4e635SHarry Wentland 	.destroy = dcn20_destroy_resource_pool,
22217ed4e635SHarry Wentland 	.link_enc_create = dcn20_link_encoder_create,
2222d4caa72eSAnthony Koo 	.panel_cntl_create = dcn20_panel_cntl_create,
22237ed4e635SHarry Wentland 	.validate_bandwidth = dcn20_validate_bandwidth,
2224198f0e89SWenjing Liu 	.acquire_free_pipe_as_secondary_dpp_pipe = dcn20_acquire_free_pipe_for_layer,
222521741810SWenjing Liu 	.release_pipe = dcn20_release_pipe,
22267ed4e635SHarry Wentland 	.add_stream_to_ctx = dcn20_add_stream_to_ctx,
2227b4f71c8cSAurabindo Pillai 	.add_dsc_to_stream_resource = dcn20_add_dsc_to_stream_resource,
22287ed4e635SHarry Wentland 	.remove_stream_from_ctx = dcn20_remove_stream_from_ctx,
22297ed4e635SHarry Wentland 	.populate_dml_writeback_from_context = dcn20_populate_dml_writeback_from_context,
22308d8c82b6SJoseph Gravenor 	.patch_unknown_plane_state = dcn20_patch_unknown_plane_state,
2231c9ae6e16SNikola Cornij 	.set_mcif_arb_params = dcn20_set_mcif_arb_params,
2232b6bfba6cSDmytro Laktyushkin 	.populate_dml_pipes = dcn20_populate_dml_pipes_from_context,
223363ab80d9SRafal Ostrowski 	.find_first_free_match_stream_enc_for_link = dcn10_find_first_free_match_stream_enc_for_link,
223463ab80d9SRafal Ostrowski 	.get_vstartup_for_pipe = dcn10_get_vstartup_for_pipe
22357ed4e635SHarry Wentland };
22367ed4e635SHarry Wentland 
dcn20_dwbc_create(struct dc_context * ctx,struct resource_pool * pool)2237bb21290fSCharlene Liu bool dcn20_dwbc_create(struct dc_context *ctx, struct resource_pool *pool)
2238bb21290fSCharlene Liu {
2239bb21290fSCharlene Liu 	int i;
2240bb21290fSCharlene Liu 	uint32_t pipe_count = pool->res_cap->num_dwb;
2241bb21290fSCharlene Liu 
2242bb21290fSCharlene Liu 	for (i = 0; i < pipe_count; i++) {
2243bb21290fSCharlene Liu 		struct dcn20_dwbc *dwbc20 = kzalloc(sizeof(struct dcn20_dwbc),
2244bb21290fSCharlene Liu 						    GFP_KERNEL);
2245bb21290fSCharlene Liu 
2246bb21290fSCharlene Liu 		if (!dwbc20) {
2247bb21290fSCharlene Liu 			dm_error("DC: failed to create dwbc20!\n");
2248bb21290fSCharlene Liu 			return false;
2249bb21290fSCharlene Liu 		}
2250bb21290fSCharlene Liu 		dcn20_dwbc_construct(dwbc20, ctx,
2251bb21290fSCharlene Liu 				&dwbc20_regs[i],
2252bb21290fSCharlene Liu 				&dwbc20_shift,
2253bb21290fSCharlene Liu 				&dwbc20_mask,
2254bb21290fSCharlene Liu 				i);
2255bb21290fSCharlene Liu 		pool->dwbc[i] = &dwbc20->base;
2256bb21290fSCharlene Liu 	}
2257bb21290fSCharlene Liu 	return true;
2258bb21290fSCharlene Liu }
2259bb21290fSCharlene Liu 
dcn20_mmhubbub_create(struct dc_context * ctx,struct resource_pool * pool)2260bb21290fSCharlene Liu bool dcn20_mmhubbub_create(struct dc_context *ctx, struct resource_pool *pool)
2261bb21290fSCharlene Liu {
2262bb21290fSCharlene Liu 	int i;
2263bb21290fSCharlene Liu 	uint32_t pipe_count = pool->res_cap->num_dwb;
2264bb21290fSCharlene Liu 
2265bb21290fSCharlene Liu 	ASSERT(pipe_count > 0);
2266bb21290fSCharlene Liu 
2267bb21290fSCharlene Liu 	for (i = 0; i < pipe_count; i++) {
2268bb21290fSCharlene Liu 		struct dcn20_mmhubbub *mcif_wb20 = kzalloc(sizeof(struct dcn20_mmhubbub),
2269bb21290fSCharlene Liu 						    GFP_KERNEL);
2270bb21290fSCharlene Liu 
2271bb21290fSCharlene Liu 		if (!mcif_wb20) {
2272bb21290fSCharlene Liu 			dm_error("DC: failed to create mcif_wb20!\n");
2273bb21290fSCharlene Liu 			return false;
2274bb21290fSCharlene Liu 		}
2275bb21290fSCharlene Liu 
2276bb21290fSCharlene Liu 		dcn20_mmhubbub_construct(mcif_wb20, ctx,
2277bb21290fSCharlene Liu 				&mcif_wb20_regs[i],
2278bb21290fSCharlene Liu 				&mcif_wb20_shift,
2279bb21290fSCharlene Liu 				&mcif_wb20_mask,
2280bb21290fSCharlene Liu 				i);
2281bb21290fSCharlene Liu 
2282bb21290fSCharlene Liu 		pool->mcif_wb[i] = &mcif_wb20->base;
2283bb21290fSCharlene Liu 	}
2284bb21290fSCharlene Liu 	return true;
2285bb21290fSCharlene Liu }
2286bb21290fSCharlene Liu 
dcn20_pp_smu_create(struct dc_context * ctx)228744e149bbSAlex Deucher static struct pp_smu_funcs *dcn20_pp_smu_create(struct dc_context *ctx)
22887ed4e635SHarry Wentland {
22893bb11050SNirmoy Das 	struct pp_smu_funcs *pp_smu = kzalloc(sizeof(*pp_smu), GFP_ATOMIC);
22907ed4e635SHarry Wentland 
22917ed4e635SHarry Wentland 	if (!pp_smu)
22927ed4e635SHarry Wentland 		return pp_smu;
22937ed4e635SHarry Wentland 
22947ed4e635SHarry Wentland 	dm_pp_get_funcs(ctx, pp_smu);
22957ed4e635SHarry Wentland 
22967ed4e635SHarry Wentland 	if (pp_smu->ctx.ver != PP_SMU_VER_NV)
22977ed4e635SHarry Wentland 		pp_smu = memset(pp_smu, 0, sizeof(struct pp_smu_funcs));
22987ed4e635SHarry Wentland 
22997ed4e635SHarry Wentland 	return pp_smu;
23007ed4e635SHarry Wentland }
23017ed4e635SHarry Wentland 
dcn20_pp_smu_destroy(struct pp_smu_funcs ** pp_smu)230244e149bbSAlex Deucher static void dcn20_pp_smu_destroy(struct pp_smu_funcs **pp_smu)
23037ed4e635SHarry Wentland {
23047ed4e635SHarry Wentland 	if (pp_smu && *pp_smu) {
23057ed4e635SHarry Wentland 		kfree(*pp_smu);
23067ed4e635SHarry Wentland 		*pp_smu = NULL;
23077ed4e635SHarry Wentland 	}
23087ed4e635SHarry Wentland }
23097ed4e635SHarry Wentland 
get_asic_rev_soc_bb(uint32_t hw_internal_rev)2310675a9e38SLeo Li static struct _vcs_dpi_soc_bounding_box_st *get_asic_rev_soc_bb(
2311675a9e38SLeo Li 	uint32_t hw_internal_rev)
2312675a9e38SLeo Li {
2313e1ab4a91SMartin Leung 	if (ASICREV_IS_NAVI14_M(hw_internal_rev))
2314e1ab4a91SMartin Leung 		return &dcn2_0_nv14_soc;
2315e1ab4a91SMartin Leung 
2316675a9e38SLeo Li 	if (ASICREV_IS_NAVI12_P(hw_internal_rev))
2317675a9e38SLeo Li 		return &dcn2_0_nv12_soc;
2318675a9e38SLeo Li 
2319675a9e38SLeo Li 	return &dcn2_0_soc;
2320675a9e38SLeo Li }
2321675a9e38SLeo Li 
get_asic_rev_ip_params(uint32_t hw_internal_rev)2322675a9e38SLeo Li static struct _vcs_dpi_ip_params_st *get_asic_rev_ip_params(
2323675a9e38SLeo Li 	uint32_t hw_internal_rev)
2324675a9e38SLeo Li {
232572b741afSZhan liu 	if (ASICREV_IS_NAVI14_M(hw_internal_rev))
232672b741afSZhan liu 		return &dcn2_0_nv14_ip;
232772b741afSZhan liu 
2328675a9e38SLeo Li 	/* NV12 and NV10 */
2329675a9e38SLeo Li 	return &dcn2_0_ip;
2330675a9e38SLeo Li }
2331675a9e38SLeo Li 
get_dml_project_version(uint32_t hw_internal_rev)2332675a9e38SLeo Li static enum dml_project get_dml_project_version(uint32_t hw_internal_rev)
2333675a9e38SLeo Li {
2334675a9e38SLeo Li 	return DML_PROJECT_NAVI10v2;
2335675a9e38SLeo Li }
2336675a9e38SLeo Li 
init_soc_bounding_box(struct dc * dc,struct dcn20_resource_pool * pool)23377ed4e635SHarry Wentland static bool init_soc_bounding_box(struct dc *dc,
23387ed4e635SHarry Wentland 				  struct dcn20_resource_pool *pool)
23397ed4e635SHarry Wentland {
2340675a9e38SLeo Li 	struct _vcs_dpi_soc_bounding_box_st *loaded_bb =
2341675a9e38SLeo Li 			get_asic_rev_soc_bb(dc->ctx->asic_id.hw_internal_rev);
2342675a9e38SLeo Li 	struct _vcs_dpi_ip_params_st *loaded_ip =
2343675a9e38SLeo Li 			get_asic_rev_ip_params(dc->ctx->asic_id.hw_internal_rev);
2344675a9e38SLeo Li 
23457ed4e635SHarry Wentland 	DC_LOGGER_INIT(dc->ctx->logger);
23467ed4e635SHarry Wentland 
23477ed4e635SHarry Wentland 	if (pool->base.pp_smu) {
23487ed4e635SHarry Wentland 		struct pp_smu_nv_clock_table max_clocks = {0};
23497ed4e635SHarry Wentland 		unsigned int uclk_states[8] = {0};
23507ed4e635SHarry Wentland 		unsigned int num_states = 0;
23517ed4e635SHarry Wentland 		enum pp_smu_status status;
23527ed4e635SHarry Wentland 		bool clock_limits_available = false;
23537ed4e635SHarry Wentland 		bool uclk_states_available = false;
23547ed4e635SHarry Wentland 
23557ed4e635SHarry Wentland 		if (pool->base.pp_smu->nv_funcs.get_uclk_dpm_states) {
23567ed4e635SHarry Wentland 			status = (pool->base.pp_smu->nv_funcs.get_uclk_dpm_states)
23577ed4e635SHarry Wentland 				(&pool->base.pp_smu->nv_funcs.pp_smu, uclk_states, &num_states);
23587ed4e635SHarry Wentland 
23597ed4e635SHarry Wentland 			uclk_states_available = (status == PP_SMU_RESULT_OK);
23607ed4e635SHarry Wentland 		}
23617ed4e635SHarry Wentland 
23627ed4e635SHarry Wentland 		if (pool->base.pp_smu->nv_funcs.get_maximum_sustainable_clocks) {
23637ed4e635SHarry Wentland 			status = (*pool->base.pp_smu->nv_funcs.get_maximum_sustainable_clocks)
23647ed4e635SHarry Wentland 					(&pool->base.pp_smu->nv_funcs.pp_smu, &max_clocks);
2365c2ad17c3SAidan Wood 			/* SMU cannot set DCF clock to anything equal to or higher than SOC clock
2366c2ad17c3SAidan Wood 			 */
2367c2ad17c3SAidan Wood 			if (max_clocks.dcfClockInKhz >= max_clocks.socClockInKhz)
2368c2ad17c3SAidan Wood 				max_clocks.dcfClockInKhz = max_clocks.socClockInKhz - 1000;
23697ed4e635SHarry Wentland 			clock_limits_available = (status == PP_SMU_RESULT_OK);
23707ed4e635SHarry Wentland 		}
23717ed4e635SHarry Wentland 
2372bc39a69aSAnson Jacob 		if (clock_limits_available && uclk_states_available && num_states) {
2373bc39a69aSAnson Jacob 			DC_FP_START();
237444ce0cd3SDmytro Laktyushkin 			dcn20_update_bounding_box(dc, loaded_bb, &max_clocks, uclk_states, num_states);
2375bc39a69aSAnson Jacob 			DC_FP_END();
2376bc39a69aSAnson Jacob 		} else if (clock_limits_available) {
2377bc39a69aSAnson Jacob 			DC_FP_START();
237844ce0cd3SDmytro Laktyushkin 			dcn20_cap_soc_clocks(loaded_bb, max_clocks);
2379bc39a69aSAnson Jacob 			DC_FP_END();
2380bc39a69aSAnson Jacob 		}
23817ed4e635SHarry Wentland 	}
23827ed4e635SHarry Wentland 
2383675a9e38SLeo Li 	loaded_ip->max_num_otg = pool->base.res_cap->num_timing_generator;
2384675a9e38SLeo Li 	loaded_ip->max_num_dpp = pool->base.pipe_count;
2385bc39a69aSAnson Jacob 	DC_FP_START();
238644ce0cd3SDmytro Laktyushkin 	dcn20_patch_bounding_box(dc, loaded_bb);
2387bc39a69aSAnson Jacob 	DC_FP_END();
23887ed4e635SHarry Wentland 	return true;
23897ed4e635SHarry Wentland }
23907ed4e635SHarry Wentland 
dcn20_resource_construct(uint8_t num_virtual_links,struct dc * dc,struct dcn20_resource_pool * pool)2391d9e32672SAnthony Koo static bool dcn20_resource_construct(
23927ed4e635SHarry Wentland 	uint8_t num_virtual_links,
23937ed4e635SHarry Wentland 	struct dc *dc,
23947ed4e635SHarry Wentland 	struct dcn20_resource_pool *pool)
23957ed4e635SHarry Wentland {
23967ed4e635SHarry Wentland 	int i;
23977ed4e635SHarry Wentland 	struct dc_context *ctx = dc->ctx;
23987ed4e635SHarry Wentland 	struct irq_service_init_data init_data;
2399130ac6d8SYu-ting Shen 	struct ddc_service_init_data ddc_init_data = {0};
2400675a9e38SLeo Li 	struct _vcs_dpi_soc_bounding_box_st *loaded_bb =
2401675a9e38SLeo Li 			get_asic_rev_soc_bb(ctx->asic_id.hw_internal_rev);
2402675a9e38SLeo Li 	struct _vcs_dpi_ip_params_st *loaded_ip =
2403675a9e38SLeo Li 			get_asic_rev_ip_params(ctx->asic_id.hw_internal_rev);
2404675a9e38SLeo Li 	enum dml_project dml_project_version =
2405675a9e38SLeo Li 			get_dml_project_version(ctx->asic_id.hw_internal_rev);
24067ed4e635SHarry Wentland 
24077ed4e635SHarry Wentland 	ctx->dc_bios->regs = &bios_regs;
24087ed4e635SHarry Wentland 	pool->base.funcs = &dcn20_res_pool_funcs;
24097ed4e635SHarry Wentland 
24102ebe1773SBhawanpreet Lakha 	if (ASICREV_IS_NAVI14_M(ctx->asic_id.hw_internal_rev)) {
24112ebe1773SBhawanpreet Lakha 		pool->base.res_cap = &res_cap_nv14;
24122ebe1773SBhawanpreet Lakha 		pool->base.pipe_count = 5;
24132ebe1773SBhawanpreet Lakha 		pool->base.mpcc_count = 5;
24142ebe1773SBhawanpreet Lakha 	} else {
24152ebe1773SBhawanpreet Lakha 		pool->base.res_cap = &res_cap_nv10;
24162ebe1773SBhawanpreet Lakha 		pool->base.pipe_count = 6;
24172ebe1773SBhawanpreet Lakha 		pool->base.mpcc_count = 6;
24182ebe1773SBhawanpreet Lakha 	}
24197ed4e635SHarry Wentland 	/*************************************************
24207ed4e635SHarry Wentland 	 *  Resource + asic cap harcoding                *
24217ed4e635SHarry Wentland 	 *************************************************/
24227ed4e635SHarry Wentland 	pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
24237ed4e635SHarry Wentland 
24247ed4e635SHarry Wentland 	dc->caps.max_downscale_ratio = 200;
24257ed4e635SHarry Wentland 	dc->caps.i2c_speed_in_khz = 100;
2426b15cde19SCharlene Liu 	dc->caps.i2c_speed_in_khz_hdcp = 100; /*1.4 w/a not applied by default*/
24277ed4e635SHarry Wentland 	dc->caps.max_cursor_size = 256;
24289248681fSAshley Thomas 	dc->caps.min_horizontal_blanking_period = 80;
24297ed4e635SHarry Wentland 	dc->caps.dmdata_alloc_size = 2048;
24307ed4e635SHarry Wentland 
24317ed4e635SHarry Wentland 	dc->caps.max_slave_planes = 1;
2432ae030570SAtufa Khan 	dc->caps.max_slave_yuv_planes = 1;
2433ae030570SAtufa Khan 	dc->caps.max_slave_rgb_planes = 1;
24347ed4e635SHarry Wentland 	dc->caps.post_blend_color_processing = true;
24357ed4e635SHarry Wentland 	dc->caps.force_dp_tps4_for_cp2520 = true;
2436ca4f844eSabdoulaye berthe 	dc->caps.extended_aux_timeout_support = true;
24372b6c4a4bSRodrigo Siqueira 	dc->caps.dmcub_support = true;
24387ed4e635SHarry Wentland 
2439a8bf7164SKrunoslav Kovac 	/* Color pipeline capabilities */
2440a8bf7164SKrunoslav Kovac 	dc->caps.color.dpp.dcn_arch = 1;
2441a8bf7164SKrunoslav Kovac 	dc->caps.color.dpp.input_lut_shared = 0;
2442a8bf7164SKrunoslav Kovac 	dc->caps.color.dpp.icsc = 1;
2443a8bf7164SKrunoslav Kovac 	dc->caps.color.dpp.dgam_ram = 1;
2444a8bf7164SKrunoslav Kovac 	dc->caps.color.dpp.dgam_rom_caps.srgb = 1;
2445a8bf7164SKrunoslav Kovac 	dc->caps.color.dpp.dgam_rom_caps.bt2020 = 1;
2446a8bf7164SKrunoslav Kovac 	dc->caps.color.dpp.dgam_rom_caps.gamma2_2 = 0;
2447a8bf7164SKrunoslav Kovac 	dc->caps.color.dpp.dgam_rom_caps.pq = 0;
2448a8bf7164SKrunoslav Kovac 	dc->caps.color.dpp.dgam_rom_caps.hlg = 0;
2449a8bf7164SKrunoslav Kovac 	dc->caps.color.dpp.post_csc = 0;
2450a8bf7164SKrunoslav Kovac 	dc->caps.color.dpp.gamma_corr = 0;
2451c6160900SJing Zhou 	dc->caps.color.dpp.dgam_rom_for_yuv = 1;
2452a8bf7164SKrunoslav Kovac 
2453a8bf7164SKrunoslav Kovac 	dc->caps.color.dpp.hw_3d_lut = 1;
2454a8bf7164SKrunoslav Kovac 	dc->caps.color.dpp.ogam_ram = 1;
2455a8bf7164SKrunoslav Kovac 	// no OGAM ROM on DCN2, only MPC ROM
2456a8bf7164SKrunoslav Kovac 	dc->caps.color.dpp.ogam_rom_caps.srgb = 0;
2457a8bf7164SKrunoslav Kovac 	dc->caps.color.dpp.ogam_rom_caps.bt2020 = 0;
2458a8bf7164SKrunoslav Kovac 	dc->caps.color.dpp.ogam_rom_caps.gamma2_2 = 0;
2459a8bf7164SKrunoslav Kovac 	dc->caps.color.dpp.ogam_rom_caps.pq = 0;
2460a8bf7164SKrunoslav Kovac 	dc->caps.color.dpp.ogam_rom_caps.hlg = 0;
2461a8bf7164SKrunoslav Kovac 	dc->caps.color.dpp.ocsc = 0;
2462a8bf7164SKrunoslav Kovac 
2463a8bf7164SKrunoslav Kovac 	dc->caps.color.mpc.gamut_remap = 0;
2464a8bf7164SKrunoslav Kovac 	dc->caps.color.mpc.num_3dluts = 0;
2465a8bf7164SKrunoslav Kovac 	dc->caps.color.mpc.shared_3d_lut = 0;
2466a8bf7164SKrunoslav Kovac 	dc->caps.color.mpc.ogam_ram = 1;
2467a8bf7164SKrunoslav Kovac 	dc->caps.color.mpc.ogam_rom_caps.srgb = 0;
2468a8bf7164SKrunoslav Kovac 	dc->caps.color.mpc.ogam_rom_caps.bt2020 = 0;
2469a8bf7164SKrunoslav Kovac 	dc->caps.color.mpc.ogam_rom_caps.gamma2_2 = 0;
2470a8bf7164SKrunoslav Kovac 	dc->caps.color.mpc.ogam_rom_caps.pq = 0;
2471a8bf7164SKrunoslav Kovac 	dc->caps.color.mpc.ogam_rom_caps.hlg = 0;
2472a8bf7164SKrunoslav Kovac 	dc->caps.color.mpc.ocsc = 1;
2473a8bf7164SKrunoslav Kovac 
2474068ab0cdSHamza Mahfooz 	dc->caps.dp_hdmi21_pcon_support = true;
2475c022375aSFangzhi Zuo 
247625879d7bSQingqing Zhuo 	if (dc->ctx->dce_environment == DCE_ENV_PRODUCTION_DRV)
24777ed4e635SHarry Wentland 		dc->debug = debug_defaults_drv;
247825879d7bSQingqing Zhuo 
24797ed4e635SHarry Wentland 	//dcn2.0x
24807ed4e635SHarry Wentland 	dc->work_arounds.dedcn20_305_wa = true;
24817ed4e635SHarry Wentland 
24827ed4e635SHarry Wentland 	// Init the vm_helper
24837ed4e635SHarry Wentland 	if (dc->vm_helper)
2484bda9afdaSDmytro Laktyushkin 		vm_helper_init(dc->vm_helper, 16);
24857ed4e635SHarry Wentland 
24867ed4e635SHarry Wentland 	/*************************************************
24877ed4e635SHarry Wentland 	 *  Create resources                             *
24887ed4e635SHarry Wentland 	 *************************************************/
24897ed4e635SHarry Wentland 
24907ed4e635SHarry Wentland 	pool->base.clock_sources[DCN20_CLK_SRC_PLL0] =
24917ed4e635SHarry Wentland 			dcn20_clock_source_create(ctx, ctx->dc_bios,
24927ed4e635SHarry Wentland 				CLOCK_SOURCE_COMBO_PHY_PLL0,
24937ed4e635SHarry Wentland 				&clk_src_regs[0], false);
24947ed4e635SHarry Wentland 	pool->base.clock_sources[DCN20_CLK_SRC_PLL1] =
24957ed4e635SHarry Wentland 			dcn20_clock_source_create(ctx, ctx->dc_bios,
24967ed4e635SHarry Wentland 				CLOCK_SOURCE_COMBO_PHY_PLL1,
24977ed4e635SHarry Wentland 				&clk_src_regs[1], false);
24987ed4e635SHarry Wentland 	pool->base.clock_sources[DCN20_CLK_SRC_PLL2] =
24997ed4e635SHarry Wentland 			dcn20_clock_source_create(ctx, ctx->dc_bios,
25007ed4e635SHarry Wentland 				CLOCK_SOURCE_COMBO_PHY_PLL2,
25017ed4e635SHarry Wentland 				&clk_src_regs[2], false);
25027ed4e635SHarry Wentland 	pool->base.clock_sources[DCN20_CLK_SRC_PLL3] =
25037ed4e635SHarry Wentland 			dcn20_clock_source_create(ctx, ctx->dc_bios,
25047ed4e635SHarry Wentland 				CLOCK_SOURCE_COMBO_PHY_PLL3,
25057ed4e635SHarry Wentland 				&clk_src_regs[3], false);
25067ed4e635SHarry Wentland 	pool->base.clock_sources[DCN20_CLK_SRC_PLL4] =
25077ed4e635SHarry Wentland 			dcn20_clock_source_create(ctx, ctx->dc_bios,
25087ed4e635SHarry Wentland 				CLOCK_SOURCE_COMBO_PHY_PLL4,
25097ed4e635SHarry Wentland 				&clk_src_regs[4], false);
25107ed4e635SHarry Wentland 	pool->base.clock_sources[DCN20_CLK_SRC_PLL5] =
25117ed4e635SHarry Wentland 			dcn20_clock_source_create(ctx, ctx->dc_bios,
25127ed4e635SHarry Wentland 				CLOCK_SOURCE_COMBO_PHY_PLL5,
25137ed4e635SHarry Wentland 				&clk_src_regs[5], false);
25147ed4e635SHarry Wentland 	pool->base.clk_src_count = DCN20_CLK_SRC_TOTAL;
25157ed4e635SHarry Wentland 	/* todo: not reuse phy_pll registers */
25167ed4e635SHarry Wentland 	pool->base.dp_clock_source =
25177ed4e635SHarry Wentland 			dcn20_clock_source_create(ctx, ctx->dc_bios,
25187ed4e635SHarry Wentland 				CLOCK_SOURCE_ID_DP_DTO,
25197ed4e635SHarry Wentland 				&clk_src_regs[0], true);
25207ed4e635SHarry Wentland 
25217ed4e635SHarry Wentland 	for (i = 0; i < pool->base.clk_src_count; i++) {
25227ed4e635SHarry Wentland 		if (pool->base.clock_sources[i] == NULL) {
25237ed4e635SHarry Wentland 			dm_error("DC: failed to create clock sources!\n");
25247ed4e635SHarry Wentland 			BREAK_TO_DEBUGGER();
25257ed4e635SHarry Wentland 			goto create_fail;
25267ed4e635SHarry Wentland 		}
25277ed4e635SHarry Wentland 	}
25287ed4e635SHarry Wentland 
25297ed4e635SHarry Wentland 	pool->base.dccg = dccg2_create(ctx, &dccg_regs, &dccg_shift, &dccg_mask);
25307ed4e635SHarry Wentland 	if (pool->base.dccg == NULL) {
25317ed4e635SHarry Wentland 		dm_error("DC: failed to create dccg!\n");
25327ed4e635SHarry Wentland 		BREAK_TO_DEBUGGER();
25337ed4e635SHarry Wentland 		goto create_fail;
25347ed4e635SHarry Wentland 	}
25357ed4e635SHarry Wentland 
25367ed4e635SHarry Wentland 	pool->base.dmcu = dcn20_dmcu_create(ctx,
25377ed4e635SHarry Wentland 			&dmcu_regs,
25387ed4e635SHarry Wentland 			&dmcu_shift,
25397ed4e635SHarry Wentland 			&dmcu_mask);
25407ed4e635SHarry Wentland 	if (pool->base.dmcu == NULL) {
25417ed4e635SHarry Wentland 		dm_error("DC: failed to create dmcu!\n");
25427ed4e635SHarry Wentland 		BREAK_TO_DEBUGGER();
25437ed4e635SHarry Wentland 		goto create_fail;
25447ed4e635SHarry Wentland 	}
25457ed4e635SHarry Wentland 
2546d7c29549SJosip Pavic 	pool->base.abm = dce_abm_create(ctx,
25477ed4e635SHarry Wentland 			&abm_regs,
25487ed4e635SHarry Wentland 			&abm_shift,
25497ed4e635SHarry Wentland 			&abm_mask);
25507ed4e635SHarry Wentland 	if (pool->base.abm == NULL) {
25517ed4e635SHarry Wentland 		dm_error("DC: failed to create abm!\n");
25527ed4e635SHarry Wentland 		BREAK_TO_DEBUGGER();
25537ed4e635SHarry Wentland 		goto create_fail;
2554d7c29549SJosip Pavic 	}
25557ed4e635SHarry Wentland 
25567ed4e635SHarry Wentland 	pool->base.pp_smu = dcn20_pp_smu_create(ctx);
25577ed4e635SHarry Wentland 
25587ed4e635SHarry Wentland 
25597ed4e635SHarry Wentland 	if (!init_soc_bounding_box(dc, pool)) {
25607ed4e635SHarry Wentland 		dm_error("DC: failed to initialize soc bounding box!\n");
25617ed4e635SHarry Wentland 		BREAK_TO_DEBUGGER();
25627ed4e635SHarry Wentland 		goto create_fail;
25637ed4e635SHarry Wentland 	}
25647ed4e635SHarry Wentland 
2565675a9e38SLeo Li 	dml_init_instance(&dc->dml, loaded_bb, loaded_ip, dml_project_version);
25667ed4e635SHarry Wentland 
25677ed4e635SHarry Wentland 	if (!dc->debug.disable_pplib_wm_range) {
25687ed4e635SHarry Wentland 		struct pp_smu_wm_range_sets ranges = {0};
25697ed4e635SHarry Wentland 		int i = 0;
25707ed4e635SHarry Wentland 
25717ed4e635SHarry Wentland 		ranges.num_reader_wm_sets = 0;
25727ed4e635SHarry Wentland 
2573675a9e38SLeo Li 		if (loaded_bb->num_states == 1) {
25747ed4e635SHarry Wentland 			ranges.reader_wm_sets[0].wm_inst = i;
25757ed4e635SHarry Wentland 			ranges.reader_wm_sets[0].min_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN;
25767ed4e635SHarry Wentland 			ranges.reader_wm_sets[0].max_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX;
25777ed4e635SHarry Wentland 			ranges.reader_wm_sets[0].min_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN;
25787ed4e635SHarry Wentland 			ranges.reader_wm_sets[0].max_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX;
25797ed4e635SHarry Wentland 
25807ed4e635SHarry Wentland 			ranges.num_reader_wm_sets = 1;
2581675a9e38SLeo Li 		} else if (loaded_bb->num_states > 1) {
2582675a9e38SLeo Li 			for (i = 0; i < 4 && i < loaded_bb->num_states; i++) {
25837ed4e635SHarry Wentland 				ranges.reader_wm_sets[i].wm_inst = i;
25847ed4e635SHarry Wentland 				ranges.reader_wm_sets[i].min_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN;
25857ed4e635SHarry Wentland 				ranges.reader_wm_sets[i].max_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX;
2586cf689e86SMelissa Wen 				DC_FP_START();
2587cf689e86SMelissa Wen 				dcn20_fpu_set_wm_ranges(i, &ranges, loaded_bb);
2588cf689e86SMelissa Wen 				DC_FP_END();
25897ed4e635SHarry Wentland 
25907ed4e635SHarry Wentland 				ranges.num_reader_wm_sets = i + 1;
25917ed4e635SHarry Wentland 			}
25927ed4e635SHarry Wentland 
25937ed4e635SHarry Wentland 			ranges.reader_wm_sets[0].min_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN;
25947ed4e635SHarry Wentland 			ranges.reader_wm_sets[ranges.num_reader_wm_sets - 1].max_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX;
25955d36f783SJun Lei 		}
25967ed4e635SHarry Wentland 
25977ed4e635SHarry Wentland 		ranges.num_writer_wm_sets = 1;
25987ed4e635SHarry Wentland 
25997ed4e635SHarry Wentland 		ranges.writer_wm_sets[0].wm_inst = 0;
26007ed4e635SHarry Wentland 		ranges.writer_wm_sets[0].min_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN;
26017ed4e635SHarry Wentland 		ranges.writer_wm_sets[0].max_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX;
26027ed4e635SHarry Wentland 		ranges.writer_wm_sets[0].min_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN;
26037ed4e635SHarry Wentland 		ranges.writer_wm_sets[0].max_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX;
26047ed4e635SHarry Wentland 
26057ed4e635SHarry Wentland 		/* Notify PP Lib/SMU which Watermarks to use for which clock ranges */
26060fd14606SAlex Hung 		if (pool->base.pp_smu && pool->base.pp_smu->nv_funcs.set_wm_ranges)
26077ed4e635SHarry Wentland 			pool->base.pp_smu->nv_funcs.set_wm_ranges(&pool->base.pp_smu->nv_funcs.pp_smu, &ranges);
26087ed4e635SHarry Wentland 	}
26097ed4e635SHarry Wentland 
26107ed4e635SHarry Wentland 	init_data.ctx = dc->ctx;
26117ed4e635SHarry Wentland 	pool->base.irqs = dal_irq_service_dcn20_create(&init_data);
26127ed4e635SHarry Wentland 	if (!pool->base.irqs)
26137ed4e635SHarry Wentland 		goto create_fail;
26147ed4e635SHarry Wentland 
26157ed4e635SHarry Wentland 	/* mem input -> ipp -> dpp -> opp -> TG */
26167ed4e635SHarry Wentland 	for (i = 0; i < pool->base.pipe_count; i++) {
26177ed4e635SHarry Wentland 		pool->base.hubps[i] = dcn20_hubp_create(ctx, i);
26187ed4e635SHarry Wentland 		if (pool->base.hubps[i] == NULL) {
26197ed4e635SHarry Wentland 			BREAK_TO_DEBUGGER();
26207ed4e635SHarry Wentland 			dm_error(
26217ed4e635SHarry Wentland 				"DC: failed to create memory input!\n");
26227ed4e635SHarry Wentland 			goto create_fail;
26237ed4e635SHarry Wentland 		}
26247ed4e635SHarry Wentland 
26257ed4e635SHarry Wentland 		pool->base.ipps[i] = dcn20_ipp_create(ctx, i);
26267ed4e635SHarry Wentland 		if (pool->base.ipps[i] == NULL) {
26277ed4e635SHarry Wentland 			BREAK_TO_DEBUGGER();
26287ed4e635SHarry Wentland 			dm_error(
26297ed4e635SHarry Wentland 				"DC: failed to create input pixel processor!\n");
26307ed4e635SHarry Wentland 			goto create_fail;
26317ed4e635SHarry Wentland 		}
26327ed4e635SHarry Wentland 
26337ed4e635SHarry Wentland 		pool->base.dpps[i] = dcn20_dpp_create(ctx, i);
26347ed4e635SHarry Wentland 		if (pool->base.dpps[i] == NULL) {
26357ed4e635SHarry Wentland 			BREAK_TO_DEBUGGER();
26367ed4e635SHarry Wentland 			dm_error(
26377ed4e635SHarry Wentland 				"DC: failed to create dpps!\n");
26387ed4e635SHarry Wentland 			goto create_fail;
26397ed4e635SHarry Wentland 		}
26407ed4e635SHarry Wentland 	}
26417ed4e635SHarry Wentland 	for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
26427ed4e635SHarry Wentland 		pool->base.engines[i] = dcn20_aux_engine_create(ctx, i);
26437ed4e635SHarry Wentland 		if (pool->base.engines[i] == NULL) {
26447ed4e635SHarry Wentland 			BREAK_TO_DEBUGGER();
26457ed4e635SHarry Wentland 			dm_error(
26467ed4e635SHarry Wentland 				"DC:failed to create aux engine!!\n");
26477ed4e635SHarry Wentland 			goto create_fail;
26487ed4e635SHarry Wentland 		}
26497ed4e635SHarry Wentland 		pool->base.hw_i2cs[i] = dcn20_i2c_hw_create(ctx, i);
26507ed4e635SHarry Wentland 		if (pool->base.hw_i2cs[i] == NULL) {
26517ed4e635SHarry Wentland 			BREAK_TO_DEBUGGER();
26527ed4e635SHarry Wentland 			dm_error(
26537ed4e635SHarry Wentland 				"DC:failed to create hw i2c!!\n");
26547ed4e635SHarry Wentland 			goto create_fail;
26557ed4e635SHarry Wentland 		}
26567ed4e635SHarry Wentland 		pool->base.sw_i2cs[i] = NULL;
26577ed4e635SHarry Wentland 	}
26587ed4e635SHarry Wentland 
26597ed4e635SHarry Wentland 	for (i = 0; i < pool->base.res_cap->num_opp; i++) {
26607ed4e635SHarry Wentland 		pool->base.opps[i] = dcn20_opp_create(ctx, i);
26617ed4e635SHarry Wentland 		if (pool->base.opps[i] == NULL) {
26627ed4e635SHarry Wentland 			BREAK_TO_DEBUGGER();
26637ed4e635SHarry Wentland 			dm_error(
26647ed4e635SHarry Wentland 				"DC: failed to create output pixel processor!\n");
26657ed4e635SHarry Wentland 			goto create_fail;
26667ed4e635SHarry Wentland 		}
26677ed4e635SHarry Wentland 	}
26687ed4e635SHarry Wentland 
26697ed4e635SHarry Wentland 	for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) {
26707ed4e635SHarry Wentland 		pool->base.timing_generators[i] = dcn20_timing_generator_create(
26717ed4e635SHarry Wentland 				ctx, i);
26727ed4e635SHarry Wentland 		if (pool->base.timing_generators[i] == NULL) {
26737ed4e635SHarry Wentland 			BREAK_TO_DEBUGGER();
26747ed4e635SHarry Wentland 			dm_error("DC: failed to create tg!\n");
26757ed4e635SHarry Wentland 			goto create_fail;
26767ed4e635SHarry Wentland 		}
26777ed4e635SHarry Wentland 	}
26787ed4e635SHarry Wentland 
26797ed4e635SHarry Wentland 	pool->base.timing_generator_count = i;
26807ed4e635SHarry Wentland 
26817ed4e635SHarry Wentland 	pool->base.mpc = dcn20_mpc_create(ctx);
26827ed4e635SHarry Wentland 	if (pool->base.mpc == NULL) {
26837ed4e635SHarry Wentland 		BREAK_TO_DEBUGGER();
26847ed4e635SHarry Wentland 		dm_error("DC: failed to create mpc!\n");
26857ed4e635SHarry Wentland 		goto create_fail;
26867ed4e635SHarry Wentland 	}
26877ed4e635SHarry Wentland 
26887ed4e635SHarry Wentland 	pool->base.hubbub = dcn20_hubbub_create(ctx);
26897ed4e635SHarry Wentland 	if (pool->base.hubbub == NULL) {
26907ed4e635SHarry Wentland 		BREAK_TO_DEBUGGER();
26917ed4e635SHarry Wentland 		dm_error("DC: failed to create hubbub!\n");
26927ed4e635SHarry Wentland 		goto create_fail;
26937ed4e635SHarry Wentland 	}
26947ed4e635SHarry Wentland 
269597bda032SHarry Wentland 	for (i = 0; i < pool->base.res_cap->num_dsc; i++) {
269697bda032SHarry Wentland 		pool->base.dscs[i] = dcn20_dsc_create(ctx, i);
269797bda032SHarry Wentland 		if (pool->base.dscs[i] == NULL) {
269897bda032SHarry Wentland 			BREAK_TO_DEBUGGER();
269997bda032SHarry Wentland 			dm_error("DC: failed to create display stream compressor %d!\n", i);
270097bda032SHarry Wentland 			goto create_fail;
270197bda032SHarry Wentland 		}
270297bda032SHarry Wentland 	}
27037ed4e635SHarry Wentland 
2704bb21290fSCharlene Liu 	if (!dcn20_dwbc_create(ctx, &pool->base)) {
2705bb21290fSCharlene Liu 		BREAK_TO_DEBUGGER();
2706bb21290fSCharlene Liu 		dm_error("DC: failed to create dwbc!\n");
2707bb21290fSCharlene Liu 		goto create_fail;
2708bb21290fSCharlene Liu 	}
2709bb21290fSCharlene Liu 	if (!dcn20_mmhubbub_create(ctx, &pool->base)) {
2710bb21290fSCharlene Liu 		BREAK_TO_DEBUGGER();
2711bb21290fSCharlene Liu 		dm_error("DC: failed to create mcif_wb!\n");
2712bb21290fSCharlene Liu 		goto create_fail;
2713bb21290fSCharlene Liu 	}
2714bb21290fSCharlene Liu 
27157ed4e635SHarry Wentland 	if (!resource_construct(num_virtual_links, dc, &pool->base,
271625879d7bSQingqing Zhuo 			&res_create_funcs))
27177ed4e635SHarry Wentland 		goto create_fail;
27187ed4e635SHarry Wentland 
27197ed4e635SHarry Wentland 	dcn20_hw_sequencer_construct(dc);
27207ed4e635SHarry Wentland 
27213c9de4daSAlvin Lee 	// IF NV12, set PG function pointer to NULL. It's not that
27223c9de4daSAlvin Lee 	// PG isn't supported for NV12, it's that we don't want to
27233c9de4daSAlvin Lee 	// program the registers because that will cause more power
27243c9de4daSAlvin Lee 	// to be consumed. We could have created dcn20_init_hw to get
27253c9de4daSAlvin Lee 	// the same effect by checking ASIC rev, but there was a
27263c9de4daSAlvin Lee 	// request at some point to not check ASIC rev on hw sequencer.
272715ce104cSAlvin Lee 	if (ASICREV_IS_NAVI12_P(dc->ctx->asic_id.hw_internal_rev)) {
27283c9de4daSAlvin Lee 		dc->hwseq->funcs.enable_power_gating_plane = NULL;
272915ce104cSAlvin Lee 		dc->debug.disable_dpp_power_gate = true;
273015ce104cSAlvin Lee 		dc->debug.disable_hubp_power_gate = true;
273115ce104cSAlvin Lee 	}
273215ce104cSAlvin Lee 
27333c9de4daSAlvin Lee 
27347ed4e635SHarry Wentland 	dc->caps.max_planes =  pool->base.pipe_count;
27357ed4e635SHarry Wentland 
27367ed4e635SHarry Wentland 	for (i = 0; i < dc->caps.max_planes; ++i)
27377ed4e635SHarry Wentland 		dc->caps.planes[i] = plane_cap;
27387ed4e635SHarry Wentland 
27397ed4e635SHarry Wentland 	dc->caps.max_odm_combine_factor = 2;
27407ed4e635SHarry Wentland 
2741d9a07577SJun Lei 	dc->cap_funcs = cap_funcs;
2742d9a07577SJun Lei 
2743d9a07577SJun Lei 	if (dc->ctx->dc_bios->fw_info.oem_i2c_present) {
2744d9a07577SJun Lei 		ddc_init_data.ctx = dc->ctx;
2745d9a07577SJun Lei 		ddc_init_data.link = NULL;
2746d9a07577SJun Lei 		ddc_init_data.id.id = dc->ctx->dc_bios->fw_info.oem_i2c_obj_id;
274798ce7d32SWenjing Liu 		ddc_init_data.id.enum_id = 0;
2748d9a07577SJun Lei 		ddc_init_data.id.type = OBJECT_TYPE_GENERIC;
2749d9a07577SJun Lei 		pool->base.oem_device = dc->link_srv->create_ddc_service(&ddc_init_data);
2750d9a07577SJun Lei 	} else {
2751d9a07577SJun Lei 		pool->base.oem_device = NULL;
27527ed4e635SHarry Wentland 	}
27537ed4e635SHarry Wentland 
27547ed4e635SHarry Wentland 	return true;
27557ed4e635SHarry Wentland 
2756d9e32672SAnthony Koo create_fail:
27577ed4e635SHarry Wentland 
27587ed4e635SHarry Wentland 	dcn20_resource_destruct(pool);
27597ed4e635SHarry Wentland 
27607ed4e635SHarry Wentland 	return false;
27617ed4e635SHarry Wentland }
27627ed4e635SHarry Wentland 
dcn20_create_resource_pool(const struct dc_init_data * init_data,struct dc * dc)27637ed4e635SHarry Wentland struct resource_pool *dcn20_create_resource_pool(
27647ed4e635SHarry Wentland 		const struct dc_init_data *init_data,
27657ed4e635SHarry Wentland 		struct dc *dc)
27663bb11050SNirmoy Das {
27677ed4e635SHarry Wentland 	struct dcn20_resource_pool *pool =
27687ed4e635SHarry Wentland 		kzalloc(sizeof(struct dcn20_resource_pool), GFP_ATOMIC);
27697ed4e635SHarry Wentland 
27707ed4e635SHarry Wentland 	if (!pool)
2771d9e32672SAnthony Koo 		return NULL;
27727ed4e635SHarry Wentland 
27737ed4e635SHarry Wentland 	if (dcn20_resource_construct(init_data->num_virtual_links, dc, pool))
27747ed4e635SHarry Wentland 		return &pool->base;
27757ed4e635SHarry Wentland 
27767ed4e635SHarry Wentland 	BREAK_TO_DEBUGGER();
27777ed4e635SHarry Wentland 	kfree(pool);
2778 	return NULL;
2779 }
2780