Back to home page

OSCL-LXR

 
 

    


0001 /*
0002 * Copyright 2018 Advanced Micro Devices, Inc.
0003  * Copyright 2019 Raptor Engineering, LLC
0004  *
0005  * Permission is hereby granted, free of charge, to any person obtaining a
0006  * copy of this software and associated documentation files (the "Software"),
0007  * to deal in the Software without restriction, including without limitation
0008  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0009  * and/or sell copies of the Software, and to permit persons to whom the
0010  * Software is furnished to do so, subject to the following conditions:
0011  *
0012  * The above copyright notice and this permission notice shall be included in
0013  * all copies or substantial portions of the Software.
0014  *
0015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0016  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0017  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0018  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0019  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0020  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0021  * OTHER DEALINGS IN THE SOFTWARE.
0022  *
0023  * Authors: AMD
0024  *
0025  */
0026 
0027 #include <linux/slab.h>
0028 
0029 #include "dm_services.h"
0030 #include "dc.h"
0031 
0032 #include "dcn21_init.h"
0033 
0034 #include "resource.h"
0035 #include "include/irq_service_interface.h"
0036 #include "dcn20/dcn20_resource.h"
0037 #include "dcn21/dcn21_resource.h"
0038 
0039 #include "dml/dcn20/dcn20_fpu.h"
0040 
0041 #include "clk_mgr.h"
0042 #include "dcn10/dcn10_hubp.h"
0043 #include "dcn10/dcn10_ipp.h"
0044 #include "dcn20/dcn20_hubbub.h"
0045 #include "dcn20/dcn20_mpc.h"
0046 #include "dcn20/dcn20_hubp.h"
0047 #include "dcn21_hubp.h"
0048 #include "irq/dcn21/irq_service_dcn21.h"
0049 #include "dcn20/dcn20_dpp.h"
0050 #include "dcn20/dcn20_optc.h"
0051 #include "dcn21/dcn21_hwseq.h"
0052 #include "dce110/dce110_hw_sequencer.h"
0053 #include "dcn20/dcn20_opp.h"
0054 #include "dcn20/dcn20_dsc.h"
0055 #include "dcn21/dcn21_link_encoder.h"
0056 #include "dcn20/dcn20_stream_encoder.h"
0057 #include "dce/dce_clock_source.h"
0058 #include "dce/dce_audio.h"
0059 #include "dce/dce_hwseq.h"
0060 #include "virtual/virtual_stream_encoder.h"
0061 #include "dml/display_mode_vba.h"
0062 #include "dcn20/dcn20_dccg.h"
0063 #include "dcn21/dcn21_dccg.h"
0064 #include "dcn21_hubbub.h"
0065 #include "dcn10/dcn10_resource.h"
0066 #include "dce/dce_panel_cntl.h"
0067 
0068 #include "dcn20/dcn20_dwb.h"
0069 #include "dcn20/dcn20_mmhubbub.h"
0070 #include "dpcs/dpcs_2_1_0_offset.h"
0071 #include "dpcs/dpcs_2_1_0_sh_mask.h"
0072 
0073 #include "renoir_ip_offset.h"
0074 #include "dcn/dcn_2_1_0_offset.h"
0075 #include "dcn/dcn_2_1_0_sh_mask.h"
0076 
0077 #include "nbio/nbio_7_0_offset.h"
0078 
0079 #include "mmhub/mmhub_2_0_0_offset.h"
0080 #include "mmhub/mmhub_2_0_0_sh_mask.h"
0081 
0082 #include "reg_helper.h"
0083 #include "dce/dce_abm.h"
0084 #include "dce/dce_dmcu.h"
0085 #include "dce/dce_aux.h"
0086 #include "dce/dce_i2c.h"
0087 #include "dcn21_resource.h"
0088 #include "vm_helper.h"
0089 #include "dcn20/dcn20_vmid.h"
0090 #include "dce/dmub_psr.h"
0091 #include "dce/dmub_abm.h"
0092 
0093 /* begin *********************
0094  * macros to expend register list macro defined in HW object header file */
0095 
0096 /* DCN */
0097 /* TODO awful hack. fixup dcn20_dwb.h */
0098 #undef BASE_INNER
0099 #define BASE_INNER(seg) DMU_BASE__INST0_SEG ## seg
0100 
0101 #define BASE(seg) BASE_INNER(seg)
0102 
0103 #define SR(reg_name)\
0104         .reg_name = BASE(mm ## reg_name ## _BASE_IDX) +  \
0105                     mm ## reg_name
0106 
0107 #define SRI(reg_name, block, id)\
0108     .reg_name = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
0109                     mm ## block ## id ## _ ## reg_name
0110 
0111 #define SRIR(var_name, reg_name, block, id)\
0112     .var_name = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
0113                     mm ## block ## id ## _ ## reg_name
0114 
0115 #define SRII(reg_name, block, id)\
0116     .reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
0117                     mm ## block ## id ## _ ## reg_name
0118 
0119 #define DCCG_SRII(reg_name, block, id)\
0120     .block ## _ ## reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
0121                     mm ## block ## id ## _ ## reg_name
0122 
0123 #define VUPDATE_SRII(reg_name, block, id)\
0124     .reg_name[id] = BASE(mm ## reg_name ## _ ## block ## id ## _BASE_IDX) + \
0125                     mm ## reg_name ## _ ## block ## id
0126 
0127 /* NBIO */
0128 #define NBIO_BASE_INNER(seg) \
0129     NBIF0_BASE__INST0_SEG ## seg
0130 
0131 #define NBIO_BASE(seg) \
0132     NBIO_BASE_INNER(seg)
0133 
0134 #define NBIO_SR(reg_name)\
0135         .reg_name = NBIO_BASE(mm ## reg_name ## _BASE_IDX) + \
0136                     mm ## reg_name
0137 
0138 /* MMHUB */
0139 #define MMHUB_BASE_INNER(seg) \
0140     MMHUB_BASE__INST0_SEG ## seg
0141 
0142 #define MMHUB_BASE(seg) \
0143     MMHUB_BASE_INNER(seg)
0144 
0145 #define MMHUB_SR(reg_name)\
0146         .reg_name = MMHUB_BASE(mmMM ## reg_name ## _BASE_IDX) + \
0147                     mmMM ## reg_name
0148 
0149 #define clk_src_regs(index, pllid)\
0150 [index] = {\
0151     CS_COMMON_REG_LIST_DCN2_1(index, pllid),\
0152 }
0153 
0154 static const struct dce110_clk_src_regs clk_src_regs[] = {
0155     clk_src_regs(0, A),
0156     clk_src_regs(1, B),
0157     clk_src_regs(2, C),
0158     clk_src_regs(3, D),
0159     clk_src_regs(4, E),
0160 };
0161 
0162 static const struct dce110_clk_src_shift cs_shift = {
0163         CS_COMMON_MASK_SH_LIST_DCN2_0(__SHIFT)
0164 };
0165 
0166 static const struct dce110_clk_src_mask cs_mask = {
0167         CS_COMMON_MASK_SH_LIST_DCN2_0(_MASK)
0168 };
0169 
0170 static const struct bios_registers bios_regs = {
0171         NBIO_SR(BIOS_SCRATCH_3),
0172         NBIO_SR(BIOS_SCRATCH_6)
0173 };
0174 
0175 static const struct dce_dmcu_registers dmcu_regs = {
0176         DMCU_DCN20_REG_LIST()
0177 };
0178 
0179 static const struct dce_dmcu_shift dmcu_shift = {
0180         DMCU_MASK_SH_LIST_DCN10(__SHIFT)
0181 };
0182 
0183 static const struct dce_dmcu_mask dmcu_mask = {
0184         DMCU_MASK_SH_LIST_DCN10(_MASK)
0185 };
0186 
0187 static const struct dce_abm_registers abm_regs = {
0188         ABM_DCN20_REG_LIST()
0189 };
0190 
0191 static const struct dce_abm_shift abm_shift = {
0192         ABM_MASK_SH_LIST_DCN20(__SHIFT)
0193 };
0194 
0195 static const struct dce_abm_mask abm_mask = {
0196         ABM_MASK_SH_LIST_DCN20(_MASK)
0197 };
0198 
0199 #define audio_regs(id)\
0200 [id] = {\
0201         AUD_COMMON_REG_LIST(id)\
0202 }
0203 
0204 static const struct dce_audio_registers audio_regs[] = {
0205     audio_regs(0),
0206     audio_regs(1),
0207     audio_regs(2),
0208     audio_regs(3),
0209     audio_regs(4),
0210     audio_regs(5),
0211 };
0212 
0213 #define DCE120_AUD_COMMON_MASK_SH_LIST(mask_sh)\
0214         SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_INDEX, AZALIA_ENDPOINT_REG_INDEX, mask_sh),\
0215         SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_DATA, AZALIA_ENDPOINT_REG_DATA, mask_sh),\
0216         AUD_COMMON_MASK_SH_LIST_BASE(mask_sh)
0217 
0218 static const struct dce_audio_shift audio_shift = {
0219         DCE120_AUD_COMMON_MASK_SH_LIST(__SHIFT)
0220 };
0221 
0222 static const struct dce_audio_mask audio_mask = {
0223         DCE120_AUD_COMMON_MASK_SH_LIST(_MASK)
0224 };
0225 
0226 static const struct dccg_registers dccg_regs = {
0227         DCCG_COMMON_REG_LIST_DCN_BASE()
0228 };
0229 
0230 static const struct dccg_shift dccg_shift = {
0231         DCCG_MASK_SH_LIST_DCN2_1(__SHIFT)
0232 };
0233 
0234 static const struct dccg_mask dccg_mask = {
0235         DCCG_MASK_SH_LIST_DCN2_1(_MASK)
0236 };
0237 
0238 #define opp_regs(id)\
0239 [id] = {\
0240     OPP_REG_LIST_DCN20(id),\
0241 }
0242 
0243 static const struct dcn20_opp_registers opp_regs[] = {
0244     opp_regs(0),
0245     opp_regs(1),
0246     opp_regs(2),
0247     opp_regs(3),
0248     opp_regs(4),
0249     opp_regs(5),
0250 };
0251 
0252 static const struct dcn20_opp_shift opp_shift = {
0253         OPP_MASK_SH_LIST_DCN20(__SHIFT)
0254 };
0255 
0256 static const struct dcn20_opp_mask opp_mask = {
0257         OPP_MASK_SH_LIST_DCN20(_MASK)
0258 };
0259 
0260 #define tg_regs(id)\
0261 [id] = {TG_COMMON_REG_LIST_DCN2_0(id)}
0262 
0263 static const struct dcn_optc_registers tg_regs[] = {
0264     tg_regs(0),
0265     tg_regs(1),
0266     tg_regs(2),
0267     tg_regs(3)
0268 };
0269 
0270 static const struct dcn_optc_shift tg_shift = {
0271     TG_COMMON_MASK_SH_LIST_DCN2_0(__SHIFT)
0272 };
0273 
0274 static const struct dcn_optc_mask tg_mask = {
0275     TG_COMMON_MASK_SH_LIST_DCN2_0(_MASK)
0276 };
0277 
0278 static const struct dcn20_mpc_registers mpc_regs = {
0279         MPC_REG_LIST_DCN2_0(0),
0280         MPC_REG_LIST_DCN2_0(1),
0281         MPC_REG_LIST_DCN2_0(2),
0282         MPC_REG_LIST_DCN2_0(3),
0283         MPC_REG_LIST_DCN2_0(4),
0284         MPC_REG_LIST_DCN2_0(5),
0285         MPC_OUT_MUX_REG_LIST_DCN2_0(0),
0286         MPC_OUT_MUX_REG_LIST_DCN2_0(1),
0287         MPC_OUT_MUX_REG_LIST_DCN2_0(2),
0288         MPC_OUT_MUX_REG_LIST_DCN2_0(3),
0289         MPC_DBG_REG_LIST_DCN2_0()
0290 };
0291 
0292 static const struct dcn20_mpc_shift mpc_shift = {
0293     MPC_COMMON_MASK_SH_LIST_DCN2_0(__SHIFT),
0294     MPC_DEBUG_REG_LIST_SH_DCN20
0295 };
0296 
0297 static const struct dcn20_mpc_mask mpc_mask = {
0298     MPC_COMMON_MASK_SH_LIST_DCN2_0(_MASK),
0299     MPC_DEBUG_REG_LIST_MASK_DCN20
0300 };
0301 
0302 #define hubp_regs(id)\
0303 [id] = {\
0304     HUBP_REG_LIST_DCN21(id)\
0305 }
0306 
0307 static const struct dcn_hubp2_registers hubp_regs[] = {
0308         hubp_regs(0),
0309         hubp_regs(1),
0310         hubp_regs(2),
0311         hubp_regs(3)
0312 };
0313 
0314 static const struct dcn_hubp2_shift hubp_shift = {
0315         HUBP_MASK_SH_LIST_DCN21(__SHIFT)
0316 };
0317 
0318 static const struct dcn_hubp2_mask hubp_mask = {
0319         HUBP_MASK_SH_LIST_DCN21(_MASK)
0320 };
0321 
0322 static const struct dcn_hubbub_registers hubbub_reg = {
0323         HUBBUB_REG_LIST_DCN21()
0324 };
0325 
0326 static const struct dcn_hubbub_shift hubbub_shift = {
0327         HUBBUB_MASK_SH_LIST_DCN21(__SHIFT)
0328 };
0329 
0330 static const struct dcn_hubbub_mask hubbub_mask = {
0331         HUBBUB_MASK_SH_LIST_DCN21(_MASK)
0332 };
0333 
0334 
0335 #define vmid_regs(id)\
0336 [id] = {\
0337         DCN20_VMID_REG_LIST(id)\
0338 }
0339 
0340 static const struct dcn_vmid_registers vmid_regs[] = {
0341     vmid_regs(0),
0342     vmid_regs(1),
0343     vmid_regs(2),
0344     vmid_regs(3),
0345     vmid_regs(4),
0346     vmid_regs(5),
0347     vmid_regs(6),
0348     vmid_regs(7),
0349     vmid_regs(8),
0350     vmid_regs(9),
0351     vmid_regs(10),
0352     vmid_regs(11),
0353     vmid_regs(12),
0354     vmid_regs(13),
0355     vmid_regs(14),
0356     vmid_regs(15)
0357 };
0358 
0359 static const struct dcn20_vmid_shift vmid_shifts = {
0360         DCN20_VMID_MASK_SH_LIST(__SHIFT)
0361 };
0362 
0363 static const struct dcn20_vmid_mask vmid_masks = {
0364         DCN20_VMID_MASK_SH_LIST(_MASK)
0365 };
0366 
0367 #define dsc_regsDCN20(id)\
0368 [id] = {\
0369     DSC_REG_LIST_DCN20(id)\
0370 }
0371 
0372 static const struct dcn20_dsc_registers dsc_regs[] = {
0373     dsc_regsDCN20(0),
0374     dsc_regsDCN20(1),
0375     dsc_regsDCN20(2),
0376     dsc_regsDCN20(3),
0377     dsc_regsDCN20(4),
0378     dsc_regsDCN20(5)
0379 };
0380 
0381 static const struct dcn20_dsc_shift dsc_shift = {
0382     DSC_REG_LIST_SH_MASK_DCN20(__SHIFT)
0383 };
0384 
0385 static const struct dcn20_dsc_mask dsc_mask = {
0386     DSC_REG_LIST_SH_MASK_DCN20(_MASK)
0387 };
0388 
0389 #define ipp_regs(id)\
0390 [id] = {\
0391     IPP_REG_LIST_DCN20(id),\
0392 }
0393 
0394 static const struct dcn10_ipp_registers ipp_regs[] = {
0395     ipp_regs(0),
0396     ipp_regs(1),
0397     ipp_regs(2),
0398     ipp_regs(3),
0399 };
0400 
0401 static const struct dcn10_ipp_shift ipp_shift = {
0402         IPP_MASK_SH_LIST_DCN20(__SHIFT)
0403 };
0404 
0405 static const struct dcn10_ipp_mask ipp_mask = {
0406         IPP_MASK_SH_LIST_DCN20(_MASK),
0407 };
0408 
0409 #define opp_regs(id)\
0410 [id] = {\
0411     OPP_REG_LIST_DCN20(id),\
0412 }
0413 
0414 
0415 #define aux_engine_regs(id)\
0416 [id] = {\
0417     AUX_COMMON_REG_LIST0(id), \
0418     .AUXN_IMPCAL = 0, \
0419     .AUXP_IMPCAL = 0, \
0420     .AUX_RESET_MASK = DP_AUX0_AUX_CONTROL__AUX_RESET_MASK, \
0421 }
0422 
0423 static const struct dce110_aux_registers aux_engine_regs[] = {
0424         aux_engine_regs(0),
0425         aux_engine_regs(1),
0426         aux_engine_regs(2),
0427         aux_engine_regs(3),
0428         aux_engine_regs(4),
0429 };
0430 
0431 #define tf_regs(id)\
0432 [id] = {\
0433     TF_REG_LIST_DCN20(id),\
0434     TF_REG_LIST_DCN20_COMMON_APPEND(id),\
0435 }
0436 
0437 static const struct dcn2_dpp_registers tf_regs[] = {
0438     tf_regs(0),
0439     tf_regs(1),
0440     tf_regs(2),
0441     tf_regs(3),
0442 };
0443 
0444 static const struct dcn2_dpp_shift tf_shift = {
0445         TF_REG_LIST_SH_MASK_DCN20(__SHIFT),
0446         TF_DEBUG_REG_LIST_SH_DCN20
0447 };
0448 
0449 static const struct dcn2_dpp_mask tf_mask = {
0450         TF_REG_LIST_SH_MASK_DCN20(_MASK),
0451         TF_DEBUG_REG_LIST_MASK_DCN20
0452 };
0453 
0454 #define stream_enc_regs(id)\
0455 [id] = {\
0456     SE_DCN2_REG_LIST(id)\
0457 }
0458 
0459 static const struct dcn10_stream_enc_registers stream_enc_regs[] = {
0460     stream_enc_regs(0),
0461     stream_enc_regs(1),
0462     stream_enc_regs(2),
0463     stream_enc_regs(3),
0464     stream_enc_regs(4),
0465 };
0466 
0467 static const struct dce110_aux_registers_shift aux_shift = {
0468     DCN_AUX_MASK_SH_LIST(__SHIFT)
0469 };
0470 
0471 static const struct dce110_aux_registers_mask aux_mask = {
0472     DCN_AUX_MASK_SH_LIST(_MASK)
0473 };
0474 
0475 static const struct dcn10_stream_encoder_shift se_shift = {
0476         SE_COMMON_MASK_SH_LIST_DCN20(__SHIFT)
0477 };
0478 
0479 static const struct dcn10_stream_encoder_mask se_mask = {
0480         SE_COMMON_MASK_SH_LIST_DCN20(_MASK)
0481 };
0482 
0483 static void dcn21_pp_smu_destroy(struct pp_smu_funcs **pp_smu);
0484 
0485 static struct input_pixel_processor *dcn21_ipp_create(
0486     struct dc_context *ctx, uint32_t inst)
0487 {
0488     struct dcn10_ipp *ipp =
0489         kzalloc(sizeof(struct dcn10_ipp), GFP_KERNEL);
0490 
0491     if (!ipp) {
0492         BREAK_TO_DEBUGGER();
0493         return NULL;
0494     }
0495 
0496     dcn20_ipp_construct(ipp, ctx, inst,
0497             &ipp_regs[inst], &ipp_shift, &ipp_mask);
0498     return &ipp->base;
0499 }
0500 
0501 static struct dpp *dcn21_dpp_create(
0502     struct dc_context *ctx,
0503     uint32_t inst)
0504 {
0505     struct dcn20_dpp *dpp =
0506         kzalloc(sizeof(struct dcn20_dpp), GFP_KERNEL);
0507 
0508     if (!dpp)
0509         return NULL;
0510 
0511     if (dpp2_construct(dpp, ctx, inst,
0512             &tf_regs[inst], &tf_shift, &tf_mask))
0513         return &dpp->base;
0514 
0515     BREAK_TO_DEBUGGER();
0516     kfree(dpp);
0517     return NULL;
0518 }
0519 
0520 static struct dce_aux *dcn21_aux_engine_create(
0521     struct dc_context *ctx,
0522     uint32_t inst)
0523 {
0524     struct aux_engine_dce110 *aux_engine =
0525         kzalloc(sizeof(struct aux_engine_dce110), GFP_KERNEL);
0526 
0527     if (!aux_engine)
0528         return NULL;
0529 
0530     dce110_aux_engine_construct(aux_engine, ctx, inst,
0531                     SW_AUX_TIMEOUT_PERIOD_MULTIPLIER * AUX_TIMEOUT_PERIOD,
0532                     &aux_engine_regs[inst],
0533                     &aux_mask,
0534                     &aux_shift,
0535                     ctx->dc->caps.extended_aux_timeout_support);
0536 
0537     return &aux_engine->base;
0538 }
0539 
0540 #define i2c_inst_regs(id) { I2C_HW_ENGINE_COMMON_REG_LIST(id) }
0541 
0542 static const struct dce_i2c_registers i2c_hw_regs[] = {
0543         i2c_inst_regs(1),
0544         i2c_inst_regs(2),
0545         i2c_inst_regs(3),
0546         i2c_inst_regs(4),
0547         i2c_inst_regs(5),
0548 };
0549 
0550 static const struct dce_i2c_shift i2c_shifts = {
0551         I2C_COMMON_MASK_SH_LIST_DCN2(__SHIFT)
0552 };
0553 
0554 static const struct dce_i2c_mask i2c_masks = {
0555         I2C_COMMON_MASK_SH_LIST_DCN2(_MASK)
0556 };
0557 
0558 static struct dce_i2c_hw *dcn21_i2c_hw_create(struct dc_context *ctx,
0559                           uint32_t inst)
0560 {
0561     struct dce_i2c_hw *dce_i2c_hw =
0562         kzalloc(sizeof(struct dce_i2c_hw), GFP_KERNEL);
0563 
0564     if (!dce_i2c_hw)
0565         return NULL;
0566 
0567     dcn2_i2c_hw_construct(dce_i2c_hw, ctx, inst,
0568                     &i2c_hw_regs[inst], &i2c_shifts, &i2c_masks);
0569 
0570     return dce_i2c_hw;
0571 }
0572 
0573 static const struct resource_caps res_cap_rn = {
0574         .num_timing_generator = 4,
0575         .num_opp = 4,
0576         .num_video_plane = 4,
0577         .num_audio = 4, // 4 audio endpoints.  4 audio streams
0578         .num_stream_encoder = 5,
0579         .num_pll = 5,  // maybe 3 because the last two used for USB-c
0580         .num_dwb = 1,
0581         .num_ddc = 5,
0582         .num_vmid = 16,
0583         .num_dsc = 3,
0584 };
0585 
0586 #ifdef DIAGS_BUILD
0587 static const struct resource_caps res_cap_rn_FPGA_4pipe = {
0588         .num_timing_generator = 4,
0589         .num_opp = 4,
0590         .num_video_plane = 4,
0591         .num_audio = 7,
0592         .num_stream_encoder = 4,
0593         .num_pll = 4,
0594         .num_dwb = 1,
0595         .num_ddc = 4,
0596         .num_dsc = 0,
0597 };
0598 
0599 static const struct resource_caps res_cap_rn_FPGA_2pipe_dsc = {
0600         .num_timing_generator = 2,
0601         .num_opp = 2,
0602         .num_video_plane = 2,
0603         .num_audio = 7,
0604         .num_stream_encoder = 2,
0605         .num_pll = 4,
0606         .num_dwb = 1,
0607         .num_ddc = 4,
0608         .num_dsc = 2,
0609 };
0610 #endif
0611 
0612 static const struct dc_plane_cap plane_cap = {
0613     .type = DC_PLANE_TYPE_DCN_UNIVERSAL,
0614     .blends_with_above = true,
0615     .blends_with_below = true,
0616     .per_pixel_alpha = true,
0617 
0618     .pixel_format_support = {
0619             .argb8888 = true,
0620             .nv12 = true,
0621             .fp16 = true,
0622             .p010 = true
0623     },
0624 
0625     .max_upscale_factor = {
0626             .argb8888 = 16000,
0627             .nv12 = 16000,
0628             .fp16 = 16000
0629     },
0630 
0631     .max_downscale_factor = {
0632             .argb8888 = 250,
0633             .nv12 = 250,
0634             .fp16 = 250
0635     },
0636     64,
0637     64
0638 };
0639 
0640 static const struct dc_debug_options debug_defaults_drv = {
0641         .disable_dmcu = false,
0642         .force_abm_enable = false,
0643         .timing_trace = false,
0644         .clock_trace = true,
0645         .disable_pplib_clock_request = true,
0646         .min_disp_clk_khz = 100000,
0647         .pipe_split_policy = MPC_SPLIT_AVOID_MULT_DISP,
0648         .force_single_disp_pipe_split = false,
0649         .disable_dcc = DCC_ENABLE,
0650         .vsr_support = true,
0651         .performance_trace = false,
0652         .max_downscale_src_width = 4096,
0653         .disable_pplib_wm_range = false,
0654         .scl_reset_length10 = true,
0655         .sanity_checks = true,
0656         .disable_48mhz_pwrdwn = false,
0657         .usbc_combo_phy_reset_wa = true,
0658         .dmub_command_table = true,
0659         .use_max_lb = true,
0660         .optimize_edp_link_rate = true
0661 };
0662 
0663 static const struct dc_debug_options debug_defaults_diags = {
0664         .disable_dmcu = false,
0665         .force_abm_enable = false,
0666         .timing_trace = true,
0667         .clock_trace = true,
0668         .disable_dpp_power_gate = true,
0669         .disable_hubp_power_gate = true,
0670         .disable_clock_gate = true,
0671         .disable_pplib_clock_request = true,
0672         .disable_pplib_wm_range = true,
0673         .disable_stutter = true,
0674         .disable_48mhz_pwrdwn = true,
0675         .disable_psr = true,
0676         .enable_tri_buf = true,
0677         .use_max_lb = true
0678 };
0679 
0680 enum dcn20_clk_src_array_id {
0681     DCN20_CLK_SRC_PLL0,
0682     DCN20_CLK_SRC_PLL1,
0683     DCN20_CLK_SRC_PLL2,
0684     DCN20_CLK_SRC_PLL3,
0685     DCN20_CLK_SRC_PLL4,
0686     DCN20_CLK_SRC_TOTAL_DCN21
0687 };
0688 
0689 static void dcn21_resource_destruct(struct dcn21_resource_pool *pool)
0690 {
0691     unsigned int i;
0692 
0693     for (i = 0; i < pool->base.stream_enc_count; i++) {
0694         if (pool->base.stream_enc[i] != NULL) {
0695             kfree(DCN10STRENC_FROM_STRENC(pool->base.stream_enc[i]));
0696             pool->base.stream_enc[i] = NULL;
0697         }
0698     }
0699 
0700     for (i = 0; i < pool->base.res_cap->num_dsc; i++) {
0701         if (pool->base.dscs[i] != NULL)
0702             dcn20_dsc_destroy(&pool->base.dscs[i]);
0703     }
0704 
0705     if (pool->base.mpc != NULL) {
0706         kfree(TO_DCN20_MPC(pool->base.mpc));
0707         pool->base.mpc = NULL;
0708     }
0709     if (pool->base.hubbub != NULL) {
0710         kfree(pool->base.hubbub);
0711         pool->base.hubbub = NULL;
0712     }
0713     for (i = 0; i < pool->base.pipe_count; i++) {
0714         if (pool->base.dpps[i] != NULL)
0715             dcn20_dpp_destroy(&pool->base.dpps[i]);
0716 
0717         if (pool->base.ipps[i] != NULL)
0718             pool->base.ipps[i]->funcs->ipp_destroy(&pool->base.ipps[i]);
0719 
0720         if (pool->base.hubps[i] != NULL) {
0721             kfree(TO_DCN20_HUBP(pool->base.hubps[i]));
0722             pool->base.hubps[i] = NULL;
0723         }
0724 
0725         if (pool->base.irqs != NULL) {
0726             dal_irq_service_destroy(&pool->base.irqs);
0727         }
0728     }
0729 
0730     for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
0731         if (pool->base.engines[i] != NULL)
0732             dce110_engine_destroy(&pool->base.engines[i]);
0733         if (pool->base.hw_i2cs[i] != NULL) {
0734             kfree(pool->base.hw_i2cs[i]);
0735             pool->base.hw_i2cs[i] = NULL;
0736         }
0737         if (pool->base.sw_i2cs[i] != NULL) {
0738             kfree(pool->base.sw_i2cs[i]);
0739             pool->base.sw_i2cs[i] = NULL;
0740         }
0741     }
0742 
0743     for (i = 0; i < pool->base.res_cap->num_opp; i++) {
0744         if (pool->base.opps[i] != NULL)
0745             pool->base.opps[i]->funcs->opp_destroy(&pool->base.opps[i]);
0746     }
0747 
0748     for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) {
0749         if (pool->base.timing_generators[i] != NULL)    {
0750             kfree(DCN10TG_FROM_TG(pool->base.timing_generators[i]));
0751             pool->base.timing_generators[i] = NULL;
0752         }
0753     }
0754 
0755     for (i = 0; i < pool->base.res_cap->num_dwb; i++) {
0756         if (pool->base.dwbc[i] != NULL) {
0757             kfree(TO_DCN20_DWBC(pool->base.dwbc[i]));
0758             pool->base.dwbc[i] = NULL;
0759         }
0760         if (pool->base.mcif_wb[i] != NULL) {
0761             kfree(TO_DCN20_MMHUBBUB(pool->base.mcif_wb[i]));
0762             pool->base.mcif_wb[i] = NULL;
0763         }
0764     }
0765 
0766     for (i = 0; i < pool->base.audio_count; i++) {
0767         if (pool->base.audios[i])
0768             dce_aud_destroy(&pool->base.audios[i]);
0769     }
0770 
0771     for (i = 0; i < pool->base.clk_src_count; i++) {
0772         if (pool->base.clock_sources[i] != NULL) {
0773             dcn20_clock_source_destroy(&pool->base.clock_sources[i]);
0774             pool->base.clock_sources[i] = NULL;
0775         }
0776     }
0777 
0778     if (pool->base.dp_clock_source != NULL) {
0779         dcn20_clock_source_destroy(&pool->base.dp_clock_source);
0780         pool->base.dp_clock_source = NULL;
0781     }
0782 
0783     if (pool->base.abm != NULL) {
0784         if (pool->base.abm->ctx->dc->config.disable_dmcu)
0785             dmub_abm_destroy(&pool->base.abm);
0786         else
0787             dce_abm_destroy(&pool->base.abm);
0788     }
0789 
0790     if (pool->base.dmcu != NULL)
0791         dce_dmcu_destroy(&pool->base.dmcu);
0792 
0793     if (pool->base.psr != NULL)
0794         dmub_psr_destroy(&pool->base.psr);
0795 
0796     if (pool->base.dccg != NULL)
0797         dcn_dccg_destroy(&pool->base.dccg);
0798 
0799     if (pool->base.pp_smu != NULL)
0800         dcn21_pp_smu_destroy(&pool->base.pp_smu);
0801 }
0802 
0803 bool dcn21_fast_validate_bw(struct dc *dc,
0804                 struct dc_state *context,
0805                 display_e2e_pipe_params_st *pipes,
0806                 int *pipe_cnt_out,
0807                 int *pipe_split_from,
0808                 int *vlevel_out,
0809                 bool fast_validate)
0810 {
0811     bool out = false;
0812     int split[MAX_PIPES] = { 0 };
0813     int pipe_cnt, i, pipe_idx, vlevel;
0814 
0815     ASSERT(pipes);
0816     if (!pipes)
0817         return false;
0818 
0819     dcn20_merge_pipes_for_validate(dc, context);
0820 
0821     DC_FP_START();
0822     pipe_cnt = dc->res_pool->funcs->populate_dml_pipes(dc, context, pipes, fast_validate);
0823     DC_FP_END();
0824 
0825     *pipe_cnt_out = pipe_cnt;
0826 
0827     if (!pipe_cnt) {
0828         out = true;
0829         goto validate_out;
0830     }
0831     /*
0832      * DML favors voltage over p-state, but we're more interested in
0833      * supporting p-state over voltage. We can't support p-state in
0834      * prefetch mode > 0 so try capping the prefetch mode to start.
0835      */
0836     context->bw_ctx.dml.soc.allow_dram_self_refresh_or_dram_clock_change_in_vblank =
0837                 dm_allow_self_refresh_and_mclk_switch;
0838     vlevel = dml_get_voltage_level(&context->bw_ctx.dml, pipes, pipe_cnt);
0839 
0840     if (vlevel > context->bw_ctx.dml.soc.num_states) {
0841         /*
0842          * If mode is unsupported or there's still no p-state support then
0843          * fall back to favoring voltage.
0844          *
0845          * We don't actually support prefetch mode 2, so require that we
0846          * at least support prefetch mode 1.
0847          */
0848         context->bw_ctx.dml.soc.allow_dram_self_refresh_or_dram_clock_change_in_vblank =
0849                     dm_allow_self_refresh;
0850         vlevel = dml_get_voltage_level(&context->bw_ctx.dml, pipes, pipe_cnt);
0851         if (vlevel > context->bw_ctx.dml.soc.num_states)
0852             goto validate_fail;
0853     }
0854 
0855     vlevel = dcn20_validate_apply_pipe_split_flags(dc, context, vlevel, split, NULL);
0856 
0857     for (i = 0, pipe_idx = 0; i < dc->res_pool->pipe_count; i++) {
0858         struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
0859         struct pipe_ctx *mpo_pipe = pipe->bottom_pipe;
0860         struct vba_vars_st *vba = &context->bw_ctx.dml.vba;
0861 
0862         if (!pipe->stream)
0863             continue;
0864 
0865         /* We only support full screen mpo with ODM */
0866         if (vba->ODMCombineEnabled[vba->pipe_plane[pipe_idx]] != dm_odm_combine_mode_disabled
0867                 && pipe->plane_state && mpo_pipe
0868                 && memcmp(&mpo_pipe->plane_res.scl_data.recout,
0869                         &pipe->plane_res.scl_data.recout,
0870                         sizeof(struct rect)) != 0) {
0871             ASSERT(mpo_pipe->plane_state != pipe->plane_state);
0872             goto validate_fail;
0873         }
0874         pipe_idx++;
0875     }
0876 
0877     /*initialize pipe_just_split_from to invalid idx*/
0878     for (i = 0; i < MAX_PIPES; i++)
0879         pipe_split_from[i] = -1;
0880 
0881     for (i = 0, pipe_idx = -1; i < dc->res_pool->pipe_count; i++) {
0882         struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
0883         struct pipe_ctx *hsplit_pipe = pipe->bottom_pipe;
0884 
0885         if (!pipe->stream || pipe_split_from[i] >= 0)
0886             continue;
0887 
0888         pipe_idx++;
0889 
0890         if (!pipe->top_pipe && !pipe->plane_state && context->bw_ctx.dml.vba.ODMCombineEnabled[pipe_idx]) {
0891             hsplit_pipe = dcn20_find_secondary_pipe(dc, &context->res_ctx, dc->res_pool, pipe);
0892             ASSERT(hsplit_pipe);
0893             if (!dcn20_split_stream_for_odm(
0894                     dc, &context->res_ctx,
0895                     pipe, hsplit_pipe))
0896                 goto validate_fail;
0897             pipe_split_from[hsplit_pipe->pipe_idx] = pipe_idx;
0898             dcn20_build_mapped_resource(dc, context, pipe->stream);
0899         }
0900 
0901         if (!pipe->plane_state)
0902             continue;
0903         /* Skip 2nd half of already split pipe */
0904         if (pipe->top_pipe && pipe->plane_state == pipe->top_pipe->plane_state)
0905             continue;
0906 
0907         if (split[i] == 2) {
0908             if (!hsplit_pipe || hsplit_pipe->plane_state != pipe->plane_state) {
0909                 /* pipe not split previously needs split */
0910                 hsplit_pipe = dcn20_find_secondary_pipe(dc, &context->res_ctx, dc->res_pool, pipe);
0911                 ASSERT(hsplit_pipe);
0912                 if (!hsplit_pipe) {
0913                     DC_FP_START();
0914                     dcn20_fpu_adjust_dppclk(&context->bw_ctx.dml.vba, vlevel, context->bw_ctx.dml.vba.maxMpcComb, pipe_idx, true);
0915                     DC_FP_END();
0916                     continue;
0917                 }
0918                 if (context->bw_ctx.dml.vba.ODMCombineEnabled[pipe_idx]) {
0919                     if (!dcn20_split_stream_for_odm(
0920                             dc, &context->res_ctx,
0921                             pipe, hsplit_pipe))
0922                         goto validate_fail;
0923                     dcn20_build_mapped_resource(dc, context, pipe->stream);
0924                 } else {
0925                     dcn20_split_stream_for_mpc(
0926                             &context->res_ctx, dc->res_pool,
0927                             pipe, hsplit_pipe);
0928                     resource_build_scaling_params(pipe);
0929                     resource_build_scaling_params(hsplit_pipe);
0930                 }
0931                 pipe_split_from[hsplit_pipe->pipe_idx] = pipe_idx;
0932             }
0933         } else if (hsplit_pipe && hsplit_pipe->plane_state == pipe->plane_state) {
0934             /* merge should already have been done */
0935             ASSERT(0);
0936         }
0937     }
0938     /* Actual dsc count per stream dsc validation*/
0939     if (!dcn20_validate_dsc(dc, context)) {
0940         context->bw_ctx.dml.vba.ValidationStatus[context->bw_ctx.dml.vba.soc.num_states] =
0941                 DML_FAIL_DSC_VALIDATION_FAILURE;
0942         goto validate_fail;
0943     }
0944 
0945     *vlevel_out = vlevel;
0946 
0947     out = true;
0948     goto validate_out;
0949 
0950 validate_fail:
0951     out = false;
0952 
0953 validate_out:
0954     return out;
0955 }
0956 
0957 /*
0958  * Some of the functions further below use the FPU, so we need to wrap this
0959  * with DC_FP_START()/DC_FP_END(). Use the same approach as for
0960  * dcn20_validate_bandwidth in dcn20_resource.c.
0961  */
0962 static bool dcn21_validate_bandwidth(struct dc *dc, struct dc_state *context,
0963         bool fast_validate)
0964 {
0965     bool voltage_supported;
0966     DC_FP_START();
0967     voltage_supported = dcn21_validate_bandwidth_fp(dc, context, fast_validate);
0968     DC_FP_END();
0969     return voltage_supported;
0970 }
0971 
0972 static void dcn21_destroy_resource_pool(struct resource_pool **pool)
0973 {
0974     struct dcn21_resource_pool *dcn21_pool = TO_DCN21_RES_POOL(*pool);
0975 
0976     dcn21_resource_destruct(dcn21_pool);
0977     kfree(dcn21_pool);
0978     *pool = NULL;
0979 }
0980 
0981 static struct clock_source *dcn21_clock_source_create(
0982         struct dc_context *ctx,
0983         struct dc_bios *bios,
0984         enum clock_source_id id,
0985         const struct dce110_clk_src_regs *regs,
0986         bool dp_clk_src)
0987 {
0988     struct dce110_clk_src *clk_src =
0989         kzalloc(sizeof(struct dce110_clk_src), GFP_KERNEL);
0990 
0991     if (!clk_src)
0992         return NULL;
0993 
0994     if (dcn20_clk_src_construct(clk_src, ctx, bios, id,
0995             regs, &cs_shift, &cs_mask)) {
0996         clk_src->base.dp_clk_src = dp_clk_src;
0997         return &clk_src->base;
0998     }
0999 
1000     kfree(clk_src);
1001     BREAK_TO_DEBUGGER();
1002     return NULL;
1003 }
1004 
1005 static struct hubp *dcn21_hubp_create(
1006     struct dc_context *ctx,
1007     uint32_t inst)
1008 {
1009     struct dcn21_hubp *hubp21 =
1010         kzalloc(sizeof(struct dcn21_hubp), GFP_KERNEL);
1011 
1012     if (!hubp21)
1013         return NULL;
1014 
1015     if (hubp21_construct(hubp21, ctx, inst,
1016             &hubp_regs[inst], &hubp_shift, &hubp_mask))
1017         return &hubp21->base;
1018 
1019     BREAK_TO_DEBUGGER();
1020     kfree(hubp21);
1021     return NULL;
1022 }
1023 
1024 static struct hubbub *dcn21_hubbub_create(struct dc_context *ctx)
1025 {
1026     int i;
1027 
1028     struct dcn20_hubbub *hubbub = kzalloc(sizeof(struct dcn20_hubbub),
1029                       GFP_KERNEL);
1030 
1031     if (!hubbub)
1032         return NULL;
1033 
1034     hubbub21_construct(hubbub, ctx,
1035             &hubbub_reg,
1036             &hubbub_shift,
1037             &hubbub_mask);
1038 
1039     for (i = 0; i < res_cap_rn.num_vmid; i++) {
1040         struct dcn20_vmid *vmid = &hubbub->vmid[i];
1041 
1042         vmid->ctx = ctx;
1043 
1044         vmid->regs = &vmid_regs[i];
1045         vmid->shifts = &vmid_shifts;
1046         vmid->masks = &vmid_masks;
1047     }
1048     hubbub->num_vmid = res_cap_rn.num_vmid;
1049 
1050     return &hubbub->base;
1051 }
1052 
1053 static struct output_pixel_processor *dcn21_opp_create(struct dc_context *ctx,
1054                                uint32_t inst)
1055 {
1056     struct dcn20_opp *opp =
1057         kzalloc(sizeof(struct dcn20_opp), GFP_KERNEL);
1058 
1059     if (!opp) {
1060         BREAK_TO_DEBUGGER();
1061         return NULL;
1062     }
1063 
1064     dcn20_opp_construct(opp, ctx, inst,
1065             &opp_regs[inst], &opp_shift, &opp_mask);
1066     return &opp->base;
1067 }
1068 
1069 static struct timing_generator *dcn21_timing_generator_create(struct dc_context *ctx,
1070                                   uint32_t instance)
1071 {
1072     struct optc *tgn10 =
1073         kzalloc(sizeof(struct optc), GFP_KERNEL);
1074 
1075     if (!tgn10)
1076         return NULL;
1077 
1078     tgn10->base.inst = instance;
1079     tgn10->base.ctx = ctx;
1080 
1081     tgn10->tg_regs = &tg_regs[instance];
1082     tgn10->tg_shift = &tg_shift;
1083     tgn10->tg_mask = &tg_mask;
1084 
1085     dcn20_timing_generator_init(tgn10);
1086 
1087     return &tgn10->base;
1088 }
1089 
1090 static struct mpc *dcn21_mpc_create(struct dc_context *ctx)
1091 {
1092     struct dcn20_mpc *mpc20 = kzalloc(sizeof(struct dcn20_mpc),
1093                       GFP_KERNEL);
1094 
1095     if (!mpc20)
1096         return NULL;
1097 
1098     dcn20_mpc_construct(mpc20, ctx,
1099             &mpc_regs,
1100             &mpc_shift,
1101             &mpc_mask,
1102             6);
1103 
1104     return &mpc20->base;
1105 }
1106 
1107 static void read_dce_straps(
1108     struct dc_context *ctx,
1109     struct resource_straps *straps)
1110 {
1111     generic_reg_get(ctx, mmDC_PINSTRAPS + BASE(mmDC_PINSTRAPS_BASE_IDX),
1112         FN(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO), &straps->dc_pinstraps_audio);
1113 
1114 }
1115 
1116 
1117 static struct display_stream_compressor *dcn21_dsc_create(struct dc_context *ctx,
1118                               uint32_t inst)
1119 {
1120     struct dcn20_dsc *dsc =
1121         kzalloc(sizeof(struct dcn20_dsc), GFP_KERNEL);
1122 
1123     if (!dsc) {
1124         BREAK_TO_DEBUGGER();
1125         return NULL;
1126     }
1127 
1128     dsc2_construct(dsc, ctx, inst, &dsc_regs[inst], &dsc_shift, &dsc_mask);
1129     return &dsc->base;
1130 }
1131 
1132 static struct pp_smu_funcs *dcn21_pp_smu_create(struct dc_context *ctx)
1133 {
1134     struct pp_smu_funcs *pp_smu = kzalloc(sizeof(*pp_smu), GFP_KERNEL);
1135 
1136     if (!pp_smu)
1137         return pp_smu;
1138 
1139     dm_pp_get_funcs(ctx, pp_smu);
1140 
1141     if (pp_smu->ctx.ver != PP_SMU_VER_RN)
1142         pp_smu = memset(pp_smu, 0, sizeof(struct pp_smu_funcs));
1143 
1144 
1145     return pp_smu;
1146 }
1147 
1148 static void dcn21_pp_smu_destroy(struct pp_smu_funcs **pp_smu)
1149 {
1150     if (pp_smu && *pp_smu) {
1151         kfree(*pp_smu);
1152         *pp_smu = NULL;
1153     }
1154 }
1155 
1156 static struct audio *dcn21_create_audio(
1157         struct dc_context *ctx, unsigned int inst)
1158 {
1159     return dce_audio_create(ctx, inst,
1160             &audio_regs[inst], &audio_shift, &audio_mask);
1161 }
1162 
1163 static struct dc_cap_funcs cap_funcs = {
1164     .get_dcc_compression_cap = dcn20_get_dcc_compression_cap
1165 };
1166 
1167 static struct stream_encoder *dcn21_stream_encoder_create(enum engine_id eng_id,
1168                               struct dc_context *ctx)
1169 {
1170     struct dcn10_stream_encoder *enc1 =
1171         kzalloc(sizeof(struct dcn10_stream_encoder), GFP_KERNEL);
1172 
1173     if (!enc1)
1174         return NULL;
1175 
1176     dcn20_stream_encoder_construct(enc1, ctx, ctx->dc_bios, eng_id,
1177                     &stream_enc_regs[eng_id],
1178                     &se_shift, &se_mask);
1179 
1180     return &enc1->base;
1181 }
1182 
1183 static const struct dce_hwseq_registers hwseq_reg = {
1184         HWSEQ_DCN21_REG_LIST()
1185 };
1186 
1187 static const struct dce_hwseq_shift hwseq_shift = {
1188         HWSEQ_DCN21_MASK_SH_LIST(__SHIFT)
1189 };
1190 
1191 static const struct dce_hwseq_mask hwseq_mask = {
1192         HWSEQ_DCN21_MASK_SH_LIST(_MASK)
1193 };
1194 
1195 static struct dce_hwseq *dcn21_hwseq_create(
1196     struct dc_context *ctx)
1197 {
1198     struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL);
1199 
1200     if (hws) {
1201         hws->ctx = ctx;
1202         hws->regs = &hwseq_reg;
1203         hws->shifts = &hwseq_shift;
1204         hws->masks = &hwseq_mask;
1205         hws->wa.DEGVIDCN21 = true;
1206         hws->wa.disallow_self_refresh_during_multi_plane_transition = true;
1207     }
1208     return hws;
1209 }
1210 
1211 static const struct resource_create_funcs res_create_funcs = {
1212     .read_dce_straps = read_dce_straps,
1213     .create_audio = dcn21_create_audio,
1214     .create_stream_encoder = dcn21_stream_encoder_create,
1215     .create_hwseq = dcn21_hwseq_create,
1216 };
1217 
1218 static const struct resource_create_funcs res_create_maximus_funcs = {
1219     .read_dce_straps = NULL,
1220     .create_audio = NULL,
1221     .create_stream_encoder = NULL,
1222     .create_hwseq = dcn21_hwseq_create,
1223 };
1224 
1225 static const struct encoder_feature_support link_enc_feature = {
1226         .max_hdmi_deep_color = COLOR_DEPTH_121212,
1227         .max_hdmi_pixel_clock = 600000,
1228         .hdmi_ycbcr420_supported = true,
1229         .dp_ycbcr420_supported = true,
1230         .fec_supported = true,
1231         .flags.bits.IS_HBR2_CAPABLE = true,
1232         .flags.bits.IS_HBR3_CAPABLE = true,
1233         .flags.bits.IS_TPS3_CAPABLE = true,
1234         .flags.bits.IS_TPS4_CAPABLE = true
1235 };
1236 
1237 
1238 #define link_regs(id, phyid)\
1239 [id] = {\
1240     LE_DCN2_REG_LIST(id), \
1241     UNIPHY_DCN2_REG_LIST(phyid), \
1242     DPCS_DCN21_REG_LIST(id), \
1243     SRI(DP_DPHY_INTERNAL_CTRL, DP, id) \
1244 }
1245 
1246 static const struct dcn10_link_enc_registers link_enc_regs[] = {
1247     link_regs(0, A),
1248     link_regs(1, B),
1249     link_regs(2, C),
1250     link_regs(3, D),
1251     link_regs(4, E),
1252 };
1253 
1254 static const struct dce_panel_cntl_registers panel_cntl_regs[] = {
1255     { DCN_PANEL_CNTL_REG_LIST() }
1256 };
1257 
1258 static const struct dce_panel_cntl_shift panel_cntl_shift = {
1259     DCE_PANEL_CNTL_MASK_SH_LIST(__SHIFT)
1260 };
1261 
1262 static const struct dce_panel_cntl_mask panel_cntl_mask = {
1263     DCE_PANEL_CNTL_MASK_SH_LIST(_MASK)
1264 };
1265 
1266 #define aux_regs(id)\
1267 [id] = {\
1268     DCN2_AUX_REG_LIST(id)\
1269 }
1270 
1271 static const struct dcn10_link_enc_aux_registers link_enc_aux_regs[] = {
1272         aux_regs(0),
1273         aux_regs(1),
1274         aux_regs(2),
1275         aux_regs(3),
1276         aux_regs(4)
1277 };
1278 
1279 #define hpd_regs(id)\
1280 [id] = {\
1281     HPD_REG_LIST(id)\
1282 }
1283 
1284 static const struct dcn10_link_enc_hpd_registers link_enc_hpd_regs[] = {
1285         hpd_regs(0),
1286         hpd_regs(1),
1287         hpd_regs(2),
1288         hpd_regs(3),
1289         hpd_regs(4)
1290 };
1291 
1292 static const struct dcn10_link_enc_shift le_shift = {
1293     LINK_ENCODER_MASK_SH_LIST_DCN20(__SHIFT),\
1294     DPCS_DCN21_MASK_SH_LIST(__SHIFT)
1295 };
1296 
1297 static const struct dcn10_link_enc_mask le_mask = {
1298     LINK_ENCODER_MASK_SH_LIST_DCN20(_MASK),\
1299     DPCS_DCN21_MASK_SH_LIST(_MASK)
1300 };
1301 
1302 static int map_transmitter_id_to_phy_instance(
1303     enum transmitter transmitter)
1304 {
1305     switch (transmitter) {
1306     case TRANSMITTER_UNIPHY_A:
1307         return 0;
1308     break;
1309     case TRANSMITTER_UNIPHY_B:
1310         return 1;
1311     break;
1312     case TRANSMITTER_UNIPHY_C:
1313         return 2;
1314     break;
1315     case TRANSMITTER_UNIPHY_D:
1316         return 3;
1317     break;
1318     case TRANSMITTER_UNIPHY_E:
1319         return 4;
1320     break;
1321     default:
1322         ASSERT(0);
1323         return 0;
1324     }
1325 }
1326 
1327 static struct link_encoder *dcn21_link_encoder_create(
1328     struct dc_context *ctx,
1329     const struct encoder_init_data *enc_init_data)
1330 {
1331     struct dcn21_link_encoder *enc21 =
1332         kzalloc(sizeof(struct dcn21_link_encoder), GFP_KERNEL);
1333     int link_regs_id;
1334 
1335     if (!enc21)
1336         return NULL;
1337 
1338     link_regs_id =
1339         map_transmitter_id_to_phy_instance(enc_init_data->transmitter);
1340 
1341     dcn21_link_encoder_construct(enc21,
1342                       enc_init_data,
1343                       &link_enc_feature,
1344                       &link_enc_regs[link_regs_id],
1345                       &link_enc_aux_regs[enc_init_data->channel - 1],
1346                       &link_enc_hpd_regs[enc_init_data->hpd_source],
1347                       &le_shift,
1348                       &le_mask);
1349 
1350     return &enc21->enc10.base;
1351 }
1352 
1353 static struct panel_cntl *dcn21_panel_cntl_create(const struct panel_cntl_init_data *init_data)
1354 {
1355     struct dce_panel_cntl *panel_cntl =
1356         kzalloc(sizeof(struct dce_panel_cntl), GFP_KERNEL);
1357 
1358     if (!panel_cntl)
1359         return NULL;
1360 
1361     dce_panel_cntl_construct(panel_cntl,
1362             init_data,
1363             &panel_cntl_regs[init_data->inst],
1364             &panel_cntl_shift,
1365             &panel_cntl_mask);
1366 
1367     return &panel_cntl->base;
1368 }
1369 
1370 #define CTX ctx
1371 
1372 #define REG(reg_name) \
1373     (DCN_BASE.instance[0].segment[mm ## reg_name ## _BASE_IDX] + mm ## reg_name)
1374 
1375 static uint32_t read_pipe_fuses(struct dc_context *ctx)
1376 {
1377     uint32_t value = REG_READ(CC_DC_PIPE_DIS);
1378     /* RV1 support max 4 pipes */
1379     value = value & 0xf;
1380     return value;
1381 }
1382 
1383 static enum dc_status dcn21_patch_unknown_plane_state(struct dc_plane_state *plane_state)
1384 {
1385     enum dc_status result = DC_OK;
1386 
1387     if (plane_state->ctx->dc->debug.disable_dcc == DCC_ENABLE) {
1388         plane_state->dcc.enable = 1;
1389         /* align to our worst case block width */
1390         plane_state->dcc.meta_pitch = ((plane_state->src_rect.width + 1023) / 1024) * 1024;
1391     }
1392     result = dcn20_patch_unknown_plane_state(plane_state);
1393     return result;
1394 }
1395 
1396 static const struct resource_funcs dcn21_res_pool_funcs = {
1397     .destroy = dcn21_destroy_resource_pool,
1398     .link_enc_create = dcn21_link_encoder_create,
1399     .panel_cntl_create = dcn21_panel_cntl_create,
1400     .validate_bandwidth = dcn21_validate_bandwidth,
1401     .populate_dml_pipes = dcn21_populate_dml_pipes_from_context,
1402     .add_stream_to_ctx = dcn20_add_stream_to_ctx,
1403     .add_dsc_to_stream_resource = dcn20_add_dsc_to_stream_resource,
1404     .remove_stream_from_ctx = dcn20_remove_stream_from_ctx,
1405     .acquire_idle_pipe_for_layer = dcn20_acquire_idle_pipe_for_layer,
1406     .populate_dml_writeback_from_context = dcn20_populate_dml_writeback_from_context,
1407     .patch_unknown_plane_state = dcn21_patch_unknown_plane_state,
1408     .set_mcif_arb_params = dcn20_set_mcif_arb_params,
1409     .find_first_free_match_stream_enc_for_link = dcn10_find_first_free_match_stream_enc_for_link,
1410     .update_bw_bounding_box = dcn21_update_bw_bounding_box,
1411 };
1412 
1413 static bool dcn21_resource_construct(
1414     uint8_t num_virtual_links,
1415     struct dc *dc,
1416     struct dcn21_resource_pool *pool)
1417 {
1418     int i, j;
1419     struct dc_context *ctx = dc->ctx;
1420     struct irq_service_init_data init_data;
1421     uint32_t pipe_fuses = read_pipe_fuses(ctx);
1422     uint32_t num_pipes;
1423 
1424     ctx->dc_bios->regs = &bios_regs;
1425 
1426     pool->base.res_cap = &res_cap_rn;
1427 #ifdef DIAGS_BUILD
1428     if (IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment))
1429         //pool->base.res_cap = &res_cap_nv10_FPGA_2pipe_dsc;
1430         pool->base.res_cap = &res_cap_rn_FPGA_4pipe;
1431 #endif
1432 
1433     pool->base.funcs = &dcn21_res_pool_funcs;
1434 
1435     /*************************************************
1436      *  Resource + asic cap harcoding                *
1437      *************************************************/
1438     pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
1439 
1440     /* max pipe num for ASIC before check pipe fuses */
1441     pool->base.pipe_count = pool->base.res_cap->num_timing_generator;
1442 
1443     dc->caps.max_downscale_ratio = 200;
1444     dc->caps.i2c_speed_in_khz = 100;
1445     dc->caps.i2c_speed_in_khz_hdcp = 5; /*1.4 w/a applied by default*/
1446     dc->caps.max_cursor_size = 256;
1447     dc->caps.min_horizontal_blanking_period = 80;
1448     dc->caps.dmdata_alloc_size = 2048;
1449 
1450     dc->caps.max_slave_planes = 1;
1451     dc->caps.max_slave_yuv_planes = 1;
1452     dc->caps.max_slave_rgb_planes = 1;
1453     dc->caps.post_blend_color_processing = true;
1454     dc->caps.force_dp_tps4_for_cp2520 = true;
1455     dc->caps.extended_aux_timeout_support = true;
1456     dc->caps.dmcub_support = true;
1457     dc->caps.is_apu = true;
1458 
1459     /* Color pipeline capabilities */
1460     dc->caps.color.dpp.dcn_arch = 1;
1461     dc->caps.color.dpp.input_lut_shared = 0;
1462     dc->caps.color.dpp.icsc = 1;
1463     dc->caps.color.dpp.dgam_ram = 1;
1464     dc->caps.color.dpp.dgam_rom_caps.srgb = 1;
1465     dc->caps.color.dpp.dgam_rom_caps.bt2020 = 1;
1466     dc->caps.color.dpp.dgam_rom_caps.gamma2_2 = 0;
1467     dc->caps.color.dpp.dgam_rom_caps.pq = 0;
1468     dc->caps.color.dpp.dgam_rom_caps.hlg = 0;
1469     dc->caps.color.dpp.post_csc = 0;
1470     dc->caps.color.dpp.gamma_corr = 0;
1471     dc->caps.color.dpp.dgam_rom_for_yuv = 1;
1472 
1473     dc->caps.color.dpp.hw_3d_lut = 1;
1474     dc->caps.color.dpp.ogam_ram = 1;
1475     // no OGAM ROM on DCN2
1476     dc->caps.color.dpp.ogam_rom_caps.srgb = 0;
1477     dc->caps.color.dpp.ogam_rom_caps.bt2020 = 0;
1478     dc->caps.color.dpp.ogam_rom_caps.gamma2_2 = 0;
1479     dc->caps.color.dpp.ogam_rom_caps.pq = 0;
1480     dc->caps.color.dpp.ogam_rom_caps.hlg = 0;
1481     dc->caps.color.dpp.ocsc = 0;
1482 
1483     dc->caps.color.mpc.gamut_remap = 0;
1484     dc->caps.color.mpc.num_3dluts = 0;
1485     dc->caps.color.mpc.shared_3d_lut = 0;
1486     dc->caps.color.mpc.ogam_ram = 1;
1487     dc->caps.color.mpc.ogam_rom_caps.srgb = 0;
1488     dc->caps.color.mpc.ogam_rom_caps.bt2020 = 0;
1489     dc->caps.color.mpc.ogam_rom_caps.gamma2_2 = 0;
1490     dc->caps.color.mpc.ogam_rom_caps.pq = 0;
1491     dc->caps.color.mpc.ogam_rom_caps.hlg = 0;
1492     dc->caps.color.mpc.ocsc = 1;
1493 
1494     dc->caps.dp_hdmi21_pcon_support = true;
1495 
1496     if (dc->ctx->dce_environment == DCE_ENV_PRODUCTION_DRV)
1497         dc->debug = debug_defaults_drv;
1498     else if (dc->ctx->dce_environment == DCE_ENV_FPGA_MAXIMUS) {
1499         pool->base.pipe_count = 4;
1500         dc->debug = debug_defaults_diags;
1501     } else
1502         dc->debug = debug_defaults_diags;
1503 
1504     // Init the vm_helper
1505     if (dc->vm_helper)
1506         vm_helper_init(dc->vm_helper, 16);
1507 
1508     /*************************************************
1509      *  Create resources                             *
1510      *************************************************/
1511 
1512     pool->base.clock_sources[DCN20_CLK_SRC_PLL0] =
1513             dcn21_clock_source_create(ctx, ctx->dc_bios,
1514                 CLOCK_SOURCE_COMBO_PHY_PLL0,
1515                 &clk_src_regs[0], false);
1516     pool->base.clock_sources[DCN20_CLK_SRC_PLL1] =
1517             dcn21_clock_source_create(ctx, ctx->dc_bios,
1518                 CLOCK_SOURCE_COMBO_PHY_PLL1,
1519                 &clk_src_regs[1], false);
1520     pool->base.clock_sources[DCN20_CLK_SRC_PLL2] =
1521             dcn21_clock_source_create(ctx, ctx->dc_bios,
1522                 CLOCK_SOURCE_COMBO_PHY_PLL2,
1523                 &clk_src_regs[2], false);
1524     pool->base.clock_sources[DCN20_CLK_SRC_PLL3] =
1525             dcn21_clock_source_create(ctx, ctx->dc_bios,
1526                 CLOCK_SOURCE_COMBO_PHY_PLL3,
1527                 &clk_src_regs[3], false);
1528     pool->base.clock_sources[DCN20_CLK_SRC_PLL4] =
1529             dcn21_clock_source_create(ctx, ctx->dc_bios,
1530                 CLOCK_SOURCE_COMBO_PHY_PLL4,
1531                 &clk_src_regs[4], false);
1532 
1533     pool->base.clk_src_count = DCN20_CLK_SRC_TOTAL_DCN21;
1534 
1535     /* todo: not reuse phy_pll registers */
1536     pool->base.dp_clock_source =
1537             dcn21_clock_source_create(ctx, ctx->dc_bios,
1538                 CLOCK_SOURCE_ID_DP_DTO,
1539                 &clk_src_regs[0], true);
1540 
1541     for (i = 0; i < pool->base.clk_src_count; i++) {
1542         if (pool->base.clock_sources[i] == NULL) {
1543             dm_error("DC: failed to create clock sources!\n");
1544             BREAK_TO_DEBUGGER();
1545             goto create_fail;
1546         }
1547     }
1548 
1549     pool->base.dccg = dccg21_create(ctx, &dccg_regs, &dccg_shift, &dccg_mask);
1550     if (pool->base.dccg == NULL) {
1551         dm_error("DC: failed to create dccg!\n");
1552         BREAK_TO_DEBUGGER();
1553         goto create_fail;
1554     }
1555 
1556     if (!dc->config.disable_dmcu) {
1557         pool->base.dmcu = dcn21_dmcu_create(ctx,
1558                 &dmcu_regs,
1559                 &dmcu_shift,
1560                 &dmcu_mask);
1561         if (pool->base.dmcu == NULL) {
1562             dm_error("DC: failed to create dmcu!\n");
1563             BREAK_TO_DEBUGGER();
1564             goto create_fail;
1565         }
1566 
1567         dc->debug.dmub_command_table = false;
1568     }
1569 
1570     if (dc->config.disable_dmcu) {
1571         pool->base.psr = dmub_psr_create(ctx);
1572 
1573         if (pool->base.psr == NULL) {
1574             dm_error("DC: failed to create psr obj!\n");
1575             BREAK_TO_DEBUGGER();
1576             goto create_fail;
1577         }
1578     }
1579 
1580     if (dc->config.disable_dmcu)
1581         pool->base.abm = dmub_abm_create(ctx,
1582             &abm_regs,
1583             &abm_shift,
1584             &abm_mask);
1585     else
1586         pool->base.abm = dce_abm_create(ctx,
1587             &abm_regs,
1588             &abm_shift,
1589             &abm_mask);
1590 
1591     pool->base.pp_smu = dcn21_pp_smu_create(ctx);
1592 
1593     num_pipes = dcn2_1_ip.max_num_dpp;
1594 
1595     for (i = 0; i < dcn2_1_ip.max_num_dpp; i++)
1596         if (pipe_fuses & 1 << i)
1597             num_pipes--;
1598     dcn2_1_ip.max_num_dpp = num_pipes;
1599     dcn2_1_ip.max_num_otg = num_pipes;
1600 
1601     dml_init_instance(&dc->dml, &dcn2_1_soc, &dcn2_1_ip, DML_PROJECT_DCN21);
1602 
1603     init_data.ctx = dc->ctx;
1604     pool->base.irqs = dal_irq_service_dcn21_create(&init_data);
1605     if (!pool->base.irqs)
1606         goto create_fail;
1607 
1608     j = 0;
1609     /* mem input -> ipp -> dpp -> opp -> TG */
1610     for (i = 0; i < pool->base.pipe_count; i++) {
1611         /* if pipe is disabled, skip instance of HW pipe,
1612          * i.e, skip ASIC register instance
1613          */
1614         if ((pipe_fuses & (1 << i)) != 0)
1615             continue;
1616 
1617         pool->base.hubps[j] = dcn21_hubp_create(ctx, i);
1618         if (pool->base.hubps[j] == NULL) {
1619             BREAK_TO_DEBUGGER();
1620             dm_error(
1621                 "DC: failed to create memory input!\n");
1622             goto create_fail;
1623         }
1624 
1625         pool->base.ipps[j] = dcn21_ipp_create(ctx, i);
1626         if (pool->base.ipps[j] == NULL) {
1627             BREAK_TO_DEBUGGER();
1628             dm_error(
1629                 "DC: failed to create input pixel processor!\n");
1630             goto create_fail;
1631         }
1632 
1633         pool->base.dpps[j] = dcn21_dpp_create(ctx, i);
1634         if (pool->base.dpps[j] == NULL) {
1635             BREAK_TO_DEBUGGER();
1636             dm_error(
1637                 "DC: failed to create dpps!\n");
1638             goto create_fail;
1639         }
1640 
1641         pool->base.opps[j] = dcn21_opp_create(ctx, i);
1642         if (pool->base.opps[j] == NULL) {
1643             BREAK_TO_DEBUGGER();
1644             dm_error(
1645                 "DC: failed to create output pixel processor!\n");
1646             goto create_fail;
1647         }
1648 
1649         pool->base.timing_generators[j] = dcn21_timing_generator_create(
1650                 ctx, i);
1651         if (pool->base.timing_generators[j] == NULL) {
1652             BREAK_TO_DEBUGGER();
1653             dm_error("DC: failed to create tg!\n");
1654             goto create_fail;
1655         }
1656         j++;
1657     }
1658 
1659     for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
1660         pool->base.engines[i] = dcn21_aux_engine_create(ctx, i);
1661         if (pool->base.engines[i] == NULL) {
1662             BREAK_TO_DEBUGGER();
1663             dm_error(
1664                 "DC:failed to create aux engine!!\n");
1665             goto create_fail;
1666         }
1667         pool->base.hw_i2cs[i] = dcn21_i2c_hw_create(ctx, i);
1668         if (pool->base.hw_i2cs[i] == NULL) {
1669             BREAK_TO_DEBUGGER();
1670             dm_error(
1671                 "DC:failed to create hw i2c!!\n");
1672             goto create_fail;
1673         }
1674         pool->base.sw_i2cs[i] = NULL;
1675     }
1676 
1677     pool->base.timing_generator_count = j;
1678     pool->base.pipe_count = j;
1679     pool->base.mpcc_count = j;
1680 
1681     pool->base.mpc = dcn21_mpc_create(ctx);
1682     if (pool->base.mpc == NULL) {
1683         BREAK_TO_DEBUGGER();
1684         dm_error("DC: failed to create mpc!\n");
1685         goto create_fail;
1686     }
1687 
1688     pool->base.hubbub = dcn21_hubbub_create(ctx);
1689     if (pool->base.hubbub == NULL) {
1690         BREAK_TO_DEBUGGER();
1691         dm_error("DC: failed to create hubbub!\n");
1692         goto create_fail;
1693     }
1694 
1695     for (i = 0; i < pool->base.res_cap->num_dsc; i++) {
1696         pool->base.dscs[i] = dcn21_dsc_create(ctx, i);
1697         if (pool->base.dscs[i] == NULL) {
1698             BREAK_TO_DEBUGGER();
1699             dm_error("DC: failed to create display stream compressor %d!\n", i);
1700             goto create_fail;
1701         }
1702     }
1703 
1704     if (!dcn20_dwbc_create(ctx, &pool->base)) {
1705         BREAK_TO_DEBUGGER();
1706         dm_error("DC: failed to create dwbc!\n");
1707         goto create_fail;
1708     }
1709     if (!dcn20_mmhubbub_create(ctx, &pool->base)) {
1710         BREAK_TO_DEBUGGER();
1711         dm_error("DC: failed to create mcif_wb!\n");
1712         goto create_fail;
1713     }
1714 
1715     if (!resource_construct(num_virtual_links, dc, &pool->base,
1716             (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment) ?
1717             &res_create_funcs : &res_create_maximus_funcs)))
1718             goto create_fail;
1719 
1720     dcn21_hw_sequencer_construct(dc);
1721 
1722     dc->caps.max_planes =  pool->base.pipe_count;
1723 
1724     for (i = 0; i < dc->caps.max_planes; ++i)
1725         dc->caps.planes[i] = plane_cap;
1726 
1727     dc->cap_funcs = cap_funcs;
1728 
1729     return true;
1730 
1731 create_fail:
1732 
1733     dcn21_resource_destruct(pool);
1734 
1735     return false;
1736 }
1737 
1738 struct resource_pool *dcn21_create_resource_pool(
1739         const struct dc_init_data *init_data,
1740         struct dc *dc)
1741 {
1742     struct dcn21_resource_pool *pool =
1743         kzalloc(sizeof(struct dcn21_resource_pool), GFP_KERNEL);
1744 
1745     if (!pool)
1746         return NULL;
1747 
1748     if (dcn21_resource_construct(init_data->num_virtual_links, dc, pool))
1749         return &pool->base;
1750 
1751     BREAK_TO_DEBUGGER();
1752     kfree(pool);
1753     return NULL;
1754 }