1 /* 2 * Copyright 2020 Advanced Micro Devices, Inc. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 * 22 * Authors: AMD 23 * 24 */ 25 26 27 #include "dm_services.h" 28 #include "dc.h" 29 30 #include "dcn30_init.h" 31 32 #include "resource.h" 33 #include "include/irq_service_interface.h" 34 #include "dcn20/dcn20_resource.h" 35 36 #include "dcn30_resource.h" 37 38 #include "dcn10/dcn10_ipp.h" 39 #include "dcn30/dcn30_hubbub.h" 40 #include "dcn30/dcn30_mpc.h" 41 #include "dcn30/dcn30_hubp.h" 42 #include "irq/dcn30/irq_service_dcn30.h" 43 #include "dcn30/dcn30_dpp.h" 44 #include "dcn30/dcn30_optc.h" 45 #include "dcn20/dcn20_hwseq.h" 46 #include "dcn30/dcn30_hwseq.h" 47 #include "dce110/dce110_hw_sequencer.h" 48 #include "dcn30/dcn30_opp.h" 49 #include "dcn20/dcn20_dsc.h" 50 #include "dcn30/dcn30_vpg.h" 51 #include "dcn30/dcn30_afmt.h" 52 #include "dcn30/dcn30_dio_stream_encoder.h" 53 #include "dcn30/dcn30_dio_link_encoder.h" 54 #include "dce/dce_clock_source.h" 55 #include "dce/dce_audio.h" 56 #include "dce/dce_hwseq.h" 57 #include "clk_mgr.h" 58 #include "virtual/virtual_stream_encoder.h" 59 #include "dce110/dce110_resource.h" 60 #include "dml/display_mode_vba.h" 61 #include "dcn30/dcn30_dccg.h" 62 #include "dcn10/dcn10_resource.h" 63 #include "dc_link_ddc.h" 64 #include "dce/dce_panel_cntl.h" 65 66 #include "dcn30/dcn30_dwb.h" 67 #include "dcn30/dcn30_mmhubbub.h" 68 69 #include "sienna_cichlid_ip_offset.h" 70 #include "dcn/dcn_3_0_0_offset.h" 71 #include "dcn/dcn_3_0_0_sh_mask.h" 72 73 #include "nbio/nbio_7_4_offset.h" 74 75 #include "dpcs/dpcs_3_0_0_offset.h" 76 #include "dpcs/dpcs_3_0_0_sh_mask.h" 77 78 #include "mmhub/mmhub_2_0_0_offset.h" 79 #include "mmhub/mmhub_2_0_0_sh_mask.h" 80 81 #include "reg_helper.h" 82 #include "dce/dmub_abm.h" 83 #include "dce/dmub_psr.h" 84 #include "dce/dce_aux.h" 85 #include "dce/dce_i2c.h" 86 87 #include "dml/dcn30/dcn30_fpu.h" 88 #include "dml/dcn30/display_mode_vba_30.h" 89 #include "vm_helper.h" 90 #include "dcn20/dcn20_vmid.h" 91 #include "amdgpu_socbb.h" 92 #include "dc_dmub_srv.h" 93 94 #define DC_LOGGER_INIT(logger) 95 96 enum dcn30_clk_src_array_id { 97 DCN30_CLK_SRC_PLL0, 98 DCN30_CLK_SRC_PLL1, 99 DCN30_CLK_SRC_PLL2, 100 DCN30_CLK_SRC_PLL3, 101 DCN30_CLK_SRC_PLL4, 102 DCN30_CLK_SRC_PLL5, 103 DCN30_CLK_SRC_TOTAL 104 }; 105 106 /* begin ********************* 107 * macros to expend register list macro defined in HW object header file 108 */ 109 110 /* DCN */ 111 /* TODO awful hack. fixup dcn20_dwb.h */ 112 #undef BASE_INNER 113 #define BASE_INNER(seg) DCN_BASE__INST0_SEG ## seg 114 115 #define BASE(seg) BASE_INNER(seg) 116 117 #define SR(reg_name)\ 118 .reg_name = BASE(mm ## reg_name ## _BASE_IDX) + \ 119 mm ## reg_name 120 121 #define SRI(reg_name, block, id)\ 122 .reg_name = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \ 123 mm ## block ## id ## _ ## reg_name 124 125 #define SRI2(reg_name, block, id)\ 126 .reg_name = BASE(mm ## reg_name ## _BASE_IDX) + \ 127 mm ## reg_name 128 129 #define SRIR(var_name, reg_name, block, id)\ 130 .var_name = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \ 131 mm ## block ## id ## _ ## reg_name 132 133 #define SRII(reg_name, block, id)\ 134 .reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \ 135 mm ## block ## id ## _ ## reg_name 136 137 #define SRII_MPC_RMU(reg_name, block, id)\ 138 .RMU##_##reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \ 139 mm ## block ## id ## _ ## reg_name 140 141 #define SRII_DWB(reg_name, temp_name, block, id)\ 142 .reg_name[id] = BASE(mm ## block ## id ## _ ## temp_name ## _BASE_IDX) + \ 143 mm ## block ## id ## _ ## temp_name 144 145 #define DCCG_SRII(reg_name, block, id)\ 146 .block ## _ ## reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \ 147 mm ## block ## id ## _ ## reg_name 148 149 #define VUPDATE_SRII(reg_name, block, id)\ 150 .reg_name[id] = BASE(mm ## reg_name ## _ ## block ## id ## _BASE_IDX) + \ 151 mm ## reg_name ## _ ## block ## id 152 153 /* NBIO */ 154 #define NBIO_BASE_INNER(seg) \ 155 NBIO_BASE__INST0_SEG ## seg 156 157 #define NBIO_BASE(seg) \ 158 NBIO_BASE_INNER(seg) 159 160 #define NBIO_SR(reg_name)\ 161 .reg_name = NBIO_BASE(mm ## reg_name ## _BASE_IDX) + \ 162 mm ## reg_name 163 164 /* MMHUB */ 165 #define MMHUB_BASE_INNER(seg) \ 166 MMHUB_BASE__INST0_SEG ## seg 167 168 #define MMHUB_BASE(seg) \ 169 MMHUB_BASE_INNER(seg) 170 171 #define MMHUB_SR(reg_name)\ 172 .reg_name = MMHUB_BASE(mmMM ## reg_name ## _BASE_IDX) + \ 173 mmMM ## reg_name 174 175 /* CLOCK */ 176 #define CLK_BASE_INNER(seg) \ 177 CLK_BASE__INST0_SEG ## seg 178 179 #define CLK_BASE(seg) \ 180 CLK_BASE_INNER(seg) 181 182 #define CLK_SRI(reg_name, block, inst)\ 183 .reg_name = CLK_BASE(mm ## block ## _ ## inst ## _ ## reg_name ## _BASE_IDX) + \ 184 mm ## block ## _ ## inst ## _ ## reg_name 185 186 187 static const struct bios_registers bios_regs = { 188 NBIO_SR(BIOS_SCRATCH_3), 189 NBIO_SR(BIOS_SCRATCH_6) 190 }; 191 192 #define clk_src_regs(index, pllid)\ 193 [index] = {\ 194 CS_COMMON_REG_LIST_DCN2_0(index, pllid),\ 195 } 196 197 static const struct dce110_clk_src_regs clk_src_regs[] = { 198 clk_src_regs(0, A), 199 clk_src_regs(1, B), 200 clk_src_regs(2, C), 201 clk_src_regs(3, D), 202 clk_src_regs(4, E), 203 clk_src_regs(5, F) 204 }; 205 206 static const struct dce110_clk_src_shift cs_shift = { 207 CS_COMMON_MASK_SH_LIST_DCN2_0(__SHIFT) 208 }; 209 210 static const struct dce110_clk_src_mask cs_mask = { 211 CS_COMMON_MASK_SH_LIST_DCN2_0(_MASK) 212 }; 213 214 #define abm_regs(id)\ 215 [id] = {\ 216 ABM_DCN30_REG_LIST(id)\ 217 } 218 219 static const struct dce_abm_registers abm_regs[] = { 220 abm_regs(0), 221 abm_regs(1), 222 abm_regs(2), 223 abm_regs(3), 224 abm_regs(4), 225 abm_regs(5), 226 }; 227 228 static const struct dce_abm_shift abm_shift = { 229 ABM_MASK_SH_LIST_DCN30(__SHIFT) 230 }; 231 232 static const struct dce_abm_mask abm_mask = { 233 ABM_MASK_SH_LIST_DCN30(_MASK) 234 }; 235 236 237 238 #define audio_regs(id)\ 239 [id] = {\ 240 AUD_COMMON_REG_LIST(id)\ 241 } 242 243 static const struct dce_audio_registers audio_regs[] = { 244 audio_regs(0), 245 audio_regs(1), 246 audio_regs(2), 247 audio_regs(3), 248 audio_regs(4), 249 audio_regs(5), 250 audio_regs(6) 251 }; 252 253 #define DCE120_AUD_COMMON_MASK_SH_LIST(mask_sh)\ 254 SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_INDEX, AZALIA_ENDPOINT_REG_INDEX, mask_sh),\ 255 SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_DATA, AZALIA_ENDPOINT_REG_DATA, mask_sh),\ 256 AUD_COMMON_MASK_SH_LIST_BASE(mask_sh) 257 258 static const struct dce_audio_shift audio_shift = { 259 DCE120_AUD_COMMON_MASK_SH_LIST(__SHIFT) 260 }; 261 262 static const struct dce_audio_mask audio_mask = { 263 DCE120_AUD_COMMON_MASK_SH_LIST(_MASK) 264 }; 265 266 #define vpg_regs(id)\ 267 [id] = {\ 268 VPG_DCN3_REG_LIST(id)\ 269 } 270 271 static const struct dcn30_vpg_registers vpg_regs[] = { 272 vpg_regs(0), 273 vpg_regs(1), 274 vpg_regs(2), 275 vpg_regs(3), 276 vpg_regs(4), 277 vpg_regs(5), 278 vpg_regs(6), 279 }; 280 281 static const struct dcn30_vpg_shift vpg_shift = { 282 DCN3_VPG_MASK_SH_LIST(__SHIFT) 283 }; 284 285 static const struct dcn30_vpg_mask vpg_mask = { 286 DCN3_VPG_MASK_SH_LIST(_MASK) 287 }; 288 289 #define afmt_regs(id)\ 290 [id] = {\ 291 AFMT_DCN3_REG_LIST(id)\ 292 } 293 294 static const struct dcn30_afmt_registers afmt_regs[] = { 295 afmt_regs(0), 296 afmt_regs(1), 297 afmt_regs(2), 298 afmt_regs(3), 299 afmt_regs(4), 300 afmt_regs(5), 301 afmt_regs(6), 302 }; 303 304 static const struct dcn30_afmt_shift afmt_shift = { 305 DCN3_AFMT_MASK_SH_LIST(__SHIFT) 306 }; 307 308 static const struct dcn30_afmt_mask afmt_mask = { 309 DCN3_AFMT_MASK_SH_LIST(_MASK) 310 }; 311 312 #define stream_enc_regs(id)\ 313 [id] = {\ 314 SE_DCN3_REG_LIST(id)\ 315 } 316 317 static const struct dcn10_stream_enc_registers stream_enc_regs[] = { 318 stream_enc_regs(0), 319 stream_enc_regs(1), 320 stream_enc_regs(2), 321 stream_enc_regs(3), 322 stream_enc_regs(4), 323 stream_enc_regs(5) 324 }; 325 326 static const struct dcn10_stream_encoder_shift se_shift = { 327 SE_COMMON_MASK_SH_LIST_DCN30(__SHIFT) 328 }; 329 330 static const struct dcn10_stream_encoder_mask se_mask = { 331 SE_COMMON_MASK_SH_LIST_DCN30(_MASK) 332 }; 333 334 335 #define aux_regs(id)\ 336 [id] = {\ 337 DCN2_AUX_REG_LIST(id)\ 338 } 339 340 static const struct dcn10_link_enc_aux_registers link_enc_aux_regs[] = { 341 aux_regs(0), 342 aux_regs(1), 343 aux_regs(2), 344 aux_regs(3), 345 aux_regs(4), 346 aux_regs(5) 347 }; 348 349 #define hpd_regs(id)\ 350 [id] = {\ 351 HPD_REG_LIST(id)\ 352 } 353 354 static const struct dcn10_link_enc_hpd_registers link_enc_hpd_regs[] = { 355 hpd_regs(0), 356 hpd_regs(1), 357 hpd_regs(2), 358 hpd_regs(3), 359 hpd_regs(4), 360 hpd_regs(5) 361 }; 362 363 #define link_regs(id, phyid)\ 364 [id] = {\ 365 LE_DCN3_REG_LIST(id), \ 366 UNIPHY_DCN2_REG_LIST(phyid), \ 367 DPCS_DCN2_REG_LIST(id), \ 368 SRI(DP_DPHY_INTERNAL_CTRL, DP, id) \ 369 } 370 371 static const struct dce110_aux_registers_shift aux_shift = { 372 DCN_AUX_MASK_SH_LIST(__SHIFT) 373 }; 374 375 static const struct dce110_aux_registers_mask aux_mask = { 376 DCN_AUX_MASK_SH_LIST(_MASK) 377 }; 378 379 static const struct dcn10_link_enc_registers link_enc_regs[] = { 380 link_regs(0, A), 381 link_regs(1, B), 382 link_regs(2, C), 383 link_regs(3, D), 384 link_regs(4, E), 385 link_regs(5, F) 386 }; 387 388 static const struct dcn10_link_enc_shift le_shift = { 389 LINK_ENCODER_MASK_SH_LIST_DCN30(__SHIFT),\ 390 DPCS_DCN2_MASK_SH_LIST(__SHIFT) 391 }; 392 393 static const struct dcn10_link_enc_mask le_mask = { 394 LINK_ENCODER_MASK_SH_LIST_DCN30(_MASK),\ 395 DPCS_DCN2_MASK_SH_LIST(_MASK) 396 }; 397 398 399 static const struct dce_panel_cntl_registers panel_cntl_regs[] = { 400 { DCN_PANEL_CNTL_REG_LIST() } 401 }; 402 403 static const struct dce_panel_cntl_shift panel_cntl_shift = { 404 DCE_PANEL_CNTL_MASK_SH_LIST(__SHIFT) 405 }; 406 407 static const struct dce_panel_cntl_mask panel_cntl_mask = { 408 DCE_PANEL_CNTL_MASK_SH_LIST(_MASK) 409 }; 410 411 #define dpp_regs(id)\ 412 [id] = {\ 413 DPP_REG_LIST_DCN30(id),\ 414 } 415 416 static const struct dcn3_dpp_registers dpp_regs[] = { 417 dpp_regs(0), 418 dpp_regs(1), 419 dpp_regs(2), 420 dpp_regs(3), 421 dpp_regs(4), 422 dpp_regs(5), 423 }; 424 425 static const struct dcn3_dpp_shift tf_shift = { 426 DPP_REG_LIST_SH_MASK_DCN30(__SHIFT) 427 }; 428 429 static const struct dcn3_dpp_mask tf_mask = { 430 DPP_REG_LIST_SH_MASK_DCN30(_MASK) 431 }; 432 433 #define opp_regs(id)\ 434 [id] = {\ 435 OPP_REG_LIST_DCN30(id),\ 436 } 437 438 static const struct dcn20_opp_registers opp_regs[] = { 439 opp_regs(0), 440 opp_regs(1), 441 opp_regs(2), 442 opp_regs(3), 443 opp_regs(4), 444 opp_regs(5) 445 }; 446 447 static const struct dcn20_opp_shift opp_shift = { 448 OPP_MASK_SH_LIST_DCN20(__SHIFT) 449 }; 450 451 static const struct dcn20_opp_mask opp_mask = { 452 OPP_MASK_SH_LIST_DCN20(_MASK) 453 }; 454 455 #define aux_engine_regs(id)\ 456 [id] = {\ 457 AUX_COMMON_REG_LIST0(id), \ 458 .AUXN_IMPCAL = 0, \ 459 .AUXP_IMPCAL = 0, \ 460 .AUX_RESET_MASK = DP_AUX0_AUX_CONTROL__AUX_RESET_MASK, \ 461 } 462 463 static const struct dce110_aux_registers aux_engine_regs[] = { 464 aux_engine_regs(0), 465 aux_engine_regs(1), 466 aux_engine_regs(2), 467 aux_engine_regs(3), 468 aux_engine_regs(4), 469 aux_engine_regs(5) 470 }; 471 472 #define dwbc_regs_dcn3(id)\ 473 [id] = {\ 474 DWBC_COMMON_REG_LIST_DCN30(id),\ 475 } 476 477 static const struct dcn30_dwbc_registers dwbc30_regs[] = { 478 dwbc_regs_dcn3(0), 479 }; 480 481 static const struct dcn30_dwbc_shift dwbc30_shift = { 482 DWBC_COMMON_MASK_SH_LIST_DCN30(__SHIFT) 483 }; 484 485 static const struct dcn30_dwbc_mask dwbc30_mask = { 486 DWBC_COMMON_MASK_SH_LIST_DCN30(_MASK) 487 }; 488 489 #define mcif_wb_regs_dcn3(id)\ 490 [id] = {\ 491 MCIF_WB_COMMON_REG_LIST_DCN30(id),\ 492 } 493 494 static const struct dcn30_mmhubbub_registers mcif_wb30_regs[] = { 495 mcif_wb_regs_dcn3(0) 496 }; 497 498 static const struct dcn30_mmhubbub_shift mcif_wb30_shift = { 499 MCIF_WB_COMMON_MASK_SH_LIST_DCN30(__SHIFT) 500 }; 501 502 static const struct dcn30_mmhubbub_mask mcif_wb30_mask = { 503 MCIF_WB_COMMON_MASK_SH_LIST_DCN30(_MASK) 504 }; 505 506 #define dsc_regsDCN20(id)\ 507 [id] = {\ 508 DSC_REG_LIST_DCN20(id)\ 509 } 510 511 static const struct dcn20_dsc_registers dsc_regs[] = { 512 dsc_regsDCN20(0), 513 dsc_regsDCN20(1), 514 dsc_regsDCN20(2), 515 dsc_regsDCN20(3), 516 dsc_regsDCN20(4), 517 dsc_regsDCN20(5) 518 }; 519 520 static const struct dcn20_dsc_shift dsc_shift = { 521 DSC_REG_LIST_SH_MASK_DCN20(__SHIFT) 522 }; 523 524 static const struct dcn20_dsc_mask dsc_mask = { 525 DSC_REG_LIST_SH_MASK_DCN20(_MASK) 526 }; 527 528 static const struct dcn30_mpc_registers mpc_regs = { 529 MPC_REG_LIST_DCN3_0(0), 530 MPC_REG_LIST_DCN3_0(1), 531 MPC_REG_LIST_DCN3_0(2), 532 MPC_REG_LIST_DCN3_0(3), 533 MPC_REG_LIST_DCN3_0(4), 534 MPC_REG_LIST_DCN3_0(5), 535 MPC_OUT_MUX_REG_LIST_DCN3_0(0), 536 MPC_OUT_MUX_REG_LIST_DCN3_0(1), 537 MPC_OUT_MUX_REG_LIST_DCN3_0(2), 538 MPC_OUT_MUX_REG_LIST_DCN3_0(3), 539 MPC_OUT_MUX_REG_LIST_DCN3_0(4), 540 MPC_OUT_MUX_REG_LIST_DCN3_0(5), 541 MPC_RMU_GLOBAL_REG_LIST_DCN3AG, 542 MPC_RMU_REG_LIST_DCN3AG(0), 543 MPC_RMU_REG_LIST_DCN3AG(1), 544 MPC_RMU_REG_LIST_DCN3AG(2), 545 MPC_DWB_MUX_REG_LIST_DCN3_0(0), 546 }; 547 548 static const struct dcn30_mpc_shift mpc_shift = { 549 MPC_COMMON_MASK_SH_LIST_DCN30(__SHIFT) 550 }; 551 552 static const struct dcn30_mpc_mask mpc_mask = { 553 MPC_COMMON_MASK_SH_LIST_DCN30(_MASK) 554 }; 555 556 #define optc_regs(id)\ 557 [id] = {OPTC_COMMON_REG_LIST_DCN3_0(id)} 558 559 560 static const struct dcn_optc_registers optc_regs[] = { 561 optc_regs(0), 562 optc_regs(1), 563 optc_regs(2), 564 optc_regs(3), 565 optc_regs(4), 566 optc_regs(5) 567 }; 568 569 static const struct dcn_optc_shift optc_shift = { 570 OPTC_COMMON_MASK_SH_LIST_DCN30(__SHIFT) 571 }; 572 573 static const struct dcn_optc_mask optc_mask = { 574 OPTC_COMMON_MASK_SH_LIST_DCN30(_MASK) 575 }; 576 577 #define hubp_regs(id)\ 578 [id] = {\ 579 HUBP_REG_LIST_DCN30(id)\ 580 } 581 582 static const struct dcn_hubp2_registers hubp_regs[] = { 583 hubp_regs(0), 584 hubp_regs(1), 585 hubp_regs(2), 586 hubp_regs(3), 587 hubp_regs(4), 588 hubp_regs(5) 589 }; 590 591 static const struct dcn_hubp2_shift hubp_shift = { 592 HUBP_MASK_SH_LIST_DCN30(__SHIFT) 593 }; 594 595 static const struct dcn_hubp2_mask hubp_mask = { 596 HUBP_MASK_SH_LIST_DCN30(_MASK) 597 }; 598 599 static const struct dcn_hubbub_registers hubbub_reg = { 600 HUBBUB_REG_LIST_DCN30(0) 601 }; 602 603 static const struct dcn_hubbub_shift hubbub_shift = { 604 HUBBUB_MASK_SH_LIST_DCN30(__SHIFT) 605 }; 606 607 static const struct dcn_hubbub_mask hubbub_mask = { 608 HUBBUB_MASK_SH_LIST_DCN30(_MASK) 609 }; 610 611 static const struct dccg_registers dccg_regs = { 612 DCCG_REG_LIST_DCN30() 613 }; 614 615 static const struct dccg_shift dccg_shift = { 616 DCCG_MASK_SH_LIST_DCN3(__SHIFT) 617 }; 618 619 static const struct dccg_mask dccg_mask = { 620 DCCG_MASK_SH_LIST_DCN3(_MASK) 621 }; 622 623 static const struct dce_hwseq_registers hwseq_reg = { 624 HWSEQ_DCN30_REG_LIST() 625 }; 626 627 static const struct dce_hwseq_shift hwseq_shift = { 628 HWSEQ_DCN30_MASK_SH_LIST(__SHIFT) 629 }; 630 631 static const struct dce_hwseq_mask hwseq_mask = { 632 HWSEQ_DCN30_MASK_SH_LIST(_MASK) 633 }; 634 #define vmid_regs(id)\ 635 [id] = {\ 636 DCN20_VMID_REG_LIST(id)\ 637 } 638 639 static const struct dcn_vmid_registers vmid_regs[] = { 640 vmid_regs(0), 641 vmid_regs(1), 642 vmid_regs(2), 643 vmid_regs(3), 644 vmid_regs(4), 645 vmid_regs(5), 646 vmid_regs(6), 647 vmid_regs(7), 648 vmid_regs(8), 649 vmid_regs(9), 650 vmid_regs(10), 651 vmid_regs(11), 652 vmid_regs(12), 653 vmid_regs(13), 654 vmid_regs(14), 655 vmid_regs(15) 656 }; 657 658 static const struct dcn20_vmid_shift vmid_shifts = { 659 DCN20_VMID_MASK_SH_LIST(__SHIFT) 660 }; 661 662 static const struct dcn20_vmid_mask vmid_masks = { 663 DCN20_VMID_MASK_SH_LIST(_MASK) 664 }; 665 666 static const struct resource_caps res_cap_dcn3 = { 667 .num_timing_generator = 6, 668 .num_opp = 6, 669 .num_video_plane = 6, 670 .num_audio = 6, 671 .num_stream_encoder = 6, 672 .num_pll = 6, 673 .num_dwb = 1, 674 .num_ddc = 6, 675 .num_vmid = 16, 676 .num_mpc_3dlut = 3, 677 .num_dsc = 6, 678 }; 679 680 static const struct dc_plane_cap plane_cap = { 681 .type = DC_PLANE_TYPE_DCN_UNIVERSAL, 682 .blends_with_above = true, 683 .blends_with_below = true, 684 .per_pixel_alpha = true, 685 686 .pixel_format_support = { 687 .argb8888 = true, 688 .nv12 = true, 689 .fp16 = true, 690 .p010 = true, 691 .ayuv = false, 692 }, 693 694 .max_upscale_factor = { 695 .argb8888 = 16000, 696 .nv12 = 16000, 697 .fp16 = 16000 698 }, 699 700 /* 6:1 downscaling ratio: 1000/6 = 166.666 */ 701 .max_downscale_factor = { 702 .argb8888 = 167, 703 .nv12 = 167, 704 .fp16 = 167 705 } 706 }; 707 708 static const struct dc_debug_options debug_defaults_drv = { 709 .disable_dmcu = true, //No DMCU on DCN30 710 .force_abm_enable = false, 711 .timing_trace = false, 712 .clock_trace = true, 713 .disable_pplib_clock_request = true, 714 .pipe_split_policy = MPC_SPLIT_DYNAMIC, 715 .force_single_disp_pipe_split = false, 716 .disable_dcc = DCC_ENABLE, 717 .vsr_support = true, 718 .performance_trace = false, 719 .max_downscale_src_width = 7680,/*upto 8K*/ 720 .disable_pplib_wm_range = false, 721 .scl_reset_length10 = true, 722 .sanity_checks = false, 723 .underflow_assert_delay_us = 0xFFFFFFFF, 724 .dwb_fi_phase = -1, // -1 = disable, 725 .dmub_command_table = true, 726 .use_max_lb = true, 727 .exit_idle_opt_for_cursor_updates = true 728 }; 729 730 static const struct dc_debug_options debug_defaults_diags = { 731 .disable_dmcu = true, //No dmcu on DCN30 732 .force_abm_enable = false, 733 .timing_trace = true, 734 .clock_trace = true, 735 .disable_dpp_power_gate = true, 736 .disable_hubp_power_gate = true, 737 .disable_clock_gate = true, 738 .disable_pplib_clock_request = true, 739 .disable_pplib_wm_range = true, 740 .disable_stutter = false, 741 .scl_reset_length10 = true, 742 .dwb_fi_phase = -1, // -1 = disable 743 .dmub_command_table = true, 744 .enable_tri_buf = true, 745 .use_max_lb = true 746 }; 747 748 static const struct dc_panel_config panel_config_defaults = { 749 .psr = { 750 .disable_psr = false, 751 .disallow_psrsu = false, 752 }, 753 }; 754 755 static void dcn30_dpp_destroy(struct dpp **dpp) 756 { 757 kfree(TO_DCN20_DPP(*dpp)); 758 *dpp = NULL; 759 } 760 761 static struct dpp *dcn30_dpp_create( 762 struct dc_context *ctx, 763 uint32_t inst) 764 { 765 struct dcn3_dpp *dpp = 766 kzalloc(sizeof(struct dcn3_dpp), GFP_KERNEL); 767 768 if (!dpp) 769 return NULL; 770 771 if (dpp3_construct(dpp, ctx, inst, 772 &dpp_regs[inst], &tf_shift, &tf_mask)) 773 return &dpp->base; 774 775 BREAK_TO_DEBUGGER(); 776 kfree(dpp); 777 return NULL; 778 } 779 780 static struct output_pixel_processor *dcn30_opp_create( 781 struct dc_context *ctx, uint32_t inst) 782 { 783 struct dcn20_opp *opp = 784 kzalloc(sizeof(struct dcn20_opp), GFP_KERNEL); 785 786 if (!opp) { 787 BREAK_TO_DEBUGGER(); 788 return NULL; 789 } 790 791 dcn20_opp_construct(opp, ctx, inst, 792 &opp_regs[inst], &opp_shift, &opp_mask); 793 return &opp->base; 794 } 795 796 static struct dce_aux *dcn30_aux_engine_create( 797 struct dc_context *ctx, 798 uint32_t inst) 799 { 800 struct aux_engine_dce110 *aux_engine = 801 kzalloc(sizeof(struct aux_engine_dce110), GFP_KERNEL); 802 803 if (!aux_engine) 804 return NULL; 805 806 dce110_aux_engine_construct(aux_engine, ctx, inst, 807 SW_AUX_TIMEOUT_PERIOD_MULTIPLIER * AUX_TIMEOUT_PERIOD, 808 &aux_engine_regs[inst], 809 &aux_mask, 810 &aux_shift, 811 ctx->dc->caps.extended_aux_timeout_support); 812 813 return &aux_engine->base; 814 } 815 816 #define i2c_inst_regs(id) { I2C_HW_ENGINE_COMMON_REG_LIST_DCN30(id) } 817 818 static const struct dce_i2c_registers i2c_hw_regs[] = { 819 i2c_inst_regs(1), 820 i2c_inst_regs(2), 821 i2c_inst_regs(3), 822 i2c_inst_regs(4), 823 i2c_inst_regs(5), 824 i2c_inst_regs(6), 825 }; 826 827 static const struct dce_i2c_shift i2c_shifts = { 828 I2C_COMMON_MASK_SH_LIST_DCN30(__SHIFT) 829 }; 830 831 static const struct dce_i2c_mask i2c_masks = { 832 I2C_COMMON_MASK_SH_LIST_DCN30(_MASK) 833 }; 834 835 static struct dce_i2c_hw *dcn30_i2c_hw_create( 836 struct dc_context *ctx, 837 uint32_t inst) 838 { 839 struct dce_i2c_hw *dce_i2c_hw = 840 kzalloc(sizeof(struct dce_i2c_hw), GFP_KERNEL); 841 842 if (!dce_i2c_hw) 843 return NULL; 844 845 dcn2_i2c_hw_construct(dce_i2c_hw, ctx, inst, 846 &i2c_hw_regs[inst], &i2c_shifts, &i2c_masks); 847 848 return dce_i2c_hw; 849 } 850 851 static struct mpc *dcn30_mpc_create( 852 struct dc_context *ctx, 853 int num_mpcc, 854 int num_rmu) 855 { 856 struct dcn30_mpc *mpc30 = kzalloc(sizeof(struct dcn30_mpc), 857 GFP_KERNEL); 858 859 if (!mpc30) 860 return NULL; 861 862 dcn30_mpc_construct(mpc30, ctx, 863 &mpc_regs, 864 &mpc_shift, 865 &mpc_mask, 866 num_mpcc, 867 num_rmu); 868 869 return &mpc30->base; 870 } 871 872 static struct hubbub *dcn30_hubbub_create(struct dc_context *ctx) 873 { 874 int i; 875 876 struct dcn20_hubbub *hubbub3 = kzalloc(sizeof(struct dcn20_hubbub), 877 GFP_KERNEL); 878 879 if (!hubbub3) 880 return NULL; 881 882 hubbub3_construct(hubbub3, ctx, 883 &hubbub_reg, 884 &hubbub_shift, 885 &hubbub_mask); 886 887 888 for (i = 0; i < res_cap_dcn3.num_vmid; i++) { 889 struct dcn20_vmid *vmid = &hubbub3->vmid[i]; 890 891 vmid->ctx = ctx; 892 893 vmid->regs = &vmid_regs[i]; 894 vmid->shifts = &vmid_shifts; 895 vmid->masks = &vmid_masks; 896 } 897 898 return &hubbub3->base; 899 } 900 901 static struct timing_generator *dcn30_timing_generator_create( 902 struct dc_context *ctx, 903 uint32_t instance) 904 { 905 struct optc *tgn10 = 906 kzalloc(sizeof(struct optc), GFP_KERNEL); 907 908 if (!tgn10) 909 return NULL; 910 911 tgn10->base.inst = instance; 912 tgn10->base.ctx = ctx; 913 914 tgn10->tg_regs = &optc_regs[instance]; 915 tgn10->tg_shift = &optc_shift; 916 tgn10->tg_mask = &optc_mask; 917 918 dcn30_timing_generator_init(tgn10); 919 920 return &tgn10->base; 921 } 922 923 static const struct encoder_feature_support link_enc_feature = { 924 .max_hdmi_deep_color = COLOR_DEPTH_121212, 925 .max_hdmi_pixel_clock = 600000, 926 .hdmi_ycbcr420_supported = true, 927 .dp_ycbcr420_supported = true, 928 .fec_supported = true, 929 .flags.bits.IS_HBR2_CAPABLE = true, 930 .flags.bits.IS_HBR3_CAPABLE = true, 931 .flags.bits.IS_TPS3_CAPABLE = true, 932 .flags.bits.IS_TPS4_CAPABLE = true 933 }; 934 935 static struct link_encoder *dcn30_link_encoder_create( 936 struct dc_context *ctx, 937 const struct encoder_init_data *enc_init_data) 938 { 939 struct dcn20_link_encoder *enc20 = 940 kzalloc(sizeof(struct dcn20_link_encoder), GFP_KERNEL); 941 942 if (!enc20) 943 return NULL; 944 945 dcn30_link_encoder_construct(enc20, 946 enc_init_data, 947 &link_enc_feature, 948 &link_enc_regs[enc_init_data->transmitter], 949 &link_enc_aux_regs[enc_init_data->channel - 1], 950 &link_enc_hpd_regs[enc_init_data->hpd_source], 951 &le_shift, 952 &le_mask); 953 954 return &enc20->enc10.base; 955 } 956 957 static struct panel_cntl *dcn30_panel_cntl_create(const struct panel_cntl_init_data *init_data) 958 { 959 struct dce_panel_cntl *panel_cntl = 960 kzalloc(sizeof(struct dce_panel_cntl), GFP_KERNEL); 961 962 if (!panel_cntl) 963 return NULL; 964 965 dce_panel_cntl_construct(panel_cntl, 966 init_data, 967 &panel_cntl_regs[init_data->inst], 968 &panel_cntl_shift, 969 &panel_cntl_mask); 970 971 return &panel_cntl->base; 972 } 973 974 static void read_dce_straps( 975 struct dc_context *ctx, 976 struct resource_straps *straps) 977 { 978 generic_reg_get(ctx, mmDC_PINSTRAPS + BASE(mmDC_PINSTRAPS_BASE_IDX), 979 FN(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO), &straps->dc_pinstraps_audio); 980 981 } 982 983 static struct audio *dcn30_create_audio( 984 struct dc_context *ctx, unsigned int inst) 985 { 986 return dce_audio_create(ctx, inst, 987 &audio_regs[inst], &audio_shift, &audio_mask); 988 } 989 990 static struct vpg *dcn30_vpg_create( 991 struct dc_context *ctx, 992 uint32_t inst) 993 { 994 struct dcn30_vpg *vpg3 = kzalloc(sizeof(struct dcn30_vpg), GFP_KERNEL); 995 996 if (!vpg3) 997 return NULL; 998 999 vpg3_construct(vpg3, ctx, inst, 1000 &vpg_regs[inst], 1001 &vpg_shift, 1002 &vpg_mask); 1003 1004 return &vpg3->base; 1005 } 1006 1007 static struct afmt *dcn30_afmt_create( 1008 struct dc_context *ctx, 1009 uint32_t inst) 1010 { 1011 struct dcn30_afmt *afmt3 = kzalloc(sizeof(struct dcn30_afmt), GFP_KERNEL); 1012 1013 if (!afmt3) 1014 return NULL; 1015 1016 afmt3_construct(afmt3, ctx, inst, 1017 &afmt_regs[inst], 1018 &afmt_shift, 1019 &afmt_mask); 1020 1021 return &afmt3->base; 1022 } 1023 1024 static struct stream_encoder *dcn30_stream_encoder_create(enum engine_id eng_id, 1025 struct dc_context *ctx) 1026 { 1027 struct dcn10_stream_encoder *enc1; 1028 struct vpg *vpg; 1029 struct afmt *afmt; 1030 int vpg_inst; 1031 int afmt_inst; 1032 1033 /* Mapping of VPG, AFMT, DME register blocks to DIO block instance */ 1034 if (eng_id <= ENGINE_ID_DIGF) { 1035 vpg_inst = eng_id; 1036 afmt_inst = eng_id; 1037 } else 1038 return NULL; 1039 1040 enc1 = kzalloc(sizeof(struct dcn10_stream_encoder), GFP_KERNEL); 1041 vpg = dcn30_vpg_create(ctx, vpg_inst); 1042 afmt = dcn30_afmt_create(ctx, afmt_inst); 1043 1044 if (!enc1 || !vpg || !afmt) { 1045 kfree(enc1); 1046 kfree(vpg); 1047 kfree(afmt); 1048 return NULL; 1049 } 1050 1051 dcn30_dio_stream_encoder_construct(enc1, ctx, ctx->dc_bios, 1052 eng_id, vpg, afmt, 1053 &stream_enc_regs[eng_id], 1054 &se_shift, &se_mask); 1055 1056 return &enc1->base; 1057 } 1058 1059 static struct dce_hwseq *dcn30_hwseq_create(struct dc_context *ctx) 1060 { 1061 struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL); 1062 1063 if (hws) { 1064 hws->ctx = ctx; 1065 hws->regs = &hwseq_reg; 1066 hws->shifts = &hwseq_shift; 1067 hws->masks = &hwseq_mask; 1068 } 1069 return hws; 1070 } 1071 static const struct resource_create_funcs res_create_funcs = { 1072 .read_dce_straps = read_dce_straps, 1073 .create_audio = dcn30_create_audio, 1074 .create_stream_encoder = dcn30_stream_encoder_create, 1075 .create_hwseq = dcn30_hwseq_create, 1076 }; 1077 1078 static const struct resource_create_funcs res_create_maximus_funcs = { 1079 .read_dce_straps = NULL, 1080 .create_audio = NULL, 1081 .create_stream_encoder = NULL, 1082 .create_hwseq = dcn30_hwseq_create, 1083 }; 1084 1085 static void dcn30_resource_destruct(struct dcn30_resource_pool *pool) 1086 { 1087 unsigned int i; 1088 1089 for (i = 0; i < pool->base.stream_enc_count; i++) { 1090 if (pool->base.stream_enc[i] != NULL) { 1091 if (pool->base.stream_enc[i]->vpg != NULL) { 1092 kfree(DCN30_VPG_FROM_VPG(pool->base.stream_enc[i]->vpg)); 1093 pool->base.stream_enc[i]->vpg = NULL; 1094 } 1095 if (pool->base.stream_enc[i]->afmt != NULL) { 1096 kfree(DCN30_AFMT_FROM_AFMT(pool->base.stream_enc[i]->afmt)); 1097 pool->base.stream_enc[i]->afmt = NULL; 1098 } 1099 kfree(DCN10STRENC_FROM_STRENC(pool->base.stream_enc[i])); 1100 pool->base.stream_enc[i] = NULL; 1101 } 1102 } 1103 1104 for (i = 0; i < pool->base.res_cap->num_dsc; i++) { 1105 if (pool->base.dscs[i] != NULL) 1106 dcn20_dsc_destroy(&pool->base.dscs[i]); 1107 } 1108 1109 if (pool->base.mpc != NULL) { 1110 kfree(TO_DCN20_MPC(pool->base.mpc)); 1111 pool->base.mpc = NULL; 1112 } 1113 if (pool->base.hubbub != NULL) { 1114 kfree(pool->base.hubbub); 1115 pool->base.hubbub = NULL; 1116 } 1117 for (i = 0; i < pool->base.pipe_count; i++) { 1118 if (pool->base.dpps[i] != NULL) 1119 dcn30_dpp_destroy(&pool->base.dpps[i]); 1120 1121 if (pool->base.ipps[i] != NULL) 1122 pool->base.ipps[i]->funcs->ipp_destroy(&pool->base.ipps[i]); 1123 1124 if (pool->base.hubps[i] != NULL) { 1125 kfree(TO_DCN20_HUBP(pool->base.hubps[i])); 1126 pool->base.hubps[i] = NULL; 1127 } 1128 1129 if (pool->base.irqs != NULL) { 1130 dal_irq_service_destroy(&pool->base.irqs); 1131 } 1132 } 1133 1134 for (i = 0; i < pool->base.res_cap->num_ddc; i++) { 1135 if (pool->base.engines[i] != NULL) 1136 dce110_engine_destroy(&pool->base.engines[i]); 1137 if (pool->base.hw_i2cs[i] != NULL) { 1138 kfree(pool->base.hw_i2cs[i]); 1139 pool->base.hw_i2cs[i] = NULL; 1140 } 1141 if (pool->base.sw_i2cs[i] != NULL) { 1142 kfree(pool->base.sw_i2cs[i]); 1143 pool->base.sw_i2cs[i] = NULL; 1144 } 1145 } 1146 1147 for (i = 0; i < pool->base.res_cap->num_opp; i++) { 1148 if (pool->base.opps[i] != NULL) 1149 pool->base.opps[i]->funcs->opp_destroy(&pool->base.opps[i]); 1150 } 1151 1152 for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) { 1153 if (pool->base.timing_generators[i] != NULL) { 1154 kfree(DCN10TG_FROM_TG(pool->base.timing_generators[i])); 1155 pool->base.timing_generators[i] = NULL; 1156 } 1157 } 1158 1159 for (i = 0; i < pool->base.res_cap->num_dwb; i++) { 1160 if (pool->base.dwbc[i] != NULL) { 1161 kfree(TO_DCN30_DWBC(pool->base.dwbc[i])); 1162 pool->base.dwbc[i] = NULL; 1163 } 1164 if (pool->base.mcif_wb[i] != NULL) { 1165 kfree(TO_DCN30_MMHUBBUB(pool->base.mcif_wb[i])); 1166 pool->base.mcif_wb[i] = NULL; 1167 } 1168 } 1169 1170 for (i = 0; i < pool->base.audio_count; i++) { 1171 if (pool->base.audios[i]) 1172 dce_aud_destroy(&pool->base.audios[i]); 1173 } 1174 1175 for (i = 0; i < pool->base.clk_src_count; i++) { 1176 if (pool->base.clock_sources[i] != NULL) { 1177 dcn20_clock_source_destroy(&pool->base.clock_sources[i]); 1178 pool->base.clock_sources[i] = NULL; 1179 } 1180 } 1181 1182 for (i = 0; i < pool->base.res_cap->num_mpc_3dlut; i++) { 1183 if (pool->base.mpc_lut[i] != NULL) { 1184 dc_3dlut_func_release(pool->base.mpc_lut[i]); 1185 pool->base.mpc_lut[i] = NULL; 1186 } 1187 if (pool->base.mpc_shaper[i] != NULL) { 1188 dc_transfer_func_release(pool->base.mpc_shaper[i]); 1189 pool->base.mpc_shaper[i] = NULL; 1190 } 1191 } 1192 1193 if (pool->base.dp_clock_source != NULL) { 1194 dcn20_clock_source_destroy(&pool->base.dp_clock_source); 1195 pool->base.dp_clock_source = NULL; 1196 } 1197 1198 for (i = 0; i < pool->base.pipe_count; i++) { 1199 if (pool->base.multiple_abms[i] != NULL) 1200 dce_abm_destroy(&pool->base.multiple_abms[i]); 1201 } 1202 1203 if (pool->base.psr != NULL) 1204 dmub_psr_destroy(&pool->base.psr); 1205 1206 if (pool->base.dccg != NULL) 1207 dcn_dccg_destroy(&pool->base.dccg); 1208 1209 if (pool->base.oem_device != NULL) 1210 dal_ddc_service_destroy(&pool->base.oem_device); 1211 } 1212 1213 static struct hubp *dcn30_hubp_create( 1214 struct dc_context *ctx, 1215 uint32_t inst) 1216 { 1217 struct dcn20_hubp *hubp2 = 1218 kzalloc(sizeof(struct dcn20_hubp), GFP_KERNEL); 1219 1220 if (!hubp2) 1221 return NULL; 1222 1223 if (hubp3_construct(hubp2, ctx, inst, 1224 &hubp_regs[inst], &hubp_shift, &hubp_mask)) 1225 return &hubp2->base; 1226 1227 BREAK_TO_DEBUGGER(); 1228 kfree(hubp2); 1229 return NULL; 1230 } 1231 1232 static bool dcn30_dwbc_create(struct dc_context *ctx, struct resource_pool *pool) 1233 { 1234 int i; 1235 uint32_t pipe_count = pool->res_cap->num_dwb; 1236 1237 for (i = 0; i < pipe_count; i++) { 1238 struct dcn30_dwbc *dwbc30 = kzalloc(sizeof(struct dcn30_dwbc), 1239 GFP_KERNEL); 1240 1241 if (!dwbc30) { 1242 dm_error("DC: failed to create dwbc30!\n"); 1243 return false; 1244 } 1245 1246 dcn30_dwbc_construct(dwbc30, ctx, 1247 &dwbc30_regs[i], 1248 &dwbc30_shift, 1249 &dwbc30_mask, 1250 i); 1251 1252 pool->dwbc[i] = &dwbc30->base; 1253 } 1254 return true; 1255 } 1256 1257 static bool dcn30_mmhubbub_create(struct dc_context *ctx, struct resource_pool *pool) 1258 { 1259 int i; 1260 uint32_t pipe_count = pool->res_cap->num_dwb; 1261 1262 for (i = 0; i < pipe_count; i++) { 1263 struct dcn30_mmhubbub *mcif_wb30 = kzalloc(sizeof(struct dcn30_mmhubbub), 1264 GFP_KERNEL); 1265 1266 if (!mcif_wb30) { 1267 dm_error("DC: failed to create mcif_wb30!\n"); 1268 return false; 1269 } 1270 1271 dcn30_mmhubbub_construct(mcif_wb30, ctx, 1272 &mcif_wb30_regs[i], 1273 &mcif_wb30_shift, 1274 &mcif_wb30_mask, 1275 i); 1276 1277 pool->mcif_wb[i] = &mcif_wb30->base; 1278 } 1279 return true; 1280 } 1281 1282 static struct display_stream_compressor *dcn30_dsc_create( 1283 struct dc_context *ctx, uint32_t inst) 1284 { 1285 struct dcn20_dsc *dsc = 1286 kzalloc(sizeof(struct dcn20_dsc), GFP_KERNEL); 1287 1288 if (!dsc) { 1289 BREAK_TO_DEBUGGER(); 1290 return NULL; 1291 } 1292 1293 dsc2_construct(dsc, ctx, inst, &dsc_regs[inst], &dsc_shift, &dsc_mask); 1294 return &dsc->base; 1295 } 1296 1297 enum dc_status dcn30_add_stream_to_ctx(struct dc *dc, struct dc_state *new_ctx, struct dc_stream_state *dc_stream) 1298 { 1299 1300 return dcn20_add_stream_to_ctx(dc, new_ctx, dc_stream); 1301 } 1302 1303 static void dcn30_destroy_resource_pool(struct resource_pool **pool) 1304 { 1305 struct dcn30_resource_pool *dcn30_pool = TO_DCN30_RES_POOL(*pool); 1306 1307 dcn30_resource_destruct(dcn30_pool); 1308 kfree(dcn30_pool); 1309 *pool = NULL; 1310 } 1311 1312 static struct clock_source *dcn30_clock_source_create( 1313 struct dc_context *ctx, 1314 struct dc_bios *bios, 1315 enum clock_source_id id, 1316 const struct dce110_clk_src_regs *regs, 1317 bool dp_clk_src) 1318 { 1319 struct dce110_clk_src *clk_src = 1320 kzalloc(sizeof(struct dce110_clk_src), GFP_KERNEL); 1321 1322 if (!clk_src) 1323 return NULL; 1324 1325 if (dcn3_clk_src_construct(clk_src, ctx, bios, id, 1326 regs, &cs_shift, &cs_mask)) { 1327 clk_src->base.dp_clk_src = dp_clk_src; 1328 return &clk_src->base; 1329 } 1330 1331 BREAK_TO_DEBUGGER(); 1332 return NULL; 1333 } 1334 1335 int dcn30_populate_dml_pipes_from_context( 1336 struct dc *dc, struct dc_state *context, 1337 display_e2e_pipe_params_st *pipes, 1338 bool fast_validate) 1339 { 1340 int i, pipe_cnt; 1341 struct resource_context *res_ctx = &context->res_ctx; 1342 1343 DC_FP_START(); 1344 dcn20_populate_dml_pipes_from_context(dc, context, pipes, fast_validate); 1345 DC_FP_END(); 1346 1347 for (i = 0, pipe_cnt = 0; i < dc->res_pool->pipe_count; i++) { 1348 if (!res_ctx->pipe_ctx[i].stream) 1349 continue; 1350 1351 pipes[pipe_cnt++].pipe.scale_ratio_depth.lb_depth = 1352 dm_lb_16; 1353 } 1354 1355 return pipe_cnt; 1356 } 1357 1358 void dcn30_populate_dml_writeback_from_context( 1359 struct dc *dc, struct resource_context *res_ctx, display_e2e_pipe_params_st *pipes) 1360 { 1361 DC_FP_START(); 1362 dcn30_fpu_populate_dml_writeback_from_context(dc, res_ctx, pipes); 1363 DC_FP_END(); 1364 } 1365 1366 unsigned int dcn30_calc_max_scaled_time( 1367 unsigned int time_per_pixel, 1368 enum mmhubbub_wbif_mode mode, 1369 unsigned int urgent_watermark) 1370 { 1371 unsigned int time_per_byte = 0; 1372 unsigned int total_free_entry = 0xb40; 1373 unsigned int buf_lh_capability; 1374 unsigned int max_scaled_time; 1375 1376 if (mode == PACKED_444) /* packed mode 32 bpp */ 1377 time_per_byte = time_per_pixel/4; 1378 else if (mode == PACKED_444_FP16) /* packed mode 64 bpp */ 1379 time_per_byte = time_per_pixel/8; 1380 1381 if (time_per_byte == 0) 1382 time_per_byte = 1; 1383 1384 buf_lh_capability = (total_free_entry*time_per_byte*32) >> 6; /* time_per_byte is in u6.6*/ 1385 max_scaled_time = buf_lh_capability - urgent_watermark; 1386 return max_scaled_time; 1387 } 1388 1389 void dcn30_set_mcif_arb_params( 1390 struct dc *dc, 1391 struct dc_state *context, 1392 display_e2e_pipe_params_st *pipes, 1393 int pipe_cnt) 1394 { 1395 enum mmhubbub_wbif_mode wbif_mode; 1396 struct display_mode_lib *dml = &context->bw_ctx.dml; 1397 struct mcif_arb_params *wb_arb_params; 1398 int i, j, dwb_pipe; 1399 1400 /* Writeback MCIF_WB arbitration parameters */ 1401 dwb_pipe = 0; 1402 for (i = 0; i < dc->res_pool->pipe_count; i++) { 1403 1404 if (!context->res_ctx.pipe_ctx[i].stream) 1405 continue; 1406 1407 for (j = 0; j < MAX_DWB_PIPES; j++) { 1408 struct dc_writeback_info *writeback_info = &context->res_ctx.pipe_ctx[i].stream->writeback_info[j]; 1409 1410 if (writeback_info->wb_enabled == false) 1411 continue; 1412 1413 //wb_arb_params = &context->res_ctx.pipe_ctx[i].stream->writeback_info[j].mcif_arb_params; 1414 wb_arb_params = &context->bw_ctx.bw.dcn.bw_writeback.mcif_wb_arb[dwb_pipe]; 1415 1416 if (writeback_info->dwb_params.cnv_params.fc_out_format == DWB_OUT_FORMAT_64BPP_ARGB || 1417 writeback_info->dwb_params.cnv_params.fc_out_format == DWB_OUT_FORMAT_64BPP_RGBA) 1418 wbif_mode = PACKED_444_FP16; 1419 else 1420 wbif_mode = PACKED_444; 1421 1422 DC_FP_START(); 1423 dcn30_fpu_set_mcif_arb_params(wb_arb_params, dml, pipes, pipe_cnt, j); 1424 DC_FP_END(); 1425 wb_arb_params->time_per_pixel = (1000000 << 6) / context->res_ctx.pipe_ctx[i].stream->phy_pix_clk; /* time_per_pixel should be in u6.6 format */ 1426 wb_arb_params->slice_lines = 32; 1427 wb_arb_params->arbitration_slice = 2; /* irrelevant since there is no YUV output */ 1428 wb_arb_params->max_scaled_time = dcn30_calc_max_scaled_time(wb_arb_params->time_per_pixel, 1429 wbif_mode, 1430 wb_arb_params->cli_watermark[0]); /* assume 4 watermark sets have the same value */ 1431 1432 dwb_pipe++; 1433 1434 if (dwb_pipe >= MAX_DWB_PIPES) 1435 return; 1436 } 1437 if (dwb_pipe >= MAX_DWB_PIPES) 1438 return; 1439 } 1440 1441 } 1442 1443 static struct dc_cap_funcs cap_funcs = { 1444 .get_dcc_compression_cap = dcn20_get_dcc_compression_cap 1445 }; 1446 1447 bool dcn30_acquire_post_bldn_3dlut( 1448 struct resource_context *res_ctx, 1449 const struct resource_pool *pool, 1450 int mpcc_id, 1451 struct dc_3dlut **lut, 1452 struct dc_transfer_func **shaper) 1453 { 1454 int i; 1455 bool ret = false; 1456 union dc_3dlut_state *state; 1457 1458 ASSERT(*lut == NULL && *shaper == NULL); 1459 *lut = NULL; 1460 *shaper = NULL; 1461 1462 for (i = 0; i < pool->res_cap->num_mpc_3dlut; i++) { 1463 if (!res_ctx->is_mpc_3dlut_acquired[i]) { 1464 *lut = pool->mpc_lut[i]; 1465 *shaper = pool->mpc_shaper[i]; 1466 state = &pool->mpc_lut[i]->state; 1467 res_ctx->is_mpc_3dlut_acquired[i] = true; 1468 state->bits.rmu_idx_valid = 1; 1469 state->bits.rmu_mux_num = i; 1470 if (state->bits.rmu_mux_num == 0) 1471 state->bits.mpc_rmu0_mux = mpcc_id; 1472 else if (state->bits.rmu_mux_num == 1) 1473 state->bits.mpc_rmu1_mux = mpcc_id; 1474 else if (state->bits.rmu_mux_num == 2) 1475 state->bits.mpc_rmu2_mux = mpcc_id; 1476 ret = true; 1477 break; 1478 } 1479 } 1480 return ret; 1481 } 1482 1483 bool dcn30_release_post_bldn_3dlut( 1484 struct resource_context *res_ctx, 1485 const struct resource_pool *pool, 1486 struct dc_3dlut **lut, 1487 struct dc_transfer_func **shaper) 1488 { 1489 int i; 1490 bool ret = false; 1491 1492 for (i = 0; i < pool->res_cap->num_mpc_3dlut; i++) { 1493 if (pool->mpc_lut[i] == *lut && pool->mpc_shaper[i] == *shaper) { 1494 res_ctx->is_mpc_3dlut_acquired[i] = false; 1495 pool->mpc_lut[i]->state.raw = 0; 1496 *lut = NULL; 1497 *shaper = NULL; 1498 ret = true; 1499 break; 1500 } 1501 } 1502 return ret; 1503 } 1504 1505 static bool is_soc_bounding_box_valid(struct dc *dc) 1506 { 1507 uint32_t hw_internal_rev = dc->ctx->asic_id.hw_internal_rev; 1508 1509 if (ASICREV_IS_SIENNA_CICHLID_P(hw_internal_rev)) 1510 return true; 1511 1512 return false; 1513 } 1514 1515 static bool init_soc_bounding_box(struct dc *dc, 1516 struct dcn30_resource_pool *pool) 1517 { 1518 struct _vcs_dpi_soc_bounding_box_st *loaded_bb = &dcn3_0_soc; 1519 struct _vcs_dpi_ip_params_st *loaded_ip = &dcn3_0_ip; 1520 1521 DC_LOGGER_INIT(dc->ctx->logger); 1522 1523 if (!is_soc_bounding_box_valid(dc)) { 1524 DC_LOG_ERROR("%s: not valid soc bounding box\n", __func__); 1525 return false; 1526 } 1527 1528 loaded_ip->max_num_otg = pool->base.res_cap->num_timing_generator; 1529 loaded_ip->max_num_dpp = pool->base.pipe_count; 1530 loaded_ip->clamp_min_dcfclk = dc->config.clamp_min_dcfclk; 1531 dcn20_patch_bounding_box(dc, loaded_bb); 1532 DC_FP_START(); 1533 patch_dcn30_soc_bounding_box(dc, &dcn3_0_soc); 1534 DC_FP_END(); 1535 1536 return true; 1537 } 1538 1539 static bool dcn30_split_stream_for_mpc_or_odm( 1540 const struct dc *dc, 1541 struct resource_context *res_ctx, 1542 struct pipe_ctx *pri_pipe, 1543 struct pipe_ctx *sec_pipe, 1544 bool odm) 1545 { 1546 int pipe_idx = sec_pipe->pipe_idx; 1547 const struct resource_pool *pool = dc->res_pool; 1548 1549 *sec_pipe = *pri_pipe; 1550 1551 sec_pipe->pipe_idx = pipe_idx; 1552 sec_pipe->plane_res.mi = pool->mis[pipe_idx]; 1553 sec_pipe->plane_res.hubp = pool->hubps[pipe_idx]; 1554 sec_pipe->plane_res.ipp = pool->ipps[pipe_idx]; 1555 sec_pipe->plane_res.xfm = pool->transforms[pipe_idx]; 1556 sec_pipe->plane_res.dpp = pool->dpps[pipe_idx]; 1557 sec_pipe->plane_res.mpcc_inst = pool->dpps[pipe_idx]->inst; 1558 sec_pipe->stream_res.dsc = NULL; 1559 if (odm) { 1560 if (pri_pipe->next_odm_pipe) { 1561 ASSERT(pri_pipe->next_odm_pipe != sec_pipe); 1562 sec_pipe->next_odm_pipe = pri_pipe->next_odm_pipe; 1563 sec_pipe->next_odm_pipe->prev_odm_pipe = sec_pipe; 1564 } 1565 if (pri_pipe->top_pipe && pri_pipe->top_pipe->next_odm_pipe) { 1566 pri_pipe->top_pipe->next_odm_pipe->bottom_pipe = sec_pipe; 1567 sec_pipe->top_pipe = pri_pipe->top_pipe->next_odm_pipe; 1568 } 1569 if (pri_pipe->bottom_pipe && pri_pipe->bottom_pipe->next_odm_pipe) { 1570 pri_pipe->bottom_pipe->next_odm_pipe->top_pipe = sec_pipe; 1571 sec_pipe->bottom_pipe = pri_pipe->bottom_pipe->next_odm_pipe; 1572 } 1573 pri_pipe->next_odm_pipe = sec_pipe; 1574 sec_pipe->prev_odm_pipe = pri_pipe; 1575 1576 if (!sec_pipe->top_pipe) 1577 sec_pipe->stream_res.opp = pool->opps[pipe_idx]; 1578 else 1579 sec_pipe->stream_res.opp = sec_pipe->top_pipe->stream_res.opp; 1580 if (sec_pipe->stream->timing.flags.DSC == 1) { 1581 dcn20_acquire_dsc(dc, res_ctx, &sec_pipe->stream_res.dsc, pipe_idx); 1582 ASSERT(sec_pipe->stream_res.dsc); 1583 if (sec_pipe->stream_res.dsc == NULL) 1584 return false; 1585 } 1586 } else { 1587 if (pri_pipe->bottom_pipe) { 1588 ASSERT(pri_pipe->bottom_pipe != sec_pipe); 1589 sec_pipe->bottom_pipe = pri_pipe->bottom_pipe; 1590 sec_pipe->bottom_pipe->top_pipe = sec_pipe; 1591 } 1592 pri_pipe->bottom_pipe = sec_pipe; 1593 sec_pipe->top_pipe = pri_pipe; 1594 1595 ASSERT(pri_pipe->plane_state); 1596 } 1597 1598 return true; 1599 } 1600 1601 static struct pipe_ctx *dcn30_find_split_pipe( 1602 struct dc *dc, 1603 struct dc_state *context, 1604 int old_index) 1605 { 1606 struct pipe_ctx *pipe = NULL; 1607 int i; 1608 1609 if (old_index >= 0 && context->res_ctx.pipe_ctx[old_index].stream == NULL) { 1610 pipe = &context->res_ctx.pipe_ctx[old_index]; 1611 pipe->pipe_idx = old_index; 1612 } 1613 1614 if (!pipe) 1615 for (i = dc->res_pool->pipe_count - 1; i >= 0; i--) { 1616 if (dc->current_state->res_ctx.pipe_ctx[i].top_pipe == NULL 1617 && dc->current_state->res_ctx.pipe_ctx[i].prev_odm_pipe == NULL) { 1618 if (context->res_ctx.pipe_ctx[i].stream == NULL) { 1619 pipe = &context->res_ctx.pipe_ctx[i]; 1620 pipe->pipe_idx = i; 1621 break; 1622 } 1623 } 1624 } 1625 1626 /* 1627 * May need to fix pipes getting tossed from 1 opp to another on flip 1628 * Add for debugging transient underflow during topology updates: 1629 * ASSERT(pipe); 1630 */ 1631 if (!pipe) 1632 for (i = dc->res_pool->pipe_count - 1; i >= 0; i--) { 1633 if (context->res_ctx.pipe_ctx[i].stream == NULL) { 1634 pipe = &context->res_ctx.pipe_ctx[i]; 1635 pipe->pipe_idx = i; 1636 break; 1637 } 1638 } 1639 1640 return pipe; 1641 } 1642 1643 noinline bool dcn30_internal_validate_bw( 1644 struct dc *dc, 1645 struct dc_state *context, 1646 display_e2e_pipe_params_st *pipes, 1647 int *pipe_cnt_out, 1648 int *vlevel_out, 1649 bool fast_validate) 1650 { 1651 bool out = false; 1652 bool repopulate_pipes = false; 1653 int split[MAX_PIPES] = { 0 }; 1654 bool merge[MAX_PIPES] = { false }; 1655 bool newly_split[MAX_PIPES] = { false }; 1656 int pipe_cnt, i, pipe_idx, vlevel; 1657 struct vba_vars_st *vba = &context->bw_ctx.dml.vba; 1658 1659 ASSERT(pipes); 1660 if (!pipes) 1661 return false; 1662 1663 context->bw_ctx.dml.vba.maxMpcComb = 0; 1664 context->bw_ctx.dml.vba.VoltageLevel = 0; 1665 context->bw_ctx.dml.vba.DRAMClockChangeSupport[0][0] = dm_dram_clock_change_vactive; 1666 dc->res_pool->funcs->update_soc_for_wm_a(dc, context); 1667 pipe_cnt = dc->res_pool->funcs->populate_dml_pipes(dc, context, pipes, fast_validate); 1668 1669 if (!pipe_cnt) { 1670 out = true; 1671 goto validate_out; 1672 } 1673 1674 dml_log_pipe_params(&context->bw_ctx.dml, pipes, pipe_cnt); 1675 1676 if (!fast_validate) { 1677 /* 1678 * DML favors voltage over p-state, but we're more interested in 1679 * supporting p-state over voltage. We can't support p-state in 1680 * prefetch mode > 0 so try capping the prefetch mode to start. 1681 */ 1682 context->bw_ctx.dml.soc.allow_dram_self_refresh_or_dram_clock_change_in_vblank = 1683 dm_allow_self_refresh_and_mclk_switch; 1684 vlevel = dml_get_voltage_level(&context->bw_ctx.dml, pipes, pipe_cnt); 1685 /* This may adjust vlevel and maxMpcComb */ 1686 if (vlevel < context->bw_ctx.dml.soc.num_states) 1687 vlevel = dcn20_validate_apply_pipe_split_flags(dc, context, vlevel, split, merge); 1688 } 1689 if (fast_validate || vlevel == context->bw_ctx.dml.soc.num_states || 1690 vba->DRAMClockChangeSupport[vlevel][vba->maxMpcComb] == dm_dram_clock_change_unsupported) { 1691 /* 1692 * If mode is unsupported or there's still no p-state support then 1693 * fall back to favoring voltage. 1694 * 1695 * We don't actually support prefetch mode 2, so require that we 1696 * at least support prefetch mode 1. 1697 */ 1698 context->bw_ctx.dml.soc.allow_dram_self_refresh_or_dram_clock_change_in_vblank = 1699 dm_allow_self_refresh; 1700 1701 vlevel = dml_get_voltage_level(&context->bw_ctx.dml, pipes, pipe_cnt); 1702 if (vlevel < context->bw_ctx.dml.soc.num_states) { 1703 memset(split, 0, sizeof(split)); 1704 memset(merge, 0, sizeof(merge)); 1705 vlevel = dcn20_validate_apply_pipe_split_flags(dc, context, vlevel, split, merge); 1706 } 1707 } 1708 1709 dml_log_mode_support_params(&context->bw_ctx.dml); 1710 1711 if (vlevel == context->bw_ctx.dml.soc.num_states) 1712 goto validate_fail; 1713 1714 if (!dc->config.enable_windowed_mpo_odm) { 1715 for (i = 0, pipe_idx = 0; i < dc->res_pool->pipe_count; i++) { 1716 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 1717 struct pipe_ctx *mpo_pipe = pipe->bottom_pipe; 1718 1719 if (!pipe->stream) 1720 continue; 1721 1722 /* We only support full screen mpo with ODM */ 1723 if (vba->ODMCombineEnabled[vba->pipe_plane[pipe_idx]] != dm_odm_combine_mode_disabled 1724 && pipe->plane_state && mpo_pipe 1725 && memcmp(&mpo_pipe->plane_res.scl_data.recout, 1726 &pipe->plane_res.scl_data.recout, 1727 sizeof(struct rect)) != 0) { 1728 ASSERT(mpo_pipe->plane_state != pipe->plane_state); 1729 goto validate_fail; 1730 } 1731 pipe_idx++; 1732 } 1733 } 1734 1735 /* merge pipes if necessary */ 1736 for (i = 0; i < dc->res_pool->pipe_count; i++) { 1737 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 1738 1739 /*skip pipes that don't need merging*/ 1740 if (!merge[i]) 1741 continue; 1742 1743 /* if ODM merge we ignore mpc tree, mpo pipes will have their own flags */ 1744 if (pipe->prev_odm_pipe) { 1745 /*split off odm pipe*/ 1746 pipe->prev_odm_pipe->next_odm_pipe = pipe->next_odm_pipe; 1747 if (pipe->next_odm_pipe) 1748 pipe->next_odm_pipe->prev_odm_pipe = pipe->prev_odm_pipe; 1749 1750 pipe->bottom_pipe = NULL; 1751 pipe->next_odm_pipe = NULL; 1752 pipe->plane_state = NULL; 1753 pipe->stream = NULL; 1754 pipe->top_pipe = NULL; 1755 pipe->prev_odm_pipe = NULL; 1756 if (pipe->stream_res.dsc) 1757 dcn20_release_dsc(&context->res_ctx, dc->res_pool, &pipe->stream_res.dsc); 1758 memset(&pipe->plane_res, 0, sizeof(pipe->plane_res)); 1759 memset(&pipe->stream_res, 0, sizeof(pipe->stream_res)); 1760 repopulate_pipes = true; 1761 } else if (pipe->top_pipe && pipe->top_pipe->plane_state == pipe->plane_state) { 1762 struct pipe_ctx *top_pipe = pipe->top_pipe; 1763 struct pipe_ctx *bottom_pipe = pipe->bottom_pipe; 1764 1765 top_pipe->bottom_pipe = bottom_pipe; 1766 if (bottom_pipe) 1767 bottom_pipe->top_pipe = top_pipe; 1768 1769 pipe->top_pipe = NULL; 1770 pipe->bottom_pipe = NULL; 1771 pipe->plane_state = NULL; 1772 pipe->stream = NULL; 1773 memset(&pipe->plane_res, 0, sizeof(pipe->plane_res)); 1774 memset(&pipe->stream_res, 0, sizeof(pipe->stream_res)); 1775 repopulate_pipes = true; 1776 } else 1777 ASSERT(0); /* Should never try to merge master pipe */ 1778 1779 } 1780 1781 for (i = 0, pipe_idx = -1; i < dc->res_pool->pipe_count; i++) { 1782 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 1783 struct pipe_ctx *old_pipe = &dc->current_state->res_ctx.pipe_ctx[i]; 1784 struct pipe_ctx *hsplit_pipe = NULL; 1785 bool odm; 1786 int old_index = -1; 1787 1788 if (!pipe->stream || newly_split[i]) 1789 continue; 1790 1791 pipe_idx++; 1792 odm = vba->ODMCombineEnabled[vba->pipe_plane[pipe_idx]] != dm_odm_combine_mode_disabled; 1793 1794 if (!pipe->plane_state && !odm) 1795 continue; 1796 1797 if (split[i]) { 1798 if (odm) { 1799 if (split[i] == 4 && old_pipe->next_odm_pipe && old_pipe->next_odm_pipe->next_odm_pipe) 1800 old_index = old_pipe->next_odm_pipe->next_odm_pipe->pipe_idx; 1801 else if (old_pipe->next_odm_pipe) 1802 old_index = old_pipe->next_odm_pipe->pipe_idx; 1803 } else { 1804 if (split[i] == 4 && old_pipe->bottom_pipe && old_pipe->bottom_pipe->bottom_pipe && 1805 old_pipe->bottom_pipe->bottom_pipe->plane_state == old_pipe->plane_state) 1806 old_index = old_pipe->bottom_pipe->bottom_pipe->pipe_idx; 1807 else if (old_pipe->bottom_pipe && 1808 old_pipe->bottom_pipe->plane_state == old_pipe->plane_state) 1809 old_index = old_pipe->bottom_pipe->pipe_idx; 1810 } 1811 hsplit_pipe = dcn30_find_split_pipe(dc, context, old_index); 1812 ASSERT(hsplit_pipe); 1813 if (!hsplit_pipe) 1814 goto validate_fail; 1815 1816 if (!dcn30_split_stream_for_mpc_or_odm( 1817 dc, &context->res_ctx, 1818 pipe, hsplit_pipe, odm)) 1819 goto validate_fail; 1820 1821 newly_split[hsplit_pipe->pipe_idx] = true; 1822 repopulate_pipes = true; 1823 } 1824 if (split[i] == 4) { 1825 struct pipe_ctx *pipe_4to1; 1826 1827 if (odm && old_pipe->next_odm_pipe) 1828 old_index = old_pipe->next_odm_pipe->pipe_idx; 1829 else if (!odm && old_pipe->bottom_pipe && 1830 old_pipe->bottom_pipe->plane_state == old_pipe->plane_state) 1831 old_index = old_pipe->bottom_pipe->pipe_idx; 1832 else 1833 old_index = -1; 1834 pipe_4to1 = dcn30_find_split_pipe(dc, context, old_index); 1835 ASSERT(pipe_4to1); 1836 if (!pipe_4to1) 1837 goto validate_fail; 1838 if (!dcn30_split_stream_for_mpc_or_odm( 1839 dc, &context->res_ctx, 1840 pipe, pipe_4to1, odm)) 1841 goto validate_fail; 1842 newly_split[pipe_4to1->pipe_idx] = true; 1843 1844 if (odm && old_pipe->next_odm_pipe && old_pipe->next_odm_pipe->next_odm_pipe 1845 && old_pipe->next_odm_pipe->next_odm_pipe->next_odm_pipe) 1846 old_index = old_pipe->next_odm_pipe->next_odm_pipe->next_odm_pipe->pipe_idx; 1847 else if (!odm && old_pipe->bottom_pipe && old_pipe->bottom_pipe->bottom_pipe && 1848 old_pipe->bottom_pipe->bottom_pipe->bottom_pipe && 1849 old_pipe->bottom_pipe->bottom_pipe->bottom_pipe->plane_state == old_pipe->plane_state) 1850 old_index = old_pipe->bottom_pipe->bottom_pipe->bottom_pipe->pipe_idx; 1851 else 1852 old_index = -1; 1853 pipe_4to1 = dcn30_find_split_pipe(dc, context, old_index); 1854 ASSERT(pipe_4to1); 1855 if (!pipe_4to1) 1856 goto validate_fail; 1857 if (!dcn30_split_stream_for_mpc_or_odm( 1858 dc, &context->res_ctx, 1859 hsplit_pipe, pipe_4to1, odm)) 1860 goto validate_fail; 1861 newly_split[pipe_4to1->pipe_idx] = true; 1862 } 1863 if (odm) 1864 dcn20_build_mapped_resource(dc, context, pipe->stream); 1865 } 1866 1867 for (i = 0; i < dc->res_pool->pipe_count; i++) { 1868 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 1869 1870 if (pipe->plane_state) { 1871 if (!resource_build_scaling_params(pipe)) 1872 goto validate_fail; 1873 } 1874 } 1875 1876 /* Actual dsc count per stream dsc validation*/ 1877 if (!dcn20_validate_dsc(dc, context)) { 1878 vba->ValidationStatus[vba->soc.num_states] = DML_FAIL_DSC_VALIDATION_FAILURE; 1879 goto validate_fail; 1880 } 1881 1882 if (repopulate_pipes) 1883 pipe_cnt = dc->res_pool->funcs->populate_dml_pipes(dc, context, pipes, fast_validate); 1884 context->bw_ctx.dml.vba.VoltageLevel = vlevel; 1885 *vlevel_out = vlevel; 1886 *pipe_cnt_out = pipe_cnt; 1887 1888 out = true; 1889 goto validate_out; 1890 1891 validate_fail: 1892 out = false; 1893 1894 validate_out: 1895 return out; 1896 } 1897 1898 static int get_refresh_rate(struct dc_state *context) 1899 { 1900 int refresh_rate = 0; 1901 int h_v_total = 0; 1902 struct dc_crtc_timing *timing = NULL; 1903 1904 if (context == NULL || context->streams[0] == NULL) 1905 return 0; 1906 1907 /* check if refresh rate at least 120hz */ 1908 timing = &context->streams[0]->timing; 1909 if (timing == NULL) 1910 return 0; 1911 1912 h_v_total = timing->h_total * timing->v_total; 1913 if (h_v_total == 0) 1914 return 0; 1915 1916 refresh_rate = ((timing->pix_clk_100hz * 100) / (h_v_total)) + 1; 1917 return refresh_rate; 1918 } 1919 1920 #define MAX_STRETCHED_V_BLANK 500 // in micro-seconds 1921 /* 1922 * Scaling factor for v_blank stretch calculations considering timing in 1923 * micro-seconds and pixel clock in 100hz. 1924 * Note: the parenthesis are necessary to ensure the correct order of 1925 * operation where V_SCALE is used. 1926 */ 1927 #define V_SCALE (10000 / MAX_STRETCHED_V_BLANK) 1928 1929 static int get_frame_rate_at_max_stretch_100hz(struct dc_state *context) 1930 { 1931 struct dc_crtc_timing *timing = NULL; 1932 uint32_t sec_per_100_lines; 1933 uint32_t max_v_blank; 1934 uint32_t curr_v_blank; 1935 uint32_t v_stretch_max; 1936 uint32_t stretched_frame_pix_cnt; 1937 uint32_t scaled_stretched_frame_pix_cnt; 1938 uint32_t scaled_refresh_rate; 1939 1940 if (context == NULL || context->streams[0] == NULL) 1941 return 0; 1942 1943 /* check if refresh rate at least 120hz */ 1944 timing = &context->streams[0]->timing; 1945 if (timing == NULL) 1946 return 0; 1947 1948 sec_per_100_lines = timing->pix_clk_100hz / timing->h_total + 1; 1949 max_v_blank = sec_per_100_lines / V_SCALE + 1; 1950 curr_v_blank = timing->v_total - timing->v_addressable; 1951 v_stretch_max = (max_v_blank > curr_v_blank) ? (max_v_blank - curr_v_blank) : (0); 1952 stretched_frame_pix_cnt = (v_stretch_max + timing->v_total) * timing->h_total; 1953 scaled_stretched_frame_pix_cnt = stretched_frame_pix_cnt / 10000; 1954 scaled_refresh_rate = (timing->pix_clk_100hz) / scaled_stretched_frame_pix_cnt + 1; 1955 1956 return scaled_refresh_rate; 1957 } 1958 1959 static bool is_refresh_rate_support_mclk_switch_using_fw_based_vblank_stretch(struct dc_state *context) 1960 { 1961 int refresh_rate_max_stretch_100hz; 1962 int min_refresh_100hz; 1963 1964 if (context == NULL || context->streams[0] == NULL) 1965 return false; 1966 1967 refresh_rate_max_stretch_100hz = get_frame_rate_at_max_stretch_100hz(context); 1968 min_refresh_100hz = context->streams[0]->timing.min_refresh_in_uhz / 10000; 1969 1970 if (refresh_rate_max_stretch_100hz < min_refresh_100hz) 1971 return false; 1972 1973 return true; 1974 } 1975 1976 bool dcn30_can_support_mclk_switch_using_fw_based_vblank_stretch(struct dc *dc, struct dc_state *context) 1977 { 1978 int refresh_rate = 0; 1979 const int minimum_refreshrate_supported = 120; 1980 1981 if (context == NULL || context->streams[0] == NULL) 1982 return false; 1983 1984 if (context->streams[0]->sink->edid_caps.panel_patch.disable_fams) 1985 return false; 1986 1987 if (dc->debug.disable_fams) 1988 return false; 1989 1990 if (!dc->caps.dmub_caps.mclk_sw) 1991 return false; 1992 1993 if (context->bw_ctx.bw.dcn.clk.fw_based_mclk_switching_shut_down) 1994 return false; 1995 1996 /* more then 1 monitor connected */ 1997 if (context->stream_count != 1) 1998 return false; 1999 2000 refresh_rate = get_refresh_rate(context); 2001 if (refresh_rate < minimum_refreshrate_supported) 2002 return false; 2003 2004 if (!is_refresh_rate_support_mclk_switch_using_fw_based_vblank_stretch(context)) 2005 return false; 2006 2007 // check if freesync enabled 2008 if (!context->streams[0]->allow_freesync) 2009 return false; 2010 2011 if (context->streams[0]->vrr_active_variable) 2012 return false; 2013 2014 return true; 2015 } 2016 2017 /* 2018 * set up FPO watermarks, pstate, dram latency 2019 */ 2020 void dcn30_setup_mclk_switch_using_fw_based_vblank_stretch(struct dc *dc, struct dc_state *context) 2021 { 2022 ASSERT(dc != NULL && context != NULL); 2023 if (dc == NULL || context == NULL) 2024 return; 2025 2026 /* Set wm_a.pstate so high natural MCLK switches are impossible: 4 seconds */ 2027 context->bw_ctx.bw.dcn.watermarks.a.cstate_pstate.pstate_change_ns = 4U * 1000U * 1000U * 1000U; 2028 } 2029 2030 void dcn30_update_soc_for_wm_a(struct dc *dc, struct dc_state *context) 2031 { 2032 DC_FP_START(); 2033 dcn30_fpu_update_soc_for_wm_a(dc, context); 2034 DC_FP_END(); 2035 } 2036 2037 void dcn30_calculate_wm_and_dlg( 2038 struct dc *dc, struct dc_state *context, 2039 display_e2e_pipe_params_st *pipes, 2040 int pipe_cnt, 2041 int vlevel) 2042 { 2043 DC_FP_START(); 2044 dcn30_fpu_calculate_wm_and_dlg(dc, context, pipes, pipe_cnt, vlevel); 2045 DC_FP_END(); 2046 } 2047 2048 bool dcn30_validate_bandwidth(struct dc *dc, 2049 struct dc_state *context, 2050 bool fast_validate) 2051 { 2052 bool out = false; 2053 2054 BW_VAL_TRACE_SETUP(); 2055 2056 int vlevel = 0; 2057 int pipe_cnt = 0; 2058 display_e2e_pipe_params_st *pipes = kzalloc(dc->res_pool->pipe_count * sizeof(display_e2e_pipe_params_st), GFP_KERNEL); 2059 DC_LOGGER_INIT(dc->ctx->logger); 2060 2061 BW_VAL_TRACE_COUNT(); 2062 2063 DC_FP_START(); 2064 out = dcn30_internal_validate_bw(dc, context, pipes, &pipe_cnt, &vlevel, fast_validate); 2065 DC_FP_END(); 2066 2067 if (pipe_cnt == 0) 2068 goto validate_out; 2069 2070 if (!out) 2071 goto validate_fail; 2072 2073 BW_VAL_TRACE_END_VOLTAGE_LEVEL(); 2074 2075 if (fast_validate) { 2076 BW_VAL_TRACE_SKIP(fast); 2077 goto validate_out; 2078 } 2079 2080 DC_FP_START(); 2081 dc->res_pool->funcs->calculate_wm_and_dlg(dc, context, pipes, pipe_cnt, vlevel); 2082 DC_FP_END(); 2083 2084 BW_VAL_TRACE_END_WATERMARKS(); 2085 2086 goto validate_out; 2087 2088 validate_fail: 2089 DC_LOG_WARNING("Mode Validation Warning: %s failed validation.\n", 2090 dml_get_status_message(context->bw_ctx.dml.vba.ValidationStatus[context->bw_ctx.dml.vba.soc.num_states])); 2091 2092 BW_VAL_TRACE_SKIP(fail); 2093 out = false; 2094 2095 validate_out: 2096 kfree(pipes); 2097 2098 BW_VAL_TRACE_FINISH(); 2099 2100 return out; 2101 } 2102 2103 void dcn30_update_bw_bounding_box(struct dc *dc, struct clk_bw_params *bw_params) 2104 { 2105 unsigned int i, j; 2106 unsigned int num_states = 0; 2107 2108 unsigned int dcfclk_mhz[DC__VOLTAGE_STATES] = {0}; 2109 unsigned int dram_speed_mts[DC__VOLTAGE_STATES] = {0}; 2110 unsigned int optimal_uclk_for_dcfclk_sta_targets[DC__VOLTAGE_STATES] = {0}; 2111 unsigned int optimal_dcfclk_for_uclk[DC__VOLTAGE_STATES] = {0}; 2112 2113 unsigned int dcfclk_sta_targets[DC__VOLTAGE_STATES] = {694, 875, 1000, 1200}; 2114 unsigned int num_dcfclk_sta_targets = 4; 2115 unsigned int num_uclk_states; 2116 2117 struct dc_bounding_box_max_clk dcn30_bb_max_clk; 2118 2119 memset(&dcn30_bb_max_clk, 0, sizeof(dcn30_bb_max_clk)); 2120 2121 if (dc->ctx->dc_bios->vram_info.num_chans) 2122 dcn3_0_soc.num_chans = dc->ctx->dc_bios->vram_info.num_chans; 2123 2124 DC_FP_START(); 2125 dcn30_fpu_update_dram_channel_width_bytes(dc); 2126 DC_FP_END(); 2127 2128 if (bw_params->clk_table.entries[0].memclk_mhz) { 2129 2130 for (i = 0; i < MAX_NUM_DPM_LVL; i++) { 2131 if (bw_params->clk_table.entries[i].dcfclk_mhz > dcn30_bb_max_clk.max_dcfclk_mhz) 2132 dcn30_bb_max_clk.max_dcfclk_mhz = bw_params->clk_table.entries[i].dcfclk_mhz; 2133 if (bw_params->clk_table.entries[i].dispclk_mhz > dcn30_bb_max_clk.max_dispclk_mhz) 2134 dcn30_bb_max_clk.max_dispclk_mhz = bw_params->clk_table.entries[i].dispclk_mhz; 2135 if (bw_params->clk_table.entries[i].dppclk_mhz > dcn30_bb_max_clk.max_dppclk_mhz) 2136 dcn30_bb_max_clk.max_dppclk_mhz = bw_params->clk_table.entries[i].dppclk_mhz; 2137 if (bw_params->clk_table.entries[i].phyclk_mhz > dcn30_bb_max_clk.max_phyclk_mhz) 2138 dcn30_bb_max_clk.max_phyclk_mhz = bw_params->clk_table.entries[i].phyclk_mhz; 2139 } 2140 2141 DC_FP_START(); 2142 dcn30_fpu_update_max_clk(&dcn30_bb_max_clk); 2143 DC_FP_END(); 2144 2145 if (dcn30_bb_max_clk.max_dcfclk_mhz > dcfclk_sta_targets[num_dcfclk_sta_targets-1]) { 2146 // If max DCFCLK is greater than the max DCFCLK STA target, insert into the DCFCLK STA target array 2147 dcfclk_sta_targets[num_dcfclk_sta_targets] = dcn30_bb_max_clk.max_dcfclk_mhz; 2148 num_dcfclk_sta_targets++; 2149 } else if (dcn30_bb_max_clk.max_dcfclk_mhz < dcfclk_sta_targets[num_dcfclk_sta_targets-1]) { 2150 // If max DCFCLK is less than the max DCFCLK STA target, cap values and remove duplicates 2151 for (i = 0; i < num_dcfclk_sta_targets; i++) { 2152 if (dcfclk_sta_targets[i] > dcn30_bb_max_clk.max_dcfclk_mhz) { 2153 dcfclk_sta_targets[i] = dcn30_bb_max_clk.max_dcfclk_mhz; 2154 break; 2155 } 2156 } 2157 // Update size of array since we "removed" duplicates 2158 num_dcfclk_sta_targets = i + 1; 2159 } 2160 2161 num_uclk_states = bw_params->clk_table.num_entries; 2162 2163 // Calculate optimal dcfclk for each uclk 2164 for (i = 0; i < num_uclk_states; i++) { 2165 DC_FP_START(); 2166 dcn30_fpu_get_optimal_dcfclk_fclk_for_uclk(bw_params->clk_table.entries[i].memclk_mhz * 16, 2167 &optimal_dcfclk_for_uclk[i], NULL); 2168 DC_FP_END(); 2169 if (optimal_dcfclk_for_uclk[i] < bw_params->clk_table.entries[0].dcfclk_mhz) { 2170 optimal_dcfclk_for_uclk[i] = bw_params->clk_table.entries[0].dcfclk_mhz; 2171 } 2172 } 2173 2174 // Calculate optimal uclk for each dcfclk sta target 2175 for (i = 0; i < num_dcfclk_sta_targets; i++) { 2176 for (j = 0; j < num_uclk_states; j++) { 2177 if (dcfclk_sta_targets[i] < optimal_dcfclk_for_uclk[j]) { 2178 optimal_uclk_for_dcfclk_sta_targets[i] = 2179 bw_params->clk_table.entries[j].memclk_mhz * 16; 2180 break; 2181 } 2182 } 2183 } 2184 2185 i = 0; 2186 j = 0; 2187 // create the final dcfclk and uclk table 2188 while (i < num_dcfclk_sta_targets && j < num_uclk_states && num_states < DC__VOLTAGE_STATES) { 2189 if (dcfclk_sta_targets[i] < optimal_dcfclk_for_uclk[j] && i < num_dcfclk_sta_targets) { 2190 dcfclk_mhz[num_states] = dcfclk_sta_targets[i]; 2191 dram_speed_mts[num_states++] = optimal_uclk_for_dcfclk_sta_targets[i++]; 2192 } else { 2193 if (j < num_uclk_states && optimal_dcfclk_for_uclk[j] <= dcn30_bb_max_clk.max_dcfclk_mhz) { 2194 dcfclk_mhz[num_states] = optimal_dcfclk_for_uclk[j]; 2195 dram_speed_mts[num_states++] = bw_params->clk_table.entries[j++].memclk_mhz * 16; 2196 } else { 2197 j = num_uclk_states; 2198 } 2199 } 2200 } 2201 2202 while (i < num_dcfclk_sta_targets && num_states < DC__VOLTAGE_STATES) { 2203 dcfclk_mhz[num_states] = dcfclk_sta_targets[i]; 2204 dram_speed_mts[num_states++] = optimal_uclk_for_dcfclk_sta_targets[i++]; 2205 } 2206 2207 while (j < num_uclk_states && num_states < DC__VOLTAGE_STATES && 2208 optimal_dcfclk_for_uclk[j] <= dcn30_bb_max_clk.max_dcfclk_mhz) { 2209 dcfclk_mhz[num_states] = optimal_dcfclk_for_uclk[j]; 2210 dram_speed_mts[num_states++] = bw_params->clk_table.entries[j++].memclk_mhz * 16; 2211 } 2212 2213 dcn3_0_soc.num_states = num_states; 2214 DC_FP_START(); 2215 dcn30_fpu_update_bw_bounding_box(dc, bw_params, &dcn30_bb_max_clk, dcfclk_mhz, dram_speed_mts); 2216 DC_FP_END(); 2217 } 2218 } 2219 2220 static void dcn30_get_panel_config_defaults(struct dc_panel_config *panel_config) 2221 { 2222 *panel_config = panel_config_defaults; 2223 } 2224 2225 static const struct resource_funcs dcn30_res_pool_funcs = { 2226 .destroy = dcn30_destroy_resource_pool, 2227 .link_enc_create = dcn30_link_encoder_create, 2228 .panel_cntl_create = dcn30_panel_cntl_create, 2229 .validate_bandwidth = dcn30_validate_bandwidth, 2230 .calculate_wm_and_dlg = dcn30_calculate_wm_and_dlg, 2231 .update_soc_for_wm_a = dcn30_update_soc_for_wm_a, 2232 .populate_dml_pipes = dcn30_populate_dml_pipes_from_context, 2233 .acquire_idle_pipe_for_layer = dcn20_acquire_idle_pipe_for_layer, 2234 .add_stream_to_ctx = dcn30_add_stream_to_ctx, 2235 .add_dsc_to_stream_resource = dcn20_add_dsc_to_stream_resource, 2236 .remove_stream_from_ctx = dcn20_remove_stream_from_ctx, 2237 .populate_dml_writeback_from_context = dcn30_populate_dml_writeback_from_context, 2238 .set_mcif_arb_params = dcn30_set_mcif_arb_params, 2239 .find_first_free_match_stream_enc_for_link = dcn10_find_first_free_match_stream_enc_for_link, 2240 .acquire_post_bldn_3dlut = dcn30_acquire_post_bldn_3dlut, 2241 .release_post_bldn_3dlut = dcn30_release_post_bldn_3dlut, 2242 .update_bw_bounding_box = dcn30_update_bw_bounding_box, 2243 .patch_unknown_plane_state = dcn20_patch_unknown_plane_state, 2244 .get_panel_config_defaults = dcn30_get_panel_config_defaults, 2245 }; 2246 2247 #define CTX ctx 2248 2249 #define REG(reg_name) \ 2250 (DCN_BASE.instance[0].segment[mm ## reg_name ## _BASE_IDX] + mm ## reg_name) 2251 2252 static uint32_t read_pipe_fuses(struct dc_context *ctx) 2253 { 2254 uint32_t value = REG_READ(CC_DC_PIPE_DIS); 2255 /* Support for max 6 pipes */ 2256 value = value & 0x3f; 2257 return value; 2258 } 2259 2260 static bool dcn30_resource_construct( 2261 uint8_t num_virtual_links, 2262 struct dc *dc, 2263 struct dcn30_resource_pool *pool) 2264 { 2265 int i; 2266 struct dc_context *ctx = dc->ctx; 2267 struct irq_service_init_data init_data; 2268 struct ddc_service_init_data ddc_init_data = {0}; 2269 uint32_t pipe_fuses = read_pipe_fuses(ctx); 2270 uint32_t num_pipes = 0; 2271 2272 if (!(pipe_fuses == 0 || pipe_fuses == 0x3e)) { 2273 BREAK_TO_DEBUGGER(); 2274 dm_error("DC: Unexpected fuse recipe for navi2x !\n"); 2275 /* fault to single pipe */ 2276 pipe_fuses = 0x3e; 2277 } 2278 2279 DC_FP_START(); 2280 2281 ctx->dc_bios->regs = &bios_regs; 2282 2283 pool->base.res_cap = &res_cap_dcn3; 2284 2285 pool->base.funcs = &dcn30_res_pool_funcs; 2286 2287 /************************************************* 2288 * Resource + asic cap harcoding * 2289 *************************************************/ 2290 pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE; 2291 pool->base.pipe_count = pool->base.res_cap->num_timing_generator; 2292 pool->base.mpcc_count = pool->base.res_cap->num_timing_generator; 2293 dc->caps.max_downscale_ratio = 600; 2294 dc->caps.i2c_speed_in_khz = 100; 2295 dc->caps.i2c_speed_in_khz_hdcp = 100; /*1.4 w/a not applied by default*/ 2296 dc->caps.max_cursor_size = 256; 2297 dc->caps.min_horizontal_blanking_period = 80; 2298 dc->caps.dmdata_alloc_size = 2048; 2299 dc->caps.mall_size_per_mem_channel = 8; 2300 /* total size = mall per channel * num channels * 1024 * 1024 */ 2301 dc->caps.mall_size_total = dc->caps.mall_size_per_mem_channel * dc->ctx->dc_bios->vram_info.num_chans * 1048576; 2302 dc->caps.cursor_cache_size = dc->caps.max_cursor_size * dc->caps.max_cursor_size * 8; 2303 2304 dc->caps.max_slave_planes = 2; 2305 dc->caps.max_slave_yuv_planes = 2; 2306 dc->caps.max_slave_rgb_planes = 2; 2307 dc->caps.post_blend_color_processing = true; 2308 dc->caps.force_dp_tps4_for_cp2520 = true; 2309 dc->caps.extended_aux_timeout_support = true; 2310 dc->caps.dmcub_support = true; 2311 2312 /* Color pipeline capabilities */ 2313 dc->caps.color.dpp.dcn_arch = 1; 2314 dc->caps.color.dpp.input_lut_shared = 0; 2315 dc->caps.color.dpp.icsc = 1; 2316 dc->caps.color.dpp.dgam_ram = 0; // must use gamma_corr 2317 dc->caps.color.dpp.dgam_rom_caps.srgb = 1; 2318 dc->caps.color.dpp.dgam_rom_caps.bt2020 = 1; 2319 dc->caps.color.dpp.dgam_rom_caps.gamma2_2 = 1; 2320 dc->caps.color.dpp.dgam_rom_caps.pq = 1; 2321 dc->caps.color.dpp.dgam_rom_caps.hlg = 1; 2322 dc->caps.color.dpp.post_csc = 1; 2323 dc->caps.color.dpp.gamma_corr = 1; 2324 dc->caps.color.dpp.dgam_rom_for_yuv = 0; 2325 2326 dc->caps.color.dpp.hw_3d_lut = 1; 2327 dc->caps.color.dpp.ogam_ram = 1; 2328 // no OGAM ROM on DCN3 2329 dc->caps.color.dpp.ogam_rom_caps.srgb = 0; 2330 dc->caps.color.dpp.ogam_rom_caps.bt2020 = 0; 2331 dc->caps.color.dpp.ogam_rom_caps.gamma2_2 = 0; 2332 dc->caps.color.dpp.ogam_rom_caps.pq = 0; 2333 dc->caps.color.dpp.ogam_rom_caps.hlg = 0; 2334 dc->caps.color.dpp.ocsc = 0; 2335 2336 dc->caps.color.mpc.gamut_remap = 1; 2337 dc->caps.color.mpc.num_3dluts = pool->base.res_cap->num_mpc_3dlut; //3 2338 dc->caps.color.mpc.ogam_ram = 1; 2339 dc->caps.color.mpc.ogam_rom_caps.srgb = 0; 2340 dc->caps.color.mpc.ogam_rom_caps.bt2020 = 0; 2341 dc->caps.color.mpc.ogam_rom_caps.gamma2_2 = 0; 2342 dc->caps.color.mpc.ogam_rom_caps.pq = 0; 2343 dc->caps.color.mpc.ogam_rom_caps.hlg = 0; 2344 dc->caps.color.mpc.ocsc = 1; 2345 2346 dc->caps.dp_hdmi21_pcon_support = true; 2347 2348 /* read VBIOS LTTPR caps */ 2349 { 2350 if (ctx->dc_bios->funcs->get_lttpr_caps) { 2351 enum bp_result bp_query_result; 2352 uint8_t is_vbios_lttpr_enable = 0; 2353 2354 bp_query_result = ctx->dc_bios->funcs->get_lttpr_caps(ctx->dc_bios, &is_vbios_lttpr_enable); 2355 dc->caps.vbios_lttpr_enable = (bp_query_result == BP_RESULT_OK) && !!is_vbios_lttpr_enable; 2356 } 2357 2358 if (ctx->dc_bios->funcs->get_lttpr_interop) { 2359 enum bp_result bp_query_result; 2360 uint8_t is_vbios_interop_enabled = 0; 2361 2362 bp_query_result = ctx->dc_bios->funcs->get_lttpr_interop(ctx->dc_bios, 2363 &is_vbios_interop_enabled); 2364 dc->caps.vbios_lttpr_aware = (bp_query_result == BP_RESULT_OK) && !!is_vbios_interop_enabled; 2365 } 2366 } 2367 2368 if (dc->ctx->dce_environment == DCE_ENV_PRODUCTION_DRV) 2369 dc->debug = debug_defaults_drv; 2370 else if (dc->ctx->dce_environment == DCE_ENV_FPGA_MAXIMUS) { 2371 dc->debug = debug_defaults_diags; 2372 } else 2373 dc->debug = debug_defaults_diags; 2374 // Init the vm_helper 2375 if (dc->vm_helper) 2376 vm_helper_init(dc->vm_helper, 16); 2377 2378 /************************************************* 2379 * Create resources * 2380 *************************************************/ 2381 2382 /* Clock Sources for Pixel Clock*/ 2383 pool->base.clock_sources[DCN30_CLK_SRC_PLL0] = 2384 dcn30_clock_source_create(ctx, ctx->dc_bios, 2385 CLOCK_SOURCE_COMBO_PHY_PLL0, 2386 &clk_src_regs[0], false); 2387 pool->base.clock_sources[DCN30_CLK_SRC_PLL1] = 2388 dcn30_clock_source_create(ctx, ctx->dc_bios, 2389 CLOCK_SOURCE_COMBO_PHY_PLL1, 2390 &clk_src_regs[1], false); 2391 pool->base.clock_sources[DCN30_CLK_SRC_PLL2] = 2392 dcn30_clock_source_create(ctx, ctx->dc_bios, 2393 CLOCK_SOURCE_COMBO_PHY_PLL2, 2394 &clk_src_regs[2], false); 2395 pool->base.clock_sources[DCN30_CLK_SRC_PLL3] = 2396 dcn30_clock_source_create(ctx, ctx->dc_bios, 2397 CLOCK_SOURCE_COMBO_PHY_PLL3, 2398 &clk_src_regs[3], false); 2399 pool->base.clock_sources[DCN30_CLK_SRC_PLL4] = 2400 dcn30_clock_source_create(ctx, ctx->dc_bios, 2401 CLOCK_SOURCE_COMBO_PHY_PLL4, 2402 &clk_src_regs[4], false); 2403 pool->base.clock_sources[DCN30_CLK_SRC_PLL5] = 2404 dcn30_clock_source_create(ctx, ctx->dc_bios, 2405 CLOCK_SOURCE_COMBO_PHY_PLL5, 2406 &clk_src_regs[5], false); 2407 2408 pool->base.clk_src_count = DCN30_CLK_SRC_TOTAL; 2409 2410 /* todo: not reuse phy_pll registers */ 2411 pool->base.dp_clock_source = 2412 dcn30_clock_source_create(ctx, ctx->dc_bios, 2413 CLOCK_SOURCE_ID_DP_DTO, 2414 &clk_src_regs[0], true); 2415 2416 for (i = 0; i < pool->base.clk_src_count; i++) { 2417 if (pool->base.clock_sources[i] == NULL) { 2418 dm_error("DC: failed to create clock sources!\n"); 2419 BREAK_TO_DEBUGGER(); 2420 goto create_fail; 2421 } 2422 } 2423 2424 /* DCCG */ 2425 pool->base.dccg = dccg30_create(ctx, &dccg_regs, &dccg_shift, &dccg_mask); 2426 if (pool->base.dccg == NULL) { 2427 dm_error("DC: failed to create dccg!\n"); 2428 BREAK_TO_DEBUGGER(); 2429 goto create_fail; 2430 } 2431 2432 /* PP Lib and SMU interfaces */ 2433 init_soc_bounding_box(dc, pool); 2434 2435 num_pipes = dcn3_0_ip.max_num_dpp; 2436 2437 for (i = 0; i < dcn3_0_ip.max_num_dpp; i++) 2438 if (pipe_fuses & 1 << i) 2439 num_pipes--; 2440 2441 dcn3_0_ip.max_num_dpp = num_pipes; 2442 dcn3_0_ip.max_num_otg = num_pipes; 2443 2444 dml_init_instance(&dc->dml, &dcn3_0_soc, &dcn3_0_ip, DML_PROJECT_DCN30); 2445 2446 /* IRQ */ 2447 init_data.ctx = dc->ctx; 2448 pool->base.irqs = dal_irq_service_dcn30_create(&init_data); 2449 if (!pool->base.irqs) 2450 goto create_fail; 2451 2452 /* HUBBUB */ 2453 pool->base.hubbub = dcn30_hubbub_create(ctx); 2454 if (pool->base.hubbub == NULL) { 2455 BREAK_TO_DEBUGGER(); 2456 dm_error("DC: failed to create hubbub!\n"); 2457 goto create_fail; 2458 } 2459 2460 /* HUBPs, DPPs, OPPs and TGs */ 2461 for (i = 0; i < pool->base.pipe_count; i++) { 2462 pool->base.hubps[i] = dcn30_hubp_create(ctx, i); 2463 if (pool->base.hubps[i] == NULL) { 2464 BREAK_TO_DEBUGGER(); 2465 dm_error( 2466 "DC: failed to create hubps!\n"); 2467 goto create_fail; 2468 } 2469 2470 pool->base.dpps[i] = dcn30_dpp_create(ctx, i); 2471 if (pool->base.dpps[i] == NULL) { 2472 BREAK_TO_DEBUGGER(); 2473 dm_error( 2474 "DC: failed to create dpps!\n"); 2475 goto create_fail; 2476 } 2477 } 2478 2479 for (i = 0; i < pool->base.res_cap->num_opp; i++) { 2480 pool->base.opps[i] = dcn30_opp_create(ctx, i); 2481 if (pool->base.opps[i] == NULL) { 2482 BREAK_TO_DEBUGGER(); 2483 dm_error( 2484 "DC: failed to create output pixel processor!\n"); 2485 goto create_fail; 2486 } 2487 } 2488 2489 for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) { 2490 pool->base.timing_generators[i] = dcn30_timing_generator_create( 2491 ctx, i); 2492 if (pool->base.timing_generators[i] == NULL) { 2493 BREAK_TO_DEBUGGER(); 2494 dm_error("DC: failed to create tg!\n"); 2495 goto create_fail; 2496 } 2497 } 2498 pool->base.timing_generator_count = i; 2499 /* PSR */ 2500 pool->base.psr = dmub_psr_create(ctx); 2501 2502 if (pool->base.psr == NULL) { 2503 dm_error("DC: failed to create PSR obj!\n"); 2504 BREAK_TO_DEBUGGER(); 2505 goto create_fail; 2506 } 2507 2508 /* ABM */ 2509 for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) { 2510 pool->base.multiple_abms[i] = dmub_abm_create(ctx, 2511 &abm_regs[i], 2512 &abm_shift, 2513 &abm_mask); 2514 if (pool->base.multiple_abms[i] == NULL) { 2515 dm_error("DC: failed to create abm for pipe %d!\n", i); 2516 BREAK_TO_DEBUGGER(); 2517 goto create_fail; 2518 } 2519 } 2520 /* MPC and DSC */ 2521 pool->base.mpc = dcn30_mpc_create(ctx, pool->base.mpcc_count, pool->base.res_cap->num_mpc_3dlut); 2522 if (pool->base.mpc == NULL) { 2523 BREAK_TO_DEBUGGER(); 2524 dm_error("DC: failed to create mpc!\n"); 2525 goto create_fail; 2526 } 2527 2528 for (i = 0; i < pool->base.res_cap->num_dsc; i++) { 2529 pool->base.dscs[i] = dcn30_dsc_create(ctx, i); 2530 if (pool->base.dscs[i] == NULL) { 2531 BREAK_TO_DEBUGGER(); 2532 dm_error("DC: failed to create display stream compressor %d!\n", i); 2533 goto create_fail; 2534 } 2535 } 2536 2537 /* DWB and MMHUBBUB */ 2538 if (!dcn30_dwbc_create(ctx, &pool->base)) { 2539 BREAK_TO_DEBUGGER(); 2540 dm_error("DC: failed to create dwbc!\n"); 2541 goto create_fail; 2542 } 2543 2544 if (!dcn30_mmhubbub_create(ctx, &pool->base)) { 2545 BREAK_TO_DEBUGGER(); 2546 dm_error("DC: failed to create mcif_wb!\n"); 2547 goto create_fail; 2548 } 2549 2550 /* AUX and I2C */ 2551 for (i = 0; i < pool->base.res_cap->num_ddc; i++) { 2552 pool->base.engines[i] = dcn30_aux_engine_create(ctx, i); 2553 if (pool->base.engines[i] == NULL) { 2554 BREAK_TO_DEBUGGER(); 2555 dm_error( 2556 "DC:failed to create aux engine!!\n"); 2557 goto create_fail; 2558 } 2559 pool->base.hw_i2cs[i] = dcn30_i2c_hw_create(ctx, i); 2560 if (pool->base.hw_i2cs[i] == NULL) { 2561 BREAK_TO_DEBUGGER(); 2562 dm_error( 2563 "DC:failed to create hw i2c!!\n"); 2564 goto create_fail; 2565 } 2566 pool->base.sw_i2cs[i] = NULL; 2567 } 2568 2569 /* Audio, Stream Encoders including DIG and virtual, MPC 3D LUTs */ 2570 if (!resource_construct(num_virtual_links, dc, &pool->base, 2571 (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment) ? 2572 &res_create_funcs : &res_create_maximus_funcs))) 2573 goto create_fail; 2574 2575 /* HW Sequencer and Plane caps */ 2576 dcn30_hw_sequencer_construct(dc); 2577 2578 dc->caps.max_planes = pool->base.pipe_count; 2579 2580 for (i = 0; i < dc->caps.max_planes; ++i) 2581 dc->caps.planes[i] = plane_cap; 2582 2583 dc->cap_funcs = cap_funcs; 2584 2585 if (dc->ctx->dc_bios->fw_info.oem_i2c_present) { 2586 ddc_init_data.ctx = dc->ctx; 2587 ddc_init_data.link = NULL; 2588 ddc_init_data.id.id = dc->ctx->dc_bios->fw_info.oem_i2c_obj_id; 2589 ddc_init_data.id.enum_id = 0; 2590 ddc_init_data.id.type = OBJECT_TYPE_GENERIC; 2591 pool->base.oem_device = dal_ddc_service_create(&ddc_init_data); 2592 } else { 2593 pool->base.oem_device = NULL; 2594 } 2595 2596 DC_FP_END(); 2597 2598 return true; 2599 2600 create_fail: 2601 2602 DC_FP_END(); 2603 dcn30_resource_destruct(pool); 2604 2605 return false; 2606 } 2607 2608 struct resource_pool *dcn30_create_resource_pool( 2609 const struct dc_init_data *init_data, 2610 struct dc *dc) 2611 { 2612 struct dcn30_resource_pool *pool = 2613 kzalloc(sizeof(struct dcn30_resource_pool), GFP_KERNEL); 2614 2615 if (!pool) 2616 return NULL; 2617 2618 if (dcn30_resource_construct(init_data->num_virtual_links, dc, pool)) 2619 return &pool->base; 2620 2621 BREAK_TO_DEBUGGER(); 2622 kfree(pool); 2623 return NULL; 2624 } 2625