Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: MIT
0002 /*
0003  * Copyright 2019 Advanced Micro Devices, Inc.
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 "dm_services.h"
0028 #include "dc.h"
0029 
0030 #include "dcn32/dcn32_init.h"
0031 
0032 #include "resource.h"
0033 #include "include/irq_service_interface.h"
0034 #include "dcn32/dcn32_resource.h"
0035 #include "dcn321_resource.h"
0036 
0037 #include "dcn20/dcn20_resource.h"
0038 #include "dcn30/dcn30_resource.h"
0039 
0040 #include "dml/dcn321/dcn321_fpu.h"
0041 
0042 #include "dcn10/dcn10_ipp.h"
0043 #include "dcn30/dcn30_hubbub.h"
0044 #include "dcn31/dcn31_hubbub.h"
0045 #include "dcn32/dcn32_hubbub.h"
0046 #include "dcn32/dcn32_mpc.h"
0047 #include "dcn32/dcn32_hubp.h"
0048 #include "irq/dcn32/irq_service_dcn32.h"
0049 #include "dcn32/dcn32_dpp.h"
0050 #include "dcn32/dcn32_optc.h"
0051 #include "dcn20/dcn20_hwseq.h"
0052 #include "dcn30/dcn30_hwseq.h"
0053 #include "dce110/dce110_hw_sequencer.h"
0054 #include "dcn30/dcn30_opp.h"
0055 #include "dcn20/dcn20_dsc.h"
0056 #include "dcn30/dcn30_vpg.h"
0057 #include "dcn30/dcn30_afmt.h"
0058 #include "dcn30/dcn30_dio_stream_encoder.h"
0059 #include "dcn32/dcn32_dio_stream_encoder.h"
0060 #include "dcn31/dcn31_hpo_dp_stream_encoder.h"
0061 #include "dcn31/dcn31_hpo_dp_link_encoder.h"
0062 #include "dcn32/dcn32_hpo_dp_link_encoder.h"
0063 #include "dc_link_dp.h"
0064 #include "dcn31/dcn31_apg.h"
0065 #include "dcn31/dcn31_dio_link_encoder.h"
0066 #include "dcn32/dcn32_dio_link_encoder.h"
0067 #include "dcn321_dio_link_encoder.h"
0068 #include "dce/dce_clock_source.h"
0069 #include "dce/dce_audio.h"
0070 #include "dce/dce_hwseq.h"
0071 #include "clk_mgr.h"
0072 #include "virtual/virtual_stream_encoder.h"
0073 #include "dml/display_mode_vba.h"
0074 #include "dcn32/dcn32_dccg.h"
0075 #include "dcn10/dcn10_resource.h"
0076 #include "dc_link_ddc.h"
0077 #include "dcn31/dcn31_panel_cntl.h"
0078 
0079 #include "dcn30/dcn30_dwb.h"
0080 #include "dcn32/dcn32_mmhubbub.h"
0081 
0082 #include "dcn/dcn_3_2_1_offset.h"
0083 #include "dcn/dcn_3_2_1_sh_mask.h"
0084 #include "nbio/nbio_4_3_0_offset.h"
0085 
0086 #include "reg_helper.h"
0087 #include "dce/dmub_abm.h"
0088 #include "dce/dmub_psr.h"
0089 #include "dce/dce_aux.h"
0090 #include "dce/dce_i2c.h"
0091 
0092 #include "dml/dcn30/display_mode_vba_30.h"
0093 #include "vm_helper.h"
0094 #include "dcn20/dcn20_vmid.h"
0095 
0096 #define DCN_BASE__INST0_SEG1                       0x000000C0
0097 #define DCN_BASE__INST0_SEG2                       0x000034C0
0098 #define DCN_BASE__INST0_SEG3                       0x00009000
0099 #define NBIO_BASE__INST0_SEG1                      0x00000014
0100 
0101 #define MAX_INSTANCE                                        8
0102 #define MAX_SEGMENT                                         6
0103 
0104 struct IP_BASE_INSTANCE {
0105     unsigned int segment[MAX_SEGMENT];
0106 };
0107 
0108 struct IP_BASE {
0109     struct IP_BASE_INSTANCE instance[MAX_INSTANCE];
0110 };
0111 
0112 static const struct IP_BASE DCN_BASE = { { { { 0x00000012, 0x000000C0, 0x000034C0, 0x00009000, 0x02403C00, 0 } },
0113                     { { 0, 0, 0, 0, 0, 0 } },
0114                     { { 0, 0, 0, 0, 0, 0 } },
0115                     { { 0, 0, 0, 0, 0, 0 } },
0116                     { { 0, 0, 0, 0, 0, 0 } },
0117                     { { 0, 0, 0, 0, 0, 0 } },
0118                     { { 0, 0, 0, 0, 0, 0 } },
0119                     { { 0, 0, 0, 0, 0, 0 } } } };
0120 
0121 #define DC_LOGGER_INIT(logger)
0122 #define fixed16_to_double(x) (((double)x) / ((double) (1 << 16)))
0123 #define fixed16_to_double_to_cpu(x) fixed16_to_double(le32_to_cpu(x))
0124 
0125 enum dcn321_clk_src_array_id {
0126     DCN321_CLK_SRC_PLL0,
0127     DCN321_CLK_SRC_PLL1,
0128     DCN321_CLK_SRC_PLL2,
0129     DCN321_CLK_SRC_PLL3,
0130     DCN321_CLK_SRC_PLL4,
0131     DCN321_CLK_SRC_TOTAL
0132 };
0133 
0134 /* begin *********************
0135  * macros to expend register list macro defined in HW object header file
0136  */
0137 
0138 /* DCN */
0139 /* TODO awful hack. fixup dcn20_dwb.h */
0140 #undef BASE_INNER
0141 #define BASE_INNER(seg) DCN_BASE__INST0_SEG ## seg
0142 
0143 #define BASE(seg) BASE_INNER(seg)
0144 
0145 #define SR(reg_name)\
0146         .reg_name = BASE(reg ## reg_name ## _BASE_IDX) +  \
0147                     reg ## reg_name
0148 
0149 #define SRI(reg_name, block, id)\
0150     .reg_name = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
0151                     reg ## block ## id ## _ ## reg_name
0152 
0153 #define SRI2(reg_name, block, id)\
0154     .reg_name = BASE(reg ## reg_name ## _BASE_IDX) + \
0155                     reg ## reg_name
0156 
0157 #define SRIR(var_name, reg_name, block, id)\
0158     .var_name = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
0159                     reg ## block ## id ## _ ## reg_name
0160 
0161 #define SRII(reg_name, block, id)\
0162     .reg_name[id] = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
0163                     reg ## block ## id ## _ ## reg_name
0164 
0165 #define SRII_MPC_RMU(reg_name, block, id)\
0166     .RMU##_##reg_name[id] = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
0167                     reg ## block ## id ## _ ## reg_name
0168 
0169 #define SRII_DWB(reg_name, temp_name, block, id)\
0170     .reg_name[id] = BASE(reg ## block ## id ## _ ## temp_name ## _BASE_IDX) + \
0171                     reg ## block ## id ## _ ## temp_name
0172 
0173 #define DCCG_SRII(reg_name, block, id)\
0174     .block ## _ ## reg_name[id] = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
0175                     reg ## block ## id ## _ ## reg_name
0176 
0177 #define VUPDATE_SRII(reg_name, block, id)\
0178     .reg_name[id] = BASE(reg ## reg_name ## _ ## block ## id ## _BASE_IDX) + \
0179                     reg ## reg_name ## _ ## block ## id
0180 
0181 /* NBIO */
0182 #define NBIO_BASE_INNER(seg) \
0183     NBIO_BASE__INST0_SEG ## seg
0184 
0185 #define NBIO_BASE(seg) \
0186     NBIO_BASE_INNER(seg)
0187 
0188 #define NBIO_SR(reg_name)\
0189         .reg_name = NBIO_BASE(regBIF_BX0_ ## reg_name ## _BASE_IDX) + \
0190                     regBIF_BX0_ ## reg_name
0191 
0192 #define CTX ctx
0193 #define REG(reg_name) \
0194     (DCN_BASE.instance[0].segment[reg ## reg_name ## _BASE_IDX] + reg ## reg_name)
0195 
0196 static const struct bios_registers bios_regs = {
0197         NBIO_SR(BIOS_SCRATCH_3),
0198         NBIO_SR(BIOS_SCRATCH_6)
0199 };
0200 
0201 #define clk_src_regs(index, pllid)\
0202 [index] = {\
0203     CS_COMMON_REG_LIST_DCN3_0(index, pllid),\
0204 }
0205 
0206 static const struct dce110_clk_src_regs clk_src_regs[] = {
0207     clk_src_regs(0, A),
0208     clk_src_regs(1, B),
0209     clk_src_regs(2, C),
0210     clk_src_regs(3, D),
0211     clk_src_regs(4, E)
0212 };
0213 
0214 static const struct dce110_clk_src_shift cs_shift = {
0215         CS_COMMON_MASK_SH_LIST_DCN3_2(__SHIFT)
0216 };
0217 
0218 static const struct dce110_clk_src_mask cs_mask = {
0219         CS_COMMON_MASK_SH_LIST_DCN3_2(_MASK)
0220 };
0221 
0222 #define abm_regs(id)\
0223 [id] = {\
0224         ABM_DCN32_REG_LIST(id)\
0225 }
0226 
0227 static const struct dce_abm_registers abm_regs[] = {
0228         abm_regs(0),
0229         abm_regs(1),
0230         abm_regs(2),
0231         abm_regs(3),
0232 };
0233 
0234 static const struct dce_abm_shift abm_shift = {
0235         ABM_MASK_SH_LIST_DCN32(__SHIFT)
0236 };
0237 
0238 static const struct dce_abm_mask abm_mask = {
0239         ABM_MASK_SH_LIST_DCN32(_MASK)
0240 };
0241 
0242 #define audio_regs(id)\
0243 [id] = {\
0244         AUD_COMMON_REG_LIST(id)\
0245 }
0246 
0247 static const struct dce_audio_registers audio_regs[] = {
0248     audio_regs(0),
0249     audio_regs(1),
0250     audio_regs(2),
0251     audio_regs(3),
0252     audio_regs(4)
0253 };
0254 
0255 #define DCE120_AUD_COMMON_MASK_SH_LIST(mask_sh)\
0256         SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_INDEX, AZALIA_ENDPOINT_REG_INDEX, mask_sh),\
0257         SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_DATA, AZALIA_ENDPOINT_REG_DATA, mask_sh),\
0258         AUD_COMMON_MASK_SH_LIST_BASE(mask_sh)
0259 
0260 static const struct dce_audio_shift audio_shift = {
0261         DCE120_AUD_COMMON_MASK_SH_LIST(__SHIFT)
0262 };
0263 
0264 static const struct dce_audio_mask audio_mask = {
0265         DCE120_AUD_COMMON_MASK_SH_LIST(_MASK)
0266 };
0267 
0268 #define vpg_regs(id)\
0269 [id] = {\
0270     VPG_DCN3_REG_LIST(id)\
0271 }
0272 
0273 static const struct dcn30_vpg_registers vpg_regs[] = {
0274     vpg_regs(0),
0275     vpg_regs(1),
0276     vpg_regs(2),
0277     vpg_regs(3),
0278     vpg_regs(4),
0279     vpg_regs(5),
0280     vpg_regs(6),
0281     vpg_regs(7),
0282     vpg_regs(8),
0283     vpg_regs(9),
0284 };
0285 
0286 static const struct dcn30_vpg_shift vpg_shift = {
0287     DCN3_VPG_MASK_SH_LIST(__SHIFT)
0288 };
0289 
0290 static const struct dcn30_vpg_mask vpg_mask = {
0291     DCN3_VPG_MASK_SH_LIST(_MASK)
0292 };
0293 
0294 #define afmt_regs(id)\
0295 [id] = {\
0296     AFMT_DCN3_REG_LIST(id)\
0297 }
0298 
0299 static const struct dcn30_afmt_registers afmt_regs[] = {
0300     afmt_regs(0),
0301     afmt_regs(1),
0302     afmt_regs(2),
0303     afmt_regs(3),
0304     afmt_regs(4),
0305     afmt_regs(5)
0306 };
0307 
0308 static const struct dcn30_afmt_shift afmt_shift = {
0309     DCN3_AFMT_MASK_SH_LIST(__SHIFT)
0310 };
0311 
0312 static const struct dcn30_afmt_mask afmt_mask = {
0313     DCN3_AFMT_MASK_SH_LIST(_MASK)
0314 };
0315 
0316 #define apg_regs(id)\
0317 [id] = {\
0318     APG_DCN31_REG_LIST(id)\
0319 }
0320 
0321 static const struct dcn31_apg_registers apg_regs[] = {
0322     apg_regs(0),
0323     apg_regs(1),
0324     apg_regs(2),
0325     apg_regs(3)
0326 };
0327 
0328 static const struct dcn31_apg_shift apg_shift = {
0329     DCN31_APG_MASK_SH_LIST(__SHIFT)
0330 };
0331 
0332 static const struct dcn31_apg_mask apg_mask = {
0333         DCN31_APG_MASK_SH_LIST(_MASK)
0334 };
0335 
0336 #define stream_enc_regs(id)\
0337 [id] = {\
0338     SE_DCN32_REG_LIST(id)\
0339 }
0340 
0341 static const struct dcn10_stream_enc_registers stream_enc_regs[] = {
0342     stream_enc_regs(0),
0343     stream_enc_regs(1),
0344     stream_enc_regs(2),
0345     stream_enc_regs(3),
0346     stream_enc_regs(4)
0347 };
0348 
0349 static const struct dcn10_stream_encoder_shift se_shift = {
0350         SE_COMMON_MASK_SH_LIST_DCN32(__SHIFT)
0351 };
0352 
0353 static const struct dcn10_stream_encoder_mask se_mask = {
0354         SE_COMMON_MASK_SH_LIST_DCN32(_MASK)
0355 };
0356 
0357 
0358 #define aux_regs(id)\
0359 [id] = {\
0360     DCN2_AUX_REG_LIST(id)\
0361 }
0362 
0363 static const struct dcn10_link_enc_aux_registers link_enc_aux_regs[] = {
0364         aux_regs(0),
0365         aux_regs(1),
0366         aux_regs(2),
0367         aux_regs(3),
0368         aux_regs(4)
0369 };
0370 
0371 #define hpd_regs(id)\
0372 [id] = {\
0373     HPD_REG_LIST(id)\
0374 }
0375 
0376 static const struct dcn10_link_enc_hpd_registers link_enc_hpd_regs[] = {
0377         hpd_regs(0),
0378         hpd_regs(1),
0379         hpd_regs(2),
0380         hpd_regs(3),
0381         hpd_regs(4)
0382 };
0383 
0384 #define link_regs(id, phyid)\
0385 [id] = {\
0386     LE_DCN31_REG_LIST(id), \
0387     UNIPHY_DCN2_REG_LIST(phyid), \
0388     /*DPCS_DCN31_REG_LIST(id),*/ \
0389 }
0390 
0391 static const struct dcn10_link_enc_registers link_enc_regs[] = {
0392     link_regs(0, A),
0393     link_regs(1, B),
0394     link_regs(2, C),
0395     link_regs(3, D),
0396     link_regs(4, E)
0397 };
0398 
0399 static const struct dcn10_link_enc_shift le_shift = {
0400     LINK_ENCODER_MASK_SH_LIST_DCN31(__SHIFT), \
0401 //  DPCS_DCN31_MASK_SH_LIST(__SHIFT)
0402 };
0403 
0404 static const struct dcn10_link_enc_mask le_mask = {
0405     LINK_ENCODER_MASK_SH_LIST_DCN31(_MASK), \
0406 //  DPCS_DCN31_MASK_SH_LIST(_MASK)
0407 };
0408 
0409 #define hpo_dp_stream_encoder_reg_list(id)\
0410 [id] = {\
0411     DCN3_1_HPO_DP_STREAM_ENC_REG_LIST(id)\
0412 }
0413 
0414 static const struct dcn31_hpo_dp_stream_encoder_registers hpo_dp_stream_enc_regs[] = {
0415     hpo_dp_stream_encoder_reg_list(0),
0416     hpo_dp_stream_encoder_reg_list(1),
0417     hpo_dp_stream_encoder_reg_list(2),
0418     hpo_dp_stream_encoder_reg_list(3),
0419 };
0420 
0421 static const struct dcn31_hpo_dp_stream_encoder_shift hpo_dp_se_shift = {
0422     DCN3_1_HPO_DP_STREAM_ENC_MASK_SH_LIST(__SHIFT)
0423 };
0424 
0425 static const struct dcn31_hpo_dp_stream_encoder_mask hpo_dp_se_mask = {
0426     DCN3_1_HPO_DP_STREAM_ENC_MASK_SH_LIST(_MASK)
0427 };
0428 
0429 
0430 #define hpo_dp_link_encoder_reg_list(id)\
0431 [id] = {\
0432     DCN3_1_HPO_DP_LINK_ENC_REG_LIST(id),\
0433     /*DCN3_1_RDPCSTX_REG_LIST(0),*/\
0434     /*DCN3_1_RDPCSTX_REG_LIST(1),*/\
0435     /*DCN3_1_RDPCSTX_REG_LIST(2),*/\
0436     /*DCN3_1_RDPCSTX_REG_LIST(3),*/\
0437     /*DCN3_1_RDPCSTX_REG_LIST(4)*/\
0438 }
0439 
0440 static const struct dcn31_hpo_dp_link_encoder_registers hpo_dp_link_enc_regs[] = {
0441     hpo_dp_link_encoder_reg_list(0),
0442     hpo_dp_link_encoder_reg_list(1),
0443 };
0444 
0445 static const struct dcn31_hpo_dp_link_encoder_shift hpo_dp_le_shift = {
0446     DCN3_2_HPO_DP_LINK_ENC_MASK_SH_LIST(__SHIFT)
0447 };
0448 
0449 static const struct dcn31_hpo_dp_link_encoder_mask hpo_dp_le_mask = {
0450     DCN3_2_HPO_DP_LINK_ENC_MASK_SH_LIST(_MASK)
0451 };
0452 
0453 #define dpp_regs(id)\
0454 [id] = {\
0455     DPP_REG_LIST_DCN30_COMMON(id),\
0456 }
0457 
0458 static const struct dcn3_dpp_registers dpp_regs[] = {
0459     dpp_regs(0),
0460     dpp_regs(1),
0461     dpp_regs(2),
0462     dpp_regs(3)
0463 };
0464 
0465 static const struct dcn3_dpp_shift tf_shift = {
0466         DPP_REG_LIST_SH_MASK_DCN30_COMMON(__SHIFT)
0467 };
0468 
0469 static const struct dcn3_dpp_mask tf_mask = {
0470         DPP_REG_LIST_SH_MASK_DCN30_COMMON(_MASK)
0471 };
0472 
0473 
0474 #define opp_regs(id)\
0475 [id] = {\
0476     OPP_REG_LIST_DCN30(id),\
0477 }
0478 
0479 static const struct dcn20_opp_registers opp_regs[] = {
0480     opp_regs(0),
0481     opp_regs(1),
0482     opp_regs(2),
0483     opp_regs(3)
0484 };
0485 
0486 static const struct dcn20_opp_shift opp_shift = {
0487     OPP_MASK_SH_LIST_DCN20(__SHIFT)
0488 };
0489 
0490 static const struct dcn20_opp_mask opp_mask = {
0491     OPP_MASK_SH_LIST_DCN20(_MASK)
0492 };
0493 
0494 #define aux_engine_regs(id)\
0495 [id] = {\
0496     AUX_COMMON_REG_LIST0(id), \
0497     .AUXN_IMPCAL = 0, \
0498     .AUXP_IMPCAL = 0, \
0499     .AUX_RESET_MASK = DP_AUX0_AUX_CONTROL__AUX_RESET_MASK, \
0500 }
0501 
0502 static const struct dce110_aux_registers aux_engine_regs[] = {
0503         aux_engine_regs(0),
0504         aux_engine_regs(1),
0505         aux_engine_regs(2),
0506         aux_engine_regs(3),
0507         aux_engine_regs(4)
0508 };
0509 
0510 static const struct dce110_aux_registers_shift aux_shift = {
0511     DCN_AUX_MASK_SH_LIST(__SHIFT)
0512 };
0513 
0514 static const struct dce110_aux_registers_mask aux_mask = {
0515     DCN_AUX_MASK_SH_LIST(_MASK)
0516 };
0517 
0518 
0519 #define dwbc_regs_dcn3(id)\
0520 [id] = {\
0521     DWBC_COMMON_REG_LIST_DCN30(id),\
0522 }
0523 
0524 static const struct dcn30_dwbc_registers dwbc30_regs[] = {
0525     dwbc_regs_dcn3(0),
0526 };
0527 
0528 static const struct dcn30_dwbc_shift dwbc30_shift = {
0529     DWBC_COMMON_MASK_SH_LIST_DCN30(__SHIFT)
0530 };
0531 
0532 static const struct dcn30_dwbc_mask dwbc30_mask = {
0533     DWBC_COMMON_MASK_SH_LIST_DCN30(_MASK)
0534 };
0535 
0536 #define mcif_wb_regs_dcn3(id)\
0537 [id] = {\
0538     MCIF_WB_COMMON_REG_LIST_DCN32(id),\
0539 }
0540 
0541 static const struct dcn30_mmhubbub_registers mcif_wb30_regs[] = {
0542     mcif_wb_regs_dcn3(0)
0543 };
0544 
0545 static const struct dcn30_mmhubbub_shift mcif_wb30_shift = {
0546     MCIF_WB_COMMON_MASK_SH_LIST_DCN32(__SHIFT)
0547 };
0548 
0549 static const struct dcn30_mmhubbub_mask mcif_wb30_mask = {
0550     MCIF_WB_COMMON_MASK_SH_LIST_DCN32(_MASK)
0551 };
0552 
0553 #define dsc_regsDCN20(id)\
0554 [id] = {\
0555     DSC_REG_LIST_DCN20(id)\
0556 }
0557 
0558 static const struct dcn20_dsc_registers dsc_regs[] = {
0559     dsc_regsDCN20(0),
0560     dsc_regsDCN20(1),
0561     dsc_regsDCN20(2),
0562     dsc_regsDCN20(3)
0563 };
0564 
0565 static const struct dcn20_dsc_shift dsc_shift = {
0566     DSC_REG_LIST_SH_MASK_DCN20(__SHIFT)
0567 };
0568 
0569 static const struct dcn20_dsc_mask dsc_mask = {
0570     DSC_REG_LIST_SH_MASK_DCN20(_MASK)
0571 };
0572 
0573 static const struct dcn30_mpc_registers mpc_regs = {
0574         MPC_REG_LIST_DCN3_2(0),
0575         MPC_REG_LIST_DCN3_2(1),
0576         MPC_REG_LIST_DCN3_2(2),
0577         MPC_REG_LIST_DCN3_2(3),
0578         MPC_OUT_MUX_REG_LIST_DCN3_0(0),
0579         MPC_OUT_MUX_REG_LIST_DCN3_0(1),
0580         MPC_OUT_MUX_REG_LIST_DCN3_0(2),
0581         MPC_OUT_MUX_REG_LIST_DCN3_0(3),
0582         MPC_DWB_MUX_REG_LIST_DCN3_0(0),
0583 };
0584 
0585 static const struct dcn30_mpc_shift mpc_shift = {
0586     MPC_COMMON_MASK_SH_LIST_DCN32(__SHIFT)
0587 };
0588 
0589 static const struct dcn30_mpc_mask mpc_mask = {
0590     MPC_COMMON_MASK_SH_LIST_DCN32(_MASK)
0591 };
0592 
0593 #define optc_regs(id)\
0594 [id] = {OPTC_COMMON_REG_LIST_DCN3_2(id)}
0595 
0596 static const struct dcn_optc_registers optc_regs[] = {
0597     optc_regs(0),
0598     optc_regs(1),
0599     optc_regs(2),
0600     optc_regs(3)
0601 };
0602 
0603 static const struct dcn_optc_shift optc_shift = {
0604     OPTC_COMMON_MASK_SH_LIST_DCN3_2(__SHIFT)
0605 };
0606 
0607 static const struct dcn_optc_mask optc_mask = {
0608     OPTC_COMMON_MASK_SH_LIST_DCN3_2(_MASK)
0609 };
0610 
0611 #define hubp_regs(id)\
0612 [id] = {\
0613     HUBP_REG_LIST_DCN32(id)\
0614 }
0615 
0616 static const struct dcn_hubp2_registers hubp_regs[] = {
0617         hubp_regs(0),
0618         hubp_regs(1),
0619         hubp_regs(2),
0620         hubp_regs(3)
0621 };
0622 
0623 
0624 static const struct dcn_hubp2_shift hubp_shift = {
0625         HUBP_MASK_SH_LIST_DCN32(__SHIFT)
0626 };
0627 
0628 static const struct dcn_hubp2_mask hubp_mask = {
0629         HUBP_MASK_SH_LIST_DCN32(_MASK)
0630 };
0631 static const struct dcn_hubbub_registers hubbub_reg = {
0632         HUBBUB_REG_LIST_DCN32(0)
0633 };
0634 
0635 static const struct dcn_hubbub_shift hubbub_shift = {
0636         HUBBUB_MASK_SH_LIST_DCN32(__SHIFT)
0637 };
0638 
0639 static const struct dcn_hubbub_mask hubbub_mask = {
0640         HUBBUB_MASK_SH_LIST_DCN32(_MASK)
0641 };
0642 
0643 static const struct dccg_registers dccg_regs = {
0644         DCCG_REG_LIST_DCN32()
0645 };
0646 
0647 static const struct dccg_shift dccg_shift = {
0648         DCCG_MASK_SH_LIST_DCN32(__SHIFT)
0649 };
0650 
0651 static const struct dccg_mask dccg_mask = {
0652         DCCG_MASK_SH_LIST_DCN32(_MASK)
0653 };
0654 
0655 
0656 #define SRII2(reg_name_pre, reg_name_post, id)\
0657     .reg_name_pre ## _ ##  reg_name_post[id] = BASE(reg ## reg_name_pre \
0658             ## id ## _ ## reg_name_post ## _BASE_IDX) + \
0659             reg ## reg_name_pre ## id ## _ ## reg_name_post
0660 
0661 
0662 #define HWSEQ_DCN32_REG_LIST()\
0663     SR(DCHUBBUB_GLOBAL_TIMER_CNTL), \
0664     SR(DIO_MEM_PWR_CTRL), \
0665     SR(ODM_MEM_PWR_CTRL3), \
0666     SR(MMHUBBUB_MEM_PWR_CNTL), \
0667     SR(DCCG_GATE_DISABLE_CNTL), \
0668     SR(DCCG_GATE_DISABLE_CNTL2), \
0669     SR(DCFCLK_CNTL),\
0670     SR(DC_MEM_GLOBAL_PWR_REQ_CNTL), \
0671     SRII(PIXEL_RATE_CNTL, OTG, 0), \
0672     SRII(PIXEL_RATE_CNTL, OTG, 1),\
0673     SRII(PIXEL_RATE_CNTL, OTG, 2),\
0674     SRII(PIXEL_RATE_CNTL, OTG, 3),\
0675     SRII(PHYPLL_PIXEL_RATE_CNTL, OTG, 0),\
0676     SRII(PHYPLL_PIXEL_RATE_CNTL, OTG, 1),\
0677     SRII(PHYPLL_PIXEL_RATE_CNTL, OTG, 2),\
0678     SRII(PHYPLL_PIXEL_RATE_CNTL, OTG, 3),\
0679     SR(MICROSECOND_TIME_BASE_DIV), \
0680     SR(MILLISECOND_TIME_BASE_DIV), \
0681     SR(DISPCLK_FREQ_CHANGE_CNTL), \
0682     SR(RBBMIF_TIMEOUT_DIS), \
0683     SR(RBBMIF_TIMEOUT_DIS_2), \
0684     SR(DCHUBBUB_CRC_CTRL), \
0685     SR(DPP_TOP0_DPP_CRC_CTRL), \
0686     SR(DPP_TOP0_DPP_CRC_VAL_B_A), \
0687     SR(DPP_TOP0_DPP_CRC_VAL_R_G), \
0688     SR(MPC_CRC_CTRL), \
0689     SR(MPC_CRC_RESULT_GB), \
0690     SR(MPC_CRC_RESULT_C), \
0691     SR(MPC_CRC_RESULT_AR), \
0692     SR(DOMAIN0_PG_CONFIG), \
0693     SR(DOMAIN1_PG_CONFIG), \
0694     SR(DOMAIN2_PG_CONFIG), \
0695     SR(DOMAIN3_PG_CONFIG), \
0696     SR(DOMAIN16_PG_CONFIG), \
0697     SR(DOMAIN17_PG_CONFIG), \
0698     SR(DOMAIN18_PG_CONFIG), \
0699     SR(DOMAIN19_PG_CONFIG), \
0700     SR(DOMAIN0_PG_STATUS), \
0701     SR(DOMAIN1_PG_STATUS), \
0702     SR(DOMAIN2_PG_STATUS), \
0703     SR(DOMAIN3_PG_STATUS), \
0704     SR(DOMAIN16_PG_STATUS), \
0705     SR(DOMAIN17_PG_STATUS), \
0706     SR(DOMAIN18_PG_STATUS), \
0707     SR(DOMAIN19_PG_STATUS), \
0708     SR(D1VGA_CONTROL), \
0709     SR(D2VGA_CONTROL), \
0710     SR(D3VGA_CONTROL), \
0711     SR(D4VGA_CONTROL), \
0712     SR(D5VGA_CONTROL), \
0713     SR(D6VGA_CONTROL), \
0714     SR(DC_IP_REQUEST_CNTL), \
0715     SR(AZALIA_AUDIO_DTO), \
0716     SR(AZALIA_CONTROLLER_CLOCK_GATING)
0717 
0718 static const struct dce_hwseq_registers hwseq_reg = {
0719         HWSEQ_DCN32_REG_LIST()
0720 };
0721 
0722 #define HWSEQ_DCN32_MASK_SH_LIST(mask_sh)\
0723     HWSEQ_DCN_MASK_SH_LIST(mask_sh), \
0724     HWS_SF(, DCHUBBUB_GLOBAL_TIMER_CNTL, DCHUBBUB_GLOBAL_TIMER_REFDIV, mask_sh), \
0725     HWS_SF(, DOMAIN0_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
0726     HWS_SF(, DOMAIN0_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
0727     HWS_SF(, DOMAIN1_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
0728     HWS_SF(, DOMAIN1_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
0729     HWS_SF(, DOMAIN2_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
0730     HWS_SF(, DOMAIN2_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
0731     HWS_SF(, DOMAIN3_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
0732     HWS_SF(, DOMAIN3_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
0733     HWS_SF(, DOMAIN16_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
0734     HWS_SF(, DOMAIN16_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
0735     HWS_SF(, DOMAIN17_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
0736     HWS_SF(, DOMAIN17_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
0737     HWS_SF(, DOMAIN18_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
0738     HWS_SF(, DOMAIN18_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
0739     HWS_SF(, DOMAIN19_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \
0740     HWS_SF(, DOMAIN19_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \
0741     HWS_SF(, DOMAIN0_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
0742     HWS_SF(, DOMAIN1_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
0743     HWS_SF(, DOMAIN2_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
0744     HWS_SF(, DOMAIN3_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
0745     HWS_SF(, DOMAIN16_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
0746     HWS_SF(, DOMAIN17_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
0747     HWS_SF(, DOMAIN18_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
0748     HWS_SF(, DOMAIN19_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \
0749     HWS_SF(, DC_IP_REQUEST_CNTL, IP_REQUEST_EN, mask_sh), \
0750     HWS_SF(, AZALIA_AUDIO_DTO, AZALIA_AUDIO_DTO_MODULE, mask_sh), \
0751     HWS_SF(, HPO_TOP_CLOCK_CONTROL, HPO_HDMISTREAMCLK_G_GATE_DIS, mask_sh), \
0752     HWS_SF(, ODM_MEM_PWR_CTRL3, ODM_MEM_UNASSIGNED_PWR_MODE, mask_sh), \
0753     HWS_SF(, ODM_MEM_PWR_CTRL3, ODM_MEM_VBLANK_PWR_MODE, mask_sh), \
0754     HWS_SF(, MMHUBBUB_MEM_PWR_CNTL, VGA_MEM_PWR_FORCE, mask_sh)
0755 
0756 static const struct dce_hwseq_shift hwseq_shift = {
0757         HWSEQ_DCN32_MASK_SH_LIST(__SHIFT)
0758 };
0759 
0760 static const struct dce_hwseq_mask hwseq_mask = {
0761         HWSEQ_DCN32_MASK_SH_LIST(_MASK)
0762 };
0763 #define vmid_regs(id)\
0764 [id] = {\
0765         DCN20_VMID_REG_LIST(id)\
0766 }
0767 
0768 static const struct dcn_vmid_registers vmid_regs[] = {
0769     vmid_regs(0),
0770     vmid_regs(1),
0771     vmid_regs(2),
0772     vmid_regs(3),
0773     vmid_regs(4),
0774     vmid_regs(5),
0775     vmid_regs(6),
0776     vmid_regs(7),
0777     vmid_regs(8),
0778     vmid_regs(9),
0779     vmid_regs(10),
0780     vmid_regs(11),
0781     vmid_regs(12),
0782     vmid_regs(13),
0783     vmid_regs(14),
0784     vmid_regs(15)
0785 };
0786 
0787 static const struct dcn20_vmid_shift vmid_shifts = {
0788         DCN20_VMID_MASK_SH_LIST(__SHIFT)
0789 };
0790 
0791 static const struct dcn20_vmid_mask vmid_masks = {
0792         DCN20_VMID_MASK_SH_LIST(_MASK)
0793 };
0794 
0795 static const struct resource_caps res_cap_dcn321 = {
0796     .num_timing_generator = 4,
0797     .num_opp = 4,
0798     .num_video_plane = 4,
0799     .num_audio = 5,
0800     .num_stream_encoder = 5,
0801     .num_hpo_dp_stream_encoder = 4,
0802     .num_hpo_dp_link_encoder = 2,
0803     .num_pll = 5,
0804     .num_dwb = 1,
0805     .num_ddc = 5,
0806     .num_vmid = 16,
0807     .num_mpc_3dlut = 4,
0808     .num_dsc = 4,
0809 };
0810 
0811 static const struct dc_plane_cap plane_cap = {
0812     .type = DC_PLANE_TYPE_DCN_UNIVERSAL,
0813     .blends_with_above = true,
0814     .blends_with_below = true,
0815     .per_pixel_alpha = true,
0816 
0817     .pixel_format_support = {
0818             .argb8888 = true,
0819             .nv12 = true,
0820             .fp16 = true,
0821             .p010 = true,
0822             .ayuv = false,
0823     },
0824 
0825     .max_upscale_factor = {
0826             .argb8888 = 16000,
0827             .nv12 = 16000,
0828             .fp16 = 16000
0829     },
0830 
0831     // 6:1 downscaling ratio: 1000/6 = 166.666
0832     .max_downscale_factor = {
0833             .argb8888 = 167,
0834             .nv12 = 167,
0835             .fp16 = 167
0836     },
0837     64,
0838     64
0839 };
0840 
0841 static const struct dc_debug_options debug_defaults_drv = {
0842     .disable_dmcu = true,
0843     .force_abm_enable = false,
0844     .timing_trace = false,
0845     .clock_trace = true,
0846     .disable_pplib_clock_request = false,
0847     .pipe_split_policy = MPC_SPLIT_AVOID,
0848     .force_single_disp_pipe_split = false,
0849     .disable_dcc = DCC_ENABLE,
0850     .vsr_support = true,
0851     .performance_trace = false,
0852     .max_downscale_src_width = 7680,/*upto 8K*/
0853     .disable_pplib_wm_range = false,
0854     .scl_reset_length10 = true,
0855     .sanity_checks = false,
0856     .underflow_assert_delay_us = 0xFFFFFFFF,
0857     .dwb_fi_phase = -1, // -1 = disable,
0858     .dmub_command_table = true,
0859     .enable_mem_low_power = {
0860         .bits = {
0861             .vga = false,
0862             .i2c = false,
0863             .dmcu = false, // This is previously known to cause hang on S3 cycles if enabled
0864             .dscl = false,
0865             .cm = false,
0866             .mpc = false,
0867             .optc = true,
0868         }
0869     },
0870     .use_max_lb = true,
0871     .force_disable_subvp = false,
0872     .exit_idle_opt_for_cursor_updates = true,
0873     .enable_single_display_2to1_odm_policy = true,
0874     .enable_dp_dig_pixel_rate_div_policy = 1,
0875     .allow_sw_cursor_fallback = false,
0876 };
0877 
0878 static const struct dc_debug_options debug_defaults_diags = {
0879     .disable_dmcu = true,
0880     .force_abm_enable = false,
0881     .timing_trace = true,
0882     .clock_trace = true,
0883     .disable_dpp_power_gate = true,
0884     .disable_hubp_power_gate = true,
0885     .disable_dsc_power_gate = true,
0886     .disable_clock_gate = true,
0887     .disable_pplib_clock_request = true,
0888     .disable_pplib_wm_range = true,
0889     .disable_stutter = false,
0890     .scl_reset_length10 = true,
0891     .dwb_fi_phase = -1, // -1 = disable
0892     .dmub_command_table = true,
0893     .enable_tri_buf = true,
0894     .use_max_lb = true,
0895     .force_disable_subvp = true
0896 };
0897 
0898 
0899 static struct dce_aux *dcn321_aux_engine_create(
0900     struct dc_context *ctx,
0901     uint32_t inst)
0902 {
0903     struct aux_engine_dce110 *aux_engine =
0904         kzalloc(sizeof(struct aux_engine_dce110), GFP_KERNEL);
0905 
0906     if (!aux_engine)
0907         return NULL;
0908 
0909     dce110_aux_engine_construct(aux_engine, ctx, inst,
0910                     SW_AUX_TIMEOUT_PERIOD_MULTIPLIER * AUX_TIMEOUT_PERIOD,
0911                     &aux_engine_regs[inst],
0912                     &aux_mask,
0913                     &aux_shift,
0914                     ctx->dc->caps.extended_aux_timeout_support);
0915 
0916     return &aux_engine->base;
0917 }
0918 #define i2c_inst_regs(id) { I2C_HW_ENGINE_COMMON_REG_LIST_DCN30(id) }
0919 
0920 static const struct dce_i2c_registers i2c_hw_regs[] = {
0921         i2c_inst_regs(1),
0922         i2c_inst_regs(2),
0923         i2c_inst_regs(3),
0924         i2c_inst_regs(4),
0925         i2c_inst_regs(5),
0926 };
0927 
0928 static const struct dce_i2c_shift i2c_shifts = {
0929         I2C_COMMON_MASK_SH_LIST_DCN30(__SHIFT)
0930 };
0931 
0932 static const struct dce_i2c_mask i2c_masks = {
0933         I2C_COMMON_MASK_SH_LIST_DCN30(_MASK)
0934 };
0935 
0936 static struct dce_i2c_hw *dcn321_i2c_hw_create(
0937     struct dc_context *ctx,
0938     uint32_t inst)
0939 {
0940     struct dce_i2c_hw *dce_i2c_hw =
0941         kzalloc(sizeof(struct dce_i2c_hw), GFP_KERNEL);
0942 
0943     if (!dce_i2c_hw)
0944         return NULL;
0945 
0946     dcn2_i2c_hw_construct(dce_i2c_hw, ctx, inst,
0947                     &i2c_hw_regs[inst], &i2c_shifts, &i2c_masks);
0948 
0949     return dce_i2c_hw;
0950 }
0951 
0952 static struct clock_source *dcn321_clock_source_create(
0953         struct dc_context *ctx,
0954         struct dc_bios *bios,
0955         enum clock_source_id id,
0956         const struct dce110_clk_src_regs *regs,
0957         bool dp_clk_src)
0958 {
0959     struct dce110_clk_src *clk_src =
0960         kzalloc(sizeof(struct dce110_clk_src), GFP_KERNEL);
0961 
0962     if (!clk_src)
0963         return NULL;
0964 
0965     if (dcn31_clk_src_construct(clk_src, ctx, bios, id,
0966             regs, &cs_shift, &cs_mask)) {
0967         clk_src->base.dp_clk_src = dp_clk_src;
0968         return &clk_src->base;
0969     }
0970 
0971     BREAK_TO_DEBUGGER();
0972     return NULL;
0973 }
0974 
0975 static struct hubbub *dcn321_hubbub_create(struct dc_context *ctx)
0976 {
0977     int i;
0978 
0979     struct dcn20_hubbub *hubbub2 = kzalloc(sizeof(struct dcn20_hubbub),
0980                       GFP_KERNEL);
0981 
0982     if (!hubbub2)
0983         return NULL;
0984 
0985     hubbub32_construct(hubbub2, ctx,
0986             &hubbub_reg,
0987             &hubbub_shift,
0988             &hubbub_mask,
0989             ctx->dc->dml.ip.det_buffer_size_kbytes,
0990             ctx->dc->dml.ip.pixel_chunk_size_kbytes,
0991             ctx->dc->dml.ip.config_return_buffer_size_in_kbytes);
0992 
0993 
0994     for (i = 0; i < res_cap_dcn321.num_vmid; i++) {
0995         struct dcn20_vmid *vmid = &hubbub2->vmid[i];
0996 
0997         vmid->ctx = ctx;
0998 
0999         vmid->regs = &vmid_regs[i];
1000         vmid->shifts = &vmid_shifts;
1001         vmid->masks = &vmid_masks;
1002     }
1003 
1004     return &hubbub2->base;
1005 }
1006 
1007 static struct hubp *dcn321_hubp_create(
1008     struct dc_context *ctx,
1009     uint32_t inst)
1010 {
1011     struct dcn20_hubp *hubp2 =
1012         kzalloc(sizeof(struct dcn20_hubp), GFP_KERNEL);
1013 
1014     if (!hubp2)
1015         return NULL;
1016 
1017     if (hubp32_construct(hubp2, ctx, inst,
1018             &hubp_regs[inst], &hubp_shift, &hubp_mask))
1019         return &hubp2->base;
1020 
1021     BREAK_TO_DEBUGGER();
1022     kfree(hubp2);
1023     return NULL;
1024 }
1025 
1026 static void dcn321_dpp_destroy(struct dpp **dpp)
1027 {
1028     kfree(TO_DCN30_DPP(*dpp));
1029     *dpp = NULL;
1030 }
1031 
1032 static struct dpp *dcn321_dpp_create(
1033     struct dc_context *ctx,
1034     uint32_t inst)
1035 {
1036     struct dcn3_dpp *dpp3 =
1037         kzalloc(sizeof(struct dcn3_dpp), GFP_KERNEL);
1038 
1039     if (!dpp3)
1040         return NULL;
1041 
1042     if (dpp32_construct(dpp3, ctx, inst,
1043             &dpp_regs[inst], &tf_shift, &tf_mask))
1044         return &dpp3->base;
1045 
1046     BREAK_TO_DEBUGGER();
1047     kfree(dpp3);
1048     return NULL;
1049 }
1050 
1051 static struct mpc *dcn321_mpc_create(
1052         struct dc_context *ctx,
1053         int num_mpcc,
1054         int num_rmu)
1055 {
1056     struct dcn30_mpc *mpc30 = kzalloc(sizeof(struct dcn30_mpc),
1057                       GFP_KERNEL);
1058 
1059     if (!mpc30)
1060         return NULL;
1061 
1062     dcn32_mpc_construct(mpc30, ctx,
1063             &mpc_regs,
1064             &mpc_shift,
1065             &mpc_mask,
1066             num_mpcc,
1067             num_rmu);
1068 
1069     return &mpc30->base;
1070 }
1071 
1072 static struct output_pixel_processor *dcn321_opp_create(
1073     struct dc_context *ctx, uint32_t inst)
1074 {
1075     struct dcn20_opp *opp2 =
1076         kzalloc(sizeof(struct dcn20_opp), GFP_KERNEL);
1077 
1078     if (!opp2) {
1079         BREAK_TO_DEBUGGER();
1080         return NULL;
1081     }
1082 
1083     dcn20_opp_construct(opp2, ctx, inst,
1084             &opp_regs[inst], &opp_shift, &opp_mask);
1085     return &opp2->base;
1086 }
1087 
1088 
1089 static struct timing_generator *dcn321_timing_generator_create(
1090         struct dc_context *ctx,
1091         uint32_t instance)
1092 {
1093     struct optc *tgn10 =
1094         kzalloc(sizeof(struct optc), GFP_KERNEL);
1095 
1096     if (!tgn10)
1097         return NULL;
1098 
1099     tgn10->base.inst = instance;
1100     tgn10->base.ctx = ctx;
1101 
1102     tgn10->tg_regs = &optc_regs[instance];
1103     tgn10->tg_shift = &optc_shift;
1104     tgn10->tg_mask = &optc_mask;
1105 
1106     dcn32_timing_generator_init(tgn10);
1107 
1108     return &tgn10->base;
1109 }
1110 
1111 static const struct encoder_feature_support link_enc_feature = {
1112         .max_hdmi_deep_color = COLOR_DEPTH_121212,
1113         .max_hdmi_pixel_clock = 600000,
1114         .hdmi_ycbcr420_supported = true,
1115         .dp_ycbcr420_supported = true,
1116         .fec_supported = true,
1117         .flags.bits.IS_HBR2_CAPABLE = true,
1118         .flags.bits.IS_HBR3_CAPABLE = true,
1119         .flags.bits.IS_TPS3_CAPABLE = true,
1120         .flags.bits.IS_TPS4_CAPABLE = true
1121 };
1122 
1123 static struct link_encoder *dcn321_link_encoder_create(
1124     struct dc_context *ctx,
1125     const struct encoder_init_data *enc_init_data)
1126 {
1127     struct dcn20_link_encoder *enc20 =
1128         kzalloc(sizeof(struct dcn20_link_encoder), GFP_KERNEL);
1129 
1130     if (!enc20)
1131         return NULL;
1132 
1133     dcn321_link_encoder_construct(enc20,
1134             enc_init_data,
1135             &link_enc_feature,
1136             &link_enc_regs[enc_init_data->transmitter],
1137             &link_enc_aux_regs[enc_init_data->channel - 1],
1138             &link_enc_hpd_regs[enc_init_data->hpd_source],
1139             &le_shift,
1140             &le_mask);
1141 
1142     return &enc20->enc10.base;
1143 }
1144 
1145 static void read_dce_straps(
1146     struct dc_context *ctx,
1147     struct resource_straps *straps)
1148 {
1149     generic_reg_get(ctx, regDC_PINSTRAPS + BASE(regDC_PINSTRAPS_BASE_IDX),
1150         FN(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO), &straps->dc_pinstraps_audio);
1151 
1152 }
1153 
1154 static struct audio *dcn321_create_audio(
1155         struct dc_context *ctx, unsigned int inst)
1156 {
1157     return dce_audio_create(ctx, inst,
1158             &audio_regs[inst], &audio_shift, &audio_mask);
1159 }
1160 
1161 static struct vpg *dcn321_vpg_create(
1162     struct dc_context *ctx,
1163     uint32_t inst)
1164 {
1165     struct dcn30_vpg *vpg3 = kzalloc(sizeof(struct dcn30_vpg), GFP_KERNEL);
1166 
1167     if (!vpg3)
1168         return NULL;
1169 
1170     vpg3_construct(vpg3, ctx, inst,
1171             &vpg_regs[inst],
1172             &vpg_shift,
1173             &vpg_mask);
1174 
1175     return &vpg3->base;
1176 }
1177 
1178 static struct afmt *dcn321_afmt_create(
1179     struct dc_context *ctx,
1180     uint32_t inst)
1181 {
1182     struct dcn30_afmt *afmt3 = kzalloc(sizeof(struct dcn30_afmt), GFP_KERNEL);
1183 
1184     if (!afmt3)
1185         return NULL;
1186 
1187     afmt3_construct(afmt3, ctx, inst,
1188             &afmt_regs[inst],
1189             &afmt_shift,
1190             &afmt_mask);
1191 
1192     return &afmt3->base;
1193 }
1194 
1195 static struct apg *dcn321_apg_create(
1196     struct dc_context *ctx,
1197     uint32_t inst)
1198 {
1199     struct dcn31_apg *apg31 = kzalloc(sizeof(struct dcn31_apg), GFP_KERNEL);
1200 
1201     if (!apg31)
1202         return NULL;
1203 
1204     apg31_construct(apg31, ctx, inst,
1205             &apg_regs[inst],
1206             &apg_shift,
1207             &apg_mask);
1208 
1209     return &apg31->base;
1210 }
1211 
1212 static struct stream_encoder *dcn321_stream_encoder_create(
1213     enum engine_id eng_id,
1214     struct dc_context *ctx)
1215 {
1216     struct dcn10_stream_encoder *enc1;
1217     struct vpg *vpg;
1218     struct afmt *afmt;
1219     int vpg_inst;
1220     int afmt_inst;
1221 
1222     /* Mapping of VPG, AFMT, DME register blocks to DIO block instance */
1223     if (eng_id <= ENGINE_ID_DIGF) {
1224         vpg_inst = eng_id;
1225         afmt_inst = eng_id;
1226     } else
1227         return NULL;
1228 
1229     enc1 = kzalloc(sizeof(struct dcn10_stream_encoder), GFP_KERNEL);
1230     vpg = dcn321_vpg_create(ctx, vpg_inst);
1231     afmt = dcn321_afmt_create(ctx, afmt_inst);
1232 
1233     if (!enc1 || !vpg || !afmt) {
1234         kfree(enc1);
1235         kfree(vpg);
1236         kfree(afmt);
1237         return NULL;
1238     }
1239 
1240     dcn32_dio_stream_encoder_construct(enc1, ctx, ctx->dc_bios,
1241                     eng_id, vpg, afmt,
1242                     &stream_enc_regs[eng_id],
1243                     &se_shift, &se_mask);
1244 
1245     return &enc1->base;
1246 }
1247 
1248 static struct hpo_dp_stream_encoder *dcn321_hpo_dp_stream_encoder_create(
1249     enum engine_id eng_id,
1250     struct dc_context *ctx)
1251 {
1252     struct dcn31_hpo_dp_stream_encoder *hpo_dp_enc31;
1253     struct vpg *vpg;
1254     struct apg *apg;
1255     uint32_t hpo_dp_inst;
1256     uint32_t vpg_inst;
1257     uint32_t apg_inst;
1258 
1259     ASSERT((eng_id >= ENGINE_ID_HPO_DP_0) && (eng_id <= ENGINE_ID_HPO_DP_3));
1260     hpo_dp_inst = eng_id - ENGINE_ID_HPO_DP_0;
1261 
1262     /* Mapping of VPG register blocks to HPO DP block instance:
1263      * VPG[6] -> HPO_DP[0]
1264      * VPG[7] -> HPO_DP[1]
1265      * VPG[8] -> HPO_DP[2]
1266      * VPG[9] -> HPO_DP[3]
1267      */
1268     vpg_inst = hpo_dp_inst + 6;
1269 
1270     /* Mapping of APG register blocks to HPO DP block instance:
1271      * APG[0] -> HPO_DP[0]
1272      * APG[1] -> HPO_DP[1]
1273      * APG[2] -> HPO_DP[2]
1274      * APG[3] -> HPO_DP[3]
1275      */
1276     apg_inst = hpo_dp_inst;
1277 
1278     /* allocate HPO stream encoder and create VPG sub-block */
1279     hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_stream_encoder), GFP_KERNEL);
1280     vpg = dcn321_vpg_create(ctx, vpg_inst);
1281     apg = dcn321_apg_create(ctx, apg_inst);
1282 
1283     if (!hpo_dp_enc31 || !vpg || !apg) {
1284         kfree(hpo_dp_enc31);
1285         kfree(vpg);
1286         kfree(apg);
1287         return NULL;
1288     }
1289 
1290     dcn31_hpo_dp_stream_encoder_construct(hpo_dp_enc31, ctx, ctx->dc_bios,
1291                     hpo_dp_inst, eng_id, vpg, apg,
1292                     &hpo_dp_stream_enc_regs[hpo_dp_inst],
1293                     &hpo_dp_se_shift, &hpo_dp_se_mask);
1294 
1295     return &hpo_dp_enc31->base;
1296 }
1297 
1298 static struct hpo_dp_link_encoder *dcn321_hpo_dp_link_encoder_create(
1299     uint8_t inst,
1300     struct dc_context *ctx)
1301 {
1302     struct dcn31_hpo_dp_link_encoder *hpo_dp_enc31;
1303 
1304     /* allocate HPO link encoder */
1305     hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_link_encoder), GFP_KERNEL);
1306 
1307     hpo_dp_link_encoder32_construct(hpo_dp_enc31, ctx, inst,
1308                     &hpo_dp_link_enc_regs[inst],
1309                     &hpo_dp_le_shift, &hpo_dp_le_mask);
1310 
1311     return &hpo_dp_enc31->base;
1312 }
1313 
1314 static struct dce_hwseq *dcn321_hwseq_create(
1315     struct dc_context *ctx)
1316 {
1317     struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL);
1318 
1319     if (hws) {
1320         hws->ctx = ctx;
1321         hws->regs = &hwseq_reg;
1322         hws->shifts = &hwseq_shift;
1323         hws->masks = &hwseq_mask;
1324     }
1325     return hws;
1326 }
1327 static const struct resource_create_funcs res_create_funcs = {
1328     .read_dce_straps = read_dce_straps,
1329     .create_audio = dcn321_create_audio,
1330     .create_stream_encoder = dcn321_stream_encoder_create,
1331     .create_hpo_dp_stream_encoder = dcn321_hpo_dp_stream_encoder_create,
1332     .create_hpo_dp_link_encoder = dcn321_hpo_dp_link_encoder_create,
1333     .create_hwseq = dcn321_hwseq_create,
1334 };
1335 
1336 static const struct resource_create_funcs res_create_maximus_funcs = {
1337     .read_dce_straps = NULL,
1338     .create_audio = NULL,
1339     .create_stream_encoder = NULL,
1340     .create_hpo_dp_stream_encoder = dcn321_hpo_dp_stream_encoder_create,
1341     .create_hpo_dp_link_encoder = dcn321_hpo_dp_link_encoder_create,
1342     .create_hwseq = dcn321_hwseq_create,
1343 };
1344 
1345 static void dcn321_resource_destruct(struct dcn321_resource_pool *pool)
1346 {
1347     unsigned int i;
1348 
1349     for (i = 0; i < pool->base.stream_enc_count; i++) {
1350         if (pool->base.stream_enc[i] != NULL) {
1351             if (pool->base.stream_enc[i]->vpg != NULL) {
1352                 kfree(DCN30_VPG_FROM_VPG(pool->base.stream_enc[i]->vpg));
1353                 pool->base.stream_enc[i]->vpg = NULL;
1354             }
1355             if (pool->base.stream_enc[i]->afmt != NULL) {
1356                 kfree(DCN30_AFMT_FROM_AFMT(pool->base.stream_enc[i]->afmt));
1357                 pool->base.stream_enc[i]->afmt = NULL;
1358             }
1359             kfree(DCN10STRENC_FROM_STRENC(pool->base.stream_enc[i]));
1360             pool->base.stream_enc[i] = NULL;
1361         }
1362     }
1363 
1364     for (i = 0; i < pool->base.hpo_dp_stream_enc_count; i++) {
1365         if (pool->base.hpo_dp_stream_enc[i] != NULL) {
1366             if (pool->base.hpo_dp_stream_enc[i]->vpg != NULL) {
1367                 kfree(DCN30_VPG_FROM_VPG(pool->base.hpo_dp_stream_enc[i]->vpg));
1368                 pool->base.hpo_dp_stream_enc[i]->vpg = NULL;
1369             }
1370             if (pool->base.hpo_dp_stream_enc[i]->apg != NULL) {
1371                 kfree(DCN31_APG_FROM_APG(pool->base.hpo_dp_stream_enc[i]->apg));
1372                 pool->base.hpo_dp_stream_enc[i]->apg = NULL;
1373             }
1374             kfree(DCN3_1_HPO_DP_STREAM_ENC_FROM_HPO_STREAM_ENC(pool->base.hpo_dp_stream_enc[i]));
1375             pool->base.hpo_dp_stream_enc[i] = NULL;
1376         }
1377     }
1378 
1379     for (i = 0; i < pool->base.hpo_dp_link_enc_count; i++) {
1380         if (pool->base.hpo_dp_link_enc[i] != NULL) {
1381             kfree(DCN3_1_HPO_DP_LINK_ENC_FROM_HPO_LINK_ENC(pool->base.hpo_dp_link_enc[i]));
1382             pool->base.hpo_dp_link_enc[i] = NULL;
1383         }
1384     }
1385 
1386     for (i = 0; i < pool->base.res_cap->num_dsc; i++) {
1387         if (pool->base.dscs[i] != NULL)
1388             dcn20_dsc_destroy(&pool->base.dscs[i]);
1389     }
1390 
1391     if (pool->base.mpc != NULL) {
1392         kfree(TO_DCN20_MPC(pool->base.mpc));
1393         pool->base.mpc = NULL;
1394     }
1395     if (pool->base.hubbub != NULL) {
1396         kfree(TO_DCN20_HUBBUB(pool->base.hubbub));
1397         pool->base.hubbub = NULL;
1398     }
1399     for (i = 0; i < pool->base.pipe_count; i++) {
1400         if (pool->base.dpps[i] != NULL)
1401             dcn321_dpp_destroy(&pool->base.dpps[i]);
1402 
1403         if (pool->base.ipps[i] != NULL)
1404             pool->base.ipps[i]->funcs->ipp_destroy(&pool->base.ipps[i]);
1405 
1406         if (pool->base.hubps[i] != NULL) {
1407             kfree(TO_DCN20_HUBP(pool->base.hubps[i]));
1408             pool->base.hubps[i] = NULL;
1409         }
1410 
1411         if (pool->base.irqs != NULL)
1412             dal_irq_service_destroy(&pool->base.irqs);
1413     }
1414 
1415     for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
1416         if (pool->base.engines[i] != NULL)
1417             dce110_engine_destroy(&pool->base.engines[i]);
1418         if (pool->base.hw_i2cs[i] != NULL) {
1419             kfree(pool->base.hw_i2cs[i]);
1420             pool->base.hw_i2cs[i] = NULL;
1421         }
1422         if (pool->base.sw_i2cs[i] != NULL) {
1423             kfree(pool->base.sw_i2cs[i]);
1424             pool->base.sw_i2cs[i] = NULL;
1425         }
1426     }
1427 
1428     for (i = 0; i < pool->base.res_cap->num_opp; i++) {
1429         if (pool->base.opps[i] != NULL)
1430             pool->base.opps[i]->funcs->opp_destroy(&pool->base.opps[i]);
1431     }
1432 
1433     for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) {
1434         if (pool->base.timing_generators[i] != NULL)    {
1435             kfree(DCN10TG_FROM_TG(pool->base.timing_generators[i]));
1436             pool->base.timing_generators[i] = NULL;
1437         }
1438     }
1439 
1440     for (i = 0; i < pool->base.res_cap->num_dwb; i++) {
1441         if (pool->base.dwbc[i] != NULL) {
1442             kfree(TO_DCN30_DWBC(pool->base.dwbc[i]));
1443             pool->base.dwbc[i] = NULL;
1444         }
1445         if (pool->base.mcif_wb[i] != NULL) {
1446             kfree(TO_DCN30_MMHUBBUB(pool->base.mcif_wb[i]));
1447             pool->base.mcif_wb[i] = NULL;
1448         }
1449     }
1450 
1451     for (i = 0; i < pool->base.audio_count; i++) {
1452         if (pool->base.audios[i])
1453             dce_aud_destroy(&pool->base.audios[i]);
1454     }
1455 
1456     for (i = 0; i < pool->base.clk_src_count; i++) {
1457         if (pool->base.clock_sources[i] != NULL) {
1458             dcn20_clock_source_destroy(&pool->base.clock_sources[i]);
1459             pool->base.clock_sources[i] = NULL;
1460         }
1461     }
1462 
1463     for (i = 0; i < pool->base.res_cap->num_mpc_3dlut; i++) {
1464         if (pool->base.mpc_lut[i] != NULL) {
1465             dc_3dlut_func_release(pool->base.mpc_lut[i]);
1466             pool->base.mpc_lut[i] = NULL;
1467         }
1468         if (pool->base.mpc_shaper[i] != NULL) {
1469             dc_transfer_func_release(pool->base.mpc_shaper[i]);
1470             pool->base.mpc_shaper[i] = NULL;
1471         }
1472     }
1473 
1474     if (pool->base.dp_clock_source != NULL) {
1475         dcn20_clock_source_destroy(&pool->base.dp_clock_source);
1476         pool->base.dp_clock_source = NULL;
1477     }
1478 
1479     for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) {
1480         if (pool->base.multiple_abms[i] != NULL)
1481             dce_abm_destroy(&pool->base.multiple_abms[i]);
1482     }
1483 
1484     if (pool->base.psr != NULL)
1485         dmub_psr_destroy(&pool->base.psr);
1486 
1487     if (pool->base.dccg != NULL)
1488         dcn_dccg_destroy(&pool->base.dccg);
1489 
1490     if (pool->base.oem_device != NULL)
1491         dal_ddc_service_destroy(&pool->base.oem_device);
1492 }
1493 
1494 
1495 static bool dcn321_dwbc_create(struct dc_context *ctx, struct resource_pool *pool)
1496 {
1497     int i;
1498     uint32_t dwb_count = pool->res_cap->num_dwb;
1499 
1500     for (i = 0; i < dwb_count; i++) {
1501         struct dcn30_dwbc *dwbc30 = kzalloc(sizeof(struct dcn30_dwbc),
1502                             GFP_KERNEL);
1503 
1504         if (!dwbc30) {
1505             dm_error("DC: failed to create dwbc30!\n");
1506             return false;
1507         }
1508 
1509         dcn30_dwbc_construct(dwbc30, ctx,
1510                 &dwbc30_regs[i],
1511                 &dwbc30_shift,
1512                 &dwbc30_mask,
1513                 i);
1514 
1515         pool->dwbc[i] = &dwbc30->base;
1516     }
1517     return true;
1518 }
1519 
1520 static bool dcn321_mmhubbub_create(struct dc_context *ctx, struct resource_pool *pool)
1521 {
1522     int i;
1523     uint32_t dwb_count = pool->res_cap->num_dwb;
1524 
1525     for (i = 0; i < dwb_count; i++) {
1526         struct dcn30_mmhubbub *mcif_wb30 = kzalloc(sizeof(struct dcn30_mmhubbub),
1527                             GFP_KERNEL);
1528 
1529         if (!mcif_wb30) {
1530             dm_error("DC: failed to create mcif_wb30!\n");
1531             return false;
1532         }
1533 
1534         dcn32_mmhubbub_construct(mcif_wb30, ctx,
1535                 &mcif_wb30_regs[i],
1536                 &mcif_wb30_shift,
1537                 &mcif_wb30_mask,
1538                 i);
1539 
1540         pool->mcif_wb[i] = &mcif_wb30->base;
1541     }
1542     return true;
1543 }
1544 
1545 static struct display_stream_compressor *dcn321_dsc_create(
1546     struct dc_context *ctx, uint32_t inst)
1547 {
1548     struct dcn20_dsc *dsc =
1549         kzalloc(sizeof(struct dcn20_dsc), GFP_KERNEL);
1550 
1551     if (!dsc) {
1552         BREAK_TO_DEBUGGER();
1553         return NULL;
1554     }
1555 
1556     dsc2_construct(dsc, ctx, inst, &dsc_regs[inst], &dsc_shift, &dsc_mask);
1557 
1558     dsc->max_image_width = 6016;
1559 
1560     return &dsc->base;
1561 }
1562 
1563 static void dcn321_destroy_resource_pool(struct resource_pool **pool)
1564 {
1565     struct dcn321_resource_pool *dcn321_pool = TO_DCN321_RES_POOL(*pool);
1566 
1567     dcn321_resource_destruct(dcn321_pool);
1568     kfree(dcn321_pool);
1569     *pool = NULL;
1570 }
1571 
1572 static struct dc_cap_funcs cap_funcs = {
1573     .get_dcc_compression_cap = dcn20_get_dcc_compression_cap
1574 };
1575 
1576 static void dcn321_update_bw_bounding_box(struct dc *dc, struct clk_bw_params *bw_params)
1577 {
1578     DC_FP_START();
1579     dcn321_update_bw_bounding_box_fpu(dc, bw_params);
1580     DC_FP_END();
1581 }
1582 
1583 static struct resource_funcs dcn321_res_pool_funcs = {
1584     .destroy = dcn321_destroy_resource_pool,
1585     .link_enc_create = dcn321_link_encoder_create,
1586     .link_enc_create_minimal = NULL,
1587     .panel_cntl_create = dcn32_panel_cntl_create,
1588     .validate_bandwidth = dcn32_validate_bandwidth,
1589     .calculate_wm_and_dlg = dcn32_calculate_wm_and_dlg,
1590     .populate_dml_pipes = dcn32_populate_dml_pipes_from_context,
1591     .acquire_idle_pipe_for_layer = dcn20_acquire_idle_pipe_for_layer,
1592     .add_stream_to_ctx = dcn30_add_stream_to_ctx,
1593     .add_dsc_to_stream_resource = dcn20_add_dsc_to_stream_resource,
1594     .remove_stream_from_ctx = dcn20_remove_stream_from_ctx,
1595     .populate_dml_writeback_from_context = dcn30_populate_dml_writeback_from_context,
1596     .set_mcif_arb_params = dcn30_set_mcif_arb_params,
1597     .find_first_free_match_stream_enc_for_link = dcn10_find_first_free_match_stream_enc_for_link,
1598     .acquire_post_bldn_3dlut = dcn32_acquire_post_bldn_3dlut,
1599     .release_post_bldn_3dlut = dcn32_release_post_bldn_3dlut,
1600     .update_bw_bounding_box = dcn321_update_bw_bounding_box,
1601     .patch_unknown_plane_state = dcn20_patch_unknown_plane_state,
1602     .update_soc_for_wm_a = dcn30_update_soc_for_wm_a,
1603     .add_phantom_pipes = dcn32_add_phantom_pipes,
1604     .remove_phantom_pipes = dcn32_remove_phantom_pipes,
1605 };
1606 
1607 
1608 static bool dcn321_resource_construct(
1609     uint8_t num_virtual_links,
1610     struct dc *dc,
1611     struct dcn321_resource_pool *pool)
1612 {
1613     int i, j;
1614     struct dc_context *ctx = dc->ctx;
1615     struct irq_service_init_data init_data;
1616     struct ddc_service_init_data ddc_init_data = {0};
1617     uint32_t pipe_fuses = 0;
1618     uint32_t num_pipes  = 4;
1619 
1620     ctx->dc_bios->regs = &bios_regs;
1621 
1622     pool->base.res_cap = &res_cap_dcn321;
1623     /* max number of pipes for ASIC before checking for pipe fuses */
1624     num_pipes  = pool->base.res_cap->num_timing_generator;
1625     pipe_fuses = REG_READ(CC_DC_PIPE_DIS);
1626 
1627     for (i = 0; i < pool->base.res_cap->num_timing_generator; i++)
1628         if (pipe_fuses & 1 << i)
1629             num_pipes--;
1630 
1631     if (pipe_fuses & 1)
1632         ASSERT(0); //Unexpected - Pipe 0 should always be fully functional!
1633 
1634     if (pipe_fuses & CC_DC_PIPE_DIS__DC_FULL_DIS_MASK)
1635         ASSERT(0); //Entire DCN is harvested!
1636 
1637     /* within dml lib, initial value is hard coded, if ASIC pipe is fused, the
1638      * value will be changed, update max_num_dpp and max_num_otg for dml.
1639      */
1640     dcn3_21_ip.max_num_dpp = num_pipes;
1641     dcn3_21_ip.max_num_otg = num_pipes;
1642 
1643     pool->base.funcs = &dcn321_res_pool_funcs;
1644 
1645     /*************************************************
1646      *  Resource + asic cap harcoding                *
1647      *************************************************/
1648     pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
1649     pool->base.timing_generator_count = num_pipes;
1650     pool->base.pipe_count = num_pipes;
1651     pool->base.mpcc_count = num_pipes;
1652     dc->caps.max_downscale_ratio = 600;
1653     dc->caps.i2c_speed_in_khz = 100;
1654     dc->caps.i2c_speed_in_khz_hdcp = 100; /*1.4 w/a applied by default*/
1655     /* TODO: Bring max cursor size back to 256 after subvp cursor corruption is fixed*/
1656     dc->caps.max_cursor_size = 64;
1657     dc->caps.min_horizontal_blanking_period = 80;
1658     dc->caps.dmdata_alloc_size = 2048;
1659     dc->caps.mall_size_per_mem_channel = 0;
1660     dc->caps.mall_size_total = 0;
1661     dc->caps.cursor_cache_size = dc->caps.max_cursor_size * dc->caps.max_cursor_size * 8;
1662     dc->caps.cache_line_size = 64;
1663     dc->caps.cache_num_ways = 16;
1664     dc->caps.max_cab_allocation_bytes = 33554432; // 32MB = 1024 * 1024 * 32
1665     dc->caps.subvp_fw_processing_delay_us = 15;
1666     dc->caps.subvp_prefetch_end_to_mall_start_us = 15;
1667     dc->caps.subvp_swath_height_margin_lines = 16;
1668     dc->caps.subvp_pstate_allow_width_us = 20;
1669     dc->caps.subvp_vertical_int_margin_us = 30;
1670     dc->caps.max_slave_planes = 1;
1671     dc->caps.max_slave_yuv_planes = 1;
1672     dc->caps.max_slave_rgb_planes = 1;
1673     dc->caps.post_blend_color_processing = true;
1674     dc->caps.force_dp_tps4_for_cp2520 = true;
1675     dc->caps.dp_hpo = true;
1676     dc->caps.dp_hdmi21_pcon_support = true;
1677     dc->caps.edp_dsc_support = true;
1678     dc->caps.extended_aux_timeout_support = true;
1679     dc->caps.dmcub_support = true;
1680 
1681     /* Color pipeline capabilities */
1682     dc->caps.color.dpp.dcn_arch = 1;
1683     dc->caps.color.dpp.input_lut_shared = 0;
1684     dc->caps.color.dpp.icsc = 1;
1685     dc->caps.color.dpp.dgam_ram = 0; // must use gamma_corr
1686     dc->caps.color.dpp.dgam_rom_caps.srgb = 1;
1687     dc->caps.color.dpp.dgam_rom_caps.bt2020 = 1;
1688     dc->caps.color.dpp.dgam_rom_caps.gamma2_2 = 1;
1689     dc->caps.color.dpp.dgam_rom_caps.pq = 1;
1690     dc->caps.color.dpp.dgam_rom_caps.hlg = 1;
1691     dc->caps.color.dpp.post_csc = 1;
1692     dc->caps.color.dpp.gamma_corr = 1;
1693     dc->caps.color.dpp.dgam_rom_for_yuv = 0;
1694 
1695     dc->caps.color.dpp.hw_3d_lut = 1;
1696     dc->caps.color.dpp.ogam_ram = 1;
1697     // no OGAM ROM on DCN2 and later ASICs
1698     dc->caps.color.dpp.ogam_rom_caps.srgb = 0;
1699     dc->caps.color.dpp.ogam_rom_caps.bt2020 = 0;
1700     dc->caps.color.dpp.ogam_rom_caps.gamma2_2 = 0;
1701     dc->caps.color.dpp.ogam_rom_caps.pq = 0;
1702     dc->caps.color.dpp.ogam_rom_caps.hlg = 0;
1703     dc->caps.color.dpp.ocsc = 0;
1704 
1705     dc->caps.color.mpc.gamut_remap = 1;
1706     dc->caps.color.mpc.num_3dluts = pool->base.res_cap->num_mpc_3dlut; //4, configurable to be before or after BLND in MPCC
1707     dc->caps.color.mpc.ogam_ram = 1;
1708     dc->caps.color.mpc.ogam_rom_caps.srgb = 0;
1709     dc->caps.color.mpc.ogam_rom_caps.bt2020 = 0;
1710     dc->caps.color.mpc.ogam_rom_caps.gamma2_2 = 0;
1711     dc->caps.color.mpc.ogam_rom_caps.pq = 0;
1712     dc->caps.color.mpc.ogam_rom_caps.hlg = 0;
1713     dc->caps.color.mpc.ocsc = 1;
1714 
1715     /* read VBIOS LTTPR caps */
1716     {
1717         if (ctx->dc_bios->funcs->get_lttpr_caps) {
1718             enum bp_result bp_query_result;
1719             uint8_t is_vbios_lttpr_enable = 0;
1720 
1721             bp_query_result = ctx->dc_bios->funcs->get_lttpr_caps(ctx->dc_bios, &is_vbios_lttpr_enable);
1722             dc->caps.vbios_lttpr_enable = (bp_query_result == BP_RESULT_OK) && !!is_vbios_lttpr_enable;
1723         }
1724 
1725         /* interop bit is implicit */
1726         {
1727             dc->caps.vbios_lttpr_aware = true;
1728         }
1729     }
1730 
1731     if (dc->ctx->dce_environment == DCE_ENV_PRODUCTION_DRV)
1732         dc->debug = debug_defaults_drv;
1733     else if (dc->ctx->dce_environment == DCE_ENV_FPGA_MAXIMUS) {
1734         dc->debug = debug_defaults_diags;
1735     } else
1736         dc->debug = debug_defaults_diags;
1737     // Init the vm_helper
1738     if (dc->vm_helper)
1739         vm_helper_init(dc->vm_helper, 16);
1740 
1741     /*************************************************
1742      *  Create resources                             *
1743      *************************************************/
1744 
1745     /* Clock Sources for Pixel Clock*/
1746     pool->base.clock_sources[DCN321_CLK_SRC_PLL0] =
1747             dcn321_clock_source_create(ctx, ctx->dc_bios,
1748                 CLOCK_SOURCE_COMBO_PHY_PLL0,
1749                 &clk_src_regs[0], false);
1750     pool->base.clock_sources[DCN321_CLK_SRC_PLL1] =
1751             dcn321_clock_source_create(ctx, ctx->dc_bios,
1752                 CLOCK_SOURCE_COMBO_PHY_PLL1,
1753                 &clk_src_regs[1], false);
1754     pool->base.clock_sources[DCN321_CLK_SRC_PLL2] =
1755             dcn321_clock_source_create(ctx, ctx->dc_bios,
1756                 CLOCK_SOURCE_COMBO_PHY_PLL2,
1757                 &clk_src_regs[2], false);
1758     pool->base.clock_sources[DCN321_CLK_SRC_PLL3] =
1759             dcn321_clock_source_create(ctx, ctx->dc_bios,
1760                 CLOCK_SOURCE_COMBO_PHY_PLL3,
1761                 &clk_src_regs[3], false);
1762     pool->base.clock_sources[DCN321_CLK_SRC_PLL4] =
1763             dcn321_clock_source_create(ctx, ctx->dc_bios,
1764                 CLOCK_SOURCE_COMBO_PHY_PLL4,
1765                 &clk_src_regs[4], false);
1766 
1767     pool->base.clk_src_count = DCN321_CLK_SRC_TOTAL;
1768 
1769     /* todo: not reuse phy_pll registers */
1770     pool->base.dp_clock_source =
1771             dcn321_clock_source_create(ctx, ctx->dc_bios,
1772                 CLOCK_SOURCE_ID_DP_DTO,
1773                 &clk_src_regs[0], true);
1774 
1775     for (i = 0; i < pool->base.clk_src_count; i++) {
1776         if (pool->base.clock_sources[i] == NULL) {
1777             dm_error("DC: failed to create clock sources!\n");
1778             BREAK_TO_DEBUGGER();
1779             goto create_fail;
1780         }
1781     }
1782 
1783     /* DCCG */
1784     pool->base.dccg = dccg32_create(ctx, &dccg_regs, &dccg_shift, &dccg_mask);
1785     if (pool->base.dccg == NULL) {
1786         dm_error("DC: failed to create dccg!\n");
1787         BREAK_TO_DEBUGGER();
1788         goto create_fail;
1789     }
1790 
1791     /* DML */
1792     if (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment))
1793         dml_init_instance(&dc->dml, &dcn3_21_soc, &dcn3_21_ip, DML_PROJECT_DCN32);
1794 
1795     /* IRQ Service */
1796     init_data.ctx = dc->ctx;
1797     pool->base.irqs = dal_irq_service_dcn32_create(&init_data);
1798     if (!pool->base.irqs)
1799         goto create_fail;
1800 
1801     /* HUBBUB */
1802     pool->base.hubbub = dcn321_hubbub_create(ctx);
1803     if (pool->base.hubbub == NULL) {
1804         BREAK_TO_DEBUGGER();
1805         dm_error("DC: failed to create hubbub!\n");
1806         goto create_fail;
1807     }
1808 
1809     /* HUBPs, DPPs, OPPs, TGs, ABMs */
1810     for (i = 0, j = 0; i < pool->base.res_cap->num_timing_generator; i++) {
1811 
1812         /* if pipe is disabled, skip instance of HW pipe,
1813          * i.e, skip ASIC register instance
1814          */
1815         if (pipe_fuses & 1 << i)
1816             continue;
1817 
1818         pool->base.hubps[j] = dcn321_hubp_create(ctx, i);
1819         if (pool->base.hubps[j] == NULL) {
1820             BREAK_TO_DEBUGGER();
1821             dm_error(
1822                 "DC: failed to create hubps!\n");
1823             goto create_fail;
1824         }
1825 
1826         pool->base.dpps[j] = dcn321_dpp_create(ctx, i);
1827         if (pool->base.dpps[j] == NULL) {
1828             BREAK_TO_DEBUGGER();
1829             dm_error(
1830                 "DC: failed to create dpps!\n");
1831             goto create_fail;
1832         }
1833 
1834         pool->base.opps[j] = dcn321_opp_create(ctx, i);
1835         if (pool->base.opps[j] == NULL) {
1836             BREAK_TO_DEBUGGER();
1837             dm_error(
1838                 "DC: failed to create output pixel processor!\n");
1839             goto create_fail;
1840         }
1841 
1842         pool->base.timing_generators[j] = dcn321_timing_generator_create(
1843                 ctx, i);
1844         if (pool->base.timing_generators[j] == NULL) {
1845             BREAK_TO_DEBUGGER();
1846             dm_error("DC: failed to create tg!\n");
1847             goto create_fail;
1848         }
1849 
1850         pool->base.multiple_abms[j] = dmub_abm_create(ctx,
1851                 &abm_regs[i],
1852                 &abm_shift,
1853                 &abm_mask);
1854         if (pool->base.multiple_abms[j] == NULL) {
1855             dm_error("DC: failed to create abm for pipe %d!\n", i);
1856             BREAK_TO_DEBUGGER();
1857             goto create_fail;
1858         }
1859 
1860         /* index for resource pool arrays for next valid pipe */
1861         j++;
1862     }
1863 
1864     /* PSR */
1865     pool->base.psr = dmub_psr_create(ctx);
1866     if (pool->base.psr == NULL) {
1867         dm_error("DC: failed to create psr obj!\n");
1868         BREAK_TO_DEBUGGER();
1869         goto create_fail;
1870     }
1871 
1872     /* MPCCs */
1873     pool->base.mpc = dcn321_mpc_create(ctx,  pool->base.res_cap->num_timing_generator, pool->base.res_cap->num_mpc_3dlut);
1874     if (pool->base.mpc == NULL) {
1875         BREAK_TO_DEBUGGER();
1876         dm_error("DC: failed to create mpc!\n");
1877         goto create_fail;
1878     }
1879 
1880     /* DSCs */
1881     for (i = 0; i < pool->base.res_cap->num_dsc; i++) {
1882         pool->base.dscs[i] = dcn321_dsc_create(ctx, i);
1883         if (pool->base.dscs[i] == NULL) {
1884             BREAK_TO_DEBUGGER();
1885             dm_error("DC: failed to create display stream compressor %d!\n", i);
1886             goto create_fail;
1887         }
1888     }
1889 
1890     /* DWB */
1891     if (!dcn321_dwbc_create(ctx, &pool->base)) {
1892         BREAK_TO_DEBUGGER();
1893         dm_error("DC: failed to create dwbc!\n");
1894         goto create_fail;
1895     }
1896 
1897     /* MMHUBBUB */
1898     if (!dcn321_mmhubbub_create(ctx, &pool->base)) {
1899         BREAK_TO_DEBUGGER();
1900         dm_error("DC: failed to create mcif_wb!\n");
1901         goto create_fail;
1902     }
1903 
1904     /* AUX and I2C */
1905     for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
1906         pool->base.engines[i] = dcn321_aux_engine_create(ctx, i);
1907         if (pool->base.engines[i] == NULL) {
1908             BREAK_TO_DEBUGGER();
1909             dm_error(
1910                 "DC:failed to create aux engine!!\n");
1911             goto create_fail;
1912         }
1913         pool->base.hw_i2cs[i] = dcn321_i2c_hw_create(ctx, i);
1914         if (pool->base.hw_i2cs[i] == NULL) {
1915             BREAK_TO_DEBUGGER();
1916             dm_error(
1917                 "DC:failed to create hw i2c!!\n");
1918             goto create_fail;
1919         }
1920         pool->base.sw_i2cs[i] = NULL;
1921     }
1922 
1923     /* Audio, HWSeq, Stream Encoders including HPO and virtual, MPC 3D LUTs */
1924     if (!resource_construct(num_virtual_links, dc, &pool->base,
1925             (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment) ?
1926             &res_create_funcs : &res_create_maximus_funcs)))
1927             goto create_fail;
1928 
1929     /* HW Sequencer init functions and Plane caps */
1930     dcn32_hw_sequencer_init_functions(dc);
1931 
1932     dc->caps.max_planes =  pool->base.pipe_count;
1933 
1934     for (i = 0; i < dc->caps.max_planes; ++i)
1935         dc->caps.planes[i] = plane_cap;
1936 
1937     dc->cap_funcs = cap_funcs;
1938 
1939     if (dc->ctx->dc_bios->fw_info.oem_i2c_present) {
1940         ddc_init_data.ctx = dc->ctx;
1941         ddc_init_data.link = NULL;
1942         ddc_init_data.id.id = dc->ctx->dc_bios->fw_info.oem_i2c_obj_id;
1943         ddc_init_data.id.enum_id = 0;
1944         ddc_init_data.id.type = OBJECT_TYPE_GENERIC;
1945         pool->base.oem_device = dal_ddc_service_create(&ddc_init_data);
1946     } else {
1947         pool->base.oem_device = NULL;
1948     }
1949 
1950     return true;
1951 
1952 create_fail:
1953 
1954     dcn321_resource_destruct(pool);
1955 
1956     return false;
1957 }
1958 
1959 struct resource_pool *dcn321_create_resource_pool(
1960         const struct dc_init_data *init_data,
1961         struct dc *dc)
1962 {
1963     struct dcn321_resource_pool *pool =
1964         kzalloc(sizeof(struct dcn321_resource_pool), GFP_KERNEL);
1965 
1966     if (!pool)
1967         return NULL;
1968 
1969     if (dcn321_resource_construct(init_data->num_virtual_links, dc, pool))
1970         return &pool->base;
1971 
1972     BREAK_TO_DEBUGGER();
1973     kfree(pool);
1974     return NULL;
1975 }