1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright 2021 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 "resource.h" 28 #include "clk_mgr.h" 29 #include "dchubbub.h" 30 #include "dcn20/dcn20_resource.h" 31 #include "dcn21/dcn21_resource.h" 32 #include "clk_mgr/dcn21/rn_clk_mgr.h" 33 #include "link_service.h" 34 #include "dcn20_fpu.h" 35 #include "dc_state_priv.h" 36 37 #define DC_LOGGER \ 38 dc->ctx->logger 39 #define DC_LOGGER_INIT(logger) 40 41 #ifndef MAX 42 #define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) 43 #endif 44 #ifndef MIN 45 #define MIN(X, Y) ((X) < (Y) ? (X) : (Y)) 46 #endif 47 48 /* Constant */ 49 #define LPDDR_MEM_RETRAIN_LATENCY 4.977 /* Number obtained from LPDDR4 Training Counter Requirement doc */ 50 51 /** 52 * DOC: DCN2x FPU manipulation Overview 53 * 54 * The DCN architecture relies on FPU operations, which require special 55 * compilation flags and the use of kernel_fpu_begin/end functions; ideally, we 56 * want to avoid spreading FPU access across multiple files. With this idea in 57 * mind, this file aims to centralize all DCN20 and DCN2.1 (DCN2x) functions 58 * that require FPU access in a single place. Code in this file follows the 59 * following code pattern: 60 * 61 * 1. Functions that use FPU operations should be isolated in static functions. 62 * 2. The FPU functions should have the noinline attribute to ensure anything 63 * that deals with FP register is contained within this call. 64 * 3. All function that needs to be accessed outside this file requires a 65 * public interface that not uses any FPU reference. 66 * 4. Developers **must not** use DC_FP_START/END in this file, but they need 67 * to ensure that the caller invokes it before access any function available 68 * in this file. For this reason, public functions in this file must invoke 69 * dc_assert_fp_enabled(); 70 * 71 * Let's expand a little bit more the idea in the code pattern. To fully 72 * isolate FPU operations in a single place, we must avoid situations where 73 * compilers spill FP values to registers due to FP enable in a specific C 74 * file. Note that even if we isolate all FPU functions in a single file and 75 * call its interface from other files, the compiler might enable the use of 76 * FPU before we call DC_FP_START. Nevertheless, it is the programmer's 77 * responsibility to invoke DC_FP_START/END in the correct place. To highlight 78 * situations where developers forgot to use the FP protection before calling 79 * the DC FPU interface functions, we introduce a helper that checks if the 80 * function is invoked under FP protection. If not, it will trigger a kernel 81 * warning. 82 */ 83 84 struct _vcs_dpi_ip_params_st dcn2_0_ip = { 85 .odm_capable = 1, 86 .gpuvm_enable = 0, 87 .hostvm_enable = 0, 88 .gpuvm_max_page_table_levels = 4, 89 .hostvm_max_page_table_levels = 4, 90 .hostvm_cached_page_table_levels = 0, 91 .pte_group_size_bytes = 2048, 92 .num_dsc = 6, 93 .rob_buffer_size_kbytes = 168, 94 .det_buffer_size_kbytes = 164, 95 .dpte_buffer_size_in_pte_reqs_luma = 84, 96 .pde_proc_buffer_size_64k_reqs = 48, 97 .dpp_output_buffer_pixels = 2560, 98 .opp_output_buffer_lines = 1, 99 .pixel_chunk_size_kbytes = 8, 100 .pte_chunk_size_kbytes = 2, 101 .meta_chunk_size_kbytes = 2, 102 .writeback_chunk_size_kbytes = 2, 103 .line_buffer_size_bits = 789504, 104 .is_line_buffer_bpp_fixed = 0, 105 .line_buffer_fixed_bpp = 0, 106 .dcc_supported = true, 107 .max_line_buffer_lines = 12, 108 .writeback_luma_buffer_size_kbytes = 12, 109 .writeback_chroma_buffer_size_kbytes = 8, 110 .writeback_chroma_line_buffer_width_pixels = 4, 111 .writeback_max_hscl_ratio = 1, 112 .writeback_max_vscl_ratio = 1, 113 .writeback_min_hscl_ratio = 1, 114 .writeback_min_vscl_ratio = 1, 115 .writeback_max_hscl_taps = 12, 116 .writeback_max_vscl_taps = 12, 117 .writeback_line_buffer_luma_buffer_size = 0, 118 .writeback_line_buffer_chroma_buffer_size = 14643, 119 .cursor_buffer_size = 8, 120 .cursor_chunk_size = 2, 121 .max_num_otg = 6, 122 .max_num_dpp = 6, 123 .max_num_wb = 1, 124 .max_dchub_pscl_bw_pix_per_clk = 4, 125 .max_pscl_lb_bw_pix_per_clk = 2, 126 .max_lb_vscl_bw_pix_per_clk = 4, 127 .max_vscl_hscl_bw_pix_per_clk = 4, 128 .max_hscl_ratio = 8, 129 .max_vscl_ratio = 8, 130 .hscl_mults = 4, 131 .vscl_mults = 4, 132 .max_hscl_taps = 8, 133 .max_vscl_taps = 8, 134 .dispclk_ramp_margin_percent = 1, 135 .underscan_factor = 1.10, 136 .min_vblank_lines = 32, // 137 .dppclk_delay_subtotal = 77, // 138 .dppclk_delay_scl_lb_only = 16, 139 .dppclk_delay_scl = 50, 140 .dppclk_delay_cnvc_formatter = 8, 141 .dppclk_delay_cnvc_cursor = 6, 142 .dispclk_delay_subtotal = 87, // 143 .dcfclk_cstate_latency = 10, // SRExitTime 144 .max_inter_dcn_tile_repeaters = 8, 145 .xfc_supported = true, 146 .xfc_fill_bw_overhead_percent = 10.0, 147 .xfc_fill_constant_bytes = 0, 148 .number_of_cursors = 1, 149 }; 150 151 struct _vcs_dpi_ip_params_st dcn2_0_nv14_ip = { 152 .odm_capable = 1, 153 .gpuvm_enable = 0, 154 .hostvm_enable = 0, 155 .gpuvm_max_page_table_levels = 4, 156 .hostvm_max_page_table_levels = 4, 157 .hostvm_cached_page_table_levels = 0, 158 .num_dsc = 5, 159 .rob_buffer_size_kbytes = 168, 160 .det_buffer_size_kbytes = 164, 161 .dpte_buffer_size_in_pte_reqs_luma = 84, 162 .dpte_buffer_size_in_pte_reqs_chroma = 42,//todo 163 .dpp_output_buffer_pixels = 2560, 164 .opp_output_buffer_lines = 1, 165 .pixel_chunk_size_kbytes = 8, 166 .pte_enable = 1, 167 .max_page_table_levels = 4, 168 .pte_chunk_size_kbytes = 2, 169 .meta_chunk_size_kbytes = 2, 170 .writeback_chunk_size_kbytes = 2, 171 .line_buffer_size_bits = 789504, 172 .is_line_buffer_bpp_fixed = 0, 173 .line_buffer_fixed_bpp = 0, 174 .dcc_supported = true, 175 .max_line_buffer_lines = 12, 176 .writeback_luma_buffer_size_kbytes = 12, 177 .writeback_chroma_buffer_size_kbytes = 8, 178 .writeback_chroma_line_buffer_width_pixels = 4, 179 .writeback_max_hscl_ratio = 1, 180 .writeback_max_vscl_ratio = 1, 181 .writeback_min_hscl_ratio = 1, 182 .writeback_min_vscl_ratio = 1, 183 .writeback_max_hscl_taps = 12, 184 .writeback_max_vscl_taps = 12, 185 .writeback_line_buffer_luma_buffer_size = 0, 186 .writeback_line_buffer_chroma_buffer_size = 14643, 187 .cursor_buffer_size = 8, 188 .cursor_chunk_size = 2, 189 .max_num_otg = 5, 190 .max_num_dpp = 5, 191 .max_num_wb = 1, 192 .max_dchub_pscl_bw_pix_per_clk = 4, 193 .max_pscl_lb_bw_pix_per_clk = 2, 194 .max_lb_vscl_bw_pix_per_clk = 4, 195 .max_vscl_hscl_bw_pix_per_clk = 4, 196 .max_hscl_ratio = 8, 197 .max_vscl_ratio = 8, 198 .hscl_mults = 4, 199 .vscl_mults = 4, 200 .max_hscl_taps = 8, 201 .max_vscl_taps = 8, 202 .dispclk_ramp_margin_percent = 1, 203 .underscan_factor = 1.10, 204 .min_vblank_lines = 32, // 205 .dppclk_delay_subtotal = 77, // 206 .dppclk_delay_scl_lb_only = 16, 207 .dppclk_delay_scl = 50, 208 .dppclk_delay_cnvc_formatter = 8, 209 .dppclk_delay_cnvc_cursor = 6, 210 .dispclk_delay_subtotal = 87, // 211 .dcfclk_cstate_latency = 10, // SRExitTime 212 .max_inter_dcn_tile_repeaters = 8, 213 .xfc_supported = true, 214 .xfc_fill_bw_overhead_percent = 10.0, 215 .xfc_fill_constant_bytes = 0, 216 .ptoi_supported = 0, 217 .number_of_cursors = 1, 218 }; 219 220 struct _vcs_dpi_soc_bounding_box_st dcn2_0_soc = { 221 /* Defaults that get patched on driver load from firmware. */ 222 .clock_limits = { 223 { 224 .state = 0, 225 .dcfclk_mhz = 560.0, 226 .fabricclk_mhz = 560.0, 227 .dispclk_mhz = 513.0, 228 .dppclk_mhz = 513.0, 229 .phyclk_mhz = 540.0, 230 .socclk_mhz = 560.0, 231 .dscclk_mhz = 171.0, 232 .dram_speed_mts = 8960.0, 233 }, 234 { 235 .state = 1, 236 .dcfclk_mhz = 694.0, 237 .fabricclk_mhz = 694.0, 238 .dispclk_mhz = 642.0, 239 .dppclk_mhz = 642.0, 240 .phyclk_mhz = 600.0, 241 .socclk_mhz = 694.0, 242 .dscclk_mhz = 214.0, 243 .dram_speed_mts = 11104.0, 244 }, 245 { 246 .state = 2, 247 .dcfclk_mhz = 875.0, 248 .fabricclk_mhz = 875.0, 249 .dispclk_mhz = 734.0, 250 .dppclk_mhz = 734.0, 251 .phyclk_mhz = 810.0, 252 .socclk_mhz = 875.0, 253 .dscclk_mhz = 245.0, 254 .dram_speed_mts = 14000.0, 255 }, 256 { 257 .state = 3, 258 .dcfclk_mhz = 1000.0, 259 .fabricclk_mhz = 1000.0, 260 .dispclk_mhz = 1100.0, 261 .dppclk_mhz = 1100.0, 262 .phyclk_mhz = 810.0, 263 .socclk_mhz = 1000.0, 264 .dscclk_mhz = 367.0, 265 .dram_speed_mts = 16000.0, 266 }, 267 { 268 .state = 4, 269 .dcfclk_mhz = 1200.0, 270 .fabricclk_mhz = 1200.0, 271 .dispclk_mhz = 1284.0, 272 .dppclk_mhz = 1284.0, 273 .phyclk_mhz = 810.0, 274 .socclk_mhz = 1200.0, 275 .dscclk_mhz = 428.0, 276 .dram_speed_mts = 16000.0, 277 }, 278 /*Extra state, no dispclk ramping*/ 279 { 280 .state = 5, 281 .dcfclk_mhz = 1200.0, 282 .fabricclk_mhz = 1200.0, 283 .dispclk_mhz = 1284.0, 284 .dppclk_mhz = 1284.0, 285 .phyclk_mhz = 810.0, 286 .socclk_mhz = 1200.0, 287 .dscclk_mhz = 428.0, 288 .dram_speed_mts = 16000.0, 289 }, 290 }, 291 .num_states = 5, 292 .sr_exit_time_us = 8.6, 293 .sr_enter_plus_exit_time_us = 10.9, 294 .urgent_latency_us = 4.0, 295 .urgent_latency_pixel_data_only_us = 4.0, 296 .urgent_latency_pixel_mixed_with_vm_data_us = 4.0, 297 .urgent_latency_vm_data_only_us = 4.0, 298 .urgent_out_of_order_return_per_channel_pixel_only_bytes = 4096, 299 .urgent_out_of_order_return_per_channel_pixel_and_vm_bytes = 4096, 300 .urgent_out_of_order_return_per_channel_vm_only_bytes = 4096, 301 .pct_ideal_dram_sdp_bw_after_urgent_pixel_only = 40.0, 302 .pct_ideal_dram_sdp_bw_after_urgent_pixel_and_vm = 40.0, 303 .pct_ideal_dram_sdp_bw_after_urgent_vm_only = 40.0, 304 .max_avg_sdp_bw_use_normal_percent = 40.0, 305 .max_avg_dram_bw_use_normal_percent = 40.0, 306 .writeback_latency_us = 12.0, 307 .ideal_dram_bw_after_urgent_percent = 40.0, 308 .max_request_size_bytes = 256, 309 .dram_channel_width_bytes = 2, 310 .fabric_datapath_to_dcn_data_return_bytes = 64, 311 .dcn_downspread_percent = 0.5, 312 .downspread_percent = 0.38, 313 .dram_page_open_time_ns = 50.0, 314 .dram_rw_turnaround_time_ns = 17.5, 315 .dram_return_buffer_per_channel_bytes = 8192, 316 .round_trip_ping_latency_dcfclk_cycles = 131, 317 .urgent_out_of_order_return_per_channel_bytes = 256, 318 .channel_interleave_bytes = 256, 319 .num_banks = 8, 320 .num_chans = 16, 321 .vmm_page_size_bytes = 4096, 322 .dram_clock_change_latency_us = 404.0, 323 .dummy_pstate_latency_us = 5.0, 324 .writeback_dram_clock_change_latency_us = 23.0, 325 .return_bus_width_bytes = 64, 326 .dispclk_dppclk_vco_speed_mhz = 3850, 327 .xfc_bus_transport_time_us = 20, 328 .xfc_xbuf_latency_tolerance_us = 4, 329 .use_urgent_burst_bw = 0 330 }; 331 332 struct _vcs_dpi_soc_bounding_box_st dcn2_0_nv14_soc = { 333 .clock_limits = { 334 { 335 .state = 0, 336 .dcfclk_mhz = 560.0, 337 .fabricclk_mhz = 560.0, 338 .dispclk_mhz = 513.0, 339 .dppclk_mhz = 513.0, 340 .phyclk_mhz = 540.0, 341 .socclk_mhz = 560.0, 342 .dscclk_mhz = 171.0, 343 .dram_speed_mts = 8960.0, 344 }, 345 { 346 .state = 1, 347 .dcfclk_mhz = 694.0, 348 .fabricclk_mhz = 694.0, 349 .dispclk_mhz = 642.0, 350 .dppclk_mhz = 642.0, 351 .phyclk_mhz = 600.0, 352 .socclk_mhz = 694.0, 353 .dscclk_mhz = 214.0, 354 .dram_speed_mts = 11104.0, 355 }, 356 { 357 .state = 2, 358 .dcfclk_mhz = 875.0, 359 .fabricclk_mhz = 875.0, 360 .dispclk_mhz = 734.0, 361 .dppclk_mhz = 734.0, 362 .phyclk_mhz = 810.0, 363 .socclk_mhz = 875.0, 364 .dscclk_mhz = 245.0, 365 .dram_speed_mts = 14000.0, 366 }, 367 { 368 .state = 3, 369 .dcfclk_mhz = 1000.0, 370 .fabricclk_mhz = 1000.0, 371 .dispclk_mhz = 1100.0, 372 .dppclk_mhz = 1100.0, 373 .phyclk_mhz = 810.0, 374 .socclk_mhz = 1000.0, 375 .dscclk_mhz = 367.0, 376 .dram_speed_mts = 16000.0, 377 }, 378 { 379 .state = 4, 380 .dcfclk_mhz = 1200.0, 381 .fabricclk_mhz = 1200.0, 382 .dispclk_mhz = 1284.0, 383 .dppclk_mhz = 1284.0, 384 .phyclk_mhz = 810.0, 385 .socclk_mhz = 1200.0, 386 .dscclk_mhz = 428.0, 387 .dram_speed_mts = 16000.0, 388 }, 389 /*Extra state, no dispclk ramping*/ 390 { 391 .state = 5, 392 .dcfclk_mhz = 1200.0, 393 .fabricclk_mhz = 1200.0, 394 .dispclk_mhz = 1284.0, 395 .dppclk_mhz = 1284.0, 396 .phyclk_mhz = 810.0, 397 .socclk_mhz = 1200.0, 398 .dscclk_mhz = 428.0, 399 .dram_speed_mts = 16000.0, 400 }, 401 }, 402 .num_states = 5, 403 .sr_exit_time_us = 11.6, 404 .sr_enter_plus_exit_time_us = 13.9, 405 .urgent_latency_us = 4.0, 406 .urgent_latency_pixel_data_only_us = 4.0, 407 .urgent_latency_pixel_mixed_with_vm_data_us = 4.0, 408 .urgent_latency_vm_data_only_us = 4.0, 409 .urgent_out_of_order_return_per_channel_pixel_only_bytes = 4096, 410 .urgent_out_of_order_return_per_channel_pixel_and_vm_bytes = 4096, 411 .urgent_out_of_order_return_per_channel_vm_only_bytes = 4096, 412 .pct_ideal_dram_sdp_bw_after_urgent_pixel_only = 40.0, 413 .pct_ideal_dram_sdp_bw_after_urgent_pixel_and_vm = 40.0, 414 .pct_ideal_dram_sdp_bw_after_urgent_vm_only = 40.0, 415 .max_avg_sdp_bw_use_normal_percent = 40.0, 416 .max_avg_dram_bw_use_normal_percent = 40.0, 417 .writeback_latency_us = 12.0, 418 .ideal_dram_bw_after_urgent_percent = 40.0, 419 .max_request_size_bytes = 256, 420 .dram_channel_width_bytes = 2, 421 .fabric_datapath_to_dcn_data_return_bytes = 64, 422 .dcn_downspread_percent = 0.5, 423 .downspread_percent = 0.38, 424 .dram_page_open_time_ns = 50.0, 425 .dram_rw_turnaround_time_ns = 17.5, 426 .dram_return_buffer_per_channel_bytes = 8192, 427 .round_trip_ping_latency_dcfclk_cycles = 131, 428 .urgent_out_of_order_return_per_channel_bytes = 256, 429 .channel_interleave_bytes = 256, 430 .num_banks = 8, 431 .num_chans = 8, 432 .vmm_page_size_bytes = 4096, 433 .dram_clock_change_latency_us = 404.0, 434 .dummy_pstate_latency_us = 5.0, 435 .writeback_dram_clock_change_latency_us = 23.0, 436 .return_bus_width_bytes = 64, 437 .dispclk_dppclk_vco_speed_mhz = 3850, 438 .xfc_bus_transport_time_us = 20, 439 .xfc_xbuf_latency_tolerance_us = 4, 440 .use_urgent_burst_bw = 0 441 }; 442 443 struct _vcs_dpi_soc_bounding_box_st dcn2_0_nv12_soc = { 444 .clock_limits = { 445 { 446 .state = 0, 447 .dcfclk_mhz = 560.0, 448 .fabricclk_mhz = 560.0, 449 .dispclk_mhz = 513.0, 450 .dppclk_mhz = 513.0, 451 .phyclk_mhz = 540.0, 452 .socclk_mhz = 560.0, 453 .dscclk_mhz = 171.0, 454 .dram_speed_mts = 1069.0, 455 }, 456 { 457 .state = 1, 458 .dcfclk_mhz = 694.0, 459 .fabricclk_mhz = 694.0, 460 .dispclk_mhz = 642.0, 461 .dppclk_mhz = 642.0, 462 .phyclk_mhz = 600.0, 463 .socclk_mhz = 694.0, 464 .dscclk_mhz = 214.0, 465 .dram_speed_mts = 1324.0, 466 }, 467 { 468 .state = 2, 469 .dcfclk_mhz = 875.0, 470 .fabricclk_mhz = 875.0, 471 .dispclk_mhz = 734.0, 472 .dppclk_mhz = 734.0, 473 .phyclk_mhz = 810.0, 474 .socclk_mhz = 875.0, 475 .dscclk_mhz = 245.0, 476 .dram_speed_mts = 1670.0, 477 }, 478 { 479 .state = 3, 480 .dcfclk_mhz = 1000.0, 481 .fabricclk_mhz = 1000.0, 482 .dispclk_mhz = 1100.0, 483 .dppclk_mhz = 1100.0, 484 .phyclk_mhz = 810.0, 485 .socclk_mhz = 1000.0, 486 .dscclk_mhz = 367.0, 487 .dram_speed_mts = 2000.0, 488 }, 489 { 490 .state = 4, 491 .dcfclk_mhz = 1200.0, 492 .fabricclk_mhz = 1200.0, 493 .dispclk_mhz = 1284.0, 494 .dppclk_mhz = 1284.0, 495 .phyclk_mhz = 810.0, 496 .socclk_mhz = 1200.0, 497 .dscclk_mhz = 428.0, 498 .dram_speed_mts = 2000.0, 499 }, 500 { 501 .state = 5, 502 .dcfclk_mhz = 1200.0, 503 .fabricclk_mhz = 1200.0, 504 .dispclk_mhz = 1284.0, 505 .dppclk_mhz = 1284.0, 506 .phyclk_mhz = 810.0, 507 .socclk_mhz = 1200.0, 508 .dscclk_mhz = 428.0, 509 .dram_speed_mts = 2000.0, 510 }, 511 }, 512 513 .num_states = 5, 514 .sr_exit_time_us = 1.9, 515 .sr_enter_plus_exit_time_us = 4.4, 516 .urgent_latency_us = 3.0, 517 .urgent_latency_pixel_data_only_us = 4.0, 518 .urgent_latency_pixel_mixed_with_vm_data_us = 4.0, 519 .urgent_latency_vm_data_only_us = 4.0, 520 .urgent_out_of_order_return_per_channel_pixel_only_bytes = 4096, 521 .urgent_out_of_order_return_per_channel_pixel_and_vm_bytes = 4096, 522 .urgent_out_of_order_return_per_channel_vm_only_bytes = 4096, 523 .pct_ideal_dram_sdp_bw_after_urgent_pixel_only = 40.0, 524 .pct_ideal_dram_sdp_bw_after_urgent_pixel_and_vm = 40.0, 525 .pct_ideal_dram_sdp_bw_after_urgent_vm_only = 40.0, 526 .max_avg_sdp_bw_use_normal_percent = 40.0, 527 .max_avg_dram_bw_use_normal_percent = 40.0, 528 .writeback_latency_us = 12.0, 529 .ideal_dram_bw_after_urgent_percent = 40.0, 530 .max_request_size_bytes = 256, 531 .dram_channel_width_bytes = 16, 532 .fabric_datapath_to_dcn_data_return_bytes = 64, 533 .dcn_downspread_percent = 0.5, 534 .downspread_percent = 0.5, 535 .dram_page_open_time_ns = 50.0, 536 .dram_rw_turnaround_time_ns = 17.5, 537 .dram_return_buffer_per_channel_bytes = 8192, 538 .round_trip_ping_latency_dcfclk_cycles = 131, 539 .urgent_out_of_order_return_per_channel_bytes = 4096, 540 .channel_interleave_bytes = 256, 541 .num_banks = 8, 542 .num_chans = 16, 543 .vmm_page_size_bytes = 4096, 544 .dram_clock_change_latency_us = 45.0, 545 .writeback_dram_clock_change_latency_us = 23.0, 546 .return_bus_width_bytes = 64, 547 .dispclk_dppclk_vco_speed_mhz = 3850, 548 .xfc_bus_transport_time_us = 20, 549 .xfc_xbuf_latency_tolerance_us = 50, 550 .use_urgent_burst_bw = 0, 551 }; 552 553 struct _vcs_dpi_ip_params_st dcn2_1_ip = { 554 .odm_capable = 1, 555 .gpuvm_enable = 1, 556 .hostvm_enable = 1, 557 .gpuvm_max_page_table_levels = 1, 558 .hostvm_max_page_table_levels = 4, 559 .hostvm_cached_page_table_levels = 2, 560 .num_dsc = 3, 561 .rob_buffer_size_kbytes = 168, 562 .det_buffer_size_kbytes = 164, 563 .dpte_buffer_size_in_pte_reqs_luma = 44, 564 .dpte_buffer_size_in_pte_reqs_chroma = 42,//todo 565 .dpp_output_buffer_pixels = 2560, 566 .opp_output_buffer_lines = 1, 567 .pixel_chunk_size_kbytes = 8, 568 .pte_enable = 1, 569 .max_page_table_levels = 4, 570 .pte_chunk_size_kbytes = 2, 571 .meta_chunk_size_kbytes = 2, 572 .min_meta_chunk_size_bytes = 256, 573 .writeback_chunk_size_kbytes = 2, 574 .line_buffer_size_bits = 789504, 575 .is_line_buffer_bpp_fixed = 0, 576 .line_buffer_fixed_bpp = 0, 577 .dcc_supported = true, 578 .max_line_buffer_lines = 12, 579 .writeback_luma_buffer_size_kbytes = 12, 580 .writeback_chroma_buffer_size_kbytes = 8, 581 .writeback_chroma_line_buffer_width_pixels = 4, 582 .writeback_max_hscl_ratio = 1, 583 .writeback_max_vscl_ratio = 1, 584 .writeback_min_hscl_ratio = 1, 585 .writeback_min_vscl_ratio = 1, 586 .writeback_max_hscl_taps = 12, 587 .writeback_max_vscl_taps = 12, 588 .writeback_line_buffer_luma_buffer_size = 0, 589 .writeback_line_buffer_chroma_buffer_size = 14643, 590 .cursor_buffer_size = 8, 591 .cursor_chunk_size = 2, 592 .max_num_otg = 4, 593 .max_num_dpp = 4, 594 .max_num_wb = 1, 595 .max_dchub_pscl_bw_pix_per_clk = 4, 596 .max_pscl_lb_bw_pix_per_clk = 2, 597 .max_lb_vscl_bw_pix_per_clk = 4, 598 .max_vscl_hscl_bw_pix_per_clk = 4, 599 .max_hscl_ratio = 4, 600 .max_vscl_ratio = 4, 601 .hscl_mults = 4, 602 .vscl_mults = 4, 603 .max_hscl_taps = 8, 604 .max_vscl_taps = 8, 605 .dispclk_ramp_margin_percent = 1, 606 .underscan_factor = 1.10, 607 .min_vblank_lines = 32, // 608 .dppclk_delay_subtotal = 77, // 609 .dppclk_delay_scl_lb_only = 16, 610 .dppclk_delay_scl = 50, 611 .dppclk_delay_cnvc_formatter = 8, 612 .dppclk_delay_cnvc_cursor = 6, 613 .dispclk_delay_subtotal = 87, // 614 .dcfclk_cstate_latency = 10, // SRExitTime 615 .max_inter_dcn_tile_repeaters = 8, 616 617 .xfc_supported = false, 618 .xfc_fill_bw_overhead_percent = 10.0, 619 .xfc_fill_constant_bytes = 0, 620 .ptoi_supported = 0, 621 .number_of_cursors = 1, 622 }; 623 624 struct _vcs_dpi_soc_bounding_box_st dcn2_1_soc = { 625 .clock_limits = { 626 { 627 .state = 0, 628 .dcfclk_mhz = 400.0, 629 .fabricclk_mhz = 400.0, 630 .dispclk_mhz = 600.0, 631 .dppclk_mhz = 400.00, 632 .phyclk_mhz = 600.0, 633 .socclk_mhz = 278.0, 634 .dscclk_mhz = 205.67, 635 .dram_speed_mts = 1600.0, 636 }, 637 { 638 .state = 1, 639 .dcfclk_mhz = 464.52, 640 .fabricclk_mhz = 800.0, 641 .dispclk_mhz = 654.55, 642 .dppclk_mhz = 626.09, 643 .phyclk_mhz = 600.0, 644 .socclk_mhz = 278.0, 645 .dscclk_mhz = 205.67, 646 .dram_speed_mts = 1600.0, 647 }, 648 { 649 .state = 2, 650 .dcfclk_mhz = 514.29, 651 .fabricclk_mhz = 933.0, 652 .dispclk_mhz = 757.89, 653 .dppclk_mhz = 685.71, 654 .phyclk_mhz = 600.0, 655 .socclk_mhz = 278.0, 656 .dscclk_mhz = 287.67, 657 .dram_speed_mts = 1866.0, 658 }, 659 { 660 .state = 3, 661 .dcfclk_mhz = 576.00, 662 .fabricclk_mhz = 1067.0, 663 .dispclk_mhz = 847.06, 664 .dppclk_mhz = 757.89, 665 .phyclk_mhz = 600.0, 666 .socclk_mhz = 715.0, 667 .dscclk_mhz = 318.334, 668 .dram_speed_mts = 2134.0, 669 }, 670 { 671 .state = 4, 672 .dcfclk_mhz = 626.09, 673 .fabricclk_mhz = 1200.0, 674 .dispclk_mhz = 900.00, 675 .dppclk_mhz = 847.06, 676 .phyclk_mhz = 810.0, 677 .socclk_mhz = 953.0, 678 .dscclk_mhz = 300.0, 679 .dram_speed_mts = 2400.0, 680 }, 681 { 682 .state = 5, 683 .dcfclk_mhz = 685.71, 684 .fabricclk_mhz = 1333.0, 685 .dispclk_mhz = 1028.57, 686 .dppclk_mhz = 960.00, 687 .phyclk_mhz = 810.0, 688 .socclk_mhz = 278.0, 689 .dscclk_mhz = 342.86, 690 .dram_speed_mts = 2666.0, 691 }, 692 { 693 .state = 6, 694 .dcfclk_mhz = 757.89, 695 .fabricclk_mhz = 1467.0, 696 .dispclk_mhz = 1107.69, 697 .dppclk_mhz = 1028.57, 698 .phyclk_mhz = 810.0, 699 .socclk_mhz = 715.0, 700 .dscclk_mhz = 369.23, 701 .dram_speed_mts = 3200.0, 702 }, 703 { 704 .state = 7, 705 .dcfclk_mhz = 847.06, 706 .fabricclk_mhz = 1600.0, 707 .dispclk_mhz = 1395.0, 708 .dppclk_mhz = 1285.00, 709 .phyclk_mhz = 1325.0, 710 .socclk_mhz = 953.0, 711 .dscclk_mhz = 489.0, 712 .dram_speed_mts = 4266.0, 713 }, 714 /*Extra state, no dispclk ramping*/ 715 { 716 .state = 8, 717 .dcfclk_mhz = 847.06, 718 .fabricclk_mhz = 1600.0, 719 .dispclk_mhz = 1395.0, 720 .dppclk_mhz = 1285.0, 721 .phyclk_mhz = 1325.0, 722 .socclk_mhz = 953.0, 723 .dscclk_mhz = 489.0, 724 .dram_speed_mts = 4266.0, 725 }, 726 727 }, 728 729 .sr_exit_time_us = 12.5, 730 .sr_enter_plus_exit_time_us = 17.0, 731 .urgent_latency_us = 4.0, 732 .urgent_latency_pixel_data_only_us = 4.0, 733 .urgent_latency_pixel_mixed_with_vm_data_us = 4.0, 734 .urgent_latency_vm_data_only_us = 4.0, 735 .urgent_out_of_order_return_per_channel_pixel_only_bytes = 4096, 736 .urgent_out_of_order_return_per_channel_pixel_and_vm_bytes = 4096, 737 .urgent_out_of_order_return_per_channel_vm_only_bytes = 4096, 738 .pct_ideal_dram_sdp_bw_after_urgent_pixel_only = 80.0, 739 .pct_ideal_dram_sdp_bw_after_urgent_pixel_and_vm = 75.0, 740 .pct_ideal_dram_sdp_bw_after_urgent_vm_only = 40.0, 741 .max_avg_sdp_bw_use_normal_percent = 60.0, 742 .max_avg_dram_bw_use_normal_percent = 100.0, 743 .writeback_latency_us = 12.0, 744 .max_request_size_bytes = 256, 745 .dram_channel_width_bytes = 4, 746 .fabric_datapath_to_dcn_data_return_bytes = 32, 747 .dcn_downspread_percent = 0.5, 748 .downspread_percent = 0.38, 749 .dram_page_open_time_ns = 50.0, 750 .dram_rw_turnaround_time_ns = 17.5, 751 .dram_return_buffer_per_channel_bytes = 8192, 752 .round_trip_ping_latency_dcfclk_cycles = 128, 753 .urgent_out_of_order_return_per_channel_bytes = 4096, 754 .channel_interleave_bytes = 256, 755 .num_banks = 8, 756 .num_chans = 4, 757 .vmm_page_size_bytes = 4096, 758 .dram_clock_change_latency_us = 23.84, 759 .return_bus_width_bytes = 64, 760 .dispclk_dppclk_vco_speed_mhz = 3600, 761 .xfc_bus_transport_time_us = 4, 762 .xfc_xbuf_latency_tolerance_us = 4, 763 .use_urgent_burst_bw = 1, 764 .num_states = 8 765 }; 766 767 struct wm_table ddr4_wm_table_gs = { 768 .entries = { 769 { 770 .wm_inst = WM_A, 771 .wm_type = WM_TYPE_PSTATE_CHG, 772 .pstate_latency_us = 11.72, 773 .sr_exit_time_us = 7.09, 774 .sr_enter_plus_exit_time_us = 8.14, 775 .valid = true, 776 }, 777 { 778 .wm_inst = WM_B, 779 .wm_type = WM_TYPE_PSTATE_CHG, 780 .pstate_latency_us = 11.72, 781 .sr_exit_time_us = 10.12, 782 .sr_enter_plus_exit_time_us = 11.48, 783 .valid = true, 784 }, 785 { 786 .wm_inst = WM_C, 787 .wm_type = WM_TYPE_PSTATE_CHG, 788 .pstate_latency_us = 11.72, 789 .sr_exit_time_us = 10.12, 790 .sr_enter_plus_exit_time_us = 11.48, 791 .valid = true, 792 }, 793 { 794 .wm_inst = WM_D, 795 .wm_type = WM_TYPE_PSTATE_CHG, 796 .pstate_latency_us = 11.72, 797 .sr_exit_time_us = 10.12, 798 .sr_enter_plus_exit_time_us = 11.48, 799 .valid = true, 800 }, 801 } 802 }; 803 804 struct wm_table lpddr4_wm_table_gs = { 805 .entries = { 806 { 807 .wm_inst = WM_A, 808 .wm_type = WM_TYPE_PSTATE_CHG, 809 .pstate_latency_us = 11.65333, 810 .sr_exit_time_us = 5.32, 811 .sr_enter_plus_exit_time_us = 6.38, 812 .valid = true, 813 }, 814 { 815 .wm_inst = WM_B, 816 .wm_type = WM_TYPE_PSTATE_CHG, 817 .pstate_latency_us = 11.65333, 818 .sr_exit_time_us = 9.82, 819 .sr_enter_plus_exit_time_us = 11.196, 820 .valid = true, 821 }, 822 { 823 .wm_inst = WM_C, 824 .wm_type = WM_TYPE_PSTATE_CHG, 825 .pstate_latency_us = 11.65333, 826 .sr_exit_time_us = 9.89, 827 .sr_enter_plus_exit_time_us = 11.24, 828 .valid = true, 829 }, 830 { 831 .wm_inst = WM_D, 832 .wm_type = WM_TYPE_PSTATE_CHG, 833 .pstate_latency_us = 11.65333, 834 .sr_exit_time_us = 9.748, 835 .sr_enter_plus_exit_time_us = 11.102, 836 .valid = true, 837 }, 838 } 839 }; 840 841 struct wm_table lpddr4_wm_table_with_disabled_ppt = { 842 .entries = { 843 { 844 .wm_inst = WM_A, 845 .wm_type = WM_TYPE_PSTATE_CHG, 846 .pstate_latency_us = 11.65333, 847 .sr_exit_time_us = 8.32, 848 .sr_enter_plus_exit_time_us = 9.38, 849 .valid = true, 850 }, 851 { 852 .wm_inst = WM_B, 853 .wm_type = WM_TYPE_PSTATE_CHG, 854 .pstate_latency_us = 11.65333, 855 .sr_exit_time_us = 9.82, 856 .sr_enter_plus_exit_time_us = 11.196, 857 .valid = true, 858 }, 859 { 860 .wm_inst = WM_C, 861 .wm_type = WM_TYPE_PSTATE_CHG, 862 .pstate_latency_us = 11.65333, 863 .sr_exit_time_us = 9.89, 864 .sr_enter_plus_exit_time_us = 11.24, 865 .valid = true, 866 }, 867 { 868 .wm_inst = WM_D, 869 .wm_type = WM_TYPE_PSTATE_CHG, 870 .pstate_latency_us = 11.65333, 871 .sr_exit_time_us = 9.748, 872 .sr_enter_plus_exit_time_us = 11.102, 873 .valid = true, 874 }, 875 } 876 }; 877 878 struct wm_table ddr4_wm_table_rn = { 879 .entries = { 880 { 881 .wm_inst = WM_A, 882 .wm_type = WM_TYPE_PSTATE_CHG, 883 .pstate_latency_us = 11.72, 884 .sr_exit_time_us = 11.90, 885 .sr_enter_plus_exit_time_us = 12.80, 886 .valid = true, 887 }, 888 { 889 .wm_inst = WM_B, 890 .wm_type = WM_TYPE_PSTATE_CHG, 891 .pstate_latency_us = 11.72, 892 .sr_exit_time_us = 13.18, 893 .sr_enter_plus_exit_time_us = 14.30, 894 .valid = true, 895 }, 896 { 897 .wm_inst = WM_C, 898 .wm_type = WM_TYPE_PSTATE_CHG, 899 .pstate_latency_us = 11.72, 900 .sr_exit_time_us = 13.18, 901 .sr_enter_plus_exit_time_us = 14.30, 902 .valid = true, 903 }, 904 { 905 .wm_inst = WM_D, 906 .wm_type = WM_TYPE_PSTATE_CHG, 907 .pstate_latency_us = 11.72, 908 .sr_exit_time_us = 13.18, 909 .sr_enter_plus_exit_time_us = 14.30, 910 .valid = true, 911 }, 912 } 913 }; 914 915 struct wm_table ddr4_1R_wm_table_rn = { 916 .entries = { 917 { 918 .wm_inst = WM_A, 919 .wm_type = WM_TYPE_PSTATE_CHG, 920 .pstate_latency_us = 11.72, 921 .sr_exit_time_us = 13.90, 922 .sr_enter_plus_exit_time_us = 14.80, 923 .valid = true, 924 }, 925 { 926 .wm_inst = WM_B, 927 .wm_type = WM_TYPE_PSTATE_CHG, 928 .pstate_latency_us = 11.72, 929 .sr_exit_time_us = 13.90, 930 .sr_enter_plus_exit_time_us = 14.80, 931 .valid = true, 932 }, 933 { 934 .wm_inst = WM_C, 935 .wm_type = WM_TYPE_PSTATE_CHG, 936 .pstate_latency_us = 11.72, 937 .sr_exit_time_us = 13.90, 938 .sr_enter_plus_exit_time_us = 14.80, 939 .valid = true, 940 }, 941 { 942 .wm_inst = WM_D, 943 .wm_type = WM_TYPE_PSTATE_CHG, 944 .pstate_latency_us = 11.72, 945 .sr_exit_time_us = 13.90, 946 .sr_enter_plus_exit_time_us = 14.80, 947 .valid = true, 948 }, 949 } 950 }; 951 952 struct wm_table lpddr4_wm_table_rn = { 953 .entries = { 954 { 955 .wm_inst = WM_A, 956 .wm_type = WM_TYPE_PSTATE_CHG, 957 .pstate_latency_us = 11.65333, 958 .sr_exit_time_us = 7.32, 959 .sr_enter_plus_exit_time_us = 8.38, 960 .valid = true, 961 }, 962 { 963 .wm_inst = WM_B, 964 .wm_type = WM_TYPE_PSTATE_CHG, 965 .pstate_latency_us = 11.65333, 966 .sr_exit_time_us = 9.82, 967 .sr_enter_plus_exit_time_us = 11.196, 968 .valid = true, 969 }, 970 { 971 .wm_inst = WM_C, 972 .wm_type = WM_TYPE_PSTATE_CHG, 973 .pstate_latency_us = 11.65333, 974 .sr_exit_time_us = 9.89, 975 .sr_enter_plus_exit_time_us = 11.24, 976 .valid = true, 977 }, 978 { 979 .wm_inst = WM_D, 980 .wm_type = WM_TYPE_PSTATE_CHG, 981 .pstate_latency_us = 11.65333, 982 .sr_exit_time_us = 9.748, 983 .sr_enter_plus_exit_time_us = 11.102, 984 .valid = true, 985 }, 986 } 987 }; 988 989 void dcn20_populate_dml_writeback_from_context(struct dc *dc, 990 struct resource_context *res_ctx, 991 display_e2e_pipe_params_st *pipes) 992 { 993 unsigned int i; 994 int pipe_cnt; 995 996 dc_assert_fp_enabled(); 997 998 for (i = 0, pipe_cnt = 0; i < dc->res_pool->pipe_count; i++) { 999 struct dc_writeback_info *wb_info = &res_ctx->pipe_ctx[i].stream->writeback_info[0]; 1000 1001 if (!res_ctx->pipe_ctx[i].stream) 1002 continue; 1003 1004 /* Set writeback information */ 1005 pipes[pipe_cnt].dout.wb_enable = (wb_info->wb_enabled == true) ? 1 : 0; 1006 pipes[pipe_cnt].dout.num_active_wb++; 1007 pipes[pipe_cnt].dout.wb.wb_src_height = wb_info->dwb_params.cnv_params.crop_height; 1008 pipes[pipe_cnt].dout.wb.wb_src_width = wb_info->dwb_params.cnv_params.crop_width; 1009 pipes[pipe_cnt].dout.wb.wb_dst_width = wb_info->dwb_params.dest_width; 1010 pipes[pipe_cnt].dout.wb.wb_dst_height = wb_info->dwb_params.dest_height; 1011 pipes[pipe_cnt].dout.wb.wb_htaps_luma = 1; 1012 pipes[pipe_cnt].dout.wb.wb_vtaps_luma = 1; 1013 pipes[pipe_cnt].dout.wb.wb_htaps_chroma = wb_info->dwb_params.scaler_taps.h_taps_c; 1014 pipes[pipe_cnt].dout.wb.wb_vtaps_chroma = wb_info->dwb_params.scaler_taps.v_taps_c; 1015 pipes[pipe_cnt].dout.wb.wb_hratio = 1.0; 1016 pipes[pipe_cnt].dout.wb.wb_vratio = 1.0; 1017 if (wb_info->dwb_params.out_format == dwb_scaler_mode_yuv420) { 1018 if (wb_info->dwb_params.output_depth == DWB_OUTPUT_PIXEL_DEPTH_8BPC) 1019 pipes[pipe_cnt].dout.wb.wb_pixel_format = dm_420_8; 1020 else 1021 pipes[pipe_cnt].dout.wb.wb_pixel_format = dm_420_10; 1022 } else { 1023 pipes[pipe_cnt].dout.wb.wb_pixel_format = dm_444_32; 1024 } 1025 1026 pipe_cnt++; 1027 } 1028 } 1029 1030 void dcn20_fpu_set_wb_arb_params(struct mcif_arb_params *wb_arb_params, 1031 struct dc_state *context, 1032 display_e2e_pipe_params_st *pipes, 1033 int pipe_cnt, int i) 1034 { 1035 int k; 1036 1037 dc_assert_fp_enabled(); 1038 1039 for (k = 0; k < sizeof(wb_arb_params->cli_watermark)/sizeof(wb_arb_params->cli_watermark[0]); k++) { 1040 wb_arb_params->cli_watermark[k] = (unsigned int)(get_wm_writeback_urgent(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000.0); 1041 wb_arb_params->pstate_watermark[k] = (unsigned int)(get_wm_writeback_dram_clock_change(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000.0); 1042 } 1043 wb_arb_params->time_per_pixel = (unsigned int)(16.0 * 1000.0 / (context->res_ctx.pipe_ctx[i].stream->phy_pix_clk / 1000)); /* 4 bit fraction, ms */ 1044 } 1045 1046 static bool is_dtbclk_required(struct dc *dc, struct dc_state *context) 1047 { 1048 unsigned int i; 1049 for (i = 0; i < dc->res_pool->pipe_count; i++) { 1050 if (!context->res_ctx.pipe_ctx[i].stream) 1051 continue; 1052 if (dc_is_hdmi_frl_signal(context->res_ctx.pipe_ctx[i].stream->signal)) 1053 return true; 1054 if (dc->link_srv->dp_is_128b_132b_signal(&context->res_ctx.pipe_ctx[i])) 1055 return true; 1056 } 1057 return false; 1058 } 1059 1060 static enum dcn_zstate_support_state decide_zstate_support(struct dc *dc, struct dc_state *context) 1061 { 1062 int plane_count; 1063 unsigned int i; 1064 1065 plane_count = 0; 1066 for (i = 0; i < dc->res_pool->pipe_count; i++) { 1067 if (context->res_ctx.pipe_ctx[i].plane_state) 1068 plane_count++; 1069 } 1070 1071 /* 1072 * Z9 and Z10 allowed cases: 1073 * 1. 0 Planes enabled 1074 * 2. single eDP, on link 0, 1 plane and stutter period > 5ms 1075 * Z10 only cases: 1076 * 1. single eDP, on link 0, 1 plane and stutter period >= 5ms 1077 * Z8 cases: 1078 * 1. stutter period sufficient 1079 * Zstate not allowed cases: 1080 * 1. Everything else 1081 */ 1082 if (plane_count == 0) 1083 return DCN_ZSTATE_SUPPORT_ALLOW; 1084 else if (context->stream_count == 1 && context->streams[0]->signal == SIGNAL_TYPE_EDP) { 1085 struct dc_link *link = context->streams[0]->sink->link; 1086 struct dc_stream_status *stream_status = &context->stream_status[0]; 1087 int minmum_z8_residency = dc->debug.minimum_z8_residency_time > 0 ? dc->debug.minimum_z8_residency_time : 1000; 1088 bool allow_z8 = context->bw_ctx.dml.vba.StutterPeriod > (double)minmum_z8_residency; 1089 bool is_pwrseq0 = (link && link->link_index == 0); 1090 bool is_psr = (link && (link->psr_settings.psr_version == DC_PSR_VERSION_1 || 1091 link->psr_settings.psr_version == DC_PSR_VERSION_SU_1) && !link->panel_config.psr.disable_psr); 1092 bool is_replay = link && link->replay_settings.replay_feature_enabled; 1093 1094 /* Don't support multi-plane configurations */ 1095 if (stream_status->plane_count > 1) 1096 return DCN_ZSTATE_SUPPORT_DISALLOW; 1097 1098 if (is_pwrseq0 && context->bw_ctx.dml.vba.StutterPeriod > 5000.0) 1099 return DCN_ZSTATE_SUPPORT_ALLOW; 1100 else if (is_pwrseq0 && (is_psr || is_replay)) 1101 return DCN_ZSTATE_SUPPORT_ALLOW_Z8_Z10_ONLY; 1102 else 1103 return allow_z8 ? DCN_ZSTATE_SUPPORT_ALLOW_Z8_ONLY : DCN_ZSTATE_SUPPORT_DISALLOW; 1104 } else { 1105 return DCN_ZSTATE_SUPPORT_DISALLOW; 1106 } 1107 } 1108 1109 static void dcn20_adjust_freesync_v_startup( 1110 const struct dc_crtc_timing *dc_crtc_timing, unsigned int *vstartup_start) 1111 { 1112 struct dc_crtc_timing patched_crtc_timing; 1113 uint32_t asic_blank_end = 0; 1114 uint32_t asic_blank_start = 0; 1115 uint32_t newVstartup = 0; 1116 1117 patched_crtc_timing = *dc_crtc_timing; 1118 1119 if (patched_crtc_timing.flags.INTERLACE == 1) { 1120 if (patched_crtc_timing.v_front_porch < 2) 1121 patched_crtc_timing.v_front_porch = 2; 1122 } else { 1123 if (patched_crtc_timing.v_front_porch < 1) 1124 patched_crtc_timing.v_front_porch = 1; 1125 } 1126 1127 /* blank_start = frame end - front porch */ 1128 asic_blank_start = patched_crtc_timing.v_total - 1129 patched_crtc_timing.v_front_porch; 1130 1131 /* blank_end = blank_start - active */ 1132 asic_blank_end = asic_blank_start - 1133 patched_crtc_timing.v_border_bottom - 1134 patched_crtc_timing.v_addressable - 1135 patched_crtc_timing.v_border_top; 1136 1137 /* The newVStartUp is 1 line before vsync point */ 1138 newVstartup = asic_blank_end + 1; 1139 1140 *vstartup_start = (((int)newVstartup > *vstartup_start) ? (int)newVstartup : *vstartup_start); 1141 } 1142 1143 void dcn20_calculate_dlg_params(struct dc *dc, 1144 struct dc_state *context, 1145 display_e2e_pipe_params_st *pipes, 1146 int pipe_cnt, 1147 int vlevel) 1148 { 1149 int pipe_idx, active_hubp_count = 0; 1150 unsigned int i; 1151 1152 dc_assert_fp_enabled(); 1153 1154 /* Writeback MCIF_WB arbitration parameters */ 1155 dc->res_pool->funcs->set_mcif_arb_params(dc, context, pipes, pipe_cnt); 1156 1157 context->bw_ctx.bw.dcn.clk.dispclk_khz = (int)(context->bw_ctx.dml.vba.DISPCLK * 1000.0); 1158 context->bw_ctx.bw.dcn.clk.dcfclk_khz = (int)(context->bw_ctx.dml.vba.DCFCLK * 1000.0); 1159 context->bw_ctx.bw.dcn.clk.socclk_khz = (int)(context->bw_ctx.dml.vba.SOCCLK * 1000.0); 1160 context->bw_ctx.bw.dcn.clk.dramclk_khz = (int)(context->bw_ctx.dml.vba.DRAMSpeed * 1000.0 / 16.0); 1161 1162 if ((int)dc->debug.min_dram_clk_khz > context->bw_ctx.bw.dcn.clk.dramclk_khz) 1163 context->bw_ctx.bw.dcn.clk.dramclk_khz = dc->debug.min_dram_clk_khz; 1164 1165 context->bw_ctx.bw.dcn.clk.dcfclk_deep_sleep_khz = (int)(context->bw_ctx.dml.vba.DCFCLKDeepSleep * 1000.0); 1166 context->bw_ctx.bw.dcn.clk.fclk_khz = (int)(context->bw_ctx.dml.vba.FabricClock * 1000.0); 1167 context->bw_ctx.bw.dcn.clk.p_state_change_support = 1168 context->bw_ctx.dml.vba.DRAMClockChangeSupport[vlevel][context->bw_ctx.dml.vba.maxMpcComb] 1169 != dm_dram_clock_change_unsupported; 1170 1171 /* Pstate change might not be supported by hardware, but it might be 1172 * possible with firmware driven vertical blank stretching. 1173 */ 1174 context->bw_ctx.bw.dcn.clk.p_state_change_support |= context->bw_ctx.bw.dcn.clk.fw_based_mclk_switching; 1175 1176 context->bw_ctx.bw.dcn.clk.dppclk_khz = 0; 1177 1178 context->bw_ctx.bw.dcn.clk.dtbclk_en = is_dtbclk_required(dc, context); 1179 1180 if ((unsigned int)context->bw_ctx.bw.dcn.clk.dispclk_khz < dc->debug.min_disp_clk_khz) 1181 context->bw_ctx.bw.dcn.clk.dispclk_khz = (int)dc->debug.min_disp_clk_khz; 1182 1183 for (i = 0, pipe_idx = 0; i < dc->res_pool->pipe_count; i++) { 1184 if (!context->res_ctx.pipe_ctx[i].stream) 1185 continue; 1186 if (context->res_ctx.pipe_ctx[i].plane_state) 1187 active_hubp_count++; 1188 pipes[pipe_idx].pipe.dest.vstartup_start = (unsigned int)get_vstartup(&context->bw_ctx.dml, pipes, pipe_cnt, pipe_idx); 1189 pipes[pipe_idx].pipe.dest.vupdate_offset = (unsigned int)get_vupdate_offset(&context->bw_ctx.dml, pipes, pipe_cnt, pipe_idx); 1190 pipes[pipe_idx].pipe.dest.vupdate_width = (unsigned int)get_vupdate_width(&context->bw_ctx.dml, pipes, pipe_cnt, pipe_idx); 1191 pipes[pipe_idx].pipe.dest.vready_offset = (unsigned int)get_vready_offset(&context->bw_ctx.dml, pipes, pipe_cnt, pipe_idx); 1192 1193 if (dc_state_get_pipe_subvp_type(context, &context->res_ctx.pipe_ctx[i]) == SUBVP_PHANTOM) { 1194 // Phantom pipe requires that DET_SIZE = 0 and no unbounded requests 1195 context->res_ctx.pipe_ctx[i].det_buffer_size_kb = 0; 1196 context->res_ctx.pipe_ctx[i].unbounded_req = false; 1197 } else { 1198 context->res_ctx.pipe_ctx[i].det_buffer_size_kb = context->bw_ctx.dml.ip.det_buffer_size_kbytes; 1199 context->res_ctx.pipe_ctx[i].unbounded_req = pipes[pipe_idx].pipe.src.unbounded_req_mode; 1200 } 1201 1202 if (context->bw_ctx.bw.dcn.clk.dppclk_khz < pipes[pipe_idx].clks_cfg.dppclk_mhz * 1000) 1203 context->bw_ctx.bw.dcn.clk.dppclk_khz = (int)(pipes[pipe_idx].clks_cfg.dppclk_mhz * 1000.0); 1204 context->res_ctx.pipe_ctx[i].plane_res.bw.dppclk_khz = 1205 (int)(pipes[pipe_idx].clks_cfg.dppclk_mhz * 1000.0); 1206 context->res_ctx.pipe_ctx[i].pipe_dlg_param = pipes[pipe_idx].pipe.dest; 1207 if (dc->ctx->dce_version < DCN_VERSION_3_1 && 1208 context->res_ctx.pipe_ctx[i].stream->adaptive_sync_infopacket.valid) 1209 dcn20_adjust_freesync_v_startup( 1210 &context->res_ctx.pipe_ctx[i].stream->timing, 1211 &context->res_ctx.pipe_ctx[i].pipe_dlg_param.vstartup_start); 1212 1213 pipe_idx++; 1214 } 1215 /* If DCN isn't making memory requests we can allow pstate change */ 1216 if (!active_hubp_count) { 1217 context->bw_ctx.bw.dcn.clk.p_state_change_support = true; 1218 } 1219 /*save a original dppclock copy*/ 1220 context->bw_ctx.bw.dcn.clk.bw_dppclk_khz = context->bw_ctx.bw.dcn.clk.dppclk_khz; 1221 context->bw_ctx.bw.dcn.clk.bw_dispclk_khz = context->bw_ctx.bw.dcn.clk.dispclk_khz; 1222 context->bw_ctx.bw.dcn.clk.max_supported_dppclk_khz = (int)(context->bw_ctx.dml.soc.clock_limits[vlevel].dppclk_mhz * 1000.0); 1223 context->bw_ctx.bw.dcn.clk.max_supported_dispclk_khz = (int)(context->bw_ctx.dml.soc.clock_limits[vlevel].dispclk_mhz * 1000.0); 1224 1225 context->bw_ctx.bw.dcn.compbuf_size_kb = context->bw_ctx.dml.ip.config_return_buffer_size_in_kbytes 1226 - context->bw_ctx.dml.ip.det_buffer_size_kbytes * pipe_idx; 1227 1228 for (i = 0, pipe_idx = 0; i < dc->res_pool->pipe_count; i++) { 1229 bool cstate_en = context->bw_ctx.dml.vba.PrefetchMode[vlevel][context->bw_ctx.dml.vba.maxMpcComb] != 2; 1230 1231 if (!context->res_ctx.pipe_ctx[i].stream) 1232 continue; 1233 1234 /* cstate disabled on 201 */ 1235 if (dc->ctx->dce_version == DCN_VERSION_2_01) 1236 cstate_en = false; 1237 1238 context->bw_ctx.dml.funcs.rq_dlg_get_dlg_reg(&context->bw_ctx.dml, 1239 &context->res_ctx.pipe_ctx[i].dlg_regs, 1240 &context->res_ctx.pipe_ctx[i].ttu_regs, 1241 pipes, 1242 pipe_cnt, 1243 pipe_idx, 1244 cstate_en, 1245 context->bw_ctx.bw.dcn.clk.p_state_change_support, 1246 false, false, true); 1247 1248 context->bw_ctx.dml.funcs.rq_dlg_get_rq_reg(&context->bw_ctx.dml, 1249 &context->res_ctx.pipe_ctx[i].rq_regs, 1250 &pipes[pipe_idx].pipe); 1251 pipe_idx++; 1252 } 1253 context->bw_ctx.bw.dcn.clk.zstate_support = decide_zstate_support(dc, context); 1254 } 1255 1256 static void swizzle_to_dml_params( 1257 enum swizzle_mode_values swizzle, 1258 int *sw_mode) 1259 { 1260 switch (swizzle) { 1261 case DC_SW_LINEAR: 1262 *sw_mode = dm_sw_linear; 1263 break; 1264 case DC_SW_4KB_S: 1265 *sw_mode = dm_sw_4kb_s; 1266 break; 1267 case DC_SW_4KB_S_X: 1268 *sw_mode = dm_sw_4kb_s_x; 1269 break; 1270 case DC_SW_4KB_D: 1271 *sw_mode = dm_sw_4kb_d; 1272 break; 1273 case DC_SW_4KB_D_X: 1274 *sw_mode = dm_sw_4kb_d_x; 1275 break; 1276 case DC_SW_64KB_S: 1277 *sw_mode = dm_sw_64kb_s; 1278 break; 1279 case DC_SW_64KB_S_X: 1280 *sw_mode = dm_sw_64kb_s_x; 1281 break; 1282 case DC_SW_64KB_S_T: 1283 *sw_mode = dm_sw_64kb_s_t; 1284 break; 1285 case DC_SW_64KB_D: 1286 *sw_mode = dm_sw_64kb_d; 1287 break; 1288 case DC_SW_64KB_D_X: 1289 *sw_mode = dm_sw_64kb_d_x; 1290 break; 1291 case DC_SW_64KB_D_T: 1292 *sw_mode = dm_sw_64kb_d_t; 1293 break; 1294 case DC_SW_64KB_R_X: 1295 *sw_mode = dm_sw_64kb_r_x; 1296 break; 1297 case DC_SW_VAR_S: 1298 *sw_mode = dm_sw_var_s; 1299 break; 1300 case DC_SW_VAR_S_X: 1301 *sw_mode = dm_sw_var_s_x; 1302 break; 1303 case DC_SW_VAR_D: 1304 *sw_mode = dm_sw_var_d; 1305 break; 1306 case DC_SW_VAR_D_X: 1307 *sw_mode = dm_sw_var_d_x; 1308 break; 1309 case DC_SW_VAR_R_X: 1310 *sw_mode = dm_sw_var_r_x; 1311 break; 1312 default: 1313 ASSERT(0); /* Not supported */ 1314 break; 1315 } 1316 } 1317 1318 int dcn20_populate_dml_pipes_from_context(struct dc *dc, 1319 struct dc_state *context, 1320 display_e2e_pipe_params_st *pipes, 1321 enum dc_validate_mode validate_mode) 1322 { 1323 (void)validate_mode; 1324 int pipe_cnt; 1325 unsigned int i; 1326 bool synchronized_vblank = true; 1327 struct resource_context *res_ctx = &context->res_ctx; 1328 1329 dc_assert_fp_enabled(); 1330 1331 for (i = 0, pipe_cnt = -1; i < dc->res_pool->pipe_count; i++) { 1332 if (!res_ctx->pipe_ctx[i].stream) 1333 continue; 1334 1335 if (pipe_cnt < 0) { 1336 pipe_cnt = i; 1337 continue; 1338 } 1339 1340 if (res_ctx->pipe_ctx[pipe_cnt].stream == res_ctx->pipe_ctx[i].stream) 1341 continue; 1342 1343 if (dc->debug.disable_timing_sync || 1344 (!resource_are_streams_timing_synchronizable( 1345 res_ctx->pipe_ctx[pipe_cnt].stream, 1346 res_ctx->pipe_ctx[i].stream) && 1347 !resource_are_vblanks_synchronizable( 1348 res_ctx->pipe_ctx[pipe_cnt].stream, 1349 res_ctx->pipe_ctx[i].stream))) { 1350 synchronized_vblank = false; 1351 break; 1352 } 1353 } 1354 1355 for (i = 0, pipe_cnt = 0; i < dc->res_pool->pipe_count; i++) { 1356 struct dc_crtc_timing *timing = &res_ctx->pipe_ctx[i].stream->timing; 1357 unsigned int v_total; 1358 unsigned int front_porch; 1359 int output_bpc; 1360 struct audio_check aud_check = {0}; 1361 1362 if (!res_ctx->pipe_ctx[i].stream) 1363 continue; 1364 1365 v_total = timing->v_total; 1366 front_porch = timing->v_front_porch; 1367 1368 /* todo: 1369 pipes[pipe_cnt].pipe.src.dynamic_metadata_enable = 0; 1370 pipes[pipe_cnt].pipe.src.dcc = 0; 1371 pipes[pipe_cnt].pipe.src.vm = 0;*/ 1372 1373 pipes[pipe_cnt].clks_cfg.refclk_mhz = dc->res_pool->ref_clocks.dchub_ref_clock_inKhz / 1000.0; 1374 1375 pipes[pipe_cnt].pipe.dest.use_maximum_vstartup = dc->ctx->dce_version == DCN_VERSION_2_01; 1376 1377 pipes[pipe_cnt].dout.dsc_enable = res_ctx->pipe_ctx[i].stream->timing.flags.DSC; 1378 /* todo: rotation?*/ 1379 pipes[pipe_cnt].dout.dsc_slices = res_ctx->pipe_ctx[i].stream->timing.dsc_cfg.num_slices_h; 1380 if (res_ctx->pipe_ctx[i].stream->use_dynamic_meta) { 1381 pipes[pipe_cnt].pipe.src.dynamic_metadata_enable = true; 1382 /* 1/2 vblank */ 1383 pipes[pipe_cnt].pipe.src.dynamic_metadata_lines_before_active = 1384 (v_total - timing->v_addressable 1385 - timing->v_border_top - timing->v_border_bottom) / 2; 1386 /* 36 bytes dp, 32 hdmi */ 1387 pipes[pipe_cnt].pipe.src.dynamic_metadata_xmit_bytes = 1388 dc_is_dp_signal(res_ctx->pipe_ctx[i].stream->signal) ? 36 : 32; 1389 } 1390 pipes[pipe_cnt].pipe.src.dcc = false; 1391 pipes[pipe_cnt].pipe.src.dcc_rate = 1; 1392 pipes[pipe_cnt].pipe.dest.synchronized_vblank_all_planes = synchronized_vblank; 1393 pipes[pipe_cnt].pipe.dest.synchronize_timings = synchronized_vblank; 1394 pipes[pipe_cnt].pipe.dest.hblank_start = timing->h_total - timing->h_front_porch; 1395 pipes[pipe_cnt].pipe.dest.hblank_end = pipes[pipe_cnt].pipe.dest.hblank_start 1396 - timing->h_addressable 1397 - timing->h_border_left 1398 - timing->h_border_right; 1399 pipes[pipe_cnt].pipe.dest.vblank_start = v_total - front_porch; 1400 pipes[pipe_cnt].pipe.dest.vblank_end = pipes[pipe_cnt].pipe.dest.vblank_start 1401 - timing->v_addressable 1402 - timing->v_border_top 1403 - timing->v_border_bottom; 1404 pipes[pipe_cnt].pipe.dest.htotal = timing->h_total; 1405 pipes[pipe_cnt].pipe.dest.vtotal = v_total; 1406 pipes[pipe_cnt].pipe.dest.hactive = 1407 timing->h_addressable + timing->h_border_left + timing->h_border_right; 1408 pipes[pipe_cnt].pipe.dest.vactive = 1409 timing->v_addressable + timing->v_border_top + timing->v_border_bottom; 1410 pipes[pipe_cnt].pipe.dest.interlaced = (unsigned char)timing->flags.INTERLACE; 1411 pipes[pipe_cnt].pipe.dest.pixel_rate_mhz = timing->pix_clk_100hz/10000.0; 1412 if (timing->timing_3d_format == TIMING_3D_FORMAT_HW_FRAME_PACKING) 1413 pipes[pipe_cnt].pipe.dest.pixel_rate_mhz *= 2; 1414 pipes[pipe_cnt].pipe.dest.otg_inst = 1415 (unsigned char)res_ctx->pipe_ctx[i].stream_res.tg->inst; 1416 pipes[pipe_cnt].dout.dp_lanes = 4; 1417 pipes[pipe_cnt].dout.dp_rate = dm_dp_rate_na; 1418 pipes[pipe_cnt].dout.is_virtual = 0; 1419 pipes[pipe_cnt].pipe.dest.vtotal_min = res_ctx->pipe_ctx[i].stream->adjust.v_total_min; 1420 pipes[pipe_cnt].pipe.dest.vtotal_max = res_ctx->pipe_ctx[i].stream->adjust.v_total_max; 1421 switch (resource_get_odm_slice_count(&res_ctx->pipe_ctx[i])) { 1422 case 2: 1423 pipes[pipe_cnt].pipe.dest.odm_combine = dm_odm_combine_mode_2to1; 1424 break; 1425 case 4: 1426 pipes[pipe_cnt].pipe.dest.odm_combine = dm_odm_combine_mode_4to1; 1427 break; 1428 default: 1429 pipes[pipe_cnt].pipe.dest.odm_combine = dm_odm_combine_mode_disabled; 1430 } 1431 pipes[pipe_cnt].pipe.src.hsplit_grp = res_ctx->pipe_ctx[i].pipe_idx; 1432 if (res_ctx->pipe_ctx[i].top_pipe && res_ctx->pipe_ctx[i].top_pipe->plane_state 1433 == res_ctx->pipe_ctx[i].plane_state) { 1434 struct pipe_ctx *first_pipe = res_ctx->pipe_ctx[i].top_pipe; 1435 int split_idx = 0; 1436 1437 while (first_pipe->top_pipe && first_pipe->top_pipe->plane_state 1438 == res_ctx->pipe_ctx[i].plane_state) { 1439 first_pipe = first_pipe->top_pipe; 1440 split_idx++; 1441 } 1442 /* Treat 4to1 mpc combine as an mpo of 2 2-to-1 combines */ 1443 if (split_idx == 0) 1444 pipes[pipe_cnt].pipe.src.hsplit_grp = first_pipe->pipe_idx; 1445 else if (split_idx == 1) 1446 pipes[pipe_cnt].pipe.src.hsplit_grp = res_ctx->pipe_ctx[i].pipe_idx; 1447 else if (split_idx == 2) 1448 pipes[pipe_cnt].pipe.src.hsplit_grp = res_ctx->pipe_ctx[i].top_pipe->pipe_idx; 1449 } else if (res_ctx->pipe_ctx[i].prev_odm_pipe) { 1450 struct pipe_ctx *first_pipe = res_ctx->pipe_ctx[i].prev_odm_pipe; 1451 1452 while (first_pipe->prev_odm_pipe) 1453 first_pipe = first_pipe->prev_odm_pipe; 1454 pipes[pipe_cnt].pipe.src.hsplit_grp = first_pipe->pipe_idx; 1455 } 1456 1457 switch (res_ctx->pipe_ctx[i].stream->signal) { 1458 case SIGNAL_TYPE_DISPLAY_PORT_MST: 1459 case SIGNAL_TYPE_DISPLAY_PORT: 1460 pipes[pipe_cnt].dout.output_type = dm_dp; 1461 if (dc->link_srv->dp_is_128b_132b_signal(&res_ctx->pipe_ctx[i])) 1462 pipes[pipe_cnt].dout.output_type = dm_dp2p0; 1463 break; 1464 case SIGNAL_TYPE_EDP: 1465 pipes[pipe_cnt].dout.output_type = dm_edp; 1466 break; 1467 case SIGNAL_TYPE_HDMI_TYPE_A: 1468 case SIGNAL_TYPE_DVI_SINGLE_LINK: 1469 case SIGNAL_TYPE_DVI_DUAL_LINK: 1470 pipes[pipe_cnt].dout.output_type = dm_hdmi; 1471 break; 1472 case SIGNAL_TYPE_HDMI_FRL: 1473 pipes[pipe_cnt].dout.output_type = dm_hdmifrl; 1474 break; 1475 default: 1476 /* In case there is no signal, set dp with 4 lanes to allow max config */ 1477 pipes[pipe_cnt].dout.is_virtual = 1; 1478 pipes[pipe_cnt].dout.output_type = dm_dp; 1479 pipes[pipe_cnt].dout.dp_lanes = 4; 1480 } 1481 1482 switch (res_ctx->pipe_ctx[i].stream->timing.display_color_depth) { 1483 case COLOR_DEPTH_666: 1484 output_bpc = 6; 1485 break; 1486 case COLOR_DEPTH_888: 1487 output_bpc = 8; 1488 break; 1489 case COLOR_DEPTH_101010: 1490 output_bpc = 10; 1491 break; 1492 case COLOR_DEPTH_121212: 1493 output_bpc = 12; 1494 break; 1495 case COLOR_DEPTH_141414: 1496 output_bpc = 14; 1497 break; 1498 case COLOR_DEPTH_161616: 1499 output_bpc = 16; 1500 break; 1501 case COLOR_DEPTH_999: 1502 output_bpc = 9; 1503 break; 1504 case COLOR_DEPTH_111111: 1505 output_bpc = 11; 1506 break; 1507 default: 1508 output_bpc = 8; 1509 break; 1510 } 1511 1512 switch (res_ctx->pipe_ctx[i].stream->timing.pixel_encoding) { 1513 case PIXEL_ENCODING_RGB: 1514 case PIXEL_ENCODING_YCBCR444: 1515 pipes[pipe_cnt].dout.output_format = dm_444; 1516 pipes[pipe_cnt].dout.output_bpp = output_bpc * 3; 1517 break; 1518 case PIXEL_ENCODING_YCBCR420: 1519 pipes[pipe_cnt].dout.output_format = dm_420; 1520 pipes[pipe_cnt].dout.output_bpp = (output_bpc * 3.0) / 2; 1521 break; 1522 case PIXEL_ENCODING_YCBCR422: 1523 if (res_ctx->pipe_ctx[i].stream->timing.flags.DSC && 1524 !res_ctx->pipe_ctx[i].stream->timing.dsc_cfg.ycbcr422_simple) 1525 pipes[pipe_cnt].dout.output_format = dm_n422; 1526 else 1527 pipes[pipe_cnt].dout.output_format = dm_s422; 1528 pipes[pipe_cnt].dout.output_bpp = output_bpc * 2; 1529 break; 1530 default: 1531 pipes[pipe_cnt].dout.output_format = dm_444; 1532 pipes[pipe_cnt].dout.output_bpp = output_bpc * 3; 1533 } 1534 1535 if (res_ctx->pipe_ctx[i].stream->timing.flags.DSC) 1536 pipes[pipe_cnt].dout.output_bpp = res_ctx->pipe_ctx[i].stream->timing.dsc_cfg.bits_per_pixel / 16.0; 1537 1538 /* todo: default max for now, until there is logic reflecting this in dc*/ 1539 pipes[pipe_cnt].dout.dsc_input_bpc = 12; 1540 /*fill up the audio sample rate (unit in kHz)*/ 1541 get_audio_check(&res_ctx->pipe_ctx[i].stream->audio_info, &aud_check); 1542 pipes[pipe_cnt].dout.max_audio_sample_rate = aud_check.max_audiosample_rate / 1000; 1543 /* 1544 * For graphic plane, cursor number is 1, nv12 is 0 1545 * bw calculations due to cursor on/off 1546 */ 1547 if (res_ctx->pipe_ctx[i].plane_state && 1548 (res_ctx->pipe_ctx[i].plane_state->address.type == PLN_ADDR_TYPE_VIDEO_PROGRESSIVE || 1549 dc_state_get_pipe_subvp_type(context, &res_ctx->pipe_ctx[i]) == SUBVP_PHANTOM)) 1550 pipes[pipe_cnt].pipe.src.num_cursors = 0; 1551 else 1552 pipes[pipe_cnt].pipe.src.num_cursors = dc->dml.ip.number_of_cursors; 1553 1554 pipes[pipe_cnt].pipe.src.cur0_src_width = 256; 1555 pipes[pipe_cnt].pipe.src.cur0_bpp = dm_cur_32bit; 1556 1557 if (!res_ctx->pipe_ctx[i].plane_state) { 1558 pipes[pipe_cnt].pipe.src.is_hsplit = pipes[pipe_cnt].pipe.dest.odm_combine != dm_odm_combine_mode_disabled; 1559 pipes[pipe_cnt].pipe.src.source_scan = dm_horz; 1560 pipes[pipe_cnt].pipe.src.source_rotation = dm_rotation_0; 1561 pipes[pipe_cnt].pipe.src.sw_mode = dm_sw_4kb_s; 1562 pipes[pipe_cnt].pipe.src.macro_tile_size = dm_64k_tile; 1563 pipes[pipe_cnt].pipe.src.viewport_width = timing->h_addressable; 1564 if (pipes[pipe_cnt].pipe.src.viewport_width > 1920) 1565 pipes[pipe_cnt].pipe.src.viewport_width = 1920; 1566 pipes[pipe_cnt].pipe.src.viewport_height = timing->v_addressable; 1567 if (pipes[pipe_cnt].pipe.src.viewport_height > 1080) 1568 pipes[pipe_cnt].pipe.src.viewport_height = 1080; 1569 pipes[pipe_cnt].pipe.src.surface_height_y = pipes[pipe_cnt].pipe.src.viewport_height; 1570 pipes[pipe_cnt].pipe.src.surface_width_y = pipes[pipe_cnt].pipe.src.viewport_width; 1571 pipes[pipe_cnt].pipe.src.surface_height_c = pipes[pipe_cnt].pipe.src.viewport_height; 1572 pipes[pipe_cnt].pipe.src.surface_width_c = pipes[pipe_cnt].pipe.src.viewport_width; 1573 pipes[pipe_cnt].pipe.src.data_pitch = ((pipes[pipe_cnt].pipe.src.viewport_width + 255) / 256) * 256; 1574 pipes[pipe_cnt].pipe.src.source_format = dm_444_32; 1575 pipes[pipe_cnt].pipe.src.cur0_src_width = 0; 1576 pipes[pipe_cnt].pipe.src.cur1_src_width = 0; 1577 pipes[pipe_cnt].pipe.dest.recout_width = pipes[pipe_cnt].pipe.src.viewport_width; /*vp_width/hratio*/ 1578 pipes[pipe_cnt].pipe.dest.recout_height = pipes[pipe_cnt].pipe.src.viewport_height; /*vp_height/vratio*/ 1579 pipes[pipe_cnt].pipe.dest.full_recout_width = pipes[pipe_cnt].pipe.dest.recout_width; /*when is_hsplit != 1*/ 1580 pipes[pipe_cnt].pipe.dest.full_recout_height = pipes[pipe_cnt].pipe.dest.recout_height; /*when is_hsplit != 1*/ 1581 pipes[pipe_cnt].pipe.scale_ratio_depth.lb_depth = dm_lb_16; 1582 pipes[pipe_cnt].pipe.scale_ratio_depth.hscl_ratio = 1.0; 1583 pipes[pipe_cnt].pipe.scale_ratio_depth.vscl_ratio = 1.0; 1584 pipes[pipe_cnt].pipe.scale_ratio_depth.scl_enable = 0; /*Lb only or Full scl*/ 1585 pipes[pipe_cnt].pipe.scale_taps.htaps = 1; 1586 pipes[pipe_cnt].pipe.scale_taps.vtaps = 1; 1587 pipes[pipe_cnt].pipe.dest.vtotal_min = v_total; 1588 pipes[pipe_cnt].pipe.dest.vtotal_max = v_total; 1589 1590 if (pipes[pipe_cnt].pipe.dest.odm_combine == dm_odm_combine_mode_2to1) { 1591 pipes[pipe_cnt].pipe.src.viewport_width /= 2; 1592 pipes[pipe_cnt].pipe.dest.recout_width /= 2; 1593 } else if (pipes[pipe_cnt].pipe.dest.odm_combine == dm_odm_combine_mode_4to1) { 1594 pipes[pipe_cnt].pipe.src.viewport_width /= 4; 1595 pipes[pipe_cnt].pipe.dest.recout_width /= 4; 1596 } 1597 } else { 1598 struct dc_plane_state *pln = res_ctx->pipe_ctx[i].plane_state; 1599 struct scaler_data *scl = &res_ctx->pipe_ctx[i].plane_res.scl_data; 1600 1601 pipes[pipe_cnt].pipe.src.immediate_flip = pln->flip_immediate; 1602 pipes[pipe_cnt].pipe.src.is_hsplit = (res_ctx->pipe_ctx[i].bottom_pipe && res_ctx->pipe_ctx[i].bottom_pipe->plane_state == pln) 1603 || (res_ctx->pipe_ctx[i].top_pipe && res_ctx->pipe_ctx[i].top_pipe->plane_state == pln) 1604 || pipes[pipe_cnt].pipe.dest.odm_combine != dm_odm_combine_mode_disabled; 1605 1606 /* stereo is not split */ 1607 if (pln->stereo_format == PLANE_STEREO_FORMAT_SIDE_BY_SIDE || 1608 pln->stereo_format == PLANE_STEREO_FORMAT_TOP_AND_BOTTOM) { 1609 pipes[pipe_cnt].pipe.src.is_hsplit = false; 1610 pipes[pipe_cnt].pipe.src.hsplit_grp = res_ctx->pipe_ctx[i].pipe_idx; 1611 } 1612 1613 pipes[pipe_cnt].pipe.src.source_scan = pln->rotation == ROTATION_ANGLE_90 1614 || pln->rotation == ROTATION_ANGLE_270 ? dm_vert : dm_horz; 1615 switch (pln->rotation) { 1616 case ROTATION_ANGLE_0: 1617 pipes[pipe_cnt].pipe.src.source_rotation = dm_rotation_0; 1618 break; 1619 case ROTATION_ANGLE_90: 1620 pipes[pipe_cnt].pipe.src.source_rotation = dm_rotation_90; 1621 break; 1622 case ROTATION_ANGLE_180: 1623 pipes[pipe_cnt].pipe.src.source_rotation = dm_rotation_180; 1624 break; 1625 case ROTATION_ANGLE_270: 1626 pipes[pipe_cnt].pipe.src.source_rotation = dm_rotation_270; 1627 break; 1628 default: 1629 break; 1630 } 1631 1632 pipes[pipe_cnt].pipe.src.viewport_y_y = scl->viewport.y; 1633 pipes[pipe_cnt].pipe.src.viewport_y_c = scl->viewport_c.y; 1634 pipes[pipe_cnt].pipe.src.viewport_x_y = scl->viewport.x; 1635 pipes[pipe_cnt].pipe.src.viewport_x_c = scl->viewport_c.x; 1636 pipes[pipe_cnt].pipe.src.viewport_width = scl->viewport.width; 1637 pipes[pipe_cnt].pipe.src.viewport_width_c = scl->viewport_c.width; 1638 pipes[pipe_cnt].pipe.src.viewport_height = scl->viewport.height; 1639 pipes[pipe_cnt].pipe.src.viewport_height_c = scl->viewport_c.height; 1640 pipes[pipe_cnt].pipe.src.viewport_width_max = pln->src_rect.width; 1641 pipes[pipe_cnt].pipe.src.viewport_height_max = pln->src_rect.height; 1642 pipes[pipe_cnt].pipe.src.surface_width_y = pln->plane_size.surface_size.width; 1643 pipes[pipe_cnt].pipe.src.surface_height_y = pln->plane_size.surface_size.height; 1644 pipes[pipe_cnt].pipe.src.surface_width_c = pln->plane_size.chroma_size.width; 1645 pipes[pipe_cnt].pipe.src.surface_height_c = pln->plane_size.chroma_size.height; 1646 if (pln->format == SURFACE_PIXEL_FORMAT_GRPH_RGBE_ALPHA 1647 || pln->format >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN) { 1648 pipes[pipe_cnt].pipe.src.data_pitch = pln->plane_size.surface_pitch; 1649 pipes[pipe_cnt].pipe.src.data_pitch_c = pln->plane_size.chroma_pitch; 1650 pipes[pipe_cnt].pipe.src.meta_pitch = pln->dcc.meta_pitch; 1651 pipes[pipe_cnt].pipe.src.meta_pitch_c = pln->dcc.meta_pitch_c; 1652 } else { 1653 pipes[pipe_cnt].pipe.src.data_pitch = pln->plane_size.surface_pitch; 1654 pipes[pipe_cnt].pipe.src.meta_pitch = pln->dcc.meta_pitch; 1655 } 1656 pipes[pipe_cnt].pipe.src.dcc = pln->dcc.enable; 1657 pipes[pipe_cnt].pipe.dest.recout_width = scl->recout.width; 1658 pipes[pipe_cnt].pipe.dest.recout_height = scl->recout.height; 1659 pipes[pipe_cnt].pipe.dest.full_recout_height = scl->recout.height; 1660 pipes[pipe_cnt].pipe.dest.full_recout_width = scl->recout.width; 1661 if (pipes[pipe_cnt].pipe.dest.odm_combine == dm_odm_combine_mode_2to1) 1662 pipes[pipe_cnt].pipe.dest.full_recout_width *= 2; 1663 else if (pipes[pipe_cnt].pipe.dest.odm_combine == dm_odm_combine_mode_4to1) 1664 pipes[pipe_cnt].pipe.dest.full_recout_width *= 4; 1665 else { 1666 struct pipe_ctx *split_pipe = res_ctx->pipe_ctx[i].bottom_pipe; 1667 1668 while (split_pipe && split_pipe->plane_state == pln) { 1669 pipes[pipe_cnt].pipe.dest.full_recout_width += split_pipe->plane_res.scl_data.recout.width; 1670 split_pipe = split_pipe->bottom_pipe; 1671 } 1672 split_pipe = res_ctx->pipe_ctx[i].top_pipe; 1673 while (split_pipe && split_pipe->plane_state == pln) { 1674 pipes[pipe_cnt].pipe.dest.full_recout_width += split_pipe->plane_res.scl_data.recout.width; 1675 split_pipe = split_pipe->top_pipe; 1676 } 1677 } 1678 1679 pipes[pipe_cnt].pipe.scale_ratio_depth.lb_depth = dm_lb_16; 1680 pipes[pipe_cnt].pipe.scale_ratio_depth.hscl_ratio = (double) scl->ratios.horz.value / (1ULL<<32); 1681 pipes[pipe_cnt].pipe.scale_ratio_depth.hscl_ratio_c = (double) scl->ratios.horz_c.value / (1ULL<<32); 1682 pipes[pipe_cnt].pipe.scale_ratio_depth.vscl_ratio = (double) scl->ratios.vert.value / (1ULL<<32); 1683 pipes[pipe_cnt].pipe.scale_ratio_depth.vscl_ratio_c = (double) scl->ratios.vert_c.value / (1ULL<<32); 1684 pipes[pipe_cnt].pipe.scale_ratio_depth.scl_enable = 1685 scl->ratios.vert.value != dc_fixpt_one.value 1686 || scl->ratios.horz.value != dc_fixpt_one.value 1687 || scl->ratios.vert_c.value != dc_fixpt_one.value 1688 || scl->ratios.horz_c.value != dc_fixpt_one.value /*Lb only or Full scl*/ 1689 || dc->debug.always_scale; /*support always scale*/ 1690 pipes[pipe_cnt].pipe.scale_taps.htaps = scl->taps.h_taps; 1691 pipes[pipe_cnt].pipe.scale_taps.htaps_c = scl->taps.h_taps_c; 1692 pipes[pipe_cnt].pipe.scale_taps.vtaps = scl->taps.v_taps; 1693 pipes[pipe_cnt].pipe.scale_taps.vtaps_c = scl->taps.v_taps_c; 1694 1695 pipes[pipe_cnt].pipe.src.macro_tile_size = 1696 swizzle_mode_to_macro_tile_size(pln->tiling_info.gfx9.swizzle); 1697 swizzle_to_dml_params(pln->tiling_info.gfx9.swizzle, 1698 &pipes[pipe_cnt].pipe.src.sw_mode); 1699 1700 switch (pln->format) { 1701 case SURFACE_PIXEL_FORMAT_VIDEO_420_YCbCr: 1702 case SURFACE_PIXEL_FORMAT_VIDEO_420_YCrCb: 1703 pipes[pipe_cnt].pipe.src.source_format = dm_420_8; 1704 break; 1705 case SURFACE_PIXEL_FORMAT_VIDEO_420_10bpc_YCbCr: 1706 case SURFACE_PIXEL_FORMAT_VIDEO_420_10bpc_YCrCb: 1707 pipes[pipe_cnt].pipe.src.source_format = dm_420_10; 1708 break; 1709 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616: 1710 case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616: 1711 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616F: 1712 case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F: 1713 pipes[pipe_cnt].pipe.src.source_format = dm_444_64; 1714 break; 1715 case SURFACE_PIXEL_FORMAT_GRPH_ARGB1555: 1716 case SURFACE_PIXEL_FORMAT_GRPH_RGB565: 1717 pipes[pipe_cnt].pipe.src.source_format = dm_444_16; 1718 break; 1719 case SURFACE_PIXEL_FORMAT_GRPH_PALETA_256_COLORS: 1720 pipes[pipe_cnt].pipe.src.source_format = dm_444_8; 1721 break; 1722 case SURFACE_PIXEL_FORMAT_GRPH_RGBE_ALPHA: 1723 pipes[pipe_cnt].pipe.src.source_format = dm_rgbe_alpha; 1724 break; 1725 default: 1726 pipes[pipe_cnt].pipe.src.source_format = dm_444_32; 1727 break; 1728 } 1729 } 1730 1731 pipe_cnt++; 1732 } 1733 1734 /* populate writeback information */ 1735 dc->res_pool->funcs->populate_dml_writeback_from_context(dc, res_ctx, pipes); 1736 1737 return pipe_cnt; 1738 } 1739 1740 void dcn20_calculate_wm(struct dc *dc, struct dc_state *context, 1741 display_e2e_pipe_params_st *pipes, 1742 int *out_pipe_cnt, 1743 int *pipe_split_from, 1744 int vlevel, 1745 enum dc_validate_mode validate_mode) 1746 { 1747 int pipe_cnt, pipe_idx; 1748 unsigned int i; 1749 1750 dc_assert_fp_enabled(); 1751 1752 for (i = 0, pipe_idx = 0, pipe_cnt = 0; i < dc->res_pool->pipe_count; i++) { 1753 if (!context->res_ctx.pipe_ctx[i].stream) 1754 continue; 1755 1756 pipes[pipe_cnt].clks_cfg.refclk_mhz = dc->res_pool->ref_clocks.dchub_ref_clock_inKhz / 1000.0; 1757 pipes[pipe_cnt].clks_cfg.dispclk_mhz = context->bw_ctx.dml.vba.RequiredDISPCLK[vlevel][context->bw_ctx.dml.vba.maxMpcComb]; 1758 1759 if (pipe_split_from[i] < 0) { 1760 pipes[pipe_cnt].clks_cfg.dppclk_mhz = 1761 context->bw_ctx.dml.vba.RequiredDPPCLK[vlevel][context->bw_ctx.dml.vba.maxMpcComb][pipe_idx]; 1762 if (context->bw_ctx.dml.vba.BlendingAndTiming[pipe_idx] == pipe_idx) 1763 pipes[pipe_cnt].pipe.dest.odm_combine = 1764 context->bw_ctx.dml.vba.ODMCombineEnabled[pipe_idx]; 1765 else 1766 pipes[pipe_cnt].pipe.dest.odm_combine = 0; 1767 pipe_idx++; 1768 } else { 1769 pipes[pipe_cnt].clks_cfg.dppclk_mhz = 1770 context->bw_ctx.dml.vba.RequiredDPPCLK[vlevel][context->bw_ctx.dml.vba.maxMpcComb][pipe_split_from[i]]; 1771 if (context->bw_ctx.dml.vba.BlendingAndTiming[pipe_split_from[i]] == pipe_split_from[i]) 1772 pipes[pipe_cnt].pipe.dest.odm_combine = 1773 context->bw_ctx.dml.vba.ODMCombineEnabled[pipe_split_from[i]]; 1774 else 1775 pipes[pipe_cnt].pipe.dest.odm_combine = 0; 1776 } 1777 1778 if (dc->config.forced_clocks) { 1779 pipes[pipe_cnt].clks_cfg.dispclk_mhz = context->bw_ctx.dml.soc.clock_limits[0].dispclk_mhz; 1780 pipes[pipe_cnt].clks_cfg.dppclk_mhz = context->bw_ctx.dml.soc.clock_limits[0].dppclk_mhz; 1781 } 1782 if (dc->debug.min_disp_clk_khz > pipes[pipe_cnt].clks_cfg.dispclk_mhz * 1000) 1783 pipes[pipe_cnt].clks_cfg.dispclk_mhz = dc->debug.min_disp_clk_khz / 1000.0; 1784 if (dc->debug.min_dpp_clk_khz > pipes[pipe_cnt].clks_cfg.dppclk_mhz * 1000) 1785 pipes[pipe_cnt].clks_cfg.dppclk_mhz = dc->debug.min_dpp_clk_khz / 1000.0; 1786 1787 pipe_cnt++; 1788 } 1789 1790 if (pipe_cnt != pipe_idx) { 1791 if (dc->res_pool->funcs->populate_dml_pipes) 1792 pipe_cnt = dc->res_pool->funcs->populate_dml_pipes(dc, 1793 context, pipes, validate_mode); 1794 else 1795 pipe_cnt = dcn20_populate_dml_pipes_from_context(dc, 1796 context, pipes, validate_mode); 1797 } 1798 1799 *out_pipe_cnt = pipe_cnt; 1800 1801 pipes[0].clks_cfg.voltage = vlevel; 1802 pipes[0].clks_cfg.dcfclk_mhz = context->bw_ctx.dml.soc.clock_limits[vlevel].dcfclk_mhz; 1803 pipes[0].clks_cfg.socclk_mhz = context->bw_ctx.dml.soc.clock_limits[vlevel].socclk_mhz; 1804 1805 /* only pipe 0 is read for voltage and dcf/soc clocks */ 1806 if (vlevel < 1) { 1807 pipes[0].clks_cfg.voltage = 1; 1808 pipes[0].clks_cfg.dcfclk_mhz = context->bw_ctx.dml.soc.clock_limits[1].dcfclk_mhz; 1809 pipes[0].clks_cfg.socclk_mhz = context->bw_ctx.dml.soc.clock_limits[1].socclk_mhz; 1810 } 1811 context->bw_ctx.bw.dcn.watermarks.b.urgent_ns = (uint32_t)(get_wm_urgent(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000.0); 1812 context->bw_ctx.bw.dcn.watermarks.b.cstate_pstate.cstate_enter_plus_exit_ns = (uint32_t)(get_wm_stutter_enter_exit(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000.0); 1813 context->bw_ctx.bw.dcn.watermarks.b.cstate_pstate.cstate_exit_ns = (uint32_t)(get_wm_stutter_exit(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000.0); 1814 context->bw_ctx.bw.dcn.watermarks.b.cstate_pstate.pstate_change_ns = (uint32_t)(get_wm_dram_clock_change(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000.0); 1815 context->bw_ctx.bw.dcn.watermarks.b.pte_meta_urgent_ns = (uint32_t)(get_wm_memory_trip(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000.0); 1816 context->bw_ctx.bw.dcn.watermarks.b.frac_urg_bw_nom = (uint32_t)(get_fraction_of_urgent_bandwidth(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000.0); 1817 context->bw_ctx.bw.dcn.watermarks.b.frac_urg_bw_flip = (uint32_t)(get_fraction_of_urgent_bandwidth_imm_flip(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000.0); 1818 context->bw_ctx.bw.dcn.watermarks.b.urgent_latency_ns = (uint32_t)(get_urgent_latency(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000.0); 1819 1820 if (vlevel < 2) { 1821 pipes[0].clks_cfg.voltage = 2; 1822 pipes[0].clks_cfg.dcfclk_mhz = context->bw_ctx.dml.soc.clock_limits[2].dcfclk_mhz; 1823 pipes[0].clks_cfg.socclk_mhz = context->bw_ctx.dml.soc.clock_limits[2].socclk_mhz; 1824 } 1825 context->bw_ctx.bw.dcn.watermarks.c.urgent_ns = (uint32_t)(get_wm_urgent(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000.0); 1826 context->bw_ctx.bw.dcn.watermarks.c.cstate_pstate.cstate_enter_plus_exit_ns = (uint32_t)(get_wm_stutter_enter_exit(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000.0); 1827 context->bw_ctx.bw.dcn.watermarks.c.cstate_pstate.cstate_exit_ns = (uint32_t)(get_wm_stutter_exit(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000.0); 1828 context->bw_ctx.bw.dcn.watermarks.c.cstate_pstate.pstate_change_ns = (uint32_t)(get_wm_dram_clock_change(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000.0); 1829 context->bw_ctx.bw.dcn.watermarks.c.pte_meta_urgent_ns = (uint32_t)(get_wm_memory_trip(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000.0); 1830 context->bw_ctx.bw.dcn.watermarks.c.frac_urg_bw_nom = (uint32_t)(get_fraction_of_urgent_bandwidth(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000.0); 1831 context->bw_ctx.bw.dcn.watermarks.c.frac_urg_bw_flip = (uint32_t)(get_fraction_of_urgent_bandwidth_imm_flip(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000.0); 1832 1833 if (vlevel < 3) { 1834 pipes[0].clks_cfg.voltage = 3; 1835 pipes[0].clks_cfg.dcfclk_mhz = context->bw_ctx.dml.soc.clock_limits[2].dcfclk_mhz; 1836 pipes[0].clks_cfg.socclk_mhz = context->bw_ctx.dml.soc.clock_limits[2].socclk_mhz; 1837 } 1838 context->bw_ctx.bw.dcn.watermarks.d.urgent_ns = (uint32_t)(get_wm_urgent(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000.0); 1839 context->bw_ctx.bw.dcn.watermarks.d.cstate_pstate.cstate_enter_plus_exit_ns = (uint32_t)(get_wm_stutter_enter_exit(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000.0); 1840 context->bw_ctx.bw.dcn.watermarks.d.cstate_pstate.cstate_exit_ns = (uint32_t)(get_wm_stutter_exit(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000.0); 1841 context->bw_ctx.bw.dcn.watermarks.d.cstate_pstate.pstate_change_ns = (uint32_t)(get_wm_dram_clock_change(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000.0); 1842 context->bw_ctx.bw.dcn.watermarks.d.pte_meta_urgent_ns = (uint32_t)(get_wm_memory_trip(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000.0); 1843 context->bw_ctx.bw.dcn.watermarks.d.frac_urg_bw_nom = (uint32_t)(get_fraction_of_urgent_bandwidth(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000.0); 1844 context->bw_ctx.bw.dcn.watermarks.d.frac_urg_bw_flip = (uint32_t)(get_fraction_of_urgent_bandwidth_imm_flip(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000.0); 1845 1846 pipes[0].clks_cfg.voltage = vlevel; 1847 pipes[0].clks_cfg.dcfclk_mhz = context->bw_ctx.dml.soc.clock_limits[vlevel].dcfclk_mhz; 1848 pipes[0].clks_cfg.socclk_mhz = context->bw_ctx.dml.soc.clock_limits[vlevel].socclk_mhz; 1849 context->bw_ctx.bw.dcn.watermarks.a.urgent_ns = (uint32_t)(get_wm_urgent(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000.0); 1850 context->bw_ctx.bw.dcn.watermarks.a.cstate_pstate.cstate_enter_plus_exit_ns = (uint32_t)(get_wm_stutter_enter_exit(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000.0); 1851 context->bw_ctx.bw.dcn.watermarks.a.cstate_pstate.cstate_exit_ns = (uint32_t)(get_wm_stutter_exit(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000.0); 1852 context->bw_ctx.bw.dcn.watermarks.a.cstate_pstate.pstate_change_ns = (uint32_t)(get_wm_dram_clock_change(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000.0); 1853 context->bw_ctx.bw.dcn.watermarks.a.pte_meta_urgent_ns = (uint32_t)(get_wm_memory_trip(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000.0); 1854 context->bw_ctx.bw.dcn.watermarks.a.frac_urg_bw_nom = (uint32_t)(get_fraction_of_urgent_bandwidth(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000.0); 1855 context->bw_ctx.bw.dcn.watermarks.a.frac_urg_bw_flip = (uint32_t)(get_fraction_of_urgent_bandwidth_imm_flip(&context->bw_ctx.dml, pipes, pipe_cnt) * 1000.0); 1856 } 1857 1858 void dcn20_update_bounding_box(struct dc *dc, 1859 struct _vcs_dpi_soc_bounding_box_st *bb, 1860 struct pp_smu_nv_clock_table *max_clocks, 1861 unsigned int *uclk_states, 1862 unsigned int num_states) 1863 { 1864 int num_calculated_states = 0; 1865 int min_dcfclk = 0; 1866 unsigned int i; 1867 1868 dc_assert_fp_enabled(); 1869 1870 if (num_states == 0) 1871 return; 1872 1873 memset(bb->clock_limits, 0, sizeof(bb->clock_limits)); 1874 1875 if (dc->bb_overrides.min_dcfclk_mhz > 0) { 1876 min_dcfclk = dc->bb_overrides.min_dcfclk_mhz; 1877 } else { 1878 if (ASICREV_IS_NAVI12_P(dc->ctx->asic_id.hw_internal_rev)) 1879 min_dcfclk = 310; 1880 else 1881 // Accounting for SOC/DCF relationship, we can go as high as 1882 // 506Mhz in Vmin. 1883 min_dcfclk = 506; 1884 } 1885 1886 for (i = 0; i < num_states; i++) { 1887 int min_fclk_required_by_uclk; 1888 bb->clock_limits[i].state = i; 1889 bb->clock_limits[i].dram_speed_mts = uclk_states[i] * 16 / 1000; 1890 1891 // FCLK:UCLK ratio is 1.08 1892 min_fclk_required_by_uclk = (int)div_u64(((unsigned long long)uclk_states[i]) * 1080, 1893 1000000); 1894 1895 bb->clock_limits[i].fabricclk_mhz = (min_fclk_required_by_uclk < min_dcfclk) ? 1896 min_dcfclk : min_fclk_required_by_uclk; 1897 1898 bb->clock_limits[i].socclk_mhz = (bb->clock_limits[i].fabricclk_mhz > max_clocks->socClockInKhz / 1000.0) ? 1899 max_clocks->socClockInKhz / 1000 : bb->clock_limits[i].fabricclk_mhz; 1900 1901 bb->clock_limits[i].dcfclk_mhz = (bb->clock_limits[i].fabricclk_mhz > max_clocks->dcfClockInKhz / 1000.0) ? 1902 max_clocks->dcfClockInKhz / 1000 : bb->clock_limits[i].fabricclk_mhz; 1903 1904 bb->clock_limits[i].dispclk_mhz = max_clocks->displayClockInKhz / 1000; 1905 bb->clock_limits[i].dppclk_mhz = max_clocks->displayClockInKhz / 1000; 1906 bb->clock_limits[i].dscclk_mhz = max_clocks->displayClockInKhz / (1000 * 3); 1907 1908 bb->clock_limits[i].phyclk_mhz = max_clocks->phyClockInKhz / 1000; 1909 1910 num_calculated_states++; 1911 } 1912 1913 bb->clock_limits[num_calculated_states - 1].socclk_mhz = max_clocks->socClockInKhz / 1000; 1914 bb->clock_limits[num_calculated_states - 1].fabricclk_mhz = max_clocks->socClockInKhz / 1000; 1915 bb->clock_limits[num_calculated_states - 1].dcfclk_mhz = max_clocks->dcfClockInKhz / 1000; 1916 1917 bb->num_states = num_calculated_states; 1918 1919 // Duplicate the last state, DML always an extra state identical to max state to work 1920 memcpy(&bb->clock_limits[num_calculated_states], &bb->clock_limits[num_calculated_states - 1], sizeof(struct _vcs_dpi_voltage_scaling_st)); 1921 bb->clock_limits[num_calculated_states].state = bb->num_states; 1922 } 1923 1924 void dcn20_cap_soc_clocks(struct _vcs_dpi_soc_bounding_box_st *bb, 1925 struct pp_smu_nv_clock_table max_clocks) 1926 { 1927 unsigned int i; 1928 1929 dc_assert_fp_enabled(); 1930 1931 // First pass - cap all clocks higher than the reported max 1932 for (i = 0; i < bb->num_states; i++) { 1933 if ((bb->clock_limits[i].dcfclk_mhz > (max_clocks.dcfClockInKhz / 1000.0)) 1934 && max_clocks.dcfClockInKhz != 0) 1935 bb->clock_limits[i].dcfclk_mhz = (max_clocks.dcfClockInKhz / 1000); 1936 1937 if ((bb->clock_limits[i].dram_speed_mts > (max_clocks.uClockInKhz / 1000.0) * 16) 1938 && max_clocks.uClockInKhz != 0) 1939 bb->clock_limits[i].dram_speed_mts = (max_clocks.uClockInKhz / 1000) * 16; 1940 1941 if ((bb->clock_limits[i].fabricclk_mhz > (max_clocks.fabricClockInKhz / 1000.0)) 1942 && max_clocks.fabricClockInKhz != 0) 1943 bb->clock_limits[i].fabricclk_mhz = (max_clocks.fabricClockInKhz / 1000); 1944 1945 if ((bb->clock_limits[i].dispclk_mhz > (max_clocks.displayClockInKhz / 1000.0)) 1946 && max_clocks.displayClockInKhz != 0) 1947 bb->clock_limits[i].dispclk_mhz = (max_clocks.displayClockInKhz / 1000); 1948 1949 if ((bb->clock_limits[i].dppclk_mhz > (max_clocks.dppClockInKhz / 1000.0)) 1950 && max_clocks.dppClockInKhz != 0) 1951 bb->clock_limits[i].dppclk_mhz = (max_clocks.dppClockInKhz / 1000); 1952 1953 if ((bb->clock_limits[i].phyclk_mhz > (max_clocks.phyClockInKhz / 1000.0)) 1954 && max_clocks.phyClockInKhz != 0) 1955 bb->clock_limits[i].phyclk_mhz = (max_clocks.phyClockInKhz / 1000); 1956 1957 if ((bb->clock_limits[i].socclk_mhz > (max_clocks.socClockInKhz / 1000.0)) 1958 && max_clocks.socClockInKhz != 0) 1959 bb->clock_limits[i].socclk_mhz = (max_clocks.socClockInKhz / 1000); 1960 1961 if ((bb->clock_limits[i].dscclk_mhz > (max_clocks.dscClockInKhz / 1000.0)) 1962 && max_clocks.dscClockInKhz != 0) 1963 bb->clock_limits[i].dscclk_mhz = (max_clocks.dscClockInKhz / 1000); 1964 } 1965 1966 // Second pass - remove all duplicate clock states 1967 for (i = bb->num_states - 1; i > 1; i--) { 1968 bool duplicate = true; 1969 1970 if (bb->clock_limits[i-1].dcfclk_mhz != bb->clock_limits[i].dcfclk_mhz) 1971 duplicate = false; 1972 if (bb->clock_limits[i-1].dispclk_mhz != bb->clock_limits[i].dispclk_mhz) 1973 duplicate = false; 1974 if (bb->clock_limits[i-1].dppclk_mhz != bb->clock_limits[i].dppclk_mhz) 1975 duplicate = false; 1976 if (bb->clock_limits[i-1].dram_speed_mts != bb->clock_limits[i].dram_speed_mts) 1977 duplicate = false; 1978 if (bb->clock_limits[i-1].dscclk_mhz != bb->clock_limits[i].dscclk_mhz) 1979 duplicate = false; 1980 if (bb->clock_limits[i-1].fabricclk_mhz != bb->clock_limits[i].fabricclk_mhz) 1981 duplicate = false; 1982 if (bb->clock_limits[i-1].phyclk_mhz != bb->clock_limits[i].phyclk_mhz) 1983 duplicate = false; 1984 if (bb->clock_limits[i-1].socclk_mhz != bb->clock_limits[i].socclk_mhz) 1985 duplicate = false; 1986 1987 if (duplicate) 1988 bb->num_states--; 1989 } 1990 } 1991 1992 void dcn20_patch_bounding_box(struct dc *dc, struct _vcs_dpi_soc_bounding_box_st *bb) 1993 { 1994 dc_assert_fp_enabled(); 1995 1996 if ((int)(bb->sr_exit_time_us * 1000) != dc->bb_overrides.sr_exit_time_ns 1997 && dc->bb_overrides.sr_exit_time_ns) { 1998 bb->sr_exit_time_us = dc->bb_overrides.sr_exit_time_ns / 1000.0; 1999 } 2000 2001 if ((int)(bb->sr_enter_plus_exit_time_us * 1000) 2002 != dc->bb_overrides.sr_enter_plus_exit_time_ns 2003 && dc->bb_overrides.sr_enter_plus_exit_time_ns) { 2004 bb->sr_enter_plus_exit_time_us = 2005 dc->bb_overrides.sr_enter_plus_exit_time_ns / 1000.0; 2006 } 2007 2008 if ((int)(bb->sr_exit_z8_time_us * 1000) 2009 != dc->bb_overrides.sr_exit_z8_time_ns 2010 && dc->bb_overrides.sr_exit_z8_time_ns) { 2011 bb->sr_exit_z8_time_us = dc->bb_overrides.sr_exit_z8_time_ns / 1000.0; 2012 } 2013 2014 if ((int)(bb->sr_enter_plus_exit_z8_time_us * 1000) 2015 != dc->bb_overrides.sr_enter_plus_exit_z8_time_ns 2016 && dc->bb_overrides.sr_enter_plus_exit_z8_time_ns) { 2017 bb->sr_enter_plus_exit_z8_time_us = dc->bb_overrides.sr_enter_plus_exit_z8_time_ns / 1000.0; 2018 } 2019 if ((int)(bb->urgent_latency_us * 1000) != dc->bb_overrides.urgent_latency_ns 2020 && dc->bb_overrides.urgent_latency_ns) { 2021 bb->urgent_latency_us = dc->bb_overrides.urgent_latency_ns / 1000.0; 2022 } 2023 2024 if ((int)(bb->dram_clock_change_latency_us * 1000) 2025 != dc->bb_overrides.dram_clock_change_latency_ns 2026 && dc->bb_overrides.dram_clock_change_latency_ns) { 2027 bb->dram_clock_change_latency_us = 2028 dc->bb_overrides.dram_clock_change_latency_ns / 1000.0; 2029 } 2030 2031 if ((int)(bb->dummy_pstate_latency_us * 1000) 2032 != dc->bb_overrides.dummy_clock_change_latency_ns 2033 && dc->bb_overrides.dummy_clock_change_latency_ns) { 2034 bb->dummy_pstate_latency_us = 2035 dc->bb_overrides.dummy_clock_change_latency_ns / 1000.0; 2036 } 2037 } 2038 2039 static bool dcn20_validate_bandwidth_internal(struct dc *dc, struct dc_state *context, 2040 enum dc_validate_mode validate_mode, display_e2e_pipe_params_st *pipes) 2041 { 2042 bool out = false; 2043 2044 BW_VAL_TRACE_SETUP(); 2045 2046 int vlevel = 0; 2047 int pipe_split_from[MAX_PIPES]; 2048 int pipe_cnt = 0; 2049 DC_LOGGER_INIT(dc->ctx->logger); 2050 2051 BW_VAL_TRACE_COUNT(); 2052 2053 out = dcn20_fast_validate_bw(dc, context, pipes, &pipe_cnt, pipe_split_from, &vlevel, validate_mode); 2054 2055 if (pipe_cnt == 0) 2056 goto validate_out; 2057 2058 if (!out) 2059 goto validate_fail; 2060 2061 BW_VAL_TRACE_END_VOLTAGE_LEVEL(); 2062 2063 if (validate_mode != DC_VALIDATE_MODE_AND_PROGRAMMING) { 2064 BW_VAL_TRACE_SKIP(fast); 2065 goto validate_out; 2066 } 2067 2068 dcn20_calculate_wm(dc, context, pipes, &pipe_cnt, pipe_split_from, vlevel, validate_mode); 2069 dcn20_calculate_dlg_params(dc, context, pipes, pipe_cnt, vlevel); 2070 2071 BW_VAL_TRACE_END_WATERMARKS(); 2072 2073 goto validate_out; 2074 2075 validate_fail: 2076 DC_LOG_WARNING("Mode Validation Warning: %s failed validation.\n", 2077 dml_get_status_message(context->bw_ctx.dml.vba.ValidationStatus[context->bw_ctx.dml.vba.soc.num_states])); 2078 2079 BW_VAL_TRACE_SKIP(fail); 2080 out = false; 2081 2082 validate_out: 2083 2084 BW_VAL_TRACE_FINISH(); 2085 2086 return out; 2087 } 2088 2089 bool dcn20_validate_bandwidth_fp(struct dc *dc, struct dc_state *context, 2090 enum dc_validate_mode validate_mode, display_e2e_pipe_params_st *pipes) 2091 { 2092 bool voltage_supported = false; 2093 bool full_pstate_supported = false; 2094 bool dummy_pstate_supported = false; 2095 double p_state_latency_us; 2096 2097 dc_assert_fp_enabled(); 2098 2099 p_state_latency_us = context->bw_ctx.dml.soc.dram_clock_change_latency_us; 2100 context->bw_ctx.dml.soc.disable_dram_clock_change_vactive_support = 2101 dc->debug.disable_dram_clock_change_vactive_support; 2102 context->bw_ctx.dml.soc.allow_dram_clock_one_display_vactive = 2103 dc->debug.enable_dram_clock_change_one_display_vactive; 2104 2105 /*Unsafe due to current pipe merge and split logic*/ 2106 ASSERT(context != dc->current_state); 2107 2108 if (validate_mode != DC_VALIDATE_MODE_AND_PROGRAMMING) 2109 return dcn20_validate_bandwidth_internal(dc, context, validate_mode, pipes); 2110 2111 // Best case, we support full UCLK switch latency 2112 voltage_supported = dcn20_validate_bandwidth_internal(dc, context, DC_VALIDATE_MODE_AND_PROGRAMMING, pipes); 2113 full_pstate_supported = context->bw_ctx.bw.dcn.clk.p_state_change_support; 2114 2115 if (context->bw_ctx.dml.soc.dummy_pstate_latency_us == 0 || 2116 (voltage_supported && full_pstate_supported)) { 2117 context->bw_ctx.bw.dcn.clk.p_state_change_support = full_pstate_supported; 2118 goto restore_dml_state; 2119 } 2120 2121 // Fallback: Try to only support G6 temperature read latency 2122 context->bw_ctx.dml.soc.dram_clock_change_latency_us = context->bw_ctx.dml.soc.dummy_pstate_latency_us; 2123 2124 memset(pipes, 0, dc->res_pool->pipe_count * sizeof(display_e2e_pipe_params_st)); 2125 voltage_supported = dcn20_validate_bandwidth_internal(dc, context, DC_VALIDATE_MODE_AND_PROGRAMMING, pipes); 2126 dummy_pstate_supported = context->bw_ctx.bw.dcn.clk.p_state_change_support; 2127 2128 if (voltage_supported && (dummy_pstate_supported || !(context->stream_count))) { 2129 context->bw_ctx.bw.dcn.clk.p_state_change_support = false; 2130 goto restore_dml_state; 2131 } 2132 2133 // ERROR: fallback is supposed to always work. 2134 ASSERT(false); 2135 2136 restore_dml_state: 2137 context->bw_ctx.dml.soc.dram_clock_change_latency_us = p_state_latency_us; 2138 return voltage_supported; 2139 } 2140 2141 void dcn20_fpu_set_wm_ranges(int i, 2142 struct pp_smu_wm_range_sets *ranges, 2143 struct _vcs_dpi_soc_bounding_box_st *loaded_bb) 2144 { 2145 dc_assert_fp_enabled(); 2146 2147 ranges->reader_wm_sets[i].min_fill_clk_mhz = (uint16_t)((i > 0) ? (loaded_bb->clock_limits[i - 1].dram_speed_mts / 16) + 1 : 0); 2148 ranges->reader_wm_sets[i].max_fill_clk_mhz = (uint16_t)(loaded_bb->clock_limits[i].dram_speed_mts / 16); 2149 } 2150 2151 void dcn20_fpu_adjust_dppclk(struct vba_vars_st *v, 2152 int vlevel, 2153 int max_mpc_comb, 2154 int pipe_idx, 2155 bool is_validating_bw) 2156 { 2157 dc_assert_fp_enabled(); 2158 2159 if (is_validating_bw) 2160 v->RequiredDPPCLK[vlevel][max_mpc_comb][pipe_idx] *= 2; 2161 else 2162 v->RequiredDPPCLK[vlevel][max_mpc_comb][pipe_idx] /= 2; 2163 } 2164 2165 int dcn21_populate_dml_pipes_from_context(struct dc *dc, 2166 struct dc_state *context, 2167 display_e2e_pipe_params_st *pipes, 2168 enum dc_validate_mode validate_mode) 2169 { 2170 uint32_t pipe_cnt; 2171 unsigned int i; 2172 2173 dc_assert_fp_enabled(); 2174 2175 pipe_cnt = dcn20_populate_dml_pipes_from_context(dc, context, pipes, validate_mode); 2176 2177 for (i = 0; i < pipe_cnt; i++) { 2178 2179 pipes[i].pipe.src.hostvm = dc->res_pool->hubbub->riommu_active; 2180 pipes[i].pipe.src.gpuvm = 1; 2181 } 2182 2183 return pipe_cnt; 2184 } 2185 2186 static void patch_bounding_box(struct dc *dc, struct _vcs_dpi_soc_bounding_box_st *bb) 2187 { 2188 int i; 2189 2190 if (dc->bb_overrides.sr_exit_time_ns) { 2191 for (i = 0; i < WM_SET_COUNT; i++) { 2192 dc->clk_mgr->bw_params->wm_table.entries[i].sr_exit_time_us = 2193 dc->bb_overrides.sr_exit_time_ns / 1000.0; 2194 } 2195 } 2196 2197 if (dc->bb_overrides.sr_enter_plus_exit_time_ns) { 2198 for (i = 0; i < WM_SET_COUNT; i++) { 2199 dc->clk_mgr->bw_params->wm_table.entries[i].sr_enter_plus_exit_time_us = 2200 dc->bb_overrides.sr_enter_plus_exit_time_ns / 1000.0; 2201 } 2202 } 2203 2204 if (dc->bb_overrides.urgent_latency_ns) { 2205 bb->urgent_latency_us = dc->bb_overrides.urgent_latency_ns / 1000.0; 2206 } 2207 2208 if (dc->bb_overrides.dram_clock_change_latency_ns) { 2209 for (i = 0; i < WM_SET_COUNT; i++) { 2210 dc->clk_mgr->bw_params->wm_table.entries[i].pstate_latency_us = 2211 dc->bb_overrides.dram_clock_change_latency_ns / 1000.0; 2212 } 2213 } 2214 } 2215 2216 static void calculate_wm_set_for_vlevel(int vlevel, 2217 struct wm_range_table_entry *table_entry, 2218 struct dcn_watermarks *wm_set, 2219 struct display_mode_lib *dml, 2220 display_e2e_pipe_params_st *pipes, 2221 int pipe_cnt) 2222 { 2223 double dram_clock_change_latency_cached = dml->soc.dram_clock_change_latency_us; 2224 2225 ASSERT(vlevel < (int)dml->soc.num_states); 2226 /* only pipe 0 is read for voltage and dcf/soc clocks */ 2227 pipes[0].clks_cfg.voltage = vlevel; 2228 pipes[0].clks_cfg.dcfclk_mhz = dml->soc.clock_limits[vlevel].dcfclk_mhz; 2229 pipes[0].clks_cfg.socclk_mhz = dml->soc.clock_limits[vlevel].socclk_mhz; 2230 2231 dml->soc.dram_clock_change_latency_us = table_entry->pstate_latency_us; 2232 dml->soc.sr_exit_time_us = table_entry->sr_exit_time_us; 2233 dml->soc.sr_enter_plus_exit_time_us = table_entry->sr_enter_plus_exit_time_us; 2234 2235 wm_set->urgent_ns = (uint32_t)(get_wm_urgent(dml, pipes, pipe_cnt) * 1000.0); 2236 wm_set->cstate_pstate.cstate_enter_plus_exit_ns = (uint32_t)(get_wm_stutter_enter_exit(dml, pipes, pipe_cnt) * 1000.0); 2237 wm_set->cstate_pstate.cstate_exit_ns = (uint32_t)(get_wm_stutter_exit(dml, pipes, pipe_cnt) * 1000.0); 2238 wm_set->cstate_pstate.pstate_change_ns = (uint32_t)(get_wm_dram_clock_change(dml, pipes, pipe_cnt) * 1000.0); 2239 wm_set->pte_meta_urgent_ns = (uint32_t)(get_wm_memory_trip(dml, pipes, pipe_cnt) * 1000.0); 2240 wm_set->frac_urg_bw_nom = (uint32_t)(get_fraction_of_urgent_bandwidth(dml, pipes, pipe_cnt) * 1000.0); 2241 wm_set->frac_urg_bw_flip = (uint32_t)(get_fraction_of_urgent_bandwidth_imm_flip(dml, pipes, pipe_cnt) * 1000.0); 2242 wm_set->urgent_latency_ns = (uint32_t)(get_urgent_latency(dml, pipes, pipe_cnt) * 1000.0); 2243 dml->soc.dram_clock_change_latency_us = dram_clock_change_latency_cached; 2244 } 2245 2246 static void dcn21_calculate_wm(struct dc *dc, struct dc_state *context, 2247 display_e2e_pipe_params_st *pipes, 2248 int *out_pipe_cnt, 2249 int *pipe_split_from, 2250 int vlevel_req, 2251 enum dc_validate_mode validate_mode) 2252 { 2253 int pipe_cnt, pipe_idx; 2254 unsigned int i; 2255 int vlevel, vlevel_max; 2256 struct wm_range_table_entry *table_entry; 2257 struct clk_bw_params *bw_params = dc->clk_mgr->bw_params; 2258 2259 ASSERT(bw_params); 2260 2261 patch_bounding_box(dc, &context->bw_ctx.dml.soc); 2262 2263 for (i = 0, pipe_idx = 0, pipe_cnt = 0; i < dc->res_pool->pipe_count; i++) { 2264 if (!context->res_ctx.pipe_ctx[i].stream) 2265 continue; 2266 2267 pipes[pipe_cnt].clks_cfg.refclk_mhz = dc->res_pool->ref_clocks.dchub_ref_clock_inKhz / 1000.0; 2268 pipes[pipe_cnt].clks_cfg.dispclk_mhz = context->bw_ctx.dml.vba.RequiredDISPCLK[vlevel_req][context->bw_ctx.dml.vba.maxMpcComb]; 2269 2270 if (pipe_split_from[i] < 0) { 2271 pipes[pipe_cnt].clks_cfg.dppclk_mhz = 2272 context->bw_ctx.dml.vba.RequiredDPPCLK[vlevel_req][context->bw_ctx.dml.vba.maxMpcComb][pipe_idx]; 2273 if (context->bw_ctx.dml.vba.BlendingAndTiming[pipe_idx] == pipe_idx) 2274 pipes[pipe_cnt].pipe.dest.odm_combine = 2275 context->bw_ctx.dml.vba.ODMCombineEnablePerState[vlevel_req][pipe_idx]; 2276 else 2277 pipes[pipe_cnt].pipe.dest.odm_combine = 0; 2278 pipe_idx++; 2279 } else { 2280 pipes[pipe_cnt].clks_cfg.dppclk_mhz = 2281 context->bw_ctx.dml.vba.RequiredDPPCLK[vlevel_req][context->bw_ctx.dml.vba.maxMpcComb][pipe_split_from[i]]; 2282 if (context->bw_ctx.dml.vba.BlendingAndTiming[pipe_split_from[i]] == pipe_split_from[i]) 2283 pipes[pipe_cnt].pipe.dest.odm_combine = 2284 context->bw_ctx.dml.vba.ODMCombineEnablePerState[vlevel_req][pipe_split_from[i]]; 2285 else 2286 pipes[pipe_cnt].pipe.dest.odm_combine = 0; 2287 } 2288 pipe_cnt++; 2289 } 2290 2291 if (pipe_cnt != pipe_idx) { 2292 if (dc->res_pool->funcs->populate_dml_pipes) 2293 pipe_cnt = dc->res_pool->funcs->populate_dml_pipes(dc, 2294 context, pipes, validate_mode); 2295 else 2296 pipe_cnt = dcn21_populate_dml_pipes_from_context(dc, 2297 context, pipes, validate_mode); 2298 } 2299 2300 *out_pipe_cnt = pipe_cnt; 2301 2302 vlevel_max = bw_params->clk_table.num_entries - 1; 2303 2304 2305 /* WM Set D */ 2306 table_entry = &bw_params->wm_table.entries[WM_D]; 2307 if (table_entry->wm_type == WM_TYPE_RETRAINING) 2308 vlevel = 0; 2309 else 2310 vlevel = vlevel_max; 2311 calculate_wm_set_for_vlevel(vlevel, table_entry, &context->bw_ctx.bw.dcn.watermarks.d, 2312 &context->bw_ctx.dml, pipes, pipe_cnt); 2313 /* WM Set C */ 2314 table_entry = &bw_params->wm_table.entries[WM_C]; 2315 vlevel = MIN(MAX(vlevel_req, 3), vlevel_max); 2316 calculate_wm_set_for_vlevel(vlevel, table_entry, &context->bw_ctx.bw.dcn.watermarks.c, 2317 &context->bw_ctx.dml, pipes, pipe_cnt); 2318 /* WM Set B */ 2319 table_entry = &bw_params->wm_table.entries[WM_B]; 2320 vlevel = MIN(MAX(vlevel_req, 2), vlevel_max); 2321 calculate_wm_set_for_vlevel(vlevel, table_entry, &context->bw_ctx.bw.dcn.watermarks.b, 2322 &context->bw_ctx.dml, pipes, pipe_cnt); 2323 2324 /* WM Set A */ 2325 table_entry = &bw_params->wm_table.entries[WM_A]; 2326 vlevel = MIN(vlevel_req, vlevel_max); 2327 calculate_wm_set_for_vlevel(vlevel, table_entry, &context->bw_ctx.bw.dcn.watermarks.a, 2328 &context->bw_ctx.dml, pipes, pipe_cnt); 2329 } 2330 2331 bool dcn21_validate_bandwidth_fp(struct dc *dc, struct dc_state *context, 2332 enum dc_validate_mode validate_mode, display_e2e_pipe_params_st *pipes) 2333 { 2334 bool out = false; 2335 2336 BW_VAL_TRACE_SETUP(); 2337 2338 int vlevel = 0; 2339 int pipe_split_from[MAX_PIPES]; 2340 int pipe_cnt = 0; 2341 DC_LOGGER_INIT(dc->ctx->logger); 2342 2343 BW_VAL_TRACE_COUNT(); 2344 2345 dc_assert_fp_enabled(); 2346 2347 /*Unsafe due to current pipe merge and split logic*/ 2348 ASSERT(context != dc->current_state); 2349 2350 out = dcn21_fast_validate_bw(dc, context, pipes, &pipe_cnt, pipe_split_from, &vlevel, validate_mode, false); 2351 2352 if (pipe_cnt == 0) 2353 goto validate_out; 2354 2355 if (!out) 2356 goto validate_fail; 2357 2358 BW_VAL_TRACE_END_VOLTAGE_LEVEL(); 2359 2360 if (validate_mode != DC_VALIDATE_MODE_AND_PROGRAMMING) { 2361 BW_VAL_TRACE_SKIP(fast); 2362 goto validate_out; 2363 } 2364 2365 dcn21_calculate_wm(dc, context, pipes, &pipe_cnt, pipe_split_from, vlevel, validate_mode); 2366 dcn20_calculate_dlg_params(dc, context, pipes, pipe_cnt, vlevel); 2367 2368 BW_VAL_TRACE_END_WATERMARKS(); 2369 2370 goto validate_out; 2371 2372 validate_fail: 2373 DC_LOG_WARNING("Mode Validation Warning: %s failed validation.\n", 2374 dml_get_status_message(context->bw_ctx.dml.vba.ValidationStatus[context->bw_ctx.dml.vba.soc.num_states])); 2375 2376 BW_VAL_TRACE_SKIP(fail); 2377 out = false; 2378 2379 validate_out: 2380 2381 BW_VAL_TRACE_FINISH(); 2382 2383 return out; 2384 } 2385 2386 static struct _vcs_dpi_voltage_scaling_st construct_low_pstate_lvl(struct clk_limit_table *clk_table, unsigned int high_voltage_lvl) 2387 { 2388 struct _vcs_dpi_voltage_scaling_st low_pstate_lvl = {0}; 2389 int i; 2390 2391 low_pstate_lvl.state = 1; 2392 low_pstate_lvl.dcfclk_mhz = clk_table->entries[0].dcfclk_mhz; 2393 low_pstate_lvl.fabricclk_mhz = clk_table->entries[0].fclk_mhz; 2394 low_pstate_lvl.socclk_mhz = clk_table->entries[0].socclk_mhz; 2395 low_pstate_lvl.dram_speed_mts = clk_table->entries[0].memclk_mhz * 2; 2396 2397 low_pstate_lvl.dispclk_mhz = dcn2_1_soc.clock_limits[high_voltage_lvl].dispclk_mhz; 2398 low_pstate_lvl.dppclk_mhz = dcn2_1_soc.clock_limits[high_voltage_lvl].dppclk_mhz; 2399 low_pstate_lvl.dram_bw_per_chan_gbps = dcn2_1_soc.clock_limits[high_voltage_lvl].dram_bw_per_chan_gbps; 2400 low_pstate_lvl.dscclk_mhz = dcn2_1_soc.clock_limits[high_voltage_lvl].dscclk_mhz; 2401 low_pstate_lvl.dtbclk_mhz = dcn2_1_soc.clock_limits[high_voltage_lvl].dtbclk_mhz; 2402 low_pstate_lvl.phyclk_d18_mhz = dcn2_1_soc.clock_limits[high_voltage_lvl].phyclk_d18_mhz; 2403 low_pstate_lvl.phyclk_mhz = dcn2_1_soc.clock_limits[high_voltage_lvl].phyclk_mhz; 2404 2405 for (i = clk_table->num_entries; i > 1; i--) 2406 clk_table->entries[i] = clk_table->entries[i-1]; 2407 clk_table->entries[1] = clk_table->entries[0]; 2408 clk_table->num_entries++; 2409 2410 return low_pstate_lvl; 2411 } 2412 2413 void dcn21_update_bw_bounding_box_fpu(struct dc *dc, struct clk_bw_params *bw_params) 2414 { 2415 struct _vcs_dpi_voltage_scaling_st *s = dc->scratch.update_bw_bounding_box.clock_limits; 2416 struct dcn21_resource_pool *pool = TO_DCN21_RES_POOL(dc->res_pool); 2417 struct clk_limit_table *clk_table = &bw_params->clk_table; 2418 unsigned int i, closest_clk_lvl = 0, k = 0; 2419 int j; 2420 2421 dc_assert_fp_enabled(); 2422 2423 dcn2_1_ip.max_num_otg = pool->base.res_cap->num_timing_generator; 2424 dcn2_1_ip.max_num_dpp = pool->base.pipe_count; 2425 dcn2_1_soc.num_chans = bw_params->num_channels; 2426 2427 ASSERT(clk_table->num_entries); 2428 /* Copy dcn2_1_soc.clock_limits to clock_limits to avoid copying over null states later */ 2429 memcpy(s, dcn2_1_soc.clock_limits, sizeof(dcn2_1_soc.clock_limits)); 2430 2431 for (i = 0; i < clk_table->num_entries; i++) { 2432 /* loop backwards*/ 2433 for (closest_clk_lvl = 0, j = dcn2_1_soc.num_states - 1; j >= 0; j--) { 2434 if ((unsigned int) dcn2_1_soc.clock_limits[j].dcfclk_mhz <= clk_table->entries[i].dcfclk_mhz) { 2435 closest_clk_lvl = j; 2436 break; 2437 } 2438 } 2439 2440 /* clk_table[1] is reserved for min DF PState. skip here to fill in later. */ 2441 if (i == 1) 2442 k++; 2443 2444 s[k].state = k; 2445 s[k].dcfclk_mhz = clk_table->entries[i].dcfclk_mhz; 2446 s[k].fabricclk_mhz = clk_table->entries[i].fclk_mhz; 2447 s[k].socclk_mhz = clk_table->entries[i].socclk_mhz; 2448 s[k].dram_speed_mts = clk_table->entries[i].memclk_mhz * 2; 2449 2450 s[k].dispclk_mhz = dcn2_1_soc.clock_limits[closest_clk_lvl].dispclk_mhz; 2451 s[k].dppclk_mhz = dcn2_1_soc.clock_limits[closest_clk_lvl].dppclk_mhz; 2452 s[k].dram_bw_per_chan_gbps = 2453 dcn2_1_soc.clock_limits[closest_clk_lvl].dram_bw_per_chan_gbps; 2454 s[k].dscclk_mhz = dcn2_1_soc.clock_limits[closest_clk_lvl].dscclk_mhz; 2455 s[k].dtbclk_mhz = dcn2_1_soc.clock_limits[closest_clk_lvl].dtbclk_mhz; 2456 s[k].phyclk_d18_mhz = dcn2_1_soc.clock_limits[closest_clk_lvl].phyclk_d18_mhz; 2457 s[k].phyclk_mhz = dcn2_1_soc.clock_limits[closest_clk_lvl].phyclk_mhz; 2458 2459 k++; 2460 } 2461 2462 memcpy(&dcn2_1_soc.clock_limits, s, sizeof(dcn2_1_soc.clock_limits)); 2463 2464 if (clk_table->num_entries) { 2465 dcn2_1_soc.num_states = clk_table->num_entries + 1; 2466 /* fill in min DF PState */ 2467 dcn2_1_soc.clock_limits[1] = construct_low_pstate_lvl(clk_table, closest_clk_lvl); 2468 /* duplicate last level */ 2469 dcn2_1_soc.clock_limits[dcn2_1_soc.num_states] = dcn2_1_soc.clock_limits[dcn2_1_soc.num_states - 1]; 2470 dcn2_1_soc.clock_limits[dcn2_1_soc.num_states].state = dcn2_1_soc.num_states; 2471 } 2472 2473 dml_init_instance(&dc->dml, &dcn2_1_soc, &dcn2_1_ip, DML_PROJECT_DCN21); 2474 } 2475 2476 void dcn21_clk_mgr_set_bw_params_wm_table(struct clk_bw_params *bw_params) 2477 { 2478 dc_assert_fp_enabled(); 2479 2480 bw_params->wm_table.entries[WM_D].pstate_latency_us = LPDDR_MEM_RETRAIN_LATENCY; 2481 bw_params->wm_table.entries[WM_D].wm_inst = WM_D; 2482 bw_params->wm_table.entries[WM_D].wm_type = WM_TYPE_RETRAINING; 2483 bw_params->wm_table.entries[WM_D].valid = true; 2484 } 2485 2486 void dcn201_populate_dml_writeback_from_context_fpu(struct dc *dc, 2487 struct resource_context *res_ctx, 2488 display_e2e_pipe_params_st *pipes) 2489 { 2490 int pipe_cnt; 2491 unsigned int i, j; 2492 double max_calc_writeback_dispclk; 2493 double writeback_dispclk; 2494 struct writeback_st dout_wb = {0}; 2495 2496 dc_assert_fp_enabled(); 2497 2498 for (i = 0, pipe_cnt = 0; i < dc->res_pool->pipe_count; i++) { 2499 struct dc_stream_state *stream = res_ctx->pipe_ctx[i].stream; 2500 2501 if (!stream) 2502 continue; 2503 max_calc_writeback_dispclk = 0; 2504 2505 /* Set writeback information */ 2506 pipes[pipe_cnt].dout.wb_enable = 0; 2507 pipes[pipe_cnt].dout.num_active_wb = 0; 2508 for (j = 0; j < stream->num_wb_info; j++) { 2509 struct dc_writeback_info *wb_info = &stream->writeback_info[j]; 2510 2511 if (wb_info->wb_enabled && wb_info->writeback_source_plane && 2512 (wb_info->writeback_source_plane == res_ctx->pipe_ctx[i].plane_state)) { 2513 pipes[pipe_cnt].dout.wb_enable = 1; 2514 pipes[pipe_cnt].dout.num_active_wb++; 2515 dout_wb.wb_src_height = wb_info->dwb_params.cnv_params.crop_en ? 2516 wb_info->dwb_params.cnv_params.crop_height : 2517 wb_info->dwb_params.cnv_params.src_height; 2518 dout_wb.wb_src_width = wb_info->dwb_params.cnv_params.crop_en ? 2519 wb_info->dwb_params.cnv_params.crop_width : 2520 wb_info->dwb_params.cnv_params.src_width; 2521 dout_wb.wb_dst_width = wb_info->dwb_params.dest_width; 2522 dout_wb.wb_dst_height = wb_info->dwb_params.dest_height; 2523 dout_wb.wb_htaps_luma = wb_info->dwb_params.scaler_taps.h_taps; 2524 dout_wb.wb_vtaps_luma = wb_info->dwb_params.scaler_taps.v_taps; 2525 dout_wb.wb_htaps_chroma = wb_info->dwb_params.scaler_taps.h_taps_c; 2526 dout_wb.wb_vtaps_chroma = wb_info->dwb_params.scaler_taps.v_taps_c; 2527 dout_wb.wb_hratio = wb_info->dwb_params.cnv_params.crop_en ? 2528 (double)wb_info->dwb_params.cnv_params.crop_width / 2529 (double)wb_info->dwb_params.dest_width : 2530 (double)wb_info->dwb_params.cnv_params.src_width / 2531 (double)wb_info->dwb_params.dest_width; 2532 dout_wb.wb_vratio = wb_info->dwb_params.cnv_params.crop_en ? 2533 (double)wb_info->dwb_params.cnv_params.crop_height / 2534 (double)wb_info->dwb_params.dest_height : 2535 (double)wb_info->dwb_params.cnv_params.src_height / 2536 (double)wb_info->dwb_params.dest_height; 2537 if (wb_info->dwb_params.out_format == dwb_scaler_mode_yuv420) { 2538 if (wb_info->dwb_params.output_depth == DWB_OUTPUT_PIXEL_DEPTH_8BPC) 2539 dout_wb.wb_pixel_format = dm_420_8; 2540 else 2541 dout_wb.wb_pixel_format = dm_420_10; 2542 } else 2543 dout_wb.wb_pixel_format = dm_444_32; 2544 2545 /* Workaround for cases where multiple writebacks are connected to same plane 2546 * In which case, need to compute worst case and set the associated writeback parameters 2547 * This workaround is necessary due to DML computation assuming only 1 set of writeback 2548 * parameters per pipe */ 2549 writeback_dispclk = CalculateWriteBackDISPCLK( 2550 dout_wb.wb_pixel_format, 2551 pipes[pipe_cnt].pipe.dest.pixel_rate_mhz, 2552 dout_wb.wb_hratio, 2553 dout_wb.wb_vratio, 2554 dout_wb.wb_htaps_luma, 2555 dout_wb.wb_vtaps_luma, 2556 dout_wb.wb_htaps_chroma, 2557 dout_wb.wb_vtaps_chroma, 2558 dout_wb.wb_dst_width, 2559 pipes[pipe_cnt].pipe.dest.htotal, 2560 2); 2561 2562 if (writeback_dispclk > max_calc_writeback_dispclk) { 2563 max_calc_writeback_dispclk = writeback_dispclk; 2564 pipes[pipe_cnt].dout.wb = dout_wb; 2565 } 2566 } 2567 } 2568 2569 pipe_cnt++; 2570 } 2571 2572 } 2573