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 (void)ctx; 948 struct dcn20_link_encoder *enc20 = 949 kzalloc_obj(struct dcn20_link_encoder); 950 int link_regs_id; 951 952 if (!enc20 || enc_init_data->hpd_source >= ARRAY_SIZE(link_enc_hpd_regs)) 953 return NULL; 954 955 link_regs_id = 956 map_transmitter_id_to_phy_instance(enc_init_data->transmitter); 957 958 dcn20_link_encoder_construct(enc20, 959 enc_init_data, 960 &link_enc_feature, 961 &link_enc_regs[link_regs_id], 962 &link_enc_aux_regs[enc_init_data->channel - 1], 963 &link_enc_hpd_regs[enc_init_data->hpd_source], 964 &le_shift, 965 &le_mask); 966 967 return &enc20->enc10.base; 968 } 969 970 static struct panel_cntl *dcn20_panel_cntl_create(const struct panel_cntl_init_data *init_data) 971 { 972 struct dce_panel_cntl *panel_cntl = 973 kzalloc_obj(struct dce_panel_cntl); 974 975 if (!panel_cntl) 976 return NULL; 977 978 dce_panel_cntl_construct(panel_cntl, 979 init_data, 980 &panel_cntl_regs[init_data->inst], 981 &panel_cntl_shift, 982 &panel_cntl_mask); 983 984 return &panel_cntl->base; 985 } 986 987 static struct clock_source *dcn20_clock_source_create( 988 struct dc_context *ctx, 989 struct dc_bios *bios, 990 enum clock_source_id id, 991 const struct dce110_clk_src_regs *regs, 992 bool dp_clk_src) 993 { 994 struct dce110_clk_src *clk_src = 995 kzalloc_obj(struct dce110_clk_src); 996 997 if (!clk_src) 998 return NULL; 999 1000 if (dcn20_clk_src_construct(clk_src, ctx, bios, id, 1001 regs, &cs_shift, &cs_mask)) { 1002 clk_src->base.dp_clk_src = dp_clk_src; 1003 return &clk_src->base; 1004 } 1005 1006 kfree(clk_src); 1007 BREAK_TO_DEBUGGER(); 1008 return NULL; 1009 } 1010 1011 static void read_dce_straps( 1012 struct dc_context *ctx, 1013 struct resource_straps *straps) 1014 { 1015 generic_reg_get(ctx, mmDC_PINSTRAPS + BASE(mmDC_PINSTRAPS_BASE_IDX), 1016 FN(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO), &straps->dc_pinstraps_audio); 1017 } 1018 1019 static struct audio *dcn20_create_audio( 1020 struct dc_context *ctx, unsigned int inst) 1021 { 1022 return dce_audio_create(ctx, inst, 1023 &audio_regs[inst], &audio_shift, &audio_mask); 1024 } 1025 1026 struct stream_encoder *dcn20_stream_encoder_create( 1027 enum engine_id eng_id, 1028 struct dc_context *ctx) 1029 { 1030 struct dcn10_stream_encoder *enc1 = 1031 kzalloc_obj(struct dcn10_stream_encoder); 1032 1033 if (!enc1) 1034 return NULL; 1035 1036 if (ASICREV_IS_NAVI14_M(ctx->asic_id.hw_internal_rev)) { 1037 if (eng_id >= ENGINE_ID_DIGD) 1038 eng_id++; 1039 } 1040 1041 dcn20_stream_encoder_construct(enc1, ctx, ctx->dc_bios, eng_id, 1042 &stream_enc_regs[eng_id], 1043 &se_shift, &se_mask); 1044 1045 return &enc1->base; 1046 } 1047 1048 static const struct dce_hwseq_registers hwseq_reg = { 1049 HWSEQ_DCN2_REG_LIST() 1050 }; 1051 1052 static const struct dce_hwseq_shift hwseq_shift = { 1053 HWSEQ_DCN2_MASK_SH_LIST(__SHIFT) 1054 }; 1055 1056 static const struct dce_hwseq_mask hwseq_mask = { 1057 HWSEQ_DCN2_MASK_SH_LIST(_MASK) 1058 }; 1059 1060 struct dce_hwseq *dcn20_hwseq_create( 1061 struct dc_context *ctx) 1062 { 1063 struct dce_hwseq *hws = kzalloc_obj(struct dce_hwseq); 1064 1065 if (hws) { 1066 hws->ctx = ctx; 1067 hws->regs = &hwseq_reg; 1068 hws->shifts = &hwseq_shift; 1069 hws->masks = &hwseq_mask; 1070 } 1071 return hws; 1072 } 1073 1074 static const struct resource_create_funcs res_create_funcs = { 1075 .read_dce_straps = read_dce_straps, 1076 .create_audio = dcn20_create_audio, 1077 .create_stream_encoder = dcn20_stream_encoder_create, 1078 .create_hwseq = dcn20_hwseq_create, 1079 }; 1080 1081 static void dcn20_pp_smu_destroy(struct pp_smu_funcs **pp_smu); 1082 1083 void dcn20_clock_source_destroy(struct clock_source **clk_src) 1084 { 1085 kfree(TO_DCE110_CLK_SRC(*clk_src)); 1086 *clk_src = NULL; 1087 } 1088 1089 1090 struct display_stream_compressor *dcn20_dsc_create( 1091 struct dc_context *ctx, uint32_t inst) 1092 { 1093 struct dcn20_dsc *dsc = 1094 kzalloc_obj(struct dcn20_dsc); 1095 1096 if (!dsc) { 1097 BREAK_TO_DEBUGGER(); 1098 return NULL; 1099 } 1100 1101 dsc2_construct(dsc, ctx, inst, &dsc_regs[inst], &dsc_shift, &dsc_mask); 1102 return &dsc->base; 1103 } 1104 1105 void dcn20_dsc_destroy(struct display_stream_compressor **dsc) 1106 { 1107 kfree(container_of(*dsc, struct dcn20_dsc, base)); 1108 *dsc = NULL; 1109 } 1110 1111 1112 static void dcn20_resource_destruct(struct dcn20_resource_pool *pool) 1113 { 1114 unsigned int i; 1115 1116 for (i = 0; i < pool->base.stream_enc_count; i++) { 1117 if (pool->base.stream_enc[i] != NULL) { 1118 kfree(DCN10STRENC_FROM_STRENC(pool->base.stream_enc[i])); 1119 pool->base.stream_enc[i] = NULL; 1120 } 1121 } 1122 1123 for (i = 0; i < (unsigned int)pool->base.res_cap->num_dsc; i++) { 1124 if (pool->base.dscs[i] != NULL) 1125 dcn20_dsc_destroy(&pool->base.dscs[i]); 1126 } 1127 1128 if (pool->base.mpc != NULL) { 1129 kfree(TO_DCN20_MPC(pool->base.mpc)); 1130 pool->base.mpc = NULL; 1131 } 1132 if (pool->base.hubbub != NULL) { 1133 kfree(pool->base.hubbub); 1134 pool->base.hubbub = NULL; 1135 } 1136 1137 if (pool->base.dio != NULL) { 1138 kfree(TO_DCN10_DIO(pool->base.dio)); 1139 pool->base.dio = NULL; 1140 } 1141 1142 for (i = 0; i < pool->base.pipe_count; i++) { 1143 if (pool->base.dpps[i] != NULL) 1144 dcn20_dpp_destroy(&pool->base.dpps[i]); 1145 1146 if (pool->base.ipps[i] != NULL) 1147 pool->base.ipps[i]->funcs->ipp_destroy(&pool->base.ipps[i]); 1148 1149 if (pool->base.hubps[i] != NULL) { 1150 kfree(TO_DCN20_HUBP(pool->base.hubps[i])); 1151 pool->base.hubps[i] = NULL; 1152 } 1153 1154 if (pool->base.irqs != NULL) { 1155 dal_irq_service_destroy(&pool->base.irqs); 1156 } 1157 } 1158 1159 for (i = 0; i < (unsigned int)pool->base.res_cap->num_ddc; i++) { 1160 if (pool->base.engines[i] != NULL) 1161 dce110_engine_destroy(&pool->base.engines[i]); 1162 if (pool->base.hw_i2cs[i] != NULL) { 1163 kfree(pool->base.hw_i2cs[i]); 1164 pool->base.hw_i2cs[i] = NULL; 1165 } 1166 if (pool->base.sw_i2cs[i] != NULL) { 1167 kfree(pool->base.sw_i2cs[i]); 1168 pool->base.sw_i2cs[i] = NULL; 1169 } 1170 } 1171 1172 for (i = 0; i < (unsigned int)pool->base.res_cap->num_opp; i++) { 1173 if (pool->base.opps[i] != NULL) 1174 pool->base.opps[i]->funcs->opp_destroy(&pool->base.opps[i]); 1175 } 1176 1177 for (i = 0; i < (unsigned int)pool->base.res_cap->num_timing_generator; i++) { 1178 if (pool->base.timing_generators[i] != NULL) { 1179 kfree(DCN10TG_FROM_TG(pool->base.timing_generators[i])); 1180 pool->base.timing_generators[i] = NULL; 1181 } 1182 } 1183 1184 for (i = 0; i < (unsigned int)pool->base.res_cap->num_dwb; i++) { 1185 if (pool->base.dwbc[i] != NULL) { 1186 kfree(TO_DCN20_DWBC(pool->base.dwbc[i])); 1187 pool->base.dwbc[i] = NULL; 1188 } 1189 if (pool->base.mcif_wb[i] != NULL) { 1190 kfree(TO_DCN20_MMHUBBUB(pool->base.mcif_wb[i])); 1191 pool->base.mcif_wb[i] = NULL; 1192 } 1193 } 1194 1195 for (i = 0; i < pool->base.audio_count; i++) { 1196 if (pool->base.audios[i]) 1197 dce_aud_destroy(&pool->base.audios[i]); 1198 } 1199 1200 for (i = 0; i < pool->base.clk_src_count; i++) { 1201 if (pool->base.clock_sources[i] != NULL) { 1202 dcn20_clock_source_destroy(&pool->base.clock_sources[i]); 1203 pool->base.clock_sources[i] = NULL; 1204 } 1205 } 1206 1207 if (pool->base.dp_clock_source != NULL) { 1208 dcn20_clock_source_destroy(&pool->base.dp_clock_source); 1209 pool->base.dp_clock_source = NULL; 1210 } 1211 1212 1213 if (pool->base.abm != NULL) 1214 dce_abm_destroy(&pool->base.abm); 1215 1216 if (pool->base.dmcu != NULL) 1217 dce_dmcu_destroy(&pool->base.dmcu); 1218 1219 if (pool->base.dccg != NULL) 1220 dcn_dccg_destroy(&pool->base.dccg); 1221 1222 if (pool->base.pp_smu != NULL) 1223 dcn20_pp_smu_destroy(&pool->base.pp_smu); 1224 1225 if (pool->base.oem_device != NULL) { 1226 struct dc *dc = pool->base.oem_device->ctx->dc; 1227 1228 dc->link_srv->destroy_ddc_service(&pool->base.oem_device); 1229 } 1230 } 1231 1232 struct hubp *dcn20_hubp_create( 1233 struct dc_context *ctx, 1234 uint32_t inst) 1235 { 1236 struct dcn20_hubp *hubp2 = 1237 kzalloc_obj(struct dcn20_hubp); 1238 1239 if (!hubp2) 1240 return NULL; 1241 1242 if (hubp2_construct(hubp2, ctx, inst, 1243 &hubp_regs[inst], &hubp_shift, &hubp_mask)) 1244 return &hubp2->base; 1245 1246 BREAK_TO_DEBUGGER(); 1247 kfree(hubp2); 1248 return NULL; 1249 } 1250 1251 static void get_pixel_clock_parameters( 1252 struct pipe_ctx *pipe_ctx, 1253 struct pixel_clk_params *pixel_clk_params) 1254 { 1255 const struct dc_stream_state *stream = pipe_ctx->stream; 1256 struct pipe_ctx *odm_pipe; 1257 int opp_cnt = 1; 1258 struct dc_link *link = stream->link; 1259 struct link_encoder *link_enc = pipe_ctx->link_res.dio_link_enc; 1260 struct dc *dc = pipe_ctx->stream->ctx->dc; 1261 struct dce_hwseq *hws = dc->hwseq; 1262 1263 for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe) 1264 opp_cnt++; 1265 1266 pixel_clk_params->requested_pix_clk_100hz = stream->timing.pix_clk_100hz; 1267 1268 if (!dc->config.unify_link_enc_assignment) 1269 link_enc = link_enc_cfg_get_link_enc(link); 1270 if (link_enc) 1271 pixel_clk_params->encoder_object_id = link_enc->id; 1272 1273 pixel_clk_params->signal_type = pipe_ctx->stream->signal; 1274 pixel_clk_params->controller_id = pipe_ctx->stream_res.tg->inst + 1; 1275 /* TODO: un-hardcode*/ 1276 /* TODO - DP2.0 HW: calculate requested_sym_clk for UHBR rates */ 1277 pixel_clk_params->requested_sym_clk = LINK_RATE_LOW * 1278 LINK_RATE_REF_FREQ_IN_KHZ; 1279 pixel_clk_params->flags.ENABLE_SS = 0; 1280 pixel_clk_params->color_depth = 1281 stream->timing.display_color_depth; 1282 pixel_clk_params->flags.DISPLAY_BLANKED = 1; 1283 pixel_clk_params->pixel_encoding = stream->timing.pixel_encoding; 1284 1285 if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR422) 1286 pixel_clk_params->color_depth = COLOR_DEPTH_888; 1287 1288 if (opp_cnt == 4) 1289 pixel_clk_params->requested_pix_clk_100hz /= 4; 1290 else if (pipe_ctx->stream_res.tg->funcs->is_two_pixels_per_container(&stream->timing) || opp_cnt == 2) 1291 pixel_clk_params->requested_pix_clk_100hz /= 2; 1292 else if (hws->funcs.is_dp_dig_pixel_rate_div_policy) { 1293 if (hws->funcs.is_dp_dig_pixel_rate_div_policy(pipe_ctx)) 1294 pixel_clk_params->requested_pix_clk_100hz /= 2; 1295 } 1296 1297 if (stream->timing.timing_3d_format == TIMING_3D_FORMAT_HW_FRAME_PACKING) 1298 pixel_clk_params->requested_pix_clk_100hz *= 2; 1299 1300 if ((pipe_ctx->stream_res.tg->funcs->is_two_pixels_per_container && 1301 pipe_ctx->stream_res.tg->funcs->is_two_pixels_per_container(&pipe_ctx->stream->timing)) || 1302 (hws->funcs.is_dp_dig_pixel_rate_div_policy && 1303 hws->funcs.is_dp_dig_pixel_rate_div_policy(pipe_ctx)) || 1304 opp_cnt > 1) { 1305 pixel_clk_params->dio_se_pix_per_cycle = 2; 1306 } else { 1307 pixel_clk_params->dio_se_pix_per_cycle = 1; 1308 } 1309 } 1310 1311 static void build_clamping_params(struct dc_stream_state *stream) 1312 { 1313 stream->clamping.clamping_level = CLAMPING_FULL_RANGE; 1314 stream->clamping.c_depth = stream->timing.display_color_depth; 1315 stream->clamping.pixel_encoding = stream->timing.pixel_encoding; 1316 } 1317 1318 void dcn20_build_pipe_pix_clk_params(struct pipe_ctx *pipe_ctx) 1319 { 1320 get_pixel_clock_parameters(pipe_ctx, &pipe_ctx->stream_res.pix_clk_params); 1321 pipe_ctx->clock_source->funcs->get_pix_clk_dividers( 1322 pipe_ctx->clock_source, 1323 &pipe_ctx->stream_res.pix_clk_params, 1324 &pipe_ctx->pll_settings); 1325 } 1326 1327 static enum dc_status build_pipe_hw_param(struct pipe_ctx *pipe_ctx) 1328 { 1329 struct resource_pool *pool = pipe_ctx->stream->ctx->dc->res_pool; 1330 1331 if (pool->funcs->build_pipe_pix_clk_params) { 1332 pool->funcs->build_pipe_pix_clk_params(pipe_ctx); 1333 } else { 1334 dcn20_build_pipe_pix_clk_params(pipe_ctx); 1335 } 1336 1337 pipe_ctx->stream->clamping.pixel_encoding = pipe_ctx->stream->timing.pixel_encoding; 1338 1339 resource_build_bit_depth_reduction_params(pipe_ctx->stream, 1340 &pipe_ctx->stream->bit_depth_params); 1341 build_clamping_params(pipe_ctx->stream); 1342 1343 return DC_OK; 1344 } 1345 1346 enum dc_status dcn20_build_mapped_resource(const struct dc *dc, struct dc_state *context, struct dc_stream_state *stream) 1347 { 1348 (void)dc; 1349 enum dc_status status = DC_OK; 1350 struct pipe_ctx *pipe_ctx = resource_get_otg_master_for_stream(&context->res_ctx, stream); 1351 1352 if (!pipe_ctx) 1353 return DC_ERROR_UNEXPECTED; 1354 1355 1356 status = build_pipe_hw_param(pipe_ctx); 1357 1358 return status; 1359 } 1360 1361 1362 void dcn20_acquire_dsc(const struct dc *dc, 1363 struct resource_context *res_ctx, 1364 struct display_stream_compressor **dsc, 1365 int pipe_idx) 1366 { 1367 int i; 1368 const struct resource_pool *pool = dc->res_pool; 1369 struct display_stream_compressor *dsc_old = dc->current_state->res_ctx.pipe_ctx[pipe_idx].stream_res.dsc; 1370 1371 ASSERT(*dsc == NULL); /* If this ASSERT fails, dsc was not released properly */ 1372 *dsc = NULL; 1373 1374 /* Always do 1-to-1 mapping when number of DSCs is same as number of pipes */ 1375 if (pool->res_cap->num_dsc == pool->res_cap->num_opp) { 1376 *dsc = pool->dscs[pipe_idx]; 1377 res_ctx->is_dsc_acquired[pipe_idx] = true; 1378 return; 1379 } 1380 1381 /* Return old DSC to avoid the need for re-programming */ 1382 if (dsc_old && !res_ctx->is_dsc_acquired[dsc_old->inst]) { 1383 *dsc = dsc_old; 1384 res_ctx->is_dsc_acquired[dsc_old->inst] = true; 1385 return ; 1386 } 1387 1388 /* Find first free DSC */ 1389 for (i = 0; i < pool->res_cap->num_dsc; i++) 1390 if (!res_ctx->is_dsc_acquired[i]) { 1391 *dsc = pool->dscs[i]; 1392 res_ctx->is_dsc_acquired[i] = true; 1393 break; 1394 } 1395 } 1396 1397 void dcn20_release_dsc(struct resource_context *res_ctx, 1398 const struct resource_pool *pool, 1399 struct display_stream_compressor **dsc) 1400 { 1401 int i; 1402 1403 for (i = 0; i < pool->res_cap->num_dsc; i++) 1404 if (pool->dscs[i] == *dsc) { 1405 res_ctx->is_dsc_acquired[i] = false; 1406 *dsc = NULL; 1407 break; 1408 } 1409 } 1410 1411 1412 1413 enum dc_status dcn20_add_dsc_to_stream_resource(struct dc *dc, 1414 struct dc_state *dc_ctx, 1415 struct dc_stream_state *dc_stream) 1416 { 1417 enum dc_status result = DC_OK; 1418 unsigned int i; 1419 1420 /* Get a DSC if required and available */ 1421 for (i = 0; i < dc->res_pool->pipe_count; i++) { 1422 struct pipe_ctx *pipe_ctx = &dc_ctx->res_ctx.pipe_ctx[i]; 1423 1424 if (pipe_ctx->top_pipe) 1425 continue; 1426 1427 if (pipe_ctx->stream != dc_stream) 1428 continue; 1429 1430 if (pipe_ctx->stream_res.dsc) 1431 continue; 1432 1433 dcn20_acquire_dsc(dc, &dc_ctx->res_ctx, &pipe_ctx->stream_res.dsc, i); 1434 1435 /* The number of DSCs can be less than the number of pipes */ 1436 if (!pipe_ctx->stream_res.dsc) { 1437 result = DC_NO_DSC_RESOURCE; 1438 } 1439 1440 break; 1441 } 1442 1443 return result; 1444 } 1445 1446 1447 static enum dc_status remove_dsc_from_stream_resource(struct dc *dc, 1448 struct dc_state *new_ctx, 1449 struct dc_stream_state *dc_stream) 1450 { 1451 struct pipe_ctx *pipe_ctx = NULL; 1452 int i; 1453 1454 for (i = 0; i < MAX_PIPES; i++) { 1455 if (new_ctx->res_ctx.pipe_ctx[i].stream == dc_stream && !new_ctx->res_ctx.pipe_ctx[i].top_pipe) { 1456 pipe_ctx = &new_ctx->res_ctx.pipe_ctx[i]; 1457 1458 if (pipe_ctx->stream_res.dsc) 1459 dcn20_release_dsc(&new_ctx->res_ctx, dc->res_pool, &pipe_ctx->stream_res.dsc); 1460 } 1461 } 1462 1463 if (!pipe_ctx) 1464 return DC_ERROR_UNEXPECTED; 1465 else 1466 return DC_OK; 1467 } 1468 1469 1470 enum dc_status dcn20_add_stream_to_ctx(struct dc *dc, struct dc_state *new_ctx, struct dc_stream_state *dc_stream) 1471 { 1472 enum dc_status result = DC_ERROR_UNEXPECTED; 1473 1474 result = resource_map_pool_resources(dc, new_ctx, dc_stream); 1475 1476 if (result == DC_OK) 1477 result = resource_map_phy_clock_resources(dc, new_ctx, dc_stream); 1478 1479 /* Get a DSC if required and available */ 1480 if (result == DC_OK && dc_stream->timing.flags.DSC) 1481 result = dcn20_add_dsc_to_stream_resource(dc, new_ctx, dc_stream); 1482 1483 if (result == DC_OK) 1484 result = dcn20_build_mapped_resource(dc, new_ctx, dc_stream); 1485 1486 return result; 1487 } 1488 1489 1490 enum dc_status dcn20_remove_stream_from_ctx(struct dc *dc, struct dc_state *new_ctx, struct dc_stream_state *dc_stream) 1491 { 1492 enum dc_status result = DC_OK; 1493 1494 result = remove_dsc_from_stream_resource(dc, new_ctx, dc_stream); 1495 1496 return result; 1497 } 1498 1499 /** 1500 * dcn20_split_stream_for_odm - Check if stream can be splited for ODM 1501 * 1502 * @dc: DC object with resource pool info required for pipe split 1503 * @res_ctx: Persistent state of resources 1504 * @prev_odm_pipe: Reference to the previous ODM pipe 1505 * @next_odm_pipe: Reference to the next ODM pipe 1506 * 1507 * This function takes a logically active pipe and a logically free pipe and 1508 * halves all the scaling parameters that need to be halved while populating 1509 * the free pipe with the required resources and configuring the next/previous 1510 * ODM pipe pointers. 1511 * 1512 * Return: 1513 * Return true if split stream for ODM is possible, otherwise, return false. 1514 */ 1515 bool dcn20_split_stream_for_odm( 1516 const struct dc *dc, 1517 struct resource_context *res_ctx, 1518 struct pipe_ctx *prev_odm_pipe, 1519 struct pipe_ctx *next_odm_pipe) 1520 { 1521 int pipe_idx = next_odm_pipe->pipe_idx; 1522 const struct resource_pool *pool = dc->res_pool; 1523 1524 *next_odm_pipe = *prev_odm_pipe; 1525 1526 next_odm_pipe->pipe_idx = (uint8_t)pipe_idx; 1527 next_odm_pipe->plane_res.mi = pool->mis[next_odm_pipe->pipe_idx]; 1528 next_odm_pipe->plane_res.hubp = pool->hubps[next_odm_pipe->pipe_idx]; 1529 next_odm_pipe->plane_res.ipp = pool->ipps[next_odm_pipe->pipe_idx]; 1530 next_odm_pipe->plane_res.xfm = pool->transforms[next_odm_pipe->pipe_idx]; 1531 next_odm_pipe->plane_res.dpp = pool->dpps[next_odm_pipe->pipe_idx]; 1532 next_odm_pipe->plane_res.mpcc_inst = (uint8_t)pool->dpps[next_odm_pipe->pipe_idx]->inst; 1533 next_odm_pipe->stream_res.dsc = NULL; 1534 if (prev_odm_pipe->next_odm_pipe && prev_odm_pipe->next_odm_pipe != next_odm_pipe) { 1535 next_odm_pipe->next_odm_pipe = prev_odm_pipe->next_odm_pipe; 1536 next_odm_pipe->next_odm_pipe->prev_odm_pipe = next_odm_pipe; 1537 } 1538 if (prev_odm_pipe->top_pipe && prev_odm_pipe->top_pipe->next_odm_pipe) { 1539 prev_odm_pipe->top_pipe->next_odm_pipe->bottom_pipe = next_odm_pipe; 1540 next_odm_pipe->top_pipe = prev_odm_pipe->top_pipe->next_odm_pipe; 1541 } 1542 if (prev_odm_pipe->bottom_pipe && prev_odm_pipe->bottom_pipe->next_odm_pipe) { 1543 prev_odm_pipe->bottom_pipe->next_odm_pipe->top_pipe = next_odm_pipe; 1544 next_odm_pipe->bottom_pipe = prev_odm_pipe->bottom_pipe->next_odm_pipe; 1545 } 1546 prev_odm_pipe->next_odm_pipe = next_odm_pipe; 1547 next_odm_pipe->prev_odm_pipe = prev_odm_pipe; 1548 1549 if (prev_odm_pipe->plane_state) { 1550 if (!resource_build_scaling_params(prev_odm_pipe) || 1551 !resource_build_scaling_params(next_odm_pipe)) { 1552 return false; 1553 } 1554 } 1555 1556 if (!next_odm_pipe->top_pipe) 1557 next_odm_pipe->stream_res.opp = pool->opps[next_odm_pipe->pipe_idx]; 1558 else 1559 next_odm_pipe->stream_res.opp = next_odm_pipe->top_pipe->stream_res.opp; 1560 if (next_odm_pipe->stream->timing.flags.DSC == 1 && !next_odm_pipe->top_pipe) { 1561 dcn20_acquire_dsc(dc, res_ctx, &next_odm_pipe->stream_res.dsc, next_odm_pipe->pipe_idx); 1562 ASSERT(next_odm_pipe->stream_res.dsc); 1563 if (next_odm_pipe->stream_res.dsc == NULL) 1564 return false; 1565 } 1566 1567 return true; 1568 } 1569 1570 void dcn20_split_stream_for_mpc( 1571 struct resource_context *res_ctx, 1572 const struct resource_pool *pool, 1573 struct pipe_ctx *primary_pipe, 1574 struct pipe_ctx *secondary_pipe) 1575 { 1576 (void)res_ctx; 1577 int pipe_idx = secondary_pipe->pipe_idx; 1578 struct pipe_ctx *sec_bot_pipe = secondary_pipe->bottom_pipe; 1579 1580 *secondary_pipe = *primary_pipe; 1581 secondary_pipe->bottom_pipe = sec_bot_pipe; 1582 1583 secondary_pipe->pipe_idx = (uint8_t)pipe_idx; 1584 secondary_pipe->plane_res.mi = pool->mis[secondary_pipe->pipe_idx]; 1585 secondary_pipe->plane_res.hubp = pool->hubps[secondary_pipe->pipe_idx]; 1586 secondary_pipe->plane_res.ipp = pool->ipps[secondary_pipe->pipe_idx]; 1587 secondary_pipe->plane_res.xfm = pool->transforms[secondary_pipe->pipe_idx]; 1588 secondary_pipe->plane_res.dpp = pool->dpps[secondary_pipe->pipe_idx]; 1589 secondary_pipe->plane_res.mpcc_inst = (uint8_t)pool->dpps[secondary_pipe->pipe_idx]->inst; 1590 secondary_pipe->stream_res.dsc = NULL; 1591 if (primary_pipe->bottom_pipe && primary_pipe->bottom_pipe != secondary_pipe) { 1592 ASSERT(!secondary_pipe->bottom_pipe); 1593 secondary_pipe->bottom_pipe = primary_pipe->bottom_pipe; 1594 secondary_pipe->bottom_pipe->top_pipe = secondary_pipe; 1595 } 1596 primary_pipe->bottom_pipe = secondary_pipe; 1597 secondary_pipe->top_pipe = primary_pipe; 1598 1599 ASSERT(primary_pipe->plane_state); 1600 } 1601 1602 unsigned int dcn20_calc_max_scaled_time( 1603 unsigned int time_per_pixel, 1604 enum mmhubbub_wbif_mode mode, 1605 unsigned int urgent_watermark) 1606 { 1607 unsigned int time_per_byte = 0; 1608 unsigned int total_y_free_entry = 0x200; /* two memory piece for luma */ 1609 unsigned int total_c_free_entry = 0x140; /* two memory piece for chroma */ 1610 unsigned int small_free_entry, max_free_entry; 1611 unsigned int buf_lh_capability; 1612 unsigned int max_scaled_time; 1613 1614 if (mode == PACKED_444) /* packed mode */ 1615 time_per_byte = time_per_pixel/4; 1616 else if (mode == PLANAR_420_8BPC) 1617 time_per_byte = time_per_pixel; 1618 else if (mode == PLANAR_420_10BPC) /* p010 */ 1619 time_per_byte = time_per_pixel * 819/1024; 1620 1621 if (time_per_byte == 0) 1622 time_per_byte = 1; 1623 1624 small_free_entry = total_c_free_entry; 1625 max_free_entry = (mode == PACKED_444) ? total_y_free_entry + total_c_free_entry : small_free_entry; 1626 buf_lh_capability = max_free_entry*time_per_byte*32/16; /* there is 4bit fraction */ 1627 max_scaled_time = buf_lh_capability - urgent_watermark; 1628 return max_scaled_time; 1629 } 1630 1631 void dcn20_set_mcif_arb_params( 1632 struct dc *dc, 1633 struct dc_state *context, 1634 display_e2e_pipe_params_st *pipes, 1635 int pipe_cnt) 1636 { 1637 enum mmhubbub_wbif_mode wbif_mode; 1638 struct mcif_arb_params *wb_arb_params; 1639 int j, dwb_pipe; 1640 unsigned int i; 1641 1642 /* Writeback MCIF_WB arbitration parameters */ 1643 dwb_pipe = 0; 1644 for (i = 0; i < dc->res_pool->pipe_count; i++) { 1645 1646 if (!context->res_ctx.pipe_ctx[i].stream) 1647 continue; 1648 1649 for (j = 0; j < MAX_DWB_PIPES; j++) { 1650 if (context->res_ctx.pipe_ctx[i].stream->writeback_info[j].wb_enabled == false) 1651 continue; 1652 1653 //wb_arb_params = &context->res_ctx.pipe_ctx[i].stream->writeback_info[j].mcif_arb_params; 1654 wb_arb_params = &context->bw_ctx.bw.dcn.bw_writeback.mcif_wb_arb[dwb_pipe]; 1655 1656 if (context->res_ctx.pipe_ctx[i].stream->writeback_info[j].dwb_params.out_format == dwb_scaler_mode_yuv420) { 1657 if (context->res_ctx.pipe_ctx[i].stream->writeback_info[j].dwb_params.output_depth == DWB_OUTPUT_PIXEL_DEPTH_8BPC) 1658 wbif_mode = PLANAR_420_8BPC; 1659 else 1660 wbif_mode = PLANAR_420_10BPC; 1661 } else 1662 wbif_mode = PACKED_444; 1663 1664 DC_FP_START(); 1665 dcn20_fpu_set_wb_arb_params(wb_arb_params, context, pipes, pipe_cnt, i); 1666 DC_FP_END(); 1667 1668 wb_arb_params->slice_lines = 32; 1669 wb_arb_params->arbitration_slice = 2; 1670 wb_arb_params->max_scaled_time = dcn20_calc_max_scaled_time(wb_arb_params->time_per_pixel, 1671 wbif_mode, 1672 wb_arb_params->cli_watermark[0]); /* assume 4 watermark sets have the same value */ 1673 1674 dwb_pipe++; 1675 1676 if (dwb_pipe >= MAX_DWB_PIPES) 1677 return; 1678 } 1679 } 1680 } 1681 1682 bool dcn20_validate_dsc(struct dc *dc, struct dc_state *new_ctx) 1683 { 1684 unsigned int i; 1685 1686 /* Validate DSC config, dsc count validation is already done */ 1687 for (i = 0; i < dc->res_pool->pipe_count; i++) { 1688 struct pipe_ctx *pipe_ctx = &new_ctx->res_ctx.pipe_ctx[i]; 1689 struct dc_stream_state *stream = pipe_ctx->stream; 1690 struct dsc_config dsc_cfg; 1691 struct pipe_ctx *odm_pipe; 1692 int opp_cnt = 1; 1693 1694 for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe) 1695 opp_cnt++; 1696 1697 /* Only need to validate top pipe */ 1698 if (pipe_ctx->top_pipe || pipe_ctx->prev_odm_pipe || !stream || !stream->timing.flags.DSC) 1699 continue; 1700 1701 dsc_cfg.pic_width = (stream->timing.h_addressable + pipe_ctx->dsc_padding_params.dsc_hactive_padding 1702 + stream->timing.h_border_left + stream->timing.h_border_right) / opp_cnt; 1703 dsc_cfg.pic_height = stream->timing.v_addressable + stream->timing.v_border_top 1704 + stream->timing.v_border_bottom; 1705 dsc_cfg.pixel_encoding = stream->timing.pixel_encoding; 1706 dsc_cfg.color_depth = stream->timing.display_color_depth; 1707 dsc_cfg.is_odm = pipe_ctx->next_odm_pipe ? true : false; 1708 dsc_cfg.dc_dsc_cfg = stream->timing.dsc_cfg; 1709 dsc_cfg.dc_dsc_cfg.num_slices_h /= opp_cnt; 1710 dsc_cfg.dsc_padding = 0; 1711 1712 if (!pipe_ctx->stream_res.dsc->funcs->dsc_validate_stream(pipe_ctx->stream_res.dsc, &dsc_cfg)) 1713 return false; 1714 } 1715 return true; 1716 } 1717 1718 struct pipe_ctx *dcn20_find_secondary_pipe(struct dc *dc, 1719 struct resource_context *res_ctx, 1720 const struct resource_pool *pool, 1721 const struct pipe_ctx *primary_pipe) 1722 { 1723 (void)pool; 1724 struct pipe_ctx *secondary_pipe = NULL; 1725 1726 if (dc && primary_pipe) { 1727 int j; 1728 int preferred_pipe_idx = 0; 1729 1730 /* first check the prev dc state: 1731 * if this primary pipe has a bottom pipe in prev. state 1732 * and if the bottom pipe is still available (which it should be), 1733 * pick that pipe as secondary 1734 * Same logic applies for ODM pipes 1735 */ 1736 if (dc->current_state->res_ctx.pipe_ctx[primary_pipe->pipe_idx].next_odm_pipe) { 1737 preferred_pipe_idx = dc->current_state->res_ctx.pipe_ctx[primary_pipe->pipe_idx].next_odm_pipe->pipe_idx; 1738 if (res_ctx->pipe_ctx[preferred_pipe_idx].stream == NULL) { 1739 secondary_pipe = &res_ctx->pipe_ctx[preferred_pipe_idx]; 1740 secondary_pipe->pipe_idx = (uint8_t)preferred_pipe_idx; 1741 } 1742 } 1743 if (secondary_pipe == NULL && 1744 dc->current_state->res_ctx.pipe_ctx[primary_pipe->pipe_idx].bottom_pipe) { 1745 preferred_pipe_idx = dc->current_state->res_ctx.pipe_ctx[primary_pipe->pipe_idx].bottom_pipe->pipe_idx; 1746 if (res_ctx->pipe_ctx[preferred_pipe_idx].stream == NULL) { 1747 secondary_pipe = &res_ctx->pipe_ctx[preferred_pipe_idx]; 1748 secondary_pipe->pipe_idx = (uint8_t)preferred_pipe_idx; 1749 } 1750 } 1751 1752 /* 1753 * if this primary pipe does not have a bottom pipe in prev. state 1754 * start backward and find a pipe that did not used to be a bottom pipe in 1755 * prev. dc state. This way we make sure we keep the same assignment as 1756 * last state and will not have to reprogram every pipe 1757 */ 1758 if (secondary_pipe == NULL) { 1759 for (j = dc->res_pool->pipe_count - 1; j >= 0; j--) { 1760 if (dc->current_state->res_ctx.pipe_ctx[j].top_pipe == NULL 1761 && dc->current_state->res_ctx.pipe_ctx[j].prev_odm_pipe == NULL) { 1762 preferred_pipe_idx = j; 1763 1764 if (res_ctx->pipe_ctx[preferred_pipe_idx].stream == NULL) { 1765 secondary_pipe = &res_ctx->pipe_ctx[preferred_pipe_idx]; 1766 secondary_pipe->pipe_idx = (uint8_t)preferred_pipe_idx; 1767 break; 1768 } 1769 } 1770 } 1771 } 1772 /* 1773 * We should never hit this assert unless assignments are shuffled around 1774 * if this happens we will prob. hit a vsync tdr 1775 */ 1776 ASSERT(secondary_pipe); 1777 /* 1778 * search backwards for the second pipe to keep pipe 1779 * assignment more consistent 1780 */ 1781 if (secondary_pipe == NULL) { 1782 for (j = dc->res_pool->pipe_count - 1; j >= 0; j--) { 1783 preferred_pipe_idx = j; 1784 1785 if (res_ctx->pipe_ctx[preferred_pipe_idx].stream == NULL) { 1786 secondary_pipe = &res_ctx->pipe_ctx[preferred_pipe_idx]; 1787 secondary_pipe->pipe_idx = (uint8_t)preferred_pipe_idx; 1788 break; 1789 } 1790 } 1791 } 1792 } 1793 1794 return secondary_pipe; 1795 } 1796 1797 void dcn20_merge_pipes_for_validate( 1798 struct dc *dc, 1799 struct dc_state *context) 1800 { 1801 unsigned int i; 1802 1803 /* merge previously split odm pipes since mode support needs to make the decision */ 1804 for (i = 0; i < dc->res_pool->pipe_count; i++) { 1805 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 1806 struct pipe_ctx *odm_pipe = pipe->next_odm_pipe; 1807 1808 if (pipe->prev_odm_pipe) 1809 continue; 1810 1811 pipe->next_odm_pipe = NULL; 1812 while (odm_pipe) { 1813 struct pipe_ctx *next_odm_pipe = odm_pipe->next_odm_pipe; 1814 1815 odm_pipe->plane_state = NULL; 1816 odm_pipe->stream = NULL; 1817 odm_pipe->top_pipe = NULL; 1818 odm_pipe->bottom_pipe = NULL; 1819 odm_pipe->prev_odm_pipe = NULL; 1820 odm_pipe->next_odm_pipe = NULL; 1821 if (odm_pipe->stream_res.dsc) 1822 dcn20_release_dsc(&context->res_ctx, dc->res_pool, &odm_pipe->stream_res.dsc); 1823 /* Clear plane_res and stream_res */ 1824 memset(&odm_pipe->plane_res, 0, sizeof(odm_pipe->plane_res)); 1825 memset(&odm_pipe->stream_res, 0, sizeof(odm_pipe->stream_res)); 1826 odm_pipe = next_odm_pipe; 1827 } 1828 if (pipe->plane_state) 1829 resource_build_scaling_params(pipe); 1830 } 1831 1832 /* merge previously mpc split pipes since mode support needs to make the decision */ 1833 for (i = 0; i < dc->res_pool->pipe_count; i++) { 1834 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 1835 struct pipe_ctx *hsplit_pipe = pipe->bottom_pipe; 1836 1837 if (!hsplit_pipe || hsplit_pipe->plane_state != pipe->plane_state) 1838 continue; 1839 1840 pipe->bottom_pipe = hsplit_pipe->bottom_pipe; 1841 if (hsplit_pipe->bottom_pipe) 1842 hsplit_pipe->bottom_pipe->top_pipe = pipe; 1843 hsplit_pipe->plane_state = NULL; 1844 hsplit_pipe->stream = NULL; 1845 hsplit_pipe->top_pipe = NULL; 1846 hsplit_pipe->bottom_pipe = NULL; 1847 1848 /* Clear plane_res and stream_res */ 1849 memset(&hsplit_pipe->plane_res, 0, sizeof(hsplit_pipe->plane_res)); 1850 memset(&hsplit_pipe->stream_res, 0, sizeof(hsplit_pipe->stream_res)); 1851 if (pipe->plane_state) 1852 resource_build_scaling_params(pipe); 1853 } 1854 } 1855 1856 static bool is_dual_plane(enum surface_pixel_format format) 1857 { 1858 return format >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN || format == SURFACE_PIXEL_FORMAT_GRPH_RGBE_ALPHA; 1859 } 1860 1861 int dcn20_validate_apply_pipe_split_flags( 1862 struct dc *dc, 1863 struct dc_state *context, 1864 int vlevel, 1865 int *split, 1866 bool *merge) 1867 { 1868 unsigned int i; 1869 int pipe_idx, vlevel_split; 1870 int plane_count = 0; 1871 bool force_split = false; 1872 bool avoid_split = dc->debug.pipe_split_policy == MPC_SPLIT_AVOID; 1873 struct vba_vars_st *v = &context->bw_ctx.dml.vba; 1874 int max_mpc_comb = v->maxMpcComb; 1875 1876 if (context->stream_count > 1) { 1877 if (dc->debug.pipe_split_policy == MPC_SPLIT_AVOID_MULT_DISP) 1878 avoid_split = true; 1879 } else if (dc->debug.force_single_disp_pipe_split) 1880 force_split = true; 1881 1882 for (i = 0; i < dc->res_pool->pipe_count; i++) { 1883 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 1884 1885 /** 1886 * Workaround for avoiding pipe-split in cases where we'd split 1887 * planes that are too small, resulting in splits that aren't 1888 * valid for the scaler. 1889 */ 1890 if (pipe->plane_state && 1891 (pipe->plane_state->dst_rect.width <= 16 || 1892 pipe->plane_state->dst_rect.height <= 16 || 1893 pipe->plane_state->src_rect.width <= 16 || 1894 pipe->plane_state->src_rect.height <= 16)) 1895 avoid_split = true; 1896 1897 /* TODO: fix dc bugs and remove this split threshold thing */ 1898 if (pipe->stream && !pipe->prev_odm_pipe && 1899 (!pipe->top_pipe || pipe->top_pipe->plane_state != pipe->plane_state)) 1900 ++plane_count; 1901 } 1902 if ((unsigned int)plane_count > dc->res_pool->pipe_count / 2) 1903 avoid_split = true; 1904 1905 /* W/A: Mode timing with borders may not work well with pipe split, avoid for this corner case */ 1906 for (i = 0; i < dc->res_pool->pipe_count; i++) { 1907 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 1908 struct dc_crtc_timing timing; 1909 1910 if (!pipe->stream) 1911 continue; 1912 else { 1913 timing = pipe->stream->timing; 1914 if (timing.h_border_left + timing.h_border_right 1915 + timing.v_border_top + timing.v_border_bottom > 0) { 1916 avoid_split = true; 1917 break; 1918 } 1919 } 1920 } 1921 1922 /* Avoid split loop looks for lowest voltage level that allows most unsplit pipes possible */ 1923 if (avoid_split) { 1924 for (i = 0, pipe_idx = 0; i < dc->res_pool->pipe_count; i++) { 1925 if (!context->res_ctx.pipe_ctx[i].stream) 1926 continue; 1927 1928 for (vlevel_split = vlevel; (unsigned int)vlevel <= context->bw_ctx.dml.soc.num_states; vlevel++) 1929 if (v->NoOfDPP[vlevel][0][pipe_idx] == 1 && 1930 v->ModeSupport[vlevel][0]) 1931 break; 1932 /* Impossible to not split this pipe */ 1933 if ((unsigned int)vlevel > context->bw_ctx.dml.soc.num_states) 1934 vlevel = vlevel_split; 1935 else 1936 max_mpc_comb = 0; 1937 pipe_idx++; 1938 } 1939 v->maxMpcComb = max_mpc_comb; 1940 } 1941 1942 /* Split loop sets which pipe should be split based on dml outputs and dc flags */ 1943 for (i = 0, pipe_idx = 0; i < dc->res_pool->pipe_count; i++) { 1944 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 1945 int pipe_plane = v->pipe_plane[pipe_idx]; 1946 bool split4mpc = false; 1947 1948 if (context->stream_count == 1 && plane_count == 1 1949 && dc->config.allow_4to1MPC && dc->res_pool->pipe_count >= 4 1950 && !dc->debug.disable_z9_mpc 1951 && pipe->plane_state && is_dual_plane(pipe->plane_state->format) 1952 && pipe->plane_state->src_rect.width <= 1920 1953 && pipe->plane_state->src_rect.height <= 1080) 1954 split4mpc = true; 1955 1956 if (!context->res_ctx.pipe_ctx[i].stream) 1957 continue; 1958 1959 if (split4mpc || v->NoOfDPP[vlevel][max_mpc_comb][pipe_plane] == 4) 1960 split[i] = 4; 1961 else if (force_split || v->NoOfDPP[vlevel][max_mpc_comb][pipe_plane] == 2) 1962 split[i] = 2; 1963 1964 if ((pipe->stream->view_format == 1965 VIEW_3D_FORMAT_SIDE_BY_SIDE || 1966 pipe->stream->view_format == 1967 VIEW_3D_FORMAT_TOP_AND_BOTTOM) && 1968 (pipe->stream->timing.timing_3d_format == 1969 TIMING_3D_FORMAT_TOP_AND_BOTTOM || 1970 pipe->stream->timing.timing_3d_format == 1971 TIMING_3D_FORMAT_SIDE_BY_SIDE)) 1972 split[i] = 2; 1973 if (dc->debug.force_odm_combine & (1 << pipe->stream_res.tg->inst)) { 1974 split[i] = 2; 1975 v->ODMCombineEnablePerState[vlevel][pipe_plane] = dm_odm_combine_mode_2to1; 1976 } 1977 if (dc->debug.force_odm_combine_4to1 & (1 << pipe->stream_res.tg->inst)) { 1978 split[i] = 4; 1979 v->ODMCombineEnablePerState[vlevel][pipe_plane] = dm_odm_combine_mode_4to1; 1980 } 1981 /*420 format workaround*/ 1982 if (pipe->stream->timing.h_addressable > 7680 && 1983 pipe->stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR420) { 1984 split[i] = 4; 1985 } 1986 v->ODMCombineEnabled[pipe_plane] = 1987 v->ODMCombineEnablePerState[vlevel][pipe_plane]; 1988 1989 if (v->ODMCombineEnabled[pipe_plane] == dm_odm_combine_mode_disabled) { 1990 if (resource_get_mpc_slice_count(pipe) == 2) { 1991 /*If need split for mpc but 2 way split already*/ 1992 if (split[i] == 4) 1993 split[i] = 2; /* 2 -> 4 MPC */ 1994 else if (split[i] == 2) 1995 split[i] = 0; /* 2 -> 2 MPC */ 1996 else if (pipe->top_pipe && pipe->top_pipe->plane_state == pipe->plane_state) 1997 merge[i] = true; /* 2 -> 1 MPC */ 1998 } else if (resource_get_mpc_slice_count(pipe) == 4) { 1999 /*If need split for mpc but 4 way split already*/ 2000 if (split[i] == 2 && ((pipe->top_pipe && !pipe->top_pipe->top_pipe) 2001 || !pipe->bottom_pipe)) { 2002 merge[i] = true; /* 4 -> 2 MPC */ 2003 } else if (split[i] == 0 && pipe->top_pipe && 2004 pipe->top_pipe->plane_state == pipe->plane_state) 2005 merge[i] = true; /* 4 -> 1 MPC */ 2006 split[i] = 0; 2007 } else if (resource_get_odm_slice_count(pipe) > 1) { 2008 /* ODM -> MPC transition */ 2009 if (pipe->prev_odm_pipe) { 2010 split[i] = 0; 2011 merge[i] = true; 2012 } 2013 } 2014 } else { 2015 if (resource_get_odm_slice_count(pipe) == 2) { 2016 /*If need split for odm but 2 way split already*/ 2017 if (split[i] == 4) 2018 split[i] = 2; /* 2 -> 4 ODM */ 2019 else if (split[i] == 2) 2020 split[i] = 0; /* 2 -> 2 ODM */ 2021 else if (pipe->prev_odm_pipe) { 2022 ASSERT(0); /* NOT expected yet */ 2023 merge[i] = true; /* exit ODM */ 2024 } 2025 } else if (resource_get_odm_slice_count(pipe) == 4) { 2026 /*If need split for odm but 4 way split already*/ 2027 if (split[i] == 2 && ((pipe->prev_odm_pipe && !pipe->prev_odm_pipe->prev_odm_pipe) 2028 || !pipe->next_odm_pipe)) { 2029 merge[i] = true; /* 4 -> 2 ODM */ 2030 } else if (split[i] == 0 && pipe->prev_odm_pipe) { 2031 ASSERT(0); /* NOT expected yet */ 2032 merge[i] = true; /* exit ODM */ 2033 } 2034 split[i] = 0; 2035 } else if (resource_get_mpc_slice_count(pipe) > 1) { 2036 /* MPC -> ODM transition */ 2037 ASSERT(0); /* NOT expected yet */ 2038 if (pipe->top_pipe && pipe->top_pipe->plane_state == pipe->plane_state) { 2039 split[i] = 0; 2040 merge[i] = true; 2041 } 2042 } 2043 } 2044 2045 /* Adjust dppclk when split is forced, do not bother with dispclk */ 2046 if (split[i] != 0 && v->NoOfDPP[vlevel][max_mpc_comb][pipe_idx] == 1) { 2047 DC_FP_START(); 2048 dcn20_fpu_adjust_dppclk(v, vlevel, max_mpc_comb, pipe_idx, false); 2049 DC_FP_END(); 2050 } 2051 pipe_idx++; 2052 } 2053 2054 return vlevel; 2055 } 2056 2057 bool dcn20_fast_validate_bw( 2058 struct dc *dc, 2059 struct dc_state *context, 2060 display_e2e_pipe_params_st *pipes, 2061 int *pipe_cnt_out, 2062 int *pipe_split_from, 2063 int *vlevel_out, 2064 enum dc_validate_mode validate_mode) 2065 { 2066 bool out = false; 2067 int split[MAX_PIPES] = { 0 }; 2068 bool merge[MAX_PIPES] = { false }; 2069 int pipe_cnt, pipe_idx, vlevel; 2070 unsigned int i; 2071 2072 ASSERT(pipes); 2073 if (!pipes) 2074 return false; 2075 2076 dcn20_merge_pipes_for_validate(dc, context); 2077 2078 pipe_cnt = dc->res_pool->funcs->populate_dml_pipes(dc, context, pipes, validate_mode); 2079 2080 *pipe_cnt_out = pipe_cnt; 2081 2082 if (!pipe_cnt) { 2083 out = true; 2084 goto validate_out; 2085 } 2086 2087 vlevel = dml_get_voltage_level(&context->bw_ctx.dml, pipes, pipe_cnt); 2088 2089 if ((unsigned int)vlevel > context->bw_ctx.dml.soc.num_states) 2090 goto validate_fail; 2091 2092 vlevel = dcn20_validate_apply_pipe_split_flags(dc, context, vlevel, split, merge); 2093 2094 /*initialize pipe_just_split_from to invalid idx*/ 2095 for (i = 0; i < MAX_PIPES; i++) 2096 pipe_split_from[i] = -1; 2097 2098 for (i = 0, pipe_idx = -1; i < dc->res_pool->pipe_count; i++) { 2099 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 2100 struct pipe_ctx *hsplit_pipe = pipe->bottom_pipe; 2101 2102 if (!pipe->stream || pipe_split_from[i] >= 0) 2103 continue; 2104 2105 pipe_idx++; 2106 2107 if (!pipe->top_pipe && !pipe->plane_state && context->bw_ctx.dml.vba.ODMCombineEnabled[pipe_idx]) { 2108 hsplit_pipe = dcn20_find_secondary_pipe(dc, &context->res_ctx, dc->res_pool, pipe); 2109 ASSERT(hsplit_pipe); 2110 if (!dcn20_split_stream_for_odm( 2111 dc, &context->res_ctx, 2112 pipe, hsplit_pipe)) 2113 goto validate_fail; 2114 pipe_split_from[hsplit_pipe->pipe_idx] = pipe_idx; 2115 dcn20_build_mapped_resource(dc, context, pipe->stream); 2116 } 2117 2118 if (!pipe->plane_state) 2119 continue; 2120 /* Skip 2nd half of already split pipe */ 2121 if (pipe->top_pipe && pipe->plane_state == pipe->top_pipe->plane_state) 2122 continue; 2123 2124 /* We do not support mpo + odm at the moment */ 2125 if (hsplit_pipe && hsplit_pipe->plane_state != pipe->plane_state 2126 && context->bw_ctx.dml.vba.ODMCombineEnabled[pipe_idx]) 2127 goto validate_fail; 2128 2129 if (split[i] == 2) { 2130 if (!hsplit_pipe || hsplit_pipe->plane_state != pipe->plane_state) { 2131 /* pipe not split previously needs split */ 2132 hsplit_pipe = dcn20_find_secondary_pipe(dc, &context->res_ctx, dc->res_pool, pipe); 2133 ASSERT(hsplit_pipe); 2134 if (!hsplit_pipe) { 2135 DC_FP_START(); 2136 dcn20_fpu_adjust_dppclk(&context->bw_ctx.dml.vba, vlevel, context->bw_ctx.dml.vba.maxMpcComb, pipe_idx, true); 2137 DC_FP_END(); 2138 continue; 2139 } 2140 if (context->bw_ctx.dml.vba.ODMCombineEnabled[pipe_idx]) { 2141 if (!dcn20_split_stream_for_odm( 2142 dc, &context->res_ctx, 2143 pipe, hsplit_pipe)) 2144 goto validate_fail; 2145 dcn20_build_mapped_resource(dc, context, pipe->stream); 2146 } else { 2147 dcn20_split_stream_for_mpc( 2148 &context->res_ctx, dc->res_pool, 2149 pipe, hsplit_pipe); 2150 resource_build_scaling_params(pipe); 2151 resource_build_scaling_params(hsplit_pipe); 2152 } 2153 pipe_split_from[hsplit_pipe->pipe_idx] = pipe_idx; 2154 } 2155 } else if (hsplit_pipe && hsplit_pipe->plane_state == pipe->plane_state) { 2156 /* merge should already have been done */ 2157 ASSERT(0); 2158 } 2159 } 2160 2161 /* Actual dsc count per stream dsc validation*/ 2162 if (!dcn20_validate_dsc(dc, context)) { 2163 context->bw_ctx.dml.vba.ValidationStatus[context->bw_ctx.dml.vba.soc.num_states] = 2164 DML_FAIL_DSC_VALIDATION_FAILURE; 2165 goto validate_fail; 2166 } 2167 2168 *vlevel_out = vlevel; 2169 2170 out = true; 2171 goto validate_out; 2172 2173 validate_fail: 2174 out = false; 2175 2176 validate_out: 2177 return out; 2178 } 2179 2180 enum dc_status dcn20_validate_bandwidth(struct dc *dc, struct dc_state *context, 2181 enum dc_validate_mode validate_mode) 2182 { 2183 bool voltage_supported; 2184 display_e2e_pipe_params_st *pipes; 2185 2186 pipes = kzalloc_objs(display_e2e_pipe_params_st, 2187 dc->res_pool->pipe_count); 2188 if (!pipes) 2189 return DC_FAIL_BANDWIDTH_VALIDATE; 2190 2191 DC_FP_START(); 2192 voltage_supported = dcn20_validate_bandwidth_fp(dc, context, validate_mode, pipes); 2193 DC_FP_END(); 2194 2195 kfree(pipes); 2196 return voltage_supported ? DC_OK : DC_FAIL_BANDWIDTH_VALIDATE; 2197 } 2198 2199 struct pipe_ctx *dcn20_acquire_free_pipe_for_layer( 2200 const struct dc_state *cur_ctx, 2201 struct dc_state *new_ctx, 2202 const struct resource_pool *pool, 2203 const struct pipe_ctx *opp_head) 2204 { 2205 (void)cur_ctx; 2206 struct resource_context *res_ctx = &new_ctx->res_ctx; 2207 struct pipe_ctx *otg_master = resource_get_otg_master_for_stream(res_ctx, opp_head->stream); 2208 struct pipe_ctx *sec_dpp_pipe = resource_find_free_secondary_pipe_legacy(res_ctx, pool, otg_master); 2209 2210 ASSERT(otg_master); 2211 2212 if (!sec_dpp_pipe) 2213 return NULL; 2214 2215 sec_dpp_pipe->stream = opp_head->stream; 2216 sec_dpp_pipe->stream_res.tg = opp_head->stream_res.tg; 2217 sec_dpp_pipe->stream_res.opp = opp_head->stream_res.opp; 2218 2219 sec_dpp_pipe->plane_res.hubp = pool->hubps[sec_dpp_pipe->pipe_idx]; 2220 sec_dpp_pipe->plane_res.ipp = pool->ipps[sec_dpp_pipe->pipe_idx]; 2221 sec_dpp_pipe->plane_res.dpp = pool->dpps[sec_dpp_pipe->pipe_idx]; 2222 sec_dpp_pipe->plane_res.mpcc_inst = (uint8_t)pool->dpps[sec_dpp_pipe->pipe_idx]->inst; 2223 2224 return sec_dpp_pipe; 2225 } 2226 2227 bool dcn20_get_dcc_compression_cap(const struct dc *dc, 2228 const struct dc_dcc_surface_param *input, 2229 struct dc_surface_dcc_cap *output) 2230 { 2231 if (dc->res_pool->hubbub->funcs->get_dcc_compression_cap) 2232 return dc->res_pool->hubbub->funcs->get_dcc_compression_cap( 2233 dc->res_pool->hubbub, input, output); 2234 2235 return false; 2236 } 2237 2238 static void dcn20_destroy_resource_pool(struct resource_pool **pool) 2239 { 2240 struct dcn20_resource_pool *dcn20_pool = TO_DCN20_RES_POOL(*pool); 2241 2242 dcn20_resource_destruct(dcn20_pool); 2243 kfree(dcn20_pool); 2244 *pool = NULL; 2245 } 2246 2247 2248 static struct dc_cap_funcs cap_funcs = { 2249 .get_dcc_compression_cap = dcn20_get_dcc_compression_cap 2250 }; 2251 2252 2253 enum dc_status dcn20_patch_unknown_plane_state(struct dc_plane_state *plane_state) 2254 { 2255 enum surface_pixel_format surf_pix_format = plane_state->format; 2256 unsigned int bpp = resource_pixel_format_to_bpp(surf_pix_format); 2257 2258 plane_state->tiling_info.gfx9.swizzle = DC_SW_64KB_S; 2259 if (bpp == 64) 2260 plane_state->tiling_info.gfx9.swizzle = DC_SW_64KB_D; 2261 2262 return DC_OK; 2263 } 2264 2265 void dcn20_release_pipe(struct dc_state *context, 2266 struct pipe_ctx *pipe, 2267 const struct resource_pool *pool) 2268 { 2269 if (resource_is_pipe_type(pipe, OPP_HEAD) && pipe->stream_res.dsc) 2270 dcn20_release_dsc(&context->res_ctx, pool, &pipe->stream_res.dsc); 2271 memset(pipe, 0, sizeof(*pipe)); 2272 } 2273 2274 static const struct resource_funcs dcn20_res_pool_funcs = { 2275 .destroy = dcn20_destroy_resource_pool, 2276 .link_enc_create = dcn20_link_encoder_create, 2277 .panel_cntl_create = dcn20_panel_cntl_create, 2278 .validate_bandwidth = dcn20_validate_bandwidth, 2279 .acquire_free_pipe_as_secondary_dpp_pipe = dcn20_acquire_free_pipe_for_layer, 2280 .release_pipe = dcn20_release_pipe, 2281 .add_stream_to_ctx = dcn20_add_stream_to_ctx, 2282 .add_dsc_to_stream_resource = dcn20_add_dsc_to_stream_resource, 2283 .remove_stream_from_ctx = dcn20_remove_stream_from_ctx, 2284 .populate_dml_writeback_from_context = dcn20_populate_dml_writeback_from_context, 2285 .patch_unknown_plane_state = dcn20_patch_unknown_plane_state, 2286 .set_mcif_arb_params = dcn20_set_mcif_arb_params, 2287 .populate_dml_pipes = dcn20_populate_dml_pipes_from_context, 2288 .find_first_free_match_stream_enc_for_link = dcn10_find_first_free_match_stream_enc_for_link, 2289 .get_vstartup_for_pipe = dcn10_get_vstartup_for_pipe, 2290 .get_default_tiling_info = dcn10_get_default_tiling_info 2291 }; 2292 2293 bool dcn20_dwbc_create(struct dc_context *ctx, struct resource_pool *pool) 2294 { 2295 unsigned int i; 2296 uint32_t pipe_count = pool->res_cap->num_dwb; 2297 2298 for (i = 0; i < pipe_count; i++) { 2299 struct dcn20_dwbc *dwbc20 = kzalloc_obj(struct dcn20_dwbc); 2300 2301 if (!dwbc20) { 2302 dm_error("DC: failed to create dwbc20!\n"); 2303 return false; 2304 } 2305 dcn20_dwbc_construct(dwbc20, ctx, 2306 &dwbc20_regs[i], 2307 &dwbc20_shift, 2308 &dwbc20_mask, 2309 i); 2310 pool->dwbc[i] = &dwbc20->base; 2311 } 2312 return true; 2313 } 2314 2315 bool dcn20_mmhubbub_create(struct dc_context *ctx, struct resource_pool *pool) 2316 { 2317 unsigned int i; 2318 uint32_t pipe_count = pool->res_cap->num_dwb; 2319 2320 ASSERT(pipe_count > 0); 2321 2322 for (i = 0; i < pipe_count; i++) { 2323 struct dcn20_mmhubbub *mcif_wb20 = kzalloc_obj(struct dcn20_mmhubbub); 2324 2325 if (!mcif_wb20) { 2326 dm_error("DC: failed to create mcif_wb20!\n"); 2327 return false; 2328 } 2329 2330 dcn20_mmhubbub_construct(mcif_wb20, ctx, 2331 &mcif_wb20_regs[i], 2332 &mcif_wb20_shift, 2333 &mcif_wb20_mask, 2334 i); 2335 2336 pool->mcif_wb[i] = &mcif_wb20->base; 2337 } 2338 return true; 2339 } 2340 2341 static struct pp_smu_funcs *dcn20_pp_smu_create(struct dc_context *ctx) 2342 { 2343 struct pp_smu_funcs *pp_smu = kzalloc_obj(*pp_smu); 2344 2345 if (!pp_smu) 2346 return pp_smu; 2347 2348 dm_pp_get_funcs(ctx, pp_smu); 2349 2350 if (pp_smu->ctx.ver != PP_SMU_VER_NV) 2351 pp_smu = memset(pp_smu, 0, sizeof(struct pp_smu_funcs)); 2352 2353 return pp_smu; 2354 } 2355 2356 static void dcn20_pp_smu_destroy(struct pp_smu_funcs **pp_smu) 2357 { 2358 if (pp_smu && *pp_smu) { 2359 kfree(*pp_smu); 2360 *pp_smu = NULL; 2361 } 2362 } 2363 2364 static struct _vcs_dpi_soc_bounding_box_st *get_asic_rev_soc_bb( 2365 uint32_t hw_internal_rev) 2366 { 2367 if (ASICREV_IS_NAVI14_M(hw_internal_rev)) 2368 return &dcn2_0_nv14_soc; 2369 2370 if (ASICREV_IS_NAVI12_P(hw_internal_rev)) 2371 return &dcn2_0_nv12_soc; 2372 2373 return &dcn2_0_soc; 2374 } 2375 2376 static struct _vcs_dpi_ip_params_st *get_asic_rev_ip_params( 2377 uint32_t hw_internal_rev) 2378 { 2379 if (ASICREV_IS_NAVI14_M(hw_internal_rev)) 2380 return &dcn2_0_nv14_ip; 2381 2382 /* NV12 and NV10 */ 2383 return &dcn2_0_ip; 2384 } 2385 2386 static enum dml_project get_dml_project_version(uint32_t hw_internal_rev) 2387 { 2388 (void)hw_internal_rev; 2389 return DML_PROJECT_NAVI10v2; 2390 } 2391 2392 static bool init_soc_bounding_box(struct dc *dc, 2393 struct dcn20_resource_pool *pool) 2394 { 2395 struct _vcs_dpi_soc_bounding_box_st *loaded_bb = 2396 get_asic_rev_soc_bb(dc->ctx->asic_id.hw_internal_rev); 2397 struct _vcs_dpi_ip_params_st *loaded_ip = 2398 get_asic_rev_ip_params(dc->ctx->asic_id.hw_internal_rev); 2399 2400 if (pool->base.pp_smu) { 2401 struct pp_smu_nv_clock_table max_clocks = {0}; 2402 unsigned int uclk_states[8] = {0}; 2403 unsigned int num_states = 0; 2404 enum pp_smu_status status; 2405 bool clock_limits_available = false; 2406 bool uclk_states_available = false; 2407 2408 if (pool->base.pp_smu->nv_funcs.get_uclk_dpm_states) { 2409 status = (pool->base.pp_smu->nv_funcs.get_uclk_dpm_states) 2410 (&pool->base.pp_smu->nv_funcs.pp_smu, uclk_states, &num_states); 2411 2412 uclk_states_available = (status == PP_SMU_RESULT_OK); 2413 } 2414 2415 if (pool->base.pp_smu->nv_funcs.get_maximum_sustainable_clocks) { 2416 status = (*pool->base.pp_smu->nv_funcs.get_maximum_sustainable_clocks) 2417 (&pool->base.pp_smu->nv_funcs.pp_smu, &max_clocks); 2418 /* SMU cannot set DCF clock to anything equal to or higher than SOC clock 2419 */ 2420 if (max_clocks.dcfClockInKhz >= max_clocks.socClockInKhz) 2421 max_clocks.dcfClockInKhz = max_clocks.socClockInKhz - 1000; 2422 clock_limits_available = (status == PP_SMU_RESULT_OK); 2423 } 2424 2425 if (clock_limits_available && uclk_states_available && num_states) { 2426 DC_FP_START(); 2427 dcn20_update_bounding_box(dc, loaded_bb, &max_clocks, uclk_states, num_states); 2428 DC_FP_END(); 2429 } else if (clock_limits_available) { 2430 DC_FP_START(); 2431 dcn20_cap_soc_clocks(loaded_bb, max_clocks); 2432 DC_FP_END(); 2433 } 2434 } 2435 2436 loaded_ip->max_num_otg = pool->base.res_cap->num_timing_generator; 2437 loaded_ip->max_num_dpp = pool->base.pipe_count; 2438 DC_FP_START(); 2439 dcn20_patch_bounding_box(dc, loaded_bb); 2440 DC_FP_END(); 2441 return true; 2442 } 2443 2444 static bool dcn20_resource_construct( 2445 uint8_t num_virtual_links, 2446 struct dc *dc, 2447 struct dcn20_resource_pool *pool) 2448 { 2449 int i; 2450 struct dc_context *ctx = dc->ctx; 2451 struct irq_service_init_data init_data; 2452 struct ddc_service_init_data ddc_init_data = {0}; 2453 struct _vcs_dpi_soc_bounding_box_st *loaded_bb = 2454 get_asic_rev_soc_bb(ctx->asic_id.hw_internal_rev); 2455 struct _vcs_dpi_ip_params_st *loaded_ip = 2456 get_asic_rev_ip_params(ctx->asic_id.hw_internal_rev); 2457 enum dml_project dml_project_version = 2458 get_dml_project_version(ctx->asic_id.hw_internal_rev); 2459 2460 ctx->dc_bios->regs = &bios_regs; 2461 pool->base.funcs = &dcn20_res_pool_funcs; 2462 2463 if (ASICREV_IS_NAVI14_M(ctx->asic_id.hw_internal_rev)) { 2464 pool->base.res_cap = &res_cap_nv14; 2465 pool->base.pipe_count = 5; 2466 pool->base.mpcc_count = 5; 2467 } else { 2468 pool->base.res_cap = &res_cap_nv10; 2469 pool->base.pipe_count = 6; 2470 pool->base.mpcc_count = 6; 2471 } 2472 /************************************************* 2473 * Resource + asic cap harcoding * 2474 *************************************************/ 2475 pool->base.underlay_pipe_index = (unsigned int)NO_UNDERLAY_PIPE; 2476 2477 dc->caps.max_downscale_ratio = 200; 2478 dc->caps.i2c_speed_in_khz = 100; 2479 dc->caps.i2c_speed_in_khz_hdcp = 100; /*1.4 w/a not applied by default*/ 2480 dc->caps.max_cursor_size = 256; 2481 dc->caps.min_horizontal_blanking_period = 80; 2482 dc->caps.dmdata_alloc_size = 2048; 2483 2484 dc->caps.max_slave_planes = 1; 2485 dc->caps.max_slave_yuv_planes = 1; 2486 dc->caps.max_slave_rgb_planes = 1; 2487 dc->caps.post_blend_color_processing = true; 2488 dc->caps.force_dp_tps4_for_cp2520 = true; 2489 dc->caps.extended_aux_timeout_support = true; 2490 dc->caps.dmcub_support = true; 2491 2492 /* Color pipeline capabilities */ 2493 dc->caps.color.dpp.dcn_arch = 1; 2494 dc->caps.color.dpp.input_lut_shared = 0; 2495 dc->caps.color.dpp.icsc = 1; 2496 dc->caps.color.dpp.dgam_ram = 1; 2497 dc->caps.color.dpp.dgam_rom_caps.srgb = 1; 2498 dc->caps.color.dpp.dgam_rom_caps.bt2020 = 1; 2499 dc->caps.color.dpp.dgam_rom_caps.gamma2_2 = 0; 2500 dc->caps.color.dpp.dgam_rom_caps.pq = 0; 2501 dc->caps.color.dpp.dgam_rom_caps.hlg = 0; 2502 dc->caps.color.dpp.post_csc = 0; 2503 dc->caps.color.dpp.gamma_corr = 0; 2504 dc->caps.color.dpp.dgam_rom_for_yuv = 1; 2505 2506 dc->caps.color.dpp.hw_3d_lut = 1; 2507 dc->caps.color.dpp.ogam_ram = 1; 2508 // no OGAM ROM on DCN2, only MPC ROM 2509 dc->caps.color.dpp.ogam_rom_caps.srgb = 0; 2510 dc->caps.color.dpp.ogam_rom_caps.bt2020 = 0; 2511 dc->caps.color.dpp.ogam_rom_caps.gamma2_2 = 0; 2512 dc->caps.color.dpp.ogam_rom_caps.pq = 0; 2513 dc->caps.color.dpp.ogam_rom_caps.hlg = 0; 2514 dc->caps.color.dpp.ocsc = 0; 2515 2516 dc->caps.color.mpc.gamut_remap = 0; 2517 dc->caps.color.mpc.num_3dluts = 0; 2518 dc->caps.color.mpc.shared_3d_lut = 0; 2519 dc->caps.color.mpc.ogam_ram = 1; 2520 dc->caps.color.mpc.ogam_rom_caps.srgb = 0; 2521 dc->caps.color.mpc.ogam_rom_caps.bt2020 = 0; 2522 dc->caps.color.mpc.ogam_rom_caps.gamma2_2 = 0; 2523 dc->caps.color.mpc.ogam_rom_caps.pq = 0; 2524 dc->caps.color.mpc.ogam_rom_caps.hlg = 0; 2525 dc->caps.color.mpc.ocsc = 1; 2526 2527 dc->caps.dp_hdmi21_pcon_support = true; 2528 dc->check_config = config_defaults; 2529 2530 if (dc->ctx->dce_environment == DCE_ENV_PRODUCTION_DRV) 2531 dc->debug = debug_defaults_drv; 2532 2533 //dcn2.0x 2534 dc->work_arounds.dedcn20_305_wa = true; 2535 2536 // Init the vm_helper 2537 if (dc->vm_helper) 2538 vm_helper_init(dc->vm_helper, 16); 2539 2540 /************************************************* 2541 * Create resources * 2542 *************************************************/ 2543 2544 pool->base.clock_sources[DCN20_CLK_SRC_PLL0] = 2545 dcn20_clock_source_create(ctx, ctx->dc_bios, 2546 CLOCK_SOURCE_COMBO_PHY_PLL0, 2547 &clk_src_regs[0], false); 2548 pool->base.clock_sources[DCN20_CLK_SRC_PLL1] = 2549 dcn20_clock_source_create(ctx, ctx->dc_bios, 2550 CLOCK_SOURCE_COMBO_PHY_PLL1, 2551 &clk_src_regs[1], false); 2552 pool->base.clock_sources[DCN20_CLK_SRC_PLL2] = 2553 dcn20_clock_source_create(ctx, ctx->dc_bios, 2554 CLOCK_SOURCE_COMBO_PHY_PLL2, 2555 &clk_src_regs[2], false); 2556 pool->base.clock_sources[DCN20_CLK_SRC_PLL3] = 2557 dcn20_clock_source_create(ctx, ctx->dc_bios, 2558 CLOCK_SOURCE_COMBO_PHY_PLL3, 2559 &clk_src_regs[3], false); 2560 pool->base.clock_sources[DCN20_CLK_SRC_PLL4] = 2561 dcn20_clock_source_create(ctx, ctx->dc_bios, 2562 CLOCK_SOURCE_COMBO_PHY_PLL4, 2563 &clk_src_regs[4], false); 2564 pool->base.clock_sources[DCN20_CLK_SRC_PLL5] = 2565 dcn20_clock_source_create(ctx, ctx->dc_bios, 2566 CLOCK_SOURCE_COMBO_PHY_PLL5, 2567 &clk_src_regs[5], false); 2568 pool->base.clk_src_count = DCN20_CLK_SRC_TOTAL; 2569 /* todo: not reuse phy_pll registers */ 2570 pool->base.dp_clock_source = 2571 dcn20_clock_source_create(ctx, ctx->dc_bios, 2572 CLOCK_SOURCE_ID_DP_DTO, 2573 &clk_src_regs[0], true); 2574 2575 for (i = 0; (unsigned int)i < pool->base.clk_src_count; i++) { 2576 if (pool->base.clock_sources[i] == NULL) { 2577 dm_error("DC: failed to create clock sources!\n"); 2578 BREAK_TO_DEBUGGER(); 2579 goto create_fail; 2580 } 2581 } 2582 2583 pool->base.dccg = dccg2_create(ctx, &dccg_regs, &dccg_shift, &dccg_mask); 2584 if (pool->base.dccg == NULL) { 2585 dm_error("DC: failed to create dccg!\n"); 2586 BREAK_TO_DEBUGGER(); 2587 goto create_fail; 2588 } 2589 2590 pool->base.dmcu = dcn20_dmcu_create(ctx, 2591 &dmcu_regs, 2592 &dmcu_shift, 2593 &dmcu_mask); 2594 if (pool->base.dmcu == NULL) { 2595 dm_error("DC: failed to create dmcu!\n"); 2596 BREAK_TO_DEBUGGER(); 2597 goto create_fail; 2598 } 2599 2600 pool->base.abm = dce_abm_create(ctx, 2601 &abm_regs, 2602 &abm_shift, 2603 &abm_mask); 2604 if (pool->base.abm == NULL) { 2605 dm_error("DC: failed to create abm!\n"); 2606 BREAK_TO_DEBUGGER(); 2607 goto create_fail; 2608 } 2609 2610 pool->base.pp_smu = dcn20_pp_smu_create(ctx); 2611 2612 2613 if (!init_soc_bounding_box(dc, pool)) { 2614 dm_error("DC: failed to initialize soc bounding box!\n"); 2615 BREAK_TO_DEBUGGER(); 2616 goto create_fail; 2617 } 2618 2619 dml_init_instance(&dc->dml, loaded_bb, loaded_ip, dml_project_version); 2620 2621 if (!dc->debug.disable_pplib_wm_range) { 2622 struct pp_smu_wm_range_sets ranges = {0}; 2623 int j = 0; 2624 2625 ranges.num_reader_wm_sets = 0; 2626 2627 if (loaded_bb->num_states == 1) { 2628 ranges.reader_wm_sets[0].wm_inst = (uint8_t)j; 2629 ranges.reader_wm_sets[0].min_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN; 2630 ranges.reader_wm_sets[0].max_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX; 2631 ranges.reader_wm_sets[0].min_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN; 2632 ranges.reader_wm_sets[0].max_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX; 2633 2634 ranges.num_reader_wm_sets = 1; 2635 } else if (loaded_bb->num_states > 1) { 2636 for (j = 0; j < 4 && (unsigned int)j < loaded_bb->num_states; j++) { 2637 ranges.reader_wm_sets[j].wm_inst = (uint8_t)j; 2638 ranges.reader_wm_sets[j].min_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN; 2639 ranges.reader_wm_sets[j].max_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX; 2640 DC_FP_START(); 2641 dcn20_fpu_set_wm_ranges(j, &ranges, loaded_bb); 2642 DC_FP_END(); 2643 ranges.num_reader_wm_sets = j + 1; 2644 } 2645 2646 ranges.reader_wm_sets[0].min_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN; 2647 ranges.reader_wm_sets[ranges.num_reader_wm_sets - 1].max_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX; 2648 } 2649 2650 ranges.num_writer_wm_sets = 1; 2651 2652 ranges.writer_wm_sets[0].wm_inst = 0; 2653 ranges.writer_wm_sets[0].min_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN; 2654 ranges.writer_wm_sets[0].max_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX; 2655 ranges.writer_wm_sets[0].min_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN; 2656 ranges.writer_wm_sets[0].max_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX; 2657 2658 /* Notify PP Lib/SMU which Watermarks to use for which clock ranges */ 2659 if (pool->base.pp_smu && pool->base.pp_smu->nv_funcs.set_wm_ranges) 2660 pool->base.pp_smu->nv_funcs.set_wm_ranges(&pool->base.pp_smu->nv_funcs.pp_smu, &ranges); 2661 } 2662 2663 init_data.ctx = dc->ctx; 2664 pool->base.irqs = dal_irq_service_dcn20_create(&init_data); 2665 if (!pool->base.irqs) 2666 goto create_fail; 2667 2668 /* mem input -> ipp -> dpp -> opp -> TG */ 2669 for (i = 0; (unsigned int)i < pool->base.pipe_count; i++) { 2670 pool->base.hubps[i] = dcn20_hubp_create(ctx, i); 2671 if (pool->base.hubps[i] == NULL) { 2672 BREAK_TO_DEBUGGER(); 2673 dm_error( 2674 "DC: failed to create memory input!\n"); 2675 goto create_fail; 2676 } 2677 2678 pool->base.ipps[i] = dcn20_ipp_create(ctx, i); 2679 if (pool->base.ipps[i] == NULL) { 2680 BREAK_TO_DEBUGGER(); 2681 dm_error( 2682 "DC: failed to create input pixel processor!\n"); 2683 goto create_fail; 2684 } 2685 2686 pool->base.dpps[i] = dcn20_dpp_create(ctx, i); 2687 if (pool->base.dpps[i] == NULL) { 2688 BREAK_TO_DEBUGGER(); 2689 dm_error( 2690 "DC: failed to create dpps!\n"); 2691 goto create_fail; 2692 } 2693 } 2694 for (i = 0; i < pool->base.res_cap->num_ddc; i++) { 2695 pool->base.engines[i] = dcn20_aux_engine_create(ctx, i); 2696 if (pool->base.engines[i] == NULL) { 2697 BREAK_TO_DEBUGGER(); 2698 dm_error( 2699 "DC:failed to create aux engine!!\n"); 2700 goto create_fail; 2701 } 2702 pool->base.hw_i2cs[i] = dcn20_i2c_hw_create(ctx, i); 2703 if (pool->base.hw_i2cs[i] == NULL) { 2704 BREAK_TO_DEBUGGER(); 2705 dm_error( 2706 "DC:failed to create hw i2c!!\n"); 2707 goto create_fail; 2708 } 2709 pool->base.sw_i2cs[i] = NULL; 2710 } 2711 2712 for (i = 0; i < pool->base.res_cap->num_opp; i++) { 2713 pool->base.opps[i] = dcn20_opp_create(ctx, i); 2714 if (pool->base.opps[i] == NULL) { 2715 BREAK_TO_DEBUGGER(); 2716 dm_error( 2717 "DC: failed to create output pixel processor!\n"); 2718 goto create_fail; 2719 } 2720 } 2721 2722 for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) { 2723 pool->base.timing_generators[i] = dcn20_timing_generator_create( 2724 ctx, i); 2725 if (pool->base.timing_generators[i] == NULL) { 2726 BREAK_TO_DEBUGGER(); 2727 dm_error("DC: failed to create tg!\n"); 2728 goto create_fail; 2729 } 2730 } 2731 2732 pool->base.timing_generator_count = i; 2733 2734 pool->base.mpc = dcn20_mpc_create(ctx); 2735 if (pool->base.mpc == NULL) { 2736 BREAK_TO_DEBUGGER(); 2737 dm_error("DC: failed to create mpc!\n"); 2738 goto create_fail; 2739 } 2740 2741 pool->base.hubbub = dcn20_hubbub_create(ctx); 2742 if (pool->base.hubbub == NULL) { 2743 BREAK_TO_DEBUGGER(); 2744 dm_error("DC: failed to create hubbub!\n"); 2745 goto create_fail; 2746 } 2747 2748 /* DIO */ 2749 pool->base.dio = dcn20_dio_create(ctx); 2750 if (pool->base.dio == NULL) { 2751 BREAK_TO_DEBUGGER(); 2752 dm_error("DC: failed to create dio!\n"); 2753 goto create_fail; 2754 } 2755 2756 for (i = 0; i < pool->base.res_cap->num_dsc; i++) { 2757 pool->base.dscs[i] = dcn20_dsc_create(ctx, i); 2758 if (pool->base.dscs[i] == NULL) { 2759 BREAK_TO_DEBUGGER(); 2760 dm_error("DC: failed to create display stream compressor %d!\n", i); 2761 goto create_fail; 2762 } 2763 } 2764 2765 if (!dcn20_dwbc_create(ctx, &pool->base)) { 2766 BREAK_TO_DEBUGGER(); 2767 dm_error("DC: failed to create dwbc!\n"); 2768 goto create_fail; 2769 } 2770 if (!dcn20_mmhubbub_create(ctx, &pool->base)) { 2771 BREAK_TO_DEBUGGER(); 2772 dm_error("DC: failed to create mcif_wb!\n"); 2773 goto create_fail; 2774 } 2775 2776 if (!resource_construct(num_virtual_links, dc, &pool->base, 2777 &res_create_funcs)) 2778 goto create_fail; 2779 2780 dcn20_hw_sequencer_construct(dc); 2781 2782 // IF NV12, set PG function pointer to NULL. It's not that 2783 // PG isn't supported for NV12, it's that we don't want to 2784 // program the registers because that will cause more power 2785 // to be consumed. We could have created dcn20_init_hw to get 2786 // the same effect by checking ASIC rev, but there was a 2787 // request at some point to not check ASIC rev on hw sequencer. 2788 if (ASICREV_IS_NAVI12_P(dc->ctx->asic_id.hw_internal_rev)) { 2789 dc->hwseq->funcs.enable_power_gating_plane = NULL; 2790 dc->debug.disable_dpp_power_gate = true; 2791 dc->debug.disable_hubp_power_gate = true; 2792 } 2793 2794 2795 dc->caps.max_planes = pool->base.pipe_count; 2796 2797 for (i = 0; (unsigned int)i < dc->caps.max_planes; ++i) 2798 dc->caps.planes[i] = plane_cap; 2799 2800 dc->caps.max_odm_combine_factor = 2; 2801 2802 dc->cap_funcs = cap_funcs; 2803 2804 if (dc->ctx->dc_bios->fw_info.oem_i2c_present) { 2805 ddc_init_data.ctx = dc->ctx; 2806 ddc_init_data.link = NULL; 2807 ddc_init_data.id.id = dc->ctx->dc_bios->fw_info.oem_i2c_obj_id; 2808 ddc_init_data.id.enum_id = 0; 2809 ddc_init_data.id.type = OBJECT_TYPE_GENERIC; 2810 pool->base.oem_device = dc->link_srv->create_ddc_service(&ddc_init_data); 2811 } else { 2812 pool->base.oem_device = NULL; 2813 } 2814 2815 return true; 2816 2817 create_fail: 2818 2819 dcn20_resource_destruct(pool); 2820 2821 return false; 2822 } 2823 2824 struct resource_pool *dcn20_create_resource_pool( 2825 const struct dc_init_data *init_data, 2826 struct dc *dc) 2827 { 2828 struct dcn20_resource_pool *pool = 2829 kzalloc_obj(struct dcn20_resource_pool); 2830 2831 if (!pool) 2832 return NULL; 2833 2834 if (dcn20_resource_construct((uint8_t)init_data->num_virtual_links, dc, pool)) 2835 return &pool->base; 2836 2837 BREAK_TO_DEBUGGER(); 2838 kfree(pool); 2839 return NULL; 2840 } 2841