1 /* 2 * Copyright 2016 Advanced Micro Devices, Inc. 3 * Copyright 2019 Raptor Engineering, LLC 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included in 13 * all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 21 * OTHER DEALINGS IN THE SOFTWARE. 22 * 23 * Authors: AMD 24 * 25 */ 26 27 #include "dm_services.h" 28 #include "dc.h" 29 30 #include "dcn20/dcn20_init.h" 31 32 #include "resource.h" 33 #include "include/irq_service_interface.h" 34 #include "dcn20/dcn20_resource.h" 35 36 #include "dml/dcn20/dcn20_fpu.h" 37 38 #include "dcn10/dcn10_hubp.h" 39 #include "dcn10/dcn10_ipp.h" 40 #include "dcn20/dcn20_hubbub.h" 41 #include "dcn20/dcn20_mpc.h" 42 #include "dcn20/dcn20_hubp.h" 43 #include "irq/dcn20/irq_service_dcn20.h" 44 #include "dcn20/dcn20_dpp.h" 45 #include "dcn20/dcn20_optc.h" 46 #include "dcn20/dcn20_hwseq.h" 47 #include "dce110/dce110_hwseq.h" 48 #include "dcn10/dcn10_resource.h" 49 #include "dcn20/dcn20_opp.h" 50 51 #include "dcn20/dcn20_dsc.h" 52 53 #include "dcn20/dcn20_link_encoder.h" 54 #include "dcn20/dcn20_stream_encoder.h" 55 #include "dce/dce_clock_source.h" 56 #include "dce/dce_audio.h" 57 #include "dce/dce_hwseq.h" 58 #include "dio/virtual/virtual_stream_encoder.h" 59 #include "dce110/dce110_resource.h" 60 #include "dml/display_mode_vba.h" 61 #include "dcn20/dcn20_dccg.h" 62 #include "dcn20/dcn20_vmid.h" 63 #include "dce/dce_panel_cntl.h" 64 65 #include "dcn20/dcn20_dwb.h" 66 #include "dcn20/dcn20_mmhubbub.h" 67 68 #include "navi10_ip_offset.h" 69 70 #include "dcn/dcn_2_0_0_offset.h" 71 #include "dcn/dcn_2_0_0_sh_mask.h" 72 #include "dpcs/dpcs_2_0_0_offset.h" 73 #include "dpcs/dpcs_2_0_0_sh_mask.h" 74 75 #include "nbio/nbio_2_3_offset.h" 76 77 #include "mmhub/mmhub_2_0_0_offset.h" 78 #include "mmhub/mmhub_2_0_0_sh_mask.h" 79 80 #include "reg_helper.h" 81 #include "dce/dce_abm.h" 82 #include "dce/dce_dmcu.h" 83 #include "dce/dce_aux.h" 84 #include "dce/dce_i2c.h" 85 #include "dio/dcn10/dcn10_dio.h" 86 #include "vm_helper.h" 87 88 #include "link_enc_cfg.h" 89 #include "link_service.h" 90 91 #define DC_LOGGER_INIT(logger) 92 93 #ifndef mmDP0_DP_DPHY_INTERNAL_CTRL 94 #define mmDP0_DP_DPHY_INTERNAL_CTRL 0x210f 95 #define mmDP0_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2 96 #define mmDP1_DP_DPHY_INTERNAL_CTRL 0x220f 97 #define mmDP1_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2 98 #define mmDP2_DP_DPHY_INTERNAL_CTRL 0x230f 99 #define mmDP2_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2 100 #define mmDP3_DP_DPHY_INTERNAL_CTRL 0x240f 101 #define mmDP3_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2 102 #define mmDP4_DP_DPHY_INTERNAL_CTRL 0x250f 103 #define mmDP4_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2 104 #define mmDP5_DP_DPHY_INTERNAL_CTRL 0x260f 105 #define mmDP5_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2 106 #define mmDP6_DP_DPHY_INTERNAL_CTRL 0x270f 107 #define mmDP6_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2 108 #endif 109 110 111 enum dcn20_clk_src_array_id { 112 DCN20_CLK_SRC_PLL0, 113 DCN20_CLK_SRC_PLL1, 114 DCN20_CLK_SRC_PLL2, 115 DCN20_CLK_SRC_PLL3, 116 DCN20_CLK_SRC_PLL4, 117 DCN20_CLK_SRC_PLL5, 118 DCN20_CLK_SRC_TOTAL 119 }; 120 121 /* begin ********************* 122 * macros to expend register list macro defined in HW object header file */ 123 124 /* DCN */ 125 #define BASE_INNER(seg) DCN_BASE__INST0_SEG ## seg 126 127 #define BASE(seg) BASE_INNER(seg) 128 129 #define SR(reg_name)\ 130 .reg_name = BASE(mm ## reg_name ## _BASE_IDX) + \ 131 mm ## reg_name 132 133 #define SRI(reg_name, block, id)\ 134 .reg_name = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \ 135 mm ## block ## id ## _ ## reg_name 136 137 #define SRI2_DWB(reg_name, block, id)\ 138 .reg_name = BASE(mm ## reg_name ## _BASE_IDX) + \ 139 mm ## reg_name 140 #define SF_DWB(reg_name, field_name, post_fix)\ 141 .field_name = reg_name ## __ ## field_name ## post_fix 142 143 #define SF_DWB2(reg_name, block, id, field_name, post_fix) \ 144 .field_name = reg_name ## __ ## field_name ## post_fix 145 146 #define SRIR(var_name, reg_name, block, id)\ 147 .var_name = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \ 148 mm ## block ## id ## _ ## reg_name 149 150 #define SRII(reg_name, block, id)\ 151 .reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \ 152 mm ## block ## id ## _ ## reg_name 153 154 #define DCCG_SRII(reg_name, block, id)\ 155 .block ## _ ## reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \ 156 mm ## block ## id ## _ ## reg_name 157 158 #define VUPDATE_SRII(reg_name, block, id)\ 159 .reg_name[id] = BASE(mm ## reg_name ## _ ## block ## id ## _BASE_IDX) + \ 160 mm ## reg_name ## _ ## block ## id 161 162 /* NBIO */ 163 #define NBIO_BASE_INNER(seg) \ 164 NBIO_BASE__INST0_SEG ## seg 165 166 #define NBIO_BASE(seg) \ 167 NBIO_BASE_INNER(seg) 168 169 #define NBIO_SR(reg_name)\ 170 .reg_name = NBIO_BASE(mm ## reg_name ## _BASE_IDX) + \ 171 mm ## reg_name 172 173 /* MMHUB */ 174 #define MMHUB_BASE_INNER(seg) \ 175 MMHUB_BASE__INST0_SEG ## seg 176 177 #define MMHUB_BASE(seg) \ 178 MMHUB_BASE_INNER(seg) 179 180 #define MMHUB_SR(reg_name)\ 181 .reg_name = MMHUB_BASE(mmMM ## reg_name ## _BASE_IDX) + \ 182 mmMM ## reg_name 183 184 static const struct bios_registers bios_regs = { 185 NBIO_SR(BIOS_SCRATCH_3), 186 NBIO_SR(BIOS_SCRATCH_6) 187 }; 188 189 #define clk_src_regs(index, pllid)\ 190 [index] = {\ 191 CS_COMMON_REG_LIST_DCN2_0(index, pllid),\ 192 } 193 194 static const struct dce110_clk_src_regs clk_src_regs[] = { 195 clk_src_regs(0, A), 196 clk_src_regs(1, B), 197 clk_src_regs(2, C), 198 clk_src_regs(3, D), 199 clk_src_regs(4, E), 200 clk_src_regs(5, F) 201 }; 202 203 static const struct dce110_clk_src_shift cs_shift = { 204 CS_COMMON_MASK_SH_LIST_DCN2_0(__SHIFT) 205 }; 206 207 static const struct dce110_clk_src_mask cs_mask = { 208 CS_COMMON_MASK_SH_LIST_DCN2_0(_MASK) 209 }; 210 211 static const struct dce_dmcu_registers dmcu_regs = { 212 DMCU_DCN10_REG_LIST() 213 }; 214 215 static const struct dce_dmcu_shift dmcu_shift = { 216 DMCU_MASK_SH_LIST_DCN10(__SHIFT) 217 }; 218 219 static const struct dce_dmcu_mask dmcu_mask = { 220 DMCU_MASK_SH_LIST_DCN10(_MASK) 221 }; 222 223 static const struct dce_abm_registers abm_regs = { 224 ABM_DCN20_REG_LIST() 225 }; 226 227 static const struct dce_abm_shift abm_shift = { 228 ABM_MASK_SH_LIST_DCN20(__SHIFT) 229 }; 230 231 static const struct dce_abm_mask abm_mask = { 232 ABM_MASK_SH_LIST_DCN20(_MASK) 233 }; 234 235 #define audio_regs(id)\ 236 [id] = {\ 237 AUD_COMMON_REG_LIST(id)\ 238 } 239 240 static const struct dce_audio_registers audio_regs[] = { 241 audio_regs(0), 242 audio_regs(1), 243 audio_regs(2), 244 audio_regs(3), 245 audio_regs(4), 246 audio_regs(5), 247 audio_regs(6), 248 }; 249 250 #define DCE120_AUD_COMMON_MASK_SH_LIST(mask_sh)\ 251 SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_INDEX, AZALIA_ENDPOINT_REG_INDEX, mask_sh),\ 252 SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_DATA, AZALIA_ENDPOINT_REG_DATA, mask_sh),\ 253 AUD_COMMON_MASK_SH_LIST_BASE(mask_sh) 254 255 static const struct dce_audio_shift audio_shift = { 256 DCE120_AUD_COMMON_MASK_SH_LIST(__SHIFT) 257 }; 258 259 static const struct dce_audio_mask audio_mask = { 260 DCE120_AUD_COMMON_MASK_SH_LIST(_MASK) 261 }; 262 263 #define stream_enc_regs(id)\ 264 [id] = {\ 265 SE_DCN2_REG_LIST(id)\ 266 } 267 268 static const struct dcn10_stream_enc_registers stream_enc_regs[] = { 269 stream_enc_regs(0), 270 stream_enc_regs(1), 271 stream_enc_regs(2), 272 stream_enc_regs(3), 273 stream_enc_regs(4), 274 stream_enc_regs(5), 275 }; 276 277 static const struct dcn10_stream_encoder_shift se_shift = { 278 SE_COMMON_MASK_SH_LIST_DCN20(__SHIFT) 279 }; 280 281 static const struct dcn10_stream_encoder_mask se_mask = { 282 SE_COMMON_MASK_SH_LIST_DCN20(_MASK) 283 }; 284 285 286 #define aux_regs(id)\ 287 [id] = {\ 288 DCN2_AUX_REG_LIST(id)\ 289 } 290 291 static const struct dcn10_link_enc_aux_registers link_enc_aux_regs[] = { 292 aux_regs(0), 293 aux_regs(1), 294 aux_regs(2), 295 aux_regs(3), 296 aux_regs(4), 297 aux_regs(5) 298 }; 299 300 #define hpd_regs(id)\ 301 [id] = {\ 302 HPD_REG_LIST(id)\ 303 } 304 305 static const struct dcn10_link_enc_hpd_registers link_enc_hpd_regs[] = { 306 hpd_regs(0), 307 hpd_regs(1), 308 hpd_regs(2), 309 hpd_regs(3), 310 hpd_regs(4), 311 hpd_regs(5) 312 }; 313 314 #define link_regs(id, phyid)\ 315 [id] = {\ 316 LE_DCN10_REG_LIST(id), \ 317 UNIPHY_DCN2_REG_LIST(phyid), \ 318 DPCS_DCN2_REG_LIST(id), \ 319 SRI(DP_DPHY_INTERNAL_CTRL, DP, id) \ 320 } 321 322 static const struct dcn10_link_enc_registers link_enc_regs[] = { 323 link_regs(0, A), 324 link_regs(1, B), 325 link_regs(2, C), 326 link_regs(3, D), 327 link_regs(4, E), 328 link_regs(5, F) 329 }; 330 331 static const struct dcn10_link_enc_shift le_shift = { 332 LINK_ENCODER_MASK_SH_LIST_DCN20(__SHIFT),\ 333 DPCS_DCN2_MASK_SH_LIST(__SHIFT) 334 }; 335 336 static const struct dcn10_link_enc_mask le_mask = { 337 LINK_ENCODER_MASK_SH_LIST_DCN20(_MASK),\ 338 DPCS_DCN2_MASK_SH_LIST(_MASK) 339 }; 340 341 static const struct dce_panel_cntl_registers panel_cntl_regs[] = { 342 { DCN_PANEL_CNTL_REG_LIST() } 343 }; 344 345 static const struct dce_panel_cntl_shift panel_cntl_shift = { 346 DCE_PANEL_CNTL_MASK_SH_LIST(__SHIFT) 347 }; 348 349 static const struct dce_panel_cntl_mask panel_cntl_mask = { 350 DCE_PANEL_CNTL_MASK_SH_LIST(_MASK) 351 }; 352 353 #define ipp_regs(id)\ 354 [id] = {\ 355 IPP_REG_LIST_DCN20(id),\ 356 } 357 358 static const struct dcn10_ipp_registers ipp_regs[] = { 359 ipp_regs(0), 360 ipp_regs(1), 361 ipp_regs(2), 362 ipp_regs(3), 363 ipp_regs(4), 364 ipp_regs(5), 365 }; 366 367 static const struct dcn10_ipp_shift ipp_shift = { 368 IPP_MASK_SH_LIST_DCN20(__SHIFT) 369 }; 370 371 static const struct dcn10_ipp_mask ipp_mask = { 372 IPP_MASK_SH_LIST_DCN20(_MASK), 373 }; 374 375 #define opp_regs(id)\ 376 [id] = {\ 377 OPP_REG_LIST_DCN20(id),\ 378 } 379 380 static const struct dcn20_opp_registers opp_regs[] = { 381 opp_regs(0), 382 opp_regs(1), 383 opp_regs(2), 384 opp_regs(3), 385 opp_regs(4), 386 opp_regs(5), 387 }; 388 389 static const struct dcn20_opp_shift opp_shift = { 390 OPP_MASK_SH_LIST_DCN20(__SHIFT) 391 }; 392 393 static const struct dcn20_opp_mask opp_mask = { 394 OPP_MASK_SH_LIST_DCN20(_MASK) 395 }; 396 397 #define aux_engine_regs(id)\ 398 [id] = {\ 399 AUX_COMMON_REG_LIST0(id), \ 400 .AUXN_IMPCAL = 0, \ 401 .AUXP_IMPCAL = 0, \ 402 .AUX_RESET_MASK = DP_AUX0_AUX_CONTROL__AUX_RESET_MASK, \ 403 } 404 405 static const struct dce110_aux_registers aux_engine_regs[] = { 406 aux_engine_regs(0), 407 aux_engine_regs(1), 408 aux_engine_regs(2), 409 aux_engine_regs(3), 410 aux_engine_regs(4), 411 aux_engine_regs(5) 412 }; 413 414 #define tf_regs(id)\ 415 [id] = {\ 416 TF_REG_LIST_DCN20(id),\ 417 TF_REG_LIST_DCN20_COMMON_APPEND(id),\ 418 } 419 420 static const struct dcn2_dpp_registers tf_regs[] = { 421 tf_regs(0), 422 tf_regs(1), 423 tf_regs(2), 424 tf_regs(3), 425 tf_regs(4), 426 tf_regs(5), 427 }; 428 429 static const struct dcn2_dpp_shift tf_shift = { 430 TF_REG_LIST_SH_MASK_DCN20(__SHIFT), 431 TF_DEBUG_REG_LIST_SH_DCN20 432 }; 433 434 static const struct dcn2_dpp_mask tf_mask = { 435 TF_REG_LIST_SH_MASK_DCN20(_MASK), 436 TF_DEBUG_REG_LIST_MASK_DCN20 437 }; 438 439 #define dwbc_regs_dcn2(id)\ 440 [id] = {\ 441 DWBC_COMMON_REG_LIST_DCN2_0(id),\ 442 } 443 444 static const struct dcn20_dwbc_registers dwbc20_regs[] = { 445 dwbc_regs_dcn2(0), 446 }; 447 448 static const struct dcn20_dwbc_shift dwbc20_shift = { 449 DWBC_COMMON_MASK_SH_LIST_DCN2_0(__SHIFT) 450 }; 451 452 static const struct dcn20_dwbc_mask dwbc20_mask = { 453 DWBC_COMMON_MASK_SH_LIST_DCN2_0(_MASK) 454 }; 455 456 #define mcif_wb_regs_dcn2(id)\ 457 [id] = {\ 458 MCIF_WB_COMMON_REG_LIST_DCN2_0(id),\ 459 } 460 461 static const struct dcn20_mmhubbub_registers mcif_wb20_regs[] = { 462 mcif_wb_regs_dcn2(0), 463 }; 464 465 static const struct dcn20_mmhubbub_shift mcif_wb20_shift = { 466 MCIF_WB_COMMON_MASK_SH_LIST_DCN2_0(__SHIFT) 467 }; 468 469 static const struct dcn20_mmhubbub_mask mcif_wb20_mask = { 470 MCIF_WB_COMMON_MASK_SH_LIST_DCN2_0(_MASK) 471 }; 472 473 static const struct dcn20_mpc_registers mpc_regs = { 474 MPC_REG_LIST_DCN2_0(0), 475 MPC_REG_LIST_DCN2_0(1), 476 MPC_REG_LIST_DCN2_0(2), 477 MPC_REG_LIST_DCN2_0(3), 478 MPC_REG_LIST_DCN2_0(4), 479 MPC_REG_LIST_DCN2_0(5), 480 MPC_OUT_MUX_REG_LIST_DCN2_0(0), 481 MPC_OUT_MUX_REG_LIST_DCN2_0(1), 482 MPC_OUT_MUX_REG_LIST_DCN2_0(2), 483 MPC_OUT_MUX_REG_LIST_DCN2_0(3), 484 MPC_OUT_MUX_REG_LIST_DCN2_0(4), 485 MPC_OUT_MUX_REG_LIST_DCN2_0(5), 486 MPC_DBG_REG_LIST_DCN2_0() 487 }; 488 489 static const struct dcn20_mpc_shift mpc_shift = { 490 MPC_COMMON_MASK_SH_LIST_DCN2_0(__SHIFT), 491 MPC_DEBUG_REG_LIST_SH_DCN20 492 }; 493 494 static const struct dcn20_mpc_mask mpc_mask = { 495 MPC_COMMON_MASK_SH_LIST_DCN2_0(_MASK), 496 MPC_DEBUG_REG_LIST_MASK_DCN20 497 }; 498 499 #define tg_regs(id)\ 500 [id] = {TG_COMMON_REG_LIST_DCN2_0(id)} 501 502 503 static const struct dcn_optc_registers tg_regs[] = { 504 tg_regs(0), 505 tg_regs(1), 506 tg_regs(2), 507 tg_regs(3), 508 tg_regs(4), 509 tg_regs(5) 510 }; 511 512 static const struct dcn_optc_shift tg_shift = { 513 TG_COMMON_MASK_SH_LIST_DCN2_0(__SHIFT) 514 }; 515 516 static const struct dcn_optc_mask tg_mask = { 517 TG_COMMON_MASK_SH_LIST_DCN2_0(_MASK) 518 }; 519 520 #define hubp_regs(id)\ 521 [id] = {\ 522 HUBP_REG_LIST_DCN20(id)\ 523 } 524 525 static const struct dcn_hubp2_registers hubp_regs[] = { 526 hubp_regs(0), 527 hubp_regs(1), 528 hubp_regs(2), 529 hubp_regs(3), 530 hubp_regs(4), 531 hubp_regs(5) 532 }; 533 534 static const struct dcn_hubp2_shift hubp_shift = { 535 HUBP_MASK_SH_LIST_DCN20(__SHIFT) 536 }; 537 538 static const struct dcn_hubp2_mask hubp_mask = { 539 HUBP_MASK_SH_LIST_DCN20(_MASK) 540 }; 541 542 static const struct dcn_hubbub_registers hubbub_reg = { 543 HUBBUB_REG_LIST_DCN20(0) 544 }; 545 546 static const struct dcn_hubbub_shift hubbub_shift = { 547 HUBBUB_MASK_SH_LIST_DCN20(__SHIFT) 548 }; 549 550 static const struct dcn_hubbub_mask hubbub_mask = { 551 HUBBUB_MASK_SH_LIST_DCN20(_MASK) 552 }; 553 554 static const struct dcn_dio_registers dio_regs = { 555 DIO_REG_LIST_DCN10() 556 }; 557 558 #define DIO_MASK_SH_LIST(mask_sh)\ 559 HWS_SF(, DIO_MEM_PWR_CTRL, I2C_LIGHT_SLEEP_FORCE, mask_sh) 560 561 static const struct dcn_dio_shift dio_shift = { 562 DIO_MASK_SH_LIST(__SHIFT) 563 }; 564 565 static const struct dcn_dio_mask dio_mask = { 566 DIO_MASK_SH_LIST(_MASK) 567 }; 568 569 static struct dio *dcn20_dio_create(struct dc_context *ctx) 570 { 571 struct dcn10_dio *dio10 = kzalloc_obj(struct dcn10_dio); 572 573 if (!dio10) 574 return NULL; 575 576 dcn10_dio_construct(dio10, ctx, &dio_regs, &dio_shift, &dio_mask); 577 578 return &dio10->base; 579 } 580 581 #define vmid_regs(id)\ 582 [id] = {\ 583 DCN20_VMID_REG_LIST(id)\ 584 } 585 586 static const struct dcn_vmid_registers vmid_regs[] = { 587 vmid_regs(0), 588 vmid_regs(1), 589 vmid_regs(2), 590 vmid_regs(3), 591 vmid_regs(4), 592 vmid_regs(5), 593 vmid_regs(6), 594 vmid_regs(7), 595 vmid_regs(8), 596 vmid_regs(9), 597 vmid_regs(10), 598 vmid_regs(11), 599 vmid_regs(12), 600 vmid_regs(13), 601 vmid_regs(14), 602 vmid_regs(15) 603 }; 604 605 static const struct dcn20_vmid_shift vmid_shifts = { 606 DCN20_VMID_MASK_SH_LIST(__SHIFT) 607 }; 608 609 static const struct dcn20_vmid_mask vmid_masks = { 610 DCN20_VMID_MASK_SH_LIST(_MASK) 611 }; 612 613 static const struct dce110_aux_registers_shift aux_shift = { 614 DCN_AUX_MASK_SH_LIST(__SHIFT) 615 }; 616 617 static const struct dce110_aux_registers_mask aux_mask = { 618 DCN_AUX_MASK_SH_LIST(_MASK) 619 }; 620 621 static int map_transmitter_id_to_phy_instance( 622 enum transmitter transmitter) 623 { 624 switch (transmitter) { 625 case TRANSMITTER_UNIPHY_A: 626 return 0; 627 break; 628 case TRANSMITTER_UNIPHY_B: 629 return 1; 630 break; 631 case TRANSMITTER_UNIPHY_C: 632 return 2; 633 break; 634 case TRANSMITTER_UNIPHY_D: 635 return 3; 636 break; 637 case TRANSMITTER_UNIPHY_E: 638 return 4; 639 break; 640 case TRANSMITTER_UNIPHY_F: 641 return 5; 642 break; 643 default: 644 ASSERT(0); 645 return 0; 646 } 647 } 648 649 #define dsc_regsDCN20(id)\ 650 [id] = {\ 651 DSC_REG_LIST_DCN20(id)\ 652 } 653 654 static const struct dcn20_dsc_registers dsc_regs[] = { 655 dsc_regsDCN20(0), 656 dsc_regsDCN20(1), 657 dsc_regsDCN20(2), 658 dsc_regsDCN20(3), 659 dsc_regsDCN20(4), 660 dsc_regsDCN20(5) 661 }; 662 663 static const struct dcn20_dsc_shift dsc_shift = { 664 DSC_REG_LIST_SH_MASK_DCN20(__SHIFT) 665 }; 666 667 static const struct dcn20_dsc_mask dsc_mask = { 668 DSC_REG_LIST_SH_MASK_DCN20(_MASK) 669 }; 670 671 static const struct dccg_registers dccg_regs = { 672 DCCG_REG_LIST_DCN2() 673 }; 674 675 static const struct dccg_shift dccg_shift = { 676 DCCG_MASK_SH_LIST_DCN2(__SHIFT) 677 }; 678 679 static const struct dccg_mask dccg_mask = { 680 DCCG_MASK_SH_LIST_DCN2(_MASK) 681 }; 682 683 static const struct resource_caps res_cap_nv10 = { 684 .num_timing_generator = 6, 685 .num_opp = 6, 686 .num_video_plane = 6, 687 .num_audio = 7, 688 .num_stream_encoder = 6, 689 .num_pll = 6, 690 .num_dwb = 1, 691 .num_ddc = 6, 692 .num_vmid = 16, 693 .num_dsc = 6, 694 }; 695 696 static const struct dc_plane_cap plane_cap = { 697 .type = DC_PLANE_TYPE_DCN_UNIVERSAL, 698 .per_pixel_alpha = true, 699 700 .pixel_format_support = { 701 .argb8888 = true, 702 .nv12 = true, 703 .fp16 = true, 704 .p010 = true 705 }, 706 707 .max_upscale_factor = { 708 .argb8888 = 16000, 709 .nv12 = 16000, 710 .fp16 = 1 711 }, 712 713 .max_downscale_factor = { 714 .argb8888 = 250, 715 .nv12 = 250, 716 .fp16 = 1 717 }, 718 16, 719 16 720 }; 721 static const struct resource_caps res_cap_nv14 = { 722 .num_timing_generator = 5, 723 .num_opp = 5, 724 .num_video_plane = 5, 725 .num_audio = 6, 726 .num_stream_encoder = 5, 727 .num_pll = 5, 728 .num_dwb = 1, 729 .num_ddc = 5, 730 .num_vmid = 16, 731 .num_dsc = 5, 732 }; 733 734 static const struct dc_debug_options debug_defaults_drv = { 735 .disable_dmcu = false, 736 .force_abm_enable = false, 737 .clock_trace = true, 738 .disable_pplib_clock_request = true, 739 .pipe_split_policy = MPC_SPLIT_AVOID_MULT_DISP, 740 .force_single_disp_pipe_split = false, 741 .disable_dcc = DCC_ENABLE, 742 .vsr_support = true, 743 .performance_trace = false, 744 .max_downscale_src_width = 5120,/*upto 5K*/ 745 .disable_pplib_wm_range = false, 746 .scl_reset_length10 = true, 747 .sanity_checks = false, 748 .underflow_assert_delay_us = 0xFFFFFFFF, 749 .using_dml2 = false, 750 }; 751 752 static const struct dc_check_config config_defaults = { 753 .enable_legacy_fast_update = true, 754 }; 755 756 void dcn20_dpp_destroy(struct dpp **dpp) 757 { 758 kfree(TO_DCN20_DPP(*dpp)); 759 *dpp = NULL; 760 } 761 762 struct dpp *dcn20_dpp_create( 763 struct dc_context *ctx, 764 uint32_t inst) 765 { 766 struct dcn20_dpp *dpp = 767 kzalloc_obj(struct dcn20_dpp); 768 769 if (!dpp) 770 return NULL; 771 772 if (dpp2_construct(dpp, ctx, inst, 773 &tf_regs[inst], &tf_shift, &tf_mask)) 774 return &dpp->base; 775 776 BREAK_TO_DEBUGGER(); 777 kfree(dpp); 778 return NULL; 779 } 780 781 struct input_pixel_processor *dcn20_ipp_create( 782 struct dc_context *ctx, uint32_t inst) 783 { 784 struct dcn10_ipp *ipp = 785 kzalloc_obj(struct dcn10_ipp); 786 787 if (!ipp) { 788 BREAK_TO_DEBUGGER(); 789 return NULL; 790 } 791 792 dcn20_ipp_construct(ipp, ctx, inst, 793 &ipp_regs[inst], &ipp_shift, &ipp_mask); 794 return &ipp->base; 795 } 796 797 798 struct output_pixel_processor *dcn20_opp_create( 799 struct dc_context *ctx, uint32_t inst) 800 { 801 struct dcn20_opp *opp = 802 kzalloc_obj(struct dcn20_opp); 803 804 if (!opp) { 805 BREAK_TO_DEBUGGER(); 806 return NULL; 807 } 808 809 dcn20_opp_construct(opp, ctx, inst, 810 &opp_regs[inst], &opp_shift, &opp_mask); 811 return &opp->base; 812 } 813 814 struct dce_aux *dcn20_aux_engine_create( 815 struct dc_context *ctx, 816 uint32_t inst) 817 { 818 struct aux_engine_dce110 *aux_engine = 819 kzalloc_obj(struct aux_engine_dce110); 820 821 if (!aux_engine) 822 return NULL; 823 824 dce110_aux_engine_construct(aux_engine, ctx, inst, 825 SW_AUX_TIMEOUT_PERIOD_MULTIPLIER * AUX_TIMEOUT_PERIOD, 826 &aux_engine_regs[inst], 827 &aux_mask, 828 &aux_shift, 829 ctx->dc->caps.extended_aux_timeout_support); 830 831 return &aux_engine->base; 832 } 833 #define i2c_inst_regs(id) { I2C_HW_ENGINE_COMMON_REG_LIST(id) } 834 835 static const struct dce_i2c_registers i2c_hw_regs[] = { 836 i2c_inst_regs(1), 837 i2c_inst_regs(2), 838 i2c_inst_regs(3), 839 i2c_inst_regs(4), 840 i2c_inst_regs(5), 841 i2c_inst_regs(6), 842 }; 843 844 static const struct dce_i2c_shift i2c_shifts = { 845 I2C_COMMON_MASK_SH_LIST_DCN2(__SHIFT) 846 }; 847 848 static const struct dce_i2c_mask i2c_masks = { 849 I2C_COMMON_MASK_SH_LIST_DCN2(_MASK) 850 }; 851 852 struct dce_i2c_hw *dcn20_i2c_hw_create( 853 struct dc_context *ctx, 854 uint32_t inst) 855 { 856 struct dce_i2c_hw *dce_i2c_hw = 857 kzalloc_obj(struct dce_i2c_hw); 858 859 if (!dce_i2c_hw) 860 return NULL; 861 862 dcn2_i2c_hw_construct(dce_i2c_hw, ctx, inst, 863 &i2c_hw_regs[inst], &i2c_shifts, &i2c_masks); 864 865 return dce_i2c_hw; 866 } 867 struct mpc *dcn20_mpc_create(struct dc_context *ctx) 868 { 869 struct dcn20_mpc *mpc20 = kzalloc_obj(struct dcn20_mpc); 870 871 if (!mpc20) 872 return NULL; 873 874 dcn20_mpc_construct(mpc20, ctx, 875 &mpc_regs, 876 &mpc_shift, 877 &mpc_mask, 878 6); 879 880 return &mpc20->base; 881 } 882 883 struct hubbub *dcn20_hubbub_create(struct dc_context *ctx) 884 { 885 int i; 886 struct dcn20_hubbub *hubbub = kzalloc_obj(struct dcn20_hubbub); 887 888 if (!hubbub) 889 return NULL; 890 891 hubbub2_construct(hubbub, ctx, 892 &hubbub_reg, 893 &hubbub_shift, 894 &hubbub_mask); 895 896 for (i = 0; i < res_cap_nv10.num_vmid; i++) { 897 struct dcn20_vmid *vmid = &hubbub->vmid[i]; 898 899 vmid->ctx = ctx; 900 901 vmid->regs = &vmid_regs[i]; 902 vmid->shifts = &vmid_shifts; 903 vmid->masks = &vmid_masks; 904 } 905 906 return &hubbub->base; 907 } 908 909 struct timing_generator *dcn20_timing_generator_create( 910 struct dc_context *ctx, 911 uint32_t instance) 912 { 913 struct optc *tgn10 = 914 kzalloc_obj(struct optc); 915 916 if (!tgn10) 917 return NULL; 918 919 tgn10->base.inst = instance; 920 tgn10->base.ctx = ctx; 921 922 tgn10->tg_regs = &tg_regs[instance]; 923 tgn10->tg_shift = &tg_shift; 924 tgn10->tg_mask = &tg_mask; 925 926 dcn20_timing_generator_init(tgn10); 927 928 return &tgn10->base; 929 } 930 931 static const struct encoder_feature_support link_enc_feature = { 932 .max_hdmi_deep_color = COLOR_DEPTH_121212, 933 .max_hdmi_pixel_clock = 600000, 934 .hdmi_ycbcr420_supported = true, 935 .dp_ycbcr420_supported = true, 936 .fec_supported = true, 937 .flags.bits.IS_HBR2_CAPABLE = true, 938 .flags.bits.IS_HBR3_CAPABLE = true, 939 .flags.bits.IS_TPS3_CAPABLE = true, 940 .flags.bits.IS_TPS4_CAPABLE = true 941 }; 942 943 struct link_encoder *dcn20_link_encoder_create( 944 struct dc_context *ctx, 945 const struct encoder_init_data *enc_init_data) 946 { 947 struct dcn20_link_encoder *enc20 = 948 kzalloc_obj(struct dcn20_link_encoder); 949 int link_regs_id; 950 951 if (!enc20 || enc_init_data->hpd_source >= ARRAY_SIZE(link_enc_hpd_regs)) 952 return NULL; 953 954 link_regs_id = 955 map_transmitter_id_to_phy_instance(enc_init_data->transmitter); 956 957 dcn20_link_encoder_construct(enc20, 958 enc_init_data, 959 &link_enc_feature, 960 &link_enc_regs[link_regs_id], 961 &link_enc_aux_regs[enc_init_data->channel - 1], 962 &link_enc_hpd_regs[enc_init_data->hpd_source], 963 &le_shift, 964 &le_mask); 965 966 return &enc20->enc10.base; 967 } 968 969 static struct panel_cntl *dcn20_panel_cntl_create(const struct panel_cntl_init_data *init_data) 970 { 971 struct dce_panel_cntl *panel_cntl = 972 kzalloc_obj(struct dce_panel_cntl); 973 974 if (!panel_cntl) 975 return NULL; 976 977 dce_panel_cntl_construct(panel_cntl, 978 init_data, 979 &panel_cntl_regs[init_data->inst], 980 &panel_cntl_shift, 981 &panel_cntl_mask); 982 983 return &panel_cntl->base; 984 } 985 986 static struct clock_source *dcn20_clock_source_create( 987 struct dc_context *ctx, 988 struct dc_bios *bios, 989 enum clock_source_id id, 990 const struct dce110_clk_src_regs *regs, 991 bool dp_clk_src) 992 { 993 struct dce110_clk_src *clk_src = 994 kzalloc_obj(struct dce110_clk_src); 995 996 if (!clk_src) 997 return NULL; 998 999 if (dcn20_clk_src_construct(clk_src, ctx, bios, id, 1000 regs, &cs_shift, &cs_mask)) { 1001 clk_src->base.dp_clk_src = dp_clk_src; 1002 return &clk_src->base; 1003 } 1004 1005 kfree(clk_src); 1006 BREAK_TO_DEBUGGER(); 1007 return NULL; 1008 } 1009 1010 static void read_dce_straps( 1011 struct dc_context *ctx, 1012 struct resource_straps *straps) 1013 { 1014 generic_reg_get(ctx, mmDC_PINSTRAPS + BASE(mmDC_PINSTRAPS_BASE_IDX), 1015 FN(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO), &straps->dc_pinstraps_audio); 1016 } 1017 1018 static struct audio *dcn20_create_audio( 1019 struct dc_context *ctx, unsigned int inst) 1020 { 1021 return dce_audio_create(ctx, inst, 1022 &audio_regs[inst], &audio_shift, &audio_mask); 1023 } 1024 1025 struct stream_encoder *dcn20_stream_encoder_create( 1026 enum engine_id eng_id, 1027 struct dc_context *ctx) 1028 { 1029 struct dcn10_stream_encoder *enc1 = 1030 kzalloc_obj(struct dcn10_stream_encoder); 1031 1032 if (!enc1) 1033 return NULL; 1034 1035 if (ASICREV_IS_NAVI14_M(ctx->asic_id.hw_internal_rev)) { 1036 if (eng_id >= ENGINE_ID_DIGD) 1037 eng_id++; 1038 } 1039 1040 dcn20_stream_encoder_construct(enc1, ctx, ctx->dc_bios, eng_id, 1041 &stream_enc_regs[eng_id], 1042 &se_shift, &se_mask); 1043 1044 return &enc1->base; 1045 } 1046 1047 static const struct dce_hwseq_registers hwseq_reg = { 1048 HWSEQ_DCN2_REG_LIST() 1049 }; 1050 1051 static const struct dce_hwseq_shift hwseq_shift = { 1052 HWSEQ_DCN2_MASK_SH_LIST(__SHIFT) 1053 }; 1054 1055 static const struct dce_hwseq_mask hwseq_mask = { 1056 HWSEQ_DCN2_MASK_SH_LIST(_MASK) 1057 }; 1058 1059 struct dce_hwseq *dcn20_hwseq_create( 1060 struct dc_context *ctx) 1061 { 1062 struct dce_hwseq *hws = kzalloc_obj(struct dce_hwseq); 1063 1064 if (hws) { 1065 hws->ctx = ctx; 1066 hws->regs = &hwseq_reg; 1067 hws->shifts = &hwseq_shift; 1068 hws->masks = &hwseq_mask; 1069 } 1070 return hws; 1071 } 1072 1073 static const struct resource_create_funcs res_create_funcs = { 1074 .read_dce_straps = read_dce_straps, 1075 .create_audio = dcn20_create_audio, 1076 .create_stream_encoder = dcn20_stream_encoder_create, 1077 .create_hwseq = dcn20_hwseq_create, 1078 }; 1079 1080 static void dcn20_pp_smu_destroy(struct pp_smu_funcs **pp_smu); 1081 1082 void dcn20_clock_source_destroy(struct clock_source **clk_src) 1083 { 1084 kfree(TO_DCE110_CLK_SRC(*clk_src)); 1085 *clk_src = NULL; 1086 } 1087 1088 1089 struct display_stream_compressor *dcn20_dsc_create( 1090 struct dc_context *ctx, uint32_t inst) 1091 { 1092 struct dcn20_dsc *dsc = 1093 kzalloc_obj(struct dcn20_dsc); 1094 1095 if (!dsc) { 1096 BREAK_TO_DEBUGGER(); 1097 return NULL; 1098 } 1099 1100 dsc2_construct(dsc, ctx, inst, &dsc_regs[inst], &dsc_shift, &dsc_mask); 1101 return &dsc->base; 1102 } 1103 1104 void dcn20_dsc_destroy(struct display_stream_compressor **dsc) 1105 { 1106 kfree(container_of(*dsc, struct dcn20_dsc, base)); 1107 *dsc = NULL; 1108 } 1109 1110 1111 static void dcn20_resource_destruct(struct dcn20_resource_pool *pool) 1112 { 1113 unsigned int i; 1114 1115 for (i = 0; i < pool->base.stream_enc_count; i++) { 1116 if (pool->base.stream_enc[i] != NULL) { 1117 kfree(DCN10STRENC_FROM_STRENC(pool->base.stream_enc[i])); 1118 pool->base.stream_enc[i] = NULL; 1119 } 1120 } 1121 1122 for (i = 0; i < pool->base.res_cap->num_dsc; i++) { 1123 if (pool->base.dscs[i] != NULL) 1124 dcn20_dsc_destroy(&pool->base.dscs[i]); 1125 } 1126 1127 if (pool->base.mpc != NULL) { 1128 kfree(TO_DCN20_MPC(pool->base.mpc)); 1129 pool->base.mpc = NULL; 1130 } 1131 if (pool->base.hubbub != NULL) { 1132 kfree(pool->base.hubbub); 1133 pool->base.hubbub = NULL; 1134 } 1135 1136 if (pool->base.dio != NULL) { 1137 kfree(TO_DCN10_DIO(pool->base.dio)); 1138 pool->base.dio = NULL; 1139 } 1140 1141 for (i = 0; i < pool->base.pipe_count; i++) { 1142 if (pool->base.dpps[i] != NULL) 1143 dcn20_dpp_destroy(&pool->base.dpps[i]); 1144 1145 if (pool->base.ipps[i] != NULL) 1146 pool->base.ipps[i]->funcs->ipp_destroy(&pool->base.ipps[i]); 1147 1148 if (pool->base.hubps[i] != NULL) { 1149 kfree(TO_DCN20_HUBP(pool->base.hubps[i])); 1150 pool->base.hubps[i] = NULL; 1151 } 1152 1153 if (pool->base.irqs != NULL) { 1154 dal_irq_service_destroy(&pool->base.irqs); 1155 } 1156 } 1157 1158 for (i = 0; i < pool->base.res_cap->num_ddc; i++) { 1159 if (pool->base.engines[i] != NULL) 1160 dce110_engine_destroy(&pool->base.engines[i]); 1161 if (pool->base.hw_i2cs[i] != NULL) { 1162 kfree(pool->base.hw_i2cs[i]); 1163 pool->base.hw_i2cs[i] = NULL; 1164 } 1165 if (pool->base.sw_i2cs[i] != NULL) { 1166 kfree(pool->base.sw_i2cs[i]); 1167 pool->base.sw_i2cs[i] = NULL; 1168 } 1169 } 1170 1171 for (i = 0; i < pool->base.res_cap->num_opp; i++) { 1172 if (pool->base.opps[i] != NULL) 1173 pool->base.opps[i]->funcs->opp_destroy(&pool->base.opps[i]); 1174 } 1175 1176 for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) { 1177 if (pool->base.timing_generators[i] != NULL) { 1178 kfree(DCN10TG_FROM_TG(pool->base.timing_generators[i])); 1179 pool->base.timing_generators[i] = NULL; 1180 } 1181 } 1182 1183 for (i = 0; i < pool->base.res_cap->num_dwb; i++) { 1184 if (pool->base.dwbc[i] != NULL) { 1185 kfree(TO_DCN20_DWBC(pool->base.dwbc[i])); 1186 pool->base.dwbc[i] = NULL; 1187 } 1188 if (pool->base.mcif_wb[i] != NULL) { 1189 kfree(TO_DCN20_MMHUBBUB(pool->base.mcif_wb[i])); 1190 pool->base.mcif_wb[i] = NULL; 1191 } 1192 } 1193 1194 for (i = 0; i < pool->base.audio_count; i++) { 1195 if (pool->base.audios[i]) 1196 dce_aud_destroy(&pool->base.audios[i]); 1197 } 1198 1199 for (i = 0; i < pool->base.clk_src_count; i++) { 1200 if (pool->base.clock_sources[i] != NULL) { 1201 dcn20_clock_source_destroy(&pool->base.clock_sources[i]); 1202 pool->base.clock_sources[i] = NULL; 1203 } 1204 } 1205 1206 if (pool->base.dp_clock_source != NULL) { 1207 dcn20_clock_source_destroy(&pool->base.dp_clock_source); 1208 pool->base.dp_clock_source = NULL; 1209 } 1210 1211 1212 if (pool->base.abm != NULL) 1213 dce_abm_destroy(&pool->base.abm); 1214 1215 if (pool->base.dmcu != NULL) 1216 dce_dmcu_destroy(&pool->base.dmcu); 1217 1218 if (pool->base.dccg != NULL) 1219 dcn_dccg_destroy(&pool->base.dccg); 1220 1221 if (pool->base.pp_smu != NULL) 1222 dcn20_pp_smu_destroy(&pool->base.pp_smu); 1223 1224 if (pool->base.oem_device != NULL) { 1225 struct dc *dc = pool->base.oem_device->ctx->dc; 1226 1227 dc->link_srv->destroy_ddc_service(&pool->base.oem_device); 1228 } 1229 } 1230 1231 struct hubp *dcn20_hubp_create( 1232 struct dc_context *ctx, 1233 uint32_t inst) 1234 { 1235 struct dcn20_hubp *hubp2 = 1236 kzalloc_obj(struct dcn20_hubp); 1237 1238 if (!hubp2) 1239 return NULL; 1240 1241 if (hubp2_construct(hubp2, ctx, inst, 1242 &hubp_regs[inst], &hubp_shift, &hubp_mask)) 1243 return &hubp2->base; 1244 1245 BREAK_TO_DEBUGGER(); 1246 kfree(hubp2); 1247 return NULL; 1248 } 1249 1250 static void get_pixel_clock_parameters( 1251 struct pipe_ctx *pipe_ctx, 1252 struct pixel_clk_params *pixel_clk_params) 1253 { 1254 const struct dc_stream_state *stream = pipe_ctx->stream; 1255 struct pipe_ctx *odm_pipe; 1256 int opp_cnt = 1; 1257 struct dc_link *link = stream->link; 1258 struct link_encoder *link_enc = pipe_ctx->link_res.dio_link_enc; 1259 struct dc *dc = pipe_ctx->stream->ctx->dc; 1260 struct dce_hwseq *hws = dc->hwseq; 1261 1262 for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe) 1263 opp_cnt++; 1264 1265 pixel_clk_params->requested_pix_clk_100hz = stream->timing.pix_clk_100hz; 1266 1267 if (!dc->config.unify_link_enc_assignment) 1268 link_enc = link_enc_cfg_get_link_enc(link); 1269 if (link_enc) 1270 pixel_clk_params->encoder_object_id = link_enc->id; 1271 1272 pixel_clk_params->signal_type = pipe_ctx->stream->signal; 1273 pixel_clk_params->controller_id = pipe_ctx->stream_res.tg->inst + 1; 1274 /* TODO: un-hardcode*/ 1275 /* TODO - DP2.0 HW: calculate requested_sym_clk for UHBR rates */ 1276 pixel_clk_params->requested_sym_clk = LINK_RATE_LOW * 1277 LINK_RATE_REF_FREQ_IN_KHZ; 1278 pixel_clk_params->flags.ENABLE_SS = 0; 1279 pixel_clk_params->color_depth = 1280 stream->timing.display_color_depth; 1281 pixel_clk_params->flags.DISPLAY_BLANKED = 1; 1282 pixel_clk_params->pixel_encoding = stream->timing.pixel_encoding; 1283 1284 if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR422) 1285 pixel_clk_params->color_depth = COLOR_DEPTH_888; 1286 1287 if (opp_cnt == 4) 1288 pixel_clk_params->requested_pix_clk_100hz /= 4; 1289 else if (pipe_ctx->stream_res.tg->funcs->is_two_pixels_per_container(&stream->timing) || opp_cnt == 2) 1290 pixel_clk_params->requested_pix_clk_100hz /= 2; 1291 else if (hws->funcs.is_dp_dig_pixel_rate_div_policy) { 1292 if (hws->funcs.is_dp_dig_pixel_rate_div_policy(pipe_ctx)) 1293 pixel_clk_params->requested_pix_clk_100hz /= 2; 1294 } 1295 1296 if (stream->timing.timing_3d_format == TIMING_3D_FORMAT_HW_FRAME_PACKING) 1297 pixel_clk_params->requested_pix_clk_100hz *= 2; 1298 1299 if ((pipe_ctx->stream_res.tg->funcs->is_two_pixels_per_container && 1300 pipe_ctx->stream_res.tg->funcs->is_two_pixels_per_container(&pipe_ctx->stream->timing)) || 1301 (hws->funcs.is_dp_dig_pixel_rate_div_policy && 1302 hws->funcs.is_dp_dig_pixel_rate_div_policy(pipe_ctx)) || 1303 opp_cnt > 1) { 1304 pixel_clk_params->dio_se_pix_per_cycle = 2; 1305 } else { 1306 pixel_clk_params->dio_se_pix_per_cycle = 1; 1307 } 1308 } 1309 1310 static void build_clamping_params(struct dc_stream_state *stream) 1311 { 1312 stream->clamping.clamping_level = CLAMPING_FULL_RANGE; 1313 stream->clamping.c_depth = stream->timing.display_color_depth; 1314 stream->clamping.pixel_encoding = stream->timing.pixel_encoding; 1315 } 1316 1317 void dcn20_build_pipe_pix_clk_params(struct pipe_ctx *pipe_ctx) 1318 { 1319 get_pixel_clock_parameters(pipe_ctx, &pipe_ctx->stream_res.pix_clk_params); 1320 pipe_ctx->clock_source->funcs->get_pix_clk_dividers( 1321 pipe_ctx->clock_source, 1322 &pipe_ctx->stream_res.pix_clk_params, 1323 &pipe_ctx->pll_settings); 1324 } 1325 1326 static enum dc_status build_pipe_hw_param(struct pipe_ctx *pipe_ctx) 1327 { 1328 struct resource_pool *pool = pipe_ctx->stream->ctx->dc->res_pool; 1329 1330 if (pool->funcs->build_pipe_pix_clk_params) { 1331 pool->funcs->build_pipe_pix_clk_params(pipe_ctx); 1332 } else { 1333 dcn20_build_pipe_pix_clk_params(pipe_ctx); 1334 } 1335 1336 pipe_ctx->stream->clamping.pixel_encoding = pipe_ctx->stream->timing.pixel_encoding; 1337 1338 resource_build_bit_depth_reduction_params(pipe_ctx->stream, 1339 &pipe_ctx->stream->bit_depth_params); 1340 build_clamping_params(pipe_ctx->stream); 1341 1342 return DC_OK; 1343 } 1344 1345 enum dc_status dcn20_build_mapped_resource(const struct dc *dc, struct dc_state *context, struct dc_stream_state *stream) 1346 { 1347 enum dc_status status = DC_OK; 1348 struct pipe_ctx *pipe_ctx = resource_get_otg_master_for_stream(&context->res_ctx, stream); 1349 1350 if (!pipe_ctx) 1351 return DC_ERROR_UNEXPECTED; 1352 1353 1354 status = build_pipe_hw_param(pipe_ctx); 1355 1356 return status; 1357 } 1358 1359 1360 void dcn20_acquire_dsc(const struct dc *dc, 1361 struct resource_context *res_ctx, 1362 struct display_stream_compressor **dsc, 1363 int pipe_idx) 1364 { 1365 int i; 1366 const struct resource_pool *pool = dc->res_pool; 1367 struct display_stream_compressor *dsc_old = dc->current_state->res_ctx.pipe_ctx[pipe_idx].stream_res.dsc; 1368 1369 ASSERT(*dsc == NULL); /* If this ASSERT fails, dsc was not released properly */ 1370 *dsc = NULL; 1371 1372 /* Always do 1-to-1 mapping when number of DSCs is same as number of pipes */ 1373 if (pool->res_cap->num_dsc == pool->res_cap->num_opp) { 1374 *dsc = pool->dscs[pipe_idx]; 1375 res_ctx->is_dsc_acquired[pipe_idx] = true; 1376 return; 1377 } 1378 1379 /* Return old DSC to avoid the need for re-programming */ 1380 if (dsc_old && !res_ctx->is_dsc_acquired[dsc_old->inst]) { 1381 *dsc = dsc_old; 1382 res_ctx->is_dsc_acquired[dsc_old->inst] = true; 1383 return ; 1384 } 1385 1386 /* Find first free DSC */ 1387 for (i = 0; i < pool->res_cap->num_dsc; i++) 1388 if (!res_ctx->is_dsc_acquired[i]) { 1389 *dsc = pool->dscs[i]; 1390 res_ctx->is_dsc_acquired[i] = true; 1391 break; 1392 } 1393 } 1394 1395 void dcn20_release_dsc(struct resource_context *res_ctx, 1396 const struct resource_pool *pool, 1397 struct display_stream_compressor **dsc) 1398 { 1399 int i; 1400 1401 for (i = 0; i < pool->res_cap->num_dsc; i++) 1402 if (pool->dscs[i] == *dsc) { 1403 res_ctx->is_dsc_acquired[i] = false; 1404 *dsc = NULL; 1405 break; 1406 } 1407 } 1408 1409 1410 1411 enum dc_status dcn20_add_dsc_to_stream_resource(struct dc *dc, 1412 struct dc_state *dc_ctx, 1413 struct dc_stream_state *dc_stream) 1414 { 1415 enum dc_status result = DC_OK; 1416 int i; 1417 1418 /* Get a DSC if required and available */ 1419 for (i = 0; i < dc->res_pool->pipe_count; i++) { 1420 struct pipe_ctx *pipe_ctx = &dc_ctx->res_ctx.pipe_ctx[i]; 1421 1422 if (pipe_ctx->top_pipe) 1423 continue; 1424 1425 if (pipe_ctx->stream != dc_stream) 1426 continue; 1427 1428 if (pipe_ctx->stream_res.dsc) 1429 continue; 1430 1431 dcn20_acquire_dsc(dc, &dc_ctx->res_ctx, &pipe_ctx->stream_res.dsc, i); 1432 1433 /* The number of DSCs can be less than the number of pipes */ 1434 if (!pipe_ctx->stream_res.dsc) { 1435 result = DC_NO_DSC_RESOURCE; 1436 } 1437 1438 break; 1439 } 1440 1441 return result; 1442 } 1443 1444 1445 static enum dc_status remove_dsc_from_stream_resource(struct dc *dc, 1446 struct dc_state *new_ctx, 1447 struct dc_stream_state *dc_stream) 1448 { 1449 struct pipe_ctx *pipe_ctx = NULL; 1450 int i; 1451 1452 for (i = 0; i < MAX_PIPES; i++) { 1453 if (new_ctx->res_ctx.pipe_ctx[i].stream == dc_stream && !new_ctx->res_ctx.pipe_ctx[i].top_pipe) { 1454 pipe_ctx = &new_ctx->res_ctx.pipe_ctx[i]; 1455 1456 if (pipe_ctx->stream_res.dsc) 1457 dcn20_release_dsc(&new_ctx->res_ctx, dc->res_pool, &pipe_ctx->stream_res.dsc); 1458 } 1459 } 1460 1461 if (!pipe_ctx) 1462 return DC_ERROR_UNEXPECTED; 1463 else 1464 return DC_OK; 1465 } 1466 1467 1468 enum dc_status dcn20_add_stream_to_ctx(struct dc *dc, struct dc_state *new_ctx, struct dc_stream_state *dc_stream) 1469 { 1470 enum dc_status result = DC_ERROR_UNEXPECTED; 1471 1472 result = resource_map_pool_resources(dc, new_ctx, dc_stream); 1473 1474 if (result == DC_OK) 1475 result = resource_map_phy_clock_resources(dc, new_ctx, dc_stream); 1476 1477 /* Get a DSC if required and available */ 1478 if (result == DC_OK && dc_stream->timing.flags.DSC) 1479 result = dcn20_add_dsc_to_stream_resource(dc, new_ctx, dc_stream); 1480 1481 if (result == DC_OK) 1482 result = dcn20_build_mapped_resource(dc, new_ctx, dc_stream); 1483 1484 return result; 1485 } 1486 1487 1488 enum dc_status dcn20_remove_stream_from_ctx(struct dc *dc, struct dc_state *new_ctx, struct dc_stream_state *dc_stream) 1489 { 1490 enum dc_status result = DC_OK; 1491 1492 result = remove_dsc_from_stream_resource(dc, new_ctx, dc_stream); 1493 1494 return result; 1495 } 1496 1497 /** 1498 * dcn20_split_stream_for_odm - Check if stream can be splited for ODM 1499 * 1500 * @dc: DC object with resource pool info required for pipe split 1501 * @res_ctx: Persistent state of resources 1502 * @prev_odm_pipe: Reference to the previous ODM pipe 1503 * @next_odm_pipe: Reference to the next ODM pipe 1504 * 1505 * This function takes a logically active pipe and a logically free pipe and 1506 * halves all the scaling parameters that need to be halved while populating 1507 * the free pipe with the required resources and configuring the next/previous 1508 * ODM pipe pointers. 1509 * 1510 * Return: 1511 * Return true if split stream for ODM is possible, otherwise, return false. 1512 */ 1513 bool dcn20_split_stream_for_odm( 1514 const struct dc *dc, 1515 struct resource_context *res_ctx, 1516 struct pipe_ctx *prev_odm_pipe, 1517 struct pipe_ctx *next_odm_pipe) 1518 { 1519 int pipe_idx = next_odm_pipe->pipe_idx; 1520 const struct resource_pool *pool = dc->res_pool; 1521 1522 *next_odm_pipe = *prev_odm_pipe; 1523 1524 next_odm_pipe->pipe_idx = pipe_idx; 1525 next_odm_pipe->plane_res.mi = pool->mis[next_odm_pipe->pipe_idx]; 1526 next_odm_pipe->plane_res.hubp = pool->hubps[next_odm_pipe->pipe_idx]; 1527 next_odm_pipe->plane_res.ipp = pool->ipps[next_odm_pipe->pipe_idx]; 1528 next_odm_pipe->plane_res.xfm = pool->transforms[next_odm_pipe->pipe_idx]; 1529 next_odm_pipe->plane_res.dpp = pool->dpps[next_odm_pipe->pipe_idx]; 1530 next_odm_pipe->plane_res.mpcc_inst = pool->dpps[next_odm_pipe->pipe_idx]->inst; 1531 next_odm_pipe->stream_res.dsc = NULL; 1532 if (prev_odm_pipe->next_odm_pipe && prev_odm_pipe->next_odm_pipe != next_odm_pipe) { 1533 next_odm_pipe->next_odm_pipe = prev_odm_pipe->next_odm_pipe; 1534 next_odm_pipe->next_odm_pipe->prev_odm_pipe = next_odm_pipe; 1535 } 1536 if (prev_odm_pipe->top_pipe && prev_odm_pipe->top_pipe->next_odm_pipe) { 1537 prev_odm_pipe->top_pipe->next_odm_pipe->bottom_pipe = next_odm_pipe; 1538 next_odm_pipe->top_pipe = prev_odm_pipe->top_pipe->next_odm_pipe; 1539 } 1540 if (prev_odm_pipe->bottom_pipe && prev_odm_pipe->bottom_pipe->next_odm_pipe) { 1541 prev_odm_pipe->bottom_pipe->next_odm_pipe->top_pipe = next_odm_pipe; 1542 next_odm_pipe->bottom_pipe = prev_odm_pipe->bottom_pipe->next_odm_pipe; 1543 } 1544 prev_odm_pipe->next_odm_pipe = next_odm_pipe; 1545 next_odm_pipe->prev_odm_pipe = prev_odm_pipe; 1546 1547 if (prev_odm_pipe->plane_state) { 1548 if (!resource_build_scaling_params(prev_odm_pipe) || 1549 !resource_build_scaling_params(next_odm_pipe)) { 1550 return false; 1551 } 1552 } 1553 1554 if (!next_odm_pipe->top_pipe) 1555 next_odm_pipe->stream_res.opp = pool->opps[next_odm_pipe->pipe_idx]; 1556 else 1557 next_odm_pipe->stream_res.opp = next_odm_pipe->top_pipe->stream_res.opp; 1558 if (next_odm_pipe->stream->timing.flags.DSC == 1 && !next_odm_pipe->top_pipe) { 1559 dcn20_acquire_dsc(dc, res_ctx, &next_odm_pipe->stream_res.dsc, next_odm_pipe->pipe_idx); 1560 ASSERT(next_odm_pipe->stream_res.dsc); 1561 if (next_odm_pipe->stream_res.dsc == NULL) 1562 return false; 1563 } 1564 1565 return true; 1566 } 1567 1568 void dcn20_split_stream_for_mpc( 1569 struct resource_context *res_ctx, 1570 const struct resource_pool *pool, 1571 struct pipe_ctx *primary_pipe, 1572 struct pipe_ctx *secondary_pipe) 1573 { 1574 int pipe_idx = secondary_pipe->pipe_idx; 1575 struct pipe_ctx *sec_bot_pipe = secondary_pipe->bottom_pipe; 1576 1577 *secondary_pipe = *primary_pipe; 1578 secondary_pipe->bottom_pipe = sec_bot_pipe; 1579 1580 secondary_pipe->pipe_idx = pipe_idx; 1581 secondary_pipe->plane_res.mi = pool->mis[secondary_pipe->pipe_idx]; 1582 secondary_pipe->plane_res.hubp = pool->hubps[secondary_pipe->pipe_idx]; 1583 secondary_pipe->plane_res.ipp = pool->ipps[secondary_pipe->pipe_idx]; 1584 secondary_pipe->plane_res.xfm = pool->transforms[secondary_pipe->pipe_idx]; 1585 secondary_pipe->plane_res.dpp = pool->dpps[secondary_pipe->pipe_idx]; 1586 secondary_pipe->plane_res.mpcc_inst = pool->dpps[secondary_pipe->pipe_idx]->inst; 1587 secondary_pipe->stream_res.dsc = NULL; 1588 if (primary_pipe->bottom_pipe && primary_pipe->bottom_pipe != secondary_pipe) { 1589 ASSERT(!secondary_pipe->bottom_pipe); 1590 secondary_pipe->bottom_pipe = primary_pipe->bottom_pipe; 1591 secondary_pipe->bottom_pipe->top_pipe = secondary_pipe; 1592 } 1593 primary_pipe->bottom_pipe = secondary_pipe; 1594 secondary_pipe->top_pipe = primary_pipe; 1595 1596 ASSERT(primary_pipe->plane_state); 1597 } 1598 1599 unsigned int dcn20_calc_max_scaled_time( 1600 unsigned int time_per_pixel, 1601 enum mmhubbub_wbif_mode mode, 1602 unsigned int urgent_watermark) 1603 { 1604 unsigned int time_per_byte = 0; 1605 unsigned int total_y_free_entry = 0x200; /* two memory piece for luma */ 1606 unsigned int total_c_free_entry = 0x140; /* two memory piece for chroma */ 1607 unsigned int small_free_entry, max_free_entry; 1608 unsigned int buf_lh_capability; 1609 unsigned int max_scaled_time; 1610 1611 if (mode == PACKED_444) /* packed mode */ 1612 time_per_byte = time_per_pixel/4; 1613 else if (mode == PLANAR_420_8BPC) 1614 time_per_byte = time_per_pixel; 1615 else if (mode == PLANAR_420_10BPC) /* p010 */ 1616 time_per_byte = time_per_pixel * 819/1024; 1617 1618 if (time_per_byte == 0) 1619 time_per_byte = 1; 1620 1621 small_free_entry = total_c_free_entry; 1622 max_free_entry = (mode == PACKED_444) ? total_y_free_entry + total_c_free_entry : small_free_entry; 1623 buf_lh_capability = max_free_entry*time_per_byte*32/16; /* there is 4bit fraction */ 1624 max_scaled_time = buf_lh_capability - urgent_watermark; 1625 return max_scaled_time; 1626 } 1627 1628 void dcn20_set_mcif_arb_params( 1629 struct dc *dc, 1630 struct dc_state *context, 1631 display_e2e_pipe_params_st *pipes, 1632 int pipe_cnt) 1633 { 1634 enum mmhubbub_wbif_mode wbif_mode; 1635 struct mcif_arb_params *wb_arb_params; 1636 int i, j, dwb_pipe; 1637 1638 /* Writeback MCIF_WB arbitration parameters */ 1639 dwb_pipe = 0; 1640 for (i = 0; i < dc->res_pool->pipe_count; i++) { 1641 1642 if (!context->res_ctx.pipe_ctx[i].stream) 1643 continue; 1644 1645 for (j = 0; j < MAX_DWB_PIPES; j++) { 1646 if (context->res_ctx.pipe_ctx[i].stream->writeback_info[j].wb_enabled == false) 1647 continue; 1648 1649 //wb_arb_params = &context->res_ctx.pipe_ctx[i].stream->writeback_info[j].mcif_arb_params; 1650 wb_arb_params = &context->bw_ctx.bw.dcn.bw_writeback.mcif_wb_arb[dwb_pipe]; 1651 1652 if (context->res_ctx.pipe_ctx[i].stream->writeback_info[j].dwb_params.out_format == dwb_scaler_mode_yuv420) { 1653 if (context->res_ctx.pipe_ctx[i].stream->writeback_info[j].dwb_params.output_depth == DWB_OUTPUT_PIXEL_DEPTH_8BPC) 1654 wbif_mode = PLANAR_420_8BPC; 1655 else 1656 wbif_mode = PLANAR_420_10BPC; 1657 } else 1658 wbif_mode = PACKED_444; 1659 1660 DC_FP_START(); 1661 dcn20_fpu_set_wb_arb_params(wb_arb_params, context, pipes, pipe_cnt, i); 1662 DC_FP_END(); 1663 1664 wb_arb_params->slice_lines = 32; 1665 wb_arb_params->arbitration_slice = 2; 1666 wb_arb_params->max_scaled_time = dcn20_calc_max_scaled_time(wb_arb_params->time_per_pixel, 1667 wbif_mode, 1668 wb_arb_params->cli_watermark[0]); /* assume 4 watermark sets have the same value */ 1669 1670 dwb_pipe++; 1671 1672 if (dwb_pipe >= MAX_DWB_PIPES) 1673 return; 1674 } 1675 } 1676 } 1677 1678 bool dcn20_validate_dsc(struct dc *dc, struct dc_state *new_ctx) 1679 { 1680 int i; 1681 1682 /* Validate DSC config, dsc count validation is already done */ 1683 for (i = 0; i < dc->res_pool->pipe_count; i++) { 1684 struct pipe_ctx *pipe_ctx = &new_ctx->res_ctx.pipe_ctx[i]; 1685 struct dc_stream_state *stream = pipe_ctx->stream; 1686 struct dsc_config dsc_cfg; 1687 struct pipe_ctx *odm_pipe; 1688 int opp_cnt = 1; 1689 1690 for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe) 1691 opp_cnt++; 1692 1693 /* Only need to validate top pipe */ 1694 if (pipe_ctx->top_pipe || pipe_ctx->prev_odm_pipe || !stream || !stream->timing.flags.DSC) 1695 continue; 1696 1697 dsc_cfg.pic_width = (stream->timing.h_addressable + pipe_ctx->dsc_padding_params.dsc_hactive_padding 1698 + stream->timing.h_border_left + stream->timing.h_border_right) / opp_cnt; 1699 dsc_cfg.pic_height = stream->timing.v_addressable + stream->timing.v_border_top 1700 + stream->timing.v_border_bottom; 1701 dsc_cfg.pixel_encoding = stream->timing.pixel_encoding; 1702 dsc_cfg.color_depth = stream->timing.display_color_depth; 1703 dsc_cfg.is_odm = pipe_ctx->next_odm_pipe ? true : false; 1704 dsc_cfg.dc_dsc_cfg = stream->timing.dsc_cfg; 1705 dsc_cfg.dc_dsc_cfg.num_slices_h /= opp_cnt; 1706 dsc_cfg.dsc_padding = 0; 1707 1708 if (!pipe_ctx->stream_res.dsc->funcs->dsc_validate_stream(pipe_ctx->stream_res.dsc, &dsc_cfg)) 1709 return false; 1710 } 1711 return true; 1712 } 1713 1714 struct pipe_ctx *dcn20_find_secondary_pipe(struct dc *dc, 1715 struct resource_context *res_ctx, 1716 const struct resource_pool *pool, 1717 const struct pipe_ctx *primary_pipe) 1718 { 1719 struct pipe_ctx *secondary_pipe = NULL; 1720 1721 if (dc && primary_pipe) { 1722 int j; 1723 int preferred_pipe_idx = 0; 1724 1725 /* first check the prev dc state: 1726 * if this primary pipe has a bottom pipe in prev. state 1727 * and if the bottom pipe is still available (which it should be), 1728 * pick that pipe as secondary 1729 * Same logic applies for ODM pipes 1730 */ 1731 if (dc->current_state->res_ctx.pipe_ctx[primary_pipe->pipe_idx].next_odm_pipe) { 1732 preferred_pipe_idx = dc->current_state->res_ctx.pipe_ctx[primary_pipe->pipe_idx].next_odm_pipe->pipe_idx; 1733 if (res_ctx->pipe_ctx[preferred_pipe_idx].stream == NULL) { 1734 secondary_pipe = &res_ctx->pipe_ctx[preferred_pipe_idx]; 1735 secondary_pipe->pipe_idx = preferred_pipe_idx; 1736 } 1737 } 1738 if (secondary_pipe == NULL && 1739 dc->current_state->res_ctx.pipe_ctx[primary_pipe->pipe_idx].bottom_pipe) { 1740 preferred_pipe_idx = dc->current_state->res_ctx.pipe_ctx[primary_pipe->pipe_idx].bottom_pipe->pipe_idx; 1741 if (res_ctx->pipe_ctx[preferred_pipe_idx].stream == NULL) { 1742 secondary_pipe = &res_ctx->pipe_ctx[preferred_pipe_idx]; 1743 secondary_pipe->pipe_idx = preferred_pipe_idx; 1744 } 1745 } 1746 1747 /* 1748 * if this primary pipe does not have a bottom pipe in prev. state 1749 * start backward and find a pipe that did not used to be a bottom pipe in 1750 * prev. dc state. This way we make sure we keep the same assignment as 1751 * last state and will not have to reprogram every pipe 1752 */ 1753 if (secondary_pipe == NULL) { 1754 for (j = dc->res_pool->pipe_count - 1; j >= 0; j--) { 1755 if (dc->current_state->res_ctx.pipe_ctx[j].top_pipe == NULL 1756 && dc->current_state->res_ctx.pipe_ctx[j].prev_odm_pipe == NULL) { 1757 preferred_pipe_idx = j; 1758 1759 if (res_ctx->pipe_ctx[preferred_pipe_idx].stream == NULL) { 1760 secondary_pipe = &res_ctx->pipe_ctx[preferred_pipe_idx]; 1761 secondary_pipe->pipe_idx = preferred_pipe_idx; 1762 break; 1763 } 1764 } 1765 } 1766 } 1767 /* 1768 * We should never hit this assert unless assignments are shuffled around 1769 * if this happens we will prob. hit a vsync tdr 1770 */ 1771 ASSERT(secondary_pipe); 1772 /* 1773 * search backwards for the second pipe to keep pipe 1774 * assignment more consistent 1775 */ 1776 if (secondary_pipe == NULL) { 1777 for (j = dc->res_pool->pipe_count - 1; j >= 0; j--) { 1778 preferred_pipe_idx = j; 1779 1780 if (res_ctx->pipe_ctx[preferred_pipe_idx].stream == NULL) { 1781 secondary_pipe = &res_ctx->pipe_ctx[preferred_pipe_idx]; 1782 secondary_pipe->pipe_idx = preferred_pipe_idx; 1783 break; 1784 } 1785 } 1786 } 1787 } 1788 1789 return secondary_pipe; 1790 } 1791 1792 void dcn20_merge_pipes_for_validate( 1793 struct dc *dc, 1794 struct dc_state *context) 1795 { 1796 int i; 1797 1798 /* merge previously split odm pipes since mode support needs to make the decision */ 1799 for (i = 0; i < dc->res_pool->pipe_count; i++) { 1800 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 1801 struct pipe_ctx *odm_pipe = pipe->next_odm_pipe; 1802 1803 if (pipe->prev_odm_pipe) 1804 continue; 1805 1806 pipe->next_odm_pipe = NULL; 1807 while (odm_pipe) { 1808 struct pipe_ctx *next_odm_pipe = odm_pipe->next_odm_pipe; 1809 1810 odm_pipe->plane_state = NULL; 1811 odm_pipe->stream = NULL; 1812 odm_pipe->top_pipe = NULL; 1813 odm_pipe->bottom_pipe = NULL; 1814 odm_pipe->prev_odm_pipe = NULL; 1815 odm_pipe->next_odm_pipe = NULL; 1816 if (odm_pipe->stream_res.dsc) 1817 dcn20_release_dsc(&context->res_ctx, dc->res_pool, &odm_pipe->stream_res.dsc); 1818 /* Clear plane_res and stream_res */ 1819 memset(&odm_pipe->plane_res, 0, sizeof(odm_pipe->plane_res)); 1820 memset(&odm_pipe->stream_res, 0, sizeof(odm_pipe->stream_res)); 1821 odm_pipe = next_odm_pipe; 1822 } 1823 if (pipe->plane_state) 1824 resource_build_scaling_params(pipe); 1825 } 1826 1827 /* merge previously mpc split pipes since mode support needs to make the decision */ 1828 for (i = 0; i < dc->res_pool->pipe_count; i++) { 1829 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 1830 struct pipe_ctx *hsplit_pipe = pipe->bottom_pipe; 1831 1832 if (!hsplit_pipe || hsplit_pipe->plane_state != pipe->plane_state) 1833 continue; 1834 1835 pipe->bottom_pipe = hsplit_pipe->bottom_pipe; 1836 if (hsplit_pipe->bottom_pipe) 1837 hsplit_pipe->bottom_pipe->top_pipe = pipe; 1838 hsplit_pipe->plane_state = NULL; 1839 hsplit_pipe->stream = NULL; 1840 hsplit_pipe->top_pipe = NULL; 1841 hsplit_pipe->bottom_pipe = NULL; 1842 1843 /* Clear plane_res and stream_res */ 1844 memset(&hsplit_pipe->plane_res, 0, sizeof(hsplit_pipe->plane_res)); 1845 memset(&hsplit_pipe->stream_res, 0, sizeof(hsplit_pipe->stream_res)); 1846 if (pipe->plane_state) 1847 resource_build_scaling_params(pipe); 1848 } 1849 } 1850 1851 int dcn20_validate_apply_pipe_split_flags( 1852 struct dc *dc, 1853 struct dc_state *context, 1854 int vlevel, 1855 int *split, 1856 bool *merge) 1857 { 1858 int i, pipe_idx, vlevel_split; 1859 int plane_count = 0; 1860 bool force_split = false; 1861 bool avoid_split = dc->debug.pipe_split_policy == MPC_SPLIT_AVOID; 1862 struct vba_vars_st *v = &context->bw_ctx.dml.vba; 1863 int max_mpc_comb = v->maxMpcComb; 1864 1865 if (context->stream_count > 1) { 1866 if (dc->debug.pipe_split_policy == MPC_SPLIT_AVOID_MULT_DISP) 1867 avoid_split = true; 1868 } else if (dc->debug.force_single_disp_pipe_split) 1869 force_split = true; 1870 1871 for (i = 0; i < dc->res_pool->pipe_count; i++) { 1872 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 1873 1874 /** 1875 * Workaround for avoiding pipe-split in cases where we'd split 1876 * planes that are too small, resulting in splits that aren't 1877 * valid for the scaler. 1878 */ 1879 if (pipe->plane_state && 1880 (pipe->plane_state->dst_rect.width <= 16 || 1881 pipe->plane_state->dst_rect.height <= 16 || 1882 pipe->plane_state->src_rect.width <= 16 || 1883 pipe->plane_state->src_rect.height <= 16)) 1884 avoid_split = true; 1885 1886 /* TODO: fix dc bugs and remove this split threshold thing */ 1887 if (pipe->stream && !pipe->prev_odm_pipe && 1888 (!pipe->top_pipe || pipe->top_pipe->plane_state != pipe->plane_state)) 1889 ++plane_count; 1890 } 1891 if (plane_count > dc->res_pool->pipe_count / 2) 1892 avoid_split = true; 1893 1894 /* W/A: Mode timing with borders may not work well with pipe split, avoid for this corner case */ 1895 for (i = 0; i < dc->res_pool->pipe_count; i++) { 1896 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 1897 struct dc_crtc_timing timing; 1898 1899 if (!pipe->stream) 1900 continue; 1901 else { 1902 timing = pipe->stream->timing; 1903 if (timing.h_border_left + timing.h_border_right 1904 + timing.v_border_top + timing.v_border_bottom > 0) { 1905 avoid_split = true; 1906 break; 1907 } 1908 } 1909 } 1910 1911 /* Avoid split loop looks for lowest voltage level that allows most unsplit pipes possible */ 1912 if (avoid_split) { 1913 for (i = 0, pipe_idx = 0; i < dc->res_pool->pipe_count; i++) { 1914 if (!context->res_ctx.pipe_ctx[i].stream) 1915 continue; 1916 1917 for (vlevel_split = vlevel; vlevel <= context->bw_ctx.dml.soc.num_states; vlevel++) 1918 if (v->NoOfDPP[vlevel][0][pipe_idx] == 1 && 1919 v->ModeSupport[vlevel][0]) 1920 break; 1921 /* Impossible to not split this pipe */ 1922 if (vlevel > context->bw_ctx.dml.soc.num_states) 1923 vlevel = vlevel_split; 1924 else 1925 max_mpc_comb = 0; 1926 pipe_idx++; 1927 } 1928 v->maxMpcComb = max_mpc_comb; 1929 } 1930 1931 /* Split loop sets which pipe should be split based on dml outputs and dc flags */ 1932 for (i = 0, pipe_idx = 0; i < dc->res_pool->pipe_count; i++) { 1933 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 1934 int pipe_plane = v->pipe_plane[pipe_idx]; 1935 bool split4mpc = context->stream_count == 1 && plane_count == 1 1936 && dc->config.enable_4to1MPC && dc->res_pool->pipe_count >= 4; 1937 1938 if (!context->res_ctx.pipe_ctx[i].stream) 1939 continue; 1940 1941 if (split4mpc || v->NoOfDPP[vlevel][max_mpc_comb][pipe_plane] == 4) 1942 split[i] = 4; 1943 else if (force_split || v->NoOfDPP[vlevel][max_mpc_comb][pipe_plane] == 2) 1944 split[i] = 2; 1945 1946 if ((pipe->stream->view_format == 1947 VIEW_3D_FORMAT_SIDE_BY_SIDE || 1948 pipe->stream->view_format == 1949 VIEW_3D_FORMAT_TOP_AND_BOTTOM) && 1950 (pipe->stream->timing.timing_3d_format == 1951 TIMING_3D_FORMAT_TOP_AND_BOTTOM || 1952 pipe->stream->timing.timing_3d_format == 1953 TIMING_3D_FORMAT_SIDE_BY_SIDE)) 1954 split[i] = 2; 1955 if (dc->debug.force_odm_combine & (1 << pipe->stream_res.tg->inst)) { 1956 split[i] = 2; 1957 v->ODMCombineEnablePerState[vlevel][pipe_plane] = dm_odm_combine_mode_2to1; 1958 } 1959 if (dc->debug.force_odm_combine_4to1 & (1 << pipe->stream_res.tg->inst)) { 1960 split[i] = 4; 1961 v->ODMCombineEnablePerState[vlevel][pipe_plane] = dm_odm_combine_mode_4to1; 1962 } 1963 /*420 format workaround*/ 1964 if (pipe->stream->timing.h_addressable > 7680 && 1965 pipe->stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR420) { 1966 split[i] = 4; 1967 } 1968 v->ODMCombineEnabled[pipe_plane] = 1969 v->ODMCombineEnablePerState[vlevel][pipe_plane]; 1970 1971 if (v->ODMCombineEnabled[pipe_plane] == dm_odm_combine_mode_disabled) { 1972 if (resource_get_mpc_slice_count(pipe) == 2) { 1973 /*If need split for mpc but 2 way split already*/ 1974 if (split[i] == 4) 1975 split[i] = 2; /* 2 -> 4 MPC */ 1976 else if (split[i] == 2) 1977 split[i] = 0; /* 2 -> 2 MPC */ 1978 else if (pipe->top_pipe && pipe->top_pipe->plane_state == pipe->plane_state) 1979 merge[i] = true; /* 2 -> 1 MPC */ 1980 } else if (resource_get_mpc_slice_count(pipe) == 4) { 1981 /*If need split for mpc but 4 way split already*/ 1982 if (split[i] == 2 && ((pipe->top_pipe && !pipe->top_pipe->top_pipe) 1983 || !pipe->bottom_pipe)) { 1984 merge[i] = true; /* 4 -> 2 MPC */ 1985 } else if (split[i] == 0 && pipe->top_pipe && 1986 pipe->top_pipe->plane_state == pipe->plane_state) 1987 merge[i] = true; /* 4 -> 1 MPC */ 1988 split[i] = 0; 1989 } else if (resource_get_odm_slice_count(pipe) > 1) { 1990 /* ODM -> MPC transition */ 1991 if (pipe->prev_odm_pipe) { 1992 split[i] = 0; 1993 merge[i] = true; 1994 } 1995 } 1996 } else { 1997 if (resource_get_odm_slice_count(pipe) == 2) { 1998 /*If need split for odm but 2 way split already*/ 1999 if (split[i] == 4) 2000 split[i] = 2; /* 2 -> 4 ODM */ 2001 else if (split[i] == 2) 2002 split[i] = 0; /* 2 -> 2 ODM */ 2003 else if (pipe->prev_odm_pipe) { 2004 ASSERT(0); /* NOT expected yet */ 2005 merge[i] = true; /* exit ODM */ 2006 } 2007 } else if (resource_get_odm_slice_count(pipe) == 4) { 2008 /*If need split for odm but 4 way split already*/ 2009 if (split[i] == 2 && ((pipe->prev_odm_pipe && !pipe->prev_odm_pipe->prev_odm_pipe) 2010 || !pipe->next_odm_pipe)) { 2011 merge[i] = true; /* 4 -> 2 ODM */ 2012 } else if (split[i] == 0 && pipe->prev_odm_pipe) { 2013 ASSERT(0); /* NOT expected yet */ 2014 merge[i] = true; /* exit ODM */ 2015 } 2016 split[i] = 0; 2017 } else if (resource_get_mpc_slice_count(pipe) > 1) { 2018 /* MPC -> ODM transition */ 2019 ASSERT(0); /* NOT expected yet */ 2020 if (pipe->top_pipe && pipe->top_pipe->plane_state == pipe->plane_state) { 2021 split[i] = 0; 2022 merge[i] = true; 2023 } 2024 } 2025 } 2026 2027 /* Adjust dppclk when split is forced, do not bother with dispclk */ 2028 if (split[i] != 0 && v->NoOfDPP[vlevel][max_mpc_comb][pipe_idx] == 1) { 2029 DC_FP_START(); 2030 dcn20_fpu_adjust_dppclk(v, vlevel, max_mpc_comb, pipe_idx, false); 2031 DC_FP_END(); 2032 } 2033 pipe_idx++; 2034 } 2035 2036 return vlevel; 2037 } 2038 2039 bool dcn20_fast_validate_bw( 2040 struct dc *dc, 2041 struct dc_state *context, 2042 display_e2e_pipe_params_st *pipes, 2043 int *pipe_cnt_out, 2044 int *pipe_split_from, 2045 int *vlevel_out, 2046 enum dc_validate_mode validate_mode) 2047 { 2048 bool out = false; 2049 int split[MAX_PIPES] = { 0 }; 2050 bool merge[MAX_PIPES] = { false }; 2051 int pipe_cnt, i, pipe_idx, vlevel; 2052 2053 ASSERT(pipes); 2054 if (!pipes) 2055 return false; 2056 2057 dcn20_merge_pipes_for_validate(dc, context); 2058 2059 pipe_cnt = dc->res_pool->funcs->populate_dml_pipes(dc, context, pipes, validate_mode); 2060 2061 *pipe_cnt_out = pipe_cnt; 2062 2063 if (!pipe_cnt) { 2064 out = true; 2065 goto validate_out; 2066 } 2067 2068 vlevel = dml_get_voltage_level(&context->bw_ctx.dml, pipes, pipe_cnt); 2069 2070 if (vlevel > context->bw_ctx.dml.soc.num_states) 2071 goto validate_fail; 2072 2073 vlevel = dcn20_validate_apply_pipe_split_flags(dc, context, vlevel, split, merge); 2074 2075 /*initialize pipe_just_split_from to invalid idx*/ 2076 for (i = 0; i < MAX_PIPES; i++) 2077 pipe_split_from[i] = -1; 2078 2079 for (i = 0, pipe_idx = -1; i < dc->res_pool->pipe_count; i++) { 2080 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 2081 struct pipe_ctx *hsplit_pipe = pipe->bottom_pipe; 2082 2083 if (!pipe->stream || pipe_split_from[i] >= 0) 2084 continue; 2085 2086 pipe_idx++; 2087 2088 if (!pipe->top_pipe && !pipe->plane_state && context->bw_ctx.dml.vba.ODMCombineEnabled[pipe_idx]) { 2089 hsplit_pipe = dcn20_find_secondary_pipe(dc, &context->res_ctx, dc->res_pool, pipe); 2090 ASSERT(hsplit_pipe); 2091 if (!dcn20_split_stream_for_odm( 2092 dc, &context->res_ctx, 2093 pipe, hsplit_pipe)) 2094 goto validate_fail; 2095 pipe_split_from[hsplit_pipe->pipe_idx] = pipe_idx; 2096 dcn20_build_mapped_resource(dc, context, pipe->stream); 2097 } 2098 2099 if (!pipe->plane_state) 2100 continue; 2101 /* Skip 2nd half of already split pipe */ 2102 if (pipe->top_pipe && pipe->plane_state == pipe->top_pipe->plane_state) 2103 continue; 2104 2105 /* We do not support mpo + odm at the moment */ 2106 if (hsplit_pipe && hsplit_pipe->plane_state != pipe->plane_state 2107 && context->bw_ctx.dml.vba.ODMCombineEnabled[pipe_idx]) 2108 goto validate_fail; 2109 2110 if (split[i] == 2) { 2111 if (!hsplit_pipe || hsplit_pipe->plane_state != pipe->plane_state) { 2112 /* pipe not split previously needs split */ 2113 hsplit_pipe = dcn20_find_secondary_pipe(dc, &context->res_ctx, dc->res_pool, pipe); 2114 ASSERT(hsplit_pipe); 2115 if (!hsplit_pipe) { 2116 DC_FP_START(); 2117 dcn20_fpu_adjust_dppclk(&context->bw_ctx.dml.vba, vlevel, context->bw_ctx.dml.vba.maxMpcComb, pipe_idx, true); 2118 DC_FP_END(); 2119 continue; 2120 } 2121 if (context->bw_ctx.dml.vba.ODMCombineEnabled[pipe_idx]) { 2122 if (!dcn20_split_stream_for_odm( 2123 dc, &context->res_ctx, 2124 pipe, hsplit_pipe)) 2125 goto validate_fail; 2126 dcn20_build_mapped_resource(dc, context, pipe->stream); 2127 } else { 2128 dcn20_split_stream_for_mpc( 2129 &context->res_ctx, dc->res_pool, 2130 pipe, hsplit_pipe); 2131 resource_build_scaling_params(pipe); 2132 resource_build_scaling_params(hsplit_pipe); 2133 } 2134 pipe_split_from[hsplit_pipe->pipe_idx] = pipe_idx; 2135 } 2136 } else if (hsplit_pipe && hsplit_pipe->plane_state == pipe->plane_state) { 2137 /* merge should already have been done */ 2138 ASSERT(0); 2139 } 2140 } 2141 2142 /* Actual dsc count per stream dsc validation*/ 2143 if (!dcn20_validate_dsc(dc, context)) { 2144 context->bw_ctx.dml.vba.ValidationStatus[context->bw_ctx.dml.vba.soc.num_states] = 2145 DML_FAIL_DSC_VALIDATION_FAILURE; 2146 goto validate_fail; 2147 } 2148 2149 *vlevel_out = vlevel; 2150 2151 out = true; 2152 goto validate_out; 2153 2154 validate_fail: 2155 out = false; 2156 2157 validate_out: 2158 return out; 2159 } 2160 2161 enum dc_status dcn20_validate_bandwidth(struct dc *dc, struct dc_state *context, 2162 enum dc_validate_mode validate_mode) 2163 { 2164 bool voltage_supported; 2165 display_e2e_pipe_params_st *pipes; 2166 2167 pipes = kzalloc_objs(display_e2e_pipe_params_st, 2168 dc->res_pool->pipe_count); 2169 if (!pipes) 2170 return DC_FAIL_BANDWIDTH_VALIDATE; 2171 2172 DC_FP_START(); 2173 voltage_supported = dcn20_validate_bandwidth_fp(dc, context, validate_mode, pipes); 2174 DC_FP_END(); 2175 2176 kfree(pipes); 2177 return voltage_supported ? DC_OK : DC_FAIL_BANDWIDTH_VALIDATE; 2178 } 2179 2180 struct pipe_ctx *dcn20_acquire_free_pipe_for_layer( 2181 const struct dc_state *cur_ctx, 2182 struct dc_state *new_ctx, 2183 const struct resource_pool *pool, 2184 const struct pipe_ctx *opp_head) 2185 { 2186 struct resource_context *res_ctx = &new_ctx->res_ctx; 2187 struct pipe_ctx *otg_master = resource_get_otg_master_for_stream(res_ctx, opp_head->stream); 2188 struct pipe_ctx *sec_dpp_pipe = resource_find_free_secondary_pipe_legacy(res_ctx, pool, otg_master); 2189 2190 ASSERT(otg_master); 2191 2192 if (!sec_dpp_pipe) 2193 return NULL; 2194 2195 sec_dpp_pipe->stream = opp_head->stream; 2196 sec_dpp_pipe->stream_res.tg = opp_head->stream_res.tg; 2197 sec_dpp_pipe->stream_res.opp = opp_head->stream_res.opp; 2198 2199 sec_dpp_pipe->plane_res.hubp = pool->hubps[sec_dpp_pipe->pipe_idx]; 2200 sec_dpp_pipe->plane_res.ipp = pool->ipps[sec_dpp_pipe->pipe_idx]; 2201 sec_dpp_pipe->plane_res.dpp = pool->dpps[sec_dpp_pipe->pipe_idx]; 2202 sec_dpp_pipe->plane_res.mpcc_inst = pool->dpps[sec_dpp_pipe->pipe_idx]->inst; 2203 2204 return sec_dpp_pipe; 2205 } 2206 2207 bool dcn20_get_dcc_compression_cap(const struct dc *dc, 2208 const struct dc_dcc_surface_param *input, 2209 struct dc_surface_dcc_cap *output) 2210 { 2211 if (dc->res_pool->hubbub->funcs->get_dcc_compression_cap) 2212 return dc->res_pool->hubbub->funcs->get_dcc_compression_cap( 2213 dc->res_pool->hubbub, input, output); 2214 2215 return false; 2216 } 2217 2218 static void dcn20_destroy_resource_pool(struct resource_pool **pool) 2219 { 2220 struct dcn20_resource_pool *dcn20_pool = TO_DCN20_RES_POOL(*pool); 2221 2222 dcn20_resource_destruct(dcn20_pool); 2223 kfree(dcn20_pool); 2224 *pool = NULL; 2225 } 2226 2227 2228 static struct dc_cap_funcs cap_funcs = { 2229 .get_dcc_compression_cap = dcn20_get_dcc_compression_cap 2230 }; 2231 2232 2233 enum dc_status dcn20_patch_unknown_plane_state(struct dc_plane_state *plane_state) 2234 { 2235 enum surface_pixel_format surf_pix_format = plane_state->format; 2236 unsigned int bpp = resource_pixel_format_to_bpp(surf_pix_format); 2237 2238 plane_state->tiling_info.gfx9.swizzle = DC_SW_64KB_S; 2239 if (bpp == 64) 2240 plane_state->tiling_info.gfx9.swizzle = DC_SW_64KB_D; 2241 2242 return DC_OK; 2243 } 2244 2245 void dcn20_release_pipe(struct dc_state *context, 2246 struct pipe_ctx *pipe, 2247 const struct resource_pool *pool) 2248 { 2249 if (resource_is_pipe_type(pipe, OPP_HEAD) && pipe->stream_res.dsc) 2250 dcn20_release_dsc(&context->res_ctx, pool, &pipe->stream_res.dsc); 2251 memset(pipe, 0, sizeof(*pipe)); 2252 } 2253 2254 static const struct resource_funcs dcn20_res_pool_funcs = { 2255 .destroy = dcn20_destroy_resource_pool, 2256 .link_enc_create = dcn20_link_encoder_create, 2257 .panel_cntl_create = dcn20_panel_cntl_create, 2258 .validate_bandwidth = dcn20_validate_bandwidth, 2259 .acquire_free_pipe_as_secondary_dpp_pipe = dcn20_acquire_free_pipe_for_layer, 2260 .release_pipe = dcn20_release_pipe, 2261 .add_stream_to_ctx = dcn20_add_stream_to_ctx, 2262 .add_dsc_to_stream_resource = dcn20_add_dsc_to_stream_resource, 2263 .remove_stream_from_ctx = dcn20_remove_stream_from_ctx, 2264 .populate_dml_writeback_from_context = dcn20_populate_dml_writeback_from_context, 2265 .patch_unknown_plane_state = dcn20_patch_unknown_plane_state, 2266 .set_mcif_arb_params = dcn20_set_mcif_arb_params, 2267 .populate_dml_pipes = dcn20_populate_dml_pipes_from_context, 2268 .find_first_free_match_stream_enc_for_link = dcn10_find_first_free_match_stream_enc_for_link, 2269 .get_vstartup_for_pipe = dcn10_get_vstartup_for_pipe 2270 }; 2271 2272 bool dcn20_dwbc_create(struct dc_context *ctx, struct resource_pool *pool) 2273 { 2274 int i; 2275 uint32_t pipe_count = pool->res_cap->num_dwb; 2276 2277 for (i = 0; i < pipe_count; i++) { 2278 struct dcn20_dwbc *dwbc20 = kzalloc_obj(struct dcn20_dwbc); 2279 2280 if (!dwbc20) { 2281 dm_error("DC: failed to create dwbc20!\n"); 2282 return false; 2283 } 2284 dcn20_dwbc_construct(dwbc20, ctx, 2285 &dwbc20_regs[i], 2286 &dwbc20_shift, 2287 &dwbc20_mask, 2288 i); 2289 pool->dwbc[i] = &dwbc20->base; 2290 } 2291 return true; 2292 } 2293 2294 bool dcn20_mmhubbub_create(struct dc_context *ctx, struct resource_pool *pool) 2295 { 2296 int i; 2297 uint32_t pipe_count = pool->res_cap->num_dwb; 2298 2299 ASSERT(pipe_count > 0); 2300 2301 for (i = 0; i < pipe_count; i++) { 2302 struct dcn20_mmhubbub *mcif_wb20 = kzalloc_obj(struct dcn20_mmhubbub); 2303 2304 if (!mcif_wb20) { 2305 dm_error("DC: failed to create mcif_wb20!\n"); 2306 return false; 2307 } 2308 2309 dcn20_mmhubbub_construct(mcif_wb20, ctx, 2310 &mcif_wb20_regs[i], 2311 &mcif_wb20_shift, 2312 &mcif_wb20_mask, 2313 i); 2314 2315 pool->mcif_wb[i] = &mcif_wb20->base; 2316 } 2317 return true; 2318 } 2319 2320 static struct pp_smu_funcs *dcn20_pp_smu_create(struct dc_context *ctx) 2321 { 2322 struct pp_smu_funcs *pp_smu = kzalloc_obj(*pp_smu); 2323 2324 if (!pp_smu) 2325 return pp_smu; 2326 2327 dm_pp_get_funcs(ctx, pp_smu); 2328 2329 if (pp_smu->ctx.ver != PP_SMU_VER_NV) 2330 pp_smu = memset(pp_smu, 0, sizeof(struct pp_smu_funcs)); 2331 2332 return pp_smu; 2333 } 2334 2335 static void dcn20_pp_smu_destroy(struct pp_smu_funcs **pp_smu) 2336 { 2337 if (pp_smu && *pp_smu) { 2338 kfree(*pp_smu); 2339 *pp_smu = NULL; 2340 } 2341 } 2342 2343 static struct _vcs_dpi_soc_bounding_box_st *get_asic_rev_soc_bb( 2344 uint32_t hw_internal_rev) 2345 { 2346 if (ASICREV_IS_NAVI14_M(hw_internal_rev)) 2347 return &dcn2_0_nv14_soc; 2348 2349 if (ASICREV_IS_NAVI12_P(hw_internal_rev)) 2350 return &dcn2_0_nv12_soc; 2351 2352 return &dcn2_0_soc; 2353 } 2354 2355 static struct _vcs_dpi_ip_params_st *get_asic_rev_ip_params( 2356 uint32_t hw_internal_rev) 2357 { 2358 if (ASICREV_IS_NAVI14_M(hw_internal_rev)) 2359 return &dcn2_0_nv14_ip; 2360 2361 /* NV12 and NV10 */ 2362 return &dcn2_0_ip; 2363 } 2364 2365 static enum dml_project get_dml_project_version(uint32_t hw_internal_rev) 2366 { 2367 return DML_PROJECT_NAVI10v2; 2368 } 2369 2370 static bool init_soc_bounding_box(struct dc *dc, 2371 struct dcn20_resource_pool *pool) 2372 { 2373 struct _vcs_dpi_soc_bounding_box_st *loaded_bb = 2374 get_asic_rev_soc_bb(dc->ctx->asic_id.hw_internal_rev); 2375 struct _vcs_dpi_ip_params_st *loaded_ip = 2376 get_asic_rev_ip_params(dc->ctx->asic_id.hw_internal_rev); 2377 2378 DC_LOGGER_INIT(dc->ctx->logger); 2379 2380 if (pool->base.pp_smu) { 2381 struct pp_smu_nv_clock_table max_clocks = {0}; 2382 unsigned int uclk_states[8] = {0}; 2383 unsigned int num_states = 0; 2384 enum pp_smu_status status; 2385 bool clock_limits_available = false; 2386 bool uclk_states_available = false; 2387 2388 if (pool->base.pp_smu->nv_funcs.get_uclk_dpm_states) { 2389 status = (pool->base.pp_smu->nv_funcs.get_uclk_dpm_states) 2390 (&pool->base.pp_smu->nv_funcs.pp_smu, uclk_states, &num_states); 2391 2392 uclk_states_available = (status == PP_SMU_RESULT_OK); 2393 } 2394 2395 if (pool->base.pp_smu->nv_funcs.get_maximum_sustainable_clocks) { 2396 status = (*pool->base.pp_smu->nv_funcs.get_maximum_sustainable_clocks) 2397 (&pool->base.pp_smu->nv_funcs.pp_smu, &max_clocks); 2398 /* SMU cannot set DCF clock to anything equal to or higher than SOC clock 2399 */ 2400 if (max_clocks.dcfClockInKhz >= max_clocks.socClockInKhz) 2401 max_clocks.dcfClockInKhz = max_clocks.socClockInKhz - 1000; 2402 clock_limits_available = (status == PP_SMU_RESULT_OK); 2403 } 2404 2405 if (clock_limits_available && uclk_states_available && num_states) { 2406 DC_FP_START(); 2407 dcn20_update_bounding_box(dc, loaded_bb, &max_clocks, uclk_states, num_states); 2408 DC_FP_END(); 2409 } else if (clock_limits_available) { 2410 DC_FP_START(); 2411 dcn20_cap_soc_clocks(loaded_bb, max_clocks); 2412 DC_FP_END(); 2413 } 2414 } 2415 2416 loaded_ip->max_num_otg = pool->base.res_cap->num_timing_generator; 2417 loaded_ip->max_num_dpp = pool->base.pipe_count; 2418 DC_FP_START(); 2419 dcn20_patch_bounding_box(dc, loaded_bb); 2420 DC_FP_END(); 2421 return true; 2422 } 2423 2424 static bool dcn20_resource_construct( 2425 uint8_t num_virtual_links, 2426 struct dc *dc, 2427 struct dcn20_resource_pool *pool) 2428 { 2429 int i; 2430 struct dc_context *ctx = dc->ctx; 2431 struct irq_service_init_data init_data; 2432 struct ddc_service_init_data ddc_init_data = {0}; 2433 struct _vcs_dpi_soc_bounding_box_st *loaded_bb = 2434 get_asic_rev_soc_bb(ctx->asic_id.hw_internal_rev); 2435 struct _vcs_dpi_ip_params_st *loaded_ip = 2436 get_asic_rev_ip_params(ctx->asic_id.hw_internal_rev); 2437 enum dml_project dml_project_version = 2438 get_dml_project_version(ctx->asic_id.hw_internal_rev); 2439 2440 ctx->dc_bios->regs = &bios_regs; 2441 pool->base.funcs = &dcn20_res_pool_funcs; 2442 2443 if (ASICREV_IS_NAVI14_M(ctx->asic_id.hw_internal_rev)) { 2444 pool->base.res_cap = &res_cap_nv14; 2445 pool->base.pipe_count = 5; 2446 pool->base.mpcc_count = 5; 2447 } else { 2448 pool->base.res_cap = &res_cap_nv10; 2449 pool->base.pipe_count = 6; 2450 pool->base.mpcc_count = 6; 2451 } 2452 /************************************************* 2453 * Resource + asic cap harcoding * 2454 *************************************************/ 2455 pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE; 2456 2457 dc->caps.max_downscale_ratio = 200; 2458 dc->caps.i2c_speed_in_khz = 100; 2459 dc->caps.i2c_speed_in_khz_hdcp = 100; /*1.4 w/a not applied by default*/ 2460 dc->caps.max_cursor_size = 256; 2461 dc->caps.min_horizontal_blanking_period = 80; 2462 dc->caps.dmdata_alloc_size = 2048; 2463 2464 dc->caps.max_slave_planes = 1; 2465 dc->caps.max_slave_yuv_planes = 1; 2466 dc->caps.max_slave_rgb_planes = 1; 2467 dc->caps.post_blend_color_processing = true; 2468 dc->caps.force_dp_tps4_for_cp2520 = true; 2469 dc->caps.extended_aux_timeout_support = true; 2470 dc->caps.dmcub_support = true; 2471 2472 /* Color pipeline capabilities */ 2473 dc->caps.color.dpp.dcn_arch = 1; 2474 dc->caps.color.dpp.input_lut_shared = 0; 2475 dc->caps.color.dpp.icsc = 1; 2476 dc->caps.color.dpp.dgam_ram = 1; 2477 dc->caps.color.dpp.dgam_rom_caps.srgb = 1; 2478 dc->caps.color.dpp.dgam_rom_caps.bt2020 = 1; 2479 dc->caps.color.dpp.dgam_rom_caps.gamma2_2 = 0; 2480 dc->caps.color.dpp.dgam_rom_caps.pq = 0; 2481 dc->caps.color.dpp.dgam_rom_caps.hlg = 0; 2482 dc->caps.color.dpp.post_csc = 0; 2483 dc->caps.color.dpp.gamma_corr = 0; 2484 dc->caps.color.dpp.dgam_rom_for_yuv = 1; 2485 2486 dc->caps.color.dpp.hw_3d_lut = 1; 2487 dc->caps.color.dpp.ogam_ram = 1; 2488 // no OGAM ROM on DCN2, only MPC ROM 2489 dc->caps.color.dpp.ogam_rom_caps.srgb = 0; 2490 dc->caps.color.dpp.ogam_rom_caps.bt2020 = 0; 2491 dc->caps.color.dpp.ogam_rom_caps.gamma2_2 = 0; 2492 dc->caps.color.dpp.ogam_rom_caps.pq = 0; 2493 dc->caps.color.dpp.ogam_rom_caps.hlg = 0; 2494 dc->caps.color.dpp.ocsc = 0; 2495 2496 dc->caps.color.mpc.gamut_remap = 0; 2497 dc->caps.color.mpc.num_3dluts = 0; 2498 dc->caps.color.mpc.shared_3d_lut = 0; 2499 dc->caps.color.mpc.ogam_ram = 1; 2500 dc->caps.color.mpc.ogam_rom_caps.srgb = 0; 2501 dc->caps.color.mpc.ogam_rom_caps.bt2020 = 0; 2502 dc->caps.color.mpc.ogam_rom_caps.gamma2_2 = 0; 2503 dc->caps.color.mpc.ogam_rom_caps.pq = 0; 2504 dc->caps.color.mpc.ogam_rom_caps.hlg = 0; 2505 dc->caps.color.mpc.ocsc = 1; 2506 2507 dc->caps.dp_hdmi21_pcon_support = true; 2508 dc->check_config = config_defaults; 2509 2510 if (dc->ctx->dce_environment == DCE_ENV_PRODUCTION_DRV) 2511 dc->debug = debug_defaults_drv; 2512 2513 //dcn2.0x 2514 dc->work_arounds.dedcn20_305_wa = true; 2515 2516 // Init the vm_helper 2517 if (dc->vm_helper) 2518 vm_helper_init(dc->vm_helper, 16); 2519 2520 /************************************************* 2521 * Create resources * 2522 *************************************************/ 2523 2524 pool->base.clock_sources[DCN20_CLK_SRC_PLL0] = 2525 dcn20_clock_source_create(ctx, ctx->dc_bios, 2526 CLOCK_SOURCE_COMBO_PHY_PLL0, 2527 &clk_src_regs[0], false); 2528 pool->base.clock_sources[DCN20_CLK_SRC_PLL1] = 2529 dcn20_clock_source_create(ctx, ctx->dc_bios, 2530 CLOCK_SOURCE_COMBO_PHY_PLL1, 2531 &clk_src_regs[1], false); 2532 pool->base.clock_sources[DCN20_CLK_SRC_PLL2] = 2533 dcn20_clock_source_create(ctx, ctx->dc_bios, 2534 CLOCK_SOURCE_COMBO_PHY_PLL2, 2535 &clk_src_regs[2], false); 2536 pool->base.clock_sources[DCN20_CLK_SRC_PLL3] = 2537 dcn20_clock_source_create(ctx, ctx->dc_bios, 2538 CLOCK_SOURCE_COMBO_PHY_PLL3, 2539 &clk_src_regs[3], false); 2540 pool->base.clock_sources[DCN20_CLK_SRC_PLL4] = 2541 dcn20_clock_source_create(ctx, ctx->dc_bios, 2542 CLOCK_SOURCE_COMBO_PHY_PLL4, 2543 &clk_src_regs[4], false); 2544 pool->base.clock_sources[DCN20_CLK_SRC_PLL5] = 2545 dcn20_clock_source_create(ctx, ctx->dc_bios, 2546 CLOCK_SOURCE_COMBO_PHY_PLL5, 2547 &clk_src_regs[5], false); 2548 pool->base.clk_src_count = DCN20_CLK_SRC_TOTAL; 2549 /* todo: not reuse phy_pll registers */ 2550 pool->base.dp_clock_source = 2551 dcn20_clock_source_create(ctx, ctx->dc_bios, 2552 CLOCK_SOURCE_ID_DP_DTO, 2553 &clk_src_regs[0], true); 2554 2555 for (i = 0; i < pool->base.clk_src_count; i++) { 2556 if (pool->base.clock_sources[i] == NULL) { 2557 dm_error("DC: failed to create clock sources!\n"); 2558 BREAK_TO_DEBUGGER(); 2559 goto create_fail; 2560 } 2561 } 2562 2563 pool->base.dccg = dccg2_create(ctx, &dccg_regs, &dccg_shift, &dccg_mask); 2564 if (pool->base.dccg == NULL) { 2565 dm_error("DC: failed to create dccg!\n"); 2566 BREAK_TO_DEBUGGER(); 2567 goto create_fail; 2568 } 2569 2570 pool->base.dmcu = dcn20_dmcu_create(ctx, 2571 &dmcu_regs, 2572 &dmcu_shift, 2573 &dmcu_mask); 2574 if (pool->base.dmcu == NULL) { 2575 dm_error("DC: failed to create dmcu!\n"); 2576 BREAK_TO_DEBUGGER(); 2577 goto create_fail; 2578 } 2579 2580 pool->base.abm = dce_abm_create(ctx, 2581 &abm_regs, 2582 &abm_shift, 2583 &abm_mask); 2584 if (pool->base.abm == NULL) { 2585 dm_error("DC: failed to create abm!\n"); 2586 BREAK_TO_DEBUGGER(); 2587 goto create_fail; 2588 } 2589 2590 pool->base.pp_smu = dcn20_pp_smu_create(ctx); 2591 2592 2593 if (!init_soc_bounding_box(dc, pool)) { 2594 dm_error("DC: failed to initialize soc bounding box!\n"); 2595 BREAK_TO_DEBUGGER(); 2596 goto create_fail; 2597 } 2598 2599 dml_init_instance(&dc->dml, loaded_bb, loaded_ip, dml_project_version); 2600 2601 if (!dc->debug.disable_pplib_wm_range) { 2602 struct pp_smu_wm_range_sets ranges = {0}; 2603 int i = 0; 2604 2605 ranges.num_reader_wm_sets = 0; 2606 2607 if (loaded_bb->num_states == 1) { 2608 ranges.reader_wm_sets[0].wm_inst = i; 2609 ranges.reader_wm_sets[0].min_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN; 2610 ranges.reader_wm_sets[0].max_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX; 2611 ranges.reader_wm_sets[0].min_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN; 2612 ranges.reader_wm_sets[0].max_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX; 2613 2614 ranges.num_reader_wm_sets = 1; 2615 } else if (loaded_bb->num_states > 1) { 2616 for (i = 0; i < 4 && i < loaded_bb->num_states; i++) { 2617 ranges.reader_wm_sets[i].wm_inst = i; 2618 ranges.reader_wm_sets[i].min_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN; 2619 ranges.reader_wm_sets[i].max_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX; 2620 DC_FP_START(); 2621 dcn20_fpu_set_wm_ranges(i, &ranges, loaded_bb); 2622 DC_FP_END(); 2623 2624 ranges.num_reader_wm_sets = i + 1; 2625 } 2626 2627 ranges.reader_wm_sets[0].min_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN; 2628 ranges.reader_wm_sets[ranges.num_reader_wm_sets - 1].max_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX; 2629 } 2630 2631 ranges.num_writer_wm_sets = 1; 2632 2633 ranges.writer_wm_sets[0].wm_inst = 0; 2634 ranges.writer_wm_sets[0].min_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN; 2635 ranges.writer_wm_sets[0].max_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX; 2636 ranges.writer_wm_sets[0].min_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN; 2637 ranges.writer_wm_sets[0].max_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX; 2638 2639 /* Notify PP Lib/SMU which Watermarks to use for which clock ranges */ 2640 if (pool->base.pp_smu && pool->base.pp_smu->nv_funcs.set_wm_ranges) 2641 pool->base.pp_smu->nv_funcs.set_wm_ranges(&pool->base.pp_smu->nv_funcs.pp_smu, &ranges); 2642 } 2643 2644 init_data.ctx = dc->ctx; 2645 pool->base.irqs = dal_irq_service_dcn20_create(&init_data); 2646 if (!pool->base.irqs) 2647 goto create_fail; 2648 2649 /* mem input -> ipp -> dpp -> opp -> TG */ 2650 for (i = 0; i < pool->base.pipe_count; i++) { 2651 pool->base.hubps[i] = dcn20_hubp_create(ctx, i); 2652 if (pool->base.hubps[i] == NULL) { 2653 BREAK_TO_DEBUGGER(); 2654 dm_error( 2655 "DC: failed to create memory input!\n"); 2656 goto create_fail; 2657 } 2658 2659 pool->base.ipps[i] = dcn20_ipp_create(ctx, i); 2660 if (pool->base.ipps[i] == NULL) { 2661 BREAK_TO_DEBUGGER(); 2662 dm_error( 2663 "DC: failed to create input pixel processor!\n"); 2664 goto create_fail; 2665 } 2666 2667 pool->base.dpps[i] = dcn20_dpp_create(ctx, i); 2668 if (pool->base.dpps[i] == NULL) { 2669 BREAK_TO_DEBUGGER(); 2670 dm_error( 2671 "DC: failed to create dpps!\n"); 2672 goto create_fail; 2673 } 2674 } 2675 for (i = 0; i < pool->base.res_cap->num_ddc; i++) { 2676 pool->base.engines[i] = dcn20_aux_engine_create(ctx, i); 2677 if (pool->base.engines[i] == NULL) { 2678 BREAK_TO_DEBUGGER(); 2679 dm_error( 2680 "DC:failed to create aux engine!!\n"); 2681 goto create_fail; 2682 } 2683 pool->base.hw_i2cs[i] = dcn20_i2c_hw_create(ctx, i); 2684 if (pool->base.hw_i2cs[i] == NULL) { 2685 BREAK_TO_DEBUGGER(); 2686 dm_error( 2687 "DC:failed to create hw i2c!!\n"); 2688 goto create_fail; 2689 } 2690 pool->base.sw_i2cs[i] = NULL; 2691 } 2692 2693 for (i = 0; i < pool->base.res_cap->num_opp; i++) { 2694 pool->base.opps[i] = dcn20_opp_create(ctx, i); 2695 if (pool->base.opps[i] == NULL) { 2696 BREAK_TO_DEBUGGER(); 2697 dm_error( 2698 "DC: failed to create output pixel processor!\n"); 2699 goto create_fail; 2700 } 2701 } 2702 2703 for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) { 2704 pool->base.timing_generators[i] = dcn20_timing_generator_create( 2705 ctx, i); 2706 if (pool->base.timing_generators[i] == NULL) { 2707 BREAK_TO_DEBUGGER(); 2708 dm_error("DC: failed to create tg!\n"); 2709 goto create_fail; 2710 } 2711 } 2712 2713 pool->base.timing_generator_count = i; 2714 2715 pool->base.mpc = dcn20_mpc_create(ctx); 2716 if (pool->base.mpc == NULL) { 2717 BREAK_TO_DEBUGGER(); 2718 dm_error("DC: failed to create mpc!\n"); 2719 goto create_fail; 2720 } 2721 2722 pool->base.hubbub = dcn20_hubbub_create(ctx); 2723 if (pool->base.hubbub == NULL) { 2724 BREAK_TO_DEBUGGER(); 2725 dm_error("DC: failed to create hubbub!\n"); 2726 goto create_fail; 2727 } 2728 2729 /* DIO */ 2730 pool->base.dio = dcn20_dio_create(ctx); 2731 if (pool->base.dio == NULL) { 2732 BREAK_TO_DEBUGGER(); 2733 dm_error("DC: failed to create dio!\n"); 2734 goto create_fail; 2735 } 2736 2737 for (i = 0; i < pool->base.res_cap->num_dsc; i++) { 2738 pool->base.dscs[i] = dcn20_dsc_create(ctx, i); 2739 if (pool->base.dscs[i] == NULL) { 2740 BREAK_TO_DEBUGGER(); 2741 dm_error("DC: failed to create display stream compressor %d!\n", i); 2742 goto create_fail; 2743 } 2744 } 2745 2746 if (!dcn20_dwbc_create(ctx, &pool->base)) { 2747 BREAK_TO_DEBUGGER(); 2748 dm_error("DC: failed to create dwbc!\n"); 2749 goto create_fail; 2750 } 2751 if (!dcn20_mmhubbub_create(ctx, &pool->base)) { 2752 BREAK_TO_DEBUGGER(); 2753 dm_error("DC: failed to create mcif_wb!\n"); 2754 goto create_fail; 2755 } 2756 2757 if (!resource_construct(num_virtual_links, dc, &pool->base, 2758 &res_create_funcs)) 2759 goto create_fail; 2760 2761 dcn20_hw_sequencer_construct(dc); 2762 2763 // IF NV12, set PG function pointer to NULL. It's not that 2764 // PG isn't supported for NV12, it's that we don't want to 2765 // program the registers because that will cause more power 2766 // to be consumed. We could have created dcn20_init_hw to get 2767 // the same effect by checking ASIC rev, but there was a 2768 // request at some point to not check ASIC rev on hw sequencer. 2769 if (ASICREV_IS_NAVI12_P(dc->ctx->asic_id.hw_internal_rev)) { 2770 dc->hwseq->funcs.enable_power_gating_plane = NULL; 2771 dc->debug.disable_dpp_power_gate = true; 2772 dc->debug.disable_hubp_power_gate = true; 2773 } 2774 2775 2776 dc->caps.max_planes = pool->base.pipe_count; 2777 2778 for (i = 0; i < dc->caps.max_planes; ++i) 2779 dc->caps.planes[i] = plane_cap; 2780 2781 dc->caps.max_odm_combine_factor = 2; 2782 2783 dc->cap_funcs = cap_funcs; 2784 2785 if (dc->ctx->dc_bios->fw_info.oem_i2c_present) { 2786 ddc_init_data.ctx = dc->ctx; 2787 ddc_init_data.link = NULL; 2788 ddc_init_data.id.id = dc->ctx->dc_bios->fw_info.oem_i2c_obj_id; 2789 ddc_init_data.id.enum_id = 0; 2790 ddc_init_data.id.type = OBJECT_TYPE_GENERIC; 2791 pool->base.oem_device = dc->link_srv->create_ddc_service(&ddc_init_data); 2792 } else { 2793 pool->base.oem_device = NULL; 2794 } 2795 2796 return true; 2797 2798 create_fail: 2799 2800 dcn20_resource_destruct(pool); 2801 2802 return false; 2803 } 2804 2805 struct resource_pool *dcn20_create_resource_pool( 2806 const struct dc_init_data *init_data, 2807 struct dc *dc) 2808 { 2809 struct dcn20_resource_pool *pool = 2810 kzalloc_obj(struct dcn20_resource_pool); 2811 2812 if (!pool) 2813 return NULL; 2814 2815 if (dcn20_resource_construct(init_data->num_virtual_links, dc, pool)) 2816 return &pool->base; 2817 2818 BREAK_TO_DEBUGGER(); 2819 kfree(pool); 2820 return NULL; 2821 } 2822