Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2019-2021 Advanced Micro Devices, Inc.
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial portions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0017  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020  * OTHER DEALINGS IN THE SOFTWARE.
0021  *
0022  * Authors: AMD
0023  *
0024  */
0025 
0026 
0027 #include "dm_services.h"
0028 #include "dc.h"
0029 
0030 #include "dcn301_init.h"
0031 
0032 #include "resource.h"
0033 #include "include/irq_service_interface.h"
0034 #include "dcn30/dcn30_resource.h"
0035 #include "dcn301_resource.h"
0036 
0037 #include "dcn20/dcn20_resource.h"
0038 
0039 #include "dcn10/dcn10_ipp.h"
0040 #include "dcn301/dcn301_hubbub.h"
0041 #include "dcn30/dcn30_mpc.h"
0042 #include "dcn30/dcn30_hubp.h"
0043 #include "irq/dcn30/irq_service_dcn30.h"
0044 #include "dcn30/dcn30_dpp.h"
0045 #include "dcn30/dcn30_optc.h"
0046 #include "dcn20/dcn20_hwseq.h"
0047 #include "dcn30/dcn30_hwseq.h"
0048 #include "dce110/dce110_hw_sequencer.h"
0049 #include "dcn30/dcn30_opp.h"
0050 #include "dcn20/dcn20_dsc.h"
0051 #include "dcn30/dcn30_vpg.h"
0052 #include "dcn30/dcn30_afmt.h"
0053 #include "dce/dce_clock_source.h"
0054 #include "dce/dce_audio.h"
0055 #include "dce/dce_hwseq.h"
0056 #include "clk_mgr.h"
0057 #include "virtual/virtual_stream_encoder.h"
0058 #include "dce110/dce110_resource.h"
0059 #include "dml/display_mode_vba.h"
0060 #include "dcn301/dcn301_dccg.h"
0061 #include "dcn10/dcn10_resource.h"
0062 #include "dcn30/dcn30_dio_stream_encoder.h"
0063 #include "dcn301/dcn301_dio_link_encoder.h"
0064 #include "dcn301_panel_cntl.h"
0065 
0066 #include "vangogh_ip_offset.h"
0067 
0068 #include "dcn30/dcn30_dwb.h"
0069 #include "dcn30/dcn30_mmhubbub.h"
0070 
0071 #include "dcn/dcn_3_0_1_offset.h"
0072 #include "dcn/dcn_3_0_1_sh_mask.h"
0073 
0074 #include "nbio/nbio_7_2_0_offset.h"
0075 
0076 #include "dpcs/dpcs_3_0_0_offset.h"
0077 #include "dpcs/dpcs_3_0_0_sh_mask.h"
0078 
0079 #include "reg_helper.h"
0080 #include "dce/dmub_abm.h"
0081 #include "dce/dce_aux.h"
0082 #include "dce/dce_i2c.h"
0083 
0084 #include "dml/dcn30/dcn30_fpu.h"
0085 
0086 #include "dml/dcn30/display_mode_vba_30.h"
0087 #include "dml/dcn301/dcn301_fpu.h"
0088 #include "vm_helper.h"
0089 #include "dcn20/dcn20_vmid.h"
0090 #include "amdgpu_socbb.h"
0091 
0092 #define TO_DCN301_RES_POOL(pool)\
0093     container_of(pool, struct dcn301_resource_pool, base)
0094 
0095 #define DC_LOGGER_INIT(logger)
0096 
0097 enum dcn301_clk_src_array_id {
0098     DCN301_CLK_SRC_PLL0,
0099     DCN301_CLK_SRC_PLL1,
0100     DCN301_CLK_SRC_PLL2,
0101     DCN301_CLK_SRC_PLL3,
0102     DCN301_CLK_SRC_TOTAL
0103 };
0104 
0105 /* begin *********************
0106  * macros to expend register list macro defined in HW object header file
0107  */
0108 
0109 /* DCN */
0110 /* TODO awful hack. fixup dcn20_dwb.h */
0111 #undef BASE_INNER
0112 #define BASE_INNER(seg) DCN_BASE__INST0_SEG ## seg
0113 
0114 #define BASE(seg) BASE_INNER(seg)
0115 
0116 #define SR(reg_name)\
0117         .reg_name = BASE(mm ## reg_name ## _BASE_IDX) +  \
0118                     mm ## reg_name
0119 
0120 #define SRI(reg_name, block, id)\
0121     .reg_name = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
0122                     mm ## block ## id ## _ ## reg_name
0123 
0124 #define SRI2(reg_name, block, id)\
0125     .reg_name = BASE(mm ## reg_name ## _BASE_IDX) + \
0126                     mm ## reg_name
0127 
0128 #define SRIR(var_name, reg_name, block, id)\
0129     .var_name = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
0130                     mm ## block ## id ## _ ## reg_name
0131 
0132 #define SRII(reg_name, block, id)\
0133     .reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
0134                     mm ## block ## id ## _ ## reg_name
0135 
0136 #define SRII2(reg_name_pre, reg_name_post, id)\
0137     .reg_name_pre ## _ ##  reg_name_post[id] = BASE(mm ## reg_name_pre \
0138             ## id ## _ ## reg_name_post ## _BASE_IDX) + \
0139             mm ## reg_name_pre ## id ## _ ## reg_name_post
0140 
0141 #define SRII_MPC_RMU(reg_name, block, id)\
0142     .RMU##_##reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
0143                     mm ## block ## id ## _ ## reg_name
0144 
0145 #define SRII_DWB(reg_name, temp_name, block, id)\
0146     .reg_name[id] = BASE(mm ## block ## id ## _ ## temp_name ## _BASE_IDX) + \
0147                     mm ## block ## id ## _ ## temp_name
0148 
0149 #define DCCG_SRII(reg_name, block, id)\
0150     .block ## _ ## reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
0151                     mm ## block ## id ## _ ## reg_name
0152 
0153 #define VUPDATE_SRII(reg_name, block, id)\
0154     .reg_name[id] = BASE(mm ## reg_name ## _ ## block ## id ## _BASE_IDX) + \
0155                     mm ## reg_name ## _ ## block ## id
0156 
0157 /* NBIO */
0158 #define NBIO_BASE_INNER(seg) \
0159     NBIO_BASE__INST0_SEG ## seg
0160 
0161 #define NBIO_BASE(seg) \
0162     NBIO_BASE_INNER(seg)
0163 
0164 #define NBIO_SR(reg_name)\
0165         .reg_name = NBIO_BASE(regBIF_BX0_ ## reg_name ## _BASE_IDX) + \
0166                     regBIF_BX0_ ## reg_name
0167 
0168 /* MMHUB */
0169 #define MMHUB_BASE_INNER(seg) \
0170     MMHUB_BASE__INST0_SEG ## seg
0171 
0172 #define MMHUB_BASE(seg) \
0173     MMHUB_BASE_INNER(seg)
0174 
0175 #define MMHUB_SR(reg_name)\
0176         .reg_name = MMHUB_BASE(regMM ## reg_name ## _BASE_IDX) + \
0177                     regMM ## reg_name
0178 
0179 /* CLOCK */
0180 #define CLK_BASE_INNER(seg) \
0181     CLK_BASE__INST0_SEG ## seg
0182 
0183 #define CLK_BASE(seg) \
0184     CLK_BASE_INNER(seg)
0185 
0186 #define CLK_SRI(reg_name, block, inst)\
0187     .reg_name = CLK_BASE(mm ## block ## _ ## inst ## _ ## reg_name ## _BASE_IDX) + \
0188                     mm ## block ## _ ## inst ## _ ## reg_name
0189 
0190 static const struct bios_registers bios_regs = {
0191         NBIO_SR(BIOS_SCRATCH_3),
0192         NBIO_SR(BIOS_SCRATCH_6)
0193 };
0194 
0195 #define clk_src_regs(index, pllid)\
0196 [index] = {\
0197     CS_COMMON_REG_LIST_DCN3_01(index, pllid),\
0198 }
0199 
0200 static const struct dce110_clk_src_regs clk_src_regs[] = {
0201     clk_src_regs(0, A),
0202     clk_src_regs(1, B),
0203     clk_src_regs(2, C),
0204     clk_src_regs(3, D)
0205 };
0206 
0207 static const struct dce110_clk_src_shift cs_shift = {
0208         CS_COMMON_MASK_SH_LIST_DCN2_0(__SHIFT)
0209 };
0210 
0211 static const struct dce110_clk_src_mask cs_mask = {
0212         CS_COMMON_MASK_SH_LIST_DCN2_0(_MASK)
0213 };
0214 
0215 #define abm_regs(id)\
0216 [id] = {\
0217         ABM_DCN301_REG_LIST(id)\
0218 }
0219 
0220 static const struct dce_abm_registers abm_regs[] = {
0221         abm_regs(0),
0222         abm_regs(1),
0223         abm_regs(2),
0224         abm_regs(3),
0225 };
0226 
0227 static const struct dce_abm_shift abm_shift = {
0228         ABM_MASK_SH_LIST_DCN30(__SHIFT)
0229 };
0230 
0231 static const struct dce_abm_mask abm_mask = {
0232         ABM_MASK_SH_LIST_DCN30(_MASK)
0233 };
0234 
0235 #define audio_regs(id)\
0236 [id] = {\
0237         AUD_COMMON_REG_LIST(id)\
0238 }
0239 
0240 static const struct dce_audio_registers audio_regs[] = {
0241     audio_regs(0),
0242     audio_regs(1),
0243     audio_regs(2),
0244     audio_regs(3),
0245     audio_regs(4),
0246     audio_regs(5),
0247     audio_regs(6)
0248 };
0249 
0250 #define DCE120_AUD_COMMON_MASK_SH_LIST(mask_sh)\
0251         SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_INDEX, AZALIA_ENDPOINT_REG_INDEX, mask_sh),\
0252         SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_DATA, AZALIA_ENDPOINT_REG_DATA, mask_sh),\
0253         AUD_COMMON_MASK_SH_LIST_BASE(mask_sh)
0254 
0255 static const struct dce_audio_shift audio_shift = {
0256         DCE120_AUD_COMMON_MASK_SH_LIST(__SHIFT)
0257 };
0258 
0259 static const struct dce_audio_mask audio_mask = {
0260         DCE120_AUD_COMMON_MASK_SH_LIST(_MASK)
0261 };
0262 
0263 #define vpg_regs(id)\
0264 [id] = {\
0265     VPG_DCN3_REG_LIST(id)\
0266 }
0267 
0268 static const struct dcn30_vpg_registers vpg_regs[] = {
0269     vpg_regs(0),
0270     vpg_regs(1),
0271     vpg_regs(2),
0272     vpg_regs(3),
0273 };
0274 
0275 static const struct dcn30_vpg_shift vpg_shift = {
0276     DCN3_VPG_MASK_SH_LIST(__SHIFT)
0277 };
0278 
0279 static const struct dcn30_vpg_mask vpg_mask = {
0280     DCN3_VPG_MASK_SH_LIST(_MASK)
0281 };
0282 
0283 #define afmt_regs(id)\
0284 [id] = {\
0285     AFMT_DCN3_REG_LIST(id)\
0286 }
0287 
0288 static const struct dcn30_afmt_registers afmt_regs[] = {
0289     afmt_regs(0),
0290     afmt_regs(1),
0291     afmt_regs(2),
0292     afmt_regs(3),
0293 };
0294 
0295 static const struct dcn30_afmt_shift afmt_shift = {
0296     DCN3_AFMT_MASK_SH_LIST(__SHIFT)
0297 };
0298 
0299 static const struct dcn30_afmt_mask afmt_mask = {
0300     DCN3_AFMT_MASK_SH_LIST(_MASK)
0301 };
0302 
0303 #define stream_enc_regs(id)\
0304 [id] = {\
0305     SE_DCN3_REG_LIST(id)\
0306 }
0307 
0308 static const struct dcn10_stream_enc_registers stream_enc_regs[] = {
0309     stream_enc_regs(0),
0310     stream_enc_regs(1),
0311     stream_enc_regs(2),
0312     stream_enc_regs(3),
0313 };
0314 
0315 static const struct dcn10_stream_encoder_shift se_shift = {
0316         SE_COMMON_MASK_SH_LIST_DCN30(__SHIFT)
0317 };
0318 
0319 static const struct dcn10_stream_encoder_mask se_mask = {
0320         SE_COMMON_MASK_SH_LIST_DCN30(_MASK)
0321 };
0322 
0323 
0324 #define aux_regs(id)\
0325 [id] = {\
0326     DCN2_AUX_REG_LIST(id)\
0327 }
0328 
0329 static const struct dcn10_link_enc_aux_registers link_enc_aux_regs[] = {
0330         aux_regs(0),
0331         aux_regs(1),
0332         aux_regs(2),
0333         aux_regs(3),
0334 };
0335 
0336 #define hpd_regs(id)\
0337 [id] = {\
0338     HPD_REG_LIST(id)\
0339 }
0340 
0341 static const struct dcn10_link_enc_hpd_registers link_enc_hpd_regs[] = {
0342         hpd_regs(0),
0343         hpd_regs(1),
0344         hpd_regs(2),
0345         hpd_regs(3),
0346 };
0347 
0348 
0349 #define link_regs(id, phyid)\
0350 [id] = {\
0351     LE_DCN301_REG_LIST(id), \
0352     UNIPHY_DCN2_REG_LIST(phyid), \
0353     DPCS_DCN2_REG_LIST(id), \
0354     SRI(DP_DPHY_INTERNAL_CTRL, DP, id) \
0355 }
0356 
0357 static const struct dce110_aux_registers_shift aux_shift = {
0358     DCN_AUX_MASK_SH_LIST(__SHIFT)
0359 };
0360 
0361 static const struct dce110_aux_registers_mask aux_mask = {
0362     DCN_AUX_MASK_SH_LIST(_MASK)
0363 };
0364 
0365 static const struct dcn10_link_enc_registers link_enc_regs[] = {
0366     link_regs(0, A),
0367     link_regs(1, B),
0368     link_regs(2, C),
0369     link_regs(3, D),
0370 };
0371 
0372 static const struct dcn10_link_enc_shift le_shift = {
0373     LINK_ENCODER_MASK_SH_LIST_DCN301(__SHIFT),\
0374     DPCS_DCN2_MASK_SH_LIST(__SHIFT)
0375 };
0376 
0377 static const struct dcn10_link_enc_mask le_mask = {
0378     LINK_ENCODER_MASK_SH_LIST_DCN301(_MASK),\
0379     DPCS_DCN2_MASK_SH_LIST(_MASK)
0380 };
0381 
0382 #define panel_cntl_regs(id)\
0383 [id] = {\
0384     DCN301_PANEL_CNTL_REG_LIST(id),\
0385 }
0386 
0387 static const struct dce_panel_cntl_registers panel_cntl_regs[] = {
0388     panel_cntl_regs(0),
0389     panel_cntl_regs(1),
0390 };
0391 
0392 static const struct dcn301_panel_cntl_shift panel_cntl_shift = {
0393     DCN301_PANEL_CNTL_MASK_SH_LIST(__SHIFT)
0394 };
0395 
0396 static const struct dcn301_panel_cntl_mask panel_cntl_mask = {
0397     DCN301_PANEL_CNTL_MASK_SH_LIST(_MASK)
0398 };
0399 
0400 #define dpp_regs(id)\
0401 [id] = {\
0402     DPP_REG_LIST_DCN30(id),\
0403 }
0404 
0405 static const struct dcn3_dpp_registers dpp_regs[] = {
0406     dpp_regs(0),
0407     dpp_regs(1),
0408     dpp_regs(2),
0409     dpp_regs(3),
0410 };
0411 
0412 static const struct dcn3_dpp_shift tf_shift = {
0413         DPP_REG_LIST_SH_MASK_DCN30(__SHIFT)
0414 };
0415 
0416 static const struct dcn3_dpp_mask tf_mask = {
0417         DPP_REG_LIST_SH_MASK_DCN30(_MASK)
0418 };
0419 
0420 #define opp_regs(id)\
0421 [id] = {\
0422     OPP_REG_LIST_DCN30(id),\
0423 }
0424 
0425 static const struct dcn20_opp_registers opp_regs[] = {
0426     opp_regs(0),
0427     opp_regs(1),
0428     opp_regs(2),
0429     opp_regs(3),
0430 };
0431 
0432 static const struct dcn20_opp_shift opp_shift = {
0433     OPP_MASK_SH_LIST_DCN20(__SHIFT)
0434 };
0435 
0436 static const struct dcn20_opp_mask opp_mask = {
0437     OPP_MASK_SH_LIST_DCN20(_MASK)
0438 };
0439 
0440 #define aux_engine_regs(id)\
0441 [id] = {\
0442     AUX_COMMON_REG_LIST0(id), \
0443     .AUXN_IMPCAL = 0, \
0444     .AUXP_IMPCAL = 0, \
0445     .AUX_RESET_MASK = DP_AUX0_AUX_CONTROL__AUX_RESET_MASK, \
0446 }
0447 
0448 static const struct dce110_aux_registers aux_engine_regs[] = {
0449         aux_engine_regs(0),
0450         aux_engine_regs(1),
0451         aux_engine_regs(2),
0452         aux_engine_regs(3),
0453 };
0454 
0455 #define dwbc_regs_dcn3(id)\
0456 [id] = {\
0457     DWBC_COMMON_REG_LIST_DCN30(id),\
0458 }
0459 
0460 static const struct dcn30_dwbc_registers dwbc30_regs[] = {
0461     dwbc_regs_dcn3(0),
0462 };
0463 
0464 static const struct dcn30_dwbc_shift dwbc30_shift = {
0465     DWBC_COMMON_MASK_SH_LIST_DCN30(__SHIFT)
0466 };
0467 
0468 static const struct dcn30_dwbc_mask dwbc30_mask = {
0469     DWBC_COMMON_MASK_SH_LIST_DCN30(_MASK)
0470 };
0471 
0472 #define mcif_wb_regs_dcn3(id)\
0473 [id] = {\
0474     MCIF_WB_COMMON_REG_LIST_DCN30(id),\
0475 }
0476 
0477 static const struct dcn30_mmhubbub_registers mcif_wb30_regs[] = {
0478     mcif_wb_regs_dcn3(0)
0479 };
0480 
0481 static const struct dcn30_mmhubbub_shift mcif_wb30_shift = {
0482     MCIF_WB_COMMON_MASK_SH_LIST_DCN30(__SHIFT)
0483 };
0484 
0485 static const struct dcn30_mmhubbub_mask mcif_wb30_mask = {
0486     MCIF_WB_COMMON_MASK_SH_LIST_DCN30(_MASK)
0487 };
0488 
0489 #define dsc_regsDCN20(id)\
0490 [id] = {\
0491     DSC_REG_LIST_DCN20(id)\
0492 }
0493 
0494 static const struct dcn20_dsc_registers dsc_regs[] = {
0495     dsc_regsDCN20(0),
0496     dsc_regsDCN20(1),
0497     dsc_regsDCN20(2),
0498 };
0499 
0500 static const struct dcn20_dsc_shift dsc_shift = {
0501     DSC_REG_LIST_SH_MASK_DCN20(__SHIFT)
0502 };
0503 
0504 static const struct dcn20_dsc_mask dsc_mask = {
0505     DSC_REG_LIST_SH_MASK_DCN20(_MASK)
0506 };
0507 
0508 static const struct dcn30_mpc_registers mpc_regs = {
0509         MPC_REG_LIST_DCN3_0(0),
0510         MPC_REG_LIST_DCN3_0(1),
0511         MPC_REG_LIST_DCN3_0(2),
0512         MPC_REG_LIST_DCN3_0(3),
0513         MPC_OUT_MUX_REG_LIST_DCN3_0(0),
0514         MPC_OUT_MUX_REG_LIST_DCN3_0(1),
0515         MPC_OUT_MUX_REG_LIST_DCN3_0(2),
0516         MPC_OUT_MUX_REG_LIST_DCN3_0(3),
0517         MPC_RMU_GLOBAL_REG_LIST_DCN3AG,
0518         MPC_RMU_REG_LIST_DCN3AG(0),
0519         MPC_RMU_REG_LIST_DCN3AG(1),
0520         MPC_DWB_MUX_REG_LIST_DCN3_0(0),
0521 };
0522 
0523 static const struct dcn30_mpc_shift mpc_shift = {
0524     MPC_COMMON_MASK_SH_LIST_DCN30(__SHIFT)
0525 };
0526 
0527 static const struct dcn30_mpc_mask mpc_mask = {
0528     MPC_COMMON_MASK_SH_LIST_DCN30(_MASK)
0529 };
0530 
0531 #define optc_regs(id)\
0532 [id] = {OPTC_COMMON_REG_LIST_DCN3_0(id)}
0533 
0534 
0535 static const struct dcn_optc_registers optc_regs[] = {
0536     optc_regs(0),
0537     optc_regs(1),
0538     optc_regs(2),
0539     optc_regs(3),
0540 };
0541 
0542 static const struct dcn_optc_shift optc_shift = {
0543     OPTC_COMMON_MASK_SH_LIST_DCN30(__SHIFT)
0544 };
0545 
0546 static const struct dcn_optc_mask optc_mask = {
0547     OPTC_COMMON_MASK_SH_LIST_DCN30(_MASK)
0548 };
0549 
0550 #define hubp_regs(id)\
0551 [id] = {\
0552     HUBP_REG_LIST_DCN30(id)\
0553 }
0554 
0555 static const struct dcn_hubp2_registers hubp_regs[] = {
0556         hubp_regs(0),
0557         hubp_regs(1),
0558         hubp_regs(2),
0559         hubp_regs(3),
0560 };
0561 
0562 static const struct dcn_hubp2_shift hubp_shift = {
0563         HUBP_MASK_SH_LIST_DCN30(__SHIFT)
0564 };
0565 
0566 static const struct dcn_hubp2_mask hubp_mask = {
0567         HUBP_MASK_SH_LIST_DCN30(_MASK)
0568 };
0569 
0570 static const struct dcn_hubbub_registers hubbub_reg = {
0571         HUBBUB_REG_LIST_DCN301(0)
0572 };
0573 
0574 static const struct dcn_hubbub_shift hubbub_shift = {
0575         HUBBUB_MASK_SH_LIST_DCN301(__SHIFT)
0576 };
0577 
0578 static const struct dcn_hubbub_mask hubbub_mask = {
0579         HUBBUB_MASK_SH_LIST_DCN301(_MASK)
0580 };
0581 
0582 static const struct dccg_registers dccg_regs = {
0583         DCCG_REG_LIST_DCN301()
0584 };
0585 
0586 static const struct dccg_shift dccg_shift = {
0587         DCCG_MASK_SH_LIST_DCN301(__SHIFT)
0588 };
0589 
0590 static const struct dccg_mask dccg_mask = {
0591         DCCG_MASK_SH_LIST_DCN301(_MASK)
0592 };
0593 
0594 static const struct dce_hwseq_registers hwseq_reg = {
0595         HWSEQ_DCN301_REG_LIST()
0596 };
0597 
0598 static const struct dce_hwseq_shift hwseq_shift = {
0599         HWSEQ_DCN301_MASK_SH_LIST(__SHIFT)
0600 };
0601 
0602 static const struct dce_hwseq_mask hwseq_mask = {
0603         HWSEQ_DCN301_MASK_SH_LIST(_MASK)
0604 };
0605 #define vmid_regs(id)\
0606 [id] = {\
0607         DCN20_VMID_REG_LIST(id)\
0608 }
0609 
0610 static const struct dcn_vmid_registers vmid_regs[] = {
0611     vmid_regs(0),
0612     vmid_regs(1),
0613     vmid_regs(2),
0614     vmid_regs(3),
0615     vmid_regs(4),
0616     vmid_regs(5),
0617     vmid_regs(6),
0618     vmid_regs(7),
0619     vmid_regs(8),
0620     vmid_regs(9),
0621     vmid_regs(10),
0622     vmid_regs(11),
0623     vmid_regs(12),
0624     vmid_regs(13),
0625     vmid_regs(14),
0626     vmid_regs(15)
0627 };
0628 
0629 static const struct dcn20_vmid_shift vmid_shifts = {
0630         DCN20_VMID_MASK_SH_LIST(__SHIFT)
0631 };
0632 
0633 static const struct dcn20_vmid_mask vmid_masks = {
0634         DCN20_VMID_MASK_SH_LIST(_MASK)
0635 };
0636 
0637 static const struct resource_caps res_cap_dcn301 = {
0638     .num_timing_generator = 4,
0639     .num_opp = 4,
0640     .num_video_plane = 4,
0641     .num_audio = 4,
0642     .num_stream_encoder = 4,
0643     .num_pll = 4,
0644     .num_dwb = 1,
0645     .num_ddc = 4,
0646     .num_vmid = 16,
0647     .num_mpc_3dlut = 2,
0648     .num_dsc = 3,
0649 };
0650 
0651 static const struct dc_plane_cap plane_cap = {
0652     .type = DC_PLANE_TYPE_DCN_UNIVERSAL,
0653     .blends_with_above = true,
0654     .blends_with_below = true,
0655     .per_pixel_alpha = true,
0656 
0657     .pixel_format_support = {
0658             .argb8888 = true,
0659             .nv12 = true,
0660             .fp16 = true,
0661             .p010 = true,
0662             .ayuv = false,
0663     },
0664 
0665     .max_upscale_factor = {
0666             .argb8888 = 16000,
0667             .nv12 = 16000,
0668             .fp16 = 16000
0669     },
0670 
0671     /* 6:1 downscaling ratio: 1000/6 = 166.666 */
0672     .max_downscale_factor = {
0673             .argb8888 = 167,
0674             .nv12 = 167,
0675             .fp16 = 167 
0676     },
0677     64,
0678     64
0679 };
0680 
0681 static const struct dc_debug_options debug_defaults_drv = {
0682     .disable_dmcu = true,
0683     .force_abm_enable = false,
0684     .timing_trace = false,
0685     .clock_trace = true,
0686     .disable_dpp_power_gate = false,
0687     .disable_hubp_power_gate = false,
0688     .disable_clock_gate = true,
0689     .disable_pplib_clock_request = true,
0690     .disable_pplib_wm_range = true,
0691     .pipe_split_policy = MPC_SPLIT_AVOID,
0692     .force_single_disp_pipe_split = false,
0693     .disable_dcc = DCC_ENABLE,
0694     .vsr_support = true,
0695     .performance_trace = false,
0696     .max_downscale_src_width = 7680,/*upto 8K*/
0697     .scl_reset_length10 = true,
0698     .sanity_checks = false,
0699     .underflow_assert_delay_us = 0xFFFFFFFF,
0700     .dwb_fi_phase = -1, // -1 = disable
0701     .dmub_command_table = true,
0702     .use_max_lb = false,
0703 };
0704 
0705 static const struct dc_debug_options debug_defaults_diags = {
0706     .disable_dmcu = true,
0707     .force_abm_enable = false,
0708     .timing_trace = true,
0709     .clock_trace = true,
0710     .disable_dpp_power_gate = false,
0711     .disable_hubp_power_gate = false,
0712     .disable_clock_gate = true,
0713     .disable_pplib_clock_request = true,
0714     .disable_pplib_wm_range = true,
0715     .disable_stutter = true,
0716     .scl_reset_length10 = true,
0717     .dwb_fi_phase = -1, // -1 = disable
0718     .dmub_command_table = true,
0719     .use_max_lb = false,
0720 };
0721 
0722 static void dcn301_dpp_destroy(struct dpp **dpp)
0723 {
0724     kfree(TO_DCN20_DPP(*dpp));
0725     *dpp = NULL;
0726 }
0727 
0728 static struct dpp *dcn301_dpp_create(struct dc_context *ctx, uint32_t inst)
0729 {
0730     struct dcn3_dpp *dpp =
0731         kzalloc(sizeof(struct dcn3_dpp), GFP_KERNEL);
0732 
0733     if (!dpp)
0734         return NULL;
0735 
0736     if (dpp3_construct(dpp, ctx, inst,
0737             &dpp_regs[inst], &tf_shift, &tf_mask))
0738         return &dpp->base;
0739 
0740     BREAK_TO_DEBUGGER();
0741     kfree(dpp);
0742     return NULL;
0743 }
0744 static struct output_pixel_processor *dcn301_opp_create(struct dc_context *ctx,
0745                             uint32_t inst)
0746 {
0747     struct dcn20_opp *opp =
0748         kzalloc(sizeof(struct dcn20_opp), GFP_KERNEL);
0749 
0750     if (!opp) {
0751         BREAK_TO_DEBUGGER();
0752         return NULL;
0753     }
0754 
0755     dcn20_opp_construct(opp, ctx, inst,
0756             &opp_regs[inst], &opp_shift, &opp_mask);
0757     return &opp->base;
0758 }
0759 
0760 static struct dce_aux *dcn301_aux_engine_create(struct dc_context *ctx, uint32_t inst)
0761 {
0762     struct aux_engine_dce110 *aux_engine =
0763         kzalloc(sizeof(struct aux_engine_dce110), GFP_KERNEL);
0764 
0765     if (!aux_engine)
0766         return NULL;
0767 
0768     dce110_aux_engine_construct(aux_engine, ctx, inst,
0769                     SW_AUX_TIMEOUT_PERIOD_MULTIPLIER * AUX_TIMEOUT_PERIOD,
0770                     &aux_engine_regs[inst],
0771                     &aux_mask,
0772                     &aux_shift,
0773                     ctx->dc->caps.extended_aux_timeout_support);
0774 
0775     return &aux_engine->base;
0776 }
0777 #define i2c_inst_regs(id) { I2C_HW_ENGINE_COMMON_REG_LIST(id) }
0778 
0779 static const struct dce_i2c_registers i2c_hw_regs[] = {
0780         i2c_inst_regs(1),
0781         i2c_inst_regs(2),
0782         i2c_inst_regs(3),
0783         i2c_inst_regs(4),
0784 };
0785 
0786 static const struct dce_i2c_shift i2c_shifts = {
0787         I2C_COMMON_MASK_SH_LIST_DCN2(__SHIFT)
0788 };
0789 
0790 static const struct dce_i2c_mask i2c_masks = {
0791         I2C_COMMON_MASK_SH_LIST_DCN2(_MASK)
0792 };
0793 
0794 static struct dce_i2c_hw *dcn301_i2c_hw_create(struct dc_context *ctx, uint32_t inst)
0795 {
0796     struct dce_i2c_hw *dce_i2c_hw =
0797         kzalloc(sizeof(struct dce_i2c_hw), GFP_KERNEL);
0798 
0799     if (!dce_i2c_hw)
0800         return NULL;
0801 
0802     dcn2_i2c_hw_construct(dce_i2c_hw, ctx, inst,
0803                     &i2c_hw_regs[inst], &i2c_shifts, &i2c_masks);
0804 
0805     return dce_i2c_hw;
0806 }
0807 static struct mpc *dcn301_mpc_create(
0808         struct dc_context *ctx,
0809         int num_mpcc,
0810         int num_rmu)
0811 {
0812     struct dcn30_mpc *mpc30 = kzalloc(sizeof(struct dcn30_mpc),
0813                       GFP_KERNEL);
0814 
0815     if (!mpc30)
0816         return NULL;
0817 
0818     dcn30_mpc_construct(mpc30, ctx,
0819             &mpc_regs,
0820             &mpc_shift,
0821             &mpc_mask,
0822             num_mpcc,
0823             num_rmu);
0824 
0825     return &mpc30->base;
0826 }
0827 
0828 static struct hubbub *dcn301_hubbub_create(struct dc_context *ctx)
0829 {
0830     int i;
0831 
0832     struct dcn20_hubbub *hubbub3 = kzalloc(sizeof(struct dcn20_hubbub),
0833                       GFP_KERNEL);
0834 
0835     if (!hubbub3)
0836         return NULL;
0837 
0838     hubbub301_construct(hubbub3, ctx,
0839             &hubbub_reg,
0840             &hubbub_shift,
0841             &hubbub_mask);
0842 
0843 
0844     for (i = 0; i < res_cap_dcn301.num_vmid; i++) {
0845         struct dcn20_vmid *vmid = &hubbub3->vmid[i];
0846 
0847         vmid->ctx = ctx;
0848 
0849         vmid->regs = &vmid_regs[i];
0850         vmid->shifts = &vmid_shifts;
0851         vmid->masks = &vmid_masks;
0852     }
0853 
0854      hubbub3->num_vmid = res_cap_dcn301.num_vmid;
0855 
0856     return &hubbub3->base;
0857 }
0858 
0859 static struct timing_generator *dcn301_timing_generator_create(
0860     struct dc_context *ctx, uint32_t instance)
0861 {
0862     struct optc *tgn10 =
0863         kzalloc(sizeof(struct optc), GFP_KERNEL);
0864 
0865     if (!tgn10)
0866         return NULL;
0867 
0868     tgn10->base.inst = instance;
0869     tgn10->base.ctx = ctx;
0870 
0871     tgn10->tg_regs = &optc_regs[instance];
0872     tgn10->tg_shift = &optc_shift;
0873     tgn10->tg_mask = &optc_mask;
0874 
0875     dcn30_timing_generator_init(tgn10);
0876 
0877     return &tgn10->base;
0878 }
0879 
0880 static const struct encoder_feature_support link_enc_feature = {
0881         .max_hdmi_deep_color = COLOR_DEPTH_121212,
0882         .max_hdmi_pixel_clock = 600000,
0883         .hdmi_ycbcr420_supported = true,
0884         .dp_ycbcr420_supported = true,
0885         .fec_supported = true,
0886         .flags.bits.IS_HBR2_CAPABLE = true,
0887         .flags.bits.IS_HBR3_CAPABLE = true,
0888         .flags.bits.IS_TPS3_CAPABLE = true,
0889         .flags.bits.IS_TPS4_CAPABLE = true
0890 };
0891 
0892 static struct link_encoder *dcn301_link_encoder_create(
0893     struct dc_context *ctx,
0894     const struct encoder_init_data *enc_init_data)
0895 {
0896     struct dcn20_link_encoder *enc20 =
0897         kzalloc(sizeof(struct dcn20_link_encoder), GFP_KERNEL);
0898 
0899     if (!enc20)
0900         return NULL;
0901 
0902     dcn301_link_encoder_construct(enc20,
0903             enc_init_data,
0904             &link_enc_feature,
0905             &link_enc_regs[enc_init_data->transmitter],
0906             &link_enc_aux_regs[enc_init_data->channel - 1],
0907             &link_enc_hpd_regs[enc_init_data->hpd_source],
0908             &le_shift,
0909             &le_mask);
0910 
0911     return &enc20->enc10.base;
0912 }
0913 
0914 static struct panel_cntl *dcn301_panel_cntl_create(const struct panel_cntl_init_data *init_data)
0915 {
0916     struct dcn301_panel_cntl *panel_cntl =
0917         kzalloc(sizeof(struct dcn301_panel_cntl), GFP_KERNEL);
0918 
0919     if (!panel_cntl)
0920         return NULL;
0921 
0922     dcn301_panel_cntl_construct(panel_cntl,
0923             init_data,
0924             &panel_cntl_regs[init_data->inst],
0925             &panel_cntl_shift,
0926             &panel_cntl_mask);
0927 
0928     return &panel_cntl->base;
0929 }
0930 
0931 
0932 #define CTX ctx
0933 
0934 #define REG(reg_name) \
0935     (DCN_BASE.instance[0].segment[mm ## reg_name ## _BASE_IDX] + mm ## reg_name)
0936 
0937 static uint32_t read_pipe_fuses(struct dc_context *ctx)
0938 {
0939     uint32_t value = REG_READ(CC_DC_PIPE_DIS);
0940     /* RV1 support max 4 pipes */
0941     value = value & 0xf;
0942     return value;
0943 }
0944 
0945 
0946 static void read_dce_straps(
0947     struct dc_context *ctx,
0948     struct resource_straps *straps)
0949 {
0950     generic_reg_get(ctx, mmDC_PINSTRAPS + BASE(mmDC_PINSTRAPS_BASE_IDX),
0951         FN(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO), &straps->dc_pinstraps_audio);
0952 
0953 }
0954 
0955 static struct audio *dcn301_create_audio(
0956         struct dc_context *ctx, unsigned int inst)
0957 {
0958     return dce_audio_create(ctx, inst,
0959             &audio_regs[inst], &audio_shift, &audio_mask);
0960 }
0961 
0962 static struct vpg *dcn301_vpg_create(
0963     struct dc_context *ctx,
0964     uint32_t inst)
0965 {
0966     struct dcn30_vpg *vpg3 = kzalloc(sizeof(struct dcn30_vpg), GFP_KERNEL);
0967 
0968     if (!vpg3)
0969         return NULL;
0970 
0971     vpg3_construct(vpg3, ctx, inst,
0972             &vpg_regs[inst],
0973             &vpg_shift,
0974             &vpg_mask);
0975 
0976     return &vpg3->base;
0977 }
0978 
0979 static struct afmt *dcn301_afmt_create(
0980     struct dc_context *ctx,
0981     uint32_t inst)
0982 {
0983     struct dcn30_afmt *afmt3 = kzalloc(sizeof(struct dcn30_afmt), GFP_KERNEL);
0984 
0985     if (!afmt3)
0986         return NULL;
0987 
0988     afmt3_construct(afmt3, ctx, inst,
0989             &afmt_regs[inst],
0990             &afmt_shift,
0991             &afmt_mask);
0992 
0993     return &afmt3->base;
0994 }
0995 
0996 static struct stream_encoder *dcn301_stream_encoder_create(enum engine_id eng_id,
0997                                struct dc_context *ctx)
0998 {
0999     struct dcn10_stream_encoder *enc1;
1000     struct vpg *vpg;
1001     struct afmt *afmt;
1002     int vpg_inst;
1003     int afmt_inst;
1004 
1005     /* Mapping of VPG, AFMT, DME register blocks to DIO block instance */
1006     if (eng_id <= ENGINE_ID_DIGF) {
1007         vpg_inst = eng_id;
1008         afmt_inst = eng_id;
1009     } else
1010         return NULL;
1011 
1012     enc1 = kzalloc(sizeof(struct dcn10_stream_encoder), GFP_KERNEL);
1013     vpg = dcn301_vpg_create(ctx, vpg_inst);
1014     afmt = dcn301_afmt_create(ctx, afmt_inst);
1015 
1016     if (!enc1 || !vpg || !afmt) {
1017         kfree(enc1);
1018         kfree(vpg);
1019         kfree(afmt);
1020         return NULL;
1021     }
1022 
1023     dcn30_dio_stream_encoder_construct(enc1, ctx, ctx->dc_bios,
1024                     eng_id, vpg, afmt,
1025                     &stream_enc_regs[eng_id],
1026                     &se_shift, &se_mask);
1027 
1028     return &enc1->base;
1029 }
1030 
1031 static struct dce_hwseq *dcn301_hwseq_create(struct dc_context *ctx)
1032 {
1033     struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL);
1034 
1035     if (hws) {
1036         hws->ctx = ctx;
1037         hws->regs = &hwseq_reg;
1038         hws->shifts = &hwseq_shift;
1039         hws->masks = &hwseq_mask;
1040     }
1041     return hws;
1042 }
1043 static const struct resource_create_funcs res_create_funcs = {
1044     .read_dce_straps = read_dce_straps,
1045     .create_audio = dcn301_create_audio,
1046     .create_stream_encoder = dcn301_stream_encoder_create,
1047     .create_hwseq = dcn301_hwseq_create,
1048 };
1049 
1050 static const struct resource_create_funcs res_create_maximus_funcs = {
1051     .read_dce_straps = NULL,
1052     .create_audio = NULL,
1053     .create_stream_encoder = NULL,
1054     .create_hwseq = dcn301_hwseq_create,
1055 };
1056 
1057 static void dcn301_destruct(struct dcn301_resource_pool *pool)
1058 {
1059     unsigned int i;
1060 
1061     for (i = 0; i < pool->base.stream_enc_count; i++) {
1062         if (pool->base.stream_enc[i] != NULL) {
1063             if (pool->base.stream_enc[i]->vpg != NULL) {
1064                 kfree(DCN30_VPG_FROM_VPG(pool->base.stream_enc[i]->vpg));
1065                 pool->base.stream_enc[i]->vpg = NULL;
1066             }
1067             if (pool->base.stream_enc[i]->afmt != NULL) {
1068                 kfree(DCN30_AFMT_FROM_AFMT(pool->base.stream_enc[i]->afmt));
1069                 pool->base.stream_enc[i]->afmt = NULL;
1070             }
1071             kfree(DCN10STRENC_FROM_STRENC(pool->base.stream_enc[i]));
1072             pool->base.stream_enc[i] = NULL;
1073         }
1074     }
1075 
1076     for (i = 0; i < pool->base.res_cap->num_dsc; i++) {
1077         if (pool->base.dscs[i] != NULL)
1078             dcn20_dsc_destroy(&pool->base.dscs[i]);
1079     }
1080 
1081     if (pool->base.mpc != NULL) {
1082         kfree(TO_DCN20_MPC(pool->base.mpc));
1083         pool->base.mpc = NULL;
1084     }
1085     if (pool->base.hubbub != NULL) {
1086         kfree(pool->base.hubbub);
1087         pool->base.hubbub = NULL;
1088     }
1089     for (i = 0; i < pool->base.pipe_count; i++) {
1090         if (pool->base.dpps[i] != NULL)
1091             dcn301_dpp_destroy(&pool->base.dpps[i]);
1092 
1093         if (pool->base.ipps[i] != NULL)
1094             pool->base.ipps[i]->funcs->ipp_destroy(&pool->base.ipps[i]);
1095 
1096         if (pool->base.hubps[i] != NULL) {
1097             kfree(TO_DCN20_HUBP(pool->base.hubps[i]));
1098             pool->base.hubps[i] = NULL;
1099         }
1100 
1101         if (pool->base.irqs != NULL) {
1102             dal_irq_service_destroy(&pool->base.irqs);
1103         }
1104     }
1105 
1106     for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
1107         if (pool->base.engines[i] != NULL)
1108             dce110_engine_destroy(&pool->base.engines[i]);
1109         if (pool->base.hw_i2cs[i] != NULL) {
1110             kfree(pool->base.hw_i2cs[i]);
1111             pool->base.hw_i2cs[i] = NULL;
1112         }
1113         if (pool->base.sw_i2cs[i] != NULL) {
1114             kfree(pool->base.sw_i2cs[i]);
1115             pool->base.sw_i2cs[i] = NULL;
1116         }
1117     }
1118 
1119     for (i = 0; i < pool->base.res_cap->num_opp; i++) {
1120         if (pool->base.opps[i] != NULL)
1121             pool->base.opps[i]->funcs->opp_destroy(&pool->base.opps[i]);
1122     }
1123 
1124     for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) {
1125         if (pool->base.timing_generators[i] != NULL)    {
1126             kfree(DCN10TG_FROM_TG(pool->base.timing_generators[i]));
1127             pool->base.timing_generators[i] = NULL;
1128         }
1129     }
1130 
1131     for (i = 0; i < pool->base.res_cap->num_dwb; i++) {
1132         if (pool->base.dwbc[i] != NULL) {
1133             kfree(TO_DCN30_DWBC(pool->base.dwbc[i]));
1134             pool->base.dwbc[i] = NULL;
1135         }
1136         if (pool->base.mcif_wb[i] != NULL) {
1137             kfree(TO_DCN30_MMHUBBUB(pool->base.mcif_wb[i]));
1138             pool->base.mcif_wb[i] = NULL;
1139         }
1140     }
1141 
1142     for (i = 0; i < pool->base.audio_count; i++) {
1143         if (pool->base.audios[i])
1144             dce_aud_destroy(&pool->base.audios[i]);
1145     }
1146 
1147     for (i = 0; i < pool->base.clk_src_count; i++) {
1148         if (pool->base.clock_sources[i] != NULL) {
1149             dcn20_clock_source_destroy(&pool->base.clock_sources[i]);
1150             pool->base.clock_sources[i] = NULL;
1151         }
1152     }
1153 
1154     for (i = 0; i < pool->base.res_cap->num_mpc_3dlut; i++) {
1155         if (pool->base.mpc_lut[i] != NULL) {
1156             dc_3dlut_func_release(pool->base.mpc_lut[i]);
1157             pool->base.mpc_lut[i] = NULL;
1158         }
1159         if (pool->base.mpc_shaper[i] != NULL) {
1160             dc_transfer_func_release(pool->base.mpc_shaper[i]);
1161             pool->base.mpc_shaper[i] = NULL;
1162         }
1163     }
1164 
1165     if (pool->base.dp_clock_source != NULL) {
1166         dcn20_clock_source_destroy(&pool->base.dp_clock_source);
1167         pool->base.dp_clock_source = NULL;
1168     }
1169 
1170     for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) {
1171         if (pool->base.multiple_abms[i] != NULL)
1172             dce_abm_destroy(&pool->base.multiple_abms[i]);
1173     }
1174 
1175     if (pool->base.dccg != NULL)
1176         dcn_dccg_destroy(&pool->base.dccg);
1177 }
1178 
1179 static struct hubp *dcn301_hubp_create(struct dc_context *ctx, uint32_t inst)
1180 {
1181     struct dcn20_hubp *hubp2 =
1182         kzalloc(sizeof(struct dcn20_hubp), GFP_KERNEL);
1183 
1184     if (!hubp2)
1185         return NULL;
1186 
1187     if (hubp3_construct(hubp2, ctx, inst,
1188             &hubp_regs[inst], &hubp_shift, &hubp_mask))
1189         return &hubp2->base;
1190 
1191     BREAK_TO_DEBUGGER();
1192     kfree(hubp2);
1193     return NULL;
1194 }
1195 
1196 static bool dcn301_dwbc_create(struct dc_context *ctx, struct resource_pool *pool)
1197 {
1198     int i;
1199     uint32_t pipe_count = pool->res_cap->num_dwb;
1200 
1201     for (i = 0; i < pipe_count; i++) {
1202         struct dcn30_dwbc *dwbc30 = kzalloc(sizeof(struct dcn30_dwbc),
1203                             GFP_KERNEL);
1204 
1205         if (!dwbc30) {
1206             dm_error("DC: failed to create dwbc30!\n");
1207             return false;
1208         }
1209 
1210         dcn30_dwbc_construct(dwbc30, ctx,
1211                 &dwbc30_regs[i],
1212                 &dwbc30_shift,
1213                 &dwbc30_mask,
1214                 i);
1215 
1216         pool->dwbc[i] = &dwbc30->base;
1217     }
1218     return true;
1219 }
1220 
1221 static bool dcn301_mmhubbub_create(struct dc_context *ctx, struct resource_pool *pool)
1222 {
1223     int i;
1224     uint32_t pipe_count = pool->res_cap->num_dwb;
1225 
1226     for (i = 0; i < pipe_count; i++) {
1227         struct dcn30_mmhubbub *mcif_wb30 = kzalloc(sizeof(struct dcn30_mmhubbub),
1228                             GFP_KERNEL);
1229 
1230         if (!mcif_wb30) {
1231             dm_error("DC: failed to create mcif_wb30!\n");
1232             return false;
1233         }
1234 
1235         dcn30_mmhubbub_construct(mcif_wb30, ctx,
1236                 &mcif_wb30_regs[i],
1237                 &mcif_wb30_shift,
1238                 &mcif_wb30_mask,
1239                 i);
1240 
1241         pool->mcif_wb[i] = &mcif_wb30->base;
1242     }
1243     return true;
1244 }
1245 
1246 static struct display_stream_compressor *dcn301_dsc_create(
1247     struct dc_context *ctx, uint32_t inst)
1248 {
1249     struct dcn20_dsc *dsc =
1250         kzalloc(sizeof(struct dcn20_dsc), GFP_KERNEL);
1251 
1252     if (!dsc) {
1253         BREAK_TO_DEBUGGER();
1254         return NULL;
1255     }
1256 
1257     dsc2_construct(dsc, ctx, inst, &dsc_regs[inst], &dsc_shift, &dsc_mask);
1258     return &dsc->base;
1259 }
1260 
1261 
1262 static void dcn301_destroy_resource_pool(struct resource_pool **pool)
1263 {
1264     struct dcn301_resource_pool *dcn301_pool = TO_DCN301_RES_POOL(*pool);
1265 
1266     dcn301_destruct(dcn301_pool);
1267     kfree(dcn301_pool);
1268     *pool = NULL;
1269 }
1270 
1271 static struct clock_source *dcn301_clock_source_create(
1272         struct dc_context *ctx,
1273         struct dc_bios *bios,
1274         enum clock_source_id id,
1275         const struct dce110_clk_src_regs *regs,
1276         bool dp_clk_src)
1277 {
1278     struct dce110_clk_src *clk_src =
1279         kzalloc(sizeof(struct dce110_clk_src), GFP_KERNEL);
1280 
1281     if (!clk_src)
1282         return NULL;
1283 
1284     if (dcn301_clk_src_construct(clk_src, ctx, bios, id,
1285             regs, &cs_shift, &cs_mask)) {
1286         clk_src->base.dp_clk_src = dp_clk_src;
1287         return &clk_src->base;
1288     }
1289 
1290     BREAK_TO_DEBUGGER();
1291     return NULL;
1292 }
1293 
1294 static struct dc_cap_funcs cap_funcs = {
1295     .get_dcc_compression_cap = dcn20_get_dcc_compression_cap
1296 };
1297 
1298 
1299 static bool is_soc_bounding_box_valid(struct dc *dc)
1300 {
1301     uint32_t hw_internal_rev = dc->ctx->asic_id.hw_internal_rev;
1302 
1303     if (ASICREV_IS_VANGOGH(hw_internal_rev))
1304         return true;
1305 
1306     return false;
1307 }
1308 
1309 static bool init_soc_bounding_box(struct dc *dc,
1310                   struct dcn301_resource_pool *pool)
1311 {
1312     struct _vcs_dpi_soc_bounding_box_st *loaded_bb = &dcn3_01_soc;
1313     struct _vcs_dpi_ip_params_st *loaded_ip = &dcn3_01_ip;
1314 
1315     DC_LOGGER_INIT(dc->ctx->logger);
1316 
1317     if (!is_soc_bounding_box_valid(dc)) {
1318         DC_LOG_ERROR("%s: not valid soc bounding box\n", __func__);
1319         return false;
1320     }
1321 
1322     loaded_ip->max_num_otg = pool->base.res_cap->num_timing_generator;
1323     loaded_ip->max_num_dpp = pool->base.pipe_count;
1324     DC_FP_START();
1325     dcn20_patch_bounding_box(dc, loaded_bb);
1326     DC_FP_END();
1327 
1328     if (dc->ctx->dc_bios->funcs->get_soc_bb_info) {
1329         struct bp_soc_bb_info bb_info = {0};
1330 
1331         if (dc->ctx->dc_bios->funcs->get_soc_bb_info(dc->ctx->dc_bios, &bb_info) == BP_RESULT_OK) {
1332             DC_FP_START();
1333             dcn301_fpu_init_soc_bounding_box(bb_info);
1334             DC_FP_END();
1335         }
1336     }
1337 
1338     return true;
1339 }
1340 
1341 
1342 static void set_wm_ranges(
1343         struct pp_smu_funcs *pp_smu,
1344         struct _vcs_dpi_soc_bounding_box_st *loaded_bb)
1345 {
1346     struct pp_smu_wm_range_sets ranges = {0};
1347     int i;
1348 
1349     ranges.num_reader_wm_sets = 0;
1350 
1351     if (loaded_bb->num_states == 1) {
1352         ranges.reader_wm_sets[0].wm_inst = 0;
1353         ranges.reader_wm_sets[0].min_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN;
1354         ranges.reader_wm_sets[0].max_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX;
1355         ranges.reader_wm_sets[0].min_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN;
1356         ranges.reader_wm_sets[0].max_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX;
1357 
1358         ranges.num_reader_wm_sets = 1;
1359     } else if (loaded_bb->num_states > 1) {
1360         for (i = 0; i < 4 && i < loaded_bb->num_states; i++) {
1361             ranges.reader_wm_sets[i].wm_inst = i;
1362             ranges.reader_wm_sets[i].min_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN;
1363             ranges.reader_wm_sets[i].max_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX;
1364             DC_FP_START();
1365             dcn301_fpu_set_wm_ranges(i, &ranges, loaded_bb);
1366             DC_FP_END();
1367             ranges.num_reader_wm_sets = i + 1;
1368         }
1369 
1370         ranges.reader_wm_sets[0].min_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN;
1371         ranges.reader_wm_sets[ranges.num_reader_wm_sets - 1].max_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX;
1372     }
1373 
1374     ranges.num_writer_wm_sets = 1;
1375 
1376     ranges.writer_wm_sets[0].wm_inst = 0;
1377     ranges.writer_wm_sets[0].min_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN;
1378     ranges.writer_wm_sets[0].max_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX;
1379     ranges.writer_wm_sets[0].min_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN;
1380     ranges.writer_wm_sets[0].max_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX;
1381 
1382     /* Notify PP Lib/SMU which Watermarks to use for which clock ranges */
1383     pp_smu->nv_funcs.set_wm_ranges(&pp_smu->nv_funcs.pp_smu, &ranges);
1384 }
1385 
1386 static void dcn301_calculate_wm_and_dlg(
1387         struct dc *dc, struct dc_state *context,
1388         display_e2e_pipe_params_st *pipes,
1389         int pipe_cnt,
1390         int vlevel)
1391 {
1392     DC_FP_START();
1393     dcn301_calculate_wm_and_dlg_fp(dc, context, pipes, pipe_cnt, vlevel);
1394     DC_FP_END();
1395 }
1396 
1397 static struct resource_funcs dcn301_res_pool_funcs = {
1398     .destroy = dcn301_destroy_resource_pool,
1399     .link_enc_create = dcn301_link_encoder_create,
1400     .panel_cntl_create = dcn301_panel_cntl_create,
1401     .validate_bandwidth = dcn30_validate_bandwidth,
1402     .calculate_wm_and_dlg = dcn301_calculate_wm_and_dlg,
1403     .update_soc_for_wm_a = dcn30_update_soc_for_wm_a,
1404     .populate_dml_pipes = dcn30_populate_dml_pipes_from_context,
1405     .acquire_idle_pipe_for_layer = dcn20_acquire_idle_pipe_for_layer,
1406     .add_stream_to_ctx = dcn30_add_stream_to_ctx,
1407     .add_dsc_to_stream_resource = dcn20_add_dsc_to_stream_resource,
1408     .remove_stream_from_ctx = dcn20_remove_stream_from_ctx,
1409     .populate_dml_writeback_from_context = dcn30_populate_dml_writeback_from_context,
1410     .set_mcif_arb_params = dcn30_set_mcif_arb_params,
1411     .find_first_free_match_stream_enc_for_link = dcn10_find_first_free_match_stream_enc_for_link,
1412     .acquire_post_bldn_3dlut = dcn30_acquire_post_bldn_3dlut,
1413     .release_post_bldn_3dlut = dcn30_release_post_bldn_3dlut,
1414     .update_bw_bounding_box = dcn301_update_bw_bounding_box
1415 };
1416 
1417 static bool dcn301_resource_construct(
1418     uint8_t num_virtual_links,
1419     struct dc *dc,
1420     struct dcn301_resource_pool *pool)
1421 {
1422     int i, j;
1423     struct dc_context *ctx = dc->ctx;
1424     struct irq_service_init_data init_data;
1425     uint32_t pipe_fuses = read_pipe_fuses(ctx);
1426     uint32_t num_pipes = 0;
1427 
1428     DC_LOGGER_INIT(dc->ctx->logger);
1429 
1430     ctx->dc_bios->regs = &bios_regs;
1431 
1432     pool->base.res_cap = &res_cap_dcn301;
1433 
1434     pool->base.funcs = &dcn301_res_pool_funcs;
1435 
1436     /*************************************************
1437      *  Resource + asic cap harcoding                *
1438      *************************************************/
1439     pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
1440     pool->base.pipe_count = pool->base.res_cap->num_timing_generator;
1441     pool->base.mpcc_count = pool->base.res_cap->num_timing_generator;
1442     dc->caps.max_downscale_ratio = 600;
1443     dc->caps.i2c_speed_in_khz = 100;
1444     dc->caps.i2c_speed_in_khz_hdcp = 5; /*1.4 w/a enabled by default*/
1445     dc->caps.max_cursor_size = 256;
1446     dc->caps.min_horizontal_blanking_period = 80;
1447     dc->caps.dmdata_alloc_size = 2048;
1448     dc->caps.max_slave_planes = 1;
1449     dc->caps.max_slave_yuv_planes = 1;
1450     dc->caps.max_slave_rgb_planes = 1;
1451     dc->caps.is_apu = true;
1452     dc->caps.post_blend_color_processing = true;
1453     dc->caps.force_dp_tps4_for_cp2520 = true;
1454     dc->caps.extended_aux_timeout_support = true;
1455     dc->caps.dmcub_support = true;
1456 
1457     /* Color pipeline capabilities */
1458     dc->caps.color.dpp.dcn_arch = 1;
1459     dc->caps.color.dpp.input_lut_shared = 0;
1460     dc->caps.color.dpp.icsc = 1;
1461     dc->caps.color.dpp.dgam_ram = 0; // must use gamma_corr
1462     dc->caps.color.dpp.dgam_rom_caps.srgb = 1;
1463     dc->caps.color.dpp.dgam_rom_caps.bt2020 = 1;
1464     dc->caps.color.dpp.dgam_rom_caps.gamma2_2 = 1;
1465     dc->caps.color.dpp.dgam_rom_caps.pq = 1;
1466     dc->caps.color.dpp.dgam_rom_caps.hlg = 1;
1467     dc->caps.color.dpp.post_csc = 1;
1468     dc->caps.color.dpp.gamma_corr = 1;
1469     dc->caps.color.dpp.dgam_rom_for_yuv = 0;
1470 
1471     dc->caps.color.dpp.hw_3d_lut = 1;
1472     dc->caps.color.dpp.ogam_ram = 1;
1473     // no OGAM ROM on DCN301
1474     dc->caps.color.dpp.ogam_rom_caps.srgb = 0;
1475     dc->caps.color.dpp.ogam_rom_caps.bt2020 = 0;
1476     dc->caps.color.dpp.ogam_rom_caps.gamma2_2 = 0;
1477     dc->caps.color.dpp.ogam_rom_caps.pq = 0;
1478     dc->caps.color.dpp.ogam_rom_caps.hlg = 0;
1479     dc->caps.color.dpp.ocsc = 0;
1480 
1481     dc->caps.color.mpc.gamut_remap = 1;
1482     dc->caps.color.mpc.num_3dluts = pool->base.res_cap->num_mpc_3dlut; //2
1483     dc->caps.color.mpc.ogam_ram = 1;
1484     dc->caps.color.mpc.ogam_rom_caps.srgb = 0;
1485     dc->caps.color.mpc.ogam_rom_caps.bt2020 = 0;
1486     dc->caps.color.mpc.ogam_rom_caps.gamma2_2 = 0;
1487     dc->caps.color.mpc.ogam_rom_caps.pq = 0;
1488     dc->caps.color.mpc.ogam_rom_caps.hlg = 0;
1489     dc->caps.color.mpc.ocsc = 1;
1490 
1491     /* read VBIOS LTTPR caps */
1492     if (ctx->dc_bios->funcs->get_lttpr_caps) {
1493         enum bp_result bp_query_result;
1494         uint8_t is_vbios_lttpr_enable = 0;
1495 
1496         bp_query_result = ctx->dc_bios->funcs->get_lttpr_caps(ctx->dc_bios, &is_vbios_lttpr_enable);
1497         dc->caps.vbios_lttpr_enable = (bp_query_result == BP_RESULT_OK) && !!is_vbios_lttpr_enable;
1498     }
1499 
1500     if (ctx->dc_bios->funcs->get_lttpr_interop) {
1501         enum bp_result bp_query_result;
1502         uint8_t is_vbios_interop_enabled = 0;
1503 
1504         bp_query_result = ctx->dc_bios->funcs->get_lttpr_interop(ctx->dc_bios, &is_vbios_interop_enabled);
1505         dc->caps.vbios_lttpr_aware = (bp_query_result == BP_RESULT_OK) && !!is_vbios_interop_enabled;
1506     }
1507 
1508     if (dc->ctx->dce_environment == DCE_ENV_PRODUCTION_DRV)
1509         dc->debug = debug_defaults_drv;
1510     else if (dc->ctx->dce_environment == DCE_ENV_FPGA_MAXIMUS) {
1511         dc->debug = debug_defaults_diags;
1512     } else
1513         dc->debug = debug_defaults_diags;
1514     // Init the vm_helper
1515     if (dc->vm_helper)
1516         vm_helper_init(dc->vm_helper, 16);
1517 
1518     /*************************************************
1519      *  Create resources                             *
1520      *************************************************/
1521 
1522     /* Clock Sources for Pixel Clock*/
1523     pool->base.clock_sources[DCN301_CLK_SRC_PLL0] =
1524             dcn301_clock_source_create(ctx, ctx->dc_bios,
1525                 CLOCK_SOURCE_COMBO_PHY_PLL0,
1526                 &clk_src_regs[0], false);
1527     pool->base.clock_sources[DCN301_CLK_SRC_PLL1] =
1528             dcn301_clock_source_create(ctx, ctx->dc_bios,
1529                 CLOCK_SOURCE_COMBO_PHY_PLL1,
1530                 &clk_src_regs[1], false);
1531     pool->base.clock_sources[DCN301_CLK_SRC_PLL2] =
1532             dcn301_clock_source_create(ctx, ctx->dc_bios,
1533                 CLOCK_SOURCE_COMBO_PHY_PLL2,
1534                 &clk_src_regs[2], false);
1535     pool->base.clock_sources[DCN301_CLK_SRC_PLL3] =
1536             dcn301_clock_source_create(ctx, ctx->dc_bios,
1537                 CLOCK_SOURCE_COMBO_PHY_PLL3,
1538                 &clk_src_regs[3], false);
1539 
1540     pool->base.clk_src_count = DCN301_CLK_SRC_TOTAL;
1541 
1542     /* todo: not reuse phy_pll registers */
1543     pool->base.dp_clock_source =
1544             dcn301_clock_source_create(ctx, ctx->dc_bios,
1545                 CLOCK_SOURCE_ID_DP_DTO,
1546                 &clk_src_regs[0], true);
1547 
1548     for (i = 0; i < pool->base.clk_src_count; i++) {
1549         if (pool->base.clock_sources[i] == NULL) {
1550             dm_error("DC: failed to create clock sources!\n");
1551             BREAK_TO_DEBUGGER();
1552             goto create_fail;
1553         }
1554     }
1555 
1556     /* DCCG */
1557     pool->base.dccg = dccg301_create(ctx, &dccg_regs, &dccg_shift, &dccg_mask);
1558     if (pool->base.dccg == NULL) {
1559         dm_error("DC: failed to create dccg!\n");
1560         BREAK_TO_DEBUGGER();
1561         goto create_fail;
1562     }
1563 
1564     init_soc_bounding_box(dc, pool);
1565 
1566     if (!dc->debug.disable_pplib_wm_range && pool->base.pp_smu->nv_funcs.set_wm_ranges)
1567         set_wm_ranges(pool->base.pp_smu, &dcn3_01_soc);
1568 
1569     num_pipes = dcn3_01_ip.max_num_dpp;
1570 
1571     for (i = 0; i < dcn3_01_ip.max_num_dpp; i++)
1572         if (pipe_fuses & 1 << i)
1573             num_pipes--;
1574     dcn3_01_ip.max_num_dpp = num_pipes;
1575     dcn3_01_ip.max_num_otg = num_pipes;
1576 
1577 
1578     dml_init_instance(&dc->dml, &dcn3_01_soc, &dcn3_01_ip, DML_PROJECT_DCN30);
1579 
1580     /* IRQ */
1581     init_data.ctx = dc->ctx;
1582     pool->base.irqs = dal_irq_service_dcn30_create(&init_data);
1583     if (!pool->base.irqs)
1584         goto create_fail;
1585 
1586     /* HUBBUB */
1587     pool->base.hubbub = dcn301_hubbub_create(ctx);
1588     if (pool->base.hubbub == NULL) {
1589         BREAK_TO_DEBUGGER();
1590         dm_error("DC: failed to create hubbub!\n");
1591         goto create_fail;
1592     }
1593 
1594     j = 0;
1595     /* HUBPs, DPPs, OPPs and TGs */
1596     for (i = 0; i < pool->base.pipe_count; i++) {
1597 
1598         /* if pipe is disabled, skip instance of HW pipe,
1599          * i.e, skip ASIC register instance
1600          */
1601         if ((pipe_fuses & (1 << i)) != 0) {
1602             DC_LOG_DEBUG("%s: fusing pipe %d\n", __func__, i);
1603             continue;
1604         }
1605 
1606         pool->base.hubps[j] = dcn301_hubp_create(ctx, i);
1607         if (pool->base.hubps[j] == NULL) {
1608             BREAK_TO_DEBUGGER();
1609             dm_error(
1610                 "DC: failed to create hubps!\n");
1611             goto create_fail;
1612         }
1613 
1614         pool->base.dpps[j] = dcn301_dpp_create(ctx, i);
1615         if (pool->base.dpps[j] == NULL) {
1616             BREAK_TO_DEBUGGER();
1617             dm_error(
1618                 "DC: failed to create dpps!\n");
1619             goto create_fail;
1620         }
1621 
1622         pool->base.opps[j] = dcn301_opp_create(ctx, i);
1623         if (pool->base.opps[j] == NULL) {
1624             BREAK_TO_DEBUGGER();
1625             dm_error(
1626                 "DC: failed to create output pixel processor!\n");
1627             goto create_fail;
1628         }
1629 
1630         pool->base.timing_generators[j] = dcn301_timing_generator_create(ctx, i);
1631         if (pool->base.timing_generators[j] == NULL) {
1632             BREAK_TO_DEBUGGER();
1633             dm_error("DC: failed to create tg!\n");
1634             goto create_fail;
1635         }
1636         j++;
1637     }
1638     pool->base.timing_generator_count = j;
1639     pool->base.pipe_count = j;
1640     pool->base.mpcc_count = j;
1641 
1642     /* ABM (or ABMs for NV2x) */
1643     /* TODO: */
1644     for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) {
1645         pool->base.multiple_abms[i] = dmub_abm_create(ctx,
1646                 &abm_regs[i],
1647                 &abm_shift,
1648                 &abm_mask);
1649         if (pool->base.multiple_abms[i] == NULL) {
1650             dm_error("DC: failed to create abm for pipe %d!\n", i);
1651             BREAK_TO_DEBUGGER();
1652             goto create_fail;
1653         }
1654     }
1655 
1656     /* MPC and DSC */
1657     pool->base.mpc = dcn301_mpc_create(ctx, pool->base.mpcc_count, pool->base.res_cap->num_mpc_3dlut);
1658     if (pool->base.mpc == NULL) {
1659         BREAK_TO_DEBUGGER();
1660         dm_error("DC: failed to create mpc!\n");
1661         goto create_fail;
1662     }
1663 
1664     for (i = 0; i < pool->base.res_cap->num_dsc; i++) {
1665         pool->base.dscs[i] = dcn301_dsc_create(ctx, i);
1666         if (pool->base.dscs[i] == NULL) {
1667             BREAK_TO_DEBUGGER();
1668             dm_error("DC: failed to create display stream compressor %d!\n", i);
1669             goto create_fail;
1670         }
1671     }
1672 
1673     /* DWB and MMHUBBUB */
1674     if (!dcn301_dwbc_create(ctx, &pool->base)) {
1675         BREAK_TO_DEBUGGER();
1676         dm_error("DC: failed to create dwbc!\n");
1677         goto create_fail;
1678     }
1679 
1680     if (!dcn301_mmhubbub_create(ctx, &pool->base)) {
1681         BREAK_TO_DEBUGGER();
1682         dm_error("DC: failed to create mcif_wb!\n");
1683         goto create_fail;
1684     }
1685 
1686     /* AUX and I2C */
1687     for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
1688         pool->base.engines[i] = dcn301_aux_engine_create(ctx, i);
1689         if (pool->base.engines[i] == NULL) {
1690             BREAK_TO_DEBUGGER();
1691             dm_error(
1692                 "DC:failed to create aux engine!!\n");
1693             goto create_fail;
1694         }
1695         pool->base.hw_i2cs[i] = dcn301_i2c_hw_create(ctx, i);
1696         if (pool->base.hw_i2cs[i] == NULL) {
1697             BREAK_TO_DEBUGGER();
1698             dm_error(
1699                 "DC:failed to create hw i2c!!\n");
1700             goto create_fail;
1701         }
1702         pool->base.sw_i2cs[i] = NULL;
1703     }
1704 
1705     /* Audio, Stream Encoders including HPO and virtual, MPC 3D LUTs */
1706     if (!resource_construct(num_virtual_links, dc, &pool->base,
1707             (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment) ?
1708             &res_create_funcs : &res_create_maximus_funcs)))
1709             goto create_fail;
1710 
1711     /* HW Sequencer and Plane caps */
1712     dcn301_hw_sequencer_construct(dc);
1713 
1714     dc->caps.max_planes =  pool->base.pipe_count;
1715 
1716     for (i = 0; i < dc->caps.max_planes; ++i)
1717         dc->caps.planes[i] = plane_cap;
1718 
1719     dc->cap_funcs = cap_funcs;
1720 
1721     return true;
1722 
1723 create_fail:
1724 
1725     dcn301_destruct(pool);
1726 
1727     return false;
1728 }
1729 
1730 struct resource_pool *dcn301_create_resource_pool(
1731         const struct dc_init_data *init_data,
1732         struct dc *dc)
1733 {
1734     struct dcn301_resource_pool *pool =
1735         kzalloc(sizeof(struct dcn301_resource_pool), GFP_KERNEL);
1736 
1737     if (!pool)
1738         return NULL;
1739 
1740     if (dcn301_resource_construct(init_data->num_virtual_links, dc, pool))
1741         return &pool->base;
1742 
1743     BREAK_TO_DEBUGGER();
1744     kfree(pool);
1745     return NULL;
1746 }