1 /* 2 * Copyright 2018 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 <linux/slab.h> 28 29 #include "dm_services.h" 30 #include "dc.h" 31 32 #include "dcn21_init.h" 33 34 #include "resource.h" 35 #include "include/irq_service_interface.h" 36 #include "dcn20/dcn20_resource.h" 37 #include "dcn21/dcn21_resource.h" 38 39 #include "dml/dcn20/dcn20_fpu.h" 40 41 #include "clk_mgr.h" 42 #include "dcn10/dcn10_hubp.h" 43 #include "dcn10/dcn10_ipp.h" 44 #include "dcn20/dcn20_hubbub.h" 45 #include "dcn20/dcn20_mpc.h" 46 #include "dcn20/dcn20_hubp.h" 47 #include "dcn21_hubp.h" 48 #include "irq/dcn21/irq_service_dcn21.h" 49 #include "dcn20/dcn20_dpp.h" 50 #include "dcn20/dcn20_optc.h" 51 #include "dcn21/dcn21_hwseq.h" 52 #include "dce110/dce110_hw_sequencer.h" 53 #include "dcn20/dcn20_opp.h" 54 #include "dcn20/dcn20_dsc.h" 55 #include "dcn21/dcn21_link_encoder.h" 56 #include "dcn20/dcn20_stream_encoder.h" 57 #include "dce/dce_clock_source.h" 58 #include "dce/dce_audio.h" 59 #include "dce/dce_hwseq.h" 60 #include "virtual/virtual_stream_encoder.h" 61 #include "dml/display_mode_vba.h" 62 #include "dcn20/dcn20_dccg.h" 63 #include "dcn21/dcn21_dccg.h" 64 #include "dcn21_hubbub.h" 65 #include "dcn10/dcn10_resource.h" 66 #include "dce/dce_panel_cntl.h" 67 68 #include "dcn20/dcn20_dwb.h" 69 #include "dcn20/dcn20_mmhubbub.h" 70 #include "dpcs/dpcs_2_1_0_offset.h" 71 #include "dpcs/dpcs_2_1_0_sh_mask.h" 72 73 #include "renoir_ip_offset.h" 74 #include "dcn/dcn_2_1_0_offset.h" 75 #include "dcn/dcn_2_1_0_sh_mask.h" 76 77 #include "nbio/nbio_7_0_offset.h" 78 79 #include "mmhub/mmhub_2_0_0_offset.h" 80 #include "mmhub/mmhub_2_0_0_sh_mask.h" 81 82 #include "reg_helper.h" 83 #include "dce/dce_abm.h" 84 #include "dce/dce_dmcu.h" 85 #include "dce/dce_aux.h" 86 #include "dce/dce_i2c.h" 87 #include "dcn21_resource.h" 88 #include "vm_helper.h" 89 #include "dcn20/dcn20_vmid.h" 90 #include "dce/dmub_psr.h" 91 #include "dce/dmub_abm.h" 92 93 /* begin ********************* 94 * macros to expend register list macro defined in HW object header file */ 95 96 /* DCN */ 97 /* TODO awful hack. fixup dcn20_dwb.h */ 98 #undef BASE_INNER 99 #define BASE_INNER(seg) DMU_BASE__INST0_SEG ## seg 100 101 #define BASE(seg) BASE_INNER(seg) 102 103 #define SR(reg_name)\ 104 .reg_name = BASE(mm ## reg_name ## _BASE_IDX) + \ 105 mm ## reg_name 106 107 #define SRI(reg_name, block, id)\ 108 .reg_name = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \ 109 mm ## block ## id ## _ ## reg_name 110 111 #define SRIR(var_name, reg_name, block, id)\ 112 .var_name = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \ 113 mm ## block ## id ## _ ## reg_name 114 115 #define SRII(reg_name, block, id)\ 116 .reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \ 117 mm ## block ## id ## _ ## reg_name 118 119 #define DCCG_SRII(reg_name, block, id)\ 120 .block ## _ ## reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \ 121 mm ## block ## id ## _ ## reg_name 122 123 #define VUPDATE_SRII(reg_name, block, id)\ 124 .reg_name[id] = BASE(mm ## reg_name ## _ ## block ## id ## _BASE_IDX) + \ 125 mm ## reg_name ## _ ## block ## id 126 127 /* NBIO */ 128 #define NBIO_BASE_INNER(seg) \ 129 NBIF0_BASE__INST0_SEG ## seg 130 131 #define NBIO_BASE(seg) \ 132 NBIO_BASE_INNER(seg) 133 134 #define NBIO_SR(reg_name)\ 135 .reg_name = NBIO_BASE(mm ## reg_name ## _BASE_IDX) + \ 136 mm ## reg_name 137 138 /* MMHUB */ 139 #define MMHUB_BASE_INNER(seg) \ 140 MMHUB_BASE__INST0_SEG ## seg 141 142 #define MMHUB_BASE(seg) \ 143 MMHUB_BASE_INNER(seg) 144 145 #define MMHUB_SR(reg_name)\ 146 .reg_name = MMHUB_BASE(mmMM ## reg_name ## _BASE_IDX) + \ 147 mmMM ## reg_name 148 149 #define clk_src_regs(index, pllid)\ 150 [index] = {\ 151 CS_COMMON_REG_LIST_DCN2_1(index, pllid),\ 152 } 153 154 static const struct dce110_clk_src_regs clk_src_regs[] = { 155 clk_src_regs(0, A), 156 clk_src_regs(1, B), 157 clk_src_regs(2, C), 158 clk_src_regs(3, D), 159 clk_src_regs(4, E), 160 }; 161 162 static const struct dce110_clk_src_shift cs_shift = { 163 CS_COMMON_MASK_SH_LIST_DCN2_0(__SHIFT) 164 }; 165 166 static const struct dce110_clk_src_mask cs_mask = { 167 CS_COMMON_MASK_SH_LIST_DCN2_0(_MASK) 168 }; 169 170 static const struct bios_registers bios_regs = { 171 NBIO_SR(BIOS_SCRATCH_3), 172 NBIO_SR(BIOS_SCRATCH_6) 173 }; 174 175 static const struct dce_dmcu_registers dmcu_regs = { 176 DMCU_DCN20_REG_LIST() 177 }; 178 179 static const struct dce_dmcu_shift dmcu_shift = { 180 DMCU_MASK_SH_LIST_DCN10(__SHIFT) 181 }; 182 183 static const struct dce_dmcu_mask dmcu_mask = { 184 DMCU_MASK_SH_LIST_DCN10(_MASK) 185 }; 186 187 static const struct dce_abm_registers abm_regs = { 188 ABM_DCN20_REG_LIST() 189 }; 190 191 static const struct dce_abm_shift abm_shift = { 192 ABM_MASK_SH_LIST_DCN20(__SHIFT) 193 }; 194 195 static const struct dce_abm_mask abm_mask = { 196 ABM_MASK_SH_LIST_DCN20(_MASK) 197 }; 198 199 #define audio_regs(id)\ 200 [id] = {\ 201 AUD_COMMON_REG_LIST(id)\ 202 } 203 204 static const struct dce_audio_registers audio_regs[] = { 205 audio_regs(0), 206 audio_regs(1), 207 audio_regs(2), 208 audio_regs(3), 209 audio_regs(4), 210 audio_regs(5), 211 }; 212 213 #define DCE120_AUD_COMMON_MASK_SH_LIST(mask_sh)\ 214 SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_INDEX, AZALIA_ENDPOINT_REG_INDEX, mask_sh),\ 215 SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_DATA, AZALIA_ENDPOINT_REG_DATA, mask_sh),\ 216 AUD_COMMON_MASK_SH_LIST_BASE(mask_sh) 217 218 static const struct dce_audio_shift audio_shift = { 219 DCE120_AUD_COMMON_MASK_SH_LIST(__SHIFT) 220 }; 221 222 static const struct dce_audio_mask audio_mask = { 223 DCE120_AUD_COMMON_MASK_SH_LIST(_MASK) 224 }; 225 226 static const struct dccg_registers dccg_regs = { 227 DCCG_COMMON_REG_LIST_DCN_BASE() 228 }; 229 230 static const struct dccg_shift dccg_shift = { 231 DCCG_MASK_SH_LIST_DCN2_1(__SHIFT) 232 }; 233 234 static const struct dccg_mask dccg_mask = { 235 DCCG_MASK_SH_LIST_DCN2_1(_MASK) 236 }; 237 238 #define opp_regs(id)\ 239 [id] = {\ 240 OPP_REG_LIST_DCN20(id),\ 241 } 242 243 static const struct dcn20_opp_registers opp_regs[] = { 244 opp_regs(0), 245 opp_regs(1), 246 opp_regs(2), 247 opp_regs(3), 248 opp_regs(4), 249 opp_regs(5), 250 }; 251 252 static const struct dcn20_opp_shift opp_shift = { 253 OPP_MASK_SH_LIST_DCN20(__SHIFT) 254 }; 255 256 static const struct dcn20_opp_mask opp_mask = { 257 OPP_MASK_SH_LIST_DCN20(_MASK) 258 }; 259 260 #define tg_regs(id)\ 261 [id] = {TG_COMMON_REG_LIST_DCN2_0(id)} 262 263 static const struct dcn_optc_registers tg_regs[] = { 264 tg_regs(0), 265 tg_regs(1), 266 tg_regs(2), 267 tg_regs(3) 268 }; 269 270 static const struct dcn_optc_shift tg_shift = { 271 TG_COMMON_MASK_SH_LIST_DCN2_0(__SHIFT) 272 }; 273 274 static const struct dcn_optc_mask tg_mask = { 275 TG_COMMON_MASK_SH_LIST_DCN2_0(_MASK) 276 }; 277 278 static const struct dcn20_mpc_registers mpc_regs = { 279 MPC_REG_LIST_DCN2_0(0), 280 MPC_REG_LIST_DCN2_0(1), 281 MPC_REG_LIST_DCN2_0(2), 282 MPC_REG_LIST_DCN2_0(3), 283 MPC_REG_LIST_DCN2_0(4), 284 MPC_REG_LIST_DCN2_0(5), 285 MPC_OUT_MUX_REG_LIST_DCN2_0(0), 286 MPC_OUT_MUX_REG_LIST_DCN2_0(1), 287 MPC_OUT_MUX_REG_LIST_DCN2_0(2), 288 MPC_OUT_MUX_REG_LIST_DCN2_0(3), 289 MPC_DBG_REG_LIST_DCN2_0() 290 }; 291 292 static const struct dcn20_mpc_shift mpc_shift = { 293 MPC_COMMON_MASK_SH_LIST_DCN2_0(__SHIFT), 294 MPC_DEBUG_REG_LIST_SH_DCN20 295 }; 296 297 static const struct dcn20_mpc_mask mpc_mask = { 298 MPC_COMMON_MASK_SH_LIST_DCN2_0(_MASK), 299 MPC_DEBUG_REG_LIST_MASK_DCN20 300 }; 301 302 #define hubp_regs(id)\ 303 [id] = {\ 304 HUBP_REG_LIST_DCN21(id)\ 305 } 306 307 static const struct dcn_hubp2_registers hubp_regs[] = { 308 hubp_regs(0), 309 hubp_regs(1), 310 hubp_regs(2), 311 hubp_regs(3) 312 }; 313 314 static const struct dcn_hubp2_shift hubp_shift = { 315 HUBP_MASK_SH_LIST_DCN21(__SHIFT) 316 }; 317 318 static const struct dcn_hubp2_mask hubp_mask = { 319 HUBP_MASK_SH_LIST_DCN21(_MASK) 320 }; 321 322 static const struct dcn_hubbub_registers hubbub_reg = { 323 HUBBUB_REG_LIST_DCN21() 324 }; 325 326 static const struct dcn_hubbub_shift hubbub_shift = { 327 HUBBUB_MASK_SH_LIST_DCN21(__SHIFT) 328 }; 329 330 static const struct dcn_hubbub_mask hubbub_mask = { 331 HUBBUB_MASK_SH_LIST_DCN21(_MASK) 332 }; 333 334 335 #define vmid_regs(id)\ 336 [id] = {\ 337 DCN20_VMID_REG_LIST(id)\ 338 } 339 340 static const struct dcn_vmid_registers vmid_regs[] = { 341 vmid_regs(0), 342 vmid_regs(1), 343 vmid_regs(2), 344 vmid_regs(3), 345 vmid_regs(4), 346 vmid_regs(5), 347 vmid_regs(6), 348 vmid_regs(7), 349 vmid_regs(8), 350 vmid_regs(9), 351 vmid_regs(10), 352 vmid_regs(11), 353 vmid_regs(12), 354 vmid_regs(13), 355 vmid_regs(14), 356 vmid_regs(15) 357 }; 358 359 static const struct dcn20_vmid_shift vmid_shifts = { 360 DCN20_VMID_MASK_SH_LIST(__SHIFT) 361 }; 362 363 static const struct dcn20_vmid_mask vmid_masks = { 364 DCN20_VMID_MASK_SH_LIST(_MASK) 365 }; 366 367 #define dsc_regsDCN20(id)\ 368 [id] = {\ 369 DSC_REG_LIST_DCN20(id)\ 370 } 371 372 static const struct dcn20_dsc_registers dsc_regs[] = { 373 dsc_regsDCN20(0), 374 dsc_regsDCN20(1), 375 dsc_regsDCN20(2), 376 dsc_regsDCN20(3), 377 dsc_regsDCN20(4), 378 dsc_regsDCN20(5) 379 }; 380 381 static const struct dcn20_dsc_shift dsc_shift = { 382 DSC_REG_LIST_SH_MASK_DCN20(__SHIFT) 383 }; 384 385 static const struct dcn20_dsc_mask dsc_mask = { 386 DSC_REG_LIST_SH_MASK_DCN20(_MASK) 387 }; 388 389 #define ipp_regs(id)\ 390 [id] = {\ 391 IPP_REG_LIST_DCN20(id),\ 392 } 393 394 static const struct dcn10_ipp_registers ipp_regs[] = { 395 ipp_regs(0), 396 ipp_regs(1), 397 ipp_regs(2), 398 ipp_regs(3), 399 }; 400 401 static const struct dcn10_ipp_shift ipp_shift = { 402 IPP_MASK_SH_LIST_DCN20(__SHIFT) 403 }; 404 405 static const struct dcn10_ipp_mask ipp_mask = { 406 IPP_MASK_SH_LIST_DCN20(_MASK), 407 }; 408 409 #define opp_regs(id)\ 410 [id] = {\ 411 OPP_REG_LIST_DCN20(id),\ 412 } 413 414 415 #define aux_engine_regs(id)\ 416 [id] = {\ 417 AUX_COMMON_REG_LIST0(id), \ 418 .AUXN_IMPCAL = 0, \ 419 .AUXP_IMPCAL = 0, \ 420 .AUX_RESET_MASK = DP_AUX0_AUX_CONTROL__AUX_RESET_MASK, \ 421 } 422 423 static const struct dce110_aux_registers aux_engine_regs[] = { 424 aux_engine_regs(0), 425 aux_engine_regs(1), 426 aux_engine_regs(2), 427 aux_engine_regs(3), 428 aux_engine_regs(4), 429 }; 430 431 #define tf_regs(id)\ 432 [id] = {\ 433 TF_REG_LIST_DCN20(id),\ 434 TF_REG_LIST_DCN20_COMMON_APPEND(id),\ 435 } 436 437 static const struct dcn2_dpp_registers tf_regs[] = { 438 tf_regs(0), 439 tf_regs(1), 440 tf_regs(2), 441 tf_regs(3), 442 }; 443 444 static const struct dcn2_dpp_shift tf_shift = { 445 TF_REG_LIST_SH_MASK_DCN20(__SHIFT), 446 TF_DEBUG_REG_LIST_SH_DCN20 447 }; 448 449 static const struct dcn2_dpp_mask tf_mask = { 450 TF_REG_LIST_SH_MASK_DCN20(_MASK), 451 TF_DEBUG_REG_LIST_MASK_DCN20 452 }; 453 454 #define stream_enc_regs(id)\ 455 [id] = {\ 456 SE_DCN2_REG_LIST(id)\ 457 } 458 459 static const struct dcn10_stream_enc_registers stream_enc_regs[] = { 460 stream_enc_regs(0), 461 stream_enc_regs(1), 462 stream_enc_regs(2), 463 stream_enc_regs(3), 464 stream_enc_regs(4), 465 }; 466 467 static const struct dce110_aux_registers_shift aux_shift = { 468 DCN_AUX_MASK_SH_LIST(__SHIFT) 469 }; 470 471 static const struct dce110_aux_registers_mask aux_mask = { 472 DCN_AUX_MASK_SH_LIST(_MASK) 473 }; 474 475 static const struct dcn10_stream_encoder_shift se_shift = { 476 SE_COMMON_MASK_SH_LIST_DCN20(__SHIFT) 477 }; 478 479 static const struct dcn10_stream_encoder_mask se_mask = { 480 SE_COMMON_MASK_SH_LIST_DCN20(_MASK) 481 }; 482 483 static void dcn21_pp_smu_destroy(struct pp_smu_funcs **pp_smu); 484 485 static struct input_pixel_processor *dcn21_ipp_create( 486 struct dc_context *ctx, uint32_t inst) 487 { 488 struct dcn10_ipp *ipp = 489 kzalloc(sizeof(struct dcn10_ipp), GFP_KERNEL); 490 491 if (!ipp) { 492 BREAK_TO_DEBUGGER(); 493 return NULL; 494 } 495 496 dcn20_ipp_construct(ipp, ctx, inst, 497 &ipp_regs[inst], &ipp_shift, &ipp_mask); 498 return &ipp->base; 499 } 500 501 static struct dpp *dcn21_dpp_create( 502 struct dc_context *ctx, 503 uint32_t inst) 504 { 505 struct dcn20_dpp *dpp = 506 kzalloc(sizeof(struct dcn20_dpp), GFP_KERNEL); 507 508 if (!dpp) 509 return NULL; 510 511 if (dpp2_construct(dpp, ctx, inst, 512 &tf_regs[inst], &tf_shift, &tf_mask)) 513 return &dpp->base; 514 515 BREAK_TO_DEBUGGER(); 516 kfree(dpp); 517 return NULL; 518 } 519 520 static struct dce_aux *dcn21_aux_engine_create( 521 struct dc_context *ctx, 522 uint32_t inst) 523 { 524 struct aux_engine_dce110 *aux_engine = 525 kzalloc(sizeof(struct aux_engine_dce110), GFP_KERNEL); 526 527 if (!aux_engine) 528 return NULL; 529 530 dce110_aux_engine_construct(aux_engine, ctx, inst, 531 SW_AUX_TIMEOUT_PERIOD_MULTIPLIER * AUX_TIMEOUT_PERIOD, 532 &aux_engine_regs[inst], 533 &aux_mask, 534 &aux_shift, 535 ctx->dc->caps.extended_aux_timeout_support); 536 537 return &aux_engine->base; 538 } 539 540 #define i2c_inst_regs(id) { I2C_HW_ENGINE_COMMON_REG_LIST(id) } 541 542 static const struct dce_i2c_registers i2c_hw_regs[] = { 543 i2c_inst_regs(1), 544 i2c_inst_regs(2), 545 i2c_inst_regs(3), 546 i2c_inst_regs(4), 547 i2c_inst_regs(5), 548 }; 549 550 static const struct dce_i2c_shift i2c_shifts = { 551 I2C_COMMON_MASK_SH_LIST_DCN2(__SHIFT) 552 }; 553 554 static const struct dce_i2c_mask i2c_masks = { 555 I2C_COMMON_MASK_SH_LIST_DCN2(_MASK) 556 }; 557 558 static struct dce_i2c_hw *dcn21_i2c_hw_create(struct dc_context *ctx, 559 uint32_t inst) 560 { 561 struct dce_i2c_hw *dce_i2c_hw = 562 kzalloc(sizeof(struct dce_i2c_hw), GFP_KERNEL); 563 564 if (!dce_i2c_hw) 565 return NULL; 566 567 dcn2_i2c_hw_construct(dce_i2c_hw, ctx, inst, 568 &i2c_hw_regs[inst], &i2c_shifts, &i2c_masks); 569 570 return dce_i2c_hw; 571 } 572 573 static const struct resource_caps res_cap_rn = { 574 .num_timing_generator = 4, 575 .num_opp = 4, 576 .num_video_plane = 4, 577 .num_audio = 4, // 4 audio endpoints. 4 audio streams 578 .num_stream_encoder = 5, 579 .num_pll = 5, // maybe 3 because the last two used for USB-c 580 .num_dwb = 1, 581 .num_ddc = 5, 582 .num_vmid = 16, 583 .num_dsc = 3, 584 }; 585 586 #ifdef DIAGS_BUILD 587 static const struct resource_caps res_cap_rn_FPGA_4pipe = { 588 .num_timing_generator = 4, 589 .num_opp = 4, 590 .num_video_plane = 4, 591 .num_audio = 7, 592 .num_stream_encoder = 4, 593 .num_pll = 4, 594 .num_dwb = 1, 595 .num_ddc = 4, 596 .num_dsc = 0, 597 }; 598 599 static const struct resource_caps res_cap_rn_FPGA_2pipe_dsc = { 600 .num_timing_generator = 2, 601 .num_opp = 2, 602 .num_video_plane = 2, 603 .num_audio = 7, 604 .num_stream_encoder = 2, 605 .num_pll = 4, 606 .num_dwb = 1, 607 .num_ddc = 4, 608 .num_dsc = 2, 609 }; 610 #endif 611 612 static const struct dc_plane_cap plane_cap = { 613 .type = DC_PLANE_TYPE_DCN_UNIVERSAL, 614 .blends_with_above = true, 615 .blends_with_below = true, 616 .per_pixel_alpha = true, 617 618 .pixel_format_support = { 619 .argb8888 = true, 620 .nv12 = true, 621 .fp16 = true, 622 .p010 = true 623 }, 624 625 .max_upscale_factor = { 626 .argb8888 = 16000, 627 .nv12 = 16000, 628 .fp16 = 16000 629 }, 630 631 .max_downscale_factor = { 632 .argb8888 = 250, 633 .nv12 = 250, 634 .fp16 = 250 635 }, 636 64, 637 64 638 }; 639 640 static const struct dc_debug_options debug_defaults_drv = { 641 .disable_dmcu = false, 642 .force_abm_enable = false, 643 .timing_trace = false, 644 .clock_trace = true, 645 .disable_pplib_clock_request = true, 646 .min_disp_clk_khz = 100000, 647 .pipe_split_policy = MPC_SPLIT_AVOID_MULT_DISP, 648 .force_single_disp_pipe_split = false, 649 .disable_dcc = DCC_ENABLE, 650 .vsr_support = true, 651 .performance_trace = false, 652 .max_downscale_src_width = 4096, 653 .disable_pplib_wm_range = false, 654 .scl_reset_length10 = true, 655 .sanity_checks = true, 656 .disable_48mhz_pwrdwn = false, 657 .usbc_combo_phy_reset_wa = true, 658 .dmub_command_table = true, 659 .use_max_lb = true, 660 }; 661 662 static const struct dc_debug_options debug_defaults_diags = { 663 .disable_dmcu = false, 664 .force_abm_enable = false, 665 .timing_trace = true, 666 .clock_trace = true, 667 .disable_dpp_power_gate = true, 668 .disable_hubp_power_gate = true, 669 .disable_clock_gate = true, 670 .disable_pplib_clock_request = true, 671 .disable_pplib_wm_range = true, 672 .disable_stutter = true, 673 .disable_48mhz_pwrdwn = true, 674 .enable_tri_buf = true, 675 .use_max_lb = true 676 }; 677 678 static const struct dc_panel_config panel_config_defaults = { 679 .psr = { 680 .disable_psr = false, 681 .disallow_psrsu = false, 682 }, 683 .ilr = { 684 .optimize_edp_link_rate = true, 685 }, 686 }; 687 688 enum dcn20_clk_src_array_id { 689 DCN20_CLK_SRC_PLL0, 690 DCN20_CLK_SRC_PLL1, 691 DCN20_CLK_SRC_PLL2, 692 DCN20_CLK_SRC_PLL3, 693 DCN20_CLK_SRC_PLL4, 694 DCN20_CLK_SRC_TOTAL_DCN21 695 }; 696 697 static void dcn21_resource_destruct(struct dcn21_resource_pool *pool) 698 { 699 unsigned int i; 700 701 for (i = 0; i < pool->base.stream_enc_count; i++) { 702 if (pool->base.stream_enc[i] != NULL) { 703 kfree(DCN10STRENC_FROM_STRENC(pool->base.stream_enc[i])); 704 pool->base.stream_enc[i] = NULL; 705 } 706 } 707 708 for (i = 0; i < pool->base.res_cap->num_dsc; i++) { 709 if (pool->base.dscs[i] != NULL) 710 dcn20_dsc_destroy(&pool->base.dscs[i]); 711 } 712 713 if (pool->base.mpc != NULL) { 714 kfree(TO_DCN20_MPC(pool->base.mpc)); 715 pool->base.mpc = NULL; 716 } 717 if (pool->base.hubbub != NULL) { 718 kfree(pool->base.hubbub); 719 pool->base.hubbub = NULL; 720 } 721 for (i = 0; i < pool->base.pipe_count; i++) { 722 if (pool->base.dpps[i] != NULL) 723 dcn20_dpp_destroy(&pool->base.dpps[i]); 724 725 if (pool->base.ipps[i] != NULL) 726 pool->base.ipps[i]->funcs->ipp_destroy(&pool->base.ipps[i]); 727 728 if (pool->base.hubps[i] != NULL) { 729 kfree(TO_DCN20_HUBP(pool->base.hubps[i])); 730 pool->base.hubps[i] = NULL; 731 } 732 733 if (pool->base.irqs != NULL) { 734 dal_irq_service_destroy(&pool->base.irqs); 735 } 736 } 737 738 for (i = 0; i < pool->base.res_cap->num_ddc; i++) { 739 if (pool->base.engines[i] != NULL) 740 dce110_engine_destroy(&pool->base.engines[i]); 741 if (pool->base.hw_i2cs[i] != NULL) { 742 kfree(pool->base.hw_i2cs[i]); 743 pool->base.hw_i2cs[i] = NULL; 744 } 745 if (pool->base.sw_i2cs[i] != NULL) { 746 kfree(pool->base.sw_i2cs[i]); 747 pool->base.sw_i2cs[i] = NULL; 748 } 749 } 750 751 for (i = 0; i < pool->base.res_cap->num_opp; i++) { 752 if (pool->base.opps[i] != NULL) 753 pool->base.opps[i]->funcs->opp_destroy(&pool->base.opps[i]); 754 } 755 756 for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) { 757 if (pool->base.timing_generators[i] != NULL) { 758 kfree(DCN10TG_FROM_TG(pool->base.timing_generators[i])); 759 pool->base.timing_generators[i] = NULL; 760 } 761 } 762 763 for (i = 0; i < pool->base.res_cap->num_dwb; i++) { 764 if (pool->base.dwbc[i] != NULL) { 765 kfree(TO_DCN20_DWBC(pool->base.dwbc[i])); 766 pool->base.dwbc[i] = NULL; 767 } 768 if (pool->base.mcif_wb[i] != NULL) { 769 kfree(TO_DCN20_MMHUBBUB(pool->base.mcif_wb[i])); 770 pool->base.mcif_wb[i] = NULL; 771 } 772 } 773 774 for (i = 0; i < pool->base.audio_count; i++) { 775 if (pool->base.audios[i]) 776 dce_aud_destroy(&pool->base.audios[i]); 777 } 778 779 for (i = 0; i < pool->base.clk_src_count; i++) { 780 if (pool->base.clock_sources[i] != NULL) { 781 dcn20_clock_source_destroy(&pool->base.clock_sources[i]); 782 pool->base.clock_sources[i] = NULL; 783 } 784 } 785 786 if (pool->base.dp_clock_source != NULL) { 787 dcn20_clock_source_destroy(&pool->base.dp_clock_source); 788 pool->base.dp_clock_source = NULL; 789 } 790 791 if (pool->base.abm != NULL) { 792 if (pool->base.abm->ctx->dc->config.disable_dmcu) 793 dmub_abm_destroy(&pool->base.abm); 794 else 795 dce_abm_destroy(&pool->base.abm); 796 } 797 798 if (pool->base.dmcu != NULL) 799 dce_dmcu_destroy(&pool->base.dmcu); 800 801 if (pool->base.psr != NULL) 802 dmub_psr_destroy(&pool->base.psr); 803 804 if (pool->base.dccg != NULL) 805 dcn_dccg_destroy(&pool->base.dccg); 806 807 if (pool->base.pp_smu != NULL) 808 dcn21_pp_smu_destroy(&pool->base.pp_smu); 809 } 810 811 bool dcn21_fast_validate_bw(struct dc *dc, 812 struct dc_state *context, 813 display_e2e_pipe_params_st *pipes, 814 int *pipe_cnt_out, 815 int *pipe_split_from, 816 int *vlevel_out, 817 bool fast_validate) 818 { 819 bool out = false; 820 int split[MAX_PIPES] = { 0 }; 821 int pipe_cnt, i, pipe_idx, vlevel; 822 823 ASSERT(pipes); 824 if (!pipes) 825 return false; 826 827 dcn20_merge_pipes_for_validate(dc, context); 828 829 DC_FP_START(); 830 pipe_cnt = dc->res_pool->funcs->populate_dml_pipes(dc, context, pipes, fast_validate); 831 DC_FP_END(); 832 833 *pipe_cnt_out = pipe_cnt; 834 835 if (!pipe_cnt) { 836 out = true; 837 goto validate_out; 838 } 839 /* 840 * DML favors voltage over p-state, but we're more interested in 841 * supporting p-state over voltage. We can't support p-state in 842 * prefetch mode > 0 so try capping the prefetch mode to start. 843 */ 844 context->bw_ctx.dml.soc.allow_dram_self_refresh_or_dram_clock_change_in_vblank = 845 dm_allow_self_refresh_and_mclk_switch; 846 vlevel = dml_get_voltage_level(&context->bw_ctx.dml, pipes, pipe_cnt); 847 848 if (vlevel > context->bw_ctx.dml.soc.num_states) { 849 /* 850 * If mode is unsupported or there's still no p-state support then 851 * fall back to favoring voltage. 852 * 853 * We don't actually support prefetch mode 2, so require that we 854 * at least support prefetch mode 1. 855 */ 856 context->bw_ctx.dml.soc.allow_dram_self_refresh_or_dram_clock_change_in_vblank = 857 dm_allow_self_refresh; 858 vlevel = dml_get_voltage_level(&context->bw_ctx.dml, pipes, pipe_cnt); 859 if (vlevel > context->bw_ctx.dml.soc.num_states) 860 goto validate_fail; 861 } 862 863 vlevel = dcn20_validate_apply_pipe_split_flags(dc, context, vlevel, split, NULL); 864 865 for (i = 0, pipe_idx = 0; i < dc->res_pool->pipe_count; i++) { 866 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 867 struct pipe_ctx *mpo_pipe = pipe->bottom_pipe; 868 struct vba_vars_st *vba = &context->bw_ctx.dml.vba; 869 870 if (!pipe->stream) 871 continue; 872 873 /* We only support full screen mpo with ODM */ 874 if (vba->ODMCombineEnabled[vba->pipe_plane[pipe_idx]] != dm_odm_combine_mode_disabled 875 && pipe->plane_state && mpo_pipe 876 && memcmp(&mpo_pipe->plane_res.scl_data.recout, 877 &pipe->plane_res.scl_data.recout, 878 sizeof(struct rect)) != 0) { 879 ASSERT(mpo_pipe->plane_state != pipe->plane_state); 880 goto validate_fail; 881 } 882 pipe_idx++; 883 } 884 885 /*initialize pipe_just_split_from to invalid idx*/ 886 for (i = 0; i < MAX_PIPES; i++) 887 pipe_split_from[i] = -1; 888 889 for (i = 0, pipe_idx = -1; i < dc->res_pool->pipe_count; i++) { 890 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 891 struct pipe_ctx *hsplit_pipe = pipe->bottom_pipe; 892 893 if (!pipe->stream || pipe_split_from[i] >= 0) 894 continue; 895 896 pipe_idx++; 897 898 if (!pipe->top_pipe && !pipe->plane_state && context->bw_ctx.dml.vba.ODMCombineEnabled[pipe_idx]) { 899 hsplit_pipe = dcn20_find_secondary_pipe(dc, &context->res_ctx, dc->res_pool, pipe); 900 ASSERT(hsplit_pipe); 901 if (!dcn20_split_stream_for_odm( 902 dc, &context->res_ctx, 903 pipe, hsplit_pipe)) 904 goto validate_fail; 905 pipe_split_from[hsplit_pipe->pipe_idx] = pipe_idx; 906 dcn20_build_mapped_resource(dc, context, pipe->stream); 907 } 908 909 if (!pipe->plane_state) 910 continue; 911 /* Skip 2nd half of already split pipe */ 912 if (pipe->top_pipe && pipe->plane_state == pipe->top_pipe->plane_state) 913 continue; 914 915 if (split[i] == 2) { 916 if (!hsplit_pipe || hsplit_pipe->plane_state != pipe->plane_state) { 917 /* pipe not split previously needs split */ 918 hsplit_pipe = dcn20_find_secondary_pipe(dc, &context->res_ctx, dc->res_pool, pipe); 919 ASSERT(hsplit_pipe); 920 if (!hsplit_pipe) { 921 DC_FP_START(); 922 dcn20_fpu_adjust_dppclk(&context->bw_ctx.dml.vba, vlevel, context->bw_ctx.dml.vba.maxMpcComb, pipe_idx, true); 923 DC_FP_END(); 924 continue; 925 } 926 if (context->bw_ctx.dml.vba.ODMCombineEnabled[pipe_idx]) { 927 if (!dcn20_split_stream_for_odm( 928 dc, &context->res_ctx, 929 pipe, hsplit_pipe)) 930 goto validate_fail; 931 dcn20_build_mapped_resource(dc, context, pipe->stream); 932 } else { 933 dcn20_split_stream_for_mpc( 934 &context->res_ctx, dc->res_pool, 935 pipe, hsplit_pipe); 936 resource_build_scaling_params(pipe); 937 resource_build_scaling_params(hsplit_pipe); 938 } 939 pipe_split_from[hsplit_pipe->pipe_idx] = pipe_idx; 940 } 941 } else if (hsplit_pipe && hsplit_pipe->plane_state == pipe->plane_state) { 942 /* merge should already have been done */ 943 ASSERT(0); 944 } 945 } 946 /* Actual dsc count per stream dsc validation*/ 947 if (!dcn20_validate_dsc(dc, context)) { 948 context->bw_ctx.dml.vba.ValidationStatus[context->bw_ctx.dml.vba.soc.num_states] = 949 DML_FAIL_DSC_VALIDATION_FAILURE; 950 goto validate_fail; 951 } 952 953 *vlevel_out = vlevel; 954 955 out = true; 956 goto validate_out; 957 958 validate_fail: 959 out = false; 960 961 validate_out: 962 return out; 963 } 964 965 /* 966 * Some of the functions further below use the FPU, so we need to wrap this 967 * with DC_FP_START()/DC_FP_END(). Use the same approach as for 968 * dcn20_validate_bandwidth in dcn20_resource.c. 969 */ 970 static bool dcn21_validate_bandwidth(struct dc *dc, struct dc_state *context, 971 bool fast_validate) 972 { 973 bool voltage_supported; 974 DC_FP_START(); 975 voltage_supported = dcn21_validate_bandwidth_fp(dc, context, fast_validate); 976 DC_FP_END(); 977 return voltage_supported; 978 } 979 980 static void dcn21_destroy_resource_pool(struct resource_pool **pool) 981 { 982 struct dcn21_resource_pool *dcn21_pool = TO_DCN21_RES_POOL(*pool); 983 984 dcn21_resource_destruct(dcn21_pool); 985 kfree(dcn21_pool); 986 *pool = NULL; 987 } 988 989 static struct clock_source *dcn21_clock_source_create( 990 struct dc_context *ctx, 991 struct dc_bios *bios, 992 enum clock_source_id id, 993 const struct dce110_clk_src_regs *regs, 994 bool dp_clk_src) 995 { 996 struct dce110_clk_src *clk_src = 997 kzalloc(sizeof(struct dce110_clk_src), GFP_KERNEL); 998 999 if (!clk_src) 1000 return NULL; 1001 1002 if (dcn20_clk_src_construct(clk_src, ctx, bios, id, 1003 regs, &cs_shift, &cs_mask)) { 1004 clk_src->base.dp_clk_src = dp_clk_src; 1005 return &clk_src->base; 1006 } 1007 1008 kfree(clk_src); 1009 BREAK_TO_DEBUGGER(); 1010 return NULL; 1011 } 1012 1013 static struct hubp *dcn21_hubp_create( 1014 struct dc_context *ctx, 1015 uint32_t inst) 1016 { 1017 struct dcn21_hubp *hubp21 = 1018 kzalloc(sizeof(struct dcn21_hubp), GFP_KERNEL); 1019 1020 if (!hubp21) 1021 return NULL; 1022 1023 if (hubp21_construct(hubp21, ctx, inst, 1024 &hubp_regs[inst], &hubp_shift, &hubp_mask)) 1025 return &hubp21->base; 1026 1027 BREAK_TO_DEBUGGER(); 1028 kfree(hubp21); 1029 return NULL; 1030 } 1031 1032 static struct hubbub *dcn21_hubbub_create(struct dc_context *ctx) 1033 { 1034 int i; 1035 1036 struct dcn20_hubbub *hubbub = kzalloc(sizeof(struct dcn20_hubbub), 1037 GFP_KERNEL); 1038 1039 if (!hubbub) 1040 return NULL; 1041 1042 hubbub21_construct(hubbub, ctx, 1043 &hubbub_reg, 1044 &hubbub_shift, 1045 &hubbub_mask); 1046 1047 for (i = 0; i < res_cap_rn.num_vmid; i++) { 1048 struct dcn20_vmid *vmid = &hubbub->vmid[i]; 1049 1050 vmid->ctx = ctx; 1051 1052 vmid->regs = &vmid_regs[i]; 1053 vmid->shifts = &vmid_shifts; 1054 vmid->masks = &vmid_masks; 1055 } 1056 hubbub->num_vmid = res_cap_rn.num_vmid; 1057 1058 return &hubbub->base; 1059 } 1060 1061 static struct output_pixel_processor *dcn21_opp_create(struct dc_context *ctx, 1062 uint32_t inst) 1063 { 1064 struct dcn20_opp *opp = 1065 kzalloc(sizeof(struct dcn20_opp), GFP_KERNEL); 1066 1067 if (!opp) { 1068 BREAK_TO_DEBUGGER(); 1069 return NULL; 1070 } 1071 1072 dcn20_opp_construct(opp, ctx, inst, 1073 &opp_regs[inst], &opp_shift, &opp_mask); 1074 return &opp->base; 1075 } 1076 1077 static struct timing_generator *dcn21_timing_generator_create(struct dc_context *ctx, 1078 uint32_t instance) 1079 { 1080 struct optc *tgn10 = 1081 kzalloc(sizeof(struct optc), GFP_KERNEL); 1082 1083 if (!tgn10) 1084 return NULL; 1085 1086 tgn10->base.inst = instance; 1087 tgn10->base.ctx = ctx; 1088 1089 tgn10->tg_regs = &tg_regs[instance]; 1090 tgn10->tg_shift = &tg_shift; 1091 tgn10->tg_mask = &tg_mask; 1092 1093 dcn20_timing_generator_init(tgn10); 1094 1095 return &tgn10->base; 1096 } 1097 1098 static struct mpc *dcn21_mpc_create(struct dc_context *ctx) 1099 { 1100 struct dcn20_mpc *mpc20 = kzalloc(sizeof(struct dcn20_mpc), 1101 GFP_KERNEL); 1102 1103 if (!mpc20) 1104 return NULL; 1105 1106 dcn20_mpc_construct(mpc20, ctx, 1107 &mpc_regs, 1108 &mpc_shift, 1109 &mpc_mask, 1110 6); 1111 1112 return &mpc20->base; 1113 } 1114 1115 static void read_dce_straps( 1116 struct dc_context *ctx, 1117 struct resource_straps *straps) 1118 { 1119 generic_reg_get(ctx, mmDC_PINSTRAPS + BASE(mmDC_PINSTRAPS_BASE_IDX), 1120 FN(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO), &straps->dc_pinstraps_audio); 1121 1122 } 1123 1124 1125 static struct display_stream_compressor *dcn21_dsc_create(struct dc_context *ctx, 1126 uint32_t inst) 1127 { 1128 struct dcn20_dsc *dsc = 1129 kzalloc(sizeof(struct dcn20_dsc), GFP_KERNEL); 1130 1131 if (!dsc) { 1132 BREAK_TO_DEBUGGER(); 1133 return NULL; 1134 } 1135 1136 dsc2_construct(dsc, ctx, inst, &dsc_regs[inst], &dsc_shift, &dsc_mask); 1137 return &dsc->base; 1138 } 1139 1140 static struct pp_smu_funcs *dcn21_pp_smu_create(struct dc_context *ctx) 1141 { 1142 struct pp_smu_funcs *pp_smu = kzalloc(sizeof(*pp_smu), GFP_KERNEL); 1143 1144 if (!pp_smu) 1145 return pp_smu; 1146 1147 dm_pp_get_funcs(ctx, pp_smu); 1148 1149 if (pp_smu->ctx.ver != PP_SMU_VER_RN) 1150 pp_smu = memset(pp_smu, 0, sizeof(struct pp_smu_funcs)); 1151 1152 1153 return pp_smu; 1154 } 1155 1156 static void dcn21_pp_smu_destroy(struct pp_smu_funcs **pp_smu) 1157 { 1158 if (pp_smu && *pp_smu) { 1159 kfree(*pp_smu); 1160 *pp_smu = NULL; 1161 } 1162 } 1163 1164 static struct audio *dcn21_create_audio( 1165 struct dc_context *ctx, unsigned int inst) 1166 { 1167 return dce_audio_create(ctx, inst, 1168 &audio_regs[inst], &audio_shift, &audio_mask); 1169 } 1170 1171 static struct dc_cap_funcs cap_funcs = { 1172 .get_dcc_compression_cap = dcn20_get_dcc_compression_cap 1173 }; 1174 1175 static struct stream_encoder *dcn21_stream_encoder_create(enum engine_id eng_id, 1176 struct dc_context *ctx) 1177 { 1178 struct dcn10_stream_encoder *enc1 = 1179 kzalloc(sizeof(struct dcn10_stream_encoder), GFP_KERNEL); 1180 1181 if (!enc1) 1182 return NULL; 1183 1184 dcn20_stream_encoder_construct(enc1, ctx, ctx->dc_bios, eng_id, 1185 &stream_enc_regs[eng_id], 1186 &se_shift, &se_mask); 1187 1188 return &enc1->base; 1189 } 1190 1191 static const struct dce_hwseq_registers hwseq_reg = { 1192 HWSEQ_DCN21_REG_LIST() 1193 }; 1194 1195 static const struct dce_hwseq_shift hwseq_shift = { 1196 HWSEQ_DCN21_MASK_SH_LIST(__SHIFT) 1197 }; 1198 1199 static const struct dce_hwseq_mask hwseq_mask = { 1200 HWSEQ_DCN21_MASK_SH_LIST(_MASK) 1201 }; 1202 1203 static struct dce_hwseq *dcn21_hwseq_create( 1204 struct dc_context *ctx) 1205 { 1206 struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL); 1207 1208 if (hws) { 1209 hws->ctx = ctx; 1210 hws->regs = &hwseq_reg; 1211 hws->shifts = &hwseq_shift; 1212 hws->masks = &hwseq_mask; 1213 hws->wa.DEGVIDCN21 = true; 1214 hws->wa.disallow_self_refresh_during_multi_plane_transition = true; 1215 } 1216 return hws; 1217 } 1218 1219 static const struct resource_create_funcs res_create_funcs = { 1220 .read_dce_straps = read_dce_straps, 1221 .create_audio = dcn21_create_audio, 1222 .create_stream_encoder = dcn21_stream_encoder_create, 1223 .create_hwseq = dcn21_hwseq_create, 1224 }; 1225 1226 static const struct resource_create_funcs res_create_maximus_funcs = { 1227 .read_dce_straps = NULL, 1228 .create_audio = NULL, 1229 .create_stream_encoder = NULL, 1230 .create_hwseq = dcn21_hwseq_create, 1231 }; 1232 1233 static const struct encoder_feature_support link_enc_feature = { 1234 .max_hdmi_deep_color = COLOR_DEPTH_121212, 1235 .max_hdmi_pixel_clock = 600000, 1236 .hdmi_ycbcr420_supported = true, 1237 .dp_ycbcr420_supported = true, 1238 .fec_supported = true, 1239 .flags.bits.IS_HBR2_CAPABLE = true, 1240 .flags.bits.IS_HBR3_CAPABLE = true, 1241 .flags.bits.IS_TPS3_CAPABLE = true, 1242 .flags.bits.IS_TPS4_CAPABLE = true 1243 }; 1244 1245 1246 #define link_regs(id, phyid)\ 1247 [id] = {\ 1248 LE_DCN2_REG_LIST(id), \ 1249 UNIPHY_DCN2_REG_LIST(phyid), \ 1250 DPCS_DCN21_REG_LIST(id), \ 1251 SRI(DP_DPHY_INTERNAL_CTRL, DP, id) \ 1252 } 1253 1254 static const struct dcn10_link_enc_registers link_enc_regs[] = { 1255 link_regs(0, A), 1256 link_regs(1, B), 1257 link_regs(2, C), 1258 link_regs(3, D), 1259 link_regs(4, E), 1260 }; 1261 1262 static const struct dce_panel_cntl_registers panel_cntl_regs[] = { 1263 { DCN_PANEL_CNTL_REG_LIST() } 1264 }; 1265 1266 static const struct dce_panel_cntl_shift panel_cntl_shift = { 1267 DCE_PANEL_CNTL_MASK_SH_LIST(__SHIFT) 1268 }; 1269 1270 static const struct dce_panel_cntl_mask panel_cntl_mask = { 1271 DCE_PANEL_CNTL_MASK_SH_LIST(_MASK) 1272 }; 1273 1274 #define aux_regs(id)\ 1275 [id] = {\ 1276 DCN2_AUX_REG_LIST(id)\ 1277 } 1278 1279 static const struct dcn10_link_enc_aux_registers link_enc_aux_regs[] = { 1280 aux_regs(0), 1281 aux_regs(1), 1282 aux_regs(2), 1283 aux_regs(3), 1284 aux_regs(4) 1285 }; 1286 1287 #define hpd_regs(id)\ 1288 [id] = {\ 1289 HPD_REG_LIST(id)\ 1290 } 1291 1292 static const struct dcn10_link_enc_hpd_registers link_enc_hpd_regs[] = { 1293 hpd_regs(0), 1294 hpd_regs(1), 1295 hpd_regs(2), 1296 hpd_regs(3), 1297 hpd_regs(4) 1298 }; 1299 1300 static const struct dcn10_link_enc_shift le_shift = { 1301 LINK_ENCODER_MASK_SH_LIST_DCN20(__SHIFT),\ 1302 DPCS_DCN21_MASK_SH_LIST(__SHIFT) 1303 }; 1304 1305 static const struct dcn10_link_enc_mask le_mask = { 1306 LINK_ENCODER_MASK_SH_LIST_DCN20(_MASK),\ 1307 DPCS_DCN21_MASK_SH_LIST(_MASK) 1308 }; 1309 1310 static int map_transmitter_id_to_phy_instance( 1311 enum transmitter transmitter) 1312 { 1313 switch (transmitter) { 1314 case TRANSMITTER_UNIPHY_A: 1315 return 0; 1316 break; 1317 case TRANSMITTER_UNIPHY_B: 1318 return 1; 1319 break; 1320 case TRANSMITTER_UNIPHY_C: 1321 return 2; 1322 break; 1323 case TRANSMITTER_UNIPHY_D: 1324 return 3; 1325 break; 1326 case TRANSMITTER_UNIPHY_E: 1327 return 4; 1328 break; 1329 default: 1330 ASSERT(0); 1331 return 0; 1332 } 1333 } 1334 1335 static struct link_encoder *dcn21_link_encoder_create( 1336 struct dc_context *ctx, 1337 const struct encoder_init_data *enc_init_data) 1338 { 1339 struct dcn21_link_encoder *enc21 = 1340 kzalloc(sizeof(struct dcn21_link_encoder), GFP_KERNEL); 1341 int link_regs_id; 1342 1343 if (!enc21) 1344 return NULL; 1345 1346 link_regs_id = 1347 map_transmitter_id_to_phy_instance(enc_init_data->transmitter); 1348 1349 dcn21_link_encoder_construct(enc21, 1350 enc_init_data, 1351 &link_enc_feature, 1352 &link_enc_regs[link_regs_id], 1353 &link_enc_aux_regs[enc_init_data->channel - 1], 1354 &link_enc_hpd_regs[enc_init_data->hpd_source], 1355 &le_shift, 1356 &le_mask); 1357 1358 return &enc21->enc10.base; 1359 } 1360 1361 static struct panel_cntl *dcn21_panel_cntl_create(const struct panel_cntl_init_data *init_data) 1362 { 1363 struct dce_panel_cntl *panel_cntl = 1364 kzalloc(sizeof(struct dce_panel_cntl), GFP_KERNEL); 1365 1366 if (!panel_cntl) 1367 return NULL; 1368 1369 dce_panel_cntl_construct(panel_cntl, 1370 init_data, 1371 &panel_cntl_regs[init_data->inst], 1372 &panel_cntl_shift, 1373 &panel_cntl_mask); 1374 1375 return &panel_cntl->base; 1376 } 1377 1378 static void dcn21_get_panel_config_defaults(struct dc_panel_config *panel_config) 1379 { 1380 *panel_config = panel_config_defaults; 1381 } 1382 1383 #define CTX ctx 1384 1385 #define REG(reg_name) \ 1386 (DCN_BASE.instance[0].segment[mm ## reg_name ## _BASE_IDX] + mm ## reg_name) 1387 1388 static uint32_t read_pipe_fuses(struct dc_context *ctx) 1389 { 1390 uint32_t value = REG_READ(CC_DC_PIPE_DIS); 1391 /* RV1 support max 4 pipes */ 1392 value = value & 0xf; 1393 return value; 1394 } 1395 1396 static enum dc_status dcn21_patch_unknown_plane_state(struct dc_plane_state *plane_state) 1397 { 1398 enum dc_status result = DC_OK; 1399 1400 if (plane_state->ctx->dc->debug.disable_dcc == DCC_ENABLE) { 1401 plane_state->dcc.enable = 1; 1402 /* align to our worst case block width */ 1403 plane_state->dcc.meta_pitch = ((plane_state->src_rect.width + 1023) / 1024) * 1024; 1404 } 1405 result = dcn20_patch_unknown_plane_state(plane_state); 1406 return result; 1407 } 1408 1409 static const struct resource_funcs dcn21_res_pool_funcs = { 1410 .destroy = dcn21_destroy_resource_pool, 1411 .link_enc_create = dcn21_link_encoder_create, 1412 .panel_cntl_create = dcn21_panel_cntl_create, 1413 .validate_bandwidth = dcn21_validate_bandwidth, 1414 .populate_dml_pipes = dcn21_populate_dml_pipes_from_context, 1415 .add_stream_to_ctx = dcn20_add_stream_to_ctx, 1416 .add_dsc_to_stream_resource = dcn20_add_dsc_to_stream_resource, 1417 .remove_stream_from_ctx = dcn20_remove_stream_from_ctx, 1418 .acquire_idle_pipe_for_layer = dcn20_acquire_idle_pipe_for_layer, 1419 .populate_dml_writeback_from_context = dcn20_populate_dml_writeback_from_context, 1420 .patch_unknown_plane_state = dcn21_patch_unknown_plane_state, 1421 .set_mcif_arb_params = dcn20_set_mcif_arb_params, 1422 .find_first_free_match_stream_enc_for_link = dcn10_find_first_free_match_stream_enc_for_link, 1423 .update_bw_bounding_box = dcn21_update_bw_bounding_box, 1424 .get_panel_config_defaults = dcn21_get_panel_config_defaults, 1425 }; 1426 1427 static bool dcn21_resource_construct( 1428 uint8_t num_virtual_links, 1429 struct dc *dc, 1430 struct dcn21_resource_pool *pool) 1431 { 1432 int i, j; 1433 struct dc_context *ctx = dc->ctx; 1434 struct irq_service_init_data init_data; 1435 uint32_t pipe_fuses = read_pipe_fuses(ctx); 1436 uint32_t num_pipes; 1437 1438 ctx->dc_bios->regs = &bios_regs; 1439 1440 pool->base.res_cap = &res_cap_rn; 1441 #ifdef DIAGS_BUILD 1442 if (IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment)) 1443 //pool->base.res_cap = &res_cap_nv10_FPGA_2pipe_dsc; 1444 pool->base.res_cap = &res_cap_rn_FPGA_4pipe; 1445 #endif 1446 1447 pool->base.funcs = &dcn21_res_pool_funcs; 1448 1449 /************************************************* 1450 * Resource + asic cap harcoding * 1451 *************************************************/ 1452 pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE; 1453 1454 /* max pipe num for ASIC before check pipe fuses */ 1455 pool->base.pipe_count = pool->base.res_cap->num_timing_generator; 1456 1457 dc->caps.max_downscale_ratio = 200; 1458 dc->caps.i2c_speed_in_khz = 100; 1459 dc->caps.i2c_speed_in_khz_hdcp = 5; /*1.4 w/a applied by default*/ 1460 dc->caps.max_cursor_size = 256; 1461 dc->caps.min_horizontal_blanking_period = 80; 1462 dc->caps.dmdata_alloc_size = 2048; 1463 1464 dc->caps.max_slave_planes = 1; 1465 dc->caps.max_slave_yuv_planes = 1; 1466 dc->caps.max_slave_rgb_planes = 1; 1467 dc->caps.post_blend_color_processing = true; 1468 dc->caps.force_dp_tps4_for_cp2520 = true; 1469 dc->caps.extended_aux_timeout_support = true; 1470 dc->caps.dmcub_support = true; 1471 dc->caps.is_apu = true; 1472 1473 /* Color pipeline capabilities */ 1474 dc->caps.color.dpp.dcn_arch = 1; 1475 dc->caps.color.dpp.input_lut_shared = 0; 1476 dc->caps.color.dpp.icsc = 1; 1477 dc->caps.color.dpp.dgam_ram = 1; 1478 dc->caps.color.dpp.dgam_rom_caps.srgb = 1; 1479 dc->caps.color.dpp.dgam_rom_caps.bt2020 = 1; 1480 dc->caps.color.dpp.dgam_rom_caps.gamma2_2 = 0; 1481 dc->caps.color.dpp.dgam_rom_caps.pq = 0; 1482 dc->caps.color.dpp.dgam_rom_caps.hlg = 0; 1483 dc->caps.color.dpp.post_csc = 0; 1484 dc->caps.color.dpp.gamma_corr = 0; 1485 dc->caps.color.dpp.dgam_rom_for_yuv = 1; 1486 1487 dc->caps.color.dpp.hw_3d_lut = 1; 1488 dc->caps.color.dpp.ogam_ram = 1; 1489 // no OGAM ROM on DCN2 1490 dc->caps.color.dpp.ogam_rom_caps.srgb = 0; 1491 dc->caps.color.dpp.ogam_rom_caps.bt2020 = 0; 1492 dc->caps.color.dpp.ogam_rom_caps.gamma2_2 = 0; 1493 dc->caps.color.dpp.ogam_rom_caps.pq = 0; 1494 dc->caps.color.dpp.ogam_rom_caps.hlg = 0; 1495 dc->caps.color.dpp.ocsc = 0; 1496 1497 dc->caps.color.mpc.gamut_remap = 0; 1498 dc->caps.color.mpc.num_3dluts = 0; 1499 dc->caps.color.mpc.shared_3d_lut = 0; 1500 dc->caps.color.mpc.ogam_ram = 1; 1501 dc->caps.color.mpc.ogam_rom_caps.srgb = 0; 1502 dc->caps.color.mpc.ogam_rom_caps.bt2020 = 0; 1503 dc->caps.color.mpc.ogam_rom_caps.gamma2_2 = 0; 1504 dc->caps.color.mpc.ogam_rom_caps.pq = 0; 1505 dc->caps.color.mpc.ogam_rom_caps.hlg = 0; 1506 dc->caps.color.mpc.ocsc = 1; 1507 1508 dc->caps.dp_hdmi21_pcon_support = true; 1509 1510 if (dc->ctx->dce_environment == DCE_ENV_PRODUCTION_DRV) 1511 dc->debug = debug_defaults_drv; 1512 else if (dc->ctx->dce_environment == DCE_ENV_FPGA_MAXIMUS) { 1513 pool->base.pipe_count = 4; 1514 dc->debug = debug_defaults_diags; 1515 } else 1516 dc->debug = debug_defaults_diags; 1517 1518 // Init the vm_helper 1519 if (dc->vm_helper) 1520 vm_helper_init(dc->vm_helper, 16); 1521 1522 /************************************************* 1523 * Create resources * 1524 *************************************************/ 1525 1526 pool->base.clock_sources[DCN20_CLK_SRC_PLL0] = 1527 dcn21_clock_source_create(ctx, ctx->dc_bios, 1528 CLOCK_SOURCE_COMBO_PHY_PLL0, 1529 &clk_src_regs[0], false); 1530 pool->base.clock_sources[DCN20_CLK_SRC_PLL1] = 1531 dcn21_clock_source_create(ctx, ctx->dc_bios, 1532 CLOCK_SOURCE_COMBO_PHY_PLL1, 1533 &clk_src_regs[1], false); 1534 pool->base.clock_sources[DCN20_CLK_SRC_PLL2] = 1535 dcn21_clock_source_create(ctx, ctx->dc_bios, 1536 CLOCK_SOURCE_COMBO_PHY_PLL2, 1537 &clk_src_regs[2], false); 1538 pool->base.clock_sources[DCN20_CLK_SRC_PLL3] = 1539 dcn21_clock_source_create(ctx, ctx->dc_bios, 1540 CLOCK_SOURCE_COMBO_PHY_PLL3, 1541 &clk_src_regs[3], false); 1542 pool->base.clock_sources[DCN20_CLK_SRC_PLL4] = 1543 dcn21_clock_source_create(ctx, ctx->dc_bios, 1544 CLOCK_SOURCE_COMBO_PHY_PLL4, 1545 &clk_src_regs[4], false); 1546 1547 pool->base.clk_src_count = DCN20_CLK_SRC_TOTAL_DCN21; 1548 1549 /* todo: not reuse phy_pll registers */ 1550 pool->base.dp_clock_source = 1551 dcn21_clock_source_create(ctx, ctx->dc_bios, 1552 CLOCK_SOURCE_ID_DP_DTO, 1553 &clk_src_regs[0], true); 1554 1555 for (i = 0; i < pool->base.clk_src_count; i++) { 1556 if (pool->base.clock_sources[i] == NULL) { 1557 dm_error("DC: failed to create clock sources!\n"); 1558 BREAK_TO_DEBUGGER(); 1559 goto create_fail; 1560 } 1561 } 1562 1563 pool->base.dccg = dccg21_create(ctx, &dccg_regs, &dccg_shift, &dccg_mask); 1564 if (pool->base.dccg == NULL) { 1565 dm_error("DC: failed to create dccg!\n"); 1566 BREAK_TO_DEBUGGER(); 1567 goto create_fail; 1568 } 1569 1570 if (!dc->config.disable_dmcu) { 1571 pool->base.dmcu = dcn21_dmcu_create(ctx, 1572 &dmcu_regs, 1573 &dmcu_shift, 1574 &dmcu_mask); 1575 if (pool->base.dmcu == NULL) { 1576 dm_error("DC: failed to create dmcu!\n"); 1577 BREAK_TO_DEBUGGER(); 1578 goto create_fail; 1579 } 1580 1581 dc->debug.dmub_command_table = false; 1582 } 1583 1584 if (dc->config.disable_dmcu) { 1585 pool->base.psr = dmub_psr_create(ctx); 1586 1587 if (pool->base.psr == NULL) { 1588 dm_error("DC: failed to create psr obj!\n"); 1589 BREAK_TO_DEBUGGER(); 1590 goto create_fail; 1591 } 1592 } 1593 1594 if (dc->config.disable_dmcu) 1595 pool->base.abm = dmub_abm_create(ctx, 1596 &abm_regs, 1597 &abm_shift, 1598 &abm_mask); 1599 else 1600 pool->base.abm = dce_abm_create(ctx, 1601 &abm_regs, 1602 &abm_shift, 1603 &abm_mask); 1604 1605 pool->base.pp_smu = dcn21_pp_smu_create(ctx); 1606 1607 num_pipes = dcn2_1_ip.max_num_dpp; 1608 1609 for (i = 0; i < dcn2_1_ip.max_num_dpp; i++) 1610 if (pipe_fuses & 1 << i) 1611 num_pipes--; 1612 dcn2_1_ip.max_num_dpp = num_pipes; 1613 dcn2_1_ip.max_num_otg = num_pipes; 1614 1615 dml_init_instance(&dc->dml, &dcn2_1_soc, &dcn2_1_ip, DML_PROJECT_DCN21); 1616 1617 init_data.ctx = dc->ctx; 1618 pool->base.irqs = dal_irq_service_dcn21_create(&init_data); 1619 if (!pool->base.irqs) 1620 goto create_fail; 1621 1622 j = 0; 1623 /* mem input -> ipp -> dpp -> opp -> TG */ 1624 for (i = 0; i < pool->base.pipe_count; i++) { 1625 /* if pipe is disabled, skip instance of HW pipe, 1626 * i.e, skip ASIC register instance 1627 */ 1628 if ((pipe_fuses & (1 << i)) != 0) 1629 continue; 1630 1631 pool->base.hubps[j] = dcn21_hubp_create(ctx, i); 1632 if (pool->base.hubps[j] == NULL) { 1633 BREAK_TO_DEBUGGER(); 1634 dm_error( 1635 "DC: failed to create memory input!\n"); 1636 goto create_fail; 1637 } 1638 1639 pool->base.ipps[j] = dcn21_ipp_create(ctx, i); 1640 if (pool->base.ipps[j] == NULL) { 1641 BREAK_TO_DEBUGGER(); 1642 dm_error( 1643 "DC: failed to create input pixel processor!\n"); 1644 goto create_fail; 1645 } 1646 1647 pool->base.dpps[j] = dcn21_dpp_create(ctx, i); 1648 if (pool->base.dpps[j] == NULL) { 1649 BREAK_TO_DEBUGGER(); 1650 dm_error( 1651 "DC: failed to create dpps!\n"); 1652 goto create_fail; 1653 } 1654 1655 pool->base.opps[j] = dcn21_opp_create(ctx, i); 1656 if (pool->base.opps[j] == NULL) { 1657 BREAK_TO_DEBUGGER(); 1658 dm_error( 1659 "DC: failed to create output pixel processor!\n"); 1660 goto create_fail; 1661 } 1662 1663 pool->base.timing_generators[j] = dcn21_timing_generator_create( 1664 ctx, i); 1665 if (pool->base.timing_generators[j] == NULL) { 1666 BREAK_TO_DEBUGGER(); 1667 dm_error("DC: failed to create tg!\n"); 1668 goto create_fail; 1669 } 1670 j++; 1671 } 1672 1673 for (i = 0; i < pool->base.res_cap->num_ddc; i++) { 1674 pool->base.engines[i] = dcn21_aux_engine_create(ctx, i); 1675 if (pool->base.engines[i] == NULL) { 1676 BREAK_TO_DEBUGGER(); 1677 dm_error( 1678 "DC:failed to create aux engine!!\n"); 1679 goto create_fail; 1680 } 1681 pool->base.hw_i2cs[i] = dcn21_i2c_hw_create(ctx, i); 1682 if (pool->base.hw_i2cs[i] == NULL) { 1683 BREAK_TO_DEBUGGER(); 1684 dm_error( 1685 "DC:failed to create hw i2c!!\n"); 1686 goto create_fail; 1687 } 1688 pool->base.sw_i2cs[i] = NULL; 1689 } 1690 1691 pool->base.timing_generator_count = j; 1692 pool->base.pipe_count = j; 1693 pool->base.mpcc_count = j; 1694 1695 pool->base.mpc = dcn21_mpc_create(ctx); 1696 if (pool->base.mpc == NULL) { 1697 BREAK_TO_DEBUGGER(); 1698 dm_error("DC: failed to create mpc!\n"); 1699 goto create_fail; 1700 } 1701 1702 pool->base.hubbub = dcn21_hubbub_create(ctx); 1703 if (pool->base.hubbub == NULL) { 1704 BREAK_TO_DEBUGGER(); 1705 dm_error("DC: failed to create hubbub!\n"); 1706 goto create_fail; 1707 } 1708 1709 for (i = 0; i < pool->base.res_cap->num_dsc; i++) { 1710 pool->base.dscs[i] = dcn21_dsc_create(ctx, i); 1711 if (pool->base.dscs[i] == NULL) { 1712 BREAK_TO_DEBUGGER(); 1713 dm_error("DC: failed to create display stream compressor %d!\n", i); 1714 goto create_fail; 1715 } 1716 } 1717 1718 if (!dcn20_dwbc_create(ctx, &pool->base)) { 1719 BREAK_TO_DEBUGGER(); 1720 dm_error("DC: failed to create dwbc!\n"); 1721 goto create_fail; 1722 } 1723 if (!dcn20_mmhubbub_create(ctx, &pool->base)) { 1724 BREAK_TO_DEBUGGER(); 1725 dm_error("DC: failed to create mcif_wb!\n"); 1726 goto create_fail; 1727 } 1728 1729 if (!resource_construct(num_virtual_links, dc, &pool->base, 1730 (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment) ? 1731 &res_create_funcs : &res_create_maximus_funcs))) 1732 goto create_fail; 1733 1734 dcn21_hw_sequencer_construct(dc); 1735 1736 dc->caps.max_planes = pool->base.pipe_count; 1737 1738 for (i = 0; i < dc->caps.max_planes; ++i) 1739 dc->caps.planes[i] = plane_cap; 1740 1741 dc->cap_funcs = cap_funcs; 1742 1743 return true; 1744 1745 create_fail: 1746 1747 dcn21_resource_destruct(pool); 1748 1749 return false; 1750 } 1751 1752 struct resource_pool *dcn21_create_resource_pool( 1753 const struct dc_init_data *init_data, 1754 struct dc *dc) 1755 { 1756 struct dcn21_resource_pool *pool = 1757 kzalloc(sizeof(struct dcn21_resource_pool), GFP_KERNEL); 1758 1759 if (!pool) 1760 return NULL; 1761 1762 if (dcn21_resource_construct(init_data->num_virtual_links, dc, pool)) 1763 return &pool->base; 1764 1765 BREAK_TO_DEBUGGER(); 1766 kfree(pool); 1767 return NULL; 1768 } 1769