1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright 2022 Advanced Micro Devices, Inc. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included in 13 * all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 21 * OTHER DEALINGS IN THE SOFTWARE. 22 * 23 * Authors: AMD 24 * 25 */ 26 27 #include "dm_services.h" 28 #include "dc.h" 29 30 #include "dcn32_init.h" 31 32 #include "resource.h" 33 #include "include/irq_service_interface.h" 34 #include "dcn32_resource.h" 35 36 #include "dcn20/dcn20_resource.h" 37 #include "dcn30/dcn30_resource.h" 38 39 #include "dcn10/dcn10_ipp.h" 40 #include "dcn30/dcn30_hubbub.h" 41 #include "dcn31/dcn31_hubbub.h" 42 #include "dcn32/dcn32_hubbub.h" 43 #include "dcn32/dcn32_mpc.h" 44 #include "dcn32_hubp.h" 45 #include "irq/dcn32/irq_service_dcn32.h" 46 #include "dcn32/dcn32_dpp.h" 47 #include "dcn32/dcn32_optc.h" 48 #include "dcn20/dcn20_hwseq.h" 49 #include "dcn30/dcn30_hwseq.h" 50 #include "dce110/dce110_hw_sequencer.h" 51 #include "dcn30/dcn30_opp.h" 52 #include "dcn20/dcn20_dsc.h" 53 #include "dcn30/dcn30_vpg.h" 54 #include "dcn30/dcn30_afmt.h" 55 #include "dcn30/dcn30_dio_stream_encoder.h" 56 #include "dcn32/dcn32_dio_stream_encoder.h" 57 #include "dcn31/dcn31_hpo_dp_stream_encoder.h" 58 #include "dcn31/dcn31_hpo_dp_link_encoder.h" 59 #include "dcn32/dcn32_hpo_dp_link_encoder.h" 60 #include "dc_link_dp.h" 61 #include "dcn31/dcn31_apg.h" 62 #include "dcn31/dcn31_dio_link_encoder.h" 63 #include "dcn32/dcn32_dio_link_encoder.h" 64 #include "dce/dce_clock_source.h" 65 #include "dce/dce_audio.h" 66 #include "dce/dce_hwseq.h" 67 #include "clk_mgr.h" 68 #include "virtual/virtual_stream_encoder.h" 69 #include "dml/display_mode_vba.h" 70 #include "dcn32/dcn32_dccg.h" 71 #include "dcn10/dcn10_resource.h" 72 #include "dc_link_ddc.h" 73 #include "dcn31/dcn31_panel_cntl.h" 74 75 #include "dcn30/dcn30_dwb.h" 76 #include "dcn32/dcn32_mmhubbub.h" 77 78 #include "dcn/dcn_3_2_0_offset.h" 79 #include "dcn/dcn_3_2_0_sh_mask.h" 80 #include "nbio/nbio_4_3_0_offset.h" 81 82 #include "reg_helper.h" 83 #include "dce/dmub_abm.h" 84 #include "dce/dmub_psr.h" 85 #include "dce/dce_aux.h" 86 #include "dce/dce_i2c.h" 87 88 #include "dml/dcn30/display_mode_vba_30.h" 89 #include "vm_helper.h" 90 #include "dcn20/dcn20_vmid.h" 91 92 #define DCN_BASE__INST0_SEG1 0x000000C0 93 #define DCN_BASE__INST0_SEG2 0x000034C0 94 #define DCN_BASE__INST0_SEG3 0x00009000 95 #define NBIO_BASE__INST0_SEG1 0x00000014 96 97 #define MAX_INSTANCE 6 98 #define MAX_SEGMENT 6 99 100 struct IP_BASE_INSTANCE { 101 unsigned int segment[MAX_SEGMENT]; 102 }; 103 104 struct IP_BASE { 105 struct IP_BASE_INSTANCE instance[MAX_INSTANCE]; 106 }; 107 108 static const struct IP_BASE DCN_BASE = { { { { 0x00000012, 0x000000C0, 0x000034C0, 0x00009000, 0x02403C00, 0 } }, 109 { { 0, 0, 0, 0, 0, 0 } }, 110 { { 0, 0, 0, 0, 0, 0 } }, 111 { { 0, 0, 0, 0, 0, 0 } }, 112 { { 0, 0, 0, 0, 0, 0 } }, 113 { { 0, 0, 0, 0, 0, 0 } } } }; 114 115 #define DC_LOGGER_INIT(logger) 116 117 #define DCN3_2_DEFAULT_DET_SIZE 256 118 #define DCN3_2_MAX_DET_SIZE 1152 119 #define DCN3_2_MIN_DET_SIZE 128 120 #define DCN3_2_MIN_COMPBUF_SIZE_KB 128 121 122 struct _vcs_dpi_ip_params_st dcn3_2_ip = { 123 .gpuvm_enable = 1, 124 .gpuvm_max_page_table_levels = 4, 125 .hostvm_enable = 0, 126 .rob_buffer_size_kbytes = 128, 127 .det_buffer_size_kbytes = DCN3_2_DEFAULT_DET_SIZE, 128 .config_return_buffer_size_in_kbytes = 1280, 129 .compressed_buffer_segment_size_in_kbytes = 64, 130 .meta_fifo_size_in_kentries = 22, 131 .zero_size_buffer_entries = 512, 132 .compbuf_reserved_space_64b = 256, 133 .compbuf_reserved_space_zs = 64, 134 .dpp_output_buffer_pixels = 2560, 135 .opp_output_buffer_lines = 1, 136 .pixel_chunk_size_kbytes = 8, 137 .alpha_pixel_chunk_size_kbytes = 4, // not appearing in spreadsheet, match c code from hw team 138 .min_pixel_chunk_size_bytes = 1024, 139 .dcc_meta_buffer_size_bytes = 6272, 140 .meta_chunk_size_kbytes = 2, 141 .min_meta_chunk_size_bytes = 256, 142 .writeback_chunk_size_kbytes = 8, 143 .ptoi_supported = false, 144 .num_dsc = 4, 145 .maximum_dsc_bits_per_component = 12, 146 .maximum_pixels_per_line_per_dsc_unit = 6016, 147 .dsc422_native_support = true, 148 .is_line_buffer_bpp_fixed = true, 149 .line_buffer_fixed_bpp = 57, 150 .line_buffer_size_bits = 1171920, //DPP doc, DCN3_2_DisplayMode_73.xlsm still shows as 986880 bits with 48 bpp 151 .max_line_buffer_lines = 32, 152 .writeback_interface_buffer_size_kbytes = 90, 153 .max_num_dpp = 4, 154 .max_num_otg = 4, 155 .max_num_hdmi_frl_outputs = 1, 156 .max_num_wb = 1, 157 .max_dchub_pscl_bw_pix_per_clk = 4, 158 .max_pscl_lb_bw_pix_per_clk = 2, 159 .max_lb_vscl_bw_pix_per_clk = 4, 160 .max_vscl_hscl_bw_pix_per_clk = 4, 161 .max_hscl_ratio = 6, 162 .max_vscl_ratio = 6, 163 .max_hscl_taps = 8, 164 .max_vscl_taps = 8, 165 .dpte_buffer_size_in_pte_reqs_luma = 64, 166 .dpte_buffer_size_in_pte_reqs_chroma = 34, 167 .dispclk_ramp_margin_percent = 1, 168 .max_inter_dcn_tile_repeaters = 8, 169 .cursor_buffer_size = 16, 170 .cursor_chunk_size = 2, 171 .writeback_line_buffer_buffer_size = 0, 172 .writeback_min_hscl_ratio = 1, 173 .writeback_min_vscl_ratio = 1, 174 .writeback_max_hscl_ratio = 1, 175 .writeback_max_vscl_ratio = 1, 176 .writeback_max_hscl_taps = 1, 177 .writeback_max_vscl_taps = 1, 178 .dppclk_delay_subtotal = 47, 179 .dppclk_delay_scl = 50, 180 .dppclk_delay_scl_lb_only = 16, 181 .dppclk_delay_cnvc_formatter = 28, 182 .dppclk_delay_cnvc_cursor = 6, 183 .dispclk_delay_subtotal = 125, 184 .dynamic_metadata_vm_enabled = false, 185 .odm_combine_4to1_supported = false, 186 .dcc_supported = true, 187 .max_num_dp2p0_outputs = 2, 188 .max_num_dp2p0_streams = 4, 189 }; 190 191 struct _vcs_dpi_soc_bounding_box_st dcn3_2_soc = { 192 .clock_limits = { 193 { 194 .state = 0, 195 .dcfclk_mhz = 1564.0, 196 .fabricclk_mhz = 400.0, 197 .dispclk_mhz = 2150.0, 198 .dppclk_mhz = 2150.0, 199 .phyclk_mhz = 810.0, 200 .phyclk_d18_mhz = 667.0, 201 .phyclk_d32_mhz = 625.0, 202 .socclk_mhz = 1200.0, 203 .dscclk_mhz = 716.667, 204 .dram_speed_mts = 1600.0, 205 .dtbclk_mhz = 1564.0, 206 }, 207 }, 208 .num_states = 1, 209 .sr_exit_time_us = 5.20, 210 .sr_enter_plus_exit_time_us = 9.60, 211 .sr_exit_z8_time_us = 285.0, 212 .sr_enter_plus_exit_z8_time_us = 320, 213 .writeback_latency_us = 12.0, 214 .round_trip_ping_latency_dcfclk_cycles = 263, 215 .urgent_latency_pixel_data_only_us = 4.0, 216 .urgent_latency_pixel_mixed_with_vm_data_us = 4.0, 217 .urgent_latency_vm_data_only_us = 4.0, 218 .fclk_change_latency_us = 20, 219 .usr_retraining_latency_us = 2, 220 .smn_latency_us = 2, 221 .mall_allocated_for_dcn_mbytes = 64, 222 .urgent_out_of_order_return_per_channel_pixel_only_bytes = 4096, 223 .urgent_out_of_order_return_per_channel_pixel_and_vm_bytes = 4096, 224 .urgent_out_of_order_return_per_channel_vm_only_bytes = 4096, 225 .pct_ideal_sdp_bw_after_urgent = 100.0, 226 .pct_ideal_fabric_bw_after_urgent = 67.0, 227 .pct_ideal_dram_sdp_bw_after_urgent_pixel_only = 20.0, 228 .pct_ideal_dram_sdp_bw_after_urgent_pixel_and_vm = 60.0, // N/A, for now keep as is until DML implemented 229 .pct_ideal_dram_sdp_bw_after_urgent_vm_only = 30.0, // N/A, for now keep as is until DML implemented 230 .pct_ideal_dram_bw_after_urgent_strobe = 67.0, 231 .max_avg_sdp_bw_use_normal_percent = 80.0, 232 .max_avg_fabric_bw_use_normal_percent = 60.0, 233 .max_avg_dram_bw_use_normal_strobe_percent = 50.0, 234 .max_avg_dram_bw_use_normal_percent = 15.0, 235 .num_chans = 8, 236 .dram_channel_width_bytes = 2, 237 .fabric_datapath_to_dcn_data_return_bytes = 64, 238 .return_bus_width_bytes = 64, 239 .downspread_percent = 0.38, 240 .dcn_downspread_percent = 0.5, 241 .dram_clock_change_latency_us = 400, 242 .dispclk_dppclk_vco_speed_mhz = 4300.0, 243 .do_urgent_latency_adjustment = true, 244 .urgent_latency_adjustment_fabric_clock_component_us = 1.0, 245 .urgent_latency_adjustment_fabric_clock_reference_mhz = 1000, 246 }; 247 248 enum dcn32_clk_src_array_id { 249 DCN32_CLK_SRC_PLL0, 250 DCN32_CLK_SRC_PLL1, 251 DCN32_CLK_SRC_PLL2, 252 DCN32_CLK_SRC_PLL3, 253 DCN32_CLK_SRC_PLL4, 254 DCN32_CLK_SRC_TOTAL 255 }; 256 257 /* begin ********************* 258 * macros to expend register list macro defined in HW object header file 259 */ 260 261 /* DCN */ 262 /* TODO awful hack. fixup dcn20_dwb.h */ 263 #undef BASE_INNER 264 #define BASE_INNER(seg) DCN_BASE__INST0_SEG ## seg 265 266 #define BASE(seg) BASE_INNER(seg) 267 268 #define SR(reg_name)\ 269 .reg_name = BASE(reg ## reg_name ## _BASE_IDX) + \ 270 reg ## reg_name 271 272 #define SRI(reg_name, block, id)\ 273 .reg_name = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \ 274 reg ## block ## id ## _ ## reg_name 275 276 #define SRI2(reg_name, block, id)\ 277 .reg_name = BASE(reg ## reg_name ## _BASE_IDX) + \ 278 reg ## reg_name 279 280 #define SRIR(var_name, reg_name, block, id)\ 281 .var_name = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \ 282 reg ## block ## id ## _ ## reg_name 283 284 #define SRII(reg_name, block, id)\ 285 .reg_name[id] = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \ 286 reg ## block ## id ## _ ## reg_name 287 288 #define SRII_MPC_RMU(reg_name, block, id)\ 289 .RMU##_##reg_name[id] = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \ 290 reg ## block ## id ## _ ## reg_name 291 292 #define SRII_DWB(reg_name, temp_name, block, id)\ 293 .reg_name[id] = BASE(reg ## block ## id ## _ ## temp_name ## _BASE_IDX) + \ 294 reg ## block ## id ## _ ## temp_name 295 296 #define DCCG_SRII(reg_name, block, id)\ 297 .block ## _ ## reg_name[id] = BASE(reg ## block ## id ## _ ## reg_name ## _BASE_IDX) + \ 298 reg ## block ## id ## _ ## reg_name 299 300 #define VUPDATE_SRII(reg_name, block, id)\ 301 .reg_name[id] = BASE(reg ## reg_name ## _ ## block ## id ## _BASE_IDX) + \ 302 reg ## reg_name ## _ ## block ## id 303 304 /* NBIO */ 305 #define NBIO_BASE_INNER(seg) \ 306 NBIO_BASE__INST0_SEG ## seg 307 308 #define NBIO_BASE(seg) \ 309 NBIO_BASE_INNER(seg) 310 311 #define NBIO_SR(reg_name)\ 312 .reg_name = NBIO_BASE(regBIF_BX0_ ## reg_name ## _BASE_IDX) + \ 313 regBIF_BX0_ ## reg_name 314 315 #define CTX ctx 316 #define REG(reg_name) \ 317 (DCN_BASE.instance[0].segment[reg ## reg_name ## _BASE_IDX] + reg ## reg_name) 318 319 static const struct bios_registers bios_regs = { 320 NBIO_SR(BIOS_SCRATCH_3), 321 NBIO_SR(BIOS_SCRATCH_6) 322 }; 323 324 #define clk_src_regs(index, pllid)\ 325 [index] = {\ 326 CS_COMMON_REG_LIST_DCN3_0(index, pllid),\ 327 } 328 329 static const struct dce110_clk_src_regs clk_src_regs[] = { 330 clk_src_regs(0, A), 331 clk_src_regs(1, B), 332 clk_src_regs(2, C), 333 clk_src_regs(3, D), 334 clk_src_regs(4, E) 335 }; 336 337 static const struct dce110_clk_src_shift cs_shift = { 338 CS_COMMON_MASK_SH_LIST_DCN3_2(__SHIFT) 339 }; 340 341 static const struct dce110_clk_src_mask cs_mask = { 342 CS_COMMON_MASK_SH_LIST_DCN3_2(_MASK) 343 }; 344 345 #define abm_regs(id)\ 346 [id] = {\ 347 ABM_DCN32_REG_LIST(id)\ 348 } 349 350 static const struct dce_abm_registers abm_regs[] = { 351 abm_regs(0), 352 abm_regs(1), 353 abm_regs(2), 354 abm_regs(3), 355 }; 356 357 static const struct dce_abm_shift abm_shift = { 358 ABM_MASK_SH_LIST_DCN32(__SHIFT) 359 }; 360 361 static const struct dce_abm_mask abm_mask = { 362 ABM_MASK_SH_LIST_DCN32(_MASK) 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 }; 377 378 #define DCE120_AUD_COMMON_MASK_SH_LIST(mask_sh)\ 379 SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_INDEX, AZALIA_ENDPOINT_REG_INDEX, mask_sh),\ 380 SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_DATA, AZALIA_ENDPOINT_REG_DATA, mask_sh),\ 381 AUD_COMMON_MASK_SH_LIST_BASE(mask_sh) 382 383 static const struct dce_audio_shift audio_shift = { 384 DCE120_AUD_COMMON_MASK_SH_LIST(__SHIFT) 385 }; 386 387 static const struct dce_audio_mask audio_mask = { 388 DCE120_AUD_COMMON_MASK_SH_LIST(_MASK) 389 }; 390 391 #define vpg_regs(id)\ 392 [id] = {\ 393 VPG_DCN3_REG_LIST(id)\ 394 } 395 396 static const struct dcn30_vpg_registers vpg_regs[] = { 397 vpg_regs(0), 398 vpg_regs(1), 399 vpg_regs(2), 400 vpg_regs(3), 401 vpg_regs(4), 402 vpg_regs(5), 403 vpg_regs(6), 404 vpg_regs(7), 405 vpg_regs(8), 406 vpg_regs(9), 407 }; 408 409 static const struct dcn30_vpg_shift vpg_shift = { 410 DCN3_VPG_MASK_SH_LIST(__SHIFT) 411 }; 412 413 static const struct dcn30_vpg_mask vpg_mask = { 414 DCN3_VPG_MASK_SH_LIST(_MASK) 415 }; 416 417 #define afmt_regs(id)\ 418 [id] = {\ 419 AFMT_DCN3_REG_LIST(id)\ 420 } 421 422 static const struct dcn30_afmt_registers afmt_regs[] = { 423 afmt_regs(0), 424 afmt_regs(1), 425 afmt_regs(2), 426 afmt_regs(3), 427 afmt_regs(4), 428 afmt_regs(5) 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 apg_regs(id)\ 440 [id] = {\ 441 APG_DCN31_REG_LIST(id)\ 442 } 443 444 static const struct dcn31_apg_registers apg_regs[] = { 445 apg_regs(0), 446 apg_regs(1), 447 apg_regs(2), 448 apg_regs(3) 449 }; 450 451 static const struct dcn31_apg_shift apg_shift = { 452 DCN31_APG_MASK_SH_LIST(__SHIFT) 453 }; 454 455 static const struct dcn31_apg_mask apg_mask = { 456 DCN31_APG_MASK_SH_LIST(_MASK) 457 }; 458 459 #define stream_enc_regs(id)\ 460 [id] = {\ 461 SE_DCN32_REG_LIST(id)\ 462 } 463 464 static const struct dcn10_stream_enc_registers stream_enc_regs[] = { 465 stream_enc_regs(0), 466 stream_enc_regs(1), 467 stream_enc_regs(2), 468 stream_enc_regs(3), 469 stream_enc_regs(4) 470 }; 471 472 static const struct dcn10_stream_encoder_shift se_shift = { 473 SE_COMMON_MASK_SH_LIST_DCN32(__SHIFT) 474 }; 475 476 static const struct dcn10_stream_encoder_mask se_mask = { 477 SE_COMMON_MASK_SH_LIST_DCN32(_MASK) 478 }; 479 480 481 #define aux_regs(id)\ 482 [id] = {\ 483 DCN2_AUX_REG_LIST(id)\ 484 } 485 486 static const struct dcn10_link_enc_aux_registers link_enc_aux_regs[] = { 487 aux_regs(0), 488 aux_regs(1), 489 aux_regs(2), 490 aux_regs(3), 491 aux_regs(4) 492 }; 493 494 #define hpd_regs(id)\ 495 [id] = {\ 496 HPD_REG_LIST(id)\ 497 } 498 499 static const struct dcn10_link_enc_hpd_registers link_enc_hpd_regs[] = { 500 hpd_regs(0), 501 hpd_regs(1), 502 hpd_regs(2), 503 hpd_regs(3), 504 hpd_regs(4) 505 }; 506 507 #define link_regs(id, phyid)\ 508 [id] = {\ 509 LE_DCN31_REG_LIST(id), \ 510 UNIPHY_DCN2_REG_LIST(phyid), \ 511 /*DPCS_DCN31_REG_LIST(id),*/ \ 512 } 513 514 static const struct dcn10_link_enc_registers link_enc_regs[] = { 515 link_regs(0, A), 516 link_regs(1, B), 517 link_regs(2, C), 518 link_regs(3, D), 519 link_regs(4, E) 520 }; 521 522 static const struct dcn10_link_enc_shift le_shift = { 523 LINK_ENCODER_MASK_SH_LIST_DCN31(__SHIFT), \ 524 //DPCS_DCN31_MASK_SH_LIST(__SHIFT) 525 }; 526 527 static const struct dcn10_link_enc_mask le_mask = { 528 LINK_ENCODER_MASK_SH_LIST_DCN31(_MASK), \ 529 530 //DPCS_DCN31_MASK_SH_LIST(_MASK) 531 }; 532 533 #define hpo_dp_stream_encoder_reg_list(id)\ 534 [id] = {\ 535 DCN3_1_HPO_DP_STREAM_ENC_REG_LIST(id)\ 536 } 537 538 static const struct dcn31_hpo_dp_stream_encoder_registers hpo_dp_stream_enc_regs[] = { 539 hpo_dp_stream_encoder_reg_list(0), 540 hpo_dp_stream_encoder_reg_list(1), 541 hpo_dp_stream_encoder_reg_list(2), 542 hpo_dp_stream_encoder_reg_list(3), 543 }; 544 545 static const struct dcn31_hpo_dp_stream_encoder_shift hpo_dp_se_shift = { 546 DCN3_1_HPO_DP_STREAM_ENC_MASK_SH_LIST(__SHIFT) 547 }; 548 549 static const struct dcn31_hpo_dp_stream_encoder_mask hpo_dp_se_mask = { 550 DCN3_1_HPO_DP_STREAM_ENC_MASK_SH_LIST(_MASK) 551 }; 552 553 554 #define hpo_dp_link_encoder_reg_list(id)\ 555 [id] = {\ 556 DCN3_1_HPO_DP_LINK_ENC_REG_LIST(id),\ 557 /*DCN3_1_RDPCSTX_REG_LIST(0),*/\ 558 /*DCN3_1_RDPCSTX_REG_LIST(1),*/\ 559 /*DCN3_1_RDPCSTX_REG_LIST(2),*/\ 560 /*DCN3_1_RDPCSTX_REG_LIST(3),*/\ 561 /*DCN3_1_RDPCSTX_REG_LIST(4)*/\ 562 } 563 564 static const struct dcn31_hpo_dp_link_encoder_registers hpo_dp_link_enc_regs[] = { 565 hpo_dp_link_encoder_reg_list(0), 566 hpo_dp_link_encoder_reg_list(1), 567 }; 568 569 static const struct dcn31_hpo_dp_link_encoder_shift hpo_dp_le_shift = { 570 DCN3_2_HPO_DP_LINK_ENC_MASK_SH_LIST(__SHIFT) 571 }; 572 573 static const struct dcn31_hpo_dp_link_encoder_mask hpo_dp_le_mask = { 574 DCN3_2_HPO_DP_LINK_ENC_MASK_SH_LIST(_MASK) 575 }; 576 577 #define dpp_regs(id)\ 578 [id] = {\ 579 DPP_REG_LIST_DCN30_COMMON(id),\ 580 } 581 582 static const struct dcn3_dpp_registers dpp_regs[] = { 583 dpp_regs(0), 584 dpp_regs(1), 585 dpp_regs(2), 586 dpp_regs(3) 587 }; 588 589 static const struct dcn3_dpp_shift tf_shift = { 590 DPP_REG_LIST_SH_MASK_DCN30_COMMON(__SHIFT) 591 }; 592 593 static const struct dcn3_dpp_mask tf_mask = { 594 DPP_REG_LIST_SH_MASK_DCN30_COMMON(_MASK) 595 }; 596 597 598 #define opp_regs(id)\ 599 [id] = {\ 600 OPP_REG_LIST_DCN30(id),\ 601 } 602 603 static const struct dcn20_opp_registers opp_regs[] = { 604 opp_regs(0), 605 opp_regs(1), 606 opp_regs(2), 607 opp_regs(3) 608 }; 609 610 static const struct dcn20_opp_shift opp_shift = { 611 OPP_MASK_SH_LIST_DCN20(__SHIFT) 612 }; 613 614 static const struct dcn20_opp_mask opp_mask = { 615 OPP_MASK_SH_LIST_DCN20(_MASK) 616 }; 617 618 #define aux_engine_regs(id)\ 619 [id] = {\ 620 AUX_COMMON_REG_LIST0(id), \ 621 .AUXN_IMPCAL = 0, \ 622 .AUXP_IMPCAL = 0, \ 623 .AUX_RESET_MASK = DP_AUX0_AUX_CONTROL__AUX_RESET_MASK, \ 624 } 625 626 static const struct dce110_aux_registers aux_engine_regs[] = { 627 aux_engine_regs(0), 628 aux_engine_regs(1), 629 aux_engine_regs(2), 630 aux_engine_regs(3), 631 aux_engine_regs(4) 632 }; 633 634 static const struct dce110_aux_registers_shift aux_shift = { 635 DCN_AUX_MASK_SH_LIST(__SHIFT) 636 }; 637 638 static const struct dce110_aux_registers_mask aux_mask = { 639 DCN_AUX_MASK_SH_LIST(_MASK) 640 }; 641 642 643 #define dwbc_regs_dcn3(id)\ 644 [id] = {\ 645 DWBC_COMMON_REG_LIST_DCN30(id),\ 646 } 647 648 static const struct dcn30_dwbc_registers dwbc30_regs[] = { 649 dwbc_regs_dcn3(0), 650 }; 651 652 static const struct dcn30_dwbc_shift dwbc30_shift = { 653 DWBC_COMMON_MASK_SH_LIST_DCN30(__SHIFT) 654 }; 655 656 static const struct dcn30_dwbc_mask dwbc30_mask = { 657 DWBC_COMMON_MASK_SH_LIST_DCN30(_MASK) 658 }; 659 660 #define mcif_wb_regs_dcn3(id)\ 661 [id] = {\ 662 MCIF_WB_COMMON_REG_LIST_DCN32(id),\ 663 } 664 665 static const struct dcn30_mmhubbub_registers mcif_wb30_regs[] = { 666 mcif_wb_regs_dcn3(0) 667 }; 668 669 static const struct dcn30_mmhubbub_shift mcif_wb30_shift = { 670 MCIF_WB_COMMON_MASK_SH_LIST_DCN32(__SHIFT) 671 }; 672 673 static const struct dcn30_mmhubbub_mask mcif_wb30_mask = { 674 MCIF_WB_COMMON_MASK_SH_LIST_DCN32(_MASK) 675 }; 676 677 #define dsc_regsDCN20(id)\ 678 [id] = {\ 679 DSC_REG_LIST_DCN20(id)\ 680 } 681 682 static const struct dcn20_dsc_registers dsc_regs[] = { 683 dsc_regsDCN20(0), 684 dsc_regsDCN20(1), 685 dsc_regsDCN20(2), 686 dsc_regsDCN20(3) 687 }; 688 689 static const struct dcn20_dsc_shift dsc_shift = { 690 DSC_REG_LIST_SH_MASK_DCN20(__SHIFT) 691 }; 692 693 static const struct dcn20_dsc_mask dsc_mask = { 694 DSC_REG_LIST_SH_MASK_DCN20(_MASK) 695 }; 696 697 static const struct dcn30_mpc_registers mpc_regs = { 698 MPC_REG_LIST_DCN3_2(0), 699 MPC_REG_LIST_DCN3_2(1), 700 MPC_REG_LIST_DCN3_2(2), 701 MPC_REG_LIST_DCN3_2(3), 702 MPC_OUT_MUX_REG_LIST_DCN3_0(0), 703 MPC_OUT_MUX_REG_LIST_DCN3_0(1), 704 MPC_OUT_MUX_REG_LIST_DCN3_0(2), 705 MPC_OUT_MUX_REG_LIST_DCN3_0(3), 706 MPC_DWB_MUX_REG_LIST_DCN3_0(0), 707 }; 708 709 static const struct dcn30_mpc_shift mpc_shift = { 710 MPC_COMMON_MASK_SH_LIST_DCN32(__SHIFT) 711 }; 712 713 static const struct dcn30_mpc_mask mpc_mask = { 714 MPC_COMMON_MASK_SH_LIST_DCN32(_MASK) 715 }; 716 717 #define optc_regs(id)\ 718 [id] = {OPTC_COMMON_REG_LIST_DCN3_2(id)} 719 720 //#ifdef DIAGS_BUILD 721 //static struct dcn_optc_registers optc_regs[] = { 722 //#else 723 static const struct dcn_optc_registers optc_regs[] = { 724 //#endif 725 optc_regs(0), 726 optc_regs(1), 727 optc_regs(2), 728 optc_regs(3) 729 }; 730 731 static const struct dcn_optc_shift optc_shift = { 732 OPTC_COMMON_MASK_SH_LIST_DCN3_2(__SHIFT) 733 }; 734 735 static const struct dcn_optc_mask optc_mask = { 736 OPTC_COMMON_MASK_SH_LIST_DCN3_2(_MASK) 737 }; 738 739 #define hubp_regs(id)\ 740 [id] = {\ 741 HUBP_REG_LIST_DCN32(id)\ 742 } 743 744 static const struct dcn_hubp2_registers hubp_regs[] = { 745 hubp_regs(0), 746 hubp_regs(1), 747 hubp_regs(2), 748 hubp_regs(3) 749 }; 750 751 752 static const struct dcn_hubp2_shift hubp_shift = { 753 HUBP_MASK_SH_LIST_DCN32(__SHIFT) 754 }; 755 756 static const struct dcn_hubp2_mask hubp_mask = { 757 HUBP_MASK_SH_LIST_DCN32(_MASK) 758 }; 759 static const struct dcn_hubbub_registers hubbub_reg = { 760 HUBBUB_REG_LIST_DCN32(0) 761 }; 762 763 static const struct dcn_hubbub_shift hubbub_shift = { 764 HUBBUB_MASK_SH_LIST_DCN32(__SHIFT) 765 }; 766 767 static const struct dcn_hubbub_mask hubbub_mask = { 768 HUBBUB_MASK_SH_LIST_DCN32(_MASK) 769 }; 770 771 static const struct dccg_registers dccg_regs = { 772 DCCG_REG_LIST_DCN32() 773 }; 774 775 static const struct dccg_shift dccg_shift = { 776 DCCG_MASK_SH_LIST_DCN32(__SHIFT) 777 }; 778 779 static const struct dccg_mask dccg_mask = { 780 DCCG_MASK_SH_LIST_DCN32(_MASK) 781 }; 782 783 784 #define SRII2(reg_name_pre, reg_name_post, id)\ 785 .reg_name_pre ## _ ## reg_name_post[id] = BASE(reg ## reg_name_pre \ 786 ## id ## _ ## reg_name_post ## _BASE_IDX) + \ 787 reg ## reg_name_pre ## id ## _ ## reg_name_post 788 789 790 #define HWSEQ_DCN32_REG_LIST()\ 791 SR(DCHUBBUB_GLOBAL_TIMER_CNTL), \ 792 SR(DIO_MEM_PWR_CTRL), \ 793 SR(ODM_MEM_PWR_CTRL3), \ 794 SR(MMHUBBUB_MEM_PWR_CNTL), \ 795 SR(DCCG_GATE_DISABLE_CNTL), \ 796 SR(DCCG_GATE_DISABLE_CNTL2), \ 797 SR(DCFCLK_CNTL),\ 798 SR(DC_MEM_GLOBAL_PWR_REQ_CNTL), \ 799 SRII(PIXEL_RATE_CNTL, OTG, 0), \ 800 SRII(PIXEL_RATE_CNTL, OTG, 1),\ 801 SRII(PIXEL_RATE_CNTL, OTG, 2),\ 802 SRII(PIXEL_RATE_CNTL, OTG, 3),\ 803 SRII(PHYPLL_PIXEL_RATE_CNTL, OTG, 0),\ 804 SRII(PHYPLL_PIXEL_RATE_CNTL, OTG, 1),\ 805 SRII(PHYPLL_PIXEL_RATE_CNTL, OTG, 2),\ 806 SRII(PHYPLL_PIXEL_RATE_CNTL, OTG, 3),\ 807 SR(MICROSECOND_TIME_BASE_DIV), \ 808 SR(MILLISECOND_TIME_BASE_DIV), \ 809 SR(DISPCLK_FREQ_CHANGE_CNTL), \ 810 SR(RBBMIF_TIMEOUT_DIS), \ 811 SR(RBBMIF_TIMEOUT_DIS_2), \ 812 SR(DCHUBBUB_CRC_CTRL), \ 813 SR(DPP_TOP0_DPP_CRC_CTRL), \ 814 SR(DPP_TOP0_DPP_CRC_VAL_B_A), \ 815 SR(DPP_TOP0_DPP_CRC_VAL_R_G), \ 816 SR(MPC_CRC_CTRL), \ 817 SR(MPC_CRC_RESULT_GB), \ 818 SR(MPC_CRC_RESULT_C), \ 819 SR(MPC_CRC_RESULT_AR), \ 820 SR(DOMAIN0_PG_CONFIG), \ 821 SR(DOMAIN1_PG_CONFIG), \ 822 SR(DOMAIN2_PG_CONFIG), \ 823 SR(DOMAIN3_PG_CONFIG), \ 824 SR(DOMAIN16_PG_CONFIG), \ 825 SR(DOMAIN17_PG_CONFIG), \ 826 SR(DOMAIN18_PG_CONFIG), \ 827 SR(DOMAIN19_PG_CONFIG), \ 828 SR(DOMAIN0_PG_STATUS), \ 829 SR(DOMAIN1_PG_STATUS), \ 830 SR(DOMAIN2_PG_STATUS), \ 831 SR(DOMAIN3_PG_STATUS), \ 832 SR(DOMAIN16_PG_STATUS), \ 833 SR(DOMAIN17_PG_STATUS), \ 834 SR(DOMAIN18_PG_STATUS), \ 835 SR(DOMAIN19_PG_STATUS), \ 836 SR(D1VGA_CONTROL), \ 837 SR(D2VGA_CONTROL), \ 838 SR(D3VGA_CONTROL), \ 839 SR(D4VGA_CONTROL), \ 840 SR(D5VGA_CONTROL), \ 841 SR(D6VGA_CONTROL), \ 842 SR(DC_IP_REQUEST_CNTL), \ 843 SR(AZALIA_AUDIO_DTO), \ 844 SR(AZALIA_CONTROLLER_CLOCK_GATING) 845 846 static const struct dce_hwseq_registers hwseq_reg = { 847 HWSEQ_DCN32_REG_LIST() 848 }; 849 850 #define HWSEQ_DCN32_MASK_SH_LIST(mask_sh)\ 851 HWSEQ_DCN_MASK_SH_LIST(mask_sh), \ 852 HWS_SF(, DCHUBBUB_GLOBAL_TIMER_CNTL, DCHUBBUB_GLOBAL_TIMER_REFDIV, mask_sh), \ 853 HWS_SF(, DOMAIN0_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \ 854 HWS_SF(, DOMAIN0_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \ 855 HWS_SF(, DOMAIN1_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \ 856 HWS_SF(, DOMAIN1_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \ 857 HWS_SF(, DOMAIN2_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \ 858 HWS_SF(, DOMAIN2_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \ 859 HWS_SF(, DOMAIN3_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \ 860 HWS_SF(, DOMAIN3_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \ 861 HWS_SF(, DOMAIN16_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \ 862 HWS_SF(, DOMAIN16_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \ 863 HWS_SF(, DOMAIN17_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \ 864 HWS_SF(, DOMAIN17_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \ 865 HWS_SF(, DOMAIN18_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \ 866 HWS_SF(, DOMAIN18_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \ 867 HWS_SF(, DOMAIN19_PG_CONFIG, DOMAIN_POWER_FORCEON, mask_sh), \ 868 HWS_SF(, DOMAIN19_PG_CONFIG, DOMAIN_POWER_GATE, mask_sh), \ 869 HWS_SF(, DOMAIN0_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \ 870 HWS_SF(, DOMAIN1_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \ 871 HWS_SF(, DOMAIN2_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \ 872 HWS_SF(, DOMAIN3_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \ 873 HWS_SF(, DOMAIN16_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \ 874 HWS_SF(, DOMAIN17_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \ 875 HWS_SF(, DOMAIN18_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \ 876 HWS_SF(, DOMAIN19_PG_STATUS, DOMAIN_PGFSM_PWR_STATUS, mask_sh), \ 877 HWS_SF(, DC_IP_REQUEST_CNTL, IP_REQUEST_EN, mask_sh), \ 878 HWS_SF(, AZALIA_AUDIO_DTO, AZALIA_AUDIO_DTO_MODULE, mask_sh), \ 879 HWS_SF(, HPO_TOP_CLOCK_CONTROL, HPO_HDMISTREAMCLK_G_GATE_DIS, mask_sh), \ 880 HWS_SF(, ODM_MEM_PWR_CTRL3, ODM_MEM_UNASSIGNED_PWR_MODE, mask_sh), \ 881 HWS_SF(, ODM_MEM_PWR_CTRL3, ODM_MEM_VBLANK_PWR_MODE, mask_sh), \ 882 HWS_SF(, MMHUBBUB_MEM_PWR_CNTL, VGA_MEM_PWR_FORCE, mask_sh) 883 884 static const struct dce_hwseq_shift hwseq_shift = { 885 HWSEQ_DCN32_MASK_SH_LIST(__SHIFT) 886 }; 887 888 static const struct dce_hwseq_mask hwseq_mask = { 889 HWSEQ_DCN32_MASK_SH_LIST(_MASK) 890 }; 891 #define vmid_regs(id)\ 892 [id] = {\ 893 DCN20_VMID_REG_LIST(id)\ 894 } 895 896 static const struct dcn_vmid_registers vmid_regs[] = { 897 vmid_regs(0), 898 vmid_regs(1), 899 vmid_regs(2), 900 vmid_regs(3), 901 vmid_regs(4), 902 vmid_regs(5), 903 vmid_regs(6), 904 vmid_regs(7), 905 vmid_regs(8), 906 vmid_regs(9), 907 vmid_regs(10), 908 vmid_regs(11), 909 vmid_regs(12), 910 vmid_regs(13), 911 vmid_regs(14), 912 vmid_regs(15) 913 }; 914 915 static const struct dcn20_vmid_shift vmid_shifts = { 916 DCN20_VMID_MASK_SH_LIST(__SHIFT) 917 }; 918 919 static const struct dcn20_vmid_mask vmid_masks = { 920 DCN20_VMID_MASK_SH_LIST(_MASK) 921 }; 922 923 static const struct resource_caps res_cap_dcn32 = { 924 .num_timing_generator = 4, 925 .num_opp = 4, 926 .num_video_plane = 4, 927 .num_audio = 5, 928 .num_stream_encoder = 5, 929 .num_hpo_dp_stream_encoder = 4, 930 .num_hpo_dp_link_encoder = 2, 931 .num_pll = 5, 932 .num_dwb = 1, 933 .num_ddc = 5, 934 .num_vmid = 16, 935 .num_mpc_3dlut = 4, 936 .num_dsc = 4, 937 }; 938 939 static const struct dc_plane_cap plane_cap = { 940 .type = DC_PLANE_TYPE_DCN_UNIVERSAL, 941 .blends_with_above = true, 942 .blends_with_below = true, 943 .per_pixel_alpha = true, 944 945 .pixel_format_support = { 946 .argb8888 = true, 947 .nv12 = true, 948 .fp16 = true, 949 .p010 = true, 950 .ayuv = false, 951 }, 952 953 .max_upscale_factor = { 954 .argb8888 = 16000, 955 .nv12 = 16000, 956 .fp16 = 16000 957 }, 958 959 // 6:1 downscaling ratio: 1000/6 = 166.666 960 .max_downscale_factor = { 961 .argb8888 = 167, 962 .nv12 = 167, 963 .fp16 = 167 964 }, 965 64, 966 64 967 }; 968 969 static const struct dc_debug_options debug_defaults_drv = { 970 .disable_dmcu = true, 971 .force_abm_enable = false, 972 .timing_trace = false, 973 .clock_trace = true, 974 .disable_pplib_clock_request = false, 975 .disable_idle_power_optimizations = true, 976 .pipe_split_policy = MPC_SPLIT_DYNAMIC, 977 .force_single_disp_pipe_split = false, 978 .disable_dcc = DCC_ENABLE, 979 .vsr_support = true, 980 .performance_trace = false, 981 .max_downscale_src_width = 7680,/*upto 8K*/ 982 .disable_pplib_wm_range = false, 983 .scl_reset_length10 = true, 984 .sanity_checks = false, 985 .underflow_assert_delay_us = 0xFFFFFFFF, 986 .dwb_fi_phase = -1, // -1 = disable, 987 .dmub_command_table = true, 988 .enable_mem_low_power = { 989 .bits = { 990 .vga = false, 991 .i2c = false, 992 .dmcu = false, // This is previously known to cause hang on S3 cycles if enabled 993 .dscl = false, 994 .cm = false, 995 .mpc = false, 996 .optc = true, 997 } 998 }, 999 .use_max_lb = true, 1000 .force_disable_subvp = true, 1001 .enable_single_display_2to1_odm_policy = true, 1002 .enable_dp_dig_pixel_rate_div_policy = 1, 1003 }; 1004 1005 static const struct dc_debug_options debug_defaults_diags = { 1006 .disable_dmcu = true, 1007 .force_abm_enable = false, 1008 .timing_trace = true, 1009 .clock_trace = true, 1010 .disable_dpp_power_gate = true, 1011 .disable_hubp_power_gate = true, 1012 .disable_dsc_power_gate = true, 1013 .disable_clock_gate = true, 1014 .disable_pplib_clock_request = true, 1015 .disable_pplib_wm_range = true, 1016 .disable_stutter = false, 1017 .scl_reset_length10 = true, 1018 .dwb_fi_phase = -1, // -1 = disable 1019 .dmub_command_table = true, 1020 .enable_tri_buf = true, 1021 .use_max_lb = true, 1022 .force_disable_subvp = true 1023 }; 1024 1025 static struct dce_aux *dcn32_aux_engine_create( 1026 struct dc_context *ctx, 1027 uint32_t inst) 1028 { 1029 struct aux_engine_dce110 *aux_engine = 1030 kzalloc(sizeof(struct aux_engine_dce110), GFP_KERNEL); 1031 1032 if (!aux_engine) 1033 return NULL; 1034 1035 dce110_aux_engine_construct(aux_engine, ctx, inst, 1036 SW_AUX_TIMEOUT_PERIOD_MULTIPLIER * AUX_TIMEOUT_PERIOD, 1037 &aux_engine_regs[inst], 1038 &aux_mask, 1039 &aux_shift, 1040 ctx->dc->caps.extended_aux_timeout_support); 1041 1042 return &aux_engine->base; 1043 } 1044 #define i2c_inst_regs(id) { I2C_HW_ENGINE_COMMON_REG_LIST_DCN30(id) } 1045 1046 static const struct dce_i2c_registers i2c_hw_regs[] = { 1047 i2c_inst_regs(1), 1048 i2c_inst_regs(2), 1049 i2c_inst_regs(3), 1050 i2c_inst_regs(4), 1051 i2c_inst_regs(5), 1052 }; 1053 1054 static const struct dce_i2c_shift i2c_shifts = { 1055 I2C_COMMON_MASK_SH_LIST_DCN30(__SHIFT) 1056 }; 1057 1058 static const struct dce_i2c_mask i2c_masks = { 1059 I2C_COMMON_MASK_SH_LIST_DCN30(_MASK) 1060 }; 1061 1062 static struct dce_i2c_hw *dcn32_i2c_hw_create( 1063 struct dc_context *ctx, 1064 uint32_t inst) 1065 { 1066 struct dce_i2c_hw *dce_i2c_hw = 1067 kzalloc(sizeof(struct dce_i2c_hw), GFP_KERNEL); 1068 1069 if (!dce_i2c_hw) 1070 return NULL; 1071 1072 dcn2_i2c_hw_construct(dce_i2c_hw, ctx, inst, 1073 &i2c_hw_regs[inst], &i2c_shifts, &i2c_masks); 1074 1075 return dce_i2c_hw; 1076 } 1077 1078 static struct clock_source *dcn32_clock_source_create( 1079 struct dc_context *ctx, 1080 struct dc_bios *bios, 1081 enum clock_source_id id, 1082 const struct dce110_clk_src_regs *regs, 1083 bool dp_clk_src) 1084 { 1085 struct dce110_clk_src *clk_src = 1086 kzalloc(sizeof(struct dce110_clk_src), GFP_KERNEL); 1087 1088 if (!clk_src) 1089 return NULL; 1090 1091 if (dcn31_clk_src_construct(clk_src, ctx, bios, id, 1092 regs, &cs_shift, &cs_mask)) { 1093 clk_src->base.dp_clk_src = dp_clk_src; 1094 return &clk_src->base; 1095 } 1096 1097 BREAK_TO_DEBUGGER(); 1098 return NULL; 1099 } 1100 1101 static struct hubbub *dcn32_hubbub_create(struct dc_context *ctx) 1102 { 1103 int i; 1104 1105 struct dcn20_hubbub *hubbub2 = kzalloc(sizeof(struct dcn20_hubbub), 1106 GFP_KERNEL); 1107 1108 if (!hubbub2) 1109 return NULL; 1110 1111 hubbub32_construct(hubbub2, ctx, 1112 &hubbub_reg, 1113 &hubbub_shift, 1114 &hubbub_mask, 1115 ctx->dc->dml.ip.det_buffer_size_kbytes, 1116 ctx->dc->dml.ip.pixel_chunk_size_kbytes, 1117 ctx->dc->dml.ip.config_return_buffer_size_in_kbytes); 1118 1119 1120 for (i = 0; i < res_cap_dcn32.num_vmid; i++) { 1121 struct dcn20_vmid *vmid = &hubbub2->vmid[i]; 1122 1123 vmid->ctx = ctx; 1124 1125 vmid->regs = &vmid_regs[i]; 1126 vmid->shifts = &vmid_shifts; 1127 vmid->masks = &vmid_masks; 1128 } 1129 1130 return &hubbub2->base; 1131 } 1132 1133 static struct hubp *dcn32_hubp_create( 1134 struct dc_context *ctx, 1135 uint32_t inst) 1136 { 1137 struct dcn20_hubp *hubp2 = 1138 kzalloc(sizeof(struct dcn20_hubp), GFP_KERNEL); 1139 1140 if (!hubp2) 1141 return NULL; 1142 1143 if (hubp32_construct(hubp2, ctx, inst, 1144 &hubp_regs[inst], &hubp_shift, &hubp_mask)) 1145 return &hubp2->base; 1146 1147 BREAK_TO_DEBUGGER(); 1148 kfree(hubp2); 1149 return NULL; 1150 } 1151 1152 static void dcn32_dpp_destroy(struct dpp **dpp) 1153 { 1154 kfree(TO_DCN30_DPP(*dpp)); 1155 *dpp = NULL; 1156 } 1157 1158 static struct dpp *dcn32_dpp_create( 1159 struct dc_context *ctx, 1160 uint32_t inst) 1161 { 1162 struct dcn3_dpp *dpp3 = 1163 kzalloc(sizeof(struct dcn3_dpp), GFP_KERNEL); 1164 1165 if (!dpp3) 1166 return NULL; 1167 1168 if (dpp32_construct(dpp3, ctx, inst, 1169 &dpp_regs[inst], &tf_shift, &tf_mask)) 1170 return &dpp3->base; 1171 1172 BREAK_TO_DEBUGGER(); 1173 kfree(dpp3); 1174 return NULL; 1175 } 1176 1177 static struct mpc *dcn32_mpc_create( 1178 struct dc_context *ctx, 1179 int num_mpcc, 1180 int num_rmu) 1181 { 1182 struct dcn30_mpc *mpc30 = kzalloc(sizeof(struct dcn30_mpc), 1183 GFP_KERNEL); 1184 1185 if (!mpc30) 1186 return NULL; 1187 1188 dcn32_mpc_construct(mpc30, ctx, 1189 &mpc_regs, 1190 &mpc_shift, 1191 &mpc_mask, 1192 num_mpcc, 1193 num_rmu); 1194 1195 return &mpc30->base; 1196 } 1197 1198 static struct output_pixel_processor *dcn32_opp_create( 1199 struct dc_context *ctx, uint32_t inst) 1200 { 1201 struct dcn20_opp *opp2 = 1202 kzalloc(sizeof(struct dcn20_opp), GFP_KERNEL); 1203 1204 if (!opp2) { 1205 BREAK_TO_DEBUGGER(); 1206 return NULL; 1207 } 1208 1209 dcn20_opp_construct(opp2, ctx, inst, 1210 &opp_regs[inst], &opp_shift, &opp_mask); 1211 return &opp2->base; 1212 } 1213 1214 1215 static struct timing_generator *dcn32_timing_generator_create( 1216 struct dc_context *ctx, 1217 uint32_t instance) 1218 { 1219 struct optc *tgn10 = 1220 kzalloc(sizeof(struct optc), GFP_KERNEL); 1221 1222 if (!tgn10) 1223 return NULL; 1224 1225 tgn10->base.inst = instance; 1226 tgn10->base.ctx = ctx; 1227 1228 tgn10->tg_regs = &optc_regs[instance]; 1229 tgn10->tg_shift = &optc_shift; 1230 tgn10->tg_mask = &optc_mask; 1231 1232 dcn32_timing_generator_init(tgn10); 1233 1234 return &tgn10->base; 1235 } 1236 1237 static const struct encoder_feature_support link_enc_feature = { 1238 .max_hdmi_deep_color = COLOR_DEPTH_121212, 1239 .max_hdmi_pixel_clock = 600000, 1240 .hdmi_ycbcr420_supported = true, 1241 .dp_ycbcr420_supported = true, 1242 .fec_supported = true, 1243 .flags.bits.IS_HBR2_CAPABLE = true, 1244 .flags.bits.IS_HBR3_CAPABLE = true, 1245 .flags.bits.IS_TPS3_CAPABLE = true, 1246 .flags.bits.IS_TPS4_CAPABLE = true 1247 }; 1248 1249 static struct link_encoder *dcn32_link_encoder_create( 1250 const struct encoder_init_data *enc_init_data) 1251 { 1252 struct dcn20_link_encoder *enc20 = 1253 kzalloc(sizeof(struct dcn20_link_encoder), GFP_KERNEL); 1254 1255 if (!enc20) 1256 return NULL; 1257 1258 dcn32_link_encoder_construct(enc20, 1259 enc_init_data, 1260 &link_enc_feature, 1261 &link_enc_regs[enc_init_data->transmitter], 1262 &link_enc_aux_regs[enc_init_data->channel - 1], 1263 &link_enc_hpd_regs[enc_init_data->hpd_source], 1264 &le_shift, 1265 &le_mask); 1266 1267 return &enc20->enc10.base; 1268 } 1269 1270 struct panel_cntl *dcn32_panel_cntl_create(const struct panel_cntl_init_data *init_data) 1271 { 1272 struct dcn31_panel_cntl *panel_cntl = 1273 kzalloc(sizeof(struct dcn31_panel_cntl), GFP_KERNEL); 1274 1275 if (!panel_cntl) 1276 return NULL; 1277 1278 dcn31_panel_cntl_construct(panel_cntl, init_data); 1279 1280 return &panel_cntl->base; 1281 } 1282 1283 static void read_dce_straps( 1284 struct dc_context *ctx, 1285 struct resource_straps *straps) 1286 { 1287 generic_reg_get(ctx, regDC_PINSTRAPS + BASE(regDC_PINSTRAPS_BASE_IDX), 1288 FN(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO), &straps->dc_pinstraps_audio); 1289 1290 } 1291 1292 static struct audio *dcn32_create_audio( 1293 struct dc_context *ctx, unsigned int inst) 1294 { 1295 return dce_audio_create(ctx, inst, 1296 &audio_regs[inst], &audio_shift, &audio_mask); 1297 } 1298 1299 static struct vpg *dcn32_vpg_create( 1300 struct dc_context *ctx, 1301 uint32_t inst) 1302 { 1303 struct dcn30_vpg *vpg3 = kzalloc(sizeof(struct dcn30_vpg), GFP_KERNEL); 1304 1305 if (!vpg3) 1306 return NULL; 1307 1308 vpg3_construct(vpg3, ctx, inst, 1309 &vpg_regs[inst], 1310 &vpg_shift, 1311 &vpg_mask); 1312 1313 return &vpg3->base; 1314 } 1315 1316 static struct afmt *dcn32_afmt_create( 1317 struct dc_context *ctx, 1318 uint32_t inst) 1319 { 1320 struct dcn30_afmt *afmt3 = kzalloc(sizeof(struct dcn30_afmt), GFP_KERNEL); 1321 1322 if (!afmt3) 1323 return NULL; 1324 1325 afmt3_construct(afmt3, ctx, inst, 1326 &afmt_regs[inst], 1327 &afmt_shift, 1328 &afmt_mask); 1329 1330 return &afmt3->base; 1331 } 1332 1333 static struct apg *dcn31_apg_create( 1334 struct dc_context *ctx, 1335 uint32_t inst) 1336 { 1337 struct dcn31_apg *apg31 = kzalloc(sizeof(struct dcn31_apg), GFP_KERNEL); 1338 1339 if (!apg31) 1340 return NULL; 1341 1342 apg31_construct(apg31, ctx, inst, 1343 &apg_regs[inst], 1344 &apg_shift, 1345 &apg_mask); 1346 1347 return &apg31->base; 1348 } 1349 1350 static struct stream_encoder *dcn32_stream_encoder_create( 1351 enum engine_id eng_id, 1352 struct dc_context *ctx) 1353 { 1354 struct dcn10_stream_encoder *enc1; 1355 struct vpg *vpg; 1356 struct afmt *afmt; 1357 int vpg_inst; 1358 int afmt_inst; 1359 1360 /* Mapping of VPG, AFMT, DME register blocks to DIO block instance */ 1361 if (eng_id <= ENGINE_ID_DIGF) { 1362 vpg_inst = eng_id; 1363 afmt_inst = eng_id; 1364 } else 1365 return NULL; 1366 1367 enc1 = kzalloc(sizeof(struct dcn10_stream_encoder), GFP_KERNEL); 1368 vpg = dcn32_vpg_create(ctx, vpg_inst); 1369 afmt = dcn32_afmt_create(ctx, afmt_inst); 1370 1371 if (!enc1 || !vpg || !afmt) { 1372 kfree(enc1); 1373 kfree(vpg); 1374 kfree(afmt); 1375 return NULL; 1376 } 1377 1378 dcn32_dio_stream_encoder_construct(enc1, ctx, ctx->dc_bios, 1379 eng_id, vpg, afmt, 1380 &stream_enc_regs[eng_id], 1381 &se_shift, &se_mask); 1382 1383 return &enc1->base; 1384 } 1385 1386 static struct hpo_dp_stream_encoder *dcn32_hpo_dp_stream_encoder_create( 1387 enum engine_id eng_id, 1388 struct dc_context *ctx) 1389 { 1390 struct dcn31_hpo_dp_stream_encoder *hpo_dp_enc31; 1391 struct vpg *vpg; 1392 struct apg *apg; 1393 uint32_t hpo_dp_inst; 1394 uint32_t vpg_inst; 1395 uint32_t apg_inst; 1396 1397 ASSERT((eng_id >= ENGINE_ID_HPO_DP_0) && (eng_id <= ENGINE_ID_HPO_DP_3)); 1398 hpo_dp_inst = eng_id - ENGINE_ID_HPO_DP_0; 1399 1400 /* Mapping of VPG register blocks to HPO DP block instance: 1401 * VPG[6] -> HPO_DP[0] 1402 * VPG[7] -> HPO_DP[1] 1403 * VPG[8] -> HPO_DP[2] 1404 * VPG[9] -> HPO_DP[3] 1405 */ 1406 vpg_inst = hpo_dp_inst + 6; 1407 1408 /* Mapping of APG register blocks to HPO DP block instance: 1409 * APG[0] -> HPO_DP[0] 1410 * APG[1] -> HPO_DP[1] 1411 * APG[2] -> HPO_DP[2] 1412 * APG[3] -> HPO_DP[3] 1413 */ 1414 apg_inst = hpo_dp_inst; 1415 1416 /* allocate HPO stream encoder and create VPG sub-block */ 1417 hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_stream_encoder), GFP_KERNEL); 1418 vpg = dcn32_vpg_create(ctx, vpg_inst); 1419 apg = dcn31_apg_create(ctx, apg_inst); 1420 1421 if (!hpo_dp_enc31 || !vpg || !apg) { 1422 kfree(hpo_dp_enc31); 1423 kfree(vpg); 1424 kfree(apg); 1425 return NULL; 1426 } 1427 1428 dcn31_hpo_dp_stream_encoder_construct(hpo_dp_enc31, ctx, ctx->dc_bios, 1429 hpo_dp_inst, eng_id, vpg, apg, 1430 &hpo_dp_stream_enc_regs[hpo_dp_inst], 1431 &hpo_dp_se_shift, &hpo_dp_se_mask); 1432 1433 return &hpo_dp_enc31->base; 1434 } 1435 1436 static struct hpo_dp_link_encoder *dcn32_hpo_dp_link_encoder_create( 1437 uint8_t inst, 1438 struct dc_context *ctx) 1439 { 1440 struct dcn31_hpo_dp_link_encoder *hpo_dp_enc31; 1441 1442 /* allocate HPO link encoder */ 1443 hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_link_encoder), GFP_KERNEL); 1444 1445 hpo_dp_link_encoder32_construct(hpo_dp_enc31, ctx, inst, 1446 &hpo_dp_link_enc_regs[inst], 1447 &hpo_dp_le_shift, &hpo_dp_le_mask); 1448 1449 return &hpo_dp_enc31->base; 1450 } 1451 1452 static struct dce_hwseq *dcn32_hwseq_create( 1453 struct dc_context *ctx) 1454 { 1455 struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL); 1456 1457 if (hws) { 1458 hws->ctx = ctx; 1459 hws->regs = &hwseq_reg; 1460 hws->shifts = &hwseq_shift; 1461 hws->masks = &hwseq_mask; 1462 } 1463 return hws; 1464 } 1465 static const struct resource_create_funcs res_create_funcs = { 1466 .read_dce_straps = read_dce_straps, 1467 .create_audio = dcn32_create_audio, 1468 .create_stream_encoder = dcn32_stream_encoder_create, 1469 .create_hpo_dp_stream_encoder = dcn32_hpo_dp_stream_encoder_create, 1470 .create_hpo_dp_link_encoder = dcn32_hpo_dp_link_encoder_create, 1471 .create_hwseq = dcn32_hwseq_create, 1472 }; 1473 1474 static const struct resource_create_funcs res_create_maximus_funcs = { 1475 .read_dce_straps = NULL, 1476 .create_audio = NULL, 1477 .create_stream_encoder = NULL, 1478 .create_hpo_dp_stream_encoder = dcn32_hpo_dp_stream_encoder_create, 1479 .create_hpo_dp_link_encoder = dcn32_hpo_dp_link_encoder_create, 1480 .create_hwseq = dcn32_hwseq_create, 1481 }; 1482 1483 static void dcn32_resource_destruct(struct dcn32_resource_pool *pool) 1484 { 1485 unsigned int i; 1486 1487 for (i = 0; i < pool->base.stream_enc_count; i++) { 1488 if (pool->base.stream_enc[i] != NULL) { 1489 if (pool->base.stream_enc[i]->vpg != NULL) { 1490 kfree(DCN30_VPG_FROM_VPG(pool->base.stream_enc[i]->vpg)); 1491 pool->base.stream_enc[i]->vpg = NULL; 1492 } 1493 if (pool->base.stream_enc[i]->afmt != NULL) { 1494 kfree(DCN30_AFMT_FROM_AFMT(pool->base.stream_enc[i]->afmt)); 1495 pool->base.stream_enc[i]->afmt = NULL; 1496 } 1497 kfree(DCN10STRENC_FROM_STRENC(pool->base.stream_enc[i])); 1498 pool->base.stream_enc[i] = NULL; 1499 } 1500 } 1501 1502 for (i = 0; i < pool->base.hpo_dp_stream_enc_count; i++) { 1503 if (pool->base.hpo_dp_stream_enc[i] != NULL) { 1504 if (pool->base.hpo_dp_stream_enc[i]->vpg != NULL) { 1505 kfree(DCN30_VPG_FROM_VPG(pool->base.hpo_dp_stream_enc[i]->vpg)); 1506 pool->base.hpo_dp_stream_enc[i]->vpg = NULL; 1507 } 1508 if (pool->base.hpo_dp_stream_enc[i]->apg != NULL) { 1509 kfree(DCN31_APG_FROM_APG(pool->base.hpo_dp_stream_enc[i]->apg)); 1510 pool->base.hpo_dp_stream_enc[i]->apg = NULL; 1511 } 1512 kfree(DCN3_1_HPO_DP_STREAM_ENC_FROM_HPO_STREAM_ENC(pool->base.hpo_dp_stream_enc[i])); 1513 pool->base.hpo_dp_stream_enc[i] = NULL; 1514 } 1515 } 1516 1517 for (i = 0; i < pool->base.hpo_dp_link_enc_count; i++) { 1518 if (pool->base.hpo_dp_link_enc[i] != NULL) { 1519 kfree(DCN3_1_HPO_DP_LINK_ENC_FROM_HPO_LINK_ENC(pool->base.hpo_dp_link_enc[i])); 1520 pool->base.hpo_dp_link_enc[i] = NULL; 1521 } 1522 } 1523 1524 for (i = 0; i < pool->base.res_cap->num_dsc; i++) { 1525 if (pool->base.dscs[i] != NULL) 1526 dcn20_dsc_destroy(&pool->base.dscs[i]); 1527 } 1528 1529 if (pool->base.mpc != NULL) { 1530 kfree(TO_DCN20_MPC(pool->base.mpc)); 1531 pool->base.mpc = NULL; 1532 } 1533 if (pool->base.hubbub != NULL) { 1534 kfree(TO_DCN20_HUBBUB(pool->base.hubbub)); 1535 pool->base.hubbub = NULL; 1536 } 1537 for (i = 0; i < pool->base.pipe_count; i++) { 1538 if (pool->base.dpps[i] != NULL) 1539 dcn32_dpp_destroy(&pool->base.dpps[i]); 1540 1541 if (pool->base.ipps[i] != NULL) 1542 pool->base.ipps[i]->funcs->ipp_destroy(&pool->base.ipps[i]); 1543 1544 if (pool->base.hubps[i] != NULL) { 1545 kfree(TO_DCN20_HUBP(pool->base.hubps[i])); 1546 pool->base.hubps[i] = NULL; 1547 } 1548 1549 if (pool->base.irqs != NULL) { 1550 dal_irq_service_destroy(&pool->base.irqs); 1551 } 1552 } 1553 1554 for (i = 0; i < pool->base.res_cap->num_ddc; i++) { 1555 if (pool->base.engines[i] != NULL) 1556 dce110_engine_destroy(&pool->base.engines[i]); 1557 if (pool->base.hw_i2cs[i] != NULL) { 1558 kfree(pool->base.hw_i2cs[i]); 1559 pool->base.hw_i2cs[i] = NULL; 1560 } 1561 if (pool->base.sw_i2cs[i] != NULL) { 1562 kfree(pool->base.sw_i2cs[i]); 1563 pool->base.sw_i2cs[i] = NULL; 1564 } 1565 } 1566 1567 for (i = 0; i < pool->base.res_cap->num_opp; i++) { 1568 if (pool->base.opps[i] != NULL) 1569 pool->base.opps[i]->funcs->opp_destroy(&pool->base.opps[i]); 1570 } 1571 1572 for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) { 1573 if (pool->base.timing_generators[i] != NULL) { 1574 kfree(DCN10TG_FROM_TG(pool->base.timing_generators[i])); 1575 pool->base.timing_generators[i] = NULL; 1576 } 1577 } 1578 1579 for (i = 0; i < pool->base.res_cap->num_dwb; i++) { 1580 if (pool->base.dwbc[i] != NULL) { 1581 kfree(TO_DCN30_DWBC(pool->base.dwbc[i])); 1582 pool->base.dwbc[i] = NULL; 1583 } 1584 if (pool->base.mcif_wb[i] != NULL) { 1585 kfree(TO_DCN30_MMHUBBUB(pool->base.mcif_wb[i])); 1586 pool->base.mcif_wb[i] = NULL; 1587 } 1588 } 1589 1590 for (i = 0; i < pool->base.audio_count; i++) { 1591 if (pool->base.audios[i]) 1592 dce_aud_destroy(&pool->base.audios[i]); 1593 } 1594 1595 for (i = 0; i < pool->base.clk_src_count; i++) { 1596 if (pool->base.clock_sources[i] != NULL) { 1597 dcn20_clock_source_destroy(&pool->base.clock_sources[i]); 1598 pool->base.clock_sources[i] = NULL; 1599 } 1600 } 1601 1602 for (i = 0; i < pool->base.res_cap->num_mpc_3dlut; i++) { 1603 if (pool->base.mpc_lut[i] != NULL) { 1604 dc_3dlut_func_release(pool->base.mpc_lut[i]); 1605 pool->base.mpc_lut[i] = NULL; 1606 } 1607 if (pool->base.mpc_shaper[i] != NULL) { 1608 dc_transfer_func_release(pool->base.mpc_shaper[i]); 1609 pool->base.mpc_shaper[i] = NULL; 1610 } 1611 } 1612 1613 if (pool->base.dp_clock_source != NULL) { 1614 dcn20_clock_source_destroy(&pool->base.dp_clock_source); 1615 pool->base.dp_clock_source = NULL; 1616 } 1617 1618 for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) { 1619 if (pool->base.multiple_abms[i] != NULL) 1620 dce_abm_destroy(&pool->base.multiple_abms[i]); 1621 } 1622 1623 if (pool->base.psr != NULL) 1624 dmub_psr_destroy(&pool->base.psr); 1625 1626 if (pool->base.dccg != NULL) 1627 dcn_dccg_destroy(&pool->base.dccg); 1628 1629 if (pool->base.oem_device != NULL) 1630 dal_ddc_service_destroy(&pool->base.oem_device); 1631 } 1632 1633 1634 static bool dcn32_dwbc_create(struct dc_context *ctx, struct resource_pool *pool) 1635 { 1636 int i; 1637 uint32_t dwb_count = pool->res_cap->num_dwb; 1638 1639 for (i = 0; i < dwb_count; i++) { 1640 struct dcn30_dwbc *dwbc30 = kzalloc(sizeof(struct dcn30_dwbc), 1641 GFP_KERNEL); 1642 1643 if (!dwbc30) { 1644 dm_error("DC: failed to create dwbc30!\n"); 1645 return false; 1646 } 1647 1648 dcn30_dwbc_construct(dwbc30, ctx, 1649 &dwbc30_regs[i], 1650 &dwbc30_shift, 1651 &dwbc30_mask, 1652 i); 1653 1654 pool->dwbc[i] = &dwbc30->base; 1655 } 1656 return true; 1657 } 1658 1659 static bool dcn32_mmhubbub_create(struct dc_context *ctx, struct resource_pool *pool) 1660 { 1661 int i; 1662 uint32_t dwb_count = pool->res_cap->num_dwb; 1663 1664 for (i = 0; i < dwb_count; i++) { 1665 struct dcn30_mmhubbub *mcif_wb30 = kzalloc(sizeof(struct dcn30_mmhubbub), 1666 GFP_KERNEL); 1667 1668 if (!mcif_wb30) { 1669 dm_error("DC: failed to create mcif_wb30!\n"); 1670 return false; 1671 } 1672 1673 dcn32_mmhubbub_construct(mcif_wb30, ctx, 1674 &mcif_wb30_regs[i], 1675 &mcif_wb30_shift, 1676 &mcif_wb30_mask, 1677 i); 1678 1679 pool->mcif_wb[i] = &mcif_wb30->base; 1680 } 1681 return true; 1682 } 1683 1684 static struct display_stream_compressor *dcn32_dsc_create( 1685 struct dc_context *ctx, uint32_t inst) 1686 { 1687 struct dcn20_dsc *dsc = 1688 kzalloc(sizeof(struct dcn20_dsc), GFP_KERNEL); 1689 1690 if (!dsc) { 1691 BREAK_TO_DEBUGGER(); 1692 return NULL; 1693 } 1694 1695 dsc2_construct(dsc, ctx, inst, &dsc_regs[inst], &dsc_shift, &dsc_mask); 1696 1697 dsc->max_image_width = 6016; 1698 1699 return &dsc->base; 1700 } 1701 1702 static void dcn32_destroy_resource_pool(struct resource_pool **pool) 1703 { 1704 struct dcn32_resource_pool *dcn32_pool = TO_DCN32_RES_POOL(*pool); 1705 1706 dcn32_resource_destruct(dcn32_pool); 1707 kfree(dcn32_pool); 1708 *pool = NULL; 1709 } 1710 1711 bool dcn32_acquire_post_bldn_3dlut( 1712 struct resource_context *res_ctx, 1713 const struct resource_pool *pool, 1714 int mpcc_id, 1715 struct dc_3dlut **lut, 1716 struct dc_transfer_func **shaper) 1717 { 1718 bool ret = false; 1719 union dc_3dlut_state *state; 1720 1721 ASSERT(*lut == NULL && *shaper == NULL); 1722 *lut = NULL; 1723 *shaper = NULL; 1724 1725 if (!res_ctx->is_mpc_3dlut_acquired[mpcc_id]) { 1726 *lut = pool->mpc_lut[mpcc_id]; 1727 *shaper = pool->mpc_shaper[mpcc_id]; 1728 state = &pool->mpc_lut[mpcc_id]->state; 1729 res_ctx->is_mpc_3dlut_acquired[mpcc_id] = true; 1730 ret = true; 1731 } 1732 return ret; 1733 } 1734 1735 bool dcn32_release_post_bldn_3dlut( 1736 struct resource_context *res_ctx, 1737 const struct resource_pool *pool, 1738 struct dc_3dlut **lut, 1739 struct dc_transfer_func **shaper) 1740 { 1741 int i; 1742 bool ret = false; 1743 1744 for (i = 0; i < pool->res_cap->num_mpc_3dlut; i++) { 1745 if (pool->mpc_lut[i] == *lut && pool->mpc_shaper[i] == *shaper) { 1746 res_ctx->is_mpc_3dlut_acquired[i] = false; 1747 pool->mpc_lut[i]->state.raw = 0; 1748 *lut = NULL; 1749 *shaper = NULL; 1750 ret = true; 1751 break; 1752 } 1753 } 1754 return ret; 1755 } 1756 1757 /** 1758 ******************************************************************************************** 1759 * dcn32_get_num_free_pipes: Calculate number of free pipes 1760 * 1761 * This function assumes that a "used" pipe is a pipe that has 1762 * both a stream and a plane assigned to it. 1763 * 1764 * @param [in] dc: current dc state 1765 * @param [in] context: new dc state 1766 * 1767 * @return: Number of free pipes available in the context 1768 * 1769 ******************************************************************************************** 1770 */ 1771 static unsigned int dcn32_get_num_free_pipes(struct dc *dc, struct dc_state *context) 1772 { 1773 unsigned int i; 1774 unsigned int free_pipes = 0; 1775 unsigned int num_pipes = 0; 1776 1777 for (i = 0; i < dc->res_pool->pipe_count; i++) { 1778 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 1779 1780 if (pipe->stream && !pipe->top_pipe) { 1781 while (pipe) { 1782 num_pipes++; 1783 pipe = pipe->bottom_pipe; 1784 } 1785 } 1786 } 1787 1788 free_pipes = dc->res_pool->pipe_count - num_pipes; 1789 return free_pipes; 1790 } 1791 1792 /** 1793 ******************************************************************************************** 1794 * dcn32_assign_subvp_pipe: Function to decide which pipe will use Sub-VP. 1795 * 1796 * We enter this function if we are Sub-VP capable (i.e. enough pipes available) 1797 * and regular P-State switching (i.e. VACTIVE/VBLANK) is not supported, or if 1798 * we are forcing SubVP P-State switching on the current config. 1799 * 1800 * The number of pipes used for the chosen surface must be less than or equal to the 1801 * number of free pipes available. 1802 * 1803 * In general we choose surfaces with the longest frame time first (better for SubVP + VBLANK). 1804 * For multi-display cases the ActiveDRAMClockChangeMargin doesn't provide enough info on its own 1805 * for determining which should be the SubVP pipe (need a way to determine if a pipe / plane doesn't 1806 * support MCLK switching naturally [i.e. ACTIVE or VBLANK]). 1807 * 1808 * @param [in] dc: current dc state 1809 * @param [in] context: new dc state 1810 * @param [out] index: dc pipe index for the pipe chosen to have phantom pipes assigned 1811 * 1812 * @return: True if a valid pipe assignment was found for Sub-VP. Otherwise false. 1813 * 1814 ******************************************************************************************** 1815 */ 1816 1817 static bool dcn32_assign_subvp_pipe(struct dc *dc, 1818 struct dc_state *context, 1819 unsigned int *index) 1820 { 1821 unsigned int i, pipe_idx; 1822 unsigned int max_frame_time = 0; 1823 bool valid_assignment_found = false; 1824 unsigned int free_pipes = dcn32_get_num_free_pipes(dc, context); 1825 bool current_assignment_freesync = false; 1826 1827 for (i = 0, pipe_idx = 0; i < dc->res_pool->pipe_count; i++) { 1828 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 1829 unsigned int num_pipes = 0; 1830 1831 if (!pipe->stream) 1832 continue; 1833 1834 if (pipe->plane_state && !pipe->top_pipe && 1835 pipe->stream->mall_stream_config.type == SUBVP_NONE) { 1836 while (pipe) { 1837 num_pipes++; 1838 pipe = pipe->bottom_pipe; 1839 } 1840 1841 pipe = &context->res_ctx.pipe_ctx[i]; 1842 if (num_pipes <= free_pipes) { 1843 struct dc_stream_state *stream = pipe->stream; 1844 unsigned int frame_us = (stream->timing.v_total * stream->timing.h_total / 1845 (double)(stream->timing.pix_clk_100hz * 100)) * 1000000; 1846 if (frame_us > max_frame_time && !stream->ignore_msa_timing_param) { 1847 *index = i; 1848 max_frame_time = frame_us; 1849 valid_assignment_found = true; 1850 current_assignment_freesync = false; 1851 /* For the 2-Freesync display case, still choose the one with the 1852 * longest frame time 1853 */ 1854 } else if (stream->ignore_msa_timing_param && (!valid_assignment_found || 1855 (current_assignment_freesync && frame_us > max_frame_time))) { 1856 *index = i; 1857 valid_assignment_found = true; 1858 current_assignment_freesync = true; 1859 } 1860 } 1861 } 1862 pipe_idx++; 1863 } 1864 return valid_assignment_found; 1865 } 1866 1867 /** 1868 * *************************************************************************************** 1869 * dcn32_enough_pipes_for_subvp: Function to check if there are "enough" pipes for SubVP. 1870 * 1871 * This function returns true if there are enough free pipes 1872 * to create the required phantom pipes for any given stream 1873 * (that does not already have phantom pipe assigned). 1874 * 1875 * e.g. For a 2 stream config where the first stream uses one 1876 * pipe and the second stream uses 2 pipes (i.e. pipe split), 1877 * this function will return true because there is 1 remaining 1878 * pipe which can be used as the phantom pipe for the non pipe 1879 * split pipe. 1880 * 1881 * @param [in] dc: current dc state 1882 * @param [in] context: new dc state 1883 * 1884 * @return: True if there are enough free pipes to assign phantom pipes to at least one 1885 * stream that does not already have phantom pipes assigned. Otherwise false. 1886 * 1887 * *************************************************************************************** 1888 */ 1889 static bool dcn32_enough_pipes_for_subvp(struct dc *dc, struct dc_state *context) 1890 { 1891 unsigned int i, split_cnt, free_pipes; 1892 unsigned int min_pipe_split = dc->res_pool->pipe_count + 1; // init as max number of pipes + 1 1893 bool subvp_possible = false; 1894 1895 for (i = 0; i < dc->res_pool->pipe_count; i++) { 1896 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 1897 1898 // Find the minimum pipe split count for non SubVP pipes 1899 if (pipe->stream && !pipe->top_pipe && 1900 pipe->stream->mall_stream_config.type == SUBVP_NONE) { 1901 split_cnt = 0; 1902 while (pipe) { 1903 split_cnt++; 1904 pipe = pipe->bottom_pipe; 1905 } 1906 1907 if (split_cnt < min_pipe_split) 1908 min_pipe_split = split_cnt; 1909 } 1910 } 1911 1912 free_pipes = dcn32_get_num_free_pipes(dc, context); 1913 1914 // SubVP only possible if at least one pipe is being used (i.e. free_pipes 1915 // should not equal to the pipe_count) 1916 if (free_pipes >= min_pipe_split && free_pipes < dc->res_pool->pipe_count) 1917 subvp_possible = true; 1918 1919 return subvp_possible; 1920 } 1921 1922 static void dcn32_enable_phantom_plane(struct dc *dc, 1923 struct dc_state *context, 1924 struct dc_stream_state *phantom_stream, 1925 unsigned int dc_pipe_idx) 1926 { 1927 struct dc_plane_state *phantom_plane = NULL; 1928 struct dc_plane_state *prev_phantom_plane = NULL; 1929 struct pipe_ctx *curr_pipe = &context->res_ctx.pipe_ctx[dc_pipe_idx]; 1930 1931 while (curr_pipe) { 1932 if (curr_pipe->top_pipe && curr_pipe->top_pipe->plane_state == curr_pipe->plane_state) 1933 phantom_plane = prev_phantom_plane; 1934 else 1935 phantom_plane = dc_create_plane_state(dc); 1936 1937 memcpy(&phantom_plane->address, &curr_pipe->plane_state->address, sizeof(phantom_plane->address)); 1938 memcpy(&phantom_plane->scaling_quality, &curr_pipe->plane_state->scaling_quality, 1939 sizeof(phantom_plane->scaling_quality)); 1940 memcpy(&phantom_plane->src_rect, &curr_pipe->plane_state->src_rect, sizeof(phantom_plane->src_rect)); 1941 memcpy(&phantom_plane->dst_rect, &curr_pipe->plane_state->dst_rect, sizeof(phantom_plane->dst_rect)); 1942 memcpy(&phantom_plane->clip_rect, &curr_pipe->plane_state->clip_rect, sizeof(phantom_plane->clip_rect)); 1943 memcpy(&phantom_plane->plane_size, &curr_pipe->plane_state->plane_size, 1944 sizeof(phantom_plane->plane_size)); 1945 memcpy(&phantom_plane->tiling_info, &curr_pipe->plane_state->tiling_info, 1946 sizeof(phantom_plane->tiling_info)); 1947 memcpy(&phantom_plane->dcc, &curr_pipe->plane_state->dcc, sizeof(phantom_plane->dcc)); 1948 phantom_plane->format = curr_pipe->plane_state->format; 1949 phantom_plane->rotation = curr_pipe->plane_state->rotation; 1950 phantom_plane->visible = curr_pipe->plane_state->visible; 1951 1952 /* Shadow pipe has small viewport. */ 1953 phantom_plane->clip_rect.y = 0; 1954 phantom_plane->clip_rect.height = phantom_stream->timing.v_addressable; 1955 1956 dc_add_plane_to_context(dc, phantom_stream, phantom_plane, context); 1957 1958 curr_pipe = curr_pipe->bottom_pipe; 1959 prev_phantom_plane = phantom_plane; 1960 } 1961 } 1962 1963 /** 1964 * *************************************************************************************** 1965 * dcn32_set_phantom_stream_timing: Set timing params for the phantom stream 1966 * 1967 * Set timing params of the phantom stream based on calculated output from DML. 1968 * This function first gets the DML pipe index using the DC pipe index, then 1969 * calls into DML (get_subviewport_lines_needed_in_mall) to get the number of 1970 * lines required for SubVP MCLK switching and assigns to the phantom stream 1971 * accordingly. 1972 * 1973 * - The number of SubVP lines calculated in DML does not take into account 1974 * FW processing delays and required pstate allow width, so we must include 1975 * that separately. 1976 * 1977 * - Set phantom backporch = vstartup of main pipe 1978 * 1979 * @param [in] dc: current dc state 1980 * @param [in] context: new dc state 1981 * @param [in] ref_pipe: Main pipe for the phantom stream 1982 * @param [in] pipes: DML pipe params 1983 * @param [in] pipe_cnt: number of DML pipes 1984 * @param [in] dc_pipe_idx: DC pipe index for the main pipe (i.e. ref_pipe) 1985 * 1986 * @return: void 1987 * 1988 * *************************************************************************************** 1989 */ 1990 static void dcn32_set_phantom_stream_timing(struct dc *dc, 1991 struct dc_state *context, 1992 struct pipe_ctx *ref_pipe, 1993 struct dc_stream_state *phantom_stream, 1994 display_e2e_pipe_params_st *pipes, 1995 unsigned int pipe_cnt, 1996 unsigned int dc_pipe_idx) 1997 { 1998 unsigned int i, pipe_idx; 1999 struct pipe_ctx *pipe; 2000 uint32_t phantom_vactive, phantom_bp, pstate_width_fw_delay_lines; 2001 unsigned int vlevel = context->bw_ctx.dml.vba.VoltageLevel; 2002 unsigned int dcfclk = context->bw_ctx.dml.vba.DCFCLKState[vlevel][context->bw_ctx.dml.vba.maxMpcComb]; 2003 unsigned int socclk = context->bw_ctx.dml.vba.SOCCLKPerState[vlevel]; 2004 2005 // Find DML pipe index (pipe_idx) using dc_pipe_idx 2006 for (i = 0, pipe_idx = 0; i < dc->res_pool->pipe_count; i++) { 2007 pipe = &context->res_ctx.pipe_ctx[i]; 2008 2009 if (!pipe->stream) 2010 continue; 2011 2012 if (i == dc_pipe_idx) 2013 break; 2014 2015 pipe_idx++; 2016 } 2017 2018 // Calculate lines required for pstate allow width and FW processing delays 2019 pstate_width_fw_delay_lines = ((double)(dc->caps.subvp_fw_processing_delay_us + 2020 dc->caps.subvp_pstate_allow_width_us) / 1000000) * 2021 (ref_pipe->stream->timing.pix_clk_100hz * 100) / 2022 (double)ref_pipe->stream->timing.h_total; 2023 2024 // Update clks_cfg for calling into recalculate 2025 pipes[0].clks_cfg.voltage = vlevel; 2026 pipes[0].clks_cfg.dcfclk_mhz = dcfclk; 2027 pipes[0].clks_cfg.socclk_mhz = socclk; 2028 2029 // DML calculation for MALL region doesn't take into account FW delay 2030 // and required pstate allow width for multi-display cases 2031 phantom_vactive = get_subviewport_lines_needed_in_mall(&context->bw_ctx.dml, pipes, pipe_cnt, pipe_idx) + 2032 pstate_width_fw_delay_lines; 2033 2034 // For backporch of phantom pipe, use vstartup of the main pipe 2035 phantom_bp = get_vstartup(&context->bw_ctx.dml, pipes, pipe_cnt, pipe_idx); 2036 2037 phantom_stream->dst.y = 0; 2038 phantom_stream->dst.height = phantom_vactive; 2039 phantom_stream->src.y = 0; 2040 phantom_stream->src.height = phantom_vactive; 2041 2042 phantom_stream->timing.v_addressable = phantom_vactive; 2043 phantom_stream->timing.v_front_porch = 1; 2044 phantom_stream->timing.v_total = phantom_stream->timing.v_addressable + 2045 phantom_stream->timing.v_front_porch + 2046 phantom_stream->timing.v_sync_width + 2047 phantom_bp; 2048 } 2049 2050 static struct dc_stream_state *dcn32_enable_phantom_stream(struct dc *dc, 2051 struct dc_state *context, 2052 display_e2e_pipe_params_st *pipes, 2053 unsigned int pipe_cnt, 2054 unsigned int dc_pipe_idx) 2055 { 2056 struct dc_stream_state *phantom_stream = NULL; 2057 struct pipe_ctx *ref_pipe = &context->res_ctx.pipe_ctx[dc_pipe_idx]; 2058 2059 phantom_stream = dc_create_stream_for_sink(ref_pipe->stream->sink); 2060 phantom_stream->signal = SIGNAL_TYPE_VIRTUAL; 2061 phantom_stream->dpms_off = true; 2062 phantom_stream->mall_stream_config.type = SUBVP_PHANTOM; 2063 phantom_stream->mall_stream_config.paired_stream = ref_pipe->stream; 2064 ref_pipe->stream->mall_stream_config.type = SUBVP_MAIN; 2065 ref_pipe->stream->mall_stream_config.paired_stream = phantom_stream; 2066 2067 /* stream has limited viewport and small timing */ 2068 memcpy(&phantom_stream->timing, &ref_pipe->stream->timing, sizeof(phantom_stream->timing)); 2069 memcpy(&phantom_stream->src, &ref_pipe->stream->src, sizeof(phantom_stream->src)); 2070 memcpy(&phantom_stream->dst, &ref_pipe->stream->dst, sizeof(phantom_stream->dst)); 2071 dcn32_set_phantom_stream_timing(dc, context, ref_pipe, phantom_stream, pipes, pipe_cnt, dc_pipe_idx); 2072 2073 dc_add_stream_to_ctx(dc, context, phantom_stream); 2074 return phantom_stream; 2075 } 2076 2077 // return true if removed piped from ctx, false otherwise 2078 bool dcn32_remove_phantom_pipes(struct dc *dc, struct dc_state *context) 2079 { 2080 int i; 2081 bool removed_pipe = false; 2082 2083 for (i = 0; i < dc->res_pool->pipe_count; i++) { 2084 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 2085 // build scaling params for phantom pipes 2086 if (pipe->plane_state && pipe->stream && pipe->stream->mall_stream_config.type == SUBVP_PHANTOM) { 2087 dc_rem_all_planes_for_stream(dc, pipe->stream, context); 2088 dc_remove_stream_from_ctx(dc, context, pipe->stream); 2089 removed_pipe = true; 2090 } 2091 2092 // Clear all phantom stream info 2093 if (pipe->stream) { 2094 pipe->stream->mall_stream_config.type = SUBVP_NONE; 2095 pipe->stream->mall_stream_config.paired_stream = NULL; 2096 } 2097 } 2098 return removed_pipe; 2099 } 2100 2101 /* TODO: Input to this function should indicate which pipe indexes (or streams) 2102 * require a phantom pipe / stream 2103 */ 2104 void dcn32_add_phantom_pipes(struct dc *dc, struct dc_state *context, 2105 display_e2e_pipe_params_st *pipes, 2106 unsigned int pipe_cnt, 2107 unsigned int index) 2108 { 2109 struct dc_stream_state *phantom_stream = NULL; 2110 unsigned int i; 2111 2112 // The index of the DC pipe passed into this function is guarenteed to 2113 // be a valid candidate for SubVP (i.e. has a plane, stream, doesn't 2114 // already have phantom pipe assigned, etc.) by previous checks. 2115 phantom_stream = dcn32_enable_phantom_stream(dc, context, pipes, pipe_cnt, index); 2116 dcn32_enable_phantom_plane(dc, context, phantom_stream, index); 2117 2118 for (i = 0; i < dc->res_pool->pipe_count; i++) { 2119 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 2120 2121 // Build scaling params for phantom pipes which were newly added. 2122 // We determine which phantom pipes were added by comparing with 2123 // the phantom stream. 2124 if (pipe->plane_state && pipe->stream && pipe->stream == phantom_stream && 2125 pipe->stream->mall_stream_config.type == SUBVP_PHANTOM) { 2126 pipe->stream->use_dynamic_meta = false; 2127 pipe->plane_state->flip_immediate = false; 2128 if (!resource_build_scaling_params(pipe)) { 2129 // Log / remove phantom pipes since failed to build scaling params 2130 } 2131 } 2132 } 2133 } 2134 2135 static bool dcn32_split_stream_for_mpc_or_odm( 2136 const struct dc *dc, 2137 struct resource_context *res_ctx, 2138 struct pipe_ctx *pri_pipe, 2139 struct pipe_ctx *sec_pipe, 2140 bool odm) 2141 { 2142 int pipe_idx = sec_pipe->pipe_idx; 2143 const struct resource_pool *pool = dc->res_pool; 2144 2145 if (pri_pipe->plane_state) { 2146 /* ODM + window MPO, where MPO window is on left half only */ 2147 if (pri_pipe->plane_state->clip_rect.x + pri_pipe->plane_state->clip_rect.width <= 2148 pri_pipe->stream->src.x + pri_pipe->stream->src.width/2) 2149 return true; 2150 2151 /* ODM + window MPO, where MPO window is on right half only */ 2152 if (pri_pipe->plane_state->clip_rect.x >= pri_pipe->stream->src.width/2) 2153 return true; 2154 } 2155 2156 *sec_pipe = *pri_pipe; 2157 2158 sec_pipe->pipe_idx = pipe_idx; 2159 sec_pipe->plane_res.mi = pool->mis[pipe_idx]; 2160 sec_pipe->plane_res.hubp = pool->hubps[pipe_idx]; 2161 sec_pipe->plane_res.ipp = pool->ipps[pipe_idx]; 2162 sec_pipe->plane_res.xfm = pool->transforms[pipe_idx]; 2163 sec_pipe->plane_res.dpp = pool->dpps[pipe_idx]; 2164 sec_pipe->plane_res.mpcc_inst = pool->dpps[pipe_idx]->inst; 2165 sec_pipe->stream_res.dsc = NULL; 2166 if (odm) { 2167 if (pri_pipe->next_odm_pipe) { 2168 ASSERT(pri_pipe->next_odm_pipe != sec_pipe); 2169 sec_pipe->next_odm_pipe = pri_pipe->next_odm_pipe; 2170 sec_pipe->next_odm_pipe->prev_odm_pipe = sec_pipe; 2171 } 2172 if (pri_pipe->top_pipe && pri_pipe->top_pipe->next_odm_pipe) { 2173 pri_pipe->top_pipe->next_odm_pipe->bottom_pipe = sec_pipe; 2174 sec_pipe->top_pipe = pri_pipe->top_pipe->next_odm_pipe; 2175 } 2176 if (pri_pipe->bottom_pipe && pri_pipe->bottom_pipe->next_odm_pipe) { 2177 pri_pipe->bottom_pipe->next_odm_pipe->top_pipe = sec_pipe; 2178 sec_pipe->bottom_pipe = pri_pipe->bottom_pipe->next_odm_pipe; 2179 } 2180 pri_pipe->next_odm_pipe = sec_pipe; 2181 sec_pipe->prev_odm_pipe = pri_pipe; 2182 ASSERT(sec_pipe->top_pipe == NULL); 2183 2184 if (!sec_pipe->top_pipe) 2185 sec_pipe->stream_res.opp = pool->opps[pipe_idx]; 2186 else 2187 sec_pipe->stream_res.opp = sec_pipe->top_pipe->stream_res.opp; 2188 if (sec_pipe->stream->timing.flags.DSC == 1) { 2189 dcn20_acquire_dsc(dc, res_ctx, &sec_pipe->stream_res.dsc, pipe_idx); 2190 ASSERT(sec_pipe->stream_res.dsc); 2191 if (sec_pipe->stream_res.dsc == NULL) 2192 return false; 2193 } 2194 } else { 2195 if (pri_pipe->bottom_pipe) { 2196 ASSERT(pri_pipe->bottom_pipe != sec_pipe); 2197 sec_pipe->bottom_pipe = pri_pipe->bottom_pipe; 2198 sec_pipe->bottom_pipe->top_pipe = sec_pipe; 2199 } 2200 pri_pipe->bottom_pipe = sec_pipe; 2201 sec_pipe->top_pipe = pri_pipe; 2202 2203 ASSERT(pri_pipe->plane_state); 2204 } 2205 2206 return true; 2207 } 2208 2209 static struct pipe_ctx *dcn32_find_split_pipe( 2210 struct dc *dc, 2211 struct dc_state *context, 2212 int old_index) 2213 { 2214 struct pipe_ctx *pipe = NULL; 2215 int i; 2216 2217 if (old_index >= 0 && context->res_ctx.pipe_ctx[old_index].stream == NULL) { 2218 pipe = &context->res_ctx.pipe_ctx[old_index]; 2219 pipe->pipe_idx = old_index; 2220 } 2221 2222 if (!pipe) 2223 for (i = dc->res_pool->pipe_count - 1; i >= 0; i--) { 2224 if (dc->current_state->res_ctx.pipe_ctx[i].top_pipe == NULL 2225 && dc->current_state->res_ctx.pipe_ctx[i].prev_odm_pipe == NULL) { 2226 if (context->res_ctx.pipe_ctx[i].stream == NULL) { 2227 pipe = &context->res_ctx.pipe_ctx[i]; 2228 pipe->pipe_idx = i; 2229 break; 2230 } 2231 } 2232 } 2233 2234 /* 2235 * May need to fix pipes getting tossed from 1 opp to another on flip 2236 * Add for debugging transient underflow during topology updates: 2237 * ASSERT(pipe); 2238 */ 2239 if (!pipe) 2240 for (i = dc->res_pool->pipe_count - 1; i >= 0; i--) { 2241 if (context->res_ctx.pipe_ctx[i].stream == NULL) { 2242 pipe = &context->res_ctx.pipe_ctx[i]; 2243 pipe->pipe_idx = i; 2244 break; 2245 } 2246 } 2247 2248 return pipe; 2249 } 2250 2251 2252 /** 2253 * *************************************************************************************** 2254 * subvp_subvp_schedulable: Determine if SubVP + SubVP config is schedulable 2255 * 2256 * High level algorithm: 2257 * 1. Find longest microschedule length (in us) between the two SubVP pipes 2258 * 2. Check if the worst case overlap (VBLANK in middle of ACTIVE) for both 2259 * pipes still allows for the maximum microschedule to fit in the active 2260 * region for both pipes. 2261 * 2262 * @param [in] dc: current dc state 2263 * @param [in] context: new dc state 2264 * 2265 * @return: bool - True if the SubVP + SubVP config is schedulable, false otherwise 2266 * 2267 * *************************************************************************************** 2268 */ 2269 static bool subvp_subvp_schedulable(struct dc *dc, struct dc_state *context) 2270 { 2271 struct pipe_ctx *subvp_pipes[2]; 2272 struct dc_stream_state *phantom = NULL; 2273 uint32_t microschedule_lines = 0; 2274 uint32_t index = 0; 2275 uint32_t i; 2276 uint32_t max_microschedule_us = 0; 2277 int32_t vactive1_us, vactive2_us, vblank1_us, vblank2_us; 2278 2279 for (i = 0; i < dc->res_pool->pipe_count; i++) { 2280 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 2281 uint32_t time_us = 0; 2282 2283 /* Loop to calculate the maximum microschedule time between the two SubVP pipes, 2284 * and also to store the two main SubVP pipe pointers in subvp_pipes[2]. 2285 */ 2286 if (pipe->stream && pipe->plane_state && !pipe->top_pipe && 2287 pipe->stream->mall_stream_config.type == SUBVP_MAIN) { 2288 phantom = pipe->stream->mall_stream_config.paired_stream; 2289 microschedule_lines = (phantom->timing.v_total - phantom->timing.v_front_porch) + 2290 phantom->timing.v_addressable; 2291 2292 // Round up when calculating microschedule time (+ 1 at the end) 2293 time_us = (microschedule_lines * phantom->timing.h_total) / 2294 (double)(phantom->timing.pix_clk_100hz * 100) * 1000000 + 2295 dc->caps.subvp_prefetch_end_to_mall_start_us + 2296 dc->caps.subvp_fw_processing_delay_us + 1; 2297 if (time_us > max_microschedule_us) 2298 max_microschedule_us = time_us; 2299 2300 subvp_pipes[index] = pipe; 2301 index++; 2302 2303 // Maximum 2 SubVP pipes 2304 if (index == 2) 2305 break; 2306 } 2307 } 2308 vactive1_us = ((subvp_pipes[0]->stream->timing.v_addressable * subvp_pipes[0]->stream->timing.h_total) / 2309 (double)(subvp_pipes[0]->stream->timing.pix_clk_100hz * 100)) * 1000000; 2310 vactive2_us = ((subvp_pipes[1]->stream->timing.v_addressable * subvp_pipes[1]->stream->timing.h_total) / 2311 (double)(subvp_pipes[1]->stream->timing.pix_clk_100hz * 100)) * 1000000; 2312 vblank1_us = (((subvp_pipes[0]->stream->timing.v_total - subvp_pipes[0]->stream->timing.v_addressable) * 2313 subvp_pipes[0]->stream->timing.h_total) / 2314 (double)(subvp_pipes[0]->stream->timing.pix_clk_100hz * 100)) * 1000000; 2315 vblank2_us = (((subvp_pipes[1]->stream->timing.v_total - subvp_pipes[1]->stream->timing.v_addressable) * 2316 subvp_pipes[1]->stream->timing.h_total) / 2317 (double)(subvp_pipes[1]->stream->timing.pix_clk_100hz * 100)) * 1000000; 2318 2319 if ((vactive1_us - vblank2_us) / 2 > max_microschedule_us && 2320 (vactive2_us - vblank1_us) / 2 > max_microschedule_us) 2321 return true; 2322 2323 return false; 2324 } 2325 2326 /** 2327 * *************************************************************************************** 2328 * subvp_drr_schedulable: Determine if SubVP + DRR config is schedulable 2329 * 2330 * High level algorithm: 2331 * 1. Get timing for SubVP pipe, phantom pipe, and DRR pipe 2332 * 2. Determine the frame time for the DRR display when adding required margin for MCLK switching 2333 * (the margin is equal to the MALL region + DRR margin (500us)) 2334 * 3.If (SubVP Active - Prefetch > Stretched DRR frame + max(MALL region, Stretched DRR frame)) 2335 * then report the configuration as supported 2336 * 2337 * @param [in] dc: current dc state 2338 * @param [in] context: new dc state 2339 * @param [in] drr_pipe: DRR pipe_ctx for the SubVP + DRR config 2340 * 2341 * @return: bool - True if the SubVP + DRR config is schedulable, false otherwise 2342 * 2343 * *************************************************************************************** 2344 */ 2345 static bool subvp_drr_schedulable(struct dc *dc, struct dc_state *context, struct pipe_ctx *drr_pipe) 2346 { 2347 bool schedulable = false; 2348 uint32_t i; 2349 struct pipe_ctx *pipe = NULL; 2350 struct dc_crtc_timing *main_timing = NULL; 2351 struct dc_crtc_timing *phantom_timing = NULL; 2352 struct dc_crtc_timing *drr_timing = NULL; 2353 int16_t prefetch_us = 0; 2354 int16_t mall_region_us = 0; 2355 int16_t drr_frame_us = 0; // nominal frame time 2356 int16_t subvp_active_us = 0; 2357 int16_t stretched_drr_us = 0; 2358 int16_t drr_stretched_vblank_us = 0; 2359 int16_t max_vblank_mallregion = 0; 2360 2361 // Find SubVP pipe 2362 for (i = 0; i < dc->res_pool->pipe_count; i++) { 2363 pipe = &context->res_ctx.pipe_ctx[i]; 2364 2365 // We check for master pipe, but it shouldn't matter since we only need 2366 // the pipe for timing info (stream should be same for any pipe splits) 2367 if (!pipe->stream || !pipe->plane_state || pipe->top_pipe || pipe->prev_odm_pipe) 2368 continue; 2369 2370 // Find the SubVP pipe 2371 if (pipe->stream->mall_stream_config.type == SUBVP_MAIN) 2372 break; 2373 } 2374 2375 main_timing = &pipe->stream->timing; 2376 phantom_timing = &pipe->stream->mall_stream_config.paired_stream->timing; 2377 drr_timing = &drr_pipe->stream->timing; 2378 prefetch_us = (phantom_timing->v_total - phantom_timing->v_front_porch) * phantom_timing->h_total / 2379 (double)(phantom_timing->pix_clk_100hz * 100) * 1000000 + 2380 dc->caps.subvp_prefetch_end_to_mall_start_us; 2381 subvp_active_us = main_timing->v_addressable * main_timing->h_total / 2382 (double)(main_timing->pix_clk_100hz * 100) * 1000000; 2383 drr_frame_us = drr_timing->v_total * drr_timing->h_total / 2384 (double)(drr_timing->pix_clk_100hz * 100) * 1000000; 2385 // P-State allow width and FW delays already included phantom_timing->v_addressable 2386 mall_region_us = phantom_timing->v_addressable * phantom_timing->h_total / 2387 (double)(phantom_timing->pix_clk_100hz * 100) * 1000000; 2388 stretched_drr_us = drr_frame_us + mall_region_us + SUBVP_DRR_MARGIN_US; 2389 drr_stretched_vblank_us = (drr_timing->v_total - drr_timing->v_addressable) * drr_timing->h_total / 2390 (double)(drr_timing->pix_clk_100hz * 100) * 1000000 + (stretched_drr_us - drr_frame_us); 2391 max_vblank_mallregion = drr_stretched_vblank_us > mall_region_us ? drr_stretched_vblank_us : mall_region_us; 2392 2393 /* We consider SubVP + DRR schedulable if the stretched frame duration of the DRR display (i.e. the 2394 * highest refresh rate + margin that can support UCLK P-State switch) passes the static analysis 2395 * for VBLANK: (VACTIVE region of the SubVP pipe can fit the MALL prefetch, VBLANK frame time, 2396 * and the max of (VBLANK blanking time, MALL region)). 2397 */ 2398 if (stretched_drr_us < (1 / (double)drr_timing->min_refresh_in_uhz) * 1000000 * 1000000 && 2399 subvp_active_us - prefetch_us - stretched_drr_us - max_vblank_mallregion > 0) 2400 schedulable = true; 2401 2402 return schedulable; 2403 } 2404 2405 /** 2406 * *************************************************************************************** 2407 * subvp_vblank_schedulable: Determine if SubVP + VBLANK config is schedulable 2408 * 2409 * High level algorithm: 2410 * 1. Get timing for SubVP pipe, phantom pipe, and VBLANK pipe 2411 * 2. If (SubVP Active - Prefetch > Vblank Frame Time + max(MALL region, Vblank blanking time)) 2412 * then report the configuration as supported 2413 * 3. If the VBLANK display is DRR, then take the DRR static schedulability path 2414 * 2415 * @param [in] dc: current dc state 2416 * @param [in] context: new dc state 2417 * 2418 * @return: bool - True if the SubVP + VBLANK/DRR config is schedulable, false otherwise 2419 * 2420 * *************************************************************************************** 2421 */ 2422 static bool subvp_vblank_schedulable(struct dc *dc, struct dc_state *context) 2423 { 2424 struct pipe_ctx *pipe = NULL; 2425 struct pipe_ctx *subvp_pipe = NULL; 2426 bool found = false; 2427 bool schedulable = false; 2428 uint32_t i = 0; 2429 uint8_t vblank_index = 0; 2430 uint16_t prefetch_us = 0; 2431 uint16_t mall_region_us = 0; 2432 uint16_t vblank_frame_us = 0; 2433 uint16_t subvp_active_us = 0; 2434 uint16_t vblank_blank_us = 0; 2435 uint16_t max_vblank_mallregion = 0; 2436 struct dc_crtc_timing *main_timing = NULL; 2437 struct dc_crtc_timing *phantom_timing = NULL; 2438 struct dc_crtc_timing *vblank_timing = NULL; 2439 2440 /* For SubVP + VBLANK/DRR cases, we assume there can only be 2441 * a single VBLANK/DRR display. If DML outputs SubVP + VBLANK 2442 * is supported, it is either a single VBLANK case or two VBLANK 2443 * displays which are synchronized (in which case they have identical 2444 * timings). 2445 */ 2446 for (i = 0; i < dc->res_pool->pipe_count; i++) { 2447 pipe = &context->res_ctx.pipe_ctx[i]; 2448 2449 // We check for master pipe, but it shouldn't matter since we only need 2450 // the pipe for timing info (stream should be same for any pipe splits) 2451 if (!pipe->stream || !pipe->plane_state || pipe->top_pipe || pipe->prev_odm_pipe) 2452 continue; 2453 2454 if (!found && pipe->stream->mall_stream_config.type == SUBVP_NONE) { 2455 // Found pipe which is not SubVP or Phantom (i.e. the VBLANK pipe). 2456 vblank_index = i; 2457 found = true; 2458 } 2459 2460 if (!subvp_pipe && pipe->stream->mall_stream_config.type == SUBVP_MAIN) 2461 subvp_pipe = pipe; 2462 } 2463 // Use ignore_msa_timing_param flag to identify as DRR 2464 if (found && context->res_ctx.pipe_ctx[vblank_index].stream->ignore_msa_timing_param) { 2465 // SUBVP + DRR case 2466 schedulable = subvp_drr_schedulable(dc, context, &context->res_ctx.pipe_ctx[vblank_index]); 2467 } else if (found) { 2468 main_timing = &subvp_pipe->stream->timing; 2469 phantom_timing = &subvp_pipe->stream->mall_stream_config.paired_stream->timing; 2470 vblank_timing = &context->res_ctx.pipe_ctx[vblank_index].stream->timing; 2471 // Prefetch time is equal to VACTIVE + BP + VSYNC of the phantom pipe 2472 // Also include the prefetch end to mallstart delay time 2473 prefetch_us = (phantom_timing->v_total - phantom_timing->v_front_porch) * phantom_timing->h_total / 2474 (double)(phantom_timing->pix_clk_100hz * 100) * 1000000 + 2475 dc->caps.subvp_prefetch_end_to_mall_start_us; 2476 // P-State allow width and FW delays already included phantom_timing->v_addressable 2477 mall_region_us = phantom_timing->v_addressable * phantom_timing->h_total / 2478 (double)(phantom_timing->pix_clk_100hz * 100) * 1000000; 2479 vblank_frame_us = vblank_timing->v_total * vblank_timing->h_total / 2480 (double)(vblank_timing->pix_clk_100hz * 100) * 1000000; 2481 vblank_blank_us = (vblank_timing->v_total - vblank_timing->v_addressable) * vblank_timing->h_total / 2482 (double)(vblank_timing->pix_clk_100hz * 100) * 1000000; 2483 subvp_active_us = main_timing->v_addressable * main_timing->h_total / 2484 (double)(main_timing->pix_clk_100hz * 100) * 1000000; 2485 max_vblank_mallregion = vblank_blank_us > mall_region_us ? vblank_blank_us : mall_region_us; 2486 2487 // Schedulable if VACTIVE region of the SubVP pipe can fit the MALL prefetch, VBLANK frame time, 2488 // and the max of (VBLANK blanking time, MALL region) 2489 // TODO: Possibly add some margin (i.e. the below conditions should be [...] > X instead of [...] > 0) 2490 if (subvp_active_us - prefetch_us - vblank_frame_us - max_vblank_mallregion > 0) 2491 schedulable = true; 2492 } 2493 return schedulable; 2494 } 2495 2496 /** 2497 * ******************************************************************************************** 2498 * subvp_validate_static_schedulability: Check which SubVP case is calculated and handle 2499 * static analysis based on the case. 2500 * 2501 * Three cases: 2502 * 1. SubVP + SubVP 2503 * 2. SubVP + VBLANK (DRR checked internally) 2504 * 3. SubVP + VACTIVE (currently unsupported) 2505 * 2506 * @param [in] dc: current dc state 2507 * @param [in] context: new dc state 2508 * @param [in] vlevel: Voltage level calculated by DML 2509 * 2510 * @return: bool - True if statically schedulable, false otherwise 2511 * 2512 * ******************************************************************************************** 2513 */ 2514 static bool subvp_validate_static_schedulability(struct dc *dc, 2515 struct dc_state *context, 2516 int vlevel) 2517 { 2518 bool schedulable = true; // true by default for single display case 2519 struct vba_vars_st *vba = &context->bw_ctx.dml.vba; 2520 uint32_t i, pipe_idx; 2521 uint8_t subvp_count = 0; 2522 uint8_t vactive_count = 0; 2523 2524 for (i = 0, pipe_idx = 0; i < dc->res_pool->pipe_count; i++) { 2525 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 2526 2527 if (!pipe->stream) 2528 continue; 2529 2530 if (pipe->plane_state && !pipe->top_pipe && 2531 pipe->stream->mall_stream_config.type == SUBVP_MAIN) 2532 subvp_count++; 2533 2534 // Count how many planes are capable of VACTIVE switching (SubVP + VACTIVE unsupported) 2535 if (vba->ActiveDRAMClockChangeLatencyMargin[vba->pipe_plane[pipe_idx]] > 0) { 2536 vactive_count++; 2537 } 2538 pipe_idx++; 2539 } 2540 2541 if (subvp_count == 2) { 2542 // Static schedulability check for SubVP + SubVP case 2543 schedulable = subvp_subvp_schedulable(dc, context); 2544 } else if (vba->DRAMClockChangeSupport[vlevel][vba->maxMpcComb] == dm_dram_clock_change_vblank_w_mall_sub_vp) { 2545 // Static schedulability check for SubVP + VBLANK case. Also handle the case where 2546 // DML outputs SubVP + VBLANK + VACTIVE (DML will report as SubVP + VBLANK) 2547 if (vactive_count > 0) 2548 schedulable = false; 2549 else 2550 schedulable = subvp_vblank_schedulable(dc, context); 2551 } else if (vba->DRAMClockChangeSupport[vlevel][vba->maxMpcComb] == dm_dram_clock_change_vactive_w_mall_sub_vp) { 2552 // SubVP + VACTIVE currently unsupported 2553 schedulable = false; 2554 } 2555 return schedulable; 2556 } 2557 2558 static void dcn32_full_validate_bw_helper(struct dc *dc, 2559 struct dc_state *context, 2560 display_e2e_pipe_params_st *pipes, 2561 int *vlevel, 2562 int *split, 2563 bool *merge, 2564 int *pipe_cnt) 2565 { 2566 struct vba_vars_st *vba = &context->bw_ctx.dml.vba; 2567 unsigned int dc_pipe_idx = 0; 2568 bool found_supported_config = false; 2569 struct pipe_ctx *pipe = NULL; 2570 uint32_t non_subvp_pipes = 0; 2571 bool drr_pipe_found = false; 2572 uint32_t drr_pipe_index = 0; 2573 uint32_t i = 0; 2574 2575 /* 2576 * DML favors voltage over p-state, but we're more interested in 2577 * supporting p-state over voltage. We can't support p-state in 2578 * prefetch mode > 0 so try capping the prefetch mode to start. 2579 */ 2580 context->bw_ctx.dml.soc.allow_for_pstate_or_stutter_in_vblank_final = 2581 dm_prefetch_support_uclk_fclk_and_stutter; 2582 *vlevel = dml_get_voltage_level(&context->bw_ctx.dml, pipes, *pipe_cnt); 2583 /* This may adjust vlevel and maxMpcComb */ 2584 if (*vlevel < context->bw_ctx.dml.soc.num_states) 2585 *vlevel = dcn20_validate_apply_pipe_split_flags(dc, context, *vlevel, split, merge); 2586 2587 /* Conditions for setting up phantom pipes for SubVP: 2588 * 1. Not force disable SubVP 2589 * 2. Full update (i.e. !fast_validate) 2590 * 3. Enough pipes are available to support SubVP (TODO: Which pipes will use VACTIVE / VBLANK / SUBVP?) 2591 * 4. Display configuration passes validation 2592 * 5. (Config doesn't support MCLK in VACTIVE/VBLANK || dc->debug.force_subvp_mclk_switch) 2593 */ 2594 if (!dc->debug.force_disable_subvp && dcn32_all_pipes_have_stream_and_plane(dc, context) && 2595 (*vlevel == context->bw_ctx.dml.soc.num_states || 2596 vba->DRAMClockChangeSupport[*vlevel][vba->maxMpcComb] == dm_dram_clock_change_unsupported || 2597 dc->debug.force_subvp_mclk_switch)) { 2598 2599 dcn32_merge_pipes_for_subvp(dc, context); 2600 2601 while (!found_supported_config && dcn32_enough_pipes_for_subvp(dc, context) && 2602 dcn32_assign_subvp_pipe(dc, context, &dc_pipe_idx)) { 2603 2604 /* For the case where *vlevel = num_states, bandwidth validation has failed for this config. 2605 * Adding phantom pipes won't change the validation result, so change the DML input param 2606 * for P-State support before adding phantom pipes and recalculating the DML result. 2607 * However, this case is only applicable for SubVP + DRR cases because the prefetch mode 2608 * will not allow for switch in VBLANK. The DRR display must have it's VBLANK stretched 2609 * enough to support support MCLK switching. 2610 */ 2611 if (*vlevel == context->bw_ctx.dml.soc.num_states) { 2612 context->bw_ctx.dml.soc.allow_for_pstate_or_stutter_in_vblank_final = 2613 dm_prefetch_support_stutter; 2614 /* There are params (such as FabricClock) that need to be recalculated 2615 * after validation fails (otherwise it will be 0). Calculation for 2616 * phantom vactive requires call into DML, so we must ensure all the 2617 * vba params are valid otherwise we'll get incorrect phantom vactive. 2618 */ 2619 *vlevel = dml_get_voltage_level(&context->bw_ctx.dml, pipes, *pipe_cnt); 2620 } 2621 2622 dc->res_pool->funcs->add_phantom_pipes(dc, context, pipes, *pipe_cnt, dc_pipe_idx); 2623 2624 *pipe_cnt = dc->res_pool->funcs->populate_dml_pipes(dc, context, pipes, false); 2625 *vlevel = dml_get_voltage_level(&context->bw_ctx.dml, pipes, *pipe_cnt); 2626 2627 if (*vlevel < context->bw_ctx.dml.soc.num_states && 2628 vba->DRAMClockChangeSupport[*vlevel][vba->maxMpcComb] != dm_dram_clock_change_unsupported 2629 && subvp_validate_static_schedulability(dc, context, *vlevel)) { 2630 found_supported_config = true; 2631 } else if (*vlevel < context->bw_ctx.dml.soc.num_states && 2632 vba->DRAMClockChangeSupport[*vlevel][vba->maxMpcComb] == dm_dram_clock_change_unsupported) { 2633 /* Case where 1 SubVP is added, and DML reports MCLK unsupported. This handles 2634 * the case for SubVP + DRR, where the DRR display does not support MCLK switch 2635 * at it's native refresh rate / timing. 2636 */ 2637 for (i = 0; i < dc->res_pool->pipe_count; i++) { 2638 pipe = &context->res_ctx.pipe_ctx[i]; 2639 if (pipe->stream && pipe->plane_state && !pipe->top_pipe && 2640 pipe->stream->mall_stream_config.type == SUBVP_NONE) { 2641 non_subvp_pipes++; 2642 // Use ignore_msa_timing_param flag to identify as DRR 2643 if (pipe->stream->ignore_msa_timing_param) { 2644 drr_pipe_found = true; 2645 drr_pipe_index = i; 2646 } 2647 } 2648 } 2649 // If there is only 1 remaining non SubVP pipe that is DRR, check static 2650 // schedulability for SubVP + DRR. 2651 if (non_subvp_pipes == 1 && drr_pipe_found) { 2652 found_supported_config = subvp_drr_schedulable(dc, 2653 context, &context->res_ctx.pipe_ctx[drr_pipe_index]); 2654 } 2655 } 2656 } 2657 2658 // If SubVP pipe config is unsupported (or cannot be used for UCLK switching) 2659 // remove phantom pipes and repopulate dml pipes 2660 if (!found_supported_config) { 2661 dc->res_pool->funcs->remove_phantom_pipes(dc, context); 2662 vba->DRAMClockChangeSupport[*vlevel][vba->maxMpcComb] = dm_dram_clock_change_unsupported; 2663 *pipe_cnt = dc->res_pool->funcs->populate_dml_pipes(dc, context, pipes, false); 2664 } else { 2665 // only call dcn20_validate_apply_pipe_split_flags if we found a supported config 2666 memset(split, 0, MAX_PIPES * sizeof(int)); 2667 memset(merge, 0, MAX_PIPES * sizeof(bool)); 2668 *vlevel = dcn20_validate_apply_pipe_split_flags(dc, context, *vlevel, split, merge); 2669 2670 // Note: We can't apply the phantom pipes to hardware at this time. We have to wait 2671 // until driver has acquired the DMCUB lock to do it safely. 2672 } 2673 } 2674 } 2675 2676 static bool dcn32_internal_validate_bw( 2677 struct dc *dc, 2678 struct dc_state *context, 2679 display_e2e_pipe_params_st *pipes, 2680 int *pipe_cnt_out, 2681 int *vlevel_out, 2682 bool fast_validate) 2683 { 2684 bool out = false; 2685 bool repopulate_pipes = false; 2686 int split[MAX_PIPES] = { 0 }; 2687 bool merge[MAX_PIPES] = { false }; 2688 bool newly_split[MAX_PIPES] = { false }; 2689 int pipe_cnt, i, pipe_idx, vlevel; 2690 struct vba_vars_st *vba = &context->bw_ctx.dml.vba; 2691 2692 ASSERT(pipes); 2693 if (!pipes) 2694 return false; 2695 2696 // For each full update, remove all existing phantom pipes first 2697 dc->res_pool->funcs->remove_phantom_pipes(dc, context); 2698 2699 dc->res_pool->funcs->update_soc_for_wm_a(dc, context); 2700 2701 pipe_cnt = dc->res_pool->funcs->populate_dml_pipes(dc, context, pipes, fast_validate); 2702 2703 if (!pipe_cnt) { 2704 out = true; 2705 goto validate_out; 2706 } 2707 2708 dml_log_pipe_params(&context->bw_ctx.dml, pipes, pipe_cnt); 2709 2710 if (!fast_validate) { 2711 dcn32_full_validate_bw_helper(dc, context, pipes, &vlevel, split, merge, &pipe_cnt); 2712 } 2713 2714 if (fast_validate || vlevel == context->bw_ctx.dml.soc.num_states || 2715 vba->DRAMClockChangeSupport[vlevel][vba->maxMpcComb] == dm_dram_clock_change_unsupported) { 2716 /* 2717 * If mode is unsupported or there's still no p-state support then 2718 * fall back to favoring voltage. 2719 * 2720 * We don't actually support prefetch mode 2, so require that we 2721 * at least support prefetch mode 1. 2722 */ 2723 context->bw_ctx.dml.soc.allow_for_pstate_or_stutter_in_vblank_final = 2724 dm_prefetch_support_stutter; 2725 2726 vlevel = dml_get_voltage_level(&context->bw_ctx.dml, pipes, pipe_cnt); 2727 if (vlevel < context->bw_ctx.dml.soc.num_states) { 2728 memset(split, 0, MAX_PIPES * sizeof(int)); 2729 memset(merge, 0, MAX_PIPES * sizeof(bool)); 2730 vlevel = dcn20_validate_apply_pipe_split_flags(dc, context, vlevel, split, merge); 2731 } 2732 } 2733 2734 dml_log_mode_support_params(&context->bw_ctx.dml); 2735 2736 if (vlevel == context->bw_ctx.dml.soc.num_states) 2737 goto validate_fail; 2738 2739 for (i = 0, pipe_idx = 0; i < dc->res_pool->pipe_count; i++) { 2740 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 2741 struct pipe_ctx *mpo_pipe = pipe->bottom_pipe; 2742 2743 if (!pipe->stream) 2744 continue; 2745 2746 /* We only support full screen mpo with ODM */ 2747 if (vba->ODMCombineEnabled[vba->pipe_plane[pipe_idx]] != dm_odm_combine_mode_disabled 2748 && pipe->plane_state && mpo_pipe 2749 && memcmp(&mpo_pipe->plane_res.scl_data.recout, 2750 &pipe->plane_res.scl_data.recout, 2751 sizeof(struct rect)) != 0) { 2752 ASSERT(mpo_pipe->plane_state != pipe->plane_state); 2753 goto validate_fail; 2754 } 2755 pipe_idx++; 2756 } 2757 2758 /* merge pipes if necessary */ 2759 for (i = 0; i < dc->res_pool->pipe_count; i++) { 2760 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 2761 2762 /*skip pipes that don't need merging*/ 2763 if (!merge[i]) 2764 continue; 2765 2766 /* if ODM merge we ignore mpc tree, mpo pipes will have their own flags */ 2767 if (pipe->prev_odm_pipe) { 2768 /*split off odm pipe*/ 2769 pipe->prev_odm_pipe->next_odm_pipe = pipe->next_odm_pipe; 2770 if (pipe->next_odm_pipe) 2771 pipe->next_odm_pipe->prev_odm_pipe = pipe->prev_odm_pipe; 2772 2773 pipe->bottom_pipe = NULL; 2774 pipe->next_odm_pipe = NULL; 2775 pipe->plane_state = NULL; 2776 pipe->stream = NULL; 2777 pipe->top_pipe = NULL; 2778 pipe->prev_odm_pipe = NULL; 2779 if (pipe->stream_res.dsc) 2780 dcn20_release_dsc(&context->res_ctx, dc->res_pool, &pipe->stream_res.dsc); 2781 memset(&pipe->plane_res, 0, sizeof(pipe->plane_res)); 2782 memset(&pipe->stream_res, 0, sizeof(pipe->stream_res)); 2783 repopulate_pipes = true; 2784 } else if (pipe->top_pipe && pipe->top_pipe->plane_state == pipe->plane_state) { 2785 struct pipe_ctx *top_pipe = pipe->top_pipe; 2786 struct pipe_ctx *bottom_pipe = pipe->bottom_pipe; 2787 2788 top_pipe->bottom_pipe = bottom_pipe; 2789 if (bottom_pipe) 2790 bottom_pipe->top_pipe = top_pipe; 2791 2792 pipe->top_pipe = NULL; 2793 pipe->bottom_pipe = NULL; 2794 pipe->plane_state = NULL; 2795 pipe->stream = NULL; 2796 memset(&pipe->plane_res, 0, sizeof(pipe->plane_res)); 2797 memset(&pipe->stream_res, 0, sizeof(pipe->stream_res)); 2798 repopulate_pipes = true; 2799 } else 2800 ASSERT(0); /* Should never try to merge master pipe */ 2801 2802 } 2803 2804 for (i = 0, pipe_idx = -1; i < dc->res_pool->pipe_count; i++) { 2805 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 2806 struct pipe_ctx *old_pipe = &dc->current_state->res_ctx.pipe_ctx[i]; 2807 struct pipe_ctx *hsplit_pipe = NULL; 2808 bool odm; 2809 int old_index = -1; 2810 2811 if (!pipe->stream || newly_split[i]) 2812 continue; 2813 2814 pipe_idx++; 2815 odm = vba->ODMCombineEnabled[vba->pipe_plane[pipe_idx]] != dm_odm_combine_mode_disabled; 2816 2817 if (!pipe->plane_state && !odm) 2818 continue; 2819 2820 if (split[i]) { 2821 if (odm) { 2822 if (split[i] == 4 && old_pipe->next_odm_pipe && old_pipe->next_odm_pipe->next_odm_pipe) 2823 old_index = old_pipe->next_odm_pipe->next_odm_pipe->pipe_idx; 2824 else if (old_pipe->next_odm_pipe) 2825 old_index = old_pipe->next_odm_pipe->pipe_idx; 2826 } else { 2827 if (split[i] == 4 && old_pipe->bottom_pipe && old_pipe->bottom_pipe->bottom_pipe && 2828 old_pipe->bottom_pipe->bottom_pipe->plane_state == old_pipe->plane_state) 2829 old_index = old_pipe->bottom_pipe->bottom_pipe->pipe_idx; 2830 else if (old_pipe->bottom_pipe && 2831 old_pipe->bottom_pipe->plane_state == old_pipe->plane_state) 2832 old_index = old_pipe->bottom_pipe->pipe_idx; 2833 } 2834 hsplit_pipe = dcn32_find_split_pipe(dc, context, old_index); 2835 ASSERT(hsplit_pipe); 2836 if (!hsplit_pipe) 2837 goto validate_fail; 2838 2839 if (!dcn32_split_stream_for_mpc_or_odm( 2840 dc, &context->res_ctx, 2841 pipe, hsplit_pipe, odm)) 2842 goto validate_fail; 2843 2844 newly_split[hsplit_pipe->pipe_idx] = true; 2845 repopulate_pipes = true; 2846 } 2847 if (split[i] == 4) { 2848 struct pipe_ctx *pipe_4to1; 2849 2850 if (odm && old_pipe->next_odm_pipe) 2851 old_index = old_pipe->next_odm_pipe->pipe_idx; 2852 else if (!odm && old_pipe->bottom_pipe && 2853 old_pipe->bottom_pipe->plane_state == old_pipe->plane_state) 2854 old_index = old_pipe->bottom_pipe->pipe_idx; 2855 else 2856 old_index = -1; 2857 pipe_4to1 = dcn32_find_split_pipe(dc, context, old_index); 2858 ASSERT(pipe_4to1); 2859 if (!pipe_4to1) 2860 goto validate_fail; 2861 if (!dcn32_split_stream_for_mpc_or_odm( 2862 dc, &context->res_ctx, 2863 pipe, pipe_4to1, odm)) 2864 goto validate_fail; 2865 newly_split[pipe_4to1->pipe_idx] = true; 2866 2867 if (odm && old_pipe->next_odm_pipe && old_pipe->next_odm_pipe->next_odm_pipe 2868 && old_pipe->next_odm_pipe->next_odm_pipe->next_odm_pipe) 2869 old_index = old_pipe->next_odm_pipe->next_odm_pipe->next_odm_pipe->pipe_idx; 2870 else if (!odm && old_pipe->bottom_pipe && old_pipe->bottom_pipe->bottom_pipe && 2871 old_pipe->bottom_pipe->bottom_pipe->bottom_pipe && 2872 old_pipe->bottom_pipe->bottom_pipe->bottom_pipe->plane_state == old_pipe->plane_state) 2873 old_index = old_pipe->bottom_pipe->bottom_pipe->bottom_pipe->pipe_idx; 2874 else 2875 old_index = -1; 2876 pipe_4to1 = dcn32_find_split_pipe(dc, context, old_index); 2877 ASSERT(pipe_4to1); 2878 if (!pipe_4to1) 2879 goto validate_fail; 2880 if (!dcn32_split_stream_for_mpc_or_odm( 2881 dc, &context->res_ctx, 2882 hsplit_pipe, pipe_4to1, odm)) 2883 goto validate_fail; 2884 newly_split[pipe_4to1->pipe_idx] = true; 2885 } 2886 if (odm) 2887 dcn20_build_mapped_resource(dc, context, pipe->stream); 2888 } 2889 2890 for (i = 0; i < dc->res_pool->pipe_count; i++) { 2891 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 2892 2893 if (pipe->plane_state) { 2894 if (!resource_build_scaling_params(pipe)) 2895 goto validate_fail; 2896 } 2897 } 2898 2899 /* Actual dsc count per stream dsc validation*/ 2900 if (!dcn20_validate_dsc(dc, context)) { 2901 vba->ValidationStatus[vba->soc.num_states] = DML_FAIL_DSC_VALIDATION_FAILURE; 2902 goto validate_fail; 2903 } 2904 2905 if (repopulate_pipes) 2906 pipe_cnt = dc->res_pool->funcs->populate_dml_pipes(dc, context, pipes, fast_validate); 2907 *vlevel_out = vlevel; 2908 *pipe_cnt_out = pipe_cnt; 2909 2910 out = true; 2911 goto validate_out; 2912 2913 validate_fail: 2914 out = false; 2915 2916 validate_out: 2917 return out; 2918 } 2919 2920 bool dcn32_validate_bandwidth(struct dc *dc, 2921 struct dc_state *context, 2922 bool fast_validate) 2923 { 2924 bool out = false; 2925 2926 BW_VAL_TRACE_SETUP(); 2927 2928 int vlevel = 0; 2929 int pipe_cnt = 0; 2930 display_e2e_pipe_params_st *pipes = kzalloc(dc->res_pool->pipe_count * sizeof(display_e2e_pipe_params_st), GFP_KERNEL); 2931 DC_LOGGER_INIT(dc->ctx->logger); 2932 2933 BW_VAL_TRACE_COUNT(); 2934 2935 DC_FP_START(); 2936 out = dcn32_internal_validate_bw(dc, context, pipes, &pipe_cnt, &vlevel, fast_validate); 2937 DC_FP_END(); 2938 2939 if (pipe_cnt == 0) 2940 goto validate_out; 2941 2942 if (!out) 2943 goto validate_fail; 2944 2945 BW_VAL_TRACE_END_VOLTAGE_LEVEL(); 2946 2947 if (fast_validate) { 2948 BW_VAL_TRACE_SKIP(fast); 2949 goto validate_out; 2950 } 2951 2952 dc->res_pool->funcs->calculate_wm_and_dlg(dc, context, pipes, pipe_cnt, vlevel); 2953 2954 BW_VAL_TRACE_END_WATERMARKS(); 2955 2956 goto validate_out; 2957 2958 validate_fail: 2959 DC_LOG_WARNING("Mode Validation Warning: %s failed validation.\n", 2960 dml_get_status_message(context->bw_ctx.dml.vba.ValidationStatus[context->bw_ctx.dml.vba.soc.num_states])); 2961 2962 BW_VAL_TRACE_SKIP(fail); 2963 out = false; 2964 2965 validate_out: 2966 kfree(pipes); 2967 2968 BW_VAL_TRACE_FINISH(); 2969 2970 return out; 2971 } 2972 2973 2974 static bool is_dual_plane(enum surface_pixel_format format) 2975 { 2976 return format >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN || format == SURFACE_PIXEL_FORMAT_GRPH_RGBE_ALPHA; 2977 } 2978 2979 int dcn32_populate_dml_pipes_from_context( 2980 struct dc *dc, struct dc_state *context, 2981 display_e2e_pipe_params_st *pipes, 2982 bool fast_validate) 2983 { 2984 int i, pipe_cnt; 2985 struct resource_context *res_ctx = &context->res_ctx; 2986 struct pipe_ctx *pipe; 2987 2988 dcn20_populate_dml_pipes_from_context(dc, context, pipes, fast_validate); 2989 2990 for (i = 0, pipe_cnt = 0; i < dc->res_pool->pipe_count; i++) { 2991 struct dc_crtc_timing *timing; 2992 2993 if (!res_ctx->pipe_ctx[i].stream) 2994 continue; 2995 pipe = &res_ctx->pipe_ctx[i]; 2996 timing = &pipe->stream->timing; 2997 2998 pipes[pipe_cnt].pipe.src.gpuvm = true; 2999 pipes[pipe_cnt].pipe.src.dcc_fraction_of_zs_req_luma = 0; 3000 pipes[pipe_cnt].pipe.src.dcc_fraction_of_zs_req_chroma = 0; 3001 pipes[pipe_cnt].pipe.dest.vfront_porch = timing->v_front_porch; 3002 pipes[pipe_cnt].pipe.src.gpuvm_min_page_size_kbytes = 256; // according to spreadsheet 3003 pipes[pipe_cnt].pipe.src.unbounded_req_mode = false; 3004 pipes[pipe_cnt].pipe.scale_ratio_depth.lb_depth = dm_lb_19; 3005 3006 switch (pipe->stream->mall_stream_config.type) { 3007 case SUBVP_MAIN: 3008 pipes[pipe_cnt].pipe.src.use_mall_for_pstate_change = dm_use_mall_pstate_change_sub_viewport; 3009 break; 3010 case SUBVP_PHANTOM: 3011 pipes[pipe_cnt].pipe.src.use_mall_for_pstate_change = dm_use_mall_pstate_change_phantom_pipe; 3012 pipes[pipe_cnt].pipe.src.use_mall_for_static_screen = dm_use_mall_static_screen_disable; 3013 // Disallow unbounded req for SubVP according to DCHUB programming guide 3014 pipes[pipe_cnt].pipe.src.unbounded_req_mode = false; 3015 break; 3016 case SUBVP_NONE: 3017 pipes[pipe_cnt].pipe.src.use_mall_for_pstate_change = dm_use_mall_pstate_change_disable; 3018 pipes[pipe_cnt].pipe.src.use_mall_for_static_screen = dm_use_mall_static_screen_disable; 3019 break; 3020 default: 3021 break; 3022 } 3023 3024 pipes[pipe_cnt].dout.dsc_input_bpc = 0; 3025 if (pipes[pipe_cnt].dout.dsc_enable) { 3026 switch (timing->display_color_depth) { 3027 case COLOR_DEPTH_888: 3028 pipes[pipe_cnt].dout.dsc_input_bpc = 8; 3029 break; 3030 case COLOR_DEPTH_101010: 3031 pipes[pipe_cnt].dout.dsc_input_bpc = 10; 3032 break; 3033 case COLOR_DEPTH_121212: 3034 pipes[pipe_cnt].dout.dsc_input_bpc = 12; 3035 break; 3036 default: 3037 ASSERT(0); 3038 break; 3039 } 3040 } 3041 3042 pipes[pipe_cnt].pipe.dest.odm_combine_policy = dm_odm_combine_policy_dal; 3043 if (context->stream_count == 1) { 3044 if (dc->debug.enable_single_display_2to1_odm_policy) 3045 pipes[pipe_cnt].pipe.dest.odm_combine_policy = dm_odm_combine_policy_2to1; 3046 } 3047 pipe_cnt++; 3048 } 3049 3050 /* For DET allocation, we don't want to use DML policy (not optimal for utilizing all 3051 * the DET available for each pipe). Use the DET override input to maintain our driver 3052 * policy. 3053 */ 3054 switch (pipe_cnt) { 3055 case 1: 3056 pipes[0].pipe.src.det_size_override = DCN3_2_MAX_DET_SIZE; 3057 if (pipe->plane_state && !dc->debug.disable_z9_mpc) { 3058 if (!is_dual_plane(pipe->plane_state->format)) { 3059 pipes[0].pipe.src.det_size_override = DCN3_2_DEFAULT_DET_SIZE; 3060 pipes[0].pipe.src.unbounded_req_mode = true; 3061 if (pipe->plane_state->src_rect.width >= 5120 && 3062 pipe->plane_state->src_rect.height >= 2880) 3063 pipes[0].pipe.src.det_size_override = 320; // 5K or higher 3064 } 3065 } 3066 break; 3067 case 2: 3068 case 3: 3069 case 4: 3070 // For 2 and 3 pipes, use (MAX_DET_SIZE / pipe_cnt), for 4 pipes use default size for each pipe 3071 for (i = 0; i < pipe_cnt; i++) { 3072 pipes[i].pipe.src.det_size_override = (pipe_cnt < 4) ? (DCN3_2_MAX_DET_SIZE / pipe_cnt) : DCN3_2_DEFAULT_DET_SIZE; 3073 } 3074 break; 3075 } 3076 3077 dcn32_update_det_override_for_mpo(dc, context, pipes); 3078 3079 return pipe_cnt; 3080 } 3081 3082 void dcn32_calculate_wm_and_dlg_fp( 3083 struct dc *dc, struct dc_state *context, 3084 display_e2e_pipe_params_st *pipes, 3085 int pipe_cnt, 3086 int vlevel) 3087 { 3088 int i, pipe_idx, vlevel_temp = 0; 3089 double dcfclk = dcn3_2_soc.clock_limits[0].dcfclk_mhz; 3090 double dcfclk_from_validation = context->bw_ctx.dml.vba.DCFCLKState[vlevel][context->bw_ctx.dml.vba.maxMpcComb]; 3091 unsigned int min_dram_speed_mts = context->bw_ctx.dml.vba.DRAMSpeed; 3092 bool pstate_en = context->bw_ctx.dml.vba.DRAMClockChangeSupport[vlevel][context->bw_ctx.dml.vba.maxMpcComb] != 3093 dm_dram_clock_change_unsupported; 3094 3095 // Override DRAMClockChangeSupport for SubVP + DRR case where the DRR cannot switch without stretching it's VBLANK 3096 if (!pstate_en && dcn32_subvp_in_use(dc, context)) { 3097 context->bw_ctx.dml.vba.DRAMClockChangeSupport[vlevel][context->bw_ctx.dml.vba.maxMpcComb] = dm_dram_clock_change_vblank_w_mall_sub_vp; 3098 pstate_en = true; 3099 } 3100 3101 /* Set B: 3102 * For Set B calculations use clocks from clock_limits[2] when available i.e. when SMU is present, 3103 * otherwise use arbitrary low value from spreadsheet for DCFCLK as lower is safer for watermark 3104 * calculations to cover bootup clocks. 3105 * DCFCLK: soc.clock_limits[2] when available 3106 * UCLK: soc.clock_limits[2] when available 3107 */ 3108 if (dcn3_2_soc.num_states > 2) { 3109 vlevel_temp = 2; 3110 dcfclk = dcn3_2_soc.clock_limits[2].dcfclk_mhz; 3111 } else 3112 dcfclk = 615; //DCFCLK Vmin_lv 3113 3114 pipes[0].clks_cfg.voltage = vlevel_temp; 3115 pipes[0].clks_cfg.dcfclk_mhz = dcfclk; 3116 pipes[0].clks_cfg.socclk_mhz = context->bw_ctx.dml.soc.clock_limits[vlevel_temp].socclk_mhz; 3117 3118 if (dc->clk_mgr->bw_params->wm_table.nv_entries[WM_B].valid) { 3119 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; 3120 context->bw_ctx.dml.soc.fclk_change_latency_us = dc->clk_mgr->bw_params->wm_table.nv_entries[WM_B].dml_input.fclk_change_latency_us; 3121 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; 3122 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; 3123 } 3124 context->bw_ctx.bw.dcn.watermarks.b.urgent_ns = get_wm_urgent(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000; 3125 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; 3126 context->bw_ctx.bw.dcn.watermarks.b.cstate_pstate.cstate_exit_ns = get_wm_stutter_exit(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000; 3127 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; 3128 context->bw_ctx.bw.dcn.watermarks.b.pte_meta_urgent_ns = get_wm_memory_trip(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000; 3129 context->bw_ctx.bw.dcn.watermarks.b.frac_urg_bw_nom = get_fraction_of_urgent_bandwidth(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000; 3130 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; 3131 context->bw_ctx.bw.dcn.watermarks.b.urgent_latency_ns = get_urgent_latency(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000; 3132 context->bw_ctx.bw.dcn.watermarks.b.cstate_pstate.fclk_pstate_change_ns = get_fclk_watermark(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000; 3133 context->bw_ctx.bw.dcn.watermarks.b.usr_retraining_ns = get_usr_retraining_watermark(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000; 3134 3135 /* Set D: 3136 * All clocks min. 3137 * DCFCLK: Min, as reported by PM FW when available 3138 * UCLK : Min, as reported by PM FW when available 3139 * sr_enter_exit/sr_exit should be lower than used for DRAM (TBD after bringup or later, use as decided in Clk Mgr) 3140 */ 3141 3142 if (dcn3_2_soc.num_states > 2) { 3143 vlevel_temp = 0; 3144 dcfclk = dc->clk_mgr->bw_params->clk_table.entries[0].dcfclk_mhz; 3145 } else 3146 dcfclk = 615; //DCFCLK Vmin_lv 3147 3148 pipes[0].clks_cfg.voltage = vlevel_temp; 3149 pipes[0].clks_cfg.dcfclk_mhz = dcfclk; 3150 pipes[0].clks_cfg.socclk_mhz = context->bw_ctx.dml.soc.clock_limits[vlevel_temp].socclk_mhz; 3151 3152 if (dc->clk_mgr->bw_params->wm_table.nv_entries[WM_D].valid) { 3153 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; 3154 context->bw_ctx.dml.soc.fclk_change_latency_us = dc->clk_mgr->bw_params->wm_table.nv_entries[WM_D].dml_input.fclk_change_latency_us; 3155 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; 3156 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; 3157 } 3158 context->bw_ctx.bw.dcn.watermarks.d.urgent_ns = get_wm_urgent(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000; 3159 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; 3160 context->bw_ctx.bw.dcn.watermarks.d.cstate_pstate.cstate_exit_ns = get_wm_stutter_exit(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000; 3161 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; 3162 context->bw_ctx.bw.dcn.watermarks.d.pte_meta_urgent_ns = get_wm_memory_trip(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000; 3163 context->bw_ctx.bw.dcn.watermarks.d.frac_urg_bw_nom = get_fraction_of_urgent_bandwidth(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000; 3164 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; 3165 context->bw_ctx.bw.dcn.watermarks.d.urgent_latency_ns = get_urgent_latency(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000; 3166 context->bw_ctx.bw.dcn.watermarks.d.cstate_pstate.fclk_pstate_change_ns = get_fclk_watermark(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000; 3167 context->bw_ctx.bw.dcn.watermarks.d.usr_retraining_ns = get_usr_retraining_watermark(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000; 3168 3169 /* Set C, for Dummy P-State: 3170 * All clocks min. 3171 * DCFCLK: Min, as reported by PM FW, when available 3172 * UCLK : Min, as reported by PM FW, when available 3173 * pstate latency as per UCLK state dummy pstate latency 3174 */ 3175 // For Set A and Set C use values from validation 3176 pipes[0].clks_cfg.voltage = vlevel; 3177 pipes[0].clks_cfg.dcfclk_mhz = dcfclk_from_validation; 3178 pipes[0].clks_cfg.socclk_mhz = context->bw_ctx.dml.soc.clock_limits[vlevel].socclk_mhz; 3179 3180 if (dc->clk_mgr->bw_params->wm_table.nv_entries[WM_C].valid) { 3181 unsigned int min_dram_speed_mts_margin = 160; 3182 3183 if ((!pstate_en)) 3184 min_dram_speed_mts = dc->clk_mgr->bw_params->clk_table.entries[dc->clk_mgr->bw_params->clk_table.num_entries - 1].memclk_mhz * 16; 3185 3186 /* find largest table entry that is lower than dram speed, but lower than DPM0 still uses DPM0 */ 3187 for (i = 3; i > 0; i--) 3188 if (min_dram_speed_mts + min_dram_speed_mts_margin > dc->clk_mgr->bw_params->dummy_pstate_table[i].dram_speed_mts) 3189 break; 3190 3191 context->bw_ctx.dml.soc.dram_clock_change_latency_us = dc->clk_mgr->bw_params->dummy_pstate_table[i].dummy_pstate_latency_us; 3192 context->bw_ctx.dml.soc.dummy_pstate_latency_us = dc->clk_mgr->bw_params->dummy_pstate_table[i].dummy_pstate_latency_us; 3193 context->bw_ctx.dml.soc.fclk_change_latency_us = dc->clk_mgr->bw_params->wm_table.nv_entries[WM_C].dml_input.fclk_change_latency_us; 3194 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; 3195 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; 3196 } 3197 context->bw_ctx.bw.dcn.watermarks.c.urgent_ns = get_wm_urgent(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000; 3198 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; 3199 context->bw_ctx.bw.dcn.watermarks.c.cstate_pstate.cstate_exit_ns = get_wm_stutter_exit(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000; 3200 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; 3201 context->bw_ctx.bw.dcn.watermarks.c.pte_meta_urgent_ns = get_wm_memory_trip(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000; 3202 context->bw_ctx.bw.dcn.watermarks.c.frac_urg_bw_nom = get_fraction_of_urgent_bandwidth(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000; 3203 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; 3204 context->bw_ctx.bw.dcn.watermarks.c.urgent_latency_ns = get_urgent_latency(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000; 3205 context->bw_ctx.bw.dcn.watermarks.c.cstate_pstate.fclk_pstate_change_ns = get_fclk_watermark(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000; 3206 context->bw_ctx.bw.dcn.watermarks.c.usr_retraining_ns = get_usr_retraining_watermark(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000; 3207 3208 if ((!pstate_en) && (dc->clk_mgr->bw_params->wm_table.nv_entries[WM_C].valid)) { 3209 /* The only difference between A and C is p-state latency, if p-state is not supported 3210 * with full p-state latency we want to calculate DLG based on dummy p-state latency, 3211 * Set A p-state watermark set to 0 on DCN32, when p-state unsupported, for now keep as DCN32. 3212 */ 3213 context->bw_ctx.bw.dcn.watermarks.a = context->bw_ctx.bw.dcn.watermarks.c; 3214 context->bw_ctx.bw.dcn.watermarks.a.cstate_pstate.pstate_change_ns = 0; 3215 } else { 3216 /* Set A: 3217 * All clocks min. 3218 * DCFCLK: Min, as reported by PM FW, when available 3219 * UCLK: Min, as reported by PM FW, when available 3220 */ 3221 dc->res_pool->funcs->update_soc_for_wm_a(dc, context); 3222 context->bw_ctx.bw.dcn.watermarks.a.urgent_ns = get_wm_urgent(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000; 3223 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; 3224 context->bw_ctx.bw.dcn.watermarks.a.cstate_pstate.cstate_exit_ns = get_wm_stutter_exit(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000; 3225 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; 3226 context->bw_ctx.bw.dcn.watermarks.a.pte_meta_urgent_ns = get_wm_memory_trip(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000; 3227 context->bw_ctx.bw.dcn.watermarks.a.frac_urg_bw_nom = get_fraction_of_urgent_bandwidth(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000; 3228 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; 3229 context->bw_ctx.bw.dcn.watermarks.a.urgent_latency_ns = get_urgent_latency(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000; 3230 context->bw_ctx.bw.dcn.watermarks.a.cstate_pstate.fclk_pstate_change_ns = get_fclk_watermark(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000; 3231 context->bw_ctx.bw.dcn.watermarks.a.usr_retraining_ns = get_usr_retraining_watermark(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000; 3232 } 3233 3234 for (i = 0, pipe_idx = 0; i < dc->res_pool->pipe_count; i++) { 3235 if (!context->res_ctx.pipe_ctx[i].stream) 3236 continue; 3237 3238 pipes[pipe_idx].clks_cfg.dispclk_mhz = get_dispclk_calculated(&context->bw_ctx.dml, pipes, pipe_cnt); 3239 pipes[pipe_idx].clks_cfg.dppclk_mhz = get_dppclk_calculated(&context->bw_ctx.dml, pipes, pipe_cnt, pipe_idx); 3240 3241 if (dc->config.forced_clocks) { 3242 pipes[pipe_idx].clks_cfg.dispclk_mhz = context->bw_ctx.dml.soc.clock_limits[0].dispclk_mhz; 3243 pipes[pipe_idx].clks_cfg.dppclk_mhz = context->bw_ctx.dml.soc.clock_limits[0].dppclk_mhz; 3244 } 3245 if (dc->debug.min_disp_clk_khz > pipes[pipe_idx].clks_cfg.dispclk_mhz * 1000) 3246 pipes[pipe_idx].clks_cfg.dispclk_mhz = dc->debug.min_disp_clk_khz / 1000.0; 3247 if (dc->debug.min_dpp_clk_khz > pipes[pipe_idx].clks_cfg.dppclk_mhz * 1000) 3248 pipes[pipe_idx].clks_cfg.dppclk_mhz = dc->debug.min_dpp_clk_khz / 1000.0; 3249 3250 pipe_idx++; 3251 } 3252 3253 context->perf_params.stutter_period_us = context->bw_ctx.dml.vba.StutterPeriod; 3254 3255 dcn32_calculate_dlg_params(dc, context, pipes, pipe_cnt, vlevel); 3256 3257 if (!pstate_en) 3258 /* Restore full p-state latency */ 3259 context->bw_ctx.dml.soc.dram_clock_change_latency_us = 3260 dc->clk_mgr->bw_params->wm_table.nv_entries[WM_A].dml_input.pstate_latency_us; 3261 } 3262 3263 static struct dc_cap_funcs cap_funcs = { 3264 .get_dcc_compression_cap = dcn20_get_dcc_compression_cap 3265 }; 3266 3267 3268 static void dcn32_get_optimal_dcfclk_fclk_for_uclk(unsigned int uclk_mts, 3269 unsigned int *optimal_dcfclk, 3270 unsigned int *optimal_fclk) 3271 { 3272 double bw_from_dram, bw_from_dram1, bw_from_dram2; 3273 3274 bw_from_dram1 = uclk_mts * dcn3_2_soc.num_chans * 3275 dcn3_2_soc.dram_channel_width_bytes * (dcn3_2_soc.max_avg_dram_bw_use_normal_percent / 100); 3276 bw_from_dram2 = uclk_mts * dcn3_2_soc.num_chans * 3277 dcn3_2_soc.dram_channel_width_bytes * (dcn3_2_soc.max_avg_sdp_bw_use_normal_percent / 100); 3278 3279 bw_from_dram = (bw_from_dram1 < bw_from_dram2) ? bw_from_dram1 : bw_from_dram2; 3280 3281 if (optimal_fclk) 3282 *optimal_fclk = bw_from_dram / 3283 (dcn3_2_soc.fabric_datapath_to_dcn_data_return_bytes * (dcn3_2_soc.max_avg_sdp_bw_use_normal_percent / 100)); 3284 3285 if (optimal_dcfclk) 3286 *optimal_dcfclk = bw_from_dram / 3287 (dcn3_2_soc.return_bus_width_bytes * (dcn3_2_soc.max_avg_sdp_bw_use_normal_percent / 100)); 3288 } 3289 3290 void dcn32_calculate_wm_and_dlg( 3291 struct dc *dc, struct dc_state *context, 3292 display_e2e_pipe_params_st *pipes, 3293 int pipe_cnt, 3294 int vlevel) 3295 { 3296 DC_FP_START(); 3297 dcn32_calculate_wm_and_dlg_fp( 3298 dc, context, 3299 pipes, 3300 pipe_cnt, 3301 vlevel); 3302 DC_FP_END(); 3303 } 3304 3305 static bool is_dtbclk_required(struct dc *dc, struct dc_state *context) 3306 { 3307 int i; 3308 3309 for (i = 0; i < dc->res_pool->pipe_count; i++) { 3310 if (!context->res_ctx.pipe_ctx[i].stream) 3311 continue; 3312 if (is_dp_128b_132b_signal(&context->res_ctx.pipe_ctx[i])) 3313 return true; 3314 } 3315 return false; 3316 } 3317 3318 void dcn32_calculate_dlg_params(struct dc *dc, struct dc_state *context, display_e2e_pipe_params_st *pipes, 3319 int pipe_cnt, int vlevel) 3320 { 3321 int i, pipe_idx; 3322 bool usr_retraining_support = false; 3323 3324 /* Writeback MCIF_WB arbitration parameters */ 3325 dc->res_pool->funcs->set_mcif_arb_params(dc, context, pipes, pipe_cnt); 3326 3327 context->bw_ctx.bw.dcn.clk.dispclk_khz = context->bw_ctx.dml.vba.DISPCLK * 1000; 3328 context->bw_ctx.bw.dcn.clk.dcfclk_khz = context->bw_ctx.dml.vba.DCFCLK * 1000; 3329 context->bw_ctx.bw.dcn.clk.socclk_khz = context->bw_ctx.dml.vba.SOCCLK * 1000; 3330 context->bw_ctx.bw.dcn.clk.dramclk_khz = context->bw_ctx.dml.vba.DRAMSpeed * 1000 / 16; 3331 context->bw_ctx.bw.dcn.clk.dcfclk_deep_sleep_khz = context->bw_ctx.dml.vba.DCFCLKDeepSleep * 1000; 3332 context->bw_ctx.bw.dcn.clk.fclk_khz = context->bw_ctx.dml.vba.FabricClock * 1000; 3333 context->bw_ctx.bw.dcn.clk.p_state_change_support = 3334 context->bw_ctx.dml.vba.DRAMClockChangeSupport[vlevel][context->bw_ctx.dml.vba.maxMpcComb] 3335 != dm_dram_clock_change_unsupported; 3336 context->bw_ctx.bw.dcn.clk.num_ways = dcn32_helper_calculate_num_ways_for_subvp(dc, context); 3337 /* 3338 * 3339 * TODO: needs FAMS 3340 * Pstate change might not be supported by hardware, but it might be 3341 * possible with firmware driven vertical blank stretching. 3342 */ 3343 // context->bw_ctx.bw.dcn.clk.p_state_change_support |= context->bw_ctx.bw.dcn.clk.fw_based_mclk_switching; 3344 context->bw_ctx.bw.dcn.clk.dppclk_khz = 0; 3345 context->bw_ctx.bw.dcn.clk.dtbclk_en = is_dtbclk_required(dc, context); 3346 context->bw_ctx.bw.dcn.clk.ref_dtbclk_khz = context->bw_ctx.dml.vba.DTBCLKPerState[vlevel] * 1000; 3347 if (context->bw_ctx.dml.vba.FCLKChangeSupport[vlevel][context->bw_ctx.dml.vba.maxMpcComb] == dm_fclock_change_unsupported) 3348 context->bw_ctx.bw.dcn.clk.fclk_p_state_change_support = false; 3349 else 3350 context->bw_ctx.bw.dcn.clk.fclk_p_state_change_support = true; 3351 3352 usr_retraining_support = context->bw_ctx.dml.vba.USRRetrainingSupport[vlevel][context->bw_ctx.dml.vba.maxMpcComb]; 3353 ASSERT(usr_retraining_support); 3354 3355 if (context->bw_ctx.bw.dcn.clk.dispclk_khz < dc->debug.min_disp_clk_khz) 3356 context->bw_ctx.bw.dcn.clk.dispclk_khz = dc->debug.min_disp_clk_khz; 3357 3358 for (i = 0, pipe_idx = 0; i < dc->res_pool->pipe_count; i++) { 3359 if (!context->res_ctx.pipe_ctx[i].stream) 3360 continue; 3361 pipes[pipe_idx].pipe.dest.vstartup_start = get_vstartup(&context->bw_ctx.dml, pipes, pipe_cnt, 3362 pipe_idx); 3363 pipes[pipe_idx].pipe.dest.vupdate_offset = get_vupdate_offset(&context->bw_ctx.dml, pipes, pipe_cnt, 3364 pipe_idx); 3365 pipes[pipe_idx].pipe.dest.vupdate_width = get_vupdate_width(&context->bw_ctx.dml, pipes, pipe_cnt, 3366 pipe_idx); 3367 pipes[pipe_idx].pipe.dest.vready_offset = get_vready_offset(&context->bw_ctx.dml, pipes, pipe_cnt, 3368 pipe_idx); 3369 if (context->res_ctx.pipe_ctx[i].stream->mall_stream_config.type == SUBVP_PHANTOM) { 3370 // Phantom pipe requires that DET_SIZE = 0 and no unbounded requests 3371 context->res_ctx.pipe_ctx[i].det_buffer_size_kb = 0; 3372 context->res_ctx.pipe_ctx[i].unbounded_req = false; 3373 } else { 3374 context->res_ctx.pipe_ctx[i].det_buffer_size_kb = get_det_buffer_size_kbytes(&context->bw_ctx.dml, pipes, pipe_cnt, 3375 pipe_idx); 3376 context->res_ctx.pipe_ctx[i].unbounded_req = pipes[pipe_idx].pipe.src.unbounded_req_mode; 3377 } 3378 if (context->bw_ctx.bw.dcn.clk.dppclk_khz < pipes[pipe_idx].clks_cfg.dppclk_mhz * 1000) 3379 context->bw_ctx.bw.dcn.clk.dppclk_khz = pipes[pipe_idx].clks_cfg.dppclk_mhz * 1000; 3380 context->res_ctx.pipe_ctx[i].plane_res.bw.dppclk_khz = pipes[pipe_idx].clks_cfg.dppclk_mhz * 1000; 3381 context->res_ctx.pipe_ctx[i].pipe_dlg_param = pipes[pipe_idx].pipe.dest; 3382 pipe_idx++; 3383 } 3384 /*save a original dppclock copy*/ 3385 context->bw_ctx.bw.dcn.clk.bw_dppclk_khz = context->bw_ctx.bw.dcn.clk.dppclk_khz; 3386 context->bw_ctx.bw.dcn.clk.bw_dispclk_khz = context->bw_ctx.bw.dcn.clk.dispclk_khz; 3387 context->bw_ctx.bw.dcn.clk.max_supported_dppclk_khz = context->bw_ctx.dml.soc.clock_limits[vlevel].dppclk_mhz 3388 * 1000; 3389 context->bw_ctx.bw.dcn.clk.max_supported_dispclk_khz = context->bw_ctx.dml.soc.clock_limits[vlevel].dispclk_mhz 3390 * 1000; 3391 3392 context->bw_ctx.bw.dcn.compbuf_size_kb = context->bw_ctx.dml.ip.config_return_buffer_size_in_kbytes; 3393 3394 for (i = 0; i < dc->res_pool->pipe_count; i++) { 3395 if (context->res_ctx.pipe_ctx[i].stream) 3396 context->bw_ctx.bw.dcn.compbuf_size_kb -= context->res_ctx.pipe_ctx[i].det_buffer_size_kb; 3397 } 3398 3399 for (i = 0, pipe_idx = 0; i < dc->res_pool->pipe_count; i++) { 3400 3401 if (!context->res_ctx.pipe_ctx[i].stream) 3402 continue; 3403 3404 context->bw_ctx.dml.funcs.rq_dlg_get_dlg_reg_v2(&context->bw_ctx.dml, 3405 &context->res_ctx.pipe_ctx[i].dlg_regs, &context->res_ctx.pipe_ctx[i].ttu_regs, pipes, 3406 pipe_cnt, pipe_idx); 3407 3408 context->bw_ctx.dml.funcs.rq_dlg_get_rq_reg_v2(&context->res_ctx.pipe_ctx[i].rq_regs, 3409 &context->bw_ctx.dml, pipes, pipe_cnt, pipe_idx); 3410 3411 pipe_idx++; 3412 } 3413 } 3414 3415 static void get_optimal_ntuple(struct _vcs_dpi_voltage_scaling_st *entry) 3416 { 3417 if (entry->dcfclk_mhz > 0) { 3418 float bw_on_sdp = entry->dcfclk_mhz * dcn3_2_soc.return_bus_width_bytes * ((float)dcn3_2_soc.pct_ideal_sdp_bw_after_urgent / 100); 3419 3420 entry->fabricclk_mhz = bw_on_sdp / (dcn3_2_soc.return_bus_width_bytes * ((float)dcn3_2_soc.pct_ideal_fabric_bw_after_urgent / 100)); 3421 entry->dram_speed_mts = bw_on_sdp / (dcn3_2_soc.num_chans * 3422 dcn3_2_soc.dram_channel_width_bytes * ((float)dcn3_2_soc.pct_ideal_dram_sdp_bw_after_urgent_pixel_only / 100)); 3423 } else if (entry->fabricclk_mhz > 0) { 3424 float bw_on_fabric = entry->fabricclk_mhz * dcn3_2_soc.return_bus_width_bytes * ((float)dcn3_2_soc.pct_ideal_fabric_bw_after_urgent / 100); 3425 3426 entry->dcfclk_mhz = bw_on_fabric / (dcn3_2_soc.return_bus_width_bytes * ((float)dcn3_2_soc.pct_ideal_sdp_bw_after_urgent / 100)); 3427 entry->dram_speed_mts = bw_on_fabric / (dcn3_2_soc.num_chans * 3428 dcn3_2_soc.dram_channel_width_bytes * ((float)dcn3_2_soc.pct_ideal_dram_sdp_bw_after_urgent_pixel_only / 100)); 3429 } else if (entry->dram_speed_mts > 0) { 3430 float bw_on_dram = entry->dram_speed_mts * dcn3_2_soc.num_chans * 3431 dcn3_2_soc.dram_channel_width_bytes * ((float)dcn3_2_soc.pct_ideal_dram_sdp_bw_after_urgent_pixel_only / 100); 3432 3433 entry->fabricclk_mhz = bw_on_dram / (dcn3_2_soc.return_bus_width_bytes * ((float)dcn3_2_soc.pct_ideal_fabric_bw_after_urgent / 100)); 3434 entry->dcfclk_mhz = bw_on_dram / (dcn3_2_soc.return_bus_width_bytes * ((float)dcn3_2_soc.pct_ideal_sdp_bw_after_urgent / 100)); 3435 } 3436 } 3437 3438 static float calculate_net_bw_in_kbytes_sec(struct _vcs_dpi_voltage_scaling_st *entry) 3439 { 3440 float memory_bw_kbytes_sec = entry->dram_speed_mts * dcn3_2_soc.num_chans * 3441 dcn3_2_soc.dram_channel_width_bytes * ((float)dcn3_2_soc.pct_ideal_dram_sdp_bw_after_urgent_pixel_only / 100); 3442 3443 float fabric_bw_kbytes_sec = entry->fabricclk_mhz * dcn3_2_soc.return_bus_width_bytes * ((float)dcn3_2_soc.pct_ideal_fabric_bw_after_urgent / 100); 3444 3445 float sdp_bw_kbytes_sec = entry->dcfclk_mhz * dcn3_2_soc.return_bus_width_bytes * ((float)dcn3_2_soc.pct_ideal_sdp_bw_after_urgent / 100); 3446 3447 float limiting_bw_kbytes_sec = memory_bw_kbytes_sec; 3448 3449 if (fabric_bw_kbytes_sec < limiting_bw_kbytes_sec) 3450 limiting_bw_kbytes_sec = fabric_bw_kbytes_sec; 3451 3452 if (sdp_bw_kbytes_sec < limiting_bw_kbytes_sec) 3453 limiting_bw_kbytes_sec = sdp_bw_kbytes_sec; 3454 3455 return limiting_bw_kbytes_sec; 3456 } 3457 3458 static void insert_entry_into_table_sorted(struct _vcs_dpi_voltage_scaling_st *table, unsigned int *num_entries, 3459 struct _vcs_dpi_voltage_scaling_st *entry) 3460 { 3461 int index = 0; 3462 int i = 0; 3463 float net_bw_of_new_state = 0; 3464 3465 if (*num_entries == 0) { 3466 table[0] = *entry; 3467 (*num_entries)++; 3468 } else { 3469 net_bw_of_new_state = calculate_net_bw_in_kbytes_sec(entry); 3470 while (net_bw_of_new_state > calculate_net_bw_in_kbytes_sec(&table[index])) { 3471 index++; 3472 if (index >= *num_entries) 3473 break; 3474 } 3475 3476 for (i = *num_entries; i > index; i--) { 3477 table[i] = table[i - 1]; 3478 } 3479 3480 table[index] = *entry; 3481 (*num_entries)++; 3482 } 3483 } 3484 3485 static void remove_entry_from_table_at_index(struct _vcs_dpi_voltage_scaling_st *table, unsigned int *num_entries, 3486 unsigned int index) 3487 { 3488 int i; 3489 3490 if (*num_entries == 0) 3491 return; 3492 3493 for (i = index; i < *num_entries - 1; i++) { 3494 table[i] = table[i + 1]; 3495 } 3496 memset(&table[--(*num_entries)], 0, sizeof(struct _vcs_dpi_voltage_scaling_st)); 3497 } 3498 3499 static int build_synthetic_soc_states(struct clk_bw_params *bw_params, 3500 struct _vcs_dpi_voltage_scaling_st *table, unsigned int *num_entries) 3501 { 3502 int i, j; 3503 struct _vcs_dpi_voltage_scaling_st entry = {0}; 3504 3505 unsigned int max_dcfclk_mhz = 0, max_dispclk_mhz = 0, max_dppclk_mhz = 0, 3506 max_phyclk_mhz = 0, max_dtbclk_mhz = 0, max_fclk_mhz = 0, max_uclk_mhz = 0; 3507 3508 unsigned int min_dcfclk_mhz = 199, min_fclk_mhz = 299; 3509 3510 static const unsigned int num_dcfclk_stas = 5; 3511 unsigned int dcfclk_sta_targets[DC__VOLTAGE_STATES] = {199, 615, 906, 1324, 1564}; 3512 3513 unsigned int num_uclk_dpms = 0; 3514 unsigned int num_fclk_dpms = 0; 3515 unsigned int num_dcfclk_dpms = 0; 3516 3517 for (i = 0; i < MAX_NUM_DPM_LVL; i++) { 3518 if (bw_params->clk_table.entries[i].dcfclk_mhz > max_dcfclk_mhz) 3519 max_dcfclk_mhz = bw_params->clk_table.entries[i].dcfclk_mhz; 3520 if (bw_params->clk_table.entries[i].fclk_mhz > max_fclk_mhz) 3521 max_fclk_mhz = bw_params->clk_table.entries[i].fclk_mhz; 3522 if (bw_params->clk_table.entries[i].memclk_mhz > max_uclk_mhz) 3523 max_uclk_mhz = bw_params->clk_table.entries[i].memclk_mhz; 3524 if (bw_params->clk_table.entries[i].dispclk_mhz > max_dispclk_mhz) 3525 max_dispclk_mhz = bw_params->clk_table.entries[i].dispclk_mhz; 3526 if (bw_params->clk_table.entries[i].dppclk_mhz > max_dppclk_mhz) 3527 max_dppclk_mhz = bw_params->clk_table.entries[i].dppclk_mhz; 3528 if (bw_params->clk_table.entries[i].phyclk_mhz > max_phyclk_mhz) 3529 max_phyclk_mhz = bw_params->clk_table.entries[i].phyclk_mhz; 3530 if (bw_params->clk_table.entries[i].dtbclk_mhz > max_dtbclk_mhz) 3531 max_dtbclk_mhz = bw_params->clk_table.entries[i].dtbclk_mhz; 3532 3533 if (bw_params->clk_table.entries[i].memclk_mhz > 0) 3534 num_uclk_dpms++; 3535 if (bw_params->clk_table.entries[i].fclk_mhz > 0) 3536 num_fclk_dpms++; 3537 if (bw_params->clk_table.entries[i].dcfclk_mhz > 0) 3538 num_dcfclk_dpms++; 3539 } 3540 3541 if (!max_dcfclk_mhz || !max_dispclk_mhz || !max_dtbclk_mhz) 3542 return -1; 3543 3544 if (max_dppclk_mhz == 0) 3545 max_dppclk_mhz = max_dispclk_mhz; 3546 3547 if (max_fclk_mhz == 0) 3548 max_fclk_mhz = max_dcfclk_mhz * dcn3_2_soc.pct_ideal_sdp_bw_after_urgent / dcn3_2_soc.pct_ideal_fabric_bw_after_urgent; 3549 3550 if (max_phyclk_mhz == 0) 3551 max_phyclk_mhz = dcn3_2_soc.clock_limits[0].phyclk_mhz; 3552 3553 *num_entries = 0; 3554 entry.dispclk_mhz = max_dispclk_mhz; 3555 entry.dscclk_mhz = max_dispclk_mhz / 3; 3556 entry.dppclk_mhz = max_dppclk_mhz; 3557 entry.dtbclk_mhz = max_dtbclk_mhz; 3558 entry.phyclk_mhz = max_phyclk_mhz; 3559 entry.phyclk_d18_mhz = dcn3_2_soc.clock_limits[0].phyclk_d18_mhz; 3560 entry.phyclk_d32_mhz = dcn3_2_soc.clock_limits[0].phyclk_d32_mhz; 3561 3562 // Insert all the DCFCLK STAs 3563 for (i = 0; i < num_dcfclk_stas; i++) { 3564 entry.dcfclk_mhz = dcfclk_sta_targets[i]; 3565 entry.fabricclk_mhz = 0; 3566 entry.dram_speed_mts = 0; 3567 3568 get_optimal_ntuple(&entry); 3569 insert_entry_into_table_sorted(table, num_entries, &entry); 3570 } 3571 3572 // Insert the max DCFCLK 3573 entry.dcfclk_mhz = max_dcfclk_mhz; 3574 entry.fabricclk_mhz = 0; 3575 entry.dram_speed_mts = 0; 3576 3577 get_optimal_ntuple(&entry); 3578 insert_entry_into_table_sorted(table, num_entries, &entry); 3579 3580 // Insert the UCLK DPMS 3581 for (i = 0; i < num_uclk_dpms; i++) { 3582 entry.dcfclk_mhz = 0; 3583 entry.fabricclk_mhz = 0; 3584 entry.dram_speed_mts = bw_params->clk_table.entries[i].memclk_mhz * 16; 3585 3586 get_optimal_ntuple(&entry); 3587 insert_entry_into_table_sorted(table, num_entries, &entry); 3588 } 3589 3590 // If FCLK is coarse grained, insert individual DPMs. 3591 if (num_fclk_dpms > 2) { 3592 for (i = 0; i < num_fclk_dpms; i++) { 3593 entry.dcfclk_mhz = 0; 3594 entry.fabricclk_mhz = bw_params->clk_table.entries[i].fclk_mhz; 3595 entry.dram_speed_mts = 0; 3596 3597 get_optimal_ntuple(&entry); 3598 insert_entry_into_table_sorted(table, num_entries, &entry); 3599 } 3600 } 3601 // If FCLK fine grained, only insert max 3602 else { 3603 entry.dcfclk_mhz = 0; 3604 entry.fabricclk_mhz = max_fclk_mhz; 3605 entry.dram_speed_mts = 0; 3606 3607 get_optimal_ntuple(&entry); 3608 insert_entry_into_table_sorted(table, num_entries, &entry); 3609 } 3610 3611 // At this point, the table contains all "points of interest" based on 3612 // DPMs from PMFW, and STAs. Table is sorted by BW, and all clock 3613 // ratios (by derate, are exact). 3614 3615 // Remove states that require higher clocks than are supported 3616 for (i = *num_entries - 1; i >= 0 ; i--) { 3617 if (table[i].dcfclk_mhz > max_dcfclk_mhz || 3618 table[i].fabricclk_mhz > max_fclk_mhz || 3619 table[i].dram_speed_mts > max_uclk_mhz * 16) 3620 remove_entry_from_table_at_index(table, num_entries, i); 3621 } 3622 3623 // At this point, the table only contains supported points of interest 3624 // it could be used as is, but some states may be redundant due to 3625 // coarse grained nature of some clocks, so we want to round up to 3626 // coarse grained DPMs and remove duplicates. 3627 3628 // Round up UCLKs 3629 for (i = *num_entries - 1; i >= 0 ; i--) { 3630 for (j = 0; j < num_uclk_dpms; j++) { 3631 if (bw_params->clk_table.entries[j].memclk_mhz * 16 >= table[i].dram_speed_mts) { 3632 table[i].dram_speed_mts = bw_params->clk_table.entries[j].memclk_mhz * 16; 3633 break; 3634 } 3635 } 3636 } 3637 3638 // If FCLK is coarse grained, round up to next DPMs 3639 if (num_fclk_dpms > 2) { 3640 for (i = *num_entries - 1; i >= 0 ; i--) { 3641 for (j = 0; j < num_fclk_dpms; j++) { 3642 if (bw_params->clk_table.entries[j].fclk_mhz >= table[i].fabricclk_mhz) { 3643 table[i].fabricclk_mhz = bw_params->clk_table.entries[j].fclk_mhz; 3644 break; 3645 } 3646 } 3647 } 3648 } 3649 // Otherwise, round up to minimum. 3650 else { 3651 for (i = *num_entries - 1; i >= 0 ; i--) { 3652 if (table[i].fabricclk_mhz < min_fclk_mhz) { 3653 table[i].fabricclk_mhz = min_fclk_mhz; 3654 break; 3655 } 3656 } 3657 } 3658 3659 // Round DCFCLKs up to minimum 3660 for (i = *num_entries - 1; i >= 0 ; i--) { 3661 if (table[i].dcfclk_mhz < min_dcfclk_mhz) { 3662 table[i].dcfclk_mhz = min_dcfclk_mhz; 3663 break; 3664 } 3665 } 3666 3667 // Remove duplicate states, note duplicate states are always neighbouring since table is sorted. 3668 i = 0; 3669 while (i < *num_entries - 1) { 3670 if (table[i].dcfclk_mhz == table[i + 1].dcfclk_mhz && 3671 table[i].fabricclk_mhz == table[i + 1].fabricclk_mhz && 3672 table[i].dram_speed_mts == table[i + 1].dram_speed_mts) 3673 remove_entry_from_table_at_index(table, num_entries, i + 1); 3674 else 3675 i++; 3676 } 3677 3678 // Fix up the state indicies 3679 for (i = *num_entries - 1; i >= 0 ; i--) { 3680 table[i].state = i; 3681 } 3682 3683 return 0; 3684 } 3685 3686 /* dcn32_update_bw_bounding_box 3687 * This would override some dcn3_2 ip_or_soc initial parameters hardcoded from spreadsheet 3688 * with actual values as per dGPU SKU: 3689 * -with passed few options from dc->config 3690 * -with dentist_vco_frequency from Clk Mgr (currently hardcoded, but might need to get it from PM FW) 3691 * -with passed latency values (passed in ns units) in dc-> bb override for debugging purposes 3692 * -with passed latencies from VBIOS (in 100_ns units) if available for certain dGPU SKU 3693 * -with number of DRAM channels from VBIOS (which differ for certain dGPU SKU of the same ASIC) 3694 * -clocks levels with passed clk_table entries from Clk Mgr as reported by PM FW for different 3695 * clocks (which might differ for certain dGPU SKU of the same ASIC) 3696 */ 3697 static void dcn32_update_bw_bounding_box(struct dc *dc, struct clk_bw_params *bw_params) 3698 { 3699 if (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment)) { 3700 3701 /* Overrides from dc->config options */ 3702 dcn3_2_ip.clamp_min_dcfclk = dc->config.clamp_min_dcfclk; 3703 3704 /* Override from passed dc->bb_overrides if available*/ 3705 if ((int)(dcn3_2_soc.sr_exit_time_us * 1000) != dc->bb_overrides.sr_exit_time_ns 3706 && dc->bb_overrides.sr_exit_time_ns) { 3707 dcn3_2_soc.sr_exit_time_us = dc->bb_overrides.sr_exit_time_ns / 1000.0; 3708 } 3709 3710 if ((int)(dcn3_2_soc.sr_enter_plus_exit_time_us * 1000) 3711 != dc->bb_overrides.sr_enter_plus_exit_time_ns 3712 && dc->bb_overrides.sr_enter_plus_exit_time_ns) { 3713 dcn3_2_soc.sr_enter_plus_exit_time_us = 3714 dc->bb_overrides.sr_enter_plus_exit_time_ns / 1000.0; 3715 } 3716 3717 if ((int)(dcn3_2_soc.urgent_latency_us * 1000) != dc->bb_overrides.urgent_latency_ns 3718 && dc->bb_overrides.urgent_latency_ns) { 3719 dcn3_2_soc.urgent_latency_us = dc->bb_overrides.urgent_latency_ns / 1000.0; 3720 } 3721 3722 if ((int)(dcn3_2_soc.dram_clock_change_latency_us * 1000) 3723 != dc->bb_overrides.dram_clock_change_latency_ns 3724 && dc->bb_overrides.dram_clock_change_latency_ns) { 3725 dcn3_2_soc.dram_clock_change_latency_us = 3726 dc->bb_overrides.dram_clock_change_latency_ns / 1000.0; 3727 } 3728 3729 if ((int)(dcn3_2_soc.dummy_pstate_latency_us * 1000) 3730 != dc->bb_overrides.dummy_clock_change_latency_ns 3731 && dc->bb_overrides.dummy_clock_change_latency_ns) { 3732 dcn3_2_soc.dummy_pstate_latency_us = 3733 dc->bb_overrides.dummy_clock_change_latency_ns / 1000.0; 3734 } 3735 3736 /* Override from VBIOS if VBIOS bb_info available */ 3737 if (dc->ctx->dc_bios->funcs->get_soc_bb_info) { 3738 struct bp_soc_bb_info bb_info = {0}; 3739 3740 if (dc->ctx->dc_bios->funcs->get_soc_bb_info(dc->ctx->dc_bios, &bb_info) == BP_RESULT_OK) { 3741 if (bb_info.dram_clock_change_latency_100ns > 0) 3742 dcn3_2_soc.dram_clock_change_latency_us = bb_info.dram_clock_change_latency_100ns * 10; 3743 3744 if (bb_info.dram_sr_enter_exit_latency_100ns > 0) 3745 dcn3_2_soc.sr_enter_plus_exit_time_us = bb_info.dram_sr_enter_exit_latency_100ns * 10; 3746 3747 if (bb_info.dram_sr_exit_latency_100ns > 0) 3748 dcn3_2_soc.sr_exit_time_us = bb_info.dram_sr_exit_latency_100ns * 10; 3749 } 3750 } 3751 3752 /* Override from VBIOS for num_chan */ 3753 if (dc->ctx->dc_bios->vram_info.num_chans) 3754 dcn3_2_soc.num_chans = dc->ctx->dc_bios->vram_info.num_chans; 3755 3756 if (dc->ctx->dc_bios->vram_info.dram_channel_width_bytes) 3757 dcn3_2_soc.dram_channel_width_bytes = dc->ctx->dc_bios->vram_info.dram_channel_width_bytes; 3758 3759 } 3760 3761 /* Override dispclk_dppclk_vco_speed_mhz from Clk Mgr */ 3762 dcn3_2_soc.dispclk_dppclk_vco_speed_mhz = dc->clk_mgr->dentist_vco_freq_khz / 1000.0; 3763 dc->dml.soc.dispclk_dppclk_vco_speed_mhz = dc->clk_mgr->dentist_vco_freq_khz / 1000.0; 3764 3765 /* Overrides Clock levelsfrom CLK Mgr table entries as reported by PM FW */ 3766 if ((!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment)) && (bw_params->clk_table.entries[0].memclk_mhz)) { 3767 if (dc->debug.use_legacy_soc_bb_mechanism) { 3768 unsigned int i = 0, j = 0, num_states = 0; 3769 3770 unsigned int dcfclk_mhz[DC__VOLTAGE_STATES] = {0}; 3771 unsigned int dram_speed_mts[DC__VOLTAGE_STATES] = {0}; 3772 unsigned int optimal_uclk_for_dcfclk_sta_targets[DC__VOLTAGE_STATES] = {0}; 3773 unsigned int optimal_dcfclk_for_uclk[DC__VOLTAGE_STATES] = {0}; 3774 unsigned int min_dcfclk = UINT_MAX; 3775 /* Set 199 as first value in STA target array to have a minimum DCFCLK value. 3776 * For DCN32 we set min to 199 so minimum FCLK DPM0 (300Mhz can be achieved) */ 3777 unsigned int dcfclk_sta_targets[DC__VOLTAGE_STATES] = {199, 615, 906, 1324, 1564}; 3778 unsigned int num_dcfclk_sta_targets = 4, num_uclk_states = 0; 3779 unsigned int max_dcfclk_mhz = 0, max_dispclk_mhz = 0, max_dppclk_mhz = 0, max_phyclk_mhz = 0; 3780 3781 for (i = 0; i < MAX_NUM_DPM_LVL; i++) { 3782 if (bw_params->clk_table.entries[i].dcfclk_mhz > max_dcfclk_mhz) 3783 max_dcfclk_mhz = bw_params->clk_table.entries[i].dcfclk_mhz; 3784 if (bw_params->clk_table.entries[i].dcfclk_mhz != 0 && 3785 bw_params->clk_table.entries[i].dcfclk_mhz < min_dcfclk) 3786 min_dcfclk = bw_params->clk_table.entries[i].dcfclk_mhz; 3787 if (bw_params->clk_table.entries[i].dispclk_mhz > max_dispclk_mhz) 3788 max_dispclk_mhz = bw_params->clk_table.entries[i].dispclk_mhz; 3789 if (bw_params->clk_table.entries[i].dppclk_mhz > max_dppclk_mhz) 3790 max_dppclk_mhz = bw_params->clk_table.entries[i].dppclk_mhz; 3791 if (bw_params->clk_table.entries[i].phyclk_mhz > max_phyclk_mhz) 3792 max_phyclk_mhz = bw_params->clk_table.entries[i].phyclk_mhz; 3793 } 3794 if (min_dcfclk > dcfclk_sta_targets[0]) 3795 dcfclk_sta_targets[0] = min_dcfclk; 3796 if (!max_dcfclk_mhz) 3797 max_dcfclk_mhz = dcn3_2_soc.clock_limits[0].dcfclk_mhz; 3798 if (!max_dispclk_mhz) 3799 max_dispclk_mhz = dcn3_2_soc.clock_limits[0].dispclk_mhz; 3800 if (!max_dppclk_mhz) 3801 max_dppclk_mhz = dcn3_2_soc.clock_limits[0].dppclk_mhz; 3802 if (!max_phyclk_mhz) 3803 max_phyclk_mhz = dcn3_2_soc.clock_limits[0].phyclk_mhz; 3804 3805 if (max_dcfclk_mhz > dcfclk_sta_targets[num_dcfclk_sta_targets-1]) { 3806 // If max DCFCLK is greater than the max DCFCLK STA target, insert into the DCFCLK STA target array 3807 dcfclk_sta_targets[num_dcfclk_sta_targets] = max_dcfclk_mhz; 3808 num_dcfclk_sta_targets++; 3809 } else if (max_dcfclk_mhz < dcfclk_sta_targets[num_dcfclk_sta_targets-1]) { 3810 // If max DCFCLK is less than the max DCFCLK STA target, cap values and remove duplicates 3811 for (i = 0; i < num_dcfclk_sta_targets; i++) { 3812 if (dcfclk_sta_targets[i] > max_dcfclk_mhz) { 3813 dcfclk_sta_targets[i] = max_dcfclk_mhz; 3814 break; 3815 } 3816 } 3817 // Update size of array since we "removed" duplicates 3818 num_dcfclk_sta_targets = i + 1; 3819 } 3820 3821 num_uclk_states = bw_params->clk_table.num_entries; 3822 3823 // Calculate optimal dcfclk for each uclk 3824 for (i = 0; i < num_uclk_states; i++) { 3825 dcn32_get_optimal_dcfclk_fclk_for_uclk(bw_params->clk_table.entries[i].memclk_mhz * 16, 3826 &optimal_dcfclk_for_uclk[i], NULL); 3827 if (optimal_dcfclk_for_uclk[i] < bw_params->clk_table.entries[0].dcfclk_mhz) { 3828 optimal_dcfclk_for_uclk[i] = bw_params->clk_table.entries[0].dcfclk_mhz; 3829 } 3830 } 3831 3832 // Calculate optimal uclk for each dcfclk sta target 3833 for (i = 0; i < num_dcfclk_sta_targets; i++) { 3834 for (j = 0; j < num_uclk_states; j++) { 3835 if (dcfclk_sta_targets[i] < optimal_dcfclk_for_uclk[j]) { 3836 optimal_uclk_for_dcfclk_sta_targets[i] = 3837 bw_params->clk_table.entries[j].memclk_mhz * 16; 3838 break; 3839 } 3840 } 3841 } 3842 3843 i = 0; 3844 j = 0; 3845 // create the final dcfclk and uclk table 3846 while (i < num_dcfclk_sta_targets && j < num_uclk_states && num_states < DC__VOLTAGE_STATES) { 3847 if (dcfclk_sta_targets[i] < optimal_dcfclk_for_uclk[j] && i < num_dcfclk_sta_targets) { 3848 dcfclk_mhz[num_states] = dcfclk_sta_targets[i]; 3849 dram_speed_mts[num_states++] = optimal_uclk_for_dcfclk_sta_targets[i++]; 3850 } else { 3851 if (j < num_uclk_states && optimal_dcfclk_for_uclk[j] <= max_dcfclk_mhz) { 3852 dcfclk_mhz[num_states] = optimal_dcfclk_for_uclk[j]; 3853 dram_speed_mts[num_states++] = bw_params->clk_table.entries[j++].memclk_mhz * 16; 3854 } else { 3855 j = num_uclk_states; 3856 } 3857 } 3858 } 3859 3860 while (i < num_dcfclk_sta_targets && num_states < DC__VOLTAGE_STATES) { 3861 dcfclk_mhz[num_states] = dcfclk_sta_targets[i]; 3862 dram_speed_mts[num_states++] = optimal_uclk_for_dcfclk_sta_targets[i++]; 3863 } 3864 3865 while (j < num_uclk_states && num_states < DC__VOLTAGE_STATES && 3866 optimal_dcfclk_for_uclk[j] <= max_dcfclk_mhz) { 3867 dcfclk_mhz[num_states] = optimal_dcfclk_for_uclk[j]; 3868 dram_speed_mts[num_states++] = bw_params->clk_table.entries[j++].memclk_mhz * 16; 3869 } 3870 3871 dcn3_2_soc.num_states = num_states; 3872 for (i = 0; i < dcn3_2_soc.num_states; i++) { 3873 dcn3_2_soc.clock_limits[i].state = i; 3874 dcn3_2_soc.clock_limits[i].dcfclk_mhz = dcfclk_mhz[i]; 3875 dcn3_2_soc.clock_limits[i].fabricclk_mhz = dcfclk_mhz[i]; 3876 3877 /* Fill all states with max values of all these clocks */ 3878 dcn3_2_soc.clock_limits[i].dispclk_mhz = max_dispclk_mhz; 3879 dcn3_2_soc.clock_limits[i].dppclk_mhz = max_dppclk_mhz; 3880 dcn3_2_soc.clock_limits[i].phyclk_mhz = max_phyclk_mhz; 3881 dcn3_2_soc.clock_limits[i].dscclk_mhz = max_dispclk_mhz / 3; 3882 3883 /* Populate from bw_params for DTBCLK, SOCCLK */ 3884 if (i > 0) { 3885 if (!bw_params->clk_table.entries[i].dtbclk_mhz) { 3886 dcn3_2_soc.clock_limits[i].dtbclk_mhz = dcn3_2_soc.clock_limits[i-1].dtbclk_mhz; 3887 } else { 3888 dcn3_2_soc.clock_limits[i].dtbclk_mhz = bw_params->clk_table.entries[i].dtbclk_mhz; 3889 } 3890 } else if (bw_params->clk_table.entries[i].dtbclk_mhz) { 3891 dcn3_2_soc.clock_limits[i].dtbclk_mhz = bw_params->clk_table.entries[i].dtbclk_mhz; 3892 } 3893 3894 if (!bw_params->clk_table.entries[i].socclk_mhz && i > 0) 3895 dcn3_2_soc.clock_limits[i].socclk_mhz = dcn3_2_soc.clock_limits[i-1].socclk_mhz; 3896 else 3897 dcn3_2_soc.clock_limits[i].socclk_mhz = bw_params->clk_table.entries[i].socclk_mhz; 3898 3899 if (!dram_speed_mts[i] && i > 0) 3900 dcn3_2_soc.clock_limits[i].dram_speed_mts = dcn3_2_soc.clock_limits[i-1].dram_speed_mts; 3901 else 3902 dcn3_2_soc.clock_limits[i].dram_speed_mts = dram_speed_mts[i]; 3903 3904 /* These clocks cannot come from bw_params, always fill from dcn3_2_soc[0] */ 3905 /* PHYCLK_D18, PHYCLK_D32 */ 3906 dcn3_2_soc.clock_limits[i].phyclk_d18_mhz = dcn3_2_soc.clock_limits[0].phyclk_d18_mhz; 3907 dcn3_2_soc.clock_limits[i].phyclk_d32_mhz = dcn3_2_soc.clock_limits[0].phyclk_d32_mhz; 3908 } 3909 } else { 3910 build_synthetic_soc_states(bw_params, dcn3_2_soc.clock_limits, &dcn3_2_soc.num_states); 3911 } 3912 3913 /* Re-init DML with updated bb */ 3914 dml_init_instance(&dc->dml, &dcn3_2_soc, &dcn3_2_ip, DML_PROJECT_DCN32); 3915 if (dc->current_state) 3916 dml_init_instance(&dc->current_state->bw_ctx.dml, &dcn3_2_soc, &dcn3_2_ip, DML_PROJECT_DCN32); 3917 } 3918 } 3919 3920 static struct resource_funcs dcn32_res_pool_funcs = { 3921 .destroy = dcn32_destroy_resource_pool, 3922 .link_enc_create = dcn32_link_encoder_create, 3923 .link_enc_create_minimal = NULL, 3924 .panel_cntl_create = dcn32_panel_cntl_create, 3925 .validate_bandwidth = dcn32_validate_bandwidth, 3926 .calculate_wm_and_dlg = dcn32_calculate_wm_and_dlg, 3927 .populate_dml_pipes = dcn32_populate_dml_pipes_from_context, 3928 .acquire_idle_pipe_for_layer = dcn20_acquire_idle_pipe_for_layer, 3929 .add_stream_to_ctx = dcn30_add_stream_to_ctx, 3930 .add_dsc_to_stream_resource = dcn20_add_dsc_to_stream_resource, 3931 .remove_stream_from_ctx = dcn20_remove_stream_from_ctx, 3932 .populate_dml_writeback_from_context = dcn30_populate_dml_writeback_from_context, 3933 .set_mcif_arb_params = dcn30_set_mcif_arb_params, 3934 .find_first_free_match_stream_enc_for_link = dcn10_find_first_free_match_stream_enc_for_link, 3935 .acquire_post_bldn_3dlut = dcn32_acquire_post_bldn_3dlut, 3936 .release_post_bldn_3dlut = dcn32_release_post_bldn_3dlut, 3937 .update_bw_bounding_box = dcn32_update_bw_bounding_box, 3938 .patch_unknown_plane_state = dcn20_patch_unknown_plane_state, 3939 .update_soc_for_wm_a = dcn30_update_soc_for_wm_a, 3940 .add_phantom_pipes = dcn32_add_phantom_pipes, 3941 .remove_phantom_pipes = dcn32_remove_phantom_pipes, 3942 }; 3943 3944 3945 static bool dcn32_resource_construct( 3946 uint8_t num_virtual_links, 3947 struct dc *dc, 3948 struct dcn32_resource_pool *pool) 3949 { 3950 int i, j; 3951 struct dc_context *ctx = dc->ctx; 3952 struct irq_service_init_data init_data; 3953 struct ddc_service_init_data ddc_init_data = {0}; 3954 uint32_t pipe_fuses = 0; 3955 uint32_t num_pipes = 4; 3956 3957 DC_FP_START(); 3958 3959 ctx->dc_bios->regs = &bios_regs; 3960 3961 pool->base.res_cap = &res_cap_dcn32; 3962 /* max number of pipes for ASIC before checking for pipe fuses */ 3963 num_pipes = pool->base.res_cap->num_timing_generator; 3964 pipe_fuses = REG_READ(CC_DC_PIPE_DIS); 3965 3966 for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) 3967 if (pipe_fuses & 1 << i) 3968 num_pipes--; 3969 3970 if (pipe_fuses & 1) 3971 ASSERT(0); //Unexpected - Pipe 0 should always be fully functional! 3972 3973 if (pipe_fuses & CC_DC_PIPE_DIS__DC_FULL_DIS_MASK) 3974 ASSERT(0); //Entire DCN is harvested! 3975 3976 /* within dml lib, initial value is hard coded, if ASIC pipe is fused, the 3977 * value will be changed, update max_num_dpp and max_num_otg for dml. 3978 */ 3979 dcn3_2_ip.max_num_dpp = num_pipes; 3980 dcn3_2_ip.max_num_otg = num_pipes; 3981 3982 pool->base.funcs = &dcn32_res_pool_funcs; 3983 3984 /************************************************* 3985 * Resource + asic cap harcoding * 3986 *************************************************/ 3987 pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE; 3988 pool->base.timing_generator_count = num_pipes; 3989 pool->base.pipe_count = num_pipes; 3990 pool->base.mpcc_count = num_pipes; 3991 dc->caps.max_downscale_ratio = 600; 3992 dc->caps.i2c_speed_in_khz = 100; 3993 dc->caps.i2c_speed_in_khz_hdcp = 100; /*1.4 w/a applied by default*/ 3994 dc->caps.max_cursor_size = 256; 3995 dc->caps.min_horizontal_blanking_period = 80; 3996 dc->caps.dmdata_alloc_size = 2048; 3997 dc->caps.mall_size_per_mem_channel = 0; 3998 dc->caps.mall_size_total = 0; 3999 dc->caps.cursor_cache_size = dc->caps.max_cursor_size * dc->caps.max_cursor_size * 8; 4000 4001 dc->caps.cache_line_size = 64; 4002 dc->caps.cache_num_ways = 16; 4003 dc->caps.max_cab_allocation_bytes = 67108864; // 64MB = 1024 * 1024 * 64 4004 dc->caps.subvp_fw_processing_delay_us = 15; 4005 dc->caps.subvp_prefetch_end_to_mall_start_us = 15; 4006 dc->caps.subvp_pstate_allow_width_us = 20; 4007 dc->caps.subvp_vertical_int_margin_us = 30; 4008 4009 dc->caps.max_slave_planes = 2; 4010 dc->caps.max_slave_yuv_planes = 2; 4011 dc->caps.max_slave_rgb_planes = 2; 4012 dc->caps.post_blend_color_processing = true; 4013 dc->caps.force_dp_tps4_for_cp2520 = true; 4014 dc->caps.dp_hpo = true; 4015 dc->caps.dp_hdmi21_pcon_support = true; 4016 dc->caps.edp_dsc_support = true; 4017 dc->caps.extended_aux_timeout_support = true; 4018 dc->caps.dmcub_support = true; 4019 4020 /* Color pipeline capabilities */ 4021 dc->caps.color.dpp.dcn_arch = 1; 4022 dc->caps.color.dpp.input_lut_shared = 0; 4023 dc->caps.color.dpp.icsc = 1; 4024 dc->caps.color.dpp.dgam_ram = 0; // must use gamma_corr 4025 dc->caps.color.dpp.dgam_rom_caps.srgb = 1; 4026 dc->caps.color.dpp.dgam_rom_caps.bt2020 = 1; 4027 dc->caps.color.dpp.dgam_rom_caps.gamma2_2 = 1; 4028 dc->caps.color.dpp.dgam_rom_caps.pq = 1; 4029 dc->caps.color.dpp.dgam_rom_caps.hlg = 1; 4030 dc->caps.color.dpp.post_csc = 1; 4031 dc->caps.color.dpp.gamma_corr = 1; 4032 dc->caps.color.dpp.dgam_rom_for_yuv = 0; 4033 4034 dc->caps.color.dpp.hw_3d_lut = 1; 4035 dc->caps.color.dpp.ogam_ram = 0; // no OGAM in DPP since DCN1 4036 // no OGAM ROM on DCN2 and later ASICs 4037 dc->caps.color.dpp.ogam_rom_caps.srgb = 0; 4038 dc->caps.color.dpp.ogam_rom_caps.bt2020 = 0; 4039 dc->caps.color.dpp.ogam_rom_caps.gamma2_2 = 0; 4040 dc->caps.color.dpp.ogam_rom_caps.pq = 0; 4041 dc->caps.color.dpp.ogam_rom_caps.hlg = 0; 4042 dc->caps.color.dpp.ocsc = 0; 4043 4044 dc->caps.color.mpc.gamut_remap = 1; 4045 dc->caps.color.mpc.num_3dluts = pool->base.res_cap->num_mpc_3dlut; //4, configurable to be before or after BLND in MPCC 4046 dc->caps.color.mpc.ogam_ram = 1; 4047 dc->caps.color.mpc.ogam_rom_caps.srgb = 0; 4048 dc->caps.color.mpc.ogam_rom_caps.bt2020 = 0; 4049 dc->caps.color.mpc.ogam_rom_caps.gamma2_2 = 0; 4050 dc->caps.color.mpc.ogam_rom_caps.pq = 0; 4051 dc->caps.color.mpc.ogam_rom_caps.hlg = 0; 4052 dc->caps.color.mpc.ocsc = 1; 4053 4054 /* Use pipe context based otg sync logic */ 4055 dc->config.use_pipe_ctx_sync_logic = true; 4056 4057 /* read VBIOS LTTPR caps */ 4058 { 4059 if (ctx->dc_bios->funcs->get_lttpr_caps) { 4060 enum bp_result bp_query_result; 4061 uint8_t is_vbios_lttpr_enable = 0; 4062 4063 bp_query_result = ctx->dc_bios->funcs->get_lttpr_caps(ctx->dc_bios, &is_vbios_lttpr_enable); 4064 dc->caps.vbios_lttpr_enable = (bp_query_result == BP_RESULT_OK) && !!is_vbios_lttpr_enable; 4065 } 4066 4067 /* interop bit is implicit */ 4068 { 4069 dc->caps.vbios_lttpr_aware = true; 4070 } 4071 } 4072 4073 if (dc->ctx->dce_environment == DCE_ENV_PRODUCTION_DRV) 4074 dc->debug = debug_defaults_drv; 4075 else if (dc->ctx->dce_environment == DCE_ENV_FPGA_MAXIMUS) { 4076 dc->debug = debug_defaults_diags; 4077 } else 4078 dc->debug = debug_defaults_diags; 4079 // Init the vm_helper 4080 if (dc->vm_helper) 4081 vm_helper_init(dc->vm_helper, 16); 4082 4083 /************************************************* 4084 * Create resources * 4085 *************************************************/ 4086 4087 /* Clock Sources for Pixel Clock*/ 4088 pool->base.clock_sources[DCN32_CLK_SRC_PLL0] = 4089 dcn32_clock_source_create(ctx, ctx->dc_bios, 4090 CLOCK_SOURCE_COMBO_PHY_PLL0, 4091 &clk_src_regs[0], false); 4092 pool->base.clock_sources[DCN32_CLK_SRC_PLL1] = 4093 dcn32_clock_source_create(ctx, ctx->dc_bios, 4094 CLOCK_SOURCE_COMBO_PHY_PLL1, 4095 &clk_src_regs[1], false); 4096 pool->base.clock_sources[DCN32_CLK_SRC_PLL2] = 4097 dcn32_clock_source_create(ctx, ctx->dc_bios, 4098 CLOCK_SOURCE_COMBO_PHY_PLL2, 4099 &clk_src_regs[2], false); 4100 pool->base.clock_sources[DCN32_CLK_SRC_PLL3] = 4101 dcn32_clock_source_create(ctx, ctx->dc_bios, 4102 CLOCK_SOURCE_COMBO_PHY_PLL3, 4103 &clk_src_regs[3], false); 4104 pool->base.clock_sources[DCN32_CLK_SRC_PLL4] = 4105 dcn32_clock_source_create(ctx, ctx->dc_bios, 4106 CLOCK_SOURCE_COMBO_PHY_PLL4, 4107 &clk_src_regs[4], false); 4108 4109 pool->base.clk_src_count = DCN32_CLK_SRC_TOTAL; 4110 4111 /* todo: not reuse phy_pll registers */ 4112 pool->base.dp_clock_source = 4113 dcn32_clock_source_create(ctx, ctx->dc_bios, 4114 CLOCK_SOURCE_ID_DP_DTO, 4115 &clk_src_regs[0], true); 4116 4117 for (i = 0; i < pool->base.clk_src_count; i++) { 4118 if (pool->base.clock_sources[i] == NULL) { 4119 dm_error("DC: failed to create clock sources!\n"); 4120 BREAK_TO_DEBUGGER(); 4121 goto create_fail; 4122 } 4123 } 4124 4125 /* DCCG */ 4126 pool->base.dccg = dccg32_create(ctx, &dccg_regs, &dccg_shift, &dccg_mask); 4127 if (pool->base.dccg == NULL) { 4128 dm_error("DC: failed to create dccg!\n"); 4129 BREAK_TO_DEBUGGER(); 4130 goto create_fail; 4131 } 4132 4133 /* DML */ 4134 if (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment)) 4135 dml_init_instance(&dc->dml, &dcn3_2_soc, &dcn3_2_ip, DML_PROJECT_DCN32); 4136 4137 /* IRQ Service */ 4138 init_data.ctx = dc->ctx; 4139 pool->base.irqs = dal_irq_service_dcn32_create(&init_data); 4140 if (!pool->base.irqs) 4141 goto create_fail; 4142 4143 /* HUBBUB */ 4144 pool->base.hubbub = dcn32_hubbub_create(ctx); 4145 if (pool->base.hubbub == NULL) { 4146 BREAK_TO_DEBUGGER(); 4147 dm_error("DC: failed to create hubbub!\n"); 4148 goto create_fail; 4149 } 4150 4151 /* HUBPs, DPPs, OPPs, TGs, ABMs */ 4152 for (i = 0, j = 0; i < pool->base.res_cap->num_timing_generator; i++) { 4153 4154 /* if pipe is disabled, skip instance of HW pipe, 4155 * i.e, skip ASIC register instance 4156 */ 4157 if (pipe_fuses & 1 << i) 4158 continue; 4159 4160 /* HUBPs */ 4161 pool->base.hubps[j] = dcn32_hubp_create(ctx, i); 4162 if (pool->base.hubps[j] == NULL) { 4163 BREAK_TO_DEBUGGER(); 4164 dm_error( 4165 "DC: failed to create hubps!\n"); 4166 goto create_fail; 4167 } 4168 4169 /* DPPs */ 4170 pool->base.dpps[j] = dcn32_dpp_create(ctx, i); 4171 if (pool->base.dpps[j] == NULL) { 4172 BREAK_TO_DEBUGGER(); 4173 dm_error( 4174 "DC: failed to create dpps!\n"); 4175 goto create_fail; 4176 } 4177 4178 /* OPPs */ 4179 pool->base.opps[j] = dcn32_opp_create(ctx, i); 4180 if (pool->base.opps[j] == NULL) { 4181 BREAK_TO_DEBUGGER(); 4182 dm_error( 4183 "DC: failed to create output pixel processor!\n"); 4184 goto create_fail; 4185 } 4186 4187 /* TGs */ 4188 pool->base.timing_generators[j] = dcn32_timing_generator_create( 4189 ctx, i); 4190 if (pool->base.timing_generators[j] == NULL) { 4191 BREAK_TO_DEBUGGER(); 4192 dm_error("DC: failed to create tg!\n"); 4193 goto create_fail; 4194 } 4195 4196 /* ABMs */ 4197 pool->base.multiple_abms[j] = dmub_abm_create(ctx, 4198 &abm_regs[i], 4199 &abm_shift, 4200 &abm_mask); 4201 if (pool->base.multiple_abms[j] == NULL) { 4202 dm_error("DC: failed to create abm for pipe %d!\n", i); 4203 BREAK_TO_DEBUGGER(); 4204 goto create_fail; 4205 } 4206 4207 /* index for resource pool arrays for next valid pipe */ 4208 j++; 4209 } 4210 4211 /* PSR */ 4212 pool->base.psr = dmub_psr_create(ctx); 4213 if (pool->base.psr == NULL) { 4214 dm_error("DC: failed to create psr obj!\n"); 4215 BREAK_TO_DEBUGGER(); 4216 goto create_fail; 4217 } 4218 4219 /* MPCCs */ 4220 pool->base.mpc = dcn32_mpc_create(ctx, pool->base.res_cap->num_timing_generator, pool->base.res_cap->num_mpc_3dlut); 4221 if (pool->base.mpc == NULL) { 4222 BREAK_TO_DEBUGGER(); 4223 dm_error("DC: failed to create mpc!\n"); 4224 goto create_fail; 4225 } 4226 4227 /* DSCs */ 4228 for (i = 0; i < pool->base.res_cap->num_dsc; i++) { 4229 pool->base.dscs[i] = dcn32_dsc_create(ctx, i); 4230 if (pool->base.dscs[i] == NULL) { 4231 BREAK_TO_DEBUGGER(); 4232 dm_error("DC: failed to create display stream compressor %d!\n", i); 4233 goto create_fail; 4234 } 4235 } 4236 4237 /* DWB */ 4238 if (!dcn32_dwbc_create(ctx, &pool->base)) { 4239 BREAK_TO_DEBUGGER(); 4240 dm_error("DC: failed to create dwbc!\n"); 4241 goto create_fail; 4242 } 4243 4244 /* MMHUBBUB */ 4245 if (!dcn32_mmhubbub_create(ctx, &pool->base)) { 4246 BREAK_TO_DEBUGGER(); 4247 dm_error("DC: failed to create mcif_wb!\n"); 4248 goto create_fail; 4249 } 4250 4251 /* AUX and I2C */ 4252 for (i = 0; i < pool->base.res_cap->num_ddc; i++) { 4253 pool->base.engines[i] = dcn32_aux_engine_create(ctx, i); 4254 if (pool->base.engines[i] == NULL) { 4255 BREAK_TO_DEBUGGER(); 4256 dm_error( 4257 "DC:failed to create aux engine!!\n"); 4258 goto create_fail; 4259 } 4260 pool->base.hw_i2cs[i] = dcn32_i2c_hw_create(ctx, i); 4261 if (pool->base.hw_i2cs[i] == NULL) { 4262 BREAK_TO_DEBUGGER(); 4263 dm_error( 4264 "DC:failed to create hw i2c!!\n"); 4265 goto create_fail; 4266 } 4267 pool->base.sw_i2cs[i] = NULL; 4268 } 4269 4270 /* Audio, HWSeq, Stream Encoders including HPO and virtual, MPC 3D LUTs */ 4271 if (!resource_construct(num_virtual_links, dc, &pool->base, 4272 (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment) ? 4273 &res_create_funcs : &res_create_maximus_funcs))) 4274 goto create_fail; 4275 4276 /* HW Sequencer init functions and Plane caps */ 4277 dcn32_hw_sequencer_init_functions(dc); 4278 4279 dc->caps.max_planes = pool->base.pipe_count; 4280 4281 for (i = 0; i < dc->caps.max_planes; ++i) 4282 dc->caps.planes[i] = plane_cap; 4283 4284 dc->cap_funcs = cap_funcs; 4285 4286 if (dc->ctx->dc_bios->fw_info.oem_i2c_present) { 4287 ddc_init_data.ctx = dc->ctx; 4288 ddc_init_data.link = NULL; 4289 ddc_init_data.id.id = dc->ctx->dc_bios->fw_info.oem_i2c_obj_id; 4290 ddc_init_data.id.enum_id = 0; 4291 ddc_init_data.id.type = OBJECT_TYPE_GENERIC; 4292 pool->base.oem_device = dal_ddc_service_create(&ddc_init_data); 4293 } else { 4294 pool->base.oem_device = NULL; 4295 } 4296 4297 DC_FP_END(); 4298 4299 return true; 4300 4301 create_fail: 4302 4303 DC_FP_END(); 4304 4305 dcn32_resource_destruct(pool); 4306 4307 return false; 4308 } 4309 4310 struct resource_pool *dcn32_create_resource_pool( 4311 const struct dc_init_data *init_data, 4312 struct dc *dc) 4313 { 4314 struct dcn32_resource_pool *pool = 4315 kzalloc(sizeof(struct dcn32_resource_pool), GFP_KERNEL); 4316 4317 if (!pool) 4318 return NULL; 4319 4320 if (dcn32_resource_construct(init_data->num_virtual_links, dc, pool)) 4321 return &pool->base; 4322 4323 BREAK_TO_DEBUGGER(); 4324 kfree(pool); 4325 return NULL; 4326 } 4327