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